]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDsimpleMC.cxx
Protection against division by 0 in Binaries().
[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 /*
17 $Log$
18 Revision 1.5  2003/01/07 09:03:52  alibrary
19 New TrackMomentum and Position without LorentzVectors
20
21 Revision 1.4  2002/11/21 22:38:47  alibrary
22 Removing AliMC and AliMCProcess
23
24 Revision 1.3  2002/10/14 14:57:44  hristov
25 Merging the VirtualMC branch to the main development branch (HEAD)
26
27 Revision 1.1.8.1  2002/07/24 10:09:31  alibrary
28 Updating VirtualMC
29
30 Revision 1.2  2002/06/12 09:54:35  cblume
31 Update of tracking code provided by Sergei
32
33 Revision 1.1  2001/11/06 17:19:41  cblume
34 Add detailed geometry and simple simulator
35                                                           
36 */
37  
38 ///////////////////////////////////////////////////////////////////////////////
39 //                                                                           //
40 //  Simple TRD Monte Carlo class                                             //
41 //                                                                           //
42 ///////////////////////////////////////////////////////////////////////////////
43  
44 #include <stdlib.h>
45
46 #include <TLorentzVector.h>
47  
48 #include "AliRun.h"
49
50 #include "AliTRDsimpleMC.h"
51 #include "AliTRDgeometry.h"
52 #include "AliTRDv1.h"
53 #include "AliTRDparameter.h"
54  
55 ClassImp(AliTRDsimpleMC)
56  
57 //_____________________________________________________________________________
58 AliTRDsimpleMC::AliTRDsimpleMC()
59 {                       
60   //
61   // AliTRDsimpleMC default constructor
62   //
63        
64   fMaxStep       = 0.0;
65   fNStep         = 0;
66   fTrack         = 0;
67   fTrackPx       = 0.0;
68   fTrackPy       = 0.0;
69   fTrackPz       = 0.0;
70   fTrackPtot     = 0.0;          
71   fTrackEtot     = 0.0;
72   fTrackX        = 0.0;          
73   fTrackY        = 0.0;          
74   fTrackZ        = 0.0;       
75   fTrackStep     = 0.0;
76   fTrackPid      = 0;
77   fTrackCharge   = 0.0;
78   fTrackMass     = 0.0;
79   fTrackEntering = kFALSE;   
80
81   fTRD           = NULL;
82   fPar           = NULL;
83                                         
84 }                                                                               
85
86 //_____________________________________________________________________________
87 AliTRDsimpleMC::AliTRDsimpleMC(const char *name, const char *title)
88                :TVirtualMC(name,title)
89 {                       
90   //
91   // AliTRDsimpleMC default constructor
92   //
93        
94   fMaxStep       = 0.0;
95   fNStep         = 0;
96   fTrack         = 0;
97   fTrackPx       = 0.0;
98   fTrackPy       = 0.0;
99   fTrackPz       = 0.0;
100   fTrackPtot     = 0.0;          
101   fTrackEtot     = 0.0;
102   fTrackX        = 0.0;          
103   fTrackY        = 0.0;          
104   fTrackZ        = 0.0;       
105   fTrackStep     = 0.0;
106   fTrackPid      = 0;
107   fTrackCharge   = 0.0;
108   fTrackMass     = 0.0;
109   fTrackEntering = kFALSE;   
110
111   fTRD           = NULL;
112   fPar           = NULL;
113                                         
114 }                                                                               
115  
116 //_____________________________________________________________________________
117 AliTRDsimpleMC::AliTRDsimpleMC(const AliTRDsimpleMC &m)
118 {
119   //
120   // AliTRDsimpleMC copy constructor
121   //
122  
123   ((AliTRDsimpleMC &) m).Copy(*this);
124  
125 }
126  
127 //_____________________________________________________________________________
128 AliTRDsimpleMC::~AliTRDsimpleMC()
129 {
130   //
131   // AliTRDsimpleMC destructor
132   //
133  
134 }                                                                               
135  
136 //_____________________________________________________________________________
137 AliTRDsimpleMC &AliTRDsimpleMC::operator=(const AliTRDsimpleMC &m)
138 {
139   //
140   // Assignment operator
141   //
142  
143   if (this != &m) ((AliTRDsimpleMC &) m).Copy(*this);
144   return *this;
145  
146 }
147  
148 //_____________________________________________________________________________
149 void AliTRDsimpleMC::Copy(TObject &m)
150 {
151   //
152   // Copy function
153   //                             
154                  
155   ((AliTRDsimpleMC &) m).fMaxStep       = fMaxStep;
156   ((AliTRDsimpleMC &) m).fNStep         = fNStep;
157   ((AliTRDsimpleMC &) m).fTrack         = fTrack;
158   ((AliTRDsimpleMC &) m).fTrackPx       = fTrackPx;
159   ((AliTRDsimpleMC &) m).fTrackPy       = fTrackPy;
160   ((AliTRDsimpleMC &) m).fTrackPz       = fTrackPz;
161   ((AliTRDsimpleMC &) m).fTrackPtot     = fTrackPtot;
162   ((AliTRDsimpleMC &) m).fTrackEtot     = fTrackEtot;
163   ((AliTRDsimpleMC &) m).fTrackX        = fTrackX;
164   ((AliTRDsimpleMC &) m).fTrackY        = fTrackY;
165   ((AliTRDsimpleMC &) m).fTrackZ        = fTrackZ;
166   ((AliTRDsimpleMC &) m).fTrackStep     = fTrackStep;
167   ((AliTRDsimpleMC &) m).fTrackPid      = fTrackPid;
168   ((AliTRDsimpleMC &) m).fTrackCharge   = fTrackCharge;
169   ((AliTRDsimpleMC &) m).fTrackMass     = fTrackMass;
170   ((AliTRDsimpleMC &) m).fTrackEntering = fTrackEntering;
171
172 }
173                                                                                 
174 //_____________________________________________________________________________
175 void AliTRDsimpleMC::NewTrack(Int_t iTrack, Int_t pdg
176                              , Double_t px, Double_t py, Double_t pz)
177 {
178   //
179   // Starts a new track.
180   // 
181
182   if (!fPar) {
183     fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
184   }
185
186   if (!fTRD) {
187     fTRD = (AliTRDv1 *) gAlice->GetDetector("TRD");   
188     fX0  = fPar->GetTime0(0) - AliTRDgeometry::DrThick(); 
189   }
190
191   fTRD->ResetHits();
192
193   fTrack         = iTrack;
194   fMaxStep       = 0.0;
195   fNStep         = 0;
196   fTrackStep     = 0.0;
197   fTrackPid      = pdg;
198   fTrackEntering = kTRUE;
199
200   switch (pdg) {
201   case kPdgElectron:
202     fTrackMass   =  5.11e-4;
203     fTrackCharge = -1.0;
204     break;
205   case kPdgPion:
206     fTrackMass   =  0.13957;
207     fTrackCharge =  1.0;
208     break;
209   default:
210     printf("<AliTRDsimpleMC::NewTrack> PDG code %d not implemented\n",pdg);
211     break;
212   };
213
214   Double_t pTot2 = px*px + py*py + pz*pz;
215   fTrackPtot = TMath::Sqrt(pTot2);
216   fTrackEtot = TMath::Sqrt(pTot2 + fTrackMass*fTrackMass); 
217   fTrackPx   = px;
218   fTrackPy   = py;
219   fTrackPz   = pz;
220   
221   fTrackX    = fX0;
222   fTrackY    = 0.0;
223   fTrackZ    = 0.0;
224
225   gAlice->SetCurrentTrack(0);
226
227 }
228                                                                                 
229 //_____________________________________________________________________________
230 void AliTRDsimpleMC::ProcessEvent()
231 {
232   //
233   // Process one single track:
234   //   - Determines the step size.
235   //   - Calculates the track position
236   //   - Calls TRD step manager.
237   //
238
239   // The stepsize from an exponential distribution
240   fTrackStep = gRandom->Exp(fMaxStep);  
241
242   if ((fTrackEntering) && (fNStep > 0)) {
243     fTrackEntering = kFALSE;
244   }
245   fNStep++;
246
247   // New track position
248   Double_t d  = fTrackStep / fTrackPtot;
249   fTrackX += fTrackPx * d;
250   fTrackY += fTrackPy * d;
251   fTrackZ += fTrackPz * d;
252
253   // Call the TRD step manager
254   fTRD->StepManager();  
255
256 }
257
258 //_____________________________________________________________________________
259 void AliTRDsimpleMC::TrackPosition(TLorentzVector& position) const
260 {
261   //
262   // Track Position
263   //
264
265   position[0] = fTrackX;
266   position[1] = fTrackY;
267   position[2] = fTrackZ;
268
269 }
270
271 //_____________________________________________________________________________
272 void AliTRDsimpleMC::TrackPosition(Double_t &x, Double_t &y, Double_t &z) const
273 {
274   //
275   // Track Position
276   //
277
278   x = fTrackX;
279   y = fTrackY;
280   z = fTrackZ;
281
282 }
283
284 //_____________________________________________________________________________
285 void AliTRDsimpleMC::TrackMomentum(TLorentzVector& momentum) const
286 {
287   //
288   // Track Momentum
289   //
290
291   momentum[0] = fTrackPx;
292   momentum[1] = fTrackPy;
293   momentum[2] = fTrackPz;
294   momentum[3] = fTrackEtot;
295
296 }
297
298 //_____________________________________________________________________________
299 void AliTRDsimpleMC::TrackMomentum(Double_t &px, Double_t &py, Double_t &pz, Double_t &etot) const
300 {
301   //
302   // Track Momentum
303   //
304
305   px   = fTrackPx;
306   py   = fTrackPy;
307   pz   = fTrackPz;
308   etot = fTrackEtot;
309
310 }
311
312 //_____________________________________________________________________________
313 Int_t AliTRDsimpleMC::VolId(const Text_t* volName) const
314 {
315   //
316   // Returns the volume IDs:
317   //   1 = drift region
318   //   2 = amplification region
319   //   3 = drift chambers
320   // 
321  
322   Int_t volId = -1;
323
324   if      (strcmp(volName,"UJ00") == 0) {
325     volId = kVolDrRg;
326   }
327   else if (strcmp(volName,"UK00") == 0) {
328     volId = kVolAmRg;
329   }
330   else if (strcmp(volName,"UC00") == 0) {
331     volId = kVolDrCh;
332   }
333
334   return volId;
335
336 }
337
338 //_____________________________________________________________________________
339 Int_t AliTRDsimpleMC::CurrentVolID(Int_t& copyNo) const
340 {
341   //
342   // Check for the current volume
343   //
344
345   Int_t volId = -1;
346
347   copyNo = 0;
348
349   // Drift region
350   if      ((fTrackX-fX0) <  AliTRDgeometry::DrThick()) {
351     volId = kVolDrRg;
352   }
353   else if ((fTrackX-fX0) < (AliTRDgeometry::DrThick() +
354                             AliTRDgeometry::AmThick())) {
355     volId = kVolAmRg;
356   }
357
358   return volId;
359
360 }
361
362 //_____________________________________________________________________________
363 const char *AliTRDsimpleMC::CurrentVolName() const
364 {
365   //
366   // Check for the current volume
367   //
368
369   Char_t *volName = "UA00";
370
371   // Drift region
372   if      ((fTrackX-fX0) <  AliTRDgeometry::DrThick()) {
373     volName = "UJ00";
374   }
375   else if ((fTrackX-fX0) < (AliTRDgeometry::DrThick() +
376                             AliTRDgeometry::AmThick())) {
377     volName = "UK00";
378   }
379
380   return volName;
381
382 }
383
384 //_____________________________________________________________________________
385 Int_t AliTRDsimpleMC::CurrentVolOffID(Int_t off, Int_t &copyNo) const
386 {
387   //
388   // Check for the current volume
389   //
390
391   copyNo = 1;
392   return kVolDrCh;
393
394 }