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