From af98e747836ebb2892ffab738e0b6f8c55762e41 Mon Sep 17 00:00:00 2001
From: enagy <elemer.nagy@cern.ch>
Date: Wed, 12 Jun 2019 16:32:15 +0200
Subject: [PATCH] Introduced trigger chain names into the root directory and
 produced random histograms as done before in TrigBjetExample_070319/ Also
 corrected the relevant import statement in TrigBjetMonitorAlgorithm.py in
 order to be able to execute the job in a separate     run directory

---
 .../python/TrigBjetMonitCategory.py           | 23 +------
 .../python/TrigBjetMonitorAlgorithm.py        | 51 ++++++++++++---
 .../src/TrigBjetMonitorAlgorithm.cxx          | 62 +++++++++++++++++--
 .../src/TrigBjetMonitorAlgorithm.h            |  4 ++
 4 files changed, 107 insertions(+), 33 deletions(-)

diff --git a/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitCategory.py b/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitCategory.py
index c217d47afb70..cfd11fc5aed9 100644
--- a/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitCategory.py
+++ b/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitCategory.py
@@ -4,7 +4,6 @@
 
 from TriggerJobOpts.TriggerFlags import TriggerFlags
 
-#monitoring_bjet_FTK = ["S_HLT_j35_boffperf_split_FTK", "E_HLT_j35_boffperf_split_FTKVtx", "E_HLT_j35_boffperf_split_FTKRefit"]
 monitoring_bjet_FTK = ["S_HLT_j35_boffperf_split_FTK_L1J15_FTK", "E_HLT_j35_boffperf_split_FTKVtx_L1J15_FTK", "E_HLT_j35_boffperf_split_FTKRefit_L1J15_FTK"]
 
 
