ATLAS Offline Software
ReferenceMasking.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include <TH1.h>
12 #include <TClass.h>
13 #include <TObjArray.h>
14 #include <dqm_core/AlgorithmManager.h>
15 
16 namespace {
17  static dqm_algorithms::ReferenceMasking Bins_GreaterThan_Threshold("Bins_GreaterThan_Threshold");
18  static dqm_algorithms::ReferenceMasking BinsDiffFromAvg("Bins_Diff_FromAvg");
19 }
20 
22 {
23  dqm_core::AlgorithmManager::instance().registerAlgorithm("ReferenceMasking_"+name,this);
24 }
25 
28 {
29  return new ReferenceMasking(m_name);
30 }
31 
33 dqm_algorithms::ReferenceMasking::execute(const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
34 {
35  TH1 * histogram;
36 
37  if( object.IsA()->InheritsFrom( "TH1" ) ) {
38  histogram = (TH1*)(object.Clone());
39  } else {
40  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
41  }
42 
43  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
44 
45  if (histogram->GetEffectiveEntries() < minstat ) {
47  result->tags_["InsufficientEffectiveEntries"] = histogram->GetEffectiveEntries();
48  delete histogram;
49  return result;
50  }
51 
52  double coeff = dqm_algorithms::tools::GetFirstFromMap("C",config.getParameters(), 0);
53 
54  TH1* refhist;
55  try {
56  refhist = static_cast<TH1 *>( config.getReference() );
57  }
58  catch ( dqm_core::Exception & ex ) {
59  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
60  }
61  if (histogram->GetDimension() != refhist->GetDimension() ) {
62  throw dqm_core::BadRefHist( ERS_HERE, "Dimension", name );
63  }
64  if ((histogram->GetNbinsX() != refhist->GetNbinsX()) || (histogram->GetNbinsY() != refhist->GetNbinsY()) || refhist->GetNbinsZ() != histogram->GetNbinsZ() ) {
65  throw dqm_core::BadRefHist( ERS_HERE, "number of bins", name );
66  }
67  ERS_DEBUG(2,"Masking bins according to reference. Will set content to"<<coeff);
68 
69  for ( Int_t binx=histogram->GetXaxis()->GetFirst() ; binx<=histogram->GetXaxis()->GetLast();++binx)
70  {
71  for ( Int_t biny=histogram->GetYaxis()->GetFirst() ; biny<=histogram->GetYaxis()->GetLast();++biny)
72  {
73  for ( Int_t binz=histogram->GetZaxis()->GetFirst() ; binz<=histogram->GetZaxis()->GetLast();++binz)
74  {
75  if ( refhist->GetBinContent(binx,biny,binz) != 0 )
76  {
77  ERS_DEBUG(3,"Found a bin in reference with entries !=0, set content of bin ("<<binx<<","<<biny<<","<<binz<<") with "<<coeff);
78  histogram->SetBinContent( binx , biny, binz , coeff );
79  }
80  }
81  }
82  }
83 
84 
85 
86  //Now prepare to run the real algorithm...
87  ERS_DEBUG(2,"Running algorithm: "<<m_name);
88  dqm_core::Algorithm* subalgorithm;
89  try {
90  subalgorithm = dqm_core::AlgorithmManager::instance().getAlgorithm( m_name );
91  }
92  catch ( dqm_core::AlgorithmNotFound& ex )
93  {
94  ERS_DEBUG(2,"Cannot find algorithm:"+m_name);
95  throw dqm_core::BadConfig(ERS_HERE,name,"Cannot Find sub-algorithm:"+m_name);
96  }
97  dqm_core::Result* result = subalgorithm->execute( name , *histogram , config);
98  ERS_DEBUG(2,"Sub algorithm returns:"<<*result);
99  //Add modified histogram to result
100  TObject* robject = result->getObject();
101  if ( !robject ) //No object defined, add this
102  {
103  ERS_DEBUG(2,"Adding modified histogram in result");
104  result->object_.reset(histogram);
105  }
106  else //Transform the object_ in TObjArray (if needed) and add this result
107  {
108  ERS_DEBUG(2,"Result already have an associated TObject, appending modified histogram");
109  if ( robject->IsA()->InheritsFrom("TObjArray") ) //It is already an array add it...
110  {
111  static_cast<TObjArray*>(robject)->Add( histogram );
112  //Check in again
113  result->object_.reset( robject );
114  }
115  else
116  {
117  TObjArray* array = new TObjArray( 2 );
118  array->AddAt( robject , 0 );
119  array->AddAt( histogram , 1 );
120  //Check in again
121  result->object_.reset( array );
122  }
123  ERS_DEBUG(2,"Result now have a TObjArray of size:"<<static_cast<TObjArray*>(result->getObject())->GetEntries());
124  }
125  return result;
126 }
127 
128 
130  out<<"ReferenceMasking_"+m_name+" : Performst the "+m_name+" algorithm after using the reference histogram to mask bins. I.e. Perform TH1::SetBinContent(bin,c) for all bins of reference with entries!=0. c (default 0) can be set via configuration. Adds to the output TObject list the modified input histogram."<<std::endl;
131  out<<"Optional Parameter : MinStat : Minimum histogram statistics needed to perform Algorithm"<<std::endl;
132  out<<"Optional Parameter : C : The value of the content of the masked bin. Default c=0"<<std::endl;
133 
134 }
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::ReferenceMasking::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: ReferenceMasking.cxx:33
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::ReferenceMasking::clone
ReferenceMasking * clone()
Definition: ReferenceMasking.cxx:27
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::ReferenceMasking
Definition: ReferenceMasking.h:19
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::ReferenceMasking::printDescription
void printDescription(std::ostream &out)
Definition: ReferenceMasking.cxx:129
dqm_algorithms::ReferenceMasking::ReferenceMasking
ReferenceMasking(const std::string &name)
Definition: ReferenceMasking.cxx:21
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
TH1::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:298
TH1
Definition: rootspy.cxx:268
ReferenceMasking.h
AlgorithmHelper.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