ATLAS Offline Software
Loading...
Searching...
No Matches
TrackAnalysisStore.h
Go to the documentation of this file.
1
12
13#ifndef IDTPM2_TRACKANALYSISSTORE_H
14#define IDTPM2_TRACKANALYSISSTORE_H
15
24
27
30
33
36
38
41
43
44
45#include "TrackParticleTraits.h"
46#include "TruthParticleTraits.h"
47
48#include "xAODVertexTraits.h"
49
51
52#include "TrackView.h"
53#include "TruthView.h"
54#include "ParentView.h"
55#include "VertexView.h"
56
57#include "TagNProbe.h"
58
59#include "MsgMacros.h"
60#include "Utils.h"
61
62
63
65#include <string>
66#include <vector>
67#include <memory>
68#include <unordered_map>
69#include <utility>
70
74
75namespace IDTPM2 {
76
77
79
80public:
81
83
84public:
85
87 TrackAnalysisStore( const std::string& anaTag, const EventContext& context );
88
89 TrackAnalysisStore( const std::string& anaTag, const ToolHandle<Trig::TrigDecisionTool>* tdt, const EventContext& context );
90
93
96
101 StatusCode initialize();
102
104
106 const std::string& anaTag() { return m_anaTag; }
107
108 const std::vector<ParentView>& parents() const { return m_parents; };
109
111
113
115
117
119
120 const std::vector<const TrackView*>& reference_tracks() const { return m_reftrackptr; }
121 const std::vector<const TrackView*>& test_tracks() const { return m_testtrackptr; }
122
123 std::vector<const TrackView*>& reference_tracks() { return m_reftrackptr; }
124 std::vector<const TrackView*>& test_tracks() { return m_testtrackptr; }
125
126
131 void reference_tracks( const std::vector<const TrackView*>& v ) { m_reftrackptr = v; m_reftracks.clear(); }
132 void test_tracks( const std::vector<const TrackView*>& v ) { m_testtrackptr = v; m_testtracks.clear(); }
133
135
136 const std::vector<const VertexView*>& refvertices() const { return m_refvertices; }
137 const std::vector<const VertexView*>& testvertices() const { return m_testvertices; }
138
139 std::vector<const VertexView*>& refvertices() { return m_refvertices; }
140 std::vector<const VertexView*>& testvertices() { return m_testvertices; }
141
143
145
147
148 const xAOD::EventInfo* eventInfo() const { return m_eventInfo; }
151
152
154
155 int roiIndex() const { return m_roiIndex; }
156
157 void roiIndex( int i ) { m_roiIndex = i; }
158
159
161
162
163 template<typename T>
164 StatusCode fillInfo( const T*& t, const std::string& key );
165
166 template<typename Collection>
167 std::pair<typename Collection::const_iterator, typename Collection::const_iterator>
169 const std::string& key );
170
171 StatusCode fillEventInfo( const std::string& key ) { return fillInfo<xAOD::EventInfo>( m_eventInfo, key ); }
172
173#if 0
174 StatusCode fillEventInfo( const SG::ReadHandleKey<xAOD::EventInfo>& eventInfoHandleKey,
175 const SG::ReadHandleKey<xAOD::TruthEventContainer>& truthEventHandleKey,
176 const SG::ReadHandleKey<xAOD::TruthPileupEventContainer>& truthPUEventHandleKey );
177#endif
178
179
181
182 void fillViewRef( const std::string& key ) {
183 fillView( key, m_reftracks );
184 if ( m_parents.size()>0 ) trackptrs( m_parents, m_reftrackptr );
186 }
187
188 void fillViewTest( const std::string& key ) { fillView( key, m_testtracks ); trackptrs( m_testtracks, m_testtrackptr ); }
189
191
192 void fillViewTest( const std::string& key, const ElementLink<TrigRoiDescriptorCollection>& roi_link ) {
194 }
195
196
198
200
202
203 void fillVertexViewTest( const std::string& key, const ElementLink<TrigRoiDescriptorCollection>& roi_link ) {
205 }
206
207 void fillEventInfo( const xAOD::EventInfo* e ) { m_eventInfo = e; }
208
209 bool hasTagNProbe() const { return m_tnp!=0; }
210
211 void addTagNProbe( const TagNProbe* t ) { m_tnp=t; }
212
213 const TagNProbe* tagNProbe() const { return m_tnp; }
214
216
217 void setBeamKeys( const beam_key_t* k ) { m_beamkeys = k; }
218
219 void decoratePerigee();
220
221protected:
222
224
225 using view_store_t = std::vector<std::unique_ptr<TrackView>>;
226
227 using vtx_store_t = std::vector<std::unique_ptr<VertexView>>;
228
229protected:
230
232
233 void fillView( const std::string& key, view_store_t& trackView );
234
235 void fillView( const std::string& key, const ElementLink<TrigRoiDescriptorCollection>& roi_link, view_store_t& trackView );
236
238
239 void fillView( const std::string& key, vtx_store_t& vertexView );
240
242 void fillView( const std::string& key, const ElementLink<TrigRoiDescriptorCollection>& roi_link, vtx_store_t& vertexView );
243
245
246 template<typename T, typename U, typename V=U>
247 bool fillView_internal( const std::string& key, std::vector<std::unique_ptr<U>>& outView );
248
249
250 // template<typename T, typename U>
251 // bool fillView_internal( const std::string& key, std::vector<U>& outView );
252
253 template<typename T>
254 bool fillView_internal( const std::string& key, std::vector<ParentView>& parentView );
255
256
257
259
261 template<typename T>
262 StatusCode fill( T const*& container, const std::string& key );
263
264 // void fillroivertices( const ElementLink<TrigRoiDescriptorCollection>& roi_link,
265 // const std::string& key="" ) { fill<VertexView,xAOD::VertexContainer>( m_testvertices, roi_link, key ); }
266
267 template<typename T>
268 StatusCode fillRoi( std::pair<typename T::const_iterator, typename T::const_iterator>& itrpair,
269 const std::string& key,
271
272
273
274 const EventContext& eventContext() const { return m_context; }
275
277 void trackptrs( const view_store_t& v, std::vector<const TrackView*>& vp ) { fill_upointers( vp, v.begin(), v.end() ); }
278
279 void trackptrs( const std::vector<ParentView>& v, std::vector<const TrackView*>& vp ) {
280 vp.clear();
281 for ( size_t i=0 ; i<v.size() ; i++ ) append_pointers( vp, v[i].begin(), v[i].end() );
282 }
283
284 void vertexptrs( const vtx_store_t& v, std::vector<const VertexView*>& vp ) { fill_upointers( vp, v.begin(), v.end() ); }
285
286
288 template<typename T>
289 bool isGoodOffline( const T& , const std::string& , const std::string& ="" ) = delete;
290
291protected:
292
294
297
298 std::vector<ParentView> m_parents;
299
300 std::vector<const TrackView*> m_reftrackptr;
301 std::vector<const TrackView*> m_testtrackptr;
302
303 const EventContext& m_context;
304
306
308
310
313
314 std::vector<const VertexView*> m_refvertices;
315 std::vector<const VertexView*> m_testvertices;
316
320
322
334
335
338
339 const ToolHandle<Trig::TrigDecisionTool>* m_tdt;
340
342
345 const xAOD::EventInfo* m_eventInfo = nullptr;
348
349
355
356 const TagNProbe* m_tnp = 0;
357
358 std::string m_anaTag;
359
360
362
364
365}; // class TrackAnalysisStore
366
367
368
369
370template<typename T, typename U, typename V >
371bool IDTPM2::TrackAnalysisStore::fillView_internal( const std::string& key, std::vector<std::unique_ptr<U>>& outView ) {
372 const T* collection = 0;
373 if ( fill( collection, key ).isSuccess() ) {
374 if ( collection ) {
375 fillv<U,V>( outView, collection->begin(), collection->end() );
376 return true;
377 }
378 }
379 return false;
380}
381
382
383
387template<typename T>
388bool IDTPM2::TrackAnalysisStore::fillView_internal( const std::string& key, std::vector<ParentView>& parentView ) {
389 ChainString cs(key);
390 const T* parents = 0;
391 if ( fill( parents, cs.head() ).isSuccess() ) {
392 if ( parents ) {
393 for ( auto p : *parents ) if ( isGoodOffline( *p, cs.value(0), cs.value(1) ) ) parentView.push_back(p);
394 for ( size_t i=parentView.size() ; i-- ; ) parentView[i].claimChildren();
395 return true;
396 }
397 }
398 return false;
399}
400
401
402
404template<typename T>
405StatusCode TrackAnalysisStore::fill( T const*& container, const std::string& key ) {
406 MY_MSG_DEBUG << "fill: collection (ordinary fill)" << key << endmsg;
407 SG::ReadHandle<T> collection( key, eventContext() );
408 if( !collection.isValid() ) return StatusCode::FAILURE; // MY_MSG_WARNING << "Collection " << key << " could not be loaded" << endmsg;
409 container = collection.cptr();
410 return StatusCode::SUCCESS;
411}
412
413
414
415
417template<typename T>
418StatusCode TrackAnalysisStore::fillRoi( std::pair<typename T::const_iterator, typename T::const_iterator>& itrpair,
419 const std::string& key,
421
422 MY_MSG_DEBUG << "fill: collection (roi)" << key << endmsg;
423
424 SG::ReadHandle<T> collection( key, eventContext() );
425
426 if( !collection.isValid() ) return StatusCode::FAILURE; // MY_MSG_WARNING << "Collection " << key << " could not be loaded" << endmsg;
427
428 if ( m_tdt ) {
429 itrpair = (*m_tdt)->associateToEventView( collection, roi_link );
430 return StatusCode::SUCCESS;
431 }
432 else return StatusCode::FAILURE;
433}
434
435
436template<typename T>
437StatusCode TrackAnalysisStore::fillInfo( const T*& t, const std::string& key ) {
438 SG::ReadHandle<T> collection( key, eventContext() );
439 if ( ! collection.isValid() ) return StatusCode::FAILURE; // MY_MSG_WARNING << "Collection " << key << " could not be loaded" << endmsg;
440 else t = collection.ptr();
441 return StatusCode::SUCCESS;
442}
443
444
445
446
447
448template<typename Collection>
449std::pair<typename Collection::const_iterator, typename Collection::const_iterator>
451 const std::string& key ) {
452
454 std::pair< typename Collection::const_iterator,
455 typename Collection::const_iterator > itrpair;
456
458
459 // CLID checkCLID;
460 // const std::string* keyStr = m_provider->evtStore()->keyToString(roi_link.key(), checkCLID);
461 // MY_MSG_DEBUG << "Requesting range over (" << key << ") associated to ROI from " << (keyStr == nullptr ? "UNKNOWN" : *keyStr) << endmsg;
462
463 if ( m_tdt ) itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
464
465 return itrpair;
466}
467
468
469
470} // namespace IDTPM2
471
472#endif // > !IDTPM2_TRACKANALYSISSTORE_H
#define endmsg
ATLAS-specific HepMC functions.
emacs: this is -*- c++ -*-
#define MY_MSG_DEBUG
Definition MsgMacros.h:25
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for reading from StoreGate.
emacs: this is -*- c++ -*-
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
const std::string & head() const
Definition ChainString.h:33
std::string value(const std::string &key) const
can't make this return a reference in case there is no such key - could throw an exception then it wo...
Definition ChainString.h:47
std::vector< ParentView > m_parents
const TIDA::Associator< const TrackView > * m_matcher
store the track matches in an actual simple way
void addTagNProbe(const TagNProbe *t)
std::vector< std::unique_ptr< VertexView > > vtx_store_t
const TagNProbe * m_tnp
TrackAnalysis properties why do ALL these classes have independent m_anaTag variables ?
const ToolHandle< Trig::TrigDecisionTool > * m_tdt
Actually, actually, we don;t even need this AT ALL, it serves no purpose since we can control everyth...
const xAOD::EventInfo * eventInfo() const
get event info
void fillVertexViewTest(const std::string &key, const ElementLink< TrigRoiDescriptorCollection > &roi_link)
void fillEventInfo(const xAOD::EventInfo *e)
void fillVertexViewTest(const std::string &key)
std::vector< const VertexView * > m_refvertices
void setBeamKeys(const beam_key_t *k)
const xAOD::TruthPileupEventContainer * truthPileupEventContainer() const
TrackAnalysisStore & operator=(const TrackAnalysisStore &)=delete
= operator
std::vector< const TrackView * > m_testtrackptr
SG::ReadDecorHandleKeyArray< xAOD::EventInfo > keys_t
StatusCode fill(T const *&container, const std::string &key)
have the eventInfo already ?? then just pass in the pointer
StatusCode fillRoi(std::pair< typename T::const_iterator, typename T::const_iterator > &itrpair, const std::string &key, const ElementLink< TrigRoiDescriptorCollection > &roi_link)
more rational generic Roi fill method
void trackptrs(const std::vector< ParentView > &v, std::vector< const TrackView * > &vp)
int roiIndex() const
odds n ends ...
std::vector< const TrackView * > & reference_tracks()
void set_vertex_matcher(const TIDA::Associator< const VertexView > *m)
const xAOD::TruthPileupEventContainer * m_truthPUEventContainer
void fillVertexViewRef(const std::string &key)
vertex fillers ...
std::vector< const VertexView * > m_testvertices
const std::vector< const TrackView * > & reference_tracks() const
StatusCode fillInfo(const T *&t, const std::string &key)
filling methods to fetch collections ...
void fillViewRef(const std::string &key)
track fillers ...
void fillViewTest(const std::string &key, const ElementLink< TrigRoiDescriptorCollection > &roi_link)
Roi filler ...
SG::ReadDecorHandleKeyArray< xAOD::EventInfo > beam_key_t
bool isGoodOffline(const T &, const std::string &, const std::string &="")=delete
to be over ridden by selection for actual EDM classes
const TIDA::Associator< const VertexView > * m_vertex_matcher
store the vertex matches in an actual simple way NB: a vertex match can be quite complex: two vertice...
const EventContext & eventContext() const
const std::vector< ParentView > & parents() const
void set_matcher(const TIDA::Associator< const TrackView > *m)
const TIDA::Associator< const VertexView > * vertex_matcher() const
const std::vector< const VertexView * > & testvertices() const
bool fillView_internal(const std::string &key, std::vector< std::unique_ptr< U > > &outView)
templates for athena type track and vertex retrieval ...
const std::vector< const TrackView * > & test_tracks() const
StatusCode fillEventInfo(const std::string &key)
std::vector< const VertexView * > & testvertices()
const TIDA::Associator< const TrackView > * matcher() const
test and reference tracks ...
TrackAnalysisStore(const std::string &anaTag, const EventContext &context)
Constructor.
void test_tracks(const std::vector< const TrackView * > &v)
const xAOD::EventInfo * m_eventInfo
— Collections class variables — EventInfo, TruthEvent, and TruthPUEvent
const xAOD::TruthEventContainer * m_truthEventContainer
std::pair< typename Collection::const_iterator, typename Collection::const_iterator > getPair(const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key)
~TrackAnalysisStore()=default
Destructor.
void trackptrs(const view_store_t &v, std::vector< const TrackView * > &vp)
do this with a single template for treacks and vertices
void fillView(const std::string &key, view_store_t &trackView)
track fillers ...
const std::vector< const VertexView * > & refvertices() const
vertex accessors
StatusCode initialize()
initialize this should not actually be needed - we should be creating a new instance whenever this is...
void vertexptrs(const vtx_store_t &v, std::vector< const VertexView * > &vp)
const beam_key_t * m_beamkeys
enable / diable local truth decoration handling
std::vector< const TrackView * > m_reftrackptr
const std::string & anaTag()
— Setter methods —
const EventContext & m_context
std::vector< const VertexView * > & refvertices()
std::vector< const TrackView * > & test_tracks()
void fillViewTest(const std::string &key)
void reference_tracks(const std::vector< const TrackView * > &v)
these are a bit dodgy - ie we pass in a vector<const TrackView*> so we want to construct a reference ...
const TagNProbe * tagNProbe() const
const xAOD::TruthEventContainer * truthEventContainer() const
std::vector< std::unique_ptr< TrackView > > view_store_t
polymoprphic master store types
Property holding a SG store/key/clid from which a ReadHandle is made.
const_pointer_type ptr()
Dereference the pointer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
emacs: this is -*- c++ -*-
void fillv(std::vector< T > &t, Iterator first, Iterator last)
void fill_upointers(std::vector< const T * > &t, Iterator first, Iterator last)
void append_pointers(std::vector< const T * > &t, Iterator first, Iterator last)
DecorHandleKeyArray< ReadDecorHandle< T, S >, ReadDecorHandleKey< T >, Gaudi::DataHandle::Reader > ReadDecorHandleKeyArray
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
EventInfo_v1 EventInfo
Definition of the latest event info version.
TruthPileupEventContainer_v1 TruthPileupEventContainer
Declare the latest version of the truth event container.
void fill(H5::Group &out_file, size_t iterations)