From be802017e8ba2aaa878902f35d5c687da400069c Mon Sep 17 00:00:00 2001
From: kristin <kristin.lohwasser@cern.ch>
Date: Wed, 4 Mar 2020 16:18:50 +0100
Subject: [PATCH] added 3d monitoring group for the hits

---
 .../Run3AFPMonitoring/AFPSiLayerAlgorithm.h   |  4 +-
 .../python/Run3AFPExampleMonitorAlgorithm.py  | 81 +++++++------------
 .../src/AFPSiLayerAlgorithm.cxx               | 35 ++++----
 3 files changed, 47 insertions(+), 73 deletions(-)

diff --git a/ForwardDetectors/AFP/Run3AFPMonitoring/Run3AFPMonitoring/AFPSiLayerAlgorithm.h b/ForwardDetectors/AFP/Run3AFPMonitoring/Run3AFPMonitoring/AFPSiLayerAlgorithm.h
index c345cbcce3e5..9e07ad9c6a66 100644
--- a/ForwardDetectors/AFP/Run3AFPMonitoring/Run3AFPMonitoring/AFPSiLayerAlgorithm.h
+++ b/ForwardDetectors/AFP/Run3AFPMonitoring/Run3AFPMonitoring/AFPSiLayerAlgorithm.h
@@ -24,9 +24,9 @@ private:
     std::vector<int> m_abGroups1;
     std::vector<std::vector<int>> m_abGroups2;
     std::map<std::string,int> m_cGroups1;
-    std::map<std::string,std::map<std::string,int>> m_cGroups2;
+    std::map<std::string,std::map<std::string,std::map<std::string,int>>> m_HitmapGroups;
     SG::ReadHandleKey<xAOD::AFPSiHitContainer> m_afpHitContainerKey;
-
+//      m_HitmapGroups = buildToolMap<std::string,std::map<std::string,int>>
 protected:
   static const int s_cNearStationIndex;
   static const int s_cFarStationIndex;
diff --git a/ForwardDetectors/AFP/Run3AFPMonitoring/python/Run3AFPExampleMonitorAlgorithm.py b/ForwardDetectors/AFP/Run3AFPMonitoring/python/Run3AFPExampleMonitorAlgorithm.py
index b5c8b2349ce6..45c962625256 100644
--- a/ForwardDetectors/AFP/Run3AFPMonitoring/python/Run3AFPExampleMonitorAlgorithm.py
+++ b/ForwardDetectors/AFP/Run3AFPMonitoring/python/Run3AFPExampleMonitorAlgorithm.py
@@ -32,11 +32,11 @@ def Run3AFPExampleMonitoringConfig(inputFlags):
     # base class configuration following the inputFlags. The returned object 
     # is the algorithm.
     from Run3AFPMonitoring.Run3AFPMonitoringConf import AFPSiLayerAlgorithm
-    afpSiLayerAlgorithm = helper.addAlgorithm(AFPSiLayerAlgorithm,'AFPSiLayer')
+    afpSiLayerAlgorithm = helper.addAlgorithm(AFPSiLayerAlgorithm,'AFPSiLayerAlg')
 
     # You can actually make multiple instances of the same algorithm and give 
     # them different configuration
-    anotherExampleMonAlg = helper.addAlgorithm(AFPSiLayerAlgorithm,'AnotherExampleMonAlg')
+    #anotherExampleMonAlg = helper.addAlgorithm(AFPSiLayerAlgorithm,'AnotherExampleMonAlg')
 
     # # If for some really obscure reason you need to instantiate an algorithm
     # # yourself, the AddAlgorithm method will still configure the base 
@@ -62,65 +62,33 @@ def Run3AFPExampleMonitoringConfig(inputFlags):
 
     # Add a generic monitoring tool (a "group" in old language). The returned 
     # object here is the standard GenericMonitoringTool.
-    station0_1 = helper.addGroup(afpSiLayerAlgorithm, 'AFPSiLayer','Station0/')
+    AFPGroup = helper.addGroup( afpSiLayerAlgorithm,         'AFPSiLayerTool',         'AFP/'     ) 
+
+#    station0_1 = helper.addGroup(afpSiLayerAlgorithm, 'AFPSiLayer','Station0/')
 
     # Add a GMT for the other example monitor algorithm
