AliPhysics  19b3b9d (19b3b9d)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMTRChEffAnalysis.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 #include "AliMTRChEffAnalysis.h"
17 
18 // ROOT includes
19 #include <Riostream.h>
20 #include "TObjString.h"
21 #include "TObjArray.h"
22 #include "TList.h"
23 #include "TSystem.h"
24 #include "TROOT.h"
25 #include "TRegexp.h"
26 #include "TFile.h"
27 #include "TDirectory.h"
28 #include "TTree.h"
29 #include "TKey.h"
30 #include "TArrayI.h"
31 #include "TArrayD.h"
32 #include "TGrid.h"
33 #include "TGridResult.h"
34 #include "TGraphAsymmErrors.h"
35 #include "TH1.h"
36 #include "TH2.h"
37 #include "TAxis.h"
38 #include "TF1.h"
39 #include "TMath.h"
40 #include "TCanvas.h"
41 #include "TLegend.h"
42 #include "TLine.h"
43 #include "TLatex.h"
44 #include "TFileMerger.h"
45 #include "TFitResultPtr.h"
46 
47 #include "AliLog.h"
48 #include "AliMergeableCollection.h"
49 #include "AliCounterCollection.h"
50 
51 #include "AliAnalysisMuonUtility.h"
52 #include "AliTrigChEffOutput.h"
53 
54 #include "AliCDBManager.h"
55 #include "AliCDBStorage.h"
56 #include "AliCDBId.h"
57 #include "AliCDBEntry.h"
58 #include "AliMUONCDB.h"
59 #include "AliMUONTriggerEfficiencyCells.h"
60 
62 ClassImp(AliMTRChEffAnalysis) // Class implementation in ROOT context
64 
65 using std::cout;
66 using std::endl;
67 using std::cin;
68 using std::ofstream;
69 using std::ifstream;
70 
71 //________________________________________________________________________
73  TObject(),
74  fConditions(0x0),
75  fNamer(0x0)
76 {
78 
79 }
80 
81 //________________________________________________________________________
82 AliMTRChEffAnalysis::AliMTRChEffAnalysis ( const char *localFileList, const char* outputName ) :
83  TObject(),
84  fConditions(0x0),
85  fNamer(0x0)
86 {
88  InitFromLocal(localFileList,outputName);
89 }
90 
91 //________________________________________________________________________
93 {
94  //
96  //
97  delete fConditions;
98  delete fNamer;
99  for ( AliMTRChEffAnalysis::AliMTRChEffInnerObj* obj : fRunMap ) delete obj;
100  for ( AliMTRChEffAnalysis::AliMTRChEffInnerObj* obj : fMergedMap ) delete obj;
101 }
102 
103 //________________________________________________________________________
104 Bool_t AliMTRChEffAnalysis::AddSystematicCondition ( const char* physSel, const char* trigClassName, const char* centrality, Int_t itrackSel, Int_t imatch, Int_t imethod )
105 {
107  return SetCondition(physSel, trigClassName, centrality, itrackSel, imatch, imethod, kFALSE);
108 }
109 
110 //________________________________________________________________________
111 Bool_t AliMTRChEffAnalysis::AddToList ( const char *filename, const char *outputName )
112 {
114  AliTrigChEffOutput* trigOut = new AliTrigChEffOutput(filename,outputName);
115  if ( ! trigOut->GetMergeableCollection() ) {
116  AliError(Form("Cannot find %s in %s",outputName,filename));
117  return kFALSE;
118  }
119 
120  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
121 
122 // // Delete counter collection to save memory
123 // trigOut->RemoveFromList(trigOut->GetCounterCollection());
124  // Just keep counter and mergeable collections
125  TList* effHistoList = GetEffHistoList(trigOut,condition);
126 // effHistoList->SetName(filename);
127  Int_t runNum = AliAnalysisMuonUtility::GetRunNumber(filename);
128 // effHistoList->SetUniqueID(currRun.Atoi());
129 
131  Int_t idxFromRun = GetIndexFromRun(runNum);
132  if ( idxFromRun >= 0 ) obj = fRunMap[idxFromRun];
133  else {
134  obj = new AliMTRChEffAnalysis::AliMTRChEffInnerObj(filename,outputName,runNum);
135  obj->SetUniqueID(fRunMap.size());
136  fRunMap.push_back(obj);
137  }
138 
139  obj->AddEffHistoList(condition->GetName(), effHistoList);
140 
141 
142  delete trigOut;
143  return kTRUE;
144 }
145 
146 //________________________________________________________________________
148 {
150 
151  // FIXME: ugly and hardcoded, but avoid loading the mapping
152 
153  TArrayI boards;
154  if ( irpc == 0 || irpc == 9 ) {
155  Int_t arr[] = {26,27,28,29,48,49,50,51,68,69,84,85,100,101,113};
156  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
157  boards.Set(nBoards,arr);
158  if ( irpc == 9 )
159  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
160  }
161  else if ( irpc == 1 || irpc == 8 ) {
162  Int_t arr[] = {9,10,11,30,31,32,33,52,53,54,55,70,71,86,87,102,103,114};
163  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
164  boards.Set(nBoards,arr);
165  if ( irpc == 8 )
166  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
167  }
168  else if ( irpc == 2 || irpc == 7 ) {
169  Int_t arr[] = {12,13,34,35,56,57,72,73,88,89,104,105,115};
170  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
171  boards.Set(nBoards,arr);
172  if ( irpc == 7 )
173  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
174  }
175  else if ( irpc == 3 || irpc == 6 ) {
176  Int_t arr[] = {14,15,36,37,58,59,74,75,90,91,106,107,116};
177  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
178  boards.Set(nBoards,arr);
179  if ( irpc == 6 )
180  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
181  }
182  else if ( irpc == 4 || irpc == 5 ) {
183  Int_t arr[] = {16,38,60,76,92,108,117};
184  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
185  boards.Set(nBoards,arr);
186  if ( irpc == 5 )
187  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
188  }
189  else if ( irpc == 17 || irpc == 10 ) {
190  Int_t arr[] = {6,7,8,22,23,24,25,44,45,46,47,66,67,82,83,98,99,112};
191  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
192  boards.Set(nBoards,arr);
193  if ( irpc == 10 )
194  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
195  }
196  else if ( irpc == 16 || irpc == 11 ) {
197  Int_t arr[] = {4,5,20,21,42,43,64,65,80,81,96,97,111};
198  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
199  boards.Set(nBoards,arr);
200  if ( irpc == 11 )
201  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
202  }
203  else if ( irpc == 15 || irpc == 12 ) {
204  Int_t arr[] = {2,3,18,19,40,41,62,63,78,79,94,95,110};
205  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
206  boards.Set(nBoards,arr);
207  if ( irpc == 12 )
208  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
209  }
210  else if ( irpc == 14 || irpc == 13 ) {
211  Int_t arr[] = {1,17,39,61,77,93,109};
212  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
213  boards.Set(nBoards,arr);
214  if ( irpc == 13 )
215  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
216  }
217 
218  return boards;
219 }
220 
221 
222 //________________________________________________________________________
224 {
226  TList* clonedEffHistos = new TList();
227  clonedEffHistos->SetOwner();
228  TIter next(effHistos);
229  TObject* obj = 0x0;
230  while ( (obj = next()) ) {
231  clonedEffHistos->Add(obj->Clone());
232  }
233  return clonedEffHistos;
234 }
235 
236 //________________________________________________________________________
238 {
240  if ( ! HasMergedResults() ) return kFALSE;
241 
242  AliInfo("Building efficiency map for systematic uncertainties");
243 
244  TString currName = "";
245  Double_t xref=0., yref=0., xpt=0., ypt=0.;
246  Double_t nSigmas = 1.;
247 
249 
250  std::vector<std::string> systKeys = obj->GetSortKeys();
251  Int_t nSysts = systKeys.size();
252 
253  // Clone the histogram list that will contain the systematic uncertainties
254  TList* effHistos = obj->GetEffHistoList(fConditions->UncheckedAt(0)->GetName());
255  TList* systematicList = CloneEffHistoList(effHistos);
256 
257  for ( Int_t ich=0; ich<4; ich++ ) {
258  // Get the efficiency graph for the different conditions
259  // as well as the list of histograms to build the efficiency
260  TGraphAsymmErrors* checkEffList[nSysts];
261  TH1* histoList[nSysts*4];
262  TH1* systHistoList[4];
263  for ( Int_t isyst=0; isyst<nSysts; isyst++ ) {
264  effHistos = obj->GetEffHistoList(systKeys[isyst].c_str());
265  for ( Int_t icount=0; icount<4; icount++ ) {
266  currName = Namer()->GetHistoName(AliTrigChEffOutput::kHboardEff, icount, ich, -1, -1, -1);
267  histoList[4*isyst+icount] = static_cast<TH1*>(effHistos->FindObject(currName.Data()));
268  if ( isyst == 0 ) {
269  systHistoList[icount] = static_cast<TH1*>(systematicList->FindObject(currName.Data()));
270  }
271  }
272 
274  Int_t iden = 4*isyst+AliTrigChEffOutput::kAllTracks;
275  checkEffList[isyst] = new TGraphAsymmErrors(histoList[inum],histoList[iden],"e0");
276  } // loop on systematics
277  TGraphAsymmErrors* refEffList[3];
278  for ( Int_t icount=0; icount<3; icount++ ) {
279  refEffList[icount] = new TGraphAsymmErrors(histoList[icount],histoList[AliTrigChEffOutput::kAllTracks],"e0");
280  }
281 
282  // First check what condition to use for the systematic uncertainty
283  // We're searching for the one giving the maximum discrepancy from the reference
284  // not compatible with statistical uncertainty
285  // If this is not found, we'll just use the statistical uncertanty of the reference
286 
287  TGraphAsymmErrors* refGraph = checkEffList[0];
288  for ( Int_t ipt=0; ipt<refGraph->GetN(); ipt++ ) {
289  refGraph->GetPoint(ipt,xref,yref);
290  Int_t chosenSyst = -1;
291  Double_t foundAbsDiff = -1.;
292  for ( Int_t isyst=1; isyst<nSysts; isyst++ ) {
293  TGraphAsymmErrors* graph = checkEffList[isyst];
294  graph->GetPoint(ipt,xpt,ypt);
295  Double_t diff = ypt - yref;
296  Double_t err = (diff > 0.) ? graph->GetErrorYlow(ipt) : graph->GetErrorYhigh(ipt);
297  Double_t absDiff = TMath::Abs(diff);
298  if ( absDiff < nSigmas*err ) continue;
299  if ( foundAbsDiff < absDiff ) {
300  foundAbsDiff = absDiff;
301  chosenSyst = isyst;
302  }
303  } // loop on Systs
304 
305  Int_t ibin = ipt+1;
306  AliDebug(2,Form("Chamber %i board %i systematicCondition %i",11+ich,ibin,chosenSyst));
307  if ( chosenSyst >= 0 ) {
308  for ( Int_t icount=0; icount<4; icount++ ) {
309  systHistoList[icount]->SetBinContent(ibin,histoList[4*chosenSyst+icount]->GetBinContent(ibin));
310  }
311  }
312  else {
313  Double_t countAll = histoList[AliTrigChEffOutput::kAllTracks]->GetBinContent(ibin);
314  systHistoList[AliTrigChEffOutput::kAllTracks]->SetBinContent(ibin,countAll);
315  for ( Int_t icount=0; icount<3; icount++ ) {
316  TGraphAsymmErrors* graph = refEffList[icount];
317  graph->GetPoint(ipt,xpt,ypt);
318  Double_t errHigh = graph->GetErrorYhigh(ipt);
319  Double_t errLow = graph->GetErrorYlow(ipt);
320  Double_t newEff = ( errLow > errHigh ) ? ypt - errLow : ypt + errHigh;
321  Double_t newCount = TMath::Nint(newEff * countAll);
322  if ( newCount < 0 || newCount > countAll ) {
323  TString warning = Form("WARNING: ch %i board %i cath %i systDiff %g newEff %g / %g",11+ich,ibin,icount,newEff-yref,newCount,countAll);
324  if ( newCount < 0 ) newCount = 0;
325  else newCount = countAll;
326  warning += Form(" => setting numerator to %g",newCount);
327  AliWarning(warning.Data());
328  }
329  systHistoList[icount]->SetBinContent(ibin,newCount);
330  }
331  }
332  } // loop on points
333  for ( Int_t it=0; it<nSysts; it++ ) delete checkEffList[it];
334  for ( Int_t it=0; it<3; it++ ) delete refEffList[it];
335  } // loop on chambers
336  obj->AddEffHistoList("Systematics",systematicList);
337  } // loop on merged efficiencies
338 
339  return kTRUE;
340 }
341 
342 //________________________________________________________________________
344 {
346  if ( fRunMap.empty() ) {
347  AliError("The list of trigger efficiency object is not initialized. Please use either InitFromLocal, InitFromGrid or InitFromWeb");
348  return 1;
349  }
350  return 0;
351 }
352 
353 //________________________________________________________________________
354 Int_t AliMTRChEffAnalysis::CompareEfficiencies ( const char* sources, const char* titles, const char* opt, const char* canvasNameSuffix ) const
355 {
357  TString srcs(sources);
358  if ( srcs.Contains("raw://") ) {
359  AliError("The method assumes that the specified storage is a SpecificStorage. Hence, please replace raw:// with the actual path in alien, e.g.: alien://folder=/alice/data/<year>/OCDB");
360  return -2;
361  }
362  TObjArray* sourceList = srcs.Tokenize(",");
363  TObjArray effHistoLists;
364  effHistoLists.SetOwner();
365 
366  TIter next(sourceList);
367  TObjString* src = 0x0;
368  while ( (src = static_cast<TObjString*>(next())) ) {
369  TList* readList = ReadEffHistoList(src->String().Data());
370  if ( ! readList ) continue;
371  effHistoLists.Add(readList);
372  }
373 
374  return CompareEfficiencies(&effHistoLists, titles, opt, canvasNameSuffix);
375 }
376 
377 //________________________________________________________________________
378 Int_t AliMTRChEffAnalysis::CompareEfficiencies ( TObjArray* effHistoLists, const char* titles, const char* opt, const char* canvasNameSuffix ) const
379 {
381 
382  TString sTitles(titles);
383  TObjArray* titleList = sTitles.Tokenize(",");
384 
385  Int_t nDiffs = 0;
386 
387  Int_t nLists = effHistoLists->GetEntriesFast();
388 
389  TString sCanvasNameSuffix(canvasNameSuffix);
390  if ( ! sCanvasNameSuffix.IsNull() && ! sCanvasNameSuffix.BeginsWith("_") ) sCanvasNameSuffix.Prepend("_");
391 
392  Double_t xpt, ypt, xref, yref;
393  enum {kEff, kDiff, kPull};
394  TString sOpt(opt);
395  sOpt.ToLower();
396  Int_t iopt = kEff;
397  TString yTitle = "Eff.";
398  if ( sOpt.Contains("diff") ) {
399  iopt = kDiff;
400  yTitle = "Eff. - (ref.Eff)";
401  }
402  else if ( sOpt.Contains("pull") ) {
403  iopt = kPull;
404  yTitle = "(Eff - (ref.Eff)) / err";
405  }
406  else nDiffs = -1;
407 
408  if ( iopt != kEff && nLists <2 ) {
409  AliError(Form("You ask for %s but you only provided one set of histograms: nothing done",opt));
410  return -1;
411  }
412 
413  Bool_t needsLegend = ( nLists > 1 );
414 // if ( iopt != kEff ) needsLegend = nLists > 2;
415 
416  Int_t colors[] = {kBlack, kRed, kSpring, kTeal, kBlue, kViolet, kMagenta, kOrange, kGray};
417  Int_t ncolors = sizeof(colors)/sizeof(colors[0]);
418 
421 
422  TString currName = "";
423  Int_t ican = 0;
424  for ( Int_t itype=0; itype<2; itype++ ) {
425  TString xTitle = ( hTypes[itype] == AliTrigChEffOutput::kHslatEff ) ? "RPC" : "Board";
426  for ( Int_t icount=0; icount<3; icount++ ) {
427  TCanvas* can = 0x0;
428  for ( Int_t ich=0; ich<4; ich++ ) {
429  TLegend* leg = 0x0;
430 // Int_t hrefIdx = AliTrigChEffOutput::kNcounts + AliTrigChEffOutput::kNcounts*4*(itype-1) + 4*AliTrigChEffOutput::kAllTracks + ich;
431 // Int_t hIdx = AliTrigChEffOutput::kNcounts + AliTrigChEffOutput::kNcounts*4*(itype-1) + 4*icount + ich;
432  TGraphAsymmErrors* refGraph = 0x0;
433  for ( Int_t ilist=0; ilist<nLists; ilist++ ) {
434  TString currTitle = titleList->At(ilist)->GetName();
435  TList* effHistos = static_cast<TList*>(effHistoLists->UncheckedAt(ilist));
436  currName = Namer()->GetHistoName(hTypes[itype], AliTrigChEffOutput::kAllTracks, ich, -1, -1, -1);
437  TH1* histoDen = static_cast<TH1*>(effHistos->FindObject(currName.Data()));
438  currName = Namer()->GetHistoName(hTypes[itype], icount, ich, -1, -1, -1);
439  TH1* histoNum = static_cast<TH1*>(effHistos->FindObject(currName.Data()));
440  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum,histoDen,"e0");
441  currName = histoNum->GetName();
442  currName.ReplaceAll("Count","Eff");
443  currName.Append(Form("_%s",currTitle.Data()));
444  graph->SetName(currName.Data());
445 
446  if ( iopt != kEff ) {
447  if ( refGraph ) {
448  for ( Int_t ipt=0; ipt<graph->GetN(); ipt++ ) {
449  refGraph->GetPoint(ipt,xref,yref);
450  graph->GetPoint(ipt,xpt,ypt);
451  Double_t diff = ypt - yref;
452  if ( TMath::Abs(diff) > 1.e-4 ) nDiffs++;
453  if ( iopt == kDiff ) graph->SetPoint(ipt,xpt,diff);
454  else if ( iopt == kPull ) {
455  Double_t err = GetError(graph->GetErrorYlow(ipt),graph->GetErrorYhigh(ipt));
456  Double_t pull = ( err > 0. ) ? diff/err : 0.;
457  graph->SetPoint(ipt,xpt,pull);
458  }
459  } // loop on points
460  }
461  else {
462  refGraph = graph;
463  continue;
464  }
465  }
466 
467  if ( ! can ) {
468  currName = graph->GetName();
469  currName.Remove(currName.Length()-currTitle.Length()-5);
470  currName += sCanvasNameSuffix;
471  can = new TCanvas(currName.Data(),currName.Data(),20*ican,20*ican,600,600);
472  can->Divide(2,2);
473  ican++;
474  }
475  if ( needsLegend && ! leg ) {
476  leg = new TLegend(0.35, 0.15, 0.65, 0.45);
477  if ( refGraph ) leg->SetHeader(Form("Ref.: %s",titleList->At(0)->GetName()));
478  }
479  can->cd(ich+1);
480  gPad->SetGridy();
481  Int_t icolor = ( ilist < ncolors ) ? colors[ilist] : 20+ilist;
482  graph->SetLineColor(icolor);
483  graph->SetMarkerColor(icolor);
484  graph->SetMarkerStyle(20+ilist);
485  graph->SetMarkerSize(0.5);
486  graph->GetXaxis()->SetTitle(xTitle.Data());
487  graph->GetYaxis()->SetTitle(yTitle.Data());
488  graph->Draw((gPad->GetListOfPrimitives()->GetEntries()==0)?"ap":"p");
489  if ( leg ) leg->AddEntry(graph,titleList->At(ilist)->GetName(),"lp");
490  } // loop on lists
491  if (leg ) leg->Draw();
492  delete refGraph;
493  } // loop on chambers
494  } // loop on counts
495  } // loop on types
496 
497  delete titleList;
498 
499  return nDiffs;
500 }
501 
502 //________________________________________________________________________
503 Int_t AliMTRChEffAnalysis::CompareEfficiencyMethods ( const char* source, const char* opt, const char* canvasNameSuffix ) const
504 {
506  if ( ! fConditions ) {
507  AliWarning("No condition found! Please specify the default efficiency condition with SetEffConditions and then add additional tests with AddSystematicCondition");
508  return -1;
509  }
510 
511  AliTrigChEffOutput trigOut(source);
512 
513  Int_t nConditions = fConditions->GetEntriesFast();
514 
515  TString titles = "";
516  TObjArray effHistoLists;
517  effHistoLists.SetOwner();
518 
519  for ( Int_t icond=0; icond<nConditions; icond++ ) {
520  TObjArray* condition = static_cast<TObjArray*>(fConditions->UncheckedAt(icond));
521  TString condTitle = GetShortConditionTitle(condition->GetName());
522 
523  TList* effHistos = GetEffHistoList(&trigOut, condition);
524  effHistoLists.Add(effHistos);
525  titles += Form("%s,",condTitle.Data());
526  }
527 
528  titles.Remove(TString::kTrailing,',');
529  return CompareEfficiencies(&effHistoLists, titles, opt, canvasNameSuffix);
530 }
531 
532 
533 //________________________________________________________________________
535 {
536  if ( ! HasMergedResults() ) return;
537 
538  if ( fMergedMap.size() < 2 ) {
539  AliWarning("There is only one merged object: nothing to compare to");
540  return;
541  }
542 
543  AliInfo("Comparing the merged efficiencies");
544 
545  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
546  TString titles = "";
547 
548  TObjArray effHistoList;
550  TList* effHistos = obj->GetEffHistoList(condition->GetName());
551  effHistoList.Add(effHistos);
552  titles += Form("%i_%i,",obj->GetMinRun(),obj->GetMaxRun());
553  }
554  titles.Remove(TString::kTrailing,',');
555 
556  CompareEfficiencies(&effHistoList, titles.Data(), opt, "MergedComp");
557 }
558 
559 //________________________________________________________________________
560 Int_t AliMTRChEffAnalysis::ComputeAndCompareEfficiencies ( const char* sources, const char* titles, const char* opt, const char* canvasNameSuffix ) const
561 {
563  TString srcs(sources);
564  TObjArray* sourceList = srcs.Tokenize(",");
565  TObjArray effHistoLists;
566  effHistoLists.SetOwner();
567 
568  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
569  if ( ! condition ) {
570  AliError("The method requires to set an efficiency confition with SetEffConditions");
571  return -1;
572  }
573 
574  TIter next(sourceList);
575  TObjString* src = 0x0;
576  while ( (src = static_cast<TObjString*>(next())) ) {
577  if ( ! src->String().EndsWith(".root") ) {
578  AliError("The method reads files with the output of AliAnalysisTaskTrigChEff and re-compute the efficiency");
579  return -1;
580  }
581  AliTrigChEffOutput trigOut(src->GetName());
582  TList* readList = GetEffHistoList(&trigOut,condition);
583  if ( ! readList ) continue;
584  effHistoLists.Add(readList);
585  }
586 
587  return CompareEfficiencies(&effHistoLists, titles, opt, canvasNameSuffix);
588 }
589 
590 
591 //________________________________________________________________________
592 //TArrayI AliMTRChEffAnalysis::CheckHomogeneity ( const TGraphAsymmErrors* trendGraph, Double_t nSigmas, Bool_t revert ) const
593 //{
594 // /// Check efficiency homogeneity
595 // TArrayI ranges(trendGraph->GetN());
596 // Double_t xpt=0., ypt=0.;
597 //
598 // Double_t sumEffOverSigma2 = -10.;
599 // Double_t sumInvSimga2 = 0.001;
600 // Int_t irange = 0;
601 // Int_t npt = trendGraph->GetN();
602 // for ( Int_t ipt=0; ipt<npt; ipt++ ) {
603 // Int_t currPt = ( revert ) ? npt-1-ipt : ipt;
604 // trendGraph->GetPoint(currPt,xpt,ypt);
605 // Double_t err = GetError(trendGraph->GetErrorYlow(currPt),trendGraph->GetErrorYhigh(currPt));
606 // Double_t invSigma2 = 1./(err*err);
607 // Double_t effOverSigma2 = ypt*invSigma2;
608 //
609 // Double_t meanEff = sumEffOverSigma2 / sumInvSimga2;
610 // Double_t diff = ypt - meanEff;
611 // Double_t diffErr = TMath::Sqrt(err*err+1./sumInvSimga2);
613 // if ( TMath::Abs(diff)/diffErr > nSigmas ) {
614 // TString run = trendGraph->GetXaxis()->GetBinLabel(currPt+1);
615 // ranges[irange++] = run.Atoi();
616 // sumEffOverSigma2 = 0.;
617 // sumInvSimga2 = 0.;
618 // }
619 // sumEffOverSigma2 += effOverSigma2;
620 // sumInvSimga2 += invSigma2;
621 // }
622 // TString run = trendGraph->GetXaxis()->GetBinLabel(trendGraph->GetN());
623 // ranges[irange++] = run.Atoi();
624 // ranges.Set(irange);
625 // return ranges;
626 //}
627 
628 //________________________________________________________________________
629 void AliMTRChEffAnalysis::CopyDir(TDirectory *source) const
630 {
632  TDirectory *savdir = gDirectory;
633  TDirectory *adir = savdir->mkdir(source->GetName());
634  adir->cd();
635  //loop on all entries of this directory
636  TKey *key;
637  TIter nextkey(source->GetListOfKeys());
638  while ((key = (TKey*)nextkey())) {
639  const char *classname = key->GetClassName();
640  TClass *cl = gROOT->GetClass(classname);
641  if (!cl) continue;
642  if (cl->InheritsFrom(TDirectory::Class())) {
643  source->cd(key->GetName());
644  TDirectory *subdir = gDirectory;
645  adir->cd();
646  CopyDir(subdir);
647  adir->cd();
648  } else if (cl->InheritsFrom(TTree::Class())) {
649  TTree *T = (TTree*)source->Get(key->GetName());
650  adir->cd();
651  TTree *newT = T->CloneTree(-1,"fast");
652  newT->Write();
653  } else {
654  source->cd();
655  TObject *obj = key->ReadObj();
656  adir->cd();
657  obj->Write(obj->GetName(),TObject::kSingleKey);
658  delete obj;
659  }
660  }
661  adir->SaveSelf(kTRUE);
662  savdir->cd();
663 }
664 
665 
666 //________________________________________________________________________
667 Bool_t AliMTRChEffAnalysis::CopyLocally ( const char* runList, const char* path, const char* pattern, const char* localFileList, const char* outDir, const char* directory ) const
668 {
670  TString sPattern(pattern);
671  TString sOutDir(outDir);
672  TString sPath(path);
673  Bool_t isGrid = (! sPattern.IsNull());
674 
675  if ( sOutDir.IsNull() ) {
676  if ( isGrid ) {
677  TString data = sPath(TRegexp("/data/"));
678  TString year = sPath(TRegexp("/20[0-9][0-9]/"));
679  TString period = sPath(TRegexp("/LHC[0-9][0-9][a-z]"));
680  period.Append("/");
681  TString pass = AliAnalysisMuonUtility::GetPassName(path);
682  if ( pass.IsNull() ) pass = AliAnalysisMuonUtility::GetPassName(pattern);
683  sOutDir = data+year+period+pass;
684  sOutDir.ReplaceAll("//","/");
685  sOutDir.Remove(TString::kTrailing,'/');
686  sOutDir.Remove(TString::kLeading,'/');
687  }
688  else sOutDir = sPath;
689  sOutDir.Remove(TString::kTrailing,'/');
690  sOutDir.Remove(TString::kLeading,'/');
691  }
692 
693  TGridResult* res = 0x0;
694  Bool_t hasCurl = kFALSE;
695  if ( isGrid ) {
696  if ( ! gGrid ) TGrid::Connect("alien://");
697  res = gGrid->Query(path,pattern);
698  }
699  else {
700  if ( gSystem->Exec("which curl &> /dev/null") == 0 ) hasCurl = kTRUE;
701  }
702 
703  TList* rl = GetRunList(runList);
704 
705  ofstream outFile(localFileList);
706  Bool_t allOk = kTRUE;
707  Bool_t prompt = kTRUE;
708  Bool_t overwrite = kFALSE;
709  for ( Int_t irun=0; irun<rl->GetEntries(); irun++ ) {
710  TString run = static_cast<TObjString*>(rl->At(irun))->String();
711  TString dest = Form("%s/%09i/QAresults.root",sOutDir.Data(),run.Atoi());
712  TString destDir = gSystem->DirName(dest.Data());
713  if ( gSystem->AccessPathName(destDir.Data()) ) ExecCommand(Form("mkdir -p %s",destDir.Data()),kFALSE);
714  Bool_t copyFile = kTRUE;
715  Bool_t isFileOk = kTRUE;
716  if ( gSystem->AccessPathName(dest) == 0 ) {
717  if ( prompt ) {
718  TString decision = "";
719  cout << "Local file " << dest.Data() << " already exist: overwrite? [y/n/ya/na (a=use decision for all)]" << endl;
720  cin >> decision;
721  if ( decision.EndsWith("a") ) prompt = kFALSE;
722  if ( decision.BeginsWith("y") ) overwrite = kTRUE;
723  else overwrite = kFALSE;
724  }
725  copyFile = overwrite;
726  }
727  if ( copyFile ) {
728  TString src = "";
729  if ( isGrid ) {
730  for ( Int_t ifile=0; ifile<res->GetEntries(); ifile++ ) {
731  TString inFilename = res->GetKey(ifile,"turl");
732  if ( inFilename.Contains(run.Data()) ) {
733  src = inFilename;
734  break;
735  }
736  }
737  if ( src.IsNull() ) {
738  AliWarning(Form("Cannot find output for run %s",run.Data()));
739  isFileOk = kFALSE;
740  }
741  else {
742  TFile* outFile = TFile::Open(dest,"RECREATE");
743  TFile* inFile = TFile::Open(src);
744  inFile->cd();
745  TDirectory* dir = static_cast<TDirectory*>(inFile->Get(directory));
746  if ( dir ) {
747  outFile->cd();
748  CopyDir(dir);
749  }
750  else isFileOk = kFALSE;
751  delete inFile;
752  delete outFile;
753  }
754  }
755  else {
756  src = Form("http://aliqamu.web.cern.ch/aliqamu/%s",dest.Data());
757  // TFile::Cp was having some issue lately.
758  // If curl is found on the system, let's use it instead...
759  if ( hasCurl ) {
760  Int_t cmdOut = gSystem->Exec(Form("curl -f -# -o %s %s",dest.Data(),src.Data()));
761  isFileOk = ( cmdOut == 0 );
762  }
763  else isFileOk = TFile::Cp(src.Data(),dest.Data());
764  }
765  }
766 
767  if ( isFileOk ) outFile << gSystem->pwd() << "/" << dest.Data() << endl;
768  else {
769  AliWarning(Form("Problem getting run %s",run.Data()));
770  allOk = kFALSE;
771  }
772  }
773  delete rl;
774  outFile.close();
775  return allOk;
776 }
777 
778 //________________________________________________________________________
779 void AliMTRChEffAnalysis::DrawEffTrend ( Int_t itype, Int_t irpc, Double_t maxNsigmaOutliers, Double_t minEff, Double_t maxEff ) const
780 {
782  if ( Check() ) return;
783 
784  TString baseNames[3] = {"Chamber","RPC","Board"};
785  TString base = baseNames[itype] + "Eff";
786  if ( itype == AliTrigChEffOutput::kHboardEff ) {
787  if ( irpc < 0 ) {
788  AliWarning("Please specify RPC");
789  return;
790  }
791  base += Form("InRPC%i",irpc);
792  }
793 
794  Int_t nColumns = 2;
795  Int_t nRows = 2;
796  Int_t width = 600;
797  Int_t height = 600;
798  Int_t nDetEl = 4;
799  Int_t nCh = 1;
800  Double_t legYmin = 0.65;
801  Double_t legYmax = 0.9;
802  if ( itype != AliTrigChEffOutput::kHchamberEff ) {
803  nColumns = 6;
804  nRows = 3;
805  width = 1200;
806  height = 800;
807  nDetEl = 18;
808  nCh = 4;
809  legYmin = 0.15;
810  legYmax = 0.4;
811  }
812  TArrayI boards = BoardsInRPC(irpc);
813  if ( itype == AliTrigChEffOutput::kHboardEff ) nDetEl = boards.GetSize();
814 
815  for ( Int_t ich=0; ich<nCh; ich++ ) {
816  TString canName = base;
817  if ( itype != AliTrigChEffOutput::kHchamberEff ) canName += Form("Ch%i",11+ich);
818  TCanvas* can = new TCanvas(canName.Data(),canName.Data(),25*ich,25*ich,width,height);
819  can->Divide(nColumns,nRows,0,0);
820  can->SetTopMargin(0.);
821  can->SetBottomMargin(0.);
822  for ( Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
823  can->cd(idetelem+1);
824  if ( idetelem/nColumns == nRows - 1 ) gPad->SetBottomMargin(0.15);
825  if ( gPad->GetListOfExecs()->GetEntries() == 0 ) gPad->AddExec("ZoomPad","AliMTRChEffAnalysis::ZoomPad()");
826  gPad->SetTicks(1,1);
827  gPad->SetGridy();
828  Int_t detElemId = idetelem;
829  if ( itype == AliTrigChEffOutput::kHchamberEff ) detElemId = 11+idetelem;
830  else if ( itype == AliTrigChEffOutput::kHboardEff ) detElemId = boards[idetelem];
831 
832  TString title = Form("%s %i",baseNames[itype].Data(),detElemId);
833  TLegend* leg = new TLegend(0.2,legYmin,0.8,legYmax);
834  leg->SetHeader(title.Data());
835  for ( Int_t icount=0; icount<2; icount++ ) {
836  TGraphAsymmErrors* gr = GetTrendEff(itype, icount, ich, detElemId);
837  gr->SetLineColor(icount+1);
838  gr->SetMarkerColor(icount+1);
839  gr->SetMarkerStyle(24+2*icount);
840  gr->GetYaxis()->SetRangeUser(minEff,maxEff);
841  gr->GetXaxis()->SetLabelSize(0.07);
842  gr->GetXaxis()->SetTitle("");
843  // gr->GetYaxis()->SetLabelSize(0.025*nRows);
844  // gr->GetXaxis()->SetLabelSize(0.025*nColumns);
845  gr->SetTitle("");
846  gr->Draw(icount==0?"ap":"p");
847  TString legTitle = ( icount==0 ) ? "bending plane" : "non-bending plane";
848  leg->AddEntry(gr,legTitle.Data(),"lp");
849  if ( maxNsigmaOutliers > 0. ) {
850  TGraphAsymmErrors* outliers = GetOutliers(gr,maxNsigmaOutliers);
851  outliers->SetLineColor(6+icount);
852  outliers->SetMarkerColor(6+icount);
853  outliers->SetMarkerStyle(20+2*icount);
854  outliers->SetLineWidth(2);
855  outliers->Draw("p");
856  legTitle.ReplaceAll("plane","outliers");
857  leg->AddEntry(outliers,legTitle.Data(),"lp");
858  }
859  }
860  leg->Draw();
861  }
862  if ( itype == AliTrigChEffOutput::kHchamberEff ) break;
863  }
864 }
865 
866 //________________________________________________________________________
867 void AliMTRChEffAnalysis::DrawStatContribution ( Int_t itype, Int_t irpc, Double_t maxNsigmaOutliers, Double_t minY, Double_t maxY ) const
868 {
870  if ( itype == AliTrigChEffOutput::kHchamberEff ) {
871  AliWarning("This function is valid only for itype 1 and 2");
872  return;
873  }
874 
875  TString baseNames[3] = {"Chamber","RPC","Board"};
876  TString base = baseNames[itype] + "Stat";
877  if ( itype == AliTrigChEffOutput::kHboardEff ) {
878  if ( irpc < 0 ) {
879  AliWarning("Please specify RPC");
880  return;
881  }
882  base += Form("InRPC%i",irpc);
883  }
884 
885  Int_t nColumns = 6;
886  Int_t nRows = 3;
887  Int_t width = 1200;
888  Int_t height = 800;
889  Int_t nDetEl = 18;
890  Int_t nCh = 1;
891 
892  TArrayI boards = BoardsInRPC(irpc);
893  if ( itype == AliTrigChEffOutput::kHboardEff ) nDetEl = boards.GetSize();
894 
895  for ( Int_t ich=0; ich<nCh; ich++ ) {
896  TH1* histos[nDetEl];
897  TH1* sumHistos = 0x0;
898  for ( Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
899  Int_t detElemId = idetelem;
900  if ( itype == AliTrigChEffOutput::kHboardEff ) detElemId = boards[idetelem];
901  histos[idetelem] = GetTrend(itype, AliTrigChEffOutput::kAllTracks, ich, detElemId);
902  histos[idetelem]->SetName(Form("%s_stat",histos[idetelem]->GetName()));
903  histos[idetelem]->SetStats(0);
904  if ( sumHistos ) sumHistos->Add(histos[idetelem]);
905  else sumHistos = static_cast<TH1*>(histos[idetelem]->Clone("sumHistos"));
906  }
907 
908  TString canName = base; //Form("%sCh%i",base.Data(),11+ich);
909  TCanvas* can = new TCanvas(canName.Data(),canName.Data(),25*ich,25*ich,width,height);
910  can->Divide(nColumns,nRows,0,0);
911  for ( Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
912  can->cd(idetelem+1);
913  if ( gPad->GetListOfExecs()->GetEntries() == 0 ) gPad->AddExec("ZoomPad","AliMTRChEffAnalysis::ZoomPad()");
914  gPad->SetTicks(1,1);
915  gPad->SetGridy();
916  Int_t detElemId = idetelem;
917  if ( itype == AliTrigChEffOutput::kHboardEff ) detElemId = boards[idetelem];
918  TString title = Form("%s %i",baseNames[itype].Data(),detElemId);
919  TLegend* leg = new TLegend(0.2,0.65,0.8,0.9);
920  leg->SetHeader(title.Data());
921  TGraphAsymmErrors* gr = new TGraphAsymmErrors(histos[idetelem],sumHistos,"e0");
922  gr->SetHistogram(static_cast<TH1F*>(histos[idetelem]));
923 
924  gr->SetMarkerStyle(24);
925  gr->SetMarkerSize(0.5);
926  gr->GetYaxis()->SetRangeUser(minY,maxY);
927  gr->GetYaxis()->SetTitle(Form("Tracks in %s / Sum of tracks of %ss in %s",baseNames[itype].Data(),baseNames[itype].Data(),baseNames[itype-1].Data()));
928  gr->SetTitle("");
929  gr->Draw("ap");
930  TString legTitle = "stat";
931 // leg->AddEntry(gr,legTitle.Data(),"lp");
932  if ( maxNsigmaOutliers > 0. ) {
933  TGraphAsymmErrors* outliers = GetOutliers(gr,maxNsigmaOutliers);
934  outliers->SetLineColor(6);
935  outliers->SetMarkerColor(6);
936  outliers->SetMarkerStyle(20);
937  outliers->SetLineWidth(2);
938  outliers->Draw("p");
939  legTitle = "outliers";
940  leg->AddEntry(outliers,legTitle.Data(),"lp");
941  }
942 // }
943  leg->Draw();
944  }
945  delete sumHistos;
946  }
947 }
948 
949 //________________________________________________________________________
951 {
953  if ( ! HasMergedResults() ) return kFALSE;
954 
955  AliInfo("Drawing the systematic variations");
956 
957  Int_t colors[] = {kBlack, kRed, kSpring, kTeal, kBlue, kViolet, kMagenta, kOrange, kGray};
958  Int_t ncolors = sizeof(colors)/sizeof(colors[0]);
959 
962 
963  Double_t xpt, ypt, xref, yref;
964  TArrayD eff(4), effErr(4);
965 
966  Int_t imerged = -1;
968  imerged++;
969  std::vector<std::string> systKeys = obj->GetSortKeys();
970  std::vector<std::string> shortSystName;
971  for ( std::string str : systKeys ) {
972  shortSystName.push_back(GetShortConditionTitle(str.c_str()).Data());
973  }
974  Int_t nSysts = systKeys.size();
975 
976  TString baseName = Form("mergedTrigEff_%i_%i",obj->GetMinRun(),obj->GetMaxRun());
977 
978  TArrayI isEmpty(nSysts);
979 
980  // First get the needed graphs
981  Int_t nDE = 0;
982  TObjArray effGraphs[8];
983  for ( Int_t iplane=0; iplane<8; iplane++ ) {
984  effGraphs[iplane].SetOwner();
985  }
986  TString titles = "";
987  TObjArray effHistoLists;
988 // effHistoLists.SetOwner();
989  for ( Int_t isyst=0; isyst<nSysts; isyst++ ) {
990  TList* effHistos = obj->GetEffHistoList(systKeys[isyst].c_str());
991  effHistoLists.Add(effHistos);
992  titles += Form("%s,",shortSystName[isyst].c_str());
993 
994  for ( Int_t ich=0; ich<4; ich++ ) {
995  TString currName = Namer()->GetHistoName(itype, AliTrigChEffOutput::kAllTracks, ich, -1, -1, -1);
996  TH1* histoDen = static_cast<TH1*>(effHistos->FindObject(currName.Data()));
997  for ( Int_t icount=0; icount<2; icount++ ) {
998  Int_t iplane = 4*icount+ich;
999 
1000  if ( histoDen->GetEntries() > 0 ) {
1001  currName = Namer()->GetHistoName(itype, countTypes[icount], ich, -1, -1, -1);
1002  TH1* histoNum = static_cast<TH1*>(effHistos->FindObject(currName.Data()));
1003  TGraphAsymmErrors* gr = new TGraphAsymmErrors(histoNum,histoDen,"e0");
1004  nDE = gr->GetN();
1005  effGraphs[iplane].AddAtAndExpand(gr,isyst);
1006  }
1007  else {
1008  isEmpty[isyst] = 1;
1009  AliWarning(Form("No entries in count %i and ch %i for %s",countTypes[icount],ich,shortSystName[isyst].c_str()));
1010  }
1011  }
1012  }
1013  }
1014 
1015  titles.Remove(TString::kTrailing,',');
1016  CompareEfficiencies(&effHistoLists, titles, "diff", baseName.Data());
1017 
1018  // Draw average dispersion per plane
1019  TString canName = Form("EffSyst_%s",baseName.Data());
1020  Int_t pos = 25*(imerged+1);
1021  TCanvas* can = new TCanvas(canName.Data(),canName.Data(),pos,pos,1200,800);
1022  can->Divide(4,2,0,0);
1023 
1024  for ( Int_t icount=0; icount<2; icount++ ) {
1025  for ( Int_t ich=0; ich<4; ich++ ) {
1026  Int_t iplane = 4*icount+ich;
1027  can->cd(iplane+1);
1028  if ( gPad->GetListOfExecs()->GetEntries() == 0 ) gPad->AddExec("ZoomPad","AliMTRChEffAnalysis::ZoomPad()");
1029  gPad->SetTicks(1,1);
1030  gPad->SetLogy();
1031  TLegend* leg = new TLegend(0.15,0.7,0.9,0.9);
1032  leg->SetHeader(Namer()->GetHistoName(-1,icount,ich,-1,-1,-1));
1033  TH1* sumHisto = 0x0;
1034  for ( Int_t isyst=1; isyst<nSysts; isyst++ ) {
1035  if ( isEmpty[isyst] == 1 ) continue;
1036  TH1* histo = new TH1D(Form("syst_%s_%s_plane%i_ch%i",baseName.Data(),shortSystName[isyst].c_str(),icount,11+ich),"",200,-0.1,0.1);
1037  histo->GetXaxis()->SetTitle("Eff.-(ref.Eff.)");
1038  histo->GetYaxis()->SetTitle("1/#sigma^{2}");
1039 
1040  TGraphAsymmErrors* gr = static_cast<TGraphAsymmErrors*>(effGraphs[iplane].UncheckedAt(isyst));
1041  TGraphAsymmErrors* grRef = static_cast<TGraphAsymmErrors*>(effGraphs[iplane].UncheckedAt(0));
1042  for ( Int_t ipt=0; ipt<gr->GetN(); ipt++ ) {
1043  gr->GetPoint(ipt,xpt,ypt);
1044  Double_t err = GetError(gr->GetErrorYlow(ipt),gr->GetErrorYhigh(ipt));
1045  Double_t invErr2 = ( err > 0. ) ? 1./(err*err) : 0.;
1046  grRef->GetPoint(ipt,xref,yref);
1047 
1048  Double_t diff = ypt-yref;
1049  histo->Fill(diff,invErr2);
1050  }
1051 
1052  if ( ! sumHisto ) {
1053  sumHisto = static_cast<TH1*>(histo->Clone(Form("syst_%s_plane%i_ch%i",baseName.Data(),icount,11+ich)));
1054  sumHisto->SetLineColor(1);
1055  sumHisto->Draw();
1056  leg->AddEntry(sumHisto,"All systematics","l");
1057  }
1058  else sumHisto->Add(histo);
1059  Int_t icolor = ( isyst < ncolors ) ? colors[isyst] : 20+isyst;
1060  histo->SetLineColor(icolor);
1061  histo->Draw("same");
1062  leg->AddEntry(histo,shortSystName[isyst].c_str(),"l");
1063  } // loop on conditions
1064  leg->Draw();
1065  } // loop on chambers
1066  } // loop on counts
1067 
1068 
1069  canName = Form("TriggerEff_3outOf4_syst_%s",baseName.Data());
1070  pos += 50;
1071  TCanvas* canSyst = new TCanvas(canName.Data(),canName.Data(),pos,pos,600,600);
1072  canSyst->SetLogy();
1073  TLegend* leg = new TLegend(0.15,0.7,0.9,0.4);
1074 // leg->SetHeader(trigOut->GetHistoName(-1,icount,ich,-1,-1,-1));
1075  TH1* histo[nSysts];
1076  for ( Int_t isyst=0; isyst<nSysts; isyst++ ) {
1077  if ( isEmpty[isyst] == 1 ) continue;
1078  histo[isyst] = new TH1D(Form("TriggerEff_syst_%s_%s",shortSystName[isyst].c_str(),baseName.Data()),"Dispersion of trigger probability (3/4)",200,-0.1,0.1);
1079  histo[isyst]->GetXaxis()->SetTitle("Trig. prob. - (ref. trig. prob)");
1080  histo[isyst]->GetYaxis()->SetTitle("1/#sigma^{2}");
1081  }
1082 
1083  for ( Int_t ipt=0; ipt<nDE; ipt++ ) {
1084  Double_t refTrigProb = 0.; // refTrigProbErr = 0.;
1085  for ( Int_t isyst=0; isyst<nSysts; isyst++ ) {
1086  if ( isEmpty[isyst] == 1 ) continue;
1087  Double_t trigProb = 1., trigProbErr2 = 0.;
1088  for ( Int_t icount=0; icount<2; icount++ ) {
1089  for ( Int_t ich=0; ich<4; ich++ ) {
1090  Int_t iplane = 4*icount+ich;
1091  TGraphAsymmErrors* gr = static_cast<TGraphAsymmErrors*>(effGraphs[iplane].UncheckedAt(isyst));
1092  gr->GetPoint(ipt,xpt,ypt);
1093  eff[ich] = ypt;
1094  effErr[ich] = GetError(gr->GetErrorYlow(ipt),gr->GetErrorYhigh(ipt));
1095  } // loop on chambers
1096  Double_t effErr34 = 0.;
1097  Double_t eff34 = GetThreeOfFour(eff,effErr,effErr34);
1098  trigProb *= eff34;
1099  trigProbErr2 += effErr34*effErr34;
1100  } // loop on counts
1101 
1102  if ( isyst == 0 ) {
1103  refTrigProb = trigProb;
1104 // refTrigProbErr = trigProbErr;
1105  }
1106  else {
1107  Double_t invErr2 = ( trigProbErr2>0. ) ? 1./trigProbErr2 : 0.;
1108  histo[isyst]->Fill(trigProb-refTrigProb,invErr2);
1109  }
1110  } // loop on conditions
1111  } // loop on points
1112 
1113  for ( Int_t isyst=0; isyst<nSysts; isyst++ ) {
1114  if ( isEmpty[isyst] == 1 ) continue;
1115  TString title = ( isyst == 0 ) ? "All systematics" : shortSystName[isyst].c_str();
1116  Int_t icolor = ( isyst < ncolors ) ? colors[isyst] : 20+isyst;
1117  histo[isyst]->SetLineColor(icolor);
1118  histo[isyst]->Draw((isyst == 0)?"":"same");
1119  leg->AddEntry(histo[isyst],title.Data(),"l");
1120  if ( isyst>0 ) histo[0]->Add(histo[isyst]);
1121  }
1122  leg->Draw();
1123  } // loop on merged output
1124  return kTRUE;
1125 }
1126 
1127 //________________________________________________________________________
1129 {
1131  TString decision = "y";
1132 
1133  if ( gROOT->IsBatch() ) prompt = kFALSE; // To run with crontab
1134 
1135  if ( prompt ) {
1136  cout << command.Data() << " ? [y/n]" << endl;
1137  cin >> decision;
1138  }
1139 
1140  decision.ToLower();
1141  if ( decision == "y" ) {
1142  cout << "Executing: " << command.Data() << endl;
1143  gSystem->Exec(command.Data());
1144  return kTRUE;
1145  }
1146 
1147  return kFALSE;
1148 }
1149 
1150 //________________________________________________________________________
1152 {
1159 
1160  Double_t xx = x[0];
1161  Double_t val = par[1];
1162  Int_t nChanges = par[0];
1163  Double_t matchDiff = 123456789.;
1164  Int_t matchChange = -1;
1165  for ( Int_t iknot=0; iknot<nChanges; iknot++ ) {
1166  Int_t iparChange = 2*(iknot+1);
1167  Double_t diff = xx - par[iparChange];
1168  if ( diff >= 0. && diff < matchDiff ) {
1169  matchDiff = diff;
1170  matchChange = iparChange;
1171  }
1172  }
1173  if ( matchChange >= 0 ) val = par[matchChange+1];
1174 
1175  return val;
1176 }
1177 
1178 //________________________________________________________________________
1179 Double_t AliMTRChEffAnalysis::GetAverageStat ( Int_t firstRun, Int_t lastRun, Int_t itype,Bool_t excludePeriphericBoard ) const
1180 {
1182 
1183  TH1* statHisto = 0x0;
1184 
1186  TList* effHistoList = obj->GetEffHistoList(fConditions->UncheckedAt(0)->GetName());
1187  Int_t run = obj->GetMinRun();
1188  if ( run < firstRun || run > lastRun ) continue;
1189  TH1* histo = GetHisto(effHistoList,itype,AliTrigChEffOutput::kAllTracks,0);
1190 // if ( ! histo ) continue;
1191  if ( statHisto ) statHisto->Add(histo);
1192  else statHisto = static_cast<TH1*>(histo->Clone("tmpStatHisto"));
1193 // delete histo;
1194  }
1195  if ( ! statHisto ) return 0.;
1196 
1197  Double_t statPerDE = 0.;
1198  Double_t nDe = 0.;
1199  if ( itype == AliTrigChEffOutput::kHboardEff && excludePeriphericBoard ) {
1200  Int_t excludeBoardsHalf[] = {1, 17, 39, 61, 77, 93,109,
1201  16, 38, 60, 76, 92, 108, 117,
1202  110, 111, 112, 113, 114, 115, 116};
1203  Int_t nExcludedHalf = sizeof(excludeBoardsHalf)/sizeof(excludeBoardsHalf[0]);
1204  for ( Int_t ibin=1; ibin<=statHisto->GetNbinsX(); ibin++ ) {
1205  Bool_t skip = kFALSE;
1206  for ( Int_t iexcl=0; iexcl<nExcludedHalf; iexcl++ ) {
1207  if ( ibin == excludeBoardsHalf[iexcl] || ibin == excludeBoardsHalf[iexcl]+117 ) {
1208  skip = kTRUE;
1209  break;
1210  }
1211  }
1212  if ( skip ) continue;
1213  statPerDE += statHisto->GetBinContent(ibin);
1214  nDe += 1.;
1215  }
1216  }
1217  else {
1218  statPerDE = statHisto->Integral();
1219  nDe = (Double_t)statHisto->GetNbinsX();
1220  }
1221  statPerDE = nDe > 0. ? statPerDE/nDe : -1.;
1222 
1223  delete statHisto;
1224  return statPerDE;
1225 }
1226 
1227 //________________________________________________________________________
1229 {
1231  Int_t itrackSel = condition->UncheckedAt(3)->GetUniqueID();
1232  Int_t imatch = condition->UncheckedAt(4)->GetUniqueID();
1233  Int_t imethod = condition->UncheckedAt(5)->GetUniqueID();
1234 
1235  return trigOut->GetEffHistoList(condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName(),itrackSel,imatch,imethod);
1236 }
1237 
1238 //________________________________________________________________________
1240 {
1242  return TMath::Max(errLow,errHigh);
1243 }
1244 
1245 //________________________________________________________________________
1246 TH1* AliMTRChEffAnalysis::GetHisto ( TList* effHistoList, Int_t itype, Int_t icount, Int_t ichamber ) const
1247 {
1249  Int_t ihisto = ( itype == AliTrigChEffOutput::kHchamberEff ) ? icount : AliTrigChEffOutput::kNcounts + 4*AliTrigChEffOutput::kNcounts*(itype-1) + 4*icount + ichamber;
1250  return static_cast<TH1*>(effHistoList->At(ihisto));
1251 }
1252 
1253 //________________________________________________________________________
1254 TArrayI AliMTRChEffAnalysis::GetHomogeneousRanges ( Double_t chi2Cut, Int_t maxNRanges, Double_t minEffVariation, Bool_t perRPC, TArrayI* forcedChanges, Double_t minEff, Double_t maxEff )
1255 {
1257 
1258  AliInfo("Selecting ranges with homogeneous efficiency");
1259 
1260  Int_t nRuns = fRunMap.size();
1261 
1262  TH1F* hRunChangeCount = new TH1F("runChangeCount","Number of RPCs changing efficiency per run",nRuns,-0.5,-0.5+(Double_t)nRuns);
1263  hRunChangeCount->SetXTitle("Run num.");
1264  hRunChangeCount->SetYTitle("Num. of RPCs with change in eff.");
1265  for ( Int_t irun=0; irun<nRuns; irun++ ) {
1266  hRunChangeCount->GetXaxis()->SetBinLabel(irun+1,Form("%i",GetRunNumber(irun)));
1267  }
1268 
1270 
1271  Int_t nCanvas = perRPC ? 4 : 18;
1272  TObjArray canList(nCanvas);
1273 
1274  for ( Int_t irpc=0; irpc<18; irpc++ ) {
1276  TArrayI boards = BoardsInRPC(irpc);
1277  Int_t firstDetEl = perRPC ? irpc : 0;
1278  Int_t lastDetEl = perRPC ? irpc : boards.GetSize()-1;
1279 
1280  for ( Int_t ich=0; ich<4; ich++ ) {
1281  Int_t ican = perRPC ? ich : irpc;
1282  TCanvas* can = static_cast<TCanvas*>(canList.At(ican));
1283  if ( ! can ) {
1284  TString canName = perRPC ? Form("testRanges_ch%i",11+ich) : Form("testRanges_RPC%i",irpc);
1285  can = new TCanvas(canName.Data(),canName.Data(),10*ich,10*ich,1200,800);
1286  can->Divide(6,3,0,0);
1287  can->SetMargin(0.,0.,0.,0.);
1288  canList.AddAt(can,ican);
1289  }
1290 
1291  for ( Int_t idetel=firstDetEl; idetel<=lastDetEl; idetel++ ) {
1292  Int_t currDE = ( perRPC ) ? idetel : boards[idetel];
1293 // for ( Int_t icount=0; icount<2; icount++ ) {
1294  TGraphAsymmErrors* trendGraph = GetTrendEff(itype,icount,ich,currDE);
1295  TArrayI range = GetHomogeneousRanges(trendGraph,chi2Cut,maxNRanges,minEffVariation,forcedChanges, kTRUE);
1296  trendGraph->GetYaxis()->SetRangeUser(minEff,maxEff);
1297 
1298  can->cd(idetel+1);
1299  if ( gPad->GetListOfExecs()->GetEntries() == 0 ) gPad->AddExec("ZoomPad","AliMTRChEffAnalysis::ZoomPad()");
1300  gPad->SetTicks(1,1);
1301  gPad->SetMargin(0.08,0.,0.08,0.);
1302  TString drawOpt = ( gPad->GetListOfPrimitives()->GetEntries() == 0 ) ? "ap" : "p";
1303 
1304  TString legendName = Form("%s_%i",can->GetName(),currDE);
1305  TLegend* leg = static_cast<TLegend*>(gPad->GetListOfPrimitives()->FindObject(legendName.Data()));
1306  if ( ! leg ) {
1307  leg = new TLegend(0.2,0.15,0.8,0.4);
1308  leg->SetHeader(Form("%s %i",perRPC?"RPC":"Board",currDE));
1309  leg->SetName(legendName.Data());
1310  }
1311 
1312  if ( ! perRPC ) {
1313  Int_t icolor = ich+1;
1314  trendGraph->SetLineColor(icolor);
1315  trendGraph->SetMarkerColor(icolor);
1316  trendGraph->SetMarkerStyle(24+ich);
1317  TF1* func = static_cast<TF1*>(trendGraph->GetListOfFunctions()->At(0));
1318  if ( func ) {
1319  func->SetLineWidth(2);
1320  func->SetLineColor(icolor);
1321  }
1322  }
1323  trendGraph->GetXaxis()->SetLabelSize(0.07);
1324  trendGraph->SetTitle("");
1325 
1326  trendGraph->Draw(drawOpt.Data());
1327  leg->AddEntry(trendGraph,Form("Chamber %i",11+ich),"lp");
1328  leg->Draw();
1329  for ( Int_t ichange=2; ichange<range.GetSize(); ichange++ ) {
1330  // Store only the run when the change applies
1331  if ( ichange%2 == 1 ) continue;
1332  Int_t runIdx = range[ichange];
1333 // if ( ichange != 0 ) {
1334  TLine* line = new TLine(runIdx,minEff,runIdx,maxEff);
1335  line->SetLineStyle(2);
1336  line->Draw("same");
1337  TLatex text;
1338  text.DrawLatex((Double_t)(runIdx-3),maxEff-0.1*(maxEff-minEff)*(Double_t)(ichange/2),Form("%i",GetRunNumber(runIdx)));
1339 // }
1340  hRunChangeCount->Fill(runIdx);
1341  if ( hRunChangeCount->GetBinContent(runIdx+1) == 1 ) {
1342  TString infoMsg = Form("Efficiency change in %i triggered by ch %i RPC %i",GetRunNumber(runIdx),11+ich,irpc);
1343  if ( ! perRPC ) infoMsg += Form(" Board %i",currDE);
1344  AliInfo(infoMsg.Data());
1345  }
1346  } // loop on change
1347  } // loop on detection element
1348 // }
1349  } // loop on chambers
1350  } // loop on RPC
1351 
1352  // Clusterize contiguous runs
1353  TArrayI runChangeClust(nRuns);
1354  Double_t sumWgtRun = 0.;
1355  Double_t sumWgt = 0;
1356  for ( Int_t irun=0; irun<=nRuns; irun++ ) {
1357  if ( irun == nRuns || hRunChangeCount->GetBinContent(irun+1) == 0 ) {
1358  if ( sumWgt > 0. ) {
1359  Int_t averageRun = TMath::Nint(sumWgtRun / sumWgt);
1360  AliDebug(2,Form("Average run: %i => %i",averageRun,GetRunNumber(averageRun)));
1361  runChangeClust[averageRun]++;
1362  sumWgtRun = 0.;
1363  sumWgt = 0.;
1364  }
1365  }
1366  if ( irun == nRuns ) break;
1367 
1368  AliDebug(2,Form("irun %i => %i: wgt %g",irun,GetRunNumber(irun),hRunChangeCount->GetBinContent(irun+1)));
1369 
1370 // Double_t wgt = (Double_t)runChangeCount[irun];
1371  Double_t wgt = hRunChangeCount->GetBinContent(irun+1);
1372  if ( forcedChanges ) {
1373  for ( Int_t ichange=0; ichange<forcedChanges->GetSize(); ichange++ ) {
1374  if ( GetRunNumber(irun) == forcedChanges->At(ichange) ) wgt *= 10.;
1375  }
1376  }
1377  sumWgtRun += wgt*(Double_t)irun;
1378  sumWgt += wgt;
1379  }
1380 
1381  TCanvas* summaryCan = new TCanvas("effChangeSummary","effChangeSummary",50,50,600,600);
1382  summaryCan->SetLogy();
1383  hRunChangeCount->GetXaxis()->LabelsOption("v");
1384  hRunChangeCount->Draw();
1385 
1386  Int_t ientry = 0;
1387  TArrayI runRanges(nRuns);
1388  runRanges[ientry++] = GetRunNumber(0);
1389  for ( Int_t irun=1; irun<nRuns; irun++ ) {
1390  if ( runChangeClust[irun] > 0 ) {
1391  runRanges[ientry++] = GetRunNumber(irun-1);
1392  runRanges[ientry++] = GetRunNumber(irun);
1393  }
1394  }
1395  runRanges[ientry++] = GetRunNumber(nRuns-1);
1396  runRanges.Set(ientry);
1397  return runRanges;
1398 }
1399 
1400 //________________________________________________________________________
1401 TArrayI AliMTRChEffAnalysis::GetHomogeneousRanges ( TGraphAsymmErrors* trendGraph, Double_t chi2Cut, Int_t maxNRanges, Double_t minEffVariation, TArrayI* forcedChanges, Bool_t returnIndex )
1402 {
1404 
1405  TArrayI runRanges;
1406  TF1* func = 0x0;
1407  TArrayD forcedChangesBin;
1408  Int_t nForced = 0;
1409  if ( forcedChanges ) {
1410  forcedChangesBin.Set(forcedChanges->GetSize());
1411  for ( Int_t ichange=0; ichange<forcedChanges->GetSize(); ichange++ ) {
1412  Int_t idx = GetIndexFromRun(forcedChanges->At(ichange));
1413  if ( idx >= 0 ) forcedChangesBin[nForced++] = (Double_t)idx;
1414  else AliWarning(Form("Cannot find run %i",forcedChanges->At(ichange)));
1415  }
1416  }
1417 
1418  Double_t minNormChi2 = 123456789.;
1419  Int_t minNormChi2Step = -1;
1420  TString fitOpt = "NQ0";
1421 // Double_t fakeVal = -999.;
1422 // TArrayD params(2*maxNRanges);
1423 // params.Reset(fakeVal);
1424 
1425  for ( Int_t istep=0; istep<maxNRanges; istep++ ) {
1426  Int_t nPars = 2*(istep+1);
1427  Double_t xMin = trendGraph->GetXaxis()->GetXmin();
1428  Double_t xMax = trendGraph->GetXaxis()->GetXmax();
1429  func = new TF1("rangeFunc",this,&AliMTRChEffAnalysis::FitRangesFunc,xMin,xMax,nPars,"AliMTRChEffAnalysis","FitRanges");
1430  func->FixParameter(0,istep);
1431  for ( Int_t ipar=1; ipar<nPars; ipar++ ) {
1432 // if ( ipar >= 2*istep ) {
1433 // if ( TMath::Abs(params[ipar]-fakeVal) < 0.01 ) {
1434 // if ( ipar%2 == 1 ) params[ipar] = 0.95;
1435 // else params[ipar] = (xMax-xMin) * (Double_t)(ipar/2)/((Double_t)(istep+1));
1436 // }
1437 // func->SetParameter(ipar,params[ipar]);
1438  Double_t val = ( ipar%2 == 1 ) ? 0.95 : (xMax-xMin) * (Double_t)(ipar/2)/((Double_t)(istep+1));
1439  func->SetParameter(ipar,val);
1440  if ( ipar%2 == 0 ) func->SetParLimits(ipar,xMin,xMax);
1441  }
1442 
1443  TFitResultPtr fitResult = trendGraph->Fit(func,fitOpt.Data());
1444  // If fit converges close to a point where a break is forced
1445  // fix parameters and redo the fit
1446  if ( forcedChanges ) {
1447  Bool_t hasFixedPars = kFALSE;
1448  for ( Int_t iforced=0; iforced<nForced; iforced++ ) {
1449  for ( Int_t jstep=0; jstep<istep; jstep++ ) {
1450  Int_t ipar = 2*(jstep+1);
1451  if ( TMath::Abs(forcedChangesBin[iforced]-func->GetParameter(ipar)) > 2. ) continue;
1452  func->FixParameter(ipar,forcedChangesBin[iforced]);
1453  hasFixedPars = kTRUE;
1454  }
1455  }
1456  if ( hasFixedPars ) fitResult = trendGraph->Fit(func,fitOpt.Data());
1457  }
1458 
1459 // for ( Int_t ipar=1; ipar<nPars; ipar++ ) {
1460 // params[ipar] = func->GetParameter(ipar);
1461 // }
1462 
1463  Double_t normChi2 = func->GetChisquare() / ((Double_t)func->GetNDF());
1464  if ( normChi2 < minNormChi2 ) {
1465  minNormChi2 = normChi2;
1466  minNormChi2Step = istep;
1467  }
1468 // if ( static_cast<int>(fitResult) == 0 && normChi2 < chi2Cut ) break;
1469  if ( normChi2 < chi2Cut ) break; // REMEMBER TO CHECK
1470  delete func;
1471  func = 0x0;
1472  }
1473 
1474  if ( func ) {
1475  trendGraph->GetListOfFunctions()->Add(func->Clone());
1476  Int_t nSteps = (Int_t)func->GetParameter(0);
1477 
1478  // The runs for which the efficiency changes could be unsorted
1479  // (when forced values are requires)
1480  // Copy the parameters in arrays to sort them
1481  Int_t nPoints = nSteps+1;
1482  TArrayD parRunIdx(nPoints);
1483  TArrayD parEff(nPoints);
1484  for ( Int_t ipar=0; ipar<func->GetNpar(); ipar++ ) {
1485  Int_t istep = ipar/2;
1486  if ( ipar%2 == 0 ) parRunIdx[istep] = func->GetParameter(ipar);
1487  else parEff[istep] = func->GetParameter(ipar);
1488  }
1489  parRunIdx[0] = 0.;
1490  TArrayI sortIdx(nPoints);
1491  TMath::Sort(nPoints,parRunIdx.GetArray(),sortIdx.GetArray(),kFALSE);
1492 
1493  runRanges.Set(2*nPoints);
1494  Int_t irun = 0;
1495  runRanges[irun++] = returnIndex ? 0 : GetRunNumber(0);
1496  for ( Int_t ipoint=1; ipoint<nPoints; ipoint++ ) {
1497  Double_t deltaEff = TMath::Abs(parEff[sortIdx[ipoint]]-parEff[sortIdx[ipoint-1]]);
1498 // if ( ipoint>=2 ) deltaEff = TMath::Max(deltaEff,TMath::Abs(parEff[sortIdx[ipoint]]-parEff[sortIdx[ipoint-2]]));
1499  if ( deltaEff < minEffVariation ) {
1500  AliWarning(Form("Efficiency variation for %s is %g => consider uniform",trendGraph->GetName(),deltaEff));
1501  continue;
1502  }
1503  Int_t runChangeIdx = TMath::Nint(parRunIdx[sortIdx[ipoint]]);
1504  AliDebug(1,Form("Change run: %s => %g => %i %i",trendGraph->GetName(),parRunIdx[sortIdx[ipoint]],runChangeIdx,GetRunNumber(runChangeIdx)));
1505  runRanges[irun++] = returnIndex ? runChangeIdx-1 : GetRunNumber(runChangeIdx-1);
1506  runRanges[irun++] = returnIndex ? runChangeIdx : GetRunNumber(runChangeIdx);
1507  }
1508  Int_t lastPt = trendGraph->GetN()-1;
1509  runRanges[irun++] = returnIndex ? lastPt : GetRunNumber(lastPt);
1510  runRanges.Set(irun);
1511  }
1512  else {
1513  AliWarning(Form("Fit did not converge for %s (minimum chi2 %g for step %i)",trendGraph->GetName(),minNormChi2,minNormChi2Step));
1514  }
1515  return runRanges;
1516 }
1517 
1518 //________________________________________________________________________
1519 TString AliMTRChEffAnalysis::GetId ( const char* condition, Int_t minRun, Int_t maxRun ) const
1520 {
1522  if ( maxRun < minRun ) maxRun = minRun;
1523  return Form("%s_%i_%i",condition,minRun,maxRun);
1524 }
1525 
1526 //________________________________________________________________________
1528 {
1531  if ( obj->GetMinRun() == runNumber ) {
1532  return obj->GetUniqueID();
1533  break;
1534  }
1535  }
1536  return -1;
1537 }
1538 
1539 //________________________________________________________________________
1541 {
1543 // TGraphAsymmErrors* outliers = new TGraphAsymmErrors();
1544  TGraphAsymmErrors* outliers = new TGraphAsymmErrors(*graph);
1545  outliers->SetHistogram(static_cast<TH1F*>(graph->GetHistogram()->Clone(Form("%s_outliers",graph->GetHistogram()->GetName()))));
1546 // outliers->SetLineColor(graph->GetLineColor()+1);
1547  if ( graph->GetListOfFunctions()->GetEntries() == 0 ) graph->Fit("pol0","Q0");
1548  TF1* func = static_cast<TF1*>(graph->GetListOfFunctions()->At(0));
1549 
1550  Double_t xpt, ypt;
1551  Int_t nremoved = 0;
1552  for ( Int_t ipt=0; ipt<graph->GetN(); ipt++ ) {
1553  graph->GetPoint(ipt,xpt,ypt);
1554  Double_t diff = ypt - func->Eval(xpt);
1555  Double_t err = ( diff > 0. ) ? graph->GetErrorYlow(ipt) : graph->GetErrorYhigh(ipt);
1556  if ( err <= 0. || TMath::Abs(diff)/err > maxNsigmas ) continue;
1557  outliers->RemovePoint(ipt-nremoved);
1558  nremoved++;
1559 // outliers->SetPoint(iopt,xpt,ypt);
1560  }
1561  return outliers;
1562 }
1563 
1564 //________________________________________________________________________
1566 {
1568  if ( ipt < 0 || ipt >= fRunMap.size() ) return -1;
1569  return fRunMap[ipt]->GetMinRun();
1570 }
1571 
1572 //________________________________________________________________________
1573 TList* AliMTRChEffAnalysis::GetRunList ( const char* runList ) const
1574 {
1576  TList* rl = new TList;
1577  rl->SetOwner();
1578  TString sRunList = gSystem->ExpandPathName(runList);
1579  if ( gSystem->AccessPathName(sRunList) || sRunList.EndsWith(".root") ) {
1580  sRunList.ReplaceAll(","," ");
1581  if ( sRunList.IsDigit() ) {
1582  TObjArray* arr = sRunList.Tokenize(" ");
1583  for ( Int_t iarr=0; iarr<arr->GetEntries(); iarr++ ) {
1584  rl->Add(new TObjString(arr->At(iarr)->GetName()));
1585  }
1586  delete arr;
1587  }
1588  }
1589  else {
1590  ifstream inFile(sRunList.Data());
1591  TString currLine = "";
1592  while ( ! inFile.eof() ) {
1593  currLine.ReadLine(inFile);
1594  TString currRun = AliAnalysisMuonUtility::GetRunNumberAsString(currLine);
1595  if ( ! currRun.IsNull() ) rl->Add(new TObjString(currRun));
1596  }
1597  inFile.close();
1598  }
1599  rl->Sort();
1600  return rl;
1601 }
1602 
1603 //________________________________________________________________________
1604 TString AliMTRChEffAnalysis::GetShortConditionTitle ( const char* conditionName ) const
1605 {
1607 
1608  TString sCond(conditionName);
1609  TObjArray* refCondition = static_cast<TObjArray*>(fConditions->UncheckedAt(0));
1610  TString sRef(refCondition->GetName());
1611 
1612  TObjArray* condition = static_cast<TObjArray*>(fConditions->FindObject(conditionName));
1613  TString title = "";
1614  if ( ! condition || sCond == sRef ) {
1615  title = sCond;
1616  }
1617  else {
1618  for ( Int_t ic=0; ic<condition->GetEntriesFast(); ic++ ) {
1619  TString currCond = static_cast<TObjString*>(condition->UncheckedAt(ic))->String();
1620  TString refCond = static_cast<TObjString*>(refCondition->UncheckedAt(ic))->String();
1621  if ( currCond == refCond ) continue;
1622  title += ";" + currCond;
1623  }
1624  title.Remove(TString::kLeading,';');
1625  }
1626  title.ReplaceAll(",","+");
1627 
1628  return title;
1629 }
1630 
1631 //________________________________________________________________________
1632 TH1* AliMTRChEffAnalysis::GetSum ( AliTrigChEffOutput* trigOut, TObjArray* condition, Int_t itype, Int_t icount, Int_t ichamber ) const
1633 {
1635  TString objName = "";
1636  for ( Int_t ic=3; ic<6; ic++ ) {
1637  objName += condition->UncheckedAt(ic)->GetName();
1638  }
1639  return static_cast<TH1*>(trigOut->GetSum(condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName(),objName));
1640 }
1641 
1642 //________________________________________________________________________
1643 TH1* AliMTRChEffAnalysis::GetTrend ( Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem ) const
1644 {
1646  if ( itype == AliTrigChEffOutput::kHchamberEff ) {
1647  if ( idetelem < 0 && ichamber >=0 ) idetelem = 11+ichamber;
1648  }
1649  TH1* outHisto = 0x0;
1650 
1651  Int_t nRuns = fRunMap.size();
1652 
1653  Int_t ibin = 0;
1655  ibin++;
1656  TList* effHistoList = obj->GetEffHistoList(fConditions->UncheckedAt(0)->GetName());
1657  if ( ! outHisto ) {
1658 // TString outName = identifier;
1659  TString outName = Form("histo_type%i_count%i_ch%i_",itype,icount,11+ichamber);
1660 // outName.ReplaceAll("/","_");
1661  outName += Form("%i_trend",idetelem);
1662  outHisto = new TH1D(outName.Data(),outName.Data(),nRuns,0.,(Double_t)nRuns);
1663  outHisto->SetDirectory(0);
1664  outHisto->GetXaxis()->SetTitle("Run num.");
1665  }
1666  Int_t run = obj->GetMinRun();
1667  outHisto->GetXaxis()->SetBinLabel(ibin,Form("%i",run));
1668  TH1* histo = GetHisto(effHistoList,itype,icount,ichamber);
1669  Int_t currBin = histo->GetXaxis()->FindBin(idetelem);
1670  outHisto->SetBinContent(ibin,histo->GetBinContent(currBin));
1671  outHisto->SetBinError(ibin,histo->GetBinError(currBin));
1672  }
1673  if ( outHisto ) outHisto->GetXaxis()->LabelsOption("v");
1674  return outHisto;
1675 }
1676 
1677 //________________________________________________________________________
1678 TGraphAsymmErrors* AliMTRChEffAnalysis::GetTrendEff ( Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem ) const
1679 {
1681  if ( Check() ) return NULL;
1682  if ( icount == AliTrigChEffOutput::kAllTracks ) {
1683  AliWarning("Chose either bending plane, non-bending plane or both planes");
1684  return NULL;
1685  }
1686  TH1* histoNum = GetTrend(itype,icount,ichamber,idetelem);
1687  TH1* histoDen = GetTrend(itype,AliTrigChEffOutput::kAllTracks,ichamber,idetelem);
1688  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum,histoDen,"e0");
1689  histoNum->Reset();
1690  histoNum->SetStats(kFALSE);
1691  // Solves crash when saving the canvas as a root file
1692  graph->SetHistogram(new TH1F(*static_cast<TH1F*>(histoNum)));
1693  graph->GetHistogram()->SetDirectory(0);
1694  graph->GetYaxis()->SetTitle("Efficiency");
1695  graph->SetMarkerSize(0.5);
1696 // for ( Int_t ibin=1; ibin<=histoNum->GetXaxis()->GetNbins(); ibin++ ) {
1697 // graph->GetXaxis()->SetBinLabel(ibin,histoNum->GetXaxis()->GetBinLabel(ibin));
1698 // }
1699  delete histoNum;
1700  delete histoDen;
1701  return graph;
1702 }
1703 
1704 //________________________________________________________________________
1706 {
1708  Double_t binomialEff = 0.;
1709  Double_t sumErr2 = 0.;
1710  for ( Int_t jch=-1; jch<4; jch++ ) {
1711  Double_t prodEff = 1.;
1712  Double_t prodErr2 = 0.;
1713  for ( Int_t ich=0; ich<4; ich++ ) {
1714  Double_t currEff = ( ich == jch ) ? 1.-eff[ich] : eff[ich];
1715  prodEff *= currEff;
1716  Double_t relErr = ( currEff>0. ) ? effErr[ich]/currEff : 0.;
1717  prodErr2 += relErr*relErr;
1718  }
1719  binomialEff += prodEff;
1720  sumErr2 += prodEff*prodEff*prodErr2;
1721  }
1722  probErr = TMath::Sqrt(sumErr2);
1723  return binomialEff;
1724 }
1725 
1726 //________________________________________________________________________
1728 {
1730  if ( fMergedMap.empty() ) {
1731  AliError("You first need to merge efficiency objects with MergeOutput");
1732  return kFALSE;
1733  }
1734  return kTRUE;
1735 }
1736 
1737 //________________________________________________________________________
1738 Bool_t AliMTRChEffAnalysis::InitFromLocal ( const char *localFileList, const char *outputName )
1739 {
1741 
1742  AliInfo("Reading efficiency objects");
1743 
1745 
1746  TString filename(localFileList);
1747  gSystem->ExpandPathName(filename);
1748  if ( gSystem->AccessPathName(filename.Data()) ) {
1749  AliWarning(Form("Cannot find %s",filename.Data()));
1750  return kFALSE;
1751  }
1752  if ( filename.EndsWith(".root") ) return AddToList(filename.Data(),outputName);
1753 
1754  Bool_t isOk = kTRUE;
1755  // std::vector<Int_t> orderedRuns;
1756  std::map<int,std::string> tmpMap;
1757  ifstream inFile(filename.Data());
1758  TString currLine = "";
1759  while ( ! inFile.eof() ) {
1760  currLine.ReadLine(inFile);
1761  if ( currLine.IsNull() ) continue;
1762  if ( gSystem->AccessPathName(currLine.Data()) ) continue;
1763  int currRun = AliAnalysisMuonUtility::GetRunNumber ( currLine );
1764  tmpMap[currRun] = std::string(currLine.Data());
1765  // orderedRuns.push_back(currRun);
1766  }
1767  inFile.close();
1768 
1769  for ( auto it = tmpMap.begin(); it != tmpMap.end(); ++it ) {
1770  if ( ! AddToList(it->second.c_str(), outputName) ) isOk = kFALSE;
1771  }
1772 
1773  return isOk;
1774 }
1775 
1776 //________________________________________________________________________
1777 Bool_t AliMTRChEffAnalysis::InitFromGrid ( const char *runList, const char *path, const char *pattern, const char* localFileList, const char* outDir, const char *directory, const char* outputName )
1778 {
1780  CopyLocally(runList,path,pattern,localFileList,outDir,directory);
1781  return InitFromLocal(localFileList,outputName);
1782 }
1783 
1784 //________________________________________________________________________
1785 Bool_t AliMTRChEffAnalysis::InitFromWeb ( const char *runList, const char *path, const char* localFileList, const char* outDir, const char *directory, const char* outputName )
1786 {
1788  CopyLocally(runList,path,"",localFileList,outDir,directory);
1789  return InitFromLocal(localFileList,outputName);
1790 }
1791 
1792 //________________________________________________________________________
1793 Bool_t AliMTRChEffAnalysis::MergeOutput ( TArrayI runRanges, Double_t averageStatError, Bool_t isIndex )
1794 {
1796 
1797  if ( runRanges.GetSize()%2 == 1 ) {
1798  AliError("Run ranges expected in the form: start_period1,end_period1,start_period2,end_period2... => even number expected");
1799  return kFALSE;
1800  }
1801 
1802  TArrayI mergedRanges = MergeRangesForStat(runRanges, averageStatError);
1803 
1804  AliInfo("Merging efficiencies");
1805 
1806  Int_t nRanges = mergedRanges.GetSize()/2;
1807 
1808 
1809  if ( fMergedMap.size() > 0 ) {
1810  for ( AliMTRChEffAnalysis::AliMTRChEffInnerObj* obj : fMergedMap ) delete obj;
1811  fMergedMap.clear();
1812  }
1813 
1814  for ( Int_t irange=0; irange<nRanges; irange++ ) {
1815  Int_t firstRun = mergedRanges[2*irange];
1816  Int_t lastRun = mergedRanges[2*irange+1];
1817  if ( isIndex ) {
1818  firstRun = GetRunNumber(firstRun);
1819  lastRun = GetRunNumber(lastRun);
1820  }
1821 
1822  TString filename = "", outputname = "";
1823 
1824  TFileMerger fileMerger;
1826  Int_t run = obj->GetMinRun();
1827  if ( run < firstRun || run > lastRun ) continue;
1828  filename = obj->GetFilename();
1829  outputname = obj->GetOutputname();
1830  if ( firstRun == lastRun ) continue;
1831  fileMerger.AddFile(filename.Data(),kFALSE);
1832  }
1833 
1834  TString sRange = Form("%i_%i",firstRun,lastRun);
1835  TString mergedFilename = Form("mergedTrigEff_runs_%s.root",sRange.Data());
1836 
1837  if ( firstRun == lastRun ) TFile::Cp(filename.Data(),mergedFilename.Data(),kFALSE);
1838  else {
1839  fileMerger.OutputFile(mergedFilename.Data());
1840  fileMerger.Merge();
1841  }
1842  AliTrigChEffOutput* trigOut = new AliTrigChEffOutput(mergedFilename,outputname);
1843  AliMTRChEffInnerObj* mergedObj = new AliMTRChEffInnerObj(mergedFilename.Data(),outputname.Data(),firstRun,lastRun);
1844  for ( Int_t icond=0; icond<fConditions->GetEntriesFast(); icond++ ) {
1845  TObjArray* condition = static_cast<TObjArray*>(fConditions->UncheckedAt(icond));
1846  TList* effHistoList = GetEffHistoList(trigOut,condition);
1847  mergedObj->AddEffHistoList(condition->GetName(), effHistoList);
1848  }
1849  fMergedMap.push_back(mergedObj);
1850  delete trigOut;
1851  }
1852  return kTRUE;
1853 }
1854 
1855 //________________________________________________________________________
1856 TArrayI AliMTRChEffAnalysis::MergeRangesForStat ( TArrayI runRanges, Double_t averageStatError, Bool_t excludePeriphericBoards ) const
1857 {
1858  if ( averageStatError <= 0. || averageStatError >= 1. ) return runRanges;
1859 
1860  // FIXME: statstical error for binomial depends on the value of epsilon
1861  // for the moment let's assume an average efficiency of 0.9 (underestimated)
1862  // in the future one could maybe actually calculate it
1863  // (still we're working with average values...so the precision is limited)
1864  Double_t effForStatCalc = 0.9;
1865 
1866  Double_t averageStatNeeded = effForStatCalc*(1.-effForStatCalc)/(averageStatError*averageStatError);
1867 
1868  AliInfo(Form("Average statistics needed to reach precision of %g : %g",averageStatError,averageStatNeeded));
1869 
1870  Int_t nRanges = runRanges.GetSize()/2;
1871 
1872  TArrayD averageStat(nRanges);
1873  Double_t fullStat = 0.;
1874  for ( Int_t irange=0; irange<nRanges; irange++ ) {
1875  averageStat[irange] = GetAverageStat(runRanges[2*irange],runRanges[2*irange+1],AliTrigChEffOutput::kHboardEff,excludePeriphericBoards);
1876  fullStat += averageStat[irange];
1877  }
1878 
1879  TArrayI mergedRanges(runRanges.GetSize());
1880  Int_t imerged = 0;
1881  mergedRanges[imerged++] = runRanges[0];
1882  Double_t mergedAverageStat = 0., remainingStat = fullStat;
1883  for ( Int_t irange=0; irange<nRanges; irange++ ) {
1884  Int_t istart = 2*irange;
1885  Int_t iend = istart+1;
1886  mergedAverageStat += averageStat[irange];
1887  remainingStat -= averageStat[irange];
1888 
1889  AliInfo(Form("%i - %i => stat %g",runRanges[2*irange],runRanges[2*irange+1],averageStat[irange]));
1890 
1891  if ( ( mergedAverageStat >= averageStatNeeded && remainingStat >= averageStatNeeded ) || iend == runRanges.GetSize()-1 ) {
1892  mergedRanges[imerged++] = runRanges[iend];
1893  AliInfo(Form(" merged range %i - %i => stat %g",mergedRanges[imerged-2],mergedRanges[imerged-1],mergedAverageStat));
1894  mergedAverageStat = 0.;
1895  Int_t nextRun = iend+1;
1896  if ( nextRun < runRanges.GetSize() ) mergedRanges[imerged++] = runRanges[nextRun];
1897  }
1898  }
1899  mergedRanges.Set(imerged);
1900  return mergedRanges;
1901 }
1902 
1903 //________________________________________________________________________
1905 {
1907  if ( fNamer ) return fNamer;
1908 
1909  TObjArray arr;
1910  fNamer = new AliTrigChEffOutput(&arr,"dummy");
1911 
1912  return fNamer;
1913 }
1914 
1915 
1916 //________________________________________________________________________
1918 {
1920  TString currSrc(src);
1921  TString trigEffCDBdir = "MUON/Calib/TriggerEfficiency";
1922 
1923  if ( currSrc.BeginsWith("alien") && ! gGrid ) TGrid::Connect("alien://");
1924 
1925  AliMUONTriggerEfficiencyCells* effMap = 0x0;
1926  Bool_t deleteMap = kTRUE;
1927  if ( currSrc.EndsWith(".root") ) effMap = new AliMUONTriggerEfficiencyCells(currSrc.Data());
1928  else {
1929  TObjArray* dirRun = currSrc.Tokenize("?");
1930  TString cdbPath = dirRun->UncheckedAt(0)->GetName();
1931  TString runNum = ( dirRun->GetEntriesFast() > 1 ) ? dirRun->UncheckedAt(1)->GetName() : "";
1932  AliCDBManager* mgr = AliCDBManager::Instance();
1933  if ( ! mgr->GetDefaultStorage() ) mgr->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
1934  if ( mgr->GetEntryCache()->Contains(trigEffCDBdir.Data()) ) mgr->UnloadFromCache(trigEffCDBdir.Data());
1935  mgr->SetSpecificStorage(trigEffCDBdir.Data(),cdbPath.Data());
1936  Int_t runNumber = 0;
1937  if ( runNum.IsNull() ) {
1938  cout << "Please enter run number: " << endl;
1939  cin >> runNumber;
1940  }
1941  else runNumber = runNum.Atoi();
1942  mgr->SetRun(runNumber);
1943  AliCDBEntry* cdbEntry = mgr->Get(trigEffCDBdir.Data());
1944 
1945  // The CDB manager replace the current effMap with another in case two specific storage are provided
1946  // To avoid double deletion, do not delete the object
1947  deleteMap = kFALSE;
1948  effMap = static_cast<AliMUONTriggerEfficiencyCells*>(cdbEntry->GetObject());
1949  }
1950 
1951  if ( ! effMap ) {
1952  AliError(Form("Cannot find effieciency map in %s",src));
1953  return 0x0;
1954  }
1955 
1956  TList* effHistoList = CloneEffHistoList(effMap->GetHistoList());
1957  if ( deleteMap ) delete effMap;
1958 
1959  return effHistoList;
1960 }
1961 
1962 //________________________________________________________________________
1963 Bool_t AliMTRChEffAnalysis::RecoverEfficiency ( const char* runList, const char* ocdb, const char* systOcdb, Int_t referenceRun )
1964 {
1972 
1973  if ( ! HasMergedResults() ) return kFALSE;
1974 
1975  AliInfo("Check for local boards where the efficiency could not be computed and recover it from other maps");
1976 
1977  TList* rList = 0x0;
1978  std::vector<TList*> readEffLists;
1979  std::vector<TList*> systLists;
1980 
1981  TString refRun = "";
1982  if ( referenceRun >= 0 ) refRun = Form("%i",referenceRun);
1983  TList *refRead = 0x0, *refSyst = 0x0;
1984 
1985  // Search for chambers with missing efficiencies
1986  TString currName = "";
1988  TList* effList = obj->GetEffHistoList(fConditions->UncheckedAt(0)->GetName());
1989  std::vector<TH1*> histoList;
1990  histoList.reserve(16);
1991  for ( Int_t ich=0; ich<4; ich++ ) {
1992  for ( Int_t icount=0; icount<4; icount++ ) {
1993  currName = Namer()->GetHistoName(AliTrigChEffOutput::kHboardEff, icount, ich, -1, -1, -1);
1994  histoList[4*ich+icount] = static_cast<TH1*>(effList->FindObject(currName.Data()));
1995  }
1996  }
1997  for ( Int_t ibin=1; ibin<=histoList[0]->GetXaxis()->GetNbins(); ibin++ ) {
1998  Bool_t isUnknown[4] = {0,0,0,0};
1999  Int_t nDead = 0, nUnknown = 0;
2000  for ( Int_t ich=0; ich<4; ich++ ) {
2001  Double_t countAll = histoList[4*ich+AliTrigChEffOutput::kAllTracks]->GetBinContent(ibin);
2002  if ( countAll > 10 ) {
2003  Double_t eff = histoList[4*ich+AliTrigChEffOutput::kBothPlanesEff]->GetBinContent(ibin) / countAll;
2004  if ( eff<0.1 ) nDead++;
2005  }
2006  else {
2007  isUnknown[ich] = 1;
2008  nUnknown++;
2009  }
2010  }
2011  if ( nDead > 0 ) {
2012  if ( nUnknown == 3 ) {
2013  for ( Int_t ich=0; ich<4; ich++ ) {
2014  AliInfo(Form("Recovering board %i in ch %i",ibin,11+ich));
2015  if ( ! isUnknown[ich] ) continue;
2016  if ( readEffLists.size() == 0 ) {
2017  // Initialize once all needed objects for recovery
2018  rList = GetRunList(runList);
2019  if ( rList->GetEntries() == 0 ) {
2020  AliError("A recovery is needed, but no run list is specified: please specify it");
2021  return kFALSE;
2022  }
2023  if ( refRun.IsNull() ) refRun = rList->Last()->GetName();
2024  else if ( ! rList->FindObject(refRun.Data()) ) rList->Add(new TObjString(refRun));
2025  AliInfo(Form("Using efficiency of run %s",refRun.Data()));
2026  for ( Int_t itype=0; itype<2; itype++ ) {
2027  // Loop once on standard efficiency and another time for systematic efficiency
2028  TString currOcdb = ( itype == 0 ) ? ocdb : systOcdb;
2029  TString baseName = ( itype == 0 ) ? "RecoveredFrom" : "RecoveredSystFrom";
2030  TIter next(rList);
2031  TObjString* runObj = 0x0;
2032  while ( (runObj = static_cast<TObjString*>(next())) ) {
2033  Bool_t isRefRun = ( runObj->String() == refRun );
2034  // We only need the systematics for the chosen run
2035  if ( itype == 1 && ! isRefRun ) continue;
2036  TList* readList = ReadEffHistoList(Form("%s?%s",currOcdb.Data(),runObj->GetName()));
2037  readEffLists.push_back(readList);
2038 
2039  // The systematic efficiency list is a clone of the merged efficiency object
2040  // We will copy later on the recovered efficiency ONLY for the missing boards
2041  TList* systEffList = CloneEffHistoList(effList);
2042  systEffList->SetName(Form("%s_%s",baseName.Data(),runObj->GetName()));
2043  systLists.push_back(systEffList);
2044 
2045  if ( isRefRun && itype == 0 ) {
2046  refRead = readList;
2047  refSyst = systEffList;
2048  }
2049  } // loop on runs
2050  } // loop on standard or systematic OCDB
2051  }
2052  for ( Int_t imap=0; imap<readEffLists.size(); imap++ ) {
2053  TList* readList = readEffLists[imap];
2054  for ( Int_t icount=0; icount<4; icount++ ) {
2055  currName = Namer()->GetHistoName(AliTrigChEffOutput::kHboardEff, icount, ich, -1, -1, -1);
2056  TH1* histoFrom = static_cast<TH1*>(readList->FindObject(currName.Data()));
2057  TH1* histoTo = ( readList == refRead ) ? histoList[4*ich+icount] : static_cast<TH1*>(systLists[imap]->FindObject(currName.Data()));
2058  histoTo->SetBinContent(ibin,histoFrom->GetBinContent(ibin));
2059  } // loop on counts
2060  } // loop on maps
2061  } // loop on chambers
2062  } // needs recovery
2063  else AliWarning(Form("Local board %i: unknown efficiency: %i %i %i %i",ibin,isUnknown[0],isUnknown[1],isUnknown[2],isUnknown[3]));
2064  }
2065  } // loop on local boards
2066  for ( TList* systEffHistoList : systLists ) {
2067  if ( systEffHistoList == refSyst ) continue;
2068  obj->AddEffHistoList(systEffHistoList->GetName(),systEffHistoList);
2069  }
2070  } // loop on merged objects
2071 
2072  // Delete objects
2073  for ( TList* obj : systLists ) delete obj;
2074  readEffLists.clear();
2075  delete rList;
2076 
2077  return kTRUE;
2078 }
2079 
2080 //________________________________________________________________________
2081 Bool_t AliMTRChEffAnalysis::SetCondition ( const char* physSel, const char* trigClassName, const char* centrality, Int_t itrackSel, Int_t imatch, Int_t imethod, Bool_t isBasic )
2082 {
2084  if ( ! fConditions ) {
2085  fConditions = new TObjArray();
2086  fConditions->SetOwner();
2087  }
2088 
2089 
2090  TString sCondition = Form("%s;%s;%s",physSel,trigClassName,centrality);
2091  sCondition += ";" + Namer()->GetHistoName(-1,-1,-1,itrackSel,-1,-1);
2092  sCondition += ";" + Namer()->GetHistoName(-1,-1,-1,-1,imatch,-1);
2093  sCondition += ";" + Namer()->GetHistoName(-1,-1,-1,-1,-1,imethod);
2094 
2095  TObjArray* foundCondition = static_cast<TObjArray*>(fConditions->FindObject(sCondition.Data()));
2096  TObjArray* basicCondition = static_cast<TObjArray*>(fConditions->At(0));
2097 
2098  TObjArray* addCondition = 0x0;
2099 
2100  if ( foundCondition ) {
2101  if ( isBasic ) {
2102  if ( foundCondition == basicCondition ) return kFALSE;
2103  else {
2104  fConditions->Remove(foundCondition);
2105  addCondition = foundCondition;
2106  }
2107  }
2108  else {
2109  AliInfo("Systematic condition already added");
2110  return kFALSE;
2111  }
2112  }
2113  else {
2114  addCondition = sCondition.Tokenize(";");
2115  addCondition->SetName(sCondition.Data());
2116  addCondition->UncheckedAt(3)->SetUniqueID(itrackSel);
2117  addCondition->UncheckedAt(4)->SetUniqueID(imatch);
2118  addCondition->UncheckedAt(5)->SetUniqueID(imethod);
2119  }
2120 
2121 
2122  if ( isBasic ) {
2123  if ( basicCondition ) {
2124  AliInfo(Form("Changing current eff. condition: %s",basicCondition->GetName()));
2125  fConditions->Remove(basicCondition);
2126  delete basicCondition;
2127  }
2128  fConditions->AddAt(addCondition,0);
2129  fConditions->Compress();
2130 
2131  // Update outputs
2133  obj->RemoveEffHistoList(sCondition.Data());
2134  AddToList(obj->GetFilename(), obj->GetOutputname());
2135  }
2136  }
2137  else fConditions->Add(addCondition);
2138 
2139  return kTRUE;
2140 }
2141 
2142 //________________________________________________________________________
2144 {
2147 }
2148 
2149 
2150 //________________________________________________________________________
2151 Bool_t AliMTRChEffAnalysis::SetEffConditions ( const char* physSel, const char* trigClassName, const char* centrality, Int_t itrackSel, Int_t imatch, Int_t imethod )
2152 {
2154  return SetCondition(physSel, trigClassName, centrality, itrackSel, imatch, imethod, kTRUE);
2155 }
2156 
2157 //________________________________________________________________________
2158 Bool_t AliMTRChEffAnalysis::WriteMergedToOCDB ( const char* outputCDB, Bool_t writeSystematics ) const
2159 {
2161  if ( ! HasMergedResults() ) return kFALSE;
2162 
2163  AliInfo("Writing merged efficiencies to OCDB");
2164 
2165  TString outCDB(outputCDB);
2166  if ( ! outCDB.Contains("://") || outCDB == "raw://" ) {
2167  AliError("Invalid CDB output dir");
2168  return kFALSE;
2169  }
2170 
2171  TString rmCommand = "rm";
2172  if ( outCDB.BeginsWith("alien://") && ! gGrid ) {
2173  TGrid::Connect("alien://");
2174  rmCommand = "alien_rm";
2175  if ( ! gGrid ) {
2176  AliError("Cannot open grid connection");
2177  return kFALSE;
2178  }
2179  }
2180 
2181  AliCDBManager* mgr = AliCDBManager::Instance();
2182  if ( ! mgr->GetDefaultStorage() ) mgr->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
2183 
2184  TString trigEffCDBdir = "MUON/Calib/TriggerEfficiency";
2185 
2186  mgr->SetSpecificStorage(trigEffCDBdir.Data(),outCDB.Data());
2187 
2188  AliCDBStorage* specificStorage = mgr->GetSpecificStorage(trigEffCDBdir.Data());
2189  TString baseOutDir = specificStorage->GetBaseFolder();
2190 
2191  TString condName = ( writeSystematics ) ? "Systematics" : fConditions->UncheckedAt(0)->GetName();
2192 
2194  TList* effHistos = obj->GetEffHistoList(condName.Data());
2195  if ( ! effHistos ) {
2196  AliWarning("No systematic condition found: you should first run BuildSystematicMap");
2197  continue;
2198  }
2199 
2200  // Write OCDB object
2201  Int_t firstRun = obj->GetMinRun();
2202  Int_t lastRun = obj->GetMaxRun();
2203 
2204  // If an object is already there, ask to remove it or keep it
2205  for ( Int_t irun=0; irun<2; irun++ ) {
2206  Int_t runnr = ( irun == 0 ) ? firstRun : lastRun;
2207  specificStorage->QueryCDB(runnr);
2208  TObjArray* allIdsForRun = specificStorage->GetQueryCDBList();
2209  TIter nextId(allIdsForRun);
2210  AliCDBId* id = 0x0;
2211  while ((id = static_cast<AliCDBId*>(nextId()))) {
2212  TString path(id->GetPath());
2213  Int_t foundFirst = id->GetFirstRun();
2214  Int_t foundLast = id->GetLastRun();
2215  Int_t version = id->GetVersion();
2216  Int_t subversion = TMath::Max(id->GetSubVersion(),0);
2217  TString fullPath = Form("%s/%s/Run%d_%d_v%d_s%d.root",baseOutDir.Data(),path.Data(),foundFirst,foundLast,version,subversion);
2218  ExecCommand(Form("%s %s",rmCommand.Data(),fullPath.Data()), kTRUE);
2219  }
2220  }
2221 
2222  // Save the CDB object in the specific storage
2223  AliMUONTriggerEfficiencyCells* effMap = new AliMUONTriggerEfficiencyCells(CloneEffHistoList(effHistos));
2224  AliMUONCDB::WriteToCDB(effMap, "MUON/Calib/TriggerEfficiency", firstRun, lastRun, "Measured efficiencies");
2225  delete effMap; // CAVEAT: effMap is owner of effHistos
2226  }
2227  return kTRUE;
2228 }
2229 
2230 //________________________________________________________________________
2232 {
2233  if ( gPad->GetEvent() != kButton1Double ) return;
2234  TVirtualPad* pad = gPad;
2235  Int_t px = pad->GetEventX();
2236  Int_t py = pad->GetEventY();
2237  TCanvas* can = new TCanvas("zoom","zoom",px,py,600,600);
2238  for ( Int_t iobj=0; iobj<pad->GetListOfPrimitives()->GetEntries(); iobj++ ) {
2239  TObject* obj = pad->GetListOfPrimitives()->At(iobj);
2240  obj = obj->Clone(Form("%s_zoom",obj->GetName()));
2241  TString drawOpt = obj->GetOption();
2242  if ( drawOpt.IsNull() ) {
2243  if ( obj->InheritsFrom(TGraph::Class()) ) {
2244  drawOpt = "p";
2245  if ( iobj == 1 ) drawOpt.Append("a");
2246  static_cast<TGraph*>(obj)->GetXaxis()->SetLabelSize();
2247  }
2248  else if ( obj->InheritsFrom(TH1::Class()) ) {
2249  drawOpt = "e";
2250  if ( iobj == 1 ) drawOpt.Append("same");
2251  static_cast<TH1*>(obj)->GetXaxis()->SetLabelSize();
2252  }
2253  }
2254  obj->Draw(drawOpt.Data());
2255  }
2256  can->Modified();
2257  can->Update();
2258 }
2259 
2260 //___________________________________________________________________________
2261 AliMTRChEffAnalysis::AliMTRChEffInnerObj::AliMTRChEffInnerObj ( const char* filename, const char* outputname, Int_t minRun, Int_t maxRun ) :
2262  TObject(),
2263  fFilename(filename),
2264  fOutputname(outputname),
2265  fMinRun(minRun),
2266  fMaxRun(maxRun)
2267 {
2269  if ( fMaxRun < fMinRun ) fMaxRun = fMinRun;
2270 }
2271 
2272 //___________________________________________________________________________
2274 {
2276  for ( auto& mapEntry : fEffLists ) delete mapEntry.second;
2277  fEffLists.clear();
2278 }
2279 
2280 //___________________________________________________________________________
2282 {
2284  auto const& mapEntry = fEffLists.find(condition);
2285  if ( mapEntry == fEffLists.end() ) return 0x0;
2286  return mapEntry->second;
2287 }
2288 
2289 //___________________________________________________________________________
2291 {
2293  if ( fEffLists.find(condition) != fEffLists.end() ) {
2294  AliWarning(Form("Condition %s already present: nothing done",condition));
2295  return kFALSE;
2296  }
2297  fEffLists.insert({condition,effHistoList});
2298  fSortKeys.push_back(condition);
2299  return kTRUE;
2300 }
2301 
2302 //___________________________________________________________________________
2304 {
2306  auto const& mapEntry = fEffLists.find(condition);
2307  if ( mapEntry == fEffLists.end() ) return kFALSE;
2308  delete mapEntry->second;
2309  return fEffLists.erase(condition);
2310 }
const char * filename
Definition: TestFCM.C:1
return jsonbuilder str().c_str()
Hit pattern from tracker track extrapolation.
TList * GetEffHistoList(TString physSel, TString trigClassNames, TString centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
void CompareMergedEfficiencies(const char *opt) const
double Double_t
Definition: External.C:58
void CopyDir(TDirectory *source) const
Double_t GetError(Double_t errLow, Double_t errHigh) const
const char * title
Definition: MakeQAPdf.C:27
const char * cdbPath
Definition: AOD.C:26
Bool_t CopyLocally(const char *runList, const char *path, const char *pattern, const char *localFileList, const char *outDir, const char *directory) const
Double_t GetThreeOfFour(TArrayD eff, TArrayD effErr, Double_t &probErr) const
AliRunLoader * rl
TSystem * gSystem
TGraphAsymmErrors * GetTrendEff(Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem) const
centrality
Bool_t RemoveEffHistoList(const char *condition)
AliMTRChEffInnerObj(const char *filename, const char *outputname, Int_t minRun, Int_t maxRun=-1)
TArrayI MergeRangesForStat(TArrayI runRanges, Double_t averageStatError, Bool_t excludePeriphericBoards=kTRUE) const
Int_t ComputeAndCompareEfficiencies(const char *sources, const char *titles, const char *opt, const char *canvasNameSuffix="") const
Counts per board histogram index.
Bool_t InitFromWeb(const char *runList, const char *path, const char *localFileList="localFileList.txt", const char *outDir="", const char *directory="MTR_ChamberEffMap", const char *outputName="testMTRChamberEff")
Int_t CompareEfficiencies(const char *sources, const char *titles, const char *opt, const char *canvasNameSuffix="") const
TList * GetEffHistoList(const char *condition) const
tracks used for calculation
Int_t nDE
UShort_t T(UShort_t m, UShort_t t)
Definition: RingBits.C:60
TList * GetEffHistoList(AliTrigChEffOutput *trigOut, TObjArray *condition) const
int Int_t
Definition: External.C:63
Bool_t WriteMergedToOCDB(const char *outputCDB="CDB", Bool_t writeSystematics=kFALSE) const
Bool_t AddToList(const char *filename, const char *outputName)
Number of count type.
Int_t CompareEfficiencyMethods(const char *source, const char *opt, const char *canvasNameSuffix="") const
Output for Trig chamber effieincy.
Bool_t InitFromLocal(const char *localFileList, const char *outputName="testMTRChamberEff")
Definition: External.C:212
Bool_t AddEffHistoList(const char *condition, TList *effHistoList)
TArrayI GetHomogeneousRanges(Double_t chi2Cut=3, Int_t maxNRanges=4, Double_t minEffVariation=0.005, Bool_t perRPC=kTRUE, TArrayI *forcedChanges=0x0, Double_t minEff=0.85, Double_t maxEff=1.01)
Bool_t SetEffConditions(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
Output for Trig chamber effieincy.
AliTrigChEffOutput * fNamer
! Namer for histograms
void DrawStatContribution(Int_t itype, Int_t irpc, Double_t maxNsigmaOutliers=-1., Double_t minY=0., Double_t maxY=0.15) const
Double_t GetAverageStat(Int_t firstRun, Int_t lastRun, Int_t itype=AliTrigChEffOutput::kHboardEff, Bool_t excludePeriphericBoards=kTRUE) const
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)
TString GetId(const char *condition, Int_t minRun, Int_t maxRun=-1) const
TObject * FindObject(int bin, const char *nameH, const TList *lst, Bool_t normPerEvent=kTRUE)
AliTrigChEffOutput * Namer() const
std::vector< AliMTRChEffAnalysis::AliMTRChEffInnerObj * > fRunMap
! Map of internal objects per run
Int_t colors[nPtBins]
std::vector< AliMTRChEffAnalysis::AliMTRChEffInnerObj * > fMergedMap
! Map of merged internal objects
ClassImp(AliAnalysisTaskDeltaPt) AliAnalysisTaskDeltaPt
TH1 * GetHisto(TList *effHistoList, Int_t itype, Int_t icount, Int_t ichamber) const
Bool_t SetCondition(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod, Bool_t isBasic)
Counts per cathode histogram index.
TList * GetRunList(const char *runList) const
Int_t GetRunNumber(Int_t ipt) const
Bool_t HasMergedResults() const
Bool_t ExecCommand(TString command, Bool_t prompt) const
TArrayI BoardsInRPC(Int_t irpc) const
Bool_t RecoverEfficiency(const char *runList, const char *ocdb, const char *systOcdb, Int_t referenceRun=-1)
Int_t GetIndexFromRun(Int_t runNumber) const
Double_t FitRangesFunc(Double_t *x, Double_t *par)
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
void DrawEffTrend(Int_t itype, Int_t irpc, Double_t maxNsigmasOutliers=-1., Double_t minEff=0.8, Double_t maxEff=1.01) const
TObjArray * fConditions
! List of conditions for trigger efficiency
Bool_t InitFromGrid(const char *runList, const char *path, const char *pattern, const char *localFileList="localFileList.txt", const char *outDir="", const char *directory="MTR_ChamberEffMap", const char *outputName="testMTRChamberEff")
TList * CloneEffHistoList(TList *effHistos) const
TGraphAsymmErrors * GetOutliers(TGraphAsymmErrors *graph, Double_t maxNsigmas=3.) const
Bool_t AddSystematicCondition(const char *physSel, const char *trigClassName, const char *centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
bool Bool_t
Definition: External.C:53
TString GetShortConditionTitle(const char *conditionName) const
Bool_t DrawSystematicEnvelope(Bool_t perRPC=kFALSE) const
Bool_t MergeOutput(TArrayI runRanges, Double_t averageStatError=0.01, Bool_t isIndex=kFALSE)
TString GetHistoName(Int_t itype, Int_t icount, Int_t ichamber, Int_t itrackSel, Int_t imatch, Int_t imethod)
Definition: External.C:196
TH1 * GetSum(AliTrigChEffOutput *trigOut, TObjArray *condition, Int_t itype, Int_t icount, Int_t ichamber) const
TDirectoryFile * dir
TList * ReadEffHistoList(const char *src) const
Counts per slat histogram index.
TH1 * GetTrend(Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem) const