ATLAS Offline Software
Loading...
Searching...
No Matches
T_AnalysisConfigMT_Tier0.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
22
23#ifndef TrigInDetAnalysisExample_T_AnalysisConfigMT_Tier0_H
24#define TrigInDetAnalysisExample_T_AnalysisConfigMT_Tier0_H
25
31
37
38#include "TTree.h"
39#include "TFile.h"
40
41#include "GaudiKernel/ToolHandle.h"
43
44
45// McParticleEvent includes
47
49#include "AtlasHepMC/GenEvent.h"
52
54
55
56
58
60
66
67
68
70
73
74// #include "TrigSteeringEvent/TrigRoiDescriptorCollection.h"
75
78
80
81
82
83
84
85template<typename T, typename A=Analysis_Tier0>
87
88public:
89
90 // Full constructor: test/reference/selection
91 // - analysisInstanceName: the name of the analysis chain being created
92 // - xxxChainName: the name of the chain to be used as test/reference/selection; must be "StoreGate" in case of direct access to SG containers
93 // - xxxType: the type of tracks to be retrieved from the test/reference/selection chain or container
94 // - xxxKey: the key for tracks to be retrieved from the test/reference/selection chain or container
95 // - all standard operations are performed in loops over 0=test 1=reference 2=selection
96 T_AnalysisConfigMT_Tier0(const std::string& analysisInstanceName,
97 const std::string& testChainName, const std::string& testType, const std::string& testKey,
98 const std::string& referenceChainName, const std::string& referenceType, const std::string& referenceKey,
99 TrackFilter* testFilter, TrackFilter* referenceFilter,
100 TrackAssociator* associator,
102 TagNProbe* TnP_tool = 0) :
103 T_AnalysisConfig<T>( analysisInstanceName,
104 testChainName, testType, testKey,
105 referenceChainName, referenceType, referenceKey,
106 testFilter, referenceFilter,
107 associator,
108 analysis),
109 _analysis(0),
110 m_useBeamCondSvc(false),
111 m_doOffline(true),
112 m_doMuons(false),
113 m_doElectrons(false),
114 m_doTaus(false),
115 m_doBjets(false),
116 m_hasTruthMap(false),
117 m_doTauThreeProng(false),
118 m_tauEtCutOffline(false),
119 m_NRois(0),
120 m_NRefTracks(0),
121 m_NTestTracks(0),
122 m_runPurity(false),
123 m_shifter(false),
124 m_pTthreshold(0),
125 m_first(true),
126 m_containTracks(false),
127 m_TnP_tool(TnP_tool),
128 m_invmass(0),
129 m_invmass_obj(0),
130 m_monTool(0)
131 {
133 m_event = new TIDA::Event();
134 m_chainNames.push_back(testChainName);
135
136#if 0
137 ChainString& chain = m_chainNames.back();
138
139 std::cout << "\nT_AnalysisConfigMT_Tier0::name: " << name() << "\t" << this << std::endl;
140 std::cout << "T_AnalysisConfigMT_Tier0::chain specification: " << testChainName << " -> " << chain << "\t" << chain.raw() << std::endl;
141 std::cout << "\tchain: " << chain.head() << std::endl;
142 std::cout << "\tkey: " << chain.tail() << std::endl;
143 std::cout << "\troi: " << chain.roi() << std::endl;
144 std::cout << "\tvtx: " << chain.vtx() << std::endl;
145 std::cout << "\tte: " << chain.element() << std::endl;
146
147 std::cout << "\tpost: " << chain.post() << std::endl;
148 std::cout << "\tpt: " << chain.postvalue("pt") << std::endl;
149
150 std::cout << "\tcontainTracks: " << m_containTracks << std::endl;
151#endif
152
153 m_testType = testType;
154 }
155
157 delete m_event;
158 if ( m_TnP_tool != 0 ) delete m_TnP_tool ;
159 }
160
161 void setRunPurity( bool b ) { m_runPurity=b; }
162
163 void setShifter( bool b ) { m_shifter=b; }
164
165 void useBeamCondSvc( bool b ) { m_useBeamCondSvc = b; }
166
167 void containTracks( bool b ) { m_containTracks = b; }
168
169public:
170
172
173protected:
174
178
179 using T_AnalysisConfig<T>::name;
181
186
187
188 virtual void loop() {
189
190 bool TnP_flag = (m_TnP_tool != 0) ; // flag for tag and probe analysis
191
192 if( m_provider->msg().level() <= MSG::VERBOSE) {
193 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigMT_Tier0::loop() for " << T_AnalysisConfig<T>::m_analysisInstanceName << endmsg;
194 }
195
196 // get (offline) beam position
197 double xbeam = 0;
198 double ybeam = 0;
199
200 if ( m_first ) {
201
202 m_first = false;
203
204 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
205 m_provider->msg(MSG::VERBOSE) << " using beam position\tx=" << xbeam << "\ty=" << ybeam << endmsg;
206
207 std::vector<std::string> configuredChains = (*(m_tdt))->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
208
209 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
210 // std::cout << "Configured chain " << configuredChains[i] << std::endl;
211 m_provider->msg(MSG::VERBOSE) << "Chain " << configuredChains[i] << endmsg;
212 }
213 }
214
215 // std::cout << "\tloop() analyse chains " << m_chainNames.size() << std::endl;
216
217 std::vector<ChainString>::iterator chainitr = m_chainNames.begin();
218
219 std::vector<ChainString> chains;
220
224 while ( chainitr!=m_chainNames.end() ) {
225
227 ChainString& chainName = (*chainitr);
228
229 if (m_provider->msg().level() <= MSG::VERBOSE) {
230 m_provider->msg(MSG::VERBOSE) << "process chain " << chainName << endmsg;
231 }
232
233 if ( chainName.head() == "" ) {
234
235 std::string selectChain = chainName.raw();
236
237 chains.push_back( ChainString(selectChain) );
238
239 }
240 else {
241
243 std::vector<std::string> selectChains = (*(m_tdt))->getListOfTriggers( chainName.head() );
244
245 for ( unsigned iselected=0 ; iselected<selectChains.size() ; iselected++ ) {
246
247 selectChains[iselected] = chainName.subs( selectChains[iselected] );
248
249#if 0
250 std::cout << "sorting:: chain specification: " << chainName << "\traw:" << chainName.raw() << std::endl;
251 std::cout << "\tchain: " << chainName.head() << std::endl;
252 std::cout << "\tkey: " << chainName.tail() << std::endl;
253 std::cout << "\tind: " << chainName.extra() << std::endl;
254 std::cout << "\troi: " << chainName.roi() << std::endl;
255 std::cout << "\tvtx: " << chainName.vtx() << std::endl;
256 std::cout << "\tte: " << chainName.element() << std::endl;
257#endif
258
260 chains.push_back( ChainString(selectChains[iselected]) );
261
262 if(m_provider->msg().level() <= MSG::VERBOSE) {
263 m_provider->msg(MSG::VERBOSE) << "Matching chain " << selectChains[iselected] << " (" << chainName.head() << ")" << endmsg;
264 }
265
266 // std::cout<< "\tMatching chain " << sc << " (" << chainName.head() << ")" << std::endl;
267
268 }
269 }
270
271 ++chainitr;
272 }
273
274 // m_chainNames.insert( m_chainNames.end(), chains.begin(), chains.end() );
275 m_chainNames = chains;
276
277 if(m_provider->msg().level() <= MSG::VERBOSE) {
278 for ( size_t ic=m_chainNames.size() ; ic-- ; ) m_provider->msg(MSG::VERBOSE) << "Analyse chain " << m_chainNames[ic] << endmsg;
279 }
280
281 }
282
283 // std::cout << "\tloop() event analysis ..." << std::endl;
284
286 Filter_True filter;
287
288 Filter_etaPT filter_etaPT(5,200);
289 Filter_Combined filter_truth( &filter_etaPT, &filter_etaPT);
290
292 // Filter_Combined filterRef (&filter_offline, &filter_vertex);
293
294 int iRefFilter = 1;
295 int iTestFilter = 0;
296
297 if ( m_runPurity ) {
298 iRefFilter = 0;
299 iTestFilter = 1;
300 }
301
302 Filter_Combined filterRef( m_filters[iRefFilter][0], &filter );
303 Filter_Combined filterTest( m_filters[iTestFilter][0], &filter );
304
305
306 TrigTrackSelector selectorTruth( &filter_truth );
307 TrigTrackSelector selectorRef( &filterRef );
308 m_selectorRef = &selectorRef;
309 TrigTrackSelector selectorTest( &filterTest );
310 m_selectorTest = &selectorTest;
311
312 if ( xbeam!=0 || ybeam!=0 ) {
313 m_selectorRef->setBeamline( xbeam, ybeam );
314 }
315
317
318 // clear the ntuple TIDA::Event class
319 m_event->clear();
320
322
323 const xAOD::EventInfo* pEventInfo;
324
325 unsigned run_number = 0;
326 unsigned long long event_number = 0;
327 unsigned lumi_block = 0;
328 unsigned bunch_crossing_id = 0;
329 unsigned time_stamp = 0;
330 double mu_val = 0;
331
332 // std::cout << "\tloop() get EventInfo" << std::endl;
333
334 if ( this->template retrieve(pEventInfo, "EventInfo").isFailure() ) {
335 m_provider->msg(MSG::WARNING) << "Failed to get EventInfo " << endmsg;
336 } else {
337
338 run_number = pEventInfo->runNumber();
339 event_number = pEventInfo->eventNumber();
340 lumi_block = pEventInfo->lumiBlock();
341 time_stamp = pEventInfo->timeStamp();
342 bunch_crossing_id = pEventInfo->bcid();
343 mu_val = pEventInfo->averageInteractionsPerCrossing();
344 }
345
346 if(m_provider->msg().level() <= MSG::VERBOSE){
347 m_provider->msg(MSG::VERBOSE) << "run " << run_number
348 << "\tevent " << event_number
349 << "\tlb " << lumi_block << endmsg;
350 }
351
352 // m_provider->msg(MSG::INFO) << "run " << run_number
353 // << "\tevent " << event_number
354 // << "\tlb " << lumi_block << endmsg;
355
356 // std::cout << "\trun " << run_number << "\tevent " << event_number << "\tlb " << lumi_block << std::endl;
357
358
359 // clear the ntuple TIDA::Event class
360 m_event->clear();
361
362 m_event->run_number(run_number);
363 m_event->event_number(event_number);
364 m_event->lumi_block(lumi_block);
365 m_event->time_stamp(time_stamp);
366 m_event->bunch_crossing_id(bunch_crossing_id);
367 m_event->mu(mu_val);
368
371
372 bool analyse = false;
373
374 // Check HLTResult
375
376 // std::cout << "\tloop() loop over trigger chains to determine whether to process this event ..." << std::endl;
377
378 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
379
380 const std::string& chainname = m_chainNames[ichain].head();
381
382 if ( chainname == "" ) analyse = true;
383 else {
384
385 //Only for trigger chains
386 if ( chainname.find("L2") == std::string::npos &&
387 chainname.find("EF") == std::string::npos &&
388 chainname.find("HLT") == std::string::npos ) continue;
389
390 if ( m_provider->msg().level() <= MSG::DEBUG ) {
391 m_provider->msg(MSG::DEBUG) << "Chain " << chainname
392 << "\tpass " << (*m_tdt)->isPassed(chainname)
393 << "\tpres " << (*m_tdt)->getPrescale(chainname) << endmsg;
394 }
395
396 // std::cout << "\tChain " << chainname << "\tpass " << (*m_tdt)->isPassed(chainname)
397 // << "\tpres " << (*m_tdt)->getPrescale(chainname) << std::endl;
398
399 if ( (*(m_tdt))->isPassed(chainname) || (*(m_tdt))->getPrescale(chainname) ) analyse = true;
400
401 }
402 }
403
404
405 // if ( (*m_tdt)->ExperimentalAndExpertMethods().isHLTTruncated() ) {
406 // m_provider->msg(MSG::WARNING) << "HLTResult truncated, skipping event" << endmsg;
407 // return;
408 // }
409
410 if ( !this->m_keepAllEvents && !analyse ) {
411 // m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg;
412 if(m_provider->msg().level() <= MSG::VERBOSE) {
413 m_provider->msg(MSG::VERBOSE) << "No chains passed unprescaled - not processing this event" << endmsg;
414 }
415 // std::cout << "\tNo chains passed unprescaled - not processing this event" << std::endl;
416 return;
417 }
418
419
420
422
423 selectorTruth.clear();
424
425
426
427 if(m_provider->msg().level() <= MSG::VERBOSE)
428 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
429
430 if ( m_mcTruth && m_provider->msg().level() <= MSG::VERBOSE ) m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
431
432
434
435 std::vector<TIDA::Vertex> vertices;
436 std::vector<TIDA::Vertex> vertices_rec;
437
438 std::vector<double> refbeamspot;
439 std::vector<double> testbeamspot;
440
442
443 m_provider->msg(MSG::VERBOSE) << "fetching AOD Primary vertex container" << endmsg;
444
445 if ( !this->select( vertices, "PrimaryVertices" ) ) {
446 m_provider->msg(MSG::VERBOSE) << "could not retrieve vertex collection " "PrimaryVertices" << std::endl;
447 }
448
450
451 if ( m_mcTruth ) {
452 m_event->addChain( "Truth" );
453 m_event->back().addRoi(TIDARoiDescriptor());
454 m_event->back().back().addTracks(selectorTruth.tracks());
455 }
456
458
459 if ( m_doOffline ) {
460 for ( unsigned i=0 ; i<vertices.size() ; i++ ) {
461 if(m_provider->msg().level() <= MSG::VERBOSE)
462 m_provider->msg(MSG::VERBOSE) << "vertex " << i << " " << vertices[i] << endmsg;
463 m_event->addVertex(vertices[i]);
464 }
465 }
466
468
469 // int Noff = 0;
470 std::vector<TIDA::Track*> offline_tracks;
471 std::vector<TIDA::Track*> electron_tracks;
472 std::vector<TIDA::Track*> muon_tracks;
473
474 std::vector<TIDA::Track*> ref_tracks;
475 std::vector<TIDA::Track*> test_tracks;
476
477 offline_tracks.clear();
478 electron_tracks.clear();
479 muon_tracks.clear();
480
481 ref_tracks.clear();
482 test_tracks.clear();
483
484 // offline track retrieval now done once for each chain rather than each roi
485 if ( m_provider->msg().level() <= MSG::VERBOSE )
486 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
487
488 bool foundTruth = false;
489
490 if ( !m_doOffline && m_mcTruth ) {
491
492 filter_truth.setRoi( 0 ); // don't filter on RoI yet (or until needed)
493
494 selectorTruth.clear();
495
496 if ( m_provider->msg().level() <= MSG::VERBOSE )
497 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
498
499 if ( m_provider->evtStore()->template contains<TruthParticleContainer>("INav4MomTruthEvent") ) {
500 //ESD
501 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "INav4MomTruthEvent" );
502 foundTruth = true;
503 }
504 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("SpclMC") ) {
506 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "SpclMC");
507 foundTruth = true;
508 }
509 else if ( m_provider->evtStore()->template contains<xAOD::TruthParticleContainer>("TruthParticles") ) {
511 this->template selectTracks<xAOD::TruthParticleContainer>( &selectorTruth, "TruthParticles");
512 foundTruth = true;
513 }
514 else if ( m_provider->evtStore()->template contains<TruthParticleContainer>("") ) {
516 this->template selectTracks<TruthParticleContainer>( &selectorTruth, "");
517 foundTruth = true;
518 }
519 else
520 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
521 m_provider->msg(MSG::VERBOSE) << "Truth not found - none whatsoever!" << endmsg;
522 }
523 }
524
525 if ( !m_doOffline && m_mcTruth && !foundTruth ) {
526
527 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
528 m_provider->msg(MSG::VERBOSE) << "getting Truth" << endmsg;
529 }
530
532
534 const McEventCollection* mcevent = 0;
535
537
538 std::string keys[4] = { "GEN_AOD", "TruthEvent", "", "G4Truth" };
539
540 std::string key = "";
541
542 bool foundcollection = false;
543
544 for ( int ik=0 ; ik<4 ; ik++ ) {
545
546 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
547 m_provider->msg(MSG::VERBOSE) << "Try McEventCollection: " << keys[ik] << endmsg;
548 }
549
550 if ( !m_provider->evtStore()->template contains<McEventCollection>(keys[ik]) ) {
551 if( m_provider->msg().level() <= MSG::VERBOSE )
552 m_provider->msg(MSG::VERBOSE) << "No McEventCollection: " << keys[ik] << endmsg;
553 continue;
554 }
555
556 if ( m_provider->msg().level() <= MSG::VERBOSE )
557 m_provider->msg(MSG::VERBOSE) << "evtStore()->retrieve( mcevent, " << keys[ik] << " )" << endmsg;
558
559 if ( this->template retrieve( mcevent, keys[ik] ).isFailure() ) {
560 if ( m_provider->msg().level() <= MSG::VERBOSE )
561 m_provider->msg(MSG::VERBOSE) << "Failed to get McEventCollection: " << keys[ik] << endmsg;
562 }
563 else {
565 key = keys[ik];
566 if(m_provider->msg().level() <= MSG::VERBOSE)
567 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << endmsg;
568 foundcollection = true;
569 break;
570 }
571 }
572
574 if ( !foundcollection ) {
575 if(m_provider->msg().level() <= MSG::VERBOSE)
576 m_provider->msg(MSG::WARNING) << "No MC Truth Collections of any sort, whatsoever!!!" << endmsg;
577
578 // m_tree->Fill();
579 // return StatusCode::FAILURE;
580
581 return;
582 }
583
584 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
585 m_provider->msg(MSG::VERBOSE) << "Found McEventCollection: " << key << "\tNevents " << mcevent->size() << endmsg;
586 }
587
588 McEventCollection::const_iterator evitr = mcevent->begin();
589 McEventCollection::const_iterator evend = mcevent->end();
590
591 unsigned ie = 0;
592 unsigned ip = 0;
593
594 unsigned ie_ip = 0;
595
596 while ( evitr!=evend ) {
597
598 int _ip = 0;
599
600 int pid = HepMC::signal_process_id((*evitr));
601
602 //The logic should be clarified here
603 if ( pid!=0 ) {
604
605 for (auto pitr: *(*evitr) ) {
606
607 selectorTruth.selectTrack( pitr );
608
609 ++_ip;
610
611 }
612
613 }
614 ++ie;
615 ++evitr;
616
617 if ( _ip>0 ) {
619 // m_provider->msg(MSG::VERBOSE) << "Found " << ie << "\tpid " << pid << "\t with " << ip << " TruthParticles (GenParticles)" << endmsg;
620 ++ie_ip;
621 ip += _ip;
622 }
623 }
624
625 if(m_provider->msg().level() <= MSG::VERBOSE){
626 m_provider->msg(MSG::VERBOSE) << "Found " << ip << " TruthParticles (GenParticles) in " << ie_ip << " GenEvents out of " << ie << endmsg;
627 m_provider->msg(MSG::VERBOSE) << "selected " << selectorTruth.size() << " TruthParticles (GenParticles)" << endmsg;
628 }
629
630 if(selectorTruth.size() > 0) foundTruth = true;
631
632 if ( !(ip>0) ) {
633 if (m_provider->msg().level() <= MSG::VERBOSE) m_provider->msg(MSG::WARNING) << "NO TRUTH PARTICLES - returning" << endmsg;
634 return;
635 }
636
637 }
638
639 // m_provider->msg(MSG::VERBOSE) << " Offline tracks " << endmsg;
640
641 if ( m_doOffline ) {
642
643 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>("InDetTrackParticles") ) {
644 this->template selectTracks<xAOD::TrackParticleContainer>( m_selectorRef, "InDetTrackParticles" );
645 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( "InDetTrackParticles" );
646 }
647 else if ( m_provider->msg().level() <= MSG::WARNING ) {
648 m_provider->msg(MSG::WARNING) << " Offline tracks not found " << endmsg;
649 }
650
651 }
652
653
654 // std::cout << "\tloop() loop over chains proper ..." << std::endl;
655
657 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
658
660
661 // std::string& chainname = chains[ichain];
662 const std::string& chainname = m_chainNames[ichain].head();
663 const std::string& key = m_chainNames[ichain].tail();
664 const std::string& vtx_name = m_chainNames[ichain].vtx();
665 //Not used left just in case
666 //const std::string& roi_name = m_chainNames[ichain].roi();
667 //const std::string& te_name = m_chainNames[ichain].element();
668 m_pTthreshold = 0;
669
670 if ( m_chainNames[ichain].postcount() ) {
671 std::string ptvalue = m_chainNames[ichain].postvalue("pt");
672 if ( ptvalue!="" ) m_pTthreshold = std::stod(ptvalue);
673 }
674
675
676 unsigned _decisiontype = TrigDefs::Physics;
677 unsigned decisiontype;
678
679 if ( this->requireDecision() ) _decisiontype = TrigDefs::requireDecision;
680
681
682 if ( m_chainNames[ichain].passed() ) decisiontype = _decisiontype;
683 else decisiontype = TrigDefs::alsoDeactivateTEs;
684
686 // if ( decisiontype==TrigDefs::requireDecision ) std::cout << "\tSUTT TrigDefs::requireDecision " << decisiontype << std::endl;
687 // if ( decisiontype==TrigDefs::Physics ) std::cout << "\tSUTT TrigDefs::Physics " << decisiontype << std::endl;
688
689 if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) {
690
691 m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname
692 << "\tpass " << (*m_tdt)->isPassed(chainname)
693 << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg;
694
695 m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg;
696
697 m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg;
698 }
699
701 // std::cout << "\tstatus for chain " << chainname
702 // << "\tpass " << (*m_tdt)->isPassed( chainname )
703 // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype )
704 // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl;
705
706
707 // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg;
708
709
710 if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue;
711
712
715 // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs);
716
719
720 // tag and probe analysis processes multiple chains passed in the tag and probe tool at once so loop over vector of chains
721 std::vector<std::string> chainNames ;
722
723 if ( !TnP_flag ) {
724 chainNames.push_back(m_chainNames[ichain].raw()) ;
725 }
726 else {
727 chainNames.push_back(m_TnP_tool->tag()) ;
728 chainNames.push_back(m_TnP_tool->probe()) ;
729 }
730
731 // loop over new chainNames vector but doing the same stuff
732 for ( unsigned i = 0 ; i < chainNames.size() ; ++i ) {
733
734 ChainString chainConfig = chainNames[i] ;
735 std::string chainName = chainConfig.head();
736
737 m_event->addChain( chainNames[i] );
738
739 TIDA::Chain& chain = m_event->back();
740
741 if ( chainName == "" ) {
742
744
745 m_selectorTest->clear();
746
748
749 TIDARoiDescriptor* roiInfo = new TIDARoiDescriptor(true);
750
751 chain.addRoi( *roiInfo );
752
753 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(key) ) {
755 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( key );
756 }
757
758 const std::vector<TIDA::Track*>& testtracks = m_selectorTest->tracks();
759
760 chain.back().addTracks(testtracks);
761
762 if ( vtx_name!="" ) {
763
765
766 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
767
768 std::vector<TIDA::Vertex> tidavertices;
769
770 if ( this->select( tidavertices, vtx_name ) ) chain.back().addVertices( tidavertices );
771 }
772
773
774 delete roiInfo;
775
776 }
777 else {
778
780
781 //std::string roi_key = m_chainNames[ichain].roi();
782
783 std::string roi_key = chainConfig.roi();
784
785 unsigned feature_type =TrigDefs::lastFeatureOfType;
786
787 if ( roi_key!="" ) feature_type= TrigDefs::allFeaturesOfType;
788
790
791 int leg = -1;
792
793 if ( chainConfig.element()!="" ) {
794 leg = std::atoi(chainConfig.element().c_str());
795 }
796
797 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > rois =
798 (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
799 decisiontype,
800 roi_key,
801 feature_type,
802 "roi",
803 leg ) );
804
805 // const unsigned int featureCollectionMode = const std::string& navElementLinkKey = "roi") const;
806
807 int iroi = 0;
808
809 for ( const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection>& roi_info : rois ) {
810
811 iroi++;
812
816
817 if ( roi_key=="SuperRoi" && iroi>1 ) continue;
818
819 // std::cout << "\troi: get link " << roi_key << " ..." << std::endl;
820
821 const ElementLink<TrigRoiDescriptorCollection> roi_link = roi_info.link;
822
824 if ( roi_key!="" && roi_link.dataID()!=roi_key ) continue;
825
826 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
827
828 if ( roiptr == 0 ) {
829 continue;
830 }
831
832 // std::cout << "\troi: link deref ..." << *roiptr << std::endl;
833
834 if (m_provider->msg().level() <= MSG::VERBOSE) {
835 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << **roiptr << endmsg;
836 }
837
839
840 // if ( dbg ) std::cout << "\troi " << iroi << " " << *roiInfo << std::endl;
841
843
844 m_selectorTest->clear();
845
846 if ( this->template selectTracks<xAOD::TrackParticleContainer>( m_selectorTest, roi_link, key ) ) { }
847
848 // beamspot stuff not needed for xAOD::TrackParticles
849
851
852 chain.addRoi( *roiInfo );
853
855
856 const std::vector<TIDA::Track*>& testtracks = m_selectorTest->tracks();
857
858 chain.back().addTracks(testtracks);
859
860
862
863 if ( vtx_name!="" ) {
864
865 std::vector<TIDA::Vertex> tidavertices;
866
867 this->select( tidavertices, roi_link, vtx_name );
868
869 chain.back().addVertices( tidavertices );
870
871 }
872
873
874#if 0
875 if ( dbg ) {
876 std::cout << "\tTIDA analysis for chain: " << chainname << "\t key: " << key << "\t" << **roiptr << std::endl;
877 std::cout << "\tcollections: " << chain.back() << std::endl;
878 }
879#endif
880
881 delete roiInfo;
882
883 }
884
885
886 }
887
888 } // end of loop chainNames vector loop
889
890
891 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
892 m_provider->msg(MSG::VERBOSE) << "event: " << *m_event << endmsg;
893 }
894
895 }
896
897 // close previous loop over chains and open new one
898
899 for ( unsigned ichain=0 ; ichain<m_event->size() ; ichain++ ) {
900
901 TIDA::Chain& chain = (*m_event)[ichain];
902 ChainString chainConfig(chain.name());
903 const std::string& vtx_name = chainConfig.vtx();
904
905 // skip tag chains to avoid performing standard analysis on them (done for tnp at the same time as probes)
906 if ( TnP_flag && chainConfig.extra().find("_tag")!=std::string::npos ) continue ;
907
908 std::vector<TIDA::Roi*> rois ;
909
910 if (TnP_flag) {
911 rois = m_TnP_tool->GetRois( m_event->chains(), m_selectorRef, &filterRef, m_invmass, m_invmass_obj );
912 // needs to be done AFTER retrieving offline tracks as m_selectorRef passed as arguement, hence restructuring
913 }
914 else {
915 rois.reserve( chain.size() );
916 for ( size_t ir=0 ; ir<chain.size() ; ir++ ) {
917 rois.push_back( &(chain.rois()[ir]) );
918 }
919 }
920
921 // now loop over the rois (again)
922
923 for ( unsigned iroi=0 ; iroi<rois.size() ; iroi++ ) {
924
925 if ( this->filterOnRoi() ) {
926 filterRef.setRoi( &(rois.at(iroi)->roi() ) );
927 filterRef.containtracks( m_containTracks );
928 }
929 else filterRef.setRoi( 0 );
930
931 test_tracks.clear();
932
933 // this block is before the track retrieval in the original, is it working the same here?
934
948
949 if ( m_provider->msg().level() <= MSG::VERBOSE )
950 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
951
952 if ( !m_doOffline && m_mcTruth ) {
953 if ( this->filterOnRoi() ) filter_truth.setRoi( &(rois.at(iroi)->roi() ) );
954 ref_tracks = m_selectorRef->tracks(&filter_truth);
955 }
956 else { // ie. if ( m_doOffline )
957 ref_tracks = m_selectorRef->tracks(&filterRef) ;
958 }
959
960 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
961 m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << m_selectorRef->tracks().size() << endmsg;
962 for ( int ii=m_selectorRef->tracks().size() ; ii-- ; ) {
963 m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *m_selectorRef->tracks()[ii] << endmsg;
964 }
965 }
966
967 test_tracks.clear();
968
969
970 for ( unsigned itrk=0 ; itrk<rois.at(iroi)->tracks().size() ; itrk++ ) {
971 test_tracks.push_back(&(rois.at(iroi)->tracks().at(itrk)));
972 }
973
974 // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl;
975
976 _analysis->setvertices( vertices.size() );
977
978 if ( refbeamspot.size()>0 ) _analysis->setBeamRef( refbeamspot );
979 if ( testbeamspot.size()>0 ) _analysis->setBeamTest( testbeamspot );
980
983
984 if ( m_runPurity ) {
985
986 if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks );
987
988 if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold );
989
991 m_NRois++;
992 m_NRefTracks += test_tracks.size();
993 m_NTestTracks += ref_tracks.size();
994
995
997 m_associator->match( test_tracks, ref_tracks );
998
999 _analysis->execute( test_tracks, ref_tracks, m_associator );
1000
1001 }
1002 else {
1003
1005 if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks );
1006
1008
1009 if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold );
1010
1012 m_NRois++;
1013 m_NRefTracks += ref_tracks.size();
1014 m_NTestTracks += test_tracks.size();
1015
1017 m_associator->match( ref_tracks, test_tracks );
1018
1019 _analysis->setroi( &rois.at(iroi)->roi() );
1020 _analysis->execute( ref_tracks, test_tracks, m_associator );
1021
1022 if ( vtx_name!="" ) {
1024 std::vector<TIDA::Vertex> vr = rois.at(iroi)->vertices();
1025 std::vector<TIDA::Vertex*> vtx_rec;
1026 for ( unsigned iv=0 ; iv<vr.size() ; iv++ ) vtx_rec.push_back( &vr[iv] );
1027
1028 std::vector<TIDA::Vertex*> vtx;
1029 if ( this->getVtxIndex()<0 ) {
1030 for ( unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1031 }
1032 else {
1033 if ( vertices.size()>unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] );
1034 }
1035
1036 _analysis->execute_vtx( vtx, vtx_rec, m_event );
1037 }
1038
1039 }
1040
1041 if ( _analysis->debug() ) {
1042 m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain]
1043 << "\trun " << run_number
1044 << "\tevent " << event_number
1045 << "\tlb " << lumi_block << endmsg;
1046 }
1047
1048 }
1049
1050 }
1051
1052 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1053 m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *m_event << endmsg;
1054 }
1055 }
1056
1057
1058
1059 virtual void book() {
1060
1061 if(m_provider->msg().level() <= MSG::VERBOSE)
1062 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigMT_Tier0::book() " << name() << endmsg;
1063
1064 m_provider->msg(MSG::ERROR) << "AnalysisConfigMT_Tier0::book() should no longer be called: " << name() << endmsg;
1065
1066
1067 }
1068
1069
1070
1071 virtual void finalize() {
1072
1073 if(m_provider->msg().level() <= MSG::VERBOSE){
1074 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigMT_Tier0::finalise() " << m_provider->name() << endmsg;
1075 }
1076
1077 m_analysis->finalise();
1078
1079 // deleting instance of TnP_tool and setting pointer to null
1080 if ( m_TnP_tool != 0 ) {
1081 delete m_TnP_tool ;
1082 m_TnP_tool = 0 ;
1083 }
1084
1085 m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg;
1086
1087 if(m_provider->msg().level() <= MSG::VERBOSE) {
1088 m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg;
1089 }
1090 }
1091
1092 void set_monTool( ToolHandle<GenericMonitoringTool>* m ) { m_monTool=m; }
1093
1094 ToolHandle<GenericMonitoringTool>* monTool() { return m_monTool; }
1095
1096protected:
1097
1099
1101
1102 std::vector<ChainString> m_chainNames;
1103 std::vector<A*> m_analyses;
1104 std::string m_testType;
1105
1114
1115 std::string m_outputFileName;
1116
1121
1123
1125
1127
1129
1131
1133
1136
1137 ToolHandle<GenericMonitoringTool>* m_monTool;
1138
1139};
1140
1141
1142
1143#endif // TrigInDetAnalysisExample_T_AnalysisConfigMT_Tier0_H
1144
#define endmsg
Erkcan's track matchers.
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
emacs: this is -*- c++ -*-
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:861
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.
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
ToolHandle< GenericMonitoringTool > * m_monTool
void set_monTool(ToolHandle< GenericMonitoringTool > *m)
T_AnalysisConfigMT_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, TagNProbe *TnP_tool=0)
ToolHandle< GenericMonitoringTool > * monTool()
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
bool select(std::vector< TIDA::Vertex > &vertices, xAOD::VertexContainer::const_iterator vtx_start, xAOD::VertexContainer::const_iterator vtx_end)
const std::vector< TIDA::Track * > & tracks() const
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
bool selectTrack(HepMC::ConstGenParticlePtr track)
virtual void clear() override
uint32_t lumiBlock() const
The current event's luminosity block number.
uint32_t bcid() const
The bunch crossing ID of the event.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
int ir
counter of the current depth
Definition fastadd.cxx:49
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:575
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
static const unsigned int allFeaturesOfType
Run 3 "enum". Return all features along legs (still with type and container checks).
EventInfo_v1 EventInfo
Definition of the latest event info version.
hold the test vectors and ease the comparison
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22