AliPhysics  v5-07-15-01 (b3d7633)
 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 ) {
471  printf("Warning: histo list not found in %s.\n", filename.Data());
472  continue;
473  }
474  if ( trigEffList->GetEntries() == 0 ) {
475  printf("Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
476  continue;
477  }
478 
479  TH1* histoDen = 0x0;
480  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
481  effName = countTypeName[icount] + "Count" + elementName[0];
482  if ( icount == 0 ) {
483  histoDen = GetHisto(effName, file, trigEffList);
484  continue;
485  }
486 
487  TH1* histoNum = GetHisto(effName, file, trigEffList);
488  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum, histoDen,"e0");
489  effName.ReplaceAll("Count","Eff");
490  graph->SetName(effName.Data());
491  effList.AddAt(graph, GetEffIndex(0, icount-1));
492  }
493  file->Close();
494 
495  if ( ! histoDen ) {
496  printf("Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
497  continue;
498  }
499 
500  // RPC/board efficiency
501  AliMUONTriggerChamberEfficiency trigChEff(filename);
502  for ( Int_t iel=1; iel<3; iel++ ) {
503  for ( Int_t ich=0; ich<kNch; ich++ ) {
504  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
505  TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
506  effList.AddAt(obj->Clone(Form("%s_cloned",obj->GetName())), GetEffIndex(iel, icount, ich));
507  }
508  }
509  }
510 
511  // Fill efficiency vs run
512  for ( Int_t iel=0; iel<3; iel++ ) {
513  for ( Int_t ich=0; ich<kNch; ich++ ) {
514  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
515  TGraphAsymmErrors* graph = static_cast<TGraphAsymmErrors*>(effList.At(GetEffIndex(iel, icount, ich)));
516  Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
517  for ( Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
518  Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
519  Double_t xpt, ypt;
520  graph->GetPoint(currPoint, xpt, ypt);
521  effValues[icount][ich] = ypt;
522  Int_t ihisto = GetEffIndex(iel,icount,ich);
523  TH2* effHisto = static_cast<TH2*>(effVsRunList.At(ihisto));
524  if ( ! effHisto ) {
525  effName = Form("effEvolution%s%s", countTypeName[icount+1].Data(), elementName[iel].Data());
526  effTitle = Form("Trigger chamber efficiency vs run");
527  if ( iel>0 ) {
528  effName += Form("Ch%i", 11+ich);
529  effTitle += Form(" for chamber %i", 11+ich);
530  }
531  effHisto = new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(Double_t)graph->GetN());
532  effVsRunList.AddAt(effHisto, ihisto);
533  }
534  Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
535  Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
536  Int_t binx, biny, binz;
537  effHisto->GetBinXYZ(currBin, binx, biny, binz);
538  effHisto->SetBinError(binx, biny, err);
539  effValues[icount][ich+kNch] = err;
540  } // loop on points
541  } // loop on counts
542  } // loop on chambers
543  if ( iel > 0 ) continue;
544  Double_t* binomialEff = GetBinomial(effValues[0], effValues[1], effValues[2]);
545  Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
546  // CAVEAT!!!!
547  // Well, error calculation of the binomial efficiency is a mess...
548  // Sometimes it happens that efficiency + error > 1.
549  // In that case reduce the error.
550  totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
551  delete [] binomialEff;
552  } // loop on detection elements
553  } // loop on runs
554 
555  // Set correct range (do not show last empty bins)
556  for ( Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
557  TH1* histo = static_cast<TH1*>(effVsRunList.At(ihisto));
558  if ( ! histo ) continue;
559  SetRunAxisRange(histo);
560  outList.Add(histo);
561  //histo->GetXaxis()->SetLabelSize(0.03);
562  }
563 
564  TString canName = "totalEff";
565  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
566  TH1* totEff = (TH1*)effVsRunList.At(kNeffVsRun-1);
567  totEff->GetYaxis()->SetRangeUser(0.9,1.05);
568  totEff->GetYaxis()->SetTitle("Probability to satisfy trigger conditions (3/4)");
569  totEff->SetStats(kFALSE);
570  totEff->DrawCopy();
571  outCanList.Add(can);
572 
573  Int_t color[3] = {kBlack, kRed, kBlue};
574  Int_t markStyle[3] = {20, 24, 26};
575  TLegend* leg = 0x0;
576 
577  for ( Int_t ich=0; ich<kNch; ich++ ) {
578  canName = Form("trigEffCh%i", 11+ich);
579  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
580  can->SetGridy();
581  leg = new TLegend(0.7, 0.8, 0.96, 0.92);
582  leg->SetBorderSize(1);
583  //can->Divide(2,2);
584  TString drawOpt = "e";
585  for(Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
586  //can->cd(icount+1);
587  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(0, icount)));
588  if ( ! histo ) continue;
589  TH1* chEff = histo->ProjectionX(Form("effEvolutionCh%i",11+ich), ich+1, ich+1);
590  chEff->SetTitle(Form("%s for chamber %i", histo->GetTitle(), 11+ich));
591  chEff->GetYaxis()->SetRangeUser(0.9,1.02);
592  chEff->SetStats(kFALSE);
593  chEff->GetYaxis()->SetTitle("Trigger chamber efficiency");
594  TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
595  copyEff->SetLineColor(color[icount]);
596  copyEff->SetMarkerColor(color[icount]);
597  copyEff->SetMarkerStyle(markStyle[icount]);
598  leg->AddEntry(copyEff, countTypeName[icount+1].Data(), "lp");
599  drawOpt = "esame";
600  } // loop on counts
601  leg->Draw("same");
602  outCanList.Add(can);
603  } // loop on chambers
604 
605  for ( Int_t iel=1; iel<3; iel++ ) {
606  for ( Int_t ich=0; ich<kNch; ich++ ) {
607  Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff; // Just plot the efficiency for both
608 // for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
609  canName = Form("trigEff%sCh%i", elementName[iel].Data(), 11+ich);
610  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
611  can->SetRightMargin(0.14);
612  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(iel, icount,ich)));
613  if ( ! histo ) continue;
614  histo->SetStats(kFALSE);
615  histo->GetYaxis()->SetTitle(elementName[iel].Data());
616  // FIX issue when plotting 2D histos in aliroot on linux
617  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
618  histo->DrawCopy("COLZ");
619 // } // loop on counts
620  outCanList.Add(can);
621  } // loop on chambers
622  } // loop on detection element type
623 
624 
625  // Find outliers in RPC efficiency
626  for ( Int_t ich=0; ich<kNch; ich++ ) {
627  Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff; // Just plot the efficiency for both
628  Int_t iel = 1;
629  // for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
630  canName = Form("trigEff%sCh%i_outliers", elementName[iel].Data(), 11+ich);
631  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
632  can->SetRightMargin(0.14);
633  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(iel, icount,ich)));
634  if ( ! histo || histo->Integral() == 0. ) continue;
635  TH2* outHisto = GetOutliers(histo);
636  TString histoTitle = histo->GetTitle();
637  histoTitle.ReplaceAll("efficiency","eff.-<eff.> for outliers");
638  outHisto->SetTitle(histoTitle.Data());
639  outList.Add(outHisto);
640  outHisto->SetMinimum(-0.08);
641  outHisto->SetMaximum(0.08);
642  outHisto->DrawCopy("COLZ");
643  // } // loop on counts
644  outCanList.Add(can);
645  } // loop on chambers
646 }
647 
648 //_____________________________________________________________________________
649 void MaskTrending ( TObjArray runNumArray, TString defaultStorage, TList& outCanList, TList& outList )
650 {
652 
653  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
654 
655  TObjArray maskedList(8);
656  TObjArray auxList(8);
657  auxList.SetOwner();
658  TString histoName = "", histoTitle = "";
659  for(Int_t icath=0; icath<2; icath++){
660  TString cathName = ( icath==0 ) ? "bendPlane" : "nonBendPlane";
661  for(Int_t ich=0; ich<kNch; ich++){
662  histoName = Form("%sMaskCh%i", cathName.Data(), 11+ich);
663  histoTitle = Form("Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
664  TH2* histo = new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
665  histo->GetYaxis()->SetTitle("Board Id");
666 // histo->SetOption("COLZ");
667  Int_t imask = 2*ich + icath;
668  maskedList.AddAt(histo, imask);
669  auxList.AddAt(histo->Clone(Form("%s_aux",histoName.Data())), imask);
670  } // loop on chambers
671  } // loop on cathodes
672 
673  TArrayS xyPatternAll[2];
674  for(Int_t icath=0; icath<2; icath++){
675  xyPatternAll[icath].Set(kNch);
676  xyPatternAll[icath].Reset(0xFFFF);
677  }
678 
679  TList* ocdbFileList = 0x0;
680  Int_t previousRun = -1;
681  AliMUONDigitMaker* digitMaker = 0x0;
682  AliMUONDigitStoreV2R digitStore;
683 
684  AliMUONCalibrationData* calibData = 0x0;
685  AliMUONTriggerUtilities* trigUtilities = 0x0;
686  for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
687  TString runNumString = runNumArray.At(irun)->GetName();
688  Int_t runNumber = runNumString.Atoi();
689 
690  if ( IsOCDBChanged(runNumber, previousRun, ocdbFileList) ) {
691  AliCDBManager::Instance()->SetRun(runNumber);
692 
693  if ( ! digitMaker ) {
694  digitMaker = new AliMUONDigitMaker(kFALSE);
695  // Create a store with all digits in trigger
696  for ( Int_t iboard=1; iboard<=234; iboard++ ) {
697  digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
698  }
699  }
700 
701  if ( ! ocdbFileList ) ocdbFileList = GetOCDBList("MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
702 
703  delete calibData;
704  calibData = new AliMUONCalibrationData (runNumber);
705  delete trigUtilities;
706  trigUtilities = new AliMUONTriggerUtilities (calibData);
707  }
708 
709  previousRun = runNumber;
710 
711  TIter next(digitStore.CreateIterator());
712  AliMUONVDigit* dig = 0x0;
713  while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
714  Int_t icath = dig->Cathode();
715  Int_t detElemId = dig->DetElemId();
716  Int_t ich = detElemId/100-11;
717  Int_t iboard = dig->ManuId();
718  Int_t imask = 2*ich + icath;
719  static_cast<TH2*>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
720  static_cast<TH2*>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(Double_t)trigUtilities->IsMasked(*dig));
721  }
722  } // loop on runs
723  delete calibData;
724  delete trigUtilities;
725  delete digitMaker;
726 
727  TString canName = "";
728  for ( Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
729  TH2* histo = static_cast<TH2*>(maskedList.At(imask));
730  histo->Divide(static_cast<TH2*>(auxList.At(imask)));
731  SetRunAxisRange(histo);
732  outList.Add(histo);
733 
734  canName = Form("%sCan", histo->GetName());
735  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
736  can->SetRightMargin(0.14);
737  histo->SetStats(kFALSE);
738  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
739  histo->DrawCopy("COLZ");
740  outCanList.Add(can);
741  }
742 }
743 
744 //_____________________________________________________________________________
745 Bool_t CheckPattern ( TString trigName, TObjArray* keepArray, TObjArray* rejectArray )
746 {
748  for ( Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
749  if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) ) return kFALSE;
750  } // loop on reject pattern
751 
752  for ( Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
753  if ( trigName.Contains(keepArray->At(ipat)->GetName() ) ) return kTRUE;
754  } // loop on keep pattern
755 
756  return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
757 }
758 
759 //_____________________________________________________________________________
760 TObjArray* BuildListOfTrigger ( const TObjArray* triggerArray, TString keepPattern = "", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
761 {
763  TObjArray* selectedList = new TObjArray();
764  selectedList->SetOwner();
765  TObjArray* rejectArray = rejectPattern.Tokenize(",");
766  TObjArray* keepArray = keepPattern.Tokenize(",");
767 
768  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
769  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
770  if ( CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(new TObjString(currTrigName.Data()));
771  }
772 
773  delete rejectArray;
774  delete keepArray;
775 
776  return selectedList;
777 
778 }
779 
780 //_____________________________________________________________________________
781 TString FindCorrespondingTrigger ( TString checkTrigger, TObjArray* triggerArray )
782 {
784  TString foundName = "";
785  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
786  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
787  TObjArray* array = currTrigName.Tokenize("-");
788  TString collisionType = array->At(1)->GetName();
789  delete array;
790  collisionType.Append("-");
791  collisionType.Prepend("-");
792  if ( checkTrigger.Contains(collisionType.Data()) ) {
793  foundName = currTrigName;
794  break;
795  }
796  }
797 
798  return foundName;
799 }
800 
801 //_____________________________________________________________________________
802 void ScalerTrending ( TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList& outCanList, TList& outList )
803 {
805  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
806 
807  //trigger count from ESDs
808  TFile *file = TFile::Open(mergedFileName.Data());
809  AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny("MUON_QA"))->FindObjectAny("eventCounters");
810 
811  //Build the trigger list for trigger with muon only in readout and min. bias triggers
812  TString triggerListName = ccol->GetKeyWords("trigger");
813 
814  TObjArray selectedTriggerArray, selectedL0TriggerArray;
815  selectedTriggerArray.SetOwner();
816  selectedL0TriggerArray.SetOwner();
817 
818  const Int_t nScaler = 3;
819  TString sScaler[nScaler] = {"L0B","L2A","L0BRATE"};
820  enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
821  Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
822  TObjArray hFromQA;
823  TObjArray hFromScalers;
824  TObjArray hOutput;
825 
826 
827  TString sHistName, sHistNameFull, sTitleName;
828  Int_t nRuns = runNumArray.GetEntries();
829 
830  //
831  //Fill histos for Scalers and QA
832  //
833  //loop on run list
834  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
835 
836  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
837  Int_t runNr = sRunNr.Atoi();
838  AliAnalysisTriggerScalers triggerScaler(runNr);
839  AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(triggerScaler.GetOCDBObject("GRP/CTP/Config",runNr));
840  const TObjArray& trClasses = tc->GetClasses();
841 
842  Int_t ibin = iRun+1;
843 
844  for ( Int_t itype=0; itype<2; itype++ ) {
845  TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
846  TString matchTrig = ( itype == 0 ) ? "" : "C0TVX";
847  TObjArray* selectedTrigArrayForRun = BuildListOfTrigger(&trClasses, matchTrig);
848 
849  //loop on trigger list
850  for ( Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
851 
852  TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
853  if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) ) continue;
854  if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(new TObjString(currTrigName));
855 
856  //loop on scaler list
857  for ( Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
858 
859  if ( itype == 1 && iScaler != kL0B ) continue;
860 
861  //from Scalers
862  TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data(),kFALSE);
863 
864  sHistName = Form("%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
865  sHistNameFull = Form("Scalers_%s",sHistName.Data());
866 
867  TH1* hist = (TH1*) hFromScalers.FindObject(sHistNameFull);
868  if ( ! hist ) {
869  hist = new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(Double_t)nRuns);
870  hist->LabelsOption("v");
871  hist->GetXaxis()->SetLabelSize(0.02);
872  hist->SetDirectory(0);
873  hist->SetMinimum(1);
874  hist->SetMaximum(maxScaler[0]);
875  hFromScalers.AddLast(hist);
876  hOutput.AddLast(hist);
877  if ( iScaler == kL2A ) {
878  sHistNameFull = "QA_" + sHistName;
879  hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
880  }
881  }
882  Double_t *tab = (Double_t*) graph->GetY();
883  if ( tab ) hist->SetBinContent(ibin,tab[0]);
884  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
885  delete graph;
886 
887  //from QA
888  if ( iScaler != kL2A ) continue;
889  TH1* histCounters = static_cast<TH1*>(ccol->Get("run",Form("run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
890  sHistNameFull = sHistNameFull = "QA_" + sHistName;
891  hist = (TH1*) hFromQA.FindObject(sHistNameFull);
892  if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
893  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
894  delete histCounters;
895  }//end loop on scaler list
896  }//end loop on trigger list
897  } // end loop on type
898  }//end loop on run list
899 
900 
901  if ( selectedTriggerArray.GetEntries() == 0 ) {
902  printf("No trigger selected from trigger list %s\n",triggerListName.Data());
903  return;
904  }
905  printf("Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
906 
907  printf("Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
908 
909  //Set options for QA and Scalers histos
910 
911  for ( Int_t itype=0; itype<2; itype++ ) {
912  TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
913  for ( Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
914  TH1* histo = static_cast<TH1*> ( currList->At(ihisto) );
915  if (!histo) continue;
916  // Write run number to each bin
917  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
918  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
919  Int_t ibin = iRun+1;
920  TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
921  if ( ! binLabel.IsNull() ) continue;
922  histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
923  }
924  histo->SetStats(kFALSE);
925  }
926  }
927 
928 
929  //Loop on histos from scalers and QA and create resulting histos from scalers
930  const Int_t nHisto = 3;
931  TString sHisto[nHisto] = {"L0BoverL0BC0TVX","L2AoverL0B","L2AQAoverSCALERS"};
932  TString sTitleHisto[nHisto] = {"L0B trigger / L0BC0TVX","L2A / L0B","L2A from QA / L2A from SCALERS"};
933  // TString sHisto[nHisto] = {"L2AoverL0B","L2AQAoverSCALERS"};
934 
935  //loop on trigger list
936  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
937 
938  sHistNameFull = Form("Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
939  TH1* histo1 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
940  if (!histo1) continue;
941 
942 
943  //C0TVX
944  TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
945  TString sL0Trig = FindCorrespondingTrigger(sTrig, &selectedL0TriggerArray);
946 
947  sHistNameFull = Form("Scalers_%s_L0B",sL0Trig.Data());
948 
949  TH1* histo0 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
950  if ( histo0 ) {
951  sHistNameFull = Form("%s_%s",sHisto[0].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
952  TH1* histo10 = (TH1*) histo1->Clone(sHistNameFull);
953  histo10->SetTitle(sTitleHisto[0].Data());
954  histo10->Sumw2();
955  histo10->Divide(histo0);
956  histo10->SetMaximum(10);
957  histo10->SetMinimum(1e-5);
958  //outList.Add(histo10);
959  hOutput.AddLast(histo10);
960  //outList.Add(histo0);
961  //outList.Add(histo1);
962  }
963 
964  //DEADTIME
965  sHistNameFull = Form("Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
966  TH1* histo2 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
967  if (!histo2) continue;
968 
969  sHistNameFull = Form("%s_%s",sHisto[1].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
970  TH1* histo3 = (TH1*) histo2->Clone(sHistNameFull);
971  histo3->SetTitle(sTitleHisto[1]);
972  histo3->Sumw2();
973  histo3->Divide(histo1);
974  histo3->SetMaximum(1.2);
975  histo3->SetMinimum(1e-5);
976  //outList.Add(histo3);
977  hOutput.AddLast(histo3);
978 
979  //QA over Scalers
980  sHistNameFull = Form("QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
981  TH1* histo4 = static_cast<TH1*> ( hFromQA.FindObject(sHistNameFull) );
982  if (!histo4) continue;
983 
984  sHistNameFull = Form("%s_%s",sHisto[2].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
985  TH1* histo5 = (TH1*) histo4->Clone(sHistNameFull);
986  histo5->SetTitle(sTitleHisto[2]);
987  histo5->Sumw2();
988  histo5->Divide(histo2);
989  histo5->SetMaximum(1.2);
990  histo5->SetMinimum(5e-1);
991  //outList.Add(histo5);
992  hOutput.AddLast(histo5);
993  }
994 
995  // Plot all on canvases (only canvases will be saved)
996  const Int_t nCanvases = nScaler + nHisto;
997  TString sCanvases[nCanvases];
998  for (Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
999  for (Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
1000 
1001  //loop on canvases
1002  for ( Int_t iCan = 0; iCan < nCanvases; iCan++) {
1003  TCanvas* canvas = new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
1004  TLegend* leg = new TLegend(0.72,0.7,0.9,0.85);
1005  leg->SetBorderSize(1);
1006  if ( iCan != 4 ) canvas->SetLogy();
1007  TString optDraw = "e";
1008 
1009  //loop on trigger list
1010  Int_t icolor = 1;
1011  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
1012 
1013  if ( iCan < nScaler ) sHistNameFull = Form("Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
1014  else sHistNameFull = Form("%s_%s",sCanvases[iCan].Data(),selectedTriggerArray.At(iTrig)->GetName());
1015  TH1* histo1 = static_cast<TH1*> ( hOutput.FindObject(sHistNameFull) );
1016  if (!histo1) continue;
1017 
1018  if ( icolor == 10 ) icolor++;
1019  histo1->SetLineColor(icolor++);
1020  histo1->Draw(optDraw);
1021  optDraw = "esame";
1022 
1023  leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),"l");
1024  }
1025 
1026  leg->Draw();
1027  outList.Add(canvas);
1028  outCanList.Add(canvas);
1029  }
1030 
1031  file->Close();
1032 }
1033 
1034 //_____________________________________________________________________________
1035 void trigEffQA(TString fileListName, TString outFilename = "", TString defaultStorage = "raw://", Bool_t doScalers = kFALSE, TString trackerQAmergedOut="QAresults_merged.root")
1036 {
1038  ifstream inFile(fileListName.Data());
1039  TObjArray fileNameArray, runNumArray;
1040  fileNameArray.SetOwner();
1041  runNumArray.SetOwner();
1042  TString currString = "";
1043  if (inFile.is_open()) {
1044  while (! inFile.eof() ) {
1045  currString.ReadLine(inFile); // Read line
1046  if ( ! currString.Contains(".root") ||
1047  currString.BeginsWith("#") ) continue;
1048  fileNameArray.AddLast(new TObjString(currString.Data()));
1049  Int_t runNum = GetRunNumber(currString);
1050  runNumArray.AddLast(new TObjString(Form("%i",runNum)));
1051  }
1052  inFile.close();
1053  }
1054  else {
1055  printf("Fatal: cannot open input file %s\n",fileListName.Data());
1056  return;
1057  }
1058 
1059  runNumArray.Sort();
1060 
1061  // Instead of using the efficiency stored in the QA output
1062  // search for the new efficiency produced with trigger tracks only
1063  TObjArray* finalFileNameArray = ChangeFilenames(fileNameArray);
1064 
1065  TList outCanList, outList;
1066  TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1067  if ( SetAndCheckOCDB(defaultStorage) ) {
1068  MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1069  if ( doScalers ) {
1070  if ( gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1071  printf("Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1072  }
1073  else {
1074  ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1075  }
1076  }
1077  }
1078 
1079  delete finalFileNameArray;
1080 
1081  if ( outFilename.IsNull() ) return;
1082 
1083  TString outCanName = outFilename;
1084  outCanName.ReplaceAll(".root",".pdf");
1085  for ( Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1086  TString canName = outCanName;
1087  if ( ican == 0 ) canName.Append("("); // open pdf file
1088  else if ( ican == outCanList.GetEntries()-1 ) canName.Append(")"); // close pdf file
1089  static_cast<TCanvas*>(outCanList.At(ican))->Print(canName.Data());
1090  }
1091  // There is a bug when creating a pdf
1092  // So create a ps and then convert via epstopdf
1093  if ( outCanName.Contains(".ps") || outCanName.Contains(".eps") ) {
1094  gSystem->Exec(Form("epstopdf %s", outCanName.Data()));
1095  gSystem->Exec(Form("rm %s", outCanName.Data()));
1096  }
1097 
1098  TFile* outFile = new TFile(outFilename.Data(), "recreate");
1099  outList.Write();
1100  outFile->Close();
1101 }
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:781
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:760
Int_t GetRunNumber(TString filePath)
Definition: trigEffQA.C:97
void ScalerTrending(TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList &outCanList, TList &outList)
Definition: trigEffQA.C:802
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:649
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:745
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:1035