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