]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/EMCALJetTasks/AliJetModelBaseTask.cxx
geometry handling
[u/mrichter/AliRoot.git] / PWGGA / EMCALJetTasks / AliJetModelBaseTask.cxx
1 // $Id$
2 //
3 // Jet modelling task.
4 //
5 // Author: Salvatore Aiola, Constantin Loizides
6
7 #include <TClonesArray.h>
8 #include <TLorentzVector.h>
9 #include <TRandom3.h>
10
11 #include "AliAnalysisManager.h"
12 #include "AliVEvent.h"
13 #include "AliVCluster.h"
14 #include "AliEMCALDigit.h"
15 #include "AliEMCALRecPoint.h"
16 #include "AliPicoTrack.h"
17 #include "AliEMCALGeometry.h"
18 #include "AliLog.h"
19
20 #include "AliJetModelBaseTask.h"
21
22 ClassImp(AliJetModelBaseTask)
23
24 //________________________________________________________________________
25 AliJetModelBaseTask::AliJetModelBaseTask() : 
26   AliAnalysisTaskSE("AliJetModelBaseTask"),
27   fGeomName(),
28   fTracksName(),
29   fOutTracksName(),
30   fCaloName(),
31   fOutCaloName(),
32   fSuffix(),
33   fEtaMin(-1),
34   fEtaMax(1),
35   fPhiMin(0),
36   fPhiMax(TMath::Pi() * 2),
37   fPtMin(0),
38   fPtMax(0),
39   fCopyArray(kTRUE),
40   fNClusters(0),
41   fNTracks(0),
42   fGeom(0),
43   fClusters(0),
44   fOutClusters(0),
45   fTracks(0),
46   fOutTracks(0)
47 {
48   // Default constructor.
49 }
50
51 //________________________________________________________________________
52 AliJetModelBaseTask::AliJetModelBaseTask(const char *name) : 
53   AliAnalysisTaskSE(name),
54   fGeomName(""),
55   fTracksName("PicoTracks"),
56   fOutTracksName("PicoTracksEmbedded"),
57   fCaloName("CaloClustersCorr"),
58   fOutCaloName("CaloClustersCorrEmbedded"),
59   fSuffix("Processed"),
60   fEtaMin(-1),
61   fEtaMax(1),
62   fPhiMin(0),
63   fPhiMax(TMath::Pi() * 2),
64   fPtMin(50),
65   fPtMax(60),
66   fCopyArray(kTRUE),
67   fNClusters(0),
68   fNTracks(1),
69   fGeom(0),
70   fClusters(0),
71   fOutClusters(0),
72   fTracks(0),
73   fOutTracks(0)
74 {
75   // Standard constructor.
76
77 }
78
79 //________________________________________________________________________
80 AliJetModelBaseTask::~AliJetModelBaseTask()
81 {
82   // Destructor
83 }
84
85 //________________________________________________________________________
86 void AliJetModelBaseTask::Init()
87 {
88   // Init task.
89
90   if (fPtMax < fPtMin) {
91     AliWarning (Form("PtMax (%f) < PtMin (%f), setting PtMax = PtMin = %f", fPtMax, fPtMin, fPtMin));
92     fPtMax = fPtMin;
93   }
94
95   if (fEtaMax < fEtaMin) {
96     AliWarning (Form("EtaMax (%f) < EtaMin (%f), setting EtaMax = EtaMin = %f", fEtaMax, fEtaMin, fEtaMin));
97     fEtaMax = fEtaMin;
98   }
99
100   if (fPhiMax < fPhiMin) {
101     AliWarning (Form("PhiMax (%f) < PhiMin (%f), setting PhiMax = PhiMin = %f", fPhiMax, fPhiMin, fPhiMin));
102     fPhiMax = fPhiMin;
103   }
104
105   if (fNTracks > 0) {
106     fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
107
108     if (strcmp(fTracks->GetClass()->GetName(), "AliPicoTrack")) {
109       AliError("Can only embed PicoTracks!");
110       return;
111     }
112  
113     if (!fTracks) {
114       AliError(Form("Couldn't retrieve tracks with name %s!", fTracksName.Data()));
115       return;
116     }
117
118     if (!fOutTracks) {
119       fOutTracksName = fTracksName;
120       if (fCopyArray) {
121         fOutTracksName += fSuffix;
122         fOutTracks = new TClonesArray(*fTracks);
123         fOutTracks->SetName(fOutTracksName);
124       }
125       else {
126         fOutTracks = fTracks;
127       }
128     }
129
130     if (fCopyArray) {
131       if (!(InputEvent()->FindListObject(fOutTracksName)))
132         InputEvent()->AddObject(fOutTracks);
133       fOutTracks->Clear();
134     }
135   }
136
137   if (fNClusters > 0) {
138     fClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
139  
140     if (!fClusters) {
141       AliError(Form("Couldn't retrieve clusters with name %s!", fCaloName.Data()));
142       return;
143     }
144
145     if (!fOutClusters) {
146       fOutCaloName = fCaloName;
147       if (fCopyArray) {
148         fOutCaloName += fSuffix;
149         fOutClusters = new TClonesArray(*fClusters);
150         fOutClusters->SetName(fOutCaloName);
151       }
152       else {
153         fOutClusters = fClusters;
154       }
155     }
156
157     if (fCopyArray) {
158       if (!(InputEvent()->FindListObject(fOutCaloName)))
159         InputEvent()->AddObject(fOutClusters);
160       fOutClusters->Clear();
161     }
162
163     if (!fGeom) {
164       if (fGeomName.Length() > 0) {
165         fGeom = AliEMCALGeometry::GetInstance(fGeomName);
166         if (!fGeom)
167           AliError(Form("Could not get geometry with name %s!", fGeomName.Data()));
168       } else {
169         fGeom = AliEMCALGeometry::GetInstance();
170         if (!fGeom) 
171           AliError("Could not get default geometry!");
172       }
173     }
174     
175     // hard-coded Emcal boundaries
176     const Float_t EmcalEtaMin = -0.7;
177     const Float_t EmcalEtaMax = 0.7;
178     const Float_t EmcalPhiMin = 80 * TMath::DegToRad();
179     const Float_t EmcalPhiMax = 180 * TMath::DegToRad();
180
181     if (fEtaMax > EmcalEtaMax) fEtaMax = EmcalEtaMax;
182     if (fEtaMax < EmcalEtaMin) fEtaMax = EmcalEtaMin;
183     if (fEtaMin > EmcalEtaMax) fEtaMin = EmcalEtaMax;
184     if (fEtaMin < EmcalEtaMin) fEtaMin = EmcalEtaMin;
185   
186     if (fPhiMax > EmcalPhiMax) fPhiMax = EmcalPhiMax;
187     if (fPhiMax < EmcalPhiMin) fPhiMax = EmcalPhiMin;
188     if (fPhiMin > EmcalPhiMax) fPhiMin = EmcalPhiMax;
189     if (fPhiMin < EmcalPhiMin) fPhiMin = EmcalPhiMin;
190   }
191 }
192
193 //________________________________________________________________________
194 void AliJetModelBaseTask::GetRandomCell(Double_t &eta, Double_t &phi, Int_t &absId)
195 {
196   Int_t repeats = 0;
197
198   do {
199     eta = gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
200     phi = gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
201     fGeom->GetAbsCellIdFromEtaPhi(eta, phi, absId);  
202     repeats++;
203   } while (absId == -1 && repeats < 100);
204   
205   if (!(absId > -1)) {
206     AliWarning(Form("Could not extract random cluster! Random eta-phi extracted more than 100 times!\n"
207                     "eta [%f, %f], phi [%f, %f]\n", fEtaMin, fEtaMax, fPhiMin, fPhiMax));
208   }
209 }
210
211 //________________________________________________________________________
212 Double_t AliJetModelBaseTask::GetRandomEta()
213 {
214   return gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
215 }
216
217 //________________________________________________________________________
218 Double_t AliJetModelBaseTask::GetRandomPhi()
219 {
220   return gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
221 }
222
223 //________________________________________________________________________
224 Double_t AliJetModelBaseTask::GetRandomPt()
225 {
226   return gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
227 }
228
229 //________________________________________________________________________
230 AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Double_t eta, Double_t phi)
231 {
232   Int_t absId = 0;
233   if (eta < 0 || phi < 0) {
234     GetRandomCell(eta, phi, absId);
235   }
236   else {
237     fGeom->EtaPhiFromIndex(absId, eta, phi);
238   }
239
240   if (absId == -1) {
241     AliWarning(Form("Unable to embed cluster in eta = %f, phi = %f!"
242                     " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])", 
243                     eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
244     return 0;
245   } 
246
247   if (e < 0) {
248     Double_t pt = GetRandomPt();
249     TLorentzVector nPart;
250     nPart.SetPtEtaPhiM(pt, eta, phi, 0);
251     e = nPart.E();
252   }
253
254   return AddCluster(e, absId);
255 }
256       
257 //________________________________________________________________________
258 AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Int_t absId)
259 {
260   const Int_t nClusters = fOutClusters->GetEntriesFast();
261
262   TClonesArray digits("AliEMCALDigit", 1);
263
264   AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(digits.New(0));
265   digit->SetId(absId);
266   digit->SetIndexInList(0);
267   digit->SetType(AliEMCALDigit::kHG);
268   digit->SetAmplitude(e);
269       
270   AliEMCALRecPoint recPoint("");
271   recPoint.AddDigit(*digit, e, kFALSE);
272   recPoint.EvalGlobalPosition(0, &digits);
273
274   TVector3 gpos;
275   recPoint.GetGlobalPosition(gpos);
276   Float_t g[3];
277   gpos.GetXYZ(g);
278       
279   AliVCluster *cluster = static_cast<AliVCluster*>(fOutClusters->New(nClusters));
280   cluster->SetType(AliVCluster::kEMCALClusterv1);
281   cluster->SetE(recPoint.GetEnergy());
282   cluster->SetPosition(g);
283   cluster->SetNCells(1);
284   UShort_t shortAbsId = absId;
285   cluster->SetCellsAbsId(&shortAbsId);
286   Double32_t fract = 1;
287   cluster->SetCellsAmplitudeFraction(&fract);
288   cluster->SetID(nClusters);
289   cluster->SetEmcCpvDistance(-1);
290   cluster->SetChi2(100); // MC flag!
291
292   return cluster;
293 }
294
295 //________________________________________________________________________
296 AliPicoTrack* AliJetModelBaseTask::AddTrack(Double_t pt, Double_t eta, Double_t phi)
297 {
298   const Int_t nTracks = fOutTracks->GetEntriesFast();
299   
300   if (pt < 0) 
301     pt = GetRandomPt();
302   if (eta < 0) 
303     eta = GetRandomEta();
304   if (phi < 0) 
305     phi = GetRandomPhi();
306   
307   AliPicoTrack *track = new ((*fOutTracks)[nTracks]) AliPicoTrack(pt, 
308                                                 eta, 
309                                                 phi, 
310                                                 1, 
311                                                 100,    // MC flag!      
312                                                 0, 
313                                                 0, 
314                                                 kFALSE);
315   return track;
316 }
317
318 //________________________________________________________________________
319 void AliJetModelBaseTask::Run() 
320 {
321
322 }
323
324 //________________________________________________________________________
325 void AliJetModelBaseTask::UserExec(Option_t *) 
326 {
327   // Execute per event.
328
329   Init();
330
331   Run();
332
333 }