-    anotherGroup = helper.addGroup(anotherExampleMonAlg,'AFPSiLayer')
+#    anotherGroup = helper.addGroup(anotherExampleMonAlg,'AFPSiLayer')
 
 
     ### STEP 5 ###
     # Configure histogramsIf you want to create histograms with variable bin widths, ROOT provides another constructor suited for this purpose. Instead of passing the data interval and the number of bins, you have to pass an array (single or double precision) of bin edges. When the histogram has n bins, then there are n+1 distinct edges, so the array you pass must be of size n+1.
 
 
-    
-    # My histograms
-    station0_1.defineHistogram('h_hitMultiplicity', title='Number of hits per event', path='AFPSiLayerPath',xbins=40, xmin=-0.5, xmax=39.5)
-    station0_1.defineHistogram('h_timeOverThreshold', title='Time over threshold', path='AFPSiLayerPath', xbins=16, xmin=-0.5, xmax=15.5)
-    # nRows = 80, nColumns = 336.
-   # station0_1.defineHistogram('h_hitMap', title='Map of hits', type='TH2F', path='AFPSiLayer', xbins=80,xmin=0.5,xmax=80+0.5, ybins=336,ymin=0.5,ymax=336+0.5)
-    # end My histograms
-    station0_1.defineHistogram('lumiPerBCID',title='Luminosity,WithCommaInTitle;L/BCID;Events',
-                            path='ToRuleThemAll',xbins=40,xmin=0.0,xmax=80.0)
-    station0_1.defineHistogram('lb', title='Luminosity Block;lb;Events',
-                            path='ToFindThem',xbins=1000,xmin=-0.5,xmax=999.5,weight='testweight')
-    station0_1.defineHistogram('random', title='LB;x;Events',
-                            path='ToBringThemAll',xbins=30,xmin=0,xmax=1,opt='kLBNHistoryDepth=10')
-    station0_1.defineHistogram('random', title='title;x;y',path='ToBringThemAll',
-                            xbins=[0,.1,.2,.4,.8,1.6])
-    station0_1.defineHistogram('random,pT', type='TH2F', title='title;x;y',path='ToBringThemAll',
-                            xbins=[0,.1,.2,.4,.8,1.6],ybins=[0,10,30,40,60,70,90])
-    # myGroup.defineHistogram('pT_passed,pT',type='TEfficiency',title='Test TEfficiency;x;Eff',
-    #                         path='AndInTheDarkness',xbins=100,xmin=0.0,xmax=50.0)
-
-    anotherGroup.defineHistogram('lbWithFilter',title='Lumi;lb;Events',
-                                 path='top',xbins=1000,xmin=-0.5,xmax=999.5)
-    anotherGroup.defineHistogram('run',title='Run Number;run;Events',
-                                 path='top',xbins=1000000,xmin=-0.5,xmax=999999.5)
-
     # Example defining an array of histograms. This is useful if one seeks to create a
     # number of histograms in an organized manner. (For instance, one plot for each ASIC
     # in the subdetector, and these components are mapped in eta, phi, and layer.) Thus,
     # one might have an array of TH1's such as quantity[etaIndex][phiIndex][layerIndex].
-    for alg in [afpSiLayerAlgorithm,anotherExampleMonAlg]:
-        # Using an array of groups
-        array = helper.addArray([2],alg,'AFPSiLayer')
-        array.defineHistogram('a,b',title='AB',type='TH2F',path='Eta',
-                              xbins=10,xmin=0.0,xmax=10.0,
-                              ybins=10,ymin=0.0,ymax=10.0)
-        array.defineHistogram('c',title='C',path='Eta',
-                              xbins=10,xmin=0.0,xmax=10.0)
-        array = helper.addArray([4,2],alg,'AFPSiLayer')
-        array.defineHistogram('a',title='A',path='EtaPhi',
-                              xbins=10,xmin=0.0,xmax=10.0)
-        # Using a map of groups
-        layerList = ['layer1','layer2']
-        clusterList = ['clusterX','clusterB']
-        array = helper.addArray([layerList],alg,'AFPSiLayer')
-        array.defineHistogram('c',title='C',path='Layer',
-                              xbins=10,xmin=0,xmax=10.0)
-        array = helper.addArray([layerList,clusterList],alg,'AFPSiLayer')
-        array.defineHistogram('c',title='C',path='LayerCluster',
-                              xbins=10,xmin=0,xmax=10.0)
+    for alg in [afpSiLayerAlgorithm]:
+
+    # Using a map of groups
+        layerList = ['P0','P1', 'P2', 'P3'] ## TODO XXX adapt to the enum/xAOD namespace names
+        stationList = ['FarStation','NearStation'] # TODO XXX
+        sideList = ['Aside' , 'Cside' ]
+        array = helper.addArray([sideList,stationList,layerList],alg,'AFPSiLayer')
+        array.defineHistogram(  'h_hitMap', title='Map of hits', type='TH2F', path='AFPSiLayer', 
+				xbins=80,xmin=0.5,xmax=80.5, 
+				ybins=336,ymin=0.5,ymax=336.5)
+
 
     ### STEP 6 ###
     # Finalize. The return value should be a tuple of the ComponentAccumulator
