ATLAS Offline Software
DivideReference.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
12 #include <TH1.h>
13 #include <TClass.h>
14 #include <TObjArray.h>
15 #include <dqm_core/AlgorithmManager.h>
16 
17 #include <iostream>
18 
19 namespace {
20  static dqm_algorithms::DivideReference d1("All_Bins_Filled");
21  static dqm_algorithms::DivideReference d2("Bins_Diff_FromAvg");
22  static dqm_algorithms::DivideReference d3("Bins_GreaterThan_Threshold");
23  static dqm_algorithms::DivideReference d4("Bins_GreaterThanEqual_Threshold");
24  static dqm_algorithms::DivideReference d5("Bins_LessThan_Threshold");
25  static dqm_algorithms::DivideReference d6("Bins_LessThanEqual_Threshold");
26  static dqm_algorithms::DivideReference d7("Bins_Equal_Threshold");
27  static dqm_algorithms::DivideReference d8("Bins_NotEqual_Threshold");
28  static dqm_algorithms::DivideReference d9("BinContentComp");
29 }
30 
32 {
33  dqm_core::AlgorithmManager::instance().registerAlgorithm("DivideReference_"+name,this);
34 }
35 
38 {
39  return new DivideReference(m_name);
40 }
41 
43 dqm_algorithms::DivideReference::execute(const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
44 {
45  TH1 * histogram;
46 
47  if( object.IsA()->InheritsFrom( "TH1" ) ) {
48  histogram = (TH1*)(object.Clone());
49  } else {
50  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
51  }
52 
53  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
54 
55  if (histogram->GetEffectiveEntries() < minstat ) {
57  result->tags_["InsufficientEffectiveEntries"] = histogram->GetEffectiveEntries();
58  delete histogram;
59  return result;
60  }
61 
62 
63  TObject* ro = config.getReference();
64  const TObject* firstReference=0;
65  TObject* secondReference=0;
66  try {
67  dqm_algorithms::tools::handleReference( *ro , firstReference , secondReference );
68  }
69  catch ( dqm_core::Exception & ex ) {
70  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
71  }
72  //Check the reference
73  const TH1* refhist = dynamic_cast<const TH1*>(firstReference);
74  if ( refhist==0 )
75  {
76  throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name );
77  }
78  if ((histogram->GetDimension() != refhist->GetDimension()) ||
79  (histogram->GetNbinsX() != refhist->GetNbinsX()) ||
80  (histogram->GetNbinsY() != refhist->GetNbinsY()) ||
81  refhist->GetNbinsZ() != histogram->GetNbinsZ() )
82  {
83  throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name );
84  }
85  //Configuration done, prepare input histogram
86  histogram->Divide(refhist);
87  //Now prepare to run the real algorithm...
88  ERS_DEBUG(2,"Running algorithm: "<<m_name);
89  dqm_core::Algorithm* subalgorithm;
90  try {
91  subalgorithm = dqm_core::AlgorithmManager::instance().getAlgorithm( m_name );
92  }
93  catch ( dqm_core::AlgorithmNotFound& ex )
94  {
95  ERS_DEBUG(2,"Cannot find algorithm:"+m_name);
96  throw dqm_core::BadConfig(ERS_HERE,name,"Cannot Find sub-algorithm:"+m_name);
97  }
98  //Copy configuration and update reference
100  newConf.setReference( secondReference );
101  dqm_core::Result* result = subalgorithm->execute( name , *histogram , newConf);
102  ERS_DEBUG(2,"Sub algorithm returns:"<<*result);
103  //Add modified histogram to result
104  TObject* robject = result->getObject();
105  if ( !robject ) //No object defined, add the modified histogram
106  {
107  ERS_DEBUG(2,"Adding modified histogram in result");
108  result->object_.reset(histogram);
109  }
110  else //Transform the object_ in TObjArray (if needed) and add this result
111  {
112  ERS_DEBUG(2,"Result already have an associated TObject, appending modified histogram");
113  if ( robject->IsA()->InheritsFrom("TCollection") ) //It is already an array add it...
114  {
115  static_cast<TCollection*>(robject)->Add( histogram );
116  }
117  else
118  {
119  TObjArray* array = new TObjArray( 2 );
120  array->AddAt( robject->Clone() , 0 );
121  array->AddAt( histogram , 1 );
122  //Check in again
123  result->object_.reset( array );
124  }
125  ERS_DEBUG(2,"Result now have a TObjArray of size:"<<static_cast<TObjArray*>(result->getObject())->GetEntries());
126  }
127  return result;
128 }
129 
130 
132  out<<"DivideReference_"+m_name+" : Performs the "+m_name+" algorithm after dividing the input histogram by the reference. I.e. performing: histogram /= Reference (see TH1::Divide). Adds to the output TObject list the modified input histogram."<<std::endl;
133  out<<"Optional Parameter : MinStat : Minimum histogram statistics needed to perform Algorithm"<<std::endl;
134 
135 
136 }
DivideReference.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::tools::SimpleAlgorithmConfig::setReference
void setReference(TObject *ref)
Setters.
Definition: SimpleAlgorithmConfig.cxx:45
dqm_algorithms::DivideReference::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: DivideReference.cxx:43
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::DivideReference
Definition: DivideReference.h:19
dqm_algorithms::DivideReference::clone
DivideReference * clone()
Definition: DivideReference.cxx:37
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::tools::SimpleAlgorithmConfig
This class provides a simple implementation of the DQMF abstract AlgorithmConfig interface which can ...
Definition: SimpleAlgorithmConfig.h:22
lumiFormat.array
array
Definition: lumiFormat.py:98
python.grid.Add
def Add(name)
Definition: grid.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::DivideReference::printDescription
void printDescription(std::ostream &out)
Definition: DivideReference.cxx:131
TH1
Definition: rootspy.cxx:268
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
AlgorithmHelper.h
dqm_algorithms::DivideReference::DivideReference
DivideReference(const std::string &name)
Definition: DivideReference.cxx:31
dqm_algorithms::tools::handleReference
void handleReference(const TObject &inputReference, const TObject *&firstReference, TObject *&secondReference)
Helper function used to handle complex reference histograms This function gets as input a reference o...
Definition: AlgorithmHelper.cxx:828
SimpleAlgorithmConfig.h
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
histogram
std::string histogram
Definition: chains.cxx:52