ATLAS Offline Software
BinwiseSummary.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #ifndef DQM_ALGORITHMS_SUMMARY_DIVIDEBYHIST_CXX
10 #define DQM_ALGORITHMS_SUMMARY_DIVIDEBYHIST_CXX
11 
12 #include <dqm_core/AlgorithmConfig.h>
14 #include <dqm_core/AlgorithmManager.h>
15 
16 #include <dqm_core/Result.h>
17 #include <dqm_core/Parameter.h>
18 
19 #include <TH1.h>
20 #include <TClass.h>
21 #include <TObjArray.h>
23 
25 #include <set>
26 #include <vector>
27 #include <map>
28 
29 
30 #ifndef DQM_ALGORITHMS_MULTIALGORITHMTEST
32 #endif //#ifndef DQM_ALGORITHMS_MULTIALGORITHMTEST
33 
34 
36 {
37  dqm_core::AlgorithmManager::instance().registerSummaryMaker("BinwiseSummary",this);
38 }
39 
41 {
42 }
43 
46 {
47  return new BinwiseSummary();
48 }
49 
52  const dqm_core::Result &,
53  const dqm_core::ParametersMap & map)
54 {
55 
56  //General summary maker infrastructure: (This can be resused)
57  dqm_core::Result *newresult = new dqm_core::Result();
58 
59  //Retrieve axis information for the first histogram:
60  int nBinsX = 0;
61  int nBinsY = 0;
62  TH1* firstBinwiseHist = 0;
63 
64  //Loop over elements of parameter map to find an example binwise status histogram, if any,
65  //Extract nbins x and y now so can check against these:
66  for (dqm_core::ParametersMap::const_iterator paramIter=map.begin();paramIter!=map.end();++paramIter){
67  if ( paramIter->second->getWeight() == 0 ) {
68  continue;
69  }
70  dqm_core::Result * inputResult = paramIter->second->getResult().get();
71  TObject* inputobject = inputResult->getObject();
72  if (inputobject == 0) {
73  continue;
74  }
75  for (std::map<std::string,double>::const_iterator tagIter=inputResult->tags_.begin();
76  tagIter != inputResult->tags_.end(); ++tagIter ) {
77  if( tagIter->first.find("Algorithm--BinsDiffByStrips") != std::string::npos) {
78  if( inputobject->IsA()->InheritsFrom("TObjArray") ) {
79  firstBinwiseHist = (TH1*) ((TObjArray*)inputobject)->First();
80  nBinsX = firstBinwiseHist->GetNbinsX();
81  nBinsY = firstBinwiseHist->GetNbinsY();
82  break;
83  }
84  }
85  }
86  if( (nBinsX != 0) || (nBinsY != 0) ) {
87  break;
88  }
89  }
90  TH1 * mask = 0;
91  std::vector<std::pair<TH1*,float> > binwiseStatHists;
93 
94  std::map<double,std::vector<std::pair<int,float> > > standardAndGroup;
95  std::map<double,std::vector<std::pair<TH1*,float> > > binwiseAndGroup;
96  std::set<double> setOfAndGroups;
97 
98 
99  //Loop over elements of the parameter map to extract histograms and there roles, if any:
100  for (dqm_core::ParametersMap::const_iterator paramIter=map.begin();paramIter!=map.end();++paramIter){
101  //If weight is 0 skip this result. Allow to "turn off"
102  // results in summary makers
103  float weight = paramIter->second->getWeight();
104  if ( weight == 0 ) {
105  ERS_DEBUG(2,"Skip result (weight 0): "<<paramIter->first);
106  continue;
107  }
108  dqm_core::Result * inputResult = paramIter->second->getResult().get();
109  TObject* inputobject = inputResult->getObject();
110  if (inputobject == 0) {
111  ERS_DEBUG(2,"Empty input object, "<<paramIter->first);
112  status = tools::WorstCaseAddStatus(status,inputResult->status_,weight);
113  continue;
114  }
115 
116  //This seems to be a good object, use it according to it's tags:
117  bool isSpecialParameter = false;
118  double andGroup = -99999.;
119  TH1* binwiseStatHist = 0;
120  for (std::map<std::string,double>::const_iterator tagIter=inputResult->tags_.begin();
121  tagIter != inputResult->tags_.end(); ++tagIter ) {
122 
123  std::string tag = tagIter->first;
124  size_t stringPos;
125  std::string tagType = "ConfParameter--Role--Mask";
126  if ( (stringPos = tag.find(tagType)) != std::string::npos) {
127  if ( inputobject->IsA()->InheritsFrom("TH1") ) {
128  if( (((TH1*)inputobject)->GetNbinsX() == nBinsX) && (((TH1*)inputobject)->GetNbinsY() == nBinsY)) {
129  mask = (TH1*)inputobject;
130  }
131  }
132  isSpecialParameter = true;
133  break;
134  }
135 
136  tagType = "Algorithm--BinsDiffByStrips"; //<-The only algorithm so far which produces a binwise status.
137  if ( (stringPos = tag.find(tagType)) != std::string::npos) {
138  if( inputobject->IsA()->InheritsFrom("TObjArray") ) {
139  binwiseStatHist = (TH1*) ((TObjArray*) inputobject)->First();
140  if( (binwiseStatHist->GetNbinsX() != nBinsX) || (binwiseStatHist->GetNbinsY() != nBinsY) ) {
141  binwiseStatHist = 0;
142  }
143  else {
144  isSpecialParameter = true;
145  }
146  }
147  }
148  tagType = "AndGroup";
149  if ( (stringPos = tag.find(tagType)) != std::string::npos) {
150  andGroup = tagIter->second;
151  }
152  }
153  if( !isSpecialParameter ){
154  status = tools::WorstCaseAddStatus(status,inputResult->status_,weight);
155  }
156  else {
157  if( andGroup == -99999. ) {
158  if( binwiseStatHist != 0 ) {
159  std::pair<TH1*,float> binStatsPair ( binwiseStatHist, weight );
160  binwiseStatHists.push_back(binStatsPair);
161  }
162  }
163  else {
164  if( binwiseStatHist != 0 ) {
165  std::map<double,std::vector<std::pair<TH1*,float> > >::iterator fitr = binwiseAndGroup.find(andGroup);
166  if( fitr == binwiseAndGroup.end() ) {
167  //New and group, make it:
168  std::vector<std::pair<TH1*,float> > newAndGroup;
169  newAndGroup.push_back( std::make_pair( binwiseStatHist, weight ) );
170  binwiseAndGroup.insert(std::make_pair(andGroup,newAndGroup));
171  setOfAndGroups.insert(andGroup);
172  }
173  else {
174  fitr->second.push_back( std::make_pair( binwiseStatHist, weight ) );
175  }
176  }
177  else {
178  std::map<double,std::vector<std::pair<int,float> > >::iterator fitr = standardAndGroup.find(andGroup);
179  if( fitr == standardAndGroup.end() ) {
180  //New and group, make it:
181  std::vector<std::pair<int,float> > newAndGroup;
182  newAndGroup.push_back( std::make_pair( inputResult->status_, weight ) );
183  standardAndGroup.insert( std::make_pair(andGroup, newAndGroup) );
184  setOfAndGroups.insert(andGroup);
185  }
186  else {
187  fitr->second.push_back( std::make_pair( inputResult->status_, weight ) );
188  }
189  }
190  }
191  }
192  }
193 
194  //Loop over set of and groups, for those found with no binwise component do status calculation
195  // here and remove from set.
196  std::set<double>::iterator setItr = setOfAndGroups.begin();
197  while (setItr != setOfAndGroups.end()) { // we cannot use a normal for-loop because we may erase the current element
198  std::map<double, std::vector<std::pair<TH1*,float> > >::iterator findIter = binwiseAndGroup.find(*setItr);
199  if( findIter == binwiseAndGroup.end() ) {
200  std::map<double, std::vector<std::pair<int,float> > >::iterator fsIter = standardAndGroup.find(*setItr);
201  if( fsIter != standardAndGroup.end() ) {
202  if( !fsIter->second.empty() ) {
204  float groupWeight = 0;
205  for( std::vector<std::pair<int,float> >::const_iterator sandItr = fsIter->second.begin();
206  sandItr != fsIter->second.end(); ++sandItr ) {
207  groupStatus = tools::BestCaseAddStatus( groupStatus, (dqm_core::Result::Status) sandItr->first, sandItr->second );
208  groupWeight += sandItr->second;
209  }
210  status = tools::WorstCaseAddStatus(status,groupStatus,groupWeight);
211  }
212  standardAndGroup.erase(fsIter);
213  }
214  setOfAndGroups.erase(setItr++); // the erased iterator will become invalid, but post-incrementing is safe
215  } else {
216  ++setItr;
217  }
218  }
219  if( (binwiseStatHists.size() == 0) && (setOfAndGroups.size() == 0) ) {
220  newresult->status_ = status;
221  return newresult;
222  }
223 
224  std::vector<std::pair<TH1*,float> >::const_iterator itr;
225  std::vector<std::pair<TH1*,float> >::const_iterator iBegin = binwiseStatHists.begin();
226  std::vector<std::pair<TH1*,float> >::const_iterator iEnd = binwiseStatHists.end();
227 
228  if( mask != 0 ){
229  for(int ix = 1; ix <= nBinsX; ix++) {
230  for(int iy = 1; iy <= nBinsY; iy++) {
231  int bin = firstBinwiseHist->GetBin(ix,iy);
232  //If there is an entry in the mask histogram, we will downweight this bin:
233  double downWeight = 0;
234  if(mask->GetBinContent(bin) != 0) {
235  downWeight = 1;
236  }
237  for( itr = iBegin; itr != iEnd; ++itr ) {
238  status = tools::WorstCaseAddStatus( status,(dqm_core::Result::Status) floor(itr->first->GetBinContent(bin)),
239  (itr->second - downWeight) );
240  }
241  //Iterate over addGroups:
242  for( std::map<double, std::vector<std::pair<TH1*,float> > >::iterator bItr = binwiseAndGroup.begin();
243  bItr != binwiseAndGroup.end(); ++ bItr ) {
245  float groupWeight = 0;
246  for( std::vector<std::pair<TH1*,float> >::const_iterator bandItr = bItr->second.begin();
247  bandItr != bItr->second.end(); ++bandItr ) {
248  groupStatus = tools::BestCaseAddStatus( groupStatus,(dqm_core::Result::Status) floor(bandItr->first->GetBinContent(bin)),
249  (bandItr->second - downWeight) );
250  groupWeight += bandItr->second - downWeight;
251  }
252  std::map<double, std::vector<std::pair<int,float> > >::iterator fsIter = standardAndGroup.find(bItr->first);
253  if( fsIter != standardAndGroup.end() ) {
254  for( std::vector<std::pair<int,float> >::const_iterator sandItr = fsIter->second.begin();
255  sandItr != fsIter->second.end(); ++sandItr ) {
256  groupStatus = tools::BestCaseAddStatus( groupStatus, (dqm_core::Result::Status) sandItr->first, sandItr->second );
257  groupWeight += sandItr->second;
258  }
259  }
260  status = tools::WorstCaseAddStatus( status, groupStatus, groupWeight );
261 
262  }
263  }
264  }
265  }
266  else {
267  for(int ix = 1; ix <= nBinsX; ix++) {
268  for(int iy = 1; iy <= nBinsY; iy++) {
269  int bin = 0;
270  if( ! binwiseStatHists.empty() ) {
271  bin = binwiseStatHists.front().first->GetBin(ix,iy);
272  }
273  else {
274  bin = binwiseAndGroup.begin()->second.front().first->GetBin(ix,iy);
275  }
276 
277  for( itr = iBegin; itr != iEnd; ++itr ) {
278  status = tools::WorstCaseAddStatus( status,(dqm_core::Result::Status) floor(itr->first->GetBinContent(bin)),
279  itr->second );
280  }
281 
282  //Iterate over addGroups:
283  for( std::map<double, std::vector<std::pair<TH1*,float> > >::iterator bItr = binwiseAndGroup.begin();
284  bItr != binwiseAndGroup.end(); ++ bItr ) {
285 
287  float groupWeight = 0;
288  for( std::vector<std::pair<TH1*,float> >::const_iterator bandItr = bItr->second.begin();
289  bandItr != bItr->second.end(); ++bandItr ) {
290  groupStatus = tools::BestCaseAddStatus( groupStatus,(dqm_core::Result::Status) floor(bandItr->first->GetBinContent(bin)),
291  bandItr->second );
292  groupWeight += bandItr->second;
293  }
294  std::map<double, std::vector<std::pair<int,float> > >::iterator fsIter = standardAndGroup.find(bItr->first);
295  if( fsIter != standardAndGroup.end() ) {
296  for( std::vector<std::pair<int,float> >::const_iterator sandItr = fsIter->second.begin();
297  sandItr != fsIter->second.end(); ++sandItr ) {
298  groupStatus = tools::BestCaseAddStatus( groupStatus, (dqm_core::Result::Status) sandItr->first,sandItr->second );
299  groupWeight += sandItr->second;
300  }
301  }
302  status = tools::WorstCaseAddStatus( status, groupStatus, groupWeight );
303  }
304  }
305  }
306  }
307  newresult->status_ = status;
308  return newresult;
309 }
310 
311 #endif // #ifndef DQM_ALGORITHMS_SUMMARY_DIVIDEBYHIST_CXX
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Undefined
@ Undefined
Definition: MaterialTypes.h:8
BinwiseSummary.h
dqm_algorithms::summary::BinwiseSummary
Definition: BinwiseSummary.h:22
dqm_algorithms::summary::BinwiseSummary::execute
dqm_core::Result * execute(const std::string &name, const dqm_core::Result &, const dqm_core::ParametersMap &)
Definition: BinwiseSummary.cxx:51
bin
Definition: BinsDiffFromStripMedian.h:43
dqm_algorithms::tools::BestCaseAddStatus
dqm_core::Result::Status BestCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
Definition: AlgorithmHelper.cxx:1347
dqm_algorithms::summary::BinwiseSummary::~BinwiseSummary
~BinwiseSummary()
Definition: BinwiseSummary.cxx:40
dqm_algorithms::tools::WorstCaseAddStatus
dqm_core::Result::Status WorstCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
Definition: AlgorithmHelper.cxx:1300
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Red
Red
Definition: handimod.py:551
TrackCorrType::First
@ First
Athena::Status
Status
Athena specific StatusCode values.
Definition: AthStatusCode.h:22
TH1
Definition: rootspy.cxx:268
AlgorithmHelper.h
dqm_algorithms::summary::BinwiseSummary::BinwiseSummary
BinwiseSummary()
Definition: BinwiseSummary.cxx:35
merge.status
status
Definition: merge.py:17
SimpleAlgorithmConfig.h
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
dqm_algorithms::summary::BinwiseSummary::clone
BinwiseSummary * clone()
Definition: BinwiseSummary.cxx:45