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"
48 #include <TClonesArray.h>
50 #include <TVirtualMC.h>
51 #include <TGeoMatrix.h>
55 #include "AliMUONVHitStore.h"
61 //___________________________________________
62 AliMUONv1::AliMUONv1()
65 fStepMaxInActiveGas(0.6),
72 fAngleEffectNorma(0x0)
74 /// Default constructor
76 AliDebug(1,Form("default (empty) ctor this=%p",this));
79 //___________________________________________
80 AliMUONv1::AliMUONv1(const char *name, const char* title)
81 : AliMUON(name, title),
83 fStepMaxInActiveGas(0.6),
90 fAngleEffectNorma(0x0)
92 /// Standard onstructor
94 AliDebug(1,Form("ctor this=%p",this));
97 if ( ! AliMpCDB::LoadMpSegmentation() ) {
98 AliFatal("Could not access mapping from OCDB !");
101 // By default include all stations
103 fStepSum = new Float_t [AliMUONConstants::NCh()];
104 fDestepSum = new Float_t [AliMUONConstants::NCh()];
105 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
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);
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);
131 //___________________________________________
132 AliMUONv1::~AliMUONv1()
136 AliDebug(1,Form("dtor this=%p",this));
138 delete [] fDestepSum;
140 delete fAngleEffect10;
141 delete fAngleEffectNorma;
144 //__________________________________________________
145 void AliMUONv1::CreateGeometry()
147 /// Construct geometry using geometry builder
149 fGeometryBuilder->CreateGeometry();
152 //________________________________________________________________
153 void AliMUONv1::CreateMaterials()
155 /// Construct materials using geometry builder
157 fGeometryBuilder->CreateMaterials();
160 //________________________________________________________________
161 void AliMUONv1::AddAlignableVolumes() const
163 /// Construct materials using geometry builder
165 GetGeometryTransformer()->AddAlignableVolumes();
169 //___________________________________________
170 void AliMUONv1::Init()
172 /// Initialize geometry
174 AliDebug(1,"Start Init for version 1 - CPC chamber type");
176 fGeometryBuilder->InitGeometry();
177 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
180 // Build segmentation
181 // using geometry parametrisation
185 AliMUONResponseFactory respFactory("default");
186 respFactory.Build(this);
190 //__________________________________________________________________
191 Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
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.
197 for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
198 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
205 //_______________________________________________________________________________
206 TString AliMUONv1::CurrentVolumePath() const
208 /// Return current volume path
209 /// (Could be removed when this function is available via gMC)
216 name = gMC->CurrentVolOffName(imother);
217 gMC->CurrentVolOffID(imother++, copyNo);
224 while ( name != TString("ALIC") );
229 //_______________________________________________________________________________
230 void AliMUONv1::StepManager()
232 /// Step manager for the chambers
234 // Only charged tracks
235 if( !(gMC->TrackCharge()) ) return;
236 // Only charged tracks
238 // Only gas gap inside chamber
239 // Tag chambers and record hits when track enters
240 static Int_t idvol=-1, iEnter = 0;
242 const Float_t kBig = 1.e10;
243 static Double_t xyzEnter[3];
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;
252 // Detection elements id
253 const AliMUONGeometryModule* kGeometryModule
254 = GetGeometry()->GetModule(iGeomModule);
255 AliMUONGeometryDetElement* detElement
256 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
258 if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
260 const AliMUONGeometryModule* kGeometryModule2
261 = GetGeometry()->GetModule(iGeomModule);
263 = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
267 if (detElement) detElemId = detElement->GetUniqueID();
271 << "Geometry module id: "
272 << setw(3) << iGeomModule << " "
274 << CurrentVolumePath()
276 << setw(5) << detElemId
279 gMC->TrackPosition(x, y, z);
281 << " global position: "
282 << x << ", " << y << ", " << z
284 AliErrorStream() << "DetElemId not identified." << endl;
287 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
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);
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
301 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
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();
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();
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())) ;
327 // Track left chamber or StepSum larger than fStepMaxInActiveGas
328 if ( gMC->IsTrackExiting() ||
329 gMC->IsTrackStop() ||
330 gMC->IsTrackDisappeared()||
331 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
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
343 gMC->TrackPosition(fTrackPosition);
344 Float_t theta = fTrackMomentum.Theta();
345 Float_t phi = fTrackMomentum.Phi();
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.
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
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;
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());
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);
382 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
384 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
387 //-------------- Angle effect
388 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
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
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
412 AliMUONHit hit(fIshunt,
413 gAlice->GetMCApp()->GetCurrentTrackNumber(),
416 fTrackPosition.Y()+yAngleEffect,
430 fStepSum[idvol] =0; // Reset for the next event
431 fDestepSum[idvol]=0; // Reset for the next event