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->evtStore()->template contains<Rec::TrackParticleContainer>("TrackParticleCandidate") ) {
648 this->template selectTracks<Rec::TrackParticleContainer>( m_selectorRef, "TrackParticleCandidate" );
649 }
650 else if ( m_provider->msg().level() <= MSG::WARNING ) {
651 m_provider->msg(MSG::WARNING) << " Offline tracks not found " << endmsg;
652 }
653
654 }
655
656
657 // std::cout << "\tloop() loop over chains proper ..." << std::endl;
658
660 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
661
663
664 // std::string& chainname = chains[ichain];
665 const std::string& chainname = m_chainNames[ichain].head();
666 const std::string& key = m_chainNames[ichain].tail();
667 const std::string& vtx_name = m_chainNames[ichain].vtx();
668 //Not used left just in case
669 //const std::string& roi_name = m_chainNames[ichain].roi();
670 //const std::string& te_name = m_chainNames[ichain].element();
671 m_pTthreshold = 0;
672
673 if ( m_chainNames[ichain].postcount() ) {
674 std::string ptvalue = m_chainNames[ichain].postvalue("pt");
675 if ( ptvalue!="" ) m_pTthreshold = std::stod(ptvalue);
676 }
677
678
679 unsigned _decisiontype = TrigDefs::Physics;
680 unsigned decisiontype;
681
682 if ( this->requireDecision() ) _decisiontype = TrigDefs::requireDecision;
683
684
685 if ( m_chainNames[ichain].passed() ) decisiontype = _decisiontype;
686 else decisiontype = TrigDefs::alsoDeactivateTEs;
687
689 // if ( decisiontype==TrigDefs::requireDecision ) std::cout << "\tSUTT TrigDefs::requireDecision " << decisiontype << std::endl;
690 // if ( decisiontype==TrigDefs::Physics ) std::cout << "\tSUTT TrigDefs::Physics " << decisiontype << std::endl;
691
692 if ( chainname!="" && m_provider->msg().level() <= MSG::VERBOSE ) {
693
694 m_provider->msg(MSG::VERBOSE) << "status for chain " << chainname
695 << "\tpass " << (*m_tdt)->isPassed(chainname)
696 << "\tprescale " << (*m_tdt)->getPrescale(chainname) << endmsg;
697
698 m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endmsg;
699
700 m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endmsg;
701 }
702
704 // std::cout << "\tstatus for chain " << chainname
705 // << "\tpass " << (*m_tdt)->isPassed( chainname )
706 // << "\tpassdt " << (*m_tdt)->isPassed( chainname, decisiontype )
707 // << "\tprescale " << (*m_tdt)->getPrescale( chainname ) << std::endl;
708
709
710 // m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << "\t" << m_chainNames[ichain] << "\trun " << run_number << "\tevent " << event_number << endmsg;
711
712
713 if ( chainname!="" && !this->m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) ) continue;
714
715
718 // Trig::FeatureContainer f = (*m_tdt)->features( chainname, TrigDefs::alsoDeactivateTEs);
719
722
723 // tag and probe analysis processes multiple chains passed in the tag and probe tool at once so loop over vector of chains
724 std::vector<std::string> chainNames ;
725
726 if ( !TnP_flag ) {
727 chainNames.push_back(m_chainNames[ichain].raw()) ;
728 }
729 else {
730 chainNames.push_back(m_TnP_tool->tag()) ;
731 chainNames.push_back(m_TnP_tool->probe()) ;
732 }
733
734 // loop over new chainNames vector but doing the same stuff
735 for ( unsigned i = 0 ; i < chainNames.size() ; ++i ) {
736
737 ChainString chainConfig = chainNames[i] ;
738 std::string chainName = chainConfig.head();
739
740 m_event->addChain( chainNames[i] );
741
742 TIDA::Chain& chain = m_event->back();
743
744 if ( chainName == "" ) {
745
747
748 m_selectorTest->clear();
749
751
752 TIDARoiDescriptor* roiInfo = new TIDARoiDescriptor(true);
753
754 chain.addRoi( *roiInfo );
755
756 if ( m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(key) ) {
758 refbeamspot = this->template getBeamspot<xAOD::TrackParticleContainer>( key );
759 }
760
761 const std::vector<TIDA::Track*>& testtracks = m_selectorTest->tracks();
762
763 chain.back().addTracks(testtracks);
764
765 if ( vtx_name!="" ) {
766
768
769 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
770
771 std::vector<TIDA::Vertex> tidavertices;
772
773 if ( this->select( tidavertices, vtx_name ) ) chain.back().addVertices( tidavertices );
774 }
775
776
777 delete roiInfo;
778
779 }
780 else {
781
783
784 //std::string roi_key = m_chainNames[ichain].roi();
785
786 std::string roi_key = chainConfig.roi();
787
788 unsigned feature_type =TrigDefs::lastFeatureOfType;
789
790 if ( roi_key!="" ) feature_type= TrigDefs::allFeaturesOfType;
791
793
794 int leg = -1;
795
796 if ( chainConfig.element()!="" ) {
797 leg = std::atoi(chainConfig.element().c_str());
798 }
799
800 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > rois =
801 (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
802 decisiontype,
803 roi_key,
804 feature_type,
805 "roi",
806 leg ) );
807
808 // const unsigned int featureCollectionMode = const std::string& navElementLinkKey = "roi") const;
809
810 int iroi = 0;
811
812 for ( const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection>& roi_info : rois ) {
813
814 iroi++;
815
819
820 if ( roi_key=="SuperRoi" && iroi>1 ) continue;
821
822 // std::cout << "\troi: get link " << roi_key << " ..." << std::endl;
823
824 const ElementLink<TrigRoiDescriptorCollection> roi_link = roi_info.link;
825
827 if ( roi_key!="" && roi_link.dataID()!=roi_key ) continue;
828
829 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
830
831 if ( roiptr == 0 ) {
832 continue;
833 }
834
835 // std::cout << "\troi: link deref ..." << *roiptr << std::endl;
836
837 if (m_provider->msg().level() <= MSG::VERBOSE) {
838 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainname << " " << **roiptr << endmsg;
839 }
840
842
843 // if ( dbg ) std::cout << "\troi " << iroi << " " << *roiInfo << std::endl;
844
846
847 m_selectorTest->clear();
848
849 if ( this->template selectTracks<xAOD::TrackParticleContainer>( m_selectorTest, roi_link, key ) ) { }
850
851 // beamspot stuff not needed for xAOD::TrackParticles
852
854
855 chain.addRoi( *roiInfo );
856
858
859 const std::vector<TIDA::Track*>& testtracks = m_selectorTest->tracks();
860
861 chain.back().addTracks(testtracks);
862
863
865
866 if ( vtx_name!="" ) {
867
868 std::vector<TIDA::Vertex> tidavertices;
869
870 this->select( tidavertices, roi_link, vtx_name );
871
872 chain.back().addVertices( tidavertices );
873
874 }
875
876
877#if 0
878 if ( dbg ) {
879 std::cout << "\tTIDA analysis for chain: " << chainname << "\t key: " << key << "\t" << **roiptr << std::endl;
880 std::cout << "\tcollections: " << chain.back() << std::endl;
881 }
882#endif
883
884 delete roiInfo;
885
886 }
887
888
889 }
890
891 } // end of loop chainNames vector loop
892
893
894 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
895 m_provider->msg(MSG::VERBOSE) << "event: " << *m_event << endmsg;
896 }
897
898 }
899
900 // close previous loop over chains and open new one
901
902 for ( unsigned ichain=0 ; ichain<m_event->size() ; ichain++ ) {
903
904 TIDA::Chain& chain = (*m_event)[ichain];
905 ChainString chainConfig(chain.name());
906 const std::string& vtx_name = chainConfig.vtx();
907
908 // skip tag chains to avoid performing standard analysis on them (done for tnp at the same time as probes)
909 if ( TnP_flag && chainConfig.extra().find("_tag")!=std::string::npos ) continue ;
910
911 std::vector<TIDA::Roi*> rois ;
912
913 if (TnP_flag) {
914 rois = m_TnP_tool->GetRois( m_event->chains(), m_selectorRef, &filterRef, m_invmass, m_invmass_obj );
915 // needs to be done AFTER retrieving offline tracks as m_selectorRef passed as arguement, hence restructuring
916 }
917 else {
918 rois.reserve( chain.size() );
919 for ( size_t ir=0 ; ir<chain.size() ; ir++ ) {
920 rois.push_back( &(chain.rois()[ir]) );
921 }
922 }
923
924 // now loop over the rois (again)
925
926 for ( unsigned iroi=0 ; iroi<rois.size() ; iroi++ ) {
927
928 if ( this->filterOnRoi() ) {
929 filterRef.setRoi( &(rois.at(iroi)->roi() ) );
930 filterRef.containtracks( m_containTracks );
931 }
932 else filterRef.setRoi( 0 );
933
934 test_tracks.clear();
935
936 // this block is before the track retrieval in the original, is it working the same here?
937
951
952 if ( m_provider->msg().level() <= MSG::VERBOSE )
953 m_provider->msg(MSG::VERBOSE) << "MC Truth flag " << m_mcTruth << endmsg;
954
955 if ( !m_doOffline && m_mcTruth ) {
956 if ( this->filterOnRoi() ) filter_truth.setRoi( &(rois.at(iroi)->roi() ) );
957 ref_tracks = m_selectorRef->tracks(&filter_truth);
958 }
959 else { // ie. if ( m_doOffline )
960 ref_tracks = m_selectorRef->tracks(&filterRef) ;
961 }
962
963 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
964 m_provider->msg(MSG::VERBOSE) << "ref tracks.size() " << m_selectorRef->tracks().size() << endmsg;
965 for ( int ii=m_selectorRef->tracks().size() ; ii-- ; ) {
966 m_provider->msg(MSG::VERBOSE) << " ref track " << ii << " " << *m_selectorRef->tracks()[ii] << endmsg;
967 }
968 }
969
970 test_tracks.clear();
971
972
973 for ( unsigned itrk=0 ; itrk<rois.at(iroi)->tracks().size() ; itrk++ ) {
974 test_tracks.push_back(&(rois.at(iroi)->tracks().at(itrk)));
975 }
976
977 // std::cout << "sutt track multiplicities: offline " << offline_tracks.size() << "\ttest " << test_tracks.size() << std::endl;
978
979 _analysis->setvertices( vertices.size() );
980
981 if ( refbeamspot.size()>0 ) _analysis->setBeamRef( refbeamspot );
982 if ( testbeamspot.size()>0 ) _analysis->setBeamTest( testbeamspot );
983
986
987 if ( m_runPurity ) {
988
989 if ( this->getUseHighestPT() ) HighestPTOnly( test_tracks );
990
991 if ( m_pTthreshold>0 ) FilterPT( test_tracks, m_pTthreshold );
992
994 m_NRois++;
995 m_NRefTracks += test_tracks.size();
996 m_NTestTracks += ref_tracks.size();
997
998
1000 m_associator->match( test_tracks, ref_tracks );
1001
1002 _analysis->execute( test_tracks, ref_tracks, m_associator );
1003
1004 }
1005 else {
1006
1008 if ( this->getUseHighestPT() ) HighestPTOnly( ref_tracks );
1009
1011
1012 if ( m_pTthreshold>0 ) FilterPT( ref_tracks, m_pTthreshold );
1013
1015 m_NRois++;
1016 m_NRefTracks += ref_tracks.size();
1017 m_NTestTracks += test_tracks.size();
1018
1020 m_associator->match( ref_tracks, test_tracks );
1021
1022 _analysis->setroi( &rois.at(iroi)->roi() );
1023 _analysis->execute( ref_tracks, test_tracks, m_associator );
1024
1025 if ( vtx_name!="" ) {
1027 std::vector<TIDA::Vertex> vr = rois.at(iroi)->vertices();
1028 std::vector<TIDA::Vertex*> vtx_rec;
1029 for ( unsigned iv=0 ; iv<vr.size() ; iv++ ) vtx_rec.push_back( &vr[iv] );
1030
1031 std::vector<TIDA::Vertex*> vtx;
1032 if ( this->getVtxIndex()<0 ) {
1033 for ( unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1034 }
1035 else {
1036 if ( vertices.size()>unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->getVtxIndex()] );
1037 }
1038
1039 _analysis->execute_vtx( vtx, vtx_rec, m_event );
1040 }
1041
1042 }
1043
1044 if ( _analysis->debug() ) {
1045 m_provider->msg(MSG::INFO) << "Missing track for " << m_chainNames[ichain]
1046 << "\trun " << run_number
1047 << "\tevent " << event_number
1048 << "\tlb " << lumi_block << endmsg;
1049 }
1050
1051 }
1052
1053 }
1054
1055 if ( m_provider->msg().level() <= MSG::VERBOSE ) {
1056 m_provider->msg(MSG::VERBOSE) << "\n\nEvent " << *m_event << endmsg;
1057 }
1058 }
1059
1060
1061
1062 virtual void book() {
1063
1064 if(m_provider->msg().level() <= MSG::VERBOSE)
1065 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigMT_Tier0::book() " << name() << endmsg;
1066
1067 m_provider->msg(MSG::ERROR) << "AnalysisConfigMT_Tier0::book() should no longer be called: " << name() << endmsg;
1068
1069
1070 }
1071
1072
1073
1074 virtual void finalize() {
1075
1076 if(m_provider->msg().level() <= MSG::VERBOSE){
1077 m_provider->msg(MSG::VERBOSE) << "AnalysisConfigMT_Tier0::finalise() " << m_provider->name() << endmsg;
1078 }
1079
1080 m_analysis->finalise();
1081
1082 // deleting instance of TnP_tool and setting pointer to null
1083 if ( m_TnP_tool != 0 ) {
1084 delete m_TnP_tool ;
1085 m_TnP_tool = 0 ;
1086 }
1087
1088 m_provider->msg(MSG::INFO) << m_provider->name() << " " << m_chainNames[0] << " \tNRois processed: " << m_NRois << "\tRef tracks: " << m_NRefTracks << "\tTestTracks: " << m_NTestTracks << endmsg;
1089
1090 if(m_provider->msg().level() <= MSG::VERBOSE) {
1091 m_provider->msg(MSG::VERBOSE) << m_provider->name() << " finalised" << endmsg;
1092 }
1093 }
1094
1095 void set_monTool( ToolHandle<GenericMonitoringTool>* m ) { m_monTool=m; }
1096
1097 ToolHandle<GenericMonitoringTool>* monTool() { return m_monTool; }
1098
1099protected:
1100
1102
1104
1105 std::vector<ChainString> m_chainNames;
1106 std::vector<A*> m_analyses;
1107 std::string m_testType;
1108
1117
1118 std::string m_outputFileName;
1119
1124
1126
1128
1130
1132
1134
1136
1139
1140 ToolHandle<GenericMonitoringTool>* m_monTool;
1141
1142};
1143
1144
1145
1146#endif // TrigInDetAnalysisExample_T_AnalysisConfigMT_Tier0_H
1147
#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
emacs: this is -*- c++ -*-
TIDA::Associator< TIDA::Track > TrackAssociator
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.
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)
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...
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:572
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