ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
12#include <TH1.h>
13#include <TClass.h>
14#include <TObjArray.h>
15#include <dqm_core/AlgorithmManager.h>
16
17#include <iostream>
18
19namespace {
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
41
42dqm_core::Result*
43dqm_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 ) {
56 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
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}
file declares the dqm_algorithms::DivideReference class.
std::string histogram
Definition chains.cxx:52
This class provides a simple implementation of the DQMF abstract AlgorithmConfig interface which can ...
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
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...
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
void printDescription(std::ostream &out)
DivideReference(const std::string &name)
#define IsA
Declare the TObject style functions.