From 3a4d8975dca57b6ea26bb68ad80b7c6da4cb917f Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Fri, 29 Sep 2023 15:20:14 +0100
Subject: [PATCH 1/7] Work in progress.

---
 .../src/MonitorElectronAlgorithm.cxx          | 340 ++++++++----------
 .../src/MonitorElectronAlgorithm.h            |   1 +
 2 files changed, 159 insertions(+), 182 deletions(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
index cc864402902f..6800d6573077 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
@@ -20,6 +20,12 @@ StatusCode MonitorElectronAlgorithm::initialize() {
     ATH_CHECK( AthMonitorAlgorithm::initialize() );
     ATH_CHECK( m_ParticleContainerKey.initialize() );
     ATH_CHECK( m_ElectronIsolationKey.initialize() );
+    if (!m_monTool.empty()) {
+      ATH_CHECK(m_monTool.retrieve());
+    }
+    else {
+      m_monTool.disable(); 
+    }
 
     return StatusCode::SUCCESS;
 }
@@ -50,7 +56,6 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
     auto np = Monitored::Scalar<int>("N",0.0);
     auto et = Monitored::Scalar<Float_t>("Et",0.0);
     // Check if small differences between old and new monitoring are related to rounding effects
-    // auto eta = Monitored::Scalar<Float_t>("Eta",0.0);
     auto eta = Monitored::Scalar<Double_t>("Eta",0.0);
     auto phi = Monitored::Scalar<Float_t>("Phi",0.0);
     auto is_pt_gt_2_5gev = Monitored::Scalar<bool>("is_pt_gt_2_5gev",false);
@@ -60,81 +65,6 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
     auto topoetcone40 = Monitored::Scalar<Float_t>("TopoEtCone40",0.0);
     auto ptcone20 = Monitored::Scalar<Float_t>("PtCone20",0.0);
 
-    // Particle variables per Region
-
-    // BARREL
-    auto np_barrel = Monitored::Scalar<int>("NinBARREL",0.0);
-    auto et_barrel = Monitored::Scalar<Float_t>("EtinBARREL",0.0);
-    auto eta_barrel = Monitored::Scalar<Float_t>("EtainBARREL",0.0);
-    auto phi_barrel = Monitored::Scalar<Float_t>("PhiinBARREL",0.0);
-    auto time_barrel = Monitored::Scalar<Float_t>("TimeinBARREL",0.0);
-    auto ehad1_barrel = Monitored::Scalar<Float_t>("Ehad1inBARREL",0.0);
-    auto eoverp_barrel = Monitored::Scalar<Float_t>("EoverPinBARREL",0.0);
-    auto coreem_barrel = Monitored::Scalar<Float_t>("CoreEMinBARREL",0.0);
-    auto f0_barrel = Monitored::Scalar<Float_t>("F0inBARREL",0.0);
-    auto f1_barrel = Monitored::Scalar<Float_t>("F1inBARREL",0.0);
-    auto f2_barrel = Monitored::Scalar<Float_t>("F2inBARREL",0.0);
-    auto f3_barrel = Monitored::Scalar<Float_t>("F3inBARREL",0.0);
-    auto re233e237_barrel = Monitored::Scalar<Float_t>("Re233e237inBARREL",0.0);
-    auto re237e277_barrel = Monitored::Scalar<Float_t>("Re237e277inBARREL",0.0);
-    auto nofblayerhits_barrel = Monitored::Scalar<u_int8_t>("NOfBLayerHitsinBARREL",0);
-    auto nofpixelhits_barrel = Monitored::Scalar<u_int8_t>("NOfPixelHitsinBARREL",0);
-    auto nofscthits_barrel = Monitored::Scalar<u_int8_t>("NOfSCTHitsinBARREL",0);
-    auto noftrthits_barrel = Monitored::Scalar<u_int8_t>("NOfTRTHitsinBARREL",0);
-    auto noftrthighthresholdhits_barrel = Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinBARREL",0);
-    auto deltaeta1_barrel = Monitored::Scalar<Float_t>("DeltaEta1inBARREL",0.0);
-    auto deltaphi2_barrel = Monitored::Scalar<Float_t>("DeltaPhi2inBARREL",0.0);
-    auto trackd0_barrel = Monitored::Scalar<Float_t>("Trackd0inBARREL",0.0);
-
-    // ENDCAP
-    auto np_endcap = Monitored::Scalar<int>("NinENDCAP",0.0);
-    auto et_endcap = Monitored::Scalar<Float_t>("EtinENDCAP",0.0);
-    auto eta_endcap = Monitored::Scalar<Float_t>("EtainENDCAP",0.0);
-    auto phi_endcap = Monitored::Scalar<Float_t>("PhiinENDCAP",0.0);
-    auto time_endcap = Monitored::Scalar<Float_t>("TimeinENDCAP",0.0);
-    auto ehad1_endcap = Monitored::Scalar<Float_t>("Ehad1inENDCAP",0.0);
-    auto eoverp_endcap = Monitored::Scalar<Float_t>("EoverPinENDCAP",0.0);
-    auto coreem_endcap = Monitored::Scalar<Float_t>("CoreEMinENDCAP",0.0);
-    auto f0_endcap = Monitored::Scalar<Float_t>("F0inENDCAP",0.0);
-    auto f1_endcap = Monitored::Scalar<Float_t>("F1inENDCAP",0.0);
-    auto f2_endcap = Monitored::Scalar<Float_t>("F2inENDCAP",0.0);
-    auto f3_endcap = Monitored::Scalar<Float_t>("F3inENDCAP",0.0);
-    auto re233e237_endcap = Monitored::Scalar<Float_t>("Re233e237inENDCAP",0.0);
-    auto re237e277_endcap = Monitored::Scalar<Float_t>("Re237e277inENDCAP",0.0);
-    auto nofblayerhits_endcap = Monitored::Scalar<u_int8_t>("NOfBLayerHitsinENDCAP",0);
-    auto nofpixelhits_endcap = Monitored::Scalar<u_int8_t>("NOfPixelHitsinENDCAP",0);
-    auto nofscthits_endcap = Monitored::Scalar<u_int8_t>("NOfSCTHitsinENDCAP",0);
-    auto noftrthits_endcap = Monitored::Scalar<u_int8_t>("NOfTRTHitsinENDCAP",0);
-    auto noftrthighthresholdhits_endcap = Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinENDCAP",0);
-    auto deltaeta1_endcap = Monitored::Scalar<Float_t>("DeltaEta1inENDCAP",0.0);
-    auto deltaphi2_endcap = Monitored::Scalar<Float_t>("DeltaPhi2inENDCAP",0.0);
-    auto trackd0_endcap = Monitored::Scalar<Float_t>("Trackd0inENDCAP",0.0);
-
-    // CRACK
-    auto np_crack = Monitored::Scalar<int>("NinCRACK",0.0);
-    auto et_crack = Monitored::Scalar<Float_t>("EtinCRACK",0.0);
-    auto eta_crack = Monitored::Scalar<Float_t>("EtainCRACK",0.0);
-    auto phi_crack = Monitored::Scalar<Float_t>("PhiinCRACK",0.0);
-    auto time_crack = Monitored::Scalar<Float_t>("TimeinCRACK",0.0);
-    auto ehad1_crack = Monitored::Scalar<Float_t>("Ehad1inCRACK",0.0);
-    auto eoverp_crack = Monitored::Scalar<Float_t>("EoverPinCRACK",0.0);
-    auto coreem_crack = Monitored::Scalar<Float_t>("CoreEMinCRACK",0.0);
-    auto f0_crack = Monitored::Scalar<Float_t>("F0inCRACK",0.0);
-    auto f1_crack = Monitored::Scalar<Float_t>("F1inCRACK",0.0);
-    auto f2_crack = Monitored::Scalar<Float_t>("F2inCRACK",0.0);
-    auto f3_crack = Monitored::Scalar<Float_t>("F3inCRACK",0.0);
-    auto re233e237_crack = Monitored::Scalar<Float_t>("Re233e237inCRACK",0.0);
-    auto re237e277_crack = Monitored::Scalar<Float_t>("Re237e277inCRACK",0.0);
-    auto nofblayerhits_crack = Monitored::Scalar<u_int8_t>("NOfBLayerHitsinCRACK",0);
-    auto nofpixelhits_crack = Monitored::Scalar<u_int8_t>("NOfPixelHitsinCRACK",0);
-    auto nofscthits_crack = Monitored::Scalar<u_int8_t>("NOfSCTHitsinCRACK",0);
-    auto noftrthits_crack = Monitored::Scalar<u_int8_t>("NOfTRTHitsinCRACK",0);
-    auto noftrthighthresholdhits_crack = Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinCRACK",0);
-    auto deltaeta1_crack = Monitored::Scalar<Float_t>("DeltaEta1inCRACK",0.0);
-    auto deltaphi2_crack = Monitored::Scalar<Float_t>("DeltaPhi2inCRACK",0.0);
-    auto trackd0_crack = Monitored::Scalar<Float_t>("Trackd0inCRACK",0.0);
-
-
     auto is_pt_gt_4gev_barrel = Monitored::Scalar<bool>("is_pt_gt_4gevBARREL",false);    
     auto is_pt_gt_4gev_endcap = Monitored::Scalar<bool>("is_pt_gt_4gevENDCAP",false);
     auto is_pt_gt_4gev_crack = Monitored::Scalar<bool>("is_pt_gt_4gevCRACK",false);
@@ -147,8 +77,7 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
     auto is_pt_gt_20gev_endcap = Monitored::Scalar<bool>("is_pt_gt_20gevENDCAP",false);
     auto is_pt_gt_20gev_crack = Monitored::Scalar<bool>("is_pt_gt_20gevCRACK",false);
 
-    // Set the values of the monitored variables for the event
-
+    // Set the values of the monitored variables for the event.
     u_int16_t mylb = GetEventInfo(ctx)->lumiBlock();
     lbNCandidates = mylb;
 
@@ -158,63 +87,39 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
     u_int16_t mynp_endcap = 0;
 
     for (const auto *const e_iter : *electrons) {
- 
-    // Check that the electron meets our requirements
+      // Check that the electron meets our requirements
       bool isGood;
-      if (! e_iter->passSelection(isGood,m_RecoName)) {
+      if (!e_iter->passSelection(isGood,m_RecoName)) {
         ATH_MSG_WARNING("Misconfiguration: " << m_RecoName << " is not a valid working point for electrons");
-        break; // no point in continuing
+        break;
       }
       if(isGood) {
-	mynp++;
-	//Float_t myetaloc = e_iter->eta();
-	Double_t myetaloc = e_iter->eta();
-	auto regionloc = GetRegion(myetaloc);
+	      mynp++;
+	      Double_t myetaloc = e_iter->eta();
+	      auto regionloc = GetRegion(myetaloc);
         ATH_MSG_DEBUG("Test electron in region : " << regionloc);
-	switch(regionloc){
-        case BARREL :
-	  mynp_barrel++;
-	  break;
-        case CRACK :
-	  mynp_crack++;
-	  break;
-	case ENDCAP : 
-	  mynp_endcap++;
-	  break;
-	default :
-	  ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
-	  break;
-	}
+
+        if (regionloc == BARREL) { 
+	        mynp_barrel++;
+        }
+        else if (regionloc == CRACK) { 
+	        mynp_crack++;
+        }
+        else if (regionloc == ENDCAP) { 
+	        mynp_endcap++;
+        }
+        else {
+	        ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
+	      }
       }
       else continue;
 
       // do specific stuff with electrons
 
       Float_t myet = e_iter->pt(); // in MeV (/Gaudi::Units::GeV; // in GeV)
-      //Float_t myeta = e_iter->eta();
       Double_t myeta = e_iter->eta();
       Float_t myphi = e_iter->phi();
 
-      bool myis_pt_gt_2_5gev = myet > 2500. ;
-      bool myis_pt_gt_4gev = myet > 4000. ;
-      bool myis_pt_gt_20gev = myet > 20000. ;
-
-      is_pt_gt_2_5gev = myis_pt_gt_2_5gev ;
-      is_pt_gt_4gev = myis_pt_gt_4gev ;
-      is_pt_gt_20gev = myis_pt_gt_20gev ;
-
-      is_pt_gt_4gev_barrel = myis_pt_gt_4gev ;
-      is_pt_gt_4gev_endcap = myis_pt_gt_4gev ;
-      is_pt_gt_4gev_crack = myis_pt_gt_4gev ;
-
-      is_pt_gt_2_5gev_barrel = myis_pt_gt_2_5gev ;
-      is_pt_gt_2_5gev_endcap = myis_pt_gt_2_5gev ;
-      is_pt_gt_2_5gev_crack = myis_pt_gt_2_5gev ;
-
-      is_pt_gt_20gev_barrel = myis_pt_gt_20gev ;
-      is_pt_gt_20gev_endcap = myis_pt_gt_20gev ;
-      is_pt_gt_20gev_crack = myis_pt_gt_20gev ;
-
       // Isolation Energy
       Float_t mytopoetcone40 = -999.;
       e_iter->isolationValue(mytopoetcone40,xAOD::Iso::topoetcone40);
@@ -277,13 +182,12 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
         t->summaryValue(mynoftrthits,xAOD::numberOfTRTHits);
         t->summaryValue(mynoftrthighthresholdhits,xAOD::numberOfTRTHighThresholdHits);
         mytrackd0 = t->d0();
-        }
+      }
       else
         ATH_MSG_DEBUG("Error attempting to retrieve associated track");
 
 
       // Associated cluster details
-
       const xAOD::CaloCluster *aCluster = e_iter->caloCluster();
       if (aCluster) {
         mytime = aCluster->time();
@@ -296,76 +200,148 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
         if (ec!=0) myf3 = aCluster->energyBE(3)/ec;
 
         if(trackp !=0) myeoverp = aCluster->e()/trackp;
-
-        //ATH_MSG_WARNING("Test eoverp : " << myeoverp);
       }
 
       // Fill per region histograms
       auto region = GetRegion(myeta);
-
-      //ATH_MSG_INFO("Test electron in region : " << region);
-
-      switch(region){
-
-      case BARREL :
-	nofblayerhits_barrel = mynofblayerhits ; nofpixelhits_barrel = mynofpixelhits ; nofscthits_barrel = mynofscthits ;
-	noftrthits_barrel = mynoftrthits ; noftrthighthresholdhits_barrel = mynoftrthighthresholdhits;
-	deltaeta1_barrel = mydeltaeta1; deltaphi2_barrel = mydeltaphi2; trackd0_barrel = mytrackd0;
-	eoverp_barrel = myeoverp;
-	et_barrel = myet ; eta_barrel = myeta ; phi_barrel = myphi ;
-	time_barrel = mytime; ehad1_barrel = myehad1; coreem_barrel = myecore;
-	f0_barrel = myf0; f1_barrel = myf1; f2_barrel = myf2; f3_barrel = myf3; re233e237_barrel = myre233e237; re237e277_barrel = myre237e277;
-	fill("MonitorElectron",np_barrel, nofblayerhits_barrel, nofpixelhits_barrel, nofscthits_barrel, noftrthits_barrel, noftrthighthresholdhits_barrel, 
-	     deltaeta1_barrel, deltaphi2_barrel,trackd0_barrel,eoverp_barrel,
-	     et_barrel,eta_barrel,phi_barrel, time_barrel, ehad1_barrel,coreem_barrel, f0_barrel,f1_barrel,f2_barrel, f3_barrel,
-	     re233e237_barrel,re237e277_barrel,is_pt_gt_4gev_barrel,is_pt_gt_2_5gev_barrel,is_pt_gt_20gev_barrel);
-	break;
-
-      case ENDCAP :
-	nofblayerhits_endcap = mynofblayerhits; nofpixelhits_endcap = mynofpixelhits ; nofscthits_endcap = mynofscthits ;
-	noftrthits_endcap = mynoftrthits ; noftrthighthresholdhits_endcap = mynoftrthighthresholdhits;
-	deltaeta1_endcap = mydeltaeta1; deltaphi2_endcap = mydeltaphi2; trackd0_endcap = mytrackd0;
-	eoverp_endcap = myeoverp;
-	et_endcap = myet ; eta_endcap = myeta ; phi_endcap = myphi ;
-	time_endcap = mytime; ehad1_endcap = myehad1; coreem_endcap = myecore;
-	f0_endcap = myf0; f1_endcap = myf1; f2_endcap = myf2; f3_endcap = myf3; re233e237_endcap = myre233e237; re237e277_endcap = myre237e277;
-	fill("MonitorElectron",np_endcap,nofblayerhits_endcap,nofpixelhits_endcap,nofscthits_endcap,noftrthits_endcap,noftrthighthresholdhits_endcap,
-	     deltaeta1_endcap, deltaphi2_endcap,trackd0_endcap,eoverp_endcap,et_endcap,eta_endcap,phi_endcap,
-	     time_endcap, ehad1_endcap,coreem_endcap,
-	     f0_endcap,f1_endcap,f2_endcap,f3_endcap,re233e237_endcap,re237e277_endcap,is_pt_gt_4gev_endcap,is_pt_gt_2_5gev_endcap,is_pt_gt_20gev_endcap);
-	break;
-
-      case CRACK :
-	nofblayerhits_crack = mynofblayerhits; nofpixelhits_crack = mynofpixelhits ; nofscthits_crack = mynofscthits ;
-	noftrthits_crack = mynoftrthits ; noftrthighthresholdhits_crack = mynoftrthighthresholdhits;
-	deltaeta1_crack = mydeltaeta1; deltaphi2_crack = mydeltaphi2; trackd0_crack = mytrackd0;
-	eoverp_crack = myeoverp;
-	et_crack = myet ; eta_crack = myeta ; phi_crack = myphi ;
-	time_crack = mytime; ehad1_crack = myehad1; coreem_crack = myecore;
-	f0_crack = myf0; f1_crack = myf1; f2_crack = myf2; f3_crack = myf3; re233e237_crack = myre233e237; re237e277_crack = myre237e277;
-	fill("MonitorElectron",np_crack,nofblayerhits_crack, nofpixelhits_crack,nofscthits_crack,noftrthits_crack,noftrthighthresholdhits_crack,
-	     deltaeta1_crack, deltaphi2_crack,trackd0_crack,eoverp_crack,et_crack,eta_crack,phi_crack,
-	     time_crack, ehad1_crack,coreem_crack,f0_crack,f1_crack,f2_crack,f3_crack,re233e237_crack,re237e277_crack,is_pt_gt_4gev_crack,is_pt_gt_2_5gev_crack,is_pt_gt_20gev_crack);
-	break;
-
-        default :
+      if (region == BARREL) {
+	      //fill(
+        //  "MonitorElectron",
+        //  Monitored::Scalar<Float_t>("EtinBARREL", myet),
+        //  Monitored::Scalar<Float_t>("EtainBARREL", myeta),
+        //  Monitored::Scalar<Float_t>("PhiinBARREL", myphi),
+        //  Monitored::Scalar<Float_t>("TimeinBARREL", mytime),
+        //  Monitored::Scalar<Float_t>("Ehad1inBARREL", myehad1),
+        //  Monitored::Scalar<Float_t>("EoverPinBARREL", myeoverp),
+        //  Monitored::Scalar<Float_t>("CoreEMinBARREL", myecore),
+        //  Monitored::Scalar<Float_t>("F0inBARREL", myf0),
+        //  Monitored::Scalar<Float_t>("F1inBARREL", myf1),
+        //  Monitored::Scalar<Float_t>("F2inBARREL", myf2),
+        //  Monitored::Scalar<Float_t>("F3inBARREL", myf3),
+        //  Monitored::Scalar<Float_t>("Re233e237inBARREL", myre233e237),
+        //  Monitored::Scalar<Float_t>("Re237e277inBARREL", myre237e277),
+        //  Monitored::Scalar<u_int8_t>("NOfBLayerHitsinBARREL", mynofblayerhits),
+        //  Monitored::Scalar<u_int8_t>("NOfPixelHitsinBARREL", mynofpixelhits),
+        //  Monitored::Scalar<u_int8_t>("NOfSCTHitsinBARREL", mynofscthits),
+        //  Monitored::Scalar<u_int8_t>("NOfTRTHitsinBARREL", mynoftrthits),
+        //  Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinBARREL", mynoftrthighthresholdhits),
+        //  Monitored::Scalar<Float_t>("DeltaEta1inBARREL", mydeltaeta1),
+        //  Monitored::Scalar<Float_t>("DeltaPhi2inBARREL", mydeltaphi2),
+        //  Monitored::Scalar<Float_t>("Trackd0inBARREL", mytrackd0)
+        //);
+      }
+      else if (region == ENDCAP) {
+	      //fill(
+        //  "MonitorElectron",
+        //  Monitored::Scalar<Float_t>("EtinENDCAP", myet),
+        //  Monitored::Scalar<Float_t>("EtainENDCAP", myeta),
+        //  Monitored::Scalar<Float_t>("PhiinENDCAP", myphi),
+        //  Monitored::Scalar<Float_t>("TimeinENDCAP", mytime),
+        //  Monitored::Scalar<Float_t>("Ehad1inENDCAP", myehad1),
+        //  Monitored::Scalar<Float_t>("EoverPinENDCAP", myeoverp),
+        //  Monitored::Scalar<Float_t>("CoreEMinENDCAP", myecore),
+        //  Monitored::Scalar<Float_t>("F0inENDCAP", myf0),
+        //  Monitored::Scalar<Float_t>("F1inENDCAP", myf1),
+        //  Monitored::Scalar<Float_t>("F2inENDCAP", myf2),
+        //  Monitored::Scalar<Float_t>("F3inENDCAP", myf3),
+        //  Monitored::Scalar<Float_t>("Re233e237inENDCAP", myre233e237),
+        //  Monitored::Scalar<Float_t>("Re237e277inENDCAP", myre237e277),
+        //  Monitored::Scalar<u_int8_t>("NOfBLayerHitsinENDCAP", mynofblayerhits),
+        //  Monitored::Scalar<u_int8_t>("NOfPixelHitsinENDCAP", mynofpixelhits),
+        //  Monitored::Scalar<u_int8_t>("NOfSCTHitsinENDCAP", mynofscthits),
+        //  Monitored::Scalar<u_int8_t>("NOfTRTHitsinENDCAP", mynoftrthits),
+        //  Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinENDCAP", mynoftrthighthresholdhits),
+        //  Monitored::Scalar<Float_t>("DeltaEta1inENDCAP", mydeltaeta1),
+        //  Monitored::Scalar<Float_t>("DeltaPhi2inENDCAP", mydeltaphi2),
+        //  Monitored::Scalar<Float_t>("Trackd0inENDCAP", mytrackd0)
+        //);
+      }
+      else if (region == CRACK) {
+      	//fill(
+        //  "MonitorElectron",
+        //  Monitored::Scalar<Float_t>("EtinCRACK", myet),
+        //  Monitored::Scalar<Float_t>("EtainCRACK", myeta),
+        //  Monitored::Scalar<Float_t>("PhiinCRACK", myphi),
+        //  Monitored::Scalar<Float_t>("TimeinCRACK", mytime),
+        //  Monitored::Scalar<Float_t>("Ehad1inCRACK", myehad1),
+        //  Monitored::Scalar<Float_t>("EoverPinCRACK", myeoverp),
+        //  Monitored::Scalar<Float_t>("CoreEMinCRACK", myecore),
+        //  Monitored::Scalar<Float_t>("F0inCRACK", myf0),
+        //  Monitored::Scalar<Float_t>("F1inCRACK", myf1),
+        //  Monitored::Scalar<Float_t>("F2inCRACK", myf2),
+        //  Monitored::Scalar<Float_t>("F3inCRACK", myf3),
+        //  Monitored::Scalar<Float_t>("Re233e237inCRACK", myre233e237),
+        //  Monitored::Scalar<Float_t>("Re237e277inCRACK", myre237e277),
+        //  Monitored::Scalar<u_int8_t>("NOfBLayerHitsinCRACK", mynofblayerhits),
+        //  Monitored::Scalar<u_int8_t>("NOfPixelHitsinCRACK", mynofpixelhits),
+        //  Monitored::Scalar<u_int8_t>("NOfSCTHitsinCRACK", mynofscthits),
+        //  Monitored::Scalar<u_int8_t>("NOfTRTHitsinCRACK", mynoftrthits),
+        //  Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinCRACK", mynoftrthighthresholdhits),
+        //  Monitored::Scalar<Float_t>("DeltaEta1inCRACK", mydeltaeta1),
+        //  Monitored::Scalar<Float_t>("DeltaPhi2inCRACK", mydeltaphi2),
+        //  Monitored::Scalar<Float_t>("Trackd0inCRACK", mytrackd0)
+        //);
+      }
+      else {
           ATH_MSG_DEBUG("found an electron outside the |eta| > 2.47 acceptance");
-          break;
       }
 
-      et = myet ; eta = myeta ; phi = myphi ;
-      fill("MonitorElectron",et,eta,phi,time,ptcone20,topoetcone40,lbNCandidates,
-      is_pt_gt_2_5gev, is_pt_gt_4gev, is_pt_gt_20gev);
 
-      // Fill. First argument is the tool name, all others are the variables to be histogramed
+      bool myis_pt_gt_2_5gev = myet > 2500. ;
+      bool myis_pt_gt_4gev = myet > 4000. ;
+      bool myis_pt_gt_20gev = myet > 20000. ;
+
+      is_pt_gt_2_5gev = myis_pt_gt_2_5gev ;
+      is_pt_gt_4gev = myis_pt_gt_4gev ;
+      is_pt_gt_20gev = myis_pt_gt_20gev ;
+
+      is_pt_gt_4gev_barrel = myis_pt_gt_4gev ;
+      is_pt_gt_4gev_endcap = myis_pt_gt_4gev ;
+      is_pt_gt_4gev_crack = myis_pt_gt_4gev ;
+
+      is_pt_gt_2_5gev_barrel = myis_pt_gt_2_5gev ;
+      is_pt_gt_2_5gev_endcap = myis_pt_gt_2_5gev ;
+      is_pt_gt_2_5gev_crack = myis_pt_gt_2_5gev ;
+
+      is_pt_gt_20gev_barrel = myis_pt_gt_20gev ;
+      is_pt_gt_20gev_endcap = myis_pt_gt_20gev ;
+      is_pt_gt_20gev_crack = myis_pt_gt_20gev ;
+
+      et = myet;
+      eta = myeta; 
+      phi = myphi;
+
+      fill(
+        "MonitorElectron",
+        et,
+        eta,
+        phi,
+        time,
+        ptcone20,
+        topoetcone40,
+        lbNCandidates,
+        is_pt_gt_2_5gev,
+        is_pt_gt_4gev,
+        is_pt_gt_20gev
+      );
     }
 
-    np = mynp;
-    np_barrel = mynp_barrel;
-    np_endcap = mynp_endcap;
-    np_crack = mynp_crack;
+    //np = mynp;
+    //np_barrel = mynp_barrel;
+    //np_endcap = mynp_endcap;
+    //np_crack = mynp_crack;
+
+    //fill(
+    //  "MonitorElectron",
+    //  np,
+    //  np_barrel,
+    //  np_endcap,
+    //  np_crack
+    //);
 
-    fill("MonitorElectron",np,np_barrel,np_endcap,np_crack);
+    fill("Test", Monitored::Scalar<bool>("test", false));
 
+    //auto testGroup = Monitored::Group(m_monTool, Monitored::Scalar<bool>("test", false));
+    
     return StatusCode::SUCCESS;
 }
diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
index ce6d345f45e8..11f130586cf9 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
@@ -35,6 +35,7 @@ private:
   Gaudi::Property<std::string> m_ParticlePrefix {this,"ParticlePrefix","electron","Name of the particle prefix to be used to define hists"};
   Gaudi::Property<std::string> m_RecoName {this,"RecoName","LHTight","Name of particle flavor in egamma reco"};
   Gaudi::Property<std::string> m_WithTrigger {this,"WithTrigger","","Name extension when electrons are chosen from triggered events"};
+  ToolHandle<GenericMonitoringTool> m_monTool {this, "MonTool", "MonitorElectronTool", "Monitoring tool"};
 
   Regions GetRegion(Float_t eta) const {
     Float_t aeta = fabs(eta);
-- 
GitLab


From 4cf2f29fa4dcec85fbe78b9b11c11de0a83436ff Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Sat, 30 Sep 2023 12:51:05 +0100
Subject: [PATCH 2/7] Elimiate intermediate variables.

---
 .../src/MonitorElectronAlgorithm.cxx          | 566 ++++++++----------
 1 file changed, 254 insertions(+), 312 deletions(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
index 6800d6573077..6b44448d23b1 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
@@ -7,6 +7,16 @@
 
 #include "MonitorElectronAlgorithm.h"
 
+namespace {
+  template <typename ...T>
+  void fillMonitorElectron(
+    const MonitorElectronAlgorithm &alg, 
+    T ...monitoreds
+  ) {
+    alg.fill("MonitorElectron", {monitoreds...});
+  }
+}
+
 MonitorElectronAlgorithm::MonitorElectronAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
 :AthMonitorAlgorithm(name,pSvcLocator)
 {
@@ -16,332 +26,264 @@ MonitorElectronAlgorithm::~MonitorElectronAlgorithm() = default;
 
 
 StatusCode MonitorElectronAlgorithm::initialize() {
-    using namespace Monitored;
-    ATH_CHECK( AthMonitorAlgorithm::initialize() );
-    ATH_CHECK( m_ParticleContainerKey.initialize() );
-    ATH_CHECK( m_ElectronIsolationKey.initialize() );
-    if (!m_monTool.empty()) {
-      ATH_CHECK(m_monTool.retrieve());
-    }
-    else {
-      m_monTool.disable(); 
-    }
-
-    return StatusCode::SUCCESS;
+  using namespace Monitored;
+  ATH_CHECK( AthMonitorAlgorithm::initialize() );
+  ATH_CHECK( m_ParticleContainerKey.initialize() );
+  ATH_CHECK( m_ElectronIsolationKey.initialize() );
+  if (!m_monTool.empty()) {
+    ATH_CHECK(m_monTool.retrieve());
+  }
+  else {
+    m_monTool.disable(); 
+  }
+
+  return StatusCode::SUCCESS;
 }
 
 StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) const {
-    using namespace Monitored;
+  using namespace Monitored;
 
-    // Only monitor good LAr Events :
-
-    xAOD::EventInfo::EventFlagErrorState error_state = GetEventInfo(ctx)->errorState(xAOD::EventInfo::LAr);
-    if (error_state==xAOD::EventInfo::Error) {
-      ATH_MSG_DEBUG("LAr event data integrity error");
-      return StatusCode::SUCCESS;
+  // Only monitor good LAr Events.
+  xAOD::EventInfo::EventFlagErrorState error_state = GetEventInfo(ctx)->errorState(xAOD::EventInfo::LAr);
+  if (error_state==xAOD::EventInfo::Error) {
+    ATH_MSG_DEBUG("LAr event data integrity error");
+    return StatusCode::SUCCESS;
+  }
+
+  // Fill the specific Electron information.
+  // Get the Electron container.
+  SG::ReadHandle<xAOD::ElectronContainer> electrons(m_ParticleContainerKey, ctx);
+  ATH_CHECK(electrons.isValid());
+
+  // Set the values of the monitored variables for the event.
+  u_int16_t mylb = GetEventInfo(ctx)->lumiBlock();
+  u_int16_t mynp = 0;
+  u_int16_t mynp_barrel = 0;
+  u_int16_t mynp_crack = 0;
+  u_int16_t mynp_endcap = 0;
+
+  for (const auto *const e_iter : *electrons) {
+    // Check that the electron meets our requirements.
+    bool isGood;
+    if (!e_iter->passSelection(isGood,m_RecoName)) {
+      ATH_MSG_WARNING("Misconfiguration: " << m_RecoName << " is not a valid working point for electrons");
+      break;
     }
-
-    //
-    // now, fill the specific Electron information
-    //
-    // get the Electron container
-
-    SG::ReadHandle<xAOD::ElectronContainer> electrons(m_ParticleContainerKey, ctx);
-    ATH_CHECK(electrons.isValid());
-
-    // Event variables to be monitored
-    auto lbNCandidates = Monitored::Scalar<u_int16_t>("LBEvoN",0);
-
-    // Particle variables to be monitored
-    auto np = Monitored::Scalar<int>("N",0.0);
-    auto et = Monitored::Scalar<Float_t>("Et",0.0);
-    // Check if small differences between old and new monitoring are related to rounding effects
-    auto eta = Monitored::Scalar<Double_t>("Eta",0.0);
-    auto phi = Monitored::Scalar<Float_t>("Phi",0.0);
-    auto is_pt_gt_2_5gev = Monitored::Scalar<bool>("is_pt_gt_2_5gev",false);
-    auto is_pt_gt_4gev = Monitored::Scalar<bool>("is_pt_gt_4gev",false);
-    auto is_pt_gt_20gev = Monitored::Scalar<bool>("is_pt_gt_20gev",false);
-    auto time = Monitored::Scalar<Float_t>("Time",0.0);
-    auto topoetcone40 = Monitored::Scalar<Float_t>("TopoEtCone40",0.0);
-    auto ptcone20 = Monitored::Scalar<Float_t>("PtCone20",0.0);
-
-    auto is_pt_gt_4gev_barrel = Monitored::Scalar<bool>("is_pt_gt_4gevBARREL",false);    
-    auto is_pt_gt_4gev_endcap = Monitored::Scalar<bool>("is_pt_gt_4gevENDCAP",false);
-    auto is_pt_gt_4gev_crack = Monitored::Scalar<bool>("is_pt_gt_4gevCRACK",false);
-
-    auto is_pt_gt_2_5gev_barrel = Monitored::Scalar<bool>("is_pt_gt_2_5gevBARREL",false);    
-    auto is_pt_gt_2_5gev_endcap = Monitored::Scalar<bool>("is_pt_gt_2_5gevENDCAP",false);
-    auto is_pt_gt_2_5gev_crack = Monitored::Scalar<bool>("is_pt_gt_2_5gevCRACK",false);
-
-    auto is_pt_gt_20gev_barrel = Monitored::Scalar<bool>("is_pt_gt_20gevBARREL",false);    
-    auto is_pt_gt_20gev_endcap = Monitored::Scalar<bool>("is_pt_gt_20gevENDCAP",false);
-    auto is_pt_gt_20gev_crack = Monitored::Scalar<bool>("is_pt_gt_20gevCRACK",false);
-
-    // Set the values of the monitored variables for the event.
-    u_int16_t mylb = GetEventInfo(ctx)->lumiBlock();
-    lbNCandidates = mylb;
-
-    u_int16_t mynp = 0;
-    u_int16_t mynp_barrel = 0;
-    u_int16_t mynp_crack = 0;
-    u_int16_t mynp_endcap = 0;
-
-    for (const auto *const e_iter : *electrons) {
-      // Check that the electron meets our requirements
-      bool isGood;
-      if (!e_iter->passSelection(isGood,m_RecoName)) {
-        ATH_MSG_WARNING("Misconfiguration: " << m_RecoName << " is not a valid working point for electrons");
-        break;
+    if(isGood) {
+	    mynp++;
+	    Double_t myetaloc = e_iter->eta();
+	    auto regionloc = GetRegion(myetaloc);
+      ATH_MSG_DEBUG("Test electron in region : " << regionloc);
+
+      if (regionloc == BARREL) { 
+	      ++mynp_barrel;
       }
-      if(isGood) {
-	      mynp++;
-	      Double_t myetaloc = e_iter->eta();
-	      auto regionloc = GetRegion(myetaloc);
-        ATH_MSG_DEBUG("Test electron in region : " << regionloc);
-
-        if (regionloc == BARREL) { 
-	        mynp_barrel++;
-        }
-        else if (regionloc == CRACK) { 
-	        mynp_crack++;
-        }
-        else if (regionloc == ENDCAP) { 
-	        mynp_endcap++;
-        }
-        else {
-	        ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
-	      }
+      else if (regionloc == CRACK) { 
+	      ++mynp_crack;
       }
-      else continue;
-
-      // do specific stuff with electrons
-
-      Float_t myet = e_iter->pt(); // in MeV (/Gaudi::Units::GeV; // in GeV)
-      Double_t myeta = e_iter->eta();
-      Float_t myphi = e_iter->phi();
-
-      // Isolation Energy
-      Float_t mytopoetcone40 = -999.;
-      e_iter->isolationValue(mytopoetcone40,xAOD::Iso::topoetcone40);
-      topoetcone40 = mytopoetcone40;
-
-      Float_t myptcone20 = -999.;
-      e_iter->isolationValue(myptcone20,xAOD::Iso::ptcone20);
-      ptcone20 = myptcone20;
+      else if (regionloc == ENDCAP) { 
+	      ++mynp_endcap;
+      }
+      else {
+	      ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
+	    }
+    }
+    else continue;
+
+    // do specific stuff with electrons
+
+    Float_t myet = e_iter->pt(); // in MeV (/Gaudi::Units::GeV; // in GeV)
+    Double_t myeta = e_iter->eta();
+    Float_t myphi = e_iter->phi();
+
+    // Isolation Energy
+    Float_t mytopoetcone40 = -999.;
+    e_iter->isolationValue(mytopoetcone40,xAOD::Iso::topoetcone40);
+
+    Float_t myptcone20 = -999.;
+    e_iter->isolationValue(myptcone20,xAOD::Iso::ptcone20);
+
+    Float_t mytime=0.0;
+
+    // Shower shape variable details
+    Float_t myehad1 = 0.0;
+    Float_t myecore = 0.0;
+    Float_t myf0    = 0.0;
+    Float_t myf1    = 0.0;
+    Float_t myf2    = 0.0;
+    Float_t myf3    = 0.0;
+    Float_t e233  = 0.0;
+    Float_t e237  = 0.0;
+    Float_t e277  = 0.0;
+    Float_t myre233e237 = 0.0;
+    Float_t myre237e277 = 0.0;
+
+    e_iter->showerShapeValue(myehad1, xAOD::EgammaParameters::ehad1);
+    e_iter->showerShapeValue(myecore, xAOD::EgammaParameters::ecore);
+
+    e_iter->showerShapeValue(e237, xAOD::EgammaParameters::e237);
+    e_iter->showerShapeValue(e233, xAOD::EgammaParameters::e233);
+    e_iter->showerShapeValue(e277, xAOD::EgammaParameters::e277);
+
+    if (e237!=0) myre233e237 = e233 / e237;
+    if (e277!=0) myre237e277 = e237 / e277;
+
+
+    // Cluster track match details
+    Float_t mydeltaeta1 = -999.0;
+    e_iter->trackCaloMatchValue(mydeltaeta1, xAOD::EgammaParameters::deltaEta1);
+    Float_t mydeltaphi2 = -999.0;
+    e_iter->trackCaloMatchValue(mydeltaphi2, xAOD::EgammaParameters::deltaPhi2);
+
+    Float_t myeoverp = -999.0;
+    Float_t mytrackd0 = -999.0;
+
+    // associated track details
+    const xAOD::TrackParticle *t = e_iter->trackParticle();
+    double trackp = 0;
+    u_int8_t mynofblayerhits=-1;
+    u_int8_t mynofpixelhits=-1;
+    u_int8_t mynofscthits=-1;
+    u_int8_t mynoftrthits=-1;
+    u_int8_t mynoftrthighthresholdhits=-1;
+
+    if(t) {
+      trackp = t->pt()*cosh(t->eta());
+      // retrieve track summary information
+      t->summaryValue(mynofblayerhits,xAOD::numberOfInnermostPixelLayerHits);
+      t->summaryValue(mynofpixelhits,xAOD::numberOfPixelHits);
+      t->summaryValue(mynofscthits,xAOD::numberOfSCTHits);
+      t->summaryValue(mynoftrthits,xAOD::numberOfTRTHits);
+      t->summaryValue(mynoftrthighthresholdhits,xAOD::numberOfTRTHighThresholdHits);
+      mytrackd0 = t->d0();
+    }
+    else
+      ATH_MSG_DEBUG("Error attempting to retrieve associated track");
 
-      Float_t mytime=0.0;
 
+    // Associated cluster details
+    const xAOD::CaloCluster *aCluster = e_iter->caloCluster();
+    if (aCluster) {
+      mytime = aCluster->time();
       // Shower shape variable details
-      Float_t myehad1 = 0.0;
-      Float_t myecore = 0.0;
-      Float_t myf0    = 0.0;
-      Float_t myf1    = 0.0;
-      Float_t myf2    = 0.0;
-      Float_t myf3    = 0.0;
-      Float_t e233  = 0.0;
-      Float_t e237  = 0.0;
-      Float_t e277  = 0.0;
-      Float_t myre233e237 = 0.0;
-      Float_t myre237e277 = 0.0;
-
-      e_iter->showerShapeValue(myehad1, xAOD::EgammaParameters::ehad1);
-      e_iter->showerShapeValue(myecore, xAOD::EgammaParameters::ecore);
-
-      e_iter->showerShapeValue(e237, xAOD::EgammaParameters::e237);
-      e_iter->showerShapeValue(e233, xAOD::EgammaParameters::e233);
-      e_iter->showerShapeValue(e277, xAOD::EgammaParameters::e277);
-
-      if (e237!=0) myre233e237 = e233 / e237;
-      if (e277!=0) myre237e277 = e237 / e277;
-
-
-      // Cluster track match details
-      Float_t mydeltaeta1 = -999.0;
-      e_iter->trackCaloMatchValue(mydeltaeta1, xAOD::EgammaParameters::deltaEta1);
-      Float_t mydeltaphi2 = -999.0;
-      e_iter->trackCaloMatchValue(mydeltaphi2, xAOD::EgammaParameters::deltaPhi2);
-
-      Float_t myeoverp = -999.0;
-      Float_t mytrackd0 = -999.0;
-
-      // associated track details
-      const xAOD::TrackParticle *t = e_iter->trackParticle();
-      double trackp = 0;
-      u_int8_t mynofblayerhits=-1;
-      u_int8_t mynofpixelhits=-1;
-      u_int8_t mynofscthits=-1;
-      u_int8_t mynoftrthits=-1;
-      u_int8_t mynoftrthighthresholdhits=-1;
-
-      if(t) {
-        trackp = t->pt()*cosh(t->eta());
-        // retrieve track summary information
-        t->summaryValue(mynofblayerhits,xAOD::numberOfInnermostPixelLayerHits);
-        t->summaryValue(mynofpixelhits,xAOD::numberOfPixelHits);
-        t->summaryValue(mynofscthits,xAOD::numberOfSCTHits);
-        t->summaryValue(mynoftrthits,xAOD::numberOfTRTHits);
-        t->summaryValue(mynoftrthighthresholdhits,xAOD::numberOfTRTHighThresholdHits);
-        mytrackd0 = t->d0();
-      }
-      else
-        ATH_MSG_DEBUG("Error attempting to retrieve associated track");
-
-
-      // Associated cluster details
-      const xAOD::CaloCluster *aCluster = e_iter->caloCluster();
-      if (aCluster) {
-        mytime = aCluster->time();
-        time = mytime ;
-        // Shower shape variable details
-        double ec = aCluster->et()*cosh(aCluster->eta());
-        if (ec!=0) myf0 = aCluster->energyBE(0)/ec;
-        if (ec!=0) myf1 = aCluster->energyBE(1)/ec;
-        if (ec!=0) myf2 = aCluster->energyBE(2)/ec;
-        if (ec!=0) myf3 = aCluster->energyBE(3)/ec;
-
-        if(trackp !=0) myeoverp = aCluster->e()/trackp;
-      }
-
-      // Fill per region histograms
-      auto region = GetRegion(myeta);
-      if (region == BARREL) {
-	      //fill(
-        //  "MonitorElectron",
-        //  Monitored::Scalar<Float_t>("EtinBARREL", myet),
-        //  Monitored::Scalar<Float_t>("EtainBARREL", myeta),
-        //  Monitored::Scalar<Float_t>("PhiinBARREL", myphi),
-        //  Monitored::Scalar<Float_t>("TimeinBARREL", mytime),
-        //  Monitored::Scalar<Float_t>("Ehad1inBARREL", myehad1),
-        //  Monitored::Scalar<Float_t>("EoverPinBARREL", myeoverp),
-        //  Monitored::Scalar<Float_t>("CoreEMinBARREL", myecore),
-        //  Monitored::Scalar<Float_t>("F0inBARREL", myf0),
-        //  Monitored::Scalar<Float_t>("F1inBARREL", myf1),
-        //  Monitored::Scalar<Float_t>("F2inBARREL", myf2),
-        //  Monitored::Scalar<Float_t>("F3inBARREL", myf3),
-        //  Monitored::Scalar<Float_t>("Re233e237inBARREL", myre233e237),
-        //  Monitored::Scalar<Float_t>("Re237e277inBARREL", myre237e277),
-        //  Monitored::Scalar<u_int8_t>("NOfBLayerHitsinBARREL", mynofblayerhits),
-        //  Monitored::Scalar<u_int8_t>("NOfPixelHitsinBARREL", mynofpixelhits),
-        //  Monitored::Scalar<u_int8_t>("NOfSCTHitsinBARREL", mynofscthits),
-        //  Monitored::Scalar<u_int8_t>("NOfTRTHitsinBARREL", mynoftrthits),
-        //  Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinBARREL", mynoftrthighthresholdhits),
-        //  Monitored::Scalar<Float_t>("DeltaEta1inBARREL", mydeltaeta1),
-        //  Monitored::Scalar<Float_t>("DeltaPhi2inBARREL", mydeltaphi2),
-        //  Monitored::Scalar<Float_t>("Trackd0inBARREL", mytrackd0)
-        //);
-      }
-      else if (region == ENDCAP) {
-	      //fill(
-        //  "MonitorElectron",
-        //  Monitored::Scalar<Float_t>("EtinENDCAP", myet),
-        //  Monitored::Scalar<Float_t>("EtainENDCAP", myeta),
-        //  Monitored::Scalar<Float_t>("PhiinENDCAP", myphi),
-        //  Monitored::Scalar<Float_t>("TimeinENDCAP", mytime),
-        //  Monitored::Scalar<Float_t>("Ehad1inENDCAP", myehad1),
-        //  Monitored::Scalar<Float_t>("EoverPinENDCAP", myeoverp),
-        //  Monitored::Scalar<Float_t>("CoreEMinENDCAP", myecore),
-        //  Monitored::Scalar<Float_t>("F0inENDCAP", myf0),
-        //  Monitored::Scalar<Float_t>("F1inENDCAP", myf1),
-        //  Monitored::Scalar<Float_t>("F2inENDCAP", myf2),
-        //  Monitored::Scalar<Float_t>("F3inENDCAP", myf3),
-        //  Monitored::Scalar<Float_t>("Re233e237inENDCAP", myre233e237),
-        //  Monitored::Scalar<Float_t>("Re237e277inENDCAP", myre237e277),
-        //  Monitored::Scalar<u_int8_t>("NOfBLayerHitsinENDCAP", mynofblayerhits),
-        //  Monitored::Scalar<u_int8_t>("NOfPixelHitsinENDCAP", mynofpixelhits),
-        //  Monitored::Scalar<u_int8_t>("NOfSCTHitsinENDCAP", mynofscthits),
-        //  Monitored::Scalar<u_int8_t>("NOfTRTHitsinENDCAP", mynoftrthits),
-        //  Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinENDCAP", mynoftrthighthresholdhits),
-        //  Monitored::Scalar<Float_t>("DeltaEta1inENDCAP", mydeltaeta1),
-        //  Monitored::Scalar<Float_t>("DeltaPhi2inENDCAP", mydeltaphi2),
-        //  Monitored::Scalar<Float_t>("Trackd0inENDCAP", mytrackd0)
-        //);
-      }
-      else if (region == CRACK) {
-      	//fill(
-        //  "MonitorElectron",
-        //  Monitored::Scalar<Float_t>("EtinCRACK", myet),
-        //  Monitored::Scalar<Float_t>("EtainCRACK", myeta),
-        //  Monitored::Scalar<Float_t>("PhiinCRACK", myphi),
-        //  Monitored::Scalar<Float_t>("TimeinCRACK", mytime),
-        //  Monitored::Scalar<Float_t>("Ehad1inCRACK", myehad1),
-        //  Monitored::Scalar<Float_t>("EoverPinCRACK", myeoverp),
-        //  Monitored::Scalar<Float_t>("CoreEMinCRACK", myecore),
-        //  Monitored::Scalar<Float_t>("F0inCRACK", myf0),
-        //  Monitored::Scalar<Float_t>("F1inCRACK", myf1),
-        //  Monitored::Scalar<Float_t>("F2inCRACK", myf2),
-        //  Monitored::Scalar<Float_t>("F3inCRACK", myf3),
-        //  Monitored::Scalar<Float_t>("Re233e237inCRACK", myre233e237),
-        //  Monitored::Scalar<Float_t>("Re237e277inCRACK", myre237e277),
-        //  Monitored::Scalar<u_int8_t>("NOfBLayerHitsinCRACK", mynofblayerhits),
-        //  Monitored::Scalar<u_int8_t>("NOfPixelHitsinCRACK", mynofpixelhits),
-        //  Monitored::Scalar<u_int8_t>("NOfSCTHitsinCRACK", mynofscthits),
-        //  Monitored::Scalar<u_int8_t>("NOfTRTHitsinCRACK", mynoftrthits),
-        //  Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinCRACK", mynoftrthighthresholdhits),
-        //  Monitored::Scalar<Float_t>("DeltaEta1inCRACK", mydeltaeta1),
-        //  Monitored::Scalar<Float_t>("DeltaPhi2inCRACK", mydeltaphi2),
-        //  Monitored::Scalar<Float_t>("Trackd0inCRACK", mytrackd0)
-        //);
-      }
-      else {
-          ATH_MSG_DEBUG("found an electron outside the |eta| > 2.47 acceptance");
-      }
+      double ec = aCluster->et()*cosh(aCluster->eta());
+      if (ec!=0) myf0 = aCluster->energyBE(0)/ec;
+      if (ec!=0) myf1 = aCluster->energyBE(1)/ec;
+      if (ec!=0) myf2 = aCluster->energyBE(2)/ec;
+      if (ec!=0) myf3 = aCluster->energyBE(3)/ec;
 
+      if(trackp !=0) myeoverp = aCluster->e()/trackp;
+    }
 
-      bool myis_pt_gt_2_5gev = myet > 2500. ;
-      bool myis_pt_gt_4gev = myet > 4000. ;
-      bool myis_pt_gt_20gev = myet > 20000. ;
-
-      is_pt_gt_2_5gev = myis_pt_gt_2_5gev ;
-      is_pt_gt_4gev = myis_pt_gt_4gev ;
-      is_pt_gt_20gev = myis_pt_gt_20gev ;
-
-      is_pt_gt_4gev_barrel = myis_pt_gt_4gev ;
-      is_pt_gt_4gev_endcap = myis_pt_gt_4gev ;
-      is_pt_gt_4gev_crack = myis_pt_gt_4gev ;
-
-      is_pt_gt_2_5gev_barrel = myis_pt_gt_2_5gev ;
-      is_pt_gt_2_5gev_endcap = myis_pt_gt_2_5gev ;
-      is_pt_gt_2_5gev_crack = myis_pt_gt_2_5gev ;
-
-      is_pt_gt_20gev_barrel = myis_pt_gt_20gev ;
-      is_pt_gt_20gev_endcap = myis_pt_gt_20gev ;
-      is_pt_gt_20gev_crack = myis_pt_gt_20gev ;
-
-      et = myet;
-      eta = myeta; 
-      phi = myphi;
-
-      fill(
-        "MonitorElectron",
-        et,
-        eta,
-        phi,
-        time,
-        ptcone20,
-        topoetcone40,
-        lbNCandidates,
-        is_pt_gt_2_5gev,
-        is_pt_gt_4gev,
-        is_pt_gt_20gev
+    // Fill per region histograms
+    auto region = GetRegion(myeta);
+    if (region == BARREL) {
+	    fillMonitorElectron(
+        *this,
+        Monitored::Scalar<Float_t>("EtinBARREL", myet),
+        Monitored::Scalar<Float_t>("EtainBARREL", myeta),
+        Monitored::Scalar<Float_t>("PhiinBARREL", myphi),
+        Monitored::Scalar<Float_t>("TimeinBARREL", mytime),
+        Monitored::Scalar<Float_t>("Ehad1inBARREL", myehad1),
+        Monitored::Scalar<Float_t>("EoverPinBARREL", myeoverp),
+        Monitored::Scalar<Float_t>("CoreEMinBARREL", myecore),
+        Monitored::Scalar<Float_t>("F0inBARREL", myf0),
+        Monitored::Scalar<Float_t>("F1inBARREL", myf1),
+        Monitored::Scalar<Float_t>("F2inBARREL", myf2),
+        Monitored::Scalar<Float_t>("F3inBARREL", myf3),
+        Monitored::Scalar<Float_t>("Re233e237inBARREL", myre233e237),
+        Monitored::Scalar<Float_t>("Re237e277inBARREL", myre237e277),
+        Monitored::Scalar<u_int8_t>("NOfBLayerHitsinBARREL", mynofblayerhits),
+        Monitored::Scalar<u_int8_t>("NOfPixelHitsinBARREL", mynofpixelhits),
+        Monitored::Scalar<u_int8_t>("NOfSCTHitsinBARREL", mynofscthits),
+        Monitored::Scalar<u_int8_t>("NOfTRTHitsinBARREL", mynoftrthits),
+        Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinBARREL", mynoftrthighthresholdhits),
+        Monitored::Scalar<Float_t>("DeltaEta1inBARREL", mydeltaeta1),
+        Monitored::Scalar<Float_t>("DeltaPhi2inBARREL", mydeltaphi2),
+        Monitored::Scalar<Float_t>("Trackd0inBARREL", mytrackd0)
       );
     }
+    else if (region == ENDCAP) {
+	    fillMonitorElectron(
+        *this,
+        Monitored::Scalar<Float_t>("EtinENDCAP", myet),
+        Monitored::Scalar<Float_t>("EtainENDCAP", myeta),
+        Monitored::Scalar<Float_t>("PhiinENDCAP", myphi),
+        Monitored::Scalar<Float_t>("TimeinENDCAP", mytime),
+        Monitored::Scalar<Float_t>("Ehad1inENDCAP", myehad1),
+        Monitored::Scalar<Float_t>("EoverPinENDCAP", myeoverp),
+        Monitored::Scalar<Float_t>("CoreEMinENDCAP", myecore),
+        Monitored::Scalar<Float_t>("F0inENDCAP", myf0),
+        Monitored::Scalar<Float_t>("F1inENDCAP", myf1),
+        Monitored::Scalar<Float_t>("F2inENDCAP", myf2),
+        Monitored::Scalar<Float_t>("F3inENDCAP", myf3),
+        Monitored::Scalar<Float_t>("Re233e237inENDCAP", myre233e237),
+        Monitored::Scalar<Float_t>("Re237e277inENDCAP", myre237e277),
+        Monitored::Scalar<u_int8_t>("NOfBLayerHitsinENDCAP", mynofblayerhits),
+        Monitored::Scalar<u_int8_t>("NOfPixelHitsinENDCAP", mynofpixelhits),
+        Monitored::Scalar<u_int8_t>("NOfSCTHitsinENDCAP", mynofscthits),
+        Monitored::Scalar<u_int8_t>("NOfTRTHitsinENDCAP", mynoftrthits),
+        Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinENDCAP", mynoftrthighthresholdhits),
+        Monitored::Scalar<Float_t>("DeltaEta1inENDCAP", mydeltaeta1),
+        Monitored::Scalar<Float_t>("DeltaPhi2inENDCAP", mydeltaphi2),
+        Monitored::Scalar<Float_t>("Trackd0inENDCAP", mytrackd0)
+      );
+    }
+    else if (region == CRACK) {
+    	fillMonitorElectron(
+        *this,
+        Monitored::Scalar<Float_t>("EtinCRACK", myet),
+        Monitored::Scalar<Float_t>("EtainCRACK", myeta),
+        Monitored::Scalar<Float_t>("PhiinCRACK", myphi),
+        Monitored::Scalar<Float_t>("TimeinCRACK", mytime),
+        Monitored::Scalar<Float_t>("Ehad1inCRACK", myehad1),
+        Monitored::Scalar<Float_t>("EoverPinCRACK", myeoverp),
+        Monitored::Scalar<Float_t>("CoreEMinCRACK", myecore),
+        Monitored::Scalar<Float_t>("F0inCRACK", myf0),
+        Monitored::Scalar<Float_t>("F1inCRACK", myf1),
+        Monitored::Scalar<Float_t>("F2inCRACK", myf2),
+        Monitored::Scalar<Float_t>("F3inCRACK", myf3),
+        Monitored::Scalar<Float_t>("Re233e237inCRACK", myre233e237),
+        Monitored::Scalar<Float_t>("Re237e277inCRACK", myre237e277),
+        Monitored::Scalar<u_int8_t>("NOfBLayerHitsinCRACK", mynofblayerhits),
+        Monitored::Scalar<u_int8_t>("NOfPixelHitsinCRACK", mynofpixelhits),
+        Monitored::Scalar<u_int8_t>("NOfSCTHitsinCRACK", mynofscthits),
+        Monitored::Scalar<u_int8_t>("NOfTRTHitsinCRACK", mynoftrthits),
+        Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinCRACK", mynoftrthighthresholdhits),
+        Monitored::Scalar<Float_t>("DeltaEta1inCRACK", mydeltaeta1),
+        Monitored::Scalar<Float_t>("DeltaPhi2inCRACK", mydeltaphi2),
+        Monitored::Scalar<Float_t>("Trackd0inCRACK", mytrackd0)
+      );
+    }
+    else {
+        ATH_MSG_DEBUG("found an electron outside the |eta| > 2.47 acceptance");
+    }
 
-    //np = mynp;
-    //np_barrel = mynp_barrel;
-    //np_endcap = mynp_endcap;
-    //np_crack = mynp_crack;
-
-    //fill(
-    //  "MonitorElectron",
-    //  np,
-    //  np_barrel,
-    //  np_endcap,
-    //  np_crack
-    //);
-
-    fill("Test", Monitored::Scalar<bool>("test", false));
 
-    //auto testGroup = Monitored::Group(m_monTool, Monitored::Scalar<bool>("test", false));
-    
-    return StatusCode::SUCCESS;
+    fillMonitorElectron(
+      *this,
+      Monitored::Scalar<Float_t>("Et", myet),
+      // Check if small differences between old and new monitoring are related to rounding effects
+      //Monitored::Scalar<Float_t>("Eta", myeta),
+      Monitored::Scalar<Double_t>("Eta", myeta),
+      Monitored::Scalar<Float_t>("Phi", myphi),
+      Monitored::Scalar<Float_t>("Time", mytime),
+      Monitored::Scalar<Float_t>("TopoEtCone40", mytopoetcone40),
+      Monitored::Scalar<Float_t>("PtCone20", myptcone20),
+      Monitored::Scalar<u_int16_t>("LBEvoN", mylb),
+      Monitored::Scalar<bool>("is_pt_gt_2_5gev", myet > 2500.),
+      Monitored::Scalar<bool>("is_pt_gt_4gev", myet > 4000.),
+      Monitored::Scalar<bool>("is_pt_gt_20gev", myet > 20000.)
+    );
+  }
+
+  fillMonitorElectron(
+    *this,
+    Monitored::Scalar<int>("N", mynp),
+    Monitored::Scalar<int>("NinBARREL", mynp_barrel),
+    Monitored::Scalar<int>("NinENDCAP", mynp_endcap),
+    Monitored::Scalar<int>("NinCRACK", mynp_crack)
+  );
+  
+  return StatusCode::SUCCESS;
 }
-- 
GitLab


From eef1c29d02220f6da5a1ec4430afddb4c7707c56 Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Sat, 30 Sep 2023 13:54:28 +0200
Subject: [PATCH 3/7] Remove test variable.

---
 .../egamma/egammaPerformance/src/MonitorElectronAlgorithm.h      | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
index 11f130586cf9..ce6d345f45e8 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
@@ -35,7 +35,6 @@ private:
   Gaudi::Property<std::string> m_ParticlePrefix {this,"ParticlePrefix","electron","Name of the particle prefix to be used to define hists"};
   Gaudi::Property<std::string> m_RecoName {this,"RecoName","LHTight","Name of particle flavor in egamma reco"};
   Gaudi::Property<std::string> m_WithTrigger {this,"WithTrigger","","Name extension when electrons are chosen from triggered events"};
-  ToolHandle<GenericMonitoringTool> m_monTool {this, "MonTool", "MonitorElectronTool", "Monitoring tool"};
 
   Regions GetRegion(Float_t eta) const {
     Float_t aeta = fabs(eta);
-- 
GitLab


From ae9a5af57b7df94518ebef270b6fb220b0c7bdb1 Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Sat, 30 Sep 2023 13:56:00 +0200
Subject: [PATCH 4/7] Remove initialisation of test variable.

---
 .../egammaPerformance/src/MonitorElectronAlgorithm.cxx     | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
index 6b44448d23b1..5e24b14004f0 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
@@ -30,13 +30,6 @@ StatusCode MonitorElectronAlgorithm::initialize() {
   ATH_CHECK( AthMonitorAlgorithm::initialize() );
   ATH_CHECK( m_ParticleContainerKey.initialize() );
   ATH_CHECK( m_ElectronIsolationKey.initialize() );
-  if (!m_monTool.empty()) {
-    ATH_CHECK(m_monTool.retrieve());
-  }
-  else {
-    m_monTool.disable(); 
-  }
-
   return StatusCode::SUCCESS;
 }
 
-- 
GitLab


From 8ac8a90c0d78bed115a9ce051b65318ed0f01dcb Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Sat, 30 Sep 2023 14:38:18 +0100
Subject: [PATCH 5/7] Tidy up the header a little. Move inline method and enum
 into anon namespace.

---
 .../src/MonitorElectronAlgorithm.cxx          | 24 +++++++++++++++++++
 .../src/MonitorElectronAlgorithm.h            | 23 ++++--------------
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
index 5e24b14004f0..dc420ad605b7 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
@@ -8,6 +8,30 @@
 #include "MonitorElectronAlgorithm.h"
 
 namespace {
+  enum Regions : int { BARREL=0, CRACK, ENDCAP, FORWARD, NREGIONS };
+
+  Regions GetRegion(Float_t eta) {
+    Float_t aeta = std::abs(eta);
+    const Float_t barrelEtaUpper = 1.37;
+    const Float_t endCapEtaLower = 1.52;
+    const Float_t endCapEtaUpper = 2.47;
+    const Float_t crackEtaLower = barrelEtaUpper;
+    const Float_t crackEtaUpper = endCapEtaLower;
+
+    if (aeta < barrelEtaUpper) {
+      return BARREL;
+    }
+    if (aeta > endCapEtaLower && aeta < endCapEtaUpper) {
+      return ENDCAP;
+    }
+    if (aeta > crackEtaLower && aeta < crackEtaUpper) {
+      return CRACK;
+    }
+    
+    // Out of acceptance.
+    return NREGIONS; 
+  }
+
   template <typename ...T>
   void fillMonitorElectron(
     const MonitorElectronAlgorithm &alg, 
diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
index ce6d345f45e8..c9159793314f 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
@@ -21,31 +21,16 @@
 
 class MonitorElectronAlgorithm : public AthMonitorAlgorithm  {
 public:
-    MonitorElectronAlgorithm( const std::string& name, ISvcLocator* pSvcLocator );
-    virtual ~MonitorElectronAlgorithm();
-    virtual StatusCode initialize() override;
-    StatusCode fillHistograms( const EventContext& ctx ) const override;
-
-    enum Regions : int { BARREL=0, CRACK, ENDCAP, FORWARD, NREGIONS };
+  MonitorElectronAlgorithm( const std::string& name, ISvcLocator* pSvcLocator );
+  virtual ~MonitorElectronAlgorithm();
+  virtual StatusCode initialize() override;
+  StatusCode fillHistograms( const EventContext& ctx ) const override;
 
 private:
-
   SG::ReadHandleKey<xAOD::ElectronContainer> m_ParticleContainerKey {this, "ParticleContainerName", "Electrons", "Name of electron container" };
   SG::ReadDecorHandleKeyArray<xAOD::ElectronContainer> m_ElectronIsolationKey {this, "ElectronIsolationKey", {"Electrons.ptcone20", "Electrons.topoetcone40"} };
   Gaudi::Property<std::string> m_ParticlePrefix {this,"ParticlePrefix","electron","Name of the particle prefix to be used to define hists"};
   Gaudi::Property<std::string> m_RecoName {this,"RecoName","LHTight","Name of particle flavor in egamma reco"};
   Gaudi::Property<std::string> m_WithTrigger {this,"WithTrigger","","Name extension when electrons are chosen from triggered events"};
-
-  Regions GetRegion(Float_t eta) const {
-    Float_t aeta = fabs(eta);
-    // check if object is in barrel
-    if ( aeta < 1.37 ) return MonitorElectronAlgorithm::BARREL;
-    // check if object is in end-caps
-    if ( aeta > 1.52 && aeta < 2.47 ) return MonitorElectronAlgorithm::ENDCAP;
-    // check if object is in crack region
-    if ( aeta > 1.37 && aeta < 1.52 ) return MonitorElectronAlgorithm::CRACK;
-    return MonitorElectronAlgorithm::NREGIONS; // out of acceptance
-  }
-
 };
 #endif
-- 
GitLab


From 6a7d58db70fae81a0f048bf278da55651ed33113 Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Sat, 30 Sep 2023 21:24:13 +0100
Subject: [PATCH 6/7] Reorganise.

---
 .../src/MonitorElectronAlgorithm.cxx          | 316 +++++++-----------
 .../src/MonitorElectronAlgorithm.h            |   1 +
 2 files changed, 131 insertions(+), 186 deletions(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
index dc420ad605b7..5ec173da1d49 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
@@ -7,6 +7,10 @@
 
 #include "MonitorElectronAlgorithm.h"
 
+#include "xAODPrimitives/IsolationType.h"
+
+#include <unordered_map>
+
 namespace {
   enum Regions : int { BARREL=0, CRACK, ENDCAP, FORWARD, NREGIONS };
 
@@ -39,6 +43,41 @@ namespace {
   ) {
     alg.fill("MonitorElectron", {monitoreds...});
   }
+  
+  float isolationValueFloat(
+    const xAOD::Electron &electron,
+    const xAOD::Iso::IsolationType &info, 
+    float deflt = -999.
+  ) {
+    float dummy(0);
+    return (electron.isolationValue(dummy, info) ? dummy : deflt);
+  }
+
+  float showerShapeValueFloat(
+    const xAOD::Electron &electron,
+    const xAOD::EgammaParameters::ShowerShapeType &info, 
+    float deflt = -999.
+  ) {
+    float dummy(0);
+    return (electron.showerShapeValue(dummy, info) ? dummy : deflt);
+  }
+
+  float trackCaloMatchValueFloat(
+    const xAOD::Electron &electron,
+    const xAOD::EgammaParameters::TrackCaloMatchType &info,
+    float deflt = -999.
+  ) {
+    float dummy(0);
+    return (electron.trackCaloMatchValue(dummy, info) ? dummy : deflt);
+  }
+
+  float divideOr(float numerator, float denominator, float deflt = -999.) {
+    if (denominator == 0) {
+      return deflt;
+    }
+
+    return numerator / denominator;
+  }
 }
 
 MonitorElectronAlgorithm::MonitorElectronAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
@@ -48,7 +87,6 @@ MonitorElectronAlgorithm::MonitorElectronAlgorithm( const std::string& name, ISv
 
 MonitorElectronAlgorithm::~MonitorElectronAlgorithm() = default;
 
-
 StatusCode MonitorElectronAlgorithm::initialize() {
   using namespace Monitored;
   ATH_CHECK( AthMonitorAlgorithm::initialize() );
@@ -59,6 +97,7 @@ StatusCode MonitorElectronAlgorithm::initialize() {
 
 StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) const {
   using namespace Monitored;
+  using namespace xAOD::EgammaHelpers;
 
   // Only monitor good LAr Events.
   xAOD::EventInfo::EventFlagErrorState error_state = GetEventInfo(ctx)->errorState(xAOD::EventInfo::LAr);
@@ -73,11 +112,12 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
   ATH_CHECK(electrons.isValid());
 
   // Set the values of the monitored variables for the event.
-  u_int16_t mylb = GetEventInfo(ctx)->lumiBlock();
   u_int16_t mynp = 0;
-  u_int16_t mynp_barrel = 0;
-  u_int16_t mynp_crack = 0;
-  u_int16_t mynp_endcap = 0;
+  std::unordered_map<Regions, u_int16_t> region_counters = {
+    {BARREL, 0},
+    {CRACK, 0},
+    {ENDCAP, 0}
+  };
 
   for (const auto *const e_iter : *electrons) {
     // Check that the electron meets our requirements.
@@ -87,219 +127,123 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
       break;
     }
     if(isGood) {
-	    mynp++;
-	    Double_t myetaloc = e_iter->eta();
-	    auto regionloc = GetRegion(myetaloc);
+	    ++mynp;
+
+	    Regions regionloc = GetRegion(e_iter->eta());
       ATH_MSG_DEBUG("Test electron in region : " << regionloc);
 
-      if (regionloc == BARREL) { 
-	      ++mynp_barrel;
-      }
-      else if (regionloc == CRACK) { 
-	      ++mynp_crack;
-      }
-      else if (regionloc == ENDCAP) { 
-	      ++mynp_endcap;
+      if (region_counters.count(regionloc)) {
+        ++region_counters[regionloc];
       }
       else {
 	      ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
 	    }
     }
-    else continue;
-
-    // do specific stuff with electrons
+    else {
+      continue;
+    }
 
+    // Do specific stuff with electrons.
     Float_t myet = e_iter->pt(); // in MeV (/Gaudi::Units::GeV; // in GeV)
     Double_t myeta = e_iter->eta();
     Float_t myphi = e_iter->phi();
-
-    // Isolation Energy
-    Float_t mytopoetcone40 = -999.;
-    e_iter->isolationValue(mytopoetcone40,xAOD::Iso::topoetcone40);
-
-    Float_t myptcone20 = -999.;
-    e_iter->isolationValue(myptcone20,xAOD::Iso::ptcone20);
-
     Float_t mytime=0.0;
 
-    // Shower shape variable details
-    Float_t myehad1 = 0.0;
-    Float_t myecore = 0.0;
-    Float_t myf0    = 0.0;
-    Float_t myf1    = 0.0;
-    Float_t myf2    = 0.0;
-    Float_t myf3    = 0.0;
-    Float_t e233  = 0.0;
-    Float_t e237  = 0.0;
-    Float_t e277  = 0.0;
-    Float_t myre233e237 = 0.0;
-    Float_t myre237e277 = 0.0;
-
-    e_iter->showerShapeValue(myehad1, xAOD::EgammaParameters::ehad1);
-    e_iter->showerShapeValue(myecore, xAOD::EgammaParameters::ecore);
+    // Fill per region histograms.
+    std::unordered_map<Regions, const std::string> region_names {
+      {BARREL, "BARREL"},
+      {CRACK, "CRACK"},
+      {ENDCAP, "ENDCAP"}
+    };
 
-    e_iter->showerShapeValue(e237, xAOD::EgammaParameters::e237);
-    e_iter->showerShapeValue(e233, xAOD::EgammaParameters::e233);
-    e_iter->showerShapeValue(e277, xAOD::EgammaParameters::e277);
+    Regions region = GetRegion(myeta);
+    if (region_names.count(region)) {
+      const std::string &region_name = region_names[region];
 
-    if (e237!=0) myre233e237 = e233 / e237;
-    if (e277!=0) myre237e277 = e237 / e277;
+      const Float_t e233 = showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::e233, 0.);
+      const Float_t e237  = showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::e237, 0.);
+      const Float_t e277 = showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::e277, 0.);
 
-
-    // Cluster track match details
-    Float_t mydeltaeta1 = -999.0;
-    e_iter->trackCaloMatchValue(mydeltaeta1, xAOD::EgammaParameters::deltaEta1);
-    Float_t mydeltaphi2 = -999.0;
-    e_iter->trackCaloMatchValue(mydeltaphi2, xAOD::EgammaParameters::deltaPhi2);
-
-    Float_t myeoverp = -999.0;
-    Float_t mytrackd0 = -999.0;
-
-    // associated track details
-    const xAOD::TrackParticle *t = e_iter->trackParticle();
-    double trackp = 0;
-    u_int8_t mynofblayerhits=-1;
-    u_int8_t mynofpixelhits=-1;
-    u_int8_t mynofscthits=-1;
-    u_int8_t mynoftrthits=-1;
-    u_int8_t mynoftrthighthresholdhits=-1;
-
-    if(t) {
-      trackp = t->pt()*cosh(t->eta());
-      // retrieve track summary information
-      t->summaryValue(mynofblayerhits,xAOD::numberOfInnermostPixelLayerHits);
-      t->summaryValue(mynofpixelhits,xAOD::numberOfPixelHits);
-      t->summaryValue(mynofscthits,xAOD::numberOfSCTHits);
-      t->summaryValue(mynoftrthits,xAOD::numberOfTRTHits);
-      t->summaryValue(mynoftrthighthresholdhits,xAOD::numberOfTRTHighThresholdHits);
-      mytrackd0 = t->d0();
-    }
-    else
-      ATH_MSG_DEBUG("Error attempting to retrieve associated track");
-
-
-    // Associated cluster details
-    const xAOD::CaloCluster *aCluster = e_iter->caloCluster();
-    if (aCluster) {
-      mytime = aCluster->time();
-      // Shower shape variable details
-      double ec = aCluster->et()*cosh(aCluster->eta());
-      if (ec!=0) myf0 = aCluster->energyBE(0)/ec;
-      if (ec!=0) myf1 = aCluster->energyBE(1)/ec;
-      if (ec!=0) myf2 = aCluster->energyBE(2)/ec;
-      if (ec!=0) myf3 = aCluster->energyBE(3)/ec;
-
-      if(trackp !=0) myeoverp = aCluster->e()/trackp;
-    }
-
-    // Fill per region histograms
-    auto region = GetRegion(myeta);
-    if (region == BARREL) {
-	    fillMonitorElectron(
-        *this,
-        Monitored::Scalar<Float_t>("EtinBARREL", myet),
-        Monitored::Scalar<Float_t>("EtainBARREL", myeta),
-        Monitored::Scalar<Float_t>("PhiinBARREL", myphi),
-        Monitored::Scalar<Float_t>("TimeinBARREL", mytime),
-        Monitored::Scalar<Float_t>("Ehad1inBARREL", myehad1),
-        Monitored::Scalar<Float_t>("EoverPinBARREL", myeoverp),
-        Monitored::Scalar<Float_t>("CoreEMinBARREL", myecore),
-        Monitored::Scalar<Float_t>("F0inBARREL", myf0),
-        Monitored::Scalar<Float_t>("F1inBARREL", myf1),
-        Monitored::Scalar<Float_t>("F2inBARREL", myf2),
-        Monitored::Scalar<Float_t>("F3inBARREL", myf3),
-        Monitored::Scalar<Float_t>("Re233e237inBARREL", myre233e237),
-        Monitored::Scalar<Float_t>("Re237e277inBARREL", myre237e277),
-        Monitored::Scalar<u_int8_t>("NOfBLayerHitsinBARREL", mynofblayerhits),
-        Monitored::Scalar<u_int8_t>("NOfPixelHitsinBARREL", mynofpixelhits),
-        Monitored::Scalar<u_int8_t>("NOfSCTHitsinBARREL", mynofscthits),
-        Monitored::Scalar<u_int8_t>("NOfTRTHitsinBARREL", mynoftrthits),
-        Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinBARREL", mynoftrthighthresholdhits),
-        Monitored::Scalar<Float_t>("DeltaEta1inBARREL", mydeltaeta1),
-        Monitored::Scalar<Float_t>("DeltaPhi2inBARREL", mydeltaphi2),
-        Monitored::Scalar<Float_t>("Trackd0inBARREL", mytrackd0)
-      );
-    }
-    else if (region == ENDCAP) {
 	    fillMonitorElectron(
         *this,
-        Monitored::Scalar<Float_t>("EtinENDCAP", myet),
-        Monitored::Scalar<Float_t>("EtainENDCAP", myeta),
-        Monitored::Scalar<Float_t>("PhiinENDCAP", myphi),
-        Monitored::Scalar<Float_t>("TimeinENDCAP", mytime),
-        Monitored::Scalar<Float_t>("Ehad1inENDCAP", myehad1),
-        Monitored::Scalar<Float_t>("EoverPinENDCAP", myeoverp),
-        Monitored::Scalar<Float_t>("CoreEMinENDCAP", myecore),
-        Monitored::Scalar<Float_t>("F0inENDCAP", myf0),
-        Monitored::Scalar<Float_t>("F1inENDCAP", myf1),
-        Monitored::Scalar<Float_t>("F2inENDCAP", myf2),
-        Monitored::Scalar<Float_t>("F3inENDCAP", myf3),
-        Monitored::Scalar<Float_t>("Re233e237inENDCAP", myre233e237),
-        Monitored::Scalar<Float_t>("Re237e277inENDCAP", myre237e277),
-        Monitored::Scalar<u_int8_t>("NOfBLayerHitsinENDCAP", mynofblayerhits),
-        Monitored::Scalar<u_int8_t>("NOfPixelHitsinENDCAP", mynofpixelhits),
-        Monitored::Scalar<u_int8_t>("NOfSCTHitsinENDCAP", mynofscthits),
-        Monitored::Scalar<u_int8_t>("NOfTRTHitsinENDCAP", mynoftrthits),
-        Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinENDCAP", mynoftrthighthresholdhits),
-        Monitored::Scalar<Float_t>("DeltaEta1inENDCAP", mydeltaeta1),
-        Monitored::Scalar<Float_t>("DeltaPhi2inENDCAP", mydeltaphi2),
-        Monitored::Scalar<Float_t>("Trackd0inENDCAP", mytrackd0)
-      );
-    }
-    else if (region == CRACK) {
-    	fillMonitorElectron(
-        *this,
-        Monitored::Scalar<Float_t>("EtinCRACK", myet),
-        Monitored::Scalar<Float_t>("EtainCRACK", myeta),
-        Monitored::Scalar<Float_t>("PhiinCRACK", myphi),
-        Monitored::Scalar<Float_t>("TimeinCRACK", mytime),
-        Monitored::Scalar<Float_t>("Ehad1inCRACK", myehad1),
-        Monitored::Scalar<Float_t>("EoverPinCRACK", myeoverp),
-        Monitored::Scalar<Float_t>("CoreEMinCRACK", myecore),
-        Monitored::Scalar<Float_t>("F0inCRACK", myf0),
-        Monitored::Scalar<Float_t>("F1inCRACK", myf1),
-        Monitored::Scalar<Float_t>("F2inCRACK", myf2),
-        Monitored::Scalar<Float_t>("F3inCRACK", myf3),
-        Monitored::Scalar<Float_t>("Re233e237inCRACK", myre233e237),
-        Monitored::Scalar<Float_t>("Re237e277inCRACK", myre237e277),
-        Monitored::Scalar<u_int8_t>("NOfBLayerHitsinCRACK", mynofblayerhits),
-        Monitored::Scalar<u_int8_t>("NOfPixelHitsinCRACK", mynofpixelhits),
-        Monitored::Scalar<u_int8_t>("NOfSCTHitsinCRACK", mynofscthits),
-        Monitored::Scalar<u_int8_t>("NOfTRTHitsinCRACK", mynoftrthits),
-        Monitored::Scalar<u_int8_t>("NOfTRTHighThresholdHitsinCRACK", mynoftrthighthresholdhits),
-        Monitored::Scalar<Float_t>("DeltaEta1inCRACK", mydeltaeta1),
-        Monitored::Scalar<Float_t>("DeltaPhi2inCRACK", mydeltaphi2),
-        Monitored::Scalar<Float_t>("Trackd0inCRACK", mytrackd0)
+        Scalar<Float_t>("Etin" + region_name, myet),
+        Scalar<Float_t>("Etain" + region_name, myeta),
+        Scalar<Float_t>("Phiin" + region_name, myphi),
+        Scalar<Float_t>("Timein" + region_name, mytime),
+        Scalar<Float_t>("Ehad1in" + region_name, showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::ehad1, 0.)),
+        Scalar<Float_t>("CoreEMin" + region_name, showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::ecore, 0.)),
+        Scalar<Float_t>("Re233e237in" + region_name, divideOr(e233, e237, 0.)),
+        Scalar<Float_t>("Re237e277in" + region_name, divideOr(e237, e277, 0.)),
+        Scalar<Float_t>("DeltaEta1in" + region_name, trackCaloMatchValueFloat(*e_iter, xAOD::EgammaParameters::deltaEta1)),
+        Scalar<Float_t>("DeltaPhi2in" + region_name, trackCaloMatchValueFloat(*e_iter, xAOD::EgammaParameters::deltaPhi2))
       );
+    
+      // Associated track details.
+      const xAOD::TrackParticle *t = e_iter->trackParticle();
+      double trackp = 0;
+      if(t) {
+        trackp = t->pt()*cosh(t->eta());
+        fillMonitorElectron(
+          *this,
+          Scalar<u_int8_t>("NOfBLayerHitsin" + region_name, summaryValueInt(*t, xAOD::numberOfInnermostPixelLayerHits, -1)),
+          Scalar<u_int8_t>("NOfPixelHitsin" + region_name, summaryValueInt(*t, xAOD::numberOfPixelHits, -1)),
+          Scalar<u_int8_t>("NOfSCTHitsin" + region_name, summaryValueInt(*t, xAOD::numberOfSCTHits, -1)),
+          Scalar<u_int8_t>("NOfTRTHitsin" + region_name, summaryValueInt(*t, xAOD::numberOfTRTHits, -1)),
+          Scalar<u_int8_t>("NOfTRTHighThresholdHitsin" + region_name, summaryValueInt(*t, xAOD::numberOfTRTHighThresholdHits, -1)),
+          Scalar<Float_t>("Trackd0in" + region_name, t->d0())
+        );
+      }
+      else {
+        ATH_MSG_DEBUG("Error attempting to retrieve associated track");
+      }
+
+      // Associated cluster details.
+      const xAOD::CaloCluster *aCluster = e_iter->caloCluster();
+      if (aCluster) {
+        mytime = aCluster->time();
+        
+        // Shower shape variable details.
+        const double ec = aCluster->et()*cosh(aCluster->eta());
+        fillMonitorElectron(
+          *this,
+          Scalar<Float_t>("F0in" + region_name, divideOr(aCluster->energyBE(0), ec, 0)),
+          Scalar<Float_t>("F1in" + region_name, divideOr(aCluster->energyBE(1), ec, 0)),
+          Scalar<Float_t>("F2in" + region_name, divideOr(aCluster->energyBE(2), ec, 0)),
+          Scalar<Float_t>("F3in" + region_name, divideOr(aCluster->energyBE(3), ec, 0)),
+          Scalar<Float_t>("EoverPin" + region_name, divideOr(aCluster->e(), trackp, 0))
+        );
+      }
+      else {
+        ATH_MSG_DEBUG("Error attempting to retrieve associated cluster");
+      }
     }
     else {
         ATH_MSG_DEBUG("found an electron outside the |eta| > 2.47 acceptance");
     }
 
-
     fillMonitorElectron(
       *this,
-      Monitored::Scalar<Float_t>("Et", myet),
+      Scalar<Float_t>("Et", myet),
       // Check if small differences between old and new monitoring are related to rounding effects
-      //Monitored::Scalar<Float_t>("Eta", myeta),
-      Monitored::Scalar<Double_t>("Eta", myeta),
-      Monitored::Scalar<Float_t>("Phi", myphi),
-      Monitored::Scalar<Float_t>("Time", mytime),
-      Monitored::Scalar<Float_t>("TopoEtCone40", mytopoetcone40),
-      Monitored::Scalar<Float_t>("PtCone20", myptcone20),
-      Monitored::Scalar<u_int16_t>("LBEvoN", mylb),
-      Monitored::Scalar<bool>("is_pt_gt_2_5gev", myet > 2500.),
-      Monitored::Scalar<bool>("is_pt_gt_4gev", myet > 4000.),
-      Monitored::Scalar<bool>("is_pt_gt_20gev", myet > 20000.)
+      //Scalar<Float_t>("Eta", myeta),
+      Scalar<Double_t>("Eta", myeta),
+      Scalar<Float_t>("Phi", myphi),
+      Scalar<Float_t>("Time", mytime),
+      Scalar<Float_t>("TopoEtCone40", isolationValueFloat(*e_iter, xAOD::Iso::topoetcone40)),
+      Scalar<Float_t>("PtCone20", isolationValueFloat(*e_iter, xAOD::Iso::ptcone20)),
+      Scalar<u_int16_t>("LBEvoN", GetEventInfo(ctx)->lumiBlock()),
+      Scalar<bool>("is_pt_gt_2_5gev", myet > 2500.),
+      Scalar<bool>("is_pt_gt_4gev", myet > 4000.),
+      Scalar<bool>("is_pt_gt_20gev", myet > 20000.)
     );
   }
 
   fillMonitorElectron(
     *this,
-    Monitored::Scalar<int>("N", mynp),
-    Monitored::Scalar<int>("NinBARREL", mynp_barrel),
-    Monitored::Scalar<int>("NinENDCAP", mynp_endcap),
-    Monitored::Scalar<int>("NinCRACK", mynp_crack)
+    Scalar<int>("N", mynp),
+    Scalar<int>("NinBARREL", region_counters[BARREL]),
+    Scalar<int>("NinENDCAP", region_counters[ENDCAP]),
+    Scalar<int>("NinCRACK", region_counters[CRACK])
   );
   
   return StatusCode::SUCCESS;
diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
index c9159793314f..bf0728ef102d 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.h
@@ -16,6 +16,7 @@
 #include "xAODEgamma/Electron.h"
 #include "xAODEgamma/ElectronContainer.h"
 #include "xAODEgamma/ElectronxAODHelpers.h"
+#include "xAODEgamma/EgammaxAODHelpers.h"
 
 #include <string>
 
-- 
GitLab


From 74ee414daf9d6f9c0696c9b3fd8b3e879ff34244 Mon Sep 17 00:00:00 2001
From: Lucy Lewitt <lucy.lewitt@cern.ch>
Date: Sat, 30 Sep 2023 23:25:34 +0100
Subject: [PATCH 7/7] Fix indent.

---
 .../egammaPerformance/src/MonitorElectronAlgorithm.cxx | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
index 5ec173da1d49..042917967217 100755
--- a/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
+++ b/Reconstruction/egamma/egammaPerformance/src/MonitorElectronAlgorithm.cxx
@@ -127,17 +127,17 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
       break;
     }
     if(isGood) {
-	    ++mynp;
+      ++mynp;
 
-	    Regions regionloc = GetRegion(e_iter->eta());
+      Regions regionloc = GetRegion(e_iter->eta());
       ATH_MSG_DEBUG("Test electron in region : " << regionloc);
 
       if (region_counters.count(regionloc)) {
         ++region_counters[regionloc];
       }
       else {
-	      ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
-	    }
+        ATH_MSG_DEBUG("Found an electron out the acceptance region : " << regionloc);
+      }
     }
     else {
       continue;
@@ -164,7 +164,7 @@ StatusCode MonitorElectronAlgorithm::fillHistograms( const EventContext& ctx ) c
       const Float_t e237  = showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::e237, 0.);
       const Float_t e277 = showerShapeValueFloat(*e_iter, xAOD::EgammaParameters::e277, 0.);
 
-	    fillMonitorElectron(
+      fillMonitorElectron(
         *this,
         Scalar<Float_t>("Etin" + region_name, myet),
         Scalar<Float_t>("Etain" + region_name, myeta),
-- 
GitLab