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 if ( vertex->particles_in().size() < 1 ) return 0;
88
90 // if ( printout ) {
91 // TruthParticle t(p);
92 // std::cout << "particle " << *p << " " << t.pdgId() << "\tparent " << p << std::endl;
93 // }
94
95 for ( auto in: vertex->particles_in()) {
96 auto parent = fromParent( pdg_id, in, printout );
97 TruthParticle t(in);
98 if ( parent && std::abs(parent->pdg_id())==pdg_id) {
99 return parent;
100 }
101 }
102 return 0;
103}
104
105
106
107template<class T>
108void remove_duplicates(std::vector<T>& vec) {
109 std::sort(vec.begin(), vec.end());
110 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
111}
112
113
115
117 std::vector<TrackTrigObject>& objects, const std::string& key ) {
118
119 objects.clear();
120
121 const std::vector< Trig::Feature<xAOD::JetContainer> > jetfeatures = citr->get<xAOD::JetContainer>( key, TrigDefs::alsoDeactivateTEs );
122
123 if ( jetfeatures.empty() ) return 0;
124
125 for ( size_t ifeature=0 ; ifeature<jetfeatures.size() ; ifeature++ ) {
126 Trig::Feature<xAOD::JetContainer> jetfeature = jetfeatures.at(ifeature);
127
128 if ( jetfeature.empty() ) continue;
129
130 const xAOD::JetContainer* jets = jetfeature.cptr();
131
132 if ( jets == 0 ) continue;
133
134 xAOD::JetContainer::const_iterator jitr = jets->begin();
135
136 for ( ; jitr!=jets->end() ; ++jitr ) {
137
138 const xAOD::Jet* ajet = (*jitr);
139
140 long unsigned jetid = (unsigned long)ajet;
141
142 TrackTrigObject jet = TrackTrigObject( ajet->eta(), ajet->phi(), ajet->pt(), 0, ajet->type(), jetid );
143
144 objects.push_back( jet );
145
146 }
147 }
148
149 return objects.size();
150
151}
152
153
154
155
157
158 m_provider->msg(MSG::INFO) << "␛[91;1m" << "AnalysisConfig_Ntuple::loop() for " << m_analysisInstanceName
159 << " compiled " << __DATE__ << " " << __TIME__ << "\t: " << date() << "␛[m" << endmsg;
160
161 m_provider->msg(MSG::ERROR) << "␛[91;1m" << "This should no longer be called" << m_analysisInstanceName << endmsg;
162
163}
164
165
166
167
169
171
172 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::book() name " << name() << endmsg;
173
177 if ( !m_finalised ) {
178 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::book() not booking " << name() << endmsg;
179 return;
180 }
181
182
183
184 // get the TriggerDecisionTool
185
186 if( m_tdt->retrieve().isFailure() ) {
187 m_provider->msg(MSG::FATAL) << " Unable to retrieve the TrigDecisionTool: Please check job options file" << endmsg;
188 // return StatusCode::FAILURE;
189 return;
190 }
191
192 m_provider->msg(MSG::INFO) << "␛[91;1m" << " Successfully retrieved the TrigDecisionTool" << "␛[m" << endmsg;
193 m_provider->msg(MSG::INFO) << "␛[91;1m" << " booking ntuple" << "␛[m" << endmsg;
194 m_provider->msg(MSG::INFO) << "␛[91;1m" << " trying to create new ntple file" << "␛[m" << endmsg;
195
197 TDirectory* dir = gDirectory;
198
199 static std::atomic<bool> first_open = true;
200
201 std::string outputFileName = m_outputFileName;
202
203 if ( genericFlag() ) {
204 static std::atomic<int> file_index = 0;
205 std::string::size_type pos = outputFileName.find(".root");
206 if ( pos != std::string::npos ) outputFileName.erase(pos, outputFileName.size());
207 char file_label[64];
208 sprintf( file_label, "-%04d.root", file_index++ );
209 outputFileName += file_label;
210 }
211
212 m_provider->msg(MSG::INFO) << "book() Writing to file " << outputFileName << endmsg;
213
214 if ( first_open || genericFlag() ) {
216 m_File = new TFile( outputFileName.c_str(), "recreate");
217
218 TTree* dataTree = new TTree("dataTree", "dataTree");
219 TString releaseData(m_releaseData.c_str());
220 dataTree->Branch( "ReleaseMetaData", "TString", &releaseData);
221 dataTree->Fill();
222 dataTree->Write("", TObject::kOverwrite);
223 delete dataTree;
224
225
226 m_Tree = new TTree("tree", "tree");
227 m_Tree->Branch( "TIDA::Event", "TIDA::Event", m_event, 6400, 1 );
228
229
230 }
231 else {
233 m_File = new TFile( outputFileName.c_str(), "update");
234 m_Tree = (TTree *)m_File->Get("tree");
235 m_Tree->SetBranchAddress( "TIDA::Event", &m_event );
236 }
237
238 m_Dir = gDirectory;
239
240 first_open = false;
241
242
243 m_provider->msg(MSG::DEBUG) << "change directory " << name() << " " << dir->GetName() << endmsg;
244
245 // std::cout << "change directory " << name() << " " << dir->GetName() << std::endl;
247 dir->cd();
248
249 // gDirectory->pwd();
250
251 m_finalised = false; // flag we have an open file that is not yet finalised
252
253 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::book() exiting" << endmsg;
254
255}
256
257
258
260
262
263 // gDirectory->pwd();
264
265
267 if ( m_finalised ) {
268 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::finalise() flagged, not finalising " << m_provider->name() << "\t" << m_Tree->GetEntries() << " entries" << endmsg;
269 return;
270 }
271
272 m_provider->msg(MSG::INFO) << "AnalysisConfig_Ntuple::finalise() writing " << m_provider->name() << "\t" << m_Tree->GetEntries() << " entries" << endmsg;
273
274 TDirectory* directory = gDirectory;
275
276 // std::cout << "change directory " << name() << " " << m_Dir->GetName() << std::endl;
277
278 m_provider->msg(MSG::DEBUG) << "change directory " << name() << " " << m_Dir->GetName() << endmsg;
279
280
281 m_Dir->cd();
282
283 // gDirectory->pwd();
284
285 m_Tree->Write("", TObject::kOverwrite);
286
287 // m_File->Write();
288 if ( m_File ) m_File->Close();
289
290
291 m_finalised = true;
292
293 // m_Tree "belongs" to the m_File so was (possibly) deleted on the m_File->Close();
294 // so don't delete it !
295 // delete m_Tree;
296 delete m_File;
297
298 m_Tree = 0;
299 m_File = 0;
300
301 // f.Write();
302 // f.Close();
303
304 // std::cout << "change directory " << name() << " " << directory->GetName() << std::endl;
305
306 directory->cd();
307
308 // gDirectory->pwd();
309
310}
311
312
313
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:60
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
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".