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 "AliMUONChamber.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONFactory.h"
34 #include "AliMUONHit.h"
35 #include "AliMUONTriggerCircuit.h"
36 #include "AliMUONGeometryBuilder.h"
37 #include "AliMUONGeometryModule.h"
38 #include "AliMUONGeometrySVMap.h"
39 #include "AliMUONGeometryDetElement.h"
47 //___________________________________________
48 AliMUONv1::AliMUONv1()
50 fStepManagerVersionOld(kFALSE),
52 fStepMaxInActiveGas(0.6),
59 fAngleEffectNorma(0x0)
61 // Default constructor
64 //___________________________________________
65 AliMUONv1::AliMUONv1(const char *name, const char *title)
66 : AliMUON(name,title),
67 fStepManagerVersionOld(kFALSE),
69 fStepMaxInActiveGas(0.6),
76 fAngleEffectNorma(0x0)
78 // Standard onstructor
80 // By default include all stations
81 AliMUONFactory factory;
82 factory.Build(this, title);
84 fStepSum = new Float_t [AliMUONConstants::NCh()];
85 fDestepSum = new Float_t [AliMUONConstants::NCh()];
86 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
90 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
91 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
92 fElossRatio->SetParameter(0,1.02138);
93 fElossRatio->SetParameter(1,-9.54149e-02);
94 fElossRatio->SetParameter(2,+7.83433e-02);
95 fElossRatio->SetParameter(3,-9.98208e-03);
96 fElossRatio->SetParameter(4,+3.83279e-04);
98 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
99 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
100 fAngleEffect10->SetParameter(0, 1.90691e+02);
101 fAngleEffect10->SetParameter(1,-6.62258e+01);
102 fAngleEffect10->SetParameter(2,+1.28247e+01);
103 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
104 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
105 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
106 fAngleEffectNorma->SetParameter(0,4.148);
107 fAngleEffectNorma->SetParameter(1,-6.809e-01);
108 fAngleEffectNorma->SetParameter(2,5.151e-02);
109 fAngleEffectNorma->SetParameter(3,-1.490e-03);
112 //_____________________________________________________________________________
113 AliMUONv1::AliMUONv1(const AliMUONv1& right)
116 // copy constructor (not implemented)
118 AliFatal("Copy constructor not provided.");
121 //___________________________________________
122 AliMUONv1::~AliMUONv1()
127 delete [] fDestepSum;
129 delete fAngleEffect10;
130 delete fAngleEffectNorma;
133 //_____________________________________________________________________________
134 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
136 // assignement operator (not implemented)
138 // check assignement to self
139 if (this == &right) return *this;
141 AliFatal("Assignement operator not provided.");
146 //__________________________________________________
147 void AliMUONv1::CreateGeometry()
150 // Construct geometry using geometry builder
153 fGeometryBuilder->CreateGeometry();
156 //________________________________________________________________
157 void AliMUONv1::CreateMaterials()
160 // Construct materials using geometry builder
163 fGeometryBuilder->CreateMaterials();
166 //___________________________________________
167 void AliMUONv1::Init()
170 // Initialize Tracking Chambers
172 AliDebug(1,"Start Init for version 1 - CPC chamber type");
174 for (i=0; i<AliMUONConstants::NCh(); i++) {
175 ( (AliMUONChamber*) (*fChambers)[i])->Init();
179 // Initialize geometry
181 fGeometryBuilder->InitGeometry();
182 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
185 AliDebug(1,"Start Init for Trigger Circuits");
186 for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
187 ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
189 AliDebug(1,"Finished Init for Trigger Circuits");
195 // Print transformations and SV map
196 for (i=0; i<AliMUONConstants::NCh(); i++) {
198 AliDebug(2,Form("Chamber: %d \n" , i+1 ));
199 AliDebug(2,"===================\n");
201 // To do - move PrintLocalTransforms to geometryModule
202 //Chamber(i).GetGeometry()
203 // ->GetDetElementStore()->PrintLocalTransforms();
205 if (GetDebug() >1) Chamber(i).GetGeometry()->GetSVMap()->Print("");
210 //__________________________________________________________________
211 Int_t AliMUONv1::GetChamberId(Int_t volId) const
213 // Check if the volume with specified volId is a sensitive volume (gas)
214 // of some chamber and returns the chamber number;
215 // if not sensitive volume - return 0.
219 for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
220 if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
222 for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
223 if ( ((AliMUONChamber*)(*fChambers)[i-1])->IsSensId(volId) ) return i;
228 //_______________________________________________________________________________
229 TString AliMUONv1::CurrentVolumePath() const
231 // Returns current volume path
232 // (Could be removed when this function is available via gMC)
240 name = gMC->CurrentVolOffName(imother);
241 gMC->CurrentVolOffID(imother++, copyNo);
248 while ( name != TString("ALIC") );
253 //_______________________________________________________________________________
254 void AliMUONv1::StepManager()
256 // Stepmanager for the chambers
258 if (fStepManagerVersionOld) {
263 // Only charged tracks
264 if( !(gMC->TrackCharge()) && !(gMC->TrackPid()==0) ) return;
265 // Only charged tracks
267 // Only gas gap inside chamber
268 // Tag chambers and record hits when track enters
269 static Int_t idvol=-1;
273 const Float_t kBig = 1.e10;
277 // Only gas gap inside chamber
278 // Tag chambers and record hits when track enters
279 id=gMC->CurrentVolID(copy);
280 iChamber = GetChamberId(id);
283 if (idvol == -1) return;
285 if (GetDebug() > 1) {
286 // Fill the global position of detection elements
287 // Only for verification
288 AliMUONGeometrySVMap* svMap
289 = Chamber(iChamber-1).GetGeometry()->GetSVMap();
291 gMC->TrackPosition(x, y, z);
292 svMap->AddPosition(CurrentVolumePath(), TGeoTranslation(x, y, z));
295 if (gMC->TrackPid()==0) return;
297 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
298 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )
299 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
301 if( gMC->IsTrackEntering() ) {
302 Float_t theta = fTrackMomentum.Theta();
303 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
307 // Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
308 // Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
310 // Particule id and mass,
311 Int_t ipart = gMC->TrackPid();
312 Float_t mass = gMC->TrackMass();
314 fDestepSum[idvol]+=gMC->Edep();
315 // Get current particle id (ipart), track position (pos) and momentum (mom)
316 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
317 fStepSum[idvol]+=gMC->TrackStep();
320 // Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
321 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, mass, fStepSum[idvol], gMC->Edep());// Info("StepManager Step","Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), fTrackMomentum.Z()) ;
322 // gMC->TrackPosition(fTrackPosition);
323 // Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
326 // Track left chamber or StepSum larger than fStepMaxInActiveGas
327 if ( gMC->IsTrackExiting() ||
328 gMC->IsTrackStop() ||
329 gMC->IsTrackDisappeared()||
330 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
332 if ( gMC->IsTrackExiting() ||
333 gMC->IsTrackStop() ||
334 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
336 gMC->TrackPosition(fTrackPosition);
337 Float_t theta = fTrackMomentum.Theta();
338 Float_t phi = fTrackMomentum.Phi();
340 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
341 fStepSum[idvol]/2.*sin(theta)*sin(phi),
342 fStepSum[idvol]/2.*cos(theta),0.0 );
344 // Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
346 // Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
347 fTrackPosition-=backToWire;
349 //-------------- Angle effect
350 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
352 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
353 Float_t sigmaEffect10degrees;
354 Float_t sigmaEffectThetadegrees;
355 Float_t eLossParticleELossMip;
356 Float_t yAngleEffect=0.;
357 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
361 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
362 betaxGamma=TMath::Log(betaxGamma);
363 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
364 // 10 degrees is a reference for a model (arbitrary)
365 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
366 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
367 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
368 if ( (iChamber==1) || (iChamber==2) )
369 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
370 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
374 // Detection elements ids
375 AliMUONGeometryModule* geometry
376 = Chamber(iChamber-1).GetGeometry();
378 AliMUONGeometryDetElement* detElement
379 = geometry->FindBySensitiveVolume(CurrentVolumePath());
382 if (detElement) detElemId = detElement->GetUniqueID();
385 cerr << "Chamber id: "
386 << setw(3) << iChamber << " "
388 << CurrentVolumePath()
390 << setw(5) << detElemId
393 gMC->TrackPosition(x, y, z);
394 cerr << " global position: "
395 << x << ", " << y << ", " << z
397 AliWarning("DetElemId not identified.");
400 // One hit per chamber
401 GetMUONData()->AddHit(fIshunt,
402 gAlice->GetMCApp()->GetCurrentTrackNumber(),
405 fTrackPosition.Y()+yAngleEffect,
418 // Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
419 // Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
420 // Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
422 fStepSum[idvol] =0; // Reset for the next event
423 fDestepSum[idvol]=0; // Reset for the next event
427 //__________________________________________
428 void AliMUONv1::StepManagerOld()
430 // Old Stepmanager for the chambers
432 static Int_t idvol =-1;
438 Float_t destep, step;
440 static Float_t sstep;
441 static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
442 const Float_t kBig = 1.e10;
443 static Float_t hits[15];
445 TClonesArray &lhits = *fHits;
449 // Only charged tracks
450 if( !(gMC->TrackCharge()) ) return;
452 // Only gas gap inside chamber
453 // Tag chambers and record hits when track enters
454 id=gMC->CurrentVolID(copy);
455 vol[0] = GetChamberId(id);
458 if (idvol == -1) return;
461 // Get current particle id (ipart), track position (pos) and momentum (mom)
462 gMC->TrackPosition(pos);
463 gMC->TrackMomentum(mom);
465 ipart = gMC->TrackPid();
468 // momentum loss and steplength in last step
469 destep = gMC->Edep();
470 step = gMC->TrackStep();
471 // cout<<"------------"<<step<<endl;
473 // record hits when track enters ...
474 if( gMC->IsTrackEntering()) {
476 gMC->SetMaxStep(fMaxStepGas);
477 Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
478 Double_t rt = TMath::Sqrt(tc);
479 Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
480 Double_t tx = mom[0]/pmom;
481 Double_t ty = mom[1]/pmom;
482 Double_t tz = mom[2]/pmom;
483 Double_t s = ((AliMUONChamber*)(*fChambers)[idvol])
486 theta = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
487 phi = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
488 hits[0] = Float_t(ipart); // Geant3 particle type
489 hits[1] = pos[0]+s*tx; // X-position for hit
490 hits[2] = pos[1]+s*ty; // Y-position for hit
491 hits[3] = pos[2]+s*tz; // Z-position for hit
492 hits[4] = theta; // theta angle of incidence
493 hits[5] = phi; // phi angle of incidence
494 hits[8] = 0;//PadHits does not exist anymore (Float_t) fNPadHits; // first padhit
495 hits[9] = -1; // last pad hit
496 hits[10] = mom[3]; // hit momentum P
497 hits[11] = mom[0]; // Px
498 hits[12] = mom[1]; // Py
499 hits[13] = mom[2]; // Pz
500 tof=gMC->TrackTime();
501 hits[14] = tof; // Time of flight
509 Chamber(idvol).ChargeCorrelationInit();
510 // Only if not trigger chamber
512 // printf("---------------------------\n");
513 // printf(">>>> Y = %f \n",hits[2]);
514 // printf("---------------------------\n");
518 // if(idvol < AliMUONConstants::NTrackingCh()) {
520 // // Initialize hit position (cursor) in the segmentation model
521 // ((AliMUONChamber*) (*fChambers)[idvol])
522 // ->SigGenInit(pos[0], pos[1], pos[2]);
524 // //geant3->Gpcxyz();
525 // //printf("In the Trigger Chamber #%d\n",idvol-9);
531 // cout<<sstep<<endl;
534 // Calculate the charge induced on a pad (disintegration) in case
536 // Mip left chamber ...
537 if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
538 gMC->SetMaxStep(kBig);
544 Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
545 gMC->Gmtod(globalPos,localPos,1);
547 if(idvol < AliMUONConstants::NTrackingCh()) {
549 x0 = 0.5*(xhit+pos[0]);
550 y0 = 0.5*(yhit+pos[1]);
551 z0 = 0.5*(zhit+pos[2]);
560 // if (eloss >0) MakePadHits(x0,y0,z0,eloss,tof,idvol);
563 hits[6] = tlength; // track length
564 hits[7] = eloss2; // de/dx energy loss
567 // if (fNPadHits > (Int_t)hits[8]) {
568 // hits[8] = hits[8]+1;
569 // hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
575 AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
578 // Check additional signal generation conditions
579 // defined by the segmentation
580 // model (boundary crossing conditions)
581 // only for tracking chambers
583 ((idvol < AliMUONConstants::NTrackingCh()) &&
584 ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
586 ((AliMUONChamber*) (*fChambers)[idvol])
587 ->SigGenInit(pos[0], pos[1], pos[2]);
590 Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
591 gMC->Gmtod(globalPos,localPos,1);
595 // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
596 // MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
603 // nothing special happened, add up energy loss
610 //______________________________________________________________________________
611 void AliMUONv1::FinishRun()
616 if (GetDebug() <= 1) return;
618 // Print the global positions of detection elements
619 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
621 AliDebug(2,Form("Chamber: %d\n" , i+1 ));
622 AliDebug(2,"===================\n");
624 AliMUONGeometrySVMap* svMap
625 = Chamber(i).GetGeometry()->GetSVMap();
627 svMap->SortPositions();
628 svMap->PrintPositions();
629 svMap->ClearPositions();