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 const Int_t INFOCOLOR(kGreen); // green = INFO
145 const Int_t WARNINGCOLOR(kYellow); // yellow = WARNING
146 const Int_t ERRORCOLOR(kOrange); // orange = ERROR
147 const Int_t FATALCOLOR(kRed); // red = FATAL
149 if ( code == AliMUONVQAChecker::kInfo ) return INFOCOLOR;
150 else if ( code == AliMUONVQAChecker::kWarning ) return WARNINGCOLOR;
151 else if ( code == AliMUONVQAChecker::kFatal) return FATALCOLOR;
152 else return ERRORCOLOR;
155 const char* NOTENOUGHEVENTMESSAGE = "Not enough event to judge. Please wait a bit";
156 const char* NOTIFYEXPERTMESSAGE = "PLEASE NOTIFY EXPERT !";
157 const char* ALLISFINEMESSAGE = "All is fine. Just enjoy.";
159 const int NOTENOUGHEVENTLIMIT = 50;
161 //___________________________________________________________________________
162 void SetupHisto(Int_t neventsseen, Int_t neventsused, const TObjArray& messages, TH1& histo, AliMUONVQAChecker::ECheckCode code, const char* extraopt="")
164 Bool_t allIsFine(kFALSE);
166 if ( code == AliMUONVQAChecker::kInfo )
171 Double_t y1 = 0.99 - (messages.GetLast()+(allIsFine?1:0)+2)*0.075;
173 TPaveText* text = new TPaveText(0.5,y1,0.99,0.99,"NDC");
175 text->AddText(Form("MCH RUN %d - %d events seen - %d events used",AliCDBManager::Instance()->GetRun(),neventsseen,neventsused));
177 TIter next(&messages);
180 while ( ( str = static_cast<TObjString*>(next()) ) )
182 text->AddText(str->String());
187 text->AddText(ALLISFINEMESSAGE);
190 text->SetFillColor(GetColorFromCheckCode(code));
192 Int_t color = GetColorFromCheckCode(code);
194 histo.SetFillStyle(1001);
195 histo.SetFillColor(color);
198 histo.SetOption(sopt.Data());
200 histo.SetTitle(kFALSE);
202 TObject* title = histo.GetListOfFunctions()->FindObject("title");
203 if (title) title->Delete();
205 histo.GetListOfFunctions()->Add(text);
210 //__________________________________________________________________
211 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker() : AliMUONVQAChecker()
216 //__________________________________________________________________
217 AliMUONTrackerQAChecker::~AliMUONTrackerQAChecker()
222 //__________________________________________________________________
223 AliMUONTrackerQAChecker::AliMUONTrackerQAChecker(const AliMUONTrackerQAChecker& qac) :
224 AliMUONVQAChecker(qac)
229 //______________________________________________________________________________
230 AliMUONVQAChecker::ECheckCode*
231 AliMUONTrackerQAChecker::CheckRecPoints(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
234 /// Very binary check for the moment.
236 AliCodeTimerAuto("",0);
238 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
239 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
240 rv[specie] = AliMUONVQAChecker::kInfo;
243 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
245 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNumberOfClustersPerDE,AliRecoParam::ConvertIndex(specie));
247 if ( !h ) rv[specie] = AliMUONVQAChecker::kWarning; // only a warning if histo not found, in order not to kill anything because QA failed...
249 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal);
254 //______________________________________________________________________________
255 AliMUONVQAChecker::ECheckCode
256 AliMUONTrackerQAChecker::MarkHisto(TH1& histo, AliMUONVQAChecker::ECheckCode value) const
258 /// Mark histo as originator of some QA error/warning
260 if ( value != AliMUONVQAChecker::kInfo )
262 histo.SetBit(AliQAv1::GetQABit());
268 //______________________________________________________________________________
269 AliMUONVQAChecker::ECheckCode*
270 AliMUONTrackerQAChecker::CheckESD(TObjArray ** list, const AliMUONRecoParam* /*recoParam*/)
274 AliCodeTimerAuto("",0);
276 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
277 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
278 rv[specie] = AliMUONVQAChecker::kInfo;
280 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
282 TH1* h = AliQAv1::GetData(list,AliMUONQAIndices::kESDnTracks,AliRecoParam::ConvertIndex(specie));
284 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
286 else if ( h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kFatal); // no track -> fatal
288 h = AliQAv1::GetData(list,AliMUONQAIndices::kESDMatchTrig,AliRecoParam::ConvertIndex(specie));
290 if (!h) rv[specie] = AliMUONVQAChecker::kWarning;
292 else if (h->GetMean() == 0.0 ) rv[specie] = MarkHisto(*h,AliMUONVQAChecker::kError); // no trigger matching -> error
297 //______________________________________________________________________________
298 AliMUONVQAChecker::ECheckCode*
299 AliMUONTrackerQAChecker::CheckRaws(TObjArray ** list, const AliMUONRecoParam* recoParam)
303 AliCodeTimerAuto("",0);
305 if (!recoParam) return 0x0;
307 AliMUONVQAChecker::ECheckCode * rv = new AliMUONVQAChecker::ECheckCode[AliRecoParam::kNSpecies] ;
309 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
311 rv[specie] = AliMUONVQAChecker::kInfo;
314 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++)
316 TH1* hneventsseen = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofPhysicsEventsSeen,AliRecoParam::ConvertIndex(specie));
317 TH1* hneventsused = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed,AliRecoParam::ConvertIndex(specie));
319 if (!hneventsseen || !hneventsused ) continue;
321 Int_t neventsseen = TMath::Nint(hneventsseen->GetBinContent(1));
322 Int_t neventsused = TMath::Nint(hneventsused->GetBinContent(1));
324 if ( !hneventsseen || !hneventsused )
329 AliMUONVQAChecker::ECheckCode c1 = AliMUONVQAChecker::kInfo;
330 AliMUONVQAChecker::ECheckCode c2 = AliMUONVQAChecker::kInfo;
331 AliMUONVQAChecker::ECheckCode c3 = AliMUONVQAChecker::kInfo;
333 TH1* hbp = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchOccupancy,AliRecoParam::ConvertIndex(specie));
334 TH1* hbpconfig = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchConfig,AliRecoParam::ConvertIndex(specie));
335 TH1* hddl = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLOccupancy,AliRecoParam::ConvertIndex(specie));
337 if ( hbp && hbpconfig && hddl )
339 c1 = BeautifyOccupancyHistograms(*hddl,*hbp,hbpconfig,neventsseen,neventsused,*recoParam);
343 AliError(Form("Could not BeautifyOccupancyHistograms : hddl=%p hbpconfig=%p hbp=%p",hddl,hbpconfig,hbp));
346 TH1* hbuspatchtokenerrors = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerBusPatchTokenLostErrors,AliRecoParam::ConvertIndex(specie));
347 TH1* hrostatus = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerReadoutStatus,AliRecoParam::ConvertIndex(specie));
348 TH1* hrostatusnorm = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerReadoutStatusPerEvent,AliRecoParam::ConvertIndex(specie));
350 if ( hrostatus && hrostatusnorm && hbuspatchtokenerrors )
352 c2 = BeautifyReadoutHistograms(*hrostatus,*hrostatusnorm,*hbuspatchtokenerrors,
353 neventsseen,neventsused,*recoParam);
357 AliError(Form("Could not BeautifyReadoutHistograms : hrostatus=%p hrostatusnorm=%p hbuspatchtokenerrors=%p",
358 hrostatus,hrostatusnorm,hbuspatchtokenerrors));
362 TH1* heventsize = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLEventSize,AliRecoParam::ConvertIndex(specie));
363 TH1* heventsizeperevent = AliQAv1::GetData(list,AliMUONQAIndices::kTrackerDDLEventSizePerEvent,AliRecoParam::ConvertIndex(specie));
365 if ( heventsize && heventsizeperevent )
367 c3 = BeautifyEventsizeHistograms(*heventsize,*heventsizeperevent,
368 neventsseen,neventsused,*recoParam);
372 AliError(Form("Could not BeautifyEventsizeHistograms heventsize=%p heventsizeperevent=%p",heventsize,heventsizeperevent));
375 if ( c1 == AliMUONVQAChecker::kFatal || c2 == AliMUONVQAChecker::kFatal || c3 == AliMUONVQAChecker::kFatal )
377 rv[specie] = AliMUONVQAChecker::kFatal;
379 else if ( c1 == AliMUONVQAChecker::kError || c2 == AliMUONVQAChecker::kError || c3 == AliMUONVQAChecker::kError )
381 rv[specie] = AliMUONVQAChecker::kError;
383 else if ( c1 == AliMUONVQAChecker::kWarning || c2 == AliMUONVQAChecker::kWarning || c3 == AliMUONVQAChecker::kWarning )
385 rv[specie] = AliMUONVQAChecker::kWarning;
389 rv[specie] = AliMUONVQAChecker::kInfo;
396 //____________________________________________________________________________
397 AliMUONVQAChecker::ECheckCode
398 AliMUONTrackerQAChecker::BeautifyOccupancyHistograms(TH1& hddl,
400 const TH1* hbuspatchconfig,
403 const AliMUONRecoParam& recoParam)
405 /// Put labels, limits and so on on the TrackerBusPatchOccupancy histograms
406 /// hbuspatchconfig and hbp must have the same bin definitions
408 if ( hbuspatchconfig )
410 if ( hbp.GetNbinsX() != hbuspatchconfig->GetNbinsX() ||
411 hbp.GetXaxis()->GetXmin() != hbuspatchconfig->GetXaxis()->GetXmin() ||
412 hbp.GetXaxis()->GetXmax() != hbuspatchconfig->GetXaxis()->GetXmax() )
414 AliError("hbp and hbuspatchconfig histograms are not compatible !");
415 return AliMUONVQAChecker::kFatal;
419 hddl.SetStats(kFALSE);
420 hbp.SetXTitle("Absolute Bus Patch Id");
421 hbp.SetYTitle("Occupancy (percent)");
422 hbp.SetStats(kFALSE);
424 Double_t xmin = hbp.GetXaxis()->GetXmin();
425 Double_t xmax = hbp.GetXaxis()->GetXmax();
427 Double_t occMax(0.1); // 0.1% y-limit for the plot
428 Double_t maxToleratedOccupancy(recoParam.BuspatchOccupancyHighLimit()*100.0);
429 Double_t minToleratedOccupancy(recoParam.BuspatchOccupancyLowLimit()*100.0);
430 TLine* line1 = new TLine(xmin,maxToleratedOccupancy,xmax,maxToleratedOccupancy);
431 line1->SetLineColor(1);
432 line1->SetLineWidth(1);
434 TLine* line2 = new TLine(xmin,minToleratedOccupancy,xmax,minToleratedOccupancy);
435 line2->SetLineColor(1);
436 line2->SetLineWidth(1);
438 hbp.GetListOfFunctions()->Add(line1);
439 hbp.GetListOfFunctions()->Add(line2);
441 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
442 AliMpBusPatch* bp(0x0);
444 Int_t nBusPatches(0);
445 Int_t nMissingBusPatches(0);
447 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
451 Int_t bin = hbp.FindBin(bp->GetId());
453 if ( hbp.GetBinContent(bin) <= 0.0 )
455 ++nMissingBusPatches;
463 Int_t nBusPatchesAboveLimit(0);
464 Int_t nBusPatchesBelowLimit(0);
465 Double_t alpha(0.1); // trim 10% of data
466 Double_t tmean(0.0),tvar(0.0);
467 Double_t ymin(0.0),ymax(0.0);
471 Double_t* x = new Double_t[nBusPatches];
473 while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
475 Int_t bin = hbp.FindBin(bp->GetId());
476 if ( hbp.GetBinContent(bin) > 0 )
478 x[n] = hbp.GetBinContent(bin);
481 if ( hbp.GetBinContent(bin) > maxToleratedOccupancy )
483 ++nBusPatchesAboveLimit;
485 if ( hbp.GetBinContent(bin) < minToleratedOccupancy )
487 // check whether this buspatch has a reason to be absent (only valid
488 // if we got the config, otherwise we cannot do the test)
489 if ( hbuspatchconfig && hbuspatchconfig->GetBinContent(bin) > 0 )
491 // should be there, so it's an error
492 ++nBusPatchesBelowLimit;
497 // computed the truncated mean of the occupancy values, in order to get a
498 // reasonable y-range for the histogram (without giant peaks to the roof
499 // for misbehaving buspatches).
500 ok = trim(n,x,alpha,tmean,tvar,ymin,ymax);
511 ymax = TMath::Max(ymax,occMax);
514 hbp.SetMaximum(ymax*1.4);
516 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kInfo);
519 messages.SetOwner(kTRUE);
521 if ( neventsseen < NOTENOUGHEVENTLIMIT )
523 messages.Add(new TObjString(NOTENOUGHEVENTMESSAGE));
529 messages.Add(new TObjString("Could not compute truncated mean. Not enough events ?"));
531 if ( neventsused < TMath::Nint(0.1*neventsseen) )
533 messages.Add(new TObjString(Form("We've actually seen %d events, but used only %d !",neventsseen,neventsused)));
534 messages.Add(new TObjString("For a normal physics run, this is highly suspect !"));
535 messages.Add(new TObjString(NOTIFYEXPERTMESSAGE));
536 rv = AliMUONVQAChecker::kFatal;
539 else if (!nBusPatches)
541 messages.Add(new TObjString(Form("Could not get the total number of buspatches (%d). ERROR !!!",
543 messages.Add(new TObjString("Please check with expert !"));
544 rv = AliMUONVQAChecker::kFatal;
548 Float_t missingBusPatchFraction = nMissingBusPatches*100.0/nBusPatches;
549 Float_t aboveLimitFraction = nBusPatchesAboveLimit*100.0/nBusPatches;
550 Float_t belowLimitFraction = nBusPatchesBelowLimit*100.0/nBusPatches;
552 messages.Add(new TObjString(Form("%5.2f %% of missing buspatches (%d out of %d)",missingBusPatchFraction,nMissingBusPatches,nBusPatches)));
553 messages.Add(new TObjString(Form("%5.2f %% bus patches above the %5.2f %% limit",aboveLimitFraction,maxToleratedOccupancy)));
554 messages.Add(new TObjString(Form("%5.2f %% bus patches below the %e %% limit",belowLimitFraction,minToleratedOccupancy)));
555 messages.Add(new TObjString(Form("Bus patch mean occupancy (truncated at %2d %%) is %7.2f %%",(Int_t)(alpha*100),tmean)));
557 if ( aboveLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 ||
558 belowLimitFraction > recoParam.FractionOfBuspatchOutsideOccupancyLimit()*100.0 )
560 rv = AliMUONVQAChecker::kError;
564 rv = AliMUONVQAChecker::kInfo;
569 SetupHisto(neventsseen,neventsused,messages,hbp,rv);
571 /// Make as well a version for DDL occupancy, that'll be used by the shifter
572 SetupHisto(neventsseen,neventsused,messages,hddl,rv);
575 hddl.SetStats(kFALSE);
580 //______________________________________________________________________________
581 AliMUONVQAChecker::ECheckCode
582 AliMUONTrackerQAChecker::BeautifyReadoutHistograms(TH1& hrostatus,
584 const TH1& hbuspatchtokenerrors,
587 const AliMUONRecoParam& recoParam)
589 /// Normalize and put some text on the readout error histogram
590 /// Note in particular the treatment of tokenlost errors !
592 hrostatusnorm.Reset();
594 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kInfo);
597 messages.SetOwner(kTRUE);
599 if ( neventsseen < NOTENOUGHEVENTLIMIT )
601 messages.Add(new TObjString(NOTENOUGHEVENTMESSAGE));
605 hrostatusnorm.Add(&hrostatus,100.0/neventsseen);
606 hrostatusnorm.SetOption("TEXT45"); // note : cannot use HIST option, otherwise the associated function (i.e. the tpavetext) is not drawn...
607 hrostatusnorm.SetMinimum(0.0);
609 Double_t tokenLost = hrostatusnorm.GetBinContent(hrostatusnorm.FindBin(1.0*AliMUONQAIndices::kTrackerRawNofTokenLostErrors));
611 if ( tokenLost > recoParam.TokenLostLimit() )
613 rv = AliMUONVQAChecker::kError;
615 messages.Add(new TObjString("There are some token lost errors !"));
616 messages.Add(new TObjString("PLEASE CHECK THE BUSY TIME FOR MUON !"));
617 messages.Add(new TObjString("If above 5 ms please have the MUON expert"));
618 messages.Add(new TObjString("check the following bus patches :"));
620 for ( Int_t i = 1; i <= hbuspatchtokenerrors.GetNbinsX(); ++i )
622 if ( hbuspatchtokenerrors.GetBinContent(i) > 0 )
624 messages.Add(new TObjString(Form("BP %4d",i)));
629 if ( hrostatusnorm.GetBinContent(hrostatusnorm.FindBin(AliMUONQAIndices::kTrackerRawNofEmptyEvents)) > 25.0 )
631 messages.Add(new TObjString("Too many empty events !"));
632 messages.Add(new TObjString(NOTIFYEXPERTMESSAGE));
633 rv = AliMUONVQAChecker::kFatal;
638 SetupHisto(neventsseen,neventsused,messages,hrostatusnorm,rv,"text45");
643 //______________________________________________________________________________
644 AliMUONVQAChecker::ECheckCode
645 AliMUONTrackerQAChecker::BeautifyEventsizeHistograms(TH1& heventsize,
646 TH1& heventsizeperevent,
649 const AliMUONRecoParam& recoParam)
651 /// Normalize and put some text on the event size histogram
653 AliMUONVQAChecker::ECheckCode rv(AliMUONVQAChecker::kInfo);
655 heventsizeperevent.Reset();
658 messages.SetOwner(kTRUE);
660 if ( neventsseen < NOTENOUGHEVENTLIMIT )
662 messages.Add(new TObjString(NOTENOUGHEVENTMESSAGE));
666 heventsizeperevent.Add(&heventsize,1.0/neventsseen/1024.0);
667 heventsizeperevent.SetMinimum(0);
669 Double_t totalEventSizePerEvent = heventsizeperevent.Integral();
674 if ( totalEventSizePerEvent > recoParam.EventSizeHardLimit() )
676 rv = AliMUONVQAChecker::kFatal;
677 msg = "That is really too high.";
678 action = NOTIFYEXPERTMESSAGE;
680 else if ( totalEventSizePerEvent > recoParam.EventSizeSoftLimit() )
682 msg = "That is a bit high.";
683 action = "Please keep an eye on it.";
684 rv = AliMUONVQAChecker::kError;
688 rv = AliMUONVQAChecker::kInfo;
691 messages.Add(new TObjString(Form("<MCH event size> %5.1f KB/event\n",totalEventSizePerEvent)));
694 messages.Add(new TObjString(msg));
695 messages.Add(new TObjString(action));
699 SetupHisto(neventsseen,neventsused,messages,heventsizeperevent,rv);