1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONTrackerQAChecker.h"
20 /// \class AliMUONTrackerQAChecker
22 /// Implementation of AliQACheckerBase for MCH and MTR
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.
27 /// \author Laurent Aphecetche, Subatech
29 #include "AliCDBManager.h"
30 #include "AliCodeTimer.h"
32 #include "AliMUONQAIndices.h"
33 #include "AliMUONRecoParam.h"
34 #include "AliMpBusPatch.h"
35 #include "AliMpDDLStore.h"
38 #include "Riostream.h"
40 #include "TDirectory.h"
44 #include "TPaveText.h"
46 #include "TVirtualPad.h"
49 ClassImp(AliMUONTrackerQAChecker)
54 //___________________________________________________________________________
64 // Calculates the trimmed (tmean) mean
65 // of a sample (x) and estimates the variance (tvar)
69 // First check input parameters
71 // number of observations
77 if ( alpha < 0 || alpha >= 0.5 )
78 // proportion of observations
79 // to be trimmed at each end of the sorted sample
84 // Input parameters are good. Let's move on.
86 // Insure we use a sample sorted into ascending order.
88 Int_t* indices = new Int_t[n];
90 TMath::Sort(n,x,indices,kFALSE);
92 Double_t* sx = new Double_t[n];
94 for ( Int_t i = 0; i < n; ++i )
96 sx[i] = x[indices[i]];
101 // Number of observations trimmed at each end.
103 Int_t k = TMath::FloorNint(alpha * n);
107 for ( Int_t i = k; i < n - k ; ++i )
112 tmean = sum / ( n - 2 * k );
116 for ( Int_t i = k; i < n - k; ++i )
118 t2 += (sx[i] - tmean) * (sx[i] - tmean);
123 k * (sx[k] - tmean) * (sx[k] - tmean) +
124 k * (sx[n - k - 1] - tmean) * (sx[n - k - 1] - tmean)
127 // get the min and max for the non-rejected values
131 for ( Int_t i = k; i < n-k; ++i )
133 min = TMath::Min(min,sx[i]);
134 max = TMath::Max(max,sx[i]);
143 //__________________________________________________________________
144 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker() : AliMUONVQAChecker()
149 //__________________________________________________________________
150 AliMUONTrackerQAChecker::~AliMUONTrackerQAChecker()
155 //__________________________________________________________________
156 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker(const AliMUONTrackerQAChecker& qac) :
157 AliMUONVQAChecker(qac)
162 //______________________________________________________________________________
163 AliMUONVQAChecker::ECheckCode*
164 AliMUONTrackerQAChecker::CheckRecPoints(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
167 /// Very binary check for the moment.
169 AliCodeTimerAuto("",0);
171 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
172 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
173 rv[specie] = AliMUONVQAChecker::kInfo;
176 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
178 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNumberOfClustersPerDE,AliRecoParam::ConvertIndex(specie));
180 if ( !h ) rv[specie] = AliMUONVQAChecker::kWarning; // only a warning if histo not found, in order not to kill anything because QA failed...
182 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal);
187 //______________________________________________________________________________
188 AliMUONVQAChecker::ECheckCode
189 AliMUONTrackerQAChecker::MarkHisto(TH1& histo, AliMUONVQAChecker::ECheckCode value) const
191 /// Mark histo as originator of some QA error/warning
193 if ( value != AliMUONVQAChecker::kInfo )
195 histo.SetBit(AliQAv1::GetQABit());
201 //______________________________________________________________________________
202 AliMUONVQAChecker::ECheckCode*
203 AliMUONTrackerQAChecker::CheckESD(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
207 AliCodeTimerAuto("",0);
209 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
210 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
211 rv[specie] = AliMUONVQAChecker::kInfo;
213 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
215 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kESDnTracks,AliRecoParam::ConvertIndex(specie));
217 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
219 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal); // no track -> fatal
221 h = AliQAv1::GetData(list,AliMUONQAIndices::kESDMatchTrig,AliRecoParam::ConvertIndex(specie));
223 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
225 else if (h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kError); // no trigger matching -> error
230 //______________________________________________________________________________
231 AliMUONVQAChecker::ECheckCode*
232 AliMUONTrackerQAChecker::CheckRaws(TObjArray ** list, const AliMUONRecoParam* recoParam)
236 AliCodeTimerAuto("",0);
238 if (!recoParam) return 0x0;
240 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
242 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
244 rv[specie] = AliMUONVQAChecker::kInfo;
247 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
249 TH1* hbp = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchOccupancy,AliRecoParam::ConvertIndex(specie));
251 TH1* hnpads = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchNofPads,AliRecoParam::ConvertIndex(specie));
253 TH1* hbpconfig = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchConfig,AliRecoParam::ConvertIndex(specie));
255 TH1* hnevents = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofRawEventSeen,AliRecoParam::ConvertIndex(specie));
257 TH1* hddl = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLOccupancy,AliRecoParam::ConvertIndex(specie));
259 if ( !hbp || !hnpads || !hnevents || !hddl )
264 Int_t nevents = TMath::Nint(hnevents->GetBinContent(1));
266 rv[specie] = BeautifyTrackerBusPatchOccupancy(*hddl,*hbp,hbpconfig,*hnpads,nevents,*recoParam);
272 //____________________________________________________________________________
273 AliMUONVQAChecker::ECheckCode
274 AliMUONTrackerQAChecker::BeautifyTrackerBusPatchOccupancy(TH1& hddl,
276 const TH1* hbuspatchconfig,
279 const AliMUONRecoParam& recoParam)
281 /// Put labels, limits and so on on the TrackerBusPatchOccupancy histogram
282 /// hbuspatchconfig and hbp must have the same bin definitions
284 if ( hbuspatchconfig )
286 if ( hbp.GetNbinsX() != hbuspatchconfig->GetNbinsX() ||
287 hbp.GetXaxis()->GetXmin() != hbuspatchconfig->GetXaxis()->GetXmin() ||
288 hbp.GetXaxis()->GetXmax() != hbuspatchconfig->GetXaxis()->GetXmax() )
290 AliError("hbp and hbuspatchconfig histograms are not compatible !");
291 return AliMUONVQAChecker::kFatal;
295 hbp.SetXTitle("Absolute Bus Patch Id");
296 hbp.SetYTitle("Occupancy (percent)");
297 hbp.SetStats(kFALSE);
299 Double_t xmin = hbp.GetXaxis()->GetXmin();
300 Double_t xmax = hbp.GetXaxis()->GetXmax();
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);
309 TLine* line2 = new TLine(xmin,minToleratedOccupancy,xmax,minToleratedOccupancy);
310 line2->SetLineColor(1);
311 line2->SetLineWidth(1);
313 hbp.GetListOfFunctions()->Add(line1);
314 hbp.GetListOfFunctions()->Add(line2);
316 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
317 AliMpBusPatch* bp(0x0);
319 Int_t nMissingPads(0);
321 Int_t nBusPatches(0);
322 Int_t nMissingBusPatches(0);
324 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
326 Int_t bin = hbp.FindBin(bp->GetId());
327 Int_t n = TMath::Nint(hnpads.GetBinContent(bin));
333 if ( hbp.GetBinContent(bin) <= 0 )
336 ++nMissingBusPatches;
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
353 Double_t* x = new Double_t[nBusPatches];
355 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
357 Int_t bin = hbp.FindBin(bp->GetId());
358 if ( hbp.GetBinContent(bin) > 0 )
360 x[n] = hbp.GetBinContent(bin);
363 if ( hbp.GetBinContent(bin) > maxToleratedOccupancy )
365 ++nBusPatchesAboveLimit;
367 if ( hbp.GetBinContent(bin) < minToleratedOccupancy )
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 )
373 // should be there, so it's an error
374 ++nBusPatchesBelowLimit;
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);
393 ymax = TMath::Max(ymax,occMax);
396 hbp.SetMaximum(ymax*1.4);
398 TPaveText* text = new TPaveText(0.30,0.50,0.99,0.99,"NDC");
400 text->AddText(Form("MCH RUN %d - %d events",AliCDBManager::Instance()->GetRun(),nevents));
404 text->AddText("Could not compute truncated mean. Not enough events ?");
405 text->AddText(Form("nBusPatches=%d n=%d",nBusPatches,n));
407 else if (!nPads || !nBusPatches)
409 text->AddText(Form("Could not get the total number of pads (%d) or total number of buspatches (%d). ERROR !!!",
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;
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));
423 text->AddText(Form("Bus patch mean occupancy (truncated at %2d %%) is %7.2f %%",(Int_t)(alpha*100),tmean));
425 if ( missingPadFraction >= 100.0 )
427 rv = AliMUONVQAChecker::kFatal;
430 else if ( missingPadFraction > recoParam.MissingPadFractionLimit()*100.0 ||
431 aboveLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 ||
432 belowLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 )
434 rv = AliMUONVQAChecker::kError;
438 rv = AliMUONVQAChecker::kInfo;
442 hbp.GetListOfFunctions()->Add(text);
444 if ( rv == AliMUONVQAChecker::kInfo )
446 text->SetFillColor(3); // green = INFO
448 else if ( rv == AliMUONVQAChecker::kWarning )
450 text->SetFillColor(5); // yellow = WARNING
452 else if ( rv == AliMUONVQAChecker::kFatal)
454 text->SetFillColor(2); // red = FATAL
458 text->SetFillColor(6); // pink = ERROR
461 /// Make as well a version for DDL occupancy, that'll be used by the shifter
463 hddl.GetListOfFunctions()->Add(text->Clone());
465 Bool_t aboveOnePercent(kFALSE);
466 Bool_t aboveTwoPercent(kFALSE);
468 for ( Int_t i = 1; i <= hddl.GetXaxis()->GetNbins(); ++i )
470 Double_t b = hddl.GetBinContent(i);
471 if ( b > 1.0 ) aboveOnePercent = kTRUE;
472 if ( b > 2.0 ) aboveTwoPercent = kTRUE;
477 hddl.SetFillStyle(0);
478 if ( aboveOnePercent )
480 hddl.SetFillStyle(1001);
481 hddl.SetFillColor(kOrange);
483 if ( aboveTwoPercent )
485 hddl.SetFillStyle(1001);
486 hddl.SetFillColor(kRed);
488 hddl.SetLineWidth(3);
489 hddl.SetStats(kFALSE);