@@ -13,34 +12,22 @@ monitoring_bjet_FTK = ["S_HLT_j35_boffperf_split_FTK_L1J15_FTK", "E_HLT_j35_boff
 
 #General trigger chains  -  default values
 
-#monitoring_bjet      = ["E_HLT_j35_boffperf_split", "E_HLT_j55_boffperf", "S_HLT_j55_boffperf_split", "E_HLT_j320_boffperf", "S_HLT_j320_boffperf_split",
-#                        "S_HLT_j225_gsc360_boffperf_split"]
-#monitoring_bjet      = ["S_HLT_j35_gsc55_boffperf_split", "E_HLT_j55_boffperf", "E_HLT_j55_boffperf_split", "S_HLT_j60_gsc110_boffperf_split", "E_HLT_j225_gsc320_boffperf_split"]
-#monitoring_bjet      = ["E_HLT_j55_boffperf_split","S_HLT_j60_gsc110_boffperf_split","S_HLT_j35_gsc55_boffperf_split","E_HLT_j225_gsc300_boffperf_split","E_HLT_j55_boffperf"]
 monitoring_bjet      = ["E_HLT_j35_boffperf_split","E_HLT_j55_boffperf_split","S_HLT_j85_gsc110_boffperf_split","S_HLT_j45_gsc55_boffperf_split","E_HLT_j225_gsc300_boffperf_split"]
 
 
 #if TriggerFlags.doFTK():
 monitoring_bjet += monitoring_bjet_FTK
 
-#monitoring_mujet     = ["S_HLT_mu4_j55_bperf_split_dr05_dz02", "E_HLT_mu4_j55_bperf_split_dr05_dz02_L1BTAG-MU4J15", "E_HLT_mu6_j110_bperf_split_dr05_dz02"]
-#monitoring_mujet     = ["S_HLT_mu4_j35_gsc55_boffperf_split_dr05_dz02", "E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02_L1BTAG-MU6J20", "E_HLT_mu6_j110_boffperf_split_dr05_dz02"]
 monitoring_mujet     = ["S_HLT_mu4_j45_gsc55_boffperf_split_dr05_dz02","E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02_L1BTAG-MU6J20","E_HLT_mu6_j110_gsc150_boffperf_split_dr05_dz02",
                         "E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02"]
 
 # triggers in pp collisions   -  used for q431 test
 
-#monitoring_bjet_pp    = ["E_HLT_j35_boffperf_split", "E_HLT_j55_boffperf", "S_HLT_j55_boffperf_split", "E_HLT_j320_boffperf", "S_HLT_j320_boffperf_split",
-#                         "S_HLT_j225_gsc360_boffperf_split"]
-#monitoring_bjet_pp      = ["S_HLT_j35_gsc55_boffperf_split", "E_HLT_j55_boffperf", "E_HLT_j55_boffperf_split", "S_HLT_j60_gsc110_boffperf_split", "E_HLT_j225_gsc320_boffperf_split"]
-#monitoring_bjet_pp      = ["E_HLT_j55_boffperf_split","S_HLT_j60_gsc110_boffperf_split","S_HLT_j35_gsc55_boffperf_split","E_HLT_j225_gsc300_boffperf_split","E_HLT_j55_boffperf"]
 monitoring_bjet_pp      = ["E_HLT_j35_boffperf_split","E_HLT_j55_boffperf_split","S_HLT_j85_gsc110_boffperf_split","S_HLT_j45_gsc55_boffperf_split","E_HLT_j225_gsc300_boffperf_split"]
 
 #if TriggerFlags.doFTK():
 monitoring_bjet_pp += monitoring_bjet_FTK
 
-#monitoring_mujet_pp   = ["S_HLT_mu4_j55_bperf_split_dr05_dz02", "E_HLT_mu4_j55_bperf_split_dr05_dz02_L1BTAG-MU4J15", "E_HLT_mu6_j110_bperf_split_dr05_dz02"]
-#monitoring_mujet_pp   = ["S_HLT_mu4_j35_gsc55_boffperf_split_dr05_dz02", "E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02_L1BTAG-MU6J20", "E_HLT_mu6_j110_boffperf_split_dr05_dz02"]
 monitoring_mujet_pp  = ["S_HLT_mu4_j45_gsc55_boffperf_split_dr05_dz02","E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02_L1BTAG-MU6J20","E_HLT_mu6_j110_gsc150_boffperf_split_dr05_dz02",
                         "E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02"]
 
@@ -48,7 +35,6 @@ monitoring_mujet_pp  = ["S_HLT_mu4_j45_gsc55_boffperf_split_dr05_dz02","E_HLT_mu
 
 #  cosmics triggers
 
-#monitoring_bjet_cosmic = ["S_HLT_j0_perf_bperf_L1RD0_EMPTY", "S_HLT_j0_perf_bperf_L1J12_EMPTY", "S_HLT_j0_perf_bperf_L1MU10"]
 monitoring_bjet_cosmic = ["S_HLT_j0_perf_boffperf_L1RD0_EMPTY", "S_HLT_j0_perf_boffperf_L1J12_EMPTY", "S_HLT_j0_perf_boffperf_L1MU10"]
 
 
@@ -64,17 +50,14 @@ monitoring_mujet_hi    = ["E_HLT_mu4_j20_ion_dr05", "S_HLT_mu4_j60_ion_dr05", "S
 
 # Triggers for MC  -  used for q221 test
 
-#monitoring_bjet_validation = ["E_HLT_j35_boffperf_split", "E_HLT_j55_boffperf", "S_HLT_j55_boffperf_split", "E_HLT_j320_boffperf", "S_HLT_j320_boffperf_split",
-#                              "S_HLT_j225_gsc360_boffperf_split"]
-#monitoring_bjet_validation = ["S_HLT_j35_gsc55_boffperf_split", "E_HLT_j55_boffperf", "E_HLT_j55_boffperf_split", "S_HLT_j60_gsc110_boffperf_split", "E_HLT_j225_gsc320_boffperf_split"]
-#monitoring_bjet_validation  = ["E_HLT_j55_boffperf_split","S_HLT_j60_gsc110_boffperf_split","S_HLT_j35_gsc55_boffperf_split","E_HLT_j225_gsc300_boffperf_split","E_HLT_j55_boffperf"]
 monitoring_bjet_validation = ["E_HLT_j35_boffperf_split","E_HLT_j55_boffperf_split","S_HLT_j85_gsc110_boffperf_split","S_HLT_j45_gsc55_boffperf_split","E_HLT_j225_gsc300_boffperf_split"]
 
 #if TriggerFlags.doFTK():
 monitoring_bjet_validation += monitoring_bjet_FTK
 
 
-#monitoring_mujet_validation     = ["S_HLT_mu4_j55_bperf_split_dr05_dz02", "E_HLT_mu4_j55_bperf_split_dr05_dz02_L1BTAG-MU4J15", "E_HLT_mu6_j110_bperf_split_dr05_dz02"]
-#monitoring_mujet_validation  = ["S_HLT_mu4_j35_gsc55_boffperf_split_dr05_dz02", "E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02_L1BTAG-MU6J20", "E_HLT_mu6_j110_boffperf_split_dr05_dz02"]
 monitoring_mujet_validation = ["S_HLT_mu4_j45_gsc55_boffperf_split_dr05_dz02","E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02_L1BTAG-MU6J20","E_HLT_mu6_j110_gsc150_boffperf_split_dr05_dz02",
                                "E_HLT_mu6_j60_gsc85_boffperf_split_dr05_dz02"]
+
+print "In TrigBjetMonitCategory: monitoring_bjet"
+print monitoring_bjet
diff --git a/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitorAlgorithm.py b/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitorAlgorithm.py
index 15bf0c5a85ec..5c448fceb084 100644
--- a/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitorAlgorithm.py
+++ b/Trigger/TrigMonitoring/TrigBjetMonitoring/python/TrigBjetMonitorAlgorithm.py
@@ -51,9 +51,24 @@ def TrigBjetMonConfig(inputFlags):
     # trigBjetMonAlg.RandomHist = True
     # to enable a trigger filter, for example:
     #trigBjetMonAlg.TriggerChain = 'HLT_mu26_ivarmedium'
-    trigBjetMonAlg.TriggerChain = 'HLT_e24_lhtight_nod0'
+    #trigBjetMonAlg.TriggerChain = 'HLT_e24_lhtight_nod0'
+    trigBjetMonAlg.TriggerChain = ''
 
     ### STEP 4 ###
+    # Read in the Bjet trigger chain names
+    from TrigBjetMonitoring import TrigBjetMonitCategory
+    bjet_triglist = TrigBjetMonitCategory.monitoring_bjet
+    print bjet_triglist
+    expert = []
+    shifter = []
+    for chain in bjet_triglist :
+        if chain[0:1] == "E" :
+            expert.append(chain[2:])
+        if chain[0:1] == "S" :
+            shifter.append(chain[2:])
+    print expert
+    print shifter
+
     # Add some tools. N.B. Do not use your own trigger decion tool. Use the
     # standard one that is included with AthMonitorAlgorithm.
 
@@ -84,17 +99,32 @@ def TrigBjetMonConfig(inputFlags):
     ### STEP 5 ###
     # Configure histograms
     #NB! The histograms defined here must match the ones in the cxx file exactly
-    myGroup.defineHistogram('lumiPerBCID',title='Luminosity;L/BCID;Events',
-                            path='ToRuleThemAll',xbins=10,xmin=0.0,xmax=10.0)
-    myGroup.defineHistogram('lb', title='Luminosity Block;lb;Events',
-                            path='ToFindThem',xbins=1000,xmin=-0.5,xmax=999.5)
+    print " ==> expert[0]: ", expert[0]
+    myGroup.defineHistogram('E1d0;E1d0', title='Distribution of d0;d0;Events',
+                            path=expert[0],xbins=10,xmin=-1.0,xmax=1.0)
+    myGroup.defineHistogram('E2d0;E2d0', title='Distribution of d0;d0;Events',
+                            path=expert[1],xbins=10,xmin=-1.0,xmax=1.0)
+
+    #myGroup.defineHistogram('lumiPerBCID',title='Luminosity;L/BCID;Events',
+    #                        path='ToRuleThemAll',xbins=10,xmin=0.0,xmax=10.0)
+    #myGroup.defineHistogram('lb', title='Luminosity Block;lb;Events',
+    #                        path='ToFindThem',xbins=1000,xmin=-0.5,xmax=999.5)
     #myGroup.defineHistogram('random', title='LB;x;Events',
     #                        path='ToBringThemAll',xbins=30,xmin=0,xmax=1,opt='kLBNHistoryDepth=10')
     #myGroup.defineHistogram('pT_passed,pT',type='TEfficiency',title='Test TEfficiency;x;Eff',
     #                        path='AndInTheDarkness',xbins=100,xmin=0.0,xmax=50.0)
 
-    shifterGroup.defineHistogram('run',title='Run Number;run;Events',
-                                  path='SomePath',xbins=1000000,xmin=-0.5,xmax=999999.5)
+
+    print " ==> shifter[0]: ", shifter[0]
+    shifterGroup.defineHistogram('S1d0;S1d0', title='Distribution of d0;d0;Events',
+                                 path=shifter[0],xbins=10,xmin=-1.0,xmax=1.0)
+    shifterGroup.defineHistogram('S2d0;S2d0', title='Distribution of d0;d0;Events',
+                                 path=shifter[1],xbins=10,xmin=-1.0,xmax=1.0)
+    shifterGroup.defineHistogram('S2IP3D_pu;S2IP3D_pu', title='IP3D_pu probability distribution;IP3D_pu;Events',
+                                 path=shifter[1],xbins=50,xmin=0.0,xmax=1.0)
+
+    #shifterGroup.defineHistogram('run',title='Run Number;run;Events',
+    #                              path='SomePath',xbins=1000000,xmin=-0.5,xmax=999999.5)
 
     ### STEP 6 ###
     # Finalize. The return value should be a tuple of the ComponentAccumulator
@@ -116,7 +146,8 @@ if __name__=='__main__':
     # Setup logs
     from AthenaCommon.Logging import log
     from AthenaCommon.Constants import DEBUG,INFO
-    log.setLevel(DEBUG)
+    # log.setLevel(DEBUG)
+    log.setLevel(INFO)
 
     # Set the Athena configuration flags
     from AthenaConfiguration.AllConfigFlags import ConfigFlags
@@ -141,5 +172,7 @@ if __name__=='__main__':
     #trigBjetMonitorAcc.getEventAlgo('TrigBjetMonAlg').OutputLevel = 2 # DEBUG
     cfg.printConfig(withDetails=True) # set True for exhaustive info
 
-    cfg.run() #use cfg.run(20) to only run on first 20 events
+    # cfg.run() #use cfg.run(20) to only run on first 20 events
+    Nevents = 10
+    cfg.run(Nevents)
 
diff --git a/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.cxx b/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.cxx
index 9b70da95f835..3d0b096f393d 100644
--- a/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.cxx
+++ b/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.cxx
@@ -6,6 +6,7 @@
 
 TrigBjetMonitorAlgorithm::TrigBjetMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
   : AthMonitorAlgorithm(name,pSvcLocator)
+  ,m_doRandom(true)
 {}
 
 
@@ -13,15 +14,16 @@ TrigBjetMonitorAlgorithm::~TrigBjetMonitorAlgorithm() {}
 
 
 StatusCode TrigBjetMonitorAlgorithm::initialize() {
-    return AthMonitorAlgorithm::initialize();
+  return AthMonitorAlgorithm::initialize();
 }
 
 
 StatusCode TrigBjetMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
-    using namespace Monitored;
+  using namespace Monitored;
 
-    // Declare the quantities which should be monitored
-    //NB! The variables and histograms defined here must match the ones in the py file exactly!
+  // Declare the quantities which should be monitored
+  //NB! The variables and histograms defined here must match the ones in the py file exactly!
+  /* Elin's example
     auto lumiPerBCID = Monitored::Scalar<float>("lumiPerBCID",0.0);
     auto lb = Monitored::Scalar<int>("lb",0);
     auto run = Monitored::Scalar<int>("run",0);
@@ -42,6 +44,58 @@ StatusCode TrigBjetMonitorAlgorithm::fillHistograms( const EventContext& ctx ) c
     // Alternative fill method. Get the group yourself, and pass it to the fill function.
     auto tool = getGroup("TrigBjetMonitor");
     fill(tool,run);
+  */
+
+    auto E1d0 = Monitored::Scalar<float>("E1d0",0.0);
+    auto E2d0 = Monitored::Scalar<float>("E2d0",0.0);
+    auto S1d0 = Monitored::Scalar<float>("S1d0",0.0);
+    auto S2d0 = Monitored::Scalar<float>("S2d0",0.0);
+    auto S2IP3D_pu = Monitored::Scalar<float>("S2IP3D_pu",0.0);
+    auto random = Monitored::Scalar<float>("random",0.0);
+
+    // Set the values of the monitored variables for the event
+    /*
+    E1d0 = -0.02;
+    E2d0 = +0.02;
+    S1d0 = -0.01;
+    S2d0 = +0.01;
+    */
+    S2IP3D_pu = 0.5;
+
+    //    TRandom r;
+    TRandom r(ctx.eventID().event_number());
+    TRandom q(ctx.eventID().event_number());
+
+    std::cout << " E1d0 before: " << E1d0 << std::endl;
+    std::cout << " S2d0 before: " << S2d0 << std::endl;
+    std::cout << " random before: " << random << std::endl;
+    std::cout << " m_doRandom " << m_doRandom << std::endl;
+    if (m_doRandom) {
+      E1d0 = r.Gaus(0.,0.1);
+      E2d0 = r.Gaus(0.,0.2);
+      S1d0 = r.Gaus(0.,0.3);
+      S2d0 = r.Gaus(0.,0.4);
+      random = q.Rndm();
+      std::cout << " E1d0 in: " << E1d0 << std::endl;
+      std::cout << " S2d0 in: " << S2d0 << std::endl;
+      std::cout << " random in: " << random << std::endl;
+    }
+    std::cout << " E1d0 after: " << E1d0 << std::endl;
+    std::cout << " S2d0 after: " << S2d0 << std::endl;
+    std::cout << " S2IP3D_pu after: " << S2IP3D_pu << std::endl;
+    std::cout << " random after: " << random << std::endl;
+
+    
+
+    // Fill. First argument is the tool name, all others are the variables to be saved.
+    fill("TrigBjetMonitor",E1d0,S1d0);
+
+    // Alternative fill method. Get the group yourself, and pass it to the fill function.
+    auto tool = getGroup("TrigBjetMonitor");
+    fill(tool,E2d0);
+    fill(tool,S2d0);
+    fill(tool,S2IP3D_pu);
+
 
     return StatusCode::SUCCESS;
 }
diff --git a/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.h b/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.h
index 264640a922bc..002649c9ad39 100644
--- a/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.h
+++ b/Trigger/TrigMonitoring/TrigBjetMonitoring/src/TrigBjetMonitorAlgorithm.h
@@ -8,6 +8,7 @@
 #include "AthenaMonitoring/AthMonitorAlgorithm.h"
 #include "AthenaMonitoring/Monitored.h"
 
+#include "TRandom3.h"
 
 class TrigBjetMonitorAlgorithm : public AthMonitorAlgorithm {
  public:
@@ -15,5 +16,8 @@ class TrigBjetMonitorAlgorithm : public AthMonitorAlgorithm {
   virtual ~TrigBjetMonitorAlgorithm();
   virtual StatusCode initialize() override;
   virtual StatusCode fillHistograms( const EventContext& ctx ) const override;
+ private:
+  //  Gaudi::Property<bool> m_doRandom {this,"RandomHist",false}; 
+  Gaudi::Property<bool> m_doRandom {this,"RandomHist",true};
 };
 #endif
-- 
GitLab