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;
242 delete [] auxBinomial;
244 Double_t* effErr =
GetProdErr(effProd, -1, 2);
246 effErrBinomial[0] += effErr[0];
247 effErrBinomial[1] += effErr[1]*effErr[1];
251 delete [] currEffErr44;
253 effErrBinomial[1] = TMath::Sqrt(effErrBinomial[1]);
255 return effErrBinomial;
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 checkFile.ReplaceAll(
"folder=",
"");
356 checkFile.ReplaceAll(
"Folder=",
"");
357 TFile*
file = TFile::Open(checkFile.Data());
359 printf(
"Cannot access test file: %s\n", checkFile.Data());
367 printf(
"Tried to set the default storage, but something went wrong.\n");
371 if ( ! isOk ) printf(
"Please check path %s\n",defaultStorage.Data());
380 if ( ! fileList )
return kTRUE;
381 for ( Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
382 TString filename =
static_cast<TObjString*
>(fileList->At(ifile))->GetString();
383 filename.ReplaceAll(
"Run",
"");
384 TObjArray* array = filename.Tokenize(
"_");
385 Int_t firstRun =
static_cast<TObjString*
>(array->At(0))->GetString().Atoi();
386 Int_t lastRun =
static_cast<TObjString*
>(array->At(1))->GetString().Atoi();
388 Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
389 Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
390 if ( isCurrRunInside != isPreviousRunInside )
return kTRUE;
396 void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList& outCanList, TList& outList)
399 TString elementName[3] = {
"Chamber",
"RPC",
"Board" };
400 TString countTypeName[4] = {
"allTracks",
"bendPlane",
"nonBendPlane",
"bothPlanes" };
402 TString filename =
"", effName =
"", effTitle =
"";
405 Double_t effValues[3][2*
kNch];
406 const Int_t kNgraphs =
kNch*3*2+3;
407 TObjArray effList(kNgraphs);
409 const Int_t kNeffVsRun = kNgraphs+1;
410 TObjArray effVsRunList(kNeffVsRun);
412 effName =
"totalEffEvolution";
413 effTitle =
"Multinomial probability of firing at least 3/4 chambers";
414 TH1D* totalEff =
new TH1D(effName.Data(), effTitle.Data(), 1, 0., 1.);
415 effVsRunList.AddAt(totalEff, kNeffVsRun-1);
417 TString runNumString =
"";
418 for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
420 runNumString = runNumArray.At(irun)->GetName();
423 for ( Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
424 filename = fileNameArray.At(ifile)->GetName();
425 if ( filename.Contains(runNumString.Data()) )
break;
428 if ( filename.Contains(
"alien://") && ! gGrid ) gGrid->Connect(
"alien://");
435 TFile*
file = TFile::Open(filename.Data());
437 printf(
"Warning: cannot find %s\n", filename.Data());
441 TList* trigEffList = (TList*)file->FindObjectAny(
"triggerChamberEff");
442 if ( ! trigEffList ) printf(
"Warning: histo list not found in %s. Check directly in file\n", filename.Data());
443 if ( trigEffList->GetEntries() == 0 ) {
444 printf(
"Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
449 for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
450 effName = countTypeName[icount] +
"Count" + elementName[0];
452 histoDen =
GetHisto(effName, file, trigEffList);
456 TH1* histoNum =
GetHisto(effName, file, trigEffList);
457 TGraphAsymmErrors* graph =
new TGraphAsymmErrors(histoNum, histoDen,
"e0");
458 effName.ReplaceAll(
"Count",
"Eff");
459 graph->SetName(effName.Data());
465 printf(
"Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
470 AliMUONTriggerChamberEfficiency trigChEff(filename);
471 for ( Int_t iel=1; iel<3; iel++ ) {
472 for ( Int_t ich=0; ich<
kNch; ich++ ) {
473 for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
474 TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
475 effList.AddAt(obj->Clone(Form(
"%s_cloned",obj->GetName())),
GetEffIndex(iel, icount, ich));
481 for ( Int_t iel=0; iel<3; iel++ ) {
482 for ( Int_t ich=0; ich<
kNch; ich++ ) {
483 for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
484 TGraphAsymmErrors* graph =
static_cast<TGraphAsymmErrors*
>(effList.At(
GetEffIndex(iel, icount, ich)));
485 Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
486 for ( Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
487 Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
489 graph->GetPoint(currPoint, xpt, ypt);
490 effValues[icount][ich] = ypt;
492 TH2* effHisto =
static_cast<TH2*
>(effVsRunList.At(ihisto));
494 effName = Form(
"effEvolution%s%s", countTypeName[icount+1].Data(), elementName[iel].Data());
495 effTitle = Form(
"Trigger chamber efficiency vs run");
497 effName += Form(
"Ch%i", 11+ich);
498 effTitle += Form(
" for chamber %i", 11+ich);
500 effHisto =
new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(Double_t)graph->GetN());
501 effVsRunList.AddAt(effHisto, ihisto);
503 Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
504 Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
505 Int_t binx, biny, binz;
506 effHisto->GetBinXYZ(currBin, binx, biny, binz);
507 effHisto->SetBinError(binx, biny, err);
508 effValues[icount][ich+
kNch] = err;
512 if ( iel > 0 )
continue;
513 Double_t* binomialEff =
GetBinomial(effValues[0], effValues[1], effValues[2]);
514 Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
519 totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
520 delete [] binomialEff;
525 for ( Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
526 TH1* histo =
static_cast<TH1*
>(effVsRunList.At(ihisto));
527 if ( ! histo )
continue;
533 TString canName =
"totalEff";
534 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
535 TH1* totEff = (TH1*)effVsRunList.At(kNeffVsRun-1);
536 totEff->GetYaxis()->SetRangeUser(0.9,1.05);
537 totEff->GetYaxis()->SetTitle(
"Probability to satisfy trigger conditions (3/4)");
538 totEff->SetStats(kFALSE);
542 Int_t
color[3] = {kBlack, kRed, kBlue};
543 Int_t markStyle[3] = {20, 24, 26};
546 for ( Int_t ich=0; ich<
kNch; ich++ ) {
547 canName = Form(
"trigEffCh%i", 11+ich);
548 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
550 leg =
new TLegend(0.6, 0.2, 0.9, 0.4);
551 leg->SetBorderSize(1);
553 TString drawOpt =
"e";
554 for(Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
556 TH2* histo =
static_cast<TH2*
>(effVsRunList.At(
GetEffIndex(0, icount)));
557 if ( ! histo )
continue;
558 TH1* chEff = histo->ProjectionX(Form(
"effEvolutionCh%i",11+ich), ich+1, ich+1);
559 chEff->SetTitle(Form(
"%s for chamber %i", histo->GetTitle(), 11+ich));
560 chEff->GetYaxis()->SetRangeUser(0.9,1.);
561 chEff->SetStats(kFALSE);
562 chEff->GetYaxis()->SetTitle(
"Trigger chamber efficiency");
563 TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
564 copyEff->SetLineColor(color[icount]);
565 copyEff->SetMarkerColor(color[icount]);
566 copyEff->SetMarkerStyle(markStyle[icount]);
567 leg->AddEntry(copyEff, countTypeName[icount+1].Data(),
"lp");
574 for ( Int_t iel=1; iel<3; iel++ ) {
575 for ( Int_t ich=0; ich<
kNch; ich++ ) {
576 Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff;
578 canName = Form(
"trigEff%sCh%i", elementName[iel].Data(), 11+ich);
579 can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
580 can->SetRightMargin(0.14);
581 TH2* histo =
static_cast<TH2*
>(effVsRunList.At(
GetEffIndex(iel, icount,ich)));
582 if ( ! histo )
continue;
583 histo->SetStats(kFALSE);
584 histo->GetYaxis()->SetTitle(elementName[iel].Data());
586 if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
587 histo->DrawCopy(
"COLZ");
595 void MaskTrending ( TObjArray runNumArray, TString defaultStorage, TList& outCanList, TList& outList )
601 TObjArray maskedList(8);
602 TObjArray auxList(8);
604 TString histoName =
"", histoTitle =
"";
605 for(Int_t icath=0; icath<2; icath++){
606 TString cathName = ( icath==0 ) ?
"bendPlane" :
"nonBendPlane";
607 for(Int_t ich=0; ich<
kNch; ich++){
608 histoName = Form(
"%sMaskCh%i", cathName.Data(), 11+ich);
609 histoTitle = Form(
"Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
610 TH2* histo =
new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
611 histo->GetYaxis()->SetTitle(
"Board Id");
613 Int_t imask = 2*ich + icath;
614 maskedList.AddAt(histo, imask);
615 auxList.AddAt(histo->Clone(Form(
"%s_aux",histoName.Data())), imask);
619 TArrayS xyPatternAll[2];
620 for(Int_t icath=0; icath<2; icath++){
621 xyPatternAll[icath].Set(
kNch);
622 xyPatternAll[icath].Reset(0xFFFF);
625 TList* ocdbFileList = 0x0;
626 Int_t previousRun = -1;
627 AliMUONDigitMaker* digitMaker = 0x0;
628 AliMUONDigitStoreV2R digitStore;
630 AliMUONCalibrationData* calibData = 0x0;
631 AliMUONTriggerUtilities* trigUtilities = 0x0;
632 for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
633 TString runNumString = runNumArray.At(irun)->GetName();
634 Int_t runNumber = runNumString.Atoi();
637 AliCDBManager::Instance()->SetRun(runNumber);
639 if ( ! digitMaker ) {
640 digitMaker =
new AliMUONDigitMaker(kFALSE);
642 for ( Int_t iboard=1; iboard<=234; iboard++ ) {
643 digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
647 if ( ! ocdbFileList ) ocdbFileList =
GetOCDBList(
"MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
650 calibData =
new AliMUONCalibrationData (runNumber);
651 delete trigUtilities;
652 trigUtilities =
new AliMUONTriggerUtilities (calibData);
655 previousRun = runNumber;
657 TIter next(digitStore.CreateIterator());
658 AliMUONVDigit* dig = 0x0;
659 while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
660 Int_t icath = dig->Cathode();
661 Int_t detElemId = dig->DetElemId();
662 Int_t ich = detElemId/100-11;
663 Int_t iboard = dig->ManuId();
664 Int_t imask = 2*ich + icath;
665 static_cast<TH2*
>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
666 static_cast<TH2*
>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(Double_t)trigUtilities->IsMasked(*dig));
670 delete trigUtilities;
673 TString canName =
"";
674 for ( Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
675 TH2* histo =
static_cast<TH2*
>(maskedList.At(imask));
676 histo->Divide(static_cast<TH2*>(auxList.At(imask)));
680 canName = Form(
"%sCan", histo->GetName());
681 TCanvas* can =
new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
682 can->SetRightMargin(0.14);
683 histo->SetStats(kFALSE);
684 if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
685 histo->DrawCopy(
"COLZ");
691 Bool_t
CheckPattern ( TString trigName, TObjArray* keepArray, TObjArray* rejectArray )
694 for ( Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
695 if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) )
return kFALSE;
698 for ( Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
699 if ( trigName.Contains(keepArray->At(ipat)->GetName() ) )
return kTRUE;
702 return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
706 TObjArray*
BuildListOfTrigger (
const TObjArray* triggerArray, TString keepPattern =
"", TString rejectPattern=
"OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
709 TObjArray* selectedList =
new TObjArray();
710 selectedList->SetOwner();
711 TObjArray* rejectArray = rejectPattern.Tokenize(
",");
712 TObjArray* keepArray = keepPattern.Tokenize(
",");
714 for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
715 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
716 if (
CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(
new TObjString(currTrigName.Data()));
730 TString foundName =
"";
731 for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
732 TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
733 TObjArray* array = currTrigName.Tokenize(
"-");
734 TString collisionType = array->At(1)->GetName();
736 collisionType.Append(
"-");
737 collisionType.Prepend(
"-");
738 if ( checkTrigger.Contains(collisionType.Data()) ) {
739 foundName = currTrigName;
748 void ScalerTrending ( TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList& outCanList, TList& outList )
754 TFile *
file = TFile::Open(mergedFileName.Data());
755 AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny(
"MUON_QA"))->FindObjectAny(
"eventCounters");
758 TString triggerListName = ccol->GetKeyWords(
"trigger");
760 TObjArray selectedTriggerArray, selectedL0TriggerArray;
761 selectedTriggerArray.SetOwner();
762 selectedL0TriggerArray.SetOwner();
764 const Int_t nScaler = 3;
765 TString sScaler[nScaler] = {
"L0B",
"L2A",
"L0BRATE"};
766 enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
767 Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
769 TObjArray hFromScalers;
773 TString sHistName, sHistNameFull, sTitleName;
774 Int_t nRuns = runNumArray.GetEntries();
780 for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
782 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
783 Int_t runNr = sRunNr.Atoi();
784 AliAnalysisTriggerScalers triggerScaler(runNr);
785 AliTriggerConfiguration* tc =
static_cast<AliTriggerConfiguration*
>(triggerScaler.GetOCDBObject(
"GRP/CTP/Config",runNr));
786 const TObjArray& trClasses = tc->GetClasses();
790 for ( Int_t itype=0; itype<2; itype++ ) {
791 TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
792 TString matchTrig = ( itype == 0 ) ?
"" :
"C0TVX";
796 for ( Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
798 TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
799 if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) )
continue;
800 if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(
new TObjString(currTrigName));
803 for ( Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
805 if ( itype == 1 && iScaler != kL0B )
continue;
808 TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data());
810 sHistName = Form(
"%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
811 sHistNameFull = Form(
"Scalers_%s",sHistName.Data());
813 TH1* hist = (TH1*) hFromScalers.FindObject(sHistNameFull);
815 hist =
new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(Double_t)nRuns);
816 hist->SetDirectory(0);
818 hist->SetMaximum(maxScaler[0]);
819 hFromScalers.AddLast(hist);
820 hOutput.AddLast(hist);
821 if ( iScaler == kL2A ) {
822 sHistNameFull =
"QA_" + sHistName;
823 hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
826 Double_t *tab = (Double_t*) graph->GetY();
827 if ( tab ) hist->SetBinContent(ibin,tab[0]);
828 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
832 if ( iScaler != kL2A )
continue;
833 TH1* histCounters =
static_cast<TH1*
>(ccol->Get(
"run",Form(
"run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
834 sHistNameFull = sHistNameFull =
"QA_" + sHistName;
835 hist = (TH1*) hFromQA.FindObject(sHistNameFull);
836 if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
837 hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
845 if ( selectedTriggerArray.GetEntries() == 0 ) {
846 printf(
"No trigger selected from trigger list %s\n",triggerListName.Data());
849 printf(
"Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
851 printf(
"Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
855 for ( Int_t itype=0; itype<2; itype++ ) {
856 TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
857 for ( Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
858 TH1* histo =
static_cast<TH1*
> ( currList->At(ihisto) );
859 if (!histo)
continue;
861 for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
862 TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
864 TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
865 if ( ! binLabel.IsNull() )
continue;
866 histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
868 histo->SetStats(kFALSE);
874 const Int_t nHisto = 3;
875 TString sHisto[nHisto] = {
"L0BoverL0BC0TVX",
"L2AoverL0B",
"L2AQAoverSCALERS"};
876 TString sTitleHisto[nHisto] = {
"L0B trigger / L0BC0TVX",
"L2A / L0B",
"L2A from QA / L2A from SCALERS"};
880 for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
882 sHistNameFull = Form(
"Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
883 TH1* histo1 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
884 if (!histo1)
continue;
888 TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
891 sHistNameFull = Form(
"Scalers_%s_L0B",sL0Trig.Data());
893 TH1* histo0 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
895 sHistNameFull = Form(
"%s_%s",sHisto[0].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
896 TH1* histo10 = (TH1*) histo1->Clone(sHistNameFull);
897 histo10->SetTitle(sTitleHisto[0].Data());
899 histo10->Divide(histo0);
900 histo10->SetMaximum(10);
901 histo10->SetMinimum(1e-5);
903 hOutput.AddLast(histo10);
909 sHistNameFull = Form(
"Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
910 TH1* histo2 =
static_cast<TH1*
> ( hFromScalers.FindObject(sHistNameFull) );
911 if (!histo2)
continue;
913 sHistNameFull = Form(
"%s_%s",sHisto[1].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
914 TH1* histo3 = (TH1*) histo2->Clone(sHistNameFull);
915 histo3->SetTitle(sTitleHisto[1]);
917 histo3->Divide(histo1);
918 histo3->SetMaximum(1.2);
919 histo3->SetMinimum(1e-5);
921 hOutput.AddLast(histo3);
924 sHistNameFull = Form(
"QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
925 TH1* histo4 =
static_cast<TH1*
> ( hFromQA.FindObject(sHistNameFull) );
926 if (!histo4)
continue;
928 sHistNameFull = Form(
"%s_%s",sHisto[2].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
929 TH1* histo5 = (TH1*) histo4->Clone(sHistNameFull);
930 histo5->SetTitle(sTitleHisto[2]);
932 histo5->Divide(histo2);
933 histo5->SetMaximum(1.2);
934 histo5->SetMinimum(5e-1);
936 hOutput.AddLast(histo5);
940 const Int_t nCanvases = nScaler + nHisto;
941 TString sCanvases[nCanvases];
942 for (Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
943 for (Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
946 for ( Int_t iCan = 0; iCan < nCanvases; iCan++) {
947 TCanvas* canvas =
new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
948 TLegend* leg =
new TLegend(0.72,0.7,0.9,0.85);
949 leg->SetBorderSize(1);
950 if ( iCan != 4 ) canvas->SetLogy();
951 TString optDraw =
"e";
955 for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
957 if ( iCan < nScaler ) sHistNameFull = Form(
"Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
958 else sHistNameFull = Form(
"%s_%s",sCanvases[iCan].Data(),selectedTriggerArray.At(iTrig)->GetName());
959 TH1* histo1 =
static_cast<TH1*
> ( hOutput.FindObject(sHistNameFull) );
960 if (!histo1)
continue;
962 if ( icolor == 10 ) icolor++;
963 histo1->SetLineColor(icolor++);
964 histo1->Draw(optDraw);
967 leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),
"l");
972 outCanList.Add(canvas);
979 void trigEffQA(TString fileListName, TString outFilename =
"", TString defaultStorage =
"raw://", Bool_t doScalers = kFALSE, TString trackerQAmergedOut=
"QAresults_merged.root")
982 ifstream inFile(fileListName.Data());
983 TObjArray fileNameArray, runNumArray;
984 fileNameArray.SetOwner();
985 runNumArray.SetOwner();
986 TString currString =
"";
987 if (inFile.is_open()) {
988 while (! inFile.eof() ) {
989 currString.ReadLine(inFile);
990 if ( ! currString.Contains(
".root") ||
991 currString.BeginsWith(
"#") )
continue;
992 fileNameArray.AddLast(
new TObjString(currString.Data()));
994 runNumArray.AddLast(
new TObjString(Form(
"%i",runNum)));
999 printf(
"Fatal: cannot open input file %s\n",fileListName.Data());
1009 TList outCanList, outList;
1010 TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1012 MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1014 if ( gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1015 printf(
"Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1018 ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1023 delete finalFileNameArray;
1025 if ( outFilename.IsNull() )
return;
1027 TString outCanName = outFilename;
1028 outCanName.ReplaceAll(
".root",
".pdf");
1029 for ( Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1030 TString canName = outCanName;
1031 if ( ican == 0 ) canName.Append(
"(");
1032 else if ( ican == outCanList.GetEntries()-1 ) canName.Append(
")");
1033 static_cast<TCanvas*
>(outCanList.At(ican))->Print(canName.Data());
1037 if ( outCanName.Contains(
".ps") || outCanName.Contains(
".eps") ) {
1038 gSystem->Exec(Form(
"epstopdf %s", outCanName.Data()));
1039 gSystem->Exec(Form(
"rm %s", outCanName.Data()));
1042 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)
TString prod[]
total number of productions
void trigEffQA(TString fileListName, TString outFilename="", TString defaultStorage="raw://", Bool_t doScalers=kFALSE, TString trackerQAmergedOut="QAresults_merged.root")