Update from DptDpt Correlations task
[u/mrichter/AliRoot.git] / PWGCF / Correlations / macros / dptdptcorrelations / AddTaskDptQA.C
1 //
2 // Macro designed for use with the AliAnalysisTaskDptDptQA task.
3 //
4 // Author: Prabhat Pujahari & Claude Pruneau, Wayne State
5 // 
6 //           system:  0: PbPb                 1: pPb
7 //      singlesOnly:  0: full correlations    1: singles only
8 //       useWeights:  0: no                   1: yes
9 // centralityMethod:  3: track count  4: V0 centrality  7: V0A centrality for pPb
10 //        chargeSet:  0: ++    1: +-    2: -+    3: --
11 /////////////////////////////////////////////////////////////////////////////////
12
13 AliAnalysisTaskDptDptQA *AddTaskDptQA
14 (int    system                 = 0,
15  int    singlesOnly            = 0,
16  int    useWeights             = 0,
17  int    centralityMethod       = 4,
18  int    chargeSet              = 1,
19  int    trackFilterBit         = 128,
20  int    nClusterMin            = 80,
21  double etaMin                 = -0.8,
22  double etaMax                 = 0.8,
23  double dcaZMin                = -3.2,
24  double dcaZMax                =  3.2,
25  double dcaXYMin               = -2.4,
26  double dcaXYMax               =  2.4,
27  int    nclus                  = 80,
28  double chi2ndf                = 4,
29  int nCentrality               =  2, 
30  Bool_t trigger                = kFALSE,
31  const char* taskname          = "dca3"
32  )
33   
34 {
35     
36   // Set Default Configuration of this analysis
37   // ==========================================
38   int    debugLevel             = 0;
39   int    rejectPileup           = 1;
40   int    rejectPairConversion   = 1;
41   int    sameFilter             = 1;
42
43   
44   //int    nCentrality;
45   double minCentrality[10];
46   double maxCentrality[10];
47
48   if (system==0) // PbPb
49     {
50     if (centralityMethod == 4)
51       {
52         
53         minCentrality[0] = 0.0; maxCentrality[0] = 10.0; 
54         minCentrality[1] = 30.0; maxCentrality[1] = 40.;
55                 
56       }
57     else
58       {
59       cout << "-F- AddTaskDptQA() system:" << system << ". centralityMethod:" << centralityMethod << " Option NOT AVAILABLE. ABORT."
60       return 0;
61       }
62     }
63   else if (system==1) // pPb
64     {
65     if (centralityMethod == 7)
66       {
67         //nCentrality = 4;
68       minCentrality[0] = 0;   maxCentrality[0] = 20.0;
69       minCentrality[1] = 20;   maxCentrality[1] = 40.;
70       minCentrality[2] = 40.; maxCentrality[2] = 60.;
71       minCentrality[3] = 0.; maxCentrality[3] = 100.;
72       }
73     else
74       {
75         //cout << "-F- AddTaskDptDptCorrelations() system:" << system << ". centralityMethod:" << centralityMethod << " Option NOT AVAILABLE. ABORT."
76       return 0;
77       }
78     }
79   else
80     {
81       //cout << "-F- AddTaskDptDptCorrelations() system:" << system << ". Option NOT CURRENTLY AVAILABLE. ABORT."
82     return 0;
83     }
84
85   double zMin                   = -10.;
86   double zMax                   =  10.;
87   double ptMin                  =  0.2;
88   double ptMax                  =  2.0;
89   double dedxMin                =  0.0;
90   double dedxMax                =  20000.0;
91   int    requestedCharge1       =  1; //default
92   int    requestedCharge2       = -1; //default
93   
94   
95   // Get the pointer to the existing analysis manager via the static access method.
96   // ==============================================================================
97   AliAnalysisManager *analysisManager = AliAnalysisManager::GetAnalysisManager();
98   
99   if (!analysisManager) 
100     {
101     ::Error("AddTaskDptDptCorrelations", "No analysis manager to connect to.");
102     return NULL;
103     }  
104   
105   TString part1Name;
106   TString part2Name;
107   TString eventName;
108   TString prefixName        = "Corr_";
109   TString pileupRejecSuffix = "_PileupRejec";
110   TString pairRejecSuffix   = "_PairRejec";
111   TString calibSuffix       = "_calib";
112   TString singlesOnlySuffix = "_SO";
113   TString suffix;
114   
115   TString inputPath         = ".";
116   TString outputPath        = ".";
117   TString baseName;
118   TString listName;
119   TString taskName;
120   TString inputHistogramFileName;
121   TString outputHistogramFileName;
122   
123   // Create the task and add subtask.
124   // ===========================================================================
125   int iTask = 0; // task counter
126   AliAnalysisDataContainer *taskInputContainer;
127   AliAnalysisDataContainer *taskOutputContainer;
128   AliAnalysisTaskDptDptQA* task;
129   
130   for (int iCentrality=0; iCentrality < nCentrality; ++iCentrality)
131     {
132       switch (chargeSet)
133         {
134           case 0: part1Name = "P_"; part2Name = "P_"; requestedCharge1 =  1; requestedCharge2 =  1; sameFilter = 1; break;
135           case 1: part1Name = "P_"; part2Name = "M_"; requestedCharge1 =  1; requestedCharge2 = -1; sameFilter = 0;   break;
136           case 2: part1Name = "M_"; part2Name = "P_"; requestedCharge1 = -1; requestedCharge2 =  1; sameFilter = 0;   break;
137           case 3: part1Name = "M_"; part2Name = "M_"; requestedCharge1 = -1; requestedCharge2 = -1; sameFilter = 1;   break;
138         }
139       //part1Name += int(1000*etaMin);                                                                                        
140       part1Name += "eta";
141       part1Name += int(1000*etaMax);
142       part1Name += "_";
143       part1Name += int(1000*ptMin);
144       part1Name += "pt";
145       part1Name += int(1000*ptMax);
146       part1Name += "_";
147       part1Name += int(1000*dcaZMin);
148       part1Name += "DCA";
149       part1Name += int(1000*dcaZMax);
150       part1Name += "_";
151
152
153       //part2Name += int(1000*etaMin);                                                                                        
154       part2Name += "eta";
155       part2Name += int(1000*etaMax);
156       part2Name += "_";
157       part2Name += int(1000*ptMin);
158       part2Name += "pt";
159       part2Name += int(1000*ptMax);
160       part2Name += "_";
161       part2Name += int(1000*dcaZMin);
162       part2Name += "DCA";
163       part2Name += int(1000*dcaZMax);
164       part2Name += "_";
165
166       eventName =  "";
167       eventName += int(10.*minCentrality[iCentrality] );
168       eventName += "Vo";
169       eventName += int(10.*maxCentrality[iCentrality] );
170       
171
172       baseName     =   prefixName;
173       baseName     +=  part1Name;
174       baseName     +=  part2Name;
175       baseName     +=  eventName;
176       listName     =   baseName;
177       taskName     =   baseName;
178       
179       
180       outputHistogramFileName = baseName;
181       if (singlesOnly) outputHistogramFileName += singlesOnlySuffix;
182       outputHistogramFileName += ".root";
183       
184     
185       TFile  * inputFile  = 0;
186       TList  * histoList  = 0;
187       TH3F   * weight_1   = 0;
188       TH3F   * weight_2   = 0;
189       if (useWeights)
190         {
191         TGrid::Connect("alien:");
192         inputFile = TFile::Open(inputHistogramFileName,"OLD");
193         if (!inputFile)
194           {
195           cout << "Requested file:" << inputHistogramFileName << " was not opened. ABORT." << endl;
196           return;
197           }
198         TString nameHistoBase = "correction_";
199         TString nameHisto;
200         nameHistoBase += eventName;
201         if (requestedCharge1 == 1)
202           {
203           nameHisto = nameHistoBase + "_p";
204           cout << "Input Histogram named: " << nameHisto << endl;
205           weight_1 = (TH3F *) inputFile->Get(nameHisto);
206           }
207         else
208           {
209           nameHisto = nameHistoBase + "_m";
210           cout << "Input Histogram named: " << nameHisto << endl;
211           weight_1 = (TH3F *) inputFile->Get(nameHisto);
212           }
213         if (!weight_1) 
214           {
215           cout << "Requested histogram 'correction_p/m' was not found. ABORT." << endl;
216           return 0;
217           }
218         
219         if (!sameFilter)
220           {
221           weight_2 = 0;
222           if (requestedCharge2 == 1)
223             {
224             nameHisto = nameHistoBase + "_p";
225             cout << "Input Histogram named: " << nameHisto << endl;
226             weight_2 = (TH3F *) inputFile->Get(nameHisto);
227             }
228           else
229             {
230             nameHisto = nameHistoBase + "_m";
231             cout << "Input Histogram named: " << nameHisto << endl;
232             weight_2 = (TH3F *) inputFile->Get(nameHisto);
233             }
234           if (!weight_2) 
235             {
236             cout << "Requested histogram 'correction_p/m' was not found. ABORT." << endl;
237             return 0;
238             }
239           }  
240         }
241       task = new  AliAnalysisTaskDptDptQA(taskName);
242       //configure my task
243       task->SetDebugLevel(          debugLevel      ); 
244       task->SetSameFilter(          sameFilter      );
245       task->SetSinglesOnly(         singlesOnly     ); 
246       task->SetUseWeights(          useWeights      ); 
247       task->SetRejectPileup(        rejectPileup    ); 
248       task->SetRejectPairConversion(rejectPairConversion); 
249       task->SetVertexZMin(          zMin            ); 
250       task->SetVertexZMax(          zMax            ); 
251       task->SetVertexXYMin(         -1.            ); 
252       task->SetVertexXYMax(          1.            ); 
253       task->SetCentralityMethod(    centralityMethod);
254       task->SetCentrality(          minCentrality[iCentrality], maxCentrality[iCentrality]);
255       task->SetPtMin1(              ptMin           ); 
256       task->SetPtMax1(              ptMax           ); 
257       task->SetEtaMin1(             etaMin          ); 
258       task->SetEtaMax1(             etaMax          ); 
259       task->SetPtMin2(              ptMin           ); 
260       task->SetPtMax2(              ptMax           ); 
261       task->SetEtaMin2(             etaMin          ); 
262       task->SetEtaMax2(             etaMax          ); 
263       task->SetDcaZMin( dcaZMin ); 
264       task->SetDcaZMax( dcaZMax ); 
265       task->SetDcaXYMin(dcaXYMin); 
266       task->SetDcaXYMax(dcaXYMax);
267       task->SetTPCNclus(nclus);
268       task->SetChi2PerNDF(chi2ndf);
269
270       task->SetDedxMin(             dedxMin         ); 
271       task->SetDedxMax(             dedxMax         ); 
272       task->SetNClusterMin(         nClusterMin     ); 
273       task->SetTrackFilterBit(      trackFilterBit  );
274       task->SetRequestedCharge_1(   requestedCharge1); 
275       task->SetRequestedCharge_2(   requestedCharge2); 
276       task->SetWeigth_1(            weight_1        );
277       task->SetWeigth_2(            weight_2        );
278             
279       
280       if(trigger) task->SelectCollisionCandidates(AliVEvent::kINT7);
281       else task->SelectCollisionCandidates(AliVEvent::kMB);
282             
283       cout << "Creating task output container" << endl;
284       
285       taskOutputContainer = analysisManager->CreateContainer(listName, 
286                                                              TList::Class(),    
287                                                              AliAnalysisManager::kOutputContainer, 
288                                                              Form("%s:%s", AliAnalysisManager::GetCommonFileName(),taskname));
289       cout << "Add task to analysis manager and connect it to input and output containers" << endl;
290            
291
292       analysisManager->AddTask(task);
293       analysisManager->ConnectInput( task,  0, analysisManager->GetCommonInputContainer());
294       analysisManager->ConnectOutput(task,  0, taskOutputContainer );
295       cout << "Task added ...." << endl;
296       
297       iTask++;
298     
299     }
300   
301   return task;
302 }