@@ -146,8 +114,17 @@ if __name__=='__main__':
 
     # Set the Athena configuration flags
     from AthenaConfiguration.AllConfigFlags import ConfigFlags
-    nightly = '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/CommonInputs/'
-    file = 'data16_13TeV.00311321.physics_Main.recon.AOD.r9264/AOD.11038520._000001.pool.root.1'
+    nightly = ''#/eos/atlas/atlastier0/tzero/prod/data18_13TeV/physics_Main/00348618/data18_13TeV.00348618.physics_Main.recon.AOD.v220/'
+    #file = 'data18_13TeV.00348618.physics_Main.recon.AOD.v220._lb0295._0009.1'
+    file = '/afs/cern.ch/work/k/kristin/dataAFP/data17_13TeV.00337176.physics_Main.merge.AOD.r10258_p3399_tid13243079_00/AOD.13243079._000005.pool.root.1'
+#/afs/cern.ch/work/k/kristin/dataAFP/data17_13TeV.00337176.physics_Main.deriv.DAOD_STDM7.r10258_p3399_p4030/DAOD_STDM7.20036794._000007.pool.root.1'
+#/afs/cern.ch/work/k/kristin/dataAFP/data17_13TeV.00337176.physics_Main.recon.AOD.r10258_p3412_r11501/AOD.18508508._000007.pool.root.1'
+#/eos/atlas/atlastier0/tzero/prod/data18_13TeV/physics_Main/00354309/data18_13TeV.00354309.physics_Main.recon.AOD.f946/data18_13TeV.00354309.physics_Main.recon.AOD.f946._lb0130._0001.1'
+   # nightly = '/eos/atlas/atlastier0/tzero/prod/data18_13TeV/physics_Main/00357750/data18_13TeV.00357750.physics_Main.recon.AOD.f1041/'
+   # file = 'data18_13TeV.00357750.physics_Main.recon.AOD.f1041._lb0105._SFO-7._0103.1'
+
+    #nightly = '/eos/atlas/atlastier0/tzero/prod/data17_13TeV/physics_Main/00337176/data17_13TeV.00337176.physics_Main.recon.AOD.f871/'
+    #file = 'data17_13TeV.00337176.physics_Main.recon.AOD.f871._lb0142._0006.1'
     ConfigFlags.Input.Files = [nightly+file]
     ConfigFlags.Input.isMC = False
     ConfigFlags.Output.HISTFileName = 'AFPOutput.root'
@@ -167,4 +144,4 @@ if __name__=='__main__':
     # exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG
     cfg.printConfig(withDetails=False) # set True for exhaustive info
 
