]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONv1.cxx
Adding comment lines to class description needed for Root documentation,
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.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 purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-----------------------------------------------------------------------------
19 // Class AliMUONv1
20 // --------------------
21 // AliDetector class for MUON subsystem which implements
22 // functions for simulation 
23 //-----------------------------------------------------------------------------
24
25 #include "AliMUONv1.h"
26 #include "AliMUONConstants.h"
27 #include "AliMUONResponseFactory.h"
28 #include "AliMUONHit.h"
29 #include "AliMUONGeometryBuilder.h"     
30 #include "AliMUONGeometry.h"    
31 #include "AliMUONGeometryTransformer.h" 
32 #include "AliMUONGeometryModule.h"      
33 #include "AliMUONStringIntMap.h"        
34 #include "AliMUONGeometryDetElement.h"  
35
36 #include "AliMpDEManager.h"
37
38 #include "AliConst.h" 
39 #include "AliMagF.h"
40 #include "AliRun.h"
41 #include "AliMC.h"
42 #include "AliTrackReference.h"
43 #include "AliLog.h"
44
45 #include <TRandom.h>
46 #include <TF1.h>
47 #include <TClonesArray.h>
48 #include <TRandom.h> 
49 #include <TVirtualMC.h>
50 #include <TGeoMatrix.h>
51
52 #include <string>
53
54 #include "AliMUONVHitStore.h"
55
56 /// \cond CLASSIMP
57 ClassImp(AliMUONv1)
58 /// \endcond
59  
60 //___________________________________________
61 AliMUONv1::AliMUONv1() 
62   : AliMUON(),
63     fAngleEffect(kTRUE),
64     fStepMaxInActiveGas(0.6),
65     fStepSum(0x0),
66     fDestepSum(0x0),
67     fTrackMomentum(), 
68     fTrackPosition(),
69     fElossRatio(0x0),
70     fAngleEffect10(0x0),
71     fAngleEffectNorma(0x0)
72 {
73 /// Default constructor
74   
75   AliDebug(1,Form("default (empty) ctor this=%p",this));
76
77
78 //___________________________________________
79 AliMUONv1::AliMUONv1(const char *name, const char* title)
80 : AliMUON(name, title), 
81     fAngleEffect(kTRUE),
82     fStepMaxInActiveGas(0.6),
83     fStepSum(0x0),
84     fDestepSum(0x0),
85     fTrackMomentum(), 
86     fTrackPosition(),
87     fElossRatio(0x0),
88     fAngleEffect10(0x0),
89     fAngleEffectNorma(0x0)
90 {
91 /// Standard onstructor
92
93     AliDebug(1,Form("ctor this=%p",this));      
94         
95     // By default include all stations
96
97     fStepSum   = new Float_t [AliMUONConstants::NCh()];
98     fDestepSum = new Float_t [AliMUONConstants::NCh()];
99     for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
100       fStepSum[i] =0.0;
101       fDestepSum[i]=0.0;
102     }
103     // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
104     fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.); 
105     fElossRatio->SetParameter(0,1.02138);
106     fElossRatio->SetParameter(1,-9.54149e-02);
107     fElossRatio->SetParameter(2,+7.83433e-02); 
108     fElossRatio->SetParameter(3,-9.98208e-03);
109     fElossRatio->SetParameter(4,+3.83279e-04);
110
111     // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
112     fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
113     fAngleEffect10->SetParameter(0, 1.90691e+02);
114     fAngleEffect10->SetParameter(1,-6.62258e+01);
115     fAngleEffect10->SetParameter(2,+1.28247e+01);
116     // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)  
117     // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
118     fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
119     fAngleEffectNorma->SetParameter(0,4.148);
120     fAngleEffectNorma->SetParameter(1,-6.809e-01);
121     fAngleEffectNorma->SetParameter(2,5.151e-02);
122     fAngleEffectNorma->SetParameter(3,-1.490e-03);
123 }
124
125 //___________________________________________
126 AliMUONv1::~AliMUONv1()
127 {
128 /// Destructor
129   
130   AliDebug(1,Form("dtor this=%p",this));
131   delete [] fStepSum;
132   delete [] fDestepSum;
133   delete fElossRatio;
134   delete fAngleEffect10;
135   delete fAngleEffectNorma; 
136 }
137
138 //__________________________________________________
139 void AliMUONv1::CreateGeometry()
140 {
141 /// Construct geometry using geometry builder
142
143   fGeometryBuilder->CreateGeometry();
144 }
145
146 //________________________________________________________________
147 void AliMUONv1::CreateMaterials()
148 {
149 /// Construct materials using geometry builder
150
151   fGeometryBuilder->CreateMaterials();
152 }
153
154 //________________________________________________________________
155 void AliMUONv1::AddAlignableVolumes() const
156 {
157 /// Construct materials using geometry builder
158
159   GetGeometryTransformer()->AddAlignableVolumes();
160 }
161
162
163 //___________________________________________
164 void AliMUONv1::Init()
165
166 /// Initialize geometry
167
168   AliDebug(1,"Start Init for version 1 - CPC chamber type");
169    
170   fGeometryBuilder->InitGeometry();
171   AliDebug(1,"Finished Init for version 1 - CPC chamber type");   
172  
173
174   // Build segmentation
175   // using geometry parametrisation
176   //
177   // Build response
178   //
179   AliMUONResponseFactory respFactory("default");
180   respFactory.Build(this);
181   
182 }
183
184 //__________________________________________________________________
185 Int_t  AliMUONv1::GetGeomModuleId(Int_t volId) const
186 {
187 /// Check if the volume with specified  volId is a sensitive volume (gas) 
188 /// of some chamber and return the chamber number;
189 /// if not sensitive volume - return 0.
190
191   for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
192     if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
193       return i;
194   }    
195
196   return -1;
197 }
198
199 //_______________________________________________________________________________
200 TString  AliMUONv1::CurrentVolumePath() const
201 {
202 /// Return current volume path
203 /// (Could be removed when this function is available via gMC)
204
205   TString path = "";
206   TString name;
207   Int_t copyNo;
208   Int_t imother = 0;
209   do {
210     name = gMC->CurrentVolOffName(imother);
211     gMC->CurrentVolOffID(imother++, copyNo);
212     TString add = "/";
213     add += name;
214     add += "_";
215     add += copyNo;
216     path.Insert(0,add); 
217   }
218   while ( name != TString("ALIC") );
219   
220   return path;  
221 }
222
223 //_______________________________________________________________________________
224 void AliMUONv1::StepManager()
225 {
226 /// Step manager for the chambers
227
228   // Only charged tracks
229   if( !(gMC->TrackCharge()) ) return; 
230   // Only charged tracks
231   
232   // Only gas gap inside chamber
233   // Tag chambers and record hits when track enters 
234   static Int_t   idvol=-1, iEnter = 0;
235   Int_t   copy;
236   const  Float_t kBig = 1.e10;
237   static Double_t xyzEnter[3];
238
239   //
240   // Only gas gap inside chamber
241   // Tag chambers and record hits when track enters 
242   Int_t id=gMC->CurrentVolID(copy);
243   Int_t iGeomModule = GetGeomModuleId(id);
244   if (iGeomModule == -1) return;
245
246   // Detection elements id
247   const AliMUONGeometryModule* kGeometryModule
248     = GetGeometry()->GetModule(iGeomModule);
249   AliMUONGeometryDetElement* detElement
250     = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
251     
252   if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
253     iGeomModule++;
254     const AliMUONGeometryModule* kGeometryModule2
255       = GetGeometry()->GetModule(iGeomModule);
256     detElement 
257       = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
258   }    
259
260   Int_t detElemId = 0;
261   if (detElement) detElemId = detElement->GetUniqueID(); 
262  
263   if (!detElemId) {
264     AliErrorStream() 
265          << "Geometry module id: "
266          << setw(3) << iGeomModule << "  "
267          << "Current SV: " 
268          <<  CurrentVolumePath() 
269          << "  detElemId: "
270          << setw(5) << detElemId 
271          << endl;
272     Double_t x, y, z;
273     gMC->TrackPosition(x, y, z);         
274     AliErrorStream() 
275          << "   global position: "
276          << x << ", " << y << ", " << z
277          << endl;
278     AliErrorStream() << "DetElemId not identified." << endl;
279   } 
280   
281   Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1; 
282   idvol = iChamber -1;
283     
284   // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
285   if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
286     AliTrackReference* trackReference    
287       = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
288     trackReference->SetUserId(detElemId);
289   }  
290   
291   if( gMC->IsTrackEntering() ) {
292      Float_t theta = fTrackMomentum.Theta();
293      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
294      iEnter = 1;
295      gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
296   }
297
298    //   AliDebug(1,
299    //       Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
300    //            ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
301   // Particule id and mass, 
302   Int_t     ipart = gMC->TrackPid();
303   Float_t   mass  = gMC->TrackMass();
304
305   fDestepSum[idvol]+=gMC->Edep();
306   // Get current particle id (ipart), track position (pos)  and momentum (mom)
307   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
308   fStepSum[idvol]+=gMC->TrackStep();
309   
310   //  if (AliDebugLevel()) {
311   //   AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
312   //                 iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
313   //         mass, fStepSum[idvol], gMC->Edep()));
314   // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), 
315   //         fTrackMomentum.Z()));
316   // gMC->TrackPosition(fTrackPosition);
317   // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
318   //         fTrackPosition.Y(),fTrackPosition.Z())) ;
319   //}
320
321   // Track left chamber or StepSum larger than fStepMaxInActiveGas
322   if ( gMC->IsTrackExiting() || 
323        gMC->IsTrackStop() || 
324        gMC->IsTrackDisappeared()||
325        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
326     
327     if   ( gMC->IsTrackExiting() || 
328            gMC->IsTrackStop() || 
329            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
330     if (fDestepSum[idvol] == 0) {
331       // AZ - no energy release
332       fStepSum[idvol] = 0; // Reset for the next event
333       iEnter = 0;
334       return; 
335     }
336
337     gMC->TrackPosition(fTrackPosition);
338     Float_t theta = fTrackMomentum.Theta();
339     Float_t phi   = fTrackMomentum.Phi();
340     
341     Int_t merge = 0;
342     Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
343     if (gMC->IsTrackExiting() && iEnter != 0) {
344       // AZ - this code is to avoid artificial hit splitting at the
345       // "fake" boundary inside the same chamber. It will still produce 
346       // 2 hits but with the same coordinates (at the wire) to allow 
347       // their merging at the digitization level.
348
349       // Only for a track going from the entrance to the exit from the volume
350       // Get local coordinates
351       gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
352
353       fTrackPosition.Vect().GetXYZ(tmp);
354       gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
355       Float_t dx = xyz0[0] - xyz1[0];
356       Float_t dy = xyz0[1] - xyz1[1];
357       Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
358       if (thLoc * TMath::RadToDeg() < 15) merge = 1; 
359     }
360
361     if (merge) {
362       Double_t dz = -0.5;
363       if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
364       tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
365       tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
366       tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
367       gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
368       fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
369     } else {
370       TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
371                                  fStepSum[idvol]/2.*sin(theta)*sin(phi),
372                                  fStepSum[idvol]/2.*cos(theta),0.0       );
373       fTrackPosition-=backToWire;
374       //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
375       //    AliDebug(1,
376       //     Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
377       // AliDebug(1,
378       //     Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
379     }
380     
381     //-------------- Angle effect 
382     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
383     
384     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
385     Float_t sigmaEffect10degrees;
386     Float_t sigmaEffectThetadegrees;
387     Float_t eLossParticleELossMip;
388     Float_t yAngleEffect=0.;
389     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
390
391
392     if (fAngleEffect){
393     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
394       betaxGamma=TMath::Log(betaxGamma);
395       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
396       // 10 degrees is a reference for a model (arbitrary)
397       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
398       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
399       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
400       if ( (iChamber==1)  ||  (iChamber==2) )  
401         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
402       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
403     }
404     }
405     
406     AliMUONHit hit(fIshunt, 
407                           gAlice->GetMCApp()->GetCurrentTrackNumber(), 
408                           detElemId, ipart,
409                           fTrackPosition.X(), 
410                           fTrackPosition.Y()+yAngleEffect, 
411                           fTrackPosition.Z(), 
412                           gMC->TrackTime(),
413                           fTrackMomentum.P(),
414                           theta, 
415                           phi, 
416                           fStepSum[idvol], 
417                           fDestepSum[idvol],                        
418                           fTrackPosition.X(),
419                           fTrackPosition.Y(),
420                           fTrackPosition.Z());
421
422     fHitStore->Add(hit);
423
424     fStepSum[idvol]  =0; // Reset for the next event
425     fDestepSum[idvol]=0; // Reset for the next event
426     iEnter = 0;
427   }
428 }