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"
47 ClassImp(AliMUONTrackerQAChecker)
52 //___________________________________________________________________________
62 // Calculates the trimmed (tmean) mean
63 // of a sample (x) and estimates the variance (tvar)
67 // First check input parameters
69 // number of observations
75 if ( alpha < 0 || alpha >= 0.5 )
76 // proportion of observations
77 // to be trimmed at each end of the sorted sample
82 // Input parameters are good. Let's move on.
84 // Insure we use a sample sorted into ascending order.
86 Int_t* indices = new Int_t[n];
88 TMath::Sort(n,x,indices,kFALSE);
90 Double_t* sx = new Double_t[n];
92 for ( Int_t i = 0; i < n; ++i )
94 sx[i] = x[indices[i]];
99 // Number of observations trimmed at each end.
101 Int_t k = TMath::FloorNint(alpha * n);
105 for ( Int_t i = k; i < n - k ; ++i )
110 tmean = sum / ( n - 2 * k );
114 for ( Int_t i = k; i < n - k; ++i )
116 t2 += (sx[i] - tmean) * (sx[i] - tmean);
121 k * (sx[k] - tmean) * (sx[k] - tmean) +
122 k * (sx[n - k - 1] - tmean) * (sx[n - k - 1] - tmean)
125 // get the min and max for the non-rejected values
129 for ( Int_t i = k; i < n-k; ++i )
131 min = TMath::Min(min,sx[i]);
132 max = TMath::Max(max,sx[i]);
141 //__________________________________________________________________
142 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker() : AliMUONVQAChecker()
147 //__________________________________________________________________
148 AliMUONTrackerQAChecker::~AliMUONTrackerQAChecker()
153 //__________________________________________________________________
154 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker(const AliMUONTrackerQAChecker& qac) :
155 AliMUONVQAChecker(qac)
160 //______________________________________________________________________________
161 AliMUONVQAChecker::ECheckCode*
162 AliMUONTrackerQAChecker::CheckRecPoints(TObjArray ** list, AliMUONRecoParam* /*recoParam*/)
165 /// Very binary check for the moment.
167 AliCodeTimerAuto("",0);
169 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
170 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
171 rv[specie] = AliMUONVQAChecker::kInfo;
174 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
176 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNumberOfClustersPerDE,AliRecoParam::ConvertIndex(specie));
178 if ( !h ) rv[specie] = AliMUONVQAChecker::kWarning; // only a warning if histo not found, in order not to kill anything because QA failed...
180 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal);
185 //______________________________________________________________________________
186 AliMUONVQAChecker::ECheckCode
187 AliMUONTrackerQAChecker::MarkHisto(TH1& histo, AliMUONVQAChecker::ECheckCode value) const
189 /// Mark histo as originator of some QA error/warning
191 if ( value != AliMUONVQAChecker::kInfo )
193 histo.SetBit(AliQAv1::GetQABit());
199 //______________________________________________________________________________
200 AliMUONVQAChecker::ECheckCode*
201 AliMUONTrackerQAChecker::CheckESD(TObjArray ** list, AliMUONRecoParam* /*recoParam*/)
205 AliCodeTimerAuto("",0);
207 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
208 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
209 rv[specie] = AliMUONVQAChecker::kInfo;
211 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
213 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kESDnTracks,AliRecoParam::ConvertIndex(specie));
215 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
217 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal); // no track -> fatal
219 h = AliQAv1::GetData(list,AliMUONQAIndices::kESDMatchTrig,AliRecoParam::ConvertIndex(specie));
221 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
223 else if (h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kError); // no trigger matching -> error
228 //______________________________________________________________________________
229 AliMUONVQAChecker::ECheckCode*
230 AliMUONTrackerQAChecker::CheckRaws(TObjArray ** list, AliMUONRecoParam* recoParam)
234 AliCodeTimerAuto("",0);
236 if (!recoParam) return 0x0;
238 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
240 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
242 rv[specie] = AliMUONVQAChecker::kInfo;
245 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
247 TH1* hbp = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchOccupancy,AliRecoParam::ConvertIndex(specie));
249 TH1* hnpads = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchNofPads,AliRecoParam::ConvertIndex(specie));
251 TH1* hbpconfig = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchConfig,AliRecoParam::ConvertIndex(specie));
253 TH1* hnevents = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofRawEventSeen,AliRecoParam::ConvertIndex(specie));
255 if ( !hbp || !hnpads || !hnevents )
260 Int_t nevents = TMath::Nint(hnevents->GetBinContent(1));
262 rv[specie] = BeautifyTrackerBusPatchOccupancy(*hbp,hbpconfig,*hnpads,nevents,*recoParam);
268 //____________________________________________________________________________
269 AliMUONVQAChecker::ECheckCode
270 AliMUONTrackerQAChecker::BeautifyTrackerBusPatchOccupancy(TH1& hbp,
271 const TH1* hbuspatchconfig,
274 AliMUONRecoParam& recoParam)
276 /// Put labels, limits and so on on the TrackerBusPatchOccupancy histogram
277 /// hbuspatchconfig and hbp must have the same bin definitions
279 if ( hbuspatchconfig )
281 if ( hbp.GetNbinsX() != hbuspatchconfig->GetNbinsX() ||
282 hbp.GetXaxis()->GetXmin() != hbuspatchconfig->GetXaxis()->GetXmin() ||
283 hbp.GetXaxis()->GetXmax() != hbuspatchconfig->GetXaxis()->GetXmax() )
285 AliError("hbp and hbuspatchconfig histograms are not compatible !");
286 return AliMUONVQAChecker::kFatal;
290 hbp.SetXTitle("Absolute Bus Patch Id");
291 hbp.SetYTitle("Occupancy (percent)");
292 hbp.SetStats(kFALSE);
294 Double_t xmin = hbp.GetXaxis()->GetXmin();
295 Double_t xmax = hbp.GetXaxis()->GetXmax();
297 Double_t occMax(0.1); // 0.1% y-limit for the plot
298 Double_t maxToleratedOccupancy(recoParam.BuspatchOccupancyHighLimit()*100.0);
299 Double_t minToleratedOccupancy(recoParam.BuspatchOccupancyLowLimit()*100.0);
300 TLine* line1 = new TLine(xmin,maxToleratedOccupancy,xmax,maxToleratedOccupancy);
301 line1->SetLineColor(1);
302 line1->SetLineWidth(1);
304 TLine* line2 = new TLine(xmin,minToleratedOccupancy,xmax,minToleratedOccupancy);
305 line2->SetLineColor(1);
306 line2->SetLineWidth(1);
308 hbp.GetListOfFunctions()->Add(line1);
309 hbp.GetListOfFunctions()->Add(line2);
311 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
312 AliMpBusPatch* bp(0x0);
314 Int_t nMissingPads(0);
316 Int_t nBusPatches(0);
317 Int_t nMissingBusPatches(0);
319 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
321 Int_t bin = hbp.FindBin(bp->GetId());
322 Int_t n = TMath::Nint(hnpads.GetBinContent(bin));
328 if ( hbp.GetBinContent(bin) <= 0 )
331 ++nMissingBusPatches;
339 Int_t nBusPatchesAboveLimit(0);
340 Int_t nBusPatchesBelowLimit(0);
341 Double_t alpha(0.1); // trim 10% of data
342 Double_t tmean(0.0),tvar(0.0);
343 Double_t ymin(0.0),ymax(0.0);
344 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kFatal); // default value = serious problem
348 Double_t* x = new Double_t[nBusPatches];
350 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
352 Int_t bin = hbp.FindBin(bp->GetId());
353 if ( hbp.GetBinContent(bin) > 0 )
355 x[n] = hbp.GetBinContent(bin);
358 if ( hbp.GetBinContent(bin) > maxToleratedOccupancy )
360 ++nBusPatchesAboveLimit;
362 if ( hbp.GetBinContent(bin) < minToleratedOccupancy )
364 // check whether this buspatch has a reason to be absent (only valid
365 // if we got the config, otherwise we cannot do the test)
366 if ( hbuspatchconfig && hbuspatchconfig->GetBinContent(bin) > 0 )
368 // should be there, so it's an error
369 ++nBusPatchesBelowLimit;
374 // computed the truncated mean of the occupancy values, in order to get a
375 // reasonable y-range for the histogram (without giant peaks to the roof
376 // for misbehaving buspatches).
377 ok = trim(n,x,alpha,tmean,tvar,ymin,ymax);
388 ymax = TMath::Max(ymax,occMax);
391 hbp.SetMaximum(ymax*1.4);
393 TPaveText* text = new TPaveText(0.50,0.60,0.99,0.99,"NDC");
395 text->AddText(Form("MCH RUN %d - %d events",AliCDBManager::Instance()->GetRun(),nevents));
399 text->AddText("Could not compute truncated mean. Not enough events ?");
400 text->AddText(Form("nBusPatches=%d n=%d",nBusPatches,n));
402 else if (!nPads || !nBusPatches)
404 text->AddText(Form("Could not get the total number of pads (%d) or total number of buspatches (%d). ERROR !!!",
409 Float_t missingPadFraction = nMissingPads*100.0/nPads;
410 Float_t missingBusPatchFraction = nMissingBusPatches*100.0/nBusPatches;
411 Float_t aboveLimitFraction = nBusPatchesAboveLimit*100.0/nBusPatches;
412 Float_t belowLimitFraction = nBusPatchesBelowLimit*100.0/nBusPatches;
414 text->AddText(Form("%5.2f %% of missing buspatches (%d out of %d)",missingBusPatchFraction,nMissingBusPatches,nBusPatches));
415 text->AddText(Form("%5.2f %% of missing pads (%d out of %d)",missingPadFraction,nMissingPads,nPads));
416 text->AddText(Form("%5.2f %% bus patches above the %5.2f %% limit",aboveLimitFraction,maxToleratedOccupancy));
417 text->AddText(Form("%5.2f %% bus patches below the %e %% limit",belowLimitFraction,minToleratedOccupancy));
418 text->AddText(Form("Truncated mean at %2d %% is %7.2f %%",(Int_t)(alpha*100),tmean));
420 if ( missingPadFraction >= 100.0 )
422 rv = AliMUONVQAChecker::kFatal;
425 else if ( missingPadFraction > recoParam.MissingPadFractionLimit()*100.0 ||
426 aboveLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 ||
427 belowLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 )
429 rv = AliMUONVQAChecker::kError;
433 rv = AliMUONVQAChecker::kInfo;
437 hbp.GetListOfFunctions()->Add(text);
439 if ( rv == AliMUONVQAChecker::kInfo )
441 text->SetFillColor(3); // green = INFO
443 else if ( rv == AliMUONVQAChecker::kWarning )
445 text->SetFillColor(5); // yellow = WARNING
447 else if ( rv == AliMUONVQAChecker::kFatal)
449 text->SetFillColor(2); // red = FATAL
453 text->SetFillColor(6); // pink = ERROR