]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONv1.cxx
Updated with refactoring of geometry & segmentation classes;
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
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.              *
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     *
12  * about the suitability of this software for any purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /////////////////////////////////////////////////////////
19 //  Manager and hits classes for set:MUON version 1    //
20 /////////////////////////////////////////////////////////
21
22 #include <TRandom.h>
23 #include <TF1.h>
24 #include <TClonesArray.h>
25 #include <TRandom.h> 
26 #include <TVirtualMC.h>
27 #include <TGeoMatrix.h>
28
29 #include "AliMUONv1.h"
30 #include "AliConst.h" 
31 #include "AliMUONConstants.h"
32 #include "AliMUONSegFactoryV4.h"
33 #include "AliMUONSegFactoryV3.h"
34 #include "AliMUONSegFactoryV2.h"
35 #include "AliMUONResponseFactory.h"
36 #include "AliMUONSegmentation.h"
37 #include "AliMUONHit.h"
38 #include "AliMUONTriggerCircuit.h"
39 #include "AliMUONGeometryBuilder.h"     
40 #include "AliMUONGeometry.h"    
41 #include "AliMUONGeometryTransformer.h" 
42 #include "AliMUONGeometryModule.h"      
43 #include "AliMUONGeometrySVMap.h"       
44 #include "AliMUONGeometryDetElement.h"  
45 #include "AliMagF.h"
46 #include "AliRun.h"
47 #include "AliMC.h"
48 #include "AliLog.h"
49
50 #include <string>
51
52 ClassImp(AliMUONv1)
53  
54 //___________________________________________
55 AliMUONv1::AliMUONv1() 
56   : AliMUON(),
57     fStepManagerVersionOld(kTRUE),
58     fStepManagerVersionDE(kTRUE),
59     fAngleEffect(kTRUE),
60     fStepMaxInActiveGas(0.6),
61     fStepSum(0x0),
62     fDestepSum(0x0),
63     fTrackMomentum(), 
64     fTrackPosition(),
65     fElossRatio(0x0),
66     fAngleEffect10(0x0),
67     fAngleEffectNorma(0x0)
68 {
69 // Default constructor
70         AliDebug(1,Form("default (empty) ctor this=%p",this));
71
72
73 //___________________________________________
74 AliMUONv1::AliMUONv1(const char *name, const char *title)
75   : AliMUON(name,title), 
76     fStepManagerVersionOld(kTRUE),
77     fStepManagerVersionDE(kTRUE),
78     fAngleEffect(kTRUE),
79     fStepMaxInActiveGas(0.6),
80     fStepSum(0x0),
81     fDestepSum(0x0),
82     fTrackMomentum(), 
83     fTrackPosition(),
84     fElossRatio(0x0),
85     fAngleEffect10(0x0),
86     fAngleEffectNorma(0x0)
87 {
88 // Standard onstructor
89
90         AliDebug(1,Form("ctor this=%p",this));  
91         
92     // By default include all stations
93
94     fStepSum   = new Float_t [AliMUONConstants::NCh()];
95     fDestepSum = new Float_t [AliMUONConstants::NCh()];
96     for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
97       fStepSum[i] =0.0;
98       fDestepSum[i]=0.0;
99     }
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);
107
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);
120 }
121
122 //_____________________________________________________________________________
123 AliMUONv1::AliMUONv1(const AliMUONv1& right) 
124   : AliMUON(right) 
125 {  
126   // copy constructor (not implemented)
127
128   AliFatal("Copy constructor not provided.");
129 }
130
131 //___________________________________________
132 AliMUONv1::~AliMUONv1()
133 {
134 // Destructor
135         AliDebug(1,Form("dtor this=%p",this));
136   delete [] fStepSum;
137   delete [] fDestepSum;
138   delete fElossRatio;
139   delete fAngleEffect10;
140   delete fAngleEffectNorma; 
141 }
142
143 //_____________________________________________________________________________
144 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
145 {
146   // assignement operator (not implemented)
147
148   // check assignement to self
149   if (this == &right) return *this;
150
151   AliFatal("Assignement operator not provided.");
152     
153   return *this;  
154 }    
155
156 //__________________________________________________
157 void AliMUONv1::CreateGeometry()
158 {
159 //
160 // Construct geometry using geometry builder
161 //
162
163   fGeometryBuilder->CreateGeometry();
164 }
165
166 //________________________________________________________________
167 void AliMUONv1::CreateMaterials()
168 {
169 //
170 // Construct materials using geometry builder
171 //
172
173   fGeometryBuilder->CreateMaterials();
174 }
175
176 //___________________________________________
177 void AliMUONv1::Init()
178
179   AliDebug(1,"Start Init for version 1 - CPC chamber type");
180    
181   //
182   // Initialize geometry
183   //
184   fGeometryBuilder->InitGeometry();
185   AliDebug(1,"Finished Init for version 1 - CPC chamber type");   
186  
187
188   std::string ftype(GetTitle());
189
190   // Build segmentation
191   // using geometry parametrisation
192   //
193   if ( ftype == "default" || ftype == "FactoryV2") {
194     AliMUONSegFactoryV2 segFactory("default");
195     segFactory.Build(GetGeometryTransformer());
196     fSegmentation = segFactory.GetSegmentation();
197   } 
198   else  if ( ftype == "FactoryV3" ) {
199     AliMUONSegFactoryV3 segFactory("default");
200     segFactory.Build(GetGeometryTransformer());
201     fSegmentation = segFactory.GetSegmentation();
202   }
203   else if ( ftype == "FactoryV4" ) {
204     AliMUONSegFactoryV4 segFactory("default");
205     segFactory.Build(GetGeometryTransformer());
206     fSegmentation = segFactory.GetSegmentation();
207   }
208   else {
209     AliFatal(Form("Wrong factory type : %s",ftype.c_str()));      
210   }
211
212   // Build response
213   //
214   AliMUONResponseFactory respFactory("default");
215   respFactory.Build(this);
216   
217
218   // Initialize segmentation
219   //
220   fSegmentation->Init();
221
222   // Initialize trigger circuits
223   //
224   for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++)  {
225     AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
226     c->Init(i);
227 //    c->Print();
228   }
229   
230 }
231
232 //__________________________________________________________________
233 Int_t  AliMUONv1::GetChamberId(Int_t volId) const
234 {
235 // Check if the volume with specified  volId is a sensitive volume (gas) 
236 // of some chamber and returns the chamber number;
237 // if not sensitive volume - return 0.
238 // ---
239
240   for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
241     if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
242       return i+1;
243   }    
244
245   return 0;
246 }
247
248 //_______________________________________________________________________________
249 TString  AliMUONv1::CurrentVolumePath() const
250 {
251 // Returns current volume path
252 // (Could be removed when this function is available via gMC)
253 // ---       
254
255   TString path = "";
256   TString name;
257   Int_t copyNo;
258   Int_t imother = 0;
259   do {
260     name = gMC->CurrentVolOffName(imother);
261     gMC->CurrentVolOffID(imother++, copyNo);
262     TString add = "/";
263     add += name;
264     add += ".";
265     add += copyNo;
266     path.Insert(0,add); 
267   }
268   while ( name != TString("ALIC") );
269   
270   return path;  
271 }
272
273 //_______________________________________________________________________________
274 void AliMUONv1::StepManager()
275 {
276   // Stepmanager for the chambers
277   // TBR
278
279  if (fStepManagerVersionDE) {
280     StepManager2();
281     return;
282   }
283
284
285   // Only charged tracks
286   if( !(gMC->TrackCharge()) ) return; 
287   // Only charged tracks
288   
289   // Only gas gap inside chamber
290   // Tag chambers and record hits when track enters 
291   static Int_t   idvol=-1;
292   Int_t   iChamber=0;
293   Int_t   id=0;
294   Int_t   copy;
295   const  Float_t kBig = 1.e10;
296
297
298   //
299   // Only gas gap inside chamber
300   // Tag chambers and record hits when track enters 
301   id=gMC->CurrentVolID(copy);
302   iChamber = GetChamberId(id);
303   idvol = iChamber -1;
304
305   if (idvol == -1) return;
306
307   // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
308   if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )     
309     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
310   
311    if( gMC->IsTrackEntering() ) {
312      Float_t theta = fTrackMomentum.Theta();
313      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
314   }
315
316    //  AliDebug(1,
317    //    Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
318    //    ( (AliMUONChamber*)(*fChambers)[idvol])->Z()));
319    // Particule id and mass, 
320   Int_t     ipart = gMC->TrackPid();
321   Float_t   mass  = gMC->TrackMass();
322
323   fDestepSum[idvol]+=gMC->Edep();
324   // Get current particle id (ipart), track position (pos)  and momentum (mom)
325   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
326   fStepSum[idvol]+=gMC->TrackStep();
327   
328   //  if(AliDebugLevel()) {
329   //  AliDebug(1,
330   //         Form("iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
331   //              iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, 
332   //              mass, fStepSum[idvol], gMC->Edep()));
333   //  AliDebug(1,
334   //         Form("Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), 
335   //              fTrackMomentum.Z()));
336   //  gMC->TrackPosition(fTrackPosition);
337   //  AliDebug(1,
338   //         Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),
339   //      fTrackPosition.Z())) ;
340   //   }
341
342   // Track left chamber or StepSum larger than fStepMaxInActiveGas
343   if ( gMC->IsTrackExiting() || 
344        gMC->IsTrackStop() || 
345        gMC->IsTrackDisappeared()||
346        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
347     
348     if   ( gMC->IsTrackExiting() || 
349            gMC->IsTrackStop() || 
350            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
351
352     gMC->TrackPosition(fTrackPosition);
353     Float_t theta = fTrackMomentum.Theta();
354     Float_t phi   = fTrackMomentum.Phi();
355     
356     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
357                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
358                                fStepSum[idvol]/2.*cos(theta),0.0       );
359     //     AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),
360     //                     fTrackPosition.Y(),fTrackPosition.Z())) ;
361     //     AliDebug(1,Form("Exit: Track backToWire %f %f %f",backToWire.X(),
362     //                     backToWire.Y(),backToWire.Z()) ;
363     fTrackPosition-=backToWire;
364     
365     //-------------- Angle effect 
366     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
367     
368     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
369     Float_t sigmaEffect10degrees;
370     Float_t sigmaEffectThetadegrees;
371     Float_t eLossParticleELossMip;
372     Float_t yAngleEffect=0.;
373     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
374
375
376     if (fAngleEffect){
377     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
378       betaxGamma=TMath::Log(betaxGamma);
379       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
380       // 10 degrees is a reference for a model (arbitrary)
381       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
382       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
383       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
384       if ( (iChamber==1)  ||  (iChamber==2) )  
385         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
386       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
387     }
388     }
389     
390     // Detection elements ids
391     const AliMUONGeometryModule* kGeometryModule
392       = GetGeometry()->GetModule(iChamber-1);
393
394     AliMUONGeometryDetElement* detElement
395       = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
396
397     Int_t detElemId = 0;
398     if (detElement) detElemId = detElement->GetUniqueID(); 
399  
400     if (!detElemId) {
401       cerr << "Chamber id: "
402            << setw(3) << iChamber << "  "
403            << "Current SV: " 
404            <<  CurrentVolumePath() 
405            << "  detElemId: "
406            << setw(5) << detElemId 
407            << endl;
408       Double_t x, y, z;
409       gMC->TrackPosition(x, y, z);         
410       cerr << "   global position: "
411            << x << ", " << y << ", " << z
412            << endl;
413       AliWarning("DetElemId not identified.");
414     }  
415     
416     // One hit per chamber
417     GetMUONData()->AddHit(fIshunt, 
418                           gAlice->GetMCApp()->GetCurrentTrackNumber(), 
419                           iChamber, ipart,
420                           fTrackPosition.X(), 
421                           fTrackPosition.Y()+yAngleEffect, 
422                           fTrackPosition.Z(), 
423                           gMC->TrackTime(),
424                           fTrackMomentum.P(),
425                           theta, 
426                           phi, 
427                           fStepSum[idvol], 
428                           fDestepSum[idvol],                        
429                           fTrackPosition.X(),
430                           fTrackPosition.Y(),
431                           fTrackPosition.Z());
432
433 //     if (AliDebugLevel()){
434 //       AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
435 //       AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
436 //       AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z())) ;
437 //     }
438     fStepSum[idvol]  =0; // Reset for the next event
439     fDestepSum[idvol]=0; // Reset for the next event
440   }
441 }
442
443 //_______________________________________________________________________________
444 void AliMUONv1::StepManager2()
445 {
446   // Stepmanager for the chambers
447
448   // Only charged tracks
449   if( !(gMC->TrackCharge()) ) return; 
450   // Only charged tracks
451   
452   // Only gas gap inside chamber
453   // Tag chambers and record hits when track enters 
454   static Int_t   idvol=-1;
455   Int_t   iChamber=0;
456   Int_t   id=0;
457   Int_t   copy;
458   const  Float_t kBig = 1.e10;
459
460
461   //
462   // Only gas gap inside chamber
463   // Tag chambers and record hits when track enters 
464   id=gMC->CurrentVolID(copy);
465   iChamber = GetChamberId(id);
466   idvol = iChamber -1;
467
468   if (idvol == -1) return;
469   
470   // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
471   if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )     
472     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
473   
474    if( gMC->IsTrackEntering() ) {
475      Float_t theta = fTrackMomentum.Theta();
476      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
477   }
478
479    //   AliDebug(1,
480    //       Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
481    //            ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
482   // Particule id and mass, 
483   Int_t     ipart = gMC->TrackPid();
484   Float_t   mass  = gMC->TrackMass();
485
486   fDestepSum[idvol]+=gMC->Edep();
487   // Get current particle id (ipart), track position (pos)  and momentum (mom)
488   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
489   fStepSum[idvol]+=gMC->TrackStep();
490   
491   //  if (AliDebugLevel()) {
492   //   AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
493   //                 iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
494   //         mass, fStepSum[idvol], gMC->Edep()));
495   // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), 
496   //         fTrackMomentum.Z()));
497   // gMC->TrackPosition(fTrackPosition);
498   // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
499   //         fTrackPosition.Y(),fTrackPosition.Z())) ;
500   //}
501
502   // Track left chamber or StepSum larger than fStepMaxInActiveGas
503   if ( gMC->IsTrackExiting() || 
504        gMC->IsTrackStop() || 
505        gMC->IsTrackDisappeared()||
506        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
507     
508     if   ( gMC->IsTrackExiting() || 
509            gMC->IsTrackStop() || 
510            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
511
512     gMC->TrackPosition(fTrackPosition);
513     Float_t theta = fTrackMomentum.Theta();
514     Float_t phi   = fTrackMomentum.Phi();
515     
516     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
517                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
518                                fStepSum[idvol]/2.*cos(theta),0.0       );
519     //    AliDebug(1,
520     //       Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
521     // AliDebug(1,
522     //       Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
523     fTrackPosition-=backToWire;
524     
525     //-------------- Angle effect 
526     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
527     
528     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
529     Float_t sigmaEffect10degrees;
530     Float_t sigmaEffectThetadegrees;
531     Float_t eLossParticleELossMip;
532     Float_t yAngleEffect=0.;
533     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
534
535
536     if (fAngleEffect){
537     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
538       betaxGamma=TMath::Log(betaxGamma);
539       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
540       // 10 degrees is a reference for a model (arbitrary)
541       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
542       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
543       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
544       if ( (iChamber==1)  ||  (iChamber==2) )  
545         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
546       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
547     }
548     }
549     
550     // Detection elements ids
551     const AliMUONGeometryModule* kGeometryModule
552       = GetGeometry()->GetModule(iChamber-1);
553
554     AliMUONGeometryDetElement* detElement
555       = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
556
557     Int_t detElemId = 0;
558     if (detElement) detElemId = detElement->GetUniqueID(); 
559  
560     if (!detElemId) {
561       cerr << "Chamber id: "
562            << setw(3) << iChamber << "  "
563            << "Current SV: " 
564            <<  CurrentVolumePath() 
565            << "  detElemId: "
566            << setw(5) << detElemId 
567            << endl;
568       Double_t x, y, z;
569       gMC->TrackPosition(x, y, z);         
570       cerr << "   global position: "
571            << x << ", " << y << ", " << z
572            << endl;
573       AliError("DetElemId not identified.");
574     }  
575     
576     // One hit per chamber
577     GetMUONData()->AddHit2(fIshunt, 
578                           gAlice->GetMCApp()->GetCurrentTrackNumber(), 
579                           detElemId, ipart,
580                           fTrackPosition.X(), 
581                           fTrackPosition.Y()+yAngleEffect, 
582                           fTrackPosition.Z(), 
583                           gMC->TrackTime(),
584                           fTrackMomentum.P(),
585                           theta, 
586                           phi, 
587                           fStepSum[idvol], 
588                           fDestepSum[idvol],                        
589                           fTrackPosition.X(),
590                           fTrackPosition.Y(),
591                           fTrackPosition.Z());
592
593     //       AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
594     //       AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
595     //       AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
596
597     fStepSum[idvol]  =0; // Reset for the next event
598     fDestepSum[idvol]=0; // Reset for the next event
599   }
600 }