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