9fb3f010ca04f4668d284ab01e35c43924229a7a
[u/mrichter/AliRoot.git] / PWGPP / EVCHAR / runProofSPDdNdEta.C
1 void runProofSPDdNdEta_CorrRef4(
2                        TString  proofCluster  = "mnicassi@alice-caf.cern.ch", //skaf.saske.sk",
3                        TString  alirootVer    = "VO_ALICE@AliRoot::v4-21-04-AN", 
4                        TString  rootVer       = "VO_ALICE@ROOT::v5-27-06a-1",
5 //                     TString  dataset       = "/alice/data/LHC10h_000137161_p1_plusplusplus", 
6                        TString  dataset       = "/alice/sim/LHC10h8_000137161",
7                        TString  outFileCorr   = "SPDdNdEtaCorr.root",
8 //                       TString  outFileCorr   = "SPDdNdEtaCorrRot.root",
9                        TString  outFileData   = "SPDdNdEtaData.root",
10                        TString  percentFile   = "./AliCentralityBy1D_LHC10g2a_100.root",
11                        TString  percentFile2  = "./AliCentralityByFunction_LHC10g2a_100.root",
12                        Bool_t   useMC         = kTRUE, 
13                        Bool_t   readtr        = kFALSE, 
14                        Bool_t   recotracklets = kTRUE, 
15                        Bool_t   dataonalien   = kFALSE,
16                        Float_t  centrlowlim   = 0., 
17                        Float_t  centruplim    = 5., 
18                        Bool_t   centrest      = kFALSE,
19                        Int_t    minClMultLay2 = 4300, 
20 //                       Int_t    minClMultLay2 = -1,  
21                        Int_t    maxClMultLay2 = 1.0*1e5, 
22                        Int_t    minV0Mult     = 14674.5,
23                        Float_t vtxlim         = 7.,
24                        Bool_t partsp          = kTRUE, 
25                        Float_t  phiWindow     = 0.8,
26                        Float_t  thetaWindow   = 0.025,
27                        Float_t  phiShift      = 0.0045,
28                        Float_t  removeClFOvl  = kFALSE,
29                        Float_t  phiOvlCut     = 0.005,
30                        Float_t  zetaOvlCut    = 0.05,
31                        Float_t  phiRotAngle   = 0.,  
32 //                       Float_t  phiRotAngle   = TMath::Pi(),
33                        Float_t  phiWindowAna  = 0.08,
34                        Int_t    nEvents       = 1.0*1e7, 
35                        Int_t    nEventsSkip   = 0) { //1.0*1e7
36
37   gEnv->SetValue("XSec.GSI.DelegProxy","2");
38
39   TString alirootMode = "";    // STEERBase,ESD,AOD,ANALYSIS,ANALYSISalice (default aliroot mode)
40   TString extraLibs;
41   TList *list = new TList();
42   if (recotracklets) {
43     alirootMode="REC";     // $ALICE_ROOT/macros/loadlibsrec.C
44     extraLibs= "ITSrec:CDB:Geom:"; // not needed in default aliroot mode
45   } else alirootMode="ALIROOT";
46   extraLibs+= "ANALYSIS:ANALYSISalice";
47
48   // sets $ALIROOT_MODE on each worker to let proof to know to run in special mode
49   list->Add(new TNamed("ALIROOT_MODE", alirootMode.Data()));
50   list->Add(new TNamed("ALIROOT_EXTRA_LIBS", extraLibs.Data()));
51   if (recotracklets||dataonalien) list->Add(new TNamed("ALIROOT_ENABLE_ALIEN", "1"));
52
53   // REM: same version of AliRoot on client!
54 //  TProof::Mgr(proofCluster.Data())->SetROOTVersion(rootVer.Data()); //If not using the default version
55   TProof::Open(proofCluster.Data());
56   // enable n workers per machine
57 //  TProof::Open(proofCluster.Data(),"workers=nx")       
58   // enable less workers
59 //  TProof::Open(proofCluster.Data(),"workers=20"); //For performance reasons, try to avoid it.
60   if (!gProof) {
61     Error("runSPDdNdEtaAna.C","Connection to AF failed.");
62     return;
63   }
64   gProof->EnablePackage(alirootVer.Data(), list);
65
66 //  gROOT->LoadMacro("AnalysisMacroa.C");
67   Analysis(dataset.Data(), outFileCorr, outFileData, percentFile, percentFile2, 
68            useMC, readtr, recotracklets, 
69            nEvents, nEventsSkip, centrlowlim, centruplim, centrest, minClMultLay2, maxClMultLay2, minV0Mult, vtxlim, partsp,
70            phiWindow, thetaWindow, phiShift, removeClFOvl, phiOvlCut, zetaOvlCut, phiRotAngle,phiWindowAna);
71
72 }
73
74 //________________________________________________________________________
75 void Analysis(TString dataset, TString outFileCorr, TString outFileData, TString percentFile, TString percentFile2, 
76               Bool_t useMC, Bool_t readtr, Bool_t recotracklets, 
77               Int_t nEvents, Int_t nEventsSkip, 
78               Float_t centrlowlim, Float_t centruplim, Bool_t centrest, Int_t minClMultLay2, Int_t maxClMultLay2, Int_t minV0Mult, Float_t vtxlim, Bool_t partsp,
79               Float_t phiWindow, Float_t thetaWindow, Float_t phiShift, Bool_t removeClFOvl, 
80               Float_t phiOvlCut, Float_t zetaOvlCut, Float_t phiRotAngle, Float_t phiWindowAna) {
81
82   TString format = GetFormatFromDataSet(dataset);
83
84   // ALICE stuff
85   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
86   if (!mgr) mgr = new AliAnalysisManager("Test train");
87
88   InputHandlerSetup(format,useMC,recotracklets);
89
90   // compile the tracklet reconstruction class
91   gProof->Load("AliTrackletAlg.cxx++");
92   // compile analysis task
93   gProof->Load("AliAnalysisTaskSPDdNdEta.cxx++");
94
95   // create manager
96   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
97   if (!mgr) mgr = new AliAnalysisManager("SPD analysis");
98
99   // create task
100   AliAnalysisTaskSPDdNdEta *task = new AliAnalysisTaskSPDdNdEta("AliAnalysisTaskSPDdNdEta");
101
102   AliTriggerAnalysis::Trigger trigg = AliTriggerAnalysis::kAcceptAll; // to be changed every time
103   AliAnalysisTaskSPDdNdEta::MCCentralityBin kmccentrbin = AliAnalysisTaskSPDdNdEta::kall; // idem
104
105   task->SetReadMC(useMC);
106   task->SetTrigger(trigg);
107   task->SetReadTrackRefs(readtr);
108   task->SetRecoTracklets(recotracklets);
109   task->SetMCCentralityBin(kmccentrbin);
110   task->SetCentralityLowLim(centrlowlim);
111   task->SetCentralityUpLim(centruplim);
112   task->SetCentralityEst(centrest);
113   task->SetMinClusterMultLay2(minClMultLay2);
114   task->SetMaxClusterMultLay2(maxClMultLay2);
115   task->SetMinV0Mult(minV0Mult); 
116   task->SetVertexRange(vtxlim);
117   task->SetPartSpecies(partsp);
118
119   task->SetPhiWindow(phiWindow);
120   task->SetThetaWindow(thetaWindow); 
121   task->SetPhiShift(phiShift);
122   task->SetRemoveClustersFromOverlaps(removeClFOvl); 
123   task->SetPhiOverlapCut(phiOvlCut);
124   task->SetZetaOverlapCut(zetaOvlCut);
125   task->SetPhiRotationAngle(phiRotAngle);
126   task->SetPhiWindowAna(phiWindowAna);
127
128   // physics selection
129   gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
130   AliPhysicsSelectionTask* physSelTask=AddTaskPhysicsSelection(useMC,kFALSE);
131   if (!useMC) {
132     AliPhysicsSelection * physSel = physSelTask->GetPhysicsSelection();
133   
134 /*    if (dataset=="/alice/data/LHC10h_000137045_p1_plus") {
135       physSel->AddCollisionTriggerClass("+CMBS1A-B-NOPF-ALL");
136       physSel->AddCollisionTriggerClass("+CMBS1C-B-NOPF-ALL");
137       physSel->AddCollisionTriggerClass("+CMBAC-B-NOPF-ALL");
138
139     } else {*/
140       physSel->AddCollisionTriggerClass("+CMBS2A-B-NOPF-ALL");
141       physSel->AddCollisionTriggerClass("+CMBS2C-B-NOPF-ALL");
142       physSel->AddCollisionTriggerClass("+CMBAC-B-NOPF-ALL");
143 //    }
144
145     task->SelectCollisionCandidates(AliVEvent::kUserDefined);
146   } else {
147
148     task->SelectCollisionCandidates(AliVEvent::kMB);
149   }
150
151   // centrality selection
152   gProof->Load("./AliCentralitySelectionTask.cxx++g");
153   AliCentralitySelectionTask *taskCentr = new AliCentralitySelectionTask("CentralitySelection");
154   taskCentr->SetPercentileFile(percentFile);
155   taskCentr->SetPercentileFile2(percentFile2);
156
157   mgr->AddTask(taskCentr);
158   mgr->ConnectInput (taskCentr,0, mgr->GetCommonInputContainer());
159
160   // create output container
161   if (useMC) AliAnalysisDataContainer *output = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer, outFileCorr);
162   else       AliAnalysisDataContainer *output = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer, outFileData);
163
164   // add task to the manager
165   mgr->AddTask(task);
166
167   // connect input and output
168   mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
169   mgr->ConnectOutput(task, 1, output);
170
171   // run analysis
172   mgr->InitAnalysis();
173   // process dataset  
174   mgr->StartAnalysis("proof", dataset.Data(), nEvents, nEventsSkip);
175
176 }
177
178 //________________________________________________________________________
179 TString GetFormatFromDataSet(TString dataset) {
180
181 //  Info("runAAF.C","Detecting format from dataset (may take while, depends on network connection)...");
182   TString dsTreeName;
183   if (dataset.Contains("#")) {
184     Info("runSPDdNdEta.C",Form("Detecting format from dataset name '%s' ...",dataset.Data()));
185     dsTreeName=dataset(dataset.Last('#'),dataset.Length());
186   } else {
187     Info("runSPDdNdEta.C",Form("Detecting format from dataset '%s' (may take while, depends on network connection) ...",dataset.Data()));
188     TFileCollection *ds = gProof->GetDataSet(dataset.Data());
189     if (!ds) {
190       Error(Form("Dataset %s doesn't exist on proof cluster!!!!",dataset.Data()));
191       return "";
192     }
193     dsTreeName = ds->GetDefaultTreeName();
194   }
195
196   if (dsTreeName.Contains("esdTree")) {
197     Info("runSPDdNdEta.C","ESD input format detected ...");
198     return "ESD";
199   } else if (dsTreeName.Contains("aodTree"))  {
200     Info("runSPDdNdEta.C","AOD input format detected ...");
201     return "AOD";
202   } else {
203     Error("runSPDdNdEta.C",Form("Tree %s is not supported !!!",dsTreeName.Data()));
204     Error("runSPDdNdEta.C",Form("Maybe set your DS to %s#esdTree or %s#aodTree",dataset.Data(),dataset.Data()));
205   }
206
207   return "";
208 }
209
210 //________________________________________________________________________
211 Bool_t InputHandlerSetup(TString format = "esd", Bool_t useKine = kTRUE, Bool_t recotracklets)
212 {
213   format.ToLower();
214
215   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
216
217   AliAnalysisDataContainer *cin = mgr->GetCommonInputContainer();
218
219   if (cin) return;
220
221   if (!format.CompareTo("esd"))
222   {
223     AliESDInputHandler *esdInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
224
225     if (!esdInputHandler)
226     {
227       Info("CustomAnalysisTaskInputSetup", "Creating esdInputHandler ...");
228       if(recotracklets) esdInputHandler = new AliESDInputHandlerRP();
229       else esdInputHandler = new AliESDInputHandler();
230       mgr->SetInputEventHandler(esdInputHandler);
231     }
232
233     if (useKine)
234     {
235       AliMCEventHandler* mcInputHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
236
237       if (!mcInputHandler)
238       {
239         Info("CustomAnalysisTaskInputSetup", "Creating mcInputHandler ...");
240         AliMCEventHandler* mcInputHandler = new AliMCEventHandler();
241         mgr->SetMCtruthEventHandler(mcInputHandler);
242       }
243     }
244
245   }
246   else if (!format.CompareTo("aod"))
247   {
248     AliAODInputHandler *aodInputHandler = dynamic_cast<AliAODInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
249
250     if (!aodInputHandler)
251     {
252       Info("CustomAnalysisTaskInputSetup", "Creating aodInputHandler ...");
253       aodInputHandler = new AliAODInputHandler();
254       mgr->SetInputEventHandler(aodInputHandler);
255     }
256   }
257   else
258   {
259     AliWarning("Wrong input format!!! Only ESD and AOD are supported. Skipping Task ...");
260     return kFALSE;
261   }
262
263   return kTRUE;
264 }
265
266 //________________________________________________________________________
267 // MEMO DATASETS ...
268 /*
269 /alice/data/LHC10h_000137045_p1           |      60 | /esdTree     | 5.144e+05|    12 GB |  100 %
270 /alice/data/LHC10h_000137045_p1_lowflux   |      50 | /esdTree     | 4.144e+05|    10 GB |  100 %
271 /alice/data/LHC10h_000137045_p1_plus      |      53 | /esdTree     | 4.444e+05|    10 GB |  100 %
272 /alice/data/LHC10h_000137124_p1           |      89 | /esdTree     | 7.152e+04|     3 GB |  100 %
273 /alice/data/LHC10h_000137125_p1           |      41 | /esdTree     | 1.537e+04|     1 GB |  100 %
274 /alice/data/LHC10h_000137132_p1           |      87 | /esdTree     | 8.881e+04|     8 GB |  100 %
275 /alice/data/LHC10h_000137133_p1           |     306 | /esdTree     | 3.521e+05|    29 GB |  100 %
276 /alice/data/LHC10h_000137161              |    3348 | /esdTree     | 6.279e+05|   407 GB |   97 %
277
278 /alice/sim/LHC10h1_000137045              |    1198 | /esdTree     | 1.198e+04|   138 GB |  100 %
279 /alice/sim/LHC10h1a_000137045             |    1022 | /esdTree     | 1.006e+04|   124 GB |   98 %
280
281 */
282 //________________________________________________________________________