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 "AliMUONTriggerCircuit.h"
31 #include "AliMUONTriggerCircuitNew.h"
32 #include "AliMUONTriggerCrateStore.h"
33 #include "AliMUONGeometryBuilder.h"
34 #include "AliMUONGeometry.h"
35 #include "AliMUONGeometryTransformer.h"
36 #include "AliMUONGeometryModule.h"
37 #include "AliMUONStringIntMap.h"
38 #include "AliMUONGeometryDetElement.h"
44 #include "AliTrackReference.h"
49 #include <TClonesArray.h>
51 #include <TVirtualMC.h>
52 #include <TGeoMatrix.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 const char* sDigitizerClassName,
81 const char* digitizerClassName)
82 : AliMUON(name,title,sDigitizerClassName,digitizerClassName),
84 fStepMaxInActiveGas(0.6),
91 fAngleEffectNorma(0x0)
93 /// Standard onstructor
95 AliDebug(1,Form("ctor this=%p",this));
97 // By default include all stations
99 fStepSum = new Float_t [AliMUONConstants::NCh()];
100 fDestepSum = new Float_t [AliMUONConstants::NCh()];
101 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
105 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
106 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
107 fElossRatio->SetParameter(0,1.02138);
108 fElossRatio->SetParameter(1,-9.54149e-02);
109 fElossRatio->SetParameter(2,+7.83433e-02);
110 fElossRatio->SetParameter(3,-9.98208e-03);
111 fElossRatio->SetParameter(4,+3.83279e-04);
113 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
114 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
115 fAngleEffect10->SetParameter(0, 1.90691e+02);
116 fAngleEffect10->SetParameter(1,-6.62258e+01);
117 fAngleEffect10->SetParameter(2,+1.28247e+01);
118 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
119 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
120 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
121 fAngleEffectNorma->SetParameter(0,4.148);
122 fAngleEffectNorma->SetParameter(1,-6.809e-01);
123 fAngleEffectNorma->SetParameter(2,5.151e-02);
124 fAngleEffectNorma->SetParameter(3,-1.490e-03);
127 //___________________________________________
128 AliMUONv1::~AliMUONv1()
132 AliDebug(1,Form("dtor this=%p",this));
134 delete [] fDestepSum;
136 delete fAngleEffect10;
137 delete fAngleEffectNorma;
140 //__________________________________________________
141 void AliMUONv1::CreateGeometry()
143 /// Construct geometry using geometry builder
145 fGeometryBuilder->CreateGeometry();
148 //________________________________________________________________
149 void AliMUONv1::CreateMaterials()
151 /// Construct materials using geometry builder
153 fGeometryBuilder->CreateMaterials();
156 //___________________________________________
157 void AliMUONv1::Init()
159 /// Initialize geometry
161 AliDebug(1,"Start Init for version 1 - CPC chamber type");
163 fGeometryBuilder->InitGeometry();
164 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
167 std::string ftype(GetTitle());
169 // Build segmentation
170 // using geometry parametrisation
172 AliMUONSegFactory segFactory(GetGeometryTransformer());
173 fSegmentation = segFactory.CreateSegmentation(ftype);
175 if (!fSegmentation) {
176 AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
181 AliMUONResponseFactory respFactory("default");
182 respFactory.Build(this);
185 // Initialize segmentation
187 fSegmentation->Init();
189 // Initialize trigger circuits
191 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
192 AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
196 AliMUONTriggerCrateStore store;
197 store.ReadFromFile();
198 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++)
200 AliMUONTriggerCircuitNew* c = (AliMUONTriggerCircuitNew*)(fTriggerCircuitsNew->At(i));
206 //__________________________________________________________________
207 Int_t AliMUONv1::GetChamberId(Int_t volId) const
209 /// Check if the volume with specified volId is a sensitive volume (gas)
210 /// of some chamber and return the chamber number;
211 /// if not sensitive volume - return 0.
213 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
214 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
221 //_______________________________________________________________________________
222 TString AliMUONv1::CurrentVolumePath() const
224 /// Return current volume path
225 /// (Could be removed when this function is available via gMC)
232 name = gMC->CurrentVolOffName(imother);
233 gMC->CurrentVolOffID(imother++, copyNo);
240 while ( name != TString("ALIC") );
245 //_______________________________________________________________________________
246 void AliMUONv1::StepManager()
248 /// Step manager for the chambers
250 // Only charged tracks
251 if( !(gMC->TrackCharge()) ) return;
252 // Only charged tracks
254 // Only gas gap inside chamber
255 // Tag chambers and record hits when track enters
256 static Int_t idvol=-1, iEnter = 0;
260 const Float_t kBig = 1.e10;
261 static Double_t xyzEnter[3];
264 // Only gas gap inside chamber
265 // Tag chambers and record hits when track enters
266 id=gMC->CurrentVolID(copy);
267 iChamber = GetChamberId(id);
270 if (idvol == -1) return;
272 // Detection elements id
273 const AliMUONGeometryModule* kGeometryModule
274 = GetGeometry()->GetModule(iChamber-1);
276 AliMUONGeometryDetElement* detElement
277 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
280 if (detElement) detElemId = detElement->GetUniqueID();
283 cerr << "Chamber id: "
284 << setw(3) << iChamber << " "
286 << CurrentVolumePath()
288 << setw(5) << detElemId
291 gMC->TrackPosition(x, y, z);
292 cerr << " global position: "
293 << x << ", " << y << ", " << z
295 AliError("DetElemId not identified.");
298 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
299 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
300 AliTrackReference* trackReference
301 = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
302 trackReference->SetUserId(detElemId);
305 if( gMC->IsTrackEntering() ) {
306 Float_t theta = fTrackMomentum.Theta();
307 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
309 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
313 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
314 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
315 // Particule id and mass,
316 Int_t ipart = gMC->TrackPid();
317 Float_t mass = gMC->TrackMass();
319 fDestepSum[idvol]+=gMC->Edep();
320 // Get current particle id (ipart), track position (pos) and momentum (mom)
321 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
322 fStepSum[idvol]+=gMC->TrackStep();
324 // if (AliDebugLevel()) {
325 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
326 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
327 // mass, fStepSum[idvol], gMC->Edep()));
328 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
329 // fTrackMomentum.Z()));
330 // gMC->TrackPosition(fTrackPosition);
331 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
332 // fTrackPosition.Y(),fTrackPosition.Z())) ;
335 // Track left chamber or StepSum larger than fStepMaxInActiveGas
336 if ( gMC->IsTrackExiting() ||
337 gMC->IsTrackStop() ||
338 gMC->IsTrackDisappeared()||
339 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
341 if ( gMC->IsTrackExiting() ||
342 gMC->IsTrackStop() ||
343 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
344 if (fDestepSum[idvol] == 0) {
345 // AZ - no energy release
346 fStepSum[idvol] = 0; // Reset for the next event
351 gMC->TrackPosition(fTrackPosition);
352 Float_t theta = fTrackMomentum.Theta();
353 Float_t phi = fTrackMomentum.Phi();
356 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
357 if (gMC->IsTrackExiting() && iEnter != 0) {
358 // AZ - this code is to avoid artificial hit splitting at the
359 // "fake" boundary inside the same chamber. It will still produce
360 // 2 hits but with the same coordinates (at the wire) to allow
361 // their merging at the digitization level.
363 // Only for a track going from the entrance to the exit from the volume
364 // Get local coordinates
365 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
367 fTrackPosition.Vect().GetXYZ(tmp);
368 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
369 Float_t dx = xyz0[0] - xyz1[0];
370 Float_t dy = xyz0[1] - xyz1[1];
371 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
372 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
377 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
378 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
379 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
380 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
381 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
382 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
384 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
385 fStepSum[idvol]/2.*sin(theta)*sin(phi),
386 fStepSum[idvol]/2.*cos(theta),0.0 );
387 fTrackPosition-=backToWire;
388 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
390 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
392 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
395 //-------------- Angle effect
396 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
398 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
399 Float_t sigmaEffect10degrees;
400 Float_t sigmaEffectThetadegrees;
401 Float_t eLossParticleELossMip;
402 Float_t yAngleEffect=0.;
403 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
407 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
408 betaxGamma=TMath::Log(betaxGamma);
409 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
410 // 10 degrees is a reference for a model (arbitrary)
411 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
412 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
413 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
414 if ( (iChamber==1) || (iChamber==2) )
415 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
416 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
420 // One hit per chamber
421 GetMUONData()->AddHit2(fIshunt,
422 gAlice->GetMCApp()->GetCurrentTrackNumber(),
425 fTrackPosition.Y()+yAngleEffect,
437 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
438 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
439 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
441 fStepSum[idvol] =0; // Reset for the next event
442 fDestepSum[idvol]=0; // Reset for the next event