44 #define CHECK( ARG ) \
46 const bool result = ARG; \
48 ::Error( "TauAnalysisToolsExample", "Failed to execute: \"%s\"", \
54 #define RETRIEVE( TYPE, CONTAINER , NAME ) \
56 if (xEvent.contains<TYPE>(NAME)) \
57 CHECK( xEvent.retrieve( CONTAINER, NAME ) ); \
59 Warning("TauAnalysisToolsExample","%s container is not available", NAME); \
64 StatusCode::enableFailure();
69 Error(
"TauAnalysisToolsExample",
"No file name received!" );
70 Error(
"TauAnalysisToolsExample",
" Usage: %s [xAOD file name]",
"TauAnalysisToolsExample" );
78 const TString sInputFileName =
argv[ 1 ];
79 Info(
"TauAnalysisToolsExample",
"Opening input file: %s", sInputFileName.Data() );
80 std::unique_ptr< TFile > fInputFile( TFile::Open( sInputFileName,
"READ" ) );
81 CHECK( fInputFile.get() );
84 TString sOutputFileName =
"output.root";
86 sOutputFileName = TString(
argv[3]);
91 Info(
"TauAnalysisToolsExample",
"Opening output file: %s", sOutputFileName.Data() );
92 std::unique_ptr< TFile > fOutputFile( TFile::Open( sOutputFileName,
"RECREATE" ) );
93 CHECK( fOutputFile.get() );
103 Info(
"TauAnalysisToolsExample",
"Number of events in the file: %i",
110 const Long64_t iMaxEntries = atoll(
argv[ 2 ] );
111 if( iMaxEntries < iEntries )
113 iEntries = iMaxEntries;
123 std::vector<std::string> vLumiCalcFiles = {
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data15_13TeV/20200803/ilumicalc_histograms_None_282026-282457_OflLumi-13TeV-009.root",
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data16_13TeV/20190708/ilumicalc_histograms_None_297730-311481_OflLumi-13TeV-010.root",
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data18_13TeV/20190318/ilumicalc_histograms_None_348885-364292_OflLumi-13TeV-010.root",
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data22_13p6TeV/20221025/ilumicalc_histograms_None_428648-436169_OflLumi-Run3-001.root",
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/data22_13p6TeV/20221025/ilumicalc_histograms_None_430536-436169_OflLumi-Run3-001.root",
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/20190609/ilumicalc_histograms_None_276262-284484_OflLumi-13TeV-010.root",
"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/GoodRunsLists/20190609/ilumicalc_histograms_None_325713-340453_OflLumi-13TeV-010.root"};
124 CHECK(m_tPRWTool->setProperty(
"LumiCalcFiles", vLumiCalcFiles));
128 ToolHandle<CP::IPileupReweightingTool> m_tPRWToolHandle = m_tPRWTool;
136 CHECK(TauSelTool->setProperty(
"CreateControlPlots",
true ));
139 CHECK(TauSelTool->setProperty(
"EleIDVersion", 1 ));
140 CHECK(TauSelTool->setProperty(
"PtMin", 20. ));
141 CHECK(TauSelTool->setProperty(
"ConfigPath",
"" ));
145 ToolHandle<TauAnalysisTools::ITauSelectionTool> TauSelToolHandle = TauSelTool;
152 CHECK(TauSmeTool.setProperty(
"RecommendationTag",
"2022-prerec"));
153 CHECK(TauSmeTool.setProperty(
"Campaign",
"mc21"));
157 std::vector<CP::SystematicSet> vSmearingSystematicSet;
161 vSmearingSystematicSet.back().insert(SystematicsVariation);
171 CHECK(TauEffCorrTool.setProperty(
"RecommendationTag",
"2022-prerec"));
175 std::vector<CP::SystematicSet> vEfficiencyCorrectionsSystematicSet;
180 vEfficiencyCorrectionsSystematicSet.back().insert(SystematicsVariation);
188 std::vector<CP::SystematicSet> vEfficiencyCorrectionsTriggerSystematicSet;
192 CHECK(TauEffTrigTool.setProperty(
"EfficiencyCorrectionTypes", std::vector<int>({SFTriggerHadTau}) ));
193 CHECK(TauEffTrigTool.setProperty(
"TriggerName",
"HLT_tau25_medium1_tracktwo" ));
195 CHECK(TauEffTrigTool.setProperty(
"PileupReweightingTool", m_tPRWToolHandle ));
196 CHECK(TauEffTrigTool.setProperty(
"TriggerSFMeasurement",
"combined"));
203 vEfficiencyCorrectionsTriggerSystematicSet.back().insert(SystematicsVariation);
210 T2MT.
msg().setLevel( MSG::INFO );
211 CHECK(T2MT.setProperty(
"TruthJetContainerName",
"AntiKt4TruthDressedWZJets"));
225 for( Long64_t iEntry = 0; iEntry < iEntries; ++iEntry )
229 const char * m_tauJetContainerName =
"TauJets";
239 Info(
"TauAnalysisToolsExample",
240 "===>>> start processing event #%i, "
241 "run #%i %i events processed so far <<<===",
243 static_cast< int >( xEventInfo->
runNumber() ),
244 static_cast< int >( iEntry ) );
249 m_tauJetContainerName =
"AnalysisTauJets";
252 std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* >xTauShallowContainer =
xAOD::shallowCopyContainer(*xTauJetContainer);
254 Info(
"TauAnalysisToolsExample:: TauJetContainer = ",m_tauJetContainerName);
262 CHECK( xEvent.
copy(m_tauJetContainerName) );
265 CHECK( xEvent.
copy(
"InDetTrackParticles") );
268 for (
auto xTau : *xTauShallowContainer.first )
271 auto xTruthTau = T2MT.
getTruth(*xTau);
274 if ((
bool)acc_IsTruthMatched(*xTau))
276 if (xTruthTau->isTau())
278 if ((
bool)acc_IsHadronicTau(*xTruthTau))
279 Info(
"TauAnalysisToolsExample",
280 "Tau was matched to a truth hadronic tau, which has %i prongs and a charge of %i",
281 int(acc_numCharged(*xTruthTau)),
282 int(xTruthTau->charge()));
284 Info(
"TauAnalysisToolsExample",
285 "Tau was matched to a truth leptonic tau, which has a charge of %i",
286 int(xTruthTau->charge()));
288 else if (xTruthTau->isElectron())
289 Info(
"TauAnalysisToolsExample",
290 "Tau was matched to a truth electron");
291 else if (xTruthTau->isMuon())
292 Info(
"TauAnalysisToolsExample",
293 "Tau was matched to a truth muon");
296 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth" );
298 auto xTruthJetLink = acc_truthJetLink(*xTau);
299 if (xTruthJetLink.isValid())
301 const xAOD::Jet* xTruthJet = *xTruthJetLink;
302 Info(
"TauAnalysisToolsExample",
303 "Tau was matched to a truth jet, which has pt=%g, eta=%g, phi=%g, m=%g",
304 xTruthJet->
p4().Pt(),
305 xTruthJet->
p4().Eta(),
306 xTruthJet->
p4().Phi(),
307 xTruthJet->
p4().M());
310 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth jet" );
312 Info(
"TauAnalysisToolsExample",
313 "Un-Smeared tau pt: %g ",
314 xTau->ptFinalCalib());
316 Info(
"TauAnalysisToolsExample",
317 "Smeared tau pt: %g ",
320 for (
auto sSystematicSet: vSmearingSystematicSet)
325 if ((
bool)acc_IsTruthMatched(*xTau) && xTruthTau->isTau() && (
bool)acc_IsHadronicTau(*xTruthTau)){
326 Info(
"TauAnalysisToolsExample",
327 "Smeared tau pt: %g for type %s ",
329 sSystematicSet.name().c_str());
334 if( ! TauSelTool->
accept( *xTau ) ){
335 Info(
"TauAnalysisToolsExample",
336 "Tau does not pass selection tool: pt %g ",
341 for (
auto sSystematicSet: vEfficiencyCorrectionsSystematicSet)
345 Info(
"TauAnalysisToolsExample",
346 "SystType %s: RecoSF: %g JetIDSF: %g EleOLRSFHadTau: %g EleRNNSFElectron: %g",
347 sSystematicSet.name().c_str(),
348 acc_TauSFRecoHadTau(*xTau),
349 acc_TauSFJetIDHadTau(*xTau),
350 acc_TauSFEleIDHadTau(*xTau),
351 acc_TauSFEleIDEle(*xTau));
354 for (
auto sSystematicSet: vEfficiencyCorrectionsTriggerSystematicSet)
358 Info(
"TauAnalysisToolsExample",
359 "SystType %s: Trigger: %g",
360 sSystematicSet.name().c_str(),
361 acc_TauSFTrigHadTau(*xTau));
364 Info(
"TauAnalysisToolsExample",
"Selected tau: pt = %g MeV, eta = %g, phi = %g, prong = %i, charge = %i",
365 xTau->pt(), xTau->eta(), xTau->phi(),
int(xTau->nTracks()),
int(xTau->charge()));
367 if (xTauJetContainer->
empty())
375 fOutputFile.get()->Close();
376 Info(
"TauAnalysisToolsExample",
"Finished writing to file: %s", sOutputFileName.Data() );