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