]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/EMCALTasks/macros/AddTaskEMCALClusterize.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / macros / AddTaskEMCALClusterize.C
1 // $Id$
2
3 AliAnalysisTaskEMCALClusterize* AddTaskEMCALClusterize(
4                                                        TString & arrayName,
5                                                        const Bool_t  bFillAOD   = kFALSE,                                                
6                                                        const Int_t   bMC        = kFALSE,
7                                                        const Bool_t  exotic     = kTRUE,
8                                                        const TString name       = "V1Unfold", // V1, V2, NxN, V1Unfold
9                                                        const TString trigger    = "", 
10                                                        const Bool_t  tm         = kTRUE, 
11                                                        const Int_t   minEcell   = 50,
12                                                        const Int_t   minEseed   = 100,
13                                                        const Int_t   maxDeltaT  = 250,
14                                                        const Int_t   timeWindow = 1000,
15                                                        const Int_t   minEUnf    = 15, 
16                                                        const Int_t   minFrac    = 1,
17                                                        const Bool_t  bRecalE    = kTRUE,
18                                                        const Bool_t  bBad       = kTRUE,
19                                                        const Bool_t  bRecalT    = kTRUE,
20                                                        const Bool_t  bNonLine   = kFALSE,
21                                                        const Int_t   minCen     = -1,
22                                                        const Int_t   maxCen     = -1,
23                                                        const Float_t clusterEnergyCutEvent = -1,
24                                                        const Int_t   nRowDiff   = 1,
25                                                        const Int_t   nColDiff   = 1,
26                                                        const Bool_t  skipOrReject = kFALSE
27                                                        )
28 {  
29   // Get the pointer to the existing analysis manager via the static access method.
30   //==============================================================================
31   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
32   if (!mgr)
33   {
34     ::Error("AddTaskEMCALClusterize", "No analysis manager to connect to.");
35     return NULL;
36   }  
37   
38   // Check the analysis type using the event handlers connected to the analysis manager.
39   //==============================================================================
40   if (!mgr->GetInputEventHandler())
41   {
42     ::Error("AddTaskEMCALClusterize", "This clusterize requires an input event handler");
43     return NULL;
44   }
45   
46   printf("Passed Settings : mc %d, exo %d, name %s, trigger %s, tm %d\n",bMC,exotic,name.Data(),trigger.Data(),tm);
47   printf("                  Ecell %d, Eseed %d, dT %d, wT %d, minUnf %d, minFrac %d \n",minEcell, minEseed,maxDeltaT,timeWindow,minEUnf,minFrac);
48   printf("                  recalE %d, bad %d, recalT %d, nonlin %d, minCen %d, maxCen %d, rowDiff %d, colDiff %d \n",bRecalE,bBad,bRecalT,bNonLine,minCen,maxCen,nRowDiff,nColDiff);
49
50   // Create name of task and AOD branch depending on different settings
51   
52   if(name.Contains("NxN")) arrayName = Form("%dx%d_Ecell%d_Eseed%d_DT%d_WT%d",2*nRowDiff+1,2*nColDiff+1,minEcell,minEseed,maxDeltaT,timeWindow);
53   else                     arrayName = Form(   "%s_Ecell%d_Eseed%d_DT%d_WT%d",              name.Data(),minEcell,minEseed,maxDeltaT,timeWindow);
54   
55   if(minCen != -1 && maxCen != -1)
56     arrayName+=Form("_Cen%d_%d",minCen,maxCen);
57
58   printf("Created Branch Name: %s \n",arrayName.Data());
59   
60   
61   //-------------------------------------------------------
62   // Init the task and do settings
63   //-------------------------------------------------------
64
65   AliAnalysisTaskEMCALClusterize* clusterize = new AliAnalysisTaskEMCALClusterize(Form("EMCALClusterize%s",arrayName.Data()));
66
67   clusterize->SetAODBranchName(arrayName);
68   
69   //clusterize->SetOCDBPath("local://$ALICE_ROOT/OCDB");
70
71   // Centrality range
72   clusterize->SetCentralityBin(minCen, maxCen); 
73   
74   // Some general settings to create AOD file in case we want to keep it
75   clusterize->SwitchOffFillAODCaloCells();
76   clusterize->SwitchOffFillAODHeader();
77   clusterize->FillAODFile(bFillAOD); // fill aod.root with clusters?, not really needed for analysis.
78
79   // Do track matching after clusterization
80   if(tm) clusterize->SwitchOnTrackMatching();
81   else   clusterize->SwitchOffTrackMatching();
82   
83   //-------------------------------------------------------
84   // Set clusterization parameters via rec param
85   //-------------------------------------------------------
86
87   AliEMCALRecParam * params = clusterize->GetRecParam();
88
89   // Position and SS weight parameter
90   params->SetW0(4.5);
91
92   // Time cuts
93   
94   if(maxDeltaT > 1) params->SetTimeCut(maxDeltaT*1.e-9);
95   else            { params->SetTimeCut(250*1.e-9); printf("default maxDeltaT = 250 ns\n"); }// Same as in reco
96   
97   if(timeWindow > 1)
98   {
99     params->SetTimeMin(-1*timeWindow*1.e-9);
100     params->SetTimeMax(timeWindow*1.e-9);
101   }
102   else
103   {
104     if(!bMC)
105     {
106       if(bRecalT)
107       {
108         params->SetTimeMin(-250*1.e-9);
109         params->SetTimeMax( 250*1.e-9);
110         printf("default time window for calibrated time -250 ns < T < 250 ns\n");
111       }
112       else
113       {
114         // same as in reco, USE IF NO TIME RECALIBRATION
115         params->SetTimeMin(425*1.e-9);
116         params->SetTimeMax(825*1.e-9);
117         printf("default time window 425 ns < T < 825 ns\n");
118       }
119     }
120     else
121     {
122       params->SetTimeMin(-100000000);
123       params->SetTimeMax( 100000000);
124       printf("open time cut\n");
125     }
126   }
127
128   // Energy cuts
129   params->SetClusteringThreshold(minEseed/1.e3);
130   params->SetMinECut            (minEcell/1.e3); 
131
132   // Clusterizer type
133   if(name.Contains("V2")) params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv2);
134   if(name.Contains("V1")) params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv1);
135   if(name.Contains("NxN"))
136   {
137     params->SetClusterizerFlag(AliEMCALRecParam::kClusterizerNxN);
138     printf("Set NxN cluster size to %dx%d (row diff %d, col diff %d)\n",2*nRowDiff+1,2*nColDiff+1,nRowDiff,nColDiff);
139     params->SetNxM(nRowDiff, nColDiff);
140   }
141
142   //-------------------------------------------------------
143   // Unfolding, 2 options :
144   //-------------------------------------------------------
145
146   //    1) Just unfold existing clusters
147   if(name.Contains("JustUnfold"))
148     clusterize->JustUnfold(kTRUE); // if TRUE, do just unfolding, do not recluster cells
149   else  
150     clusterize->JustUnfold(kFALSE); 
151
152   //   2) Unfold clusters created in the clusterize (revise settings)
153   if (name.Contains("Unfold"))
154   {
155     clusterize->SwitchOnCellEnergySelection();
156     clusterize->SetCellCuts(minEUnf/1000.,minFrac/10000.);
157     clusterize->SetRejectBelowThreshold(skipOrReject);
158     printf("AliAnalysisTaskEMCALClusterize - Cuts: min E %f, frac %f\n",minEUnf/1000.,minFrac/10000.);
159     //clusterize->SwitchOffCellEnergySelection(); 
160     
161     if(!name.Contains("Just"))
162       params->SetUnfold(kTRUE);
163     else 
164       params->SetUnfold(kFALSE);
165     
166   } // unfold
167   
168   //-------------------------------------------------------
169   // Configure AliEMCALRecoUtils
170   //-------------------------------------------------------
171
172   AliEMCALRecoUtils * reco = clusterize->GetRecoUtils();
173   gROOT->LoadMacro("$ALICE_ROOT/PWGGA/EMCALTasks/macros/ConfigureEMCALRecoUtils.C"); // $ALICE_ROOT/PWGGA/EMCALTasks/macros
174   ConfigureEMCALRecoUtils(reco,bMC,exotic,bNonLine,bRecalE,bBad,bRecalT);
175   
176   //-------------------------------------------------------
177   // Alignment matrices
178   //-------------------------------------------------------
179
180   //clusterize->SetImportGeometryFromFile(kTRUE,"$ALICE_ROOT/OADB/EMCAL/geometry_2011.root"); // done automatically, set here to force
181
182   clusterize->SwitchOnLoadOwnGeometryMatrices();
183   
184   //-------------------------------------------------------
185   // Clusterize events with some significant signal
186   //-------------------------------------------------------
187   
188   if(clusterEnergyCutEvent > 0)
189   {
190     clusterize->SwitchOnSelectEMCALEvent();
191     clusterize->SetEMCALEnergyCut(clusterEnergyCutEvent);
192     clusterize->SetEMCALNcellsCut(3);
193   }
194   else clusterize->SwitchOffSelectEMCALEvent();
195   
196   //-------------------------------------------------------
197   // Cluster MC labels recalculation
198   //-------------------------------------------------------
199   
200   if(bMC)
201   {
202     printf("Recalculate MC labels\n");
203     clusterize->SwitchOnUseClusterMCLabelForCell(0) ; // Take the cell MC label as basis (only possible in recent productions)
204     clusterize->SwitchOnRemapMCLabelForAODs()  ;      // Only in case 0, and for productions where the re-mapping of cell label in AODs was not done (productions before March 2013?)
205
206     //clusterize->SwitchOnUseClusterMCLabelForCell(1) ; // Assign to each cell the same MC label as the original cluster to which it belonged
207     //clusterize->SwitchOnUseClusterMCLabelForCell(2) ; // Find the original clusters that have the same cells as the new cluster,
208                                                         // assign the labels of the original clusters to the new cluster.
209                                                         // only interesting if output is V1
210   
211   }
212   
213   //-------------------------------------------------------
214   // Trigger options
215   //-------------------------------------------------------
216
217   if(trigger=="EMC7")
218   {
219     printf("Clusterizing task trigger EMC7\n");
220     clusterize->SelectCollisionCandidates(AliVEvent::kEMC7);
221   }
222   else if (trigger=="INT7")
223   {
224     printf("Clusterizing task trigger INT7\n");
225     clusterize->SelectCollisionCandidates(AliVEvent::kINT7);
226   }
227   else if(trigger=="EMC1")
228   {
229     printf("Clusterizing task trigger EMC1\n");
230     clusterize->SelectCollisionCandidates(AliVEvent::kEMC1);
231   }
232   else if(trigger=="MB")
233   {
234     printf("Clusterizing task trigger MB\n");
235     clusterize->SelectCollisionCandidates(AliVEvent::kMB);
236   }  
237   else if(trigger=="PHOS")
238   {
239     printf("Clusterizing task trigger PHOS\n");
240     clusterize->SelectCollisionCandidates(AliVEvent::kPHI7);
241   }  
242   else if(trigger=="PHOSPb")
243   {
244     printf("Clusterizing task trigger PHOSPb\n");
245     clusterize->SelectCollisionCandidates(AliVEvent::kPHOSPb);
246   }
247   else if(trigger=="AnyINT")
248   {
249     printf("Clusterizing task trigger AnyINT\n");
250     clusterize->SelectCollisionCandidates(AliVEvent::kAnyINT);
251   }  
252   else if(trigger=="INT")
253   {
254     printf("Clusterizing task trigger AnyINT\n");
255     clusterize->SelectCollisionCandidates(AliVEvent::kAny);
256   }
257   else if(trigger=="EMCEGA")
258   {
259     printf("Clusterizing task trigger EMC Gamma\n");
260     clusterize->SelectCollisionCandidates(AliVEvent::kEMCEGA);
261   } 
262   else if(trigger=="EMCEJE")
263   {
264     printf("Clusterizing task trigger EMC Jet\n");
265     clusterize->SelectCollisionCandidates(AliVEvent::kEMCEJE);
266   }
267   else if(trigger=="Central")
268   {
269     printf("Clusterizing task trigger Central\n");
270     clusterize->SelectCollisionCandidates(AliVEvent::kCentral);
271   } 
272   else if(trigger=="SemiCentral")
273   {
274     printf("Clusterizing task trigger SemiCentral\n");
275     clusterize->SelectCollisionCandidates(AliVEvent::kSemiCentral);
276   }
277   
278   // Set clusters branch name, make sure the analysis after this one reads this name
279     
280   //-------------------------------------------------------
281   // Final settings, pass to manager and set the containers
282   //-------------------------------------------------------
283
284   mgr->AddTask(clusterize);
285   
286   // Create containers for input/output
287   AliAnalysisDataContainer *cinput1  = mgr->GetCommonInputContainer()  ;
288   mgr->ConnectInput  (clusterize, 0,  cinput1 );
289   
290   if(bFillAOD)  
291   {
292     printf("AddTaskEMCALClusterize - Fill output AOD\n");
293     AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer() ;
294     mgr->ConnectOutput (clusterize, 0, coutput1 );
295   }
296   return clusterize;
297 }