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