AliPhysics  e6c8d43 (e6c8d43)
trigEffQA.C
Go to the documentation of this file.
1 
2 #if !defined(__CINT__) || defined(__MAKECINT__)
3 // ROOT includes
4 #include "TFile.h"
5 #include "TH1.h"
6 #include "TH2.h"
7 #include "TGraphAsymmErrors.h"
8 #include "TSystem.h"
9 #include "Riostream.h"
10 #include "TCanvas.h"
11 #include "TStyle.h"
12 #include "TROOT.h"
13 #include "TLegend.h"
14 #include "TMath.h"
15 #include "TObjArray.h"
16 #include "TList.h"
17 #include "TObjString.h"
18 #include "TString.h"
19 #include "TGrid.h"
20 #include "TArrayD.h"
21 #include "TArrayI.h"
22 #include "TMap.h"
23 #include "TGridResult.h"
24 #include "TF1.h"
25 #include "TPad.h"
26 #include "TLatex.h"
27 
28 #include "AliCDBManager.h"
29 #include "AliCDBEntry.h"
30 #include "AliCDBPath.h"
31 #include "AliCDBStorage.h"
32 #include "AliMTRChEffAnalysis.h"
33 #include "AliMUONTriggerUtilities.h"
34 #include "AliMUONDigitMaker.h"
35 #include "AliMUONVDigit.h"
36 #include "AliMUONDigitStoreV2R.h"
37 #include "AliMUONCalibrationData.h"
38 #include "AliAnalysisTriggerScalers.h"
39 #include "AliCounterCollection.h"
40 #include "AliTriggerConfiguration.h"
41 #endif
42 
43 const Int_t kNch = 4;
44 const Double_t kZero = 1.e-7; // Avoid problems when comparing to 0.
45 
46 //_____________________________________________________________________________
47 void SetMyStyle()
48 {
50  gStyle->SetCanvasColor(10);
51  gStyle->SetFrameFillColor(10);
52  gStyle->SetStatColor(10);
53  gStyle->SetFillColor(10);
54  gStyle->SetTitleFillColor(10);
55 
56  gStyle->SetTitleXSize(0.03);
57  gStyle->SetTitleXOffset(1.1);
58  gStyle->SetTitleYSize(0.03);
59  gStyle->SetTitleYOffset(1.9);
60 
61  gStyle->SetMarkerSize(0.7);
62  gStyle->SetHistLineWidth(2);
63 
64  gStyle->SetPadLeftMargin(0.12);
65  gStyle->SetPadRightMargin(0.04);
66  gStyle->SetPadBottomMargin(0.12);
67  gStyle->SetPadTopMargin(0.03);
68 
69  gROOT->ForceStyle();
70 }
71 
72 //_____________________________________________________________________________
73 Bool_t IsRunNum ( TString stringToken )
74 {
75  return ( stringToken.IsDigit() && stringToken.Length()>=6 && stringToken.Length()<=9 );
76 }
77 
78 
79 //_____________________________________________________________________________
80 void SetRunAxisRange ( TH1* histo, TString runAxis = "X" )
81 {
83  runAxis.ToUpper();
84  TAxis* axis = histo->GetXaxis();
85  if ( runAxis == "Y" ) axis = histo->GetYaxis();
86  else if ( runAxis == "Z" ) axis = histo->GetZaxis();
87  histo->LabelsOption("v",runAxis.Data());
88  axis->SetLabelSize(0.02);
89  for ( Int_t ibin=1; ibin<=axis->GetNbins(); ibin++ ) {
90  TString binLabel = axis->GetBinLabel(ibin);
91  if ( ! binLabel.IsNull()) continue;
92  axis->SetRange(1, ibin-1);
93  return;
94  }
95 }
96 
97 //_____________________________________________________________________________
99 {
101  TObjArray* array = filePath.Tokenize("/");
102  array->SetOwner();
103  TString auxString = "";
104  Int_t runNum = -1;
105  for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
106  auxString = array->At(ientry)->GetName();
107  if ( IsRunNum(auxString) ) {
108  runNum = auxString.Atoi();
109  break;
110  }
111  }
112  delete array;
113 
114  if ( runNum < 0 ) {
115  array = auxString.Tokenize("_");
116  array->SetOwner();
117  auxString = array->Last()->GetName();
118  auxString.ReplaceAll(".root","");
119  if ( IsRunNum(auxString) ) runNum = auxString.Atoi();
120  delete array;
121  }
122 
123  return runNum;
124 }
125 
126 //_____________________________________________________________________________
127 Double_t* GetProdErr(Double_t* effErr, Int_t exclude, Int_t nFactors = kNch)
128 {
130  Double_t prod = 1.;
131  Double_t relErr = 0., relProdErrSquare = 0.;
132  for ( Int_t iprod=0; iprod<nFactors; iprod++ ) {
133  if ( iprod == exclude ) continue;
134  prod *= effErr[iprod];
135  relErr = ( effErr[iprod] > kZero ) ? effErr[iprod+nFactors]/effErr[iprod] : 0.;
136  relProdErrSquare += relErr*relErr;
137  //printf("%f +- %f ", effErr[iprod], effErr[iprod+nFactors]); // alBER TO CUT
138  }
139  Double_t* prodErr = new Double_t[2];
140  prodErr[0] = prod;
141  prodErr[1] = prod*TMath::Sqrt(relProdErrSquare);
142  //printf("-> %f %f\n", prodErr[0], prodErr[1]); // REMEMBER TO CUT
143  return prodErr;
144 }
145 
146 
147 //_____________________________________________________________________________
148 Double_t* GetConditionalEffErr(Double_t* effErr1, Double_t* effErr2, Double_t* effErrBoth, Int_t exclude = -1)
149 {
151  Double_t* effErr = new Double_t[2*kNch];
152  for ( Int_t ich=0; ich<kNch; ich++ ) {
153  if ( ich == exclude ) {
154  effErr[ich] = ( effErr1[ich] < 1. ) ? ( effErr2[ich] - effErrBoth[ich] ) / ( 1. - effErr1[ich] ) : 0.;
155  effErr[ich+kNch] = 0;
156  if ( effErr1[ich] < 1. ) {
157  Double_t err2 = effErr2[ich+kNch] / ( 1. - effErr1[ich] );
158  Double_t errBoth = effErrBoth[ich+kNch] / ( 1. - effErr1[ich] );
159  Double_t err1 = effErr1[ich+kNch] * effErr[ich] / ( 1. - effErr1[ich] );
160  effErr[ich+kNch] = TMath::Sqrt(err2*err2 + errBoth*errBoth + err1*err1);
161  }
162  }
163  else {
164  effErr[ich] = ( effErr1[ich] > kZero ) ? effErrBoth[ich]/effErr1[ich] : 0.;
165  Double_t relErr1 = ( effErr1[ich] > kZero ) ? effErr1[ich+kNch]/effErr1[ich] : 0.;
166  Double_t relErrBoth = ( effErrBoth[ich] > kZero ) ? effErrBoth[ich+kNch]/effErrBoth[ich] : 0.;
167  effErr[ich+kNch] = effErr[ich] * TMath::Sqrt(relErr1*relErr1 + relErrBoth*relErrBoth);
168  }
169  //printf("%f %f %f -> %f\n", effErr1[ich], effErr2[ich], effErrBoth[ich], effErr[ich]); // REMEMBER TO CUT
170  } // loop on chambers
171  return effErr;
172 }
173 
174 
175 //_____________________________________________________________________________
176 Double_t* GetBinomial(Double_t* effErr1, Double_t* effErr2 = 0x0, Double_t* effErrBoth = 0x0)
177 {
179  Double_t effProd[4];
180  Double_t defaultEffErr[2] = {1.,0.};
181  Double_t* auxBinomial = 0x0;
182  Double_t* currEffErr44 = 0x0;
183  Double_t* effErrBinomial = new Double_t[2];
184  effErrBinomial[0] = 0.;
185  effErrBinomial[1] = 0.;
186 
187  for ( Int_t ich = -1; ich<kNch; ich++ ) {
188  Double_t* currEffErr = GetProdErr(effErr1, ich);
189  if ( ich >= 0 ) {
190  currEffErr[0] = currEffErr[0] - currEffErr44[0];
191  currEffErr[1] = TMath::Sqrt(currEffErr[1]*currEffErr[1] + currEffErr44[1]*currEffErr44[1]);
192  }
193  if ( effErr2 ) {
194  Double_t* auxEffErr = GetConditionalEffErr(effErr1, effErr2, effErrBoth, ich);
195  auxBinomial = GetBinomial(auxEffErr);
196  delete [] auxEffErr;
197  }
198  for ( Int_t ival=0; ival<2; ival++ ) {
199  effProd[2*ival] = currEffErr[ival];
200  effProd[2*ival+1] = ( effErr2 ) ? auxBinomial[ival] : defaultEffErr[ival];
201  }
202  if ( ich < 0 ) currEffErr44 = currEffErr;
203  else delete [] currEffErr;
204  delete [] auxBinomial;
205 
206  Double_t* effErr = GetProdErr(effProd, -1, 2);
207  //printf("%f * %f = %f\n", effProd[0], effProd[1], effErr[0]); // REMEMBER TO CUT
208  effErrBinomial[0] += effErr[0];
209  effErrBinomial[1] += effErr[1]*effErr[1];
210  delete [] effErr;
211  } // loop on chambers
212 
213  delete [] currEffErr44;
214 
215  effErrBinomial[1] = TMath::Sqrt(effErrBinomial[1]);
216 
217  return effErrBinomial;
218 }
219 
220 //_____________________________________________________________________________
221 Bool_t CheckOCDBFile ( TString cdbDir, Int_t runNum )
222 {
228  if ( runNum >= 0 ) AliCDBManager::Instance()->SetRun(runNum);
229  TList* list = AliCDBManager::Instance()->GetAll(cdbDir.Data());
230  if ( list->GetEntries() == 0 ) {
231  printf("Warning: no entry found in %s for run %i\n",cdbDir.Data(),runNum);
232  return kFALSE;
233  }
234  return kTRUE;
235 }
236 
237 //_____________________________________________________________________________
238 TList* GetOCDBList ( TString ocdbDirs )
239 {
241  TString storageType = AliCDBManager::Instance()->GetDefaultStorage()->GetType();
242  Bool_t isGrid = storageType.Contains("alien");
243  TString baseFolder = AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder();
244 
245  TList* outList = new TList();
246  outList->SetOwner();
247  TObjArray* dirNameList = ocdbDirs.Tokenize(",");
248  for ( Int_t idir=0; idir<dirNameList->GetEntries(); idir++ ) {
249  TString fullPath = Form("%s/%s",baseFolder.Data(),dirNameList->At(idir)->GetName());
250  if ( isGrid ) {
251  TGridResult *res = gGrid->Ls(fullPath.Data());
252  if (!res) return 0x0;
253  for ( Int_t ires=0; ires<res->GetEntries(); ires++ ) {
254  TString currFile = static_cast<TMap*>(res->At(ires))->GetValue("name")->GetName();
255  outList->Add(new TObjString(currFile));
256  }
257  delete res;
258  }
259  else {
260  TString fileListStr = gSystem->GetFromPipe(Form("ls %s",fullPath.Data()));
261  TObjArray* fileList = fileListStr.Tokenize("\n");
262  for ( Int_t ires=0; ires<fileList->GetEntries(); ires++ ) {
263  TString currFile = fileList->At(ires)->GetName();
264  outList->Add(new TObjString(currFile));
265  }
266  delete fileList;
267  }
268  }
269  delete dirNameList;
270  return outList;
271 }
272 
273 //_____________________________________________________________________________
274 Bool_t SetAndCheckOCDB ( TString defaultStorage )
275 {
277  if ( defaultStorage.IsNull() ) {
278  printf("Default storage not specified. Nothing done\n");
279  return kFALSE;
280  }
281 
282  if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
283  printf("Default storage already set: nothing done\n");
284  return kTRUE;
285  }
286 
287  if ( defaultStorage.Contains("alien://") || defaultStorage.Contains("raw://") ) {
288  if ( ! gGrid ) TGrid::Connect("alien://");
289  if ( ! gGrid ) {
290  printf("Error: Problem connetting to grid: default storage not set\n");
291  return kFALSE;
292  }
293  }
294 
295  AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
296 
297  if ( defaultStorage.Contains("raw://") ) return kTRUE;
298 
299  Bool_t isOk = kTRUE;
300 
301  if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
302  TString searchDir = "MUON/Calib/MappingData";
303  TString fullPath = Form("%s/%s",defaultStorage.Data(),searchDir.Data());
304  TList* ocdbList = GetOCDBList(searchDir);
305  if ( ocdbList->GetEntries() == 0 ) {
306  printf("No entries in %s\n",fullPath.Data());
307  isOk = kFALSE;
308  }
309  else {
310  TString checkFile = Form("%s/%s",fullPath.Data(),ocdbList->At(0)->GetName());
311  checkFile.ReplaceAll("local://","");
312  checkFile.ReplaceAll("folder=","");
313  checkFile.ReplaceAll("Folder=","");
314  TFile* file = TFile::Open(checkFile.Data());
315  if ( ! file ) {
316  printf("Cannot access test file: %s\n", checkFile.Data());
317  isOk = kFALSE;
318  }
319  delete file;
320  }
321  delete ocdbList;
322  }
323  else {
324  printf("Tried to set the default storage, but something went wrong.\n");
325  isOk = kFALSE;
326  }
327 
328  if ( ! isOk ) printf("Please check path %s\n",defaultStorage.Data());
329 
330  return isOk;
331 }
332 
333 //_____________________________________________________________________________
334 Bool_t IsOCDBChanged ( Int_t currRun, Int_t previousRun, TList* fileList )
335 {
337  if ( ! fileList ) return kTRUE;
338  for ( Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
339  TString filename = static_cast<TObjString*>(fileList->At(ifile))->GetString();
340  filename.ReplaceAll("Run","");
341  TObjArray* array = filename.Tokenize("_");
342  Int_t firstRun = static_cast<TObjString*>(array->At(0))->GetString().Atoi();
343  Int_t lastRun = static_cast<TObjString*>(array->At(1))->GetString().Atoi();
344  delete array;
345  Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
346  Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
347  if ( isCurrRunInside != isPreviousRunInside ) return kTRUE;
348  }
349  return kFALSE;
350 }
351 
352 
353 //_____________________________________________________________________________
354 void TrigEffTrending ( TString fileNameList, TList& outList)
355 {
356 
357  TString physSel = "PhysSelPass,PhysSelReject";
358  TString trigClass = "ANY";
359  TString centrClass = "-5_105";
361  for ( Int_t ieff=0; ieff<2; ieff++ ) {
364 
366  an.SetEffConditions(physSel,trigClass,centrClass,trackSel,matchTrig,effType);
367  an.InitFromLocal(fileNameList);
368 
369  Int_t nCanvases = gROOT->GetListOfCanvases()->GetEntries();
370 
372  an.DrawEffTrend(AliTrigChEffOutput::kHslatEff,-1,3.,0.8,1.05);
373 
374  TString baseName = ( ieff == 0 ) ? "Trigger" : "Tracker";
375  for ( Int_t ican=nCanvases; ican<gROOT->GetListOfCanvases()->GetEntries(); ican++ ) {
376  TCanvas* can = static_cast<TCanvas*>(gROOT->GetListOfCanvases()->At(ican));
377  can->SetName(Form("%s_from%s",baseName.Data(),can->GetName()));
378  can->SetTitle(Form("%s_from%s",baseName.Data(),can->GetTitle()));
379  can->cd();
380  TPad* pad = new TPad(Form("%s_text",can->GetName()),"",0.35,0.97,0.65,1.);
381  pad->SetFillStyle(4000);
382  pad->Draw();
383  pad->cd();
384  TLatex tex;
385  tex.SetTextSize(0.75);
386  tex.DrawLatexNDC(0.1,0.1,Form("From %s track",baseName.Data()));
387  outList.Add(can);
388  } // loop on canvases
389  } // loop on efficiency types
390 }
391 
392 //_____________________________________________________________________________
393 void MaskTrending ( TObjArray runNumArray, TString defaultStorage, TList& outList )
394 {
396 
397  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
398 
399  TObjArray maskedList(8);
400  TObjArray auxList(8);
401  auxList.SetOwner();
402  TString histoName = "", histoTitle = "";
403  for(Int_t icath=0; icath<2; icath++){
404  TString cathName = ( icath==0 ) ? "bendPlane" : "nonBendPlane";
405  for(Int_t ich=0; ich<kNch; ich++){
406  histoName = Form("%sMaskCh%i", cathName.Data(), 11+ich);
407  histoTitle = Form("Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
408  TH2* histo = new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
409  histo->GetYaxis()->SetTitle("Board Id");
410 // histo->SetOption("COLZ");
411  Int_t imask = 2*ich + icath;
412  maskedList.AddAt(histo, imask);
413  auxList.AddAt(histo->Clone(Form("%s_aux",histoName.Data())), imask);
414  } // loop on chambers
415  } // loop on cathodes
416 
417  TArrayS xyPatternAll[2];
418  for(Int_t icath=0; icath<2; icath++){
419  xyPatternAll[icath].Set(kNch);
420  xyPatternAll[icath].Reset(0xFFFF);
421  }
422 
423  TList* ocdbFileList = 0x0;
424  Int_t previousRun = -1;
425  AliMUONDigitMaker* digitMaker = 0x0;
426  AliMUONDigitStoreV2R digitStore;
427 
428  AliMUONCalibrationData* calibData = 0x0;
429  AliMUONTriggerUtilities* trigUtilities = 0x0;
430  for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
431  TString runNumString = runNumArray.At(irun)->GetName();
432  Int_t runNumber = runNumString.Atoi();
433 
434  if ( IsOCDBChanged(runNumber, previousRun, ocdbFileList) ) {
435  AliCDBManager::Instance()->SetRun(runNumber);
436 
437  if ( ! digitMaker ) {
438  digitMaker = new AliMUONDigitMaker(kFALSE);
439  // Create a store with all digits in trigger
440  for ( Int_t iboard=1; iboard<=234; iboard++ ) {
441  digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
442  }
443  }
444 
445  if ( ! ocdbFileList ) ocdbFileList = GetOCDBList("MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
446 
447  delete calibData;
448  calibData = new AliMUONCalibrationData (runNumber);
449  delete trigUtilities;
450  trigUtilities = new AliMUONTriggerUtilities (calibData);
451  }
452 
453  previousRun = runNumber;
454 
455  TIter next(digitStore.CreateIterator());
456  AliMUONVDigit* dig = 0x0;
457  while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
458  Int_t icath = dig->Cathode();
459  Int_t detElemId = dig->DetElemId();
460  Int_t ich = detElemId/100-11;
461  Int_t iboard = dig->ManuId();
462  Int_t imask = 2*ich + icath;
463  static_cast<TH2*>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
464  static_cast<TH2*>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(Double_t)trigUtilities->IsMasked(*dig));
465  }
466  } // loop on runs
467  delete calibData;
468  delete trigUtilities;
469  delete digitMaker;
470 
471  TString canName = "";
472  for ( Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
473  TH2* histo = static_cast<TH2*>(maskedList.At(imask));
474  histo->Divide(static_cast<TH2*>(auxList.At(imask)));
475  SetRunAxisRange(histo);
476 
477  canName = Form("%sCan", histo->GetName());
478  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
479  can->SetRightMargin(0.14);
480  histo->SetStats(kFALSE);
481  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
482  histo->DrawCopy("COLZ");
483  outList.Add(can);
484  }
485 }
486 
487 //_____________________________________________________________________________
488 Bool_t CheckPattern ( TString trigName, TObjArray* keepArray, TObjArray* rejectArray )
489 {
491  for ( Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
492  if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) ) return kFALSE;
493  } // loop on reject pattern
494 
495  for ( Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
496  if ( trigName.Contains(keepArray->At(ipat)->GetName() ) ) return kTRUE;
497  } // loop on keep pattern
498 
499  return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
500 }
501 
502 //_____________________________________________________________________________
503 TObjArray* BuildListOfTrigger ( const TObjArray* triggerArray, TString keepPattern = "", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
504 {
506  TObjArray* selectedList = new TObjArray();
507  selectedList->SetOwner();
508  TObjArray* rejectArray = rejectPattern.Tokenize(",");
509  TObjArray* keepArray = keepPattern.Tokenize(",");
510 
511  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
512  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
513  if ( CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(new TObjString(currTrigName.Data()));
514  }
515 
516  delete rejectArray;
517  delete keepArray;
518 
519  return selectedList;
520 
521 }
522 
523 //_____________________________________________________________________________
524 TString FindCorrespondingTrigger ( TString checkTrigger, TObjArray* triggerArray )
525 {
527  TString foundName = "";
528  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
529  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
530  TObjArray* array = currTrigName.Tokenize("-");
531  TString collisionType = array->At(1)->GetName();
532  delete array;
533  collisionType.Append("-");
534  collisionType.Prepend("-");
535  if ( checkTrigger.Contains(collisionType.Data()) ) {
536  foundName = currTrigName;
537  break;
538  }
539  }
540 
541  return foundName;
542 }
543 
544 //_____________________________________________________________________________
545 void ScalerTrending ( TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList& outList )
546 {
548  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
549 
550  //trigger count from ESDs
551  TFile *file = TFile::Open(mergedFileName.Data());
552  AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny("MUON_QA"))->FindObjectAny("eventCounters");
553 
554  //Build the trigger list for trigger with muon only in readout and min. bias triggers
555  TString triggerListName = ccol->GetKeyWords("trigger");
556 
557  TObjArray selectedTriggerArray, selectedL0TriggerArray;
558  selectedTriggerArray.SetOwner();
559  selectedL0TriggerArray.SetOwner();
560 
561  const Int_t nScaler = 3;
562  TString sScaler[nScaler] = {"L0B","L2A","L0BRATE"};
563  enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
564  Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
565  TObjArray hFromQA;
566  TObjArray hFromScalers;
567  TObjArray hOutput;
568 
569  TString cdbDir = "GRP/CTP/Config";
570 
571 
572  TString sHistName, sHistNameFull, sTitleName;
573  Int_t nRuns = runNumArray.GetEntries();
574 
575  //
576  //Fill histos for Scalers and QA
577  //
578  //loop on run list
579  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
580 
581  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
582  Int_t runNr = sRunNr.Atoi();
583  if ( ! CheckOCDBFile(cdbDir, runNr)) continue;
584  AliAnalysisTriggerScalers triggerScaler(runNr);
585  AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(triggerScaler.GetOCDBObject(cdbDir.Data(),runNr));
586  const TObjArray& trClasses = tc->GetClasses();
587 
588  Int_t ibin = iRun+1;
589 
590  for ( Int_t itype=0; itype<2; itype++ ) {
591  TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
592  TString matchTrig = ( itype == 0 ) ? "" : "C0TVX";
593  TObjArray* selectedTrigArrayForRun = BuildListOfTrigger(&trClasses, matchTrig);
594 
595  //loop on trigger list
596  for ( Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
597 
598  TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
599  if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) ) continue;
600  if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(new TObjString(currTrigName));
601 
602  //loop on scaler list
603  for ( Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
604 
605  if ( itype == 1 && iScaler != kL0B ) continue;
606 
607  //from Scalers
608  TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data(),kFALSE);
609 
610  sHistName = Form("%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
611  sHistNameFull = Form("Scalers_%s",sHistName.Data());
612 
613  TH1* hist = (TH1*) hFromScalers.FindObject(sHistNameFull);
614  if ( ! hist ) {
615  hist = new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(Double_t)nRuns);
616  hist->LabelsOption("v");
617  hist->GetXaxis()->SetLabelSize(0.02);
618  hist->SetDirectory(0);
619  hist->SetMinimum(1);
620  hist->SetMaximum(maxScaler[0]);
621  hFromScalers.AddLast(hist);
622  hOutput.AddLast(hist);
623  if ( iScaler == kL2A ) {
624  sHistNameFull = "QA_" + sHistName;
625  hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
626  }
627  }
628  Double_t *tab = (Double_t*) graph->GetY();
629  if ( tab ) hist->SetBinContent(ibin,tab[0]);
630  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
631  delete graph;
632 
633  //from QA
634  if ( iScaler != kL2A ) continue;
635  TH1* histCounters = static_cast<TH1*>(ccol->Get("run",Form("run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
636  sHistNameFull = sHistNameFull = "QA_" + sHistName;
637  hist = (TH1*) hFromQA.FindObject(sHistNameFull);
638  if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
639  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
640  delete histCounters;
641  }//end loop on scaler list
642  }//end loop on trigger list
643  } // end loop on type
644  }//end loop on run list
645 
646 
647  if ( selectedTriggerArray.GetEntries() == 0 ) {
648  printf("No trigger selected from trigger list %s\n",triggerListName.Data());
649  return;
650  }
651  printf("Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
652 
653  printf("Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
654 
655  //Set options for QA and Scalers histos
656 
657  for ( Int_t itype=0; itype<2; itype++ ) {
658  TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
659  for ( Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
660  TH1* histo = static_cast<TH1*> ( currList->At(ihisto) );
661  if (!histo) continue;
662  // Write run number to each bin
663  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
664  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
665  Int_t ibin = iRun+1;
666  TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
667  if ( ! binLabel.IsNull() ) continue;
668  histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
669  }
670  histo->SetStats(kFALSE);
671  }
672  }
673 
674 
675  //Loop on histos from scalers and QA and create resulting histos from scalers
676  const Int_t nHisto = 3;
677  TString sHisto[nHisto] = {"L0BoverL0BC0TVX","L2AoverL0B","L2AQAoverSCALERS"};
678  TString sTitleHisto[nHisto] = {"L0B trigger / L0BC0TVX","L2A / L0B","L2A from QA / L2A from SCALERS"};
679  // TString sHisto[nHisto] = {"L2AoverL0B","L2AQAoverSCALERS"};
680 
681  //loop on trigger list
682  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
683 
684  sHistNameFull = Form("Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
685  TH1* histo1 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
686  if (!histo1) continue;
687 
688 
689  //C0TVX
690  TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
691  TString sL0Trig = FindCorrespondingTrigger(sTrig, &selectedL0TriggerArray);
692 
693  sHistNameFull = Form("Scalers_%s_L0B",sL0Trig.Data());
694 
695  TH1* histo0 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
696  if ( histo0 ) {
697  sHistNameFull = Form("%s_%s",sHisto[0].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
698  TH1* histo10 = (TH1*) histo1->Clone(sHistNameFull);
699  histo10->SetTitle(sTitleHisto[0].Data());
700  histo10->Sumw2();
701  histo10->Divide(histo0);
702  histo10->SetMaximum(10);
703  histo10->SetMinimum(1e-5);
704  //outList.Add(histo10);
705  hOutput.AddLast(histo10);
706  //outList.Add(histo0);
707  //outList.Add(histo1);
708  }
709 
710  //DEADTIME
711  sHistNameFull = Form("Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
712  TH1* histo2 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
713  if (!histo2) continue;
714 
715  sHistNameFull = Form("%s_%s",sHisto[1].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
716  TH1* histo3 = (TH1*) histo2->Clone(sHistNameFull);
717  histo3->SetTitle(sTitleHisto[1]);
718  histo3->Sumw2();
719  histo3->Divide(histo1);
720  histo3->SetMaximum(1.2);
721  histo3->SetMinimum(1e-5);
722  //outList.Add(histo3);
723  hOutput.AddLast(histo3);
724 
725  //QA over Scalers
726  sHistNameFull = Form("QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
727  TH1* histo4 = static_cast<TH1*> ( hFromQA.FindObject(sHistNameFull) );
728  if (!histo4) continue;
729 
730  sHistNameFull = Form("%s_%s",sHisto[2].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
731  TH1* histo5 = (TH1*) histo4->Clone(sHistNameFull);
732  histo5->SetTitle(sTitleHisto[2]);
733  histo5->Sumw2();
734  histo5->Divide(histo2);
735  histo5->SetMaximum(1.2);
736  histo5->SetMinimum(5e-1);
737  //outList.Add(histo5);
738  hOutput.AddLast(histo5);
739  }
740 
741  // Plot all on canvases (only canvases will be saved)
742  const Int_t nCanvases = nScaler + nHisto;
743  TString sCanvases[nCanvases];
744  for (Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
745  for (Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
746 
747  //loop on canvases
748  for ( Int_t iCan = 0; iCan < nCanvases; iCan++) {
749  TCanvas* canvas = new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
750  TLegend* leg = new TLegend(0.72,0.7,0.9,0.85);
751  leg->SetBorderSize(1);
752  if ( iCan != 4 ) canvas->SetLogy();
753  TString optDraw = "e";
754 
755  //loop on trigger list
756  Int_t icolor = 1;
757  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
758 
759  if ( iCan < nScaler ) sHistNameFull = Form("Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
760  else sHistNameFull = Form("%s_%s",sCanvases[iCan].Data(),selectedTriggerArray.At(iTrig)->GetName());
761  TH1* histo1 = static_cast<TH1*> ( hOutput.FindObject(sHistNameFull) );
762  if (!histo1) continue;
763 
764  if ( icolor == 10 ) icolor++;
765  histo1->SetLineColor(icolor++);
766  histo1->Draw(optDraw);
767  optDraw = "esame";
768 
769  leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),"l");
770  }
771 
772  leg->Draw();
773  outList.Add(canvas);
774  }
775 
776  file->Close();
777 }
778 
779 //_____________________________________________________________________________
780 void trigEffQA(TString fileListName, TString outFilename = "", TString defaultStorage = "raw://", Bool_t doScalers = kFALSE, TString trackerQAmergedOut="QAresults_merged.root")
781 {
783  ifstream inFile(fileListName.Data());
784  TObjArray fileNameArray, runNumArray;
785  fileNameArray.SetOwner();
786  runNumArray.SetOwner();
787  TString currString = "";
788  if (inFile.is_open()) {
789  while (! inFile.eof() ) {
790  currString.ReadLine(inFile); // Read line
791  if ( ! currString.Contains(".root") ||
792  currString.BeginsWith("#") ) continue;
793  fileNameArray.AddLast(new TObjString(currString.Data()));
794  Int_t runNum = GetRunNumber(currString);
795  runNumArray.AddLast(new TObjString(Form("%i",runNum)));
796  }
797  inFile.close();
798  }
799  else {
800  printf("Fatal: cannot open input file %s\n",fileListName.Data());
801  return;
802  }
803 
804  runNumArray.Sort();
805 
806  TList outList;
807  TrigEffTrending(fileListName, outList);
808  if ( SetAndCheckOCDB(defaultStorage) ) {
809  MaskTrending(runNumArray, defaultStorage, outList);
810  if ( doScalers ) {
811  if ( gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
812  printf("Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
813  }
814  else {
815  ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outList);
816  }
817  }
818  }
819 
820  if ( outFilename.IsNull() ) return;
821 
822  TString outCanName = outFilename;
823  outCanName.ReplaceAll(".root",".pdf");
824  for ( Int_t ican=0; ican<outList.GetEntries(); ican++ ) {
825  TString canName = outCanName;
826  if ( ican == 0 ) canName.Append("("); // open pdf file
827  else if ( ican == outList.GetEntries()-1 ) canName.Append(")"); // close pdf file
828  static_cast<TCanvas*>(outList.At(ican))->Print(canName.Data());
829  }
830  // There is a bug when creating a pdf
831  // So create a ps and then convert via epstopdf
832  if ( outCanName.Contains(".ps") || outCanName.Contains(".eps") ) {
833  gSystem->Exec(Form("epstopdf %s", outCanName.Data()));
834  gSystem->Exec(Form("rm %s", outCanName.Data()));
835  }
836 
837  TFile* outFile = new TFile(outFilename.Data(), "recreate");
838  outList.Write();
839  outFile->Close();
840 }
const char * filename
Definition: TestFCM.C:1
void Print(std::ostream &o, const char *name, Double_t dT, Double_t dVM, Double_t alldT, Double_t alldVM)
Definition: PlotSysInfo.C:121
Hit pattern from tracker track extrapolation.
double Double_t
Definition: External.C:58
const Int_t kNch
Definition: trigEffQA.C:43
TCanvas * canvas
Definition: DrawAnaELoss.C:28
void SetMyStyle()
Definition: trigEffQA.C:47
TSystem * gSystem
Bool_t SetAndCheckOCDB(TString defaultStorage)
Definition: trigEffQA.C:274
void TrigEffTrending(TString fileNameList, TList &outList)
Definition: trigEffQA.C:354
TString FindCorrespondingTrigger(TString checkTrigger, TObjArray *triggerArray)
Definition: trigEffQA.C:524
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Double_t * GetConditionalEffErr(Double_t *effErr1, Double_t *effErr2, Double_t *effErrBoth, Int_t exclude=-1)
Definition: trigEffQA.C:148
Output for Trig chamber effieincy.
const Double_t kZero
Definition: trigEffQA.C:44
Bool_t InitFromLocal(const char *localFileList, const char *outputName="testMTRChamberEff")
Double_t * GetProdErr(Double_t *effErr, Int_t exclude, Int_t nFactors=kNch)
Definition: trigEffQA.C:127
Definition: External.C:228
Definition: External.C:212
Bool_t IsRunNum(TString stringToken)
Definition: trigEffQA.C:73
Bool_t SetEffConditions(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
TObjArray * BuildListOfTrigger(const TObjArray *triggerArray, TString keepPattern="", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM")
Definition: trigEffQA.C:503
void MaskTrending(TObjArray runNumArray, TString defaultStorage, TList &outList)
Definition: trigEffQA.C:393
Int_t GetRunNumber(TString filePath)
Definition: trigEffQA.C:98
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)
Non selected tracks (includes ghosts)
Bool_t CheckOCDBFile(TString cdbDir, Int_t runNum)
Definition: trigEffQA.C:221
Counts per cathode histogram index.
Definition: External.C:220
void SetRunAxisRange(TH1 *histo, TString runAxis="X")
Definition: trigEffQA.C:80
Double_t * GetBinomial(Double_t *effErr1, Double_t *effErr2=0x0, Double_t *effErrBoth=0x0)
Definition: trigEffQA.C:176
TFile * file
TList with histograms for a given trigger.
Bool_t IsOCDBChanged(Int_t currRun, Int_t previousRun, TList *fileList)
Definition: trigEffQA.C:334
void DrawEffTrend(Int_t itype, Int_t irpc, Double_t maxNsigmasOutliers=-1., Double_t minEff=0.8, Double_t maxEff=1.01) const
void ScalerTrending(TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList &outList)
Definition: trigEffQA.C:545
bool Bool_t
Definition: External.C:53
Hit pattern from trigger.
TList * GetOCDBList(TString ocdbDirs)
Definition: trigEffQA.C:238
Bool_t CheckPattern(TString trigName, TObjArray *keepArray, TObjArray *rejectArray)
Definition: trigEffQA.C:488
Definition: External.C:196
TString prod[]
productions to be compared, directory name
Counts per slat histogram index.
void trigEffQA(TString fileListName, TString outFilename="", TString defaultStorage="raw://", Bool_t doScalers=kFALSE, TString trackerQAmergedOut="QAresults_merged.root")
Definition: trigEffQA.C:780