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