45 #define CHECK( ARG ) \
47 const bool result = ARG; \
49 ::Error( "TauAnalysisToolsExample", "Failed to execute: \"%s\"", \
55 #define RETRIEVE( TYPE, CONTAINER , NAME ) \
57 if (xEvent.contains<TYPE>(NAME)) \
58 CHECK( xEvent.retrieve( CONTAINER, NAME ) ); \
60 Warning("TauAnalysisToolsExample","%s container is not available", NAME); \
65 StatusCode::enableFailure();
70 Error(
"TauAnalysisToolsExample",
"No file name received!" );
71 Error(
"TauAnalysisToolsExample",
" Usage: %s [xAOD file name]",
"TauAnalysisToolsExample" );
79 const TString sInputFileName =
argv[ 1 ];
80 Info(
"TauAnalysisToolsExample",
"Opening input file: %s", sInputFileName.Data() );
81 std::unique_ptr< TFile > fInputFile( TFile::Open( sInputFileName,
"READ" ) );
82 CHECK( fInputFile.get() );
85 TString sOutputFileName =
"output.root";
87 sOutputFileName = TString(
argv[3]);
92 Info(
"TauAnalysisToolsExample",
"Opening output file: %s", sOutputFileName.Data() );
93 std::unique_ptr< TFile > fOutputFile( TFile::Open( sOutputFileName,
"RECREATE" ) );
94 CHECK( fOutputFile.get() );
104 Info(
"TauAnalysisToolsExample",
"Number of events in the file: %i",
111 const Long64_t iMaxEntries = atoll(
argv[ 2 ] );
112 if( iMaxEntries < iEntries )
114 iEntries = iMaxEntries;
124 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"};
125 CHECK(m_tPRWTool->setProperty(
"LumiCalcFiles", vLumiCalcFiles));
129 ToolHandle<CP::IPileupReweightingTool> m_tPRWToolHandle = m_tPRWTool;
137 CHECK(TauSelTool->setProperty(
"CreateControlPlots",
true ));
140 CHECK(TauSelTool->setProperty(
"EleIDVersion", 1 ));
141 CHECK(TauSelTool->setProperty(
"PtMin", 20. ));
142 CHECK(TauSelTool->setProperty(
"ConfigPath",
"" ));
146 ToolHandle<TauAnalysisTools::ITauSelectionTool> TauSelToolHandle = TauSelTool;
153 CHECK(TauSmeTool.setProperty(
"RecommendationTag",
"2022-prerec"));
154 CHECK(TauSmeTool.setProperty(
"Campaign",
"mc21"));
158 std::vector<CP::SystematicSet> vSmearingSystematicSet;
162 vSmearingSystematicSet.back().insert(SystematicsVariation);
170 CHECK(TauEffCorrTool.setProperty(
"TauSelectionTool",TauSelToolHandle));
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"));
218 T3MT.
msg().setLevel( MSG::INFO );
222 for( Long64_t iEntry = 0; iEntry < iEntries; ++iEntry )
226 const char * m_tauJetContainerName =
"TauJets";
236 Info(
"TauAnalysisToolsExample",
237 "===>>> start processing event #%i, "
238 "run #%i %i events processed so far <<<===",
240 static_cast< int >( xEventInfo->
runNumber() ),
241 static_cast< int >( iEntry ) );
246 m_tauJetContainerName =
"AnalysisTauJets";
249 std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* >xTauShallowContainer =
xAOD::shallowCopyContainer(*xTauJetContainer);
251 Info(
"TauAnalysisToolsExample:: TauJetContainer = ",m_tauJetContainerName);
259 CHECK( xEvent.
copy(m_tauJetContainerName) );
262 CHECK( xEvent.
copy(
"InDetTrackParticles") );
265 for (
auto xTau : *xTauShallowContainer.first )
268 auto xTruthTau = T2MT.
getTruth(*xTau);
271 if ((
bool)xTau->auxdata<
char>(
"IsTruthMatched"))
273 if (xTruthTau->isTau())
275 if ((
bool)xTruthTau->auxdata<
char>(
"IsHadronicTau"))
276 Info(
"TauAnalysisToolsExample",
277 "Tau was matched to a truth hadronic tau, which has %i prongs and a charge of %i",
278 int(xTruthTau->auxdata<
size_t>(
"numCharged")),
279 int(xTruthTau->charge()));
281 Info(
"TauAnalysisToolsExample",
282 "Tau was matched to a truth leptonic tau, which has a charge of %i",
283 int(xTruthTau->charge()));
285 else if (xTruthTau->isElectron())
286 Info(
"TauAnalysisToolsExample",
287 "Tau was matched to a truth electron");
288 else if (xTruthTau->isMuon())
289 Info(
"TauAnalysisToolsExample",
290 "Tau was matched to a truth muon");
293 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth" );
296 if (xTruthJetLink.isValid())
298 const xAOD::Jet* xTruthJet = *xTruthJetLink;
299 Info(
"TauAnalysisToolsExample",
300 "Tau was matched to a truth jet, which has pt=%g, eta=%g, phi=%g, m=%g",
301 xTruthJet->
p4().Pt(),
302 xTruthJet->
p4().Eta(),
303 xTruthJet->
p4().Phi(),
304 xTruthJet->
p4().M());
307 Info(
"TauAnalysisToolsExample",
"Tau was not matched to truth jet" );
309 Info(
"TauAnalysisToolsExample",
310 "Un-Smeared tau pt: %g ",
311 xTau->ptFinalCalib());
313 Info(
"TauAnalysisToolsExample",
314 "Smeared tau pt: %g ",
317 for (
auto sSystematicSet: vSmearingSystematicSet)
322 if ((
bool)xTau->auxdata<
char>(
"IsTruthMatched") && xTruthTau->isTau() && (
bool)xTruthTau->auxdata<
char>(
"IsHadronicTau")){
323 Info(
"TauAnalysisToolsExample",
324 "Smeared tau pt: %g for type %s ",
326 sSystematicSet.name().c_str());
331 if( ! TauSelTool->
accept( *xTau ) ){
332 Info(
"TauAnalysisToolsExample",
333 "Tau does not pass selection tool: pt %g ",
338 for (
auto sSystematicSet: vEfficiencyCorrectionsSystematicSet)
342 Info(
"TauAnalysisToolsExample",
343 "SystType %s: RecoSF: %g JetIDSF: %g EleOLRSFHadTau: %g EleRNNSFElectron: %g",
344 sSystematicSet.name().c_str(),
345 xTau->auxdata<
double >(
"TauScaleFactorReconstructionHadTau" ),
346 xTau->auxdata<
double >(
"TauScaleFactorJetIDHadTau" ),
347 xTau->auxdata<
double >(
"TauScaleFactorEleIDHadTau" ),
348 xTau->auxdata<
double >(
"TauScaleFactorEleIDElectron" ));
351 for (
auto sSystematicSet: vEfficiencyCorrectionsTriggerSystematicSet)
355 Info(
"TauAnalysisToolsExample",
356 "SystType %s: Trigger: %g",
357 sSystematicSet.name().c_str(),
358 xTau->auxdata<
double >(
"TauScaleFactorTriggerHadTau" ));
361 Info(
"TauAnalysisToolsExample",
"Selected tau: pt = %g MeV, eta = %g, phi = %g, prong = %i, charge = %i",
362 xTau->pt(), xTau->eta(), xTau->phi(),
int(xTau->nTracks()),
int(xTau->charge()));
378 if (xTauJetContainer->
empty())
386 fOutputFile.get()->Close();
387 Info(
"TauAnalysisToolsExample",
"Finished writing to file: %s", sOutputFileName.Data() );