62 StatusCode::enableFailure();
67 Error(
"TauAnalysisToolsExample",
"No file name received!" );
68 Error(
"TauAnalysisToolsExample",
" Usage: %s [xAOD file name]",
"TauAnalysisToolsExample" );
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() );
82 TString sOutputFileName =
"output.root";
84 sOutputFileName = TString(
argv[3]);
89 Info(
"TauAnalysisToolsExample",
"Opening output file: %s", sOutputFileName.Data() );
90 std::unique_ptr< TFile > fOutputFile( TFile::Open( sOutputFileName,
"RECREATE" ) );
91 CHECK( fOutputFile.get() );
96 CHECK( xEvent.readFrom( fInputFile.get() ) );
99 CHECK( xEvent.writeTo( fOutputFile.get() ) );
101 Info(
"TauAnalysisToolsExample",
"Number of events in the file: %i",
102 static_cast< int >( xEvent.getEntries() ) );
105 Long64_t iEntries = xEvent.getEntries();
108 const Long64_t iMaxEntries = atoll(
argv[ 2 ] );
109 if( iMaxEntries < iEntries )
111 iEntries = iMaxEntries;
126 CHECK(TauSelTool->setProperty(
"CreateControlPlots",
true ));
129 CHECK(TauSelTool->setProperty(
"EleIDVersion", 1 ));
130 CHECK(TauSelTool->setProperty(
"PtMin", 20. ));
131 CHECK(TauSelTool->setProperty(
"ConfigPath",
"" ));
140 CHECK(TauSmeTool.setProperty(
"RecommendationTag",
"2025-prerec"));
141 CHECK(TauSmeTool.setProperty(
"Campaign",
"mc23"));
142 CHECK(TauSmeTool.initialize());
145 std::vector<CP::SystematicSet> vSmearingSystematicSet;
146 for (
auto SystematicsVariation : TauSmeTool.recommendedSystematics())
149 vSmearingSystematicSet.back().insert(SystematicsVariation);
159 CHECK(TauEffCorrTool.setProperty(
"RecommendationTag",
"2025-prerec"));
160 CHECK(TauEffCorrTool.setProperty(
"Campaign",
"mc23"));
161 CHECK(TauEffCorrTool.initialize());
164 std::vector<CP::SystematicSet> vEfficiencyCorrectionsSystematicSet;
166 for (
auto SystematicsVariation : TauEffCorrTool.recommendedSystematics())
169 vEfficiencyCorrectionsSystematicSet.back().insert(SystematicsVariation);
177 std::vector<CP::SystematicSet> vEfficiencyCorrectionsTriggerSystematicSet;
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());
188 for (
auto SystematicsVariation : TauEffTrigTool.recommendedSystematics())
191 vEfficiencyCorrectionsTriggerSystematicSet.back().insert(SystematicsVariation);
199 CHECK(T2MT.setProperty(
"TruthJetContainerName",
"AntiKt4TruthDressedWZJets"));
200 CHECK(T2MT.initialize());
213 for( Long64_t iEntry = 0; iEntry < iEntries; ++iEntry )
216 xEvent.getEntry( iEntry );
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 ) );
230 const char * m_tauJetContainerName =
"TauJets";
234 m_tauJetContainerName =
"AnalysisTauJets";
237 std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* >xTauShallowContainer =
xAOD::shallowCopyContainer(*xTauJetContainer);
239 Info(
"TauAnalysisToolsExample:: TauJetContainer = ",m_tauJetContainerName);
244 CHECK( xEvent.copy(
"TruthParticles") );
247 CHECK( xEvent.copy(m_tauJetContainerName) );
250 CHECK( xEvent.copy(
"InDetTrackParticles") );
253 for (
auto xTau : *xTauShallowContainer.first )
256 auto xTruthTau = T2MT.getTruth(*xTau);
258 if (
static_cast<bool>(acc_IsTruthMatched(*xTau)))
260 if (xTruthTau->isTau())
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()));
268 Info(
"TauAnalysisToolsExample",
269 "Tau was matched to a truth leptonic tau, which has a charge of %i",
270 int(xTruthTau->charge()));
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");
280 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth" );
282 auto xTruthJetLink = acc_truthJetLink(*xTau);
283 if (xTruthJetLink.isValid())
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());
294 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth jet" );
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 ",
304 for (
auto sSystematicSet: vSmearingSystematicSet)
306 CHECK( TauSmeTool.applySystematicVariation(sSystematicSet)) ;
307 CHECK( TauSmeTool.applyCorrection(*xTau) );
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 ",
313 sSystematicSet.name().c_str());
318 if( ! TauSelTool->
accept( *xTau ) ){
319 Info(
"TauAnalysisToolsExample",
320 "Tau does not pass selection tool: pt %g ",
325 for (
auto sSystematicSet: vEfficiencyCorrectionsSystematicSet)
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));
338 for (
auto sSystematicSet: vEfficiencyCorrectionsTriggerSystematicSet)
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));
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()));
351 if (xTauJetContainer->
empty())
352 CHECK (T2MT.retrieveTruthTaus());
358 CHECK( xEvent.finishWritingTo(fOutputFile.get()));
359 fOutputFile.get()->Close();
360 Info(
"TauAnalysisToolsExample",
"Finished writing to file: %s", sOutputFileName.Data() );