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