ATLAS Offline Software
Loading...
Searching...
No Matches
JetCalibTools_Example.cxx File Reference

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 68 of file JetCalibTools_Example.cxx.

68 {
69
70 using namespace asg::msgUserCode;
72
73 //---------------------------------------------
74 // Declaring input variables with default values
75 //---------------------------------------------
76 std::string isData = "";
77 std::string sample = "";
78 std::string jetColl = "";
79 std::string jetCalibConfig = "";
80 std::string calibSeq = "";
81 std::string calibArea = "";
82 bool devMode = false;
83 bool isCollision = false;
84
85 //---------------------------
86 // Decoding the user settings
87 //---------------------------
88 for (int i=1; i< argc; i++){
89
90 std::string opt(argv[i]); std::vector< std::string > v;
91
92 std::istringstream iss(opt);
93
94 std::string item;
95 char delim = '=';
96
97 while (std::getline(iss, item, delim)){
98 v.push_back(item);
99 }
100
101 if ( opt.find("--help") != std::string::npos ) {
102 usage(); return 0;
103 }
104
105 if ( opt.find("--sample=") != std::string::npos ) sample = v[1];
106
107 if ( opt.find("--jetColl=") != std::string::npos ) jetColl = v[1];
108
109 if ( opt.find("--jetCalibConfig=") != std::string::npos ) jetCalibConfig = v[1];
110
111 if ( opt.find("--calibSeq=") != std::string::npos ) calibSeq = v[1];
112
113 if ( opt.find("--calibArea=") != std::string::npos ) calibArea = v[1];
114
115 if ( opt.find("--isData=") != std::string::npos ) isData = v[1];
116
117 if ( opt.find("--devMode") != std::string::npos ) devMode = true;
118
119 }//End: Loop over input options
120
121 if(sample.empty()){
122 std::cout << "No input xAOD file specified, exiting" << std::endl;
123 return 1;
124 }
125 if(jetColl.empty()){
126 std::cout << "No jet collection specified, exiting" << std::endl;
127 return 1;
128 }
129 if(jetCalibConfig.empty()){
130 std::cout << "No JetCalibTools config specified, exiting" << std::endl;
131 return 1;
132 }
133 if(calibSeq.empty()){
134 std::cout << "No calibration sequence specified, exiting" << std::endl;
135 return 1;
136 }
137 if(isData.empty()){
138 std::cout << "isData not specified, exiting" << std::endl;
139 return 1;
140 }
141 else if(isData=="TRUE") isCollision = true;
142
143 //--------------------
144 // Opening input file
145 //--------------------
146 std::unique_ptr< TFile > ifile( TFile::Open( sample.c_str(), "READ" ) );
147
148 // Create a TEvent object.
149#ifdef XAOD_STANDALONE
152 ANA_CHECK( event.readFrom( ifile.get() ) );
153 ANA_MSG_WARNING(calibSeq);
154 // Create ONNX service for LargeRDNN calibration
155 asg::AsgServiceConfig config ("AthOnnx::OnnxRuntimeSvc/OnnxRuntimeSvc");
156 std::shared_ptr<AthOnnx::IOnnxRuntimeSvc> service;
157 ANA_CHECK(config.makeService (service));
158#else // Athena "Store" is the same StoreGate used by the TEvent
160 ANA_CHECK( event.readFrom( ifile.get() ) );
161#endif
162
163 //----------------------------------
164 // Initialization of JetCalibTools
165 //----------------------------------
166 const std::string name_JetCalibTools = "JetCalib_Example";
167
168 // Call the constructor
169 JetCalibrationTool jetCalibrationTool(name_JetCalibTools.c_str());
170 ANA_CHECK( jetCalibrationTool.setProperty("JetCollection",jetColl.c_str()) );
171
172 ANA_CHECK( jetCalibrationTool.setProperty("CalibSequence",calibSeq.c_str()) );
173
174 ANA_CHECK( jetCalibrationTool.setProperty("ConfigFile",jetCalibConfig.c_str()) );
175
176 ANA_CHECK( jetCalibrationTool.setProperty("IsData",isCollision) );
177
178 if(!calibArea.empty()){
179 ANA_CHECK( jetCalibrationTool.setProperty("CalibArea",calibArea.c_str()) );
180 }
181
182 ANA_CHECK( jetCalibrationTool.setProperty("DEVmode", devMode ) );
183
184 // Initialize the tool
185 if(!(jetCalibrationTool.initialize().isSuccess())){
186 std::cout << "Initialization of JetCalibTools failed, exiting" << std::endl;
187 return 0;
188 }
189
190 //------------------
191 // Loop over events
192 //------------------
193
194 const Long64_t nevents = event.getEntries();
195 for(Long64_t ievent = 0; ievent < nevents; ++ievent){
196
197 // Load the event:
198 if( event.getEntry( ievent ) < 0 ) {
199 std::cerr << "Failed to load entry " << ievent << std::endl;
200 return 1;
201 }
202
203 // Show status
204 if(ievent % 100==0) std::cout << "Event " << ievent << " of " << nevents << std::endl;
205
206 // Retrieve jet container
207 const xAOD::JetContainer* jets = nullptr;
208 ANA_CHECK( event.retrieve( jets, jetColl + "Jets" ) );
209
210 // Shallow copy
211 auto jets_shallowCopy = xAOD::shallowCopy( *jets );
212
213 // Calibrate the shallow copy
214 ANA_CHECK( jetCalibrationTool.applyCalibration( *jets_shallowCopy.first ) );
215 }//END: Loop over events
216
218
219 return 0;
220}
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
void usage()
an object that can create a AsgService
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".

◆ usage()

void usage ( )

Definition at line 50 of file JetCalibTools_Example.cxx.

50 {
51 std::cout << "Running options:" << std::endl;
52 std::cout << " --help : To get the help you're reading" << std::endl;
53 std::cout << " --jetCalibConfig= : Specify the JetCalibTools config" << std::endl;
54 std::cout << " --jetColl= : Specify the jet collection" << std::endl;
55 std::cout << " --calibSeq= : Specify the calibration sequence for JetCalibTools" << std::endl;
56 std::cout << " --calibArea : Specify the calibration area for JetCalibTools" << std::endl;
57 std::cout << " --isData=TRUE : Specify isData true for JetCalibTools" << std::endl;
58 std::cout << " --isData=FALSE : Specify isData false for JetCalibTools" << std::endl;
59 std::cout << " --sample= : Specify input xAOD" << std::endl;
60 std::cout << " --devMode : Set dev mode for calibration sequence" << std::endl;
61 std::cout << " Example: Example --jetCalibConfig=JES_2015dataset_recommendation_Feb2016.config --jetColl=AntiKt4EMTopo --calibSeq=JetArea_Residual_Origin_EtaJES_GSC --isData=FALSE --sample=xAOD.root" << std::endl;
62}