ATLAS Offline Software
MUCTPISLTiming.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <iostream>
9 #include <map>
10 #include <vector>
11 #include <string>
12 
13 #include <TClass.h>
14 #include <TH1.h>
15 #include <TH2.h>
16 
17 #include "dqm_core/exceptions.h"
18 #include "dqm_core/AlgorithmConfig.h"
19 #include "dqm_core/AlgorithmManager.h"
20 #include "dqm_core/Result.h"
22 #include "ers/ers.h"
23 
24 
25 static dqm_algorithms::MUCTPISLTiming staticInstance;
26 
27 
28 namespace dqm_algorithms {
29 
30 // *********************************************************************
31 // Public Methods
32 // *********************************************************************
33 
35  : m_name("MUCTPISLTiming")
36 {
37  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
38 }
39 
42 {
43  return new MUCTPISLTiming(*this);
44 }
45 
46 
48 MUCTPISLTiming::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
49 {
50  using namespace std;
51 
52  const TH2 * hist;
53  //TH2 * ref; //not using reference in this case
54 
55  if( object.IsA()->InheritsFrom( "TH2" ) ) {
56  hist = (const TH2*)&object;
57  if (hist->GetDimension() != 2 ){
58  throw dqm_core::BadConfig( ERS_HERE, name, "dimension != 2 " );
59  }
60  } else {
61  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2" );
62  }
63 
64  //Get Parameters and Thresholds
65  double thresh=0.5;
66  double minstat=-1;
67  int centralBin=4; // the middle of 7 bins;
68 
69  try {
70  thresh = dqm_algorithms::tools::GetFirstFromMap("thresh", config.getParameters(), 0.5);
71  minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
72  }
73  catch ( dqm_core::Exception & ex ) {
74  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
75  }
76 
77  //Algo
78 
79  //project our 2D histogram to 1D (x-axis), thus summing up along y
80  //will then compare every bin of the projection with the GetBinContent of the central bin in the 2D histo
81  TH1* projection = hist->ProjectionX();
82 
84  std::map<std::string,double> tags; //defined in https://gitlab.cern.ch/atlas-tdaq-software/dqm_core/-/blob/master/dqm_core/Result.h
85 
86  //assume all good, until find a bad one
88  uint howmanybad=0;
89 
90  for(int iBin=1;iBin<=projection->GetNbinsX();iBin++)//0=underflow bin
91  {
92  if( projection->GetBinContent(iBin)*thresh > hist->GetBinContent(iBin,centralBin) ) //if central slice is less than half of SL sum => bad
93  {
94  result->status_ = dqm_core::Result::Yellow;
95  howmanybad++;
96  //add tag to print which bins are actually the "problematic" ones
97  std::string slNum = std::to_string(iBin-1);
98  if(iBin < 10) slNum = "0" + slNum; // leading zero for conformity
99 
100  tags[slNum] = hist->GetBinContent(iBin,centralBin)*1.0 / projection->GetBinContent(iBin) ;
101  }
102  }
103  tags["howmanybad"] = howmanybad;
104 
105  //set the result tags
106  result->tags_ = tags;
107 
108  //If more than 2SL have bad timing, make it red
109  if(howmanybad>2)
110  result->status_ = dqm_core::Result::Red;
111 
112  Double_t stats[7];
113  hist->GetStats(stats);
114  //if not enough stats, reset the result (but keep this here, so can still see the tag for bad SL)
115  if(stats[0]<minstat)
117 
118  // Return the result
119  return result;
120 }
121 
122 
123 void
125  std::string message;
126  message += "\n";
127  message += "Algorithm: \"" + m_name + "\"\n";
128  message += "Description: for each SL x-slice (set of y-bins for the same x value) check that the central y bin has at least 'thresh' percent(ratio) of the sum of values in the SL \n";
129  out << message;
130 }
131 
132 } // namespace dqm_algorithms
MUCTPISLTiming.h
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
dqm_algorithms::MUCTPISLTiming::m_name
std::string m_name
Definition: MUCTPISLTiming.h:27
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
plotmaker.hist
hist
Definition: plotmaker.py:148
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
dqm_algorithms::MUCTPISLTiming::MUCTPISLTiming
MUCTPISLTiming()
Definition: MUCTPISLTiming.cxx:34
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::MUCTPISLTiming
Definition: MUCTPISLTiming.h:15
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
dqm_algorithms::MUCTPISLTiming::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: MUCTPISLTiming.cxx:48
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::MUCTPISLTiming::printDescription
virtual void printDescription(std::ostream &out)
Definition: MUCTPISLTiming.cxx:124
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
dqm_algorithms::MUCTPISLTiming::clone
virtual dqm_core::Algorithm * clone()
Definition: MUCTPISLTiming.cxx:41
dqm_algorithms
Definition: AddReference.h:17
AlgorithmHelper.h
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339