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 67 of file JetCalibTools_Example.cxx.

67 {
68
69 using namespace asg::msgUserCode;
71
72 //---------------------------------------------
73 // Declaring input variables with default values
74 //---------------------------------------------
75 std::string isData = "";
76 std::string sample = "";
77 std::string jetColl = "";
78 std::string jetCalibConfig = "";
79 std::string calibSeq = "";
80 std::string calibArea = "";
81 bool devMode = false;
82 bool isCollision = false;
83
84 //---------------------------
85 // Decoding the user settings
86 //---------------------------
87 for (int i=1; i< argc; i++){
88
89 std::string opt(argv[i]); std::vector< std::string > v;
90
91 std::istringstream iss(opt);
92
93 std::string item;
94 char delim = '=';
95
96 while (std::getline(iss, item, delim)){
97 v.push_back(item);
98 }
99
100 if ( opt.find("--help") != std::string::npos ) {
101 usage(); return 0;
102 }
103
104 if ( opt.find("--sample=") != std::string::npos ) sample = v[1];
105
106 if ( opt.find("--jetColl=") != std::string::npos ) jetColl = v[1];
107
108 if ( opt.find("--jetCalibConfig=") != std::string::npos ) jetCalibConfig = v[1];
109
110 if ( opt.find("--calibSeq=") != std::string::npos ) calibSeq = v[1];
111
112 if ( opt.find("--calibArea=") != std::string::npos ) calibArea = v[1];
113
114 if ( opt.find("--isData=") != std::string::npos ) isData = v[1];
115
116 if ( opt.find("--devMode") != std::string::npos ) devMode = true;
117
118 }//End: Loop over input options
119
120 if(sample.empty()){
121 std::cout << "No input xAOD file specified, exiting" << std::endl;
122 return 1;
123 }
124 if(jetColl.empty()){
125 std::cout << "No jet collection specified, exiting" << std::endl;
126 return 1;
127 }
128 if(jetCalibConfig.empty()){
129 std::cout << "No JetCalibTools config specified, exiting" << std::endl;
130 return 1;
131 }
132 if(calibSeq.empty()){
133 std::cout << "No calibration sequence specified, exiting" << std::endl;
134 return 1;
135 }
136 if(isData.empty()){
137 std::cout << "isData not specified, exiting" << std::endl;
138 return 1;
139 }
140 else if(isData=="TRUE") isCollision = true;
141
142 //--------------------
143 // Opening input file
144 //--------------------
145 std::unique_ptr< TFile > ifile( TFile::Open( sample.c_str(), "READ" ) );
146
147 // Create a TEvent object.
148#ifdef XAOD_STANDALONE
151 ANA_CHECK( event.readFrom( ifile.get() ) );
152 ANA_MSG_WARNING(calibSeq);
153 // Create ONNX service for LargeRDNN calibration
154 asg::AsgServiceConfig config ("AthOnnx::OnnxRuntimeSvc/OnnxRuntimeSvc");
155 std::shared_ptr<AthOnnx::IOnnxRuntimeSvc> service;
156 ANA_CHECK(config.makeService (service));
157#else // Athena "Store" is the same StoreGate used by the TEvent
159 ANA_CHECK( event.readFrom( ifile.get() ) );
160#endif
161
162 //----------------------------------
163 // Initialization of JetCalibTools
164 //----------------------------------
165 const std::string name_JetCalibTools = "JetCalib_Example";
166
167 // Call the constructor
168 JetCalibrationTool jetCalibrationTool(name_JetCalibTools.c_str());
169 ANA_CHECK( jetCalibrationTool.setProperty("JetCollection",jetColl.c_str()) );
170
171 ANA_CHECK( jetCalibrationTool.setProperty("CalibSequence",calibSeq.c_str()) );
172
173 ANA_CHECK( jetCalibrationTool.setProperty("ConfigFile",jetCalibConfig.c_str()) );
174
175 ANA_CHECK( jetCalibrationTool.setProperty("IsData",isCollision) );
176
177 if(!calibArea.empty()){
178 ANA_CHECK( jetCalibrationTool.setProperty("CalibArea",calibArea.c_str()) );
179 }
180
181 ANA_CHECK( jetCalibrationTool.setProperty("DEVmode", devMode ) );
182
183 // Initialize the tool
184 if(!(jetCalibrationTool.initialize().isSuccess())){
185 std::cout << "Initialization of JetCalibTools failed, exiting" << std::endl;
186 return 0;
187 }
188
189 //------------------
190 // Loop over events
191 //------------------
192
193 const Long64_t nevents = event.getEntries();
194 for(Long64_t ievent = 0; ievent < nevents; ++ievent){
195
196 // Load the event:
197 if( event.getEntry( ievent ) < 0 ) {
198 std::cerr << "Failed to load entry " << ievent << std::endl;
199 return 1;
200 }
201
202 // Show status
203 if(ievent % 100==0) std::cout << "Event " << ievent << " of " << nevents << std::endl;
204
205 // Retrieve jet container
206 const xAOD::JetContainer* jets = nullptr;
207 ANA_CHECK( event.retrieve( jets, jetColl + "Jets" ) );
208
209 // Shallow copy
210 auto jets_shallowCopy = xAOD::shallowCopyContainer( *jets );
211
212 // Calibrate the shallow copy
213 ANA_CHECK( jetCalibrationTool.applyCalibration( *(jets_shallowCopy.first) ) );
214
215 delete jets_shallowCopy.first;
216 delete jets_shallowCopy.second;
217
218 }//END: Loop over events
219
221
222 return 0;
223}
#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
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".

◆ usage()

void usage ( )

Definition at line 49 of file JetCalibTools_Example.cxx.

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