23 #ifndef TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
24 #define TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H
40 #include "GaudiKernel/ToolHandle.h"
89 std::ostream&
operator<<( std::ostream&
s,
const std::vector<T>&
v) {
90 for (
size_t i=0 ;
i<
v.size() ;
i++ )
s <<
" " <<
v[
i];
95 template<
typename T,
typename A=AnalysisR3_Tier0>
108 const std::string& testChainName,
const std::string& testType,
const std::string& testKey,
109 const std::string& referenceChainName,
const std::string& referenceType,
const std::string& referenceKey,
115 testChainName, testType, testKey,
116 referenceChainName, referenceType, referenceKey,
117 testFilter, referenceFilter,
158 std::cout <<
"\nT_AnalysisConfigR3_Tier0::name: " <<
name() <<
"\t" <<
this << std::endl;
159 std::cout <<
"T_AnalysisConfigR3_Tier0::chain specification: " << testChainName <<
" -> " <<
chain <<
"\t" <<
chain.raw() << std::endl;
160 std::cout <<
"\tchain: " <<
chain.head() << std::endl;
161 std::cout <<
"\tkey: " <<
chain.tail() << std::endl;
162 std::cout <<
"\troi: " <<
chain.roi() << std::endl;
163 std::cout <<
"\tvtx: " <<
chain.vtx() << std::endl;
164 std::cout <<
"\tte: " <<
chain.element() << std::endl;
165 std::cout <<
"\textra: " <<
chain.extra() << std::endl;
167 std::cout <<
"\tpost: " <<
chain.post() << std::endl;
168 std::cout <<
"\tpt: " <<
chain.postvalue(
"pt") << std::endl;
268 std::vector<std::string> configuredChains = (*(
m_tdt))->getListOfTriggers(
"L2_.*, EF_.*, HLT_.*");
270 for (
unsigned i=0 ;
i<configuredChains.size() ;
i++ ) {
315 if (
m_mcTruth ) pselectorRef = &selectorTruth;
328 double beamline[4] = { 0, 0, 0, 0 };
338 unsigned long long event_number = 0;
339 unsigned lumi_block = 0;
340 unsigned bunch_crossing_id = 0;
341 unsigned time_stamp = 0;
347 if ( this->
template retrieve( pEventInfo,
"EventInfo" ).isFailure() ) {
355 bunch_crossing_id = pEventInfo->
bcid();
361 <<
"\tevent " << event_number
362 <<
"\tlb " << lumi_block <<
endmsg;
378 bool analyse =
false;
382 for (
unsigned ichain=0 ; ichain<
m_chainNames.size() ; ichain++ ) {
384 const std::string& chainname =
m_chainNames[ichain].head();
386 if ( chainname ==
"" ) analyse =
true;
390 if ( chainname.find(
"L2") == std::string::npos &&
391 chainname.find(
"EF") == std::string::npos &&
392 chainname.find(
"HLT") == std::string::npos )
continue;
396 <<
"\tpass " << (*m_tdt)->isPassed(chainname)
397 <<
"\tpres " << (*m_tdt)->getPrescale(chainname) <<
endmsg;
404 if ( (*(
m_tdt))->isPassed(chainname) ) analyse =
true;
421 selectorTruth.
clear();
428 std::vector<TIDA::Vertex> vertices;
429 std::vector<TIDA::Vertex> vertices_rec;
431 std::vector<double> refbeamspot;
432 std::vector<double> testbeamspot;
438 if ( !this->
select( vertices,
"PrimaryVertices" ) ) {
439 m_provider->msg(
MSG::VERBOSE) <<
"could not retrieve the 'PrimaryVertices' vertex collection" << std::endl;
453 for (
unsigned i=0 ;
i<vertices.size() ;
i++ ) {
464 std::vector<TIDA::Track*> offline_tracks;
465 std::vector<TIDA::Track*> electron_tracks;
466 std::vector<TIDA::Track*> muon_tracks;
468 std::vector<TIDA::Track*> ref_tracks;
469 std::vector<TIDA::Track*> test_tracks;
471 offline_tracks.clear();
472 electron_tracks.clear();
482 bool foundTruth =
false;
490 selectorTruth.
clear();
495 if (
m_provider->evtStore()->template contains<TruthParticleContainer>(
"INav4MomTruthEvent") ) {
497 this->
template selectTracks<TruthParticleContainer>( &selectorTruth,
"INav4MomTruthEvent" );
500 else if (
m_provider->evtStore()->template contains<TruthParticleContainer>(
"SpclMC") ) {
502 this->
template selectTracks<TruthParticleContainer>( &selectorTruth,
"SpclMC");
505 else if (
m_provider->evtStore()->template contains<xAOD::TruthParticleContainer>(
"TruthParticles") ) {
507 this->
template selectTracks<xAOD::TruthParticleContainer>( &selectorTruth,
"TruthParticles");
510 else if (
m_provider->evtStore()->template contains<TruthParticleContainer>(
"") ) {
512 this->
template selectTracks<TruthParticleContainer>( &selectorTruth,
"");
533 std::string
keys[4] = {
"GEN_AOD",
"TruthEvent",
"",
"G4Truth" };
535 std::string
key =
"";
537 bool foundcollection =
false;
539 for (
int ik=0 ; ik<4 ; ik++ ) {
545 if ( !
m_provider->evtStore()->template contains<McEventCollection>(
keys[ik]) ) {
554 if ( this->
template retrieve( mcevent,
keys[ik] ).isFailure() ) {
563 foundcollection =
true;
569 if ( !foundcollection ) {
571 m_provider->msg(MSG::WARNING) <<
"No MC Truth Collections of any sort, whatsoever!!!" <<
endmsg;
591 while ( evitr!=evend ) {
608 while ( pitr!=pend ) {
633 if(selectorTruth.
size() > 0) foundTruth =
true;
644 bool found_offline =
false;
648 this->
template selectTracks<xAOD::TrackParticleContainer>( pselectorRef,
m_offline_types[
it] );
649 refbeamspot = this->
template getBeamspot<xAOD::TrackParticleContainer>(
m_offline_types[
it] );
650 found_offline =
true;
657 if ( !found_offline ) {
658 if (
m_provider->evtStore()->template contains<Rec::TrackParticleContainer>(
"TrackParticleCandidate") ) {
660 this->
template selectTracks<Rec::TrackParticleContainer>( pselectorRef,
"TrackParticleCandidate" );
663 m_provider->msg(MSG::WARNING) <<
"Offline tracks not found: " <<
"TrackParticleCandidate" <<
endmsg;
676 for (
unsigned ichain=0 ; ichain<
m_chainNames.size() ; ichain++ ) {
681 const std::string& chainname =
m_chainNames[ichain].head();
683 const std::string& vtx_name =
m_chainNames[ichain].vtx();
691 std::string ptvalue =
m_chainNames[ichain].postvalue(
"pt");
696 unsigned decisiontype = TrigDefs::Physics;
698 if ( !
m_chainNames[ichain].
passed() ) decisiontype = TrigDefs::includeFailedDecisions;
707 <<
"\tpass " << (*m_tdt)->isPassed(chainname)
708 <<
"\tprescale " << (*m_tdt)->getPrescale(chainname) <<
endmsg;
725 if ( chainname!=
"" && !this->
m_keepAllEvents && !(*m_tdt)->isPassed( chainname, decisiontype ) )
continue;
735 std::vector<std::string> chainNames ;
741 chainNames.push_back(pTnP_tool->
tag());
742 chainNames.push_back(pTnP_tool->
probe());
746 for (
size_t i=0 ;
i<chainNames.size() ;
i++ ) {
759 pselectorTest->
clear();
769 if (
m_provider->evtStore()->template contains<xAOD::TrackParticleContainer>(
key) ) {
770 this->
template selectTracks<xAOD::TrackParticleContainer>( pselectorTest,
key );
771 refbeamspot = this->
template getBeamspot<xAOD::TrackParticleContainer>(
key );
774 const std::vector<TIDA::Track*>& testtracks = pselectorTest->
tracks();
776 chain.back().addTracks(testtracks);
778 if ( vtx_name!=
"" ) {
784 std::vector<TIDA::Vertex> tidavertices;
786 if ( this->
select( tidavertices, vtx_name ) )
chain.back().addVertices( tidavertices );
799 std::string roi_key = chainConfig.
roi();
801 unsigned feature_type =TrigDefs::lastFeatureOfType;
803 if ( roi_key!=
"" ) feature_type= TrigDefs::allFeaturesOfType;
809 if ( chainConfig.
element()!=
"" ) {
813 std::string rgex = roi_key;
815 std::vector< TrigCompositeUtils::LinkInfo<TrigRoiDescriptorCollection> >
rois =
826 if (
rois.empty() ) {
827 if ( !rgex.empty() ) {
848 if ( roi_key==
"SuperRoi" && iroi>1 )
continue;
855 if ( roi_key!=
"" && roi_link.
dataID()!=rgex )
continue;
858 if ( !roi_link.
isValid() )
continue;
862 if ( roiptr == 0 )
continue;
878 pselectorTest->
clear();
880 if ( this->
template selectTracks<xAOD::TrackParticleContainer>( pselectorTest, roi_link,
key ) ) { }
886 chain.addRoi( *roiInfo );
890 const std::vector<TIDA::Track*>& testtracks = pselectorTest->
tracks();
892 chain.back().addTracks(testtracks);
897 if ( vtx_name!=
"" ) {
899 std::vector<TIDA::Vertex> tidavertices;
901 this->
select( tidavertices, roi_link, vtx_name );
903 chain.back().addVertices( tidavertices );
910 std::cout <<
"\tTIDA analysis for chain: " << chainname <<
"\t key: " <<
key <<
"\t" << **roiptr << std::endl;
911 std::cout <<
"\tcollections: " <<
chain.back() << std::endl;
933 for (
unsigned ichain=0 ; ichain<eventp->
size() ; ichain++ ) {
937 const std::string& vtx_name = chainConfig.
vtx();
940 if (
m_tnp_flag && chainConfig.
extra().find(
"_tag")!=std::string::npos ) continue ;
942 std::vector<TIDA::Roi*>
rois ;
957 for (
unsigned iroi=0 ; iroi<
rois.size() ; iroi++ ) {
963 else filterRef.
setRoi( 0 );
988 ref_tracks = pselectorRef->
tracks(&filter_truth);
991 ref_tracks = pselectorRef->
tracks(&filterRef) ;
996 for (
int ii=pselectorRef->
tracks().size() ; ii-- ; ) {
1001 test_tracks.clear();
1004 for (
unsigned itrk=0 ; itrk<
rois.at(iroi)->tracks().
size() ; itrk++ ) {
1005 test_tracks.push_back(&(
rois.at(iroi)->tracks().at(itrk)));
1013 beamline[0] = pselectorTest->
getBeamX();
1014 beamline[1] = pselectorTest->
getBeamY();
1015 beamline[2] = pselectorTest->
getBeamZ();
1017 beamline[3] = vertices.size();
1043 associator->
match( test_tracks, ref_tracks );
1045 m_manalysis->execute( test_tracks, ref_tracks, associator, eventp, beamline );
1067 associator->
match( ref_tracks, test_tracks );
1074 m_manalysis->execute( ref_tracks, test_tracks, associator, eventp, beamline, &(
rois.at(iroi)->roi()) );
1076 if ( vtx_name!=
"" ) {
1078 std::vector<TIDA::Vertex>
vr =
rois.at(iroi)->vertices();
1079 std::vector<TIDA::Vertex*> vtx_rec;
1080 for (
unsigned iv=0 ; iv<
vr.size() ; iv++ ) vtx_rec.push_back( &
vr[iv] );
1082 std::vector<TIDA::Vertex*> vtx;
1084 for (
unsigned iv=0 ; iv<vertices.size() ; iv++ ) vtx.push_back( &vertices[iv] );
1087 if ( vertices.size()>
unsigned(this->getVtxIndex()) ) vtx.push_back( &vertices[this->
getVtxIndex()] );
1090 m_manalysis->execute_vtx( vtx, vtx_rec, eventp );
1098 <<
"\tevent " << event_number
1099 <<
"\tlb " << lumi_block <<
endmsg;
1123 if(
m_tdt->retrieve().isFailure() ) {
1125 m_provider->msg(MSG::ERROR) <<
" Unable to retrieve the TrigDecisionTool: Please check job options file" <<
endmsg;
1136 std::vector<std::string> configuredChains = (*(
m_tdt))->getListOfTriggers(
"L2_.*, EF_.*, HLT_.*");
1139 for (
unsigned i=0 ;
i<configuredChains.size() ;
i++ ) {
1157 std::string folder_name =
"";
1159 if (
name()!=
"" ) folder_name =
name();
1160 else folder_name =
"HLT/TRIDT/IDMon";
1165 std::string mongroup;
1171 if (
name().find(
"Shifter")!=std::string::npos ||
m_shifter ) {
1173 if (
m_chainNames.at(
ic).tail().find(
"_FTF") != std::string::npos ) mongroup = folder_name +
"/FTF";
1174 else if (
m_chainNames.at(
ic).tail().find(
"_IDTrig") != std::string::npos ||
1175 m_chainNames.at(
ic).tail().find(
"_EFID") != std::string::npos ) mongroup = folder_name +
"/EFID";
1176 else if (
m_chainNames.at(
ic).tail().find(
"InDetTrigParticle") != std::string::npos ) mongroup = folder_name +
"/EFID_RUN1";
1177 else if (
m_chainNames.at(
ic).tail().find(
"_GSF") != std::string::npos ) mongroup = folder_name +
"/GSF";
1178 else mongroup = folder_name +
"/Unknown";
1190 std::string track_collection =
"";
1198 if ( track_collection!=
"" ) track_collection +=
"_" +
m_chainNames[
ic].roi();
1203 if ( track_collection!=
"" ) track_collection +=
"_" +
m_chainNames[
ic].vtx();
1209 if ( track_collection!=
"" ) track_collection +=
"_" +
m_chainNames[
ic].element();
1213 if ( track_collection!=
"" ) mongroup += track_collection;
1304 #endif // TrigInDetAnalysisExample_T_AnalysisConfigR3_Tier0_H