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 /////////////////////////////////////////////////////////
24 #include <TClonesArray.h>
26 #include <TVirtualMC.h>
27 #include <TGeoMatrix.h>
29 #include "AliMUONv1.h"
31 #include "AliMUONConstants.h"
32 #include "AliMUONSegFactory.h"
33 #include "AliMUONResponseFactory.h"
34 #include "AliMUONSegmentation.h"
35 #include "AliMUONHit.h"
36 #include "AliMUONTriggerCircuit.h"
37 #include "AliMUONGeometryBuilder.h"
38 #include "AliMUONGeometry.h"
39 #include "AliMUONGeometryTransformer.h"
40 #include "AliMUONGeometryModule.h"
41 #include "AliMUONGeometrySVMap.h"
42 #include "AliMUONGeometryDetElement.h"
52 //___________________________________________
53 AliMUONv1::AliMUONv1()
55 fStepManagerVersionOld(kTRUE),
56 fStepManagerVersionDE(kTRUE),
58 fStepMaxInActiveGas(0.6),
65 fAngleEffectNorma(0x0)
67 // Default constructor
68 AliDebug(1,Form("default (empty) ctor this=%p",this));
71 //___________________________________________
72 AliMUONv1::AliMUONv1(const char *name, const char *title,
73 const char* sDigitizerClassName,
74 const char* digitizerClassName)
75 : AliMUON(name,title,sDigitizerClassName,digitizerClassName),
76 fStepManagerVersionOld(kTRUE),
77 fStepManagerVersionDE(kTRUE),
79 fStepMaxInActiveGas(0.6),
86 fAngleEffectNorma(0x0)
88 // Standard onstructor
90 AliDebug(1,Form("ctor this=%p",this));
92 // By default include all stations
94 fStepSum = new Float_t [AliMUONConstants::NCh()];
95 fDestepSum = new Float_t [AliMUONConstants::NCh()];
96 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
100 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
101 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
102 fElossRatio->SetParameter(0,1.02138);
103 fElossRatio->SetParameter(1,-9.54149e-02);
104 fElossRatio->SetParameter(2,+7.83433e-02);
105 fElossRatio->SetParameter(3,-9.98208e-03);
106 fElossRatio->SetParameter(4,+3.83279e-04);
108 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
109 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
110 fAngleEffect10->SetParameter(0, 1.90691e+02);
111 fAngleEffect10->SetParameter(1,-6.62258e+01);
112 fAngleEffect10->SetParameter(2,+1.28247e+01);
113 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
114 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
115 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
116 fAngleEffectNorma->SetParameter(0,4.148);
117 fAngleEffectNorma->SetParameter(1,-6.809e-01);
118 fAngleEffectNorma->SetParameter(2,5.151e-02);
119 fAngleEffectNorma->SetParameter(3,-1.490e-03);
122 //_____________________________________________________________________________
123 AliMUONv1::AliMUONv1(const AliMUONv1& right)
126 // copy constructor (not implemented)
128 AliFatal("Copy constructor not provided.");
131 //___________________________________________
132 AliMUONv1::~AliMUONv1()
135 AliDebug(1,Form("dtor this=%p",this));
137 delete [] fDestepSum;
139 delete fAngleEffect10;
140 delete fAngleEffectNorma;
143 //_____________________________________________________________________________
144 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
146 // assignement operator (not implemented)
148 // check assignement to self
149 if (this == &right) return *this;
151 AliFatal("Assignement operator not provided.");
156 //__________________________________________________
157 void AliMUONv1::CreateGeometry()
160 // Construct geometry using geometry builder
163 fGeometryBuilder->CreateGeometry();
166 //________________________________________________________________
167 void AliMUONv1::CreateMaterials()
170 // Construct materials using geometry builder
173 fGeometryBuilder->CreateMaterials();
176 //___________________________________________
177 void AliMUONv1::Init()
179 AliDebug(1,"Start Init for version 1 - CPC chamber type");
182 // Initialize geometry
184 fGeometryBuilder->InitGeometry();
185 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
188 std::string ftype(GetTitle());
190 // Build segmentation
191 // using geometry parametrisation
193 AliMUONSegFactory segFactory(GetGeometryTransformer());
194 fSegmentation = segFactory.CreateSegmentation(ftype);
196 if (!fSegmentation) {
197 AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
202 AliMUONResponseFactory respFactory("default");
203 respFactory.Build(this);
206 // Initialize segmentation
208 fSegmentation->Init();
210 // Initialize trigger circuits
212 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
213 AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
220 //__________________________________________________________________
221 Int_t AliMUONv1::GetChamberId(Int_t volId) const
223 // Check if the volume with specified volId is a sensitive volume (gas)
224 // of some chamber and returns the chamber number;
225 // if not sensitive volume - return 0.
228 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
229 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
236 //_______________________________________________________________________________
237 TString AliMUONv1::CurrentVolumePath() const
239 // Returns current volume path
240 // (Could be removed when this function is available via gMC)
248 name = gMC->CurrentVolOffName(imother);
249 gMC->CurrentVolOffID(imother++, copyNo);
256 while ( name != TString("ALIC") );
261 //_______________________________________________________________________________
262 void AliMUONv1::StepManager()
264 // Stepmanager for the chambers
267 if (fStepManagerVersionDE) {
273 // Only charged tracks
274 if( !(gMC->TrackCharge()) ) return;
275 // Only charged tracks
277 // Only gas gap inside chamber
278 // Tag chambers and record hits when track enters
279 static Int_t idvol=-1;
283 const Float_t kBig = 1.e10;
287 // Only gas gap inside chamber
288 // Tag chambers and record hits when track enters
289 id=gMC->CurrentVolID(copy);
290 iChamber = GetChamberId(id);
293 if (idvol == -1) return;
295 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
296 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
297 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
299 if( gMC->IsTrackEntering() ) {
300 Float_t theta = fTrackMomentum.Theta();
301 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
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()) {
318 // Form("iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
319 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
320 // mass, fStepSum[idvol], gMC->Edep()));
322 // Form("Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
323 // fTrackMomentum.Z()));
324 // gMC->TrackPosition(fTrackPosition);
326 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),
327 // fTrackPosition.Z())) ;
330 // Track left chamber or StepSum larger than fStepMaxInActiveGas
331 if ( gMC->IsTrackExiting() ||
332 gMC->IsTrackStop() ||
333 gMC->IsTrackDisappeared()||
334 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
336 if ( gMC->IsTrackExiting() ||
337 gMC->IsTrackStop() ||
338 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
340 gMC->TrackPosition(fTrackPosition);
341 Float_t theta = fTrackMomentum.Theta();
342 Float_t phi = fTrackMomentum.Phi();
344 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
345 fStepSum[idvol]/2.*sin(theta)*sin(phi),
346 fStepSum[idvol]/2.*cos(theta),0.0 );
347 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),
348 // fTrackPosition.Y(),fTrackPosition.Z())) ;
349 // AliDebug(1,Form("Exit: Track backToWire %f %f %f",backToWire.X(),
350 // backToWire.Y(),backToWire.Z()) ;
351 fTrackPosition-=backToWire;
353 //-------------- Angle effect
354 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
356 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
357 Float_t sigmaEffect10degrees;
358 Float_t sigmaEffectThetadegrees;
359 Float_t eLossParticleELossMip;
360 Float_t yAngleEffect=0.;
361 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
365 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
366 betaxGamma=TMath::Log(betaxGamma);
367 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
368 // 10 degrees is a reference for a model (arbitrary)
369 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
370 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
371 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
372 if ( (iChamber==1) || (iChamber==2) )
373 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
374 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
378 // Detection elements ids
379 const AliMUONGeometryModule* kGeometryModule
380 = GetGeometry()->GetModule(iChamber-1);
382 AliMUONGeometryDetElement* detElement
383 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
386 if (detElement) detElemId = detElement->GetUniqueID();
389 cerr << "Chamber id: "
390 << setw(3) << iChamber << " "
392 << CurrentVolumePath()
394 << setw(5) << detElemId
397 gMC->TrackPosition(x, y, z);
398 cerr << " global position: "
399 << x << ", " << y << ", " << z
401 AliWarning("DetElemId not identified.");
404 // One hit per chamber
405 GetMUONData()->AddHit(fIshunt,
406 gAlice->GetMCApp()->GetCurrentTrackNumber(),
409 fTrackPosition.Y()+yAngleEffect,
421 // if (AliDebugLevel()){
422 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
423 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
424 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z())) ;
426 fStepSum[idvol] =0; // Reset for the next event
427 fDestepSum[idvol]=0; // Reset for the next event
431 //_______________________________________________________________________________
432 void AliMUONv1::StepManager2()
434 // Stepmanager for the chambers
436 // Only charged tracks
437 if( !(gMC->TrackCharge()) ) return;
438 // Only charged tracks
440 // Only gas gap inside chamber
441 // Tag chambers and record hits when track enters
442 static Int_t idvol=-1, iEnter = 0;
446 const Float_t kBig = 1.e10;
447 static Double_t xyzEnter[3];
450 // Only gas gap inside chamber
451 // Tag chambers and record hits when track enters
452 id=gMC->CurrentVolID(copy);
453 iChamber = GetChamberId(id);
456 if (idvol == -1) return;
458 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
459 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
460 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
462 if( gMC->IsTrackEntering() ) {
463 Float_t theta = fTrackMomentum.Theta();
464 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
466 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
470 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
471 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
472 // Particule id and mass,
473 Int_t ipart = gMC->TrackPid();
474 Float_t mass = gMC->TrackMass();
476 fDestepSum[idvol]+=gMC->Edep();
477 // Get current particle id (ipart), track position (pos) and momentum (mom)
478 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
479 fStepSum[idvol]+=gMC->TrackStep();
481 // if (AliDebugLevel()) {
482 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
483 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
484 // mass, fStepSum[idvol], gMC->Edep()));
485 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
486 // fTrackMomentum.Z()));
487 // gMC->TrackPosition(fTrackPosition);
488 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
489 // fTrackPosition.Y(),fTrackPosition.Z())) ;
492 // Track left chamber or StepSum larger than fStepMaxInActiveGas
493 if ( gMC->IsTrackExiting() ||
494 gMC->IsTrackStop() ||
495 gMC->IsTrackDisappeared()||
496 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
498 if ( gMC->IsTrackExiting() ||
499 gMC->IsTrackStop() ||
500 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
501 if (fDestepSum[idvol] == 0) {
502 // AZ - no energy release
503 fStepSum[idvol] = 0; // Reset for the next event
508 gMC->TrackPosition(fTrackPosition);
509 Float_t theta = fTrackMomentum.Theta();
510 Float_t phi = fTrackMomentum.Phi();
512 if (gMC->IsTrackExiting() && iEnter != 0) {
513 // AZ - this code is to avoid artificial hit splitting at the
514 // "fake" boundary inside the same chamber. It will still produce
515 // 2 hits but with the same coordinates (at the wire) to allow
516 // their merging at the digitization level.
518 // Only for a track going from the entrance to the exit from the volume
519 // Get local coordinates
520 Double_t xyz0[3], xyz1[3], tmp[3];
521 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
523 fTrackPosition.Vect().GetXYZ(tmp);
524 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
527 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
528 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
529 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
530 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
531 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
532 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
534 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
535 fStepSum[idvol]/2.*sin(theta)*sin(phi),
536 fStepSum[idvol]/2.*cos(theta),0.0 );
537 fTrackPosition-=backToWire;
538 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
540 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
542 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
545 //-------------- Angle effect
546 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
548 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
549 Float_t sigmaEffect10degrees;
550 Float_t sigmaEffectThetadegrees;
551 Float_t eLossParticleELossMip;
552 Float_t yAngleEffect=0.;
553 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
557 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
558 betaxGamma=TMath::Log(betaxGamma);
559 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
560 // 10 degrees is a reference for a model (arbitrary)
561 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
562 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
563 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
564 if ( (iChamber==1) || (iChamber==2) )
565 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
566 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
570 // Detection elements ids
571 const AliMUONGeometryModule* kGeometryModule
572 = GetGeometry()->GetModule(iChamber-1);
574 AliMUONGeometryDetElement* detElement
575 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
578 if (detElement) detElemId = detElement->GetUniqueID();
581 cerr << "Chamber id: "
582 << setw(3) << iChamber << " "
584 << CurrentVolumePath()
586 << setw(5) << detElemId
589 gMC->TrackPosition(x, y, z);
590 cerr << " global position: "
591 << x << ", " << y << ", " << z
593 AliError("DetElemId not identified.");
596 // One hit per chamber
597 GetMUONData()->AddHit2(fIshunt,
598 gAlice->GetMCApp()->GetCurrentTrackNumber(),
601 fTrackPosition.Y()+yAngleEffect,
613 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
614 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
615 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
617 fStepSum[idvol] =0; // Reset for the next event
618 fDestepSum[idvol]=0; // Reset for the next event