54{
55
56
57 dqm_core::Result *newresult = new dqm_core::Result();
58
59
60 int nBinsX = 0;
61 int nBinsY = 0;
62 TH1* firstBinwiseHist = 0;
63
64
65
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 = static_cast<TH1*> (static_cast<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 }
91 std::vector<std::pair<TH1*,float> > binwiseStatHists;
92 dqm_core::Result::Status
status = dqm_core::Result::Undefined;
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
100 for (dqm_core::ParametersMap::const_iterator paramIter=map.begin();paramIter!=map.end();++paramIter){
101
102
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);
113 continue;
114 }
115
116
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( (static_cast<TH1*>(inputobject)->GetNbinsX() == nBinsX) &&
129 (static_cast<TH1*>(inputobject)->GetNbinsY() == nBinsY)) {
130 mask =
static_cast<TH1*
>(inputobject);
131 }
132 }
133 isSpecialParameter = true;
134 break;
135 }
136
137 tagType = "Algorithm--BinsDiffByStrips";
138 if ( (stringPos =
tag.find(tagType)) != std::string::npos) {
139 if( inputobject->IsA()->InheritsFrom("TObjArray") ) {
140 binwiseStatHist = static_cast<TH1*> (static_cast<TObjArray*> (inputobject)->First());
141 if( (binwiseStatHist->GetNbinsX() != nBinsX) || (binwiseStatHist->GetNbinsY() != nBinsY) ) {
142 binwiseStatHist = 0;
143 }
144 else {
145 isSpecialParameter = true;
146 }
147 }
148 }
149 tagType = "AndGroup";
150 if ( (stringPos =
tag.find(tagType)) != std::string::npos) {
151 andGroup = tagIter->second;
152 }
153 }
154 if( !isSpecialParameter ){
156 }
157 else {
158 if( andGroup == -99999. ) {
159 if( binwiseStatHist != 0 ) {
160 std::pair<TH1*,float> binStatsPair ( binwiseStatHist, weight );
161 binwiseStatHists.push_back(binStatsPair);
162 }
163 }
164 else {
165 if( binwiseStatHist != 0 ) {
166 std::map<double,std::vector<std::pair<TH1*,float> > >::iterator fitr = binwiseAndGroup.find(andGroup);
167 if( fitr == binwiseAndGroup.end() ) {
168
169 std::vector<std::pair<TH1*,float> > newAndGroup;
170 newAndGroup.push_back( std::make_pair( binwiseStatHist, weight ) );
171 binwiseAndGroup.insert(std::make_pair(andGroup,newAndGroup));
172 setOfAndGroups.insert(andGroup);
173 }
174 else {
175 fitr->second.push_back( std::make_pair( binwiseStatHist, weight ) );
176 }
177 }
178 else {
179 std::map<double,std::vector<std::pair<int,float> > >::iterator fitr = standardAndGroup.find(andGroup);
180 if( fitr == standardAndGroup.end() ) {
181
182 std::vector<std::pair<int,float> > newAndGroup;
183 newAndGroup.push_back( std::make_pair( inputResult->status_, weight ) );
184 standardAndGroup.insert( std::make_pair(andGroup, newAndGroup) );
185 setOfAndGroups.insert(andGroup);
186 }
187 else {
188 fitr->second.push_back( std::make_pair( inputResult->status_, weight ) );
189 }
190 }
191 }
192 }
193 }
194
195
196
197 std::set<double>::iterator setItr = setOfAndGroups.begin();
198 while (setItr != setOfAndGroups.end()) {
199 std::map<double, std::vector<std::pair<TH1*,float> > >::iterator findIter = binwiseAndGroup.find(*setItr);
200 if( findIter == binwiseAndGroup.end() ) {
201 std::map<double, std::vector<std::pair<int,float> > >::iterator fsIter = standardAndGroup.find(*setItr);
202 if( fsIter != standardAndGroup.end() ) {
203 if( !fsIter->second.empty() ) {
204 dqm_core::Result::Status groupStatus = dqm_core::Result::Red;
205 float groupWeight = 0;
206 for( std::vector<std::pair<int,float> >::const_iterator sandItr = fsIter->second.begin();
207 sandItr != fsIter->second.end(); ++sandItr ) {
209 groupWeight += sandItr->second;
210 }
212 }
213 standardAndGroup.erase(fsIter);
214 }
215 setOfAndGroups.erase(setItr++);
216 } else {
217 ++setItr;
218 }
219 }
220 if( (binwiseStatHists.size() == 0) && (setOfAndGroups.size() == 0) ) {
221 newresult->status_ =
status;
222 return newresult;
223 }
224
225 std::vector<std::pair<TH1*,float> >::const_iterator itr;
226 std::vector<std::pair<TH1*,float> >::const_iterator iBegin = binwiseStatHists.begin();
227 std::vector<std::pair<TH1*,float> >::const_iterator iEnd = binwiseStatHists.end();
228
229 if( mask != 0 ){
230 for(int ix = 1; ix <= nBinsX; ix++) {
231 for(int iy = 1; iy <= nBinsY; iy++) {
232 int bin = firstBinwiseHist->GetBin(ix,iy);
233
234 double downWeight = 0;
235 if(
mask->GetBinContent(bin) != 0) {
236 downWeight = 1;
237 }
238 for( itr = iBegin; itr != iEnd; ++itr ) {
240 (itr->second - downWeight) );
241 }
242
243 for( std::map<double, std::vector<std::pair<TH1*,float> > >::iterator bItr = binwiseAndGroup.begin();
244 bItr != binwiseAndGroup.end(); ++ bItr ) {
245 dqm_core::Result::Status groupStatus = dqm_core::Result::Red;
246 float groupWeight = 0;
247 for( std::vector<std::pair<TH1*,float> >::const_iterator bandItr = bItr->second.begin();
248 bandItr != bItr->second.end(); ++bandItr ) {
249 groupStatus =
tools::BestCaseAddStatus( groupStatus,(dqm_core::Result::Status) floor(bandItr->first->GetBinContent(bin)),
250 (bandItr->second - downWeight) );
251 groupWeight += bandItr->second - downWeight;
252 }
253 std::map<double, std::vector<std::pair<int,float> > >::iterator fsIter = standardAndGroup.find(bItr->first);
254 if( fsIter != standardAndGroup.end() ) {
255 for( std::vector<std::pair<int,float> >::const_iterator sandItr = fsIter->second.begin();
256 sandItr != fsIter->second.end(); ++sandItr ) {
258 groupWeight += sandItr->second;
259 }
260 }
262
263 }
264 }
265 }
266 }
267 else {
268 for(int ix = 1; ix <= nBinsX; ix++) {
269 for(int iy = 1; iy <= nBinsY; iy++) {
271 if( ! binwiseStatHists.empty() ) {
272 bin = binwiseStatHists.front().first->GetBin(ix,iy);
273 }
274 else {
275 bin = binwiseAndGroup.begin()->second.front().first->GetBin(ix,iy);
276 }
277
278 for( itr = iBegin; itr != iEnd; ++itr ) {
280 itr->second );
281 }
282
283
284 for( std::map<double, std::vector<std::pair<TH1*,float> > >::iterator bItr = binwiseAndGroup.begin();
285 bItr != binwiseAndGroup.end(); ++ bItr ) {
286
287 dqm_core::Result::Status groupStatus = dqm_core::Result::Red;
288 float groupWeight = 0;
289 for( std::vector<std::pair<TH1*,float> >::const_iterator bandItr = bItr->second.begin();
290 bandItr != bItr->second.end(); ++bandItr ) {
291 groupStatus =
tools::BestCaseAddStatus( groupStatus,(dqm_core::Result::Status) floor(bandItr->first->GetBinContent(bin)),
292 bandItr->second );
293 groupWeight += bandItr->second;
294 }
295 std::map<double, std::vector<std::pair<int,float> > >::iterator fsIter = standardAndGroup.find(bItr->first);
296 if( fsIter != standardAndGroup.end() ) {
297 for( std::vector<std::pair<int,float> >::const_iterator sandItr = fsIter->second.begin();
298 sandItr != fsIter->second.end(); ++sandItr ) {
300 groupWeight += sandItr->second;
301 }
302 }
304 }
305 }
306 }
307 }
308 newresult->status_ =
status;
309 return newresult;
310}