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