]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/EBYE/NetParticle/macros/AddTaskNetParticle.C
de5015b42424fa61fb7ef40063a8353d8e1ec7b9
[u/mrichter/AliRoot.git] / PWGCF / EBYE / NetParticle / macros / AddTaskNetParticle.C
1 /* *********************************************************************************
2  * File    : AddTaskNetParticle.C  
3  * Authors : Jochen Thaeder <jochen@thaeder.de>
4  *           Michael Weber <m.weber@cern.ch>
5  * *********************************************************************************
6  * Configuring NetParticle Task:
7  * - ARGUMENTS : 
8  *     name           -> Name of the task, containing particle type :
9  *                       Currently : Proton, Pion, Kaon, Charge      
10  *     isModeDist     -> Fill Distributions
11  *     isModeEff      -> Fill Efficiency/Contamination ThnSparse
12  *     isModeDCA      -> Fill DCA ThnSparse
13  *     isModeQA       -> Fill QA ThnSparse
14  *     isModeAOD      -> Use AOD input 
15  *     isCreateCSC    -> Prepare for CrossSectionCorrection 
16  *                       - requires isModeEff to be set
17  *                       - Proton only
18  *     modeCSC        -> Use differnt Pt cut for
19  *                       0 : TPC+TOF
20  *                       1 : TPC
21  *     modeCuts       -> Different Cut scenarios
22  *                       0 : Standard cuts
23  *                       1 : LF cuts
24  *     modePID        -> PID Strategy 
25  *                      -1 :   Default -> 7 (modeCuts=0) and 5 (modeCuts=1)  
26  *                       0 :   TPC(TPClow+TPCHigh)
27  *                       1 :   ITS
28  *                       2 :   TOF
29  *                       3 :   ITS+TPC(TPClow+TPCHigh)
30  *                       4 :   TPC(TPClow+TPCHigh)+TOF
31  *                       5 :   TPC(TPClow+TPCHigh)+TOF for pT >= fMinPtForTOFRequired TOF is required, below, only used if there
32  *                       6 :   TPC(TPClow+TPCHigh)+ITS+TOF with TOF only for those tracks which have TOF information
33  *                       7 :   TPC(TPClow+TPCHigh)+ITS+TOF for pT >= fMinPtForTOFRequired TOF is required, below, only used if there
34  *                       8 :   TPC(TPClow+TPCHigh)+ITS+TOF 
35  * 
36  * *********************************************************************************
37  * - PID Strategy
38  *
39 * *********************************************************************************
40  * - OUTPUT CONTAINER : #N = 5
41  *   (1) - Standard Output, Distributions
42  *   (2) - Efficiency ThnSparse
43  *   (3) - Contamination ThnSparse
44  *   (4) - DCA ThnSparse
45  *   (5) - QA ThnSparse
46  *
47  ********************************************************************************* */
48
49 AliAnalysisTask *AddTaskNetParticle(const Char_t * name = "jthaeder_NetProton", 
50                                     Bool_t isModeDist, Bool_t isModeEff, Bool_t isModeDCA, Bool_t isModeQA = kFALSE,
51                                     Bool_t isCreateCSC = kFALSE, Bool_t isModeAOD = kFALSE, Int_t modeCSC = 0, Int_t modeCuts = 0, Int_t modePID = -1) {
52
53   // TURN OFF QA for now
54   isModeQA = kFALSE;
55
56
57   TString sName(name);
58
59   if (isCreateCSC && !isModeEff) {
60     Error("AddTaskNetParticle", "Creating CrossSectionCorrection needs 'isModeEff' to be set.");
61     return NULL;
62   }
63
64   // ----------------------------------------------
65   // -- Get the current analysis manager
66   // ----------------------------------------------
67   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
68   if (!mgr) {
69     Error("AddTaskNetParticle", "No analysis manager found.");
70     return NULL;
71   }
72
73   // ----------------------------------------------
74   // -- Check for MC
75   // ----------------------------------------------
76   Bool_t isMC = (mgr->GetMCtruthEventHandler() != NULL);
77   if (isMC)
78     Info("AddTaskNetParticle", "This task has MC.");
79   
80   // ----------------------------------------------
81   // -- Create task 
82   // ----------------------------------------------
83   AliAnalysisTaskNetParticle *task = new AliAnalysisTaskNetParticle("AliAnalysisTaskNetParticle");
84   if (!task) {
85     Error("AddTaskNetParticle", "Task could not be created.");
86     return NULL;
87   }
88
89   // ----------------------------------------------
90   // -- Configure flags
91   // ----------------------------------------------
92   if (isMC) 
93     task->SetIsMC();
94   if (isModeEff) 
95     task->SetModeEffCreation(1);     // => 1 = on    | 0 = off (default)
96   if (isModeDCA)
97     task->SetModeDCACreation(1);     // => 1 = on    | 0 = off (default)
98   if (isModeDist)
99     task->SetModeDistCreation(1);    // => 1 = on    | 0 = off (default)
100   if (isModeAOD) {
101     task->SetIsAOD(1);               // => 1 = AOD   | 0 = ESD (default)
102     task->SetTrackFilterBit(1024);   // 1024 = RAA cuts
103   }
104   if (isModeQA)
105     task->SetModeQACreation(1);      // => 1 = on    | 0 = off (default)
106
107   // ----------------------------------------------
108   // -- Create helper class
109   // ----------------------------------------------
110   AliAnalysisNetParticleHelper *helper = new AliAnalysisNetParticleHelper;
111   if (!helper) {
112     Error("AddTaskNetParticle", "Helper could not be created.");
113     delete task;
114     return NULL;
115   }
116
117   task->SetNetParticleHelper(helper);
118
119   // ----------------------------------------------
120   // -- Set particle type
121   // ----------------------------------------------
122   Float_t minPt, maxPt, minPtEff, maxPtEff, minPtForTOF, etaMax, etaMaxEff, nSigmaITS, nSigmaTPC, nSigmaTPClow, nSigmaTOF; 
123   Int_t pidStrategy;
124
125   if (sName.Contains("Proton")) {
126     helper->SetParticleSpecies(AliPID::kProton);
127     minPtForTOF    = 0.69;                //    minPtForTOF = 0.21;
128     maxPtForTPClow = 0.69;
129     minPt    = 0.5;     maxPt   = 2.0;    //    minPt    = 0.22;     maxPt   = 4.5;
130     minPtEff = 0.5;    maxPtEff = 2.0;    //    minPtEff = 0.22;     maxPtEff = 4.5;
131     etaMax     = 0.8;  
132     etaMaxEff  = 0.8;  
133     nSigmaITS = 4.0;   nSigmaTPC = 4.0;   nSigmaTPClow = 3.0;   nSigmaTOF = 4.0; 
134
135     if (modePID == -1) { // default
136       pidStrategy = 7;         // 7: ITS + TPC + TOF (using minPtForTOF)
137       if (modeCuts == 1)
138         pidStrategy = 5;       // 5: TPC + TOF (using minPtForTOF) 
139     }
140     else
141       pidStrategy = modePID;
142
143     // For TPC only case
144     if (isCreateCSC && modeCSC == 1)
145       minPtForTOF = maxPtEff;
146   }
147   else if (sName.Contains("Pion")) {
148     helper->SetParticleSpecies(AliPID::kPion);
149     minPt    = 0.3;    maxPt    = 0.6;
150     minPtEff = 0.2;    maxPtEff = 1.0;
151     minPtForTOF = 0.8;
152     etaMax     = 99.99;    // 0.8 ->> eta cut off for now
153     etaMaxEff  = 99.99;    // 0.9 ->> eta cut off for now
154     nSigmaITS = 2.5;   nSigmaTPC = 2.5;   nSigmaTOF = 2.5;
155     pidStrategy = 1;
156   }
157   else if (sName.Contains("Kaon")) {
158     helper->SetParticleSpecies(AliPID::kKaon);
159     minPt    = 0.5;    maxPt    = 1.4;
160     minPtEff = 0.1;    maxPtEff = 2.5;
161     minPtForTOF = 0.5;
162     etaMax     = 99.99;    // 0.8 ->> eta cut off for now
163     etaMaxEff  = 99.99;    // 0.9 ->> eta cut off for now
164     nSigmaITS = 2.5;   nSigmaTPC = 2.5;   nSigmaTOF = 2.5;
165     pidStrategy = 1;
166   }
167   else if (sName.Contains("Charge")) {
168     helper->SetUsePID(kFALSE);
169     minPt    = 0.3;    maxPt    = 2.5;
170     minPtEff = 0.1;    maxPtEff = 3.0;
171     minPtForTOF = -1.;
172     etaMax     = 0.8; 
173     etaMaxEff  = 0.9; 
174     nSigmaITS = -1.;   nSigmaTPC = -1.;   nSigmaTOF = -1.;
175     pidStrategy = 1;
176   }
177   else {
178     Error("AddTaskNetParticle", "Unknown Particle type.");
179     delete task;
180     return NULL;
181   }
182
183   // ----------------------------------------------
184   // -- Read Environment Variables 
185   // ----------------------------------------------
186   ifstream in;
187   in.open("setRunENV.txt");
188   
189   TString current;    
190   while(in.good()) {
191     in >> current;
192     
193     TObjArray *arr = current.Tokenize('=');
194     if (!arr) 
195       continue;
196     
197     TObjString* oKey = dynamic_cast<TObjString*>(arr->At(0));
198     TObjString* oValue = dynamic_cast<TObjString*>(arr->At(1));
199     if (!oKey)
200       continue;
201
202     TString key(oKey->GetString());
203     TString value(oValue->GetString());
204    
205     if (!key.CompareTo("NETPARTICLE_PID_STRATEGY")) {
206       pidStrategy = value.Atoi();
207       printf(">>>> USE NETPARTICLE_PID_STRATEGY %d\n", pidStrategy);
208     }
209     if (!key.CompareTo("NETPARTICLE_NSIGMAMAX_ITS")) {
210       nSigmaITS = value.Atof();
211       printf(">>>> USE NETPARTICLE_NSIGMAMAX_ITS %.2f\n", nSigmaITS);
212     }
213     if (!key.CompareTo("NETPARTICLE_NSIGMAMAX_TPC")) {
214       nSigmaTPC = value.Atof();
215       printf(">>>> USE NETPARTICLE_NSIGMAMAX_TPC %.2f\n", nSigmaTPC);
216     }
217     if (!key.CompareTo("NETPARTICLE_NSIGMAMAX_TOF")) {
218       nSigmaTOF = value.Atof();
219       printf(">>>> USE NETPARTICLE_NSIGMAMAX_TOF %.2f\n", nSigmaTOF);
220     }
221
222     arr->Clear();
223     delete arr;
224   }
225
226   in.close();
227
228   // ----------------------------------------------
229   // -- Configure cuts 
230   // ----------------------------------------------
231
232   // -- Set cut flags 
233   task->SetESDTrackCutMode(modeCuts);       // => 0 = normal | 1 = LF
234
235   // -- Set analysis ranges
236   task->SetEtaMax(etaMax);                  // eta cut
237   task->SetEtaMaxEff(etaMaxEff);            // eta cut for efficiency
238   task->SetPtRange(minPt, maxPt);           // pt cut range for the analysis
239   task->SetPtRangeEff(minPtEff, maxPtEff);  // pt cut range for the correction / efficiency / contamination creation
240
241   // ----------------------------------------------
242   // -- Configure cuts - helper class
243   // ----------------------------------------------
244
245   // -- Set standard event cuts
246   helper->SetVertexZMax(10.);   
247   helper->SetCentralityBinMax(7);
248
249   // -- Set track event cuts
250   helper->SetRapidityMax(0.5); 
251   //  helper->SetRapidityMax(0.2); 
252   helper->SetMinTrackLengthMC(70.);  
253   helper->SetNSigmaMaxCdd(0.);    //  3. ||   ->> Turn off sigmaDCA cuts for now
254   helper->SetNSigmaMaxCzz(0.);    //  3. ||   ->> Turn off sigmaDCA cuts for now
255   helper->SetPhiRange(0., 3.88);  //  Only used if requested in task - default is TwoPi
256
257   // -- Set pid cuts
258   helper->SetPIDStrategy(pidStrategy);
259   helper->SetNSigmaMaxITS(nSigmaITS);
260   helper->SetNSigmaMaxTPC(nSigmaTPC);
261   helper->SetNSigmaMaxTPClow(nSigmaTPClow);
262   helper->SetNSigmaMaxTOF(nSigmaTOF);
263   helper->SetMinPtForTOFRequired(minPtForTOF);
264   helper->SetMaxPtForTPClow(maxPtForTPClow);
265   
266   // -- Set N sub samples
267   helper->SetNSubSamples(20);
268
269   // ----------------------------------------------
270   // -- Add task to the ANALYSIS manager
271   // ----------------------------------------------
272   mgr->AddTask(task);
273
274   // ----------------------------------------------
275   // -- data containers - input
276   // ----------------------------------------------
277   AliAnalysisDataContainer *cinput  = mgr->GetCommonInputContainer();
278
279   // ----------------------------------------------
280   // -- data containers - output
281   // ----------------------------------------------
282   TString outputFileName   = "";
283   TString outputQAFileName = "";
284   if(isModeAOD){
285     outputFileName   = Form("%s:%s", AliAnalysisManager::GetCommonFileName(), name);
286     outputQAFileName = Form("%s:%s", AliAnalysisManager::GetCommonFileName(), name);
287   }
288   else{
289     outputFileName   = Form("%s.root",   name);
290     outputQAFileName = Form("%sQA.root", name);
291   }
292
293   AliAnalysisDataContainer *coutput     = mgr->CreateContainer(name, TList::Class(),  AliAnalysisManager::kOutputContainer, outputFileName);
294   AliAnalysisDataContainer *coutputEff  = mgr->CreateContainer(Form("%s_eff",  name), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName);
295   AliAnalysisDataContainer *coutputCont = mgr->CreateContainer(Form("%s_cont", name), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName);
296   AliAnalysisDataContainer *coutputDca  = mgr->CreateContainer(Form("%s_dca",  name), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName);
297
298   AliAnalysisDataContainer *coutputQA   = mgr->CreateContainer(Form("%sQA",    name), TList::Class(), AliAnalysisManager::kOutputContainer, outputQAFileName);
299     
300   mgr->ConnectInput  (task,  0, cinput );
301   mgr->ConnectOutput (task,  1, coutput);
302   mgr->ConnectOutput (task,  2, coutputEff);
303   mgr->ConnectOutput (task,  3, coutputCont);
304   mgr->ConnectOutput (task,  4, coutputDca);
305   mgr->ConnectOutput (task,  5, coutputQA);
306
307   return task;
308 }