ATLAS Offline Software
Loading...
Searching...
No Matches
T_AnalysisConfig.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11
12#ifndef TrigInDetAnalysisUtils_T_AnalysisConfig_H
13#define TrigInDetAnalysisUtils_T_AnalysisConfig_H
14
15#include <iostream>
16#include <sstream>
17#include <string>
18#include <map>
19
20#include "GaudiKernel/IToolSvc.h"
21#include "GaudiKernel/ITHistSvc.h"
22// #include "GaudiKernel/AlgFactory.h"
23
25
30
31
32// #include "TrigInDetAnalysisUtils/RoI.h"
33// #include "TrigInDetAnalysisUtils/Converter.h"
37
38#ifdef XAODTRACKING_TRACKPARTICLE_H
43#else
46#endif
47
48class MsgSvc;
49
50// class TrackAssociator;
51// class Converter;
52
53// class RoI;
54// class TrackFilter;
55
56template<class Provider>
58
59public:
60
61 // Full constructor: test/reference/selection
62 // - analysisInstanceName: the name of the analysis chain being created
63 // - xxxChainName: the name of the chain to be used as test/reference/selection; must be "StoreGate" in case of direct access to SG containers
64 // - xxxType: the type of tracks to be retrieved from the test/reference/selection chain or container
65 // - xxxKey: the key for tracks to be retrieved from the test/reference/selection chain or container
66 // - all standard operations are performed in loops over 0=test 1=reference 2=selection
67 T_AnalysisConfig(const std::string& analysisInstanceName,
68 const std::string& testChainName, const std::string& testType, const std::string& testKey,
69 const std::string& referenceChainName, const std::string& referenceType, const std::string& referenceKey,
70 const std::string& selectionChainName, const std::string& selectionType, const std::string& selectionKey,
71 TrackFilter* testFilter, TrackFilter* referenceFilter, TrackFilter* selectionFilter,
72 TrackAssociator* associator,
74 m_provider(0),
75 m_tdt(0),
76 m_analysisInstanceName(analysisInstanceName),
77 m_refChainName(referenceChainName),
78 m_refChainKey(referenceKey),
79 m_testChainName(testChainName),
80 m_testChainKey(testKey),
84 m_associator(associator),
86 m_mcTruth(false),
87 m_beamX(0),
88 m_beamY(0),
89 m_beamZ(0),
90 m_genericFlag(true),
91 m_releaseData(""),
92 m_keepAllEvents(false),
93 m_useHighestPT(false),
94 m_vtxIndex(-1),
95 m_filterOnRoi(true),
97 {
98 // Rearrange objects in vectors: chain names
99 std::vector<std::string> testChainNames; testChainNames.push_back(testChainName);
100 std::vector<std::string> referenceChainNames; referenceChainNames.push_back(referenceChainName);
101 std::vector<std::string> selectionChainNames; selectionChainNames.push_back(selectionChainName);
102 m_chainNames.push_back(testChainNames); m_chainNames.push_back(referenceChainNames); m_chainNames.push_back(selectionChainNames);
103 // Types
104 std::vector<std::string> testTypes; testTypes.push_back(testType);
105 std::vector<std::string> referenceTypes; referenceTypes.push_back(referenceType);
106 std::vector<std::string> selectionTypes; selectionTypes.push_back(selectionType);
107 m_types.push_back(testTypes); m_types.push_back(referenceTypes); m_types.push_back(selectionTypes);
108 // Keys
109 std::vector<std::string> testKeys; testKeys.push_back(testKey);
110 std::vector<std::string> referenceKeys; referenceKeys.push_back(referenceKey);
111 std::vector<std::string> selectionKeys; selectionKeys.push_back(selectionKey);
112 m_keys.push_back(testKeys); m_keys.push_back(referenceKeys); m_keys.push_back(selectionKeys);
113 // Filters
114 std::vector<TrackFilter*> testFilters; testFilters.push_back(testFilter);
115 std::vector<TrackFilter*> referenceFilters; referenceFilters.push_back(referenceFilter);
116 std::vector<TrackFilter*> selectionFilters; selectionFilters.push_back(selectionFilter);
117 m_filters.push_back(testFilters); m_filters.push_back(referenceFilters); m_filters.push_back(selectionFilters);
118 }
119
120
121 // Partial constructor: test/reference
122 // - analysisInstanceName: the name of the analysis chain being created
123 // - xxxChainName: the name of the chain to be used as test/reference; must be "StoreGate" in case of direct access to SG containers
124 // - xxxType: the type of tracks to be retrieved from the test/reference chain or container
125 // - xxxKey: the key for tracks to be retrieved from the test/reference chain or container
126 // - all standard operations are performed in loops over 0=test 1=reference 2=selection
127 T_AnalysisConfig(const std::string& analysisInstanceName,
128 const std::string& testChainName, const std::string& testType, const std::string& testKey,
129 const std::string& referenceChainName, const std::string& referenceType, const std::string& referenceKey,
130 TrackFilter* testFilter, TrackFilter* referenceFilter,
131 TrackAssociator* associator,
133 m_provider(0),
134 m_tdt(0),
135 m_analysisInstanceName(analysisInstanceName),
136 m_refChainName(referenceChainName),
137 m_refChainKey(referenceKey),
138 m_testChainName(testChainName),
139 m_testChainKey(testKey),
140 m_selectorRef(0),
142 m_selectorSel(0),
143 m_associator(associator),
145 m_mcTruth(false),
146 m_beamX(0),
147 m_beamY(0),
148 m_beamZ(0),
149 m_genericFlag(true),
150 m_releaseData(""),
151 m_keepAllEvents(false),
152 m_useHighestPT(false),
153 m_vtxIndex(-1),
154 m_filterOnRoi(true),
155 m_requireDecision(false)
156 {
157 // Rearrange objects in vectors: chain names
158 std::vector<std::string> testChainNames; testChainNames.push_back(testChainName);
159 std::vector<std::string> referenceChainNames; referenceChainNames.push_back(referenceChainName);
160 std::vector<std::string> selectionChainNames; selectionChainNames.push_back("NONE");
161 m_chainNames.push_back(testChainNames); m_chainNames.push_back(referenceChainNames); m_chainNames.push_back(selectionChainNames);
162 // Types
163 std::vector<std::string> testTypes; testTypes.push_back(testType);
164 std::vector<std::string> referenceTypes; referenceTypes.push_back(referenceType);
165 std::vector<std::string> selectionTypes; selectionTypes.push_back("");
166 m_types.push_back(testTypes); m_types.push_back(referenceTypes); m_types.push_back(selectionTypes);
167 // Keys
168 std::vector<std::string> testKeys; testKeys.push_back(testKey);
169 std::vector<std::string> referenceKeys; referenceKeys.push_back(referenceKey);
170 std::vector<std::string> selectionKeys; selectionKeys.push_back("");
171 m_keys.push_back(testKeys); m_keys.push_back(referenceKeys); m_keys.push_back(selectionKeys);
172 // Filters
173 std::vector<TrackFilter*> testFilters; testFilters.push_back(testFilter);
174 std::vector<TrackFilter*> referenceFilters; referenceFilters.push_back(referenceFilter);
175 std::vector<TrackFilter*> selectionFilters;
176 m_filters.push_back(testFilters); m_filters.push_back(referenceFilters); m_filters.push_back(selectionFilters);
177
178 // m_selectorRef = new TrigTrackSelector( referenceFilter );
179 // m_selectorTest = new TrigTrackSelector( testFilter );
180 }
181
182
183
184
185
186 // Destructor
188 // if ( m_selectorRef ) delete m_selectorRef;
189 // if ( m_selectorTest ) delete m_selectorTest;
190 // if ( m_selectorSel ) delete m_selectorSel;
191 // if ( m_analysis ) delete m_analysis;
192 }
193
194
195
196 // Configuration methods
197 void addTestChain(const std::string& chainName, const std::string& type, const std::string& key) {
198 m_chainNames[0].push_back(chainName); m_types[0].push_back(type); m_keys[0].push_back(key);
199 }
200
201 void addReferenceChain(const std::string& chainName, const std::string& type, const std::string& key) {
202 m_chainNames[1].push_back(chainName); m_types[1].push_back(type); m_keys[1].push_back(key);
203 }
204
205 void addSelectionChain(const std::string& chainName, const std::string& type, const std::string& key) {
206 m_chainNames[2].push_back(chainName); m_types[2].push_back(type); m_keys[2].push_back(key);
207 }
208
209 void addTestFilter(TrackFilter* filter) { m_filters[0].push_back(filter); }
210 void addReferenceFilter(TrackFilter* filter) { m_filters[1].push_back(filter); }
211 void addSelectionFilter(TrackFilter* filter) { m_filters[2].push_back(filter); }
212
213 // Initialize, execute and finalize generic methods
214 virtual void initialize(Provider* p, ToolHandle<Trig::TrigDecisionTool>* tdt ) {
215 m_provider = p;
216 m_tdt = tdt;
217 if ( m_tdt==0 ) m_analysis->initialise();
218
219 }
220
221
222
223 virtual void execute() {
224 if ( !m_provider ) std::cerr << "ERROR T_AnalysisConfig::execute() called without initialising" << std::endl;
225 loop();
226 }
227
228 virtual void finalize() { m_analysis->finalise(); }
229
230 virtual void book() { }
231
232 // Accessor methods
233 const std::string& name() const {return m_analysisInstanceName;}
234
235 const std::string testChains() const {
236 std::string name;
237 for(unsigned int i=0; i<m_chainNames[0].size(); i++)
238 name += (m_chainNames[0][i]+"::"+m_types[0][i]+"::"+m_keys[0][i]+" ");
239 return name;
240 }
241
242 const std::string referenceChains() const {
243 std::string name;
244 for(unsigned int i=0; i<m_chainNames[1].size(); i++)
245 name += (m_chainNames[1][i]+"::"+m_types[1][i]+"::"+m_keys[1][i]+" ");
246 return name;
247 }
248
249 const std::string selectionChains() const {
250 std::string name;
251 for(unsigned int i=0; i<m_chainNames[2].size(); i++)
252 name += (m_chainNames[2][i]+"::"+m_types[2][i]+"::"+m_keys[2][i]+" ");
253 return name;
254 }
255
256 const TrackAnalysis* analysis() const {return m_analysis;}
257
258 void setMCTruth(bool b=true) { m_mcTruth=b; }
259 bool mcTruth() const { return m_mcTruth; }
260
261 void setBeamX(double d) { m_beamX=d; }
262 void setBeamY(double d) { m_beamY=d; }
263 void setBeamZ(double d) { m_beamZ=d; }
264 double beamX() const { return m_beamX; }
265 double beamY() const { return m_beamY; }
266 double beamZ() const { return m_beamZ; }
267
268 bool genericFlag() const { return m_genericFlag; }
269 void setGenericFlag(bool b) { m_genericFlag=b; }
270
271 const std::string& releaseData() const { return m_releaseData; }
272 void releaseData(const std::string& s) { m_releaseData = s; }
273
274 void keepAllEvents( bool b ) { m_keepAllEvents = b; }
275
276 void setUseHighestPT( bool b ) { m_useHighestPT=b; }
277 bool getUseHighestPT() const { return m_useHighestPT; }
278
279 void setVtxIndex( int i ) { m_vtxIndex=i; }
280 int getVtxIndex() const { return m_vtxIndex; }
281
282 bool filterOnRoi() const { return m_filterOnRoi; }
283 bool setFilterOnRoi(bool b) { return m_filterOnRoi=b; }
284
286 bool requireDecision() const { return m_requireDecision; }
287
288protected:
289
290 virtual void loop() = 0;
291
292
294
295 template<class Collection>
296 std::pair< typename Collection::const_iterator, typename Collection::const_iterator >
298 const std::string& key="" ) {
299
302 // std::cout << "try " << key << "\t" << m_provider->evtStore()->template transientContains<Collection>(key) << std::endl;
303
306 std::string key_collection = key;
307 std::string key_tename = "";
308 size_t pos = key_collection.find("/");
309 if ( pos!=std::string::npos ) {
310 key_collection = key.substr( pos+1, key.size()-pos );
311 key_tename = key.substr( 0, pos );
312 }
313
314 std::pair< typename Collection::const_iterator,
315 typename Collection::const_iterator > itrpair;
316
317 SG::ReadHandle<Collection> handle(key);
318
319 CLID checkCLID;
320 const std::string* keyStr = m_provider->evtStore()->keyToString(roi_link.key(), checkCLID);
321 m_provider->msg(MSG::DEBUG) << "Requesting range over (" << key << ") associated to ROI from " << (keyStr == nullptr ? "UNKNOWN" : *keyStr) << endmsg;
322
323 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
324
325 return itrpair;
326 }
327
328
329
330
331
332
333
334
335
336
337
338
339
340 bool select( std::vector<TIDA::Vertex>& vertices,
343
344 xAOD::VertexContainer::const_iterator vtxitr = vtx_start;
345
346 for ( ; vtxitr!=vtx_end ; ++vtxitr ) {
347 if ( (*vtxitr)->vertexType()!=0 ) {
348 m_provider->msg(MSG::VERBOSE) << "\tvertex " << (*vtxitr)->z() << endmsg;
349
350 vertices.push_back( TIDA::Vertex( (*vtxitr)->x(),
351 (*vtxitr)->y(),
352 (*vtxitr)->z(),
354 (*vtxitr)->covariancePosition()(Trk::x,Trk::x),
355 (*vtxitr)->covariancePosition()(Trk::y,Trk::y),
356 (*vtxitr)->covariancePosition()(Trk::z,Trk::z),
357 (*vtxitr)->nTrackParticles(),
359 (*vtxitr)->chiSquared(),
360 (*vtxitr)->numberDoF() ) );
361
362 }
363 }
364
365 return true;
366 }
367
368
369 bool select( std::vector<TIDA::Vertex>& vertices,
371 const std::string& key="" ) {
372
373 m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer for key: " << key << endmsg;
374
376 xAOD::VertexContainer::const_iterator > vtx_itrpair = this->template getCollection<xAOD::VertexContainer>( roi_link, key );
377
378 if ( vtx_itrpair.first == vtx_itrpair.second ) {
379 m_provider->msg(MSG::WARNING) << "\tNo xAOD::Vertex collection for key " << key << endmsg;
380 return false;
381 }
382
383 m_provider->msg(MSG::DEBUG) << "\txAOD::VertexContainer found with size " << (vtx_itrpair.second - vtx_itrpair.first)
384 << "\t:" << key << endmsg;
385
386 return select( vertices, vtx_itrpair.first, vtx_itrpair.second );
387 }
388
389
390
391
392 bool select( std::vector<TIDA::Vertex>& vertices, const std::string& key="" ) {
393
394 m_provider->msg(MSG::VERBOSE) << "fetching AOD vertex container" << endmsg;
395
396 const xAOD::VertexContainer* xaodVtxCollection = 0;
397
398 if ( retrieve( xaodVtxCollection, key ).isFailure()) {
399 m_provider->msg(MSG::WARNING) << "xAOD vertex container not found with key " << key << endmsg;
400 return false;
401 }
402
403 if ( xaodVtxCollection!=0 ) {
404
405 m_provider->msg(MSG::VERBOSE) << "xAOD vertex container " << xaodVtxCollection->size() << " entries" << endmsg;
406
407 return select( vertices, xaodVtxCollection->begin(), xaodVtxCollection->end() );
408
409#if 0
410
411 xAOD::VertexContainer::const_iterator vtxitr = xaodVtxCollection->begin();
412
413 for ( ; vtxitr != xaodVtxCollection->end(); vtxitr++ ) {
414 if ( (*vtxitr)->nTrackParticles()>0 && (*vtxitr)->vertexType()!=0 ) {
415 vertices.push_back( TIDA::Vertex( (*vtxitr)->x(),
416 (*vtxitr)->y(),
417 (*vtxitr)->z(),
419 (*vtxitr)->covariancePosition()(Trk::x,Trk::x),
420 (*vtxitr)->covariancePosition()(Trk::y,Trk::y),
421 (*vtxitr)->covariancePosition()(Trk::z,Trk::z),
422 (*vtxitr)->nTrackParticles(),
424 (*vtxitr)->chiSquared(),
425 (*vtxitr)->numberDoF() ) );
426 }
427 }
428
429#endif
430
431 }
432
433 return true;
434 }
435
436
437
438 template<class Collection>
440 // const TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> roi_link,
442 const std::string& key="" ) {
443
444
447 // std::cout << "try " << key << "\t" << m_provider->evtStore()->template transientContains<Collection>(key) << std::endl;
448
451 std::string key_collection = key;
452 std::string key_tename = "";
453 size_t pos = key_collection.find("/");
454 if ( pos!=std::string::npos ) {
455 key_collection = key.substr( pos+1, key.size()-pos );
456 key_tename = key.substr( 0, pos );
457 }
458
459 std::pair< typename Collection::const_iterator,
460 typename Collection::const_iterator > itrpair;
461
462 SG::ReadHandle<Collection> handle(key);
463
464 CLID checkCLID;
465 const std::string* keyStr = m_provider->evtStore()->keyToString(roi_link.key(), checkCLID);
466 m_provider->msg(MSG::DEBUG) << "Requesting range over (" << key << ") associated to ROI from " << (keyStr == nullptr ? "UNKNOWN" : *keyStr) << endmsg;
467
468 itrpair = (*m_tdt)->associateToEventView( handle, roi_link );
469
470 if ( itrpair.first != itrpair.second ) {
471 selector->selectTracks( itrpair.first, itrpair.second );
472 return true;
473 }
474 else {
475 m_provider->msg(MSG::DEBUG) << "TDT TrackFeature collection (" << key << ") is empty " << endmsg;
476 return false;
477 }
478 }
479
480
481
483
484 template<class Collection>
485 bool selectTracks( TrigTrackSelector* selector, Trig::FeatureContainer::combination_const_iterator citr, const std::string& key="" ) {
486 // std::cout << "try " << key << "\t" << m_provider->evtStore()->template transientContains<Collection>(key) << std::endl;
487
488 std::string key_collection = key;
489 std::string key_tename = "";
490 size_t pos = key_collection.find("/");
491 if ( pos!=std::string::npos ) {
492 key_collection = key.substr( pos+1, key.size()-pos );
493 key_tename = key.substr( 0, pos );
494 }
495
496 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key_collection, TrigDefs::alsoDeactivateTEs, key_tename );
497 if ( !trackcollections.empty() ) {
498 // NB!! a combination should never have more than one entry for a track collection from a single algorithm, for single object triggers
499 for ( unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
500 Trig::Feature<Collection> trackfeature = trackcollections.at(ifeat);
501 if ( !trackfeature.empty() ) {
502 // actually select the tracks from this roi at last!!
503 const Collection* trigtracks = trackfeature.cptr();
504 selector->selectTracks( trigtracks );
505 }
506 }
507 return true;
508 }
509 else {
510 m_provider->msg(MSG::DEBUG) << "TDT TrackFeature collection (" << key << ") is empty " << endmsg;
511 return false;
512 }
513 }
514
515
517 template<class Collection>
518 bool selectTracks( TrigTrackSelector* selector, Trig::FeatureContainer::combination_const_iterator citr, const std::string& key, unsigned index ) {
519
520 // std::cout << "try " << key << "\t" << m_provider->evtStore()->template transientContains<Collection>(key) << std::endl;
521
522 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key, TrigDefs::alsoDeactivateTEs );
523 if ( !trackcollections.empty() ) {
524
525 const HLT::NavigationCore* nc = (*m_tdt)->ExperimentalAndExpertMethods().getNavigation();
526
527 // NB!! a combination should never have more than one entry for a track collection from a single algorithm,
528 // if ( trackcollections.size()>1 ) std::cerr << "SUTT OH NO!!!!!!!!" << endmsg;
529 // maybe a bit dodgy, if we really do have multiple objects returned, but that should only be for
530 // multiple object triggers - then probably none of this would work anyhow
531 for ( unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
532
533 Trig::Feature<Collection> trackfeature = trackcollections.at(ifeat);
534
536 const HLT::TriggerElement* te = trackfeature.te();
537
539 std::vector< const Collection* > collectionVector;
540 if ( !const_cast<HLT::NavigationCore *>(nc)->getFeatures( te, collectionVector, key ) ) return false;
541
542 // std::cout << "foundok " << foundok << "\tsize " << collectionVector.size() << std::endl;
543
545
546 for ( unsigned iv=collectionVector.size() ; iv-- ; ) {
550 if ( index!=iv ) continue;
552 // m_provider->msg(MSG::DEBUG) << "TDT TrackFeature->size() " << collectionVector[iv]->size() << " (" << key << ")" << endmsg;
553 selector->selectTracks( collectionVector[iv] );
554 break;
555 }
556 }
557 return true;
558 }
559 else {
560 m_provider->msg(MSG::DEBUG) << "TDT TrackFeature collection (" << key << ") is empty" << endmsg;
561 return false;
562 }
563 }
564
565
566
567 template<class Collection>
568 StatusCode retrieve( Collection const*& collection, const std::string& key="" ) {
571 if ( m_provider->evtStore()->template contains<Collection>( key ) ) {
572 SG::ReadHandle<Collection> handle(key);
573 if ( handle.isValid() ) {
576 collection = handle.cptr();
577 return StatusCode::SUCCESS;
578 }
579 }
580 return StatusCode::FAILURE;
581 }
582
583
584
585 template<class Collection>
586 bool selectTracks( TrigTrackSelector* selector, const std::string& key ) {
587 if ( key!="" ) {
588 SG::ReadHandle<Collection> handle(key);
589 if ( handle.isValid() ) {
591 // std::cout << "\t\t\t T_AnalysisConfig::selectTracks() - > TrackSelector" << std::endl;
592 selector->selectTracks( handle.cptr() );
593 return true;
594 }
595 }
596 return false;
597 }
598
599
600
601
602 template<class Collection>
603 bool selectTracksNotEmpty( TrigTrackSelector* selector, const std::string& key ) {
604 const Collection* collection = nullptr;
605 if ( key.empty() ) return false;
606 if ( !m_provider->evtStore()->template contains<Collection>( key ) ) return false;
607
608 StatusCode sc = retrieve( collection, key );
609
610 if ( !( sc.isSuccess() && collection ) ) return false;
611
612 m_provider->msg(MSG::DEBUG) << "SG Collection->size() " << collection->size() << " (" << key << ")" << endmsg;
613
614 // added to fix muon samples bug
615 if ( collection->size() == 0 ) {
616 m_provider->msg(MSG::WARNING) << "no particles in collection" << endmsg;
617 return false;
618 }
619
620 selector->selectTracks( collection );
621 return true;
622 }
623
624
625
626
627
628 template<class Collection>
629 std::vector<double> getBeamspot( const std::string& key ) {
630 const Collection* collection = 0;
631 std::vector<double> v;
632
633 if ( key!="" ) {
634 if ( m_provider->evtStore()->template contains<Collection>( key ) ) {
635 StatusCode sc = retrieve( collection, key );
636 if( sc.isSuccess() && collection ) {
637 m_provider->msg(MSG::DEBUG) << "SG Collection->size() " << collection->size() << " (" << key << ")" << endmsg;
638
639 typename Collection::const_iterator trackitr = collection->begin();
640 typename Collection::const_iterator trackend = collection->end();
641 if ( trackitr!=trackend ) {
642 v.resize(3);
643 v[0] = (*trackitr)->vx();
644 v[1] = (*trackitr)->vy();
645 v[2] = (*trackitr)->vz();
646 return v;
647 } // only need to look at the first track
648 }
649 }
650 }
651 return v;
652 }
653
654
655
656
657 template<class Collection>
658 std::vector<double> getBeamspot( Trig::FeatureContainer::combination_const_iterator citr, const std::string& key="" ) {
659 std::vector< Trig::Feature<Collection> > trackcollections = citr->get<Collection>( key, TrigDefs::alsoDeactivateTEs );
660 std::vector<double> v;
661 if ( !trackcollections.empty() ) {
662 // NB!! a combination should never have more than one entry for a track collection from a single algorithm,
663 // if ( trackcollections.size()>1 ) std::cerr << "SUTT OH NO!!!!!!!!" << endmsg;
664 for ( unsigned ifeat=0 ; ifeat<trackcollections.size() ; ifeat++ ) {
665 // std::cout << "selectTracks() ifeat=" << ifeat << "\tkey " << key << std::endl;
666 Trig::Feature<Collection> trackfeature = trackcollections.at(ifeat);
667 if ( !trackfeature.empty() ) {
668 // m_provider->msg(MSG::DEBUG) << "TDT TrackFeature->size() " << trackfeature.cptr()->size() << " (" << key << ")" << endmsg;
669 // actually select the tracks from this roi at last!!
670 const Collection* trigtracks = trackfeature.cptr();
671
672 typename Collection::const_iterator trackitr = trigtracks->begin();
673 typename Collection::const_iterator trackend = trigtracks->end();
674 if ( trackitr!=trackend ) {
675 v.resize(3);
676 v[0] = (*trackitr)->vx();
677 v[1] = (*trackitr)->vy();
678 v[2] = (*trackitr)->vz();
679 return v;
680 } // only need to look at the first track
681 }
682 }
683 return v;
684 }
685 else {
686 m_provider->msg(MSG::DEBUG) << "TDT TrackFeature collection (" << key << ") is empty " << endmsg;
687 return v;
688 }
689 }
690
691
692
693
694
698 unsigned processElectrons( TrigTrackSelector& selectorRef,
699 std::vector<TrackTrigObject>* elevec=0,
700 const unsigned int selection=0,
701 bool raw_track=false,
702 double ETOffline=0,
703# ifdef XAODTRACKING_TRACKPARTICLE_H
704 const std::string& containerName = "Electrons"
705# else
706 const std::string& containerName = "ElectronAODCollection"
707# endif
708 ) {
709
710 m_provider->msg(MSG::DEBUG) << "Fetching offline electrons: " << containerName << endmsg;
711
712 selectorRef.clear();
713
714# ifdef XAODTRACKING_TRACKPARTICLE_H
716# else
718# endif
719
720
721 const Container* container = 0;
722
723 if( ! m_provider->evtStore()->template contains<Container>(containerName) ) {
724 m_provider->msg(MSG::WARNING) << "Error No Electron Container " << containerName << " !" << endmsg;
725 return 0;
726 }
727
728 StatusCode sc = retrieve( container, containerName);
729 if( sc.isFailure() || !container ) {
730 m_provider->msg(MSG::WARNING) << "Error retrieving container: " << containerName << " !" << endmsg;
731 return 0;
732 }
733
734 m_provider->msg(MSG::DEBUG) << "Event with " << container->size() << " Electron object(s) " << endmsg;
735
736 Container::const_iterator elec = container->begin();
737 Container::const_iterator elec_end = container->end();
738
739 for( ; elec!=elec_end ; ++elec ){
740 //m_provider->msg(MSG::DEBUG) << " Electron " << (*elec)
741 // << ", eta " << (*elec)->eta()
742 // << ", phi " << (*elec)->phi()
743 // << ", ET " << (*elec)->pt()
744 // << ", author " << (*elec)->author()
745 // << ", trackParticle " << (*elec)->trackParticle()
746 // << ", conversion " << (*elec)->conversion()
747 // << ", mediumPP " << ((*elec)->isem(egammaPID::ElectronMediumPP)==0)
748 // << endmsg;
749
750 bool good_electron = false;
751# ifdef XAODTRACKING_TRACKPARTICLE_H
752 good_electron = TIDA::isGoodOffline( *(*elec), selection, ETOffline );
753# else
754 good_electron = TIDA::isGoodOffline( *(*elec));
755# endif
756
757 if (good_electron) {
758 const xAOD::Electron_v1& eleduff = *(*elec);
759 long unsigned eleid = (unsigned long)(&eleduff) ;
760 TrackTrigObject eleobj = TrackTrigObject( (*elec)->eta(),
761 (*elec)->phi(),
762 (*elec)->pt(),
763 0,
764 (*elec)->type(),
765 eleid );
766
767 bool trk_added ;
768 if ( raw_track ) trk_added = selectorRef.selectTrack( xAOD::EgammaHelpers::getOriginalTrackParticle( *elec ) );
769 else trk_added = selectorRef.selectTrack( (*elec)->trackParticle() );
770
771 if (trk_added) eleobj.addChild( selectorRef.tracks().back()->id() );
772 if (elevec) elevec->push_back( eleobj );
773 }
774 }
775
776 return selectorRef.tracks().size();
777 }
778
779
780
784 unsigned processMuons( TrigTrackSelector& selectorRef, const unsigned int selection=0,
785 double ETOffline=0,
786# ifdef XAODTRACKING_TRACKPARTICLE_H
787 const std::string& containerName = "Muons"
788# else
789 const std::string& containerName = "StacoMuonCollection"
790# endif
791 ) {
792
793# ifdef XAODTRACKING_TRACKPARTICLE_H
795# else
797# endif
798
799 m_provider->msg(MSG::DEBUG) << " Offline muons (" << containerName << ")" << endmsg;
800
801 selectorRef.clear();
802
803 const Container* container = 0;
804
805 if( ! m_provider->evtStore()->template contains<Container>(containerName) ) {
806 m_provider->msg(MSG::WARNING) << "Error No MuonCollection" << containerName << " !" << endmsg;
807 return 0;
808 }
809
810 StatusCode sc = retrieve( container, containerName );
811 if( sc.isFailure() || !container ) {
812 m_provider->msg(MSG::WARNING) << "Error retrieving " << containerName << " !" << endmsg;
813 return 0;
814 }
815
816 auto muon = container->begin();
817 auto muon_end = container->end();
818
819 // std::cout << "SUTT Offline muons " << container->size() << "\t threshold " << ETOffline << std::endl;
820
821 for( ; muon!=muon_end ; ++muon ){
822# ifdef XAODTRACKING_TRACKPARTICLE_H
823 if ( TIDA::isGoodOffline(*(*muon), selection, ETOffline ) ) selectorRef.selectTrack((*muon)->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle));
824# else
825 if ( TIDA::isGoodOffline(*(*muon)) ) selectorRef.selectTrack((*muon)->inDetTrackParticle());
826# endif
827 }
828
829
830 // std::cout << "SUTT found " << selectorRef.tracks().size() << " muons for " << containerName << std::endl;
831 m_provider->msg(MSG::DEBUG) << "found " << selectorRef.tracks().size() << " muons for " << containerName << endmsg;
832
833 return selectorRef.tracks().size();
834}
835
836
837
841unsigned processTaus( TrigTrackSelector& selectorRef,
842 std::vector<TrackTrigObject>* tauvec=0,
843 const unsigned selection=0,
844 int requireNtracks=0,
845 double EtCutOffline=0,
846 const std::string& containerName = "TauJets"
847 ) {
848
850
851 selectorRef.clear();
852
853 const Container* container = 0;
854
855 selectorRef.clear();
856
857 m_provider->msg(MSG::DEBUG) << " Offline taus " << containerName << endmsg;
858
859 if ( !m_provider->evtStore()->template contains<Container>(containerName)) {
860 m_provider->msg(MSG::WARNING) << " Offline taus not found" << endmsg;
861 return 0;
862 }
863
864 StatusCode sc = retrieve( container, containerName);
865 if (sc != StatusCode::SUCCESS) {
866 m_provider->msg(MSG::WARNING) << " Offline tau retrieval not successful" << endmsg;
867 return 0;
868 }
869
870 Container::const_iterator tau = container->begin();
871 Container::const_iterator tau_end = container->end();
872
873
874 for ( ; tau!=tau_end ; ++tau ) {
875
876# ifndef XAODTAU_VERSIONS_TAUJET_V3_H
877 int N = (*tau)->nTracks();
878 // std::cout << "SUTT no tau detail " << N << "\t3prong: " << doThreeProng << std::endl;
879# else
880 int N=0;
881 (*tau)->detail( xAOD::TauJetParameters::nChargedTracks, N );
882 // std::cout << "SUTT tau detail: N " << N << "\t3prong: " << doThreeProng << std::endl;
883# endif
884
885 bool good_tau = false;
886 good_tau = TIDA::isGoodOffline( *(*tau), selection, requireNtracks, EtCutOffline );
887
888 // std::cout << "SUTT tau ntracks: " << N << "\tgoodtau: " << good_tau << "\tpt: " << (*tau)->p4().Et() << "\t3prong: " << doThreeProng << std::endl;
889
890 if (good_tau){
891 const xAOD::TauJet_v3& duff = *(*tau);
892 long unsigned tauid = (unsigned long)(&duff) ;
893 TrackTrigObject tauobj = TrackTrigObject( (*tau)->eta(),
894 (*tau)->phi(),
895 (*tau)->pt(),
896 0,
897 (*tau)->type(),
898 tauid );
899
900 bool trk_added = false;
901
902 for ( unsigned i=N ; i-- ; ) {
903# ifdef XAODTAU_TAUTRACK_H
904
905 std::vector< ElementLink<xAOD::TrackParticleContainer> > alink = (*tau)->track(i)->trackLinks();
906
907 trk_added = false;
908
909 for ( size_t ilink=0 ; ilink<alink.size() ; ilink++ ) {
910 if ( alink[ilink].isValid() ) trk_added = selectorRef.selectTrack((*alink[ilink]));
911 }
913 // trk_added = selectorRef.selectTrack((*tau)->track(i)->track());
915# else
916 trk_added = selectorRef.selectTrack((*tau)->track(i));
917# endif
918 if ( trk_added ) tauobj.addChild( selectorRef.tracks().back()->id() );
919 }
920 if ( tauvec ) tauvec->push_back( tauobj );
921 }
922 }
923
924 return selectorRef.tracks().size();
925
926}
927
928protected:
929
930 // Athena tools
931
932 Provider* m_provider;
933
934 ToolHandle<Trig::TrigDecisionTool>* m_tdt;
935
936 // TrigInDetAnalysis tools
937 // Converter* m_converter;
938
939 // Analysis instance name
941
942 // Chain info
943 std::vector< std::vector<std::string> > m_chainNames;
944 std::vector< std::vector<std::string> > m_types;
945 std::vector< std::vector<std::string> > m_keys;
946
947 std::string m_refChainName;
948 std::string m_refChainKey;
949
950 std::string m_testChainName;
951 std::string m_testChainKey;
952
953 // Analysis tools
954 std::vector< std::vector<TrackFilter*> > m_filters;
955
959
962
964
966
968 std::string m_releaseData;
969
971
973
975
977
979
980};
981
982//}
983
984
985#endif // TrigInDetAnalysisUtils_T_AnalysisConfig_H
#define endmsg
uint32_t CLID
The Class ID type.
static Double_t sc
TIDA::Associator< TIDA::Track > TrackAssociator
base class for a single track selection filter allowing parameter setting for complex track selection
definition of StoreGate container holding a vector of Analysis::Muon
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.
The NavigationCore class, adds on top of the TrigNavStructure the EDM read-only handling.
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
storage of the time histories of all the cells
double beamX() const
std::pair< typename Collection::const_iterator, typename Collection::const_iterator > getCollection(const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
new MT feature access
const TrackAnalysis * analysis() const
bool setFilterOnRoi(bool b)
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="ElectronAODCollection")
select offline electrons
const std::string referenceChains() const
void setRequireDecision(bool b)
std::vector< std::vector< std::string > > m_chainNames
int getVtxIndex() const
TrackAnalysis * m_analysis
bool select(std::vector< TIDA::Vertex > &vertices, const std::string &key="")
bool requireDecision() const
const std::string & name() const
void addSelectionChain(const std::string &chainName, const std::string &type, const std::string &key)
bool select(std::vector< TIDA::Vertex > &vertices, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
void addTestChain(const std::string &chainName, const std::string &type, const std::string &key)
void setBeamY(double d)
void setVtxIndex(int i)
std::vector< std::vector< std::string > > m_types
virtual void finalize()
bool filterOnRoi() const
bool getUseHighestPT() const
std::string m_releaseData
TrigTrackSelector * m_selectorTest
TrigTrackSelector * m_selectorSel
std::string m_analysisInstanceName
bool selectTracks(TrigTrackSelector *selector, const ElementLink< TrigRoiDescriptorCollection > &roi_link, const std::string &key="")
std::string m_testChainKey
bool selectTracks(TrigTrackSelector *selector, const std::string &key)
std::vector< std::vector< TrackFilter * > > m_filters
unsigned processTaus(TrigTrackSelector &selectorRef, std::vector< TrackTrigObject > *tauvec=0, const unsigned selection=0, int requireNtracks=0, double EtCutOffline=0, const std::string &containerName="TauJets")
select offline taus
void setGenericFlag(bool b)
void keepAllEvents(bool b)
void setBeamZ(double d)
void addReferenceFilter(TrackFilter *filter)
bool selectTracks(TrigTrackSelector *selector, Trig::FeatureContainer::combination_const_iterator citr, const std::string &key="")
lagacy run 2 access
void addReferenceChain(const std::string &chainName, const std::string &type, const std::string &key)
void setUseHighestPT(bool b)
void addTestFilter(TrackFilter *filter)
std::string m_testChainName
void releaseData(const std::string &s)
TrigTrackSelector * m_selectorRef
unsigned processMuons(TrigTrackSelector &selectorRef, const unsigned int selection=0, double ETOffline=0, const std::string &containerName="StacoMuonCollection")
select offlinqe muons
double beamZ() const
void setBeamX(double d)
virtual void initialize(Provider *p, ToolHandle< Trig::TrigDecisionTool > *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, TrackFilter *testFilter, TrackFilter *referenceFilter, TrackAssociator *associator, TrackAnalysis *analysis)
const std::string selectionChains() const
virtual void loop()=0
StatusCode retrieve(Collection const *&collection, const std::string &key="")
std::string m_refChainName
std::vector< double > getBeamspot(Trig::FeatureContainer::combination_const_iterator citr, const std::string &key="")
std::vector< double > getBeamspot(const std::string &key)
void setMCTruth(bool b=true)
ToolHandle< Trig::TrigDecisionTool > * m_tdt
std::string m_refChainKey
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)
double beamY() const
bool genericFlag() const
const std::string testChains() const
void addSelectionFilter(TrackFilter *filter)
bool selectTracksNotEmpty(TrigTrackSelector *selector, const std::string &key)
bool selectTracks(TrigTrackSelector *selector, Trig::FeatureContainer::combination_const_iterator citr, const std::string &key, unsigned index)
NB: because we want to use this for the L2Star chains, we have to use this method,...
virtual ~T_AnalysisConfig()
TrackAssociator * m_associator
bool select(std::vector< TIDA::Vertex > &vertices, xAOD::VertexContainer::const_iterator vtx_start, xAOD::VertexContainer::const_iterator vtx_end)
virtual void book()
virtual void execute()
const std::string & releaseData() const
std::vector< std::vector< std::string > > m_keys
void addChild(unsigned long id)
virtual void clear() override
bool selectTrack(const Rec::TrackParticle *track)
neater code to make use of vector function also for a single ancestor pdgid, instead of the full code...
std::vector< Combination >::const_iterator combination_const_iterator
is basic vehicle of object access in TDT
Definition Feature.h:112
const T * cptr() const
explicit conversion to object
Definition Feature.h:171
const HLT::TriggerElement * te() const
explicit conversion to TriggerElement
Definition Feature.h:181
bool empty() const
test method to check if the object is truly there
Definition Feature.h:197
Class describing a tau jet.
Definition TauJet_v3.h:41
const std::string selection
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
bool isGoodOffline(const Analysis::Electron &elec)
@ x
Definition ParamDefs.h:55
@ z
global position (cartesian)
Definition ParamDefs.h:57
@ y
Definition ParamDefs.h:56
Definition index.py:1
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".