ATLAS Offline Software
Loading...
Searching...
No Matches
AnalysisConfig_Ntuple.cxx
Go to the documentation of this file.
1
8
9
10#include <cstdio>
11
12#include <sys/time.h>
13
15
17#include "AtlasHepMC/GenEvent.h"
20
21
22#include "EventInfo/EventInfo.h"
23#include "EventInfo/EventID.h"
25
26
29
31
35
37// #include "TrigInDetAnalysisUtils/OfflineObjectSelection.h"
38
41#include "TrkTrack/Track.h"
42
43
45
47
49
51
52//#include "JetEvent/JetCollection.h"
53
56
58
61
62
63#define endmsg endmsg
64
65
66
67std::string date() {
68 time_t t;
69 time(&t);
70 char buf[26];
71 std::string mtime = ctime_r(&t, buf);
72 mtime.erase( std::remove(mtime.begin(), mtime.end(), '\n'), mtime.end() );
73 return mtime;
74}
75
76
77//function to find true taus
79
80 if ( p==0 ) return 0;
81 if (std::abs(p->pdg_id())==11 || std::abs(p->pdg_id())==13 ) return 0; //don't want light leptons from tau decays
82 if ( std::abs(p->pdg_id())==pdg_id ) return p;
83
84 auto vertex = p->production_vertex();
85 if ( !vertex) return 0; // has no production vertex !!!
86
87#ifdef HEPMC3
88 if ( vertex->particles_in().size() < 1 ) return 0;
89
91 // if ( printout ) {
92 // TruthParticle t(p);
93 // std::cout << "particle " << *p << " " << t.pdgId() << "\tparent " << p << std::endl;
94 // }
95
96 for ( auto in: vertex->particles_in()) {
97 auto parent = fromParent( pdg_id, in, printout );
98 TruthParticle t(in);
99 if ( parent && std::abs(parent->pdg_id())==pdg_id) {
100 return parent;
101 }
102 }
103#else
104 if ( vertex->particles_in_size() < 1 ) return 0;
105
106 HepMC::GenVertex::particles_in_const_iterator in = vertex->particles_in_const_begin();
107 HepMC::GenVertex::particles_in_const_iterator end = vertex->particles_in_const_end();
108 while ( in!=end ) {
109 const HepMC::GenParticle* parent = fromParent( pdg_id, *in, printout );
110 TruthParticle t(*in);
111 // if ( printout ) std::cout << "\tvalue for particle " << *in << " " << t.pdgId() << "\tparent " << parent << std::endl;
112 if ( parent && std::abs(parent->pdg_id())==pdg_id) {
113 //if ( printout ) std::cout << "found tau! - in parents" << std::endl;
114 return parent;
115 }
116 in++;
117 }
118#endif
119
120 return 0;
121}
122
123
124
125template<class T>
126void remove_duplicates(std::vector<T>& vec) {
127 std::sort(vec.begin(), vec.end());
128 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
129}
130
131
133
135 std::vector<TrackTrigObject>& objects, const std::string& key ) {
136
137 objects.clear();
138
139 const std::vector< Trig::Feature<xAOD::JetContainer> > jetfeatures = citr->get<xAOD::JetContainer>( key, TrigDefs::alsoDeactivateTEs );
140
141 if ( jetfeatures.empty() ) return 0;
142
143 for ( size_t ifeature=0 ; ifeature<jetfeatures.size() ; ifeature++ ) {
144 Trig::Feature<xAOD::JetContainer> jetfeature = jetfeatures.at(ifeature);
145
146 if ( jetfeature.empty() ) continue;
147
148 const xAOD::JetContainer* jets = jetfeature.cptr();
149
150 if ( jets == 0 ) continue;
151
152 xAOD::JetContainer::const_iterator jitr = jets->begin();
153
154 for ( int j=0 ; jitr!=jets->end() ; ++jitr, j++ ) {
155
156 const xAOD::Jet* ajet = (*jitr);
157
158 long unsigned jetid = (unsigned long)ajet;
159
160 TrackTrigObject jet = TrackTrigObject( ajet->eta(), ajet->phi(), ajet->pt(), 0, ajet->type(), jetid );
161
162 objects.push_back( jet );
163
164 }
165 }
166
167 return objects.size();
168
169}
170
171
172
173
175
176 m_provider->msg(MSG::INFO) << "␛[91;1m" << "AnalysisConfig_Ntuple::loop() for " << m_analysisInstanceName
177 << " compiled " << __DATE__ << " " << __TIME__ << "\t: " << date() << "␛[m" << endmsg;
178
179 m_provider->msg(MSG::ERROR) << "␛[91;1m" << "This should no longer be called" << m_analysisInstanceName << endmsg;
180
181}
182
183
184
185
187
189
190 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::book() name " << name() << endmsg;
191
195 if ( !m_finalised ) {
196 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::book() not booking " << name() << endmsg;
197 return;
198 }
199
200
201
202 // get the TriggerDecisionTool
203
204 if( m_tdt->retrieve().isFailure() ) {
205 m_provider->msg(MSG::FATAL) << " Unable to retrieve the TrigDecisionTool: Please check job options file" << endmsg;
206 // return StatusCode::FAILURE;
207 return;
208 }
209
210 m_provider->msg(MSG::INFO) << "␛[91;1m" << " Successfully retrieved the TrigDecisionTool" << "␛[m" << endmsg;
211 m_provider->msg(MSG::INFO) << "␛[91;1m" << " booking ntuple" << "␛[m" << endmsg;
212 m_provider->msg(MSG::INFO) << "␛[91;1m" << " trying to create new ntple file" << "␛[m" << endmsg;
213
215 TDirectory* dir = gDirectory;
216
217 static std::atomic<bool> first_open = true;
218
219 std::string outputFileName = m_outputFileName;
220
221 if ( genericFlag() ) {
222 static std::atomic<int> file_index = 0;
223 std::string::size_type pos = outputFileName.find(".root");
224 if ( pos != std::string::npos ) outputFileName.erase(pos, outputFileName.size());
225 char file_label[64];
226 sprintf( file_label, "-%04d.root", file_index++ );
227 outputFileName += file_label;
228 }
229
230 m_provider->msg(MSG::INFO) << "book() Writing to file " << outputFileName << endmsg;
231
232 if ( first_open || genericFlag() ) {
234 m_File = new TFile( outputFileName.c_str(), "recreate");
235
236 TTree* dataTree = new TTree("dataTree", "dataTree");
237 TString releaseData(m_releaseData.c_str());
238 dataTree->Branch( "ReleaseMetaData", "TString", &releaseData);
239 dataTree->Fill();
240 dataTree->Write("", TObject::kOverwrite);
241 delete dataTree;
242
243
244 m_Tree = new TTree("tree", "tree");
245 m_Tree->Branch( "TIDA::Event", "TIDA::Event", m_event, 6400, 1 );
246
247
248 }
249 else {
251 m_File = new TFile( outputFileName.c_str(), "update");
252 m_Tree = (TTree *)m_File->Get("tree");
253 m_Tree->SetBranchAddress( "TIDA::Event", &m_event );
254 }
255
256 m_Dir = gDirectory;
257
258 first_open = false;
259
260
261 m_provider->msg(MSG::DEBUG) << "change directory " << name() << " " << dir->GetName() << endmsg;
262
263 // std::cout << "change directory " << name() << " " << dir->GetName() << std::endl;
265 dir->cd();
266
267 // gDirectory->pwd();
268
269 m_finalised = false; // flag we have an open file that is not yet finalised
270
271 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::book() exiting" << endmsg;
272
273}
274
275
276
278
280
281 // gDirectory->pwd();
282
283
285 if ( m_finalised ) {
286 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::finalise() flagged, not finalising " << m_provider->name() << "\t" << m_Tree->GetEntries() << " entries" << endmsg;
287 return;
288 }
289
290 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::finalise() writing " << m_provider->name() << "\t" << m_Tree->GetEntries() << " entries" << endmsg;
291
292 TDirectory* directory = gDirectory;
293
294 // std::cout << "change directory " << name() << " " << m_Dir->GetName() << std::endl;
295
296 m_provider->msg(MSG::DEBUG) << "change directory " << name() << " " << m_Dir->GetName() << endmsg;
297
298
299 m_Dir->cd();
300
301 // gDirectory->pwd();
302
303 m_Tree->Write("", TObject::kOverwrite);
304
305 // m_File->Write();
306 if ( m_File ) m_File->Close();
307
308
309 m_finalised = true;
310
311 // m_Tree "belongs" to the m_File so was (possibly) deleted on the m_File->Close();
312 // so don't delete it !
313 // delete m_Tree;
314 delete m_File;
315
316 m_Tree = 0;
317 m_File = 0;
318
319 // f.Write();
320 // f.Close();
321
322 // std::cout << "change directory " << name() << " " << directory->GetName() << std::endl;
323
324 directory->cd();
325
326 // gDirectory->pwd();
327
328}
329
330
331
std::string date()
sadly, includes a return at the end
HepMC::ConstGenParticlePtr fromParent(int pdg_id, HepMC::ConstGenParticlePtr p, bool printout=false)
void remove_duplicates(std::vector< T > &vec)
#define endmsg
std::vector< size_t > vec
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
generic track filter to filter on eta and PT only
static const std::string outputFileName
size_t get_jets(Trig::FeatureContainer::combination_const_iterator citr, std::vector< TrackTrigObject > &objects, const std::string &key="")
retrieve the jets from the Roi
virtual void finalize()
finalise the analysis - take ratios for efficiencies etc
virtual void book()
setup the analysis the analysis, retrieve the tools etc
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
ToolHandle< Trig::TrigDecisionTool > * m_tdt
std::vector< Combination >::const_iterator combination_const_iterator
is basic vehicle of object access in TDT
Definition Feature.h:112
const T * cptr() const
explicit conversion to object
Definition Feature.h:171
bool empty() const
test method to check if the object is truly there
Definition Feature.h:197
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition Jet_v1.cxx:54
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition Jet_v1.cxx:44
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition Jet_v1.cxx:49
virtual Type::ObjectType type() const
The type of the object as a simple enumeration.
Definition Jet_v1.cxx:85
std::string date()
sadly, includes a return at the end
Definition hcg.cxx:58
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".