- Old StepManager() replaced with StepManager2()
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
0c527060 3 * *
a9e2aefa 4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 *
2c799aa2 12 * about the suitability of this software for any purpeateose. It is *
a9e2aefa 13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
88cb7938 16/* $Id$ */
a9e2aefa 17
d19b6003 18// --------------------
19// Class AliMUONv1
20// --------------------
21// AliDetector class for MUON subsystem which implements
22// functions for simulation
acc838fd 23
30178c30 24#include "AliMUONv1.h"
88cb7938 25#include "AliMUONConstants.h"
40afd6cd 26#include "AliMUONSegFactory.h"
b7ef3c96 27#include "AliMUONResponseFactory.h"
28#include "AliMUONSegmentation.h"
a9e2aefa 29#include "AliMUONHit.h"
8c449e83 30#include "AliMUONTriggerCircuit.h"
0c527060 31#include "AliMUONTriggerCircuitNew.h"
32#include "AliMUONTriggerCrateStore.h"
d4bb94a1 33#include "AliMUONGeometryBuilder.h"
b7ef3c96 34#include "AliMUONGeometry.h"
35#include "AliMUONGeometryTransformer.h"
e118b27e 36#include "AliMUONGeometryModule.h"
7ecf374b 37#include "AliMUONStringIntMap.h"
e118b27e 38#include "AliMUONGeometryDetElement.h"
7ecf374b 39
40#include "AliConst.h"
88cb7938 41#include "AliMagF.h"
42#include "AliRun.h"
5d12ce38 43#include "AliMC.h"
8c343c7c 44#include "AliLog.h"
a9e2aefa 45
7ecf374b 46#include <TRandom.h>
47#include <TF1.h>
48#include <TClonesArray.h>
49#include <TRandom.h>
50#include <TVirtualMC.h>
51#include <TGeoMatrix.h>
52
edee5e63 53#include <string>
54
a9e2aefa 55ClassImp(AliMUONv1)
56
57//___________________________________________
30178c30 58AliMUONv1::AliMUONv1()
59 : AliMUON(),
e8e385f7 60 fStepManagerVersionOld(kTRUE),
61 fStepManagerVersionDE(kTRUE),
d4bb94a1 62 fAngleEffect(kTRUE),
63 fStepMaxInActiveGas(0.6),
64 fStepSum(0x0),
65 fDestepSum(0x0),
66 fTrackMomentum(),
67 fTrackPosition(),
68 fElossRatio(0x0),
69 fAngleEffect10(0x0),
b7ef3c96 70 fAngleEffectNorma(0x0)
a9e2aefa 71{
d19b6003 72/// Default constructor
73
74 AliDebug(1,Form("default (empty) ctor this=%p",this));
1391e633 75}
d4bb94a1 76
a9e2aefa 77//___________________________________________
b05d84a5 78AliMUONv1::AliMUONv1(const char *name, const char *title,
79 const char* sDigitizerClassName,
80 const char* digitizerClassName)
81: AliMUON(name,title,sDigitizerClassName,digitizerClassName),
e8e385f7 82 fStepManagerVersionOld(kTRUE),
83 fStepManagerVersionDE(kTRUE),
d4bb94a1 84 fAngleEffect(kTRUE),
85 fStepMaxInActiveGas(0.6),
86 fStepSum(0x0),
87 fDestepSum(0x0),
88 fTrackMomentum(),
89 fTrackPosition(),
90 fElossRatio(0x0),
91 fAngleEffect10(0x0),
b7ef3c96 92 fAngleEffectNorma(0x0)
a9e2aefa 93{
d19b6003 94/// Standard onstructor
d4bb94a1 95
d19b6003 96 AliDebug(1,Form("ctor this=%p",this));
edee5e63 97
ba030c0e 98 // By default include all stations
c33d9661 99
1391e633 100 fStepSum = new Float_t [AliMUONConstants::NCh()];
101 fDestepSum = new Float_t [AliMUONConstants::NCh()];
102 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
103 fStepSum[i] =0.0;
104 fDestepSum[i]=0.0;
105 }
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);
113
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);
a9e2aefa 126}
127
fb1bf5c0 128//_____________________________________________________________________________
129AliMUONv1::AliMUONv1(const AliMUONv1& right)
130 : AliMUON(right)
131{
d19b6003 132/// Copy constructor (not implemented)
fb1bf5c0 133
8c343c7c 134 AliFatal("Copy constructor not provided.");
fb1bf5c0 135}
136
a9e2aefa 137//___________________________________________
acc838fd 138AliMUONv1::~AliMUONv1()
a9e2aefa 139{
d19b6003 140/// Destructor
141
142 AliDebug(1,Form("dtor this=%p",this));
d4bb94a1 143 delete [] fStepSum;
144 delete [] fDestepSum;
145 delete fElossRatio;
146 delete fAngleEffect10;
8109731a 147 delete fAngleEffectNorma;
acc838fd 148}
b17c0c87 149
fb1bf5c0 150//_____________________________________________________________________________
151AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
152{
d19b6003 153/// Assignement operator (not implemented)
fb1bf5c0 154
155 // check assignement to self
156 if (this == &right) return *this;
157
8c343c7c 158 AliFatal("Assignement operator not provided.");
fb1bf5c0 159
160 return *this;
161}
162
acc838fd 163//__________________________________________________
164void AliMUONv1::CreateGeometry()
165{
d19b6003 166/// Construct geometry using geometry builder
a9e2aefa 167
d4bb94a1 168 fGeometryBuilder->CreateGeometry();
acc838fd 169}
a9e2aefa 170
acc838fd 171//________________________________________________________________
a9e2aefa 172void AliMUONv1::CreateMaterials()
173{
d19b6003 174/// Construct materials using geometry builder
acc838fd 175
d4bb94a1 176 fGeometryBuilder->CreateMaterials();
a9e2aefa 177}
178
acc838fd 179//___________________________________________
a9e2aefa 180void AliMUONv1::Init()
a713db22 181{
d19b6003 182/// Initialize geometry
183
edee5e63 184 AliDebug(1,"Start Init for version 1 - CPC chamber type");
002920d1 185
edee5e63 186 fGeometryBuilder->InitGeometry();
187 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
b7ef3c96 188
189
edee5e63 190 std::string ftype(GetTitle());
b7ef3c96 191
192 // Build segmentation
193 // using geometry parametrisation
194 //
40afd6cd 195 AliMUONSegFactory segFactory(GetGeometryTransformer());
196 fSegmentation = segFactory.CreateSegmentation(ftype);
197
198 if (!fSegmentation) {
199 AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
200 }
b7ef3c96 201
202 // Build response
edee5e63 203 //
b7ef3c96 204 AliMUONResponseFactory respFactory("default");
205 respFactory.Build(this);
206
207
edee5e63 208 // Initialize segmentation
209 //
b7ef3c96 210 fSegmentation->Init();
211
212 // Initialize trigger circuits
213 //
214 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
e1d9a0df 215 AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
216 c->Init(i);
0c527060 217 }
218
219 AliMUONTriggerCrateStore store;
220 store.ReadFromFile();
221 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++)
222 {
223 AliMUONTriggerCircuitNew* c = (AliMUONTriggerCircuitNew*)(fTriggerCircuitsNew->At(i));
224 c->Init(i,store);
e1d9a0df 225 }
edee5e63 226
a9e2aefa 227}
1391e633 228
d4bb94a1 229//__________________________________________________________________
230Int_t AliMUONv1::GetChamberId(Int_t volId) const
231{
d19b6003 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.
d4bb94a1 235
b7ef3c96 236 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
237 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
238 return i+1;
239 }
d4bb94a1 240
241 return 0;
242}
333f7cda 243
244//_______________________________________________________________________________
245TString AliMUONv1::CurrentVolumePath() const
246{
d19b6003 247/// Return current volume path
248/// (Could be removed when this function is available via gMC)
333f7cda 249
250 TString path = "";
251 TString name;
252 Int_t copyNo;
253 Int_t imother = 0;
254 do {
255 name = gMC->CurrentVolOffName(imother);
256 gMC->CurrentVolOffID(imother++, copyNo);
257 TString add = "/";
258 add += name;
7ecf374b 259 add += "_";
333f7cda 260 add += copyNo;
261 path.Insert(0,add);
262 }
263 while ( name != TString("ALIC") );
264
265 return path;
266}
267
1391e633 268//_______________________________________________________________________________
c33d9661 269void AliMUONv1::StepManager()
270{
d19b6003 271/// Step manager for the chambers
272/// TBR
d59b2ec3 273
274 if (fStepManagerVersionDE) {
275 StepManager2();
276 return;
277 }
d7c4fbc4 278
c33d9661 279
280 // Only charged tracks
d59b2ec3 281 if( !(gMC->TrackCharge()) ) return;
1391e633 282 // Only charged tracks
283
c33d9661 284 // Only gas gap inside chamber
285 // Tag chambers and record hits when track enters
acc838fd 286 static Int_t idvol=-1;
1391e633 287 Int_t iChamber=0;
288 Int_t id=0;
289 Int_t copy;
290 const Float_t kBig = 1.e10;
291
acc838fd 292
293 //
294 // Only gas gap inside chamber
295 // Tag chambers and record hits when track enters
c33d9661 296 id=gMC->CurrentVolID(copy);
acc838fd 297 iChamber = GetChamberId(id);
298 idvol = iChamber -1;
299
300 if (idvol == -1) return;
abaf7c9d 301
967a2a25 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());
305
1391e633 306 if( gMC->IsTrackEntering() ) {
307 Float_t theta = fTrackMomentum.Theta();
4ac9d21e 308 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
309 }
abaf7c9d 310
5a0e88a7 311 // AliDebug(1,
312 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
313 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z()));
314 // Particule id and mass,
1391e633 315 Int_t ipart = gMC->TrackPid();
316 Float_t mass = gMC->TrackMass();
317
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();
abaf7c9d 322
5a0e88a7 323 // if(AliDebugLevel()) {
324 // AliDebug(1,
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()));
328 // AliDebug(1,
329 // Form("Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
330 // fTrackMomentum.Z()));
331 // gMC->TrackPosition(fTrackPosition);
332 // AliDebug(1,
333 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),
334 // fTrackPosition.Z())) ;
335 // }
1391e633 336
337 // Track left chamber or StepSum larger than fStepMaxInActiveGas
338 if ( gMC->IsTrackExiting() ||
339 gMC->IsTrackStop() ||
340 gMC->IsTrackDisappeared()||
341 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
342
343 if ( gMC->IsTrackExiting() ||
acc838fd 344 gMC->IsTrackStop() ||
345 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
1391e633 346
347 gMC->TrackPosition(fTrackPosition);
348 Float_t theta = fTrackMomentum.Theta();
349 Float_t phi = fTrackMomentum.Phi();
350
d7c4fbc4 351 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
acc838fd 352 fStepSum[idvol]/2.*sin(theta)*sin(phi),
353 fStepSum[idvol]/2.*cos(theta),0.0 );
5a0e88a7 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()) ;
d7c4fbc4 358 fTrackPosition-=backToWire;
1391e633 359
360 //-------------- Angle effect
361 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
362
30178c30 363 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
d7c4fbc4 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
369
374ebd7d 370
371 if (fAngleEffect){
30178c30 372 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
373 betaxGamma=TMath::Log(betaxGamma);
374 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
1391e633 375 // 10 degrees is a reference for a model (arbitrary)
d7c4fbc4 376 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
1391e633 377 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
d7c4fbc4 378 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
1391e633 379 if ( (iChamber==1) || (iChamber==2) )
acc838fd 380 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
d7c4fbc4 381 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
1391e633 382 }
374ebd7d 383 }
1391e633 384
333f7cda 385 // Detection elements ids
b7ef3c96 386 const AliMUONGeometryModule* kGeometryModule
387 = GetGeometry()->GetModule(iChamber-1);
e118b27e 388
389 AliMUONGeometryDetElement* detElement
b7ef3c96 390 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
e118b27e 391
333f7cda 392 Int_t detElemId = 0;
e118b27e 393 if (detElement) detElemId = detElement->GetUniqueID();
333f7cda 394
395 if (!detElemId) {
396 cerr << "Chamber id: "
397 << setw(3) << iChamber << " "
398 << "Current SV: "
399 << CurrentVolumePath()
400 << " detElemId: "
401 << setw(5) << detElemId
402 << endl;
403 Double_t x, y, z;
404 gMC->TrackPosition(x, y, z);
405 cerr << " global position: "
406 << x << ", " << y << ", " << z
407 << endl;
8c343c7c 408 AliWarning("DetElemId not identified.");
333f7cda 409 }
410
1391e633 411 // One hit per chamber
47464038 412 GetMUONData()->AddHit(fIshunt,
413 gAlice->GetMCApp()->GetCurrentTrackNumber(),
414 iChamber, ipart,
415 fTrackPosition.X(),
416 fTrackPosition.Y()+yAngleEffect,
417 fTrackPosition.Z(),
418 gMC->TrackTime(),
419 fTrackMomentum.P(),
420 theta,
421 phi,
422 fStepSum[idvol],
423 fDestepSum[idvol],
424 fTrackPosition.X(),
425 fTrackPosition.Y(),
426 fTrackPosition.Z());
427
5a0e88a7 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())) ;
1391e633 432// }
433 fStepSum[idvol] =0; // Reset for the next event
434 fDestepSum[idvol]=0; // Reset for the next event
435 }
abaf7c9d 436}
5f91c9e8 437
d59b2ec3 438//_______________________________________________________________________________
439void AliMUONv1::StepManager2()
440{
d19b6003 441/// Step manager for the chambers
d59b2ec3 442
d59b2ec3 443 // Only charged tracks
444 if( !(gMC->TrackCharge()) ) return;
445 // Only charged tracks
446
447 // Only gas gap inside chamber
448 // Tag chambers and record hits when track enters
c5ce4e69 449 static Int_t idvol=-1, iEnter = 0;
d59b2ec3 450 Int_t iChamber=0;
451 Int_t id=0;
452 Int_t copy;
453 const Float_t kBig = 1.e10;
c5ce4e69 454 static Double_t xyzEnter[3];
d59b2ec3 455
456 //
457 // Only gas gap inside chamber
458 // Tag chambers and record hits when track enters
459 id=gMC->CurrentVolID(copy);
460 iChamber = GetChamberId(id);
461 idvol = iChamber -1;
462
463 if (idvol == -1) return;
464
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());
468
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
c5ce4e69 472 iEnter = 1;
473 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
d59b2ec3 474 }
475
5a0e88a7 476 // AliDebug(1,
477 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
478 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
d59b2ec3 479 // Particule id and mass,
480 Int_t ipart = gMC->TrackPid();
481 Float_t mass = gMC->TrackMass();
482
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();
487
5a0e88a7 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())) ;
497 //}
d59b2ec3 498
499 // Track left chamber or StepSum larger than fStepMaxInActiveGas
500 if ( gMC->IsTrackExiting() ||
501 gMC->IsTrackStop() ||
502 gMC->IsTrackDisappeared()||
503 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
504
505 if ( gMC->IsTrackExiting() ||
506 gMC->IsTrackStop() ||
507 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
c5ce4e69 508 if (fDestepSum[idvol] == 0) {
509 // AZ - no energy release
510 fStepSum[idvol] = 0; // Reset for the next event
511 iEnter = 0;
512 return;
513 }
d59b2ec3 514
515 gMC->TrackPosition(fTrackPosition);
516 Float_t theta = fTrackMomentum.Theta();
517 Float_t phi = fTrackMomentum.Phi();
518
795b3f56 519 Int_t merge = 0;
520 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
c5ce4e69 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.
526
527 // Only for a track going from the entrance to the exit from the volume
528 // Get local coordinates
c5ce4e69 529 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
530
531 fTrackPosition.Vect().GetXYZ(tmp);
532 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
795b3f56 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;
537 }
c5ce4e69 538
795b3f56 539 if (merge) {
c5ce4e69 540 Double_t dz = -0.5;
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());
547 } else {
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);
553 // AliDebug(1,
554 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
555 // AliDebug(1,
556 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
557 }
d59b2ec3 558
559 //-------------- Angle effect
560 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
561
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
568
569
570 if (fAngleEffect){
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
581 }
582 }
583
584 // Detection elements ids
b7ef3c96 585 const AliMUONGeometryModule* kGeometryModule
586 = GetGeometry()->GetModule(iChamber-1);
d59b2ec3 587
588 AliMUONGeometryDetElement* detElement
b7ef3c96 589 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
d59b2ec3 590
591 Int_t detElemId = 0;
592 if (detElement) detElemId = detElement->GetUniqueID();
593
594 if (!detElemId) {
595 cerr << "Chamber id: "
596 << setw(3) << iChamber << " "
597 << "Current SV: "
598 << CurrentVolumePath()
599 << " detElemId: "
600 << setw(5) << detElemId
601 << endl;
602 Double_t x, y, z;
603 gMC->TrackPosition(x, y, z);
604 cerr << " global position: "
605 << x << ", " << y << ", " << z
606 << endl;
607 AliError("DetElemId not identified.");
608 }
609
610 // One hit per chamber
8690a0a6 611 GetMUONData()->AddHit2(fIshunt,
d59b2ec3 612 gAlice->GetMCApp()->GetCurrentTrackNumber(),
613 detElemId, ipart,
614 fTrackPosition.X(),
615 fTrackPosition.Y()+yAngleEffect,
616 fTrackPosition.Z(),
617 gMC->TrackTime(),
618 fTrackMomentum.P(),
619 theta,
620 phi,
621 fStepSum[idvol],
622 fDestepSum[idvol],
623 fTrackPosition.X(),
624 fTrackPosition.Y(),
625 fTrackPosition.Z());
626
5a0e88a7 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()) ;
630
d59b2ec3 631 fStepSum[idvol] =0; // Reset for the next event
632 fDestepSum[idvol]=0; // Reset for the next event
c5ce4e69 633 iEnter = 0;
d59b2ec3 634 }
635}