AliPhysics  29d4213 (29d4213)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
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 
26 #include "AliCDBManager.h"
27 #include "AliCDBEntry.h"
28 #include "AliCDBPath.h"
29 #include "AliCDBStorage.h"
30 #include "AliMUONTriggerEfficiencyCells.h"
31 #include "AliMUONTriggerChamberEfficiency.h"
32 #include "AliMUONTriggerUtilities.h"
33 #include "AliMUONDigitMaker.h"
34 #include "AliMUONVDigit.h"
35 #include "AliMUONDigitStoreV2R.h"
36 #include "AliMUONCalibrationData.h"
37 #include "AliAnalysisTriggerScalers.h"
38 #include "AliCounterCollection.h"
39 #include "AliTriggerConfiguration.h"
40 #endif
41 
42 const Int_t kNch = 4;
43 const Double_t kZero = 1.e-7; // Avoid problems when comparing to 0.
44 
45 //_____________________________________________________________________________
46 void SetMyStyle()
47 {
49  gStyle->SetCanvasColor(10);
50  gStyle->SetFrameFillColor(10);
51  gStyle->SetStatColor(10);
52  gStyle->SetFillColor(10);
53  gStyle->SetTitleFillColor(10);
54 
55  gStyle->SetTitleXSize(0.03);
56  gStyle->SetTitleXOffset(1.1);
57  gStyle->SetTitleYSize(0.03);
58  gStyle->SetTitleYOffset(1.9);
59 
60  gStyle->SetMarkerSize(0.7);
61  gStyle->SetHistLineWidth(2);
62 
63  gStyle->SetPadLeftMargin(0.12);
64  gStyle->SetPadRightMargin(0.04);
65  gStyle->SetPadBottomMargin(0.08);
66  gStyle->SetPadTopMargin(0.08);
67 
68  gROOT->ForceStyle();
69 }
70 
71 //_____________________________________________________________________________
72 Bool_t IsRunNum ( TString stringToken )
73 {
74  return ( stringToken.IsDigit() && stringToken.Length()>=6 && stringToken.Length()<=9 );
75 }
76 
77 
78 //_____________________________________________________________________________
79 void SetRunAxisRange ( TH1* histo, TString runAxis = "X" )
80 {
82  runAxis.ToUpper();
83  TAxis* axis = histo->GetXaxis();
84  if ( runAxis == "Y" ) axis = histo->GetYaxis();
85  else if ( runAxis == "Z" ) axis = histo->GetZaxis();
86  histo->LabelsOption("v",runAxis.Data());
87  axis->SetLabelSize(0.02);
88  for ( Int_t ibin=1; ibin<=axis->GetNbins(); ibin++ ) {
89  TString binLabel = axis->GetBinLabel(ibin);
90  if ( ! binLabel.IsNull()) continue;
91  axis->SetRange(1, ibin-1);
92  return;
93  }
94 }
95 
96 //_____________________________________________________________________________
97 Int_t GetRunNumber(TString filePath)
98 {
100  TObjArray* array = filePath.Tokenize("/");
101  array->SetOwner();
102  TString auxString = "";
103  Int_t runNum = -1;
104  for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
105  auxString = array->At(ientry)->GetName();
106  if ( IsRunNum(auxString) ) {
107  runNum = auxString.Atoi();
108  break;
109  }
110  }
111  delete array;
112 
113  if ( runNum < 0 ) {
114  array = auxString.Tokenize("_");
115  array->SetOwner();
116  auxString = array->Last()->GetName();
117  auxString.ReplaceAll(".root","");
118  if ( IsRunNum(auxString) ) runNum = auxString.Atoi();
119  delete array;
120  }
121 
122  return runNum;
123 }
124 
125 //_____________________________________________________________________________
126 TObjArray* ChangeFilenames ( const TObjArray &fileNameArray )
127 {
134  TObjArray* outArray = new TObjArray(fileNameArray.GetEntries());
135  outArray->SetOwner();
136  TString newBaseName = "trigChEff_ANY_Apt_allTrig.root";
137  for ( Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
138  TObjString* currObjString = static_cast<TObjString*>(fileNameArray.At(ifile));
139  TString currFile = currObjString->GetString();
140  TString baseName = gSystem->BaseName(currFile.Data());
141  // In the old scripts, the run number is in the QA filename
142  Int_t runNum = GetRunNumber(baseName);
143  TString newFilename = "";
144  if ( runNum < 0 ) {
145  // New central script: the re-created trigger output is in the same directory
146  newFilename = currFile;
147  newFilename.ReplaceAll(baseName.Data(),newBaseName.Data());
148  }
149  else {
150  // Old script. The re-creaated trigger output is in terminateRuns
151  TString dirName = gSystem->DirName(currFile.Data());
152  newFilename = Form("%s/terminateRuns/%i/%s",dirName.Data(),runNum,newBaseName.Data());
153  }
154  if ( gSystem->AccessPathName(newFilename.Data()) ) {
155  printf("New output not found in %s.\n", currFile.Data());
156  delete outArray;
157  outArray = 0x0;
158  break;
159  }
160  outArray->AddAt(new TObjString(newFilename),ifile);
161  }
162 
163  if ( outArray ) printf("Using re-built output in %s\n",newBaseName.Data());
164  else {
165  outArray = static_cast<TObjArray*>(fileNameArray.Clone());
166  printf("Using default output\n");
167  }
168  return outArray;
169 }
170 
171 //_____________________________________________________________________________
172 Double_t* GetProdErr(Double_t* effErr, Int_t exclude, Int_t nFactors = kNch)
173 {
175  Double_t prod = 1.;
176  Double_t relErr = 0., relProdErrSquare = 0.;
177  for ( Int_t iprod=0; iprod<nFactors; iprod++ ) {
178  if ( iprod == exclude ) continue;
179  prod *= effErr[iprod];
180  relErr = ( effErr[iprod] > kZero ) ? effErr[iprod+nFactors]/effErr[iprod] : 0.;
181  relProdErrSquare += relErr*relErr;
182  //printf("%f +- %f ", effErr[iprod], effErr[iprod+nFactors]); // alBER TO CUT
183  }
184  Double_t* prodErr = new Double_t[2];
185  prodErr[0] = prod;
186  prodErr[1] = prod*TMath::Sqrt(relProdErrSquare);
187  //printf("-> %f %f\n", prodErr[0], prodErr[1]); // REMEMBER TO CUT
188  return prodErr;
189 }
190 
191 
192 //_____________________________________________________________________________
193 Double_t* GetConditionalEffErr(Double_t* effErr1, Double_t* effErr2, Double_t* effErrBoth, Int_t exclude = -1)
194 {
196  Double_t* effErr = new Double_t[2*kNch];
197  for ( Int_t ich=0; ich<kNch; ich++ ) {
198  if ( ich == exclude ) {
199  effErr[ich] = ( effErr1[ich] < 1. ) ? ( effErr2[ich] - effErrBoth[ich] ) / ( 1. - effErr1[ich] ) : 0.;
200  effErr[ich+kNch] = 0;
201  if ( effErr1[ich] < 1. ) {
202  Double_t err2 = effErr2[ich+kNch] / ( 1. - effErr1[ich] );
203  Double_t errBoth = effErrBoth[ich+kNch] / ( 1. - effErr1[ich] );
204  Double_t err1 = effErr1[ich+kNch] * effErr[ich] / ( 1. - effErr1[ich] );
205  effErr[ich+kNch] = TMath::Sqrt(err2*err2 + errBoth*errBoth + err1*err1);
206  }
207  }
208  else {
209  effErr[ich] = ( effErr1[ich] > kZero ) ? effErrBoth[ich]/effErr1[ich] : 0.;
210  Double_t relErr1 = ( effErr1[ich] > kZero ) ? effErr1[ich+kNch]/effErr1[ich] : 0.;
211  Double_t relErrBoth = ( effErrBoth[ich] > kZero ) ? effErrBoth[ich+kNch]/effErrBoth[ich] : 0.;
212  effErr[ich+kNch] = effErr[ich] * TMath::Sqrt(relErr1*relErr1 + relErrBoth*relErrBoth);
213  }
214  //printf("%f %f %f -> %f\n", effErr1[ich], effErr2[ich], effErrBoth[ich], effErr[ich]); // REMEMBER TO CUT
215  } // loop on chambers
216  return effErr;
217 }
218 
219 
220 //_____________________________________________________________________________
221 Double_t* GetBinomial(Double_t* effErr1, Double_t* effErr2 = 0x0, Double_t* effErrBoth = 0x0)
222 {
224  Double_t effProd[4];
225  Double_t defaultEffErr[2] = {1.,0.};
226  Double_t* auxBinomial = 0x0;
227  Double_t* currEffErr44 = 0x0;
228  Double_t* effErrBinomial = new Double_t[2];
229  effErrBinomial[0] = 0.;
230  effErrBinomial[1] = 0.;
231 
232  for ( Int_t ich = -1; ich<kNch; ich++ ) {
233  Double_t* currEffErr = GetProdErr(effErr1, ich);
234  if ( ich >= 0 ) {
235  currEffErr[0] = currEffErr[0] - currEffErr44[0];
236  currEffErr[1] = TMath::Sqrt(currEffErr[1]*currEffErr[1] + currEffErr44[1]*currEffErr44[1]);
237  }
238  if ( effErr2 ) {
239  Double_t* auxEffErr = GetConditionalEffErr(effErr1, effErr2, effErrBoth, ich);
240  auxBinomial = GetBinomial(auxEffErr);
241  delete [] auxEffErr;
242  }
243  for ( Int_t ival=0; ival<2; ival++ ) {
244  effProd[2*ival] = currEffErr[ival];
245  effProd[2*ival+1] = ( effErr2 ) ? auxBinomial[ival] : defaultEffErr[ival];
246  }
247  if ( ich < 0 ) currEffErr44 = currEffErr;
248  else delete [] currEffErr;
249  delete [] auxBinomial;
250 
251  Double_t* effErr = GetProdErr(effProd, -1, 2);
252  //printf("%f * %f = %f\n", effProd[0], effProd[1], effErr[0]); // REMEMBER TO CUT
253  effErrBinomial[0] += effErr[0];
254  effErrBinomial[1] += effErr[1]*effErr[1];
255  delete [] effErr;
256  } // loop on chambers
257 
258  delete [] currEffErr44;
259 
260  effErrBinomial[1] = TMath::Sqrt(effErrBinomial[1]);
261 
262  return effErrBinomial;
263 }
264 
265 
266 //_____________________________________________________________________________
267 TH1* GetHisto(TString histoName, TFile* file, TList* histoList)
268 {
270  TH1* histo = 0x0;
271  if ( histoList )
272  histo = (TH1*)histoList->FindObject(histoName.Data());
273  else
274  histo = (TH1*)file->FindObjectAny(histoName.Data());
275 
276  return histo;
277 }
278 
279 //_____________________________________________________________________________
280 Int_t GetEffIndex ( Int_t iel, Int_t icount, Int_t ich = -1 )
281 {
283  if ( iel == 0 ) return icount;
284  return 3 + 4*3*(iel-1) + 3*ich + icount;
285 }
286 
287 //_____________________________________________________________________________
288 TList* GetOCDBList ( TString ocdbDirs )
289 {
291  TString storageType = AliCDBManager::Instance()->GetDefaultStorage()->GetType();
292  Bool_t isGrid = storageType.Contains("alien");
293  TString baseFolder = AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder();
294 
295  TList* outList = new TList();
296  outList->SetOwner();
297  TObjArray* dirNameList = ocdbDirs.Tokenize(",");
298  for ( Int_t idir=0; idir<dirNameList->GetEntries(); idir++ ) {
299  TString fullPath = Form("%s/%s",baseFolder.Data(),dirNameList->At(idir)->GetName());
300  if ( isGrid ) {
301  TGridResult *res = gGrid->Ls(fullPath.Data());
302  if (!res) return 0x0;
303  for ( Int_t ires=0; ires<res->GetEntries(); ires++ ) {
304  TString currFile = static_cast<TMap*>(res->At(ires))->GetValue("name")->GetName();
305  outList->Add(new TObjString(currFile));
306  }
307  delete res;
308  }
309  else {
310  TString fileListStr = gSystem->GetFromPipe(Form("ls %s",fullPath.Data()));
311  TObjArray* fileList = fileListStr.Tokenize("\n");
312  for ( Int_t ires=0; ires<fileList->GetEntries(); ires++ ) {
313  TString currFile = fileList->At(ires)->GetName();
314  outList->Add(new TObjString(currFile));
315  }
316  delete fileList;
317  }
318  }
319  delete dirNameList;
320  return outList;
321 }
322 
323 //_____________________________________________________________________________
324 Bool_t SetAndCheckOCDB ( TString defaultStorage )
325 {
327  if ( defaultStorage.IsNull() ) {
328  printf("Default storage not specified. Nothing done\n");
329  return kFALSE;
330  }
331 
332  if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
333  printf("Default storage already set: nothing done\n");
334  return kTRUE;
335  }
336 
337  if ( defaultStorage.Contains("alien://") || defaultStorage.Contains("raw://") ) {
338  if ( ! gGrid ) TGrid::Connect("alien://");
339  if ( ! gGrid ) {
340  printf("Error: Problem connetting to grid: default storage not set\n");
341  return kFALSE;
342  }
343  }
344 
345  AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
346 
347  if ( defaultStorage.Contains("raw://") ) return kTRUE;
348 
349  Bool_t isOk = kTRUE;
350 
351  if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
352  TString searchDir = "MUON/Calib/MappingData";
353  TString fullPath = Form("%s/%s",defaultStorage.Data(),searchDir.Data());
354  TList* ocdbList = GetOCDBList(searchDir);
355  if ( ocdbList->GetEntries() == 0 ) {
356  printf("No entries in %s\n",fullPath.Data());
357  isOk = kFALSE;
358  }
359  else {
360  TString checkFile = Form("%s/%s",fullPath.Data(),ocdbList->At(0)->GetName());
361  checkFile.ReplaceAll("local://","");
362  checkFile.ReplaceAll("folder=","");
363  checkFile.ReplaceAll("Folder=","");
364  TFile* file = TFile::Open(checkFile.Data());
365  if ( ! file ) {
366  printf("Cannot access test file: %s\n", checkFile.Data());
367  isOk = kFALSE;
368  }
369  delete file;
370  }
371  delete ocdbList;
372  }
373  else {
374  printf("Tried to set the default storage, but something went wrong.\n");
375  isOk = kFALSE;
376  }
377 
378  if ( ! isOk ) printf("Please check path %s\n",defaultStorage.Data());
379 
380  return isOk;
381 }
382 
383 //_____________________________________________________________________________
384 Bool_t IsOCDBChanged ( Int_t currRun, Int_t previousRun, TList* fileList )
385 {
387  if ( ! fileList ) return kTRUE;
388  for ( Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
389  TString filename = static_cast<TObjString*>(fileList->At(ifile))->GetString();
390  filename.ReplaceAll("Run","");
391  TObjArray* array = filename.Tokenize("_");
392  Int_t firstRun = static_cast<TObjString*>(array->At(0))->GetString().Atoi();
393  Int_t lastRun = static_cast<TObjString*>(array->At(1))->GetString().Atoi();
394  delete array;
395  Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
396  Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
397  if ( isCurrRunInside != isPreviousRunInside ) return kTRUE;
398  }
399  return kFALSE;
400 }
401 
402 //_____________________________________________________________________________
403 TH2* GetOutliers ( TH2* histo, Double_t nSigmas = 3. )
404 {
405  TH2* outHisto = static_cast<TH2*>(histo->Clone());
406  outHisto->SetName(Form("%s_outlier",histo->GetName()));
407  outHisto->Reset();
408  for ( Int_t ybin=1; ybin<=histo->GetYaxis()->GetNbins(); ybin++ ) {
409  TH1* auxHisto = histo->ProjectionX("projectionOutlier",ybin,ybin);
410  auxHisto->Fit("pol0","Q0");
411  Double_t mean = auxHisto->GetFunction("pol0")->GetParameter(0);
412  for ( Int_t xbin=1; xbin<=auxHisto->GetXaxis()->GetNbins(); xbin++ ) {
413  Double_t err = auxHisto->GetBinError(xbin);
414  if ( err == 0. ) continue;
415  if ( TMath::Abs(auxHisto->GetBinContent(xbin)-mean)/err < nSigmas ) continue;
416  outHisto->SetBinContent(xbin,ybin,auxHisto->GetBinContent(xbin)-mean);
417  }
418  delete auxHisto;
419  }
420  return outHisto;
421 }
422 
423 //_____________________________________________________________________________
424 void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList& outCanList, TList& outList)
425 {
427  TString elementName[3] = { "Chamber", "RPC", "Board" };
428  TString countTypeName[4] = { "allTracks", "bendPlane", "nonBendPlane", "bothPlanes" };
429 
430  TString filename = "", effName = "", effTitle = "";
431 
432  SetMyStyle();
433  Double_t effValues[3][2*kNch];
434  const Int_t kNgraphs = kNch*3*2+3;
435  TObjArray effList(kNgraphs);
436  effList.SetOwner();
437  const Int_t kNeffVsRun = kNgraphs+1;
438  TObjArray effVsRunList(kNeffVsRun);
439 
440  effName = "totalEffEvolution";
441  effTitle = "Multinomial probability of firing at least 3/4 chambers";
442  TH1D* totalEff = new TH1D(effName.Data(), effTitle.Data(), 1, 0., 1.);
443  effVsRunList.AddAt(totalEff, kNeffVsRun-1);
444 
445  TString runNumString = "";
446  for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
447  effList.Clear();
448  runNumString = runNumArray.At(irun)->GetName();
449 
450  // Search corresponding file (for sorting)
451  for ( Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
452  filename = fileNameArray.At(ifile)->GetName();
453  if ( filename.Contains(runNumString.Data()) ) break;
454  }
455 
456  if ( filename.Contains("alien://") && ! gGrid ) gGrid->Connect("alien://");
457 
458  //
459  // First get the list of efficiency graphs
460  //
461 
462  // Chamber efficiency
463  TFile* file = TFile::Open(filename.Data());
464  if ( ! file ) {
465  printf("Warning: cannot find %s\n", filename.Data());
466  continue;
467  }
468 
469  TList* trigEffList = (TList*)file->FindObjectAny("triggerChamberEff");
470  if ( ! trigEffList ) printf("Warning: histo list not found in %s. Check directly in file\n", filename.Data());
471  if ( trigEffList->GetEntries() == 0 ) {
472  printf("Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
473  continue;
474  }
475 
476  TH1* histoDen = 0x0;
477  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
478  effName = countTypeName[icount] + "Count" + elementName[0];
479  if ( icount == 0 ) {
480  histoDen = GetHisto(effName, file, trigEffList);
481  continue;
482  }
483 
484  TH1* histoNum = GetHisto(effName, file, trigEffList);
485  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum, histoDen,"e0");
486  effName.ReplaceAll("Count","Eff");
487  graph->SetName(effName.Data());
488  effList.AddAt(graph, GetEffIndex(0, icount-1));
489  }
490  file->Close();
491 
492  if ( ! histoDen ) {
493  printf("Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
494  continue;
495  }
496 
497  // RPC/board efficiency
498  AliMUONTriggerChamberEfficiency trigChEff(filename);
499  for ( Int_t iel=1; iel<3; iel++ ) {
500  for ( Int_t ich=0; ich<kNch; ich++ ) {
501  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
502  TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
503  effList.AddAt(obj->Clone(Form("%s_cloned",obj->GetName())), GetEffIndex(iel, icount, ich));
504  }
505  }
506  }
507 
508  // Fill efficiency vs run
509  for ( Int_t iel=0; iel<3; iel++ ) {
510  for ( Int_t ich=0; ich<kNch; ich++ ) {
511  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
512  TGraphAsymmErrors* graph = static_cast<TGraphAsymmErrors*>(effList.At(GetEffIndex(iel, icount, ich)));
513  Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
514  for ( Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
515  Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
516  Double_t xpt, ypt;
517  graph->GetPoint(currPoint, xpt, ypt);
518  effValues[icount][ich] = ypt;
519  Int_t ihisto = GetEffIndex(iel,icount,ich);
520  TH2* effHisto = static_cast<TH2*>(effVsRunList.At(ihisto));
521  if ( ! effHisto ) {
522  effName = Form("effEvolution%s%s", countTypeName[icount+1].Data(), elementName[iel].Data());
523  effTitle = Form("Trigger chamber efficiency vs run");
524  if ( iel>0 ) {
525  effName += Form("Ch%i", 11+ich);
526  effTitle += Form(" for chamber %i", 11+ich);
527  }
528  effHisto = new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(Double_t)graph->GetN());
529  effVsRunList.AddAt(effHisto, ihisto);
530  }
531  Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
532  Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
533  Int_t binx, biny, binz;
534  effHisto->GetBinXYZ(currBin, binx, biny, binz);
535  effHisto->SetBinError(binx, biny, err);
536  effValues[icount][ich+kNch] = err;
537  } // loop on points
538  } // loop on counts
539  } // loop on chambers
540  if ( iel > 0 ) continue;
541  Double_t* binomialEff = GetBinomial(effValues[0], effValues[1], effValues[2]);
542  Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
543  // CAVEAT!!!!
544  // Well, error calculation of the binomial efficiency is a mess...
545  // Sometimes it happens that efficiency + error > 1.
546  // In that case reduce the error.
547  totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
548  delete [] binomialEff;
549  } // loop on detection elements
550  } // loop on runs
551 
552  // Set correct range (do not show last empty bins)
553  for ( Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
554  TH1* histo = static_cast<TH1*>(effVsRunList.At(ihisto));
555  if ( ! histo ) continue;
556  SetRunAxisRange(histo);
557  outList.Add(histo);
558  //histo->GetXaxis()->SetLabelSize(0.03);
559  }
560 
561  TString canName = "totalEff";
562  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
563  TH1* totEff = (TH1*)effVsRunList.At(kNeffVsRun-1);
564  totEff->GetYaxis()->SetRangeUser(0.9,1.05);
565  totEff->GetYaxis()->SetTitle("Probability to satisfy trigger conditions (3/4)");
566  totEff->SetStats(kFALSE);
567  totEff->DrawCopy();
568  outCanList.Add(can);
569 
570  Int_t color[3] = {kBlack, kRed, kBlue};
571  Int_t markStyle[3] = {20, 24, 26};
572  TLegend* leg = 0x0;
573 
574  for ( Int_t ich=0; ich<kNch; ich++ ) {
575  canName = Form("trigEffCh%i", 11+ich);
576  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
577  can->SetGridy();
578  leg = new TLegend(0.7, 0.8, 0.96, 0.92);
579  leg->SetBorderSize(1);
580  //can->Divide(2,2);
581  TString drawOpt = "e";
582  for(Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
583  //can->cd(icount+1);
584  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(0, icount)));
585  if ( ! histo ) continue;
586  TH1* chEff = histo->ProjectionX(Form("effEvolutionCh%i",11+ich), ich+1, ich+1);
587  chEff->SetTitle(Form("%s for chamber %i", histo->GetTitle(), 11+ich));
588  chEff->GetYaxis()->SetRangeUser(0.9,1.02);
589  chEff->SetStats(kFALSE);
590  chEff->GetYaxis()->SetTitle("Trigger chamber efficiency");
591  TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
592  copyEff->SetLineColor(color[icount]);
593  copyEff->SetMarkerColor(color[icount]);
594  copyEff->SetMarkerStyle(markStyle[icount]);
595  leg->AddEntry(copyEff, countTypeName[icount+1].Data(), "lp");
596  drawOpt = "esame";
597  } // loop on counts
598  leg->Draw("same");
599  outCanList.Add(can);
600  } // loop on chambers
601 
602  for ( Int_t iel=1; iel<3; iel++ ) {
603  for ( Int_t ich=0; ich<kNch; ich++ ) {
604  Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff; // Just plot the efficiency for both
605 // for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
606  canName = Form("trigEff%sCh%i", elementName[iel].Data(), 11+ich);
607  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
608  can->SetRightMargin(0.14);
609  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(iel, icount,ich)));
610  if ( ! histo ) continue;
611  histo->SetStats(kFALSE);
612  histo->GetYaxis()->SetTitle(elementName[iel].Data());
613  // FIX issue when plotting 2D histos in aliroot on linux
614  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
615  histo->DrawCopy("COLZ");
616 // } // loop on counts
617  outCanList.Add(can);
618  } // loop on chambers
619  } // loop on detection element type
620 
621 
622  // Find outliers in RPC efficiency
623  for ( Int_t ich=0; ich<kNch; ich++ ) {
624  Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff; // Just plot the efficiency for both
625  Int_t iel = 1;
626  // for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
627  canName = Form("trigEff%sCh%i_outliers", elementName[iel].Data(), 11+ich);
628  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
629  can->SetRightMargin(0.14);
630  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(iel, icount,ich)));
631  if ( ! histo ) continue;
632  TH2* outHisto = GetOutliers(histo);
633  TString histoTitle = histo->GetTitle();
634  histoTitle.ReplaceAll("efficiency","eff.-<eff.> for outliers");
635  outHisto->SetTitle(histoTitle.Data());
636  outList.Add(outHisto);
637  outHisto->SetMinimum(-0.08);
638  outHisto->SetMaximum(0.08);
639  outHisto->DrawCopy("COLZ");
640  // } // loop on counts
641  outCanList.Add(can);
642  } // loop on chambers
643 }
644 
645 //_____________________________________________________________________________
646 void MaskTrending ( TObjArray runNumArray, TString defaultStorage, TList& outCanList, TList& outList )
647 {
649 
650  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
651 
652  TObjArray maskedList(8);
653  TObjArray auxList(8);
654  auxList.SetOwner();
655  TString histoName = "", histoTitle = "";
656  for(Int_t icath=0; icath<2; icath++){
657  TString cathName = ( icath==0 ) ? "bendPlane" : "nonBendPlane";
658  for(Int_t ich=0; ich<kNch; ich++){
659  histoName = Form("%sMaskCh%i", cathName.Data(), 11+ich);
660  histoTitle = Form("Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
661  TH2* histo = new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
662  histo->GetYaxis()->SetTitle("Board Id");
663 // histo->SetOption("COLZ");
664  Int_t imask = 2*ich + icath;
665  maskedList.AddAt(histo, imask);
666  auxList.AddAt(histo->Clone(Form("%s_aux",histoName.Data())), imask);
667  } // loop on chambers
668  } // loop on cathodes
669 
670  TArrayS xyPatternAll[2];
671  for(Int_t icath=0; icath<2; icath++){
672  xyPatternAll[icath].Set(kNch);
673  xyPatternAll[icath].Reset(0xFFFF);
674  }
675 
676  TList* ocdbFileList = 0x0;
677  Int_t previousRun = -1;
678  AliMUONDigitMaker* digitMaker = 0x0;
679  AliMUONDigitStoreV2R digitStore;
680 
681  AliMUONCalibrationData* calibData = 0x0;
682  AliMUONTriggerUtilities* trigUtilities = 0x0;
683  for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
684  TString runNumString = runNumArray.At(irun)->GetName();
685  Int_t runNumber = runNumString.Atoi();
686 
687  if ( IsOCDBChanged(runNumber, previousRun, ocdbFileList) ) {
688  AliCDBManager::Instance()->SetRun(runNumber);
689 
690  if ( ! digitMaker ) {
691  digitMaker = new AliMUONDigitMaker(kFALSE);
692  // Create a store with all digits in trigger
693  for ( Int_t iboard=1; iboard<=234; iboard++ ) {
694  digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
695  }
696  }
697 
698  if ( ! ocdbFileList ) ocdbFileList = GetOCDBList("MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
699 
700  delete calibData;
701  calibData = new AliMUONCalibrationData (runNumber);
702  delete trigUtilities;
703  trigUtilities = new AliMUONTriggerUtilities (calibData);
704  }
705 
706  previousRun = runNumber;
707 
708  TIter next(digitStore.CreateIterator());
709  AliMUONVDigit* dig = 0x0;
710  while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
711  Int_t icath = dig->Cathode();
712  Int_t detElemId = dig->DetElemId();
713  Int_t ich = detElemId/100-11;
714  Int_t iboard = dig->ManuId();
715  Int_t imask = 2*ich + icath;
716  static_cast<TH2*>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
717  static_cast<TH2*>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(Double_t)trigUtilities->IsMasked(*dig));
718  }
719  } // loop on runs
720  delete calibData;
721  delete trigUtilities;
722  delete digitMaker;
723 
724  TString canName = "";
725  for ( Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
726  TH2* histo = static_cast<TH2*>(maskedList.At(imask));
727  histo->Divide(static_cast<TH2*>(auxList.At(imask)));
728  SetRunAxisRange(histo);
729  outList.Add(histo);
730 
731  canName = Form("%sCan", histo->GetName());
732  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
733  can->SetRightMargin(0.14);
734  histo->SetStats(kFALSE);
735  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
736  histo->DrawCopy("COLZ");
737  outCanList.Add(can);
738  }
739 }
740 
741 //_____________________________________________________________________________
742 Bool_t CheckPattern ( TString trigName, TObjArray* keepArray, TObjArray* rejectArray )
743 {
745  for ( Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
746  if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) ) return kFALSE;
747  } // loop on reject pattern
748 
749  for ( Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
750  if ( trigName.Contains(keepArray->At(ipat)->GetName() ) ) return kTRUE;
751  } // loop on keep pattern
752 
753  return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
754 }
755 
756 //_____________________________________________________________________________
757 TObjArray* BuildListOfTrigger ( const TObjArray* triggerArray, TString keepPattern = "", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
758 {
760  TObjArray* selectedList = new TObjArray();
761  selectedList->SetOwner();
762  TObjArray* rejectArray = rejectPattern.Tokenize(",");
763  TObjArray* keepArray = keepPattern.Tokenize(",");
764 
765  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
766  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
767  if ( CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(new TObjString(currTrigName.Data()));
768  }
769 
770  delete rejectArray;
771  delete keepArray;
772 
773  return selectedList;
774 
775 }
776 
777 //_____________________________________________________________________________
778 TString FindCorrespondingTrigger ( TString checkTrigger, TObjArray* triggerArray )
779 {
781  TString foundName = "";
782  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
783  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
784  TObjArray* array = currTrigName.Tokenize("-");
785  TString collisionType = array->At(1)->GetName();
786  delete array;
787  collisionType.Append("-");
788  collisionType.Prepend("-");
789  if ( checkTrigger.Contains(collisionType.Data()) ) {
790  foundName = currTrigName;
791  break;
792  }
793  }
794 
795  return foundName;
796 }
797 
798 //_____________________________________________________________________________
799 void ScalerTrending ( TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList& outCanList, TList& outList )
800 {
802  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
803 
804  //trigger count from ESDs
805  TFile *file = TFile::Open(mergedFileName.Data());
806  AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny("MUON_QA"))->FindObjectAny("eventCounters");
807 
808  //Build the trigger list for trigger with muon only in readout and min. bias triggers
809  TString triggerListName = ccol->GetKeyWords("trigger");
810 
811  TObjArray selectedTriggerArray, selectedL0TriggerArray;
812  selectedTriggerArray.SetOwner();
813  selectedL0TriggerArray.SetOwner();
814 
815  const Int_t nScaler = 3;
816  TString sScaler[nScaler] = {"L0B","L2A","L0BRATE"};
817  enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
818  Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
819  TObjArray hFromQA;
820  TObjArray hFromScalers;
821  TObjArray hOutput;
822 
823 
824  TString sHistName, sHistNameFull, sTitleName;
825  Int_t nRuns = runNumArray.GetEntries();
826 
827  //
828  //Fill histos for Scalers and QA
829  //
830  //loop on run list
831  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
832 
833  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
834  Int_t runNr = sRunNr.Atoi();
835  AliAnalysisTriggerScalers triggerScaler(runNr);
836  AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(triggerScaler.GetOCDBObject("GRP/CTP/Config",runNr));
837  const TObjArray& trClasses = tc->GetClasses();
838 
839  Int_t ibin = iRun+1;
840 
841  for ( Int_t itype=0; itype<2; itype++ ) {
842  TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
843  TString matchTrig = ( itype == 0 ) ? "" : "C0TVX";
844  TObjArray* selectedTrigArrayForRun = BuildListOfTrigger(&trClasses, matchTrig);
845 
846  //loop on trigger list
847  for ( Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
848 
849  TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
850  if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) ) continue;
851  if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(new TObjString(currTrigName));
852 
853  //loop on scaler list
854  for ( Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
855 
856  if ( itype == 1 && iScaler != kL0B ) continue;
857 
858  //from Scalers
859  TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data(),kFALSE);
860 
861  sHistName = Form("%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
862  sHistNameFull = Form("Scalers_%s",sHistName.Data());
863 
864  TH1* hist = (TH1*) hFromScalers.FindObject(sHistNameFull);
865  if ( ! hist ) {
866  hist = new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(Double_t)nRuns);
867  hist->LabelsOption("v");
868  hist->GetXaxis()->SetLabelSize(0.02);
869  hist->SetDirectory(0);
870  hist->SetMinimum(1);
871  hist->SetMaximum(maxScaler[0]);
872  hFromScalers.AddLast(hist);
873  hOutput.AddLast(hist);
874  if ( iScaler == kL2A ) {
875  sHistNameFull = "QA_" + sHistName;
876  hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
877  }
878  }
879  Double_t *tab = (Double_t*) graph->GetY();
880  if ( tab ) hist->SetBinContent(ibin,tab[0]);
881  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
882  delete graph;
883 
884  //from QA
885  if ( iScaler != kL2A ) continue;
886  TH1* histCounters = static_cast<TH1*>(ccol->Get("run",Form("run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
887  sHistNameFull = sHistNameFull = "QA_" + sHistName;
888  hist = (TH1*) hFromQA.FindObject(sHistNameFull);
889  if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
890  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
891  delete histCounters;
892  }//end loop on scaler list
893  }//end loop on trigger list
894  } // end loop on type
895  }//end loop on run list
896 
897 
898  if ( selectedTriggerArray.GetEntries() == 0 ) {
899  printf("No trigger selected from trigger list %s\n",triggerListName.Data());
900  return;
901  }
902  printf("Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
903 
904  printf("Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
905 
906  //Set options for QA and Scalers histos
907 
908  for ( Int_t itype=0; itype<2; itype++ ) {
909  TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
910  for ( Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
911  TH1* histo = static_cast<TH1*> ( currList->At(ihisto) );
912  if (!histo) continue;
913  // Write run number to each bin
914  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
915  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
916  Int_t ibin = iRun+1;
917  TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
918  if ( ! binLabel.IsNull() ) continue;
919  histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
920  }
921  histo->SetStats(kFALSE);
922  }
923  }
924 
925 
926  //Loop on histos from scalers and QA and create resulting histos from scalers
927  const Int_t nHisto = 3;
928  TString sHisto[nHisto] = {"L0BoverL0BC0TVX","L2AoverL0B","L2AQAoverSCALERS"};
929  TString sTitleHisto[nHisto] = {"L0B trigger / L0BC0TVX","L2A / L0B","L2A from QA / L2A from SCALERS"};
930  // TString sHisto[nHisto] = {"L2AoverL0B","L2AQAoverSCALERS"};
931 
932  //loop on trigger list
933  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
934 
935  sHistNameFull = Form("Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
936  TH1* histo1 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
937  if (!histo1) continue;
938 
939 
940  //C0TVX
941  TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
942  TString sL0Trig = FindCorrespondingTrigger(sTrig, &selectedL0TriggerArray);
943 
944  sHistNameFull = Form("Scalers_%s_L0B",sL0Trig.Data());
945 
946  TH1* histo0 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
947  if ( histo0 ) {
948  sHistNameFull = Form("%s_%s",sHisto[0].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
949  TH1* histo10 = (TH1*) histo1->Clone(sHistNameFull);
950  histo10->SetTitle(sTitleHisto[0].Data());
951  histo10->Sumw2();
952  histo10->Divide(histo0);
953  histo10->SetMaximum(10);
954  histo10->SetMinimum(1e-5);
955  //outList.Add(histo10);
956  hOutput.AddLast(histo10);
957  //outList.Add(histo0);
958  //outList.Add(histo1);
959  }
960 
961  //DEADTIME
962  sHistNameFull = Form("Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
963  TH1* histo2 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
964  if (!histo2) continue;
965 
966  sHistNameFull = Form("%s_%s",sHisto[1].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
967  TH1* histo3 = (TH1*) histo2->Clone(sHistNameFull);
968  histo3->SetTitle(sTitleHisto[1]);
969  histo3->Sumw2();
970  histo3->Divide(histo1);
971  histo3->SetMaximum(1.2);
972  histo3->SetMinimum(1e-5);
973  //outList.Add(histo3);
974  hOutput.AddLast(histo3);
975 
976  //QA over Scalers
977  sHistNameFull = Form("QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
978  TH1* histo4 = static_cast<TH1*> ( hFromQA.FindObject(sHistNameFull) );
979  if (!histo4) continue;
980 
981  sHistNameFull = Form("%s_%s",sHisto[2].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
982  TH1* histo5 = (TH1*) histo4->Clone(sHistNameFull);
983  histo5->SetTitle(sTitleHisto[2]);
984  histo5->Sumw2();
985  histo5->Divide(histo2);
986  histo5->SetMaximum(1.2);
987  histo5->SetMinimum(5e-1);
988  //outList.Add(histo5);
989  hOutput.AddLast(histo5);
990  }
991 
992  // Plot all on canvases (only canvases will be saved)
993  const Int_t nCanvases = nScaler + nHisto;
994  TString sCanvases[nCanvases];
995  for (Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
996  for (Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
997 
998  //loop on canvases
999  for ( Int_t iCan = 0; iCan < nCanvases; iCan++) {
1000  TCanvas* canvas = new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
1001  TLegend* leg = new TLegend(0.72,0.7,0.9,0.85);
1002  leg->SetBorderSize(1);
1003  if ( iCan != 4 ) canvas->SetLogy();
1004  TString optDraw = "e";
1005 
1006  //loop on trigger list
1007  Int_t icolor = 1;
1008  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
1009 
1010  if ( iCan < nScaler ) sHistNameFull = Form("Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
1011  else sHistNameFull = Form("%s_%s",sCanvases[iCan].Data(),selectedTriggerArray.At(iTrig)->GetName());
1012  TH1* histo1 = static_cast<TH1*> ( hOutput.FindObject(sHistNameFull) );
1013  if (!histo1) continue;
1014 
1015  if ( icolor == 10 ) icolor++;
1016  histo1->SetLineColor(icolor++);
1017  histo1->Draw(optDraw);
1018  optDraw = "esame";
1019 
1020  leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),"l");
1021  }
1022 
1023  leg->Draw();
1024  outList.Add(canvas);
1025  outCanList.Add(canvas);
1026  }
1027 
1028  file->Close();
1029 }
1030 
1031 //_____________________________________________________________________________
1032 void trigEffQA(TString fileListName, TString outFilename = "", TString defaultStorage = "raw://", Bool_t doScalers = kFALSE, TString trackerQAmergedOut="QAresults_merged.root")
1033 {
1035  ifstream inFile(fileListName.Data());
1036  TObjArray fileNameArray, runNumArray;
1037  fileNameArray.SetOwner();
1038  runNumArray.SetOwner();
1039  TString currString = "";
1040  if (inFile.is_open()) {
1041  while (! inFile.eof() ) {
1042  currString.ReadLine(inFile); // Read line
1043  if ( ! currString.Contains(".root") ||
1044  currString.BeginsWith("#") ) continue;
1045  fileNameArray.AddLast(new TObjString(currString.Data()));
1046  Int_t runNum = GetRunNumber(currString);
1047  runNumArray.AddLast(new TObjString(Form("%i",runNum)));
1048  }
1049  inFile.close();
1050  }
1051  else {
1052  printf("Fatal: cannot open input file %s\n",fileListName.Data());
1053  return;
1054  }
1055 
1056  runNumArray.Sort();
1057 
1058  // Instead of using the efficiency stored in the QA output
1059  // search for the new efficiency produced with trigger tracks only
1060  TObjArray* finalFileNameArray = ChangeFilenames(fileNameArray);
1061 
1062  TList outCanList, outList;
1063  TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1064  if ( SetAndCheckOCDB(defaultStorage) ) {
1065  MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1066  if ( doScalers ) {
1067  if ( gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1068  printf("Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1069  }
1070  else {
1071  ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1072  }
1073  }
1074  }
1075 
1076  delete finalFileNameArray;
1077 
1078  if ( outFilename.IsNull() ) return;
1079 
1080  TString outCanName = outFilename;
1081  outCanName.ReplaceAll(".root",".pdf");
1082  for ( Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1083  TString canName = outCanName;
1084  if ( ican == 0 ) canName.Append("("); // open pdf file
1085  else if ( ican == outCanList.GetEntries()-1 ) canName.Append(")"); // close pdf file
1086  static_cast<TCanvas*>(outCanList.At(ican))->Print(canName.Data());
1087  }
1088  // There is a bug when creating a pdf
1089  // So create a ps and then convert via epstopdf
1090  if ( outCanName.Contains(".ps") || outCanName.Contains(".eps") ) {
1091  gSystem->Exec(Form("epstopdf %s", outCanName.Data()));
1092  gSystem->Exec(Form("rm %s", outCanName.Data()));
1093  }
1094 
1095  TFile* outFile = new TFile(outFilename.Data(), "recreate");
1096  outList.Write();
1097  outFile->Close();
1098 }
Int_t color[]
const Int_t kNch
Definition: trigEffQA.C:42
void SetMyStyle()
Definition: trigEffQA.C:46
TSystem * gSystem
Bool_t SetAndCheckOCDB(TString defaultStorage)
Definition: trigEffQA.C:324
TH2 * GetOutliers(TH2 *histo, Double_t nSigmas=3.)
Definition: trigEffQA.C:403
TH1 * GetHisto(TString histoName, TFile *file, TList *histoList)
Definition: trigEffQA.C:267
TString FindCorrespondingTrigger(TString checkTrigger, TObjArray *triggerArray)
Definition: trigEffQA.C:778
Double_t * GetConditionalEffErr(Double_t *effErr1, Double_t *effErr2, Double_t *effErrBoth, Int_t exclude=-1)
Definition: trigEffQA.C:193
const Double_t kZero
Definition: trigEffQA.C:43
Double_t * GetProdErr(Double_t *effErr, Int_t exclude, Int_t nFactors=kNch)
Definition: trigEffQA.C:172
Bool_t IsRunNum(TString stringToken)
Definition: trigEffQA.C:72
TObjArray * BuildListOfTrigger(const TObjArray *triggerArray, TString keepPattern="", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM")
Definition: trigEffQA.C:757
Int_t GetRunNumber(TString filePath)
Definition: trigEffQA.C:97
void ScalerTrending(TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList &outCanList, TList &outList)
Definition: trigEffQA.C:799
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
TObjArray * ChangeFilenames(const TObjArray &fileNameArray)
Definition: trigEffQA.C:126
void SetRunAxisRange(TH1 *histo, TString runAxis="X")
Definition: trigEffQA.C:79
Double_t * GetBinomial(Double_t *effErr1, Double_t *effErr2=0x0, Double_t *effErrBoth=0x0)
Definition: trigEffQA.C:221
TFile * file
Bool_t IsOCDBChanged(Int_t currRun, Int_t previousRun, TList *fileList)
Definition: trigEffQA.C:384
void MaskTrending(TObjArray runNumArray, TString defaultStorage, TList &outCanList, TList &outList)
Definition: trigEffQA.C:646
void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList &outCanList, TList &outList)
Definition: trigEffQA.C:424
Int_t GetEffIndex(Int_t iel, Int_t icount, Int_t ich=-1)
Definition: trigEffQA.C:280
TList * GetOCDBList(TString ocdbDirs)
Definition: trigEffQA.C:288
Bool_t CheckPattern(TString trigName, TObjArray *keepArray, TObjArray *rejectArray)
Definition: trigEffQA.C:742
TString prod[]
total number of productions
void trigEffQA(TString fileListName, TString outFilename="", TString defaultStorage="raw://", Bool_t doScalers=kFALSE, TString trackerQAmergedOut="QAresults_merged.root")
Definition: trigEffQA.C:1032