61{
62 StatusCode::enableFailure();
63
64
65 if( argc < 2 )
66 {
67 Error(
"TauAnalysisToolsExample",
"No file name received!" );
68 Error(
"TauAnalysisToolsExample",
" Usage: %s [xAOD file name]",
"TauAnalysisToolsExample" );
69 return 1;
70 }
71
72
74
75
76 const TString sInputFileName =
argv[ 1 ];
77 Info(
"TauAnalysisToolsExample",
"Opening input file: %s", sInputFileName.Data() );
78 std::unique_ptr< TFile > fInputFile( TFile::Open( sInputFileName, "READ" ) );
79 CHECK( fInputFile.get() );
80
81
82 TString sOutputFileName = "output.root";
83 if (argc>3)
84 sOutputFileName = TString(argv[3]);
85
86
87 bool m_doTrigger =
bool(argc>4);
88
89 Info(
"TauAnalysisToolsExample",
"Opening output file: %s", sOutputFileName.Data() );
90 std::unique_ptr< TFile > fOutputFile( TFile::Open( sOutputFileName, "RECREATE" ) );
91 CHECK( fOutputFile.get() );
92
93
94
96 CHECK( xEvent.readFrom( fInputFile.get() ) );
97
98
99 CHECK( xEvent.writeTo( fOutputFile.get() ) );
100
101 Info(
"TauAnalysisToolsExample",
"Number of events in the file: %i",
102 static_cast< int >( xEvent.getEntries() ) );
103
104
105 Long64_t iEntries = xEvent.getEntries();
106 if( argc > 2 )
107 {
108 const Long64_t iMaxEntries = atoll( argv[ 2 ] );
109 if( iMaxEntries < iEntries )
110 {
111 iEntries = iMaxEntries;
112 }
113 }
114
115
118
119
120
121
123 TauSelTool->
msg().setLevel( MSG::DEBUG );
124
126 CHECK(TauSelTool->setProperty(
"CreateControlPlots",
true ));
129 CHECK(TauSelTool->setProperty(
"EleIDVersion", 1 ));
130 CHECK(TauSelTool->setProperty(
"PtMin", 20. ));
131 CHECK(TauSelTool->setProperty(
"ConfigPath",
"" ));
134
135
136
137
139 TauSmeTool.msg().setLevel( MSG::DEBUG );
140 CHECK(TauSmeTool.setProperty(
"RecommendationTag",
"2025-prerec"));
141 CHECK(TauSmeTool.setProperty(
"Campaign",
"mc23"));
142 CHECK(TauSmeTool.initialize());
143
144
145 std::vector<CP::SystematicSet> vSmearingSystematicSet;
146 for (auto SystematicsVariation : TauSmeTool.recommendedSystematics())
147 {
149 vSmearingSystematicSet.back().insert(SystematicsVariation);
150 }
151
152
153
154
156 TauEffCorrTool.msg().setLevel( MSG::VERBOSE );
159 CHECK(TauEffCorrTool.setProperty(
"RecommendationTag",
"2025-prerec"));
160 CHECK(TauEffCorrTool.setProperty(
"Campaign",
"mc23"));
161 CHECK(TauEffCorrTool.initialize());
162
163
164 std::vector<CP::SystematicSet> vEfficiencyCorrectionsSystematicSet;
166 for (auto SystematicsVariation : TauEffCorrTool.recommendedSystematics())
167 {
169 vEfficiencyCorrectionsSystematicSet.back().insert(SystematicsVariation);
170 }
171
172
173
174
176
177 std::vector<CP::SystematicSet> vEfficiencyCorrectionsTriggerSystematicSet;
178 if (m_doTrigger){
179
180 TauEffTrigTool.msg().setLevel( MSG::DEBUG );
181 CHECK(TauEffTrigTool.setProperty(
"EfficiencyCorrectionTypes", std::vector<int>({SFTriggerHadTau}) ));
182 CHECK(TauEffTrigTool.setProperty(
"TriggerName",
"HLT_tau25_mediumRNN_tracktwoMVA" ));
184 CHECK(TauEffTrigTool.setProperty(
"Campaign",
"mc23a"));
185 CHECK(TauEffTrigTool.initialize());
186
188 for (auto SystematicsVariation : TauEffTrigTool.recommendedSystematics())
189 {
191 vEfficiencyCorrectionsTriggerSystematicSet.back().insert(SystematicsVariation);
192 }
193 }
194
195
196
198 T2MT.msg().setLevel( MSG::INFO );
199 CHECK(T2MT.setProperty(
"TruthJetContainerName",
"AntiKt4TruthDressedWZJets"));
200 CHECK(T2MT.initialize());
201
211
212
213 for( Long64_t iEntry = 0; iEntry < iEntries; ++iEntry )
214 {
215
216 xEvent.getEntry( iEntry );
217
218
220 if (xEventInfo)
221 Info(
"TauAnalysisToolsExample",
222 "===>>> start processing event #%i, "
223 "run #%i %i events processed so far <<<===",
225 static_cast< int >( xEventInfo->
runNumber() ),
226 static_cast< int >( iEntry ) );
227
228
229
230 const char * m_tauJetContainerName = "TauJets";
233 }else{
234 m_tauJetContainerName = "AnalysisTauJets";
236 }
237 std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* >xTauShallowContainer =
xAOD::shallowCopyContainer(*xTauJetContainer);
238 if(iEntry==0){
239 Info(
"TauAnalysisToolsExample:: TauJetContainer = ",m_tauJetContainerName);
240 }
241
242
244 CHECK( xEvent.copy(
"TruthParticles") );
245
246
247 CHECK( xEvent.copy(m_tauJetContainerName) );
248
249
250 CHECK( xEvent.copy(
"InDetTrackParticles") );
251
252
253 for ( auto xTau : *xTauShallowContainer.first )
254 {
255
256 auto xTruthTau = T2MT.getTruth(*xTau);
257
258 if (static_cast<bool>(acc_IsTruthMatched(*xTau)))
259 {
260 if (xTruthTau->isTau())
261 {
262 if (static_cast<bool>(acc_IsHadronicTau(*xTruthTau)))
263 Info(
"TauAnalysisToolsExample",
264 "Tau was matched to a truth hadronic tau, which has %i prongs and a charge of %i",
265 int(acc_numCharged(*xTruthTau)),
266 int(xTruthTau->charge()));
267 else
268 Info(
"TauAnalysisToolsExample",
269 "Tau was matched to a truth leptonic tau, which has a charge of %i",
270 int(xTruthTau->charge()));
271 }
272 else if (xTruthTau->isElectron())
273 Info(
"TauAnalysisToolsExample",
274 "Tau was matched to a truth electron");
275 else if (xTruthTau->isMuon())
276 Info(
"TauAnalysisToolsExample",
277 "Tau was matched to a truth muon");
278 }
279 else
280 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth" );
281
282 auto xTruthJetLink = acc_truthJetLink(*xTau);
283 if (xTruthJetLink.isValid())
284 {
285 const xAOD::Jet* xTruthJet = *xTruthJetLink;
286 Info(
"TauAnalysisToolsExample",
287 "Tau was matched to a truth jet, which has pt=%g, eta=%g, phi=%g, m=%g",
288 xTruthJet->
p4().Pt(),
289 xTruthJet->
p4().Eta(),
290 xTruthJet->
p4().Phi(),
291 xTruthJet->
p4().M());
292 }
293 else
294 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth jet" );
295
296 Info(
"TauAnalysisToolsExample",
297 "Un-Smeared tau pt: %g ",
298 xTau->ptFinalCalib());
299 CHECK( TauSmeTool.applyCorrection(*xTau) );
300 Info(
"TauAnalysisToolsExample",
301 "Smeared tau pt: %g ",
302 xTau->pt());
303
304 for (auto sSystematicSet: vSmearingSystematicSet)
305 {
306 CHECK( TauSmeTool.applySystematicVariation(sSystematicSet)) ;
307 CHECK( TauSmeTool.applyCorrection(*xTau) );
308
309 if (static_cast<bool>(acc_IsTruthMatched(*xTau)) && xTruthTau->isTau() && static_cast<bool>(acc_IsHadronicTau(*xTruthTau))){
310 Info(
"TauAnalysisToolsExample",
311 "Smeared tau pt: %g for type %s ",
312 xTau->pt(),
313 sSystematicSet.name().c_str());
314 }
315 }
316
317
318 if( ! TauSelTool->
accept( *xTau ) ){
319 Info(
"TauAnalysisToolsExample",
320 "Tau does not pass selection tool: pt %g ",
321 xTau->pt());
322 continue;
323 }
324
325 for (auto sSystematicSet: vEfficiencyCorrectionsSystematicSet)
326 {
327 CHECK( TauEffCorrTool.applySystematicVariation(sSystematicSet));
328 CHECK( TauEffCorrTool.applyEfficiencyScaleFactor(*xTau) );
329 Info(
"TauAnalysisToolsExample",
330 "SystType %s: RecoSF: %g JetIDSF: %g EleOLRSFHadTau: %g EleRNNSFElectron: %g",
331 sSystematicSet.name().c_str(),
332 acc_TauSFRecoHadTau(*xTau),
333 acc_TauSFJetIDHadTau(*xTau),
334 acc_TauSFEleIDHadTau(*xTau),
335 acc_TauSFEleIDEle(*xTau));
336 }
337
338 for (auto sSystematicSet: vEfficiencyCorrectionsTriggerSystematicSet)
339 {
340 CHECK( TauEffTrigTool.applySystematicVariation(sSystematicSet));
341 CHECK( TauEffTrigTool.applyEfficiencyScaleFactor(*xTau) );
342 Info(
"TauAnalysisToolsExample",
343 "SystType %s: Trigger: %g",
344 sSystematicSet.name().c_str(),
345 acc_TauSFTrigHadTau(*xTau));
346 }
347
348 Info(
"TauAnalysisToolsExample",
"Selected tau: pt = %g MeV, eta = %g, phi = %g, prong = %i, charge = %i",
349 xTau->pt(), xTau->eta(), xTau->phi(), int(xTau->nTracks()), int(xTau->charge()));
350 }
351 if (xTauJetContainer->
empty())
352 CHECK (T2MT.retrieveTruthTaus());
353 xEvent.fill();
354 }
355
357 delete TauSelTool;
358 CHECK( xEvent.finishWritingTo(fOutputFile.get()));
359 fOutputFile.get()->Close();
360 Info(
"TauAnalysisToolsExample",
"Finished writing to file: %s", sOutputFileName.Data() );
361
362
364
365 return 0;
366}
Class to wrap a set of SystematicVariations.
bool empty() const noexcept
Returns true if the collection is empty.
Helper class to provide constant type-safe access to aux data.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
ReadStats & stats()
Access the object belonging to the current thread.
static IOStats & instance()
Singleton object accessor.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kAthenaAccess
Access containers/objects like Athena does.
Error
The different types of error that can be flagged in the L1TopoRDO.
Jet_v1 Jet
Definition of the current "jet version".
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
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.
setBGCode setTAP setLVL2ErrorBits bool
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.