2 #if !defined(__CINT__) || defined(__MAKECINT__)
7 #include "TGraphAsymmErrors.h"
15 #include "TObjArray.h"
17 #include "TObjString.h"
23 #include "TGridResult.h"
25 #include "AliCDBManager.h"
26 #include "AliCDBEntry.h"
27 #include "AliCDBPath.h"
28 #include "AliCDBStorage.h"
29 #include "AliMUONTriggerEfficiencyCells.h"
30 #include "AliMUONTriggerChamberEfficiency.h"
31 #include "AliMUONTriggerUtilities.h"
32 #include "AliMUONDigitMaker.h"
33 #include "AliMUONVDigit.h"
34 #include "AliMUONDigitStoreV2R.h"
35 #include "AliMUONCalibrationData.h"
36 #include "AliAnalysisTriggerScalers.h"
37 #include "AliCounterCollection.h"
38 #include "AliTriggerConfiguration.h"
48 gStyle->SetCanvasColor(10);
49 gStyle->SetFrameFillColor(10);
50 gStyle->SetStatColor(10);
51 gStyle->SetFillColor(10);
52 gStyle->SetTitleFillColor(10);
54 gStyle->SetTitleXSize(0.03);
55 gStyle->SetTitleXOffset(1.1);
56 gStyle->SetTitleYSize(0.03);
57 gStyle->SetTitleYOffset(1.9);
59 gStyle->SetMarkerSize(0.7);
60 gStyle->SetHistLineWidth(2);
62 gStyle->SetPadLeftMargin(0.12);
63 gStyle->SetPadRightMargin(0.04);
64 gStyle->SetPadBottomMargin(0.08);
65 gStyle->SetPadTopMargin(0.08);
73 return ( stringToken.IsDigit() && stringToken.Length()>=6 && stringToken.Length()<=9 );
81 for ( Int_t ibin=1; ibin<=axis->GetNbins(); ibin++ ) {
82 TString binLabel = axis->GetBinLabel(ibin);
83 if ( ! binLabel.IsNull())
continue;
84 axis->SetRange(1, ibin-1);
93 TObjArray* array = filePath.Tokenize(
"/");
95 TString auxString =
"";
97 for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
98 auxString = array->At(ientry)->GetName();
100 runNum = auxString.Atoi();
107 array = auxString.Tokenize(
"_");
109 auxString = array->Last()->GetName();
110 auxString.ReplaceAll(
".root",
"");
111 if (
IsRunNum(auxString) ) runNum = auxString.Atoi();
127 TObjArray* outArray =
new TObjArray(fileNameArray.GetEntries());
128 outArray->SetOwner();
129 TString newBaseName =
"trigChEff_ANY_Apt_allTrig.root";
130 for ( Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
131 TObjString* currObjString =
static_cast<TObjString*
>(fileNameArray.At(ifile));
132 TString currFile = currObjString->GetString();
133 TString baseName = gSystem->BaseName(currFile.Data());
136 TString newFilename =
"";
139 newFilename = currFile;
140 newFilename.ReplaceAll(baseName.Data(),newBaseName.Data());
144 TString dirName = gSystem->DirName(currFile.Data());
145 newFilename = Form(
"%s/terminateRuns/%i/%s",dirName.Data(),runNum,newBaseName.Data());
147 if ( gSystem->AccessPathName(newFilename.Data()) ) {
148 printf(
"New output not found in %s.\n", currFile.Data());
153 outArray->AddAt(
new TObjString(newFilename),ifile);
156 if ( outArray ) printf(
"Using re-built output in %s\n",newBaseName.Data());
158 outArray =
static_cast<TObjArray*
>(fileNameArray.Clone());
159 printf(
"Using default output\n");
169 Double_t relErr = 0., relProdErrSquare = 0.;
170 for ( Int_t iprod=0; iprod<nFactors; iprod++ ) {
171 if ( iprod == exclude )
continue;
172 prod *= effErr[iprod];
173 relErr = ( effErr[iprod] >
kZero ) ? effErr[iprod+nFactors]/effErr[iprod] : 0.;
174 relProdErrSquare += relErr*relErr;
177 Double_t* prodErr =
new Double_t[2];
179 prodErr[1] = prod*TMath::Sqrt(relProdErrSquare);
189 Double_t* effErr =
new Double_t[2*
kNch];
190 for ( Int_t ich=0; ich<
kNch; ich++ ) {
191 if ( ich == exclude ) {
192 effErr[ich] = ( effErr1[ich] < 1. ) ? ( effErr2[ich] - effErrBoth[ich] ) / ( 1. - effErr1[ich] ) : 0.;
193 effErr[ich+
kNch] = 0;
194 if ( effErr1[ich] < 1. ) {
195 Double_t err2 = effErr2[ich+
kNch] / ( 1. - effErr1[ich] );
196 Double_t errBoth = effErrBoth[ich+
kNch] / ( 1. - effErr1[ich] );
197 Double_t err1 = effErr1[ich+
kNch] * effErr[ich] / ( 1. - effErr1[ich] );
198 effErr[ich+
kNch] = TMath::Sqrt(err2*err2 + errBoth*errBoth + err1*err1);
202 effErr[ich] = ( effErr1[ich] >
kZero ) ? effErrBoth[ich]/effErr1[ich] : 0.;
203 Double_t relErr1 = ( effErr1[ich] >
kZero ) ? effErr1[ich+kNch]/effErr1[ich] : 0.;
204 Double_t relErrBoth = ( effErrBoth[ich] >
kZero ) ? effErrBoth[ich+kNch]/effErrBoth[ich] : 0.;
205 effErr[ich+
kNch] = effErr[ich] * TMath::Sqrt(relErr1*relErr1 + relErrBoth*relErrBoth);
214 Double_t*
GetBinomial(Double_t* effErr1, Double_t* effErr2 = 0x0, Double_t* effErrBoth = 0x0)
218 Double_t defaultEffErr[2] = {1.,0.};
219 Double_t* auxBinomial = 0x0;
220 Double_t* currEffErr44 = 0x0;
221 Double_t* effErrBinomial =
new Double_t[2];
222 effErrBinomial[0] = 0.;
223 effErrBinomial[1] = 0.;
225 for ( Int_t ich = -1; ich<
kNch; ich++ ) {
226 Double_t* currEffErr =
GetProdErr(effErr1, ich);
228 currEffErr[0] = currEffErr[0] - currEffErr44[0];
229 currEffErr[1] = TMath::Sqrt(currEffErr[1]*currEffErr[1] + currEffErr44[1]*currEffErr44[1]);
236 for ( Int_t ival=0; ival<2; ival++ ) {
237 effProd[2*ival] = currEffErr[ival];
238 effProd[2*ival+1] = ( effErr2 ) ? auxBinomial[ival] : defaultEffErr[ival];
240 if ( ich < 0 ) currEffErr44 = currEffErr;
241 else delete currEffErr;
244 Double_t* effErr =
GetProdErr(effProd, -1, 2);
246 effErrBinomial[0] += effErr[0];
247 effErrBinomial[1] += effErr[1]*effErr[1];
253 effErrBinomial[1] = TMath::Sqrt(effErrBinomial[1]);
255 return effErrBinomial;
260 TH1*
GetHisto(TString histoName, TFile* file, TList* histoList)
265 histo = (TH1*)histoList->FindObject(histoName.Data());
267 histo = (TH1*)file->FindObjectAny(histoName.Data());
276 if ( iel == 0 )
return icount;
277 return 3 + 4*3*(iel-1) + 3*ich + icount;
284 TString storageType = AliCDBManager::Instance()->GetDefaultStorage()->GetType();
285 Bool_t isGrid = storageType.Contains(
"alien");
286 TString baseFolder = AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder();
288 TList* outList =
new TList();
290 TObjArray* dirNameList = ocdbDirs.Tokenize(
",");
291 for ( Int_t idir=0; idir<dirNameList->GetEntries(); idir++ ) {
292 TString fullPath = Form(
"%s/%s",baseFolder.Data(),dirNameList->At(idir)->GetName());
294 TGridResult *res = gGrid->Ls(fullPath.Data());
295 if (!res)
return 0x0;
296 for ( Int_t ires=0; ires<res->GetEntries(); ires++ ) {
297 TString currFile =
static_cast<TMap*
>(res->At(ires))->GetValue(
"name")->GetName();
298 outList->Add(
new TObjString(currFile));
303 TString fileListStr = gSystem->GetFromPipe(Form(
"ls %s",fullPath.Data()));
304 TObjArray* fileList = fileListStr.Tokenize(
"\n");
305 for ( Int_t ires=0; ires<fileList->GetEntries(); ires++ ) {
306 TString currFile = fileList->At(ires)->GetName();
307 outList->Add(
new TObjString(currFile));
320 if ( defaultStorage.IsNull() ) {
321 printf(
"Default storage not specified. Nothing done\n");
325 if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
326 printf(
"Default storage already set: nothing done\n");
330 if ( defaultStorage.Contains(
"alien://") || defaultStorage.Contains(
"raw://") ) {
331 if ( ! gGrid ) TGrid::Connect(
"alien://");
333 printf(
"Error: Problem connetting to grid: default storage not set\n");
338 AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
340 if ( defaultStorage.Contains(
"raw://") )
return kTRUE;
344 if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
345 TString searchDir =
"MUON/Calib/MappingData";
346 TString fullPath = Form(
"%s/%s",defaultStorage.Data(),searchDir.Data());
348 if ( ocdbList->GetEntries() == 0 ) {
349 printf(
"No entries in %s\n",fullPath.Data());
353 TString checkFile = Form(
"%s/%s",fullPath.Data(),ocdbList->At(0)->GetName());
354 checkFile.ReplaceAll(
"local://",
"");
355 TFile* file = TFile::Open(checkFile.Data());
357 printf(
"Cannot access test file: %s\n", checkFile.Data());
365 printf(
"Tried to set the default storage, but something went wrong.\n");
369 if ( ! isOk ) printf(
"Please check path %s\n",defaultStorage.Data());
378 if ( ! fileList )
return kTRUE;
379 for ( Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
380 TString filename =
static_cast<TObjString*
>(fileList->At(ifile))->GetString();
381 filename.ReplaceAll(
"Run",
"");
382 TObjArray* array = filename.Tokenize(
"_");
383 Int_t firstRun =
static_cast<TObjString*
>(array->At(0))->GetString().Atoi();
384 Int_t lastRun =
static_cast<TObjString*
>(array->At(1))->GetString().Atoi();
386 Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
387 Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
388 if ( isCurrRunInside != isPreviousRunInside )
return kTRUE;
394 void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList& outCanList, TList& outList)
397 TString elementName[3] = {
"Chamber",
"RPC",
"Board" };
398 TString countTypeName[4] = {
"allTracks",
"bendPlane",
"nonBendPlane",
"bothPlanes" };
400 TString filename =
"", effName =
"", effTitle =
"";
403 Double_t effValues[3][2*
kNch];
404 const Int_t kNgraphs =
kNch*3*2+3;
405 TObjArray effList(kNgraphs);
407 const Int_t kNeffVsRun = kNgraphs+1;
408 TObjArray effVsRunList(kNeffVsRun);
410 effName =
"totalEffEvolution";
411 effTitle =
"Multinomial probability of firing at least 3/4 chambers";
412 TH1D* totalEff =
new TH1D(effName.Data(), effTitle.Data(), 1, 0., 1.);
413 effVsRunList.AddAt(totalEff, kNeffVsRun-1);
415 TString runNumString =
"";
416 for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
418 runNumString = runNumArray.At(irun)->GetName();
421 for ( Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
422 filename = fileNameArray.At(ifile)->GetName();
423 if ( filename.Contains(runNumString.Data()) )
break;
426 if ( filename.Contains(
"alien://") && ! gGrid ) gGrid->Connect(
"alien://");
433 TFile* file = TFile::Open(filename.Data());
435 printf(
"Warning: cannot find %s\n", filename.Data());
439 TList* trigEffList = (TList*)file->FindObjectAny(
"triggerChamberEff");
440 if ( ! trigEffList ) printf(
"Warning: histo list not found in %s. Check directly in file\n", filename.Data());
441 if ( trigEffList->GetEntries() == 0 ) {
442 printf(
"Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
447 for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
448 effName = countTypeName[icount] +
"Count" + elementName[0];
450 histoDen =
GetHisto(effName, file, trigEffList);
454 TH1* histoNum =
GetHisto(effName, file, trigEffList);
455 TGraphAsymmErrors* graph =
new TGraphAsymmErrors(histoNum, histoDen,
"e0");
456 effName.ReplaceAll(
"Count",
"Eff");
457 graph->SetName(effName.Data());
463 printf(
"Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
468 AliMUONTriggerChamberEfficiency trigChEff(filename);
469 for ( Int_t iel=1; iel<3; iel++ ) {
470 for ( Int_t ich=0; ich<
kNch; ich++ ) {
471 for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
472 TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
473 effList.AddAt(obj->Clone(Form(
"%s_cloned",obj->GetName())),
GetEffIndex(iel, icount, ich));
479 for ( Int_t iel=0; iel<3; iel++ ) {
480 for ( Int_t ich=0; ich<
kNch; ich++ ) {
481 for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
482 TGraphAsymmErrors* graph =
static_cast<TGraphAsymmErrors*
>(effList.At(
GetEffIndex(iel, icount, ich)));
483 Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
484 for ( Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
485 Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
487 graph->GetPoint(currPoint, xpt, ypt);
488 effValues[icount][ich] = ypt;
490 TH2* effHisto =
static_cast<TH2*
>(effVsRunList.At(ihisto));
492 effName = Form(
"effEvolution%s%s", countTypeName[icount+1].Data(), elementName[iel].Data());
493 effTitle = Form(
"Trigger chamber efficiency vs run");
495 effName += Form(
"Ch%i", 11+ich);
496 effTitle += Form(
" for chamber %i", 11+ich);
498 effHisto =
new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(Double_t)graph->GetN());
499 effVsRunList.AddAt(effHisto, ihisto);
501 Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
502 Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
503 Int_t binx, biny, binz;
504 effHisto->GetBinXYZ(currBin, binx, biny, binz);
505 effHisto->SetBinError(binx, biny, err);
506 effValues[icount][ich+
kNch] = err;
510 if ( iel > 0 )
continue;
511 Double_t* binomialEff =
GetBinomial(effValues[0], effValues[1], effValues[2]);
512 Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
517 totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
523 for ( Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
524 TH1* histo =
static_cast<TH1*
>(effVsRunList.At(ihisto));
525 if ( ! histo )
continue;
531 TString canName =
"totalEff";
532 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
533 TH1* totEff = (TH1*)effVsRunList.At(kNeffVsRun-1);
534 totEff->GetYaxis()->SetRangeUser(0.9,1.05);
535 totEff->GetYaxis()->SetTitle(
"Probability to satisfy trigger conditions (3/4)");
536 totEff->SetStats(kFALSE);
540 Int_t color[3] = {kBlack, kRed, kBlue};
541 Int_t markStyle[3] = {20, 24, 26};
544 for ( Int_t ich=0; ich<
kNch; ich++ ) {
545 canName = Form(
"trigEffCh%i", 11+ich);
546 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
548 leg =
new TLegend(0.6, 0.2, 0.9, 0.4);
549 leg->SetBorderSize(1);
551 TString drawOpt =
"e";
552 for(Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
554 TH2* histo =
static_cast<TH2*
>(effVsRunList.At(
GetEffIndex(0, icount)));
555 if ( ! histo )
continue;
556 TH1* chEff = histo->ProjectionX(Form(
"effEvolutionCh%i",11+ich), ich+1, ich+1);
557 chEff->SetTitle(Form(
"%s for chamber %i", histo->GetTitle(), 11+ich));
558 chEff->GetYaxis()->SetRangeUser(0.9,1.);
559 chEff->SetStats(kFALSE);
560 chEff->GetYaxis()->SetTitle(
"Trigger chamber efficiency");
561 TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
562 copyEff->SetLineColor(color[icount]);
563 copyEff->SetMarkerColor(color[icount]);
564 copyEff->SetMarkerStyle(markStyle[icount]);
565 leg->AddEntry(copyEff, countTypeName[icount+1].Data(),
"lp");
572 for ( Int_t iel=1; iel<3; iel++ ) {
573 for ( Int_t ich=0; ich<
kNch; ich++ ) {
574 Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff;
576 canName = Form(
"trigEff%sCh%i", elementName[iel].Data(), 11+ich);
577 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
578 can->SetRightMargin(0.14);
579 TH2* histo =
static_cast<TH2*
>(effVsRunList.At(
GetEffIndex(iel, icount,ich)));
580 if ( ! histo )
continue;
581 histo->SetStats(kFALSE);
582 histo->GetYaxis()->SetTitle(elementName[iel].Data());
583 histo->DrawCopy(
"COLZ");
591 void MaskTrending ( TObjArray runNumArray, TString defaultStorage, TList& outCanList, TList& outList )
597 TObjArray maskedList(8);
598 TObjArray auxList(8);
600 TString histoName =
"", histoTitle =
"";
601 for(Int_t icath=0; icath<2; icath++){
602 TString cathName = ( icath==0 ) ?
"bendPlane" :
"nonBendPlane";
603 for(Int_t ich=0; ich<
kNch; ich++){
604 histoName = Form(
"%sMaskCh%i", cathName.Data(), 11+ich);
605 histoTitle = Form(
"Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
606 TH2* histo =
new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
607 histo->GetYaxis()->SetTitle(
"Board Id");
608 histo->SetOption(
"COLZ");
609 Int_t imask = 2*ich + icath;
610 maskedList.AddAt(histo, imask);
611 auxList.AddAt(histo->Clone(Form(
"%s_aux",histoName.Data())), imask);
615 TArrayS xyPatternAll[2];
616 for(Int_t icath=0; icath<2; icath++){
617 xyPatternAll[icath].Set(
kNch);
618 xyPatternAll[icath].Reset(0xFFFF);
621 TList* ocdbFileList = 0x0;
622 Int_t previousRun = -1;
623 AliMUONDigitMaker* digitMaker = 0x0;
624 AliMUONDigitStoreV2R digitStore;
626 AliMUONCalibrationData* calibData = 0x0;
627 AliMUONTriggerUtilities* trigUtilities = 0x0;
628 for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
629 TString runNumString = runNumArray.At(irun)->GetName();
630 Int_t runNumber = runNumString.Atoi();
633 AliCDBManager::Instance()->SetRun(runNumber);
635 if ( ! digitMaker ) {
636 digitMaker =
new AliMUONDigitMaker(kFALSE);
638 for ( Int_t iboard=1; iboard<=234; iboard++ ) {
639 digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
643 if ( ! ocdbFileList ) ocdbFileList =
GetOCDBList(
"MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
646 calibData =
new AliMUONCalibrationData (runNumber);
647 delete trigUtilities;
648 trigUtilities =
new AliMUONTriggerUtilities (calibData);
651 previousRun = runNumber;
653 TIter next(digitStore.CreateIterator());
654 AliMUONVDigit* dig = 0x0;
655 while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
656 Int_t icath = dig->Cathode();
657 Int_t detElemId = dig->DetElemId();
658 Int_t ich = detElemId/100-11;
659 Int_t iboard = dig->ManuId();
660 Int_t imask = 2*ich + icath;
661 static_cast<TH2*
>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
662 static_cast<TH2*
>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(Double_t)trigUtilities->IsMasked(*dig));
666 delete trigUtilities;
669 TString canName =
"";
670 for ( Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
671 TH2* histo =
static_cast<TH2*
>(maskedList.At(imask));
672 histo->Divide(static_cast<TH2*>(auxList.At(imask)));
676 canName = Form(
"%sCan", histo->GetName());
677 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
678 can->SetRightMargin(0.14);
679 histo->SetStats(kFALSE);
680 histo->DrawCopy(
"COLZ");
686 Bool_t
CheckPattern ( TString trigName, TObjArray* keepArray, TObjArray* rejectArray )
689 for ( Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
690 if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) )
return kFALSE;
693 for ( Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
694 if ( trigName.Contains(keepArray->At(ipat)->GetName() ) )
return kTRUE;
697 return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
701 TObjArray*
BuildListOfTrigger (
const TObjArray* triggerArray, TString keepPattern =
"", TString rejectPattern=
"OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
704 TObjArray* selectedList =
new TObjArray();
705 selectedList->SetOwner();
706 TObjArray* rejectArray = rejectPattern.Tokenize(
",");
707 TObjArray* keepArray = keepPattern.Tokenize(
",");
709 for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
710 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
711 if (
CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(
new TObjString(currTrigName.Data()));
725 TString foundName =
"";
726 for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
727 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
728 TObjArray* array = currTrigName.Tokenize(
"-");
729 TString collisionType = array->At(1)->GetName();
731 collisionType.Append(
"-");
732 collisionType.Prepend(
"-");
733 if ( checkTrigger.Contains(collisionType.Data()) ) {
734 foundName = currTrigName;
743 void ScalerTrending ( TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList& outCanList, TList& outList )
749 TFile *file = TFile::Open(mergedFileName.Data());
750 AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny(
"MUON_QA"))->FindObjectAny(
"eventCounters");
753 TString triggerListName = ccol->GetKeyWords(
"trigger");
755 TObjArray selectedTriggerArray, selectedL0TriggerArray;
756 selectedTriggerArray.SetOwner();
757 selectedL0TriggerArray.SetOwner();
759 const Int_t nScaler = 3;
760 TString sScaler[nScaler] = {
"L0B",
"L2A",
"L0BRATE"};
761 enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
762 Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
764 TObjArray hFromScalers;
768 TString sHistName, sHistNameFull, sTitleName;
769 Int_t nRuns = runNumArray.GetEntries();
775 for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
777 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
778 Int_t runNr = sRunNr.Atoi();
779 AliAnalysisTriggerScalers triggerScaler(runNr);
780 AliTriggerConfiguration* tc =
static_cast<AliTriggerConfiguration*
>(triggerScaler.GetOCDBObject(
"GRP/CTP/Config",runNr));
781 const TObjArray& trClasses = tc->GetClasses();
785 for ( Int_t itype=0; itype<2; itype++ ) {
786 TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
787 TString matchTrig = ( itype == 0 ) ?
"" :
"C0TVX";
791 for ( Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
793 TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
794 if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) )
continue;
795 if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(
new TObjString(currTrigName));
798 for ( Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
800 if ( itype == 1 && iScaler != kL0B )
continue;
803 TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data());
805 sHistName = Form(
"%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
806 sHistNameFull = Form(
"Scalers_%s",sHistName.Data());
808 TH1* hist = (TH1*) hFromScalers.FindObject(sHistNameFull);
810 hist =
new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(Double_t)nRuns);
811 hist->SetDirectory(0);
813 hist->SetMaximum(maxScaler[0]);
814 hFromScalers.AddLast(hist);
815 hOutput.AddLast(hist);
816 if ( iScaler == kL2A ) {
817 sHistNameFull =
"QA_" + sHistName;
818 hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
821 Double_t *tab = (Double_t*) graph->GetY();
822 if ( tab ) hist->SetBinContent(ibin,tab[0]);
823 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
827 if ( iScaler != kL2A )
continue;
828 TH1* histCounters =
static_cast<TH1*
>(ccol->Get(
"run",Form(
"run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
829 sHistNameFull = sHistNameFull =
"QA_" + sHistName;
830 hist = (TH1*) hFromQA.FindObject(sHistNameFull);
831 if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
832 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
840 if ( selectedTriggerArray.GetEntries() == 0 ) {
841 printf(
"No trigger selected from trigger list %s\n",triggerListName.Data());
844 printf(
"Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
846 printf(
"Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
850 for ( Int_t itype=0; itype<2; itype++ ) {
851 TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
852 for ( Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
853 TH1* histo =
static_cast<TH1*
> ( currList->At(ihisto) );
854 if (!histo)
continue;
856 for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
857 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
859 TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
860 if ( ! binLabel.IsNull() )
continue;
861 histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
863 histo->SetStats(kFALSE);
869 const Int_t nHisto = 3;
870 TString sHisto[nHisto] = {
"L0BoverL0BC0TVX",
"L2AoverL0B",
"L2AQAoverSCALERS"};
871 TString sTitleHisto[nHisto] = {
"L0B trigger / L0BC0TVX",
"L2A / L0B",
"L2A from QA / L2A from SCALERS"};
875 for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
877 sHistNameFull = Form(
"Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
878 TH1* histo1 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
879 if (!histo1)
continue;
883 TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
886 sHistNameFull = Form(
"Scalers_%s_L0B",sL0Trig.Data());
888 TH1* histo0 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
890 sHistNameFull = Form(
"%s_%s",sHisto[0].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
891 TH1* histo10 = (TH1*) histo1->Clone(sHistNameFull);
892 histo10->SetTitle(sTitleHisto[0].Data());
894 histo10->Divide(histo0);
895 histo10->SetMaximum(10);
896 histo10->SetMinimum(1e-5);
898 hOutput.AddLast(histo10);
904 sHistNameFull = Form(
"Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
905 TH1* histo2 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
906 if (!histo2)
continue;
908 sHistNameFull = Form(
"%s_%s",sHisto[1].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
909 TH1* histo3 = (TH1*) histo2->Clone(sHistNameFull);
910 histo3->SetTitle(sTitleHisto[1]);
912 histo3->Divide(histo1);
913 histo3->SetMaximum(1.2);
914 histo3->SetMinimum(1e-5);
916 hOutput.AddLast(histo3);
919 sHistNameFull = Form(
"QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
920 TH1* histo4 =
static_cast<TH1*
> ( hFromQA.FindObject(sHistNameFull) );
921 if (!histo4)
continue;
923 sHistNameFull = Form(
"%s_%s",sHisto[2].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
924 TH1* histo5 = (TH1*) histo4->Clone(sHistNameFull);
925 histo5->SetTitle(sTitleHisto[2]);
927 histo5->Divide(histo2);
928 histo5->SetMaximum(1.2);
929 histo5->SetMinimum(5e-1);
931 hOutput.AddLast(histo5);
935 const Int_t nCanvases = nScaler + nHisto;
936 TString sCanvases[nCanvases];
937 for (Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
938 for (Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
941 for ( Int_t iCan = 0; iCan < nCanvases; iCan++) {
942 TCanvas* canvas =
new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
943 TLegend* leg =
new TLegend(0.72,0.7,0.9,0.85);
944 leg->SetBorderSize(1);
945 if ( iCan != 4 ) canvas->SetLogy();
946 TString optDraw =
"e";
950 for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
952 if ( iCan < nScaler ) sHistNameFull = Form(
"Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
953 else sHistNameFull = Form(
"%s_%s",sCanvases[iCan].Data(),selectedTriggerArray.At(iTrig)->GetName());
954 TH1* histo1 =
static_cast<TH1*
> ( hOutput.FindObject(sHistNameFull) );
955 if (!histo1)
continue;
957 if ( icolor == 10 ) icolor++;
958 histo1->SetLineColor(icolor++);
959 histo1->Draw(optDraw);
962 leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),
"l");
967 outCanList.Add(canvas);
974 void trigEffQA(TString fileListName, TString outFilename =
"", TString defaultStorage =
"raw://", Bool_t doScalers = kFALSE, TString trackerQAmergedOut=
"QAresults_merged.root")
977 ifstream inFile(fileListName.Data());
978 TObjArray fileNameArray, runNumArray;
979 fileNameArray.SetOwner();
980 runNumArray.SetOwner();
981 TString currString =
"";
982 if (inFile.is_open()) {
983 while (! inFile.eof() ) {
984 currString.ReadLine(inFile);
985 if ( ! currString.Contains(
".root") ||
986 currString.BeginsWith(
"#") )
continue;
987 fileNameArray.AddLast(
new TObjString(currString.Data()));
989 runNumArray.AddLast(
new TObjString(Form(
"%i",runNum)));
994 printf(
"Fatal: cannot open input file %s\n",fileListName.Data());
1004 TList outCanList, outList;
1005 TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1007 MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1009 if ( gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1010 printf(
"Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1013 ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1018 delete finalFileNameArray;
1020 if ( outFilename.IsNull() )
return;
1022 TString outCanName = outFilename;
1023 outCanName.ReplaceAll(
".root",
".pdf");
1024 for ( Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1025 TString canName = outCanName;
1026 if ( ican == 0 ) canName.Append(
"(");
1027 else if ( ican == outCanList.GetEntries()-1 ) canName.Append(
")");
1028 static_cast<TCanvas*
>(outCanList.At(ican))->Print(canName.Data());
1032 if ( outCanName.Contains(
".ps") || outCanName.Contains(
".eps") ) {
1033 gSystem->Exec(Form(
"epstopdf %s", outCanName.Data()));
1034 gSystem->Exec(Form(
"rm %s", outCanName.Data()));
1037 TFile* outFile =
new TFile(outFilename.Data(),
"recreate");
void SetRunAxisRange(TAxis *axis)
Bool_t SetAndCheckOCDB(TString defaultStorage)
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)
TObjArray * ChangeFilenames(const TObjArray &fileNameArray)
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)
void trigEffQA(TString fileListName, TString outFilename="", TString defaultStorage="raw://", Bool_t doScalers=kFALSE, TString trackerQAmergedOut="QAresults_merged.root")