]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDsimpleMC.cxx
Modifications needed to do the following:
[u/mrichter/AliRoot.git] / TRD / AliTRDsimpleMC.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15  
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Simple TRD Monte Carlo class                                             //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23  
24 #include <stdlib.h>
25
26 #include <TLorentzVector.h>
27  
28 #include "AliRun.h"
29 #include "AliTRDgeometry.h"
30 #include "AliTRDsimpleMC.h"
31 #include "AliTRDv1.h"
32 #include "AliMC.h"
33
34 ClassImp(AliTRDsimpleMC)
35  
36 //_____________________________________________________________________________
37 AliTRDsimpleMC::AliTRDsimpleMC()
38 {                       
39   //
40   // AliTRDsimpleMC default constructor
41   //
42        
43   fMaxStep       = 0.0;
44   fNStep         = 0;
45   fTrack         = 0;
46   fTrackPx       = 0.0;
47   fTrackPy       = 0.0;
48   fTrackPz       = 0.0;
49   fTrackPtot     = 0.0;          
50   fTrackEtot     = 0.0;
51   fTrackX        = 0.0;          
52   fTrackY        = 0.0;          
53   fTrackZ        = 0.0;       
54   fTrackStep     = 0.0;
55   fTrackPid      = 0;
56   fTrackCharge   = 0.0;
57   fTrackMass     = 0.0;
58   fTrackEntering = kFALSE;   
59
60   fTRD           = NULL;
61
62 }
63
64 //_____________________________________________________________________________
65 AliTRDsimpleMC::AliTRDsimpleMC(const char *name, const char *title)
66                :TVirtualMC(name,title,kFALSE)
67 {                       
68   //
69   // AliTRDsimpleMC default constructor
70   //
71        
72   fMaxStep       = 0.0;
73   fNStep         = 0;
74   fTrack         = 0;
75   fTrackPx       = 0.0;
76   fTrackPy       = 0.0;
77   fTrackPz       = 0.0;
78   fTrackPtot     = 0.0;          
79   fTrackEtot     = 0.0;
80   fTrackX        = 0.0;          
81   fTrackY        = 0.0;          
82   fTrackZ        = 0.0;       
83   fTrackStep     = 0.0;
84   fTrackPid      = 0;
85   fTrackCharge   = 0.0;
86   fTrackMass     = 0.0;
87   fTrackEntering = kFALSE;   
88
89   fTRD           = NULL;
90
91 }
92  
93 //_____________________________________________________________________________
94 AliTRDsimpleMC::AliTRDsimpleMC(const AliTRDsimpleMC &m):TVirtualMC(m)
95 {
96   //
97   // AliTRDsimpleMC copy constructor
98   //
99  
100   ((AliTRDsimpleMC &) m).Copy(*this);
101  
102 }
103  
104 //_____________________________________________________________________________
105 AliTRDsimpleMC::~AliTRDsimpleMC()
106 {
107   //
108   // AliTRDsimpleMC destructor
109   //
110  
111 }                                                                               
112  
113 //_____________________________________________________________________________
114 AliTRDsimpleMC &AliTRDsimpleMC::operator=(const AliTRDsimpleMC &m)
115 {
116   //
117   // Assignment operator
118   //
119  
120   if (this != &m) ((AliTRDsimpleMC &) m).Copy(*this);
121   return *this;
122  
123 }
124  
125 //_____________________________________________________________________________
126 void AliTRDsimpleMC::Copy(TObject &m) const
127 {
128   //
129   // Copy function
130   //                             
131                  
132   ((AliTRDsimpleMC &) m).fMaxStep       = fMaxStep;
133   ((AliTRDsimpleMC &) m).fNStep         = fNStep;
134   ((AliTRDsimpleMC &) m).fTrack         = fTrack;
135   ((AliTRDsimpleMC &) m).fTrackPx       = fTrackPx;
136   ((AliTRDsimpleMC &) m).fTrackPy       = fTrackPy;
137   ((AliTRDsimpleMC &) m).fTrackPz       = fTrackPz;
138   ((AliTRDsimpleMC &) m).fTrackPtot     = fTrackPtot;
139   ((AliTRDsimpleMC &) m).fTrackEtot     = fTrackEtot;
140   ((AliTRDsimpleMC &) m).fTrackX        = fTrackX;
141   ((AliTRDsimpleMC &) m).fTrackY        = fTrackY;
142   ((AliTRDsimpleMC &) m).fTrackZ        = fTrackZ;
143   ((AliTRDsimpleMC &) m).fTrackStep     = fTrackStep;
144   ((AliTRDsimpleMC &) m).fTrackPid      = fTrackPid;
145   ((AliTRDsimpleMC &) m).fTrackCharge   = fTrackCharge;
146   ((AliTRDsimpleMC &) m).fTrackMass     = fTrackMass;
147   ((AliTRDsimpleMC &) m).fTrackEntering = fTrackEntering;
148
149 }
150                                                                                 
151 //_____________________________________________________________________________
152 void AliTRDsimpleMC::NewTrack(Int_t iTrack, Int_t pdg
153                              , Double_t px, Double_t py, Double_t pz)
154 {
155   //
156   // Starts a new track.
157   // 
158
159   if (!fTRD) {
160     fTRD = (AliTRDv1 *) gAlice->GetDetector("TRD");   
161     fX0  = AliTRDgeometry::GetTime0(0) - AliTRDgeometry::DrThick();
162   }
163
164   fTRD->ResetHits();
165
166   fTrack         = iTrack;
167   fMaxStep       = 0.0;
168   fNStep         = 0;
169   fTrackStep     = 0.0;
170   fTrackPid      = pdg;
171   fTrackEntering = kTRUE;
172
173   switch (pdg) {
174   case kPdgElectron:
175     fTrackMass   =  5.11e-4;
176     fTrackCharge = -1.0;
177     break;
178   case kPdgPion:
179     fTrackMass   =  0.13957;
180     fTrackCharge =  1.0;
181     break;
182   default:
183     printf("<AliTRDsimpleMC::NewTrack> PDG code %d not implemented\n",pdg);
184     break;
185   };
186
187   Double_t pTot2 = px*px + py*py + pz*pz;
188   fTrackPtot = TMath::Sqrt(pTot2);
189   fTrackEtot = TMath::Sqrt(pTot2 + fTrackMass*fTrackMass); 
190   fTrackPx   = px;
191   fTrackPy   = py;
192   fTrackPz   = pz;
193   
194   fTrackX    = fX0;
195   fTrackY    = 0.0;
196   fTrackZ    = 0.0;
197
198   gAlice->GetMCApp()->SetCurrentTrack(0);
199
200 }
201                                                                                 
202 //_____________________________________________________________________________
203 void AliTRDsimpleMC::ProcessEvent()
204 {
205   //
206   // Process one single track:
207   //   - Determines the step size.
208   //   - Calculates the track position
209   //   - Calls TRD step manager.
210   //
211
212   // The stepsize from an exponential distribution
213   fTrackStep = gRandom->Exp(fMaxStep);  
214
215   if ((fTrackEntering) && (fNStep > 0)) {
216     fTrackEntering = kFALSE;
217   }
218   fNStep++;
219
220   // New track position
221   Double_t d  = fTrackStep / fTrackPtot;
222   fTrackX += fTrackPx * d;
223   fTrackY += fTrackPy * d;
224   fTrackZ += fTrackPz * d;
225
226   // Call the TRD step manager
227   fTRD->StepManager();  
228
229 }
230
231 //_____________________________________________________________________________
232 void AliTRDsimpleMC::TrackPosition(TLorentzVector& position) const
233 {
234   //
235   // Track Position
236   //
237
238   position[0] = fTrackX;
239   position[1] = fTrackY;
240   position[2] = fTrackZ;
241
242 }
243
244 //_____________________________________________________________________________
245 void AliTRDsimpleMC::TrackPosition(Double_t &x, Double_t &y, Double_t &z) const
246 {
247   //
248   // Track Position
249   //
250
251   x = fTrackX;
252   y = fTrackY;
253   z = fTrackZ;
254
255 }
256
257 //_____________________________________________________________________________
258 void AliTRDsimpleMC::TrackMomentum(TLorentzVector& momentum) const
259 {
260   //
261   // Track Momentum
262   //
263
264   momentum[0] = fTrackPx;
265   momentum[1] = fTrackPy;
266   momentum[2] = fTrackPz;
267   momentum[3] = fTrackEtot;
268
269 }
270
271 //_____________________________________________________________________________
272 void AliTRDsimpleMC::TrackMomentum(Double_t &px, Double_t &py,
273                                    Double_t &pz, Double_t &et) const
274 {
275   //
276   // Track Momentum
277   //
278
279   px = fTrackPx;
280   py = fTrackPy;
281   pz = fTrackPz;
282   et = fTrackEtot;
283
284 }
285
286 //_____________________________________________________________________________
287 Int_t AliTRDsimpleMC::VolId(const Text_t* volName) const
288 {
289   //
290   // Returns the volume IDs:
291   //   1 = drift region
292   //   2 = amplification region
293   //   3 = drift chambers
294   // 
295  
296   Int_t volId = -1;
297
298   if      (strcmp(volName,"UJ00") == 0) {
299     volId = kVolDrRg;
300   }
301   else if (strcmp(volName,"UK00") == 0) {
302     volId = kVolAmRg;
303   }
304   else if (strcmp(volName,"UC00") == 0) {
305     volId = kVolDrCh;
306   }
307
308   return volId;
309
310 }
311
312 //_____________________________________________________________________________
313 Int_t AliTRDsimpleMC::CurrentVolID(Int_t& copyNo) const
314 {
315   //
316   // Check for the current volume
317   //
318
319   Int_t volId = -1;
320
321   copyNo = 0;
322
323   // Drift region
324   if      ((fTrackX-fX0) <  AliTRDgeometry::DrThick()) {
325     volId = kVolDrRg;
326   }
327   else if ((fTrackX-fX0) < (AliTRDgeometry::DrThick() +
328                             AliTRDgeometry::AmThick())) {
329     volId = kVolAmRg;
330   }
331
332   return volId;
333
334 }
335
336 //_____________________________________________________________________________
337 const char *AliTRDsimpleMC::CurrentVolName() const
338 {
339   //
340   // Check for the current volume
341   //
342
343   const char *volName = "UA00";
344
345   // Drift region
346   if      ((fTrackX-fX0) <  AliTRDgeometry::DrThick()) {
347     volName = "UJ00";
348   }
349   else if ((fTrackX-fX0) < (AliTRDgeometry::DrThick() +
350                             AliTRDgeometry::AmThick())) {
351     volName = "UK00";
352   }
353
354   return volName;
355
356 }
357
358 //_____________________________________________________________________________
359 Int_t AliTRDsimpleMC::CurrentVolOffID(Int_t , Int_t &copyNo) const
360 {
361   //
362   // Check for the current volume
363   //
364
365   copyNo = 1;
366   return kVolDrCh;
367
368 }