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;
291 TString storageType = AliCDBManager::Instance()->GetDefaultStorage()->GetType();
292 Bool_t isGrid = storageType.Contains(
"alien");
293 TString baseFolder = AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder();
297 TObjArray* dirNameList = ocdbDirs.Tokenize(
",");
298 for (
Int_t idir=0; idir<dirNameList->GetEntries(); idir++ ) {
299 TString fullPath = Form(
"%s/%s",baseFolder.Data(),dirNameList->At(idir)->GetName());
301 TGridResult *res = gGrid->Ls(fullPath.Data());
302 if (!res)
return 0x0;
303 for (
Int_t ires=0; ires<res->GetEntries(); ires++ ) {
304 TString currFile =
static_cast<TMap*
>(res->At(ires))->GetValue(
"name")->GetName();
305 outList->Add(
new TObjString(currFile));
310 TString fileListStr =
gSystem->GetFromPipe(Form(
"ls %s",fullPath.Data()));
311 TObjArray* fileList = fileListStr.Tokenize(
"\n");
312 for (
Int_t ires=0; ires<fileList->GetEntries(); ires++ ) {
313 TString currFile = fileList->At(ires)->GetName();
314 outList->Add(
new TObjString(currFile));
327 if ( defaultStorage.IsNull() ) {
328 printf(
"Default storage not specified. Nothing done\n");
332 if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
333 printf(
"Default storage already set: nothing done\n");
337 if ( defaultStorage.Contains(
"alien://") || defaultStorage.Contains(
"raw://") ) {
338 if ( ! gGrid ) TGrid::Connect(
"alien://");
340 printf(
"Error: Problem connetting to grid: default storage not set\n");
345 AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
347 if ( defaultStorage.Contains(
"raw://") )
return kTRUE;
351 if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
352 TString searchDir =
"MUON/Calib/MappingData";
353 TString fullPath = Form(
"%s/%s",defaultStorage.Data(),searchDir.Data());
355 if ( ocdbList->GetEntries() == 0 ) {
356 printf(
"No entries in %s\n",fullPath.Data());
360 TString checkFile = Form(
"%s/%s",fullPath.Data(),ocdbList->At(0)->GetName());
361 checkFile.ReplaceAll(
"local://",
"");
362 checkFile.ReplaceAll(
"folder=",
"");
363 checkFile.ReplaceAll(
"Folder=",
"");
364 TFile*
file = TFile::Open(checkFile.Data());
366 printf(
"Cannot access test file: %s\n", checkFile.Data());
374 printf(
"Tried to set the default storage, but something went wrong.\n");
378 if ( ! isOk ) printf(
"Please check path %s\n",defaultStorage.Data());
387 if ( ! fileList )
return kTRUE;
388 for (
Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
389 TString filename =
static_cast<TObjString*
>(fileList->At(ifile))->GetString();
390 filename.ReplaceAll(
"Run",
"");
391 TObjArray* array = filename.Tokenize(
"_");
392 Int_t firstRun =
static_cast<TObjString*
>(array->At(0))->GetString().Atoi();
393 Int_t lastRun =
static_cast<TObjString*
>(array->At(1))->GetString().Atoi();
395 Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
396 Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
397 if ( isCurrRunInside != isPreviousRunInside )
return kTRUE;
405 TH2* outHisto =
static_cast<TH2*
>(histo->Clone());
406 outHisto->SetName(Form(
"%s_outlier",histo->GetName()));
408 for (
Int_t ybin=1; ybin<=histo->GetYaxis()->GetNbins(); ybin++ ) {
409 TH1* auxHisto = histo->ProjectionX(
"projectionOutlier",ybin,ybin);
410 if ( auxHisto->Integral() == 0. )
continue;
411 auxHisto->Fit(
"pol0",
"Q0");
412 Double_t mean = auxHisto->GetFunction(
"pol0")->GetParameter(0);
413 for (
Int_t xbin=1; xbin<=auxHisto->GetXaxis()->GetNbins(); xbin++ ) {
414 Double_t err = auxHisto->GetBinError(xbin);
415 if ( err == 0. )
continue;
416 if ( TMath::Abs(auxHisto->GetBinContent(xbin)-mean)/err < nSigmas )
continue;
417 outHisto->SetBinContent(xbin,ybin,auxHisto->GetBinContent(xbin)-mean);
428 TString elementName[3] = {
"Chamber",
"RPC",
"Board" };
429 TString countTypeName[4] = {
"allTracks",
"bendPlane",
"nonBendPlane",
"bothPlanes" };
438 const Int_t kNeffVsRun = kNgraphs+1;
441 effName =
"totalEffEvolution";
442 effTitle =
"Multinomial probability of firing at least 3/4 chambers";
443 TH1D* totalEff =
new TH1D(effName.Data(), effTitle.Data(), 1, 0., 1.);
444 effVsRunList.AddAt(totalEff, kNeffVsRun-1);
447 for (
Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
449 runNumString = runNumArray.At(irun)->GetName();
452 for (
Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
453 filename = fileNameArray.At(ifile)->GetName();
454 if ( filename.Contains(runNumString.Data()) )
break;
457 if ( filename.Contains(
"alien://") && ! gGrid ) gGrid->Connect(
"alien://");
464 TFile*
file = TFile::Open(filename.Data());
466 printf(
"Warning: cannot find %s\n", filename.Data());
470 TList* trigEffList = (
TList*)file->FindObjectAny(
"triggerChamberEff");
471 if ( ! trigEffList ) {
472 printf(
"Warning: histo list not found in %s.\n", filename.Data());
475 if ( trigEffList->GetEntries() == 0 ) {
476 printf(
"Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
481 for (
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
482 effName = countTypeName[icount] +
"Count" + elementName[0];
484 histoDen =
GetHisto(effName, file, trigEffList);
488 TH1* histoNum =
GetHisto(effName, file, trigEffList);
490 effName.ReplaceAll(
"Count",
"Eff");
491 graph->SetName(effName.Data());
497 printf(
"Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
502 AliMUONTriggerChamberEfficiency trigChEff(filename);
503 for (
Int_t iel=1; iel<3; iel++ ) {
505 for (
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
506 TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
507 effList.AddAt(obj->Clone(Form(
"%s_cloned",obj->GetName())),
GetEffIndex(iel, icount, ich));
513 for (
Int_t iel=0; iel<3; iel++ ) {
515 for (
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
517 Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
518 for (
Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
519 Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
521 graph->GetPoint(currPoint, xpt, ypt);
522 effValues[icount][ich] = ypt;
524 TH2* effHisto =
static_cast<TH2*
>(effVsRunList.At(ihisto));
526 effName = Form(
"effEvolution%s%s", countTypeName[icount+1].
Data(), elementName[iel].
Data());
527 effTitle = Form(
"Trigger chamber efficiency vs run");
529 effName += Form(
"Ch%i", 11+ich);
530 effTitle += Form(
" for chamber %i", 11+ich);
532 effHisto =
new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(
Double_t)graph->GetN());
533 effVsRunList.AddAt(effHisto, ihisto);
535 Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
536 Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
537 Int_t binx, biny, binz;
538 effHisto->GetBinXYZ(currBin, binx, biny, binz);
539 effHisto->SetBinError(binx, biny, err);
540 effValues[icount][ich+
kNch] = err;
544 if ( iel > 0 )
continue;
546 Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
551 totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
552 delete [] binomialEff;
557 for (
Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
558 TH1* histo =
static_cast<TH1*
>(effVsRunList.At(ihisto));
559 if ( ! histo )
continue;
566 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
567 TH1* totEff = (
TH1*)effVsRunList.At(kNeffVsRun-1);
568 totEff->GetYaxis()->SetRangeUser(0.9,1.05);
569 totEff->GetYaxis()->SetTitle(
"Probability to satisfy trigger conditions (3/4)");
570 totEff->SetStats(kFALSE);
575 Int_t markStyle[3] = {20, 24, 26};
579 canName = Form(
"trigEffCh%i", 11+ich);
580 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
582 leg =
new TLegend(0.7, 0.8, 0.96, 0.92);
583 leg->SetBorderSize(1);
586 for(
Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
589 if ( ! histo )
continue;
590 TH1* chEff = histo->ProjectionX(Form(
"effEvolutionCh%i",11+ich), ich+1, ich+1);
591 chEff->SetTitle(Form(
"%s for chamber %i", histo->GetTitle(), 11+ich));
592 chEff->GetYaxis()->SetRangeUser(0.9,1.02);
593 chEff->SetStats(kFALSE);
594 chEff->GetYaxis()->SetTitle(
"Trigger chamber efficiency");
595 TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
596 copyEff->SetLineColor(color[icount]);
597 copyEff->SetMarkerColor(color[icount]);
598 copyEff->SetMarkerStyle(markStyle[icount]);
599 leg->AddEntry(copyEff, countTypeName[icount+1].
Data(),
"lp");
606 for (
Int_t iel=1; iel<3; iel++ ) {
608 Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff;
610 canName = Form(
"trigEff%sCh%i", elementName[iel].
Data(), 11+ich);
611 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
612 can->SetRightMargin(0.14);
614 if ( ! histo )
continue;
615 histo->SetStats(kFALSE);
616 histo->GetYaxis()->SetTitle(elementName[iel].
Data());
618 if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
619 histo->DrawCopy(
"COLZ");
628 Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff;
631 canName = Form(
"trigEff%sCh%i_outliers", elementName[iel].
Data(), 11+ich);
632 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
633 can->SetRightMargin(0.14);
635 if ( ! histo || histo->Integral() == 0. )
continue;
637 TString histoTitle = histo->GetTitle();
638 histoTitle.ReplaceAll(
"efficiency",
"eff.-<eff.> for outliers");
639 outHisto->SetTitle(histoTitle.Data());
640 outList.Add(outHisto);
641 outHisto->SetMinimum(-0.08);
642 outHisto->SetMaximum(0.08);
643 outHisto->DrawCopy(
"COLZ");
659 TString histoName =
"", histoTitle =
"";
660 for(
Int_t icath=0; icath<2; icath++){
661 TString cathName = ( icath==0 ) ?
"bendPlane" :
"nonBendPlane";
663 histoName = Form(
"%sMaskCh%i", cathName.Data(), 11+ich);
664 histoTitle = Form(
"Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
665 TH2* histo =
new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
666 histo->GetYaxis()->SetTitle(
"Board Id");
668 Int_t imask = 2*ich + icath;
669 maskedList.AddAt(histo, imask);
670 auxList.AddAt(histo->Clone(Form(
"%s_aux",histoName.Data())), imask);
674 TArrayS xyPatternAll[2];
675 for(
Int_t icath=0; icath<2; icath++){
676 xyPatternAll[icath].Set(
kNch);
677 xyPatternAll[icath].Reset(0xFFFF);
680 TList* ocdbFileList = 0x0;
681 Int_t previousRun = -1;
682 AliMUONDigitMaker* digitMaker = 0x0;
683 AliMUONDigitStoreV2R digitStore;
685 AliMUONCalibrationData* calibData = 0x0;
686 AliMUONTriggerUtilities* trigUtilities = 0x0;
687 for (
Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
688 TString runNumString = runNumArray.At(irun)->GetName();
689 Int_t runNumber = runNumString.Atoi();
692 AliCDBManager::Instance()->SetRun(runNumber);
694 if ( ! digitMaker ) {
695 digitMaker =
new AliMUONDigitMaker(kFALSE);
697 for (
Int_t iboard=1; iboard<=234; iboard++ ) {
698 digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
702 if ( ! ocdbFileList ) ocdbFileList =
GetOCDBList(
"MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
705 calibData =
new AliMUONCalibrationData (runNumber);
706 delete trigUtilities;
707 trigUtilities =
new AliMUONTriggerUtilities (calibData);
710 previousRun = runNumber;
712 TIter next(digitStore.CreateIterator());
713 AliMUONVDigit* dig = 0x0;
714 while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
715 Int_t icath = dig->Cathode();
716 Int_t detElemId = dig->DetElemId();
717 Int_t ich = detElemId/100-11;
718 Int_t iboard = dig->ManuId();
719 Int_t imask = 2*ich + icath;
720 static_cast<TH2*
>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
721 static_cast<TH2*
>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(
Double_t)trigUtilities->IsMasked(*dig));
725 delete trigUtilities;
729 for (
Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
730 TH2* histo =
static_cast<TH2*
>(maskedList.At(imask));
731 histo->Divide(static_cast<TH2*>(auxList.At(imask)));
735 canName = Form(
"%sCan", histo->GetName());
736 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
737 can->SetRightMargin(0.14);
738 histo->SetStats(kFALSE);
739 if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
740 histo->DrawCopy(
"COLZ");
749 for (
Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
750 if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) )
return kFALSE;
753 for (
Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
754 if ( trigName.Contains(keepArray->At(ipat)->GetName() ) )
return kTRUE;
757 return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
761 TObjArray*
BuildListOfTrigger (
const TObjArray* triggerArray,
TString keepPattern =
"",
TString rejectPattern=
"OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
765 selectedList->SetOwner();
766 TObjArray* rejectArray = rejectPattern.Tokenize(
",");
767 TObjArray* keepArray = keepPattern.Tokenize(
",");
769 for (
Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
770 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
771 if (
CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(
new TObjString(currTrigName.Data()));
786 for (
Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
787 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
788 TObjArray* array = currTrigName.Tokenize(
"-");
789 TString collisionType = array->At(1)->GetName();
791 collisionType.Append(
"-");
792 collisionType.Prepend(
"-");
793 if ( checkTrigger.Contains(collisionType.Data()) ) {
794 foundName = currTrigName;
809 TFile *
file = TFile::Open(mergedFileName.Data());
810 AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny(
"MUON_QA"))->FindObjectAny(
"eventCounters");
813 TString triggerListName = ccol->GetKeyWords(
"trigger");
815 TObjArray selectedTriggerArray, selectedL0TriggerArray;
816 selectedTriggerArray.SetOwner();
817 selectedL0TriggerArray.SetOwner();
819 const Int_t nScaler = 3;
820 TString sScaler[nScaler] = {
"L0B",
"L2A",
"L0BRATE"};
821 enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
822 Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
828 TString sHistName, sHistNameFull, sTitleName;
829 Int_t nRuns = runNumArray.GetEntries();
835 for (
Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
837 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
838 Int_t runNr = sRunNr.Atoi();
839 AliAnalysisTriggerScalers triggerScaler(runNr);
840 AliTriggerConfiguration* tc =
static_cast<AliTriggerConfiguration*
>(triggerScaler.GetOCDBObject(
"GRP/CTP/Config",runNr));
841 const TObjArray& trClasses = tc->GetClasses();
845 for (
Int_t itype=0; itype<2; itype++ ) {
846 TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
847 TString matchTrig = ( itype == 0 ) ?
"" :
"C0TVX";
851 for (
Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
853 TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
854 if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) )
continue;
855 if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(
new TObjString(currTrigName));
858 for (
Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
860 if ( itype == 1 && iScaler != kL0B )
continue;
863 TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data(),kFALSE);
865 sHistName = Form(
"%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
866 sHistNameFull = Form(
"Scalers_%s",sHistName.Data());
868 TH1* hist = (
TH1*) hFromScalers.FindObject(sHistNameFull);
870 hist =
new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(
Double_t)nRuns);
871 hist->LabelsOption(
"v");
872 hist->GetXaxis()->SetLabelSize(0.02);
873 hist->SetDirectory(0);
875 hist->SetMaximum(maxScaler[0]);
876 hFromScalers.AddLast(hist);
877 hOutput.AddLast(hist);
878 if ( iScaler == kL2A ) {
879 sHistNameFull =
"QA_" + sHistName;
880 hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
884 if ( tab ) hist->SetBinContent(ibin,tab[0]);
885 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
889 if ( iScaler != kL2A )
continue;
890 TH1* histCounters =
static_cast<TH1*
>(ccol->Get(
"run",Form(
"run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
891 sHistNameFull = sHistNameFull =
"QA_" + sHistName;
892 hist = (
TH1*) hFromQA.FindObject(sHistNameFull);
893 if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
894 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
902 if ( selectedTriggerArray.GetEntries() == 0 ) {
903 printf(
"No trigger selected from trigger list %s\n",triggerListName.Data());
906 printf(
"Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
908 printf(
"Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
912 for (
Int_t itype=0; itype<2; itype++ ) {
913 TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
914 for (
Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
915 TH1* histo =
static_cast<TH1*
> ( currList->At(ihisto) );
916 if (!histo)
continue;
918 for (
Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
919 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
921 TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
922 if ( ! binLabel.IsNull() )
continue;
923 histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
925 histo->SetStats(kFALSE);
931 const Int_t nHisto = 3;
932 TString sHisto[nHisto] = {
"L0BoverL0BC0TVX",
"L2AoverL0B",
"L2AQAoverSCALERS"};
933 TString sTitleHisto[nHisto] = {
"L0B trigger / L0BC0TVX",
"L2A / L0B",
"L2A from QA / L2A from SCALERS"};
937 for (
Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
939 sHistNameFull = Form(
"Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
940 TH1* histo1 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
941 if (!histo1)
continue;
945 TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
948 sHistNameFull = Form(
"Scalers_%s_L0B",sL0Trig.Data());
950 TH1* histo0 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
952 sHistNameFull = Form(
"%s_%s",sHisto[0].
Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
953 TH1* histo10 = (
TH1*) histo1->Clone(sHistNameFull);
954 histo10->SetTitle(sTitleHisto[0].
Data());
956 histo10->Divide(histo0);
957 histo10->SetMaximum(10);
958 histo10->SetMinimum(1e-5);
960 hOutput.AddLast(histo10);
966 sHistNameFull = Form(
"Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
967 TH1* histo2 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
968 if (!histo2)
continue;
970 sHistNameFull = Form(
"%s_%s",sHisto[1].
Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
971 TH1* histo3 = (
TH1*) histo2->Clone(sHistNameFull);
972 histo3->SetTitle(sTitleHisto[1]);
974 histo3->Divide(histo1);
975 histo3->SetMaximum(1.2);
976 histo3->SetMinimum(1e-5);
978 hOutput.AddLast(histo3);
981 sHistNameFull = Form(
"QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
982 TH1* histo4 =
static_cast<TH1*
> ( hFromQA.FindObject(sHistNameFull) );
983 if (!histo4)
continue;
985 sHistNameFull = Form(
"%s_%s",sHisto[2].
Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
986 TH1* histo5 = (
TH1*) histo4->Clone(sHistNameFull);
987 histo5->SetTitle(sTitleHisto[2]);
989 histo5->Divide(histo2);
990 histo5->SetMaximum(1.2);
991 histo5->SetMinimum(5e-1);
993 hOutput.AddLast(histo5);
997 const Int_t nCanvases = nScaler + nHisto;
999 for (
Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
1000 for (
Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
1003 for (
Int_t iCan = 0; iCan < nCanvases; iCan++) {
1004 TCanvas*
canvas =
new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
1005 TLegend* leg =
new TLegend(0.72,0.7,0.9,0.85);
1006 leg->SetBorderSize(1);
1007 if ( iCan != 4 ) canvas->SetLogy();
1012 for (
Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
1014 if ( iCan < nScaler ) sHistNameFull = Form(
"Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
1015 else sHistNameFull = Form(
"%s_%s",sCanvases[iCan].
Data(),selectedTriggerArray.At(iTrig)->GetName());
1016 TH1* histo1 =
static_cast<TH1*
> ( hOutput.FindObject(sHistNameFull) );
1017 if (!histo1)
continue;
1019 if ( icolor == 10 ) icolor++;
1020 histo1->SetLineColor(icolor++);
1021 histo1->Draw(optDraw);
1024 leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),
"l");
1028 outList.Add(canvas);
1029 outCanList.Add(canvas);
1039 ifstream inFile(fileListName.Data());
1041 fileNameArray.SetOwner();
1042 runNumArray.SetOwner();
1044 if (inFile.is_open()) {
1045 while (! inFile.eof() ) {
1046 currString.ReadLine(inFile);
1047 if ( ! currString.Contains(
".root") ||
1048 currString.BeginsWith(
"#") )
continue;
1049 fileNameArray.AddLast(
new TObjString(currString.Data()));
1051 runNumArray.AddLast(
new TObjString(Form(
"%i",runNum)));
1056 printf(
"Fatal: cannot open input file %s\n",fileListName.Data());
1066 TList outCanList, outList;
1067 TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1069 MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1071 if (
gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1072 printf(
"Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1075 ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1080 delete finalFileNameArray;
1082 if ( outFilename.IsNull() )
return;
1084 TString outCanName = outFilename;
1085 outCanName.ReplaceAll(
".root",
".pdf");
1086 for (
Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1088 if ( ican == 0 ) canName.Append(
"(");
1089 else if ( ican == outCanList.GetEntries()-1 ) canName.Append(
")");
1090 static_cast<TCanvas*
>(outCanList.At(ican))->
Print(canName.Data());
1094 if ( outCanName.Contains(
".ps") || outCanName.Contains(
".eps") ) {
1095 gSystem->Exec(Form(
"epstopdf %s", outCanName.Data()));
1096 gSystem->Exec(Form(
"rm %s", outCanName.Data()));
1099 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)
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")