AliPhysics  defa9f6 (defa9f6)
MuonResolution.C
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // Macro compiled and launch by RunMuonResolution.C for submitting muon Resolution analysis locally or on CAF.
3 // See RunMuonResolution.C for more details
4 //
5 // Author: Philippe Pillot - SUBATECH Nantes
6 //--------------------------------------------------------------------------
7 
8 #if !defined(__CINT__) || defined(__MAKECINT__)
9 // ROOT includes
10 #include <fstream>
11 #include <TString.h>
12 #include <TStopwatch.h>
13 #include <TMultiGraph.h>
14 #include <TSystem.h>
15 #include <TChain.h>
16 #include <TGraphErrors.h>
17 #include <TProof.h>
18 #include <TList.h>
19 #include <TCanvas.h>
20 #include <TFile.h>
21 #include <TGrid.h>
22 #include <TEnv.h>
23 #include <TROOT.h>
24 #include <TAxis.h>
25 #include <THashList.h>
26 #include <TFileCollection.h>
27 #include <TAlienCollection.h>
28 #include <TGridCollection.h>
29 #include <TGridResult.h>
30 
31 // STEER includes
32 #include "AliLog.h"
33 #include "AliCDBManager.h"
34 #include "AliAnalysisManager.h"
35 #include "AliESDInputHandler.h"
36 #include "AliTagAnalysis.h"
37 #include "AliRunTagCuts.h"
38 #include "AliLHCTagCuts.h"
39 #include "AliDetectorTagCuts.h"
40 #include "AliEventTagCuts.h"
41 #include "AliAnalysisDataContainer.h"
42 #include "AliAnalysisAlien.h"
43 
44 // PHYSICS includes
45 #include "AliPhysicsSelectionTask.h"
46 #include "AliPhysicsSelection.h"
47 #include "AliMultSelectionTask.h"
49 
50 // MUON includes
51 #include "AliMpCDB.h"
52 #include "AliMpDetElement.h"
53 #include "AliMpDDLStore.h"
54 #include "AliMUONCalibParamND.h"
55 #include "AliMUON2DMap.h"
56 #include "AliMUONTrackerData.h"
57 #include "AliMUONPainterDataRegistry.h"
58 #include "AliMUONTrackerDataWrapper.h"
59 
60 #include "AliMuonEventCuts.h"
61 #include "AliMuonTrackCuts.h"
62 
63 #include "AddTaskMuonResolution.C"
64 
65 #endif
66 
68 Int_t nDE = 200;
69 
70 Bool_t Resume(Int_t mode, Int_t &firstStep, Double_t clusterResNB[10], Double_t clusterResB[10],
71  Double_t clusterResNBErr[10], Double_t clusterResBErr[10],
72  Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
73  Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20],
74  Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200],
75  TGraphErrors* clusterResXVsStep[10], TGraphErrors* clusterResYVsStep[10],
76  TGraphErrors* halfChShiftXVsStep[20], TGraphErrors* halfChShiftYVsStep[20]);
77 void LoadAlirootOnProof(TString& aaf, TString rootVersion, TString aliphysicsVersion, Int_t iStep);
78 void CreateAlienHandler(TString runMode, TString& aliphysicsVersion, TString& runListName,
79  TString &dataDir, TString &dataPattern, TString &outDir, Int_t iStep,
80  TString runFormat, Int_t maxFilesPerJob, Int_t maxMergeFiles, Int_t maxMergeStages);
81 AliAnalysisTaskMuonResolution* CreateAnalysisTrain(Int_t mode, Int_t iStep, Bool_t selectPhysics, Bool_t selectTrigger,
82  Bool_t matchTrig, Bool_t applyAccCut, Bool_t applyPDCACut,
83  Double_t minMomentum, Double_t minPt, Bool_t isMC, Bool_t correctForSystematics,
84  Int_t extrapMode, Double_t clusterResNB[10], Double_t clusterResB[10],
85  Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
86  Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200]);
87 Bool_t GetChamberResolution(Int_t iStep, Double_t clusterResNB[10], Double_t clusterResB[10],
88  Double_t clusterResNBErr[10], Double_t clusterResBErr[10]);
89 Bool_t AddHalfChShift(Int_t iStep, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20]);
90 Bool_t AddDEShift(Int_t iStep, Double_t deShiftNB[200], Double_t deShiftB[200]);
91 void AddMCHViews(TString smode, TFile* file);
92 AliMUONTrackerData* ConvertGraph(TGraphErrors& g, const char* name);
93 Int_t GetMode(TString smode, TString input);
94 TChain* CreateChainFromCollection(const char *xmlfile);
95 TChain* CreateChainFromFile(const char *rootfile);
96 TChain* CreateChainFromESDList(const char *esdList);
98 
99 //______________________________________________________________________________
100 void MuonResolution(TString smode, TString inputFileName, Int_t nSteps,
101  TString rootVersion, TString aliphysicsVersion,
102  TString dataDir, TString dataPattern, TString runFormat, TString outDir,
103  Int_t maxFilesPerJob, Int_t maxMergeFiles, Int_t maxMergeStages,
104  Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig, Bool_t applyAccCut, Bool_t applyPDCACut,
105  Double_t minMomentum, Double_t minPt, Bool_t isMC, Bool_t correctForSystematics, Int_t extrapMode,
106  Bool_t shiftHalfCh, Bool_t shiftDE, Int_t nevents)
107 {
109 
110  // timer start...
111  TStopwatch* localTimer = new TStopwatch;
112 
113  // check parameters
114  nSteps = TMath::Max(nSteps,1);
115  if (extrapMode != 0 && extrapMode != 1) {
116  Error("MuonResolution","incorrect extrapolation mode!");
117  return;
118  }
119 
120  // Check runing mode
121  Int_t mode = GetMode(smode, inputFileName);
122  if(mode < 0){
123  Error("MuonResolution","Please provide either an ESD root file, a list of ESDs, a collection of ESDs or a dataset.");
124  return;
125  }
126 
127  // set starting chamber resolution (if -1 they will be loaded from recoParam in the task)
128  Double_t clusterResNB[10] = {-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.};
129  Double_t clusterResB[10] = {-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.};
130  Double_t clusterResNBErr[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
131  Double_t clusterResBErr[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
132  Double_t halfChShiftNB[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
133  Double_t halfChShiftB[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
134  Double_t halfChShiftNBErr[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
135  Double_t halfChShiftBErr[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
136  Double_t deShiftNB[200];
137  Double_t deShiftB[200];
138  for (Int_t i=0; i<200; i++) {
139  deShiftNB[i] = 0.;
140  deShiftB[i] = 0.;
141  }
142 
143  // output graphs
144  TMultiGraph* mgClusterResXVsStep = new TMultiGraph("mgClusterResXVsStep","cluster X-resolution versus step;step;#sigma_{X} (cm)");
145  TMultiGraph* mgClusterResYVsStep = new TMultiGraph("mgClusterResYVsStep","cluster Y-resolution versus step;step;#sigma_{Y} (cm)");
146  TGraphErrors* clusterResXVsStep[10];
147  TGraphErrors* clusterResYVsStep[10];
148  for (Int_t i = 0; i < 10; i++) {
149  clusterResXVsStep[i] = new TGraphErrors(nSteps+1);
150  clusterResXVsStep[i]->SetName(Form("gResX_ch%d",i+1));
151  clusterResXVsStep[i]->SetMarkerStyle(kFullDotMedium);
152  clusterResXVsStep[i]->SetMarkerColor(i+1+i/9);
153  mgClusterResXVsStep->Add(clusterResXVsStep[i],"lp");
154 
155  clusterResYVsStep[i] = new TGraphErrors(nSteps+1);
156  clusterResYVsStep[i]->SetName(Form("gResY_ch%d",i+1));
157  clusterResYVsStep[i]->SetMarkerStyle(kFullDotMedium);
158  clusterResYVsStep[i]->SetMarkerColor(i+1+i/9);
159  mgClusterResYVsStep->Add(clusterResYVsStep[i],"lp");
160  }
161  TMultiGraph* mgHalfChShiftXVsStep = new TMultiGraph("mgHalfChShiftXVsStep","half-chamber displacement in X direction versus step;step;#Delta_{X} (cm)");
162  TMultiGraph* mgHalfChShiftYVsStep = new TMultiGraph("mgHalfChShiftYVsStep","half-chamber displacement in Y direction versus step;step;#Delta_{Y} (cm)");
163  TGraphErrors* halfChShiftXVsStep[20];
164  TGraphErrors* halfChShiftYVsStep[20];
165  for (Int_t i = 0; i < 20; i++) {
166  halfChShiftXVsStep[i] = new TGraphErrors(nSteps+1);
167  halfChShiftXVsStep[i]->SetName(Form("gShiftX_hch%d",i+1));
168  halfChShiftXVsStep[i]->SetMarkerStyle(kFullDotMedium);
169  halfChShiftXVsStep[i]->SetMarkerColor(i+1+i/9+i/18);
170  mgHalfChShiftXVsStep->Add(halfChShiftXVsStep[i],"lp");
171  halfChShiftXVsStep[i]->SetPoint(0, 0, halfChShiftNB[i]);
172  halfChShiftXVsStep[i]->SetPointError(0, 0., halfChShiftNBErr[i]);
173 
174  halfChShiftYVsStep[i] = new TGraphErrors(nSteps+1);
175  halfChShiftYVsStep[i]->SetName(Form("gShiftY_hch%d",i+1));
176  halfChShiftYVsStep[i]->SetMarkerStyle(kFullDotMedium);
177  halfChShiftYVsStep[i]->SetMarkerColor(i+1+i/9+i/18);
178  mgHalfChShiftYVsStep->Add(halfChShiftYVsStep[i],"lp");
179  halfChShiftYVsStep[i]->SetPoint(0, 0, halfChShiftB[i]);
180  halfChShiftYVsStep[i]->SetPointError(0, 0., halfChShiftBErr[i]);
181  }
182 
183  // check for old output files
184  Int_t firstStep = 0;
185  char remove = '\0';
186  if (!gSystem->Exec("ls chamberResolution_step*[0-9].root")) {
187  cout<<"Above files already exist in the current directory. [d=delete, r=resume, e=exit] "<<flush;
188  while (remove != 'd' && remove != 'r' && remove != 'e') cin>>remove;
189  if (remove == 'y') gSystem->Exec("rm -f chamberResolution_step*[0-9].root");
190  else if (remove == 'r' && !Resume(mode, firstStep, clusterResNB, clusterResB, clusterResNBErr, clusterResBErr,
191  shiftHalfCh, halfChShiftNB, halfChShiftB, halfChShiftNBErr, halfChShiftBErr,
192  shiftDE, deShiftNB, deShiftB, clusterResXVsStep, clusterResYVsStep,
193  halfChShiftXVsStep, halfChShiftYVsStep)) return;
194  else if (remove == 'e') return;
195  }
196 
197  // Create input object
198  TObject* inputObj = 0x0;
199  if (mode != kGrid && mode != kTerminate) {
200  if (mode == kProof) {
201  if (inputFileName.EndsWith(".root")) {
202  TFile *inFile = TFile::Open(inputFileName.Data(),"READ");
203  if (inFile && inFile->IsOpen()) {
204  inputObj = dynamic_cast<TFileCollection*>(inFile->FindObjectAny("dataset"));
205  inFile->Close();
206  }
207  } else inputObj = new TObjString(inputFileName);
208  } else inputObj = CreateChain(mode, inputFileName);
209  if (!inputObj) return;
210  }
211 
212  // loop over step
213  for (Int_t iStep = firstStep; iStep < nSteps; iStep++) {
214  cout<<"step "<<iStep+1<<"/"<<nSteps<<endl;
215 
216  // create the analysis train
217  AliAnalysisTaskMuonResolution *muonResolution = CreateAnalysisTrain(mode, iStep, selectPhysics, selectTrigger, matchTrig,
218  applyAccCut, applyPDCACut, minMomentum, minPt, isMC,
219  correctForSystematics, extrapMode, clusterResNB, clusterResB,
220  shiftHalfCh, halfChShiftNB, halfChShiftB, shiftDE, deShiftNB, deShiftB);
221  if (!muonResolution) return;
222 
223  // prepare proof or grid environment
224  if (mode == kProof) LoadAlirootOnProof(smode, rootVersion, aliphysicsVersion, iStep-firstStep);
225  else if (mode == kGrid || mode == kTerminate) {
226  if (!gGrid) TGrid::Connect("alien://");
227  TString resultDir = Form("%s/%s/step%d", gGrid->GetHomeDirectory(), outDir.Data(), iStep);
228  if ((smode == "submit" || smode == "full") && AliAnalysisAlien::DirectoryExists(resultDir.Data())) {
229  cout << endl << "Output directory alien://" << resultDir <<" already exist." << endl;
230  cout << "Do you want to continue? [Y/n] " << endl;
231  TString reply = "";
232  reply.Gets(stdin,kTRUE);
233  reply.ToLower();
234  if (reply.BeginsWith("n")) return;
235  }
236  CreateAlienHandler(smode, aliphysicsVersion, inputFileName, dataDir, dataPattern, outDir, iStep,
237  runFormat, maxFilesPerJob, maxMergeFiles, maxMergeStages);
238  }
239 
240  // start analysis
241  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
242  if (mgr->InitAnalysis()) {
243  mgr->PrintStatus();
244  if (mode == kGrid) {
245  mgr->StartAnalysis("grid");
246  if (smode != "terminate") return; // stop here if we don't have yet the result of this step
247  } else if (mode == kTerminate) mgr->StartAnalysis("grid terminate");
248  else if (mode == kProof) {
249  if (inputObj->IsA() == TFileCollection::Class())
250  mgr->StartAnalysis("proof", static_cast<TFileCollection*>(inputObj), nevents);
251  else mgr->StartAnalysis("proof", static_cast<TObjString*>(inputObj)->GetName(), nevents);
252  } else mgr->StartAnalysis("local", static_cast<TChain*>(inputObj), nevents);
253  }
254 
255  // save the summary canvases and mchview display
256  if (muonResolution->GetCanvases()) {
257  TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"UPDATE");
258  if (outFile && outFile->IsOpen()) {
259  outFile->cd();
260  muonResolution->GetCanvases()->Write();
261  AddMCHViews(smode, outFile);
262  outFile->Close();
263  delete outFile;
264  }
265  }
266 
267  // fill graphs with starting resolutions from the task at very first step
268  if (iStep == 0) {
269  muonResolution->GetStartingResolution(clusterResNB, clusterResB);
270  for (Int_t i = 0; i < 10; i++) {
271  clusterResXVsStep[i]->SetPoint(0, 0, clusterResNB[i]);
272  clusterResXVsStep[i]->SetPointError(0, 0., clusterResNBErr[i]);
273  clusterResYVsStep[i]->SetPoint(0, 0, clusterResB[i]);
274  clusterResYVsStep[i]->SetPointError(0, 0., clusterResBErr[i]);
275  }
276  }
277 
278  // read the chamber resolution from the output file
279  if (!GetChamberResolution(iStep, clusterResNB, clusterResB, clusterResNBErr, clusterResBErr)) return;
280 
281  // fill graphs with computed resolutions
282  for (Int_t i = 0; i < 10; i++) {
283  clusterResXVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResNB[i]);
284  clusterResXVsStep[i]->SetPointError(iStep+1, 0., clusterResNBErr[i]);
285  clusterResYVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResB[i]);
286  clusterResYVsStep[i]->SetPointError(iStep+1, 0., clusterResBErr[i]);
287  }
288 
289  // get the half-chamber displacements currently used and add the new measurements from the output file
290  muonResolution->GetHalfChShift(halfChShiftNB, halfChShiftB);
291  if (!AddHalfChShift(iStep, halfChShiftNB, halfChShiftB, halfChShiftNBErr, halfChShiftBErr)) return;
292 
293  // fill graphs with computed displacements
294  for (Int_t i = 0; i < 20; i++) {
295  halfChShiftXVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftNB[i]);
296  halfChShiftXVsStep[i]->SetPointError(iStep+1, 0., halfChShiftNBErr[i]);
297  halfChShiftYVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftB[i]);
298  halfChShiftYVsStep[i]->SetPointError(iStep+1, 0., halfChShiftBErr[i]);
299  }
300 
301  // get the DE displacements currently used and add the new measurements from the output file
302  muonResolution->GetDEShift(deShiftNB, deShiftB);
303  if (!AddDEShift(iStep, deShiftNB, deShiftB)) return;
304 
305  // clean memory
306  mgr->SetAnalysisType(AliAnalysisManager::kLocalAnalysis); // to make sure that all output containers are deleted
307  delete mgr;
308  TObject::SetObjectStat(kFALSE);
309 
310  // in grid mode, stop here unless it is the final step
311  if ((mode == kGrid || mode == kTerminate) && iStep != nSteps-1) return;
312 
313  }
314 
315  // copy final results in results.root file
316  gSystem->Exec(Form("cp chamberResolution_step%d.root results.root", nSteps-1));
317 
318  // display convergence of cluster resolution
319  TCanvas* convergence1 = new TCanvas("convergenceRes","convergence of cluster resolution");
320  convergence1->Divide(1,2);
321  convergence1->cd(1);
322  mgClusterResXVsStep->Draw("ap");
323  convergence1->cd(2);
324  mgClusterResYVsStep->Draw("ap");
325 
326  // display convergence of half-chamber displacements
327  TCanvas* convergence2 = new TCanvas("convergenceShift","convergence of half-chamber displacements");
328  convergence2->Divide(1,2);
329  convergence2->cd(1);
330  mgHalfChShiftXVsStep->Draw("ap");
331  convergence2->cd(2);
332  mgHalfChShiftYVsStep->Draw("ap");
333 
334  // save convergence plots
335  TFile* outFile = TFile::Open("results.root","UPDATE");
336  if (!outFile || !outFile->IsOpen()) return;
337  outFile->cd();
338  mgClusterResXVsStep->Write();
339  mgClusterResYVsStep->Write();
340  convergence1->Write();
341  mgHalfChShiftXVsStep->Write();
342  mgHalfChShiftYVsStep->Write();
343  convergence2->Write();
344  outFile->Close();
345  delete outFile;
346 
347  // print final half-chamber displacements
348  printf("\nhalf-chamber total displacements:\n");
349  printf(" - non-bending:");
350  for (Int_t i = 0; i < 20; i++) printf((i==0)?" %6.4f":", %6.4f", halfChShiftNB[i]);
351  printf("\n - bending:");
352  for (Int_t i = 0; i < 20; i++) printf((i==0)?" %6.4f":", %6.4f", halfChShiftB[i]);
353  printf("\n\n");
354 
355  // print final DE displacements
356  printf("\nDE total displacements:\n");
357  printf(" - non-bending:");
358  for (Int_t i = 0; i < nDE; i++) printf((i==0)?" %6.4f":", %6.4f", deShiftNB[i]);
359  printf("\n - bending:");
360  for (Int_t i = 0; i < nDE; i++) printf((i==0)?" %6.4f":", %6.4f", deShiftB[i]);
361  printf("\n\n");
362 
363  // ...timer stop
364  localTimer->Stop();
365  localTimer->Print();
366  delete localTimer;
367 
368 }
369 
370 //______________________________________________________________________________
371 Bool_t Resume(Int_t mode, Int_t &firstStep, Double_t clusterResNB[10], Double_t clusterResB[10],
372  Double_t clusterResNBErr[10], Double_t clusterResBErr[10],
373  Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
374  Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20],
375  Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200],
376  TGraphErrors* clusterResXVsStep[10], TGraphErrors* clusterResYVsStep[10],
377  TGraphErrors* halfChShiftXVsStep[20], TGraphErrors* halfChShiftYVsStep[20])
378 {
381 
382  while (kTRUE) {
383 
384  // Get the step to restart from
385  cout<<"From which step (included) you want to resume? [#, e=exit] "<<flush;
386  TString step = "";
387  do {step.Gets(stdin,kTRUE);} while (!step.IsDigit() && step != "e");
388  if (step == "e") return kFALSE;
389  firstStep = step.Atoi();
390 
391  // restart from scratch if requested
392  if (firstStep == 0 && mode != kTerminate) {
393  gSystem->Exec("rm -f chamberResolution_step*[0-9].root");
394  return kTRUE;
395  }
396 
397  // look for results from the previous step
398  if (firstStep != 0 && gSystem->AccessPathName(Form("chamberResolution_step%d.root", firstStep-1))) {
399  cout<<"No result found from the previous step ("<<firstStep-1<<"). Unable to resume from step "<<firstStep<<endl;
400  continue;
401  }
402 
403  // fill graph with starting resolutions
404  for (Int_t i = 0; i < 10; i++) {
405  clusterResXVsStep[i]->SetPoint(0, 0, clusterResNB[i]);
406  clusterResXVsStep[i]->SetPointError(0, 0., clusterResNBErr[i]);
407  clusterResYVsStep[i]->SetPoint(0, 0, clusterResB[i]);
408  clusterResYVsStep[i]->SetPointError(0, 0., clusterResBErr[i]);
409  }
410 
411  // loop over previous steps
412  Bool_t missingInfo = kFALSE;
413  for (Int_t iStep = 0; iStep < firstStep; iStep++) {
414 
415  // read the chamber resolution from the output file
416  if (!GetChamberResolution(iStep, clusterResNB, clusterResB, clusterResNBErr, clusterResBErr) && iStep == firstStep-1) {
417  missingInfo = kTRUE;
418  break;
419  }
420 
421  // fill graphs with computed resolutions
422  for (Int_t i = 0; i < 10; i++) {
423  clusterResXVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResNB[i]);
424  clusterResXVsStep[i]->SetPointError(iStep+1, 0., clusterResNBErr[i]);
425  clusterResYVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResB[i]);
426  clusterResYVsStep[i]->SetPointError(iStep+1, 0., clusterResBErr[i]);
427  }
428 
429  // reset the half-chamber displacements if not used and add the new measurements from the output file
430  if (!shiftHalfCh) for (Int_t i=0; i<20; i++) {
431  halfChShiftNB[i] = 0.; halfChShiftB[i] = 0.;
432  halfChShiftNBErr[i] = 0.; halfChShiftBErr[i] = 0.;
433  }
434  if (!AddHalfChShift(iStep, halfChShiftNB, halfChShiftB, halfChShiftNBErr, halfChShiftBErr) && shiftHalfCh) {
435  missingInfo = kTRUE;
436  break;
437  }
438 
439  // fill graphs with computed displacements
440  for (Int_t i = 0; i < 20; i++) {
441  halfChShiftXVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftNB[i]);
442  halfChShiftXVsStep[i]->SetPointError(iStep+1, 0., halfChShiftNBErr[i]);
443  halfChShiftYVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftB[i]);
444  halfChShiftYVsStep[i]->SetPointError(iStep+1, 0., halfChShiftBErr[i]);
445  }
446 
447  // add the new measurements of DE displacements from the output file if in use
448  if (shiftDE && !AddDEShift(iStep, deShiftNB, deShiftB)) {
449  missingInfo = kTRUE;
450  break;
451  }
452 
453  }
454 
455  // check if missing important results from previous steps
456  if (missingInfo) continue;
457 
458  // keep previous steps and remove the others
459  if (mode != kTerminate) {
460  gSystem->Exec("mkdir __TMP__");
461  for (Int_t iStep = 0; iStep < firstStep; iStep++)
462  if (!gSystem->AccessPathName(Form("chamberResolution_step%d.root", iStep)))
463  gSystem->Exec(Form("mv chamberResolution_step%d.root __TMP__", iStep));
464  gSystem->Exec("rm -f chamberResolution_step*[0-9].root");
465  gSystem->Exec("mv __TMP__/chamberResolution_step*[0-9].root .");
466  gSystem->Exec("rm -rf __TMP__");
467  }
468 
469  return kTRUE;
470  }
471 
472 }
473 
474 //______________________________________________________________________________
475 void LoadAlirootOnProof(TString& aaf, TString rootVersion, TString aliphysicsVersion, Int_t iStep)
476 {
478 
479  // set general environment and close previous session
480  if (iStep == 0) gEnv->SetValue("XSec.GSI.DelegProxy","2");
481  else gProof->Close("s");
482 
483  // connect
484  if (aaf == "saf3") TProof::Open("pod://");
485  else {
486  TString location = (aaf == "caf") ? "alice-caf.cern.ch" : "nansafmaster2.in2p3.fr"; //"localhost:1093"
487  TString nWorkers = (aaf == "caf") ? "workers=80" : ""; //"workers=3x"
488  TString user = (gSystem->Getenv("alien_API_USER") == NULL) ? "" : Form("%s@",gSystem->Getenv("alien_API_USER"));
489  TProof::Mgr(Form("%s%s",user.Data(), location.Data()))->SetROOTVersion(Form("VO_ALICE@ROOT::%s",rootVersion.Data()));
490  TProof::Open(Form("%s%s/?N",user.Data(), location.Data()), nWorkers.Data());
491  }
492  if (!gProof) return;
493 
494  // set environment and load libraries on workers
495  TList* list = new TList();
496  list->Add(new TNamed("ALIROOT_MODE", "base"));
497  list->Add(new TNamed("ALIROOT_ENABLE_ALIEN", "1"));
498  if (aaf == "saf3") {
499  TString home = gSystem->Getenv("HOME");
500  gProof->UploadPackage(Form("%s/AliceVaf.par", home.Data()));
501  gProof->EnablePackage(Form("%s/AliceVaf.par", home.Data()), list, (iStep!=0));
502  } else gProof->EnablePackage(Form("VO_ALICE@AliPhysics::%s",aliphysicsVersion.Data()), list, kTRUE);
503 // gProof->UploadPackage("$ALICE_PHYSICS/PARfiles/PWGPPMUONdep.par");
504 // gProof->EnablePackage("$ALICE_PHYSICS/PARfiles/PWGPPMUONdep.par", kTRUE);
505 // gProof->UploadPackage("PWGPPMUONdep.par");
506 // gProof->EnablePackage("PWGPPMUONdep.par", kTRUE);
507 
508 }
509 
510 //______________________________________________________________________________
511 void CreateAlienHandler(TString runMode, TString& aliphysicsVersion, TString& runListName,
512  TString &dataDir, TString &dataPattern, TString &outDir, Int_t iStep,
513  TString runFormat, Int_t maxFilesPerJob, Int_t maxMergeFiles, Int_t maxMergeStages)
514 {
515  // Configure the alien plugin
516  AliAnalysisAlien *plugin = new AliAnalysisAlien();
517 
518  // If the run mode is merge, run in mode terminate to merge via jdl
519  // If the run mode is terminate, disable the mergin via jdl
520  Bool_t merge = kTRUE;
521  if (runMode.Contains("terminate")) merge = kFALSE;
522  else if (runMode == "merge") runMode = "terminate";
523 
524  // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
525  plugin->SetRunMode(runMode.Data());
526 
527  // Set the number of input files in test mode
528  plugin->SetNtestFiles(2);
529 
530  // Set versions of used packages
531  plugin->SetAPIVersion("V1.1x");
532  if (!aliphysicsVersion.IsNull()) plugin->SetAliPhysicsVersion(aliphysicsVersion.Data());
533 
534  // Declare input data to be processed
535  plugin->SetGridDataDir(dataDir.Data());
536  plugin->SetDataPattern(dataPattern.Data());
537  ifstream inFile(runListName.Data());
538  TString currRun;
539  if (inFile.is_open())
540  {
541  while (! inFile.eof() )
542  {
543  currRun.ReadLine(inFile,kTRUE); // Read line
544  if(currRun.IsNull()) continue;
545  plugin->AddRunNumber(Form(runFormat.Data(), currRun.Atoi()));
546  }
547  }
548  inFile.close();
549 
550  // Define alien work directory where all files will be copied. Relative to alien $HOME
551  plugin->SetGridWorkingDir(outDir.Data());
552 
553  // Declare alien output directory. Relative to working directory
554  plugin->SetGridOutputDir(Form("step%d",iStep));
555 
556  // Set the ouput directory of each masterjob to the run number
557  plugin->SetOutputToRunNo();
558 
559  // Declare all libraries (other than the default ones for the framework)
560  plugin->SetAdditionalRootLibs("libGui.so libProofPlayer.so libXMLParser.so");
561 
562  // Optionally add include paths
563  plugin->AddIncludePath("-I$ALICE_ROOT/include");
564  plugin->AddIncludePath("-I$ALICE_PHYSICS/include");
565  plugin->AddIncludePath("-I.");
566 
567  // Optionally add packages
568 // plugin->EnablePackage("PWGPPMUONdep.par");
569 
570  // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
571  plugin->SetAnalysisMacro("Resolution.C");
572  plugin->SetExecutable("Resolution.sh");
573 
574  // Optionally set time to live (default 30000 sec)
575  plugin->SetTTL(30000);
576 
577  // Optionally set input format (default xml-single)
578  plugin->SetInputFormat("xml-single");
579 
580  // Optionally modify the name of the generated JDL (default analysis.jdl)
581  plugin->SetJDLName("Resolution.jdl");
582 
583  // Optionally modify job price (default 1)
584  plugin->SetPrice(1);
585 
586  // Optionally modify split mode (default 'se')
587  plugin->SetSplitMode("se");
588 
589  // Optionally modify the maximum number of files per job
590  plugin->SetSplitMaxInputFileNumber(maxFilesPerJob);
591 
592  // Merge via JDL
593  if (merge) plugin->SetMergeViaJDL(kTRUE);
594 
595  // Optionally set the maximum number of files merged together in one stage
596  plugin->SetMaxMergeFiles(maxMergeFiles);
597 
598  // Optionally set the maximum number of merging stages
599  plugin->SetMaxMergeStages(maxMergeStages);
600 
601  // Exclude given output file(s) from registration/merging
602  plugin->SetRegisterExcludes("AnalysisResults.root EventStat_temp.root");
603 
604  // Save the log files
605  plugin->SetKeepLogs();
606 
607  AliAnalysisManager::GetAnalysisManager()->SetGridHandler(plugin);
608 }
609 
610 //______________________________________________________________________________
612  Bool_t matchTrig, Bool_t applyAccCut, Bool_t applyPDCACut,
613  Double_t minMomentum, Double_t minPt, Bool_t isMC, Bool_t correctForSystematics,
614  Int_t extrapMode, Double_t clusterResNB[10], Double_t clusterResB[10],
615  Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
616  Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200])
617 {
619 
620  // Create the analysis manager
621  AliAnalysisManager *mgr = new AliAnalysisManager("MuonResolutionAnalysis");
622  //mgr->SetNSysInfo(100);
623  //mgr->SetDebugLevel(3);
624 
625  // ESD input handler
626  AliESDInputHandler* esdH = new AliESDInputHandler();
627  esdH->SetReadFriends(kFALSE);
628  esdH->SetInactiveBranches("*");
629  esdH->SetActiveBranches("MuonTracks MuonClusters MuonPads AliESDRun. AliESDHeader. AliMultiplicity. AliESDFMD. AliESDVZERO. SPDVertex. PrimaryVertex. AliESDZDC.");
630  mgr->SetInputEventHandler(esdH);
631 
632  // event selection
633  UInt_t eventSelectionMask = 0;
634  if (selectPhysics) {
635  gROOT->LoadMacro("$ALICE_PHYSICS/OADB/macros/AddTaskPhysicsSelection.C");
636  AliPhysicsSelectionTask* physicsSelection = reinterpret_cast<AliPhysicsSelectionTask*>(gROOT->ProcessLineSync(TString::Format("AddTaskPhysicsSelection(%d)", isMC)));
637  if (!physicsSelection) {
638  Error("CreateAnalysisTrain","AliPhysicsSelectionTask not created!");
639  return 0x0;
640  }
641  //if (!isMC) physicsSelection->GetPhysicsSelection()->SetUseBXNumbers(kFALSE); // Needed to merge runs with different running scheme
642  eventSelectionMask |= AliMuonEventCuts::kPhysicsSelected;
643  }
644  if (selectTrigger) eventSelectionMask |= AliMuonEventCuts::kSelectedTrig;
645 
646  // multiplicity/centrality selection
647  gROOT->LoadMacro("$ALICE_PHYSICS/OADB/COMMON/MULTIPLICITY/macros/AddTaskMultSelection.C");
648  AliMultSelectionTask *mult = reinterpret_cast<AliMultSelectionTask*>(gROOT->ProcessLineSync("AddTaskMultSelection()"));
649  if (!mult) {
650  Error("CreateAnalysisTrain","AliMultSelectionTask not created!");
651  return 0x0;
652  }
653 // mult->SetAlternateOADBforEstimators("LHC15o");
654 
655  // Muon Resolution analysis
656  TString outputFileName = Form("chamberResolution_step%d.root", iStep);
657  AliAnalysisManager::SetCommonFileName(outputFileName.Data());
658  AliAnalysisTaskMuonResolution *muonResolution = AddTaskMuonResolution(minMomentum, minPt, correctForSystematics, extrapMode);
659  if (!muonResolution) {
660  Error("CreateAnalysisTrain","AliAnalysisTaskMuonResolution not created!");
661  return 0x0;
662  }
663  /*if (mode == kLocal) muonResolution->SetDefaultStorage("local://$ALIROOT_OCDB_ROOT/OCDB");
664  else muonResolution->SetDefaultStorage("raw://");*/
665  muonResolution->SetDefaultStorage("raw://");
666 // muonResolution->SetDefaultStorage("local:///cvmfs/alice-ocdb.cern.ch/calibration/data/2017/OCDB");
667  if (mode != kProof) muonResolution->ShowProgressBar();
668  muonResolution->PrintClusterRes(kTRUE, kTRUE);
669  muonResolution->SetStartingResolution(clusterResNB, clusterResB);
670  muonResolution->RemoveMonoCathodClusters(kTRUE, kFALSE);
671 // muonResolution->FitResiduals(kFALSE);
672 // muonResolution->ImproveTracks(kTRUE);
673 // muonResolution->ReAlign("", 1, -1, "alien://folder=/alice/cern.ch/user/h/hupereir/CDB/LHC17g_realign");
674 // muonResolution->ReAlign("", 1, 0, "");
675 // muonResolution->SetAlignStorage("", 1);
676 // muonResolution->SetMuonSign(-1);
677 // muonResolution->UseMCLabel();
678 
679  if (shiftHalfCh) {
680  muonResolution->SetHalfChShift(halfChShiftNB, halfChShiftB);
681  muonResolution->ShiftHalfCh();
682  muonResolution->PrintHalfChShift();
683  }
684  if (shiftDE) {
685  muonResolution->SetDEShift(deShiftNB, deShiftB);
686  muonResolution->ShiftDE();
687  muonResolution->PrintDEShift();
688  }
689 
690  if (eventSelectionMask != 0) {
691  AliMuonEventCuts eventCuts("muEventCuts", "muEventCuts");
692  eventCuts.SetFilterMask(eventSelectionMask);
693  if (selectPhysics) eventCuts.SetPhysicsSelectionMask(AliVEvent::kAny);
694 // if (selectPhysics) eventCuts.SetPhysicsSelectionMask(AliVEvent::kINT7inMUON);
695 // if (selectPhysics) eventCuts.SetPhysicsSelectionMask(AliVEvent::kMuonUnlikeLowPt7);
696  if (selectTrigger) eventCuts.SetTrigClassPatterns(eventCuts.GetDefaultTrigClassPatterns());
697  muonResolution->SetMuonEventCuts(eventCuts);
698  }
699 
700  UInt_t trackSelectionMask = 0;
701  if (matchTrig) trackSelectionMask |= AliMuonTrackCuts::kMuMatchLpt;
702  if (applyAccCut) trackSelectionMask |= AliMuonTrackCuts::kMuEta | AliMuonTrackCuts::kMuThetaAbs;
703  if (applyPDCACut) trackSelectionMask |= AliMuonTrackCuts::kMuPdca;
704  if (trackSelectionMask != 0) {
705  AliMuonTrackCuts trackCuts("muTrackCuts", "muTrackCuts");
706  trackCuts.SetAllowDefaultParams();
707  if (isMC) trackCuts.SetIsMC();
708  trackCuts.SetFilterMask(trackSelectionMask);
709  muonResolution->SetMuonTrackCuts(trackCuts);
710  }
711 
712  return muonResolution;
713 
714 }
715 
716 //______________________________________________________________________________
717 Bool_t GetChamberResolution(Int_t iStep, Double_t clusterResNB[10], Double_t clusterResB[10], Double_t clusterResNBErr[10], Double_t clusterResBErr[10])
718 {
720 
721  TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"READ");
722 
723  if (!outFile || !outFile->IsOpen()) {
724  Error("GetChamberResolution","output file does not exist!");
725  return kFALSE;
726  }
727 
728  TObjArray* summary = static_cast<TObjArray*>(outFile->FindObjectAny("ChamberRes"));
729  TGraphErrors* gCombinedResidualXPerChSigma = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualXPerChSigma")) : 0x0;
730  TGraphErrors* gCombinedResidualYPerChSigma = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualYPerChSigma")) : 0x0;
731 
732  if (!gCombinedResidualXPerChSigma || !gCombinedResidualYPerChSigma) {
733  Error("GetChamberResolution","resolution graphs do not exist!");
734  return kFALSE;
735  }
736 
737  Double_t dummy;
738  for (Int_t i = 0; i < 10; i++) {
739  gCombinedResidualXPerChSigma->GetPoint(i, dummy, clusterResNB[i]);
740  gCombinedResidualYPerChSigma->GetPoint(i, dummy, clusterResB[i]);
741  clusterResNBErr[i] = gCombinedResidualXPerChSigma->GetErrorY(i);
742  clusterResBErr[i] = gCombinedResidualYPerChSigma->GetErrorY(i);
743  }
744 
745  outFile->Close();
746  //delete outFile;
747 
748  return kTRUE;
749 }
750 
751 //______________________________________________________________________________
752 Bool_t AddHalfChShift(Int_t iStep, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20])
753 {
755 
756  TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"READ");
757 
758  if (!outFile || !outFile->IsOpen()) {
759  Error("AddHalfChShift","output file does not exist!");
760  return kFALSE;
761  }
762 
763  TObjArray* summary = static_cast<TObjArray*>(outFile->FindObjectAny("ChamberRes"));
764  TGraphErrors* gResidualXPerHalfChMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualXPerHalfChMean_ClusterIn")) : 0x0;
765  TGraphErrors* gResidualYPerHalfChMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualYPerHalfChMean_ClusterIn")) : 0x0;
766 
767  if (!gResidualXPerHalfChMean || !gResidualYPerHalfChMean) {
768  Error("AddHalfChShift","half-chamber shift graphs do not exist!");
769  return kFALSE;
770  }
771 
772  Double_t dummy, dx, dy;
773  for (Int_t i = 0; i < 20; i++) {
774  gResidualXPerHalfChMean->GetPoint(i, dummy, dx);
775  halfChShiftNB[i] += dx;
776  halfChShiftNBErr[i] = gResidualXPerHalfChMean->GetErrorY(i);
777  gResidualYPerHalfChMean->GetPoint(i, dummy, dy);
778  halfChShiftB[i] += dy;
779  halfChShiftBErr[i] = gResidualYPerHalfChMean->GetErrorY(i);
780  }
781 
782  outFile->Close();
783  //delete outFile;
784 
785  return kTRUE;
786 }
787 
788 //______________________________________________________________________________
789 Bool_t AddDEShift(Int_t iStep, Double_t deShiftNB[200], Double_t deShiftB[200])
790 {
792 
793  TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"READ");
794 
795  if (!outFile || !outFile->IsOpen()) {
796  Error("AddDEShift","output file does not exist!");
797  return kFALSE;
798  }
799 
800  TObjArray* summary = static_cast<TObjArray*>(outFile->FindObjectAny("ChamberRes"));
801  TGraphErrors* gResidualXPerDEMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualXPerDEMean_ClusterIn")) : 0x0;
802  TGraphErrors* gResidualYPerDEMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualYPerDEMean_ClusterIn")) : 0x0;
803 
804  if (!gResidualXPerDEMean || !gResidualYPerDEMean) {
805  Error("AddDEShift","DE shift graphs do not exist!");
806  return kFALSE;
807  }
808 
809  Double_t dummy, dx, dy;
810  nDE = gResidualXPerDEMean->GetN();
811  for (Int_t i = 0; i < nDE; i++) {
812  gResidualXPerDEMean->GetPoint(i, dummy, dx);
813  deShiftNB[i] += dx;
814  gResidualYPerDEMean->GetPoint(i, dummy, dy);
815  deShiftB[i] += dy;
816  }
817 
818  outFile->Close();
819  //delete outFile;
820 
821  return kTRUE;
822 }
823 
824 //______________________________________________________________________________
825 void AddMCHViews(TString smode, TFile* file)
826 {
828 
829  if ( ! AliMpDDLStore::Instance(false) )
830  {
831  Warning("AddMCHViews","mapping was not loaded. Loading it from OCDB");
832  if (smode == "saf3") AliCDBManager::Instance()->SetDefaultStorage("raw://");
833  else AliCDBManager::Instance()->SetDefaultStorage("local://$ALIROOT_OCDB_ROOT/OCDB");
834  AliCDBManager::Instance()->SetRun(999999999);
835  }
836 
837  AliMpCDB::LoadAll();
838 
839  TObjArray* summary = static_cast<TObjArray*>(file->FindObjectAny("ChamberRes"));
840  if (!summary) {
841  Error("AddMCHViews","resolution graphs do not exist!");
842  return;
843  }
844 
845  TGraphErrors* g = 0x0;
846  g = static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualXPerDESigma"));
847  if (g) {
848  file->cd();
849  AliMUONTrackerData* data = ConvertGraph(*g, "resoX");
850  data->Write();
851  delete data;
852  }
853 
854  g = static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualYPerDESigma"));
855  if (g) {
856  file->cd();
857  AliMUONTrackerData* data = ConvertGraph(*g, "resoY");
858  data->Write();
859  delete data;
860  }
861 
862  g = static_cast<TGraphErrors*>(summary->FindObject("gResidualXPerDEMean_ClusterOut"));
863  if (g) {
864  file->cd();
865  AliMUONTrackerData* data = ConvertGraph(*g, "shiftX");
866  data->Write();
867  delete data;
868  }
869 
870  g = static_cast<TGraphErrors*>(summary->FindObject("gResidualYPerDEMean_ClusterOut"));
871  if (g) {
872  file->cd();
873  AliMUONTrackerData* data = ConvertGraph(*g, "shiftY");
874  data->Write();
875  delete data;
876  }
877 }
878 
879 //______________________________________________________________________________
880 AliMUONTrackerData* ConvertGraph(TGraphErrors& g, const char* name)
881 {
883 
884  AliMUON2DMap deValues(kFALSE);
885 
886  for ( Int_t i = 0 ; i < g.GetN(); ++i )
887  {
888  double y = g.GetY()[i];
889  double ey = g.GetEY()[i];
890  int detElemId;
891  sscanf(g.GetXaxis()->GetBinLabel(i+1),"%d",&detElemId);
892 
893  AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
894 
895  AliMUONVCalibParam* param = new AliMUONCalibParamND(5, 1, detElemId, 0);
896 
897  Double_t sumn = 1000.0;
898  Double_t sumw = sumn*y;
899  Double_t sumw2 = (sumn-1)*ey*ey+sumw*sumw/sumn;
900 
901  param->SetValueAsDouble(0,0,sumw);
902  param->SetValueAsDouble(0,1,sumw2);
903  param->SetValueAsDouble(0,2,sumn);
904  param->SetValueAsDouble(0,3,de->NofChannels());
905  param->SetValueAsDouble(0,4,1);
906 
907  deValues.Add(param);
908  }
909 
910  AliMUONTrackerData* data = new AliMUONTrackerData(name,name,deValues,1);
911  data->SetDimensionName(0,name);
912 
913  return data;
914 }
915 
916 //______________________________________________________________________________
918 {
919  if (smode == "local") {
920  if ( input.EndsWith(".xml") ) return kInteractif_xml;
921  else if ( input.EndsWith(".txt") ) return kInteractif_ESDList;
922  else if ( input.EndsWith(".root") ) return kLocal;
923  } else if (smode == "caf" || smode == "saf" || smode == "saf3") return kProof;
924  else if ((smode == "test" || smode == "offline" || smode == "submit" || smode == "full" ||
925  smode == "merge" || smode == "terminate") && input.EndsWith(".txt")) return kGrid;
926  else if (smode == "terminateonly") return kTerminate;
927  return -1;
928 }
929 
930 //______________________________________________________________________________
931 TChain* CreateChainFromCollection(const char *xmlfile)
932 {
933  // Create a chain from the collection of tags.
934  if (!TGrid::Connect("alien://")) return NULL;
935 
936  TGridCollection* coll = TAlienCollection::Open(xmlfile);
937  if (!coll) {
938  Error("CreateChainFromCollection", "Cannot create the AliEn collection");
939  return NULL;
940  }
941 
942  TGridResult* tagResult = coll->GetGridResult("",kFALSE,kFALSE);
943  AliTagAnalysis *tagAna = new AliTagAnalysis("ESD");
944  tagAna->ChainGridTags(tagResult);
945 
946  AliRunTagCuts *runCuts = new AliRunTagCuts();
947  AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
948  AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
949  AliEventTagCuts *evCuts = new AliEventTagCuts();
950 
951  // Check if the cuts configuration file was provided
952  if (!gSystem->AccessPathName("ConfigureCuts.C"))
953  gROOT->ProcessLine(Form(".x ConfigureCuts.C((AliRunTagCuts*)%p, (AliLHCTagCuts*)%p, (AliDetectorTagCuts*)%p,"
954  " (AliEventTagCuts*)%p)", runCuts, lhcCuts, detCuts, evCuts));
955 
956  TChain *chain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evCuts);
957  if (!chain || !chain->GetNtrees()) return NULL;
958  chain->ls();
959  return chain;
960 }
961 
962 //______________________________________________________________________________
963 TChain* CreateChainFromFile(const char *rootfile)
964 {
965  // Create a chain using the root file.
966  TChain* chain = new TChain("esdTree");
967  chain->Add(rootfile);
968  if (!chain->GetNtrees()) return NULL;
969  chain->ls();
970  return chain;
971 }
972 
973 //______________________________________________________________________________
974 TChain* CreateChainFromESDList(const char *esdList)
975 {
976  // Create a chain using tags from the run list.
977  TChain* chain = new TChain("esdTree");
978  ifstream inFile(esdList);
979  TString inFileName;
980  if (inFile.is_open()) {
981  while (! inFile.eof() ) {
982  inFileName.ReadLine(inFile,kFALSE);
983  if(!inFileName.EndsWith(".root")) continue;
984  chain->Add(inFileName.Data());
985  }
986  }
987  inFile.close();
988  if (!chain->GetNtrees()) return NULL;
989  chain->ls();
990  return chain;
991 }
992 
993 //______________________________________________________________________________
995 {
996  printf("*******************************\n");
997  printf("*** Getting the Chain ***\n");
998  printf("*******************************\n");
999  if(mode == kInteractif_xml) return CreateChainFromCollection(input.Data());
1000  else if (mode == kInteractif_ESDList) return CreateChainFromESDList(input.Data());
1001  else if (mode == kLocal) return CreateChainFromFile(input.Data());
1002  else return NULL;
1003 }
1004 
Bool_t AddDEShift(Int_t iStep, Double_t deShiftNB[200], Double_t deShiftB[200])
void CreateAlienHandler(TString runMode, TString &aliphysicsVersion, TString &runListName, TString &dataDir, TString &dataPattern, TString &outDir, Int_t iStep, TString runFormat, Int_t maxFilesPerJob, Int_t maxMergeFiles, Int_t maxMergeStages)
double Double_t
Definition: External.C:58
Int_t GetMode(TString smode, TString input)
TChain * CreateChain(Int_t mode, TString input)
TSystem * gSystem
void LoadAlirootOnProof(TString &aaf, TString rootVersion, TString aliphysicsVersion, Int_t iStep)
void MuonResolution(TString smode, TString inputFileName, Int_t nSteps, TString rootVersion, TString aliphysicsVersion, TString dataDir, TString dataPattern, TString runFormat, TString outDir, Int_t maxFilesPerJob, Int_t maxMergeFiles, Int_t maxMergeStages, Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig, Bool_t applyAccCut, Bool_t applyPDCACut, Double_t minMomentum, Double_t minPt, Bool_t isMC, Bool_t correctForSystematics, Int_t extrapMode, Bool_t shiftHalfCh, Bool_t shiftDE, Int_t nevents)
TChain * CreateChainFromESDList(const char *esdList)
TObjArray * GetCanvases()
return the list of summary canvases
Bool_t GetChamberResolution(Int_t iStep, Double_t clusterResNB[10], Double_t clusterResB[10], Double_t clusterResNBErr[10], Double_t clusterResBErr[10])
Int_t nDE
TChain * CreateChainFromCollection(const char *xmlfile)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
AliAnalysisTaskMuonResolution * AddTaskMuonResolution(Double_t minMomentum=0., Double_t minPt=0., Bool_t correctForSystematics=kTRUE, Int_t extrapMode=1)
Int_t mode
Definition: anaM.C:41
void GetHalfChShift(Double_t valNB[20], Double_t valB[20]) const
void AddMCHViews(TString smode, TFile *file)
void GetStartingResolution(Double_t valNB[10], Double_t valB[10]) const
Bool_t isMC
TChain * CreateChainFromFile(const char *rootfile)
Muon spectrometer resolution.
TFile * file
TList with histograms for a given trigger.
Int_t nevents[nsamples]
Bool_t AddHalfChShift(Int_t iStep, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20])
bool Bool_t
Definition: External.C:53
Bool_t Resume(Int_t mode, Int_t &firstStep, Double_t clusterResNB[10], Double_t clusterResB[10], Double_t clusterResNBErr[10], Double_t clusterResBErr[10], Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20], Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200], TGraphErrors *clusterResXVsStep[10], TGraphErrors *clusterResYVsStep[10], TGraphErrors *halfChShiftXVsStep[20], TGraphErrors *halfChShiftYVsStep[20])
void GetDEShift(Double_t valNB[200], Double_t valB[200]) const
AliAnalysisTaskMuonResolution * CreateAnalysisTrain(Int_t mode, Int_t iStep, Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig, Bool_t applyAccCut, Bool_t applyPDCACut, Double_t minMomentum, Double_t minPt, Bool_t isMC, Bool_t correctForSystematics, Int_t extrapMode, Double_t clusterResNB[10], Double_t clusterResB[10], Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200])
AliMUONTrackerData * ConvertGraph(TGraphErrors &g, const char *name)