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"
37 #include "Riostream.h"
39 #include "TDirectory.h"
44 #include "TPaveText.h"
45 #include "TVirtualPad.h"
48 ClassImp(AliMUONTrackerQAChecker)
53 //___________________________________________________________________________
63 // Calculates the trimmed (tmean) mean
64 // of a sample (x) and estimates the variance (tvar)
68 // First check input parameters
70 // number of observations
76 if ( alpha < 0 || alpha >= 0.5 )
77 // proportion of observations
78 // to be trimmed at each end of the sorted sample
83 // Input parameters are good. Let's move on.
85 // Insure we use a sample sorted into ascending order.
87 Int_t* indices = new Int_t[n];
89 TMath::Sort(n,x,indices,kFALSE);
91 Double_t* sx = new Double_t[n];
93 for ( Int_t i = 0; i < n; ++i )
95 sx[i] = x[indices[i]];
100 // Number of observations trimmed at each end.
102 Int_t k = TMath::FloorNint(alpha * n);
106 for ( Int_t i = k; i < n - k ; ++i )
111 tmean = sum / ( n - 2 * k );
115 for ( Int_t i = k; i < n - k; ++i )
117 t2 += (sx[i] - tmean) * (sx[i] - tmean);
122 k * (sx[k] - tmean) * (sx[k] - tmean) +
123 k * (sx[n - k - 1] - tmean) * (sx[n - k - 1] - tmean)
126 // get the min and max for the non-rejected values
130 for ( Int_t i = k; i < n-k; ++i )
132 min = TMath::Min(min,sx[i]);
133 max = TMath::Max(max,sx[i]);
141 //___________________________________________________________________________
142 Int_t GetColorFromCheckCode(AliMUONVQAChecker::ECheckCode code)
144 if ( code == AliMUONVQAChecker::kInfo ) return AliMUONVQAChecker::kInfoColor;
145 else if ( code == AliMUONVQAChecker::kWarning ) return AliMUONVQAChecker::kWarningColor;
146 else if ( code == AliMUONVQAChecker::kFatal) return AliMUONVQAChecker::kFatalColor;
147 else return AliMUONVQAChecker::kErrorColor;
150 const char* NOTENOUGHEVENTMESSAGE = "Not enough event to judge. Please wait a bit";
151 const char* NOTIFYEXPERTMESSAGE = "PLEASE NOTIFY EXPERT !";
152 const char* ALLISFINEMESSAGE = "All is fine. Just enjoy.";
154 const int NOTENOUGHEVENTLIMIT = 50;
156 //___________________________________________________________________________
157 void SetupHisto(Int_t neventsseen, Int_t neventsused, const TObjArray& messages, TH1& histo, AliMUONVQAChecker::ECheckCode code, const char* extraopt="")
159 Bool_t allIsFine(kFALSE);
161 if ( code == AliMUONVQAChecker::kInfo )
166 Double_t y1 = 0.99 - (messages.GetLast()+(allIsFine?1:0)+2)*0.075;
168 TPaveText* text = new TPaveText(0.5,y1,0.99,0.99,"NDC");
170 text->AddText(Form("MCH RUN %d - %d events seen - %d events used",AliCDBManager::Instance()->GetRun(),neventsseen,neventsused));
172 TIter next(&messages);
175 while ( ( str = static_cast<TObjString*>(next()) ) )
177 text->AddText(str->String());
182 text->AddText(ALLISFINEMESSAGE);
185 text->SetFillColor(GetColorFromCheckCode(code));
187 Int_t color = GetColorFromCheckCode(code);
189 histo.SetFillStyle(1001);
190 histo.SetFillColor(color);
193 histo.SetOption(sopt.Data());
195 histo.SetTitle(kFALSE);
197 TObject* title = histo.GetListOfFunctions()->FindObject("title");
198 if (title) title->Delete();
200 histo.GetListOfFunctions()->Add(text);
205 //__________________________________________________________________
206 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker() : AliMUONVQAChecker()
211 //__________________________________________________________________
212 AliMUONTrackerQAChecker::~AliMUONTrackerQAChecker()
217 //__________________________________________________________________
218 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker(const AliMUONTrackerQAChecker& qac) :
219 AliMUONVQAChecker(qac)
224 //______________________________________________________________________________
225 AliMUONVQAChecker::ECheckCode*
226 AliMUONTrackerQAChecker::CheckRecPoints(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
229 /// Very binary check for the moment.
231 AliCodeTimerAuto("",0);
233 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
234 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
235 rv[specie] = AliMUONVQAChecker::kInfo;
238 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
240 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNumberOfClustersPerDE,AliRecoParam::ConvertIndex(specie));
242 if ( !h ) rv[specie] = AliMUONVQAChecker::kWarning; // only a warning if histo not found, in order not to kill anything because QA failed...
244 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal);
249 //______________________________________________________________________________
250 AliMUONVQAChecker::ECheckCode
251 AliMUONTrackerQAChecker::MarkHisto(TH1& histo, AliMUONVQAChecker::ECheckCode value) const
253 /// Mark histo as originator of some QA error/warning
255 if ( value != AliMUONVQAChecker::kInfo )
257 histo.SetBit(AliQAv1::GetQABit());
263 //______________________________________________________________________________
264 AliMUONVQAChecker::ECheckCode*
265 AliMUONTrackerQAChecker::CheckESD(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
269 AliCodeTimerAuto("",0);
271 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
272 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
273 rv[specie] = AliMUONVQAChecker::kInfo;
275 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
277 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kESDnTracks,AliRecoParam::ConvertIndex(specie));
279 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
281 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal); // no track -> fatal
283 h = AliQAv1::GetData(list,AliMUONQAIndices::kESDMatchTrig,AliRecoParam::ConvertIndex(specie));
285 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
287 else if (h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kError); // no trigger matching -> error
292 //______________________________________________________________________________
293 AliMUONVQAChecker::ECheckCode*
294 AliMUONTrackerQAChecker::CheckRaws(TObjArray ** list, const AliMUONRecoParam* recoParam)
298 AliCodeTimerAuto("",0);
300 if (!recoParam) return 0x0;
302 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
304 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
306 rv[specie] = AliMUONVQAChecker::kInfo;
309 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
311 TH1* hneventsseen = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofPhysicsEventsSeen,AliRecoParam::ConvertIndex(specie));
312 TH1* hneventsused = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed,AliRecoParam::ConvertIndex(specie));
314 if (!hneventsseen || !hneventsused ) continue;
316 Int_t neventsseen = TMath::Nint(hneventsseen->GetBinContent(1));
317 Int_t neventsused = TMath::Nint(hneventsused->GetBinContent(1));
319 if ( !hneventsseen || !hneventsused )
324 AliMUONVQAChecker::ECheckCode c1 = AliMUONVQAChecker::kInfo;
325 AliMUONVQAChecker::ECheckCode c2 = AliMUONVQAChecker::kInfo;
326 AliMUONVQAChecker::ECheckCode c3 = AliMUONVQAChecker::kInfo;
328 TH1* hbp = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchOccupancy,AliRecoParam::ConvertIndex(specie));
329 TH1* hbpconfig = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchConfig,AliRecoParam::ConvertIndex(specie));
330 TH1* hddl = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLOccupancy,AliRecoParam::ConvertIndex(specie));
332 if ( hbp && hbpconfig && hddl )
334 c1 = BeautifyOccupancyHistograms(*hddl,*hbp,hbpconfig,neventsseen,neventsused,*recoParam);
338 AliError(Form("Could not BeautifyOccupancyHistograms : hddl=%p hbpconfig=%p hbp=%p",hddl,hbpconfig,hbp));
341 TH1* hbuspatchtokenerrors = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchTokenLostErrors,AliRecoParam::ConvertIndex(specie));
342 TH1* hrostatus = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerReadoutStatus,AliRecoParam::ConvertIndex(specie));
343 TH1* hrostatusnorm = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerReadoutStatusPerEvent,AliRecoParam::ConvertIndex(specie));
345 if ( hrostatus && hrostatusnorm && hbuspatchtokenerrors )
347 c2 = BeautifyReadoutHistograms(*hrostatus,*hrostatusnorm,*hbuspatchtokenerrors,
348 neventsseen,neventsused,*recoParam);
352 AliError(Form("Could not BeautifyReadoutHistograms : hrostatus=%p hrostatusnorm=%p hbuspatchtokenerrors=%p",
353 hrostatus,hrostatusnorm,hbuspatchtokenerrors));
357 TH1* heventsize = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLEventSize,AliRecoParam::ConvertIndex(specie));
358 TH1* heventsizeperevent = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLEventSizePerEvent,AliRecoParam::ConvertIndex(specie));
360 if ( heventsize && heventsizeperevent )
362 c3 = BeautifyEventsizeHistograms(*heventsize,*heventsizeperevent,
363 neventsseen,neventsused,*recoParam);
367 AliError(Form("Could not BeautifyEventsizeHistograms heventsize=%p heventsizeperevent=%p",heventsize,heventsizeperevent));
370 if ( c1 == AliMUONVQAChecker::kFatal || c2 == AliMUONVQAChecker::kFatal || c3 == AliMUONVQAChecker::kFatal )
372 rv[specie] = AliMUONVQAChecker::kFatal;
374 else if ( c1 == AliMUONVQAChecker::kError || c2 == AliMUONVQAChecker::kError || c3 == AliMUONVQAChecker::kError )
376 rv[specie] = AliMUONVQAChecker::kError;
378 else if ( c1 == AliMUONVQAChecker::kWarning || c2 == AliMUONVQAChecker::kWarning || c3 == AliMUONVQAChecker::kWarning )
380 rv[specie] = AliMUONVQAChecker::kWarning;
384 rv[specie] = AliMUONVQAChecker::kInfo;
391 //____________________________________________________________________________
392 AliMUONVQAChecker::ECheckCode
393 AliMUONTrackerQAChecker::BeautifyOccupancyHistograms(TH1& hddl,
395 const TH1* hbuspatchconfig,
398 const AliMUONRecoParam& recoParam)
400 /// Put labels, limits and so on on the TrackerBusPatchOccupancy histograms
401 /// hbuspatchconfig and hbp must have the same bin definitions
403 if ( hbuspatchconfig )
405 if ( hbp.GetNbinsX() != hbuspatchconfig->GetNbinsX() ||
406 hbp.GetXaxis()->GetXmin() != hbuspatchconfig->GetXaxis()->GetXmin() ||
407 hbp.GetXaxis()->GetXmax() != hbuspatchconfig->GetXaxis()->GetXmax() )
409 AliError("hbp and hbuspatchconfig histograms are not compatible !");
410 return AliMUONVQAChecker::kFatal;
414 hddl.SetStats(kFALSE);
415 hbp.SetXTitle("Absolute Bus Patch Id");
416 hbp.SetYTitle("Occupancy (percent)");
417 hbp.SetStats(kFALSE);
419 Double_t xmin = hbp.GetXaxis()->GetXmin();
420 Double_t xmax = hbp.GetXaxis()->GetXmax();
422 Double_t occMax(0.1); // 0.1% y-limit for the plot
423 Double_t maxToleratedOccupancy(recoParam.BuspatchOccupancyHighLimit()*100.0);
424 Double_t minToleratedOccupancy(recoParam.BuspatchOccupancyLowLimit()*100.0);
425 TLine* line1 = new TLine(xmin,maxToleratedOccupancy,xmax,maxToleratedOccupancy);
426 line1->SetLineColor(1);
427 line1->SetLineWidth(1);
429 TLine* line2 = new TLine(xmin,minToleratedOccupancy,xmax,minToleratedOccupancy);
430 line2->SetLineColor(1);
431 line2->SetLineWidth(1);
433 hbp.GetListOfFunctions()->Delete();
435 hbp.GetListOfFunctions()->Add(line1);
436 hbp.GetListOfFunctions()->Add(line2);
438 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
439 AliMpBusPatch* bp(0x0);
441 Int_t nBusPatches(0);
442 Int_t nMissingBusPatches(0);
444 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
448 Int_t bin = hbp.FindBin(bp->GetId());
450 if ( hbp.GetBinContent(bin) <= 0.0 )
452 ++nMissingBusPatches;
460 Int_t nBusPatchesAboveLimit(0);
461 Int_t nBusPatchesBelowLimit(0);
462 Double_t alpha(0.1); // trim 10% of data
463 Double_t tmean(0.0),tvar(0.0);
464 Double_t ymin(0.0),ymax(0.0);
468 Double_t* x = new Double_t[nBusPatches];
470 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
472 Int_t bin = hbp.FindBin(bp->GetId());
473 if ( hbp.GetBinContent(bin) > 0 )
475 x[n] = hbp.GetBinContent(bin);
478 if ( hbp.GetBinContent(bin) > maxToleratedOccupancy )
480 ++nBusPatchesAboveLimit;
482 if ( hbp.GetBinContent(bin) < minToleratedOccupancy )
484 // check whether this buspatch has a reason to be absent (only valid
485 // if we got the config, otherwise we cannot do the test)
486 if ( hbuspatchconfig && hbuspatchconfig->GetBinContent(bin) > 0 )
488 // should be there, so it's an error
489 ++nBusPatchesBelowLimit;
494 // computed the truncated mean of the occupancy values, in order to get a
495 // reasonable y-range for the histogram (without giant peaks to the roof
496 // for misbehaving buspatches).
497 ok = trim(n,x,alpha,tmean,tvar,ymin,ymax);
508 ymax = TMath::Max(ymax,occMax);
511 hbp.SetMaximum(ymax*1.4);
513 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kInfo);
516 messages.SetOwner(kTRUE);
518 if ( neventsseen < NOTENOUGHEVENTLIMIT )
520 messages.Add(new TObjString(NOTENOUGHEVENTMESSAGE));
526 messages.Add(new TObjString("Could not compute truncated mean. Not enough events ?"));
528 if ( neventsused < TMath::Nint(0.1*neventsseen) )
530 messages.Add(new TObjString(Form("We've actually seen %d events, but used only %d !",neventsseen,neventsused)));
531 messages.Add(new TObjString("For a normal physics run, this is highly suspect !"));
532 messages.Add(new TObjString(NOTIFYEXPERTMESSAGE));
533 rv = AliMUONVQAChecker::kFatal;
536 else if (!nBusPatches)
538 messages.Add(new TObjString(Form("Could not get the total number of buspatches (%d). ERROR !!!",
540 messages.Add(new TObjString("Please check with expert !"));
541 rv = AliMUONVQAChecker::kFatal;
545 Float_t missingBusPatchFraction = nMissingBusPatches*100.0/nBusPatches;
546 Float_t aboveLimitFraction = nBusPatchesAboveLimit*100.0/nBusPatches;
547 Float_t belowLimitFraction = nBusPatchesBelowLimit*100.0/nBusPatches;
549 messages.Add(new TObjString(Form("%5.2f %% of missing buspatches (%d out of %d)",missingBusPatchFraction,nMissingBusPatches,nBusPatches)));
550 messages.Add(new TObjString(Form("%5.2f %% bus patches above the %5.2f %% limit",aboveLimitFraction,maxToleratedOccupancy)));
551 messages.Add(new TObjString(Form("%5.2f %% bus patches below the %e %% limit",belowLimitFraction,minToleratedOccupancy)));
552 messages.Add(new TObjString(Form("Bus patch mean occupancy (truncated at %2d %%) is %7.2f %%",(Int_t)(alpha*100),tmean)));
554 if ( aboveLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 ||
555 belowLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 )
557 rv = AliMUONVQAChecker::kError;
561 rv = AliMUONVQAChecker::kInfo;
566 SetupHisto(neventsseen,neventsused,messages,hbp,rv);
568 /// Make as well a version for DDL occupancy, that'll be used by the shifter
569 SetupHisto(neventsseen,neventsused,messages,hddl,rv);
572 hddl.SetStats(kFALSE);
577 //______________________________________________________________________________
578 AliMUONVQAChecker::ECheckCode
579 AliMUONTrackerQAChecker::BeautifyReadoutHistograms(TH1& hrostatus,
581 const TH1& hbuspatchtokenerrors,
584 const AliMUONRecoParam& recoParam)
586 /// Normalize and put some text on the readout error histogram
587 /// Note in particular the treatment of tokenlost errors !
589 hrostatusnorm.Reset();
591 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kInfo);
594 messages.SetOwner(kTRUE);
596 if ( neventsseen < NOTENOUGHEVENTLIMIT )
598 messages.Add(new TObjString(NOTENOUGHEVENTMESSAGE));
602 hrostatusnorm.Add(&hrostatus,100.0/neventsseen);
603 hrostatusnorm.SetOption("TEXT45"); // note : cannot use HIST option, otherwise the associated function (i.e. the tpavetext) is not drawn...
604 hrostatusnorm.SetMinimum(0.0);
606 Double_t tokenLost = hrostatusnorm.GetBinContent(hrostatusnorm.FindBin(1.0*AliMUONQAIndices::kTrackerRawNofTokenLostErrors));
608 if ( tokenLost > recoParam.TokenLostLimit() )
610 rv = AliMUONVQAChecker::kError;
612 messages.Add(new TObjString("There are some token lost errors !"));
613 messages.Add(new TObjString("PLEASE CHECK THE BUSY TIME FOR MUON !"));
614 messages.Add(new TObjString("If above 5 ms please have the MUON expert"));
615 messages.Add(new TObjString("check the following bus patches :"));
617 for ( Int_t i = 1; i <= hbuspatchtokenerrors.GetNbinsX(); ++i )
619 if ( hbuspatchtokenerrors.GetBinContent(i) > 0 )
621 messages.Add(new TObjString(Form("BP %4d",i)));
626 if ( hrostatusnorm.GetBinContent(hrostatusnorm.FindBin(AliMUONQAIndices::kTrackerRawNofEmptyEvents)) > 25.0 )
628 messages.Add(new TObjString("Too many empty events !"));
629 messages.Add(new TObjString(NOTIFYEXPERTMESSAGE));
630 rv = AliMUONVQAChecker::kFatal;
635 SetupHisto(neventsseen,neventsused,messages,hrostatusnorm,rv,"text45");
640 //______________________________________________________________________________
641 AliMUONVQAChecker::ECheckCode
642 AliMUONTrackerQAChecker::BeautifyEventsizeHistograms(TH1& heventsize,
643 TH1& heventsizeperevent,
646 const AliMUONRecoParam& recoParam)
648 /// Normalize and put some text on the event size histogram
650 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kInfo);
652 heventsizeperevent.Reset();
655 messages.SetOwner(kTRUE);
657 if ( neventsseen < NOTENOUGHEVENTLIMIT )
659 messages.Add(new TObjString(NOTENOUGHEVENTMESSAGE));
663 heventsizeperevent.Add(&heventsize,1.0/neventsseen/1024.0);
664 heventsizeperevent.SetMinimum(0);
666 Double_t totalEventSizePerEvent = heventsizeperevent.Integral();
671 if ( totalEventSizePerEvent > recoParam.EventSizeHardLimit() )
673 rv = AliMUONVQAChecker::kError;
674 msg = "That is really too high.";
675 action = NOTIFYEXPERTMESSAGE;
677 else if ( totalEventSizePerEvent > recoParam.EventSizeSoftLimit() )
679 msg = "That is a bit high.";
680 action = "Please keep an eye on it.";
681 rv = AliMUONVQAChecker::kWarning;
685 rv = AliMUONVQAChecker::kInfo;
688 messages.Add(new TObjString(Form("<MCH event size> %5.1f KB/event\n",totalEventSizePerEvent)));
691 messages.Add(new TObjString(msg));
692 messages.Add(new TObjString(action));
696 SetupHisto(neventsseen,neventsused,messages,heventsizeperevent,rv);