AliPhysics  dccfc39 (dccfc39)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 "TPRegexp.h"
26 #include "TRegexp.h"
27 #include "TFile.h"
28 #include "TDirectory.h"
29 #include "TTree.h"
30 #include "TKey.h"
31 #include "TArrayI.h"
32 #include "TArrayD.h"
33 #include "TGrid.h"
34 #include "TGridResult.h"
35 #include "TGraphAsymmErrors.h"
36 #include "TH1.h"
37 #include "TH2.h"
38 #include "TAxis.h"
39 #include "TF1.h"
40 #include "TMath.h"
41 #include "TCanvas.h"
42 #include "TLegend.h"
43 #include "TLine.h"
44 #include "TLatex.h"
45 #include "TFileMerger.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  fOutputs(0x0),
75  fConditions(0x0),
76  fMergedOutputs(0x0)
77 {
79 
80 }
81 
82 //________________________________________________________________________
83 AliMTRChEffAnalysis::AliMTRChEffAnalysis ( const char *localFileList, const char* outputName ) :
84  TObject(),
85  fOutputs(0x0),
86  fConditions(0x0),
87  fMergedOutputs(0x0)
88 {
90  SetOutList(localFileList,outputName);
91 }
92 
93 //________________________________________________________________________
95 {
96  //
98  //
99  delete fOutputs;
100  delete fConditions;
101  delete fMergedOutputs;
102 }
103 
104 //________________________________________________________________________
105 Bool_t AliMTRChEffAnalysis::AddSystematicCondition ( const char* physSel, const char* trigClassName, const char* centrality, Int_t itrackSel, Int_t imatch, Int_t imethod )
106 {
108  return SetCondition(physSel, trigClassName, centrality, itrackSel, imatch, imethod, kFALSE);
109 }
110 
111 //________________________________________________________________________
112 Bool_t AliMTRChEffAnalysis::AddToList ( const char *filename, const char *outputName )
113 {
115  AliTrigChEffOutput* trigOut = new AliTrigChEffOutput(filename,outputName);
116  if ( ! trigOut->GetMergeableCollection() ) {
117  AliError(Form("Cannot find %s in %s\n",outputName,filename));
118  return kFALSE;
119  }
120 
121  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
122 
123 // // Delete counter collection to save memory
124 // trigOut->RemoveFromList(trigOut->GetCounterCollection());
125  // Just keep counter and mergeable collections
126  TList* effHistoList = GetEffHistoList(trigOut,condition);
127  effHistoList->SetName(filename);
128  TString currRun = AliAnalysisMuonUtility::GetRunNumberAsString(filename);
129  effHistoList->SetUniqueID(currRun.Atoi());
130 
131  if ( ! fOutputs ) {
132  fOutputs = new TObjArray();
133  fOutputs->SetOwner();
134  fOutputs->SetName(outputName);
135  }
136  fOutputs->Add(effHistoList);
137  delete trigOut;
138  return kTRUE;
139 }
140 
141 //________________________________________________________________________
142 TArrayI AliMTRChEffAnalysis::BoardsInRPC ( Int_t irpc ) const
143 {
145 
146  // FIXME: ugly and hardcoded, but avoid loading the mapping
147 
148  TArrayI boards;
149  if ( irpc == 0 || irpc == 9 ) {
150  Int_t arr[] = {26,27,28,29,48,49,50,51,68,69,84,85,100,101,113};
151  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
152  boards.Set(nBoards,arr);
153  if ( irpc == 9 )
154  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
155  }
156  else if ( irpc == 1 || irpc == 8 ) {
157  Int_t arr[] = {9,10,11,30,31,32,33,52,53,54,55,70,71,86,87,102,103,114};
158  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
159  boards.Set(nBoards,arr);
160  if ( irpc == 8 )
161  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
162  }
163  else if ( irpc == 2 || irpc == 7 ) {
164  Int_t arr[] = {12,13,34,35,56,57,72,73,88,89,104,105,115};
165  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
166  boards.Set(nBoards,arr);
167  if ( irpc == 7 )
168  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
169  }
170  else if ( irpc == 3 || irpc == 6 ) {
171  Int_t arr[] = {14,15,36,37,58,59,74,75,90,91,106,107,116};
172  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
173  boards.Set(nBoards,arr);
174  if ( irpc == 6 )
175  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
176  }
177  else if ( irpc == 4 || irpc == 5 ) {
178  Int_t arr[] = {16,38,60,76,92,108,117};
179  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
180  boards.Set(nBoards,arr);
181  if ( irpc == 5 )
182  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
183  }
184  else if ( irpc == 17 || irpc == 10 ) {
185  Int_t arr[] = {6,7,8,22,23,24,25,44,45,46,47,66,67,82,83,98,99,112};
186  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
187  boards.Set(nBoards,arr);
188  if ( irpc == 10 )
189  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
190  }
191  else if ( irpc == 16 || irpc == 11 ) {
192  Int_t arr[] = {4,5,20,21,42,43,64,65,80,81,96,97,111};
193  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
194  boards.Set(nBoards,arr);
195  if ( irpc == 11 )
196  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
197  }
198  else if ( irpc == 15 || irpc == 12 ) {
199  Int_t arr[] = {2,3,18,19,40,41,62,63,78,79,94,95,110};
200  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
201  boards.Set(nBoards,arr);
202  if ( irpc == 12 )
203  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
204  }
205  else if ( irpc == 14 || irpc == 13 ) {
206  Int_t arr[] = {1,17,39,61,77,93,109};
207  Int_t nBoards = sizeof(arr)/sizeof(arr[0]);
208  boards.Set(nBoards,arr);
209  if ( irpc == 13 )
210  for ( Int_t iboard=0; iboard<nBoards; iboard++ ) boards[iboard] += 117;
211  }
212 
213  return boards;
214 }
215 
216 //________________________________________________________________________
217 void AliMTRChEffAnalysis::CompareEfficiencies ( const char* sources, const char* titles, const char* opt ) const
218 {
220  TString srcs(sources);
221  TObjArray* sourceList = srcs.Tokenize(",");
222  TObjArray effMapList;
223  effMapList.SetOwner();
224 
225  TString trigEffCDBdir = "MUON/Calib/TriggerEfficiency";
226 
227  TIter next(sourceList);
228  TObjString* src = 0x0;
229  while ( (src = static_cast<TObjString*>(next())) ) {
230  TString currSrc = src->String();
231  if ( currSrc.BeginsWith("alien") && ! gGrid ) TGrid::Connect("alien://");
232 
233  AliMUONTriggerEfficiencyCells* effMap = 0x0;
234  if ( currSrc.EndsWith(".root") ) effMap = new AliMUONTriggerEfficiencyCells(currSrc.Data());
235  else {
236  TObjArray* dirRun = currSrc.Tokenize("?");
237  TString cdbPath = dirRun->UncheckedAt(0)->GetName();
238  TString runNum = ( dirRun->GetEntriesFast() > 1 ) ? dirRun->UncheckedAt(1)->GetName() : "";
239  AliCDBManager* mgr = AliCDBManager::Instance();
240  if ( ! mgr->GetDefaultStorage() ) mgr->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
241  mgr->SetSpecificStorage(trigEffCDBdir.Data(),cdbPath.Data());
242  Int_t runNumber = 0;
243  if ( runNum.IsNull() ) {
244  cout << "Please enter run number: " << endl;
245  cin >> runNumber;
246  }
247  else runNumber = runNum.Atoi();
248  mgr->SetRun(runNumber);
249  AliCDBEntry* cdbEntry = mgr->Get(trigEffCDBdir.Data());
250 
251  effMap = static_cast<AliMUONTriggerEfficiencyCells*>(cdbEntry->GetObject());
252  }
253  if ( ! effMap ) continue;
254  effMapList.Add(effMap);
255  }
256 
257  CompareEfficiencies(&effMapList, titles, opt);
258 }
259 
260 //________________________________________________________________________
261 void AliMTRChEffAnalysis::CompareEfficiencies ( TObjArray* effMapList, const char* titles, const char* opt ) const
262 {
264 
265  TString sTitles(titles);
266  TObjArray* titleList = sTitles.Tokenize(",");
267 
268  Int_t nLists = effMapList->GetEntriesFast();
269 
270  Double_t xpt, ypt, xref, yref;
271  enum {kEff, kDiff, kPull};
272  TString sOpt(opt);
273  sOpt.ToLower();
274  Int_t iopt = kEff;
275  TString yTitle = "Eff.";
276  if ( sOpt.Contains("diff") ) {
277  iopt = kDiff;
278  yTitle = "Eff. - (ref.Eff)";
279  }
280  else if ( sOpt.Contains("pull") ) {
281  iopt = kPull;
282  yTitle = "(Eff - (ref.Eff)) / err";
283  }
284 
285  Bool_t needsLegend = ( nLists > 1 );
286 // if ( iopt != kEff ) needsLegend = nLists > 2;
287 
288  Int_t colors[] = {kBlack, kRed, kSpring, kTeal, kBlue, kViolet, kMagenta, kOrange, kGray};
289  Int_t ncolors = sizeof(colors)/sizeof(colors[0]);
290 
291  Int_t hTypes[2] = {AliMUONTriggerEfficiencyCells::kHboardCount,AliMUONTriggerEfficiencyCells::kHslatCount};
292  Int_t countTypes[3] = {AliMUONTriggerEfficiencyCells::kBendingEff,AliMUONTriggerEfficiencyCells::kNonBendingEff,AliMUONTriggerEfficiencyCells::kBothPlanesEff};
293 
294  TString currName = "";
295  Int_t ican = 0;
296  for ( Int_t itype=0; itype<2; itype++ ) {
297  TString xTitle = ( hTypes[itype] == AliMUONTriggerEfficiencyCells::kHslatCount ) ? "RPC" : "Board";
298  for ( Int_t icount=0; icount<3; icount++ ) {
299  TCanvas* can = 0x0;
300  for ( Int_t ich=0; ich<4; ich++ ) {
301  TLegend* leg = 0x0;
302 // Int_t hrefIdx = AliTrigChEffOutput::kNcounts + AliTrigChEffOutput::kNcounts*4*(itype-1) + 4*AliTrigChEffOutput::kAllTracks + ich;
303 // Int_t hIdx = AliTrigChEffOutput::kNcounts + AliTrigChEffOutput::kNcounts*4*(itype-1) + 4*icount + ich;
304  TGraphAsymmErrors* refGraph = 0x0;
305  for ( Int_t ilist=0; ilist<nLists; ilist++ ) {
306  TString currTitle = titleList->At(ilist)->GetName();
307  AliMUONTriggerEfficiencyCells* effMap = static_cast<AliMUONTriggerEfficiencyCells*>(effMapList->UncheckedAt(ilist));
308  currName = effMap->GetHistoName(hTypes[itype],AliMUONTriggerEfficiencyCells::kAllTracks,ich);
309  TH1* histoDen = static_cast<TH1*>(effMap->GetHistoList()->FindObject(currName.Data()));
310  currName = effMap->GetHistoName(hTypes[itype],countTypes[icount],ich);
311  TH1* histoNum = static_cast<TH1*>(effMap->GetHistoList()->FindObject(currName.Data()));
312  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum,histoDen,"e0");
313  currName = histoNum->GetName();
314  currName.ReplaceAll("Count","Eff");
315  currName.Append(Form("_%s",currTitle.Data()));
316  graph->SetName(currName.Data());
317 
318  if ( iopt != kEff ) {
319  if ( refGraph ) {
320  for ( Int_t ipt=0; ipt<graph->GetN(); ipt++ ) {
321  refGraph->GetPoint(ipt,xref,yref);
322  graph->GetPoint(ipt,xpt,ypt);
323  if ( iopt == kDiff ) graph->SetPoint(ipt,xpt,ypt-yref);
324  else if ( iopt == kPull ) {
325  Double_t err = GetError(graph->GetErrorYlow(ipt),graph->GetErrorYhigh(ipt));
326  Double_t pull = ( err > 0. ) ? (ypt-yref)/err : 0.;
327  graph->SetPoint(ipt,xpt,pull);
328  }
329  } // loop on points
330  }
331  else {
332  refGraph = graph;
333  continue;
334  }
335  }
336 
337  if ( ! can ) {
338  currName = graph->GetName();
339  currName.Remove(currName.Length()-currTitle.Length()-5);
340  can = new TCanvas(currName.Data(),currName.Data(),20*ican,20*ican,600,600);
341  can->Divide(2,2);
342  ican++;
343  }
344  if ( needsLegend && ! leg ) {
345  leg = new TLegend(0.35, 0.15, 0.65, 0.45);
346  if ( refGraph ) leg->SetHeader(Form("Ref.: %s",titleList->At(0)->GetName()));
347  }
348  can->cd(ich+1);
349  gPad->SetGridy();
350  Int_t icolor = ( ilist < ncolors ) ? colors[ilist] : 20+ilist;
351  graph->SetLineColor(icolor);
352  graph->SetMarkerColor(icolor);
353  graph->SetMarkerStyle(20+ilist);
354  graph->SetMarkerSize(0.5);
355  graph->GetXaxis()->SetTitle(xTitle.Data());
356  graph->GetYaxis()->SetTitle(yTitle.Data());
357  graph->Draw((gPad->GetListOfPrimitives()->GetEntries()==0)?"ap":"p");
358  if ( leg ) leg->AddEntry(graph,titleList->At(ilist)->GetName(),"lp");
359  } // loop on lists
360  if (leg ) leg->Draw();
361  delete refGraph;
362  } // loop on chambers
363  } // loop on counts
364  } // loop on types
365 
366  delete titleList;
367 }
368 
369 //________________________________________________________________________
371 {
372  if ( ! HasMergedResults() ) return;
373 
374  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
375  TString titles = "";
376 
377  TObjArray effMapList;
378  effMapList.SetOwner();
379 
380  AliTrigChEffOutput* trigOut = 0x0;
381  TIter next(fMergedOutputs);
382  while ( (trigOut = static_cast<AliTrigChEffOutput*>(next())) ) {
383  TList* effList = GetEffHistoList(trigOut, condition);
384  AliMUONTriggerEfficiencyCells* effMap = new AliMUONTriggerEfficiencyCells(effList);
385  effMapList.Add(effMap);
386  titles += Form("%s,",trigOut->GetName());
387  }
388  titles.Remove(TString::kTrailing,',');
389 
390  CompareEfficiencies(&effMapList, titles.Data(), opt);
391 }
392 
393 
394 //________________________________________________________________________
395 //TArrayI AliMTRChEffAnalysis::CheckHomogeneity ( const TGraphAsymmErrors* trendGraph, Double_t nSigmas, Bool_t revert ) const
396 //{
397 // /// Check efficiency homogeneity
398 // TArrayI ranges(trendGraph->GetN());
399 // Double_t xpt=0., ypt=0.;
400 //
401 // Double_t sumEffOverSigma2 = -10.;
402 // Double_t sumInvSimga2 = 0.001;
403 // Int_t irange = 0;
404 // Int_t npt = trendGraph->GetN();
405 // for ( Int_t ipt=0; ipt<npt; ipt++ ) {
406 // Int_t currPt = ( revert ) ? npt-1-ipt : ipt;
407 // trendGraph->GetPoint(currPt,xpt,ypt);
408 // Double_t err = GetError(trendGraph->GetErrorYlow(currPt),trendGraph->GetErrorYhigh(currPt));
409 // Double_t invSigma2 = 1./(err*err);
410 // Double_t effOverSigma2 = ypt*invSigma2;
411 //
412 // Double_t meanEff = sumEffOverSigma2 / sumInvSimga2;
413 // Double_t diff = ypt - meanEff;
414 // Double_t diffErr = TMath::Sqrt(err*err+1./sumInvSimga2);
416 // if ( TMath::Abs(diff)/diffErr > nSigmas ) {
417 // TString run = trendGraph->GetXaxis()->GetBinLabel(currPt+1);
418 // ranges[irange++] = run.Atoi();
419 // sumEffOverSigma2 = 0.;
420 // sumInvSimga2 = 0.;
421 // }
422 // sumEffOverSigma2 += effOverSigma2;
423 // sumInvSimga2 += invSigma2;
424 // }
425 // TString run = trendGraph->GetXaxis()->GetBinLabel(trendGraph->GetN());
426 // ranges[irange++] = run.Atoi();
427 // ranges.Set(irange);
428 // return ranges;
429 //}
430 
431 //________________________________________________________________________
432 void AliMTRChEffAnalysis::CopyDir(TDirectory *source) const
433 {
435  TDirectory *savdir = gDirectory;
436  TDirectory *adir = savdir->mkdir(source->GetName());
437  adir->cd();
438  //loop on all entries of this directory
439  TKey *key;
440  TIter nextkey(source->GetListOfKeys());
441  while ((key = (TKey*)nextkey())) {
442  const char *classname = key->GetClassName();
443  TClass *cl = gROOT->GetClass(classname);
444  if (!cl) continue;
445  if (cl->InheritsFrom(TDirectory::Class())) {
446  source->cd(key->GetName());
447  TDirectory *subdir = gDirectory;
448  adir->cd();
449  CopyDir(subdir);
450  adir->cd();
451  } else if (cl->InheritsFrom(TTree::Class())) {
452  TTree *T = (TTree*)source->Get(key->GetName());
453  adir->cd();
454  TTree *newT = T->CloneTree(-1,"fast");
455  newT->Write();
456  } else {
457  source->cd();
458  TObject *obj = key->ReadObj();
459  adir->cd();
460  obj->Write(obj->GetName(),TObject::kSingleKey);
461  delete obj;
462  }
463  }
464  adir->SaveSelf(kTRUE);
465  savdir->cd();
466 }
467 
468 
469 //________________________________________________________________________
470 Bool_t AliMTRChEffAnalysis::CopyLocally ( const char* runList, const char* path, const char* pattern, const char* localFileList, const char* outDir, const char* directory ) const
471 {
473  TString sPattern(pattern);
474  TString sOutDir(outDir);
475  TString sPath(path);
476  Bool_t isGrid = (! sPattern.IsNull());
477 
478  if ( sOutDir.IsNull() ) {
479  if ( isGrid ) {
480  TString data = sPath(TRegexp("/data/"));
481  TString year = sPath(TRegexp("/20[0-9][0-9]/"));
482  TString period = sPath(TRegexp("/LHC[0-9][0-9][a-z]"));
483  period.Append("/");
484  // TPRegexp re("/(muon|pass).*?/");
485  TString pass = AliAnalysisMuonUtility::GetPassName(path);
486  if ( pass.IsNull() ) pass = AliAnalysisMuonUtility::GetPassName(pattern);
487  sOutDir = data+year+period+pass;
488  sOutDir.ReplaceAll("//","/");
489  sOutDir.Remove(TString::kTrailing,'/');
490  sOutDir.Remove(TString::kLeading,'/');
491  }
492  else sOutDir = sPath;
493  sOutDir.Remove(TString::kTrailing,'/');
494  sOutDir.Remove(TString::kLeading,'/');
495  }
496 
497  TGridResult* res = 0x0;
498  if ( isGrid ) {
499  if ( ! gGrid ) TGrid::Connect("alien://");
500  res = gGrid->Query(path,pattern);
501  }
502 
503  TList* rl = GetRunList(runList);
504 
505  ofstream outFile(localFileList);
506  Bool_t allOk = kTRUE;
507  Bool_t prompt = kTRUE;
508  Bool_t overwrite = kFALSE;
509  for ( Int_t irun=0; irun<rl->GetEntries(); irun++ ) {
510  TString run = static_cast<TObjString*>(rl->At(irun))->String();
511  TString dest = Form("%s/%09i/QAresults.root",sOutDir.Data(),run.Atoi());
512  TString destDir = gSystem->DirName(dest.Data());
513  if ( gSystem->AccessPathName(destDir.Data()) ) ExecCommand(Form("mkdir -p %s",destDir.Data()),kFALSE);
514  Bool_t copyFile = kTRUE;
515  Bool_t isFileOk = kTRUE;
516  if ( gSystem->AccessPathName(dest) == 0 ) {
517  if ( prompt ) {
518  TString decision = "";
519  cout << "Local file " << dest.Data() << " already exist: overwrite? [y/n/ya/na (a=use decision for all)]" << endl;
520  cin >> decision;
521  if ( decision.EndsWith("a") ) prompt = kFALSE;
522  if ( decision.BeginsWith("y") ) overwrite = kTRUE;
523  else overwrite = kFALSE;
524  }
525  copyFile = overwrite;
526  }
527  if ( copyFile ) {
528  TString src = "";
529  if ( isGrid ) {
530  for ( Int_t ifile=0; ifile<res->GetEntries(); ifile++ ) {
531  TString inFilename = res->GetKey(ifile,"turl");
532  if ( inFilename.Contains(run.Data()) ) {
533  src = inFilename;
534  break;
535  }
536  }
537  if ( src.IsNull() ) {
538  AliWarning(Form("Cannot find output for run %s",run.Data()));
539  isFileOk = kFALSE;
540  }
541  else {
542  TFile* outFile = TFile::Open(dest,"RECREATE");
543  TFile* inFile = TFile::Open(src);
544  inFile->cd();
545  TDirectory* dir = static_cast<TDirectory*>(inFile->Get(directory));
546  if ( dir ) {
547  outFile->cd();
548  CopyDir(dir);
549  }
550  else isFileOk = kFALSE;
551  delete inFile;
552  delete outFile;
553  }
554  }
555  else {
556  src = Form("http://aliqamu.web.cern.ch/aliqamu/%s",dest.Data());
557  isFileOk = TFile::Cp(src.Data(),dest.Data());
558  }
559  }
560 
561  if ( isFileOk ) outFile << gSystem->pwd() << "/" << dest.Data() << endl;
562  else allOk = kFALSE;
563  }
564  delete rl;
565  outFile.close();
566  return allOk;
567 }
568 
569 //________________________________________________________________________
570 void AliMTRChEffAnalysis::DrawEffTrend ( Int_t itype, Int_t irpc, Double_t maxNsigmaOutliers, Double_t minEff, Double_t maxEff ) const
571 {
573  TString baseNames[3] = {"Chamber","RPC","Board"};
574  TString base = baseNames[itype] + "Eff";
575  if ( itype == AliTrigChEffOutput::kHboardEff ) {
576  if ( irpc < 0 ) {
577  AliWarning("Please specify RPC");
578  return;
579  }
580  base += Form("InRPC%i",irpc);
581  }
582 
583  Int_t nColumns = 2;
584  Int_t nRows = 2;
585  Int_t width = 600;
586  Int_t height = 600;
587  Int_t nDetEl = 4;
588  Int_t nCh = 1;
589  if ( itype != AliTrigChEffOutput::kHchamberEff ) {
590  nColumns = 6;
591  nRows = 3;
592  width = 1200;
593  height = 800;
594  nDetEl = 18;
595  nCh = 4;
596  }
597  TArrayI boards = BoardsInRPC(irpc);
598  if ( itype == AliTrigChEffOutput::kHboardEff ) nDetEl = boards.GetSize();
599 
600  for ( Int_t ich=0; ich<nCh; ich++ ) {
601  TString canName = base;
602  if ( itype != AliTrigChEffOutput::kHchamberEff ) canName += Form("Ch%i",11+ich);
603  TCanvas* can = new TCanvas(canName.Data(),canName.Data(),25*ich,25*ich,width,height);
604  can->Divide(nColumns,nRows,0,0);
605 // can->SetTopMargin(0.03);
606 // can->SetBottomMargin(0.1);
607  for ( Int_t idetelem=0; idetelem<nDetEl; idetelem++ ) {
608  can->cd(idetelem+1);
609  gPad->SetTicks(1,1);
610  Int_t detElemId = idetelem;
611  if ( itype == AliTrigChEffOutput::kHchamberEff ) detElemId = 11+idetelem;
612  else if ( itype == AliTrigChEffOutput::kHboardEff ) detElemId = boards[idetelem];
613 
614  TString title = Form("%s %i",baseNames[itype].Data(),detElemId);
615  TLegend* leg = new TLegend(0.2,0.15,0.8,0.4);
616  leg->SetHeader(title.Data());
617  for ( Int_t icount=0; icount<2; icount++ ) {
618  TGraphAsymmErrors* gr = GetTrendEff(itype, icount, ich, detElemId);
619  gr->SetLineColor(icount+1);
620  gr->SetMarkerColor(icount+1);
621  gr->SetMarkerStyle(24+2*icount);
622  gr->GetYaxis()->SetRangeUser(minEff,maxEff);
623 // gr->GetYaxis()->SetLabelSize(0.025*nRows);
624 // gr->GetXaxis()->SetLabelSize(0.025*nColumns);
625  gr->SetTitle("");
626  gr->Draw(icount==0?"ap":"p");
627  TString legTitle = ( icount==0 ) ? "bending plane" : "non-bending plane";
628  leg->AddEntry(gr,legTitle.Data(),"lp");
629  if ( maxNsigmaOutliers > 0. ) {
630  TGraphAsymmErrors* outliers = GetOutliers(gr,maxNsigmaOutliers);
631  outliers->SetLineColor(6+icount);
632  outliers->SetMarkerColor(6+icount);
633  outliers->SetMarkerStyle(20+2*icount);
634  outliers->SetLineWidth(2);
635  outliers->Draw("p");
636  legTitle.ReplaceAll("plane","outliers");
637  leg->AddEntry(outliers,legTitle.Data(),"lp");
638  }
639  }
640  leg->Draw();
641  }
642  if ( itype == AliTrigChEffOutput::kHchamberEff ) break;
643  }
644 }
645 
646 //________________________________________________________________________
647 Bool_t AliMTRChEffAnalysis::DrawSystematicEnvelope ( Bool_t perRPC, Double_t miny, Double_t maxy ) const
648 {
650  if ( ! HasMergedResults() ) return kFALSE;
651 
653 
654  Int_t colors[] = {kBlack, kRed, kSpring, kTeal, kBlue, kViolet, kMagenta, kOrange, kGray};
655  Int_t ncolors = sizeof(colors)/sizeof(colors[0]);
656 
657  Int_t nConditions = fConditions->GetEntriesFast();
658 
659 
660  TObjArray* refCondition = 0x0;
661  TObjArray condTitle(nConditions);
662  condTitle.SetOwner();
663 
664  Double_t xpt, ypt, xref, yref;
665  TArrayD eff(4), effErr(4);
666 
667  AliTrigChEffOutput* trigOut = 0x0;
668  TIter next(fMergedOutputs);
669  Int_t imerged = -1;
670  while ( (trigOut = static_cast<AliTrigChEffOutput*>(next())) ) {
671  imerged++;
672 
673  // Get meaningful short titles for each systematic
674  if ( imerged == 0 ) {
675  for ( Int_t icond=0; icond<nConditions; icond++ ) {
676  TObjArray* condition = static_cast<TObjArray*>(fConditions->UncheckedAt(icond));
677  if ( icond == 0 ) refCondition = condition;
678  TString title = "";
679  for ( Int_t ic=0; ic<condition->GetEntriesFast(); ic++ ) {
680  TString currCond = static_cast<TObjString*>(condition->UncheckedAt(ic))->String();
681  TString refCond = static_cast<TObjString*>(refCondition->UncheckedAt(ic))->String();
682  if ( currCond == refCond ) continue;
683  TString add = currCond;
684  if ( ic == 3 ) add = trigOut->GetHistoName(-1,-1,-1,currCond.Atoi(),-1,-1);
685  else if ( ic == 4 ) add = trigOut->GetHistoName(-1,-1,-1,-1,currCond.Atoi(),-1);
686  else if ( ic == 5 ) add = trigOut->GetHistoName(-1,-1,-1,-1,-1,currCond.Atoi());
687  title += Form("_%s",add.Data());
688  }
689  title.Remove(TString::kLeading,'_');
690  condTitle.AddAt(new TObjString(title),icond);
691  }
692  }
693 
694  // First get the needed graphs
695  Int_t nDE = 0;
696  TObjArray effGraphs[8];
697  for ( Int_t iplane=0; iplane<8; iplane++ ) {
698  effGraphs[iplane].SetOwner();
699  }
700  for ( Int_t icond=0; icond<nConditions; icond++ ) {
701  TObjArray* condition = static_cast<TObjArray*>(fConditions->UncheckedAt(icond));
702  for ( Int_t icount=0; icount<2; icount++ ) {
703  for ( Int_t ich=0; ich<4; ich++ ) {
704  Int_t iplane = 4*icount+ich;
705  TH1* histoNum = GetSum(trigOut,condition,itype,icount,ich);
706  TH1* histoDen = GetSum(trigOut,condition,itype,AliTrigChEffOutput::kAllTracks,ich);
707  TGraphAsymmErrors* gr = new TGraphAsymmErrors(histoNum,histoDen,"e0");
708  nDE = gr->GetN();
709  effGraphs[iplane].Add(gr);
710  delete histoNum;
711  delete histoDen;
712  }
713  }
714  }
715 
716  // Draw average dispersion per plane
717  TString canName = Form("EffSyst_%s",trigOut->GetName());
718  Int_t pos = 25*(imerged+1);
719  TCanvas* can = new TCanvas(canName.Data(),canName.Data(),pos,pos,1200,800);
720  can->Divide(4,2,0,0);
721 
722  TObjArray* refCond = static_cast<TObjArray*>(fConditions->UncheckedAt(0));
723  for ( Int_t icount=0; icount<2; icount++ ) {
724  for ( Int_t ich=0; ich<4; ich++ ) {
725  Int_t iplane = 4*icount+ich;
726  can->cd(iplane+1);
727  gPad->SetTicks(1,1);
728  gPad->SetLogy();
729  TLegend* leg = new TLegend(0.15,0.7,0.9,0.9);
730  leg->SetHeader(trigOut->GetHistoName(-1,icount,ich,-1,-1,-1));
731  TH1* sumHisto = 0x0;
732  for ( Int_t icond=1; icond<nConditions; icond++ ) {
733  TH1* histo = new TH1D(Form("syst_%s_%s_plane%i_ch%i",trigOut->GetName(),condTitle[icond]->GetName(),icount,11+ich),"",200,-0.1,0.1);
734  histo->GetXaxis()->SetTitle("Eff.-(ref.Eff.)");
735 // histo->GetXaxis()->SetTitle("1/#sigma^{2}");
736 
737  TGraphAsymmErrors* gr = static_cast<TGraphAsymmErrors*>(effGraphs[iplane].UncheckedAt(icond));
738  TGraphAsymmErrors* grRef = static_cast<TGraphAsymmErrors*>(effGraphs[iplane].UncheckedAt(0));
739  for ( Int_t ipt=0; ipt<gr->GetN(); ipt++ ) {
740  gr->GetPoint(ipt,xpt,ypt);
741  Double_t err = GetError(gr->GetErrorYlow(ipt),gr->GetErrorYhigh(ipt));
742  Double_t invErr2 = ( err > 0. ) ? 1./(err*err) : 0.;
743  grRef->GetPoint(ipt,xref,yref);
744 
745  Double_t diff = ypt-yref;
746  histo->Fill(diff,invErr2);
747  }
748 
749  if ( ! sumHisto ) {
750  sumHisto = static_cast<TH1*>(histo->Clone(Form("syst_%s_plane%i_ch%i",trigOut->GetName(),icount,11+ich)));
751  sumHisto->SetLineColor(1);
752  sumHisto->Draw();
753  leg->AddEntry(sumHisto,"All systematics","l");
754  }
755  else sumHisto->Add(histo);
756  Int_t icolor = ( icond < ncolors ) ? colors[icond] : 20+icond;
757  histo->SetLineColor(icolor);
758  histo->Draw("same");
759  leg->AddEntry(histo,condTitle[icond]->GetName(),"l");
760  } // loop on conditions
761  leg->Draw();
762  } // loop on chambers
763  } // loop on counts
764 
765 
766  canName = Form("TriggerEff_3outOf4_syst_%s",trigOut->GetName());
767  pos += 50;
768  TCanvas* canSyst = new TCanvas(canName.Data(),canName.Data(),pos,pos,600,600);
769  canSyst->SetLogy();
770  TLegend* leg = new TLegend(0.15,0.7,0.9,0.4);
771 // leg->SetHeader(trigOut->GetHistoName(-1,icount,ich,-1,-1,-1));
772  TH1* sumHisto = 0x0;
773  TH1* histo[nConditions];
774  for ( Int_t icond=0; icond<nConditions; icond++ ) {
775  histo[icond] = new TH1D(Form("TriggerEff_syst_%s_%s",condTitle[icond]->GetName(),trigOut->GetName()),"Dispersion of trigger probability (3/4)",200,-0.1,0.1);
776  histo[icond]->GetXaxis()->SetTitle("Trig. prob. - (ref. trig. prob)");
777  }
778 
779  for ( Int_t ipt=0; ipt<nDE; ipt++ ) {
780  Double_t refTrigProb = 0.; // refTrigProbErr = 0.;
781  for ( Int_t icond=0; icond<nConditions; icond++ ) {
782  Double_t trigProb = 1., trigProbErr2 = 0.;
783  for ( Int_t icount=0; icount<2; icount++ ) {
784  for ( Int_t ich=0; ich<4; ich++ ) {
785  Int_t iplane = 4*icount+ich;
786  TGraphAsymmErrors* gr = static_cast<TGraphAsymmErrors*>(effGraphs[iplane].UncheckedAt(icond));
787  gr->GetPoint(ipt,xpt,ypt);
788  eff[ich] = ypt;
789  effErr[ich] = GetError(gr->GetErrorYlow(ipt),gr->GetErrorYhigh(ipt));
790  } // loop on chambers
791  Double_t effErr34 = 0.;
792  Double_t eff34 = GetThreeOfFour(eff,effErr,effErr34);
793  trigProb *= eff34;
794  trigProbErr2 += effErr34*effErr34;
795  } // loop on counts
796 
797  if ( icond == 0 ) {
798  refTrigProb = trigProb;
799 // refTrigProbErr = trigProbErr;
800  }
801  else {
802  Double_t invErr2 = ( trigProbErr2>0. ) ? 1./trigProbErr2 : 0.;
803  histo[icond]->Fill(trigProb-refTrigProb,invErr2);
804  }
805  } // loop on conditions
806  } // loop on points
807 
808  for ( Int_t icond=0; icond<nConditions; icond++ ) {
809  TString title = ( icond == 0 ) ? "All systematics" : condTitle[icond]->GetName();
810  Int_t icolor = ( icond < ncolors ) ? colors[icond] : 20+icond;
811  histo[icond]->SetLineColor(icolor);
812  histo[icond]->Draw((icond == 0)?"":"same");
813  leg->AddEntry(histo[icond],title.Data(),"l");
814  if ( icond>0 ) histo[0]->Add(histo[icond]);
815  }
816  leg->Draw();
817  } // loop on merged output
818  return kTRUE;
819 }
820 
821 //________________________________________________________________________
822 Bool_t AliMTRChEffAnalysis::ExecCommand ( TString command, Bool_t prompt ) const
823 {
825  TString decision = "y";
826 
827  if ( gROOT->IsBatch() ) prompt = kFALSE; // To run with crontab
828 
829  if ( prompt ) {
830  cout << command.Data() << " ? [y/n]" << endl;
831  cin >> decision;
832  }
833 
834  decision.ToLower();
835  if ( decision == "y" ) {
836  cout << "Executing: " << command.Data() << endl;
837  gSystem->Exec(command.Data());
838  return kTRUE;
839  }
840 
841  return kFALSE;
842 }
843 
844 //________________________________________________________________________
845 Double_t AliMTRChEffAnalysis::FitRangesFunc ( Double_t* x, Double_t* par )
846 {
853 
854  Double_t xx = x[0];
855  Double_t val = par[1];
856  Int_t nChanges = par[0];
857  for ( Int_t iknot=0; iknot<nChanges; iknot++ ) {
858  if ( xx > par[2*(iknot+1)] ) val = par[2*(iknot+1)+1];
859  }
860  return val;
861 }
862 
863 //________________________________________________________________________
864 Double_t AliMTRChEffAnalysis::GetAverageStat ( Int_t firstRun, Int_t lastRun, Int_t itype,Bool_t excludePeriphericBoard ) const
865 {
866  TH1* statHisto = 0x0;
867  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
868 
869  TIter next(fOutputs);
870  TList* effHistoList = 0x0;
871  while ( (effHistoList = static_cast<TList*>(next()) ) ) {
872  UInt_t run = effHistoList->GetUniqueID();
873  if ( run < firstRun || run > lastRun ) continue;
874  TH1* histo = GetHisto(effHistoList,itype,AliTrigChEffOutput::kAllTracks,0);
875 // if ( ! histo ) continue;
876  if ( statHisto ) statHisto->Add(histo);
877  else statHisto = static_cast<TH1*>(histo->Clone("tmpStatHisto"));
878 // delete histo;
879  }
880  if ( ! statHisto ) return 0.;
881 
882  Double_t statPerDE = 0.;
883  Double_t nDe = 0.;
884  if ( itype == AliTrigChEffOutput::kHboardEff && excludePeriphericBoard ) {
885  Int_t excludeBoardsHalf[] = {1, 17, 39, 61, 77, 93,109,
886  16, 38, 60, 76, 92, 108, 117,
887  110, 111, 112, 113, 114, 115, 116};
888  Int_t nExcludedHalf = sizeof(excludeBoardsHalf)/sizeof(excludeBoardsHalf[0]);
889  for ( Int_t ibin=1; ibin<=statHisto->GetNbinsX(); ibin++ ) {
890  Bool_t skip = kFALSE;
891  for ( Int_t iexcl=0; iexcl<nExcludedHalf; iexcl++ ) {
892  if ( ibin == excludeBoardsHalf[iexcl] || ibin == excludeBoardsHalf[iexcl]+117 ) {
893  skip = kTRUE;
894  break;
895  }
896  }
897  if ( skip ) continue;
898  statPerDE += statHisto->GetBinContent(ibin);
899  nDe += 1.;
900  }
901  }
902  else {
903  statPerDE = statHisto->Integral();
904  nDe = (Double_t)statHisto->GetNbinsX();
905  }
906  statPerDE = nDe > 0. ? statPerDE/nDe : -1.;
907 
908  delete statHisto;
909  return statPerDE;
910 }
911 
912 //________________________________________________________________________
913 TList* AliMTRChEffAnalysis::GetEffHistoList ( AliTrigChEffOutput* trigOut, TObjArray* condition ) const
914 {
916  Int_t itrackSel = static_cast<TObjString*>(condition->At(3))->String().Atoi();
917  Int_t imatch = static_cast<TObjString*>(condition->At(4))->String().Atoi();
918  Int_t imethod = static_cast<TObjString*>(condition->At(5))->String().Atoi();
919 
920  return trigOut->GetEffHistoList(condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName(),itrackSel,imatch,imethod);
921 }
922 
923 //________________________________________________________________________
924 Double_t AliMTRChEffAnalysis::GetError ( Double_t errLow, Double_t errHigh ) const
925 {
927  return TMath::Max(errLow,errHigh);
928 }
929 
930 //________________________________________________________________________
931 TH1* AliMTRChEffAnalysis::GetHisto ( TList* effHistoList, Int_t itype, Int_t icount, Int_t ichamber ) const
932 {
934  Int_t ihisto = ( itype == AliTrigChEffOutput::kHchamberEff ) ? itype : AliTrigChEffOutput::kNcounts + 4*AliTrigChEffOutput::kNcounts*(itype-1) + 4*icount + ichamber;
935  return static_cast<TH1*>(effHistoList->At(ihisto));
936 }
937 
938 //________________________________________________________________________
939 TArrayI AliMTRChEffAnalysis::GetHomogeneusRanges ( Double_t chi2Cut, Int_t maxNRanges, Double_t minEffVariation, TArrayI* forcedChanges, Double_t minEff, Double_t maxEff )
940 {
942 
943  Int_t nRuns = fOutputs->GetEntriesFast();
944 
945  TH1F* hRunChangeCount = new TH1F("runChangeCount","Number of RPCs changing efficiency per run",nRuns,-0.5,-0.5+(Double_t)nRuns);
946  hRunChangeCount->SetXTitle("Run num.");
947  hRunChangeCount->SetYTitle("Num. of RPCs with change in eff.");
948  for ( Int_t irun=0; irun<nRuns; irun++ ) {
949  hRunChangeCount->GetXaxis()->SetBinLabel(irun+1,Form("%i",GetRunNumber(irun)));
950  }
951 
952  for ( Int_t ich=0; ich<4; ich++ ) {
953  TString canName = Form("testRanges_ch%i",11+ich);
954  TCanvas* can = new TCanvas(canName.Data(),canName.Data(),10*ich,10*ich,1200,800);
955  can->Divide(6,3,0,0);
956  for ( Int_t irpc=0; irpc<18; irpc++ ) {
957  Int_t icount = AliTrigChEffOutput::kBothPlanesEff;
958  can->cd(irpc+1);
959  gPad->SetTicks(1,1);
960 // for ( Int_t icount=0; icount<2; icount++ ) {
961  TGraphAsymmErrors* trendGraph = GetTrendEff(AliTrigChEffOutput::kHslatEff,icount,ich,irpc);
962  TArrayI range = GetHomogeneusRanges(trendGraph,chi2Cut,maxNRanges,minEffVariation,forcedChanges, kTRUE);
963  trendGraph->GetYaxis()->SetRangeUser(minEff,maxEff);
964  trendGraph->Draw("ap");
965  for ( Int_t ichange=0; ichange<range.GetSize(); ichange++ ) {
966  // Store only the run when the change applies
967  if ( ichange%2 == 1 ) continue;
968  Int_t runIdx = range[ichange];
969  if ( ichange != 0 ) {
970  TLine* line = new TLine(runIdx,minEff,runIdx,maxEff);
971  line->SetLineStyle(2);
972  line->Draw("same");
973  TLatex text;
974  text.DrawLatex((Double_t)(runIdx-3),maxEff-0.1*(maxEff-minEff)*(Double_t)(ichange/2),Form("%i",GetRunNumber(runIdx)));
975  }
976  hRunChangeCount->Fill(runIdx);
977  if ( hRunChangeCount->GetBinContent(runIdx+1) == 1 ) {
978  AliInfo(Form("Efficiency change in %i triggered by ch %i RPC %i",GetRunNumber(runIdx),11+ich,irpc));
979  }
980  }
981 // }
982  }
983  }
984 
985  // Clusterize contiguous runs
986  TArrayI runChangeClust(nRuns);
987  Double_t sumWgtRun = 0.;
988  Double_t sumWgt = 0;
989  for ( Int_t irun=0; irun<=nRuns; irun++ ) {
990  if ( irun == nRuns || hRunChangeCount->GetBinContent(irun+1) == 0 ) {
991  if ( sumWgt > 0. ) {
992  Int_t averageRun = TMath::Nint(sumWgtRun / sumWgt);
993  AliDebug(2,Form("Average run: %i => %i\n",averageRun,GetRunNumber(averageRun)));
994  runChangeClust[averageRun]++;
995  sumWgtRun = 0.;
996  sumWgt = 0.;
997  }
998  }
999  if ( irun == nRuns ) break;
1000 
1001  AliDebug(2,Form("irun %i => %i: wgt %g",irun,GetRunNumber(irun),hRunChangeCount->GetBinContent(irun+1)));
1002 
1003 // Double_t wgt = (Double_t)runChangeCount[irun];
1004  Double_t wgt = hRunChangeCount->GetBinContent(irun+1);
1005  if ( forcedChanges ) {
1006  for ( Int_t ichange=0; ichange<forcedChanges->GetSize(); ichange++ ) {
1007  if ( GetRunNumber(irun) == forcedChanges->At(ichange) ) wgt *= 10.;
1008  }
1009  }
1010  sumWgtRun += wgt*(Double_t)irun;
1011  sumWgt += wgt;
1012  }
1013 
1014  TCanvas* summaryCan = new TCanvas("effChangeSummary","effChangeSummary",50,50,600,600);
1015  summaryCan->SetLogy();
1016  hRunChangeCount->GetXaxis()->LabelsOption("v");
1017  hRunChangeCount->Draw();
1018 
1019  Int_t ientry = 0;
1020  TArrayI runRanges(nRuns);
1021  for ( Int_t irun=0; irun<nRuns; irun++ ) {
1022  if ( runChangeClust[irun] > 0 ) {
1023  if ( irun > 0 ) runRanges[ientry++] = GetRunNumber(irun-1);
1024  runRanges[ientry++] = GetRunNumber(irun);
1025  }
1026  }
1027  runRanges[ientry++] = GetRunNumber(nRuns-1);
1028  runRanges.Set(ientry);
1029  return runRanges;
1030 }
1031 
1032 //________________________________________________________________________
1033 TArrayI AliMTRChEffAnalysis::GetHomogeneusRanges ( TGraphAsymmErrors* trendGraph, Double_t chi2Cut, Int_t maxNRanges, Double_t minEffVariation, TArrayI* forcedChanges, Bool_t returnIndex )
1034 {
1036 
1037  TArrayI runRanges;
1038  TF1* func = 0x0;
1039 // TString canName = "fitTestCan";
1040  TArrayD forcedChangesBin;
1041  Int_t nForced = 0;
1042  if ( forcedChanges ) {
1043  forcedChangesBin.Set(forcedChanges->GetSize());
1044  for ( Int_t ichange=0; ichange<forcedChanges->GetSize(); ichange++ ) {
1045  Int_t idx = GetIndexFromRun(forcedChanges->At(ichange));
1046  if ( idx >= 0 ) forcedChangesBin[nForced++] = (Double_t)idx;
1047  else AliWarning(Form("Cannot find run %i\n",forcedChanges->At(ichange)));
1048  }
1049  }
1050 
1051  for ( Int_t istep=0; istep<maxNRanges; istep++ ) {
1052  Int_t nPars = 2*(istep+1);
1053  Double_t xMin = trendGraph->GetXaxis()->GetXmin();
1054  Double_t xMax = trendGraph->GetXaxis()->GetXmax();
1055  func = new TF1("rangeFunc",this,&AliMTRChEffAnalysis::FitRangesFunc,xMin,xMax,nPars,"AliMTRChEffAnalysis","FitRanges");
1056  func->FixParameter(0,istep);
1057  for ( Int_t ipar=1; ipar<nPars; ipar++ ) {
1058  Double_t val = ( ipar%2 == 1 ) ? 0.95 : (xMax-xMin) * (Double_t)(ipar/2)/((Double_t)(istep+1));
1059  func->SetParameter(ipar,val);
1060  if ( forcedChanges ) {
1061  Int_t currChange = ipar/2 - 1;
1062  if ( ipar%2==0 && currChange < nForced ) func->FixParameter(ipar,forcedChangesBin[currChange]);
1063  }
1064  }
1065 // trendGraph->Draw("ap");
1066  trendGraph->Fit(func,"NQ0");
1067 // func->DrawCopy("same");
1068  Double_t normChi2 = func->GetChisquare() / ((Double_t)func->GetNDF());
1069 // printf("normChi2 %g\n",normChi2);
1070  if ( normChi2 < chi2Cut ) break;
1071  delete func;
1072  func = 0x0;
1073  }
1074 
1075  if ( func ) {
1076  trendGraph->GetListOfFunctions()->Add(func->Clone());
1077  Int_t nSteps = func->GetParameter(0);
1078  runRanges.Set(2*(nSteps+1));
1079  Int_t irun = 0;
1080  runRanges[irun++] = returnIndex ? 0 : GetRunNumber(0);
1081  for ( Int_t istep=0; istep<nSteps; istep++ ) {
1082  Int_t ipar = 2*(istep+1);
1083  Double_t deltaEff = TMath::Abs(func->GetParameter(ipar-1)-func->GetParameter(ipar+1));
1084  if ( deltaEff < minEffVariation ) {
1085  AliWarning(Form("Efficiency variation for %s is %g => consider uniform",trendGraph->GetName(),deltaEff));
1086  continue;
1087  }
1088  Int_t runChangeIdx = TMath::Nint(func->GetParameter(ipar));
1089  AliDebug(1,Form("Change run: %s => %g => %i %i",trendGraph->GetName(),func->GetParameter(ipar),runChangeIdx,GetRunNumber(runChangeIdx)));
1090  runRanges[irun++] = returnIndex ? runChangeIdx-1 : GetRunNumber(runChangeIdx-1);
1091  runRanges[irun++] = returnIndex ? runChangeIdx : GetRunNumber(runChangeIdx);
1092  }
1093  Int_t lastPt = trendGraph->GetN()-1;
1094  runRanges[irun++] = returnIndex ? lastPt : GetRunNumber(trendGraph->GetN()-1);
1095  runRanges.Set(irun);
1096 // for ( Int_t irange=0; irange<runRanges.GetSize()/2; irange++ ) {
1097 // printf("%i - %i\n",runRanges[2*irange],runRanges[2*irange+1]);
1098 // }
1099  }
1100  return runRanges;
1101 }
1102 
1103 //________________________________________________________________________
1104 TString AliMTRChEffAnalysis::GetIdentifier ( AliTrigChEffOutput* trigOut, TObjArray* condition, Int_t itype, Int_t icount, Int_t ichamber ) const
1105 {
1107 // AliTrigChEffOutput* trigOut = static_cast<AliTrigChEffOutput*>(fOutputs->At(0));
1108 // if ( ! trigOut ) {
1109 // AliWarning("No output object found!");
1110 // delete arr;
1111 // return "";
1112 // }
1113  TString identifier = Form("/%s/%s/%s/",condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName());
1114  Int_t itrackSel = static_cast<TObjString*>(condition->At(3))->String().Atoi();
1115  Int_t imatch = static_cast<TObjString*>(condition->At(4))->String().Atoi();
1116  Int_t imethod = static_cast<TObjString*>(condition->At(5))->String().Atoi();
1117  TString objName = trigOut->GetHistoName(itype, icount, ichamber, itrackSel, imatch, imethod);
1118  identifier += objName;
1119  return identifier;
1120 }
1121 
1122 //________________________________________________________________________
1123 Int_t AliMTRChEffAnalysis::GetIndexFromRun ( UInt_t runNumber ) const
1124 {
1126  for ( Int_t ipt=0; ipt<fOutputs->GetEntriesFast(); ipt++ ) {
1127  UInt_t run = fOutputs->UncheckedAt(ipt)->GetUniqueID();
1128  if ( run == runNumber ) return ipt;
1129  }
1130  return -1;
1131 }
1132 
1133 //________________________________________________________________________
1134 TGraphAsymmErrors* AliMTRChEffAnalysis::GetOutliers ( TGraphAsymmErrors* graph, Double_t maxNsigmas ) const
1135 {
1137 // TGraphAsymmErrors* outliers = new TGraphAsymmErrors();
1138  TGraphAsymmErrors* outliers = new TGraphAsymmErrors(*graph);
1139  outliers->SetHistogram(static_cast<TH1F*>(graph->GetHistogram()->Clone(Form("%s_outliers",graph->GetHistogram()->GetName()))));
1140 // outliers->SetLineColor(graph->GetLineColor()+1);
1141  if ( graph->GetListOfFunctions()->GetEntries() == 0 ) graph->Fit("pol0","Q0");
1142  TF1* func = static_cast<TF1*>(graph->GetListOfFunctions()->At(0));
1143 
1144  Double_t xpt, ypt;
1145  Int_t nremoved = 0;
1146  for ( Int_t ipt=0; ipt<graph->GetN(); ipt++ ) {
1147  graph->GetPoint(ipt,xpt,ypt);
1148  Double_t diff = ypt - func->Eval(xpt);
1149  Double_t err = ( diff > 0 ) ? graph->GetErrorYlow(ipt) : graph->GetErrorYhigh(ipt);
1150  if ( err < 0. || diff/err > maxNsigmas ) continue;
1151  outliers->RemovePoint(ipt-nremoved);
1152  nremoved++;
1153 // outliers->SetPoint(iopt,xpt,ypt);
1154  }
1155  return outliers;
1156 }
1157 
1158 //________________________________________________________________________
1159 Int_t AliMTRChEffAnalysis::GetRunNumber ( Int_t ipt ) const
1160 {
1162  if ( ipt < 0 && ipt >= fOutputs->GetEntriesFast() ) return -1;
1163  return fOutputs->UncheckedAt(ipt)->GetUniqueID();
1164 }
1165 
1166 //________________________________________________________________________
1167 TList* AliMTRChEffAnalysis::GetRunList ( const char* runList ) const
1168 {
1170  TList* rl = new TList;
1171  rl->SetOwner();
1172  TString sRunList = gSystem->ExpandPathName(runList);
1173  if ( gSystem->AccessPathName(sRunList) || sRunList.EndsWith(".root") ) {
1174  sRunList.ReplaceAll(","," ");
1175  if ( sRunList.IsDigit() ) {
1176  TObjArray* arr = sRunList.Tokenize(" ");
1177  for ( Int_t iarr=0; iarr<arr->GetEntries(); iarr++ ) {
1178  rl->Add(new TObjString(arr->At(iarr)->GetName()));
1179  }
1180  delete arr;
1181  }
1182  }
1183  else {
1184  ifstream inFile(sRunList.Data());
1185  TString currLine = "";
1186  while ( ! inFile.eof() ) {
1187  currLine.ReadLine(inFile);
1188  TString currRun = AliAnalysisMuonUtility::GetRunNumberAsString(currLine);
1189  if ( ! currRun.IsNull() ) rl->Add(new TObjString(currRun));
1190  }
1191  inFile.close();
1192  }
1193  rl->Sort();
1194  return rl;
1195 }
1196 
1197 //________________________________________________________________________
1198 TH1* AliMTRChEffAnalysis::GetSum ( AliTrigChEffOutput* trigOut, TObjArray* condition, Int_t itype, Int_t icount, Int_t ichamber ) const
1199 {
1201  Int_t itrackSel = static_cast<TObjString*>(condition->At(3))->String().Atoi();
1202  Int_t imatch = static_cast<TObjString*>(condition->At(4))->String().Atoi();
1203  Int_t imethod = static_cast<TObjString*>(condition->At(5))->String().Atoi();
1204  TString objName = trigOut->GetHistoName(itype, icount, ichamber, itrackSel, imatch, imethod);
1205  return static_cast<TH1*>(trigOut->GetSum(condition->At(0)->GetName(),condition->At(1)->GetName(),condition->At(2)->GetName(),objName));
1206 }
1207 
1208 //________________________________________________________________________
1209 TH1* AliMTRChEffAnalysis::GetTrend ( Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem ) const
1210 {
1212  if ( itype == AliTrigChEffOutput::kHchamberEff ) {
1213  if ( idetelem < 0 && ichamber >=0 ) idetelem = 11+ichamber;
1214  }
1215  TH1* outHisto = 0x0;
1216  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
1217 
1218  TIter next(fOutputs);
1219  TList* effHistoList = 0x0;
1220  Int_t ibin = 0;
1221  while ( (effHistoList = static_cast<TList*>(next()) ) ) {
1222  ibin++;
1223 // TString identifier = GetIdentifier(trigOut,condition,itype,icount,ichamber);
1224  if ( ! outHisto ) {
1225 // TString outName = identifier;
1226  TString outName = Form("histo_type%i_count%i_ch%i_",itype,icount,11+ichamber);
1227 // outName.ReplaceAll("/","_");
1228  outName += Form("%i_trend",idetelem);
1229  outHisto = new TH1D(outName.Data(),outName.Data(),fOutputs->GetEntriesFast(),0.,(Double_t)fOutputs->GetEntriesFast());
1230  outHisto->SetDirectory(0);
1231  outHisto->GetXaxis()->SetTitle("Run num.");
1232  }
1233  UInt_t run = effHistoList->GetUniqueID();
1234  outHisto->GetXaxis()->SetBinLabel(ibin,Form("%u",run));
1235  TH1* histo = GetHisto(effHistoList,itype,icount,ichamber);
1236  Int_t currBin = histo->GetXaxis()->FindBin(idetelem);
1237  outHisto->SetBinContent(ibin,histo->GetBinContent(currBin));
1238  outHisto->SetBinError(ibin,histo->GetBinError(currBin));
1239  }
1240  if ( outHisto ) outHisto->GetXaxis()->LabelsOption("v");
1241  return outHisto;
1242 }
1243 
1244 //________________________________________________________________________
1245 TGraphAsymmErrors* AliMTRChEffAnalysis::GetTrendEff ( Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem ) const
1246 {
1248  if ( icount == AliTrigChEffOutput::kAllTracks ) {
1249  AliWarning("Chose either bending plane, non-bending plane or both planes");
1250  return NULL;
1251  }
1252  TH1* histoNum = GetTrend(itype,icount,ichamber,idetelem);
1253  TH1* histoDen = GetTrend(itype,AliTrigChEffOutput::kAllTracks,ichamber,idetelem);
1254  TGraphAsymmErrors* graph = new TGraphAsymmErrors(histoNum,histoDen,"e0");
1255  histoNum->Reset();
1256  histoNum->SetStats(kFALSE);
1257  graph->SetHistogram(static_cast<TH1F*>(histoNum));
1258  graph->GetYaxis()->SetTitle("Efficiency");
1259  graph->SetMarkerSize(0.5);
1260 // for ( Int_t ibin=1; ibin<=histoNum->GetXaxis()->GetNbins(); ibin++ ) {
1261 // graph->GetXaxis()->SetBinLabel(ibin,histoNum->GetXaxis()->GetBinLabel(ibin));
1262 // }
1263 // delete histoNum;
1264  delete histoDen;
1265  return graph;
1266 }
1267 
1268 //________________________________________________________________________
1269 Double_t AliMTRChEffAnalysis::GetThreeOfFour ( TArrayD eff, TArrayD effErr, Double_t &probErr ) const
1270 {
1272  Double_t binomialEff = 0.;
1273  Double_t sumErr2 = 0.;
1274  for ( Int_t jch=-1; jch<4; jch++ ) {
1275  Double_t prodEff = 1.;
1276  Double_t prodErr2 = 0.;
1277  for ( Int_t ich=0; ich<4; ich++ ) {
1278  Double_t currEff = ( ich == jch ) ? 1.-eff[ich] : eff[ich];
1279  prodEff *= currEff;
1280  Double_t relErr = ( currEff>0. ) ? effErr[ich]/currEff : 0.;
1281  prodErr2 += relErr*relErr;
1282  }
1283  binomialEff += prodEff;
1284  sumErr2 += prodEff*prodEff*prodErr2;
1285  }
1286  probErr = TMath::Sqrt(sumErr2);
1287  return binomialEff;
1288 }
1289 
1290 //________________________________________________________________________
1292 {
1294  if ( ! fMergedOutputs || fMergedOutputs->IsEmpty() ) {
1295  AliError("You first need to merge efficiency objects with MergeOutput");
1296  return kFALSE;
1297  }
1298  return kTRUE;
1299 }
1300 
1301 //________________________________________________________________________
1302 Bool_t AliMTRChEffAnalysis::MergeOutput ( TArrayI runRanges, Double_t averageStatError, Bool_t isIndex )
1303 {
1305 
1306  if ( runRanges.GetSize()%2 == 1 ) {
1307  AliError("Run ranges expected in the form: start_period1,end_period1,start_period2,end_period2... => even number expected");
1308  return kFALSE;
1309  }
1310 
1311  TArrayI mergedRanges = MergeRangesForStat(runRanges, averageStatError);
1312 
1313  Int_t nRanges = mergedRanges.GetSize()/2;
1314 
1315 
1316  if ( fMergedOutputs ) fMergedOutputs->Delete();
1317  else {
1318  fMergedOutputs = new TObjArray(nRanges);
1319  fMergedOutputs->SetOwner();
1320  }
1321 
1322  TList* effHistoList = 0x0;
1323  for ( Int_t irange=0; irange<nRanges; irange++ ) {
1324  Int_t firstRun = mergedRanges[2*irange];
1325  Int_t lastRun = mergedRanges[2*irange+1];
1326  if ( isIndex ) {
1327  firstRun = GetRunNumber(firstRun);
1328  lastRun = GetRunNumber(lastRun);
1329  }
1330 
1331  TObjArray* mergedOut = 0x0;
1332  TIter next(fOutputs);
1333  TFileMerger fileMerger;
1334  while ( (effHistoList = static_cast<TList*>(next()) ) ) {
1335  UInt_t run = effHistoList->GetUniqueID();
1336  if ( run < firstRun || run > lastRun ) continue;
1337  fileMerger.AddFile(effHistoList->GetName(),kFALSE);
1338  }
1339 
1340  TString sRange = Form("%i_%i",firstRun,lastRun);
1341  TString mergedFilename = Form("mergedTrigEff_runs_%s.root",sRange.Data());
1342  fileMerger.OutputFile(mergedFilename.Data());
1343  fileMerger.Merge();
1344  AliTrigChEffOutput* trigOut = new AliTrigChEffOutput(mergedFilename);
1345  trigOut->SetName(sRange.Data());
1346  fMergedOutputs->Add(trigOut);
1347  }
1348  return kTRUE;
1349 }
1350 
1351 //________________________________________________________________________
1352 TArrayI AliMTRChEffAnalysis::MergeRangesForStat ( TArrayI runRanges, Double_t averageStatError, Bool_t excludePeriphericBoards ) const
1353 {
1354  if ( averageStatError <= 0. || averageStatError >= 1. ) return runRanges;
1355 
1356  // FIXME: statstical error for binomial depends on the value of epsilon
1357  // for the moment let's assume an average efficiency of 0.9 (underestimated)
1358  // in the future one could maybe actually calculate it
1359  // (still we're working with average values...so the precision is limited)
1360  Double_t effForStatCalc = 0.9;
1361 
1362  Double_t averageStatNeeded = effForStatCalc*(1.-effForStatCalc)/(averageStatError*averageStatError);
1363 
1364  AliInfo(Form("Average statistics needed to reach precision of %g : %g",averageStatError,averageStatNeeded));
1365 
1366  Int_t nRanges = runRanges.GetSize()/2;
1367 
1368  TArrayD averageStat(nRanges);
1369  Double_t fullStat = 0.;
1370  for ( Int_t irange=0; irange<nRanges; irange++ ) {
1371  averageStat[irange] = GetAverageStat(runRanges[2*irange],runRanges[2*irange+1],AliTrigChEffOutput::kHboardEff,excludePeriphericBoards);
1372  fullStat += averageStat[irange];
1373  }
1374 
1375  TArrayI mergedRanges(runRanges.GetSize());
1376  Int_t imerged = 0;
1377  mergedRanges[imerged++] = runRanges[0];
1378  Double_t mergedAverageStat = 0., remainingStat = fullStat;
1379  for ( Int_t irange=0; irange<nRanges; irange++ ) {
1380  Int_t istart = 2*irange;
1381  Int_t iend = istart+1;
1382  mergedAverageStat += averageStat[irange];
1383  remainingStat -= averageStat[irange];
1384 
1385  AliInfo(Form("%i - %i => stat %g",runRanges[2*irange],runRanges[2*irange+1],averageStat[irange]));
1386 
1387  if ( ( mergedAverageStat >= averageStatNeeded && remainingStat >= averageStatNeeded ) || iend == runRanges.GetSize()-1 ) {
1388  mergedRanges[imerged++] = runRanges[iend];
1389  AliInfo(Form(" merged range %i - %i => stat %g",mergedRanges[imerged-2],mergedRanges[imerged-1],mergedAverageStat));
1390  mergedAverageStat = 0.;
1391  Int_t nextRun = iend+1;
1392  if ( nextRun < runRanges.GetSize() ) mergedRanges[imerged++] = runRanges[nextRun];
1393  }
1394  }
1395  mergedRanges.Set(imerged);
1396  return mergedRanges;
1397 }
1398 
1399 //________________________________________________________________________
1400 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 )
1401 {
1403  if ( ! fConditions ) {
1404  fConditions = new TObjArray();
1405  fConditions->SetOwner();
1406  }
1407 
1408  TString sCondition = Form("%s;%s;%s;%i;%i;%i",physSel,trigClassName,centrality,itrackSel,imatch,imethod);
1409  TObjArray* foundCondition = static_cast<TObjArray*>(fConditions->FindObject(sCondition.Data()));
1410  TObjArray* basicCondition = static_cast<TObjArray*>(fConditions->At(0));
1411 
1412  TObjArray* addCondition = 0x0;
1413 
1414  if ( foundCondition ) {
1415  if ( isBasic ) {
1416  if ( foundCondition == basicCondition ) return kFALSE;
1417  else {
1418  fConditions->Remove(foundCondition);
1419  addCondition = foundCondition;
1420  }
1421  }
1422  else {
1423  AliInfo("Systematic condition already added");
1424  return kFALSE;
1425  }
1426  }
1427  else {
1428  addCondition = sCondition.Tokenize(";");
1429  addCondition->SetName(sCondition.Data());
1430  }
1431 
1432 
1433  if ( isBasic ) {
1434  if ( basicCondition ) {
1435  AliInfo(Form("Changing current eff. condition: %s\n",basicCondition->GetName()));
1436  fConditions->Remove(basicCondition);
1437  delete basicCondition;
1438  }
1439  fConditions->AddAt(addCondition,0);
1440  fConditions->Compress();
1441 
1442  // Update outputs
1443  if ( fOutputs ) {
1444  TObjArray* tmpOutputs = static_cast<TObjArray*>(fOutputs->Clone());
1445  fOutputs->Delete();
1446  TIter next(tmpOutputs);
1447  TList* effHistiList = 0x0;
1448  while ( (effHistiList = static_cast<TList*>(next())) ) {
1449  AddToList(effHistiList->GetName(), fOutputs->GetName());
1450  }
1451  delete tmpOutputs;
1452  }
1453  }
1454  else fConditions->Add(addCondition);
1455 
1456  return kTRUE;
1457 }
1458 
1459 //________________________________________________________________________
1461 {
1464 }
1465 
1466 
1467 //________________________________________________________________________
1468 Bool_t AliMTRChEffAnalysis::SetEffConditions ( const char* physSel, const char* trigClassName, const char* centrality, Int_t itrackSel, Int_t imatch, Int_t imethod )
1469 {
1471  return SetCondition(physSel, trigClassName, centrality, itrackSel, imatch, imethod, kTRUE);
1472 }
1473 
1474 //________________________________________________________________________
1475 Bool_t AliMTRChEffAnalysis::SetOutList ( const char *localFileList, const char *outputName )
1476 {
1478 
1480 
1481  TString filename(localFileList);
1482  gSystem->ExpandPathName(filename);
1483  if ( gSystem->AccessPathName(filename.Data()) ) {
1484  AliWarning(Form("Cannot find %s",filename.Data()));
1485  return kFALSE;
1486  }
1487  if ( filename.EndsWith(".root") ) return AddToList(filename.Data(),outputName);
1488 
1489  Bool_t isOk = kTRUE;
1490  ifstream inFile(filename.Data());
1491  TString currLine = "";
1492  while ( ! inFile.eof() ) {
1493  currLine.ReadLine(inFile);
1494  if ( currLine.IsNull() ) continue;
1495  if ( gSystem->AccessPathName(currLine.Data()) ) continue;
1496  if ( ! AddToList(currLine.Data(), outputName) ) isOk = kFALSE;
1497  }
1498  inFile.close();
1499 
1500  return isOk;
1501 }
1502 
1503 //________________________________________________________________________
1504 Bool_t AliMTRChEffAnalysis::SetResultsFromGrid ( const char *runList, const char *path, const char *pattern, const char* localFileList, const char* outDir, const char *directory, const char* outputName )
1505 {
1507  CopyLocally(runList,path,pattern,localFileList,outDir,directory);
1508  return SetOutList(localFileList,outputName);
1509 }
1510 
1511 //________________________________________________________________________
1512 Bool_t AliMTRChEffAnalysis::SetResultsFromWeb ( const char *runList, const char *path, const char* localFileList, const char* outDir, const char *directory, const char* outputName )
1513 {
1515  CopyLocally(runList,path,"",localFileList,outDir,directory);
1516  return SetOutList(localFileList,outputName);
1517 }
1518 
1519 //________________________________________________________________________
1520 Bool_t AliMTRChEffAnalysis::WriteMergedToOCDB ( const char* outputCDB ) const
1521 {
1523  if ( ! HasMergedResults() ) return kFALSE;
1524  TString outCDBdir(outputCDB);
1525  if ( outCDBdir.Contains("://") && ! outCDBdir.BeginsWith("local") ) {
1526  AliError("A local directory is required to store the information");
1527  return kFALSE;
1528  }
1529  outCDBdir.ReplaceAll("local://","");
1530  if ( gSystem->AccessPathName(outCDBdir.Data()) ) {
1531  if ( ! ExecCommand(Form("mkdir -p %s",outCDBdir.Data()), kTRUE) ) {
1532  AliError(Form("Failed to create directory %s",outCDBdir.Data()));
1533  return kFALSE;
1534  }
1535  }
1536  TString outCDB = outCDBdir;
1537  outCDB.Prepend("local://");
1538 
1539  AliCDBManager* mgr = AliCDBManager::Instance();
1540  if ( ! mgr->GetDefaultStorage() ) mgr->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
1541 
1542  TString trigEffCDBdir = "MUON/Calib/TriggerEfficiency";
1543 
1544  mgr->SetSpecificStorage(trigEffCDBdir.Data(),outCDB.Data());
1545 
1546  AliCDBStorage* specificStorage = mgr->GetSpecificStorage(trigEffCDBdir.Data());
1547 
1548  TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
1549 
1550  AliTrigChEffOutput* trigOut = 0x0;
1551  TIter next(fMergedOutputs);
1552  while ( (trigOut = static_cast<AliTrigChEffOutput*>(next())) ) {
1553  TList* effList = GetEffHistoList(trigOut,condition);
1554  TString runRange = trigOut->GetName();
1555 
1556 // // Write full merged output in file
1557 // TFile* file = TFile::Open(Form("mergedTrigEff_runs_%s.root",runRange.Data()),"RECREATE");
1558 // effList->Write("triggerChamberEff",TObject::kSingleKey);
1559 // trigOut->GetOutput()->Write(trigOut->GetOutput()->GetName(),TObject::kSingleKey);
1560 // file->Close();
1561 // delete file;
1562 
1563 
1564  // Write OCDB object
1565  TObjArray* currRange = runRange.Tokenize("_");
1566  Int_t firstRun = static_cast<TObjString*>(currRange->UncheckedAt(0))->String().Atoi();
1567  Int_t lastRun = static_cast<TObjString*>(currRange->UncheckedAt(1))->String().Atoi();
1568  delete currRange;
1569 
1570  // If an object is already there, ask to remove it or keep it
1571  for ( Int_t irun=0; irun<2; irun++ ) {
1572  Int_t runnr = ( irun == 0 ) ? firstRun : lastRun;
1573  specificStorage->QueryCDB(runnr);
1574  TObjArray* allIdsForRun = specificStorage->GetQueryCDBList();
1575  TIter nextId(allIdsForRun);
1576  AliCDBId* id = 0x0;
1577  while ((id = dynamic_cast<AliCDBId*>(nextId()))) {
1578  TString path(id->GetPath());
1579  Int_t foundFirst = id->GetFirstRun();
1580  Int_t foundLast = id->GetLastRun();
1581  Int_t version = id->GetVersion();
1582  Int_t subversion = id->GetSubVersion();
1583  TString locPath = Form("%s/%s/Run%d_%d_v%d_s%d.root",outCDBdir.Data(),path.Data(),foundFirst,foundLast,version,subversion);
1584  if ( ! gSystem->AccessPathName(locPath.Data()) ) {
1585  ExecCommand(Form("rm %s",locPath.Data()), kTRUE);
1586  }
1587  }
1588  }
1589 
1590  // Save the CDB object in the specific storage
1591  AliMUONTriggerEfficiencyCells* effMap = new AliMUONTriggerEfficiencyCells(effList);
1592  AliMUONCDB::WriteToCDB(effMap, "MUON/Calib/TriggerEfficiency", firstRun, lastRun, "Measured efficiencies");
1593  delete effMap; // CAVEAT: effMap is owner of efflist
1594  }
1595  return kTRUE;
1596 }
1597 
1598 //___________________________________________________________________________
1599 //Bool_t AliMTRChEffAnalysis::WriteMerged() const
1600 //{
1601 // /// Write merged efficiencies on file
1602 // if ( ! HasMergedResults ) return kFALSE;
1603 //
1604 // TObjArray* condition = static_cast<TObjArray*>(fConditions->At(0));
1605 //
1606 // AliTrigChEffOutput* trigOut = 0x0;
1607 // TIter next(fMergedOutputs);
1608 // while ( (trigOut = static_cast<AliTrigChEffOutput*>(next())) ) {
1609 // TFile* file = TFile::Open(Form("mergedTrigEff_runs_%s.root",trigOut->GetName()),"RECREATE");
1610 // TList* effList = GetEffHistoList(trigOut,condition);
1611 // effList->Write("triggerChamberEff",TObject::kSingleKey);
1612 // trigOut->GetOutput()->Write(trigOut->GetOutput()->GetName(),TObject::kSingleKey);
1613 // file->Close();
1614 // delete file;
1615 // delete effList;
1616 // }
1617 // return kTRUE;
1618 //}
void CompareEfficiencies(const char *sources, const char *titles, const char *opt) const
TArrayI GetHomogeneusRanges(Double_t chi2Cut=3, Int_t maxNRanges=4, Double_t minEffVariation=0.005, TArrayI *forcedChanges=0x0, Double_t minEff=0.85, Double_t maxEff=1.01)
Counts per cathode histogram index.
Int_t GetIndexFromRun(UInt_t runNumber) const
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
TList * GetEffHistoList(TString physSel, TString trigClassNames, TString centrality, Int_t itrackSel, Int_t imatch, Int_t imethod)
void CompareMergedEfficiencies(const char *opt) const
void CopyDir(TDirectory *source) const
Double_t GetError(Double_t errLow, Double_t errHigh) const
Bool_t DrawSystematicEnvelope(Bool_t perRPC=kFALSE, Double_t miny=-0.03, Double_t maxy=0.03) const
const char * title
Definition: MakeQAPdf.C:26
tracks used for calculation
Bool_t CopyLocally(const char *runList, const char *path, const char *pattern, const char *localFileList, const char *outDir, const char *directory) const
Hit pattern from tracker track extrapolation.
Double_t GetThreeOfFour(TArrayD eff, TArrayD effErr, Double_t &probErr) const
TSystem * gSystem
TGraphAsymmErrors * GetTrendEff(Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem) const
centrality
TArrayI MergeRangesForStat(TArrayI runRanges, Double_t averageStatError, Bool_t excludePeriphericBoards=kTRUE) const
Counts per slat histogram index.
Bool_t SetResultsFromGrid(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")
Int_t nDE
TList * GetEffHistoList(AliTrigChEffOutput *trigOut, TObjArray *condition) const
Number of count type.
Bool_t AddToList(const char *filename, const char *outputName)
TObjArray * fMergedOutputs
!<! List of conditions for trigger efficiency
Output for Trig chamber effieincy.
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.
Double_t GetAverageStat(Int_t firstRun, Int_t lastRun, Int_t itype=AliTrigChEffOutput::kHboardEff, Bool_t excludePeriphericBoards=kTRUE) const
Bool_t SetOutList(const char *localFileList, const char *outputName)
TString GetIdentifier(AliTrigChEffOutput *trigOut, TObjArray *condition, Int_t itype, Int_t icount, Int_t ichamber) 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)
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)
Bool_t WriteMergedToOCDB(const char *outputCDB="CDB") const
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
Double_t FitRangesFunc(Double_t *x, Double_t *par)
Counts per board histogram index.
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 outputs
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_t SetResultsFromWeb(const char *runList, const char *path, const char *localFileList="localFileList.txt", const char *outDir="", const char *directory="MTR_ChamberEffMap", const char *outputName="testMTRChamberEff")
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)
TH1 * GetSum(AliTrigChEffOutput *trigOut, TObjArray *condition, Int_t itype, Int_t icount, Int_t ichamber) const
TH1 * GetTrend(Int_t itype, Int_t icount, Int_t ichamber, Int_t idetelem) const