1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
20 // --------------------
21 // AliDetector class for MUON subsystem which implements
22 // functions for simulation
23 //-----------------------------------------------------------------------------
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"
36 #include "AliMpDEManager.h"
42 #include "AliTrackReference.h"
47 #include <TClonesArray.h>
49 #include <TVirtualMC.h>
50 #include <TGeoMatrix.h>
54 #include "AliMUONVHitStore.h"
60 //___________________________________________
61 AliMUONv1::AliMUONv1()
64 fStepMaxInActiveGas(0.6),
71 fAngleEffectNorma(0x0)
73 /// Default constructor
75 AliDebug(1,Form("default (empty) ctor this=%p",this));
78 //___________________________________________
79 AliMUONv1::AliMUONv1(const char *name, const char* title)
80 : AliMUON(name, title),
82 fStepMaxInActiveGas(0.6),
89 fAngleEffectNorma(0x0)
91 /// Standard onstructor
93 AliDebug(1,Form("ctor this=%p",this));
95 // By default include all stations
97 fStepSum = new Float_t [AliMUONConstants::NCh()];
98 fDestepSum = new Float_t [AliMUONConstants::NCh()];
99 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
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);
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);
125 //___________________________________________
126 AliMUONv1::~AliMUONv1()
130 AliDebug(1,Form("dtor this=%p",this));
132 delete [] fDestepSum;
134 delete fAngleEffect10;
135 delete fAngleEffectNorma;
138 //__________________________________________________
139 void AliMUONv1::CreateGeometry()
141 /// Construct geometry using geometry builder
143 fGeometryBuilder->CreateGeometry();
146 //________________________________________________________________
147 void AliMUONv1::CreateMaterials()
149 /// Construct materials using geometry builder
151 fGeometryBuilder->CreateMaterials();
154 //________________________________________________________________
155 void AliMUONv1::AddAlignableVolumes() const
157 /// Construct materials using geometry builder
159 GetGeometryTransformer()->AddAlignableVolumes();
163 //___________________________________________
164 void AliMUONv1::Init()
166 /// Initialize geometry
168 AliDebug(1,"Start Init for version 1 - CPC chamber type");
170 fGeometryBuilder->InitGeometry();
171 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
174 // Build segmentation
175 // using geometry parametrisation
179 AliMUONResponseFactory respFactory("default");
180 respFactory.Build(this);
184 //__________________________________________________________________
185 Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
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.
191 for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
192 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
199 //_______________________________________________________________________________
200 TString AliMUONv1::CurrentVolumePath() const
202 /// Return current volume path
203 /// (Could be removed when this function is available via gMC)
210 name = gMC->CurrentVolOffName(imother);
211 gMC->CurrentVolOffID(imother++, copyNo);
218 while ( name != TString("ALIC") );
223 //_______________________________________________________________________________
224 void AliMUONv1::StepManager()
226 /// Step manager for the chambers
228 // Only charged tracks
229 if( !(gMC->TrackCharge()) ) return;
230 // Only charged tracks
232 // Only gas gap inside chamber
233 // Tag chambers and record hits when track enters
234 static Int_t idvol=-1, iEnter = 0;
236 const Float_t kBig = 1.e10;
237 static Double_t xyzEnter[3];
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;
246 // Detection elements id
247 const AliMUONGeometryModule* kGeometryModule
248 = GetGeometry()->GetModule(iGeomModule);
249 AliMUONGeometryDetElement* detElement
250 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
252 if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
254 const AliMUONGeometryModule* kGeometryModule2
255 = GetGeometry()->GetModule(iGeomModule);
257 = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
261 if (detElement) detElemId = detElement->GetUniqueID();
265 << "Geometry module id: "
266 << setw(3) << iGeomModule << " "
268 << CurrentVolumePath()
270 << setw(5) << detElemId
273 gMC->TrackPosition(x, y, z);
275 << " global position: "
276 << x << ", " << y << ", " << z
278 AliErrorStream() << "DetElemId not identified." << endl;
281 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
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(), AliTrackReference::kMUON);
288 trackReference->SetUserId(detElemId);
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
295 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
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();
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();
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())) ;
321 // Track left chamber or StepSum larger than fStepMaxInActiveGas
322 if ( gMC->IsTrackExiting() ||
323 gMC->IsTrackStop() ||
324 gMC->IsTrackDisappeared()||
325 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
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
337 gMC->TrackPosition(fTrackPosition);
338 Float_t theta = fTrackMomentum.Theta();
339 Float_t phi = fTrackMomentum.Phi();
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.
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
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;
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());
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);
376 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
378 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
381 //-------------- Angle effect
382 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
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
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
406 AliMUONHit hit(fIshunt,
407 gAlice->GetMCApp()->GetCurrentTrackNumber(),
410 fTrackPosition.Y()+yAngleEffect,
424 fStepSum[idvol] =0; // Reset for the next event
425 fDestepSum[idvol]=0; // Reset for the next event