ATLAS Offline Software
Functions
test_HLLHCSmoothedTopTagger.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/SmoothedTopTagger.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 36 of file test_HLLHCSmoothedTopTagger.cxx.

36  {
37 
38  ANA_CHECK_SET_TYPE (int); // makes ANA_CHECK return ints if exiting function
39 
40  // The application's name:
41  char* APP_NAME = argv[ 0 ];
42 
43  // arguments
44  TString fileName = "/eos/atlas/atlascerngroupdisk/perf-jets/ReferenceFiles/mc16_13TeV.361028.Pythia8EvtGen_A14NNPDF23LO_jetjet_JZ8W.deriv.DAOD_FTAG1.e3569_s3126_r9364_r9315_p3260/DAOD_FTAG1.12133096._000074.pool.root.1";
45  int ievent=-1;
46  int nevents=-1;
47  bool verbose=false;
48  bool useConfigFile = true; // use config file from CVMFS for tagger (alternately setup cut functions manually)
49 
50  Info( APP_NAME, "==============================================" );
51  Info( APP_NAME, "Usage: $> %s [xAOD file name]", APP_NAME );
52  Info( APP_NAME, " $> %s | Run on default file", APP_NAME );
53  Info( APP_NAME, " $> %s -f X | Run on xAOD file X", APP_NAME );
54  Info( APP_NAME, " $> %s -n X | X = number of events you want to run on", APP_NAME );
55  Info( APP_NAME, " $> %s -e X | X = specific number of the event to run on - for debugging", APP_NAME );
56  Info( APP_NAME, " $> %s -v | run in verbose mode ", APP_NAME );
57  Info( APP_NAME, " $> %s -wp | working point to test (either 50 or 80 [signal efficiency]) ", APP_NAME );
58  Info( APP_NAME, " $> %s -m | manually setup taggers using cut function and tagger mode properties", APP_NAME );
59  Info( APP_NAME, "==============================================" );
60 
61  // Check if we received a file name:
62  if( argc < 2 ) {
63  Info( APP_NAME, "No arguments - using default file" );
64  Info( APP_NAME, "Executing on : %s", fileName.Data() );
65  }
66 
68  //::: parse the options
70  std::string options;
71  for( int i=0; i<argc; i++){
72  options+=(argv[i]);
73  }
74 
75  if(options.find("-f")!=std::string::npos){
76  for( int ipos=0; ipos<argc ; ipos++ ) {
77  if(std::string(argv[ipos]).compare("-f")==0){
78  fileName = argv[ipos+1];
79  Info( APP_NAME, "Argument (-f) : Running on file # %s", fileName.Data() );
80  break;
81  }
82  }
83  }
84 
85  // check both -event and -e in case the argument is shortened as in the description
86  if(options.find("-event")!=std::string::npos || options.find("-e")!=std::string::npos) {
87  for( int ipos=0; ipos<argc ; ipos++ ) {
88  if(std::string(argv[ipos]).compare("-event")==0 || std::string(argv[ipos]).compare("-e")==0){
89  ievent = atoi(argv[ipos+1]);
90  Info( APP_NAME, "Argument (-event) : Running only on event # %i", ievent );
91  break;
92  }
93  }
94  }
95 
96  if(options.find("-n")!=std::string::npos){
97  for( int ipos=0; ipos<argc ; ipos++ ) {
98  if(std::string(argv[ipos]).compare("-n")==0){
99  nevents = atoi(argv[ipos+1]);
100  Info( APP_NAME, "Argument (-n) : Running on NEvents = %i", nevents );
101  break;
102  }
103  }
104  }
105 
106  if(options.find("-v")!=std::string::npos){
107  verbose=true;
108  Info( APP_NAME, "Argument (-v) : Setting verbose");
109  }
110 
111  if(options.find("-m")!=std::string::npos){
112  useConfigFile=false;
113  Info( APP_NAME, "Argument (-m) : Setting manual tagger setup");
114  }
115 
116  // default to 50% efficiency WP
117  std::string taggerEfficiency = "50";
118  // check if efficiency option is provided
119  if (options.find("-wp") != std::string::npos) {
120  for( int ipos=0; ipos<argc ; ipos++ ) {
121  if(std::string(argv[ipos]).compare("-wp")==0) {
122  if (std::string(argv[ipos+1]) == "50" || std::string(argv[ipos+1]) == "80") {
123  taggerEfficiency = argv[ipos+1];
124  if (taggerEfficiency == "50") {
125  Info( APP_NAME, "Argument (-wp) : Setting is 50pc signal efficiency");
126  } else if (taggerEfficiency == "80") {
127  Info( APP_NAME, "Argument (-wp) : Setting is 80pc signal efficiency");
128  }
129  } else {
130  Error( APP_NAME, "Argument (-wp) : Invalid value (should be 50 or 80), using default 50 value");
131  }
132  }
133  }
134  }
135 
136 
138  //::: initialize the application and get the event
141  StatusCode::enableFailure();
142 
143  // Open the input file:
144  TFile* ifile( TFile::Open( fileName, "READ" ) );
145  if( !ifile ) Error( APP_NAME, "Cannot find file %s",fileName.Data() );
146 
147  TChain *chain = new TChain ("CollectionTree","CollectionTree");
148  chain->Add(fileName);
149 
150  // Create a TEvent object:
152  Info( APP_NAME, "Number of events in the file: %i", static_cast< int >( event.getEntries() ) );
153 
154  // Create a transient object store. Needed for the tools.
156 
157  // Decide how many events to run over:
158  Long64_t entries = event.getEntries();
159 
160  // create ROOT filename with tagger efficiency
161  std::string ROOTFileName = "output_HLLHCSmoothedTopTaggers_" + taggerEfficiency + "SignalEff.root";
162 
163  // Fill a validation true with the tag return value
164  TFile* outputFile = TFile::Open( ROOTFileName.c_str(), "recreate" );
165  int pass, passMass, passSphericity, validJet, validKinRange;
166  float sphericityCut, massCut;
167  TTree* Tree = new TTree( "tree", "test_tree" );
168  Tree->Branch( "pass", &pass, "pass/I" );
169  Tree->Branch( "passMass", &passMass, "passMass/I" );
170  Tree->Branch( "passSphericity", &passSphericity, "passSphericity/I" );
171  Tree->Branch( "massCut", &massCut, "massCut/F" );
172  Tree->Branch( "sphericityCut", &sphericityCut, "sphericityCut/F" );
173  Tree->Branch( "validJetContent", &validJet, "validJetContent/I" );
174  Tree->Branch( "validKinRange", &validKinRange, "validKinRange/I" );
175 
176  // extra tree variables for jets
177  float jetPt, jetEta, jetPhi, jetM, jetE, jetSphericity;
178  Tree->Branch("jetEta", &jetEta, "jetEta/F");
179  Tree->Branch("jetPt", &jetPt, "jetPt/F");
180  Tree->Branch("jetPhi", &jetPhi, "jetPhi/F");
181  Tree->Branch("jetM", &jetM, "jetM/F");
182  Tree->Branch("jetE", &jetE, "jetE/F");
183  Tree->Branch("jetSphericity", &jetSphericity, "jetSphericity/F");
184 
188 
189  // flags used for tagger setup
190  bool useLocalCalibArea = true; // retrieve config files from local directory
191 
192  // variables to define different config related variables
193  std::string configFile, decorationName;
194 
195  // 50% efficiency setup
196  if (taggerEfficiency == "50") {
197  configFile = "HLLHCSmoothedContainedTopTagger_AntiKt10LCTopoTrimmed_MassSphericityFixedSignalEfficiency50_20220413.dat";
198  decorationName = "HLLHCSmoothedTop50MassSphericity";
199  }
200  // 80% efficiency setup
201  else if (taggerEfficiency == "80") {
202  configFile = "HLLHCSmoothedContainedTopTagger_AntiKt10LCTopoTrimmed_MassSphericityFixedSignalEfficiency80_20220413.dat";
203  decorationName = "HLLHCSmoothedTop80MassSphericity";
204  }
205 
207  //::: Tool setup
208  // setup the tool handle as per the
209  // recommendation by ASG - https://twiki.cern.ch/twiki/bin/view/AtlasProtected/AthAnalysisBase#How_to_use_AnaToolHandle
211 
212  /*
213  How to setup the HL-LHC tagger:
214 
215  Config file provided:
216  set ConfigFile to required config location + file
217  for local running set CalibArea to Local
218 
219  No config file (user specifying own selections):
220  for local running set CalibArea to Local
221  instead of providing ConfigFile containing information
222  provide:
223  TaggerMode = MassSphericity
224  Var1CutFunc = mass cut function (C++ string formatted with x to indicate where mass should be inserted)
225  Var2CutFunc = sphericity cut function (C++ string with same formatting as Var1CutFunc)
226 
227  */
228  std::string localConfigPath = "HLLHCSmoothedTopTaggers/";
229 
230  std::cout<<"Initializing HLLHC Top Tagger"<<std::endl;
232  m_Tagger.setTypeAndName("SmoothedTopTagger/MyTagger");
233  if(verbose) ANA_CHECK( m_Tagger.setProperty("OutputLevel", MSG::DEBUG) );
234  if (useLocalCalibArea) {ANA_CHECK( m_Tagger.setProperty("CalibArea", "Local") );}
235  else {ANA_CHECK( m_Tagger.setProperty("CalibArea", "SmoothedTopTaggers/HLLHC/July2022/") );}
236 
237  if (useConfigFile) {
238  if (!useLocalCalibArea) {
239  ANA_CHECK( m_Tagger.setProperty( "ConfigFile", configFile) );
240  } else {
241  ANA_CHECK( m_Tagger.setProperty( "ConfigFile", localConfigPath + configFile) )
242  }
243  }
244  else {
245  // use an empty CalibArea
246  ANA_CHECK( m_Tagger.setProperty("CalibArea", "") );
247  // working point dependent settings for tagger cuts
248  std::vector<std::string> variableNames = {"Mass", "Sphericity"};
249  std::vector<std::string> cutExpressions;
250  if (taggerEfficiency == "50") {
251  ANA_CHECK( m_Tagger.setProperty("Decoration", "HLLHCSmoothedTop50MassSphericity") );
252  cutExpressions.push_back("(x > 2250.0) ? 163.5 : (x < 575.0) ? 121.5 : (107.08208957157846) * pow(x, 0.0) + (0.025074626862387987) * pow(x, 1.0)");
253  cutExpressions.push_back("(x > 2250.0) ? 0.2665 : (x < 575.0) ? 0.2115 : (0.21589532367374106) * pow(x, 0.0) + (-4.630614969502935e-05) * pow(x, 1.0) + (7.982389622058105e-08) * pow(x, 2.0) + (-2.188773324349366e-11) * pow(x, 3.0)");
254  } else if (taggerEfficiency == "80") {
255  ANA_CHECK( m_Tagger.setProperty("Decoration", "HLLHCSmoothedTop80MassSphericity") );
256  cutExpressions.push_back("(x > 2250.0) ? 142.5 : (x < 575.0) ? 96.5 : (80.7089552147599) * pow(x, 0.0) + (0.027462686570187158) * pow(x, 1.0)");
257  cutExpressions.push_back("(x > 2250.0) ? 0.0965 : (x < 575.0) ? 0.0445 : (-0.015521973683231065) * pow(x, 0.0) + (0.0001160203413917445) * pow(x, 1.0) + (-1.7074246660926898e-08) * pow(x, 2.0) + (-5.494467663191552e-12) * pow(x, 3.0)");
258  } else {
259  Error( APP_NAME, "Invalid tagger efficiency working point" );
260  }
261 
262  ANA_CHECK( m_Tagger.setProperty("VarCutFuncs", cutExpressions) );
263  ANA_CHECK( m_Tagger.setProperty("VarCutNames", variableNames) );
264  }
265  ANA_CHECK( m_Tagger.retrieve() );
266 
268  // Loop over the events
270 
271  // setup the decoration names
272  std::string massDecor = decorationName + "_Cut_m";
273  std::string sphericityDecor = decorationName + "_Cut_Sphericity";
274 
275  std::string sphericityPassDecor = decorationName + "_PassSphericity";
276  std::string massPassDecor = decorationName + "_PassMass";
277 
278  std::string validJetDecor = decorationName + "_ValidJetContent";
279  std::string validKinRangeDecor = decorationName + "_ValidKinRange";
280 
281  for( Long64_t entry = 0; entry < entries; ++entry ) {
282 
283  if( nevents!=-1 && entry > nevents ) break;
284  // Tell the object which entry to look at:
285  event.getEntry( entry );
286 
287  // Print some event information
288  const xAOD::EventInfo* evtInfo = 0;
289  if(event.retrieve( evtInfo, "EventInfo" ) != StatusCode::SUCCESS){
290  continue;
291  }
292  if(ievent!=-1 && static_cast <int> (evtInfo->eventNumber())!=ievent) {
293  continue;
294  }
295 
296  // Get the jets
297  const xAOD::JetContainer* myJets = 0;
298  if( event.retrieve( myJets, "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets" ) != StatusCode::SUCCESS)
299  continue ;
300 
301  // Loop over jet container
302  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > jets_shallowCopy = xAOD::shallowCopyContainer( *myJets );
303  std::unique_ptr<xAOD::JetContainer> shallowJets(jets_shallowCopy.first);
304  std::unique_ptr<xAOD::ShallowAuxContainer> shallowAux(jets_shallowCopy.second);
305  for(const xAOD::Jet* jet : * shallowJets ){
306 
307  if(verbose) std::cout<<"Testing Top Tagger"<< std::endl;
308 
309  ANA_CHECK( m_Tagger->tag( *jet ) );
310 
311  // get tagger results and store in tree variables
312  // if (res) {pass = 1;} else {pass = 0;}
313  // pass = (res) ? 1 : 0; // tagger pass result (evaluates to true if all TAccept attributes are true)
314  passMass = jet->auxdecor<bool>(massPassDecor);
315  passSphericity = jet->auxdecor<bool>(sphericityPassDecor);
316  massCut = jet->auxdecor<float>(massDecor);
317  sphericityCut = jet->auxdecor<float>(sphericityDecor);
318  jetEta = jet->eta();
319  jetPhi = jet->phi();
320  // store jet E, m, pT in GeV
321  jetM = jet->m()*0.001;
322  jetE = jet->e()*0.001;
323  jetPt = jet->pt()*0.001;
324  validJet = jet->auxdata<bool>(validJetDecor);
325  validKinRange = jet->auxdata<bool>(validKinRangeDecor);
326  // ints implicitly converted to bool in this approach
327  pass = validJet && passMass && passSphericity && validKinRange;
328  if (!(jet->getAttribute("Sphericity",jetSphericity))) {
329  std::cout << "WARNING sphericity is not decorated on this jet!" << std::endl;
330  }
331 
332  if (verbose) {
333  std::cout<<"Total tagger result : "<<pass<<std::endl;
334  std::cout<<"Valid jet content = "<<validJet<<std::endl;
335  std::cout<<"result massPass = "<<passMass<<std::endl;
336  std::cout<<"result sphericityPass = "<<passSphericity<<std::endl;
337  std::cout<<"result massCut = "<<massCut<<std::endl;
338  std::cout<<"result sphericityCut = "<<sphericityCut<<std::endl;
339  std::cout << "Jet pT (GeV) = " << jetPt << ", eta = " << jetEta << " ; mass (GeV) = " << jetM << ", Sphericity = " << jetSphericity << std::endl;
340  }
341 
342  Tree->Fill();
343  }
344 
345  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 ) );
346  }
347 
351 
352  // write the tree to the output file
353  outputFile->cd();
354  Tree->Write();
355  outputFile->Close();
356 
357  // cleanup
358  delete chain;
359 
360  // print the branches that were used for help with smart slimming
361  std::cout<<std::endl<<std::endl;
362  std::cout<<"Smart Slimming Checker :"<<std::endl;
364  std::cout<<std::endl<<std::endl;
365 
366  return 0;
367 
368 }
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
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
taskman.configFile
configFile
Definition: taskman.py:311
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
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
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
SmoothedTopTagger::tag
virtual StatusCode tag(const xAOD::Jet &jet) const override
Decorate single jet with tagging info.
Definition: SmoothedTopTagger.cxx:154
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
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
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
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
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
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