]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONv1.cxx
Code revision:
[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 <TGeoMatrix.h>
27 #include <TVirtualMC.h>
28
29 #include "AliMUONv1.h"
30 #include "AliConst.h" 
31 #include "AliMUONChamber.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONFactory.h"
34 #include "AliMUONHit.h"
35 #include "AliMUONTriggerCircuit.h"
36 #include "AliMUONVGeometryBuilder.h"    
37 #include "AliMUONChamberGeometry.h"     
38 #include "AliMUONGeometryEnvelope.h"    
39 #include "AliMUONGeometryConstituent.h" 
40 #include "AliMagF.h"
41 #include "AliRun.h"
42 #include "AliMC.h"
43
44 ClassImp(AliMUONv1)
45  
46 //___________________________________________
47 AliMUONv1::AliMUONv1() 
48   : AliMUON(),
49     fTrackMomentum(), fTrackPosition(),fGlobalTransformation(0) 
50 {
51 // Constructor
52     fChambers   = 0;
53     fStepManagerVersionOld  = kFALSE;
54     fAngleEffect = kTRUE;
55     fStepMaxInActiveGas     = 0.6;
56     fStepSum    =  0x0;
57     fDestepSum  =  0x0;
58     fElossRatio =  0x0;
59     fAngleEffect10   = 0x0;
60     fAngleEffectNorma= 0x0;
61
62 //___________________________________________
63 AliMUONv1::AliMUONv1(const char *name, const char *title)
64   : AliMUON(name,title), fTrackMomentum(), fTrackPosition()
65 {
66 // Constructor
67     // By default include all stations
68     AliMUONFactory factory;
69     factory.Build(this, title);
70
71     fStepManagerVersionOld = kFALSE;
72     fAngleEffect = kTRUE;
73     fStepMaxInActiveGas = 0.6;
74
75     fStepSum   = new Float_t [AliMUONConstants::NCh()];
76     fDestepSum = new Float_t [AliMUONConstants::NCh()];
77     for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
78       fStepSum[i] =0.0;
79       fDestepSum[i]=0.0;
80     }
81     // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
82     fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.); 
83     fElossRatio->SetParameter(0,1.02138);
84     fElossRatio->SetParameter(1,-9.54149e-02);
85     fElossRatio->SetParameter(2,+7.83433e-02); 
86     fElossRatio->SetParameter(3,-9.98208e-03);
87     fElossRatio->SetParameter(4,+3.83279e-04);
88
89     // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
90     fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
91     fAngleEffect10->SetParameter(0, 1.90691e+02);
92     fAngleEffect10->SetParameter(1,-6.62258e+01);
93     fAngleEffect10->SetParameter(2,+1.28247e+01);
94     // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)  
95     // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
96     fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
97     fAngleEffectNorma->SetParameter(0,4.148);
98     fAngleEffectNorma->SetParameter(1,-6.809e-01);
99     fAngleEffectNorma->SetParameter(2,5.151e-02);
100     fAngleEffectNorma->SetParameter(3,-1.490e-03);
101
102     // Define the global transformation:
103     // Transformation from the old ALICE coordinate system to a new one:
104     // x->-x, z->-z 
105     TGeoRotation* rotGlobal 
106       = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
107     fGlobalTransformation = new TGeoCombiTrans(0., 0., 0., rotGlobal);
108 }
109
110 //_____________________________________________________________________________
111 AliMUONv1::AliMUONv1(const AliMUONv1& right) 
112   : AliMUON(right) 
113 {  
114   // copy constructor (not implemented)
115
116   Fatal("AliMUONv1", "Copy constructor not provided.");
117 }
118
119 //___________________________________________
120 AliMUONv1::~AliMUONv1()
121 {
122 // Destructor
123
124   delete fGlobalTransformation;
125 }
126
127 //_____________________________________________________________________________
128 AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
129 {
130   // assignement operator (not implemented)
131
132   // check assignement to self
133   if (this == &right) return *this;
134
135   Fatal("operator =", "Assignement operator not provided.");
136     
137   return *this;  
138 }    
139
140 //__________________________________________________
141 void AliMUONv1::CreateGeometry()
142 {
143 //
144 // Construct geometry using geometry builders.
145 //
146
147   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
148
149     // Get the builder
150     AliMUONVGeometryBuilder* builder
151       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
152
153     // Create geometry with each builder
154     if (builder) {
155       builder->CreateGeometry();
156       builder->SetTransformations();
157     }
158   }
159
160   for (Int_t j=0; j<AliMUONConstants::NCh(); j++) {
161
162     AliMUONChamberGeometry* geometry = Chamber(j).GetGeometry();
163
164     if (!geometry) continue;
165           // Skip chambers with not defined geometry  
166           
167     // Loop over envelopes
168     const TObjArray* kEnvelopes = geometry->GetEnvelopes();
169     for (Int_t k=0; k<kEnvelopes->GetEntriesFast(); k++) {
170
171       // Get envelope
172       AliMUONGeometryEnvelope* env = (AliMUONGeometryEnvelope*)kEnvelopes->At(k);
173       const TGeoCombiTrans* kEnvTrans = env->GetTransformation();
174       const char* only = "ONLY";
175       if (env->IsMANY()) only = "MANY";
176
177       if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
178         // virtual envelope + nof constituents = 0 
179         //         => not allowed;
180         //            empty virtual envelope has no sense 
181         Fatal("CreateGeometry", "Virtual envelope must have constituents.");
182         return;
183       }
184
185       if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
186         // non virtual envelope + nof constituents > 0 
187         //        => not allowed;
188         //           use VMC to place constituents
189         Fatal("CreateGeometry", "Non virtual envelope cannot have constituents.");
190         return;
191       }
192
193       if (!env->IsVirtual() && env->GetConstituents()->GetEntriesFast() == 0 ) {
194         // non virtual envelope + nof constituents = 0 
195         //        => place envelope in ALICE by composed transformation:
196         //           Tglobal * Tch * Tenv
197
198         // Compound chamber transformation with the envelope one
199         TGeoHMatrix total 
200           = (*fGlobalTransformation) * 
201             (*geometry->GetTransformation()) * 
202             (*kEnvTrans);
203         PlaceVolume(env->GetName(), geometry->GetMotherVolume(),
204                     env->GetCopyNo(), total, 0, 0, only);
205       }
206
207       if (env->IsVirtual() && env->GetConstituents()->GetEntriesFast() > 0 ) {
208         // virtual envelope + nof constituents > 0 
209         //         => do not place envelope and place constituents
210         //            in ALICE by composed transformation:
211         //            Tglobal * Tch * Tenv * Tconst   
212
213         for  (Int_t l=0; l<env->GetConstituents()->GetEntriesFast(); l++) {
214           AliMUONGeometryConstituent* constituent
215             = (AliMUONGeometryConstituent*)env->GetConstituents()->At(l);
216
217           // Compound chamber transformation with the envelope one + the constituent one
218           TGeoHMatrix total 
219             = (*fGlobalTransformation) *
220               (*geometry->GetTransformation()) * 
221               (*kEnvTrans) * 
222               (*constituent->GetTransformation());
223
224           PlaceVolume(constituent->GetName(), geometry->GetMotherVolume(),
225                       constituent->GetCopyNo(), total,
226                       constituent->GetNpar(), constituent->GetParam(), only);
227         }
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 /*
241   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
242     if (volId==((AliMUONChamber*)(*fChambers)[i-1])->GetGid()) return i;
243 */
244   for (Int_t i = 1; i <= AliMUONConstants::NCh(); i++)
245     if ( ((AliMUONChamber*)(*fChambers)[i-1])->IsSensId(volId) ) return i;
246
247   return 0;
248 }
249 //________________________________________________________________
250 void AliMUONv1::CreateMaterials()
251 {
252
253   // *** DEFINITION OF AVAILABLE MUON MATERIALS *** 
254   //
255   //     Ar-CO2 gas (80%+20%)
256     Float_t ag1[3]   = { 39.95,12.01,16. };
257     Float_t zg1[3]   = { 18.,6.,8. };
258     Float_t wg1[3]   = { .8,.0667,.13333 };
259     Float_t dg1      = .001821;
260     //
261     //     Ar-buthane-freon gas -- trigger chambers 
262     Float_t atr1[4]  = { 39.95,12.01,1.01,19. };
263     Float_t ztr1[4]  = { 18.,6.,1.,9. };
264     Float_t wtr1[4]  = { .56,.1262857,.2857143,.028 };
265     Float_t dtr1     = .002599;
266     //
267     //     Ar-CO2 gas 
268     Float_t agas[3]  = { 39.95,12.01,16. };
269     Float_t zgas[3]  = { 18.,6.,8. };
270     Float_t wgas[3]  = { .74,.086684,.173316 };
271     Float_t dgas     = .0018327;
272     //
273     //     Ar-Isobutane gas (80%+20%) -- tracking 
274     Float_t ag[3]    = { 39.95,12.01,1.01 };
275     Float_t zg[3]    = { 18.,6.,1. };
276     Float_t wg[3]    = { .8,.057,.143 };
277     Float_t dg       = .0019596;
278     //
279     //     Ar-Isobutane-Forane-SF6 gas (49%+7%+40%+4%) -- trigger 
280     Float_t atrig[5] = { 39.95,12.01,1.01,19.,32.066 };
281     Float_t ztrig[5] = { 18.,6.,1.,9.,16. };
282     Float_t wtrig[5] = { .49,1.08,1.5,1.84,0.04 };
283     Float_t dtrig    = .0031463;
284     //
285     //     bakelite 
286
287     Float_t abak[3] = {12.01 , 1.01 , 16.};
288     Float_t zbak[3] = {6.     , 1.   , 8.};
289     Float_t wbak[3] = {6.     , 6.   , 1.}; 
290     Float_t dbak = 1.4;
291
292     Float_t epsil, stmin, deemax, tmaxfd, stemax;
293
294     Int_t iSXFLD   = gAlice->Field()->Integ();
295     Float_t sXMGMX = gAlice->Field()->Max();
296     //
297     // --- Define the various materials for GEANT --- 
298     AliMaterial(9, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
299     AliMaterial(10, "ALUMINIUM$", 26.98, 13., 2.7, 8.9, 37.2);
300     AliMaterial(15, "AIR$      ", 14.61, 7.3, .001205, 30423.24, 67500);
301     AliMixture(19, "Bakelite$", abak, zbak, dbak, -3, wbak);
302     AliMixture(20, "ArC4H10 GAS$", ag, zg, dg, 3, wg);
303     AliMixture(21, "TRIG GAS$", atrig, ztrig, dtrig, -5, wtrig);
304     AliMixture(22, "ArCO2 80%$", ag1, zg1, dg1, 3, wg1);
305     AliMixture(23, "Ar-freon $", atr1, ztr1, dtr1, 4, wtr1);
306     AliMixture(24, "ArCO2 GAS$", agas, zgas, dgas, 3, wgas);
307     // materials for slat: 
308     //     Sensitive area: gas (already defined) 
309     //     PCB: copper 
310     //     insulating material and frame: vetronite
311     //     walls: carbon, rohacell, carbon 
312   Float_t aglass[5]={12.01, 28.09, 16.,   10.8,  23.};
313   Float_t zglass[5]={ 6.,   14.,    8.,    5.,   11.};
314   Float_t wglass[5]={ 0.5,  0.105, 0.355, 0.03,  0.01};
315   Float_t dglass=1.74;
316
317   // rohacell: C9 H13 N1 O2
318   Float_t arohac[4] = {12.01,  1.01, 14.010, 16.};
319   Float_t zrohac[4] = { 6.,    1.,    7.,     8.};
320   Float_t wrohac[4] = { 9.,   13.,    1.,     2.};
321   Float_t drohac    = 0.03;
322
323   AliMaterial(31, "COPPER$",   63.54,    29.,   8.96,  1.4, 0.);
324   AliMixture(32, "Vetronite$",aglass, zglass, dglass,    5, wglass);
325   AliMaterial(33, "Carbon$",   12.01,     6.,  2.265, 18.8, 49.9);
326   AliMixture(34, "Rohacell$", arohac, zrohac, drohac,   -4, wrohac); 
327
328
329     epsil  = .001; // Tracking precision, 
330     stemax = -1.;  // Maximum displacement for multiple scat 
331     tmaxfd = -20.; // Maximum angle due to field deflection 
332     deemax = -.3;  // Maximum fractional energy loss, DLS 
333     stmin  = -.8;
334     //
335     //    Air 
336     AliMedium(1, "AIR_CH_US         ", 15, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
337     //
338     //    Aluminum 
339
340     AliMedium(4, "ALU_CH_US          ", 9, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
341             fMaxDestepAlu, epsil, stmin);
342     AliMedium(5, "ALU_CH_US          ", 10, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
343             fMaxDestepAlu, epsil, stmin);
344     //
345     //    Ar-isoC4H10 gas 
346
347     AliMedium(6, "AR_CH_US          ", 20, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
348             fMaxDestepGas, epsil, stmin);
349 //
350     //    Ar-Isobuthane-Forane-SF6 gas 
351
352     AliMedium(7, "GAS_CH_TRIGGER    ", 21, 1, iSXFLD, sXMGMX, tmaxfd, stemax, deemax, epsil, stmin);
353
354     AliMedium(8, "BAKE_CH_TRIGGER   ", 19, 0, iSXFLD, sXMGMX, tmaxfd, fMaxStepAlu, 
355             fMaxDestepAlu, epsil, stmin);
356
357     AliMedium(9, "ARG_CO2   ", 22, 1, iSXFLD, sXMGMX, tmaxfd, fMaxStepGas, 
358             fMaxDestepAlu, epsil, stmin);
359     // tracking media for slats: check the parameters!! 
360     AliMedium(11, "PCB_COPPER        ", 31, 0, iSXFLD, sXMGMX, tmaxfd, 
361               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
362     AliMedium(12, "VETRONITE         ", 32, 0, iSXFLD, sXMGMX, tmaxfd, 
363               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
364     AliMedium(13, "CARBON            ", 33, 0, iSXFLD, sXMGMX, tmaxfd, 
365               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
366     AliMedium(14, "Rohacell          ", 34, 0, iSXFLD, sXMGMX, tmaxfd, 
367               fMaxStepAlu, fMaxDestepAlu, epsil, stmin);
368
369
370
371   //.Materials specific to stations
372   // created via builders
373   
374   for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
375
376     // Get the builder
377     AliMUONVGeometryBuilder* builder
378       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
379
380     // Create materials with each builder
381     if (builder) builder->CreateMaterials();
382   }
383 }
384
385 //______________________________________________________________________________
386 void AliMUONv1::PlaceVolume(const TString& name, const TString& mName, 
387                             Int_t copyNo, const TGeoHMatrix& matrix, 
388                             Int_t npar, Double_t* param, const char* only) const
389 {
390 // Place the volume specified by name with the given transformation matrix
391 // ---
392
393   // Do not apply global transformation 
394   // if mother volume == DDIP
395   // (as it is applied on this volume)
396   TGeoHMatrix transform(matrix);
397   if (mName == TString("DDIP")) {
398     transform = (*fGlobalTransformation) * transform;
399                // To be changed to (*fGlobalTransformation).inverse()
400                // when available in TGeo
401                // To make this correct also for a general case when
402                // (*fGlobalTransformation) * *fGlobalTransformation) != 1
403   }            
404      
405   // Decompose transformation
406   const Double_t* xyz = transform.GetTranslation();
407   const Double_t* rm = transform.GetRotationMatrix();
408         
409   //cout << "Got translation: "
410   //     << xyz[0] << " " << xyz[1] << " " << xyz[2] << endl;
411         
412   //cout << "Got rotation: "
413   //     << rm[0] << " " << rm[1] << " " << rm[2] << endl
414   //     << rm[3] << " " << rm[4] << " " << rm[5] << endl
415   //     << rm[6] << " " << rm[7] << " " << rm[8] << endl;
416
417   // Check for presence of rotation
418   // (will be nice to be available in TGeo)
419   const Double_t kTolerance = 1e-04;
420   Bool_t isRotation = true; 
421   if (TMath::Abs(rm[0] - 1.) < kTolerance &&
422       TMath::Abs(rm[1] - 0.) < kTolerance &&
423       TMath::Abs(rm[2] - 0.) < kTolerance &&
424       TMath::Abs(rm[3] - 0.) < kTolerance &&
425       TMath::Abs(rm[4] - 1.) < kTolerance &&
426       TMath::Abs(rm[5] - 0.) < kTolerance &&
427       TMath::Abs(rm[6] - 0.) < kTolerance &&
428       TMath::Abs(rm[7] - 0.) < kTolerance &&
429       TMath::Abs(rm[8] - 1.) < kTolerance) isRotation = false; 
430
431   Int_t krot = 0;
432   if (isRotation) {
433     TGeoRotation rot;
434     rot.SetMatrix(const_cast<Double_t*>(transform.GetRotationMatrix()));
435     Double_t theta1, phi1, theta2, phi2, theta3, phi3;
436     rot.GetAngles(theta1, phi1, theta2, phi2, theta3, phi3);
437         
438     //cout << "angles: " 
439     //     << theta1 << " " << phi1 << " "
440     //     << theta2 << " " << phi2 << " "
441     //     << theta3 << " " << phi3 << endl;
442         
443     AliMatrix(krot, theta1, phi1, theta2, phi2, theta3, phi3);
444   }     
445         
446   // Place the volume in ALIC
447   if (npar == 0)
448     gMC->Gspos(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only);
449   else 
450     gMC->Gsposp(name, copyNo, mName, xyz[0], xyz[1], xyz[2] , krot, only,
451                 param, npar);
452
453
454
455 //___________________________________________
456 void AliMUONv1::Init()
457 {
458    // 
459    // Initialize Tracking Chambers
460    //
461
462    if(fDebug) printf("\n%s: Start Init for version 1 - CPC chamber type\n\n",ClassName());
463    Int_t i;
464    for (i=0; i<AliMUONConstants::NCh(); i++) {
465        ( (AliMUONChamber*) (*fChambers)[i])->Init();
466    }
467    
468    //
469    // Set the chamber (sensitive region) GEANT identifier
470    //
471    for (Int_t i=0; i<fGeometryBuilders->GetEntriesFast(); i++) {
472
473     // Get the builder
474     AliMUONVGeometryBuilder* builder
475       = (AliMUONVGeometryBuilder*)fGeometryBuilders->At(i);
476
477     // Set sesitive volumes with each builder
478     if (builder) builder->SetSensitiveVolumes();
479   }
480
481 /*
482    //
483    // Set the chamber (sensitive region) GEANT identifier
484    ((AliMUONChamber*)(*fChambers)[0])->SetGid(gMC->VolId("S01G"));
485    ((AliMUONChamber*)(*fChambers)[1])->SetGid(gMC->VolId("S02G"));
486
487    ((AliMUONChamber*)(*fChambers)[2])->SetGid(gMC->VolId("S03G"));
488    ((AliMUONChamber*)(*fChambers)[3])->SetGid(gMC->VolId("S04G"));
489
490    ((AliMUONChamber*)(*fChambers)[4])->SetGid(gMC->VolId("S05G"));
491    ((AliMUONChamber*)(*fChambers)[5])->SetGid(gMC->VolId("S06G"));
492
493    ((AliMUONChamber*)(*fChambers)[6])->SetGid(gMC->VolId("S07G"));
494    ((AliMUONChamber*)(*fChambers)[7])->SetGid(gMC->VolId("S08G"));
495
496    ((AliMUONChamber*)(*fChambers)[8])->SetGid(gMC->VolId("S09G"));
497    ((AliMUONChamber*)(*fChambers)[9])->SetGid(gMC->VolId("S10G"));
498
499    ((AliMUONChamber*)(*fChambers)[10])->SetGid(gMC->VolId("SG1A"));
500    ((AliMUONChamber*)(*fChambers)[11])->SetGid(gMC->VolId("SG2A"));
501    ((AliMUONChamber*)(*fChambers)[12])->SetGid(gMC->VolId("SG3A"));
502    ((AliMUONChamber*)(*fChambers)[13])->SetGid(gMC->VolId("SG4A"));
503 */
504    if(fDebug) printf("\n%s: Finished Init for version 1 - CPC chamber type\n",ClassName());
505
506    //cp 
507    if(fDebug) printf("\n%s: Start Init for Trigger Circuits\n",ClassName());
508    for (i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
509      ( (AliMUONTriggerCircuit*) (*fTriggerCircuits)[i])->Init(i);
510    }
511    if(fDebug) printf("%s: Finished Init for Trigger Circuits\n",ClassName());
512    //cp
513 }
514
515 //_______________________________________________________________________________
516 void AliMUONv1::StepManager()
517 {
518   // Stepmanager for the chambers
519
520  if (fStepManagerVersionOld) {
521     StepManagerOld();
522     return;
523   }
524
525   // Only charged tracks
526   if( !(gMC->TrackCharge()) ) return; 
527   // Only charged tracks
528   
529   // Only gas gap inside chamber
530   // Tag chambers and record hits when track enters 
531   static Int_t   idvol=-1;
532   Int_t   iChamber=0;
533   Int_t   id=0;
534   Int_t   copy;
535   const  Float_t kBig = 1.e10;
536
537
538   //
539   // Only gas gap inside chamber
540   // Tag chambers and record hits when track enters 
541   id=gMC->CurrentVolID(copy);
542   iChamber = GetChamberId(id);
543   idvol = iChamber -1;
544
545   if (idvol == -1) return;
546
547   // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
548   if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) )     
549     AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
550   
551    if( gMC->IsTrackEntering() ) {
552      Float_t theta = fTrackMomentum.Theta();
553      if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
554   }
555
556 //  if (GetDebug()) {
557 //     Float_t z = ( (AliMUONChamber*)(*fChambers)[idvol])->Z() ;
558 //      Info("StepManager Step","Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber, z);
559 //   }  
560   // Particule id and mass, 
561   Int_t     ipart = gMC->TrackPid();
562   Float_t   mass  = gMC->TrackMass();
563
564   fDestepSum[idvol]+=gMC->Edep();
565   // Get current particle id (ipart), track position (pos)  and momentum (mom)
566   if ( fStepSum[idvol]==0.0 )  gMC->TrackMomentum(fTrackMomentum);
567   fStepSum[idvol]+=gMC->TrackStep();
568   
569 //   if (GetDebug()) {
570 //     Info("StepManager Step","iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
571 //       iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg, mass, fStepSum[idvol], gMC->Edep());
572 //     Info("StepManager Step","Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(), fTrackMomentum.Z()) ;
573 //     gMC->TrackPosition(fTrackPosition);
574 //     Info("StepManager Step","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
575 //   }
576
577   // Track left chamber or StepSum larger than fStepMaxInActiveGas
578   if ( gMC->IsTrackExiting() || 
579        gMC->IsTrackStop() || 
580        gMC->IsTrackDisappeared()||
581        (fStepSum[idvol]>fStepMaxInActiveGas) ) {
582     
583     if   ( gMC->IsTrackExiting() || 
584            gMC->IsTrackStop() || 
585            gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
586
587     gMC->TrackPosition(fTrackPosition);
588     Float_t theta = fTrackMomentum.Theta();
589     Float_t phi   = fTrackMomentum.Phi();
590     
591     TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
592                                fStepSum[idvol]/2.*sin(theta)*sin(phi),
593                                fStepSum[idvol]/2.*cos(theta),0.0       );
594     //     if (GetDebug()) 
595     //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
596     //     if (GetDebug()) 
597     //        Info("StepManager Exit ","Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z()) ;
598     fTrackPosition-=backToWire;
599     
600     //-------------- Angle effect 
601     // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
602     
603     Float_t betaxGamma    = fTrackMomentum.P()/mass;//  pc/mc2
604     Float_t sigmaEffect10degrees;
605     Float_t sigmaEffectThetadegrees;
606     Float_t eLossParticleELossMip;
607     Float_t yAngleEffect=0.;
608     Float_t thetawires      =  TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
609
610
611     if (fAngleEffect){
612     if ( (betaxGamma >3.2)   &&  (thetawires*kRaddeg<=15.) ) {
613       betaxGamma=TMath::Log(betaxGamma);
614       eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
615       // 10 degrees is a reference for a model (arbitrary)
616       sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
617       // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
618       sigmaEffectThetadegrees =  sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg);  // For 5mm gap  
619       if ( (iChamber==1)  ||  (iChamber==2) )  
620         sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
621       yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
622     }
623     }
624     
625     // One hit per chamber
626     GetMUONData()->AddHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), iChamber, ipart, 
627                           fTrackPosition.X(), fTrackPosition.Y()+yAngleEffect, fTrackPosition.Z(), 0.0, 
628                           fTrackMomentum.P(),theta, phi, fStepSum[idvol], fDestepSum[idvol],
629                           fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z());
630 //     if (GetDebug()){
631 //       Info("StepManager Exit","Particle exiting from chamber %d",iChamber);
632 //       Info("StepManager Exit","StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]);
633 //       Info("StepManager Exit","Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
634 //     }
635     fStepSum[idvol]  =0; // Reset for the next event
636     fDestepSum[idvol]=0; // Reset for the next event
637   }
638 }
639
640 //__________________________________________
641 void AliMUONv1::StepManagerOld()
642 {
643   // Old Stepmanager for the chambers
644   Int_t          copy, id;
645   static Int_t   idvol =-1;
646   static Int_t   vol[2];
647   Int_t          ipart;
648   TLorentzVector pos;
649   TLorentzVector mom;
650   Float_t        theta,phi;
651   Float_t        destep, step;
652   
653   static Float_t sstep;
654   static Float_t eloss, eloss2, xhit, yhit, zhit, tof, tlength;
655   const  Float_t kBig = 1.e10;
656   static Float_t hits[15];
657
658   TClonesArray &lhits = *fHits;
659
660   //
661   //
662   // Only charged tracks
663   if( !(gMC->TrackCharge()) ) return; 
664   //
665   // Only gas gap inside chamber
666   // Tag chambers and record hits when track enters 
667   id=gMC->CurrentVolID(copy);
668   vol[0] = GetChamberId(id);
669   idvol = vol[0] -1;
670
671   if (idvol == -1) return;
672
673   //
674   // Get current particle id (ipart), track position (pos)  and momentum (mom) 
675   gMC->TrackPosition(pos);
676   gMC->TrackMomentum(mom);
677
678   ipart  = gMC->TrackPid();
679
680   //
681   // momentum loss and steplength in last step
682   destep = gMC->Edep();
683   step   = gMC->TrackStep();
684   // cout<<"------------"<<step<<endl;
685   //
686   // record hits when track enters ...
687   if( gMC->IsTrackEntering()) {
688
689       gMC->SetMaxStep(fMaxStepGas);
690       Double_t tc = mom[0]*mom[0]+mom[1]*mom[1];
691       Double_t rt = TMath::Sqrt(tc);
692       Double_t pmom = TMath::Sqrt(tc+mom[2]*mom[2]);
693       Double_t tx = mom[0]/pmom;
694       Double_t ty = mom[1]/pmom;
695       Double_t tz = mom[2]/pmom;
696       Double_t s  = ((AliMUONChamber*)(*fChambers)[idvol])
697           ->ResponseModel()
698           ->Pitch()/tz;
699       theta   = Float_t(TMath::ATan2(rt,Double_t(mom[2])))*kRaddeg;
700       phi     = Float_t(TMath::ATan2(Double_t(mom[1]),Double_t(mom[0])))*kRaddeg;
701       hits[0] = Float_t(ipart);         // Geant3 particle type
702       hits[1] = pos[0]+s*tx;            // X-position for hit
703       hits[2] = pos[1]+s*ty;            // Y-position for hit
704       hits[3] = pos[2]+s*tz;            // Z-position for hit
705       hits[4] = theta;                  // theta angle of incidence
706       hits[5] = phi;                    // phi angle of incidence 
707       hits[8] = 0;//PadHits does not exist anymore  (Float_t) fNPadHits;    // first padhit
708       hits[9] = -1;                     // last pad hit
709       hits[10] = mom[3];                // hit momentum P
710       hits[11] = mom[0];                // Px
711       hits[12] = mom[1];                // Py
712       hits[13] = mom[2];                // Pz
713       tof=gMC->TrackTime();
714       hits[14] = tof;                   // Time of flight
715       tlength  = 0;
716       eloss    = 0;
717       eloss2   = 0;
718       sstep=0;
719       xhit     = pos[0];
720       yhit     = pos[1];      
721       zhit     = pos[2];      
722       Chamber(idvol).ChargeCorrelationInit();
723       // Only if not trigger chamber
724
725 //       printf("---------------------------\n");
726 //       printf(">>>> Y =  %f \n",hits[2]);
727 //       printf("---------------------------\n");
728     
729       
730
731      //  if(idvol < AliMUONConstants::NTrackingCh()) {
732 //        //
733 //        //  Initialize hit position (cursor) in the segmentation model 
734 //        ((AliMUONChamber*) (*fChambers)[idvol])
735 //            ->SigGenInit(pos[0], pos[1], pos[2]);
736 //       } else {
737 //        //geant3->Gpcxyz();
738 //        //printf("In the Trigger Chamber #%d\n",idvol-9);
739 //       }
740   }
741   eloss2+=destep;
742   sstep+=step;
743
744   // cout<<sstep<<endl;
745
746   // 
747   // Calculate the charge induced on a pad (disintegration) in case 
748   //
749   // Mip left chamber ...
750   if( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()){
751       gMC->SetMaxStep(kBig);
752       eloss   += destep;
753       tlength += step;
754       
755       Float_t x0,y0,z0;
756       Float_t localPos[3];
757       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
758       gMC->Gmtod(globalPos,localPos,1); 
759
760       if(idvol < AliMUONConstants::NTrackingCh()) {
761 // tracking chambers
762           x0 = 0.5*(xhit+pos[0]);
763           y0 = 0.5*(yhit+pos[1]);
764           z0 = 0.5*(zhit+pos[2]);
765       } else {
766 // trigger chambers
767           x0 = xhit;
768           y0 = yhit;
769           z0 = 0.;
770       }
771       
772
773       //      if (eloss >0)  MakePadHits(x0,y0,z0,eloss,tof,idvol);
774       
775           
776       hits[6] = tlength;   // track length
777       hits[7] = eloss2;    // de/dx energy loss
778
779
780       //      if (fNPadHits > (Int_t)hits[8]) {
781       //          hits[8] = hits[8]+1;
782       //          hits[9] = 0: // PadHits does not exist anymore (Float_t) fNPadHits;
783       //}
784 //
785 //    new hit 
786       
787       new(lhits[fNhits++]) 
788           AliMUONHit(fIshunt, gAlice->GetMCApp()->GetCurrentTrackNumber(), vol,hits);
789       eloss = 0; 
790       //
791       // Check additional signal generation conditions 
792       // defined by the segmentation
793       // model (boundary crossing conditions)
794       // only for tracking chambers
795   } else if 
796       ((idvol < AliMUONConstants::NTrackingCh()) &&
797        ((AliMUONChamber*) (*fChambers)[idvol])->SigGenCond(pos[0], pos[1], pos[2]))
798   {
799       ((AliMUONChamber*) (*fChambers)[idvol])
800           ->SigGenInit(pos[0], pos[1], pos[2]);
801       
802       Float_t localPos[3];
803       Float_t globalPos[3] = {pos[0], pos[1], pos[2]};
804       gMC->Gmtod(globalPos,localPos,1); 
805
806       eloss    += destep;
807
808       // if (eloss > 0 && idvol < AliMUONConstants::NTrackingCh())
809       //        MakePadHits(0.5*(xhit+pos[0]),0.5*(yhit+pos[1]),pos[2],eloss,tof,idvol);
810       xhit     = pos[0];
811       yhit     = pos[1]; 
812       zhit     = pos[2];
813       eloss = 0;
814       tlength += step ;
815       //
816       // nothing special  happened, add up energy loss
817   } else {        
818       eloss   += destep;
819       tlength += step ;
820   }
821 }