AliRoot Core  edcc906 (edcc906)
AliMUONv1.cxx
Go to the documentation of this file.
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"
32 #include "AliMUONGeometryModule.h"
33 #include "AliMUONStringIntMap.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 <TClonesArray.h>
47 #include <TF1.h>
48 #include <TF2.h>
49 #include <TGeoGlobalMagField.h>
50 #include <TGeoMatrix.h>
51 #include <TRandom.h>
52 #include <TRandom.h>
53 #include <TVirtualMC.h>
54 
55 #include <string>
56 
57 #include "AliMUONVHitStore.h"
58 #include <iostream>
59 #include <iomanip>
60 
61 using std::endl;
62 using std::cout;
63 using std::setw;
65 ClassImp(AliMUONv1)
67 
68 //___________________________________________
70  : AliMUON(),
71  fAngleEffect(kTRUE),
72  fMagEffect(kTRUE),
73  fStepMaxInActiveGas(0.6),
74  fStepSum(0x0),
75  fDestepSum(0x0),
76  fTrackMomentum(),
77  fTrackPosition(),
78  fElossRatio(0x0),
79  fAngleEffect10(0x0),
80  fAngleEffectNorma(0x0),
81  fMagAngleEffectNorma(0x0)
82 {
84 
85  AliDebug(1,Form("default (empty) ctor this=%p",this));
86 }
87 
88 //___________________________________________
89 AliMUONv1::AliMUONv1(const char *name, const char* title)
90 : AliMUON(name, title),
91  fAngleEffect(kTRUE),
92  fMagEffect(kTRUE),
93  fStepMaxInActiveGas(0.6),
94  fStepSum(0x0),
95  fDestepSum(0x0),
96  fTrackMomentum(),
97  fTrackPosition(),
98  fElossRatio(0x0),
99  fAngleEffect10(0x0),
100  fAngleEffectNorma(0x0),
101  fMagAngleEffectNorma(0x0)
102 {
104 
105  AliDebug(1,Form("ctor this=%p",this));
106 
107  // Load mapping
108  if ( ! AliMpCDB::LoadMpSegmentation() ) {
109  AliFatal("Could not access mapping from OCDB !");
110  }
111 
112  // By default include all stations
113 
114  fStepSum = new Float_t [AliMUONConstants::NCh()];
115  fDestepSum = new Float_t [AliMUONConstants::NCh()];
116  for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
117  fStepSum[i] =0.0;
118  fDestepSum[i]=0.0;
119  }
120  // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
121  fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
122  fElossRatio->SetParameter(0,1.02138);
123  fElossRatio->SetParameter(1,-9.54149e-02);
124  fElossRatio->SetParameter(2,+7.83433e-02);
125  fElossRatio->SetParameter(3,-9.98208e-03);
126  fElossRatio->SetParameter(4,+3.83279e-04);
127 
128  // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
129  fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
130  fAngleEffect10->SetParameter(0, 1.90691e+02);
131  fAngleEffect10->SetParameter(1,-6.62258e+01);
132  fAngleEffect10->SetParameter(2,+1.28247e+01);
133  // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
134  // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
135  fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
136  fAngleEffectNorma->SetParameter(0,4.148);
137  fAngleEffectNorma->SetParameter(1,-6.809e-01);
138  fAngleEffectNorma->SetParameter(2,5.151e-02);
139  fAngleEffectNorma->SetParameter(3,-1.490e-03);
140 
141  // Magnetic field effect: Normalisation form theta=16 degres (eq. 10 degrees B=0) to theta between -20 and 20 (Lamia Benhabib jun 2006 )
142  // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
143  fMagAngleEffectNorma = new TF2("MagAngleEffectNorma","121.24/(([1]+[2]*abs(y))+[3]*abs(x-[0]*y)+[4]*abs((x-[0]*y)*(x-[0]*y))+[5]*abs((x-[0]*y)*(x-[0]*y)*(x-[0]*y))+[6]*abs((x-[0]*y)*(x-[0]*y)*(x-[0]*y)*(x-[0]*y)))",-20.0,20.0,-1.,1.);
144  fMagAngleEffectNorma->SetParameters(8.6995, 25.4022, 13.8822, 2.4717, 1.1551, -0.0624, 0.0012);
145 }
146 
147 //___________________________________________
149 {
151 
152  AliDebug(1,Form("dtor this=%p",this));
153  delete [] fStepSum;
154  delete [] fDestepSum;
155  delete fElossRatio;
156  delete fAngleEffect10;
157  delete fAngleEffectNorma;
158  delete fMagAngleEffectNorma;
159 }
160 
161 //__________________________________________________
163 {
165 
167 }
168 
169 //________________________________________________________________
171 {
173 
175 }
176 
177 //________________________________________________________________
179 {
181 
182  // Load mapping
183  if ( ! AliMpCDB::LoadMpSegmentation() ) {
184  AliFatal("Could not access mapping from OCDB !");
185  }
186 
188 }
189 
190 //________________________________________________________________
192 {
194 
196 }
197 
198 
199 //___________________________________________
201 {
203 
204  AliDebug(1,"Start Init for version 1 - CPC chamber type");
205 
207  AliDebug(1,"Finished Init for version 1 - CPC chamber type");
208 
209 
210  // Build segmentation
211  // using geometry parametrisation
212  //
213  // Build response
214  //
215  AliMUONResponseFactory respFactory("default", fIsTailEffect);
216  respFactory.Build(this);
217 
218 }
219 
220 //__________________________________________________________________
221 Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
222 {
226 
227  for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
228  if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
229  return i;
230  }
231 
232  return -1;
233 }
234 
235 //_______________________________________________________________________________
237 {
240 
241  TString path = "";
242  TString name;
243  Int_t copyNo;
244  Int_t imother = 0;
245  do {
246  name = TVirtualMC::GetMC()->CurrentVolOffName(imother);
247  TVirtualMC::GetMC()->CurrentVolOffID(imother++, copyNo);
248  TString add = "/";
249  add += name;
250  add += "_";
251  add += copyNo;
252  path.Insert(0,add);
253  }
254  while ( name != TString("ALIC") );
255 
256  return path;
257 }
258 
259 //_______________________________________________________________________________
261 {
263 
264  // Only charged tracks
265  if( !(fMC->TrackCharge()) ) return;
266  // Only charged tracks
267 
268  // Only gas gap inside chamber
269  // Tag chambers and record hits when track enters
270  static Int_t idvol=-1, iEnter = 0;
271  Int_t copy;
272  const Float_t kBig = 1.e10;
273  static Double_t xyzEnter[3];
274 
275  //
276  // Only gas gap inside chamber
277  // Tag chambers and record hits when track enters
278  Int_t id=fMC->CurrentVolID(copy);
279  Int_t iGeomModule = GetGeomModuleId(id);
280  if (iGeomModule == -1) return;
281 
282  // Detection elements id
283  const AliMUONGeometryModule* kGeometryModule
284  = GetGeometry()->GetModule(iGeomModule);
285  AliMUONGeometryDetElement* detElement
286  = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
287 
288  if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
289  iGeomModule++;
290  const AliMUONGeometryModule* kGeometryModule2
291  = GetGeometry()->GetModule(iGeomModule);
292  detElement
293  = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
294  }
295 
296  Int_t detElemId = 0;
297  if (detElement) detElemId = detElement->GetUniqueID();
298 
299  if (!detElemId) {
300  AliErrorStream()
301  << "Geometry module id: "
302  << setw(3) << iGeomModule << " "
303  << "Current SV: "
304  << CurrentVolumePath()
305  << " detElemId: "
306  << setw(5) << detElemId
307  << endl;
308  Double_t x, y, z;
309  fMC->TrackPosition(x, y, z);
310  AliErrorStream()
311  << " global position: "
312  << x << ", " << y << ", " << z
313  << endl;
314  AliErrorStream() << "DetElemId not identified." << endl;
315  }
316 
317  Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
318  idvol = iChamber -1;
319 
320  // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
321  if ( (fMC->IsTrackEntering() || fMC->IsTrackExiting() ) ) {
322  AliTrackReference* trackReference
324  trackReference->SetUserId(detElemId);
325  }
326 
327  if( fMC->IsTrackEntering() ) {
328  Float_t theta = fTrackMomentum.Theta();
329  if ( fIsMaxStep && (TMath::Pi()-theta)*kRaddeg>=15. ) {
330  fMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
331  }
332  iEnter = 1;
333  fMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
334  }
335 
336  // AliDebug(1,
337  // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
338  // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
339  // Particule id and mass,
340  Int_t ipart = fMC->TrackPid();
341  Float_t mass = fMC->TrackMass();
342 
343  fDestepSum[idvol]+=fMC->Edep();
344  // Get current particle id (ipart), track position (pos) and momentum (mom)
345  if ( fStepSum[idvol]==0.0 ) fMC->TrackMomentum(fTrackMomentum);
346  fStepSum[idvol]+=fMC->TrackStep();
347 
348  // if (AliDebugLevel()) {
349  // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
350  // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
351  // mass, fStepSum[idvol], fMC->Edep()));
352  // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
353  // fTrackMomentum.Z()));
354  // fMC->TrackPosition(fTrackPosition);
355  // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
356  // fTrackPosition.Y(),fTrackPosition.Z())) ;
357  //}
358 
359  // Track left chamber or StepSum larger than fStepMaxInActiveGas
360  if ( fMC->IsTrackExiting() ||
361  fMC->IsTrackStop() ||
362  fMC->IsTrackDisappeared()||
363  (fStepSum[idvol]>fStepMaxInActiveGas) ) {
364 
365  if ( fIsMaxStep &&
366  ( fMC->IsTrackExiting() ||
367  fMC->IsTrackStop() ||
368  fMC->IsTrackDisappeared() ) ) fMC->SetMaxStep(kBig);
369  if (fDestepSum[idvol] == 0) {
370  // AZ - no energy release
371  fStepSum[idvol] = 0; // Reset for the next event
372  iEnter = 0;
373  return;
374  }
375 
376  fMC->TrackPosition(fTrackPosition);
377  Float_t theta = fTrackMomentum.Theta();
378  Float_t phi = fTrackMomentum.Phi();
379 
380  Int_t merge = 0;
381  Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
382  if (fMC->IsTrackExiting() && iEnter != 0) {
383  // AZ - this code is to avoid artificial hit splitting at the
384  // "fake" boundary inside the same chamber. It will still produce
385  // 2 hits but with the same coordinates (at the wire) to allow
386  // their merging at the digitization level.
387 
388  // Only for a track going from the entrance to the exit from the volume
389  // Get local coordinates
390  fMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
391 
392  fTrackPosition.Vect().GetXYZ(tmp);
393  fMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
394  Float_t dx = xyz0[0] - xyz1[0];
395  Float_t dy = xyz0[1] - xyz1[1];
396  Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
397  if (thLoc * TMath::RadToDeg() < 15) merge = 1;
398  }
399 
400  if (merge) {
401  Double_t dz = -0.5;
402  if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
403  tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
404  tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
405  tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
406  fMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
407  fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
408  } else {
409  TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
410  fStepSum[idvol]/2.*sin(theta)*sin(phi),
411  fStepSum[idvol]/2.*cos(theta),0.0 );
412  fTrackPosition-=backToWire;
413  //printf(" %d %d %d %f %d \n", fMC->IsTrackExiting(), fMC->IsTrackStop(), fMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
414  // AliDebug(1,
415  // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
416  // AliDebug(1,
417  // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
418  }
419 
420  //-------------- Angle effect
421  // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
422 
423  Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
424  Float_t sigmaEffect10degrees;
425  Float_t sigmaEffectThetadegrees;
426  Float_t eLossParticleELossMip;
427  Float_t yAngleEffect=0.;
428  Float_t thetawires = TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) ;// We use Pi-theta because z is negative
429  Double_t bField[3] = {0};
430  fTrackPosition.Vect().GetXYZ(tmp);
431  TGeoGlobalMagField::Instance()->Field(tmp,bField);
432 
433  if (fAngleEffect && !fMagEffect){
434  thetawires = TMath::Abs(thetawires);
435  if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
436  betaxGamma=TMath::Log(betaxGamma);
437  eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
438  // 10 degrees is a reference for a model (arbitrary)
439  sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
440  // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
441  sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
442  if ( (iChamber==1) || (iChamber==2) )
443  sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
444  yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
445  }
446  }
447  else if (fAngleEffect && fMagEffect) {
448  if ( (betaxGamma >3.2) && (TMath::Abs(thetawires*kRaddeg)<=15.) ) {
449  betaxGamma=TMath::Log(betaxGamma);
450  eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
451  // 10 degrees is a reference for a model (arbitrary)
452  sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
453  // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
454  sigmaEffectThetadegrees = sigmaEffect10degrees/fMagAngleEffectNorma->Eval(thetawires*kRaddeg,bField[0]/10.); // For 5mm gap
455  if ( (iChamber==1) || (iChamber==2) )
456  sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
457  yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
458  }
459  }
460 
461  AliMUONHit hit(fIshunt,
463  detElemId, ipart,
464  fTrackPosition.X(),
465  fTrackPosition.Y()+yAngleEffect,
466  fTrackPosition.Z(),
467  fMC->TrackTime(),
468  fTrackMomentum.P(),
469  theta,
470  phi,
471  fStepSum[idvol],
472  fDestepSum[idvol],
473  fTrackPosition.X(),
474  fTrackPosition.Y(),
475  fTrackPosition.Z());
476 
477  fHitStore->Add(hit);
478 
479  fStepSum[idvol] =0; // Reset for the next event
480  fDestepSum[idvol]=0; // Reset for the next event
481  iEnter = 0;
482  }
483 }
virtual void SetUserId(Int_t userId)
const AliMUONGeometry * GetGeometry() const
Definition: AliMUON.cxx:230
AliMUONVHitStore * fHitStore
! container of hits
Definition: AliMUON.h:192
#define AliErrorStream()
Definition: AliLog.h:630
TString CurrentVolumePath() const
Definition: AliMUONv1.cxx:236
Bool_t fAngleEffect
Angle Effect along wires, Default is true.
Definition: AliMUONv1.h:62
virtual void UpdateInternalGeometry()
Definition: AliMUONv1.cxx:178
Float_t * fDestepSum
! Sum of energy deposits per chamber
Definition: AliMUONv1.h:68
AliMUONGeometryDetElement * FindBySensitiveVolume(const TString &volumePath) const
const char * path
virtual void CreateMaterials()
Definition: AliMUONv1.cxx:170
TVirtualMC * fMC
Definition: AliModule.h:155
virtual void Init()
Definition: AliMUONv1.cxx:200
virtual void AddAlignableVolumes() const
Definition: AliMUONv1.cxx:191
Float_t * fStepSum
! Sum of track steps per chamber
Definition: AliMUONv1.h:67
TF1 * fElossRatio
Ratio of particle mean eloss with respect MIP&#39;s.
Definition: AliMUONv1.h:72
TF1 * fAngleEffectNorma
Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 20...
Definition: AliMUONv1.h:74
void InitGeometry()
Initialize geometry.
AliDetector class for MUON subsystem providing simulation data management.
Definition: AliMUON.h:37
TF2 * fMagAngleEffectNorma
Magnetic field effect: Normalisation from theta=16 degres to theta between -20 and 20 (Lamia Benhabib...
Definition: AliMUONv1.h:75
TLorentzVector fTrackPosition
Position of the particle exiting the active gas of chamber.
Definition: AliMUONv1.h:71
Bool_t fIsTailEffect
Switch to turn on/off the tail effect.
Definition: AliMUON.h:185
Factory for muon response.
static Int_t GetChamberId(Int_t detElemId, Bool_t warn=true)
AliDetector class for MUON subsystem which implements functions for simulation.
Definition: AliMUONv1.h:24
Float_t fStepMaxInActiveGas
Step max in active gas default 0.6cm.
Definition: AliMUONv1.h:64
static Int_t NGeomModules()
Return number of geometry modules.
const AliMUONGeometryTransformer * GetGeometryTransformer() const
Definition: AliMUON.cxx:243
virtual Bool_t Add(TObject *object)
Add an object, if of type AliMUONHit.
AliRun * gAlice
Definition: AliRun.cxx:62
Int_t GetCurrentTrackNumber() const
Definition: AliMC.cxx:1846
virtual ~AliMUONv1()
Definition: AliMUONv1.cxx:148
AliMUONGeometryBuilder * fGeometryBuilder
Geometry builder.
Definition: AliMUON.h:160
#define AliFatal(message)
Definition: AliLog.h:640
static Int_t NCh()
Return number of chambers.
virtual Int_t GetGeomModuleId(Int_t volId) const
Definition: AliMUONv1.cxx:221
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
Bool_t fMagEffect
Magnetic Field Effect along wires, Default is true.
Definition: AliMUONv1.h:63
TLorentzVector fTrackMomentum
Momentum of the particle entering in the active gas of chamber.
Definition: AliMUONv1.h:70
MonteCarlo hit.
Definition: AliMUONHit.h:24
virtual AliTrackReference * AddTrackReference(Int_t label, Int_t id=-999)
Definition: AliModule.cxx:378
const AliMUONGeometryModule * GetModule(Int_t index, Bool_t warn=true) const
Geometry parameters for detector module.
TF1 * fAngleEffect10
Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE...
Definition: AliMUONv1.h:73
Int_t fIshunt
Definition: AliDetector.h:73
virtual void StepManager()
Definition: AliMUONv1.cxx:260
Class for storing detection element transformations.
#define kRaddeg
Definition: AliConst.h:12
Bool_t IsSensitiveVolume(Int_t volId) const
static Bool_t LoadMpSegmentation(Bool_t warn=false)
Definition: AliMpCDB.cxx:113
AliMC * GetMCApp() const
Definition: AliRun.h:53
virtual void CreateGeometry()
Definition: AliMUONv1.cxx:162
Bool_t fIsMaxStep
Flag to inactivate calls to TVirtualMC::GetMC()->SetMaxStep.
Definition: AliMUON.h:178