ATLAS Offline Software
Loading...
Searching...
No Matches
T_AnalysisConfig_Tier0.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
22
23#ifndef TrigInDetAnalysisExample_T_AnalysisConfig_Tier0_H
24#define TrigInDetAnalysisExample_T_AnalysisConfig_Tier0_H
25
26
30
35
36#include "TTree.h"
37#include "TFile.h"
38
39
40// McParticleEvent includes
42
44#include "AtlasHepMC/GenEvent.h"
47
48#include "EventInfo/EventInfo.h"
49#include "EventInfo/EventID.h"
51
52
53
55
57
63
64
66
69
71
74
75
76
77
78
79template<typename T>
81
82public:
83
84 // Full constructor: test/reference/selection
85 // - analysisInstanceName: the name of the analysis chain being created
86 // - xxxChainName: the name of the chain to be used as test/reference/selection; must be "StoreGate" in case of direct access to SG containers
87 // - xxxType: the type of tracks to be retrieved from the test/reference/selection chain or container
88 // - xxxKey: the key for tracks to be retrieved from the test/reference/selection chain or container
89 // - all standard operations are performed in loops over 0=test 1=reference 2=selection
90 T_AnalysisConfig_Tier0(const std::string& analysisInstanceName,
91 const std::string& testChainName, const std::string& testType, const std::string& testKey,
92 const std::string& referenceChainName, const std::string& referenceType, const std::string& referenceKey,
93 TrackFilter* testFilter, TrackFilter* referenceFilter,
94 TrackAssociator* associator,
96 T_AnalysisConfig<T>( analysisInstanceName,
97 testChainName, testType, testKey,
98 referenceChainName, referenceType, referenceKey,
99 testFilter, referenceFilter,
100 associator,
101 analysis ),
102 _analysis(0),
103 m_useBeamCondSvc(false),
104 m_doOffline(true),
105 m_doMuons(false),
106 m_doElectrons(false),
107 m_doTaus(false),
108 m_doBjets(false),
109 m_hasTruthMap(false),
110 m_doTauThreeProng(false),
111 m_tauEtCutOffline(false),
112 m_NRois(0),
113 m_NRefTracks(0),
114 m_NTestTracks(0),
115 m_runPurity(false),
116 m_shifter(false),
117 m_pTthreshold(0),
118 m_first(true),
119 m_containTracks(false)
120 {
121 m_event = new TIDA::Event();
122 m_chainNames.push_back(testChainName);
123
124#if 0
125 ChainString& chain = m_chainNames.back();
126
127 std::cout << "\nT_AnalysisConfig_Tier0::name: " << name() << "\t" << this << std::endl;
128 std::cout << "T_AnalysisConfig_Tier0::chain specification: " << testChainName << " -> " << chain << "\t" << chain.raw() << std::endl;
129 std::cout << "\tchain: " << chain.head() << std::endl;
130 std::cout << "\tkey: " << chain.tail() << std::endl;
131 std::cout << "\troi: " << chain.roi() << std::endl;
132 std::cout << "\tvtx: " << chain.vtx() << std::endl;
133 std::cout << "\tte: " << chain.element() << std::endl;
134
135 std::cout << "\tpost: " << chain.post() << std::endl;
136 std::cout << "\tpt: " << chain.postvalue("pt") << std::endl;
137
138 std::cout << "\tcontainTracks: " << m_containTracks << std::endl;
139#endif
140
141 m_testType = testType;
142 }
143
144 virtual ~T_AnalysisConfig_Tier0() { delete m_event; }
145
146 void setRunPurity( bool b ) { m_runPurity=b; }
147
148 void setShifter( bool b ) { m_shifter=b; }
149
150 void useBeamCondSvc( bool b ) { m_useBeamCondSvc = b; }
151
152 void containTracks( bool b ) { m_containTracks = b; }
153
154public:
155
157
159 // void verbose( std::ostream& s ) {
160 // if( m_provider->msg().level() <= MSG::VERBOSE ) m_provider->msg(MSG::VERBOSE) << s << endmsg;
161 // }
162
163protected:
164
168
169 using T_AnalysisConfig<T>::name;
171
176
177 // using T_AnalysisConfig<T>::selectTracks;
178
179 virtual void loop() {
180
181 if( m_provider->msg().level() <= MSG::VERBOSE) {
182 m_provider->msg(MSG::VERBOSE) << "AnalysisConfig_Tier0::loop() for " << T_AnalysisConfig<T>::m_analysisInstanceName << endmsg;
183 }
184
185 // get (offline) beam position
186 double xbeam = 0;
187 double ybeam = 0;
188
189 if ( m_first ) {
190
191 m_first = false;
192
193 m_provider->msg(MSG::VERBOSE) << " using beam position\tx=" << xbeam << "\ty=" << ybeam << endmsg;
194
195 if (m_provider->msg().level() <= MSG::VERBOSE) {
196
197 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
198
199 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
200 m_provider->msg(MSG::VERBOSE) << "Chain " << configuredChains[i] << endmsg;
201 }
202
203 }
204
205
206 std::vector<ChainString>::iterator chainitr = m_chainNames.begin();
207
208 std::vector<ChainString> chains;
209
213 while ( chainitr!=m_chainNames.end() ) {
214
216 ChainString& chainName = (*chainitr);
217
218 m_provider->msg(MSG::INFO) << "process chain " << chainName << endmsg;
219
220 if ( chainName.head() == "" ) {
221
222 std::string selectChain = chainName.raw();
223
224 chains.push_back( ChainString(selectChain) );
225
226 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
227 m_provider->msg(MSG::VERBOSE) << "Matching chain " << selectChain << " (" << chainName.head() << ")" << endmsg;
228 }
229
230 }
231 else {
232
234 std::vector<std::string> selectChains = (*(m_tdt))->getListOfTriggers( chainName.head() );
235
236
237 for ( unsigned iselected=0 ; iselected<selectChains.size() ; iselected++ ) {
238
239 selectChains[iselected] = chainName.subs( selectChains[iselected] );
240
241#if 0
242 std::cout << "sorting:: chain specification: " << chainName << "\traw:" << chainName.raw() << std::endl;
243 std::cout << "\tchain: " << chainName.head() << std::endl;
244 std::cout << "\tkey: " << chainName.tail() << std::endl;
245 std::cout << "\troi: " << chainName.roi() << std::endl;
246 std::cout << "\tvtx: " << chainName.vtx() << std::endl;
247 std::cout << "\tte: " << chainName.element() << std::endl;
248 std::cout << "\tind: " << chainName.extra() << std::endl;
249#endif
250
252 chains.push_back( ChainString(selectChains[iselected]) );
253
254 if(m_provider->msg().level() <= MSG::VERBOSE) {
255 m_provider->msg(MSG::VERBOSE) << "Matching chain " << selectChains[iselected] << " (" << chainName.head() << ")" << endmsg;
256 }
257
258 }
259 }
260
261 ++chainitr;
262 }
263
264 // m_chainNames.insert( m_chainNames.end(), chains.begin(), chains.end() );
265 m_chainNames = chains;
266
267 for ( unsigned ic=0 ; ic<m_chainNames.size() ; ic++ ) m_provider->msg(MSG::VERBOSE) << "Analyse chain " << m_chainNames[ic] << endmsg;
268
269 }
270
271
273 Filter_True filter;
274
275 Filter_etaPT filter_etaPT(5,200);
276 Filter_Combined filter_truth( &filter_etaPT, &filter_etaPT);
277
279 // Filter_Combined filterRef (&filter_offline, &filter_vertex);
280
281 int iRefFilter = 1;
282 int iTestFilter = 0;
283
284 if ( m_runPurity ) {
285 iRefFilter = 0;
286 iTestFilter = 1;
287 }
288
289 Filter_Combined filterRef( m_filters[iRefFilter][0], &filter );
290 Filter_Combined filterTest( m_filters[iTestFilter][0], &filter );
291
292 TrigTrackSelector selectorTruth( &filter_truth );
293 TrigTrackSelector selectorRef( &filterRef );
294 m_selectorRef = &selectorRef;
295 TrigTrackSelector selectorTest( &filterTest );
296 m_selectorTest = &selectorTest;
297
298 if ( xbeam!=0 || ybeam!=0 ) {
299 m_selectorRef->setBeamline( xbeam, ybeam );
300 }
301
303
304 // clear the ntuple TIDA::Event class
305 m_event->clear();
306
308#ifndef XAODTRACKING_TRACKPARTICLE_H
309 const EventInfo* pEventInfo;
310#else
311 const xAOD::EventInfo* pEventInfo;
312#endif
313 unsigned run_number = 0;
314 uint64_t event_number = 0;
315 unsigned lumi_block = 0;
316 unsigned bunch_crossing_id = 0;
317 unsigned time_stamp = 0;
318 double mu_val = 0;
319
320 if ( this->template retrieve(pEventInfo, "EventInfo").isFailure() ) {
321 m_provider->msg(MSG::WARNING) << "Failed to get EventInfo " << endmsg;
322 } else {
323
324#ifndef XAODTRACKING_TRACKPARTICLE_H
325 run_number = pEventInfo->event_ID()->run_number();
326 event_number = pEventInfo->event_ID()->event_number();
327 lumi_block = pEventInfo->event_ID()->lumi_block();
328 time_stamp = pEventInfo->event_ID()->time_stamp();
329 bunch_crossing_id = pEventInfo->event_ID()->bunch_crossing_id();
330 mu_val = pEventInfo->averageInteractionsPerCrossing();
331#else
332 run_number = pEventInfo->runNumber();
333 event_number = pEventInfo->eventNumber();
334 lumi_block = pEventInfo->lumiBlock();
335 time_stamp = pEventInfo->timeStamp();
336 bunch_crossing_id = pEventInfo->bcid();
337 mu_val = pEventInfo->averageInteractionsPerCrossing();
338#endif
339 }
340
341 if(m_provider->msg().level() <= MSG::VERBOSE){
342 m_provider->msg(MSG::VERBOSE) << "run " << run_number
343 << "\tevent " << event_number
344 << "\tlb " << lumi_block << endmsg;
345 }
346
347 // m_provider->msg(MSG::INFO) << "run " << run_number
348 // << "\tevent " << event_number
349 // << "\tlb " << lumi_block << endmsg;
350
351 // std::cout << "run " << run_number << "\tevent " << event_number << "\tlb " << lumi_block << std::endl;
352
353
354 // clear the ntuple TIDA::Event class
355 m_event->clear();
356
357 m_event->run_number(run_number);
358 m_event->event_number(event_number);
359 m_event->lumi_block(lumi_block);
360 m_event->time_stamp(time_stamp);
361 m_event->bunch_crossing_id(bunch_crossing_id);
362 m_event->mu(mu_val);
363
366
367 bool analyse = false;
368
369 // Check HLTResult
370
371 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
372
373 const std::string& chainname = m_chainNames[ichain].head();
374
375 if ( chainname == "" ) analyse = true;
376 else {
377
378 //Only for trigger chains
379 if ( chainname.find("L2") == std::string::npos &&
380 chainname.find("EF") == std::string::npos &&
381 chainname.find("HLT") == std::string::npos ) continue;
382
383 if ( m_provider->msg().level() <= MSG::DEBUG ) {
384 m_provider->msg(MSG::DEBUG) << "Chain " << chainname
385 << "\tpass " << (*m_tdt)->isPassed(chainname)
386 << "\tpres " << (*m_tdt)->getPrescale(chainname) << endmsg;
387 }
388
389 // std::cout << "Chain " << chainname << "\tpass " << (*m_tdt)->isPassed(chainname)
390 // << "\tpres " << (*m_tdt)->getPrescale(chainname) << std::endl;
391
392 if ( (*(m_tdt))->isPassed(chainname) || (*(m_tdt))->getPrescale(chainname) ) analyse = true;
393
394 }
395 }
396
397 // Remove this code to skip on truncated HLT results
398 // Need to leave the code here for the time being however, since we will
399 // still need in the future a more robust test to achieve this same
400 // functionality
401 //
402 // if ( (*m_tdt)->ExperimentalAndExpertMethods().isHLTTruncated() ) {
403 // m_provider->msg(MSG::WARNING) << "HLTResult truncated, skipping event" << endmsg;
404 // return;
405 // }
406
407 if ( !this->m_keepAllEvents && !analyse ) {
408 // m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg;
409 if(m_provider->msg().level() <= MSG::VERBOSE)
410 m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg;
411 return;
412 }
413
415
416 selectorTruth.clear();
417
418 if(m_provider->msg().level() <= MSG::VERBOSE)
419 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
420
421 if ( m_mcTruth && m_provider->msg().level() <= MSG::VERBOSE ) m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
422
423
425
426 std::vector<TIDA::Vertex> vertices;
427 std::vector<TIDA::Vertex> vertices_rec;
428
429 std::vector<double> refbeamspot;
430 std::vector<double> testbeamspot;
431
432
433
434#ifndef XAODTRACKING_TRACKPARTICLE_H
435
436 const VxContainer* primaryVtxCollection;
437
438 if ( m_doOffline ) {
439 if ( m_provider->evtStore()->template contains<VxContainer>("VxPrimaryCandidate") ) {
440 if ( this->template retrieve(primaryVtxCollection, "VxPrimaryCandidate").isFailure()) {
441 if (m_provider->msg().level() <= MSG::WARNING) m_provider->msg(MSG::WARNING) << "Primary vertex container not found" << endmsg;
442 }
443 else {
444 VxContainer::const_iterator vtxitr = primaryVtxCollection->begin();
445 for ( ; vtxitr != primaryVtxCollection->end(); ++vtxitr) {
446 if ( (*vtxitr)->vxTrackAtVertex()->size()>0 ) {
447 vertices.push_back( TIDA::Vertex( (*vtxitr)->recVertex().position().x(),
448 (*vtxitr)->recVertex().position().y(),
449 (*vtxitr)->recVertex().position().z(),
450 0,0,0,
451 (*vtxitr)->vxTrackAtVertex()->size() ) );
452 }
453 }
454 }
455
456 // filter_vertex.setVertex(vertices);
457 }
458 }
459
460#else
461
462 //std::vector<TIDA::Vertex> vertices;
463
464 m_provider->msg(MSG::VERBOSE) << "fetching AOD Primary vertex container" << endmsg;
465
466 const xAOD::VertexContainer* xaodVtxCollection = 0;
467
468 if ( this->template retrieve( xaodVtxCollection, "PrimaryVertices" ).isFailure()) {
469 if (m_provider->msg().level() <= MSG::WARNING) m_provider->msg(MSG::WARNING) << "xAOD Primary vertex container not found with key " << "PrimaryVertices" << endmsg;
470 }
471
472 if ( xaodVtxCollection!=0 ) {
473
474 m_provider->msg(MSG::VERBOSE) << "xAOD Primary vertex container " << xaodVtxCollection->size() << " entries" << endmsg;
475
476 xAOD::VertexContainer::const_iterator vtxitr = xaodVtxCollection->begin();
477 for ( ; vtxitr != xaodVtxCollection->end(); ++vtxitr ) {
478 if ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) {
479 vertices.push_back( TIDA::Vertex( (*vtxitr)->x(),
480 (*vtxitr)->y(),
481 (*vtxitr)->z(),
483 (*vtxitr)->covariancePosition()(Trk::x,Trk::x),
484 (*vtxitr)->covariancePosition()(Trk::y,Trk::y),
485 (*vtxitr)->covariancePosition()(Trk::z,Trk::z),
486 (*vtxitr)->nTrackParticles(),
488 (*vtxitr)->chiSquared(),
489 (*vtxitr)->numberDoF() ) );
490 }
491 }
492 }
493
494
495#endif
496
497
499
500 if ( m_mcTruth ) {
501 m_event->addChain( "Truth" );
502 m_event->back().addRoi(TIDARoiDescriptor());
503 m_event->back().back().addTracks(selectorTruth.tracks());
504 }
505
507
508 if ( m_doOffline ) {
509 for ( unsigned i=0 ; i<vertices.size() ; i++ ) {
510 if(m_provider->msg().level() <= MSG::VERBOSE)
511 m_provider->msg(MSG::VERBOSE) << "vertex " << i << " " << vertices[i] << endmsg;
512 m_event->addVertex(vertices[i]);
513 }
514 }
515
517
518 // int Noff = 0;
519 std::vector<TIDA::Track*> offline_tracks;
520 std::vector<TIDA::Track*> electron_tracks;
521 std::vector<TIDA::Track*> muon_tracks;
522
523 std::vector<TIDA::Track*> ref_tracks;
524 std::vector<TIDA::Track*> test_tracks;
525
526 offline_tracks.clear();
527 electron_tracks.clear();
528 muon_tracks.clear();
529
530 ref_tracks.clear();
531 test_tracks.clear();
532
534 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
535
536 test_tracks.clear();
537
539
540 // std::string& chainname = chains[ichain];
541 const std::string& chainname = m_chainNames[ichain].head();
542 const std::string& key = m_chainNames[ichain].tail();
543 const std::string& vtx_name = m_chainNames[ichain].vtx();
544 //no currently used but retained in case
545 //const std::string& roi_name = m_chainNames[ichain].roi();
546 //const std::string& te_name = m_chainNames[ichain].element();
547
548 m_pTthreshold = 0;
549
550 if ( m_chainNames[ichain].postcount() ) {
551 std::string ptvalue = m_chainNames[ichain].postvalue("pt");
552 if ( ptvalue!="" ) m_pTthreshold = std::stod(ptvalue);
553 }
554
555 // std::cout << "\tchain " << m_chainNames[ichain] << "\tchainname " << chainname << "\tvtx " << vtx_name << "\troi " << roi_name << std::endl;
556
557 unsigned _decisiontype = TrigDefs::Physics;
558 unsigned decisiontype;
559
560 if ( this->requireDecision() ) _decisiontype = TrigDefs::requireDecision;
561
562
563 if ( m_chainNames[ichain].passed() ) decisiontype = _decisiontype;
564 else decisiontype = TrigDefs::alsoDeactivateTEs;
565
566 if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) {
567
568 m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname
569 << "\tpass " << (*m_tdt)->isPassed(chainname)
570 << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg;
571
572 m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg;
573
574 m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg;
575 }
576
577 // std::cout << "\tstatus for chain " << chainname
578 // << "\tpass " << (*m_tdt)->isPassed( chainname )
579 // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype )
580 // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl;
581
582
583 // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg;
584
585
586 if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue;
587
590 // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs);
591
594
595 ChainString& chainConfig = m_chainNames[ichain];
596
597 std::string chainName = chainConfig.head();
598
599 m_event->addChain( chainConfig );
600
601 TIDA::Chain& chain = m_event->back();
602
603 if ( chainName == "" ) {
604
605 m_selectorTest->clear();
606
608
609 TIDARoiDescriptor* roiInfo = new TIDARoiDescriptor(true);
610
611 chain.addRoi( *roiInfo );
612
613
614# ifdef XAODTRACKING_TRACKPARTICLE_H
615 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(key) ) {
617 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( key );
618 }
619# endif
620
621 const std::vector<TIDA::Track*>& testtracks = m_selectorTest->tracks();
622
623 chain.back().addTracks(testtracks);
624
625 delete roiInfo;
626
627 }
628 else {
629
630 Trig::FeatureContainer f = (*m_tdt)->features( chainname, decisiontype );
631 Trig::FeatureContainer::combination_const_iterator c(f.getCombinations().begin());
632 Trig::FeatureContainer::combination_const_iterator cEnd(f.getCombinations().end());
633
634
635 if ( c==cEnd ) {
636 if(m_provider->msg().level() <= MSG::VERBOSE){
637 m_provider->msg(MSG::VERBOSE) << "No combinations: skipping this chain " << chainname << endmsg;
638 }
639 continue;
640 }
641
642 if(m_provider->msg().level() <= MSG::VERBOSE) {
643 m_provider->msg(MSG::VERBOSE) << "combinations for chain " << chainname << " " << (cEnd-c) << endmsg;
644 }
645
646 unsigned icomb = 0;
647
648 for( ; c!=cEnd ; ++c ) {
649
650 icomb++;
651
652 // now add rois to this ntuple chain
653
654 // Get seeding RoI
655 // std::vector< Trig::Feature<TrigRoiDescriptor> > initRois = c->get<TrigRoiDescriptor>("initialRoI", TrigDefs::alsoDeactivateTEs);
656 // std::vector< Trig::Feature<TrigRoiDescriptor> > initRois = c->get<TrigRoiDescriptor>("forID", TrigDefs::alsoDeactivateTEs);
657
658 std::vector< Trig::Feature<TrigRoiDescriptor> > initRois;
659
660 std::string roi_key = m_chainNames[ichain].roi();
661
662 if ( roi_key=="SuperRoi" && icomb>1 ) continue;
663
664 if ( roi_key!="" ) {
665 initRois = c->get<TrigRoiDescriptor>(roi_key, decisiontype );
666 }
667 else {
668 initRois = c->get<TrigRoiDescriptor>("forID", decisiontype );
669 if ( initRois.empty() ) initRois = c->get<TrigRoiDescriptor>("", decisiontype );
670 if ( initRois.empty() ) initRois = c->get<TrigRoiDescriptor>("initialRoI", decisiontype );
671 }
672
673 // std::cout << "initRois.size() " << initRois.size() << std::endl;
674
675 if ( initRois.empty() ) continue;
676
677
678 // for ( unsigned ir=0 ; ir<initRois.size() ; ir++ ) {
679 // std::cout << "\t" << ir << "\t" << *initRois[ir].cptr() << std::endl;
680 // }
681
682 // Skip chains seeded by multiple RoIs: not yet implemented
683 if(initRois.size()>1 && roi_key!="SuperRoi" ) {
684 if(m_provider->msg().level() <= MSG::VERBOSE)
685 m_provider->msg(MSG::VERBOSE) << " More than one initial RoI found for seeded chain " << chainname << ": not yet supported" << endmsg;
686 continue;
687 }
688
689 TIDARoiDescriptor* roiInfo = 0;
690
691 if( !initRois.empty() ) {
692 const TrigRoiDescriptor* roid = initRois[0].cptr();
693
694 if(m_provider->msg().level() <= MSG::VERBOSE)
695 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << *roid << endmsg;
696
697 roiInfo = new TIDARoiDescriptor(TIDARoiDescriptorBuilder(*roid));
698 // roiInfo->etaHalfWidth(m_roiInfo->etaHalfWidth());
699 // roiInfo->phiHalfWidth(m_roiInfo->phiHalfWidth());
700 // roiInfo->etaHalfWidth(roid->etaHalfWidth());
701 // roiInfo->phiHalfWidth(roid->phiHalfWidth());
702 // roiInfo->zedHalfWidth(roid->zedHalfWidth());
703
704 if(m_provider->msg().level() <= MSG::VERBOSE)
705 m_provider->msg(MSG::VERBOSE) << "using chain roi " << *roid << endmsg;
706
707 }
708 else {
709 roiInfo = new TIDARoiDescriptor();
710 // roiInfo->etaHalfWidth(5);
711 // roiInfo->phiHalfWidth(M_PI);
712 // roiInfo->zedHalfWidth(m_roiInfo->zedHalfWidth());
713
714 if(m_provider->msg().level() <= MSG::WARNING)
715 m_provider->msg(MSG::WARNING) << "roi not found" << endmsg;
716
717 }
718
719 if(m_provider->msg().level() <= MSG::VERBOSE) m_provider->msg(MSG::VERBOSE) << *roiInfo << endmsg;
720
721 m_selectorTest->clear();
722
723 m_provider->msg(MSG::VERBOSE) << "Searching for collection " << key << endmsg;
724 // std::cout << "Searching for collection " << key << std::endl;
725
727 if ( key.find("InDetTrigParticleCreation")!=std::string::npos ||
728 key.find("_IDTrig")!=std::string::npos ||
729 key.find("_EFID")!=std::string::npos ||
730 chainName.find("EF_")!=std::string::npos ||
731 chainName.find("HLT_")!=std::string::npos ) {
732# ifdef XAODTRACKING_TRACKPARTICLE_H
733 if ( this->template selectTracks<xAOD::TrackParticleContainer>( m_selectorTest, c, key ) ) testbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( c, key );
734 else if ( this->template selectTracks<Rec::TrackParticleContainer>( m_selectorTest, c, key ) );
735# else
736 if ( this->template selectTracks<Rec::TrackParticleContainer>( m_selectorTest, c, key ) );
737# endif
738 else if ( this->template selectTracks<TrackCollection>( m_selectorTest, c, key ) );
739 else {
740 //m_provider->msg(MSG::WARNING) << "No track collection " << key << " found" << endmsg;
741 }
742 }
743 else {
745 if ( chainName.find("L2_")!=std::string::npos ) {
746 if ( this->template selectTracks<Rec::TrackParticleContainer>( m_selectorTest, c, key ) );
747 else if ( this->template selectTracks<TrackCollection>( m_selectorTest, c, key ) );
748# ifdef XAODTRACKING_TRACKPARTICLE_H
749 else if ( this->template selectTracks<xAOD::TrackParticleContainer>( m_selectorTest, c, key ) ) testbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( c, key );
750# endif
751 else m_provider->msg(MSG::WARNING) << "No track collection " << key << " found" << endmsg;
752 }
753 }
754
755
756 const std::vector<TIDA::Track*>& testtracks = m_selectorTest->tracks();
757
758 m_provider->msg(MSG::VERBOSE) << "test tracks.size() " << testtracks.size() << endmsg;
759 // std::cout << "test tracks.size() " << testtracks.size() << std::endl;
760
761 // std::cout << "\ttest tracks.size() " << testtracks.size() << std::endl;
762
763 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
764 m_provider->msg(MSG::VERBOSE) << "test tracks.size() " << testtracks.size() << endmsg;
765 for ( int ii=testtracks.size() ; ii-- ; ) {
766 m_provider->msg(MSG::VERBOSE) << " test track " << ii << " " << *testtracks[ii] << endmsg;
767 //test_tracks.push_back(testtracks.at(ii));
768 }
769 }
770
771 chain.addRoi( *roiInfo );
772
773 chain.back().addTracks(testtracks);
774
775 delete roiInfo;
776
778
780
781 // std::cout << "vertex " << vtx_name << "\tchain " << chainName << "\tconfig " << chainConfig << std::endl;
782
783 if ( vtx_name!="" ) {
784
785 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer for chain " << chainConfig << " with key " << vtx_name << endmsg;
786
787 std::vector< Trig::Feature<xAOD::VertexContainer> > xaodtrigvertices = c->get<xAOD::VertexContainer>(vtx_name);
788
789 if ( xaodtrigvertices.empty() ) {
790 if ( m_provider->msg().level() <= MSG::DEBUG ) {
791 m_provider->msg(MSG::WARNING) << "\tNo xAOD::VertexContainer for chain " << chainConfig << " for key " << vtx_name << endmsg;
792 }
793 }
794 else {
795
796 m_provider->msg(MSG::VERBOSE) << "\txAOD::VertexContainer found with size " << xaodtrigvertices.size() << "\t" << vtx_name << endmsg;
797
798 for ( unsigned iv=0 ; iv<xaodtrigvertices.size() ; iv++ ) {
799
800 const xAOD::VertexContainer* vert = xaodtrigvertices[iv].cptr();
801
802 m_provider->msg(MSG::VERBOSE) << "\t" << iv << " xAOD VxContainer for " << chainConfig << " " << vert << " key " << vtx_name << endmsg;
803
805
806 for ( ; vtxitr != vert->end(); ++vtxitr) {
809 // if ( ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) || vtx_name=="EFHistoPrmVtx" ) {
810 if ( (*vtxitr)->vertexType()!=0 || vtx_name=="EFHistoPrmVtx" ) {
811 chain.back().addVertex( TIDA::Vertex( (*vtxitr)->x(),
812 (*vtxitr)->y(),
813 (*vtxitr)->z(),
815 (*vtxitr)->covariancePosition()(Trk::x,Trk::x),
816 (*vtxitr)->covariancePosition()(Trk::y,Trk::y),
817 (*vtxitr)->covariancePosition()(Trk::z,Trk::z),
818 (*vtxitr)->nTrackParticles(),
820 (*vtxitr)->chiSquared(),
821 (*vtxitr)->numberDoF() ) );
822
823 }
824 }
825 }
826
827 }
828
829 }
830
831 }
832
833 }
834
835
836 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
837 m_provider->msg(MSG::VERBOSE) << "event: " << *m_event << endmsg;
838 }
839
841
842 for ( unsigned iroi=0 ; iroi<chain.size() ; iroi++ ) {
843
844 m_selectorRef->clear();
845
846 if ( this->filterOnRoi() ) {
847 filterRef.setRoi( &chain.rois().at(iroi).roi() );
848 filterRef.containtracks( m_containTracks );
849 }
850 else filterRef.setRoi( 0 );
851
852 test_tracks.clear();
853
854
868
869 if ( m_provider->msg().level() <= MSG::VERBOSE )
870 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
871
872 bool foundTruth = false;
873
874 if ( !m_doOffline && m_mcTruth ) {
875
876 if ( this->filterOnRoi() ) filter_truth.setRoi( &chain.rois().at(iroi).roi() );
877 else filter_truth.setRoi( 0 ); // don't filter on RoI unless needed
878
879 selectorTruth.clear();
880
881 if ( m_provider->msg().level() <= MSG::VERBOSE )
882 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
883
884 if ( m_provider->evtStore()->template contains<TruthParticleContainer>("INav4MomTruthEvent") ) {
885 //ESD
886 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "INav4MomTruthEvent" );
887 foundTruth = true;
888 }
889 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("SpclMC") ) {
891 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "SpclMC");
892 foundTruth = true;
893 }
894 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("") ) {
896 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "");
897 foundTruth = true;
898 }
899 else
900 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
901 m_provider->msg(MSG::VERBOSE) << "Truth not found - none whatsoever!" << endmsg;
902 }
903 }
904
905
906 if ( !m_doOffline && m_mcTruth && !foundTruth ) {
907
908 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
909 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
910 }
911
913
915 const McEventCollection* mcevent = 0;
916
918
919 std::string keys[4] = { "GEN_AOD", "TruthEvent", "", "G4Truth" };
920
921 std::string key = "";
922
923 bool foundcollection = false;
924
925 for ( int ik=0 ; ik<4 ; ik++ ) {
926
927 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
928 m_provider->msg(MSG::VERBOSE) << "Try McEventCollection: " << keys[ik] << endmsg;
929 }
930
931 if ( !m_provider->evtStore()->template contains<McEventCollection>(keys[ik]) ) {
932 if( m_provider->msg().level() <= MSG::VERBOSE )
933 m_provider->msg(MSG::VERBOSE) << "No McEventCollection: " << keys[ik] << endmsg;
934 continue;
935 }
936
937 if ( m_provider->msg().level() <= MSG::VERBOSE )
938 m_provider->msg(MSG::VERBOSE) << "evtStore()->retrieve( mcevent, " << keys[ik] << " )" << endmsg;
939
940 if ( this->template retrieve( mcevent, keys[ik] ).isFailure() ) {
941 if ( m_provider->msg().level() <= MSG::VERBOSE )
942 m_provider->msg(MSG::VERBOSE) << "Failed to get McEventCollection: " << keys[ik] << endmsg;
943 }
944 else {
946 key = keys[ik];
947 if(m_provider->msg().level() <= MSG::VERBOSE)
948 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << endmsg;
949 foundcollection = true;
950 break;
951 }
952 }
953
955 if ( !foundcollection ) {
956 if(m_provider->msg().level() <= MSG::VERBOSE)
957 m_provider->msg(MSG::WARNING) << "No MC Truth Collections of any sort, whatsoever!!!" << endmsg;
958
959 // m_tree->Fill();
960 // return StatusCode::FAILURE;
961
962 return;
963 }
964
965 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
966 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << "\tNevents " << mcevent->size() << endmsg;
967 }
968
969 McEventCollection::const_iterator evitr = mcevent->begin();
970 McEventCollection::const_iterator evend = mcevent->end();
971
972 unsigned ie = 0;
973 unsigned ip = 0;
974
975 unsigned ie_ip = 0;
976
977 while ( evitr!=evend ) {
978
979 int _ip = 0;
980
981 int pid = HepMC::signal_process_id((*evitr));
982
983 //The logic should be clarified here
984 if ( pid!=0 ) {
985
986 for (auto pitr: *(*evitr)) {
987
988 selectorTruth.selectTrack( pitr );
989
990 ++_ip;
991
992 }
993
994 }
995 ++ie;
996 ++evitr;
997
998 if ( _ip>0 ) {
1000 // m_provider->msg(MSG::VERBOSE) << "Found " << ie << "\tpid " << pid << "\t with " << ip << " TruthParticles (GenParticles)" << endmsg;
1001 ++ie_ip;
1002 ip += _ip;
1003 }
1004 }
1005
1006 if(m_provider->msg().level() <= MSG::VERBOSE){
1007 m_provider->msg(MSG::VERBOSE) << "Found " << ip << " TruthParticles (GenParticles) in " << ie_ip << " GenEvents out of " << ie << endmsg;
1008 m_provider->msg(MSG::VERBOSE) << "selected " << selectorTruth.size() << " TruthParticles (GenParticles)" << endmsg;
1009 }
1010
1011 if(selectorTruth.size() > 0) foundTruth = true;
1012
1013 if ( !(ip>0) ) {
1014 if (m_provider->msg().level() <= MSG::VERBOSE) m_provider->msg(MSG::WARNING) << "NO TRUTH PARTICLES - returning" << endmsg;
1015 return;
1016 }
1017
1018 }
1019
1021
1022 // m_provider->msg(MSG::VERBOSE) << " Offline tracks " << endmsg;
1023
1024 if ( m_doOffline ) {
1025
1026# ifdef XAODTRACKING_TRACKPARTICLE_H
1027 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>("InDetTrackParticles") ) {
1028 this->template selectTracks<xAOD::TrackParticleContainer>( m_selectorRef, "InDetTrackParticles" );
1029 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( "InDetTrackParticles" );
1030 }
1031 else if (m_provider->evtStore()->template contains<Rec::TrackParticleContainer>("TrackParticleCandidate") ) {
1032 this->template selectTracks<Rec::TrackParticleContainer>( m_selectorRef, "TrackParticleCandidate" );
1033 }
1034# else
1035 if (m_provider->evtStore()->template contains<Rec::TrackParticleContainer>("TrackParticleCandidate") ) {
1036 this->template selectTracks<Rec::TrackParticleContainer>( m_selectorRef, "TrackParticleCandidate" );
1037 }
1038# endif
1039 else if ( m_provider->msg().level() <= MSG::WARNING ) {
1040 m_provider->msg(MSG::WARNING) << " Offline tracks not found " << endmsg;
1041 }
1042
1043 ref_tracks = m_selectorRef->tracks();
1044
1045 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1046 m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << m_selectorRef->tracks().size() << endmsg;
1047 for ( int ii=m_selectorRef->tracks().size() ; ii-- ; ) {
1048 m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *m_selectorRef->tracks()[ii] << endmsg;
1049 }
1050 }
1051
1052 }
1053 else {
1055 if ( m_mcTruth && foundTruth ){
1056 ref_tracks=selectorTruth.tracks();
1057 }
1058 }
1059
1060
1061
1062 test_tracks.clear();
1063
1064 for ( unsigned itrk=0 ; itrk<chain.rois().at(iroi).tracks().size() ; itrk++ ) {
1065 test_tracks.push_back(&(chain.rois().at(iroi).tracks().at(itrk)));
1066 }
1067
1068
1069 // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl;
1070
1071 _analysis->setvertices( vertices.size() );
1072
1073 if ( refbeamspot.size()>0 ) _analysis->setBeamRef( refbeamspot );
1074 if ( testbeamspot.size()>0 ) _analysis->setBeamTest( testbeamspot );
1075
1078
1079 if ( m_runPurity ) {
1080
1081 if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks );
1082
1083 if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold );
1084
1086 m_NRois++;
1087 m_NRefTracks += test_tracks.size();
1088 m_NTestTracks += ref_tracks.size();
1089
1091 m_associator->match( test_tracks, ref_tracks );
1092
1093 _analysis->execute( test_tracks, ref_tracks, m_associator );
1094
1095 }
1096 else {
1097
1099
1100 if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks );
1101
1103
1104 if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold );
1105
1107 m_NRois++;
1108 m_NRefTracks += ref_tracks.size();
1109 m_NTestTracks += test_tracks.size();
1110
1112 m_associator->match( ref_tracks, test_tracks );
1113
1114 // std::cout << "SUTT: execute : N tracks " << ref_tracks.size() << " " << test_tracks.size() << std::endl;
1115
1116 _analysis->setroi( &chain.rois().at(iroi).roi() );
1117 _analysis->execute( ref_tracks, test_tracks, m_associator );
1118
1119 // std::cout << "chain " << m_chainNames[ichain] << " " << "\tvtx name " << vtx_name << std::endl;
1120
1121 if ( vtx_name!="" ) {
1123 std::vector<TIDA::Vertex> vr = chain.rois().at(iroi).vertices();
1124 std::vector<TIDA::Vertex*> vtx_rec;
1125 for ( unsigned iv=0 ; iv<vr.size() ; iv++ ) vtx_rec.push_back( &vr[iv] );
1126
1127 std::vector<TIDA::Vertex*> vtx;
1128 if ( this->getVtxIndex()<0 ) {
1129 for ( unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1130 }
1131 else {
1132 if ( vertices.size()>unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] );
1133 }
1134
1135 _analysis->execute_vtx( vtx, vtx_rec, m_event );
1136 }
1137
1138 }
1139
1140 if ( _analysis->debug() ) {
1141 m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain]
1142 << "\trun " << run_number
1143 << "\tevent " << event_number
1144 << "\tlb " << lumi_block << endmsg;
1145 }
1146
1147 }
1148
1149 }
1150
1151 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1152 m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *m_event << endmsg;
1153 }
1154 }
1155
1156
1157
1158 virtual void book() {
1159
1160 if(m_provider->msg().level() <= MSG::VERBOSE)
1161 m_provider->msg(MSG::VERBOSE) << "AnalysisConfig_Tier0::book() " << name() << endmsg;
1162
1163 m_provider->msg(MSG::ERROR) << "AnalysisConfig_Tier0::book() should no longer ever be called: " << name() << endmsg;
1164
1165 }
1166
1167
1168
1169 virtual void finalize() {
1170
1171 if(m_provider->msg().level() <= MSG::VERBOSE)
1172 m_provider->msg(MSG::VERBOSE) << "AnalysisConfig_Tier0::finalise() " << m_provider->name() << endmsg;
1173
1174 m_analysis->finalise();
1175
1176 m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg;
1177
1178 if(m_provider->msg().level() <= MSG::VERBOSE)
1179 m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg;
1180
1181 }
1182
1183
1184protected:
1185
1187
1189
1190 std::vector<ChainString> m_chainNames;
1191 std::vector<Analysis_Tier0*> m_analyses;
1192 std::string m_testType;
1193
1202
1203 std::string m_outputFileName;
1204
1209
1211
1213
1215
1217
1219
1220};
1221
1222
1223
1224#endif // TrigInDetAnalysisExample_T_AnalysisConfig_Tier0_H
1225
#define endmsg
Erkcan's track matchers.
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
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
size_t size() const
Number of registered mappings.
Basic event class to contain a vector of chains for trigger analysis.
useful tool for the TrigInDetAnalysis class code
void HighestPTOnly(std::vector< T * > &tracks)
Definition TIDATools.h:20
void FilterPT(std::vector< T * > &tracks, double pt)
Definition TIDATools.h:41
TIDA::Associator< TIDA::Track > TrackAssociator
virtual void execute_vtx(const std::vector< TIDA::Vertex * > &vtx0, const std::vector< TIDA::Vertex * > &vtx1, const TIDA::Event *tevt=0)
const std::string & extra() const
Definition ChainString.h:38
const std::string & roi() const
Definition ChainString.h:35
std::string subs(std::string s) const
const std::string & raw() const
Definition ChainString.h:42
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
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
EventID * event_ID()
the unique identification of the event.
float averageInteractionsPerCrossing() const
average interactions per crossing for all BCIDs - for out-of-time pile-up
void setRoi(TIDARoiDescriptor *r)
Definition Filters.h:236
void containtracks(bool b=true)
set / unset the flag to determine whether tracks should be fully contained in the RoI or not
Definition Filters.h:242
default simple filter which accepts all tracks
Definition Filters.h:26
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Describes the Region of Interest geometry It has basically 8 parameters.
std::vector< ChainString > m_chainNames
T_AnalysisConfig_Tier0(const std::string &analysisInstanceName, const std::string &testChainName, const std::string &testType, const std::string &testKey, const std::string &referenceChainName, const std::string &referenceType, const std::string &referenceKey, TrackFilter *testFilter, TrackFilter *referenceFilter, TrackAssociator *associator, TrackAnalysis *analysis)
std::vector< Analysis_Tier0 * > m_analyses
const TrackAnalysis * analysis() const
TrackAnalysis * m_analysis
const std::string & name() const
TrigTrackSelector * m_selectorTest
std::string m_analysisInstanceName
bool selectTracks(TrigTrackSelector *selector, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
std::vector< std::vector< TrackFilter * > > m_filters
TrigTrackSelector * m_selectorRef
StatusCode retrieve(Collection const *&collection, const std::string &key="")
std::vector< double > getBeamspot(const std::string &key)
ToolHandle< Trig::TrigDecisionTool > * m_tdt
T_AnalysisConfig(const std::string &analysisInstanceName, const std::string &testChainName, const std::string &testType, const std::string &testKey, const std::string &referenceChainName, const std::string &referenceType, const std::string &referenceKey, const std::string &selectionChainName, const std::string &selectionType, const std::string &selectionKey, TrackFilter *testFilter, TrackFilter *referenceFilter, TrackFilter *selectionFilter, TrackAssociator *associator, TrackAnalysis *analysis)
TrackAssociator * m_associator
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
virtual void clear() override
bool selectTrack(const Rec::TrackParticle *track)
neater code to make use of vector function also for a single ancestor pdgid, instead of the full code...
std::vector< Combination >::const_iterator combination_const_iterator
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
int signal_process_id(const GenEvent &evt)
Definition GenEvent.h:572
@ x
Definition ParamDefs.h:55
@ z
global position (cartesian)
Definition ParamDefs.h:57
@ y
Definition ParamDefs.h:56
EventInfo_v1 EventInfo
Definition of the latest event info version.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".