ATLAS Offline Software
Loading...
Searching...
No Matches
TrackAnalysis.cxx
Go to the documentation of this file.
1
11
13
15
16#include "TrackAnalysisStore.h"
17
18#include "MsgMacros.h"
19
20#include "TrackView.h"
21#include "VertexView.h"
22
23
24#include "TrackAnalysis.h"
25#include "TBestMatch.h"
26
27#include "TrackRoiSelector.h"
28
29#include "TagNProbe.h"
30
31#include <algorithm>
32#include <limits>
33#include <cmath>
34#include <utility>
35#include <cstdlib>
36
37
41IDTPM2::TrackAnalysis::TrackAnalysis( const std::string& type, const std::string& name, const IInterface* parent ) :
42 AthAlgTool( type, name, parent ),
43 m_tdt("Trig::TrigDecisionTool/TrigDecisionTool"),
44 m_analysis(std::make_unique<AnalysisR4>(name))
45{ }
46
47
48
49
50
55
56
61
62 MY_MSG_INFO << "TrackAnalysis::initialize() name: " << name() << endmsg;
63
64 std::string selectChain = name().substr(name().find(".")+1,name().size());
65
66 if ( selectChain.find(":")==std::string::npos ) selectChain = ":"+selectChain;
67
68 ChainString chainName = selectChain; //chainName.head();
69
72 if ( chainName.head()!="" ) m_triggerchain = chainName.head();
73 if ( chainName.tail()!="" ) m_testTracks = chainName.tail();
74 if ( chainName.roi()!="" ) m_rois = chainName.roi();
75 if ( chainName.vtx()!="" ) m_vertices = chainName.vtx();
76 if ( chainName.element()!="" ) m_leg = std::atoi(chainName.element().c_str());
77 if ( chainName.extra()!="" ) m_extra = chainName.extra();
78
82
84
86
87 MY_MSG_INFO << "analysis: " << name() << endmsg;
88 MY_MSG_INFO << "trigger: " << m_triggerchain << endmsg;
89 MY_MSG_INFO << "reference: " << m_refTracks << ( m_refTracks_tag.empty() ? "" : "\t"+ m_refTracks_tag ) << endmsg;
90 MY_MSG_INFO << "test: " << m_testTracks << endmsg;
91 if ( !m_vertices.empty() ) { MY_MSG_INFO << "vtx: " << name() << endmsg; }
93
94 if ( !m_tagChain.empty() ) {
95
96 ChainString tagchain = m_tagChain.value();
97
100
101 MY_MSG_INFO << "Tag and probe: " << tagchain << endmsg;
102
103 MY_MSG_INFO << "Tag chain: " << tagchain.head()
104 << "\t" << tagchain.roi()
105 << "\t" << tagchain.element()
106 << "\t" << tagchain.extra()
107 << "\treferences: " << m_reference << "\t" << m_reference_tag
108 << endmsg;
109
110 m_triggerchain_tag = tagchain.head();
111 m_roi_tag = tagchain.roi();
112 m_extra_tag = tagchain.extra();
113 if ( !tagchain.element().empty() ) m_leg_tag = std::atoi(tagchain.element().c_str());
114
116
117 if ( m_refPdgId_tag.value() ) m_tnpPredicate = std::make_unique<PtPdgHelper>( m_minTagPT.value(), m_refPdgId_tag.value() );
118 else m_tnpPredicate = std::make_unique<PtHelper<TrackView>>( m_minTagPT.value() );
119
120 MY_MSG_INFO << "TagNProbe: " << m_triggerchain << " -> " << m_triggerchain_tag << endmsg;
121
122 }
123
124
125 MY_MSG_DEBUG << "TrackAnalysis::initialize()"
126 << " trigger=" << m_triggerchain
127 << " testTracks=" << m_testTracks
128 << " refTracks=" << m_refTracks
129 << " rois=" << m_rois << endmsg;
130
131 ATH_CHECK( m_eventInfoName.initialize() );
132
133 ATH_CHECK( m_beamKeys.initialize() );
134
135 ATH_CHECK( m_refSelector.retrieve() );
136 ATH_CHECK( m_testSelector.retrieve() );
137
138 // ATH_CHECK( m_vertexQualitySelectionTool.retrieve() );
139
140 ATH_CHECK( m_trackMatchingTool.retrieve() );
141
142#if 0
144 std::unique_ptr<TrackAnalysisDefinition> config = std::make_unique<TrackAnalysisDefinition>();
145
146 config->setTestCollection( m_testTracks );
147 config->setReferenceCollection( m_refTracks );
148
149 config->setTestType( "Trigger" );
150 config->setReferenceType( "Offline" );
151
157 config->setUseTrigger( true );
158 config->setUseOffline( true );
159 config->setDoTrigNavigation( true );
160
165 m_trkAnaDef = std::move( config );
166
167#endif
168
169 // m_trackQualitySelectionTool->setAnaDef(m_trkAnaDef.get());
170
171 MY_MSG_DEBUG << "TrackAnalysis::initialize() exitting" << endmsg;
172
173 m_analysis->set_monTool( &m_tool );
174
175 for ( size_t i=m_fillers.size() ; i-- ; ) m_analysis->addFillTool( m_fillers[i] );
176
177 m_analysis->initialise();
178
179 m_initialized = true;
180
181 return StatusCode::SUCCESS;
182
183}
184
185
186
191{
192 return StatusCode::SUCCESS;
193}
194
195
199StatusCode IDTPM2::TrackAnalysis::fillHistograms( const EventContext& context ) const {
200 if ( execute( context ) ) return StatusCode::SUCCESS;
201 return StatusCode::FAILURE;
202}
203
204
205
206
207void printtracks( const std::vector<const TrackView*>& ars, const std::string& sht="" ) {
208 std::cout << "\nSUTT printtracks: " << sht << "\tsize: " << ars.size() << std::endl;
209 for ( size_t i=0 ; i<ars.size() && i<10 ; i++ ) std::cout << "\t" << i << "\t" << *ars[i] << std::endl;
210 std::cout << std::endl;
211}
212
213
214template<typename T>
215std::ostream& operator<<( std::ostream& s, std::vector<T>& v ) {
216 for ( size_t i=0 ; i<v.size() ; i++ ) s << "\t" << v[i];
217 return s;
218}
219
220
221#include <fenv.h>
222
223bool IDTPM2::TrackAnalysis::execute( const EventContext& context ) const {
224
225 feclearexcept(FE_ALL_EXCEPT);
226 fedisableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
227
228 MY_MSG_DEBUG << "Filling hists " << name() << "\ttrigger: " << m_triggerchain << " ..." << endmsg;
229
230 unsigned decisionType = TrigDefs::Physics; // TrigDefs::includeFailedDecisions;
231
232 if( !m_triggerchain.empty() && !m_tdt->isPassed( m_triggerchain, decisionType ) ) return true;
233
234 MY_MSG_DEBUG << "␛[91;1m PROCESSING ------------------------------------------------------------------------------------␛[m" << endmsg;
235
236 MY_MSG_DEBUG << "TrackAnalysis::execute() " << name()
237 << " refTracks: " << m_refTracks
238 << "\t testTracks: " << m_testTracks
239 << "\ttriggerchain: " << m_triggerchain << endmsg;
240
241
242#if 0
243 if ( m_testTracks.find("HLT_")==std::string::npos && m_testTracks.find("EF_")==std::string::npos ) {
244
245 const std::vector<std::string> configuredChains = m_tdt->getListOfTriggers("HLT_.*, EF_.*");
246
247 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
248 if( m_tdt->isPassed( configuredChains[i], decisionType ) ) std::cout << i << "\t" << "␛[91;1m" << "Chain " << configuredChains[i] << " pass (ACN)␛[m" << std::endl;
249 if ( configuredChains[i] == m_triggerchain ) std::cout << "Mutha ..." << configuredChains[i] << " " << m_triggerchain << "\n\n" << std::endl;
250 }
251
252 MY_MSG_INFO << "␛[91;1m" << configuredChains.size() << " Configured Chains" << "␛[m"
253 <<"\ttrigger chain: " << m_triggerchain << " :: "
254 << m_tdt->isPassed( m_triggerchain, decisionType ) << endmsg;
255 }
256#endif
257
258 IDTPM2::TrackAnalysisStore trackAnaStore( "_duff", context );
259
260 if ( !m_useDecorations ) trackAnaStore.setBeamKeys( &m_beamKeys );
261
263 // trackAnaStore.setTDT( &m_tdt );
264
265 RoiSelector roiSelector(&m_tdt);
266
267 trackAnaStore.fillViewRef( m_refTracks );
268
269 // printtracks( trackAnaStore.reference_tracks(), "\ttrackAnaStore: reference" );
270
272
273 bool isTrigger = m_testTracks.find("HLT_")!=std::string::npos || m_testTracks.find("EF_")!=std::string::npos;
274
275 if ( !isTrigger ) trackAnaStore.fillViewTest( m_testTracks );
276
280 std::vector<TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > selectedRois;
281
284 std::vector<TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > tagRois;
285
288 size_t selectedRoisSize = 1; // by default only one "dummy" RoI, i.e. for offline analysis
289
292
295 TrackRoiSelector roiFilter;
296
297 std::unique_ptr<TagNProbe> tnp = 0;
298
303
304 if ( !m_tagChain.empty() ) tnp = std::make_unique<TagNProbe>( m_minTagMass, m_maxTagMass );
305
310 if ( !m_triggerchain.empty() ) {
311 selectedRois = roiSelector.retrieveRois( m_triggerchain, m_rois );
312 selectedRoisSize = selectedRois.size();
313 }
314
318
321 std::unique_ptr<TrackAnalysisStore> tagStore = 0;
322
323 if ( tnp ) {
324
326
328 const std::vector<const TrackView*>* vref_ptr;
329
330 MY_MSG_DEBUG << "reftracks: " << m_refTracks << "\t:" << m_refTracks_tag << endmsg;
331
334 tagStore = std::make_unique<TrackAnalysisStore>( "tagstore", context );
335 tagStore->fillViewRef( m_refTracks_tag );
336 vref_ptr = &tagStore->reference_tracks();
337 }
338 else {
339 vref_ptr = &trackAnaStore.reference_tracks();
340 }
341
342 const std::vector<const TrackView*>& vref = *vref_ptr;
343
344 tagRois = roiSelector.retrieveRois( m_triggerchain_tag, m_roi_tag, m_leg_tag );
345
346 for ( auto roi : tagRois ) {
348 if( ! roi_link.isValid() ) continue;
349 std::vector<const TrackView*> v = roiFilter.getTracks( vref, *roi_link.cptr() );
351 tnp->append_tags( v.begin(), v.end(), *m_tnpPredicate.get() );
352 }
353
354 MY_MSG_DEBUG << "tnp size() : " << tnp->size() << "\t" << vref.size() << endmsg;
355
356#if 0
358 const std::vector<const TrackView*>& v = trackAnaStore.reference_tracks();
359 for ( size_t i=0 ; i<v.size() ; i++ ) {
360 bool ok = tnp->select( v[i] );
361 std::vector<double> m = tnp->masses( v[i] );
362 std::cout << "\ttnp: " << ok << "\tm: " << m.size() << m << "\t " << *v[i] << std::endl;
363 }
364#endif
365
366 }
367
377
378 TrackAnalysisStore roiStore( "roi", &m_tdt, context );
379 TrackAnalysisStore selectedStore( "selected", &m_tdt, context );
380
382 if ( !m_vertices.empty() && !m_refVertices.empty() ) selectedStore.fillVertexViewRef( m_refVertices );
383
385
386 // std::cout << "TrackAnalysis: ref vtx size: " << selectedStore.refvertices().size() << std::endl;
387
388 // const std::vector<const VertexView*> vtx = selectedStore.refvertices();
389
390 // for ( int iv=vtx.size() ; iv-- ; ) {
391 // if ( vtx[iv]->vertexType()!=0 ) std::cout << "\t" << iv << "\tvtx[" << iv << "]: " << *vtx[iv] << std::endl;
392 // }
393
397
398
402 if ( selectedStore.fillEventInfo( m_eventInfoName.key() ).isFailure() ) return false;
403
404 MY_MSG_DEBUG << "Processing event = " << selectedStore.eventInfo()->eventNumber() << endmsg;
405
406 for( size_t ir=selectedRoisSize ; ir-- ; ) {
407
408 MY_MSG_DEBUG << "\tRoi: " << ir << endmsg;
409
410 if( !m_triggerchain.empty() ) {
411
413 selectedStore.roiIndex(ir);
414
416 ElementLink<TrigRoiDescriptorCollection> roi_link = selectedRois[ir].link;
417
419 if( ! roi_link.isValid() ) {
420 MY_MSG_WARNING << "Found non-valid RoI ElementLink" << endmsg;
421 continue;
422 }
423
424 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
425
426 if ( !roiptr ) {
427 MY_MSG_WARNING << "could not fetch RoiDescriptor: " << m_rois << endmsg;
428 continue;
429 }
430
432 if ( isTrigger ) {
433
434 roiStore.fillViewTest( m_testTracks, roi_link );
435
439 if ( !m_vertices.empty() ) selectedStore.fillVertexViewTest( m_vertices, roi_link );
440
442 // const std::vector<const VertexView*> vtx = selectedStore.testvertices();
443
444 // for ( int iv=vtx.size() ; iv-- ; ) {
445 // std::cout << "\t\t" << iv << "\tvtx[" << iv << "]: " << *vtx[iv] << std::endl;
446 // }
447
448 // printtracks( roiStore.test_tracks(), "\nroiStore: test tracks" );
449 // if ( !m_vertices.empty() ) fillroivertices( roi_link, m_vertices );
450
451 // selectedStore.fill<VertexView,xAOD::VertexContainer>( selectedStore.testvertices(),
452 // roi_link, m_vertices );
453
454 }
455
457 // printtracks( trackAnaStore.test_tracks(), "test (should be ok - roi retrieve II)" );
458
465
466 roiStore.reference_tracks() = roiFilter.getTracks( trackAnaStore.reference_tracks(), *roiptr );
467
469
470 }
471 else {
473 roiStore.reference_tracks() = trackAnaStore.reference_tracks();
474 roiStore.test_tracks() = trackAnaStore.test_tracks();
475 }
476
477 // printtracks( roiStore.reference_tracks(), "\troiStore: reference" );
478 // printtracks( roiStore.test_tracks(), "\troiStore: test" );
479
480 MY_MSG_DEBUG << "SUTT: TrackSelection ..." << endmsg;
481
482 selectedStore.reference_tracks() = m_refSelector->selectTracks( roiStore.reference_tracks(), tnp.get() );
483
484 // printtracks( selectedStore.reference_tracks(), "\tselectedStore: reference" );
485
487 selectedStore.test_tracks() = m_testSelector->selectTracks( roiStore.test_tracks() );
488
489 // printtracks( selectedStore.test_tracks(), "\tselectedStore: test" );
490
492 // TDeltaRMatcher<const TrackView> matcher( "DeltaRMatcher", 0.1 ); /// FIXME: turn this hard coded parameter in to a job Property
493
494 std::unique_ptr<TIDA::Associator<const TrackView> > matcher = m_trackMatchingTool->uclone();
495
496 // MY_MSG_DEBUG << "n matched: " << matcher->size() << endmsg;
497
499 // matchertype mt = matcher.uclone();
500 matcher->match( selectedStore.reference_tracks(), selectedStore.test_tracks() );
501
502 // matcher.match( tref, ttest );
503
504 // MY_MSG_DEBUG << "SUTT: n matched: " << matcher->size() << endmsg;
505
506 selectedStore.set_matcher( matcher.get() );
507
508 TDeltaZMatcher<const VertexView> vertex_matcher( "DeltaZMatcher", 1.0 );
509
510 if ( !m_vertices.empty() ) {
511 vertex_matcher.match( selectedStore.refvertices(), selectedStore.testvertices() );
512 selectedStore.set_vertex_matcher( &vertex_matcher );
513 }
514
515 if ( tnp ) selectedStore.addTagNProbe( tnp.get() );
516
518 // selectedStore.refMap( trackAnaStore );
519
522
523 m_analysis->execute( selectedStore );
524
525 }
526
527 return true;
528
529}
530
531
536
537 MY_MSG_DEBUG << "Finalising plots" << endmsg;
538
540 // if( endOfRunFlag() ) m_analysis->finalize()
541
542 m_analysis->finalize();
543
544 MY_MSG_DEBUG << "Successfully finalized hists" << endmsg;
545
546 return StatusCode::SUCCESS;
547}
548
549
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
std::ostream & operator<<(std::ostream &s, const std::tuple< Tup... > &tup)
emacs: this is -*- c++ -*-
#define MY_MSG_DEBUG
Definition MsgMacros.h:25
#define MY_MSG_INFO
Definition MsgMacros.h:24
#define MY_MSG_WARNING
Definition MsgMacros.h:23
size_t size() const
Number of registered mappings.
emacs: this is -*- c++ -*-
void printtracks(const std::vector< const TrackView * > &ars, const std::string &sht="")
emacs: this is -*- c++ -*-
emacs: this is -*- c++ -*-
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual void match(const std::vector< T * > &ref, const std::vector< S * > &test)
Definition BestMatcher.h:68
const std::string & extra() const
Definition ChainString.h:38
const std::string & roi() const
Definition ChainString.h:35
const std::string & head() const
Definition ChainString.h:33
const std::string & tail() const
Definition ChainString.h:34
const std::string & vtx() const
Definition ChainString.h:36
const std::string & element() const
Definition ChainString.h:37
std::vector< roi_info_t > retrieveRois(const std::string &chainName, const std::string &roiKey, const int &chainLeg=-1) const
Retrieve RoIs.
void addTagNProbe(const TagNProbe *t)
const xAOD::EventInfo * eventInfo() const
get event info
void fillVertexViewTest(const std::string &key)
void setBeamKeys(const beam_key_t *k)
int roiIndex() const
odds n ends ...
void set_vertex_matcher(const TIDA::Associator< const VertexView > *m)
void fillVertexViewRef(const std::string &key)
vertex fillers ...
const std::vector< const TrackView * > & reference_tracks() const
void fillViewRef(const std::string &key)
track fillers ...
void set_matcher(const TIDA::Associator< const TrackView > *m)
const std::vector< const VertexView * > & testvertices() const
const std::vector< const TrackView * > & test_tracks() const
StatusCode fillEventInfo(const std::string &key)
const std::vector< const VertexView * > & refvertices() const
vertex accessors
void fillViewTest(const std::string &key)
virtual StatusCode fillHistograms(const EventContext &context) const
ToolHandle< TrackViewMatchingTool > m_trackMatchingTool
need to define a proper interface class
Gaudi::Property< ConfiguredValue< int > > m_refPdgId_tag
virtual StatusCode initialize() override
std::unique_ptr< AnalysisR4 > m_analysis
and the lightweight tool to actually fill them - could join this with the above montool,...
Gaudi::Property< std::string > m_reference
properties
bool m_initialized
and sensible internal variables we can set from the configuration ...
virtual ~TrackAnalysis()
Destructor.
SG::ReadDecorHandleKeyArray< xAOD::EventInfo > m_beamKeys
bool execute(const EventContext &context) const
finalise histograms in stop()
virtual StatusCode bookHistograms()
virtual StatusCode proc()
finalise histograms in stop()
std::unique_ptr< IPredicate< TrackView > > m_tnpPredicate
ToolHandle< IDTPM2::ITrackSelector > m_refSelector
tools
Gaudi::Property< std::vector< std::string > > m_fillers
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoName
read handles, but ...
ToolHandle< GenericMonitoringTool > m_tool
histogram montool - books the histograms in the python
doesn't actually need to be an algtool as it class variables, so requires no python configuration
std::vector< const T * > getTracks(const std::vector< const T * > &tracks, const TrigRoiDescriptor *roi) const
track getter function (for offline tracks || truth particles)
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
uint64_t eventNumber() const
The current event's event number.
int ir
counter of the current depth
Definition fastadd.cxx:49
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
STL namespace.