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
24 #include "AliMUONv1.h"
25 #include "AliMUONConstants.h"
26 #include "AliMUONSegFactory.h"
27 #include "AliMUONResponseFactory.h"
28 #include "AliMUONSegmentation.h"
29 #include "AliMUONHit.h"
30 #include "AliMUONGeometryBuilder.h"
31 #include "AliMUONGeometry.h"
32 #include "AliMUONGeometryTransformer.h"
33 #include "AliMUONGeometryModule.h"
34 #include "AliMUONStringIntMap.h"
35 #include "AliMUONGeometryDetElement.h"
37 #include "AliMpDEManager.h"
43 #include "AliTrackReference.h"
48 #include <TClonesArray.h>
50 #include <TVirtualMC.h>
51 #include <TGeoMatrix.h>
59 //___________________________________________
60 AliMUONv1::AliMUONv1()
63 fStepMaxInActiveGas(0.6),
70 fAngleEffectNorma(0x0)
72 /// Default constructor
74 AliDebug(1,Form("default (empty) ctor this=%p",this));
77 //___________________________________________
78 AliMUONv1::AliMUONv1(const char *name, const char* title)
79 : AliMUON(name, title),
81 fStepMaxInActiveGas(0.6),
88 fAngleEffectNorma(0x0)
90 /// Standard onstructor
92 AliDebug(1,Form("ctor this=%p",this));
94 // By default include all stations
96 fStepSum = new Float_t [AliMUONConstants::NCh()];
97 fDestepSum = new Float_t [AliMUONConstants::NCh()];
98 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
102 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
103 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
104 fElossRatio->SetParameter(0,1.02138);
105 fElossRatio->SetParameter(1,-9.54149e-02);
106 fElossRatio->SetParameter(2,+7.83433e-02);
107 fElossRatio->SetParameter(3,-9.98208e-03);
108 fElossRatio->SetParameter(4,+3.83279e-04);
110 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
111 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
112 fAngleEffect10->SetParameter(0, 1.90691e+02);
113 fAngleEffect10->SetParameter(1,-6.62258e+01);
114 fAngleEffect10->SetParameter(2,+1.28247e+01);
115 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
116 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
117 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
118 fAngleEffectNorma->SetParameter(0,4.148);
119 fAngleEffectNorma->SetParameter(1,-6.809e-01);
120 fAngleEffectNorma->SetParameter(2,5.151e-02);
121 fAngleEffectNorma->SetParameter(3,-1.490e-03);
124 //___________________________________________
125 AliMUONv1::~AliMUONv1()
129 AliDebug(1,Form("dtor this=%p",this));
131 delete [] fDestepSum;
133 delete fAngleEffect10;
134 delete fAngleEffectNorma;
137 //__________________________________________________
138 void AliMUONv1::CreateGeometry()
140 /// Construct geometry using geometry builder
142 fGeometryBuilder->CreateGeometry();
145 //________________________________________________________________
146 void AliMUONv1::CreateMaterials()
148 /// Construct materials using geometry builder
150 fGeometryBuilder->CreateMaterials();
153 //________________________________________________________________
154 void AliMUONv1::AddAlignableVolumes() const
156 /// Construct materials using geometry builder
158 GetGeometryTransformer()->AddAlignableVolumes();
162 //___________________________________________
163 void AliMUONv1::Init()
165 /// Initialize geometry
167 AliDebug(1,"Start Init for version 1 - CPC chamber type");
169 fGeometryBuilder->InitGeometry();
170 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
173 // Build segmentation
174 // using geometry parametrisation
176 AliMUONSegFactory segFactory(GetGeometryTransformer());
177 fSegmentation = segFactory.CreateSegmentation();
181 AliMUONResponseFactory respFactory("default");
182 respFactory.Build(this);
185 // Initialize segmentation
187 fSegmentation->Init();
191 //__________________________________________________________________
192 Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
194 /// Check if the volume with specified volId is a sensitive volume (gas)
195 /// of some chamber and return the chamber number;
196 /// if not sensitive volume - return 0.
198 for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
199 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
206 //_______________________________________________________________________________
207 TString AliMUONv1::CurrentVolumePath() const
209 /// Return current volume path
210 /// (Could be removed when this function is available via gMC)
217 name = gMC->CurrentVolOffName(imother);
218 gMC->CurrentVolOffID(imother++, copyNo);
225 while ( name != TString("ALIC") );
230 //_______________________________________________________________________________
231 void AliMUONv1::StepManager()
233 /// Step manager for the chambers
235 // Only charged tracks
236 if( !(gMC->TrackCharge()) ) return;
237 // Only charged tracks
239 // Only gas gap inside chamber
240 // Tag chambers and record hits when track enters
241 static Int_t idvol=-1, iEnter = 0;
243 const Float_t kBig = 1.e10;
244 static Double_t xyzEnter[3];
247 // Only gas gap inside chamber
248 // Tag chambers and record hits when track enters
249 Int_t id=gMC->CurrentVolID(copy);
250 Int_t iGeomModule = GetGeomModuleId(id);
251 if (iGeomModule == -1) return;
253 // Detection elements id
254 const AliMUONGeometryModule* kGeometryModule
255 = GetGeometry()->GetModule(iGeomModule);
256 AliMUONGeometryDetElement* detElement
257 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
259 if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
261 const AliMUONGeometryModule* kGeometryModule2
262 = GetGeometry()->GetModule(iGeomModule);
264 = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
268 if (detElement) detElemId = detElement->GetUniqueID();
272 << "Geometry module id: "
273 << setw(3) << iGeomModule << " "
275 << CurrentVolumePath()
277 << setw(5) << detElemId
280 gMC->TrackPosition(x, y, z);
282 << " global position: "
283 << x << ", " << y << ", " << z
285 AliErrorStream() << "DetElemId not identified." << endl;
288 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
291 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
292 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
293 AliTrackReference* trackReference
294 = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
295 trackReference->SetUserId(detElemId);
298 if( gMC->IsTrackEntering() ) {
299 Float_t theta = fTrackMomentum.Theta();
300 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
302 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
306 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
307 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
308 // Particule id and mass,
309 Int_t ipart = gMC->TrackPid();
310 Float_t mass = gMC->TrackMass();
312 fDestepSum[idvol]+=gMC->Edep();
313 // Get current particle id (ipart), track position (pos) and momentum (mom)
314 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
315 fStepSum[idvol]+=gMC->TrackStep();
317 // if (AliDebugLevel()) {
318 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
319 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
320 // mass, fStepSum[idvol], gMC->Edep()));
321 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
322 // fTrackMomentum.Z()));
323 // gMC->TrackPosition(fTrackPosition);
324 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
325 // fTrackPosition.Y(),fTrackPosition.Z())) ;
328 // Track left chamber or StepSum larger than fStepMaxInActiveGas
329 if ( gMC->IsTrackExiting() ||
330 gMC->IsTrackStop() ||
331 gMC->IsTrackDisappeared()||
332 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
334 if ( gMC->IsTrackExiting() ||
335 gMC->IsTrackStop() ||
336 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
337 if (fDestepSum[idvol] == 0) {
338 // AZ - no energy release
339 fStepSum[idvol] = 0; // Reset for the next event
344 gMC->TrackPosition(fTrackPosition);
345 Float_t theta = fTrackMomentum.Theta();
346 Float_t phi = fTrackMomentum.Phi();
349 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
350 if (gMC->IsTrackExiting() && iEnter != 0) {
351 // AZ - this code is to avoid artificial hit splitting at the
352 // "fake" boundary inside the same chamber. It will still produce
353 // 2 hits but with the same coordinates (at the wire) to allow
354 // their merging at the digitization level.
356 // Only for a track going from the entrance to the exit from the volume
357 // Get local coordinates
358 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
360 fTrackPosition.Vect().GetXYZ(tmp);
361 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
362 Float_t dx = xyz0[0] - xyz1[0];
363 Float_t dy = xyz0[1] - xyz1[1];
364 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
365 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
370 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
371 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
372 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
373 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
374 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
375 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
377 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
378 fStepSum[idvol]/2.*sin(theta)*sin(phi),
379 fStepSum[idvol]/2.*cos(theta),0.0 );
380 fTrackPosition-=backToWire;
381 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
383 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
385 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
388 //-------------- Angle effect
389 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
391 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
392 Float_t sigmaEffect10degrees;
393 Float_t sigmaEffectThetadegrees;
394 Float_t eLossParticleELossMip;
395 Float_t yAngleEffect=0.;
396 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
400 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
401 betaxGamma=TMath::Log(betaxGamma);
402 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
403 // 10 degrees is a reference for a model (arbitrary)
404 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
405 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
406 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
407 if ( (iChamber==1) || (iChamber==2) )
408 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
409 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
413 // One hit per chamber
414 GetMUONData()->AddHit(fIshunt,
415 gAlice->GetMCApp()->GetCurrentTrackNumber(),
418 fTrackPosition.Y()+yAngleEffect,
430 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
431 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
432 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
434 fStepSum[idvol] =0; // Reset for the next event
435 fDestepSum[idvol]=0; // Reset for the next event