ATLAS Offline Software
Functions
test_SmoothedWZTagger.cxx File Reference
#include <string>
#include <TFile.h>
#include <TString.h>
#include <TTree.h>
#include <TChain.h>
#include "AsgTools/StandaloneToolHandle.h"
#include "xAODCore/ShallowAuxContainer.h"
#include "xAODCore/ShallowCopy.h"
#include "xAODCore/tools/IOStats.h"
#include "BoostedJetTaggers/SmoothedWZTagger.h"
#include "JetUncertainties/JetUncertaintiesTool.h"
#include "AsgMessaging/MessageCheck.h"

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 37 of file test_SmoothedWZTagger.cxx.

37  {
38 
39  ANA_CHECK_SET_TYPE (int); // makes ANA_CHECK return ints if exiting function
40 
41  // The application's name:
42  char* APP_NAME = argv[ 0 ];
43 
44  // arguments
45  TString fileName = "/eos/atlas/atlascerngroupdisk/perf-jets/ReferenceFiles/DAOD_JETM2.Wprime.pool.root";
46  int ievent=-1;
47  int nevents=-1;
48  bool isMC=true;
49  bool verbose=false;
50  bool runSystematics=true;
51 
52 
53  Info( APP_NAME, "==============================================" );
54  Info( APP_NAME, "Usage: $> %s [xAOD file name]", APP_NAME );
55  Info( APP_NAME, " $> %s | Run on default file", APP_NAME );
56  Info( APP_NAME, " $> %s -f X | Run on xAOD file X", APP_NAME );
57  Info( APP_NAME, " $> %s -n X | X = number of events you want to run on", APP_NAME );
58  Info( APP_NAME, " $> %s -e X | X = specific number of the event to run on - for debugging", APP_NAME );
59  Info( APP_NAME, " $> %s -d X | X = dataset ID", APP_NAME );
60  Info( APP_NAME, " $> %s -m X | X = isMC", APP_NAME );
61  Info( APP_NAME, " $> %s -noSys | Run without systematics", APP_NAME );
62  Info( APP_NAME, " $> %s -v | run in verbose mode ", APP_NAME );
63  Info( APP_NAME, "==============================================" );
64 
65  // Check if we received a file name:
66  if( argc < 2 ) {
67  Info( APP_NAME, "No arguments - using default file" );
68  Info( APP_NAME, "Executing on : %s", fileName.Data() );
69  }
70 
72  //::: parse the options
74  std::string options;
75  for( int i=0; i<argc; i++){
76  options+=(argv[i]);
77  }
78 
79  if(options.find("-f")!=std::string::npos){
80  for( int ipos=0; ipos<argc ; ipos++ ) {
81  if(std::string(argv[ipos]).compare("-f")==0){
82  if( ipos+1 == argc || std::string(argv[ipos+1])[0]=='-' ) {
83  Error( APP_NAME, "Please add the file name after -f argument" );
84  return 1;
85  }
86  fileName = argv[ipos+1];
87  Info( APP_NAME, "Argument (-f) : Running on file # %s", fileName.Data() );
88  break;
89  }
90  }
91  }
92 
93  if(options.find("-event")!=std::string::npos){
94  for( int ipos=0; ipos<argc ; ipos++ ) {
95  if(std::string(argv[ipos]).compare("-event")==0){
96  if( ipos+1 == argc || std::string(argv[ipos+1])[0]=='-' ) {
97  Error( APP_NAME, "Please add the event# after -event argument" );
98  return 1;
99  }
100  ievent = atoi(argv[ipos+1]);
101  Info( APP_NAME, "Argument (-event) : Running only on event # %i", ievent );
102  break;
103  }
104  }
105  }
106 
107  if(options.find("-m")!=std::string::npos){
108  for( int ipos=0; ipos<argc ; ipos++ ) {
109  if(std::string(argv[ipos]).compare("-m")==0){
110  if( ipos+1 == argc || std::string(argv[ipos+1])[0]=='-' ) {
111  Error( APP_NAME, "Please add 0 or 1 after -m (IsMC) argument" );
112  return 1;
113  }
114  isMC = atoi(argv[ipos+1]);
115  Info( APP_NAME, "Argument (-m) : IsMC = %i", isMC );
116  break;
117  }
118  }
119  }
120 
121  if(options.find("-n")!=std::string::npos){
122  for( int ipos=0; ipos<argc ; ipos++ ) {
123  if(std::string(argv[ipos]).compare("-n")==0){
124  if( ipos+1 == argc || std::string(argv[ipos+1])[0]=='-' ) {
125  Error( APP_NAME, "Please add NEvents after -n argument" );
126  return 1;
127  }
128  nevents = atoi(argv[ipos+1]);
129  Info( APP_NAME, "Argument (-n) : Running on NEvents = %i", nevents );
130  break;
131  }
132  }
133  }
134 
135  if(options.find("-noSys")!=std::string::npos){
136  runSystematics=false;
137  Info( APP_NAME, "Argument (-noSys) : Setting runSystematics");
138  }
139 
140  if(options.find("-v")!=std::string::npos){
141  verbose=true;
142  Info( APP_NAME, "Argument (-v) : Setting verbose");
143  }
144 
145 
147  //::: initialize the application and get the event
150  StatusCode::enableFailure();
151 
152  // Open the input file:
153  TFile* ifile( TFile::Open( fileName, "READ" ) );
154  if( !ifile ) Error( APP_NAME, "Cannot find file %s",fileName.Data() );
155 
156  TChain *chain = new TChain ("CollectionTree","CollectionTree");
157  chain->Add(fileName);
158 
159  // Create a TEvent object:
161  Info( APP_NAME, "Number of events in the file: %i", static_cast< int >( event.getEntries() ) );
162 
163  // Create a transient object store. Needed for the tools.
165 
166  // Decide how many events to run over:
167  Long64_t entries = event.getEntries();
168 
169  // Fill a validation true with the tag return value
170  std::unique_ptr<TFile> outputFile(TFile::Open("output_SmoothedWZTagger.root", "recreate"));
171  int pass,truthLabel,ntrk;
172  float sf,pt,eta,m,eff,effSF,sigeffSF;
173  TTree* Tree = new TTree( "tree", "test_tree" );
174  Tree->Branch( "pass", &pass, "pass/I" );
175  Tree->Branch( "sf", &sf, "sf/F" );
176  Tree->Branch( "pt", &pt, "pt/F" );
177  Tree->Branch( "m", &m, "m/F" );
178  Tree->Branch( "eta", &eta, "eta/F" );
179  Tree->Branch( "ntrk", &ntrk, "ntrk/I" );
180  Tree->Branch( "eff", &eff, "eff/F" );
181  Tree->Branch( "effSF", &effSF, "effSF/F" );
182  Tree->Branch( "sigeffSF", &sigeffSF, "sigeffSF/F" );
183  Tree->Branch( "truthLabel", &truthLabel, "truthLabel/I" );
184 
185  std::unique_ptr<JetUncertaintiesTool> jetUncToolSF(new JetUncertaintiesTool(("JetUncProvider_SF")));
186  std::vector<CP::SystematicSet> jetUnc_sysSets;
187 
188  if(runSystematics){
189  ANA_CHECK( jetUncToolSF->setProperty("JetDefinition", "AntiKt10LCTopoTrimmedPtFrac5SmallR20") );
190  ANA_CHECK( jetUncToolSF->setProperty("ConfigFile", "rel21/Fall2020/R10_SF_LCTopo_WTag_SigEff50.config") );
191  ANA_CHECK( jetUncToolSF->setProperty("MCType", "MC16") );
192  ANA_CHECK( jetUncToolSF->initialize() );
193 
194  std::vector<std::string> pulls = {"__1down", "__1up"};
195  CP::SystematicSet jetUnc_sysSet = jetUncToolSF->recommendedSystematics();
196  const std::set<std::string> sysNames = jetUnc_sysSet.getBaseNames();
197  for (const std::string & sysName: sysNames) {
198  for (const std::string & pull : pulls) {
199  std::string sysPulled = sysName + pull;
200  jetUnc_sysSets.push_back(CP::SystematicSet(sysPulled));
201  }
202  }
203  }
204 
208 
210  //::: Tool setup
211  // setup the tool handle as per the
212  // recommendation by ASG - https://twiki.cern.ch/twiki/bin/view/AtlasProtected/AthAnalysisBase#How_to_use_AnaToolHandle
214  std::cout<<"Initializing WZ Tagger"<<std::endl;
216  m_Tagger.setTypeAndName("SmoothedWZTagger/MyTagger");
217  if(verbose) ANA_CHECK( m_Tagger.setProperty("OutputLevel", MSG::DEBUG) );
218  ANA_CHECK( m_Tagger.setProperty( "CalibArea", "SmoothedWZTaggers/Rel21/February2022/") );
219  ANA_CHECK( m_Tagger.setProperty( "ConfigFile", "SmoothedContainedWTagger_AntiKt10UFOCSSKSoftDrop_FixedSignalEfficiency50_20220221.dat") );
220  ANA_CHECK( m_Tagger.setProperty( "IsMC", isMC ) );
221  ANA_CHECK( m_Tagger.retrieve() );
222 
224  // Loop over the events
226  for( Long64_t entry = 0; entry < entries; ++entry ) {
227 
228  if( nevents!=-1 && entry > nevents ) break;
229  // Tell the object which entry to look at:
230  event.getEntry( entry );
231 
232  // Print some event information
233  const xAOD::EventInfo* evtInfo = 0;
234  if(event.retrieve( evtInfo, "EventInfo" ) != StatusCode::SUCCESS){
235  continue;
236  }
237  if(ievent!=-1 && static_cast <int> (evtInfo->eventNumber())!=ievent) {
238  continue;
239  }
240 
241  // Get the jets
242  const xAOD::JetContainer* myJets = 0;
243  if( event.retrieve( myJets, "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets" ) != StatusCode::SUCCESS)
244  continue ;
245 
246  // Loop over jet container
247  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > jets_shallowCopy = xAOD::shallowCopyContainer( *myJets );
248  std::unique_ptr<xAOD::JetContainer> shallowJets(jets_shallowCopy.first);
249  std::unique_ptr<xAOD::ShallowAuxContainer> shallowAux(jets_shallowCopy.second);
250  for( xAOD::Jet* jetSC : *shallowJets ){
251 
252  ANA_CHECK( m_Tagger->tag( *jetSC ) );
253  if(verbose) {
254  std::cout << "Testing W Tagger " << std::endl;
255  std::cout << "jet pt = " << jetSC->pt() << std::endl;
256  std::cout << "jet ntrk = " << jetSC->auxdata<int>("ParentJetNTrkPt500") << std::endl;
257  std::cout << "RunningTag : " << jetSC->auxdata<bool>("SmoothWContained50_Tagged") << std::endl;
258  std::cout << "result d2pass = " << jetSC->auxdata<bool>("SmoothWContained50_PassD2") << std::endl;
259  std::cout << "result ntrkpass = " << jetSC->auxdata<bool>("SmoothWContained50_PassNtrk") << std::endl;
260  std::cout << "result masspass = " << jetSC->auxdata<bool>("SmoothWContained50_PassMass") << std::endl;
261  }
262  truthLabel = jetSC->auxdata<int>("R10TruthLabel_R21Precision_2022v1");
263 
264  pass = jetSC->auxdata<bool>("SmoothWContained50_Tagged");
265  pt = jetSC->pt();
266  m = jetSC->m();
267  eta = jetSC->eta();
268  ntrk = jetSC->auxdata<int>("ParentJetNTrkPt500");
269  sf = jetSC->auxdata<float>("SmoothWContained50_SF");
270  eff = jetSC->auxdata<float>("SmoothWContained50_efficiency");
271  effSF = jetSC->auxdata<float>("SmoothWContained50_effSF");
272  sigeffSF = jetSC->auxdata<float>("SmoothWContained50_sigeffSF");
273  std::cout << "pass " << pass
274  << " truthLabel " << truthLabel
275  << " sf " << sf
276  << " pt " << pt*0.001
277  << " eta " << eta
278  << " m " << m*0.001
279  << " eff " << eff
280  << " effSF " << effSF
281  << " sigeffSF " << sigeffSF
282  << std::endl;
283 
284  Tree->Fill();
285 
286  if(runSystematics){
287  if ( isMC ){
288  if ( pt/1.e3 > 150 && std::abs(jetSC->eta()) < 2.0 ) {
289  bool validForUncTool = ( pt/1.e3 >= 150 && pt/1.e3 < 2500 && m > 40000. && m < 700000.);
290  validForUncTool &= ( m/pt >= 0 && m/pt <= 1 );
291  validForUncTool &= ( std::abs(eta) < 2 );
292  std::cout << "Pass: " << pass << std::endl;
293  std::cout << "Nominal SF=" << sf << " truthLabel=" << truthLabel << " (1: t->qqb) "
294  << effSF << " " << eff << " " << pass << std::endl;
295  if( validForUncTool ){
296  for ( const CP::SystematicSet& sysSet : jetUnc_sysSets ){
297  ANA_CHECK( m_Tagger->tag( *jetSC ) );
298  ANA_CHECK( jetUncToolSF->applySystematicVariation(sysSet) );
299  ANA_CHECK( jetUncToolSF->applyCorrection(*jetSC) );
300  std::cout << sysSet.name() << " " << jetSC->auxdata<float>("SmoothWContained50_SF") << std::endl;
301  }
302  }
303  }
304  }
305  }
306  }
307 
308  Info( APP_NAME, "===>>> done processing event #%i, run #%i %i events processed so far <<<===", static_cast< int >( evtInfo->eventNumber() ), static_cast< int >( evtInfo->runNumber() ), static_cast< int >( entry + 1 ) );
309  }
310 
314 
315  // write the tree to the output file
316  outputFile->cd();
317  Tree->Write();
318  outputFile->Close();
319 
320  // cleanup
321  delete chain;
322 
323  // print the branches that were used for help with smart slimming
324  std::cout<<std::endl<<std::endl;
325  std::cout<<"Smart Slimming Checker :"<<std::endl;
327  std::cout<<std::endl<<std::endl;
328 
329  return 0;
330 
331 }
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
CaloCondBlobAlgs_fillNoiseFromASCII.sysName
sysName
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:93
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
Amg::compare
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
Definition: EventPrimitivesHelpers.h:109
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
Tree
Definition: Tree.h:18
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
test_pyathena.pt
pt
Definition: test_pyathena.py:11
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
compareGeometries.outputFile
string outputFile
Definition: compareGeometries.py:25
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition: StandaloneToolHandle.h:105
lumiFormat.i
int i
Definition: lumiFormat.py:92
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
JetUncertaintiesTool
Definition: JetUncertaintiesTool.h:44
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
python.StandardJetMods.pull
pull
Definition: StandardJetMods.py:264
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
CP::SystematicSet::getBaseNames
std::set< std::string > getBaseNames() const
description: get the set of base systematic names from this set
Definition: SystematicSet.cxx:159
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
asg::StandaloneToolHandle::retrieve
StatusCode retrieve()
initialize the tool, will succeed if the tool was already initialized
Definition: StandaloneToolHandle.h:147
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
SmoothedWZTagger::tag
virtual StatusCode tag(const xAOD::Jet &jet) const override
Decorate single jet with tagging info.
Definition: SmoothedWZTagger.cxx:177
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
asg::StandaloneToolHandle::setTypeAndName
void setTypeAndName(const std::string &typeAndName)
Definition: StandaloneToolHandle.h:101
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
DEBUG
#define DEBUG
Definition: page_access.h:11
entries
double entries
Definition: listroot.cxx:49
EventInfoRead.isMC
isMC
Definition: EventInfoRead.py:11
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
LArG4GenerateShowerLib.nevents
nevents
Definition: LArG4GenerateShowerLib.py:19
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31