ATLAS Offline Software
Loading...
Searching...
No Matches
AnalysisConfigMT_Ntuple.cxx
Go to the documentation of this file.
1
8
10
13
15
17
23
26
27
28std::string date();
29
30
31//function to find true taus
32HepMC::ConstGenParticlePtr fromParent( int pdg_id, HepMC::ConstGenParticlePtr p, bool printout=false );
33
34
35
36template<class T>
37void remove_duplicates(std::vector<T>& vec) {
38 std::sort(vec.begin(), vec.end());
39 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
40}
41
42
44 std::set<std::string> chains;
45 const std::vector<std::string> configuredChains = (*m_tdt)->getListOfTriggers("L2_.*, EF_.*, HLT_.*");
46
47 if (m_provider->msg().level() <= MSG::VERBOSE) {
48 m_provider->msg(MSG::VERBOSE) << "␛[91;1m" << configuredChains.size() << " Configured Chains" << "␛[m" << endmsg;
49 }
50
51 for ( unsigned i=0 ; i<configuredChains.size() ; i++ ) {
52 if (m_provider->msg().level() <= MSG::VERBOSE) {
53 m_provider->msg(MSG::VERBOSE) << "␛[91;1m" << "Chain " << configuredChains[i] << " (ACN)␛[m" << endmsg;
54 }
55 chains.insert( configuredChains[i] );
56 }
57
58 std::vector<ChainString> chainNames;
59 std::vector<ChainString>::iterator chainitr = m_chainNames.begin();
60
62 while ( chainitr!=m_chainNames.end() ) {
63
65 ChainString& chainName = (*chainitr);
66
68
69 std::vector<std::string> selectChains;
70 selectChains.clear();
71 if ( chainitr->head()=="" ) selectChains.push_back("");
72 else selectChains = (*m_tdt)->getListOfTriggers( chainName.head() );
73
74 for ( unsigned iselected=0 ; iselected<selectChains.size() ; iselected++ ) {
75
76 selectChains[iselected] = chainName.subs( selectChains[iselected] );
77
79 chainNames.push_back( ChainString(selectChains[iselected]) );
80
81 m_provider->msg(MSG::INFO) << "␛[91;1m" << "Matching chain " << selectChains[iselected] << "␛[m" << endmsg;
82
85 if ( selectChains[iselected].find("cosmic")!=std::string::npos ) m_fiducial_radius = 1e10;
86
87 }
88
89 ++chainitr;
90 }
91
92 m_chainNames = chainNames;
93 return chains;
94}
95
96
98
99 m_provider->msg(MSG::DEBUG) << "␛[91;1m" << "AnalysisConfigMT_Ntuple::loop() for " << m_analysisInstanceName
100 << " compiled " << __DATE__ << " " << __TIME__ << "\t: " << date() << "␛[m" << endmsg;
101
102
103 bool foundOffline = false;
104
105 // get (offline) beam position
106 double xbeam = 0;
107 double ybeam = 0;
108 double zbeam = 0;
109 std::vector<double> beamline;
110
111
112 // get (online) beam position
113 double xbeam_online = 0;
114 double ybeam_online = 0;
115 double zbeam_online = 0;
116
117 std::vector<double> beamline_online;
118
119 // m_provider->msg(MSG::INFO) << " offline beam position\tx=" << xbeam << "\ty=" << ybeam << "\tz=" << zbeam << endmsg;
120 // m_provider->msg(MSG::INFO) << " online beam position\tx=" << xbeam_online << "\ty=" << ybeam_online << "\tz=" << zbeam_online << endmsg;
121
123 static const std::set<std::string> configuredHLTChains = get_configured_chains();
124
125 Filter_AcceptAll filter;
128 Filter_etaPT filterRef(5,500);
130 Filter_etaPT filter_etaPT(5.0,m_ptmin);
131 Filter_pdgIdpTeta filter_pdgIdpTeta(m_TruthPdgId,5.0,m_ptmin); // |eta|<5, pt>m_ptmin
132
133 TrackFilter* truthFilter = &filter_etaPT;
134
136
137 TrigTrackSelector selectorRef( &filter_etaPT );
138 TrigTrackSelector selectorTest( &filter );
139
140 TIDAVertexBuilder vertexBuilder;
141
142 if ( xbeam!=0 || ybeam!=0 ) {
143 selectorTruth.setBeamline( xbeam, ybeam, zbeam );
144 selectorRef.setBeamline( xbeam, ybeam, zbeam );
145 }
146
147 if ( xbeam_online!=0 || ybeam_online!=0 ) {
148 selectorTest.setBeamline( xbeam_online, ybeam_online, zbeam_online );
149 }
150
151 selectorTruth.correctTracks( true );
152 selectorRef.correctTracks( true );
153 selectorTest.correctTracks( true );
154
155
156 // clear the ntuple TIDA::Event class
157 m_event->clear();
158
159 const xAOD::EventInfo* pEventInfo = 0;
160
161 unsigned run_number = 0;
162 unsigned long long event_number = 0;
163 unsigned lumi_block = 0;
164 unsigned bunch_crossing_id = 0;
165 unsigned time_stamp = 0;
166 double mu_val = 0;
167
168 if ( retrieve(pEventInfo, "EventInfo").isFailure() ) {
169 m_provider->msg(MSG::DEBUG) << "Failed to get EventInfo " << endmsg;
170 }
171 else {
172 run_number = pEventInfo->runNumber();
173 event_number = pEventInfo->eventNumber();
174 lumi_block = pEventInfo->lumiBlock();
175 time_stamp = pEventInfo->timeStamp();
176 bunch_crossing_id = pEventInfo->bcid();
177 mu_val = pEventInfo->averageInteractionsPerCrossing();
178 }
179
180 m_provider->msg(MSG::DEBUG) << "run " << run_number
181 << "\tevent " << event_number
182 << "\tlb " << lumi_block << endmsg;
183
184 m_event->run_number(run_number);
185 m_event->event_number(event_number);
186 m_event->lumi_block(lumi_block);
187 m_event->time_stamp(time_stamp);
188 m_event->bunch_crossing_id(bunch_crossing_id);
189 m_event->mu(mu_val);
190
191 // build a chain group on the fly and use the reference
192 const Trig::ChainGroup* L2chain=(*m_tdt)->getChainGroup("L2_.*");
193 const Trig::ChainGroup* EFchain=(*m_tdt)->getChainGroup("EF_.*");
194 const Trig::ChainGroup* HLTchain=(*m_tdt)->getChainGroup("HLT_.*");
195
196 m_provider->msg(MSG::DEBUG) << "␛[91;1m"
197 << "L2 pass " << L2chain->isPassed() << "\t"
198 << "EF pass " << EFchain->isPassed() << "\t"
199 << "HLT pass " << HLTchain->isPassed() << "␛[m"
200 << endmsg;
201
204
205 bool analyse = false;
206
207 unsigned decisiontype = TrigDefs::Physics;
208
210
211 int passed_chains = 0;
212
213 m_provider->msg(MSG::DEBUG) << "Checking " << m_chainNames.size() << " chains" << endmsg;
214
215 if ( m_chainNames.empty() ) {
216 m_provider->msg(MSG::WARNING) << "No chains to check" << endmsg;
217 return;
218 }
219
220 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
221
222 std::string chainName = m_chainNames[ichain].head();
223
224 // Only for trigger chains
225
226 if (chainName.find("L2") == std::string::npos &&
227 chainName.find("EF") == std::string::npos &&
228 chainName.find("HLT") == std::string::npos ) continue;
229
230 if ( configuredHLTChains.find(chainName)==configuredHLTChains.end() ) {
231 m_provider->msg(MSG::WARNING) << "␛[91;1m" << "Chain " << chainName
232 << " is not configured for this event" << "␛[m"
233 << endmsg;
234 continue;
235 }
236
237 if ( m_chainNames[ichain].passed() ) decisiontype = TrigDefs::Physics;
238 else decisiontype = TrigDefs::includeFailedDecisions;
239
240 std::string roistring = "";
241 if ( m_chainNames[ichain].roi()!="" ) roistring += "\troi " + m_chainNames[ichain].roi();
242
243 bool passPhysics = (*m_tdt)->isPassed(chainName);
244
245 m_provider->msg(MSG::DEBUG) << "Chain " << chainName << "\troi " << roistring
246 << "\tpres " << (*m_tdt)->getPrescale(chainName)
247 << ( passPhysics ? "␛[91;1m" : "" ) << "\tpass physics " << passPhysics << ( passPhysics ? "␛[m" : "" )
248 << "\t: ( pass " << (*m_tdt)->isPassed(chainName, decisiontype ) << "\tdec type " << decisiontype << " ) " << endmsg;
249
250 if ( (*m_tdt)->isPassed(chainName, decisiontype ) || !m_chainNames[ichain].passed() ) {
251 analyse = true;
252 passed_chains++;
253 }
254
255 }
256
257
258
261 if ( !analyse && !m_keepAllEvents && !foundOffline ) {
262 m_provider->msg(MSG::DEBUG) << "No chains passed unprescaled - not processing this event: " << run_number << " " << event_number << " " << lumi_block << endmsg;
263 return;
264 }
265
266
267 m_provider->msg(MSG::DEBUG) << "Chains passed " << passed_chains << endmsg;
268
269
271
272 // const TruthParticleContainer* mcpartTES = 0;
273
274 selectorTruth.clear();
275
276 m_provider->msg(MSG::DEBUG) << "MC Truth flag " << m_mcTruth << endmsg;
277
278 if ( m_mcTruth) {
279 m_provider->msg(MSG::DEBUG) << "getting Truth" << endmsg;
280
281 if (m_provider->evtStore()->contains<TruthParticleContainer>("INav4MomTruthEvent")) {
282 //ESD
283 selectTracks<TruthParticleContainer>( &selectorTruth, "INav4MomTruthEvent" );
284 }
285 else if (m_provider->evtStore()->contains<TruthParticleContainer>("SpclMC")) {
287 selectTracks<TruthParticleContainer>( &selectorTruth, "SpclMC");
288 }
289 else if (m_provider->evtStore()->contains<TruthParticleContainer>("")) {
291 selectTracks<TruthParticleContainer>( &selectorTruth, "");
292 }
293 else if (m_provider->evtStore()->contains<xAOD::TruthParticleContainer>("TruthParticles")) {
295 selectTracks<xAOD::TruthParticleContainer>( &selectorTruth, "TruthParticles" );
296 }
297 else if (m_provider->evtStore()->contains<xAOD::TruthParticleContainer>("")) {
299 selectTracks<xAOD::TruthParticleContainer>( &selectorTruth, "" );
300 }
301 else {
302 m_provider->msg(MSG::WARNING) << "Truth not found - none whatsoever!" << endmsg;
303 }
304 }
305
306
307 // clear the ntuple TIDA::Event class
308 m_event->clear();
309
311
313
314 m_provider->msg(MSG::DEBUG) << " Offline tracks " << endmsg;
315
316 selectorRef.clear();
317
318 if (m_provider->evtStore()->contains<xAOD::TrackParticleContainer>("InDetTrackParticles")) {
319 selectTracks<xAOD::TrackParticleContainer>( &selectorRef, "InDetTrackParticles" );
320 }
321 else {
322 m_provider->msg(MSG::WARNING) << " Offline tracks not found " << endmsg;
323 }
324
325
327 for ( size_t iv=0; iv<m_vertexType.size(); iv++ ) {
328
329 std::vector<TIDA::Vertex> vertices;
330
331 std::string vertexType = "PrimaryVertices";
332 std::string vertexChainname = "Vertex";
333 if ( m_vertexType[iv]!="" ) {
334 vertexType = m_vertexType[iv];
335 vertexChainname += ":" + vertexType;
336 }
337
338 m_provider->msg(MSG::VERBOSE) << "fetching offline AOD vertex container with key " << vertexType << endmsg;
339
340 const xAOD::VertexContainer* xaodVtxCollection = 0;
341
342 if ( retrieve( xaodVtxCollection, vertexType ).isFailure()) {
343 if (m_provider->msg().level() <= MSG::WARNING) m_provider->msg(MSG::WARNING) << "xAOD vertex container not found with key " << vertexType << endmsg;
344 }
345
346 if ( xaodVtxCollection!=0 ) {
347
348 m_provider->msg(MSG::DEBUG) << "xAOD vertex container " << vertexType << " found with " << xaodVtxCollection->size() << " entries" << endmsg;
349
350 // Vertex types in some secondary vertex collections are not properly set and are all 0,
351 // allow these vertices if primary vertices are not used
352 if ( vertexType.find("SecVtx") != std::string::npos ) {
353 vertices = vertexBuilder.select( xaodVtxCollection, &selectorRef.tracks(), true );
354 }
355 else {
356 vertices = vertexBuilder.select( xaodVtxCollection, &selectorRef.tracks() );
357 }
358 }
359
360 // now add the offline vertices
361 if ( m_doOffline || m_doVertices ) {
362 m_event->addChain( vertexChainname );
363 m_event->back().addRoi(TIDARoiDescriptor(true));
364 m_event->back().back().addVertices( vertices );
365 }
366 }
367
369
371
372 if ( m_mcTruth ) {
373 m_event->addChain( "Truth" );
374 m_event->back().addRoi(TIDARoiDescriptor(true));
375 m_event->back().back().addTracks(selectorTruth.tracks());
376 }
377
378#if 0
380 for ( unsigned i=0 ; i<vertices.size() ; i++ ) {
381 m_provider->msg(MSG::DEBUG) << "vertex " << i << " " << vertices[i] << endmsg;
382 m_event->addVertex(vertices[i]);
383 }
384#endif
385
387
388 int Noff = 0;
389 int Nmu = 0;
390 int Nel = 0;
391 int Ntau = 0;
392
394
395 if ( m_doOffline ) {
396
397 m_event->addChain( "Offline" );
398 m_event->back().addRoi(TIDARoiDescriptor(true));
399 m_event->back().back().addTracks(selectorRef.tracks());
400
401 if ( selectorRef.getBeamX()!=0 || selectorRef.getBeamY()!=0 || selectorRef.getBeamZ()!=0 ) {
402 std::vector<double> beamline_;
403 beamline_.push_back( selectorRef.getBeamX() );
404 beamline_.push_back( selectorRef.getBeamY() );
405 beamline_.push_back( selectorRef.getBeamZ() );
406 m_event->back().back().addUserData(beamline_);
407 }
408
409
410 Noff = selectorRef.tracks().size();
411
412 m_provider->msg(MSG::DEBUG) << "ref tracks.size() " << selectorRef.tracks().size() << endmsg;
413 for ( int ii=selectorRef.tracks().size() ; ii-- ; ) m_provider->msg(MSG::DEBUG) << " ref track " << ii << " " << *selectorRef.tracks()[ii] << endmsg;
414
415 }
416
418 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
419
421 // m_provider->msg(MSG::INFO)<< "chain:\t" << m_chainNames[ichain] << endmsg;
422
424 std::string chainname = m_chainNames[ichain].head();
425 std::string collectionname = m_chainNames[ichain].tail();
426 std::string vtx_name = m_chainNames[ichain].vtx();
427
428
429 if ( chainname!="" ) continue;
430 if ( collectionname=="" ) continue;
431
432 chainname = collectionname;
433 if ( vtx_name!="" ) chainname += ":" + vtx_name;
434
435 // useful debug information - leave this here
436
439
440 selectorTest.clear();
441
442 bool found = false;
443
444 std::string collection_test = collectionname;
445 size_t pos = collectionname.find("/");
446 if ( pos!=std::string::npos ) collection_test = collectionname.substr( pos+1, collectionname.size()-pos );
447
448 if (m_provider->evtStore()->contains<xAOD::TrackParticleContainer>(collection_test)) {
449 found = selectTracks<xAOD::TrackParticleContainer>( &selectorTest, collectionname );
450 }
451 else if (m_provider->evtStore()->contains<TrackCollection>(collection_test)) {
452 found = selectTracks<TrackCollection>( &selectorTest, collectionname );
453 }
454 else {
455 m_provider->msg(MSG::WARNING) << "\tcollection " << collectionname << " not found" << endmsg;
456 }
457
458
460
461 std::vector<TIDA::Vertex> tidavertices;
462
463 m_provider->msg(MSG::DEBUG) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
464
465 if ( vtx_name!="" ) {
466
467 m_provider->msg(MSG::DEBUG) << "\tFetch xAOD::VertexContainer with key " << vtx_name << endmsg;
468
470
471 const xAOD::VertexContainer* xaodVtxCollection = 0;
472
473 if ( retrieve( xaodVtxCollection, vtx_name ).isFailure() ) {
474 if (m_provider->msg().level() <= MSG::WARNING) m_provider->msg(MSG::WARNING) << "xAOD vertex container not found with key " << vtx_name << endmsg;
475 }
476
477 if ( xaodVtxCollection!=0 ) {
478
479 m_provider->msg(MSG::DEBUG) << "\txAOD::VertexContainer found with size " << xaodVtxCollection->size()
480 << "\t" << vtx_name << endmsg;
481
482 // Vertex types in some secondary vertex collections are not properly set and are all 0,
483 // allow these vertices if primary vertices are not used
484 if ( vtx_name.find("SecVtx") != std::string::npos ) {
485 tidavertices = vertexBuilder.select( xaodVtxCollection, 0, true );
486 }
487 else {
488 tidavertices = vertexBuilder.select( xaodVtxCollection );
489 }
490 }
491
492 }
493
494
495 if ( found ) {
496
497 m_event->addChain( chainname );
498 m_event->back().addRoi(TIDARoiDescriptor(true));
499 if ( vtx_name!="" ) m_event->back().back().addVertices( tidavertices );
500 m_event->back().back().addTracks(selectorTest.tracks());
501
502 if ( selectorTest.getBeamX()!=0 || selectorTest.getBeamY()!=0 || selectorTest.getBeamZ()!=0 ) {
503 std::vector<double> beamline_;
504 beamline_.push_back( selectorTest.getBeamX() );
505 beamline_.push_back( selectorTest.getBeamY() );
506 beamline_.push_back( selectorTest.getBeamZ() );
507 m_event->back().back().addUserData(beamline_);
508 }
509
510 int Ntest = selectorTest.tracks().size();
511
512 m_provider->msg(MSG::DEBUG) << "collection " << collectionname << "\ttest tracks.size() " << Ntest << endmsg;
513 for ( int ii=Ntest ; ii-- ; ) m_provider->msg(MSG::DEBUG) << " test track " << ii << " " << *selectorTest.tracks()[ii] << endmsg;
514 }
515 }
516
517
518 std::string ElectronRef[7] = {
519 "",
520 "TightCB", "MediumCB", "LooseCB",
521 "TightLH", "MediumLH", "LooseLH" };
522
523
525
526 for ( size_t ielec=0 ; ielec<m_electronType.size() ; ielec++ ) {
529
530 int itype = -1;
531 for ( int it=0 ; it<7 ; it++ ) if ( m_electronType[ielec]==ElectronRef[it] ) itype = it;
532 if ( itype<0 ) continue;
533
534 std::vector<TrackTrigObject> elevec;
535
536 std::string echain = std::string("Electrons");
537 if (m_electronIsLRT[ielec]) echain = std::string("LRTElectrons");
538
539 int Nel_ = processElectrons( selectorRef, &elevec, itype, ( m_rawElectrons[ielec]=="raw" ? true : false ), 0.0, echain );
540
541 if ( Nel_ < 1 ) continue;
542
543 Nel += Nel_;
544
545 if ( m_electronType[ielec]!="" ) echain += "_" + m_electronType[ielec];
546 if ( m_rawElectrons[ielec]=="raw" ) echain += "_raw";
547
548 m_event->addChain( echain );
549 m_event->back().addRoi(TIDARoiDescriptor(true));
550 m_event->back().back().addTracks(selectorRef.tracks());
551 m_event->back().back().addObjects( elevec );
552
553 if ( selectorRef.getBeamX()!=0 || selectorRef.getBeamY()!=0 || selectorRef.getBeamZ()!=0 ) {
554 std::vector<double> beamline_;
555 beamline_.push_back( selectorRef.getBeamX() );
556 beamline_.push_back( selectorRef.getBeamY() );
557 beamline_.push_back( selectorRef.getBeamZ() );
558 m_event->back().back().addUserData(beamline_);
559 }
560
561 }
562
563
564 std::string MuonRef[5] = { "", "Tight", "Medium", "Loose", "VeryLoose" };
565
567 for ( size_t imuon=0 ; imuon<m_muonType.size() ; imuon++ ) {
568
569 m_provider->msg(MSG::DEBUG) << "fetching offline muons " << endmsg;
570
571 int muonType = -1;
572 for ( int it=0 ; it<5 ; it++ ) if ( m_muonType[imuon] == MuonRef[it] ) muonType=it;
573 if ( muonType<0 ) continue;
574
575 std::string mchain = "Muons";
576 if (m_muonIsLRT[imuon]) mchain = "MuonsLRT";
577
578 int Nmu_ = processMuons( selectorRef, muonType, 0, mchain );
579
580 if ( Nmu_ < 1 ) continue;
581
582 Nmu += Nmu_;
583
584 m_provider->msg(MSG::DEBUG) << "found " << Nmu << " offline muons " << endmsg;
585
586 if ( m_muonType[imuon]!="" ) mchain += "_" + m_muonType[imuon];
587
588 m_event->addChain(mchain);
589 m_event->back().addRoi(TIDARoiDescriptor(true));
590 m_event->back().back().addTracks(selectorRef.tracks());
591
592 if ( selectorRef.getBeamX()!=0 || selectorRef.getBeamY()!=0 || selectorRef.getBeamZ()!=0 ) {
593 std::vector<double> beamline_;
594 beamline_.push_back( selectorRef.getBeamX() );
595 beamline_.push_back( selectorRef.getBeamY() );
596 beamline_.push_back( selectorRef.getBeamZ() );
597 m_event->back().back().addUserData(beamline_);
598 }
599
600 m_provider->msg(MSG::DEBUG) << "ref muon tracks.size() " << selectorRef.tracks().size() << endmsg;
601 for ( int ii=selectorRef.tracks().size() ; ii-- ; ) m_provider->msg(MSG::DEBUG) << " ref muon track " << ii << " " << *selectorRef.tracks()[ii] << endmsg;
602 }
603
604
606 if ( m_doMuonsSP ) {
607
608 m_provider->msg(MSG::DEBUG) << "fetching offline muons " << endmsg;
609
610 int muonType = 0;
611
612 Nmu += processMuons( selectorRef, muonType );
613
614 m_provider->msg(MSG::DEBUG) << "found " << Nmu << " offline muons " << endmsg;
615
616 m_event->addChain("MuonsSP");
617 m_event->back().addRoi(TIDARoiDescriptor(true));
618 m_event->back().back().addTracks(selectorRef.tracks());
619
620 m_provider->msg(MSG::DEBUG) << "ref muon tracks.size() " << selectorRef.tracks().size() << endmsg;
621 for ( int ii=selectorRef.tracks().size() ; ii-- ; ) m_provider->msg(MSG::DEBUG) << " ref muon track " << ii << " " << *selectorRef.tracks()[ii] << endmsg;
622 }
623
624
625
627 std::string TauRef[4] = { "", "Tight", "Medium", "Loose" };
628
629
630 for ( size_t itau=0 ; itau<m_tauType.size() ; itau++ ) {
633
634 int itype = -1;
635 for ( int it=0 ; it<4 ; it++ ) if ( m_tauType[itau]==TauRef[it] ) itype = it;
636 if ( itype<0 ) continue;
637
639 int requireNtracks = 0;
640 if ( m_tauProngs[itau]=="3Prong" ) requireNtracks = 3;
641 if ( m_tauProngs[itau]=="1Prong" ) requireNtracks = 1;
642
643 std::vector<TrackTrigObject> tauvec;
644
645 int Ntau_ = processTaus( selectorRef, &tauvec, itype, requireNtracks, 20000 );
646
647 Ntau += Ntau_;
648
649 if ( Ntau_ > 0 ) {
652
653 std::string tchain = std::string("Taus");
654 if ( m_tauType[itau] != "" ) tchain += "_" + m_tauType[itau];
655 if ( m_tauProngs[itau] != "" ) tchain += "_" + m_tauProngs[itau];
656
657 m_event->addChain( tchain );
658 m_event->back().addRoi(TIDARoiDescriptor(true));
659 m_event->back().back().addTracks(selectorRef.tracks());
660 m_event->back().back().addObjects( tauvec ) ;
661
662 if ( selectorRef.getBeamX()!=0 || selectorRef.getBeamY()!=0 || selectorRef.getBeamZ()!=0 ) {
663 std::vector<double> beamline_;
664 beamline_.push_back( selectorRef.getBeamX() );
665 beamline_.push_back( selectorRef.getBeamY() );
666 beamline_.push_back( selectorRef.getBeamZ() );
667 m_event->back().back().addUserData(beamline_);
668 }
669
670 }
671 }
672
673 if ( Nmu==0 && Noff==0 && Nel==0 && Ntau==0 ) m_provider->msg(MSG::DEBUG) << "No offline objects found " << endmsg;
674 else foundOffline = true;
675
676
677 // now loop over all relevant chains to get the trigger tracks...
678
679 for ( unsigned ichain=0 ; ichain<m_chainNames.size() ; ichain++ ) {
680
681 // create chains for ntpl
682
684 const std::string& chainName = m_chainNames[ichain].head();
685
687 const std::string& collectionName = m_chainNames[ichain].tail();
688
689 if( chainName.find("L2_")==std::string::npos &&
690 chainName.find("EF_")==std::string::npos &&
691 chainName.find("HLT_")==std::string::npos ) continue;
692
693 if ( m_chainNames[ichain].passed() ) decisiontype = TrigDefs::Physics;
694 else decisiontype = TrigDefs::includeFailedDecisions;
695
696
697 m_provider->msg(MSG::DEBUG) << "chain " << chainName
698 << "\tprescale " << (*m_tdt)->getPrescale(chainName)
699 << "\tpass " << (*m_tdt)->isPassed(chainName) << " physics "
700 << " (req dec " << (*m_tdt)->isPassed(chainName, decisiontype ) << " dec type " << decisiontype << ")"
701 << endmsg;
702
705
707 if ( !(*m_tdt)->isPassed( chainName, decisiontype ) ) continue;
708
710
711
712 std::string roi_key = m_chainNames[ichain].roi();
713 std::string vtx_name = m_chainNames[ichain].vtx();
714
715
716#if 0
721
722
723 if ( roi_name!="" ) {
724
725 std::string roi_name_tmp = roi_name;
726 std::string roi_tename = "";
727
728 if ( roi_name.find("/")!=std::string::npos ) {
729 roi_name_tmp = roi_name.substr( roi_name.find("/")+1, roi_name.size()-roi_name.find("/") );
730 roi_tename = roi_name.substr( 0, roi_name.find("/") );
731 }
732
733 roist = comb->get<TrigRoiDescriptor>( roi_name_tmp, decisiontype, roi_tename );
734
735 if ( roist.size()>0 ) {
736 for ( unsigned ir=0 ; ir<roist.size() ; ir++ ) m_provider->msg(MSG::DEBUG) << "\t\tRetrieved roi " << roi_name << "\t" << *roist[ir].cptr() << endmsg;
737 }
738 else {
739 m_provider->msg(MSG::WARNING) << "\t\tRequested roi " << roi_name << " not found" << endmsg;
740 }
741
742 }
743 else {
744 roist = comb->get<TrigRoiDescriptor>("forID1");
745 if ( roist.empty() ) roist = comb->get<TrigRoiDescriptor>("forID");
746 if ( roist.empty() ) roist = comb->get<TrigRoiDescriptor>("");
747 if ( roist.empty() ) roist = comb->get<TrigRoiDescriptor>("initialRoI");
748 }
749#endif
750
751
752 unsigned feature_type = TrigDefs::lastFeatureOfType;
753
754 if ( roi_key!="" ) feature_type = TrigDefs::allFeaturesOfType;
755
756 int leg = -1;
757
758 if ( m_chainNames[ichain].element()!="" ) {
759 leg = std::atoi(m_chainNames[ichain].element().c_str());
760 }
761
762
763 std::string rgex = roi_key;
764
765 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> > rois =
766 (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
767 decisiontype,
768 rgex,
769 feature_type,
770 "roi",
771 leg ) );
772
775 if ( rois.empty() ) {
776 if ( !rgex.empty() ) {
777 rgex += "_probe";
778 rois = (*m_tdt)->template features<TrigRoiDescriptorCollection>( Trig::FeatureRequestDescriptor( chainName,
779 decisiontype,
780 rgex,
781 feature_type,
782 "roi",
783 leg ) );
784 }
785 }
786
787 int iroi = 0;
788
790
791 if ( rois.size()==0 ) continue;
792
794
795 m_event->addChain( m_chainNames[ichain] );
796
797 TIDA::Chain& chain = m_event->back();
798
800 for ( const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection>& roi_info : rois ) {
801
802 iroi++;
803
807
808 if ( roi_key=="SuperRoi" && iroi>1 ) continue;
809
810 if ( roi_key.find("JetSuper")!=std::string::npos && iroi>1 ) continue;
811
812 const ElementLink<TrigRoiDescriptorCollection> roi_link = roi_info.link;
813
815 if ( roi_key!="" && roi_link.dataID()!=rgex ) continue;
816
817 const TrigRoiDescriptor* const* roiptr = roi_link.cptr();
818
819 if ( roiptr == 0 ) {
820 // std::cerr << "\treadback link is null DAMMIT !!!" << std::endl;
821 continue;
822 }
823
824 if (m_provider->msg().level() <= MSG::VERBOSE) {
825 m_provider->msg(MSG::VERBOSE) << " RoI descriptor for seeded chain " << chainName << " " << **roiptr << endmsg;
826 }
827
829
831
834
837
838 selectorTest.clear();
839
840
841 if ( chainName.find("HLT_")!=std::string::npos || chainName.find("EF_")!=std::string::npos ) {
842 if ( selectTracks<xAOD::TrackParticleContainer>( &selectorTest, roi_link, collectionName ) );
843 else {
844 if (m_provider->msg().level() <= MSG::DEBUG) {
845 m_provider->msg(MSG::WARNING) << "\tNo track collection " << collectionName << " found" << endmsg;
846 }
847 }
848 }
849
851
852 std::vector<TIDA::Vertex> tidavertices;
853
854 if ( vtx_name!="" ) {
855
856 m_provider->msg(MSG::DEBUG) << "\tFetch xAOD::VertexContainer for chain " << chainName << " with key " << vtx_name << endmsg;
857
859
862
863 if ( vtx_itrpair.first == vtx_itrpair.second ) {
864 if ( m_provider->msg().level() <= MSG::DEBUG ) {
865 m_provider->msg(MSG::WARNING) << "\tNo xAOD::Vertex for chain " << chainName << " for key " << vtx_name << endmsg;
866 }
867 }
868 else {
869
870 m_provider->msg(MSG::DEBUG) << "\txAOD::VertexContainer found with size " << (vtx_itrpair.second - vtx_itrpair.first)
871 << "\t" << vtx_name << endmsg;
872
873 // Vertex types in some secondary vertex collections are not properly set and are all 0,
874 // allow these vertices if primary vertices are not used
875 if ( vtx_name.find("SecVtx") != std::string::npos ) {
876 tidavertices = vertexBuilder.select( vtx_itrpair.first, vtx_itrpair.second, &selectorRef.tracks(), true );
877 }
878 else {
879 tidavertices = vertexBuilder.select( vtx_itrpair.first, vtx_itrpair.second, &selectorTest.tracks() );
880 }
881 }
882 }
883
884#if 0
886 // now get the jets if they are present
887 std::vector<TrackTrigObject> jets;
888 if ( chainName.find("HLT_j")!=std::string::npos || chainName.find("EF_j")!=std::string::npos ) {
889 if ( get_jets( comb, jets ) == 0 ) m_provider->msg(MSG::WARNING) << "\tjets could not be retrieved " << endmsg;
890 }
891#endif
892
893 const std::vector<TIDA::Track*>& testTracks = selectorTest.tracks();
894 m_provider->msg(MSG::DEBUG) << "\ttest tracks.size() " << testTracks.size() << endmsg;
895 for (unsigned int ii=0; ii < testTracks.size(); ii++) {
896 m_provider->msg(MSG::DEBUG) << " test track " << ii << "for chain " << chainName + ":" + collectionName << " " << *testTracks[ii] << endmsg;
897 }
898
899
900 // only add chain if there are any rois - also add beamline position for postprocessing
901
902
903 if ( roi_tmp == 0 ) {
904 if ( testTracks.size()>0 ) m_provider->msg(MSG::WARNING) << "\ttest tracks.size() " << testTracks.size() << "found but no roi!!!" << endmsg;
905 roi_tmp = new TIDARoiDescriptor(true);
906 }
907
908 chain.addRoi( *roi_tmp );
909
910 chain.back().addTracks(testTracks);
911 chain.back().addVertices(tidavertices);
912
913#if 0
915 if ( chainName.find("HLT_j")!=std::string::npos ) chain.back().addObjects( jets );
916#endif
917
918 if ( selectorTest.getBeamX()!=0 || selectorTest.getBeamY()!=0 || selectorTest.getBeamZ()!=0 ) {
919 std::vector<double> beamline_;
920 beamline_.push_back( selectorTest.getBeamX() );
921 beamline_.push_back( selectorTest.getBeamY() );
922 beamline_.push_back( selectorTest.getBeamZ() );
923 chain.back().addUserData(beamline_);
924 }
925
926 delete roi_tmp;
927 roi_tmp = 0;
928
929 }
930
931 }
932
933#if 0
935
936 {
938
939 if ( filterOnRoi() || m_ptmin>0 ) {
940
941 TIDA::Chain* offline = 0;
942
943 std::vector<std::string> chainnames = m_event->chainnames();
944
946
947 for ( size_t ic=chainnames.size() ; ic-- ; ) {
948 if ( chainnames[ic] == "Offline" ) {
949 offline = &(m_event->chains()[ic]);
950 break;
951 }
952 }
953
954 if ( offline ) {
955
956 std::vector<TIDA::Chain>& chains = m_event->chains();
957 std::vector<TIDA::Chain>::iterator citr = chains.begin();
958
959 std::vector<std::pair<double,double> > philims;
960
961 for ( ; citr!=chains.end() ; ++citr ) {
962 if ( citr->name().find("HLT_")!=std::string::npos || citr->name().find("EF_")!=std::string::npos ) {
963 for ( size_t ir=0 ; ir<citr->size() ; ir++ ) {
964 TIDARoiDescriptor& roi = citr->rois()[ir].roi();
965 if ( roi.composite() ) {
966 for ( size_t isub=0 ; isub<roi.size() ; isub++ ) {
967 philims.push_back( std::pair<double,double>( roi[isub]->phiMinus(), roi[isub]->phiPlus() ) );
968 }
969 }
970 else philims.push_back( std::pair<double,double>( roi.phiMinus(), roi.phiPlus() ) );
971 }
972 }
973 }
974
975 remove_duplicates( philims );
976
977 for ( size_t iroi=0 ; iroi<offline->size() ; iroi++ ) {
978
979 std::vector<TIDA::Track>& tracks = offline->rois()[iroi].tracks();
980
983 // size_t Noffline = tracks.size();
984
985 for ( std::vector<TIDA::Track>::iterator it=tracks.begin() ; it<tracks.end() ; ) {
986 bool inc = true;
987 if ( m_ptmin>0 ) {
988 if ( std::fabs(it->pT())<m_ptmin ) { inc=false; tracks.erase( it ); }
989 }
990 if ( inc && filterOnRoi() ) {
991 bool remove_track = true;
992 for ( size_t isub=0 ; isub<philims.size() ; isub++ ) {
993
994 if ( philims[isub].first < philims[isub].second ) {
995 if ( it->phi()>=philims[isub].first && it->phi()<=philims[isub].second ) {
996 remove_track = false;
997 break;
998 }
999 }
1000 else {
1001 if ( it->phi()>=philims[isub].first || it->phi()<=philims[isub].second ) {
1002 remove_track = false;
1003 break;
1004 }
1005 }
1006 }
1007 if ( remove_track ) { inc=false; tracks.erase( it ); }
1008 }
1009 if ( inc ) ++it;
1010 }
1011
1014 // m_provider->msg(MSG::DEBUG) << "TIDA::Roi offline track reduction: " << Noffline << " -> " << tracks.size() << endmsg;
1015
1016 }
1017
1018 }
1019
1020 }
1021 }
1022
1023#endif
1024
1025 if ( m_Tree ) m_Tree->Fill();
1026
1027}
1028
1029
1030
std::string date()
sadly, includes a return at the end
Definition hcg.cxx:60
HepMC::ConstGenParticlePtr fromParent(int pdg_id, HepMC::ConstGenParticlePtr p, bool printout=false)
void remove_duplicates(std::vector< T > &vec)
#define endmsg
void remove_duplicates(std::vector< T > &vec)
std::vector< size_t > vec
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
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
std::set< std::string > get_configured_chains()
std::vector< std::string > m_tauType
std::vector< std::string > m_muonType
size_t get_jets(Trig::FeatureContainer::combination_const_iterator citr, std::vector< TrackTrigObject > &objects, const std::string &key="")
retrieve the jets from the Roi
std::vector< std::string > m_tauProngs
std::vector< ChainString > m_chainNames
std::vector< std::string > m_electronType
std::vector< std::string > m_rawElectrons
std::vector< bool > m_electronIsLRT
std::vector< bool > m_muonIsLRT
std::vector< std::string > m_vertexType
std::string subs(std::string s) const
const std::string & head() const
Definition ChainString.h:33
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
size_type size() const noexcept
Returns the number of elements in the collection.
Describes the Region of Interest geometry It has basically 8 parameters.
double phiPlus() const
double phiMinus() const
bool composite() const
composite RoI methods
static std::vector< TIDA::Vertex > select(const xAOD::VertexContainer *xAODVertices, const std::vector< TIDA::Track * > *trackCollection=0, bool useType0=false, bool require_tracks=true)
unsigned processMuons(TrigTrackSelector &selectorRef, const unsigned int selection=0, double ETOffline=0, const std::string &containerName="Muons")
std::pair< typename Collection::const_iterator, typename Collection::const_iterator > getCollection(const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
unsigned processElectrons(TrigTrackSelector &selectorRef, std::vector< TrackTrigObject > *elevec=0, const unsigned int selection=0, bool raw_track=false, double ETOffline=0, const std::string &containerName="Electrons")
bool selectTracks(TrigTrackSelector *selector, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
unsigned processTaus(TrigTrackSelector &selectorRef, std::vector< TrackTrigObject > *tauvec=0, const unsigned selection=0, int requireNtracks=0, double EtCutOffline=0, const std::string &containerName="TauJets")
StatusCode retrieve(Collection const *&collection, const std::string &key="")
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...
void setBeamline(double x, double y, double z=0)
void correctTracks(bool b=true)
double getBeamY() const
virtual void clear() override
double getBeamX() const
double getBeamZ() const
bool isPassed(unsigned int condition=TrigDefs::Physics) const
tells if chain group passed
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.
Definition zbeam.h:24
int ir
counter of the current depth
Definition fastadd.cxx:49
std::string date()
sadly, includes a return at the end
Definition hcg.cxx:60
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
static const unsigned int includeFailedDecisions
Run3 synonym of alsoDeactivateTEs.
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).
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
EventInfo_v1 EventInfo
Definition of the latest event info version.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22