]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONv1.cxx
Added deleting of AliMUONFactory in AliMUON (Ivana)
[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 "AliMUONFactoryV2.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"  
40 #include "AliMagF.h"
41 #include "AliRun.h"
42 #include "AliMC.h"
43 #include "AliLog.h"
44
45 ClassImp(AliMUONv1)
46  
47 //___________________________________________
48 AliMUONv1::AliMUONv1() 
49   : AliMUON(),
50     fStepManagerVersionOld(kFALSE),
51     fStepManagerVersionDE(kFALSE),
52     fAngleEffect(kTRUE),
53     fStepMaxInActiveGas(0.6),
54     fStepSum(0x0),
55     fDestepSum(0x0),
56     fTrackMomentum(), 
57     fTrackPosition(),
58     fElossRatio(0x0),
59     fAngleEffect10(0x0),
60     fAngleEffectNorma(0x0)
61 {
62 // Default constructor
63
64
65 //___________________________________________
66 AliMUONv1::AliMUONv1(const char *name, const char *title)
67   : AliMUON(name,title), 
68     fStepManagerVersionOld(kFALSE),
69     fStepManagerVersionDE(kFALSE),
70     fAngleEffect(kTRUE),
71     fStepMaxInActiveGas(0.6),
72     fStepSum(0x0),
73     fDestepSum(0x0),
74     fTrackMomentum(), 
75     fTrackPosition(),
76     fElossRatio(0x0),
77     fAngleEffect10(0x0),
78     fAngleEffectNorma(0x0)
79 {
80 // Standard onstructor
81
82     // By default include all stations
83
84     fStepSum   = new Float_t [AliMUONConstants::NCh()];
85     fDestepSum = new Float_t [AliMUONConstants::NCh()];
86     for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
87       fStepSum[i] =0.0;
88       fDestepSum[i]=0.0;
89     }
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);
97
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);
110 }
111
112 //_____________________________________________________________________________
113 AliMUONv1::AliMUONv1(const AliMUONv1& right) 
114   : AliMUON(right) 
115 {  
116   // copy constructor (not implemented)
117
118   AliFatal("Copy constructor not provided.");
119 }
120
121 //___________________________________________
122 AliMUONv1::~AliMUONv1()
123 {
124 // Destructor
125
126   delete [] fStepSum;
127   delete [] fDestepSum;
128   delete fElossRatio;
129   delete fAngleEffect10;
130   delete fAngleEffectNorma; 
131 }
132
133 //_____________________________________________________________________________
134 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
135 {
136   // assignement operator (not implemented)
137
138   // check assignement to self
139   if (this == &right) return *this;
140
141   AliFatal("Assignement operator not provided.");
142     
143   return *this;  
144 }    
145
146 //__________________________________________________
147 void AliMUONv1::CreateGeometry()
148 {
149 //
150 // Construct geometry using geometry builder
151 //
152
153   fGeometryBuilder->CreateGeometry();
154 }
155
156 //________________________________________________________________
157 void AliMUONv1::CreateMaterials()
158 {
159 //
160 // Construct materials using geometry builder
161 //
162
163   fGeometryBuilder->CreateMaterials();
164 }
165
166 //___________________________________________
167 void AliMUONv1::Init()
168
169    AliDebug(1,"Start Init for version 1 - CPC chamber type");
170    Int_t i;
171
172  
173   //
174    // Initialize geometry
175    //
176    fGeometryBuilder->InitGeometry();
177    AliDebug(1,"Finished Init for version 1 - CPC chamber type");   
178
179    if (fSegmentationType == 1) {
180      fFactory = new AliMUONFactory("Old MUON Factory");
181      printf("\n Old Segmentation \n");
182    }
183
184    if (fSegmentationType == 2) {
185      fFactory = new AliMUONFactoryV2("New MUON Factory");
186      printf("\n New Segmentation \n");
187    } 
188
189    fFactory->Build(this, "default");
190
191    //
192    // Initialize segmentation
193    //
194    if (!fSegmentationType) {
195      AliFatal("No Segmentation Type defined.");
196      return;
197    }
198
199    if (fSegmentationType == 1) {
200    for (i=0; i<AliMUONConstants::NCh(); i++) 
201        ( (AliMUONChamber*) (*fChambers)[i])->Init();
202    }
203
204    if (fSegmentationType == 2) {
205      for (i=0; i<AliMUONConstants::NCh(); i++) 
206        ( (AliMUONChamber*) (*fChambers)[i])->Init(fSegmentationType);// new segmentation
207    }
208  
209    if (fSegmentationType == 1) {
210     //cp 
211      AliDebug(1,"Start Init for Trigger Circuits");
212      for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) 
213        ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
214      AliDebug(1,"Finished Init for Trigger Circuits");
215    } 
216
217
218
219 }
220
221 //__________________________________________________________________
222 Int_t  AliMUONv1::GetChamberId(Int_t volId) const
223 {
224 // Check if the volume with specified  volId is a sensitive volume (gas) 
225 // of some chamber and returns the chamber number;
226 // if not sensitive volume - return 0.
227 // ---
228
229 /*
230   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
231     if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
232 */
233   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
234     if ( ((AliMUONChamber*)(*fChambers)[i-1])->IsSensId(volId) ) return i;
235
236   return 0;
237 }
238
239 //_______________________________________________________________________________
240 TString  AliMUONv1::CurrentVolumePath() const
241 {
242 // Returns current volume path
243 // (Could be removed when this function is available via gMC)
244 // ---       
245
246   TString path = "";
247   TString name;
248   Int_t copyNo;
249   Int_t imother = 0;
250   do {
251     name = gMC->CurrentVolOffName(imother);
252     gMC->CurrentVolOffID(imother++, copyNo);
253     TString add = "/";
254     add += name;
255     add += ".";
256     add += copyNo;
257     path.Insert(0,add); 
258   }
259   while ( name != TString("ALIC") );
260   
261   return path;  
262 }
263
264 //_______________________________________________________________________________
265 void AliMUONv1::StepManager()
266 {
267   // Stepmanager for the chambers
268   // TBR
269
270  if (fStepManagerVersionDE) {
271     StepManager2();
272     return;
273   }
274
275  if (fStepManagerVersionOld) {
276     StepManagerOld();
277     return;
278   }
279
280   // Only charged tracks
281   if( !(gMC->TrackCharge()) ) return; 
282   // Only charged tracks
283   
284   // Only gas gap inside chamber
285   // Tag chambers and record hits when track enters 
286   static Int_t   idvol=-1;
287   Int_t   iChamber=0;
288   Int_t   id=0;
289   Int_t   copy;
290   const  Float_t kBig = 1.e10;
291
292
293   //
294   // Only gas gap inside chamber
295   // Tag chambers and record hits when track enters 
296   id=gMC->CurrentVolID(copy);
297   iChamber = GetChamberId(id);
298   idvol = iChamber -1;
299
300   if (idvol == -1) return;
301
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   
306    if( gMC->IsTrackEntering() ) {
307      Float_t theta = fTrackMomentum.Theta();
308      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
309   }
310
311 //  if (GetDebug()) {
312 //     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
313 //      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
314 //   }  
315   // Particule id and mass, 
316   Int_t     ipart = gMC->TrackPid();
317   Float_t   mass  = gMC->TrackMass();
318
319   fDestepSum[idvol]+=gMC->Edep();
320   // Get current particle id (ipart), track position (pos)  and momentum (mom)
321   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
322   fStepSum[idvol]+=gMC->TrackStep();
323   
324 //   if (GetDebug()) {
325 //     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
326 //       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()) ;
327 //     gMC->TrackPosition(fTrackPosition);
328 //     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
329 //   }
330
331   // Track left chamber or StepSum larger than fStepMaxInActiveGas
332   if ( gMC->IsTrackExiting() || 
333        gMC->IsTrackStop() || 
334        gMC->IsTrackDisappeared()||
335        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
336     
337     if   ( gMC->IsTrackExiting() || 
338            gMC->IsTrackStop() || 
339            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
340
341     gMC->TrackPosition(fTrackPosition);
342     Float_t theta = fTrackMomentum.Theta();
343     Float_t phi   = fTrackMomentum.Phi();
344     
345     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
346                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
347                                fStepSum[idvol]/2.*cos(theta),0.0       );
348     //     if (GetDebug()) 
349     //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
350     //     if (GetDebug()) 
351     //        Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
352     fTrackPosition-=backToWire;
353     
354     //-------------- Angle effect 
355     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
356     
357     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
358     Float_t sigmaEffect10degrees;
359     Float_t sigmaEffectThetadegrees;
360     Float_t eLossParticleELossMip;
361     Float_t yAngleEffect=0.;
362     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
363
364
365     if (fAngleEffect){
366     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
367       betaxGamma=TMath::Log(betaxGamma);
368       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
369       // 10 degrees is a reference for a model (arbitrary)
370       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
371       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
372       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
373       if ( (iChamber==1)  ||  (iChamber==2) )  
374         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
375       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
376     }
377     }
378     
379     // Detection elements ids
380     AliMUONGeometryModule* geometry
381       = Chamber(iChamber-1).GetGeometry();
382
383     AliMUONGeometryDetElement* detElement
384       = geometry->FindBySensitiveVolume(CurrentVolumePath());
385
386     Int_t detElemId = 0;
387     if (detElement) detElemId = detElement->GetUniqueID(); 
388  
389     if (!detElemId) {
390       cerr << "Chamber id: "
391            << setw(3) << iChamber << "  "
392            << "Current SV: " 
393            <<  CurrentVolumePath() 
394            << "  detElemId: "
395            << setw(5) << detElemId 
396            << endl;
397       Double_t x, y, z;
398       gMC->TrackPosition(x, y, z);         
399       cerr << "   global position: "
400            << x << ", " << y << ", " << z
401            << endl;
402       AliWarning("DetElemId not identified.");
403     }  
404     
405     // One hit per chamber
406     GetMUONData()->AddHit(fIshunt, 
407                           gAlice->GetMCApp()->GetCurrentTrackNumber(), 
408                           iChamber, ipart,
409                           fTrackPosition.X(), 
410                           fTrackPosition.Y()+yAngleEffect, 
411                           fTrackPosition.Z(), 
412                           gMC->TrackTime(),
413                           fTrackMomentum.P(),
414                           theta, 
415                           phi, 
416                           fStepSum[idvol], 
417                           fDestepSum[idvol],                        
418                           fTrackPosition.X(),
419                           fTrackPosition.Y(),
420                           fTrackPosition.Z());
421
422 //     if (GetDebug()){
423 //       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
424 //       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
425 //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
426 //     }
427     fStepSum[idvol]  =0; // Reset for the next event
428     fDestepSum[idvol]=0; // Reset for the next event
429   }
430 }
431
432 //_______________________________________________________________________________
433 void AliMUONv1::StepManager2()
434 {
435   // Stepmanager for the chambers
436
437  if (fStepManagerVersionOld) {
438     StepManagerOld2();
439     return;
440   }
441
442   // Only charged tracks
443   if( !(gMC->TrackCharge()) ) return; 
444   // Only charged tracks
445   
446   // Only gas gap inside chamber
447   // Tag chambers and record hits when track enters 
448   static Int_t   idvol=-1;
449   Int_t   iChamber=0;
450   Int_t   id=0;
451   Int_t   copy;
452   const  Float_t kBig = 1.e10;
453
454
455   //
456   // Only gas gap inside chamber
457   // Tag chambers and record hits when track enters 
458   id=gMC->CurrentVolID(copy);
459   iChamber = GetChamberId(id);
460   idvol = iChamber -1;
461
462   if (idvol == -1) return;
463   
464   // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
465   if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )     
466     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
467   
468    if( gMC->IsTrackEntering() ) {
469      Float_t theta = fTrackMomentum.Theta();
470      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
471   }
472
473 //  if (GetDebug()) {
474 //     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
475 //      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
476 //   }  
477   // Particule id and mass, 
478   Int_t     ipart = gMC->TrackPid();
479   Float_t   mass  = gMC->TrackMass();
480
481   fDestepSum[idvol]+=gMC->Edep();
482   // Get current particle id (ipart), track position (pos)  and momentum (mom)
483   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
484   fStepSum[idvol]+=gMC->TrackStep();
485   
486 //   if (GetDebug()) {
487 //     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
488 //       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()) ;
489 //     gMC->TrackPosition(fTrackPosition);
490 //     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
491 //   }
492
493   // Track left chamber or StepSum larger than fStepMaxInActiveGas
494   if ( gMC->IsTrackExiting() || 
495        gMC->IsTrackStop() || 
496        gMC->IsTrackDisappeared()||
497        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
498     
499     if   ( gMC->IsTrackExiting() || 
500            gMC->IsTrackStop() || 
501            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
502
503     gMC->TrackPosition(fTrackPosition);
504     Float_t theta = fTrackMomentum.Theta();
505     Float_t phi   = fTrackMomentum.Phi();
506     
507     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
508                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
509                                fStepSum[idvol]/2.*cos(theta),0.0       );
510     //     if (GetDebug()) 
511     //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
512     //     if (GetDebug()) 
513     //        Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
514     fTrackPosition-=backToWire;
515     
516     //-------------- Angle effect 
517     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
518     
519     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
520     Float_t sigmaEffect10degrees;
521     Float_t sigmaEffectThetadegrees;
522     Float_t eLossParticleELossMip;
523     Float_t yAngleEffect=0.;
524     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
525
526
527     if (fAngleEffect){
528     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
529       betaxGamma=TMath::Log(betaxGamma);
530       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
531       // 10 degrees is a reference for a model (arbitrary)
532       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
533       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
534       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
535       if ( (iChamber==1)  ||  (iChamber==2) )  
536         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
537       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
538     }
539     }
540     
541     // Detection elements ids
542     AliMUONGeometryModule* geometry
543       = Chamber(iChamber-1).GetGeometry();
544
545     AliMUONGeometryDetElement* detElement
546       = geometry->FindBySensitiveVolume(CurrentVolumePath());
547
548     Int_t detElemId = 0;
549     if (detElement) detElemId = detElement->GetUniqueID(); 
550  
551     if (!detElemId) {
552       cerr << "Chamber id: "
553            << setw(3) << iChamber << "  "
554            << "Current SV: " 
555            <<  CurrentVolumePath() 
556            << "  detElemId: "
557            << setw(5) << detElemId 
558            << endl;
559       Double_t x, y, z;
560       gMC->TrackPosition(x, y, z);         
561       cerr << "   global position: "
562            << x << ", " << y << ", " << z
563            << endl;
564       AliError("DetElemId not identified.");
565     }  
566     
567     // One hit per chamber
568     GetMUONData()->AddHit2(fIshunt, 
569                           gAlice->GetMCApp()->GetCurrentTrackNumber(), 
570                           detElemId, ipart,
571                           fTrackPosition.X(), 
572                           fTrackPosition.Y()+yAngleEffect, 
573                           fTrackPosition.Z(), 
574                           gMC->TrackTime(),
575                           fTrackMomentum.P(),
576                           theta, 
577                           phi, 
578                           fStepSum[idvol], 
579                           fDestepSum[idvol],                        
580                           fTrackPosition.X(),
581                           fTrackPosition.Y(),
582                           fTrackPosition.Z());
583
584 //     if (GetDebug()){
585 //       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
586 //       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
587 //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
588 //     }
589     fStepSum[idvol]  =0; // Reset for the next event
590     fDestepSum[idvol]=0; // Reset for the next event
591   }
592 }
593
594 //__________________________________________
595 void AliMUONv1::StepManagerOld()
596 {
597   // Old Stepmanager for the chambers
598   // TBR
599   
600   Int_t          copy, id;
601   static Int_t   idvol =-1;
602   static Int_t   vol[2];
603   Int_t          ipart;
604   TLorentzVector pos;
605   TLorentzVector mom;
606   Float_t        theta,phi;
607   Float_t        destep, step;
608   
609   static Float_t sstep;
610   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
611   const  Float_t kBig = 1.e10;
612   static Float_t hits[15];
613
614   TClonesArray &lhits = *fHits;
615
616   //
617   //
618   // Only charged tracks
619   if( !(gMC->TrackCharge()) ) return; 
620   //
621   // Only gas gap inside chamber
622   // Tag chambers and record hits when track enters 
623   id=gMC->CurrentVolID(copy);
624   vol[0] = GetChamberId(id);
625   idvol = vol[0] -1;
626
627   if (idvol == -1) return;
628
629   //
630   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
631   gMC->TrackPosition(pos);
632   gMC->TrackMomentum(mom);
633
634   ipart  = gMC->TrackPid();
635
636   //
637   // momentum loss and steplength in last step
638   destep = gMC->Edep();
639   step   = gMC->TrackStep();
640   // cout<<"------------"<<step<<endl;
641   //
642   // record hits when track enters ...
643   if( gMC->IsTrackEntering()) {
644
645       gMC->SetMaxStep(fMaxStepGas);
646       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
647       Double_t rt = TMath::Sqrt(tc);
648       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
649       Double_t tx = mom[0]/pmom;
650       Double_t ty = mom[1]/pmom;
651       Double_t tz = mom[2]/pmom;
652       Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
653           ->ResponseModel()
654           ->Pitch()/tz;
655       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
656       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
657       hits[0] = Float_t(ipart);         // Geant3 particle type
658       hits[1] = pos[0]+s*tx;            // X-position for hit
659       hits[2] = pos[1]+s*ty;            // Y-position for hit
660       hits[3] = pos[2]+s*tz;            // Z-position for hit
661       hits[4] = theta;                  // theta angle of incidence
662       hits[5] = phi;                    // phi angle of incidence 
663       hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
664       hits[9] = -1;                     // last pad hit
665       hits[10] = mom[3];                // hit momentum P
666       hits[11] = mom[0];                // Px
667       hits[12] = mom[1];                // Py
668       hits[13] = mom[2];                // Pz
669       tof=gMC->TrackTime();
670       hits[14] = tof;                   // Time of flight
671       tlength  = 0;
672       eloss    = 0;
673       eloss2   = 0;
674       sstep=0;
675       xhit     = pos[0];
676       yhit     = pos[1];      
677       zhit     = pos[2];      
678       Chamber(idvol).ChargeCorrelationInit();
679       // Only if not trigger chamber
680
681 //       printf("---------------------------\n");
682 //       printf(">>>> Y =  %f \n",hits[2]);
683 //       printf("---------------------------\n");
684     
685       
686
687      //  if(idvol < AliMUONConstants::NTrackingCh()) {
688 //        //
689 //        //  Initialize hit position (cursor) in the segmentation model 
690 //        ((AliMUONChamber*) (*fChambers)[idvol])
691 //            ->SigGenInit(pos[0], pos[1], pos[2]);
692 //       } else {
693 //        //geant3->Gpcxyz();
694 //        //printf("In the Trigger Chamber #%d\n",idvol-9);
695 //       }
696   }
697   eloss2+=destep;
698   sstep+=step;
699
700   // cout<<sstep<<endl;
701
702   // 
703   // Calculate the charge induced on a pad (disintegration) in case 
704   //
705   // Mip left chamber ...
706   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
707       gMC->SetMaxStep(kBig);
708       eloss   += destep;
709       tlength += step;
710       
711       Float_t x0,y0,z0;
712       Float_t localPos[3];
713       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
714       gMC->Gmtod(globalPos,localPos,1); 
715
716       if(idvol < AliMUONConstants::NTrackingCh()) {
717 // tracking chambers
718           x0 = 0.5*(xhit+pos[0]);
719           y0 = 0.5*(yhit+pos[1]);
720           z0 = 0.5*(zhit+pos[2]);
721       } else {
722 // trigger chambers
723           x0 = xhit;
724           y0 = yhit;
725           z0 = 0.;
726       }
727       
728
729       //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
730       
731           
732       hits[6] = tlength;   // track length
733       hits[7] = eloss2;    // de/dx energy loss
734
735
736       //      if (fNPadHits > (Int_t)hits[8]) {
737       //          hits[8] = hits[8]+1;
738       //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
739       //}
740 //
741 //    new hit 
742       
743       new(lhits[fNhits++]) 
744         AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol, hits, kTRUE);
745       eloss = 0; 
746       //
747       // Check additional signal generation conditions 
748       // defined by the segmentation
749       // model (boundary crossing conditions)
750       // only for tracking chambers
751   } else if 
752       ((idvol < AliMUONConstants::NTrackingCh()) &&
753        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
754   {
755       ((AliMUONChamber*) (*fChambers)[idvol])
756           ->SigGenInit(pos[0], pos[1], pos[2]);
757       
758       Float_t localPos[3];
759       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
760       gMC->Gmtod(globalPos,localPos,1); 
761
762       eloss    += destep;
763
764       // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
765       //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
766       xhit     = pos[0];
767       yhit     = pos[1]; 
768       zhit     = pos[2];
769       eloss = 0;
770       tlength += step ;
771       //
772       // nothing special  happened, add up energy loss
773   } else {        
774       eloss   += destep;
775       tlength += step ;
776   }
777 }
778
779 //__________________________________________
780 void AliMUONv1::StepManagerOld2()
781 {
782   // Old Stepmanager for the chambers
783   Int_t          copy, id;
784   static Int_t   idvol =-1;
785   static Int_t   vol[2];
786   Int_t          ipart;
787   TLorentzVector pos;
788   TLorentzVector mom;
789   Float_t        theta,phi;
790   Float_t        destep, step;
791   
792   static Float_t sstep;
793   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
794   const  Float_t kBig = 1.e10;
795   static Float_t hits[15];
796
797   TClonesArray &lhits = *fHits;
798
799   //
800   //
801   // Only charged tracks
802   if( !(gMC->TrackCharge()) ) return; 
803   //
804   // Only gas gap inside chamber
805   // Tag chambers and record hits when track enters 
806   id=gMC->CurrentVolID(copy);
807
808   Int_t iChamber = GetChamberId(id);
809   idvol =  iChamber-1;
810
811   if (idvol == -1) return;
812
813   // Detection elements id
814   AliMUONGeometryModule* geometry
815     = Chamber(iChamber-1).GetGeometry();
816
817   AliMUONGeometryDetElement* detElement
818     = geometry->FindBySensitiveVolume(CurrentVolumePath());
819
820   Int_t detElemId = 0;
821   if (detElement) detElemId = detElement->GetUniqueID(); 
822  
823   if (!detElemId) {
824     cerr << "Chamber id: "
825          << setw(3) << iChamber << "  "
826          << "Current SV: " 
827          <<  CurrentVolumePath() 
828          << "  detElemId: "
829          << setw(5) << detElemId 
830          << endl;
831     Double_t x, y, z;
832     gMC->TrackPosition(x, y, z);           
833     cerr << "   global position: "
834          << x << ", " << y << ", " << z
835          << endl;
836     AliError("DetElemId not identified.");
837   }  
838   vol[0] = detElemId;
839     
840   //
841   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
842   gMC->TrackPosition(pos);
843   gMC->TrackMomentum(mom);
844
845   ipart  = gMC->TrackPid();
846
847   //
848   // momentum loss and steplength in last step
849   destep = gMC->Edep();
850   step   = gMC->TrackStep();
851   // cout<<"------------"<<step<<endl;
852   //
853   // record hits when track enters ...
854   if( gMC->IsTrackEntering()) {
855
856       gMC->SetMaxStep(fMaxStepGas);
857       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
858       Double_t rt = TMath::Sqrt(tc);
859       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
860       Double_t tx = mom[0]/pmom;
861       Double_t ty = mom[1]/pmom;
862       Double_t tz = mom[2]/pmom;
863       Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
864           ->ResponseModel()
865           ->Pitch()/tz;
866       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
867       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
868       hits[0] = Float_t(ipart);         // Geant3 particle type
869       hits[1] = pos[0]+s*tx;            // X-position for hit
870       hits[2] = pos[1]+s*ty;            // Y-position for hit
871       hits[3] = pos[2]+s*tz;            // Z-position for hit
872       hits[4] = theta;                  // theta angle of incidence
873       hits[5] = phi;                    // phi angle of incidence 
874       hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
875       hits[9] = -1;                     // last pad hit
876       hits[10] = mom[3];                // hit momentum P
877       hits[11] = mom[0];                // Px
878       hits[12] = mom[1];                // Py
879       hits[13] = mom[2];                // Pz
880       tof=gMC->TrackTime();
881       hits[14] = tof;                   // Time of flight
882       tlength  = 0;
883       eloss    = 0;
884       eloss2   = 0;
885       sstep=0;
886       xhit     = pos[0];
887       yhit     = pos[1];      
888       zhit     = pos[2];      
889       Chamber(idvol).ChargeCorrelationInit();
890       // Only if not trigger chamber
891
892 //       printf("---------------------------\n");
893 //       printf(">>>> Y =  %f \n",hits[2]);
894 //       printf("---------------------------\n");
895     
896       
897
898      //  if(idvol < AliMUONConstants::NTrackingCh()) {
899 //        //
900 //        //  Initialize hit position (cursor) in the segmentation model 
901 //        ((AliMUONChamber*) (*fChambers)[idvol])
902 //            ->SigGenInit(pos[0], pos[1], pos[2]);
903 //       } else {
904 //        //geant3->Gpcxyz();
905 //        //printf("In the Trigger Chamber #%d\n",idvol-9);
906 //       }
907   }
908   eloss2+=destep;
909   sstep+=step;
910
911   // cout<<sstep<<endl;
912
913   // 
914   // Calculate the charge induced on a pad (disintegration) in case 
915   //
916   // Mip left chamber ...
917   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
918       gMC->SetMaxStep(kBig);
919       eloss   += destep;
920       tlength += step;
921       
922       Float_t x0,y0,z0;
923       Float_t localPos[3];
924       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
925       gMC->Gmtod(globalPos,localPos,1); 
926
927       if(idvol < AliMUONConstants::NTrackingCh()) {
928 // tracking chambers
929           x0 = 0.5*(xhit+pos[0]);
930           y0 = 0.5*(yhit+pos[1]);
931           z0 = 0.5*(zhit+pos[2]);
932       } else {
933 // trigger chambers
934           x0 = xhit;
935           y0 = yhit;
936           z0 = 0.;
937       }
938       
939
940       //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
941       
942           
943       hits[6] = tlength;   // track length
944       hits[7] = eloss2;    // de/dx energy loss
945
946
947       //      if (fNPadHits > (Int_t)hits[8]) {
948       //          hits[8] = hits[8]+1;
949       //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
950       //}
951 //
952 //    new hit 
953       
954       new(lhits[fNhits++]) 
955           AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits,
956                      true);
957       eloss = 0; 
958       //
959       // Check additional signal generation conditions 
960       // defined by the segmentation
961       // model (boundary crossing conditions)
962       // only for tracking chambers
963   } else if 
964       ((idvol < AliMUONConstants::NTrackingCh()) &&
965        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
966   {
967       ((AliMUONChamber*) (*fChambers)[idvol])
968           ->SigGenInit(pos[0], pos[1], pos[2]);
969       
970       Float_t localPos[3];
971       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
972       gMC->Gmtod(globalPos,localPos,1); 
973
974       eloss    += destep;
975
976       // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
977       //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
978       xhit     = pos[0];
979       yhit     = pos[1]; 
980       zhit     = pos[2];
981       eloss = 0;
982       tlength += step ;
983       //
984       // nothing special  happened, add up energy loss
985   } else {        
986       eloss   += destep;
987       tlength += step ;
988   }
989 }