Updated macros for Grid/AAF + new macros for trains
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / macros / runProofCascadePbPb.C
1 void runProofCascadePbPb(
2                      TString  proofCluster      = "mnicassi@alice-caf.cern.ch",//kiaf.sdfarm.kr", //skaf.saske.sk"
3                      TString  alirootVer        = "VO_ALICE@AliRoot::v5-30-01-AN",
4                      TString  rootVer           = "VO_ALICE@ROOT::v5-30-06-1", 
5                      TString  dataset           = "/alice/sim/LHC11f5_000139514", 
6                      TString  outFileMC         = "CascadePerformance.root",
7                      TString  outFileData       = "CascadeAna.root",
8                      Bool_t   runperformancetask= kTRUE, 
9                      Bool_t   useMC             = kTRUE, 
10                      Bool_t   dataonalien       = kFALSE,
11                      Float_t  centrlowlim       = 0., 
12                      Float_t  centruplim        = 90., 
13                      TString  centrest          = "V0M",
14                      Float_t  vtxlim            = 10.,  
15                      Bool_t   kextrasel         = kFALSE,
16                      Bool_t   acccut            = kFALSE,
17                      Bool_t   krelaunchvertexers= kFALSE,
18                      Int_t    nEvents           = 1.0*1e7, 
19                      Int_t    nEventsSkip       = 0) { 
20
21   gEnv->SetValue("XSec.GSI.DelegProxy","2");
22
23   TString alirootMode = "";    // STEERBase,ESD,AOD,ANALYSIS,ANALYSISalice (default aliroot mode)
24   TString extraLibs;
25   TList *list = new TList();
26   alirootMode="ALIROOT";
27   extraLibs+= "ANALYSIS:OADB:ANALYSISalice:CORRFW";  
28   // sets $ALIROOT_MODE on each worker to let proof to know to run in special mode
29   list->Add(new TNamed("ALIROOT_MODE", alirootMode.Data()));
30   list->Add(new TNamed("ALIROOT_EXTRA_LIBS", extraLibs.Data()));
31   if (dataonalien) list->Add(new TNamed("ALIROOT_ENABLE_ALIEN", "1"));
32
33   // REM: same version of AliRoot on client!
34   TProof::Mgr(proofCluster.Data())->SetROOTVersion(rootVer.Data()); //If not using the default version, do it the first time only
35   TProof::Open(proofCluster.Data());
36
37   // enable n workers per machine
38 //  TProof::Open(proofCluster.Data(),"workers=nx")       
39   // enable less workers
40 //  TProof::Open(proofCluster.Data(),"workers=20"); //For performance reasons, try to avoid it.
41   if (!gProof) {
42     Error("runProof.C","Connection to AF failed.");
43     return;
44   }
45
46   gProof->EnablePackage(alirootVer.Data(), list);
47
48
49   Analysis(dataset.Data(), outFileMC, outFileData, 
50            useMC, nEvents, nEventsSkip,
51            centrlowlim, centruplim, centrest, 
52            vtxlim, kextrasel,
53            runperformancetask, acccut, krelaunchvertexers);
54
55 }
56
57 //________________________________________________________________________
58 void Analysis(TString dataset, TString outFileMC, TString outFileData, 
59               Bool_t useMC, Int_t nEvents, Int_t nEventsSkip, 
60               Float_t centrlowlim, Float_t centruplim, TString centrest,
61               Float_t vtxlim, 
62               Bool_t kextrasel, Bool_t runperformancetask, Bool_t acccut, Bool_t krelaunchvertexers) {
63
64
65   TString format = GetFormatFromDataSet(dataset);
66
67   // ALICE stuff
68   // create manager
69   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
70   if (!mgr) mgr = new AliAnalysisManager("Test train");
71
72   InputHandlerSetup(format,runperformancetask);
73
74   // compile analysis task
75   if (runperformancetask) gProof->Load("AliAnalysisTaskCheckPerformanceCascadePbPb.cxx++");
76   else gProof->Load("AliAnalysisTaskCheckCascadePbPb.cxx++");
77
78   // physics selection
79   gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
80   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(useMC);
81
82   // centrality selection
83   cout<<"Format"<<format.Data()<<endl;
84   if (!format.CompareTo("ESD")) {
85     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
86     AliCentralitySelectionTask *taskCentr = AddTaskCentrality();
87     if (useMC) {
88       taskCentr->SetMCInput();
89       taskCentr->DontUseCleaning(); // for injected MC
90     }
91   }
92
93   
94   // add PID response task
95   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
96   AliAnalysisTaskPIDResponse *pidTask = AddTaskPIDResponse(useMC);
97
98   // create task
99   if (runperformancetask) {
100     AliAnalysisTaskCheckPerformanceCascadePbPb *task = new AliAnalysisTaskCheckPerformanceCascadePbPb("AliAnalysisTaskCheckPerformanceCascadePbPb");
101     task->SetApplyAccCut                 (acccut);
102     task->SetRejectEventPileUp(kFALSE);
103
104   } else {
105     AliAnalysisTaskCheckCascadePbPb *task = new AliAnalysisTaskCheckCascadePbPb("AliAnalysisTaskCheckCascadePbPb");
106   }
107
108   task->SetAnalysisType               (format);
109   task->SetRelaunchV0CascVertexers    (krelaunchvertexers);                 
110   task->SetQualityCutZprimVtxPos      (kTRUE);             // selects vertices in +-10cm
111   task->SetQualityCutNoTPConlyPrimVtx (kTRUE);             // retains only events with tracking + SPD vertex 
112   task->SetQualityCutTPCrefit         (kTRUE);             // requires TPC refit flag to be true to select a track
113   task->SetQualityCut80TPCcls         (kTRUE);             // rejects tracks that have less than 80 clusters in the TPC
114   task->SetExtraSelections            (kextrasel);         // used to add other selection cuts 
115   task->SetCentralityLowLim           (centrlowlim);       // setting centrality selection variables
116   task->SetCentralityUpLim            (centruplim);
117   task->SetCentralityEst              (centrest);
118   task->SetVertexRange                (vtxlim);
119
120   // create output container
121   if (runperformancetask) AliAnalysisDataContainer *output = mgr->CreateContainer("clist", TList::Class(), AliAnalysisManager::kOutputContainer, outFileMC);
122   else       AliAnalysisDataContainer *output = mgr->CreateContainer("clist", TList::Class(), AliAnalysisManager::kOutputContainer, outFileData);
123
124   // add task to the manager
125   mgr->AddTask(task);
126
127   task->SelectCollisionCandidates();
128
129   // connect input and output
130   mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
131   mgr->ConnectOutput(task, 1, output);
132
133   // run analysis
134   mgr->InitAnalysis();
135   // process dataset  
136   mgr->StartAnalysis("proof", dataset.Data(), nEvents, nEventsSkip);  // single dataset
137   //mgr->StartAnalysis("proof","/alice/sim/LHC11f5_000139514|/alice/sim/LHC11f5_000139517",nEvents, nEventsSkip);  // multiple dataset
138
139 }
140
141 //________________________________________________________________________
142 TString GetFormatFromDataSet(TString dataset) {
143
144 //  Info("runProof.C","Detecting format from dataset (may take while, depends on network connection)...");
145   TString dsTreeName;
146   if (dataset.Contains("#")) {
147     Info("runProof.C",Form("Detecting format from dataset name '%s' ...",dataset.Data()));
148     dsTreeName=dataset(dataset.Last('#'),dataset.Length());
149   } else {
150     Info("runProof.C",Form("Detecting format from dataset '%s' (may take while, depends on network connection) ...",dataset.Data()));
151     TFileCollection *ds = gProof->GetDataSet(dataset.Data());
152     if (!ds) {
153       Error(Form("Dataset %s doesn't exist on proof cluster!!!!",dataset.Data()));
154       return "";
155     }
156     dsTreeName = ds->GetDefaultTreeName();
157   }
158
159   if (dsTreeName.Contains("esdTree")) {
160     Info("runProof.C","ESD input format detected ...");
161     return "ESD";
162   } else if (dsTreeName.Contains("aodTree"))  {
163     Info("runProof.C","AOD input format detected ...");
164     return "AOD";
165   } else {
166     Error("runProof.C",Form("Tree %s is not supported !!!",dsTreeName.Data()));
167     Error("runProof.C",Form("Maybe set your DS to %s#esdTree or %s#aodTree",dataset.Data(),dataset.Data()));
168   }
169
170   return "";
171 }
172
173 //________________________________________________________________________
174 Bool_t InputHandlerSetup(TString format = "esd", Bool_t useKine = kTRUE) {
175   format.ToLower();
176
177   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
178
179   AliAnalysisDataContainer *cin = mgr->GetCommonInputContainer();
180
181   if (cin) return;
182
183   if (!format.CompareTo("esd")) {
184     AliESDInputHandler *esdInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
185
186     if (!esdInputHandler) {
187       Info("CustomAnalysisTaskInputSetup", "Creating esdInputHandler ...");
188       esdInputHandler = new AliESDInputHandler();
189       mgr->SetInputEventHandler(esdInputHandler);
190     }
191
192     if (useKine) {
193       AliMCEventHandler* mcInputHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
194
195       if (!mcInputHandler) {
196         Info("CustomAnalysisTaskInputSetup", "Creating mcInputHandler ...");
197         AliMCEventHandler* mcInputHandler = new AliMCEventHandler();
198         mgr->SetMCtruthEventHandler(mcInputHandler);
199       }
200     }
201   } else if (!format.CompareTo("aod")) {
202     AliAODInputHandler *aodInputHandler = dynamic_cast<AliAODInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
203
204     if (!aodInputHandler) {
205       Info("CustomAnalysisTaskInputSetup", "Creating aodInputHandler ...");
206       aodInputHandler = new AliAODInputHandler();
207       mgr->SetInputEventHandler(aodInputHandler);
208     }
209   } else {
210     AliWarning("Wrong input format!!! Only ESD and AOD are supported. Skipping Task ...");
211     return kFALSE;
212   }
213
214   return kTRUE; 
215