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"
48 #include <TClonesArray.h>
50 #include <TVirtualMC.h>
51 #include <TGeoMatrix.h>
57 //___________________________________________
58 AliMUONv1::AliMUONv1()
60 fStepManagerVersionOld(kTRUE),
61 fStepManagerVersionDE(kTRUE),
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 const char* sDigitizerClassName,
80 const char* digitizerClassName)
81 : AliMUON(name,title,sDigitizerClassName,digitizerClassName),
82 fStepManagerVersionOld(kTRUE),
83 fStepManagerVersionDE(kTRUE),
85 fStepMaxInActiveGas(0.6),
92 fAngleEffectNorma(0x0)
94 /// Standard onstructor
96 AliDebug(1,Form("ctor this=%p",this));
98 // By default include all stations
100 fStepSum = new Float_t [AliMUONConstants::NCh()];
101 fDestepSum = new Float_t [AliMUONConstants::NCh()];
102 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
106 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
107 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
108 fElossRatio->SetParameter(0,1.02138);
109 fElossRatio->SetParameter(1,-9.54149e-02);
110 fElossRatio->SetParameter(2,+7.83433e-02);
111 fElossRatio->SetParameter(3,-9.98208e-03);
112 fElossRatio->SetParameter(4,+3.83279e-04);
114 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
115 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
116 fAngleEffect10->SetParameter(0, 1.90691e+02);
117 fAngleEffect10->SetParameter(1,-6.62258e+01);
118 fAngleEffect10->SetParameter(2,+1.28247e+01);
119 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
120 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
121 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
122 fAngleEffectNorma->SetParameter(0,4.148);
123 fAngleEffectNorma->SetParameter(1,-6.809e-01);
124 fAngleEffectNorma->SetParameter(2,5.151e-02);
125 fAngleEffectNorma->SetParameter(3,-1.490e-03);
128 //_____________________________________________________________________________
129 AliMUONv1::AliMUONv1(const AliMUONv1& right)
132 /// Copy constructor (not implemented)
134 AliFatal("Copy constructor not provided.");
137 //___________________________________________
138 AliMUONv1::~AliMUONv1()
142 AliDebug(1,Form("dtor this=%p",this));
144 delete [] fDestepSum;
146 delete fAngleEffect10;
147 delete fAngleEffectNorma;
150 //_____________________________________________________________________________
151 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
153 /// Assignement operator (not implemented)
155 // check assignement to self
156 if (this == &right) return *this;
158 AliFatal("Assignement operator not provided.");
163 //__________________________________________________
164 void AliMUONv1::CreateGeometry()
166 /// Construct geometry using geometry builder
168 fGeometryBuilder->CreateGeometry();
171 //________________________________________________________________
172 void AliMUONv1::CreateMaterials()
174 /// Construct materials using geometry builder
176 fGeometryBuilder->CreateMaterials();
179 //___________________________________________
180 void AliMUONv1::Init()
182 /// Initialize geometry
184 AliDebug(1,"Start Init for version 1 - CPC chamber type");
186 fGeometryBuilder->InitGeometry();
187 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
190 std::string ftype(GetTitle());
192 // Build segmentation
193 // using geometry parametrisation
195 AliMUONSegFactory segFactory(GetGeometryTransformer());
196 fSegmentation = segFactory.CreateSegmentation(ftype);
198 if (!fSegmentation) {
199 AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
204 AliMUONResponseFactory respFactory("default");
205 respFactory.Build(this);
208 // Initialize segmentation
210 fSegmentation->Init();
212 // Initialize trigger circuits
214 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
215 AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
219 AliMUONTriggerCrateStore store;
220 store.ReadFromFile();
221 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++)
223 AliMUONTriggerCircuitNew* c = (AliMUONTriggerCircuitNew*)(fTriggerCircuitsNew->At(i));
229 //__________________________________________________________________
230 Int_t AliMUONv1::GetChamberId(Int_t volId) const
232 /// Check if the volume with specified volId is a sensitive volume (gas)
233 /// of some chamber and returns the chamber number;
234 /// if not sensitive volume - return 0.
236 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
237 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
244 //_______________________________________________________________________________
245 TString AliMUONv1::CurrentVolumePath() const
247 /// Return current volume path
248 /// (Could be removed when this function is available via gMC)
255 name = gMC->CurrentVolOffName(imother);
256 gMC->CurrentVolOffID(imother++, copyNo);
263 while ( name != TString("ALIC") );
268 //_______________________________________________________________________________
269 void AliMUONv1::StepManager()
271 /// Step manager for the chambers
274 if (fStepManagerVersionDE) {
280 // Only charged tracks
281 if( !(gMC->TrackCharge()) ) return;
282 // Only charged tracks
284 // Only gas gap inside chamber
285 // Tag chambers and record hits when track enters
286 static Int_t idvol=-1;
290 const Float_t kBig = 1.e10;
294 // Only gas gap inside chamber
295 // Tag chambers and record hits when track enters
296 id=gMC->CurrentVolID(copy);
297 iChamber = GetChamberId(id);
300 if (idvol == -1) return;
302 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
303 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
304 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
306 if( gMC->IsTrackEntering() ) {
307 Float_t theta = fTrackMomentum.Theta();
308 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
312 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
313 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z()));
314 // Particule id and mass,
315 Int_t ipart = gMC->TrackPid();
316 Float_t mass = gMC->TrackMass();
318 fDestepSum[idvol]+=gMC->Edep();
319 // Get current particle id (ipart), track position (pos) and momentum (mom)
320 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
321 fStepSum[idvol]+=gMC->TrackStep();
323 // if(AliDebugLevel()) {
325 // Form("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()));
329 // Form("Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
330 // fTrackMomentum.Z()));
331 // gMC->TrackPosition(fTrackPosition);
333 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),
334 // fTrackPosition.Z())) ;
337 // Track left chamber or StepSum larger than fStepMaxInActiveGas
338 if ( gMC->IsTrackExiting() ||
339 gMC->IsTrackStop() ||
340 gMC->IsTrackDisappeared()||
341 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
343 if ( gMC->IsTrackExiting() ||
344 gMC->IsTrackStop() ||
345 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
347 gMC->TrackPosition(fTrackPosition);
348 Float_t theta = fTrackMomentum.Theta();
349 Float_t phi = fTrackMomentum.Phi();
351 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
352 fStepSum[idvol]/2.*sin(theta)*sin(phi),
353 fStepSum[idvol]/2.*cos(theta),0.0 );
354 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),
355 // fTrackPosition.Y(),fTrackPosition.Z())) ;
356 // AliDebug(1,Form("Exit: Track backToWire %f %f %f",backToWire.X(),
357 // backToWire.Y(),backToWire.Z()) ;
358 fTrackPosition-=backToWire;
360 //-------------- Angle effect
361 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
363 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
364 Float_t sigmaEffect10degrees;
365 Float_t sigmaEffectThetadegrees;
366 Float_t eLossParticleELossMip;
367 Float_t yAngleEffect=0.;
368 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
372 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
373 betaxGamma=TMath::Log(betaxGamma);
374 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
375 // 10 degrees is a reference for a model (arbitrary)
376 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
377 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
378 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
379 if ( (iChamber==1) || (iChamber==2) )
380 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
381 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
385 // Detection elements ids
386 const AliMUONGeometryModule* kGeometryModule
387 = GetGeometry()->GetModule(iChamber-1);
389 AliMUONGeometryDetElement* detElement
390 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
393 if (detElement) detElemId = detElement->GetUniqueID();
396 cerr << "Chamber id: "
397 << setw(3) << iChamber << " "
399 << CurrentVolumePath()
401 << setw(5) << detElemId
404 gMC->TrackPosition(x, y, z);
405 cerr << " global position: "
406 << x << ", " << y << ", " << z
408 AliWarning("DetElemId not identified.");
411 // One hit per chamber
412 GetMUONData()->AddHit(fIshunt,
413 gAlice->GetMCApp()->GetCurrentTrackNumber(),
416 fTrackPosition.Y()+yAngleEffect,
428 // if (AliDebugLevel()){
429 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
430 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
431 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z())) ;
433 fStepSum[idvol] =0; // Reset for the next event
434 fDestepSum[idvol]=0; // Reset for the next event
438 //_______________________________________________________________________________
439 void AliMUONv1::StepManager2()
441 /// Step manager for the chambers
443 // Only charged tracks
444 if( !(gMC->TrackCharge()) ) return;
445 // Only charged tracks
447 // Only gas gap inside chamber
448 // Tag chambers and record hits when track enters
449 static Int_t idvol=-1, iEnter = 0;
453 const Float_t kBig = 1.e10;
454 static Double_t xyzEnter[3];
457 // Only gas gap inside chamber
458 // Tag chambers and record hits when track enters
459 id=gMC->CurrentVolID(copy);
460 iChamber = GetChamberId(id);
463 if (idvol == -1) return;
465 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
466 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
467 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
469 if( gMC->IsTrackEntering() ) {
470 Float_t theta = fTrackMomentum.Theta();
471 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
473 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
477 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
478 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
479 // Particule id and mass,
480 Int_t ipart = gMC->TrackPid();
481 Float_t mass = gMC->TrackMass();
483 fDestepSum[idvol]+=gMC->Edep();
484 // Get current particle id (ipart), track position (pos) and momentum (mom)
485 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
486 fStepSum[idvol]+=gMC->TrackStep();
488 // if (AliDebugLevel()) {
489 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
490 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
491 // mass, fStepSum[idvol], gMC->Edep()));
492 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
493 // fTrackMomentum.Z()));
494 // gMC->TrackPosition(fTrackPosition);
495 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
496 // fTrackPosition.Y(),fTrackPosition.Z())) ;
499 // Track left chamber or StepSum larger than fStepMaxInActiveGas
500 if ( gMC->IsTrackExiting() ||
501 gMC->IsTrackStop() ||
502 gMC->IsTrackDisappeared()||
503 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
505 if ( gMC->IsTrackExiting() ||
506 gMC->IsTrackStop() ||
507 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
508 if (fDestepSum[idvol] == 0) {
509 // AZ - no energy release
510 fStepSum[idvol] = 0; // Reset for the next event
515 gMC->TrackPosition(fTrackPosition);
516 Float_t theta = fTrackMomentum.Theta();
517 Float_t phi = fTrackMomentum.Phi();
520 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
521 if (gMC->IsTrackExiting() && iEnter != 0) {
522 // AZ - this code is to avoid artificial hit splitting at the
523 // "fake" boundary inside the same chamber. It will still produce
524 // 2 hits but with the same coordinates (at the wire) to allow
525 // their merging at the digitization level.
527 // Only for a track going from the entrance to the exit from the volume
528 // Get local coordinates
529 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
531 fTrackPosition.Vect().GetXYZ(tmp);
532 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
533 Float_t dx = xyz0[0] - xyz1[0];
534 Float_t dy = xyz0[1] - xyz1[1];
535 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
536 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
541 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
542 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
543 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
544 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
545 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
546 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
548 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
549 fStepSum[idvol]/2.*sin(theta)*sin(phi),
550 fStepSum[idvol]/2.*cos(theta),0.0 );
551 fTrackPosition-=backToWire;
552 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
554 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
556 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
559 //-------------- Angle effect
560 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
562 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
563 Float_t sigmaEffect10degrees;
564 Float_t sigmaEffectThetadegrees;
565 Float_t eLossParticleELossMip;
566 Float_t yAngleEffect=0.;
567 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
571 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
572 betaxGamma=TMath::Log(betaxGamma);
573 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
574 // 10 degrees is a reference for a model (arbitrary)
575 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
576 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
577 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
578 if ( (iChamber==1) || (iChamber==2) )
579 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
580 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
584 // Detection elements ids
585 const AliMUONGeometryModule* kGeometryModule
586 = GetGeometry()->GetModule(iChamber-1);
588 AliMUONGeometryDetElement* detElement
589 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
592 if (detElement) detElemId = detElement->GetUniqueID();
595 cerr << "Chamber id: "
596 << setw(3) << iChamber << " "
598 << CurrentVolumePath()
600 << setw(5) << detElemId
603 gMC->TrackPosition(x, y, z);
604 cerr << " global position: "
605 << x << ", " << y << ", " << z
607 AliError("DetElemId not identified.");
610 // One hit per chamber
611 GetMUONData()->AddHit2(fIshunt,
612 gAlice->GetMCApp()->GetCurrentTrackNumber(),
615 fTrackPosition.Y()+yAngleEffect,
627 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
628 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
629 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
631 fStepSum[idvol] =0; // Reset for the next event
632 fDestepSum[idvol]=0; // Reset for the next event