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
5 // Author: Philippe Pillot - SUBATECH Nantes
6 //--------------------------------------------------------------------------
8 #if !defined(__CINT__) || defined(__MAKECINT__)
12 #include <TStopwatch.h>
13 #include <TMultiGraph.h>
16 #include <TGraphErrors.h>
25 #include "THashList.h"
26 #include <TAlienCollection.h>
27 #include <TGridCollection.h>
28 #include <TGridResult.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 "AliPhysicsSelectionTask.h"
41 #include "AliPhysicsSelection.h"
42 #include "AliBackgroundSelection.h"
43 #include "AliCentralitySelectionTask.h"
44 #include "AliAnalysisDataContainer.h"
45 #include "AliAnalysisTaskMuonResolution.h"
49 #include "AliMpDetElement.h"
50 #include "AliMpDDLStore.h"
51 #include "AliMUONCalibParamND.h"
52 #include "AliMUON2DMap.h"
53 #include "AliMUONTrackerData.h"
54 #include "AliMUONPainterDataRegistry.h"
55 #include "AliMUONTrackerDataWrapper.h"
57 #include "AliMuonTrackCuts.h"
59 #include "AddTaskMuonResolution.C"
63 enum {kLocal, kInteractif_xml, kInteractif_ESDList, kProof};
66 Bool_t Resume(Int_t &firstStep, Double_t clusterResNB[10], Double_t clusterResB[10],
67 Double_t clusterResNBErr[10], Double_t clusterResBErr[10],
68 Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
69 Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20],
70 Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200],
71 TGraphErrors* clusterResXVsStep[10], TGraphErrors* clusterResYVsStep[10],
72 TGraphErrors* halfChShiftXVsStep[20], TGraphErrors* halfChShiftYVsStep[20]);
73 void LoadAlirootOnProof(TString& aaf, TString rootVersion, TString alirootVersion, TString& extraLibs, Int_t iStep);
74 AliAnalysisTaskMuonResolution* CreateAnalysisTrain(Int_t mode, Int_t iStep, Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig,
75 Bool_t applyAccCut, Double_t minMomentum, Bool_t correctForSystematics, Int_t extrapMode,
76 Double_t clusterResNB[10], Double_t clusterResB[10],
77 Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
78 Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200]);
79 Bool_t GetChamberResolution(Int_t iStep, Double_t clusterResNB[10], Double_t clusterResB[10],
80 Double_t clusterResNBErr[10], Double_t clusterResBErr[10]);
81 Bool_t AddHalfChShift(Int_t iStep, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20]);
82 Bool_t AddDEShift(Int_t iStep, Double_t deShiftNB[200], Double_t deShiftB[200]);
83 void AddMCHViews(TFile* file);
84 AliMUONTrackerData* ConvertGraph(TGraphErrors& g, const char* name);
85 Int_t GetMode(TString smode, TString input);
86 TChain* CreateChainFromCollection(const char *xmlfile);
87 TChain* CreateChainFromFile(const char *rootfile);
88 TChain* CreateChainFromESDList(const char *esdList);
89 TChain* CreateChain(Int_t mode, TString input);
91 //______________________________________________________________________________
92 void MuonResolution(TString smode, TString inputFileName, TString rootVersion, TString alirootVersion, Int_t nSteps,
93 Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig, Bool_t applyAccCut,
94 Double_t minMomentum, Bool_t correctForSystematics, Int_t extrapMode,
95 Bool_t shiftHalfCh, Bool_t shiftDE, Int_t nevents, TString extraLibs)
97 /// Compute the cluster resolution by studying cluster-track residual, deconvoluting from track resolution
100 TStopwatch* localTimer = new TStopwatch;
103 nSteps = TMath::Max(nSteps,1);
104 if (extrapMode != 0 && extrapMode != 1) {
105 Error("MuonResolution","incorrect extrapolation mode!");
110 Int_t mode = GetMode(smode, inputFileName);
112 Error("MuonResolution","Please provide either an ESD root file, a list of ESDs, a collection of ESDs or a dataset.");
116 // set starting chamber resolution (if -1 they will be loaded from recoParam in the task)
117 Double_t clusterResNB[10] = {-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.};
118 Double_t clusterResB[10] = {-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.};
119 Double_t clusterResNBErr[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
120 Double_t clusterResBErr[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
121 Double_t halfChShiftNB[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
122 Double_t halfChShiftB[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
123 Double_t halfChShiftNBErr[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
124 Double_t halfChShiftBErr[20] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
125 Double_t deShiftNB[200];
126 Double_t deShiftB[200];
127 for (Int_t i=0; i<200; i++) {
133 TMultiGraph* mgClusterResXVsStep = new TMultiGraph("mgClusterResXVsStep","cluster X-resolution versus step;step;#sigma_{X} (cm)");
134 TMultiGraph* mgClusterResYVsStep = new TMultiGraph("mgClusterResYVsStep","cluster Y-resolution versus step;step;#sigma_{Y} (cm)");
135 TGraphErrors* clusterResXVsStep[10];
136 TGraphErrors* clusterResYVsStep[10];
137 for (Int_t i = 0; i < 10; i++) {
138 clusterResXVsStep[i] = new TGraphErrors(nSteps+1);
139 clusterResXVsStep[i]->SetName(Form("gResX_ch%d",i+1));
140 clusterResXVsStep[i]->SetMarkerStyle(kFullDotMedium);
141 clusterResXVsStep[i]->SetMarkerColor(i+1+i/9);
142 mgClusterResXVsStep->Add(clusterResXVsStep[i],"lp");
144 clusterResYVsStep[i] = new TGraphErrors(nSteps+1);
145 clusterResYVsStep[i]->SetName(Form("gResY_ch%d",i+1));
146 clusterResYVsStep[i]->SetMarkerStyle(kFullDotMedium);
147 clusterResYVsStep[i]->SetMarkerColor(i+1+i/9);
148 mgClusterResYVsStep->Add(clusterResYVsStep[i],"lp");
150 TMultiGraph* mgHalfChShiftXVsStep = new TMultiGraph("mgHalfChShiftXVsStep","half-chamber displacement in X direction versus step;step;#Delta_{X} (cm)");
151 TMultiGraph* mgHalfChShiftYVsStep = new TMultiGraph("mgHalfChShiftYVsStep","half-chamber displacement in Y direction versus step;step;#Delta_{Y} (cm)");
152 TGraphErrors* halfChShiftXVsStep[20];
153 TGraphErrors* halfChShiftYVsStep[20];
154 for (Int_t i = 0; i < 20; i++) {
155 halfChShiftXVsStep[i] = new TGraphErrors(nSteps+1);
156 halfChShiftXVsStep[i]->SetName(Form("gShiftX_hch%d",i+1));
157 halfChShiftXVsStep[i]->SetMarkerStyle(kFullDotMedium);
158 halfChShiftXVsStep[i]->SetMarkerColor(i+1+i/9+i/18);
159 mgHalfChShiftXVsStep->Add(halfChShiftXVsStep[i],"lp");
160 halfChShiftXVsStep[i]->SetPoint(0, 0, halfChShiftNB[i]);
161 halfChShiftXVsStep[i]->SetPointError(0, 0., halfChShiftNBErr[i]);
163 halfChShiftYVsStep[i] = new TGraphErrors(nSteps+1);
164 halfChShiftYVsStep[i]->SetName(Form("gShiftY_hch%d",i+1));
165 halfChShiftYVsStep[i]->SetMarkerStyle(kFullDotMedium);
166 halfChShiftYVsStep[i]->SetMarkerColor(i+1+i/9+i/18);
167 mgHalfChShiftYVsStep->Add(halfChShiftYVsStep[i],"lp");
168 halfChShiftYVsStep[i]->SetPoint(0, 0, halfChShiftB[i]);
169 halfChShiftYVsStep[i]->SetPointError(0, 0., halfChShiftBErr[i]);
172 // check for old output files
175 if (!gSystem->Exec("ls chamberResolution_step*[0-9].root")) {
176 cout<<"Above files already exist in the current directory. [d=delete, r=resume, e=exit] "<<flush;
177 while (remove != 'd' && remove != 'r' && remove != 'e') cin>>remove;
178 if (remove == 'y') gSystem->Exec("rm -f chamberResolution_step*[0-9].root");
179 else if (remove == 'r' && !Resume(firstStep, clusterResNB, clusterResB, clusterResNBErr, clusterResBErr,
180 shiftHalfCh, halfChShiftNB, halfChShiftB, halfChShiftNBErr, halfChShiftBErr,
181 shiftDE, deShiftNB, deShiftB, clusterResXVsStep, clusterResYVsStep,
182 halfChShiftXVsStep, halfChShiftYVsStep)) return;
183 else if (remove == 'e') return;
186 // Create input object
187 TObject* inputObj = 0x0;
188 if (mode == kProof) inputObj = new TObjString(inputFileName);
189 else inputObj = CreateChain(mode, inputFileName);
190 if (!inputObj) return;
193 for (Int_t iStep = firstStep; iStep < nSteps; iStep++) {
194 cout<<"step "<<iStep+1<<"/"<<nSteps<<endl;
196 // Connect to proof if needed and prepare environment
197 if (mode == kProof) LoadAlirootOnProof(smode, rootVersion, alirootVersion, extraLibs, iStep-firstStep);
199 // create the analysis train
200 AliAnalysisTaskMuonResolution *muonResolution = CreateAnalysisTrain(mode, iStep, selectPhysics, selectTrigger,
201 matchTrig, applyAccCut, minMomentum, correctForSystematics,
202 extrapMode, clusterResNB, clusterResB, shiftHalfCh,
203 halfChShiftNB, halfChShiftB, shiftDE, deShiftNB, deShiftB);
204 if (!muonResolution) return;
207 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
208 if (mgr->InitAnalysis()) {
210 if (mode == kProof) mgr->StartAnalysis("proof", static_cast<TObjString*>(inputObj)->GetName(), nevents);
211 else mgr->StartAnalysis("local", static_cast<TChain*>(inputObj), nevents);
214 // save the summary canvases and mchview display
215 if (muonResolution->GetCanvases()) {
216 TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"UPDATE");
217 if (outFile && outFile->IsOpen()) {
219 muonResolution->GetCanvases()->Write();
220 AddMCHViews(outFile);
226 // fill graphs with starting resolutions from the task at very first step
228 muonResolution->GetStartingResolution(clusterResNB, clusterResB);
229 for (Int_t i = 0; i < 10; i++) {
230 clusterResXVsStep[i]->SetPoint(0, 0, clusterResNB[i]);
231 clusterResXVsStep[i]->SetPointError(0, 0., clusterResNBErr[i]);
232 clusterResYVsStep[i]->SetPoint(0, 0, clusterResB[i]);
233 clusterResYVsStep[i]->SetPointError(0, 0., clusterResBErr[i]);
237 // read the chamber resolution from the output file
238 if (!GetChamberResolution(iStep, clusterResNB, clusterResB, clusterResNBErr, clusterResBErr)) return;
240 // fill graphs with computed resolutions
241 for (Int_t i = 0; i < 10; i++) {
242 clusterResXVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResNB[i]);
243 clusterResXVsStep[i]->SetPointError(iStep+1, 0., clusterResNBErr[i]);
244 clusterResYVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResB[i]);
245 clusterResYVsStep[i]->SetPointError(iStep+1, 0., clusterResBErr[i]);
248 // get the half-chamber displacements currently used and add the new measurements from the output file
249 muonResolution->GetHalfChShift(halfChShiftNB, halfChShiftB);
250 if (!AddHalfChShift(iStep, halfChShiftNB, halfChShiftB, halfChShiftNBErr, halfChShiftBErr)) return;
252 // fill graphs with computed displacements
253 for (Int_t i = 0; i < 20; i++) {
254 halfChShiftXVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftNB[i]);
255 halfChShiftXVsStep[i]->SetPointError(iStep+1, 0., halfChShiftNBErr[i]);
256 halfChShiftYVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftB[i]);
257 halfChShiftYVsStep[i]->SetPointError(iStep+1, 0., halfChShiftBErr[i]);
260 // get the DE displacements currently used and add the new measurements from the output file
261 muonResolution->GetDEShift(deShiftNB, deShiftB);
262 if (!AddDEShift(iStep, deShiftNB, deShiftB)) return;
265 mgr->SetAnalysisType(AliAnalysisManager::kLocalAnalysis); // to make sure that all output containers are deleted
267 TObject::SetObjectStat(kFALSE);
271 // copy final results in results.root file
272 gSystem->Exec(Form("cp chamberResolution_step%d.root results.root", nSteps-1));
274 // display convergence of cluster resolution
275 TCanvas* convergence1 = new TCanvas("convergenceRes","convergence of cluster resolution");
276 convergence1->Divide(1,2);
278 mgClusterResXVsStep->Draw("ap");
280 mgClusterResYVsStep->Draw("ap");
282 // display convergence of half-chamber displacements
283 TCanvas* convergence2 = new TCanvas("convergenceShift","convergence of half-chamber displacements");
284 convergence2->Divide(1,2);
286 mgHalfChShiftXVsStep->Draw("ap");
288 mgHalfChShiftYVsStep->Draw("ap");
290 // save convergence plots
291 TFile* outFile = TFile::Open("results.root","UPDATE");
292 if (!outFile || !outFile->IsOpen()) return;
294 mgClusterResXVsStep->Write();
295 mgClusterResYVsStep->Write();
296 convergence1->Write();
297 mgHalfChShiftXVsStep->Write();
298 mgHalfChShiftYVsStep->Write();
299 convergence2->Write();
303 // print final half-chamber displacements
304 printf("\nhalf-chamber total displacements:\n");
305 printf(" - non-bending:");
306 for (Int_t i = 0; i < 20; i++) printf((i==0)?" %6.4f":", %6.4f", halfChShiftNB[i]);
307 printf("\n - bending:");
308 for (Int_t i = 0; i < 20; i++) printf((i==0)?" %6.4f":", %6.4f", halfChShiftB[i]);
311 // print final DE displacements
312 printf("\nDE total displacements:\n");
313 printf(" - non-bending:");
314 for (Int_t i = 0; i < nDE; i++) printf((i==0)?" %6.4f":", %6.4f", deShiftNB[i]);
315 printf("\n - bending:");
316 for (Int_t i = 0; i < nDE; i++) printf((i==0)?" %6.4f":", %6.4f", deShiftB[i]);
326 //______________________________________________________________________________
327 Bool_t Resume(Int_t &firstStep, Double_t clusterResNB[10], Double_t clusterResB[10],
328 Double_t clusterResNBErr[10], Double_t clusterResBErr[10],
329 Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
330 Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20],
331 Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200],
332 TGraphErrors* clusterResXVsStep[10], TGraphErrors* clusterResYVsStep[10],
333 TGraphErrors* halfChShiftXVsStep[20], TGraphErrors* halfChShiftYVsStep[20])
335 /// resume analysis from desired step
339 // Get the step to restart from
340 cout<<"From which step (included) you want to resume? [#, e=exit] "<<flush;
342 do {step.Gets(stdin,kTRUE);} while (!step.IsDigit() && step != "e");
343 if (step == "e") return kFALSE;
344 firstStep = step.Atoi();
346 // restart from scratch if requested
347 if (firstStep == 0) {
348 gSystem->Exec("rm -f chamberResolution_step*[0-9].root");
352 // look for results from the previous step
353 if (gSystem->AccessPathName(Form("chamberResolution_step%d.root", firstStep-1))) {
354 cout<<"No result found from the previous step ("<<firstStep-1<<"). Unable to resume from step "<<firstStep<<endl;
358 // fill graph with starting resolutions
359 for (Int_t i = 0; i < 10; i++) {
360 clusterResXVsStep[i]->SetPoint(0, 0, clusterResNB[i]);
361 clusterResXVsStep[i]->SetPointError(0, 0., clusterResNBErr[i]);
362 clusterResYVsStep[i]->SetPoint(0, 0, clusterResB[i]);
363 clusterResYVsStep[i]->SetPointError(0, 0., clusterResBErr[i]);
366 // loop over previous steps
367 Bool_t missingInfo = kFALSE;
368 for (Int_t iStep = 0; iStep < firstStep; iStep++) {
370 // read the chamber resolution from the output file
371 if (!GetChamberResolution(iStep, clusterResNB, clusterResB, clusterResNBErr, clusterResBErr) && iStep == firstStep-1) {
376 // fill graphs with computed resolutions
377 for (Int_t i = 0; i < 10; i++) {
378 clusterResXVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResNB[i]);
379 clusterResXVsStep[i]->SetPointError(iStep+1, 0., clusterResNBErr[i]);
380 clusterResYVsStep[i]->SetPoint(iStep+1, iStep+1, clusterResB[i]);
381 clusterResYVsStep[i]->SetPointError(iStep+1, 0., clusterResBErr[i]);
384 // reset the half-chamber displacements if not used and add the new measurements from the output file
385 if (!shiftHalfCh) for (Int_t i=0; i<20; i++) {
386 halfChShiftNB[i] = 0.; halfChShiftB[i] = 0.;
387 halfChShiftNBErr[i] = 0.; halfChShiftBErr[i] = 0.;
389 if (!AddHalfChShift(iStep, halfChShiftNB, halfChShiftB, halfChShiftNBErr, halfChShiftBErr) && shiftHalfCh) {
394 // fill graphs with computed displacements
395 for (Int_t i = 0; i < 20; i++) {
396 halfChShiftXVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftNB[i]);
397 halfChShiftXVsStep[i]->SetPointError(iStep+1, 0., halfChShiftNBErr[i]);
398 halfChShiftYVsStep[i]->SetPoint(iStep+1, iStep+1, halfChShiftB[i]);
399 halfChShiftYVsStep[i]->SetPointError(iStep+1, 0., halfChShiftBErr[i]);
402 // add the new measurements of DE displacements from the output file if in use
403 if (shiftDE && !AddDEShift(iStep, deShiftNB, deShiftB)) {
410 // check if missing important results from previous steps
411 if (missingInfo) continue;
413 // keep previous steps and remove the others
414 gSystem->Exec("mkdir __TMP__");
415 for (Int_t iStep = 0; iStep < firstStep; iStep++)
416 if (!gSystem->AccessPathName(Form("chamberResolution_step%d.root", iStep)))
417 gSystem->Exec(Form("mv chamberResolution_step%d.root __TMP__", iStep));
418 gSystem->Exec("rm -f chamberResolution_step*[0-9].root");
419 gSystem->Exec("mv __TMP__/chamberResolution_step*[0-9].root .");
420 gSystem->Exec("rm -rf __TMP__");
427 //______________________________________________________________________________
428 void LoadAlirootOnProof(TString& aaf, TString rootVersion, TString alirootVersion, TString& extraLibs, Int_t iStep)
430 /// Load aliroot packages and set environment on Proof
432 // set general environment and close previous session
433 if (iStep == 0) gEnv->SetValue("XSec.GSI.DelegProxy","2");
434 else gProof->Close("s");
437 TString location = (aaf == "caf") ? "alice-caf.cern.ch" : "nansafmaster.in2p3.fr"; //"localhost:1093"
438 TString nWorkers = (aaf == "caf") ? "workers=80" : ""; //"workers=3x"
439 TString user = (gSystem->Getenv("alien_API_USER") == NULL) ? "" : Form("%s@",gSystem->Getenv("alien_API_USER"));
440 TProof::Mgr(Form("%s%s",user.Data(), location.Data()))->SetROOTVersion(Form("VO_ALICE@ROOT::%s",rootVersion.Data()));
441 TProof::Open(Form("%s%s/?N",user.Data(), location.Data()), nWorkers.Data());
444 // set environment and load libraries on workers
445 TList* list = new TList();
446 list->Add(new TNamed("ALIROOT_MODE", ""));
447 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", extraLibs.Data()));
448 if (!gSystem->AccessPathName("AliAnalysisTaskMuonResolution.cxx"))
449 list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES", "MUON:MUON/mapping"));
450 gProof->EnablePackage(Form("VO_ALICE@AliRoot::%s",alirootVersion.Data()), list, kTRUE);
452 // compile task on workers
453 if (!gSystem->AccessPathName("AliAnalysisTaskMuonResolution.cxx"))
454 gProof->Load("AliAnalysisTaskMuonResolution.cxx++g", kTRUE);
458 //______________________________________________________________________________
459 AliAnalysisTaskMuonResolution* CreateAnalysisTrain(Int_t mode, Int_t iStep, Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig,
460 Bool_t applyAccCut, Double_t minMomentum, Bool_t correctForSystematics, Int_t extrapMode,
461 Double_t clusterResNB[10], Double_t clusterResB[10],
462 Bool_t shiftHalfCh, Double_t halfChShiftNB[20], Double_t halfChShiftB[20],
463 Bool_t shiftDE, Double_t deShiftNB[200], Double_t deShiftB[200])
465 /// create the analysis train and configure it
467 // Create the analysis manager
468 AliAnalysisManager *mgr = new AliAnalysisManager("MuonResolutionAnalysis");
469 //mgr->SetNSysInfo(100);
472 AliESDInputHandler* esdH = new AliESDInputHandler();
473 esdH->SetReadFriends(kFALSE);
474 esdH->SetInactiveBranches("*");
475 esdH->SetActiveBranches("MuonTracks MuonClusters MuonPads AliESDRun. AliESDHeader. AliMultiplicity. AliESDFMD. AliESDVZERO. SPDVertex. PrimaryVertex. AliESDZDC.");
476 mgr->SetInputEventHandler(esdH);
480 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
481 if (!gROOT->ProcessLineFast("AddTaskPhysicsSelection()")) {
482 Error("CreateAnalysisTrain","AliPhysicsSelectionTask not created!");
487 // centrality selection
488 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
489 if (!gROOT->ProcessLineFast("AddTaskCentrality()")) {
490 Error("CreateAnalysisTrain","AliCentralitySelectionTask not created!");
494 // Muon Resolution analysis
495 TString outputFileName = Form("chamberResolution_step%d.root", iStep);
496 AliAnalysisManager::SetCommonFileName(outputFileName.Data());
497 AliAnalysisTaskMuonResolution *muonResolution = AddTaskMuonResolution(selectPhysics, selectTrigger, matchTrig, applyAccCut, minMomentum, correctForSystematics, extrapMode);
498 if (!muonResolution) {
499 Error("CreateAnalysisTrain","AliAnalysisTaskMuonResolution not created!");
502 /*if (mode == kLocal) muonResolution->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
503 else */muonResolution->SetDefaultStorage("raw://");
504 if (mode != kProof) muonResolution->ShowProgressBar();
505 muonResolution->PrintClusterRes(kTRUE, kTRUE);
506 muonResolution->SetStartingResolution(clusterResNB, clusterResB);
507 muonResolution->RemoveMonoCathodClusters(kTRUE, kFALSE);
508 // muonResolution->FitResiduals(kFALSE);
509 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011","");
510 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align2");
511 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align2");
512 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBVanik");
513 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBJavier");
514 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBVanik2");
515 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBJavier2");
516 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBTest");
517 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBJavierI");
518 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBJavier2St345");
519 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestQuadrant");
520 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_x_CDB");
521 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_x_CDB");
522 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00asCDB");
523 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00asCDB");
524 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_xypxvzyvz_x015y015_CDB");
525 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_xypxvzyvz_x015y015_CDB");
526 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_xypxvzyvz_x010y015_CDB");
527 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_xypxvzyvz_x010y015_CDB");
528 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_gc5_x015y015_fix24zIO_CDB");
529 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/j/jcastill/ReAligni00as_gc5_x015y015_fix24zIO_CDB");
530 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBVanik2St345_B2");
531 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBVanik2St345_B3");
532 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBQuadrant_B2");
533 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/MATFtestCDBQuadrant_B3");
534 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align2bis");
535 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB_BON_woConst");
536 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB_BON_wConst");
537 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB_BON_wConst_v2");
538 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/s/shahoian/CorG4Fresmx05y015");
539 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/s/shahoian/CorG4Gresmx05y015");
540 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011", "alien://folder=/alice/cern.ch/user/s/shahoian/CorG4Gresmx05y015");
541 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/p/ppillot/OCDB_RubenB0");
542 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/CorG4Fresmx05y015_BOff");
543 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/CorG4Fresmx05y015");
544 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/CorG4Gresmx05y015_BOff");
545 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/CorG4Gresmx05y015");
546 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/pbpb11wrk/CorG4Fresmx05y015_pp2PbPb");
547 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "alien://folder=/alice/cern.ch/user/j/jcastill/pp11wrk/CorG4Fresmx05y015_pp2pp");
548 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2011_Align1", "");
549 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/RAi00ab_p1_t1b_CDB");
550 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/RAi00ab_p1_t2b_CDB");
551 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/LHC12h_3ce");
552 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/LHC12h_4cf");
553 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/LHC12h_5cf");
554 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/LHC11Boffp2");
555 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/LHC12h_8dh");
556 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/h/hupereir/CDB/LHC12_ReAlign_0");
557 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/j/jcastill/pp12wrk/LHC12h_8di");
558 // muonResolution->ReAlign("", "alien://folder=/alice/cern.ch/user/h/hupereir/CDB/LHC12_ReAlign_new_0");
559 // muonResolution->ReAlign("alien://folder=/alice/cern.ch/user/p/ppillot/OCDB2012", "alien://folder=/alice/cern.ch/user/h/hupereir/CDB/LHC12_ReAlign_new_1");
561 muonResolution->SetAlignStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
564 muonResolution->SetHalfChShift(halfChShiftNB, halfChShiftB);
565 muonResolution->ShiftHalfCh();
566 muonResolution->PrintHalfChShift();
569 muonResolution->SetDEShift(deShiftNB, deShiftB);
570 muonResolution->ShiftDE();
571 muonResolution->PrintDEShift();
573 // muonResolution->ImproveTracks(kTRUE);
574 AliMuonTrackCuts trackCuts("stdCuts", "stdCuts");
575 trackCuts.SetAllowDefaultParams();
577 trackCuts.SetFilterMask(AliMuonTrackCuts::kMuPdca);
578 muonResolution->SetMuonTrackCuts(trackCuts);
580 return muonResolution;
584 //______________________________________________________________________________
585 Bool_t GetChamberResolution(Int_t iStep, Double_t clusterResNB[10], Double_t clusterResB[10], Double_t clusterResNBErr[10], Double_t clusterResBErr[10])
587 /// read the chamber resolution from the output file
589 TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"READ");
591 if (!outFile || !outFile->IsOpen()) {
592 Error("GetChamberResolution","output file does not exist!");
596 TObjArray* summary = static_cast<TObjArray*>(outFile->FindObjectAny("ChamberRes"));
597 TGraphErrors* gCombinedResidualXPerChSigma = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualXPerChSigma")) : 0x0;
598 TGraphErrors* gCombinedResidualYPerChSigma = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualYPerChSigma")) : 0x0;
600 if (!gCombinedResidualXPerChSigma || !gCombinedResidualYPerChSigma) {
601 Error("GetChamberResolution","resolution graphs do not exist!");
606 for (Int_t i = 0; i < 10; i++) {
607 gCombinedResidualXPerChSigma->GetPoint(i, dummy, clusterResNB[i]);
608 gCombinedResidualYPerChSigma->GetPoint(i, dummy, clusterResB[i]);
609 clusterResNBErr[i] = gCombinedResidualXPerChSigma->GetErrorY(i);
610 clusterResBErr[i] = gCombinedResidualYPerChSigma->GetErrorY(i);
619 //______________________________________________________________________________
620 Bool_t AddHalfChShift(Int_t iStep, Double_t halfChShiftNB[20], Double_t halfChShiftB[20], Double_t halfChShiftNBErr[20], Double_t halfChShiftBErr[20])
622 /// read the chamber resolution from the output file
624 TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"READ");
626 if (!outFile || !outFile->IsOpen()) {
627 Error("AddHalfChShift","output file does not exist!");
631 TObjArray* summary = static_cast<TObjArray*>(outFile->FindObjectAny("ChamberRes"));
632 TGraphErrors* gResidualXPerHalfChMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualXPerHalfChMean_ClusterIn")) : 0x0;
633 TGraphErrors* gResidualYPerHalfChMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualYPerHalfChMean_ClusterIn")) : 0x0;
635 if (!gResidualXPerHalfChMean || !gResidualYPerHalfChMean) {
636 Error("AddHalfChShift","half-chamber shift graphs do not exist!");
640 Double_t dummy, dx, dy;
641 for (Int_t i = 0; i < 20; i++) {
642 gResidualXPerHalfChMean->GetPoint(i, dummy, dx);
643 halfChShiftNB[i] += dx;
644 halfChShiftNBErr[i] = gResidualXPerHalfChMean->GetErrorY(i);
645 gResidualYPerHalfChMean->GetPoint(i, dummy, dy);
646 halfChShiftB[i] += dy;
647 halfChShiftBErr[i] = gResidualYPerHalfChMean->GetErrorY(i);
656 //______________________________________________________________________________
657 Bool_t AddDEShift(Int_t iStep, Double_t deShiftNB[200], Double_t deShiftB[200])
659 /// read the chamber resolution from the output file
661 TFile* outFile = TFile::Open(Form("chamberResolution_step%d.root", iStep),"READ");
663 if (!outFile || !outFile->IsOpen()) {
664 Error("AddDEShift","output file does not exist!");
668 TObjArray* summary = static_cast<TObjArray*>(outFile->FindObjectAny("ChamberRes"));
669 TGraphErrors* gResidualXPerDEMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualXPerDEMean_ClusterIn")) : 0x0;
670 TGraphErrors* gResidualYPerDEMean = (summary) ? static_cast<TGraphErrors*>(summary->FindObject("gResidualYPerDEMean_ClusterIn")) : 0x0;
672 if (!gResidualXPerDEMean || !gResidualYPerDEMean) {
673 Error("AddDEShift","DE shift graphs do not exist!");
677 Double_t dummy, dx, dy;
678 nDE = gResidualXPerDEMean->GetN();
679 for (Int_t i = 0; i < nDE; i++) {
680 gResidualXPerDEMean->GetPoint(i, dummy, dx);
682 gResidualYPerDEMean->GetPoint(i, dummy, dy);
692 //______________________________________________________________________________
693 void AddMCHViews(TFile* file)
695 /// Get from the file the graphs containing data per DE, convert them into mchview objects and save them
697 if ( ! AliMpDDLStore::Instance(false) )
699 Warning("AddMCHViews","mapping was not loaded. Loading it from $ALICE_ROOT/OCDB");
700 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
701 AliCDBManager::Instance()->SetRun(999999999);
706 TObjArray* summary = static_cast<TObjArray*>(file->FindObjectAny("ChamberRes"));
708 Error("AddMCHViews","resolution graphs do not exist!");
712 TGraphErrors* g = 0x0;
713 g = static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualXPerDESigma"));
716 AliMUONTrackerData* data = ConvertGraph(*g, "resoX");
721 g = static_cast<TGraphErrors*>(summary->FindObject("gCombinedResidualYPerDESigma"));
724 AliMUONTrackerData* data = ConvertGraph(*g, "resoY");
729 g = static_cast<TGraphErrors*>(summary->FindObject("gResidualXPerDEMean_ClusterOut"));
732 AliMUONTrackerData* data = ConvertGraph(*g, "shiftX");
737 g = static_cast<TGraphErrors*>(summary->FindObject("gResidualYPerDEMean_ClusterOut"));
740 AliMUONTrackerData* data = ConvertGraph(*g, "shiftY");
746 //______________________________________________________________________________
747 AliMUONTrackerData* ConvertGraph(TGraphErrors& g, const char* name)
749 /// Convert graph containing data per DE into mchview object
751 AliMUON2DMap deValues(kFALSE);
753 for ( Int_t i = 0 ; i < g.GetN(); ++i )
755 double y = g.GetY()[i];
756 double ey = g.GetEY()[i];
758 sscanf(g.GetXaxis()->GetBinLabel(i+1),"%d",&detElemId);
760 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
762 AliMUONVCalibParam* param = new AliMUONCalibParamND(5, 1, detElemId, 0);
764 Double_t sumn = 1000.0;
765 Double_t sumw = sumn*y;
766 Double_t sumw2 = (sumn-1)*ey*ey+sumw*sumw/sumn;
768 param->SetValueAsDouble(0,0,sumw);
769 param->SetValueAsDouble(0,1,sumw2);
770 param->SetValueAsDouble(0,2,sumn);
771 param->SetValueAsDouble(0,3,de->NofChannels());
772 param->SetValueAsDouble(0,4,1);
777 AliMUONTrackerData* data = new AliMUONTrackerData(name,name,deValues,1);
778 data->SetDimensionName(0,name);
783 //______________________________________________________________________________
784 Int_t GetMode(TString smode, TString input)
786 if (smode == "local") {
787 if ( input.EndsWith(".xml") ) return kInteractif_xml;
788 else if ( input.EndsWith(".txt") ) return kInteractif_ESDList;
789 else if ( input.EndsWith(".root") ) return kLocal;
790 } else if (smode == "caf" || smode == "saf") return kProof;
794 //______________________________________________________________________________
795 TChain* CreateChainFromCollection(const char *xmlfile)
797 // Create a chain from the collection of tags.
798 if (!TGrid::Connect("alien://")) return NULL;
800 TGridCollection* coll = TAlienCollection::Open(xmlfile);
802 Error("CreateChainFromCollection", "Cannot create the AliEn collection");
806 TGridResult* tagResult = coll->GetGridResult("",kFALSE,kFALSE);
807 AliTagAnalysis *tagAna = new AliTagAnalysis("ESD");
808 tagAna->ChainGridTags(tagResult);
810 AliRunTagCuts *runCuts = new AliRunTagCuts();
811 AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
812 AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
813 AliEventTagCuts *evCuts = new AliEventTagCuts();
815 // Check if the cuts configuration file was provided
816 if (!gSystem->AccessPathName("ConfigureCuts.C"))
817 gROOT->ProcessLine(Form(".x ConfigureCuts.C((AliRunTagCuts*)%p, (AliLHCTagCuts*)%p, (AliDetectorTagCuts*)%p,"
818 " (AliEventTagCuts*)%p)", runCuts, lhcCuts, detCuts, evCuts));
820 TChain *chain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evCuts);
821 if (!chain || !chain->GetNtrees()) return NULL;
826 //______________________________________________________________________________
827 TChain* CreateChainFromFile(const char *rootfile)
829 // Create a chain using the root file.
830 TChain* chain = new TChain("esdTree");
831 chain->Add(rootfile);
832 if (!chain->GetNtrees()) return NULL;
837 //______________________________________________________________________________
838 TChain* CreateChainFromESDList(const char *esdList)
840 // Create a chain using tags from the run list.
841 TChain* chain = new TChain("esdTree");
842 ifstream inFile(esdList);
844 if (inFile.is_open()) {
845 while (! inFile.eof() ) {
846 inFileName.ReadLine(inFile,kFALSE);
847 if(!inFileName.EndsWith(".root")) continue;
848 chain->Add(inFileName.Data());
852 if (!chain->GetNtrees()) return NULL;
857 //______________________________________________________________________________
858 TChain* CreateChain(Int_t mode, TString input)
860 printf("*******************************\n");
861 printf("*** Getting the Chain ***\n");
862 printf("*******************************\n");
863 if(mode == kInteractif_xml) return CreateChainFromCollection(input.Data());
864 else if (mode == kInteractif_ESDList) return CreateChainFromESDList(input.Data());
865 else if (mode == kLocal) return CreateChainFromFile(input.Data());