2 #if !defined(__CINT__) || defined(__MAKECINT__)
7 #include "TGraphAsymmErrors.h"
15 #include "TObjArray.h"
17 #include "TObjString.h"
23 #include "TGridResult.h"
26 #include "AliCDBManager.h"
27 #include "AliCDBEntry.h"
28 #include "AliCDBPath.h"
29 #include "AliCDBStorage.h"
30 #include "AliMUONTriggerEfficiencyCells.h"
31 #include "AliMUONTriggerChamberEfficiency.h"
32 #include "AliMUONTriggerUtilities.h"
33 #include "AliMUONDigitMaker.h"
34 #include "AliMUONVDigit.h"
35 #include "AliMUONDigitStoreV2R.h"
36 #include "AliMUONCalibrationData.h"
37 #include "AliAnalysisTriggerScalers.h"
38 #include "AliCounterCollection.h"
39 #include "AliTriggerConfiguration.h"
49 gStyle->SetCanvasColor(10);
50 gStyle->SetFrameFillColor(10);
51 gStyle->SetStatColor(10);
52 gStyle->SetFillColor(10);
53 gStyle->SetTitleFillColor(10);
55 gStyle->SetTitleXSize(0.03);
56 gStyle->SetTitleXOffset(1.1);
57 gStyle->SetTitleYSize(0.03);
58 gStyle->SetTitleYOffset(1.9);
60 gStyle->SetMarkerSize(0.7);
61 gStyle->SetHistLineWidth(2);
63 gStyle->SetPadLeftMargin(0.12);
64 gStyle->SetPadRightMargin(0.04);
65 gStyle->SetPadBottomMargin(0.08);
66 gStyle->SetPadTopMargin(0.08);
74 return ( stringToken.IsDigit() && stringToken.Length()>=6 && stringToken.Length()<=9 );
83 TAxis* axis = histo->GetXaxis();
84 if ( runAxis ==
"Y" ) axis = histo->GetYaxis();
85 else if ( runAxis ==
"Z" ) axis = histo->GetZaxis();
86 histo->LabelsOption(
"v",runAxis.Data());
87 axis->SetLabelSize(0.02);
88 for (
Int_t ibin=1; ibin<=axis->GetNbins(); ibin++ ) {
89 TString binLabel = axis->GetBinLabel(ibin);
90 if ( ! binLabel.IsNull())
continue;
91 axis->SetRange(1, ibin-1);
100 TObjArray* array = filePath.Tokenize(
"/");
104 for (
Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
105 auxString = array->At(ientry)->GetName();
107 runNum = auxString.Atoi();
114 array = auxString.Tokenize(
"_");
116 auxString = array->Last()->GetName();
117 auxString.ReplaceAll(
".root",
"");
118 if (
IsRunNum(auxString) ) runNum = auxString.Atoi();
135 outArray->SetOwner();
136 TString newBaseName =
"trigChEff_ANY_Apt_allTrig.root";
137 for (
Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
138 TObjString* currObjString =
static_cast<TObjString*
>(fileNameArray.At(ifile));
139 TString currFile = currObjString->GetString();
146 newFilename = currFile;
147 newFilename.ReplaceAll(baseName.Data(),newBaseName.Data());
152 newFilename = Form(
"%s/terminateRuns/%i/%s",dirName.Data(),runNum,newBaseName.Data());
154 if (
gSystem->AccessPathName(newFilename.Data()) ) {
155 printf(
"New output not found in %s.\n", currFile.Data());
160 outArray->AddAt(
new TObjString(newFilename),ifile);
163 if ( outArray ) printf(
"Using re-built output in %s\n",newBaseName.Data());
165 outArray =
static_cast<TObjArray*
>(fileNameArray.Clone());
166 printf(
"Using default output\n");
176 Double_t relErr = 0., relProdErrSquare = 0.;
177 for (
Int_t iprod=0; iprod<nFactors; iprod++ ) {
178 if ( iprod == exclude )
continue;
179 prod *= effErr[iprod];
180 relErr = ( effErr[iprod] >
kZero ) ? effErr[iprod+nFactors]/effErr[iprod] : 0.;
181 relProdErrSquare += relErr*relErr;
186 prodErr[1] = prod*TMath::Sqrt(relProdErrSquare);
198 if ( ich == exclude ) {
199 effErr[ich] = ( effErr1[ich] < 1. ) ? ( effErr2[ich] - effErrBoth[ich] ) / ( 1. - effErr1[ich] ) : 0.;
200 effErr[ich+
kNch] = 0;
201 if ( effErr1[ich] < 1. ) {
202 Double_t err2 = effErr2[ich+
kNch] / ( 1. - effErr1[ich] );
203 Double_t errBoth = effErrBoth[ich+
kNch] / ( 1. - effErr1[ich] );
204 Double_t err1 = effErr1[ich+
kNch] * effErr[ich] / ( 1. - effErr1[ich] );
205 effErr[ich+
kNch] = TMath::Sqrt(err2*err2 + errBoth*errBoth + err1*err1);
209 effErr[ich] = ( effErr1[ich] >
kZero ) ? effErrBoth[ich]/effErr1[ich] : 0.;
210 Double_t relErr1 = ( effErr1[ich] >
kZero ) ? effErr1[ich+kNch]/effErr1[ich] : 0.;
211 Double_t relErrBoth = ( effErrBoth[ich] >
kZero ) ? effErrBoth[ich+kNch]/effErrBoth[ich] : 0.;
212 effErr[ich+
kNch] = effErr[ich] * TMath::Sqrt(relErr1*relErr1 + relErrBoth*relErrBoth);
225 Double_t defaultEffErr[2] = {1.,0.};
229 effErrBinomial[0] = 0.;
230 effErrBinomial[1] = 0.;
232 for (
Int_t ich = -1; ich<
kNch; ich++ ) {
235 currEffErr[0] = currEffErr[0] - currEffErr44[0];
236 currEffErr[1] = TMath::Sqrt(currEffErr[1]*currEffErr[1] + currEffErr44[1]*currEffErr44[1]);
243 for (
Int_t ival=0; ival<2; ival++ ) {
244 effProd[2*ival] = currEffErr[ival];
245 effProd[2*ival+1] = ( effErr2 ) ? auxBinomial[ival] : defaultEffErr[ival];
247 if ( ich < 0 ) currEffErr44 = currEffErr;
248 else delete [] currEffErr;
249 delete [] auxBinomial;
253 effErrBinomial[0] += effErr[0];
254 effErrBinomial[1] += effErr[1]*effErr[1];
258 delete [] currEffErr44;
260 effErrBinomial[1] = TMath::Sqrt(effErrBinomial[1]);
262 return effErrBinomial;
272 histo = (
TH1*)histoList->FindObject(histoName.Data());
274 histo = (
TH1*)file->FindObjectAny(histoName.Data());
283 if ( iel == 0 )
return icount;
284 return 3 + 4*3*(iel-1) + 3*ich + icount;
295 if ( runNum >= 0 ) AliCDBManager::Instance()->SetRun(runNum);
296 TList*
list = AliCDBManager::Instance()->GetAll(cdbDir.Data());
297 if ( list->GetEntries() == 0 ) {
298 printf(
"Warning: no entry found in %s for run %i\n",cdbDir.Data(),runNum);
308 TString storageType = AliCDBManager::Instance()->GetDefaultStorage()->GetType();
309 Bool_t isGrid = storageType.Contains(
"alien");
310 TString baseFolder = AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder();
314 TObjArray* dirNameList = ocdbDirs.Tokenize(
",");
315 for (
Int_t idir=0; idir<dirNameList->GetEntries(); idir++ ) {
316 TString fullPath = Form(
"%s/%s",baseFolder.Data(),dirNameList->At(idir)->GetName());
318 TGridResult *res = gGrid->Ls(fullPath.Data());
319 if (!res)
return 0x0;
320 for (
Int_t ires=0; ires<res->GetEntries(); ires++ ) {
321 TString currFile =
static_cast<TMap*
>(res->At(ires))->GetValue(
"name")->GetName();
322 outList->Add(
new TObjString(currFile));
327 TString fileListStr =
gSystem->GetFromPipe(Form(
"ls %s",fullPath.Data()));
328 TObjArray* fileList = fileListStr.Tokenize(
"\n");
329 for (
Int_t ires=0; ires<fileList->GetEntries(); ires++ ) {
330 TString currFile = fileList->At(ires)->GetName();
331 outList->Add(
new TObjString(currFile));
344 if ( defaultStorage.IsNull() ) {
345 printf(
"Default storage not specified. Nothing done\n");
349 if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
350 printf(
"Default storage already set: nothing done\n");
354 if ( defaultStorage.Contains(
"alien://") || defaultStorage.Contains(
"raw://") ) {
355 if ( ! gGrid ) TGrid::Connect(
"alien://");
357 printf(
"Error: Problem connetting to grid: default storage not set\n");
362 AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
364 if ( defaultStorage.Contains(
"raw://") )
return kTRUE;
368 if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
369 TString searchDir =
"MUON/Calib/MappingData";
370 TString fullPath = Form(
"%s/%s",defaultStorage.Data(),searchDir.Data());
372 if ( ocdbList->GetEntries() == 0 ) {
373 printf(
"No entries in %s\n",fullPath.Data());
377 TString checkFile = Form(
"%s/%s",fullPath.Data(),ocdbList->At(0)->GetName());
378 checkFile.ReplaceAll(
"local://",
"");
379 checkFile.ReplaceAll(
"folder=",
"");
380 checkFile.ReplaceAll(
"Folder=",
"");
381 TFile*
file = TFile::Open(checkFile.Data());
383 printf(
"Cannot access test file: %s\n", checkFile.Data());
391 printf(
"Tried to set the default storage, but something went wrong.\n");
395 if ( ! isOk ) printf(
"Please check path %s\n",defaultStorage.Data());
404 if ( ! fileList )
return kTRUE;
405 for (
Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
406 TString filename =
static_cast<TObjString*
>(fileList->At(ifile))->GetString();
407 filename.ReplaceAll(
"Run",
"");
408 TObjArray* array = filename.Tokenize(
"_");
409 Int_t firstRun =
static_cast<TObjString*
>(array->At(0))->GetString().Atoi();
410 Int_t lastRun =
static_cast<TObjString*
>(array->At(1))->GetString().Atoi();
412 Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
413 Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
414 if ( isCurrRunInside != isPreviousRunInside )
return kTRUE;
422 TH2* outHisto =
static_cast<TH2*
>(histo->Clone());
423 outHisto->SetName(Form(
"%s_outlier",histo->GetName()));
425 for (
Int_t ybin=1; ybin<=histo->GetYaxis()->GetNbins(); ybin++ ) {
426 TH1* auxHisto = histo->ProjectionX(
"projectionOutlier",ybin,ybin);
427 if ( auxHisto->Integral() == 0. )
continue;
428 auxHisto->Fit(
"pol0",
"Q0");
429 Double_t mean = auxHisto->GetFunction(
"pol0")->GetParameter(0);
430 for (
Int_t xbin=1; xbin<=auxHisto->GetXaxis()->GetNbins(); xbin++ ) {
431 Double_t err = auxHisto->GetBinError(xbin);
432 if ( err == 0. )
continue;
433 if ( TMath::Abs(auxHisto->GetBinContent(xbin)-mean)/err < nSigmas )
continue;
434 outHisto->SetBinContent(xbin,ybin,auxHisto->GetBinContent(xbin)-mean);
445 TString elementName[3] = {
"Chamber",
"RPC",
"Board" };
446 TString countTypeName[4] = {
"allTracks",
"bendPlane",
"nonBendPlane",
"bothPlanes" };
455 const Int_t kNeffVsRun = kNgraphs+1;
458 effName =
"totalEffEvolution";
459 effTitle =
"Multinomial probability of firing at least 3/4 chambers";
460 TH1D* totalEff =
new TH1D(effName.Data(), effTitle.Data(), 1, 0., 1.);
461 effVsRunList.AddAt(totalEff, kNeffVsRun-1);
464 for (
Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
466 runNumString = runNumArray.At(irun)->GetName();
469 for (
Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
470 filename = fileNameArray.At(ifile)->GetName();
471 if ( filename.Contains(runNumString.Data()) )
break;
474 if ( filename.Contains(
"alien://") && ! gGrid ) gGrid->Connect(
"alien://");
481 TFile*
file = TFile::Open(filename.Data());
483 printf(
"Warning: cannot find %s\n", filename.Data());
487 TList* trigEffList = (
TList*)file->FindObjectAny(
"triggerChamberEff");
488 if ( ! trigEffList ) {
489 printf(
"Warning: histo list not found in %s.\n", filename.Data());
492 if ( trigEffList->GetEntries() == 0 ) {
493 printf(
"Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
498 for (
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
499 effName = countTypeName[icount] +
"Count" + elementName[0];
501 histoDen =
GetHisto(effName, file, trigEffList);
505 TH1* histoNum =
GetHisto(effName, file, trigEffList);
507 effName.ReplaceAll(
"Count",
"Eff");
508 graph->SetName(effName.Data());
514 printf(
"Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
519 AliMUONTriggerChamberEfficiency trigChEff(filename);
520 for (
Int_t iel=1; iel<3; iel++ ) {
522 for (
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
523 TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
524 effList.AddAt(obj->Clone(Form(
"%s_cloned",obj->GetName())),
GetEffIndex(iel, icount, ich));
530 for (
Int_t iel=0; iel<3; iel++ ) {
532 for (
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
534 Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
535 for (
Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
536 Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
538 graph->GetPoint(currPoint, xpt, ypt);
539 effValues[icount][ich] = ypt;
541 TH2* effHisto =
static_cast<TH2*
>(effVsRunList.At(ihisto));
543 effName = Form(
"effEvolution%s%s", countTypeName[icount+1].
Data(), elementName[iel].
Data());
544 effTitle = Form(
"Trigger chamber efficiency vs run");
546 effName += Form(
"Ch%i", 11+ich);
547 effTitle += Form(
" for chamber %i", 11+ich);
549 effHisto =
new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(
Double_t)graph->GetN());
550 effVsRunList.AddAt(effHisto, ihisto);
552 Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
553 Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
554 Int_t binx, biny, binz;
555 effHisto->GetBinXYZ(currBin, binx, biny, binz);
556 effHisto->SetBinError(binx, biny, err);
557 effValues[icount][ich+
kNch] = err;
561 if ( iel > 0 )
continue;
563 Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
568 totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
569 delete [] binomialEff;
574 for (
Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
575 TH1* histo =
static_cast<TH1*
>(effVsRunList.At(ihisto));
576 if ( ! histo )
continue;
583 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
584 TH1* totEff = (
TH1*)effVsRunList.At(kNeffVsRun-1);
585 totEff->GetYaxis()->SetRangeUser(0.9,1.05);
586 totEff->GetYaxis()->SetTitle(
"Probability to satisfy trigger conditions (3/4)");
587 totEff->SetStats(kFALSE);
592 Int_t markStyle[3] = {20, 24, 26};
596 canName = Form(
"trigEffCh%i", 11+ich);
597 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
599 leg =
new TLegend(0.7, 0.8, 0.96, 0.92);
600 leg->SetBorderSize(1);
603 for(
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
606 if ( ! histo )
continue;
607 TH1* chEff = histo->ProjectionX(Form(
"effEvolutionCh%i",11+ich), ich+1, ich+1);
608 chEff->SetTitle(Form(
"%s for chamber %i", histo->GetTitle(), 11+ich));
609 chEff->GetYaxis()->SetRangeUser(0.9,1.02);
610 chEff->SetStats(kFALSE);
611 chEff->GetYaxis()->SetTitle(
"Trigger chamber efficiency");
612 TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
613 copyEff->SetLineColor(color[icount]);
614 copyEff->SetMarkerColor(color[icount]);
615 copyEff->SetMarkerStyle(markStyle[icount]);
616 leg->AddEntry(copyEff, countTypeName[icount+1].
Data(),
"lp");
623 for (
Int_t iel=1; iel<3; iel++ ) {
625 Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff;
627 canName = Form(
"trigEff%sCh%i", elementName[iel].
Data(), 11+ich);
628 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
629 can->SetRightMargin(0.14);
631 if ( ! histo )
continue;
632 histo->SetStats(kFALSE);
633 histo->GetYaxis()->SetTitle(elementName[iel].
Data());
635 if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
636 histo->DrawCopy(
"COLZ");
645 Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff;
648 canName = Form(
"trigEff%sCh%i_outliers", elementName[iel].
Data(), 11+ich);
649 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
650 can->SetRightMargin(0.14);
652 if ( ! histo || histo->Integral() == 0. )
continue;
654 TString histoTitle = histo->GetTitle();
655 histoTitle.ReplaceAll(
"efficiency",
"eff.-<eff.> for outliers");
656 outHisto->SetTitle(histoTitle.Data());
657 outList.Add(outHisto);
658 outHisto->SetMinimum(-0.08);
659 outHisto->SetMaximum(0.08);
660 outHisto->DrawCopy(
"COLZ");
676 TString histoName =
"", histoTitle =
"";
677 for(
Int_t icath=0; icath<2; icath++){
678 TString cathName = ( icath==0 ) ?
"bendPlane" :
"nonBendPlane";
680 histoName = Form(
"%sMaskCh%i", cathName.Data(), 11+ich);
681 histoTitle = Form(
"Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
682 TH2* histo =
new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
683 histo->GetYaxis()->SetTitle(
"Board Id");
685 Int_t imask = 2*ich + icath;
686 maskedList.AddAt(histo, imask);
687 auxList.AddAt(histo->Clone(Form(
"%s_aux",histoName.Data())), imask);
691 TArrayS xyPatternAll[2];
692 for(
Int_t icath=0; icath<2; icath++){
693 xyPatternAll[icath].Set(
kNch);
694 xyPatternAll[icath].Reset(0xFFFF);
697 TList* ocdbFileList = 0x0;
698 Int_t previousRun = -1;
699 AliMUONDigitMaker* digitMaker = 0x0;
700 AliMUONDigitStoreV2R digitStore;
702 AliMUONCalibrationData* calibData = 0x0;
703 AliMUONTriggerUtilities* trigUtilities = 0x0;
704 for (
Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
705 TString runNumString = runNumArray.At(irun)->GetName();
706 Int_t runNumber = runNumString.Atoi();
709 AliCDBManager::Instance()->SetRun(runNumber);
711 if ( ! digitMaker ) {
712 digitMaker =
new AliMUONDigitMaker(kFALSE);
714 for (
Int_t iboard=1; iboard<=234; iboard++ ) {
715 digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
719 if ( ! ocdbFileList ) ocdbFileList =
GetOCDBList(
"MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
722 calibData =
new AliMUONCalibrationData (runNumber);
723 delete trigUtilities;
724 trigUtilities =
new AliMUONTriggerUtilities (calibData);
727 previousRun = runNumber;
729 TIter next(digitStore.CreateIterator());
730 AliMUONVDigit* dig = 0x0;
731 while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
732 Int_t icath = dig->Cathode();
733 Int_t detElemId = dig->DetElemId();
734 Int_t ich = detElemId/100-11;
735 Int_t iboard = dig->ManuId();
736 Int_t imask = 2*ich + icath;
737 static_cast<TH2*
>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
738 static_cast<TH2*
>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(
Double_t)trigUtilities->IsMasked(*dig));
742 delete trigUtilities;
746 for (
Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
747 TH2* histo =
static_cast<TH2*
>(maskedList.At(imask));
748 histo->Divide(static_cast<TH2*>(auxList.At(imask)));
752 canName = Form(
"%sCan", histo->GetName());
753 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
754 can->SetRightMargin(0.14);
755 histo->SetStats(kFALSE);
756 if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
757 histo->DrawCopy(
"COLZ");
766 for (
Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
767 if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) )
return kFALSE;
770 for (
Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
771 if ( trigName.Contains(keepArray->At(ipat)->GetName() ) )
return kTRUE;
774 return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
778 TObjArray*
BuildListOfTrigger (
const TObjArray* triggerArray,
TString keepPattern =
"",
TString rejectPattern=
"OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
782 selectedList->SetOwner();
783 TObjArray* rejectArray = rejectPattern.Tokenize(
",");
784 TObjArray* keepArray = keepPattern.Tokenize(
",");
786 for (
Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
787 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
788 if (
CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(
new TObjString(currTrigName.Data()));
803 for (
Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
804 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
805 TObjArray* array = currTrigName.Tokenize(
"-");
806 TString collisionType = array->At(1)->GetName();
808 collisionType.Append(
"-");
809 collisionType.Prepend(
"-");
810 if ( checkTrigger.Contains(collisionType.Data()) ) {
811 foundName = currTrigName;
826 TFile *
file = TFile::Open(mergedFileName.Data());
827 AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny(
"MUON_QA"))->FindObjectAny(
"eventCounters");
830 TString triggerListName = ccol->GetKeyWords(
"trigger");
832 TObjArray selectedTriggerArray, selectedL0TriggerArray;
833 selectedTriggerArray.SetOwner();
834 selectedL0TriggerArray.SetOwner();
836 const Int_t nScaler = 3;
837 TString sScaler[nScaler] = {
"L0B",
"L2A",
"L0BRATE"};
838 enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
839 Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
844 TString cdbDir =
"GRP/CTP/Config";
847 TString sHistName, sHistNameFull, sTitleName;
848 Int_t nRuns = runNumArray.GetEntries();
854 for (
Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
856 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
857 Int_t runNr = sRunNr.Atoi();
859 AliAnalysisTriggerScalers triggerScaler(runNr);
860 AliTriggerConfiguration* tc =
static_cast<AliTriggerConfiguration*
>(triggerScaler.GetOCDBObject(cdbDir.Data(),runNr));
861 const TObjArray& trClasses = tc->GetClasses();
865 for (
Int_t itype=0; itype<2; itype++ ) {
866 TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
867 TString matchTrig = ( itype == 0 ) ?
"" :
"C0TVX";
871 for (
Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
873 TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
874 if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) )
continue;
875 if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(
new TObjString(currTrigName));
878 for (
Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
880 if ( itype == 1 && iScaler != kL0B )
continue;
883 TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data(),kFALSE);
885 sHistName = Form(
"%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
886 sHistNameFull = Form(
"Scalers_%s",sHistName.Data());
888 TH1* hist = (
TH1*) hFromScalers.FindObject(sHistNameFull);
890 hist =
new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(
Double_t)nRuns);
891 hist->LabelsOption(
"v");
892 hist->GetXaxis()->SetLabelSize(0.02);
893 hist->SetDirectory(0);
895 hist->SetMaximum(maxScaler[0]);
896 hFromScalers.AddLast(hist);
897 hOutput.AddLast(hist);
898 if ( iScaler == kL2A ) {
899 sHistNameFull =
"QA_" + sHistName;
900 hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
904 if ( tab ) hist->SetBinContent(ibin,tab[0]);
905 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
909 if ( iScaler != kL2A )
continue;
910 TH1* histCounters =
static_cast<TH1*
>(ccol->Get(
"run",Form(
"run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
911 sHistNameFull = sHistNameFull =
"QA_" + sHistName;
912 hist = (
TH1*) hFromQA.FindObject(sHistNameFull);
913 if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
914 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
922 if ( selectedTriggerArray.GetEntries() == 0 ) {
923 printf(
"No trigger selected from trigger list %s\n",triggerListName.Data());
926 printf(
"Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
928 printf(
"Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
932 for (
Int_t itype=0; itype<2; itype++ ) {
933 TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
934 for (
Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
935 TH1* histo =
static_cast<TH1*
> ( currList->At(ihisto) );
936 if (!histo)
continue;
938 for (
Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
939 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
941 TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
942 if ( ! binLabel.IsNull() )
continue;
943 histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
945 histo->SetStats(kFALSE);
951 const Int_t nHisto = 3;
952 TString sHisto[nHisto] = {
"L0BoverL0BC0TVX",
"L2AoverL0B",
"L2AQAoverSCALERS"};
953 TString sTitleHisto[nHisto] = {
"L0B trigger / L0BC0TVX",
"L2A / L0B",
"L2A from QA / L2A from SCALERS"};
957 for (
Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
959 sHistNameFull = Form(
"Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
960 TH1* histo1 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
961 if (!histo1)
continue;
965 TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
968 sHistNameFull = Form(
"Scalers_%s_L0B",sL0Trig.Data());
970 TH1* histo0 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
972 sHistNameFull = Form(
"%s_%s",sHisto[0].
Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
973 TH1* histo10 = (
TH1*) histo1->Clone(sHistNameFull);
974 histo10->SetTitle(sTitleHisto[0].
Data());
976 histo10->Divide(histo0);
977 histo10->SetMaximum(10);
978 histo10->SetMinimum(1e-5);
980 hOutput.AddLast(histo10);
986 sHistNameFull = Form(
"Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
987 TH1* histo2 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
988 if (!histo2)
continue;
990 sHistNameFull = Form(
"%s_%s",sHisto[1].
Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
991 TH1* histo3 = (
TH1*) histo2->Clone(sHistNameFull);
992 histo3->SetTitle(sTitleHisto[1]);
994 histo3->Divide(histo1);
995 histo3->SetMaximum(1.2);
996 histo3->SetMinimum(1e-5);
998 hOutput.AddLast(histo3);
1001 sHistNameFull = Form(
"QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
1002 TH1* histo4 =
static_cast<TH1*
> ( hFromQA.FindObject(sHistNameFull) );
1003 if (!histo4)
continue;
1005 sHistNameFull = Form(
"%s_%s",sHisto[2].
Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
1006 TH1* histo5 = (
TH1*) histo4->Clone(sHistNameFull);
1007 histo5->SetTitle(sTitleHisto[2]);
1009 histo5->Divide(histo2);
1010 histo5->SetMaximum(1.2);
1011 histo5->SetMinimum(5e-1);
1013 hOutput.AddLast(histo5);
1017 const Int_t nCanvases = nScaler + nHisto;
1019 for (
Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
1020 for (
Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
1023 for (
Int_t iCan = 0; iCan < nCanvases; iCan++) {
1024 TCanvas*
canvas =
new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
1025 TLegend* leg =
new TLegend(0.72,0.7,0.9,0.85);
1026 leg->SetBorderSize(1);
1027 if ( iCan != 4 ) canvas->SetLogy();
1032 for (
Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
1034 if ( iCan < nScaler ) sHistNameFull = Form(
"Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
1035 else sHistNameFull = Form(
"%s_%s",sCanvases[iCan].
Data(),selectedTriggerArray.At(iTrig)->GetName());
1036 TH1* histo1 =
static_cast<TH1*
> ( hOutput.FindObject(sHistNameFull) );
1037 if (!histo1)
continue;
1039 if ( icolor == 10 ) icolor++;
1040 histo1->SetLineColor(icolor++);
1041 histo1->Draw(optDraw);
1044 leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),
"l");
1048 outList.Add(canvas);
1049 outCanList.Add(canvas);
1059 ifstream inFile(fileListName.Data());
1061 fileNameArray.SetOwner();
1062 runNumArray.SetOwner();
1064 if (inFile.is_open()) {
1065 while (! inFile.eof() ) {
1066 currString.ReadLine(inFile);
1067 if ( ! currString.Contains(
".root") ||
1068 currString.BeginsWith(
"#") )
continue;
1069 fileNameArray.AddLast(
new TObjString(currString.Data()));
1071 runNumArray.AddLast(
new TObjString(Form(
"%i",runNum)));
1076 printf(
"Fatal: cannot open input file %s\n",fileListName.Data());
1086 TList outCanList, outList;
1087 TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1089 MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1091 if (
gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1092 printf(
"Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1095 ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1100 delete finalFileNameArray;
1102 if ( outFilename.IsNull() )
return;
1104 TString outCanName = outFilename;
1105 outCanName.ReplaceAll(
".root",
".pdf");
1106 for (
Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1108 if ( ican == 0 ) canName.Append(
"(");
1109 else if ( ican == outCanList.GetEntries()-1 ) canName.Append(
")");
1110 static_cast<TCanvas*
>(outCanList.At(ican))->
Print(canName.Data());
1114 if ( outCanName.Contains(
".ps") || outCanName.Contains(
".eps") ) {
1115 gSystem->Exec(Form(
"epstopdf %s", outCanName.Data()));
1116 gSystem->Exec(Form(
"rm %s", outCanName.Data()));
1119 TFile* outFile =
new TFile(outFilename.Data(),
"recreate");
void Print(std::ostream &o, const char *name, Double_t dT, Double_t dVM, Double_t alldT, Double_t alldVM)
Bool_t SetAndCheckOCDB(TString defaultStorage)
TH2 * GetOutliers(TH2 *histo, Double_t nSigmas=3.)
TH1 * GetHisto(TString histoName, TFile *file, TList *histoList)
TString FindCorrespondingTrigger(TString checkTrigger, TObjArray *triggerArray)
Double_t * GetConditionalEffErr(Double_t *effErr1, Double_t *effErr2, Double_t *effErrBoth, Int_t exclude=-1)
Double_t * GetProdErr(Double_t *effErr, Int_t exclude, Int_t nFactors=kNch)
Bool_t IsRunNum(TString stringToken)
TObjArray * BuildListOfTrigger(const TObjArray *triggerArray, TString keepPattern="", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM")
Int_t GetRunNumber(TString filePath)
void ScalerTrending(TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList &outCanList, TList &outList)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
TObjArray * ChangeFilenames(const TObjArray &fileNameArray)
Bool_t CheckOCDBFile(TString cdbDir, Int_t runNum)
void SetRunAxisRange(TH1 *histo, TString runAxis="X")
Double_t * GetBinomial(Double_t *effErr1, Double_t *effErr2=0x0, Double_t *effErrBoth=0x0)
Bool_t IsOCDBChanged(Int_t currRun, Int_t previousRun, TList *fileList)
void MaskTrending(TObjArray runNumArray, TString defaultStorage, TList &outCanList, TList &outList)
void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList &outCanList, TList &outList)
Int_t GetEffIndex(Int_t iel, Int_t icount, Int_t ich=-1)
TList * GetOCDBList(TString ocdbDirs)
Bool_t CheckPattern(TString trigName, TObjArray *keepArray, TObjArray *rejectArray)
TString prod[]
total number of productions
void trigEffQA(TString fileListName, TString outFilename="", TString defaultStorage="raw://", Bool_t doScalers=kFALSE, TString trackerQAmergedOut="QAresults_merged.root")