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