new functionality and new class added
[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"
6482f70b 32#include "AliMUONQAIndices.h"
ece56eb9 33#include "AliMUONRecoParam.h"
ece56eb9 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"
b71c3d2d 45#include "TGaxis.h"
46#include "TVirtualPad.h"
ece56eb9 47
48/// \cond CLASSIMP
49ClassImp(AliMUONTrackerQAChecker)
50/// \endcond
51
52namespace {
53
54 //___________________________________________________________________________
55 int trim(Int_t n,
56 Double_t* x,
57 Double_t alpha,
58 Double_t& tmean,
59 Double_t& tvar,
60 Double_t& min,
61 Double_t& max)
62 {
63 //
64 // Calculates the trimmed (tmean) mean
65 // of a sample (x) and estimates the variance (tvar)
66 // of that mean.
67 //
68
69 // First check input parameters
70
71 // number of observations
72 if ( n < 2 )
73 {
74 return -1;
75 }
76
77 if ( alpha < 0 || alpha >= 0.5 )
78 // proportion of observations
79 // to be trimmed at each end of the sorted sample
80 {
81 return -2;
82 }
83
84 // Input parameters are good. Let's move on.
85
86 // Insure we use a sample sorted into ascending order.
87
88 Int_t* indices = new Int_t[n];
89
90 TMath::Sort(n,x,indices,kFALSE);
91
92 Double_t* sx = new Double_t[n];
93
94 for ( Int_t i = 0; i < n; ++i )
95 {
96 sx[i] = x[indices[i]];
97 }
98 delete[] indices;
99
100
101 // Number of observations trimmed at each end.
102
103 Int_t k = TMath::FloorNint(alpha * n);
104
105 double sum = 0.0;
106
107 for ( Int_t i = k; i < n - k ; ++i )
108 {
109 sum += sx[i];
110 }
111
112 tmean = sum / ( n - 2 * k );
113
114 double t2 = 0.0;
115
116 for ( Int_t i = k; i < n - k; ++i )
117 {
118 t2 += (sx[i] - tmean) * (sx[i] - tmean);
119 }
120
121 tvar = (
122 t2 +
123 k * (sx[k] - tmean) * (sx[k] - tmean) +
124 k * (sx[n - k - 1] - tmean) * (sx[n - k - 1] - tmean)
125 ) / (n * n);
126
127 // get the min and max for the non-rejected values
128 min = DBL_MAX;
129 max = 0.0;
130
131 for ( Int_t i = k; i < n-k; ++i )
132 {
133 min = TMath::Min(min,sx[i]);
134 max = TMath::Max(max,sx[i]);
135 }
136
137 delete[] sx;
138
139 return 0;
140 }
141}
142
143//__________________________________________________________________
144AliMUONTrackerQAChecker::AliMUONTrackerQAChecker() : AliMUONVQAChecker()
145{
146 /// ctor
147}
148
149//__________________________________________________________________
150AliMUONTrackerQAChecker::~AliMUONTrackerQAChecker()
151{
152 /// dtor
153}
154
155//__________________________________________________________________
156AliMUONTrackerQAChecker::AliMUONTrackerQAChecker(const AliMUONTrackerQAChecker& qac) :
157 AliMUONVQAChecker(qac)
158{
159 /// copy ctor
160}
161
162//______________________________________________________________________________
163AliMUONVQAChecker::ECheckCode*
486788fc 164AliMUONTrackerQAChecker::CheckRecPoints(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
ece56eb9 165{
166 /// Check rec points
167 /// Very binary check for the moment.
168
169 AliCodeTimerAuto("",0);
170
171 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
172 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
173 rv[specie] = AliMUONVQAChecker::kInfo;
174
6482f70b 175
ece56eb9 176 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
177 {
6482f70b 178 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNumberOfClustersPerDE,AliRecoParam::ConvertIndex(specie));
ece56eb9 179
180 if ( !h ) rv[specie] = AliMUONVQAChecker::kWarning; // only a warning if histo not found, in order not to kill anything because QA failed...
181
182 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal);
183 }
184 return rv;
185}
186
187//______________________________________________________________________________
188AliMUONVQAChecker::ECheckCode
189AliMUONTrackerQAChecker::MarkHisto(TH1& histo, AliMUONVQAChecker::ECheckCode value) const
190{
191 /// Mark histo as originator of some QA error/warning
192
193 if ( value != AliMUONVQAChecker::kInfo )
194 {
195 histo.SetBit(AliQAv1::GetQABit());
196 }
197
198 return value;
199}
200
201//______________________________________________________________________________
202AliMUONVQAChecker::ECheckCode*
486788fc 203AliMUONTrackerQAChecker::CheckESD(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
ece56eb9 204{
205 /// Check ESD
206
207 AliCodeTimerAuto("",0);
208
209 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
210 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
211 rv[specie] = AliMUONVQAChecker::kInfo;
212
213 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
214
6482f70b 215 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kESDnTracks,AliRecoParam::ConvertIndex(specie));
ece56eb9 216
217 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
218
219 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal); // no track -> fatal
220
6482f70b 221 h = AliQAv1::GetData(list,AliMUONQAIndices::kESDMatchTrig,AliRecoParam::ConvertIndex(specie));
ece56eb9 222
223 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
224
225 else if (h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kError); // no trigger matching -> error
226 }
227 return rv;
228}
229
230//______________________________________________________________________________
231AliMUONVQAChecker::ECheckCode*
486788fc 232AliMUONTrackerQAChecker::CheckRaws(TObjArray ** list, const AliMUONRecoParam* recoParam)
ece56eb9 233{
234 /// Check raws
235
236 AliCodeTimerAuto("",0);
237
238 if (!recoParam) return 0x0;
239
240 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
241
242 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
243 {
244 rv[specie] = AliMUONVQAChecker::kInfo;
245 }
246
247 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
248 {
6482f70b 249 TH1* hbp = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchOccupancy,AliRecoParam::ConvertIndex(specie));
ece56eb9 250
6482f70b 251 TH1* hnpads = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchNofPads,AliRecoParam::ConvertIndex(specie));
ece56eb9 252
6482f70b 253 TH1* hbpconfig = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchConfig,AliRecoParam::ConvertIndex(specie));
ece56eb9 254
64c2397e 255 TH1* hnevents = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofRawEventSeen,AliRecoParam::ConvertIndex(specie));
256
b71c3d2d 257 TH1* hddl = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLOccupancy,AliRecoParam::ConvertIndex(specie));
258
259 if ( !hbp || !hnpads || !hnevents || !hddl )
ece56eb9 260 {
261 continue;
262 }
64c2397e 263
b71c3d2d 264 Int_t nevents = TMath::Nint(hnevents->GetBinContent(1));
265
266 rv[specie] = BeautifyTrackerBusPatchOccupancy(*hddl,*hbp,hbpconfig,*hnpads,nevents,*recoParam);
ece56eb9 267 }
268
269 return rv;
270}
271
272//____________________________________________________________________________
273AliMUONVQAChecker::ECheckCode
b71c3d2d 274AliMUONTrackerQAChecker::BeautifyTrackerBusPatchOccupancy(TH1& hddl,
275 TH1& hbp,
ece56eb9 276 const TH1* hbuspatchconfig,
277 const TH1& hnpads,
64c2397e 278 Int_t nevents,
486788fc 279 const AliMUONRecoParam& recoParam)
ece56eb9 280{
281 /// Put labels, limits and so on on the TrackerBusPatchOccupancy histogram
282 /// hbuspatchconfig and hbp must have the same bin definitions
283
284 if ( hbuspatchconfig )
285 {
286 if ( hbp.GetNbinsX() != hbuspatchconfig->GetNbinsX() ||
287 hbp.GetXaxis()->GetXmin() != hbuspatchconfig->GetXaxis()->GetXmin() ||
288 hbp.GetXaxis()->GetXmax() != hbuspatchconfig->GetXaxis()->GetXmax() )
289 {
290 AliError("hbp and hbuspatchconfig histograms are not compatible !");
291 return AliMUONVQAChecker::kFatal;
292 }
293 }
294
295 hbp.SetXTitle("Absolute Bus Patch Id");
296 hbp.SetYTitle("Occupancy (percent)");
297 hbp.SetStats(kFALSE);
298
299 Double_t xmin = hbp.GetXaxis()->GetXmin();
300 Double_t xmax = hbp.GetXaxis()->GetXmax();
301
302 Double_t occMax(0.1); // 0.1% y-limit for the plot
303 Double_t maxToleratedOccupancy(recoParam.BuspatchOccupancyHighLimit()*100.0);
304 Double_t minToleratedOccupancy(recoParam.BuspatchOccupancyLowLimit()*100.0);
305 TLine* line1 = new TLine(xmin,maxToleratedOccupancy,xmax,maxToleratedOccupancy);
306 line1->SetLineColor(1);
307 line1->SetLineWidth(1);
308
309 TLine* line2 = new TLine(xmin,minToleratedOccupancy,xmax,minToleratedOccupancy);
310 line2->SetLineColor(1);
311 line2->SetLineWidth(1);
312
313 hbp.GetListOfFunctions()->Add(line1);
314 hbp.GetListOfFunctions()->Add(line2);
315
316 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
317 AliMpBusPatch* bp(0x0);
318
319 Int_t nMissingPads(0);
320 Int_t nPads(0);
321 Int_t nBusPatches(0);
322 Int_t nMissingBusPatches(0);
323
324 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
325 {
326 Int_t bin = hbp.FindBin(bp->GetId());
b1f9e9c3 327 Int_t n = TMath::Nint(hnpads.GetBinContent(bin));
ece56eb9 328
329 ++nBusPatches;
330
331 nPads += n;
332
333 if ( hbp.GetBinContent(bin) <= 0 )
334 {
335 nMissingPads += n;
336 ++nMissingBusPatches;
337 }
338 }
339
340 next.Reset();
341
342 Int_t ok(-1);
343 Int_t n(0);
344 Int_t nBusPatchesAboveLimit(0);
345 Int_t nBusPatchesBelowLimit(0);
346 Double_t alpha(0.1); // trim 10% of data
347 Double_t tmean(0.0),tvar(0.0);
348 Double_t ymin(0.0),ymax(0.0);
349 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kFatal); // default value = serious problem
350
351 if ( nBusPatches )
352 {
353 Double_t* x = new Double_t[nBusPatches];
354
355 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
356 {
357 Int_t bin = hbp.FindBin(bp->GetId());
358 if ( hbp.GetBinContent(bin) > 0 )
359 {
360 x[n] = hbp.GetBinContent(bin);
361 ++n;
362 }
363 if ( hbp.GetBinContent(bin) > maxToleratedOccupancy )
364 {
365 ++nBusPatchesAboveLimit;
366 }
367 if ( hbp.GetBinContent(bin) < minToleratedOccupancy )
368 {
369 // check whether this buspatch has a reason to be absent (only valid
370 // if we got the config, otherwise we cannot do the test)
371 if ( hbuspatchconfig && hbuspatchconfig->GetBinContent(bin) > 0 )
372 {
373 // should be there, so it's an error
374 ++nBusPatchesBelowLimit;
375 }
376 }
377 }
378
379 // computed the truncated mean of the occupancy values, in order to get a
380 // reasonable y-range for the histogram (without giant peaks to the roof
381 // for misbehaving buspatches).
382 ok = trim(n,x,alpha,tmean,tvar,ymin,ymax);
383
384 delete[] x;
385 }
386
387 if ( ok < 0 )
388 {
389 ymax = occMax;
390 }
391 else
392 {
393 ymax = TMath::Max(ymax,occMax);
394 }
395
396 hbp.SetMaximum(ymax*1.4);
397
b71c3d2d 398 TPaveText* text = new TPaveText(0.30,0.50,0.99,0.99,"NDC");
ece56eb9 399
64c2397e 400 text->AddText(Form("MCH RUN %d - %d events",AliCDBManager::Instance()->GetRun(),nevents));
401
402 if ( ok < 0 )
ece56eb9 403 {
404 text->AddText("Could not compute truncated mean. Not enough events ?");
64c2397e 405 text->AddText(Form("nBusPatches=%d n=%d",nBusPatches,n));
ece56eb9 406 }
407 else if (!nPads || !nBusPatches)
408 {
64c2397e 409 text->AddText(Form("Could not get the total number of pads (%d) or total number of buspatches (%d). ERROR !!!",
410 nPads,nBusPatches));
ece56eb9 411 }
412 else
413 {
414 Float_t missingPadFraction = nMissingPads*100.0/nPads;
415 Float_t missingBusPatchFraction = nMissingBusPatches*100.0/nBusPatches;
416 Float_t aboveLimitFraction = nBusPatchesAboveLimit*100.0/nBusPatches;
417 Float_t belowLimitFraction = nBusPatchesBelowLimit*100.0/nBusPatches;
418
ece56eb9 419 text->AddText(Form("%5.2f %% of missing buspatches (%d out of %d)",missingBusPatchFraction,nMissingBusPatches,nBusPatches));
420 text->AddText(Form("%5.2f %% of missing pads (%d out of %d)",missingPadFraction,nMissingPads,nPads));
421 text->AddText(Form("%5.2f %% bus patches above the %5.2f %% limit",aboveLimitFraction,maxToleratedOccupancy));
422 text->AddText(Form("%5.2f %% bus patches below the %e %% limit",belowLimitFraction,minToleratedOccupancy));
b71c3d2d 423 text->AddText(Form("Bus patch mean occupancy (truncated at %2d %%) is %7.2f %%",(Int_t)(alpha*100),tmean));
ece56eb9 424
425 if ( missingPadFraction >= 100.0 )
426 {
427 rv = AliMUONVQAChecker::kFatal;
428 }
429
430 else if ( missingPadFraction > recoParam.MissingPadFractionLimit()*100.0 ||
431 aboveLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 ||
432 belowLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 )
433 {
434 rv = AliMUONVQAChecker::kError;
435 }
436 else
437 {
438 rv = AliMUONVQAChecker::kInfo;
439 }
440 }
441
442 hbp.GetListOfFunctions()->Add(text);
443
444 if ( rv == AliMUONVQAChecker::kInfo )
445 {
446 text->SetFillColor(3); // green = INFO
447 }
448 else if ( rv == AliMUONVQAChecker::kWarning )
449 {
450 text->SetFillColor(5); // yellow = WARNING
451 }
452 else if ( rv == AliMUONVQAChecker::kFatal)
453 {
454 text->SetFillColor(2); // red = FATAL
455 }
456 else
457 {
458 text->SetFillColor(6); // pink = ERROR
459 }
460
b71c3d2d 461 /// Make as well a version for DDL occupancy, that'll be used by the shifter
462
463 hddl.GetListOfFunctions()->Add(text->Clone());
464
465 Bool_t aboveOnePercent(kFALSE);
466 Bool_t aboveTwoPercent(kFALSE);
467
468 for ( Int_t i = 1; i <= hddl.GetXaxis()->GetNbins(); ++i )
469 {
470 Double_t b = hddl.GetBinContent(i);
471 if ( b > 1.0 ) aboveOnePercent = kTRUE;
472 if ( b > 2.0 ) aboveTwoPercent = kTRUE;
473
474 }
475
476 hddl.SetMaximum(2);
477 hddl.SetFillStyle(0);
478 if ( aboveOnePercent )
479 {
480 hddl.SetFillStyle(1001);
481 hddl.SetFillColor(kOrange);
482 }
483 if ( aboveTwoPercent )
484 {
485 hddl.SetFillStyle(1001);
486 hddl.SetFillColor(kRed);
487 }
488 hddl.SetLineWidth(3);
489 hddl.SetStats(kFALSE);
490
ece56eb9 491 return rv;
492}