1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * SigmaEffect_thetadegrees *
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 /////////////////////////////////////////////////////////
19 // Manager and hits classes for set:MUON version 1 //
20 /////////////////////////////////////////////////////////
22 #include "AliMUONv1.h"
23 #include "AliMUONConstants.h"
24 #include "AliMUONSegFactory.h"
25 #include "AliMUONResponseFactory.h"
26 #include "AliMUONSegmentation.h"
27 #include "AliMUONHit.h"
28 #include "AliMUONTriggerCircuit.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"
44 #include <TClonesArray.h>
46 #include <TVirtualMC.h>
47 #include <TGeoMatrix.h>
53 //___________________________________________
54 AliMUONv1::AliMUONv1()
56 fStepManagerVersionOld(kTRUE),
57 fStepManagerVersionDE(kTRUE),
59 fStepMaxInActiveGas(0.6),
66 fAngleEffectNorma(0x0)
68 // Default constructor
69 AliDebug(1,Form("default (empty) ctor this=%p",this));
72 //___________________________________________
73 AliMUONv1::AliMUONv1(const char *name, const char *title,
74 const char* sDigitizerClassName,
75 const char* digitizerClassName)
76 : AliMUON(name,title,sDigitizerClassName,digitizerClassName),
77 fStepManagerVersionOld(kTRUE),
78 fStepManagerVersionDE(kTRUE),
80 fStepMaxInActiveGas(0.6),
87 fAngleEffectNorma(0x0)
89 // Standard onstructor
91 AliDebug(1,Form("ctor this=%p",this));
93 // By default include all stations
95 fStepSum = new Float_t [AliMUONConstants::NCh()];
96 fDestepSum = new Float_t [AliMUONConstants::NCh()];
97 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
101 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
102 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
103 fElossRatio->SetParameter(0,1.02138);
104 fElossRatio->SetParameter(1,-9.54149e-02);
105 fElossRatio->SetParameter(2,+7.83433e-02);
106 fElossRatio->SetParameter(3,-9.98208e-03);
107 fElossRatio->SetParameter(4,+3.83279e-04);
109 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
110 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
111 fAngleEffect10->SetParameter(0, 1.90691e+02);
112 fAngleEffect10->SetParameter(1,-6.62258e+01);
113 fAngleEffect10->SetParameter(2,+1.28247e+01);
114 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
115 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
116 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
117 fAngleEffectNorma->SetParameter(0,4.148);
118 fAngleEffectNorma->SetParameter(1,-6.809e-01);
119 fAngleEffectNorma->SetParameter(2,5.151e-02);
120 fAngleEffectNorma->SetParameter(3,-1.490e-03);
123 //_____________________________________________________________________________
124 AliMUONv1::AliMUONv1(const AliMUONv1& right)
127 // copy constructor (not implemented)
129 AliFatal("Copy constructor not provided.");
132 //___________________________________________
133 AliMUONv1::~AliMUONv1()
136 AliDebug(1,Form("dtor this=%p",this));
138 delete [] fDestepSum;
140 delete fAngleEffect10;
141 delete fAngleEffectNorma;
144 //_____________________________________________________________________________
145 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
147 // assignement operator (not implemented)
149 // check assignement to self
150 if (this == &right) return *this;
152 AliFatal("Assignement operator not provided.");
157 //__________________________________________________
158 void AliMUONv1::CreateGeometry()
161 // Construct geometry using geometry builder
164 fGeometryBuilder->CreateGeometry();
167 //________________________________________________________________
168 void AliMUONv1::CreateMaterials()
171 // Construct materials using geometry builder
174 fGeometryBuilder->CreateMaterials();
177 //___________________________________________
178 void AliMUONv1::Init()
180 AliDebug(1,"Start Init for version 1 - CPC chamber type");
183 // Initialize geometry
185 fGeometryBuilder->InitGeometry();
186 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
189 std::string ftype(GetTitle());
191 // Build segmentation
192 // using geometry parametrisation
194 AliMUONSegFactory segFactory(GetGeometryTransformer());
195 fSegmentation = segFactory.CreateSegmentation(ftype);
197 if (!fSegmentation) {
198 AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
203 AliMUONResponseFactory respFactory("default");
204 respFactory.Build(this);
207 // Initialize segmentation
209 fSegmentation->Init();
211 // Initialize trigger circuits
213 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
214 AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
221 //__________________________________________________________________
222 Int_t AliMUONv1::GetChamberId(Int_t volId) const
224 // Check if the volume with specified volId is a sensitive volume (gas)
225 // of some chamber and returns the chamber number;
226 // if not sensitive volume - return 0.
229 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
230 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
237 //_______________________________________________________________________________
238 TString AliMUONv1::CurrentVolumePath() const
240 // Returns current volume path
241 // (Could be removed when this function is available via gMC)
249 name = gMC->CurrentVolOffName(imother);
250 gMC->CurrentVolOffID(imother++, copyNo);
257 while ( name != TString("ALIC") );
262 //_______________________________________________________________________________
263 void AliMUONv1::StepManager()
265 // Stepmanager for the chambers
268 if (fStepManagerVersionDE) {
274 // Only charged tracks
275 if( !(gMC->TrackCharge()) ) return;
276 // Only charged tracks
278 // Only gas gap inside chamber
279 // Tag chambers and record hits when track enters
280 static Int_t idvol=-1;
284 const Float_t kBig = 1.e10;
288 // Only gas gap inside chamber
289 // Tag chambers and record hits when track enters
290 id=gMC->CurrentVolID(copy);
291 iChamber = GetChamberId(id);
294 if (idvol == -1) return;
296 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
297 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
298 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
300 if( gMC->IsTrackEntering() ) {
301 Float_t theta = fTrackMomentum.Theta();
302 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
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()) {
319 // Form("iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
320 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
321 // mass, fStepSum[idvol], gMC->Edep()));
323 // Form("Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
324 // fTrackMomentum.Z()));
325 // gMC->TrackPosition(fTrackPosition);
327 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),
328 // fTrackPosition.Z())) ;
331 // Track left chamber or StepSum larger than fStepMaxInActiveGas
332 if ( gMC->IsTrackExiting() ||
333 gMC->IsTrackStop() ||
334 gMC->IsTrackDisappeared()||
335 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
337 if ( gMC->IsTrackExiting() ||
338 gMC->IsTrackStop() ||
339 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
341 gMC->TrackPosition(fTrackPosition);
342 Float_t theta = fTrackMomentum.Theta();
343 Float_t phi = fTrackMomentum.Phi();
345 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
346 fStepSum[idvol]/2.*sin(theta)*sin(phi),
347 fStepSum[idvol]/2.*cos(theta),0.0 );
348 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),
349 // fTrackPosition.Y(),fTrackPosition.Z())) ;
350 // AliDebug(1,Form("Exit: Track backToWire %f %f %f",backToWire.X(),
351 // backToWire.Y(),backToWire.Z()) ;
352 fTrackPosition-=backToWire;
354 //-------------- Angle effect
355 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
357 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
358 Float_t sigmaEffect10degrees;
359 Float_t sigmaEffectThetadegrees;
360 Float_t eLossParticleELossMip;
361 Float_t yAngleEffect=0.;
362 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
366 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
367 betaxGamma=TMath::Log(betaxGamma);
368 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
369 // 10 degrees is a reference for a model (arbitrary)
370 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
371 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
372 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
373 if ( (iChamber==1) || (iChamber==2) )
374 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
375 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
379 // Detection elements ids
380 const AliMUONGeometryModule* kGeometryModule
381 = GetGeometry()->GetModule(iChamber-1);
383 AliMUONGeometryDetElement* detElement
384 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
387 if (detElement) detElemId = detElement->GetUniqueID();
390 cerr << "Chamber id: "
391 << setw(3) << iChamber << " "
393 << CurrentVolumePath()
395 << setw(5) << detElemId
398 gMC->TrackPosition(x, y, z);
399 cerr << " global position: "
400 << x << ", " << y << ", " << z
402 AliWarning("DetElemId not identified.");
405 // One hit per chamber
406 GetMUONData()->AddHit(fIshunt,
407 gAlice->GetMCApp()->GetCurrentTrackNumber(),
410 fTrackPosition.Y()+yAngleEffect,
422 // if (AliDebugLevel()){
423 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
424 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
425 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z())) ;
427 fStepSum[idvol] =0; // Reset for the next event
428 fDestepSum[idvol]=0; // Reset for the next event
432 //_______________________________________________________________________________
433 void AliMUONv1::StepManager2()
435 // Stepmanager for the chambers
437 // Only charged tracks
438 if( !(gMC->TrackCharge()) ) return;
439 // Only charged tracks
441 // Only gas gap inside chamber
442 // Tag chambers and record hits when track enters
443 static Int_t idvol=-1, iEnter = 0;
447 const Float_t kBig = 1.e10;
448 static Double_t xyzEnter[3];
451 // Only gas gap inside chamber
452 // Tag chambers and record hits when track enters
453 id=gMC->CurrentVolID(copy);
454 iChamber = GetChamberId(id);
457 if (idvol == -1) return;
459 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
460 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
461 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
463 if( gMC->IsTrackEntering() ) {
464 Float_t theta = fTrackMomentum.Theta();
465 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
467 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
471 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
472 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
473 // Particule id and mass,
474 Int_t ipart = gMC->TrackPid();
475 Float_t mass = gMC->TrackMass();
477 fDestepSum[idvol]+=gMC->Edep();
478 // Get current particle id (ipart), track position (pos) and momentum (mom)
479 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
480 fStepSum[idvol]+=gMC->TrackStep();
482 // if (AliDebugLevel()) {
483 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
484 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
485 // mass, fStepSum[idvol], gMC->Edep()));
486 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
487 // fTrackMomentum.Z()));
488 // gMC->TrackPosition(fTrackPosition);
489 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
490 // fTrackPosition.Y(),fTrackPosition.Z())) ;
493 // Track left chamber or StepSum larger than fStepMaxInActiveGas
494 if ( gMC->IsTrackExiting() ||
495 gMC->IsTrackStop() ||
496 gMC->IsTrackDisappeared()||
497 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
499 if ( gMC->IsTrackExiting() ||
500 gMC->IsTrackStop() ||
501 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
502 if (fDestepSum[idvol] == 0) {
503 // AZ - no energy release
504 fStepSum[idvol] = 0; // Reset for the next event
509 gMC->TrackPosition(fTrackPosition);
510 Float_t theta = fTrackMomentum.Theta();
511 Float_t phi = fTrackMomentum.Phi();
514 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
515 if (gMC->IsTrackExiting() && iEnter != 0) {
516 // AZ - this code is to avoid artificial hit splitting at the
517 // "fake" boundary inside the same chamber. It will still produce
518 // 2 hits but with the same coordinates (at the wire) to allow
519 // their merging at the digitization level.
521 // Only for a track going from the entrance to the exit from the volume
522 // Get local coordinates
523 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
525 fTrackPosition.Vect().GetXYZ(tmp);
526 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
527 Float_t dx = xyz0[0] - xyz1[0];
528 Float_t dy = xyz0[1] - xyz1[1];
529 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
530 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
535 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
536 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
537 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
538 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
539 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
540 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
542 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
543 fStepSum[idvol]/2.*sin(theta)*sin(phi),
544 fStepSum[idvol]/2.*cos(theta),0.0 );
545 fTrackPosition-=backToWire;
546 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
548 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
550 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
553 //-------------- Angle effect
554 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
556 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
557 Float_t sigmaEffect10degrees;
558 Float_t sigmaEffectThetadegrees;
559 Float_t eLossParticleELossMip;
560 Float_t yAngleEffect=0.;
561 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
565 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
566 betaxGamma=TMath::Log(betaxGamma);
567 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
568 // 10 degrees is a reference for a model (arbitrary)
569 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
570 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
571 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
572 if ( (iChamber==1) || (iChamber==2) )
573 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
574 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
578 // Detection elements ids
579 const AliMUONGeometryModule* kGeometryModule
580 = GetGeometry()->GetModule(iChamber-1);
582 AliMUONGeometryDetElement* detElement
583 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
586 if (detElement) detElemId = detElement->GetUniqueID();
589 cerr << "Chamber id: "
590 << setw(3) << iChamber << " "
592 << CurrentVolumePath()
594 << setw(5) << detElemId
597 gMC->TrackPosition(x, y, z);
598 cerr << " global position: "
599 << x << ", " << y << ", " << z
601 AliError("DetElemId not identified.");
604 // One hit per chamber
605 GetMUONData()->AddHit2(fIshunt,
606 gAlice->GetMCApp()->GetCurrentTrackNumber(),
609 fTrackPosition.Y()+yAngleEffect,
621 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
622 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
623 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
625 fStepSum[idvol] =0; // Reset for the next event
626 fDestepSum[idvol]=0; // Reset for the next event