From 66bff8e282a87deb9c34e55f788138f3624377ce Mon Sep 17 00:00:00 2001
From: Mark Sutton <mark.sutton@cern.ch>
Date: Tue, 24 Jan 2017 19:02:06 +0100
Subject: [PATCH] update offline electron selection
 (TrigInDetAnalysisExample-00-04-04)

        * TrigInDetAnalysisExample-00-04-04
        * update offline electron selection

2017-01-24 sutt < sutt @ cern.ch >
        * TrigInDetAnalysisExample-00-04-03
        * extend offline electron selection

2017-01-24 sutt < sutt @ cern.ch >
        * TrigInDetAnalysisExample-00-04-02
        * extend offline electron selection

2017-01-18 sutt < sutt @ cern.ch >
        * TrigInDetAnalysisExample-00-04-01
        * add electron offline raw track capability

2016-12-20 sutt < sutt @ cern.ch >
        * TrigInDetAnalysisExample-00-04-00
        * promote local printout and fix tag

2016-12-20 sutt < sutt @ cern.ch >
...
(Long ChangeLog diff - truncated)
---
 .../AnalysisConfig_Ntuple.h                   | 38 +++++++++--
 .../T_AnalysisConfig_Tier0.h                  | 11 ++--
 .../src/AnalysisConfig_Ntuple.cxx             | 64 +++++++++++++++----
 .../src/VtxAnalysis.cxx                       | 12 ++--
 4 files changed, 99 insertions(+), 26 deletions(-)

diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Ntuple.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Ntuple.h
index 4580dcecdf7..c131680a323 100644
--- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Ntuple.h
+++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/AnalysisConfig_Ntuple.h
@@ -16,10 +16,11 @@
 
 #include "TrkParticleCreator/TrackParticleCreatorTool.h"
 
-
 #include "TTree.h"
 #include "TFile.h"
 
