ATLAS Offline Software
Loading...
Searching...
No Matches
testEgChargeCorr.cxx File Reference

Go to the source code of this file.

Namespaces

namespace  asg

Functions

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

Function Documentation

◆ main()

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

Definition at line 47 of file testEgChargeCorr.cxx.

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