]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackerQAChecker.cxx
Changes required in QA for the amoreQAshifter agent; change units of titles from...
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerQAChecker.cxx
CommitLineData
ece56eb9 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17
18#include "AliMUONTrackerQAChecker.h"
19
20/// \class AliMUONTrackerQAChecker
21///
22/// Implementation of AliQACheckerBase for MCH and MTR
23///
24/// For the moment we only implement the checking of raw data QA for the tracker
25/// by looking at the occupancy at the bus patch level.
26///
27/// \author Laurent Aphecetche, Subatech
28
29#include "AliCDBManager.h"
30#include "AliCodeTimer.h"
31#include "AliLog.h"
32#include "AliMUONRecoParam.h"
33#include "AliMUONTrackerQADataMakerRec.h"
34#include "AliMpBusPatch.h"
35#include "AliMpDDLStore.h"
36#include "AliQAv1.h"
37#include "AliQAv1.h"
38#include "Riostream.h"
39#include "TAxis.h"
40#include "TDirectory.h"
41#include "TH1.h"
42#include "TLine.h"
43#include "TMath.h"
44#include "TPaveText.h"
45
46/// \cond CLASSIMP
47ClassImp(AliMUONTrackerQAChecker)
48/// \endcond
49
50namespace {
51
52 //___________________________________________________________________________
53 int trim(Int_t n,
54 Double_t* x,
55 Double_t alpha,
56 Double_t& tmean,
57 Double_t& tvar,
58 Double_t& min,
59 Double_t& max)
60 {
61 //
62 // Calculates the trimmed (tmean) mean
63 // of a sample (x) and estimates the variance (tvar)
64 // of that mean.
65 //
66
67 // First check input parameters
68
69 // number of observations
70 if ( n < 2 )
71 {
72 return -1;
73 }
74
75 if ( alpha < 0 || alpha >= 0.5 )
76 // proportion of observations
77 // to be trimmed at each end of the sorted sample
78 {
79 return -2;
80 }
81
82 // Input parameters are good. Let's move on.
83
84 // Insure we use a sample sorted into ascending order.
85
86 Int_t* indices = new Int_t[n];
87
88 TMath::Sort(n,x,indices,kFALSE);
89
90 Double_t* sx = new Double_t[n];
91
92 for ( Int_t i = 0; i < n; ++i )
93 {
94 sx[i] = x[indices[i]];
95 }
96 delete[] indices;
97
98
99 // Number of observations trimmed at each end.
100
101 Int_t k = TMath::FloorNint(alpha * n);
102
103 double sum = 0.0;
104
105 for ( Int_t i = k; i < n - k ; ++i )
106 {
107 sum += sx[i];
108 }
109
110 tmean = sum / ( n - 2 * k );
111
112 double t2 = 0.0;
113
114 for ( Int_t i = k; i < n - k; ++i )
115 {
116 t2 += (sx[i] - tmean) * (sx[i] - tmean);
117 }
118
119 tvar = (
120 t2 +
121 k * (sx[k] - tmean) * (sx[k] - tmean) +
122 k * (sx[n - k - 1] - tmean) * (sx[n - k - 1] - tmean)
123 ) / (n * n);
124
125 // get the min and max for the non-rejected values
126 min = DBL_MAX;
127 max = 0.0;
128
129 for ( Int_t i = k; i < n-k; ++i )
130 {
131 min = TMath::Min(min,sx[i]);
132 max = TMath::Max(max,sx[i]);
133 }
134
135 delete[] sx;
136
137 return 0;
138 }
139}
140
141//__________________________________________________________________
142AliMUONTrackerQAChecker::AliMUONTrackerQAChecker() : AliMUONVQAChecker()
143{
144 /// ctor
145}
146
147//__________________________________________________________________
148AliMUONTrackerQAChecker::~AliMUONTrackerQAChecker()
149{
150 /// dtor
151}
152
153//__________________________________________________________________
154AliMUONTrackerQAChecker::AliMUONTrackerQAChecker(const AliMUONTrackerQAChecker& qac) :
155 AliMUONVQAChecker(qac)
156{
157 /// copy ctor
158}
159
160//______________________________________________________________________________
161AliMUONVQAChecker::ECheckCode*
162AliMUONTrackerQAChecker::CheckRecPoints(TObjArray ** list, AliMUONRecoParam* /*recoParam*/)
163{
164 /// Check rec points
165 /// Very binary check for the moment.
166
167 AliCodeTimerAuto("",0);
168
169 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
170 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
171 rv[specie] = AliMUONVQAChecker::kInfo;
172
173 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
174 {
175 TH1* h = AliQAv1::GetData(list,AliMUONTrackerQADataMakerRec::kTrackerNumberOfClustersPerDE,AliRecoParam::ConvertIndex(specie));
176
177 if ( !h ) rv[specie] = AliMUONVQAChecker::kWarning; // only a warning if histo not found, in order not to kill anything because QA failed...
178
179 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal);
180 }
181 return rv;
182}
183
184//______________________________________________________________________________
185AliMUONVQAChecker::ECheckCode
186AliMUONTrackerQAChecker::MarkHisto(TH1& histo, AliMUONVQAChecker::ECheckCode value) const
187{
188 /// Mark histo as originator of some QA error/warning
189
190 if ( value != AliMUONVQAChecker::kInfo )
191 {
192 histo.SetBit(AliQAv1::GetQABit());
193 }
194
195 return value;
196}
197
198//______________________________________________________________________________
199AliMUONVQAChecker::ECheckCode*
200AliMUONTrackerQAChecker::CheckESD(TObjArray ** list, AliMUONRecoParam* /*recoParam*/)
201{
202 /// Check ESD
203
204 AliCodeTimerAuto("",0);
205
206 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
207 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
208 rv[specie] = AliMUONVQAChecker::kInfo;
209
210 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
211
212 TH1* h = AliQAv1::GetData(list,AliMUONTrackerQADataMakerRec::kESDnTracks,AliRecoParam::ConvertIndex(specie));
213
214 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
215
216 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal); // no track -> fatal
217
218 h = AliQAv1::GetData(list,AliMUONTrackerQADataMakerRec::kESDMatchTrig,AliRecoParam::ConvertIndex(specie));
219
220 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
221
222 else if (h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kError); // no trigger matching -> error
223 }
224 return rv;
225}
226
227//______________________________________________________________________________
228AliMUONVQAChecker::ECheckCode*
229AliMUONTrackerQAChecker::CheckRaws(TObjArray ** list, AliMUONRecoParam* recoParam)
230{
231 /// Check raws
232
233 AliCodeTimerAuto("",0);
234
235 if (!recoParam) return 0x0;
236
237 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
238
239 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
240 {
241 rv[specie] = AliMUONVQAChecker::kInfo;
242 }
243
244 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
245 {
246 TH1* hbp = AliQAv1::GetData(list,AliMUONTrackerQADataMakerRec::kTrackerBusPatchOccupancy,AliRecoParam::ConvertIndex(specie));
247
248 TH1* hnpads = AliQAv1::GetData(list,AliMUONTrackerQADataMakerRec::kTrackerBusPatchNofPads,AliRecoParam::ConvertIndex(specie));
249
250 TH1* hbpconfig = AliQAv1::GetData(list,AliMUONTrackerQADataMakerRec::kTrackerBusPatchConfig,AliRecoParam::ConvertIndex(specie));
251
252 if (!hbp || !hnpads )
253 {
254 continue;
255 }
256
257 rv[specie] = BeautifyTrackerBusPatchOccupancy(*hbp,hbpconfig,*hnpads,*recoParam);
258 }
259
260 return rv;
261}
262
263//____________________________________________________________________________
264AliMUONVQAChecker::ECheckCode
265AliMUONTrackerQAChecker::BeautifyTrackerBusPatchOccupancy(TH1& hbp,
266 const TH1* hbuspatchconfig,
267 const TH1& hnpads,
268 AliMUONRecoParam& recoParam)
269{
270 /// Put labels, limits and so on on the TrackerBusPatchOccupancy histogram
271 /// hbuspatchconfig and hbp must have the same bin definitions
272
273 if ( hbuspatchconfig )
274 {
275 if ( hbp.GetNbinsX() != hbuspatchconfig->GetNbinsX() ||
276 hbp.GetXaxis()->GetXmin() != hbuspatchconfig->GetXaxis()->GetXmin() ||
277 hbp.GetXaxis()->GetXmax() != hbuspatchconfig->GetXaxis()->GetXmax() )
278 {
279 AliError("hbp and hbuspatchconfig histograms are not compatible !");
280 return AliMUONVQAChecker::kFatal;
281 }
282 }
283
284 hbp.SetXTitle("Absolute Bus Patch Id");
285 hbp.SetYTitle("Occupancy (percent)");
286 hbp.SetStats(kFALSE);
287
288 Double_t xmin = hbp.GetXaxis()->GetXmin();
289 Double_t xmax = hbp.GetXaxis()->GetXmax();
290
291 Double_t occMax(0.1); // 0.1% y-limit for the plot
292 Double_t maxToleratedOccupancy(recoParam.BuspatchOccupancyHighLimit()*100.0);
293 Double_t minToleratedOccupancy(recoParam.BuspatchOccupancyLowLimit()*100.0);
294 TLine* line1 = new TLine(xmin,maxToleratedOccupancy,xmax,maxToleratedOccupancy);
295 line1->SetLineColor(1);
296 line1->SetLineWidth(1);
297
298 TLine* line2 = new TLine(xmin,minToleratedOccupancy,xmax,minToleratedOccupancy);
299 line2->SetLineColor(1);
300 line2->SetLineWidth(1);
301
302 hbp.GetListOfFunctions()->Add(line1);
303 hbp.GetListOfFunctions()->Add(line2);
304
305 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
306 AliMpBusPatch* bp(0x0);
307
308 Int_t nMissingPads(0);
309 Int_t nPads(0);
310 Int_t nBusPatches(0);
311 Int_t nMissingBusPatches(0);
312
313 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
314 {
315 Int_t bin = hbp.FindBin(bp->GetId());
316 Int_t n = hnpads.GetBinContent(bin);
317
318 ++nBusPatches;
319
320 nPads += n;
321
322 if ( hbp.GetBinContent(bin) <= 0 )
323 {
324 nMissingPads += n;
325 ++nMissingBusPatches;
326 }
327 }
328
329 next.Reset();
330
331 Int_t ok(-1);
332 Int_t n(0);
333 Int_t nBusPatchesAboveLimit(0);
334 Int_t nBusPatchesBelowLimit(0);
335 Double_t alpha(0.1); // trim 10% of data
336 Double_t tmean(0.0),tvar(0.0);
337 Double_t ymin(0.0),ymax(0.0);
338 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kFatal); // default value = serious problem
339
340 if ( nBusPatches )
341 {
342 Double_t* x = new Double_t[nBusPatches];
343
344 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
345 {
346 Int_t bin = hbp.FindBin(bp->GetId());
347 if ( hbp.GetBinContent(bin) > 0 )
348 {
349 x[n] = hbp.GetBinContent(bin);
350 ++n;
351 }
352 if ( hbp.GetBinContent(bin) > maxToleratedOccupancy )
353 {
354 ++nBusPatchesAboveLimit;
355 }
356 if ( hbp.GetBinContent(bin) < minToleratedOccupancy )
357 {
358 // check whether this buspatch has a reason to be absent (only valid
359 // if we got the config, otherwise we cannot do the test)
360 if ( hbuspatchconfig && hbuspatchconfig->GetBinContent(bin) > 0 )
361 {
362 // should be there, so it's an error
363 ++nBusPatchesBelowLimit;
364 }
365 }
366 }
367
368 // computed the truncated mean of the occupancy values, in order to get a
369 // reasonable y-range for the histogram (without giant peaks to the roof
370 // for misbehaving buspatches).
371 ok = trim(n,x,alpha,tmean,tvar,ymin,ymax);
372
373 delete[] x;
374 }
375
376 if ( ok < 0 )
377 {
378 ymax = occMax;
379 }
380 else
381 {
382 ymax = TMath::Max(ymax,occMax);
383 }
384
385 hbp.SetMaximum(ymax*1.4);
386
387 TPaveText* text = new TPaveText(0.50,0.80,0.99,0.99,"NDC");
388
389 if (ok < 0 )
390 {
391 text->AddText("Could not compute truncated mean. Not enough events ?");
392 }
393 else if (!nPads || !nBusPatches)
394 {
395 text->AddText("Could not get the total number of pads. ERROR !!!");
396 }
397 else
398 {
399 Float_t missingPadFraction = nMissingPads*100.0/nPads;
400 Float_t missingBusPatchFraction = nMissingBusPatches*100.0/nBusPatches;
401 Float_t aboveLimitFraction = nBusPatchesAboveLimit*100.0/nBusPatches;
402 Float_t belowLimitFraction = nBusPatchesBelowLimit*100.0/nBusPatches;
403
404 text->AddText(Form("MCH RUN %d",AliCDBManager::Instance()->GetRun()));
405 text->AddText(Form("%5.2f %% of missing buspatches (%d out of %d)",missingBusPatchFraction,nMissingBusPatches,nBusPatches));
406 text->AddText(Form("%5.2f %% of missing pads (%d out of %d)",missingPadFraction,nMissingPads,nPads));
407 text->AddText(Form("%5.2f %% bus patches above the %5.2f %% limit",aboveLimitFraction,maxToleratedOccupancy));
408 text->AddText(Form("%5.2f %% bus patches below the %e %% limit",belowLimitFraction,minToleratedOccupancy));
409 text->AddText(Form("Truncated mean at %2d %% is %7.2f %%",(Int_t)(alpha*100),tmean));
410
411 if ( missingPadFraction >= 100.0 )
412 {
413 rv = AliMUONVQAChecker::kFatal;
414 }
415
416 else if ( missingPadFraction > recoParam.MissingPadFractionLimit()*100.0 ||
417 aboveLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 ||
418 belowLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 )
419 {
420 rv = AliMUONVQAChecker::kError;
421 }
422 else
423 {
424 rv = AliMUONVQAChecker::kInfo;
425 }
426 }
427
428 hbp.GetListOfFunctions()->Add(text);
429
430 if ( rv == AliMUONVQAChecker::kInfo )
431 {
432 text->SetFillColor(3); // green = INFO
433 }
434 else if ( rv == AliMUONVQAChecker::kWarning )
435 {
436 text->SetFillColor(5); // yellow = WARNING
437 }
438 else if ( rv == AliMUONVQAChecker::kFatal)
439 {
440 text->SetFillColor(2); // red = FATAL
441 }
442 else
443 {
444 text->SetFillColor(6); // pink = ERROR
445 }
446
447 return rv;
448}
449