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"
37 #include "AliMpDEManager.h"
43 #include "AliTrackReference.h"
46 #include <TClonesArray.h>
49 #include <TGeoGlobalMagField.h>
50 #include <TGeoMatrix.h>
53 #include <TVirtualMC.h>
57 #include "AliMUONVHitStore.h"
63 //___________________________________________
64 AliMUONv1::AliMUONv1()
68 fStepMaxInActiveGas(0.6),
75 fAngleEffectNorma(0x0),
76 fMagAngleEffectNorma(0x0)
78 /// Default constructor
80 AliDebug(1,Form("default (empty) ctor this=%p",this));
83 //___________________________________________
84 AliMUONv1::AliMUONv1(const char *name, const char* title)
85 : AliMUON(name, title),
88 fStepMaxInActiveGas(0.6),
95 fAngleEffectNorma(0x0),
96 fMagAngleEffectNorma(0x0)
98 /// Standard onstructor
100 AliDebug(1,Form("ctor this=%p",this));
103 if ( ! AliMpCDB::LoadMpSegmentation() ) {
104 AliFatal("Could not access mapping from OCDB !");
107 // By default include all stations
109 fStepSum = new Float_t [AliMUONConstants::NCh()];
110 fDestepSum = new Float_t [AliMUONConstants::NCh()];
111 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
115 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
116 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
117 fElossRatio->SetParameter(0,1.02138);
118 fElossRatio->SetParameter(1,-9.54149e-02);
119 fElossRatio->SetParameter(2,+7.83433e-02);
120 fElossRatio->SetParameter(3,-9.98208e-03);
121 fElossRatio->SetParameter(4,+3.83279e-04);
123 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
124 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
125 fAngleEffect10->SetParameter(0, 1.90691e+02);
126 fAngleEffect10->SetParameter(1,-6.62258e+01);
127 fAngleEffect10->SetParameter(2,+1.28247e+01);
128 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
129 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
130 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
131 fAngleEffectNorma->SetParameter(0,4.148);
132 fAngleEffectNorma->SetParameter(1,-6.809e-01);
133 fAngleEffectNorma->SetParameter(2,5.151e-02);
134 fAngleEffectNorma->SetParameter(3,-1.490e-03);
136 // Magnetic field effect: Normalisation form theta=16 degres (eq. 10 degrees B=0) to theta between -20 and 20 (Lamia Benhabib jun 2006 )
137 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
138 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.);
139 fMagAngleEffectNorma->SetParameters(8.6995, 25.4022, 13.8822, 2.4717, 1.1551, -0.0624, 0.0012);
142 //___________________________________________
143 AliMUONv1::~AliMUONv1()
147 AliDebug(1,Form("dtor this=%p",this));
149 delete [] fDestepSum;
151 delete fAngleEffect10;
152 delete fAngleEffectNorma;
153 delete fMagAngleEffectNorma;
156 //__________________________________________________
157 void AliMUONv1::CreateGeometry()
159 /// Construct geometry using geometry builder
161 fGeometryBuilder->CreateGeometry();
164 //________________________________________________________________
165 void AliMUONv1::CreateMaterials()
167 /// Construct materials using geometry builder
169 fGeometryBuilder->CreateMaterials();
172 //________________________________________________________________
173 void AliMUONv1::UpdateInternalGeometry()
175 /// Update geometry after applying mis-alignment
178 if ( ! AliMpCDB::LoadMpSegmentation() ) {
179 AliFatal("Could not access mapping from OCDB !");
182 fGeometryBuilder->UpdateInternalGeometry();
185 //________________________________________________________________
186 void AliMUONv1::AddAlignableVolumes() const
188 /// Construct materials using geometry builder
190 GetGeometryTransformer()->AddAlignableVolumes();
194 //___________________________________________
195 void AliMUONv1::Init()
197 /// Initialize geometry
199 AliDebug(1,"Start Init for version 1 - CPC chamber type");
201 fGeometryBuilder->InitGeometry();
202 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
205 // Build segmentation
206 // using geometry parametrisation
210 AliMUONResponseFactory respFactory("default", fIsTailEffect);
211 respFactory.Build(this);
215 //__________________________________________________________________
216 Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
218 /// Check if the volume with specified volId is a sensitive volume (gas)
219 /// of some chamber and return the chamber number;
220 /// if not sensitive volume - return 0.
222 for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
223 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
230 //_______________________________________________________________________________
231 TString AliMUONv1::CurrentVolumePath() const
233 /// Return current volume path
234 /// (Could be removed when this function is available via gMC)
241 name = gMC->CurrentVolOffName(imother);
242 gMC->CurrentVolOffID(imother++, copyNo);
249 while ( name != TString("ALIC") );
254 //_______________________________________________________________________________
255 void AliMUONv1::StepManager()
257 /// Step manager for the chambers
259 // Only charged tracks
260 if( !(gMC->TrackCharge()) ) return;
261 // Only charged tracks
263 // Only gas gap inside chamber
264 // Tag chambers and record hits when track enters
265 static Int_t idvol=-1, iEnter = 0;
267 const Float_t kBig = 1.e10;
268 static Double_t xyzEnter[3];
271 // Only gas gap inside chamber
272 // Tag chambers and record hits when track enters
273 Int_t id=gMC->CurrentVolID(copy);
274 Int_t iGeomModule = GetGeomModuleId(id);
275 if (iGeomModule == -1) return;
277 // Detection elements id
278 const AliMUONGeometryModule* kGeometryModule
279 = GetGeometry()->GetModule(iGeomModule);
280 AliMUONGeometryDetElement* detElement
281 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
283 if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
285 const AliMUONGeometryModule* kGeometryModule2
286 = GetGeometry()->GetModule(iGeomModule);
288 = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
292 if (detElement) detElemId = detElement->GetUniqueID();
296 << "Geometry module id: "
297 << setw(3) << iGeomModule << " "
299 << CurrentVolumePath()
301 << setw(5) << detElemId
304 gMC->TrackPosition(x, y, z);
306 << " global position: "
307 << x << ", " << y << ", " << z
309 AliErrorStream() << "DetElemId not identified." << endl;
312 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
315 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
316 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
317 AliTrackReference* trackReference
318 = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kMUON);
319 trackReference->SetUserId(detElemId);
322 if( gMC->IsTrackEntering() ) {
323 Float_t theta = fTrackMomentum.Theta();
324 if ( fIsMaxStep && (TMath::Pi()-theta)*kRaddeg>=15. ) {
325 gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
328 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
332 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
333 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
334 // Particule id and mass,
335 Int_t ipart = gMC->TrackPid();
336 Float_t mass = gMC->TrackMass();
338 fDestepSum[idvol]+=gMC->Edep();
339 // Get current particle id (ipart), track position (pos) and momentum (mom)
340 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
341 fStepSum[idvol]+=gMC->TrackStep();
343 // if (AliDebugLevel()) {
344 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
345 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
346 // mass, fStepSum[idvol], gMC->Edep()));
347 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
348 // fTrackMomentum.Z()));
349 // gMC->TrackPosition(fTrackPosition);
350 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
351 // fTrackPosition.Y(),fTrackPosition.Z())) ;
354 // Track left chamber or StepSum larger than fStepMaxInActiveGas
355 if ( gMC->IsTrackExiting() ||
356 gMC->IsTrackStop() ||
357 gMC->IsTrackDisappeared()||
358 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
361 ( gMC->IsTrackExiting() ||
362 gMC->IsTrackStop() ||
363 gMC->IsTrackDisappeared() ) ) gMC->SetMaxStep(kBig);
364 if (fDestepSum[idvol] == 0) {
365 // AZ - no energy release
366 fStepSum[idvol] = 0; // Reset for the next event
371 gMC->TrackPosition(fTrackPosition);
372 Float_t theta = fTrackMomentum.Theta();
373 Float_t phi = fTrackMomentum.Phi();
376 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
377 if (gMC->IsTrackExiting() && iEnter != 0) {
378 // AZ - this code is to avoid artificial hit splitting at the
379 // "fake" boundary inside the same chamber. It will still produce
380 // 2 hits but with the same coordinates (at the wire) to allow
381 // their merging at the digitization level.
383 // Only for a track going from the entrance to the exit from the volume
384 // Get local coordinates
385 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
387 fTrackPosition.Vect().GetXYZ(tmp);
388 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
389 Float_t dx = xyz0[0] - xyz1[0];
390 Float_t dy = xyz0[1] - xyz1[1];
391 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
392 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
397 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
398 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
399 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
400 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
401 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
402 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
404 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
405 fStepSum[idvol]/2.*sin(theta)*sin(phi),
406 fStepSum[idvol]/2.*cos(theta),0.0 );
407 fTrackPosition-=backToWire;
408 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
410 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
412 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
415 //-------------- Angle effect
416 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
418 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
419 Float_t sigmaEffect10degrees;
420 Float_t sigmaEffectThetadegrees;
421 Float_t eLossParticleELossMip;
422 Float_t yAngleEffect=0.;
423 Float_t thetawires = TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) ;// We use Pi-theta because z is negative
424 Double_t bField[3] = {0};
425 fTrackPosition.Vect().GetXYZ(tmp);
426 TGeoGlobalMagField::Instance()->Field(tmp,bField);
428 if (fAngleEffect && !fMagEffect){
429 thetawires = TMath::Abs(thetawires);
430 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
431 betaxGamma=TMath::Log(betaxGamma);
432 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
433 // 10 degrees is a reference for a model (arbitrary)
434 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
435 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
436 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
437 if ( (iChamber==1) || (iChamber==2) )
438 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
439 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
442 else if (fAngleEffect && fMagEffect) {
443 if ( (betaxGamma >3.2) && (TMath::Abs(thetawires*kRaddeg)<=15.) ) {
444 betaxGamma=TMath::Log(betaxGamma);
445 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
446 // 10 degrees is a reference for a model (arbitrary)
447 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
448 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
449 sigmaEffectThetadegrees = sigmaEffect10degrees/fMagAngleEffectNorma->Eval(thetawires*kRaddeg,bField[0]/10.); // For 5mm gap
450 if ( (iChamber==1) || (iChamber==2) )
451 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
452 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
456 AliMUONHit hit(fIshunt,
457 gAlice->GetMCApp()->GetCurrentTrackNumber(),
460 fTrackPosition.Y()+yAngleEffect,
474 fStepSum[idvol] =0; // Reset for the next event
475 fDestepSum[idvol]=0; // Reset for the next event