ATLAS Offline Software
Namespaces | Functions
testEgChargeCorr.cxx File Reference
#include <cstdlib>
#include <memory>
#include <string>
#include <TError.h>
#include <TFile.h>
#include <TString.h>
#include "ElectronEfficiencyCorrection/ElectronChargeEfficiencyCorrectionTool.h"
#include "ElectronEfficiencyCorrection/ElectronEfficiencyHelpers.h"
#include "xAODCore/ShallowCopy.h"
#include "xAODEgamma/Egamma.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEventInfo/EventInfo.h"
#include "AsgMessaging/AsgMessaging.h"
#include "PATCore/AcceptData.h"
#include "PATInterfaces/SystematicsUtil.h"
#include <ElectronPhotonSelectorTools/AsgElectronLikelihoodTool.h>
#include "AsgMessaging/MessageCheck.h"
#include "AsgMessaging/MsgStream.h"

Go to the source code of this file.

Namespaces

 asg
 

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 48 of file testEgChargeCorr.cxx.

49 {
50  const char* APP_NAME = argv[0];
51  using namespace asg::testEgChargeCorr;
52  ANA_CHECK_SET_TYPE (int);
53  MSG::Level mylevel=MSG::INFO;
54  setMsgLevel(mylevel);
55  msg().setName(APP_NAME);
56 
57  // Check if we received a file name:
58  if (argc < 3) {
59  Error(APP_NAME, "No file name received!");
61  " Usage: %s [xAOD file name] [Correction File name]",
62  APP_NAME);
63  return 1;
64  }
65 
66  double SF_chargeID = 0;
67  int SF_nevents = 0;
68 
69  double n_chargeID = 0;
70  double n_chargeMisID = 0;
71 
72  // Initialise the application:
74 
75  // Open the input file:
76  const TString fileName = argv[1];
77  const TString corrFileName = argv[2];
78 
79  Info(APP_NAME, "Opening file: %s", fileName.Data());
80  std::unique_ptr<TFile> ifile(TFile::Open(fileName, "READ"));
81  ANA_CHECK(ifile.get());
82 
83  // Create a TEvent object:
84  // xAOD::TEvent event( xAOD::TEvent::kBranchAccess );
86  ANA_CHECK(event.readFrom(ifile.get()));
87  Info(APP_NAME,
88  "Number of events in the file: %i",
89  static_cast<int>(event.getEntries()));
90 
91  std::cout << "==" << std::endl;
92 
93  // Decide how many events to run over:
94  Long64_t entries = event.getEntries();
95  if (argc > 2) {
96  const Long64_t e = atoll(argv[2]);
97  if (e < entries) {
98  entries = e;
99  }
100  }
101 
102  // Likelihood
103  CP::ElectronChargeEfficiencyCorrectionTool myEgCorrections("myEgCorrections");
104  ANA_CHECK(myEgCorrections.setProperty("OutputLevel", mylevel));
105 
106  std::string inputFile =
107  corrFileName.Data(); //"data/ChMisIDSF_TightLL_FixedCutTight.root" ;
108  ANA_CHECK(myEgCorrections.setProperty("CorrectionFileName", inputFile));
109  ANA_CHECK(myEgCorrections.setProperty("ForceDataType", 1));
110 
111  ANA_CHECK(myEgCorrections.setProperty("DefaultRandomRunNumber",
112  (unsigned int)311481));
113  ANA_CHECK(myEgCorrections.setProperty("UseRandomRunNumber", false));
114  ANA_CHECK(myEgCorrections.initialize());
115 
116  AsgElectronLikelihoodTool* m_LHToolTight =
117  new AsgElectronLikelihoodTool("m_LHToolTight");
118  ANA_CHECK(
119  m_LHToolTight->setProperty("primaryVertexContainer", "PrimaryVertices"));
120  m_LHToolTight
121  ->setProperty("ConfigFile",
122  "ElectronPhotonSelectorTools/offline/mc15_20160512/"
123  "ElectronLikelihoodLooseOfflineConfig2016_CutBL_Smooth.conf")
124  .ignore();
125  ANA_CHECK(m_LHToolTight->initialize());
126 
127  // Get a list of systematics
128  CP::SystematicSet recSysts = myEgCorrections.recommendedSystematics();
129  // Convert into a simple list
130  // std::vector<CP::SystematicSet> sysList =
131  // CP::make_systematics_vector(recSysts);
132 
133  std::cout << "==" << std::endl;
134 
135  // Loop over the events:
136  entries = 600;
137 
138  Long64_t entry = 0;
139  for (; entry < entries; ++entry) {
140 
141  // Tell the object which entry to look at:
142  event.getEntry(entry);
143 
144  if (entry < 10)
145  std::cout << "=================NEXT EVENT=========================="
146  << std::endl;
147  Info(APP_NAME, "Electron");
148 
149  const xAOD::EventInfo* event_info = nullptr;
150  ANA_CHECK(event.retrieve(event_info, "EventInfo"));
151 
152  const xAOD::ElectronContainer* electrons = nullptr;
153  ANA_CHECK(event.retrieve(electrons, "Electrons"));
154 
155  // Create shallow copy for this systematic
156  std::pair<xAOD::ElectronContainer*, xAOD::ShallowAuxContainer*>
157  electrons_shallowCopy = xAOD::shallowCopyContainer(*electrons);
158 
159  // Iterate over the shallow copy
160  xAOD::ElectronContainer* elsCorr = electrons_shallowCopy.first;
161  xAOD::ElectronContainer::iterator el_it = elsCorr->begin();
162  xAOD::ElectronContainer::iterator el_it_last = elsCorr->end();
163 
164  static const SG::ConstAccessor<float> sfAcc("SF");
165 
166  unsigned int i = 0;
167  double SF = 0;
168  for (; el_it != el_it_last; ++el_it, ++i) {
169 
170  xAOD::Electron* el = *el_it;
171  if (el->pt() < 20000)
172  continue; // skip electrons outside of recommendations
173 
174  bool LHacc{ m_LHToolTight->accept(el) };
175  std::cout << "acc: " << LHacc << std::endl;
176  if (!m_LHToolTight->accept(el))
177  continue;
178  double clusAbsEta = std::abs(el->caloCluster()->etaBE(2));
179  if ( clusAbsEta > 1.37 && (clusAbsEta < 1.52 || clusAbsEta > 2.47) )
180  continue; // skip electrons outside of recommendations (in the crack we fill 1 into the SFs)
181 
182  SF_nevents++;
183 
184  Info(APP_NAME, "Electron #%d", i);
185 
186  if (myEgCorrections.getEfficiencyScaleFactor(*el, SF) !=
188  Error(APP_NAME, "Problem in getEfficiencyScaleFactor");
189  return EXIT_FAILURE;
190  }
191 
192  if (myEgCorrections.applyEfficiencyScaleFactor(*el) !=
194  Error(APP_NAME, "Problem in applyEfficiencyScaleFactor");
195  return EXIT_FAILURE;
196  }
197 
198  Info( APP_NAME, "===>>> Resulting SF (from get function) %f, (from apply function) %f",
199  SF, sfAcc(*el));
200 
201  SF_chargeID = SF_chargeID + SF;
202 
203  for (const auto& sys : recSysts) { // recSysts){
204  double systematic = 0;
205 
206  // Configure the tool for this systematic
207  ANA_CHECK(myEgCorrections.applySystematicVariation({ sys }));
208  //
209  if (myEgCorrections.getEfficiencyScaleFactor(*el, systematic) ==
211  Info(APP_NAME,
212  "%f Result %f Systematic value %f ",
213  SF,
214  systematic,
215  systematic - SF);
216  }
217  }
218  ANA_CHECK(myEgCorrections.applySystematicVariation({})); // Empty variation is the nominal
219 
220 
221  int truthcharge = false;
223  if (el->charge() * truthcharge < 0) {
224  n_chargeMisID+=SF;
225  } else
226  n_chargeID+=SF;
227  }
228 
229  // }
230  }
231  Info(APP_NAME, "===>>> done processing event #%lld ", entry);
232  Info(APP_NAME, "===>>> processed #%d electrons", SF_nevents);
233  Info(APP_NAME, "===>>> compared to #%f (from Charge MisId SF)", SF_chargeID);
234  Info(APP_NAME, "===>>> compared to #%f and #%f ", n_chargeID, n_chargeMisID);
235 
236  // Return gracefully:
237  return 0;
238 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TRT_PAI_gasdata::SF
const float SF[NF]
Cross sections for Fluor.
Definition: TRT_PAI_gasdata.h:285
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
AsgElectronLikelihoodTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const override final
The main accept method: using the generic interface.
Definition: AsgElectronLikelihoodTool.cxx:868
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor< float >
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
AsgElectronLikelihoodTool
Electron selector tool to select objects in Athena using an underlying pure ROOT tool.
Definition: AsgElectronLikelihoodTool.h:30
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::ElectronChargeEfficiencyCorrectionTool
Definition: ElectronChargeEfficiencyCorrectionTool.h:29
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:85
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:124
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
ElectronEfficiencyHelpers::getEleTruthCharge
CP::CorrectionCode getEleTruthCharge(const xAOD::Electron &ele, int &truthcharge)
Get the charge of the original electron.
Definition: ElectronEfficiencyHelpers.cxx:14
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
entries
double entries
Definition: listroot.cxx:49
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
AsgElectronLikelihoodTool::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations.
Definition: AsgElectronLikelihoodTool.cxx:80
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31