+#define endreq endmsg
+
 class AnalysisConfig_Ntuple : public T_AnalysisConfig<IHLTMonTool> { 
     
 public:
@@ -32,6 +33,7 @@ public:
     // - roiInfo: in case the test chain is a real chain, this is used to specify RoI widths; in case the test chain is a fake chain, this is used 
     //   for RoI position too
     // - all standard operations are performed in loops over 0=test 1=reference 2=selection
+
   AnalysisConfig_Ntuple(TIDARoiDescriptor* roiInfo, 
 			const std::vector<std::string>& chainNames, std::string outputFileName="TrkNtuple.root", 
 			double tauEtCutOffline=0.0, int TruthPdgId = 0, bool _keepAllEvents=false) : 
@@ -57,6 +59,8 @@ public:
     m_doElectrons_tightLH(false),
     m_doElectrons_mediumLH(false),
     m_doElectrons_looseLH(false),
+    m_electronType(),
+    m_rawElectrons(),
     m_doTaus_1Prong(false),
     m_doTaus_tight_1Prong(false),
     m_doTaus_medium_1Prong(false),
@@ -78,7 +82,7 @@ public:
 
     for ( unsigned i=0 ; i<chainNames.size() ; i++ ) { 
       if ( chainNames[i] != "Offline"     &&
-	   chainNames[i] != "Electrons"   &&
+	   chainNames[i].find("Electrons")!=0 &&
 	   chainNames[i] != "Muons"       &&
 	   chainNames[i] != "Taus_1Prong" &&
 	   chainNames[i] != "Taus_3Prong" &&
@@ -87,13 +91,33 @@ public:
 	//	std::cout << "AnalysisConfig_Ntuple: chain[" << i << "] " << chainNames[i] << std::endl;
 	
 	m_chainNames.push_back( ChainString(chainNames[i]) );
-
 	
       }
 
+      ChainString chain(chainNames[i]);
+
+      //      std::cout << "\tchain " << i << "\t" << chainNames[i] << std::endl;
+      //      std::cout << "\t\t\t"                << chain         << std::endl;
+
       if ( chainNames[i]=="Offline" )     m_doOffline     = true;
       if ( chainNames[i]=="Vertex" )      m_doVertices    = true;
-      if ( chainNames[i]=="Electrons" )   m_doElectrons   = true;
+
+
+      if ( chain.head()=="Electrons" ) { 
+
+	// m_doElectrons = true;
+	
+	if ( chain.tail()!="" || chain.extra()!="" ) { 
+	  //  std::cout << "\telectrons.head  " << chain.head() << std::endl;
+	  //  std::cout << "\telectrons.tail  " << chain.tail() << std::endl;
+	  //  std::cout << "\telectrons.extra " << chain.extra() << std::endl;
+	  
+	  m_electronType.push_back(chain.tail());
+	  m_rawElectrons.push_back(chain.extra());
+	}
+      }
+      
+      if ( chainNames[i]=="Electrons" )          m_doElectrons   = true;
       if ( chainNames[i]=="Electrons_TightCB" )  m_doElectrons_tightCB  = true;
       if ( chainNames[i]=="Electrons_MediumCB" ) m_doElectrons_mediumCB = true;
       if ( chainNames[i]=="Electrons_LooseCB" )  m_doElectrons_looseCB  = true;
@@ -116,6 +140,7 @@ public:
     m_outputFileName=outputFileName;
   }
   
+  
 
   virtual ~AnalysisConfig_Ntuple() {
     //    std::cout << "AnalysisConfig_Ntuple::~AnalysisConfig_Ntuple() running destructor" << std::endl;
@@ -147,6 +172,7 @@ protected:
   bool m_doVertices;
   bool m_doMuons;
   bool m_doMuonsSP;
+
   bool m_doElectrons;
   bool m_doElectrons_tightCB;
   bool m_doElectrons_mediumCB;
@@ -154,6 +180,10 @@ protected:
   bool m_doElectrons_tightLH;
   bool m_doElectrons_mediumLH;
   bool m_doElectrons_looseLH;
+
+  std::vector<std::string>  m_electronType;
+  std::vector<std::string>  m_rawElectrons;
+
   bool m_doTaus_1Prong;
   bool m_doTaus_tight_1Prong;
   bool m_doTaus_medium_1Prong;
diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h
index 2a5745e624d..a520fa022a1 100644
--- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h
+++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/TrigInDetAnalysisExample/T_AnalysisConfig_Tier0.h
@@ -86,6 +86,7 @@
 // the xAOD::TrackParticle header if it exists
 #include "TrkParticleCreator/TrackParticleCreatorTool.h"
 
+#define endreq endmsg
 
 
 template<typename T>
@@ -636,8 +637,8 @@ protected:
         m_provider->msg(MSG::VERBOSE) << "fetching features for chain " << chainname << endreq;
       }
 
-      if(m_provider->msg().level() <= MSG::INFO){
-        m_provider->msg(MSG::INFO) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endreq;
+      if(m_provider->msg().level() <= MSG::VERBOSE){
+        m_provider->msg(MSG::VERBOSE) << chainname << "\tpassed: " << (*m_tdt)->isPassed( chainname ) << endreq;
       }
 
       //      std::cout << "\tstatus for chain " << chainname
@@ -826,7 +827,7 @@ protected:
 
 	if ( vtx_name!="" ) { 
 
-	  m_provider->msg(MSG::INFO) << "\tFetch xAOD::VertexContainer for chain " << chainConfig << " with key " << vtx_name << endreq;
+	  m_provider->msg(MSG::VERBOSE) << "\tFetch xAOD::VertexContainer for chain " << chainConfig << " with key " << vtx_name << endreq;
 
 	  std::vector< Trig::Feature<xAOD::VertexContainer> > xaodtrigvertices = c->get<xAOD::VertexContainer>(vtx_name);
 	  
@@ -835,13 +836,13 @@ protected:
 	  }
 	  else {
 	    
-	    m_provider->msg(MSG::INFO) << "\txAOD::VertexContainer found with size  " << xaodtrigvertices.size() << "\t" << vtx_name << endreq;
+	    m_provider->msg(MSG::VERBOSE) << "\txAOD::VertexContainer found with size  " << xaodtrigvertices.size() << "\t" << vtx_name << endreq;
 	    
 	    for (  unsigned iv=0  ;  iv<xaodtrigvertices.size()  ;  iv++ ) {
 	      
 	      const xAOD::VertexContainer* vert = xaodtrigvertices[iv].cptr();
 	      
-	      m_provider->msg(MSG::INFO) << "\t" << iv << "  xAOD VxContainer for " << chainConfig << " " << vert << " key " << vtx_name << endreq;
+	      m_provider->msg(MSG::VERBOSE) << "\t" << iv << "  xAOD VxContainer for " << chainConfig << " " << vert << " key " << vtx_name << endreq;
 	      
 	      xAOD::VertexContainer::const_iterator vtxitr = vert->begin();
 	      
diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisConfig_Ntuple.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisConfig_Ntuple.cxx
index b06950170c9..a8bc92e503c 100644
--- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisConfig_Ntuple.cxx
+++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/AnalysisConfig_Ntuple.cxx
@@ -63,6 +63,7 @@
 #include "TrkParticleCreator/TrackParticleCreatorTool.h"
 
 
+#define endreq endmsg
 
 
 bool tida_first = true;
@@ -419,9 +420,11 @@ void AnalysisConfig_Ntuple::loop() {
 
 	    std::string chainName = configuredChains[i];
 
+#if 0
 	    std::cout << "" << "Chain " << configuredChains[i]
 		      << "\tpassed:     " <<   (*m_tdt)->isPassed(configuredChains[i], _decisiontype)  << " ( type " << _decisiontype << ") : "  
 		      << "\trequiredec: " <<   (*m_tdt)->isPassed(configuredChains[i], TrigDefs::requireDecision)  << "   (ACN)" << std::endl;
+#endif
 	    if ( (*m_tdt)->isPassed(configuredChains[i], _decisiontype) ) { 
 	      npassed++;
 	      passed.push_back(configuredChains[i]);
@@ -801,7 +804,7 @@ void AnalysisConfig_Ntuple::loop() {
 
 	//	std::vector<TIDA::Vertex> vertices;
 	
-	m_provider->msg(MSG::INFO) << "fetching AOD Primary vertex container" << endreq;
+	m_provider->msg(MSG::VERBOSE) << "fetching AOD Primary vertex container" << endreq;
 
 	const xAOD::VertexContainer* xaodVtxCollection = 0;
 
@@ -974,19 +977,58 @@ void AnalysisConfig_Ntuple::loop() {
 
 
 	std::string ElectronRef[7] =  { 
-	  "Electrons", 
-	  "Electrons_TightCB", "Electrons_MediumCB", "Electrons_LooseCB",
-	  "Electrons_TightLH", "Electrons_MediumLH", "Electrons_LooseLH" };
+	  "", 
+	  "TightCB", "MediumCB", "LooseCB",
+	  "TightLH", "MediumLH", "LooseLH" };
  
 	bool ElectronTypes[7] = { 
 	  m_doElectrons, 
 	  m_doElectrons_tightCB,   m_doElectrons_mediumCB,   m_doElectrons_looseCB,  
 	  m_doElectrons_tightLH,   m_doElectrons_mediumLH,   m_doElectrons_looseLH };
 
+
+	/// new electron selection 
+
+	for ( size_t ielec=0 ; ielec<m_electronType.size() ; ielec++ ) {
+	  /// hmm, if we stored the types as a map it would be more 
+	  /// straightforward than having to stick all this in a loop
+
+	  int itype = -1;
+	  for ( int it=0 ; it<7 ; it++ ) if ( m_electronType[ielec]==ElectronRef[it] ) itype = it; 
+	  if ( itype<0 ) continue;
+
+	  //	  std::cout << "\tElectrons selection " << ielec << " " << m_electronType[ielec] 
+	  //		    << "\t" << itype << " " << ElectronRef[itype] << "\t" << m_rawElectrons[ielec] << std::endl;
+	  
+	  Nel += processElectrons( selectorRef, itype, ( m_rawElectrons[ielec]=="raw" ? true : false ) );
+	
+	  std::string echain = std::string("Electrons_") + m_electronType[ielec];
+	  if ( m_rawElectrons[ielec]=="raw" ) echain += "_raw";
+	  
+	  m_event->addChain( echain );
+	  m_event->back().addRoi(TIDARoiDescriptor(true));
+	  m_event->back().back().addTracks(selectorRef.tracks());
+	  if ( selectorRef.getBeamX()!=0 || selectorRef.getBeamY()!=0 || selectorRef.getBeamZ()!=0 ) { 
+	    std::vector<double> _beamline;
+	    _beamline.push_back( selectorRef.getBeamX() );
+	    _beamline.push_back( selectorRef.getBeamY() );
+	    _beamline.push_back( selectorRef.getBeamZ() );
+	    m_event->back().back().addUserData(_beamline);
+	  }
+	  else { 	  
+	    m_event->back().back().addUserData(beamline);
+	  }
+	}
+	
+       
+
+	/// old electron selection 
+	
 	for ( int ielec=0 ; ielec<7 ; ielec++ ) {
 	  if ( ElectronTypes[ielec] ) {   
-	    Nel = processElectrons( selectorRef, ielec ); ///
-	    m_event->addChain( ElectronRef[ielec] );
+	    Nel += processElectrons( selectorRef, ielec, false ); ///
+	    if ( ElectronRef[ielec]=="" ) m_event->addChain( "Electrons" );
+	    else                          m_event->addChain( std::string("oldElectrons0_")+ ElectronRef[ielec] );
 	    m_event->back().addRoi(TIDARoiDescriptor(true));
 	    m_event->back().back().addTracks(selectorRef.tracks());
 	    if ( selectorRef.getBeamX()!=0 || selectorRef.getBeamY()!=0 || selectorRef.getBeamZ()!=0 ) { 
@@ -1002,14 +1044,14 @@ void AnalysisConfig_Ntuple::loop() {
 	  }
 	}	  
 
-	//	std::cout << "SUTT doMuons " << m_doMuons << std::endl;
+	//	std::cout << "doMuons " << m_doMuons << std::endl;
 
 	/// get muons 
 	if ( m_doMuons ) { 
 	  
 	  m_provider->msg(MSG::INFO) << "fetching offline muons " << endreq; 
 
-	  Nmu   = processMuons( selectorRef );
+	  Nmu += processMuons( selectorRef );
 
 	  m_provider->msg(MSG::INFO) << "found " << Nmu << " offline muons " << endreq; 
 
@@ -1039,7 +1081,7 @@ void AnalysisConfig_Ntuple::loop() {
 	  
 	  m_provider->msg(MSG::INFO) << "fetching offline muons " << endreq; 
 
-	  Nmu   = processMuons( selectorRef );
+	  Nmu += processMuons( selectorRef );
 
 	  m_provider->msg(MSG::INFO) << "found " << Nmu << " offline muons " << endreq; 
 
@@ -1361,8 +1403,8 @@ void AnalysisConfig_Ntuple::loop() {
 			  else if ( selectTracks<TrigInDetTrackCollection>( &selectorTest, comb, truthMap, collectionName, collectionName_index ) );
 #ifdef XAODTRACKING_TRACKPARTICLE_H
 			  else {
-			    m_provider->msg(MSG::INFO) << "\tsearch for xAOD::TrackParticle " << collectionName << endreq;  
-			    if ( selectTracks<xAOD::TrackParticleContainer>( &selectorTest, comb, collectionName ) ) m_provider->msg(MSG::WARNING) << "\tFound xAOD collection " << collectionName << " (Ntple)"  << endreq;  
+			    // m_provider->msg(MSG::INFO) << "\tsearch for xAOD::TrackParticle " << collectionName << endreq;  
+			    if ( selectTracks<xAOD::TrackParticleContainer>( &selectorTest, comb, collectionName ) ); //m_provider->msg(MSG::INFO) << "\tFound xAOD collection " << collectionName << " (Ntple)"  << endreq;  
 			    else m_provider->msg(MSG::WARNING) << "\tNo track collection " << collectionName << " found"  << endreq;  
 			  }
 #else
diff --git a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/VtxAnalysis.cxx b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/VtxAnalysis.cxx
index 12295d72f69..5b9df8c6693 100644
--- a/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/VtxAnalysis.cxx
+++ b/Trigger/TrigAnalysis/TrigInDetAnalysisExample/src/VtxAnalysis.cxx
@@ -56,8 +56,8 @@ void VtxAnalysis::initialise() {
 
 
   hnvtx   = new TH1F( "vx_nvtx", ";number of vertices",   100, -0.5,  100.5   );
-  hzed    = new TH1F( "vx_zed",   ";vtx z [mm]",       200, -300,   300   );
-  hntrax  = new TH1F( "vx_ntrax", ";number of tracks", 100,   0.5, 200.5 );
+  hzed    = new TH1F( "vx_zed",   ";vtx z [mm]",          100, -250,   250   );
+  hntrax  = new TH1F( "vx_ntrax", ";number of tracks",    100,   0.5, 200.5 );
 
   addHistogram( hnvtx );
   addHistogram( hzed );
@@ -65,8 +65,8 @@ void VtxAnalysis::initialise() {
 
 
   hnvtx_rec  = new TH1F( "vx_nvtx_rec",  ";number of vertices",   100, -0.5,  100.5   );
-  hzed_rec   = new TH1F( "vx_zed_rec",   ";vtx z [mm]",       200, -300,   300   );
-  hntrax_rec = new TH1F( "vx_ntrax_rec", ";number of tracks", 100,   0.5, 200.5 );
+  hzed_rec   = new TH1F( "vx_zed_rec",   ";vtx z [mm]",           100, -250,   250   );
+  hntrax_rec = new TH1F( "vx_ntrax_rec", ";number of tracks",     100,   0.5, 200.5 );
 
   addHistogram( hnvtx_rec );
   addHistogram( hzed_rec );
@@ -76,7 +76,7 @@ void VtxAnalysis::initialise() {
 
   addHistogram( hzed_res );
 
-  rdz_vs_zed    = new TProfile( "vx_rdz_vs_zed",   "rdz_vs_zed; vtx z [mm];z residual [mm]",           100, -300,   300 ); 
+  rdz_vs_zed    = new TProfile( "vx_rdz_vs_zed",   "rdz_vs_zed; vtx z [mm];z residual [mm]",           100, -250,   250 ); 
   rdz_vs_ntrax  = new TProfile( "vx_rdz_vs_ntrax", "rdz_vs_ntrax;number of tracks;z residual [mm]",     80, vnbins );
   rdz_vs_nvtx   = new TProfile( "vx_rdz_vs_nvtx",  "rdz_vs_nvtx;number of vertices;z residual [mm]",    51, -0.125, 50.125 );
 
@@ -86,7 +86,7 @@ void VtxAnalysis::initialise() {
  
   //  rdz_vs_mu     = new TProfile( "rdz_vs_mu",    30,     0,    30,    400, -20, 20 ); 
 
-  eff_zed   = new TProfile( "vx_zed_eff", "zed_eff;efficiency;offline vtx z [mm]",     200, -300,  300   );
+  eff_zed   = new TProfile( "vx_zed_eff", "zed_eff;efficiency;offline vtx z [mm]",       50, -250,  250   );
   eff_ntrax = new TProfile( "vx_ntrax_eff", "ntrax_eff;number of tracks;efficiency",    80, vnbins );
   eff_nvtx  = new TProfile( "vx_nvtx_eff",  "nvtx_eff;number of vertices;efficiency",  100, -0.5,  100.5   );
   eff_mu    = new TProfile( "vx_mu_eff",     "lb_eff;<#mu>;efficiency",                 61, -0.5,  60.5   );
-- 
GitLab