AliPhysics  914d8ff (914d8ff)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //_____________________________________________________________________________
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 Bool_t CheckOCDBFile ( TString cdbDir, Int_t runNum )
289 {
295  if ( runNum >= 0 ) AliCDBManager::Instance()->SetRun(runNum);
296  TList* list = AliCDBManager::Instance()->GetAll(cdbDir.Data());
297  if ( list->GetEntries() == 0 ) {
298  printf("Warning: no entry found in %s for run %i\n",cdbDir.Data(),runNum);
299  return kFALSE;
300  }
301  return kTRUE;
302 }
303 
304 //_____________________________________________________________________________
305 TList* GetOCDBList ( TString ocdbDirs )
306 {
308  TString storageType = AliCDBManager::Instance()->GetDefaultStorage()->GetType();
309  Bool_t isGrid = storageType.Contains("alien");
310  TString baseFolder = AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder();
311 
312  TList* outList = new TList();
313  outList->SetOwner();
314  TObjArray* dirNameList = ocdbDirs.Tokenize(",");
315  for ( Int_t idir=0; idir<dirNameList->GetEntries(); idir++ ) {
316  TString fullPath = Form("%s/%s",baseFolder.Data(),dirNameList->At(idir)->GetName());
317  if ( isGrid ) {
318  TGridResult *res = gGrid->Ls(fullPath.Data());
319  if (!res) return 0x0;
320  for ( Int_t ires=0; ires<res->GetEntries(); ires++ ) {
321  TString currFile = static_cast<TMap*>(res->At(ires))->GetValue("name")->GetName();
322  outList->Add(new TObjString(currFile));
323  }
324  delete res;
325  }
326  else {
327  TString fileListStr = gSystem->GetFromPipe(Form("ls %s",fullPath.Data()));
328  TObjArray* fileList = fileListStr.Tokenize("\n");
329  for ( Int_t ires=0; ires<fileList->GetEntries(); ires++ ) {
330  TString currFile = fileList->At(ires)->GetName();
331  outList->Add(new TObjString(currFile));
332  }
333  delete fileList;
334  }
335  }
336  delete dirNameList;
337  return outList;
338 }
339 
340 //_____________________________________________________________________________
341 Bool_t SetAndCheckOCDB ( TString defaultStorage )
342 {
344  if ( defaultStorage.IsNull() ) {
345  printf("Default storage not specified. Nothing done\n");
346  return kFALSE;
347  }
348 
349  if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
350  printf("Default storage already set: nothing done\n");
351  return kTRUE;
352  }
353 
354  if ( defaultStorage.Contains("alien://") || defaultStorage.Contains("raw://") ) {
355  if ( ! gGrid ) TGrid::Connect("alien://");
356  if ( ! gGrid ) {
357  printf("Error: Problem connetting to grid: default storage not set\n");
358  return kFALSE;
359  }
360  }
361 
362  AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data());
363 
364  if ( defaultStorage.Contains("raw://") ) return kTRUE;
365 
366  Bool_t isOk = kTRUE;
367 
368  if ( AliCDBManager::Instance()->IsDefaultStorageSet() ) {
369  TString searchDir = "MUON/Calib/MappingData";
370  TString fullPath = Form("%s/%s",defaultStorage.Data(),searchDir.Data());
371  TList* ocdbList = GetOCDBList(searchDir);
372  if ( ocdbList->GetEntries() == 0 ) {
373  printf("No entries in %s\n",fullPath.Data());
374  isOk = kFALSE;
375  }
376  else {
377  TString checkFile = Form("%s/%s",fullPath.Data(),ocdbList->At(0)->GetName());
378  checkFile.ReplaceAll("local://","");
379  checkFile.ReplaceAll("folder=","");
380  checkFile.ReplaceAll("Folder=","");
381  TFile* file = TFile::Open(checkFile.Data());
382  if ( ! file ) {
383  printf("Cannot access test file: %s\n", checkFile.Data());
384  isOk = kFALSE;
385  }
386  delete file;
387  }
388  delete ocdbList;
389  }
390  else {
391  printf("Tried to set the default storage, but something went wrong.\n");
392  isOk = kFALSE;
393  }
394 
395  if ( ! isOk ) printf("Please check path %s\n",defaultStorage.Data());
396 
397  return isOk;
398 }
399 
400 //_____________________________________________________________________________
401 Bool_t IsOCDBChanged ( Int_t currRun, Int_t previousRun, TList* fileList )
402 {
404  if ( ! fileList ) return kTRUE;
405  for ( Int_t ifile=0; ifile<fileList->GetEntries(); ifile++ ) {
406  TString filename = static_cast<TObjString*>(fileList->At(ifile))->GetString();
407  filename.ReplaceAll("Run","");
408  TObjArray* array = filename.Tokenize("_");
409  Int_t firstRun = static_cast<TObjString*>(array->At(0))->GetString().Atoi();
410  Int_t lastRun = static_cast<TObjString*>(array->At(1))->GetString().Atoi();
411  delete array;
412  Bool_t isCurrRunInside = ( currRun >= firstRun && currRun <= lastRun );
413  Bool_t isPreviousRunInside = ( previousRun >= firstRun && previousRun <= lastRun );
414  if ( isCurrRunInside != isPreviousRunInside ) return kTRUE;
415  }
416  return kFALSE;
417 }
418 
419 //_____________________________________________________________________________
420 TH2* GetOutliers ( TH2* histo, Double_t nSigmas = 3. )
421 {
422  TH2* outHisto = static_cast<TH2*>(histo->Clone());
423  outHisto->SetName(Form("%s_outlier",histo->GetName()));
424  outHisto->Reset();
425  for ( Int_t ybin=1; ybin<=histo->GetYaxis()->GetNbins(); ybin++ ) {
426  TH1* auxHisto = histo->ProjectionX("projectionOutlier",ybin,ybin);
427  if ( auxHisto->Integral() == 0. ) continue;
428  auxHisto->Fit("pol0","Q0");
429  Double_t mean = auxHisto->GetFunction("pol0")->GetParameter(0);
430  for ( Int_t xbin=1; xbin<=auxHisto->GetXaxis()->GetNbins(); xbin++ ) {
431  Double_t err = auxHisto->GetBinError(xbin);
432  if ( err == 0. ) continue;
433  if ( TMath::Abs(auxHisto->GetBinContent(xbin)-mean)/err < nSigmas ) continue;
434  outHisto->SetBinContent(xbin,ybin,auxHisto->GetBinContent(xbin)-mean);
435  }
436  delete auxHisto;
437  }
438  return outHisto;
439 }
440 
441 //_____________________________________________________________________________
442 void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList& outCanList, TList& outList)
443 {
445  TString elementName[3] = { "Chamber", "RPC", "Board" };
446  TString countTypeName[4] = { "allTracks", "bendPlane", "nonBendPlane", "bothPlanes" };
447 
448  TString filename = "", effName = "", effTitle = "";
449 
450  SetMyStyle();
451  Double_t effValues[3][2*kNch];
452  const Int_t kNgraphs = kNch*3*2+3;
453  TObjArray effList(kNgraphs);
454  effList.SetOwner();
455  const Int_t kNeffVsRun = kNgraphs+1;
456  TObjArray effVsRunList(kNeffVsRun);
457 
458  effName = "totalEffEvolution";
459  effTitle = "Multinomial probability of firing at least 3/4 chambers";
460  TH1D* totalEff = new TH1D(effName.Data(), effTitle.Data(), 1, 0., 1.);
461  effVsRunList.AddAt(totalEff, kNeffVsRun-1);
462 
463  TString runNumString = "";
464  for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
465  effList.Clear();
466  runNumString = runNumArray.At(irun)->GetName();
467 
468  // Search corresponding file (for sorting)
469  for ( Int_t ifile=0; ifile<fileNameArray.GetEntries(); ifile++ ) {
470  filename = fileNameArray.At(ifile)->GetName();
471  if ( filename.Contains(runNumString.Data()) ) break;
472  }
473 
474  if ( filename.Contains("alien://") && ! gGrid ) gGrid->Connect("alien://");
475 
476  //
477  // First get the list of efficiency graphs
478  //
479 
480  // Chamber efficiency
481  TFile* file = TFile::Open(filename.Data());
482  if ( ! file ) {
483  printf("Warning: cannot find %s\n", filename.Data());
484  continue;
485  }
486 
487  TList* trigEffList = (TList*)file->FindObjectAny("triggerChamberEff");
488  if ( ! trigEffList ) {
489  printf("Warning: histo list not found in %s.\n", filename.Data());
490  continue;
491  }
492  if ( trigEffList->GetEntries() == 0 ) {
493  printf("Warning: empty trigger list in file %s. Probably no MUON info there. Skip.\n", filename.Data());
494  continue;
495  }
496 
497  TH1* histoDen = 0x0;
498  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts; icount++ ) {
499  effName = countTypeName[icount] + "Count" + elementName[0];
500  if ( icount == 0 ) {
501  histoDen = GetHisto(effName, file, trigEffList);
502  continue;
503  }
504 
505  TH1* histoNum = GetHisto(effName, file, trigEffList);
506  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum, histoDen,"e0");
507  effName.ReplaceAll("Count","Eff");
508  graph->SetName(effName.Data());
509  effList.AddAt(graph, GetEffIndex(0, icount-1));
510  }
511  file->Close();
512 
513  if ( ! histoDen ) {
514  printf("Error: cannot find histograms in file %s. Skip to next\n", filename.Data());
515  continue;
516  }
517 
518  // RPC/board efficiency
519  AliMUONTriggerChamberEfficiency trigChEff(filename);
520  for ( Int_t iel=1; iel<3; iel++ ) {
521  for ( Int_t ich=0; ich<kNch; ich++ ) {
522  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
523  TObject* obj = trigChEff.GetEffObject(2-iel, icount, ich);
524  effList.AddAt(obj->Clone(Form("%s_cloned",obj->GetName())), GetEffIndex(iel, icount, ich));
525  }
526  }
527  }
528 
529  // Fill efficiency vs run
530  for ( Int_t iel=0; iel<3; iel++ ) {
531  for ( Int_t ich=0; ich<kNch; ich++ ) {
532  for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
533  TGraphAsymmErrors* graph = static_cast<TGraphAsymmErrors*>(effList.At(GetEffIndex(iel, icount, ich)));
534  Int_t nPoints = ( iel == 0 ) ? 1 : graph->GetN();
535  for ( Int_t ipoint=0; ipoint<nPoints; ipoint++ ) {
536  Int_t currPoint = ( iel == 0 ) ? ich : ipoint;
537  Double_t xpt, ypt;
538  graph->GetPoint(currPoint, xpt, ypt);
539  effValues[icount][ich] = ypt;
540  Int_t ihisto = GetEffIndex(iel,icount,ich);
541  TH2* effHisto = static_cast<TH2*>(effVsRunList.At(ihisto));
542  if ( ! effHisto ) {
543  effName = Form("effEvolution%s%s", countTypeName[icount+1].Data(), elementName[iel].Data());
544  effTitle = Form("Trigger chamber efficiency vs run");
545  if ( iel>0 ) {
546  effName += Form("Ch%i", 11+ich);
547  effTitle += Form(" for chamber %i", 11+ich);
548  }
549  effHisto = new TH2D(effName.Data(), effTitle.Data(), 1, 0., 1., graph->GetN(), xpt-0.5, xpt-0.5+(Double_t)graph->GetN());
550  effVsRunList.AddAt(effHisto, ihisto);
551  }
552  Int_t currBin = effHisto->Fill(runNumString.Data(), xpt, ypt);
553  Double_t err = 0.5*(graph->GetErrorYlow(ipoint) + graph->GetErrorYhigh(ipoint));
554  Int_t binx, biny, binz;
555  effHisto->GetBinXYZ(currBin, binx, biny, binz);
556  effHisto->SetBinError(binx, biny, err);
557  effValues[icount][ich+kNch] = err;
558  } // loop on points
559  } // loop on counts
560  } // loop on chambers
561  if ( iel > 0 ) continue;
562  Double_t* binomialEff = GetBinomial(effValues[0], effValues[1], effValues[2]);
563  Int_t currBin = totalEff->Fill(runNumString, binomialEff[0]);
564  // CAVEAT!!!!
565  // Well, error calculation of the binomial efficiency is a mess...
566  // Sometimes it happens that efficiency + error > 1.
567  // In that case reduce the error.
568  totalEff->SetBinError(currBin, TMath::Min(binomialEff[1], 1.-binomialEff[0]));
569  delete [] binomialEff;
570  } // loop on detection elements
571  } // loop on runs
572 
573  // Set correct range (do not show last empty bins)
574  for ( Int_t ihisto=0; ihisto<effVsRunList.GetEntries(); ihisto++ ) {
575  TH1* histo = static_cast<TH1*>(effVsRunList.At(ihisto));
576  if ( ! histo ) continue;
577  SetRunAxisRange(histo);
578  outList.Add(histo);
579  //histo->GetXaxis()->SetLabelSize(0.03);
580  }
581 
582  TString canName = "totalEff";
583  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
584  TH1* totEff = (TH1*)effVsRunList.At(kNeffVsRun-1);
585  totEff->GetYaxis()->SetRangeUser(0.9,1.05);
586  totEff->GetYaxis()->SetTitle("Probability to satisfy trigger conditions (3/4)");
587  totEff->SetStats(kFALSE);
588  totEff->DrawCopy();
589  outCanList.Add(can);
590 
591  Int_t color[3] = {kBlack, kRed, kBlue};
592  Int_t markStyle[3] = {20, 24, 26};
593  TLegend* leg = 0x0;
594 
595  for ( Int_t ich=0; ich<kNch; ich++ ) {
596  canName = Form("trigEffCh%i", 11+ich);
597  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
598  can->SetGridy();
599  leg = new TLegend(0.7, 0.8, 0.96, 0.92);
600  leg->SetBorderSize(1);
601  //can->Divide(2,2);
602  TString drawOpt = "e";
603  for(Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++) {
604  //can->cd(icount+1);
605  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(0, icount)));
606  if ( ! histo ) continue;
607  TH1* chEff = histo->ProjectionX(Form("effEvolutionCh%i",11+ich), ich+1, ich+1);
608  chEff->SetTitle(Form("%s for chamber %i", histo->GetTitle(), 11+ich));
609  chEff->GetYaxis()->SetRangeUser(0.9,1.02);
610  chEff->SetStats(kFALSE);
611  chEff->GetYaxis()->SetTitle("Trigger chamber efficiency");
612  TH1* copyEff = chEff->DrawCopy(drawOpt.Data());
613  copyEff->SetLineColor(color[icount]);
614  copyEff->SetMarkerColor(color[icount]);
615  copyEff->SetMarkerStyle(markStyle[icount]);
616  leg->AddEntry(copyEff, countTypeName[icount+1].Data(), "lp");
617  drawOpt = "esame";
618  } // loop on counts
619  leg->Draw("same");
620  outCanList.Add(can);
621  } // loop on chambers
622 
623  for ( Int_t iel=1; iel<3; iel++ ) {
624  for ( Int_t ich=0; ich<kNch; ich++ ) {
625  Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff; // Just plot the efficiency for both
626 // for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
627  canName = Form("trigEff%sCh%i", 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  histo->SetStats(kFALSE);
633  histo->GetYaxis()->SetTitle(elementName[iel].Data());
634  // FIX issue when plotting 2D histos in aliroot on linux
635  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
636  histo->DrawCopy("COLZ");
637 // } // loop on counts
638  outCanList.Add(can);
639  } // loop on chambers
640  } // loop on detection element type
641 
642 
643  // Find outliers in RPC efficiency
644  for ( Int_t ich=0; ich<kNch; ich++ ) {
645  Int_t icount = AliMUONTriggerEfficiencyCells::kBothPlanesEff; // Just plot the efficiency for both
646  Int_t iel = 1;
647  // for ( Int_t icount=0; icount<AliMUONTriggerEfficiencyCells::kNcounts-1; icount++ ) {
648  canName = Form("trigEff%sCh%i_outliers", elementName[iel].Data(), 11+ich);
649  can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
650  can->SetRightMargin(0.14);
651  TH2* histo = static_cast<TH2*>(effVsRunList.At(GetEffIndex(iel, icount,ich)));
652  if ( ! histo || histo->Integral() == 0. ) continue;
653  TH2* outHisto = GetOutliers(histo);
654  TString histoTitle = histo->GetTitle();
655  histoTitle.ReplaceAll("efficiency","eff.-<eff.> for outliers");
656  outHisto->SetTitle(histoTitle.Data());
657  outList.Add(outHisto);
658  outHisto->SetMinimum(-0.08);
659  outHisto->SetMaximum(0.08);
660  outHisto->DrawCopy("COLZ");
661  // } // loop on counts
662  outCanList.Add(can);
663  } // loop on chambers
664 }
665 
666 //_____________________________________________________________________________
667 void MaskTrending ( TObjArray runNumArray, TString defaultStorage, TList& outCanList, TList& outList )
668 {
670 
671  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
672 
673  TObjArray maskedList(8);
674  TObjArray auxList(8);
675  auxList.SetOwner();
676  TString histoName = "", histoTitle = "";
677  for(Int_t icath=0; icath<2; icath++){
678  TString cathName = ( icath==0 ) ? "bendPlane" : "nonBendPlane";
679  for(Int_t ich=0; ich<kNch; ich++){
680  histoName = Form("%sMaskCh%i", cathName.Data(), 11+ich);
681  histoTitle = Form("Chamber %i - %s: fraction of masked channels", 11+ich, cathName.Data());
682  TH2* histo = new TH2D(histoName.Data(), histoTitle.Data(),1,0.,1., 234, 0.5, 234. + 0.5);
683  histo->GetYaxis()->SetTitle("Board Id");
684 // histo->SetOption("COLZ");
685  Int_t imask = 2*ich + icath;
686  maskedList.AddAt(histo, imask);
687  auxList.AddAt(histo->Clone(Form("%s_aux",histoName.Data())), imask);
688  } // loop on chambers
689  } // loop on cathodes
690 
691  TArrayS xyPatternAll[2];
692  for(Int_t icath=0; icath<2; icath++){
693  xyPatternAll[icath].Set(kNch);
694  xyPatternAll[icath].Reset(0xFFFF);
695  }
696 
697  TList* ocdbFileList = 0x0;
698  Int_t previousRun = -1;
699  AliMUONDigitMaker* digitMaker = 0x0;
700  AliMUONDigitStoreV2R digitStore;
701 
702  AliMUONCalibrationData* calibData = 0x0;
703  AliMUONTriggerUtilities* trigUtilities = 0x0;
704  for ( Int_t irun=0; irun<runNumArray.GetEntries(); irun++ ) {
705  TString runNumString = runNumArray.At(irun)->GetName();
706  Int_t runNumber = runNumString.Atoi();
707 
708  if ( IsOCDBChanged(runNumber, previousRun, ocdbFileList) ) {
709  AliCDBManager::Instance()->SetRun(runNumber);
710 
711  if ( ! digitMaker ) {
712  digitMaker = new AliMUONDigitMaker(kFALSE);
713  // Create a store with all digits in trigger
714  for ( Int_t iboard=1; iboard<=234; iboard++ ) {
715  digitMaker->TriggerDigits(iboard, xyPatternAll, digitStore, kFALSE);
716  }
717  }
718 
719  if ( ! ocdbFileList ) ocdbFileList = GetOCDBList("MUON/Calib/GlobalTriggerCrateConfig,MUON/Calib/RegionalTriggerConfig,MUON/Calib/LocalTriggerBoardMasks");
720 
721  delete calibData;
722  calibData = new AliMUONCalibrationData (runNumber);
723  delete trigUtilities;
724  trigUtilities = new AliMUONTriggerUtilities (calibData);
725  }
726 
727  previousRun = runNumber;
728 
729  TIter next(digitStore.CreateIterator());
730  AliMUONVDigit* dig = 0x0;
731  while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) ) {
732  Int_t icath = dig->Cathode();
733  Int_t detElemId = dig->DetElemId();
734  Int_t ich = detElemId/100-11;
735  Int_t iboard = dig->ManuId();
736  Int_t imask = 2*ich + icath;
737  static_cast<TH2*>(auxList.At(imask))->Fill(runNumString.Data(),iboard,1.);
738  static_cast<TH2*>(maskedList.At(imask))->Fill(runNumString.Data(),iboard,(Double_t)trigUtilities->IsMasked(*dig));
739  }
740  } // loop on runs
741  delete calibData;
742  delete trigUtilities;
743  delete digitMaker;
744 
745  TString canName = "";
746  for ( Int_t imask=0; imask<maskedList.GetEntries(); imask++ ) {
747  TH2* histo = static_cast<TH2*>(maskedList.At(imask));
748  histo->Divide(static_cast<TH2*>(auxList.At(imask)));
749  SetRunAxisRange(histo);
750  outList.Add(histo);
751 
752  canName = Form("%sCan", histo->GetName());
753  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
754  can->SetRightMargin(0.14);
755  histo->SetStats(kFALSE);
756  if ( histo->GetMinimum() == 0. && histo->GetMaximum() == 0. ) histo->SetMaximum(0.1);
757  histo->DrawCopy("COLZ");
758  outCanList.Add(can);
759  }
760 }
761 
762 //_____________________________________________________________________________
763 Bool_t CheckPattern ( TString trigName, TObjArray* keepArray, TObjArray* rejectArray )
764 {
766  for ( Int_t ipat=0; ipat<rejectArray->GetEntries(); ++ipat ) {
767  if ( trigName.Contains(rejectArray->At(ipat)->GetName() ) ) return kFALSE;
768  } // loop on reject pattern
769 
770  for ( Int_t ipat=0; ipat<keepArray->GetEntries(); ++ipat ) {
771  if ( trigName.Contains(keepArray->At(ipat)->GetName() ) ) return kTRUE;
772  } // loop on keep pattern
773 
774  return ( keepArray->GetEntries() == 0 ) ? kTRUE : kFALSE;
775 }
776 
777 //_____________________________________________________________________________
778 TObjArray* BuildListOfTrigger ( const TObjArray* triggerArray, TString keepPattern = "", TString rejectPattern="OTHER,TRUE,PHI,ANY,EMC,-ACE-,-ABCE-,WU,MUP,SPI,SHM" )
779 {
781  TObjArray* selectedList = new TObjArray();
782  selectedList->SetOwner();
783  TObjArray* rejectArray = rejectPattern.Tokenize(",");
784  TObjArray* keepArray = keepPattern.Tokenize(",");
785 
786  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
787  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
788  if ( CheckPattern(currTrigName, keepArray, rejectArray) ) selectedList->AddLast(new TObjString(currTrigName.Data()));
789  }
790 
791  delete rejectArray;
792  delete keepArray;
793 
794  return selectedList;
795 
796 }
797 
798 //_____________________________________________________________________________
799 TString FindCorrespondingTrigger ( TString checkTrigger, TObjArray* triggerArray )
800 {
802  TString foundName = "";
803  for ( Int_t iTrig = 0; iTrig < triggerArray->GetEntries(); iTrig++ ){
804  TString currTrigName = ((TObjString*)triggerArray->At(iTrig))->GetName();
805  TObjArray* array = currTrigName.Tokenize("-");
806  TString collisionType = array->At(1)->GetName();
807  delete array;
808  collisionType.Append("-");
809  collisionType.Prepend("-");
810  if ( checkTrigger.Contains(collisionType.Data()) ) {
811  foundName = currTrigName;
812  break;
813  }
814  }
815 
816  return foundName;
817 }
818 
819 //_____________________________________________________________________________
820 void ScalerTrending ( TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList& outCanList, TList& outList )
821 {
823  if ( ! SetAndCheckOCDB(defaultStorage) ) return;
824 
825  //trigger count from ESDs
826  TFile *file = TFile::Open(mergedFileName.Data());
827  AliCounterCollection* ccol = (AliCounterCollection*)((TDirectoryFile*)file->FindObjectAny("MUON_QA"))->FindObjectAny("eventCounters");
828 
829  //Build the trigger list for trigger with muon only in readout and min. bias triggers
830  TString triggerListName = ccol->GetKeyWords("trigger");
831 
832  TObjArray selectedTriggerArray, selectedL0TriggerArray;
833  selectedTriggerArray.SetOwner();
834  selectedL0TriggerArray.SetOwner();
835 
836  const Int_t nScaler = 3;
837  TString sScaler[nScaler] = {"L0B","L2A","L0BRATE"};
838  enum eScaler {kL0B = 0, kL2A=1, kL0BRATE=2};
839  Float_t maxScaler[nScaler] = {1e8,1e7,1e6};
840  TObjArray hFromQA;
841  TObjArray hFromScalers;
842  TObjArray hOutput;
843 
844  TString cdbDir = "GRP/CTP/Config";
845 
846 
847  TString sHistName, sHistNameFull, sTitleName;
848  Int_t nRuns = runNumArray.GetEntries();
849 
850  //
851  //Fill histos for Scalers and QA
852  //
853  //loop on run list
854  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
855 
856  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
857  Int_t runNr = sRunNr.Atoi();
858  if ( ! CheckOCDBFile(cdbDir, runNr)) continue;
859  AliAnalysisTriggerScalers triggerScaler(runNr);
860  AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(triggerScaler.GetOCDBObject(cdbDir.Data(),runNr));
861  const TObjArray& trClasses = tc->GetClasses();
862 
863  Int_t ibin = iRun+1;
864 
865  for ( Int_t itype=0; itype<2; itype++ ) {
866  TObjArray* currSelectedList = ( itype == 0 ) ? &selectedTriggerArray : &selectedL0TriggerArray;
867  TString matchTrig = ( itype == 0 ) ? "" : "C0TVX";
868  TObjArray* selectedTrigArrayForRun = BuildListOfTrigger(&trClasses, matchTrig);
869 
870  //loop on trigger list
871  for ( Int_t iTrig = 0; iTrig < selectedTrigArrayForRun->GetEntries(); iTrig++ ) {
872 
873  TString currTrigName = selectedTrigArrayForRun->At(iTrig)->GetName();
874  if ( itype == 0 && ! triggerListName.Contains(currTrigName.Data()) ) continue;
875  if ( ! currSelectedList->FindObject(currTrigName.Data()) ) currSelectedList->Add(new TObjString(currTrigName));
876 
877  //loop on scaler list
878  for ( Int_t iScaler = 0; iScaler < nScaler; iScaler++ ) {
879 
880  if ( itype == 1 && iScaler != kL0B ) continue;
881 
882  //from Scalers
883  TGraph* graph = triggerScaler.PlotTrigger(currTrigName.Data(),sScaler[iScaler].Data(),kFALSE);
884 
885  sHistName = Form("%s_%s",currTrigName.Data(),sScaler[iScaler].Data());
886  sHistNameFull = Form("Scalers_%s",sHistName.Data());
887 
888  TH1* hist = (TH1*) hFromScalers.FindObject(sHistNameFull);
889  if ( ! hist ) {
890  hist = new TH1D(sHistNameFull,sHistName,nRuns,1.,1.+(Double_t)nRuns);
891  hist->LabelsOption("v");
892  hist->GetXaxis()->SetLabelSize(0.02);
893  hist->SetDirectory(0);
894  hist->SetMinimum(1);
895  hist->SetMaximum(maxScaler[0]);
896  hFromScalers.AddLast(hist);
897  hOutput.AddLast(hist);
898  if ( iScaler == kL2A ) {
899  sHistNameFull = "QA_" + sHistName;
900  hFromQA.AddLast(hist->Clone(sHistNameFull.Data()));
901  }
902  }
903  Double_t *tab = (Double_t*) graph->GetY();
904  if ( tab ) hist->SetBinContent(ibin,tab[0]);
905  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
906  delete graph;
907 
908  //from QA
909  if ( iScaler != kL2A ) continue;
910  TH1* histCounters = static_cast<TH1*>(ccol->Get("run",Form("run:%s/trigger:%s",sRunNr.Data(),currTrigName.Data())));
911  sHistNameFull = sHistNameFull = "QA_" + sHistName;
912  hist = (TH1*) hFromQA.FindObject(sHistNameFull);
913  if ( histCounters ) hist->SetBinContent(ibin,histCounters->GetSumOfWeights());
914  hist->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
915  delete histCounters;
916  }//end loop on scaler list
917  }//end loop on trigger list
918  } // end loop on type
919  }//end loop on run list
920 
921 
922  if ( selectedTriggerArray.GetEntries() == 0 ) {
923  printf("No trigger selected from trigger list %s\n",triggerListName.Data());
924  return;
925  }
926  printf("Nr of triggers selected %i\n",selectedTriggerArray.GetEntries());
927 
928  printf("Nr of T0 triggers selected %i\n",selectedL0TriggerArray.GetEntries());
929 
930  //Set options for QA and Scalers histos
931 
932  for ( Int_t itype=0; itype<2; itype++ ) {
933  TObjArray* currList = ( itype == 0 ) ? &hFromScalers : &hFromQA;
934  for ( Int_t ihisto=0; ihisto<currList->GetEntriesFast(); ihisto++ ) {
935  TH1* histo = static_cast<TH1*> ( currList->At(ihisto) );
936  if (!histo) continue;
937  // Write run number to each bin
938  for ( Int_t iRun = 0; iRun < runNumArray.GetEntries(); iRun++ ) {
939  TString sRunNr = ((TObjString*)runNumArray.At(iRun))->GetString();
940  Int_t ibin = iRun+1;
941  TString binLabel = histo->GetXaxis()->GetBinLabel(ibin);
942  if ( ! binLabel.IsNull() ) continue;
943  histo->GetXaxis()->SetBinLabel(ibin,sRunNr.Data());
944  }
945  histo->SetStats(kFALSE);
946  }
947  }
948 
949 
950  //Loop on histos from scalers and QA and create resulting histos from scalers
951  const Int_t nHisto = 3;
952  TString sHisto[nHisto] = {"L0BoverL0BC0TVX","L2AoverL0B","L2AQAoverSCALERS"};
953  TString sTitleHisto[nHisto] = {"L0B trigger / L0BC0TVX","L2A / L0B","L2A from QA / L2A from SCALERS"};
954  // TString sHisto[nHisto] = {"L2AoverL0B","L2AQAoverSCALERS"};
955 
956  //loop on trigger list
957  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
958 
959  sHistNameFull = Form("Scalers_%s_L0B",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
960  TH1* histo1 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
961  if (!histo1) continue;
962 
963 
964  //C0TVX
965  TString sTrig = ( (TObjString*) selectedTriggerArray.At(iTrig) )->GetName();
966  TString sL0Trig = FindCorrespondingTrigger(sTrig, &selectedL0TriggerArray);
967 
968  sHistNameFull = Form("Scalers_%s_L0B",sL0Trig.Data());
969 
970  TH1* histo0 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
971  if ( histo0 ) {
972  sHistNameFull = Form("%s_%s",sHisto[0].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
973  TH1* histo10 = (TH1*) histo1->Clone(sHistNameFull);
974  histo10->SetTitle(sTitleHisto[0].Data());
975  histo10->Sumw2();
976  histo10->Divide(histo0);
977  histo10->SetMaximum(10);
978  histo10->SetMinimum(1e-5);
979  //outList.Add(histo10);
980  hOutput.AddLast(histo10);
981  //outList.Add(histo0);
982  //outList.Add(histo1);
983  }
984 
985  //DEADTIME
986  sHistNameFull = Form("Scalers_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
987  TH1* histo2 = static_cast<TH1*> ( hFromScalers.FindObject(sHistNameFull) );
988  if (!histo2) continue;
989 
990  sHistNameFull = Form("%s_%s",sHisto[1].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
991  TH1* histo3 = (TH1*) histo2->Clone(sHistNameFull);
992  histo3->SetTitle(sTitleHisto[1]);
993  histo3->Sumw2();
994  histo3->Divide(histo1);
995  histo3->SetMaximum(1.2);
996  histo3->SetMinimum(1e-5);
997  //outList.Add(histo3);
998  hOutput.AddLast(histo3);
999 
1000  //QA over Scalers
1001  sHistNameFull = Form("QA_%s_L2A",((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
1002  TH1* histo4 = static_cast<TH1*> ( hFromQA.FindObject(sHistNameFull) );
1003  if (!histo4) continue;
1004 
1005  sHistNameFull = Form("%s_%s",sHisto[2].Data(),((TObjString*) selectedTriggerArray.At(iTrig))->GetName());
1006  TH1* histo5 = (TH1*) histo4->Clone(sHistNameFull);
1007  histo5->SetTitle(sTitleHisto[2]);
1008  histo5->Sumw2();
1009  histo5->Divide(histo2);
1010  histo5->SetMaximum(1.2);
1011  histo5->SetMinimum(5e-1);
1012  //outList.Add(histo5);
1013  hOutput.AddLast(histo5);
1014  }
1015 
1016  // Plot all on canvases (only canvases will be saved)
1017  const Int_t nCanvases = nScaler + nHisto;
1018  TString sCanvases[nCanvases];
1019  for (Int_t iScaler = 0; iScaler < nScaler; iScaler++) sCanvases[iScaler] = sScaler[iScaler];
1020  for (Int_t iHisto = 0; iHisto < nHisto; iHisto++) sCanvases[nScaler+iHisto] = sHisto[iHisto];
1021 
1022  //loop on canvases
1023  for ( Int_t iCan = 0; iCan < nCanvases; iCan++) {
1024  TCanvas* canvas = new TCanvas(sCanvases[iCan],sCanvases[iCan],200,10,600,600);
1025  TLegend* leg = new TLegend(0.72,0.7,0.9,0.85);
1026  leg->SetBorderSize(1);
1027  if ( iCan != 4 ) canvas->SetLogy();
1028  TString optDraw = "e";
1029 
1030  //loop on trigger list
1031  Int_t icolor = 1;
1032  for ( Int_t iTrig = 0; iTrig < selectedTriggerArray.GetEntries(); iTrig++ ) {
1033 
1034  if ( iCan < nScaler ) sHistNameFull = Form("Scalers_%s_%s",selectedTriggerArray.At(iTrig)->GetName(),sCanvases[iCan].Data());
1035  else sHistNameFull = Form("%s_%s",sCanvases[iCan].Data(),selectedTriggerArray.At(iTrig)->GetName());
1036  TH1* histo1 = static_cast<TH1*> ( hOutput.FindObject(sHistNameFull) );
1037  if (!histo1) continue;
1038 
1039  if ( icolor == 10 ) icolor++;
1040  histo1->SetLineColor(icolor++);
1041  histo1->Draw(optDraw);
1042  optDraw = "esame";
1043 
1044  leg->AddEntry(histo1,selectedTriggerArray.At(iTrig)->GetName(),"l");
1045  }
1046 
1047  leg->Draw();
1048  outList.Add(canvas);
1049  outCanList.Add(canvas);
1050  }
1051 
1052  file->Close();
1053 }
1054 
1055 //_____________________________________________________________________________
1056 void trigEffQA(TString fileListName, TString outFilename = "", TString defaultStorage = "raw://", Bool_t doScalers = kFALSE, TString trackerQAmergedOut="QAresults_merged.root")
1057 {
1059  ifstream inFile(fileListName.Data());
1060  TObjArray fileNameArray, runNumArray;
1061  fileNameArray.SetOwner();
1062  runNumArray.SetOwner();
1063  TString currString = "";
1064  if (inFile.is_open()) {
1065  while (! inFile.eof() ) {
1066  currString.ReadLine(inFile); // Read line
1067  if ( ! currString.Contains(".root") ||
1068  currString.BeginsWith("#") ) continue;
1069  fileNameArray.AddLast(new TObjString(currString.Data()));
1070  Int_t runNum = GetRunNumber(currString);
1071  runNumArray.AddLast(new TObjString(Form("%i",runNum)));
1072  }
1073  inFile.close();
1074  }
1075  else {
1076  printf("Fatal: cannot open input file %s\n",fileListName.Data());
1077  return;
1078  }
1079 
1080  runNumArray.Sort();
1081 
1082  // Instead of using the efficiency stored in the QA output
1083  // search for the new efficiency produced with trigger tracks only
1084  TObjArray* finalFileNameArray = ChangeFilenames(fileNameArray);
1085 
1086  TList outCanList, outList;
1087  TrigEffTrending(runNumArray, *finalFileNameArray, outCanList, outList);
1088  if ( SetAndCheckOCDB(defaultStorage) ) {
1089  MaskTrending(runNumArray, defaultStorage, outCanList, outList);
1090  if ( doScalers ) {
1091  if ( gSystem->AccessPathName(trackerQAmergedOut.Data()) ) {
1092  printf("Warning: cannot perform scaler trending:\n merged QA from tracker\n %s\n does not exist\n",trackerQAmergedOut.Data());
1093  }
1094  else {
1095  ScalerTrending(runNumArray, trackerQAmergedOut, defaultStorage, outCanList, outList);
1096  }
1097  }
1098  }
1099 
1100  delete finalFileNameArray;
1101 
1102  if ( outFilename.IsNull() ) return;
1103 
1104  TString outCanName = outFilename;
1105  outCanName.ReplaceAll(".root",".pdf");
1106  for ( Int_t ican=0; ican<outCanList.GetEntries(); ican++ ) {
1107  TString canName = outCanName;
1108  if ( ican == 0 ) canName.Append("("); // open pdf file
1109  else if ( ican == outCanList.GetEntries()-1 ) canName.Append(")"); // close pdf file
1110  static_cast<TCanvas*>(outCanList.At(ican))->Print(canName.Data());
1111  }
1112  // There is a bug when creating a pdf
1113  // So create a ps and then convert via epstopdf
1114  if ( outCanName.Contains(".ps") || outCanName.Contains(".eps") ) {
1115  gSystem->Exec(Form("epstopdf %s", outCanName.Data()));
1116  gSystem->Exec(Form("rm %s", outCanName.Data()));
1117  }
1118 
1119  TFile* outFile = new TFile(outFilename.Data(), "recreate");
1120  outList.Write();
1121  outFile->Close();
1122 }
Int_t color[]
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
double Double_t
Definition: External.C:58
const Int_t kNch
Definition: trigEffQA.C:42
TCanvas * canvas
Definition: DrawAnaELoss.C:28
void SetMyStyle()
Definition: trigEffQA.C:46
TSystem * gSystem
Bool_t SetAndCheckOCDB(TString defaultStorage)
Definition: trigEffQA.C:341
TH2 * GetOutliers(TH2 *histo, Double_t nSigmas=3.)
Definition: trigEffQA.C:420
TList * list
TH1 * GetHisto(TString histoName, TFile *file, TList *histoList)
Definition: trigEffQA.C:267
TString FindCorrespondingTrigger(TString checkTrigger, TObjArray *triggerArray)
Definition: trigEffQA.C:799
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: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
Definition: External.C:228
Definition: External.C:212
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:778
Int_t GetRunNumber(TString filePath)
Definition: trigEffQA.C:97
void ScalerTrending(TObjArray runNumArray, TString mergedFileName, TString defaultStorage, TList &outCanList, TList &outList)
Definition: trigEffQA.C:820
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
Bool_t CheckOCDBFile(TString cdbDir, Int_t runNum)
Definition: trigEffQA.C:288
Definition: External.C:220
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:401
void MaskTrending(TObjArray runNumArray, TString defaultStorage, TList &outCanList, TList &outList)
Definition: trigEffQA.C:667
void TrigEffTrending(TObjArray runNumArray, TObjArray fileNameArray, TList &outCanList, TList &outList)
Definition: trigEffQA.C:442
bool Bool_t
Definition: External.C:53
Int_t GetEffIndex(Int_t iel, Int_t icount, Int_t ich=-1)
Definition: trigEffQA.C:280
TList * GetOCDBList(TString ocdbDirs)
Definition: trigEffQA.C:305
Bool_t CheckPattern(TString trigName, TObjArray *keepArray, TObjArray *rejectArray)
Definition: trigEffQA.C:763
Definition: External.C:196
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:1056