-    cfg.run(10) #use cfg.run(20) to only run on first 20 events
+    cfg.run(10000) #use cfg.run(20) to only run on first 20 events
diff --git a/ForwardDetectors/AFP/Run3AFPMonitoring/src/AFPSiLayerAlgorithm.cxx b/ForwardDetectors/AFP/Run3AFPMonitoring/src/AFPSiLayerAlgorithm.cxx
index 7301d788d968..d33b6042176a 100644
--- a/ForwardDetectors/AFP/Run3AFPMonitoring/src/AFPSiLayerAlgorithm.cxx
+++ b/ForwardDetectors/AFP/Run3AFPMonitoring/src/AFPSiLayerAlgorithm.cxx
@@ -35,20 +35,17 @@ AFPSiLayerAlgorithm::~AFPSiLayerAlgorithm() {}
 
 StatusCode AFPSiLayerAlgorithm::initialize() {
     using namespace Monitored;
-    
-m_abGroups1 = buildToolMap<int>(m_tools,"AFPSiLayer",2);
-    m_abGroups2 = buildToolMap<std::vector<int>>(m_tools,"AFPSiLayer",4,2);
-    /*
-    std::vector<std::string> layers = {"layer1","layer2"};
-    std::vector<std::string> clusters = {"clusterX","clusterB"};
-    m_cGroups1 = buildToolMap<int>(m_tools,"AFPSiLayer",layers);
-    m_cGroups2 = buildToolMap<std::map<std::string,int>>(m_tools,"AFPSiLayer",layers,clusters);
-    return AthMonitorAlgorithm::initialize();
-    */
-    // We must declare to the framework in initialize what SG objects we are going to use
-    //SG::ReadHandleKey<xAOD::AFPSiHitContainer> afpHitContainerKey("AFPSiHits");
+ 
+    std::vector<std::string> layers = { "P0","P1", "P2", "P3"};
+    std::vector<std::string> stations = { "FarStation","NearStation"};
+    std::vector<std::string> sides = { "Aside","Cside"};
+
+    m_HitmapGroups = buildToolMap<std::map<std::string,std::map<std::string,int>>>(m_tools,"AFPSiLayerTool",sides,stations,layers);
 
-    ATH_CHECK(m_afpHitContainerKey.initialize());
+//  std::map<std::string,std::map<std::string,int>> <std::map<std::string,int>> 
+     // We must declare to the framework in initialize what SG objects we are going to use
+    //SG::ReadHandleKey<xAOD::AFPSiHitContainer> afpHitContainerKey("AFPSiHits");
+    //    ATH_CHECK(m_afpHitContainerKey.initialize());
     // ...
     return AthMonitorAlgorithm::initialize();
 }
@@ -59,8 +56,8 @@ StatusCode AFPSiLayerAlgorithm::fillHistograms( const EventContext& ctx ) const
 
     // Declare the quantities which should be monitored
     // My histograms:
-    auto h_hitMultiplicity = Monitored::Scalar<int>("h_hitMultiplicity", 0);
-    auto h_timeOverThreshold = Monitored::Scalar<int>("h_timeOverThreshold", 0);
+ //   auto h_hitMultiplicity = Monitored::Scalar<int>("h_hitMultiplicity", 0);
+ //   auto h_timeOverThreshold = Monitored::Scalar<int>("h_timeOverThreshold", 0);
     //auto h_hitMap = Monitored::Scalar<int>("h_hitMap", 0);
     // End
 /*	
@@ -76,8 +73,8 @@ StatusCode AFPSiLayerAlgorithm::fillHistograms( const EventContext& ctx ) const
     auto pT_passed = Monitored::Scalar<bool>("pT_passed",false);
 */
     // Set the values of the monitored variables for the event
-    h_timeOverThreshold = lbAverageInteractionsPerCrossing(ctx);
-    h_hitMultiplicity = lbAverageInteractionsPerCrossing(ctx);
+  //  h_timeOverThreshold = lbAverageInteractionsPerCrossing(ctx);
+  //  h_hitMultiplicity = lbAverageInteractionsPerCrossing(ctx);
     //    h_hitMap = lbAverageInteractionsPerCrossing(ctx);
 /*
     lumiPerBCID = lbAverageInteractionsPerCrossing(ctx);
@@ -145,7 +142,7 @@ StatusCode AFPSiLayerAlgorithm::fillHistograms( const EventContext& ctx ) const
 
     //ATH_CHECK( afpHitContainerKey.initialize() );
  //for (const auto& muonItr : *muons) {
-    for(const xAOD::AFPSiHit *hitsItr: *afpHitContainer)
+  /*  for(const xAOD::AFPSiHit *hitsItr: *afpHitContainer)
     {
        std::cout << hitsItr->stationID() << std::endl;
 
@@ -162,7 +159,7 @@ StatusCode AFPSiLayerAlgorithm::fillHistograms( const EventContext& ctx ) const
 	}
 
     }
-
+*/
 	//m_cNearStation.eventEnd();
 	//m_cFarStation.eventEnd();
 
-- 
GitLab