]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSvFast.cxx
coding convention
[u/mrichter/AliRoot.git] / PHOS / AliPHOSvFast.cxx
1   /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
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 purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 // Implementation of the PHOS manager class for fast simulations     
20 // Tracks particles until the reach a grossly designed PHOS module
21 // Modify the particles property (momentum, energy, type) according to
22 //  the PHOS response function. The result is called a virtual reconstructed
23 //  particle.                
24 //
25 //*-- Author: Yves Schutz (SUBATECH)
26
27 // --- ROOT system ---
28  
29 #include <TBRIK.h>
30 #include <TGeometry.h>
31 #include <TNode.h>
32 #include <TParticle.h>
33 #include "TClonesArray.h" 
34 #include <TVirtualMC.h>
35
36 // --- Standard library ---
37
38 // --- AliRoot header files ---
39 #include "AliPHOSFastRecParticle.h"
40 #include "AliPHOSGeometry.h"
41 #include "AliPHOSLoader.h"
42 #include "AliPHOSvFast.h"
43 #include "AliRun.h"
44
45 ClassImp(AliPHOSvFast)
46
47 //____________________________________________________________________________
48 AliPHOSvFast::AliPHOSvFast() : AliPHOS()
49 {
50   // default ctor : initialize data member
51    fBigBoxX = 0. ;                      
52    fBigBoxY = 0. ;                      
53    fBigBoxZ = 0. ;                       
54    fFastRecParticles = 0 ;        
55    fNRecParticles = 0 ;                
56    fRan = 0 ;                            
57    fResPara1 = 0. ;                       
58    fResPara2 = 0. ;                        
59    fResPara3 = 0. ;                      
60    fPosParaA0 = 0. ;                      
61    fPosParaA1 = 0. ;
62    fPosParaB0 = 0. ;     
63    fPosParaB1 = 0. ;    
64    fPosParaB2 = 0. ;    
65
66 }
67
68 //____________________________________________________________________________
69 AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
70   AliPHOS(name,title)
71 {
72   // ctor
73
74   
75   // create the Loader 
76   
77   SetBigBox(0, GetGeometry()->GetOuterBoxSize(0) ) ;
78   SetBigBox(1, GetGeometry()->GetOuterBoxSize(3) + GetGeometry()->GetCPVBoxSize(1) ) ; 
79   SetBigBox(2, GetGeometry()->GetOuterBoxSize(2) ); 
80   
81   fNRecParticles = 0 ; 
82   fFastRecParticles = new AliPHOSFastRecParticle::FastRecParticlesList("AliPHOSFastRecParticle", 100) ;
83   
84   fResPara1 = 0.030 ;    // GeV
85   fResPara2 = 0.00003 ; 
86   fResPara3 = 0.00001 ; 
87   
88   fPosParaA0 = 2.87 ;    // mm
89   fPosParaA1 = -0.0975 ;  
90   fPosParaB0 = 0.257 ;   
91   fPosParaB1 = 0.137 ; 
92   fPosParaB2 = 0.00619 ; 
93 }
94
95 //____________________________________________________________________________
96 AliPHOSvFast::~AliPHOSvFast()
97 {
98   // dtor
99  
100   fFastRecParticles->Delete() ; 
101   delete fFastRecParticles ;
102   fFastRecParticles = 0 ; 
103
104 }
105
106 //____________________________________________________________________________
107 void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
108 {  
109   // Add a virtually reconstructed particle to the list 
110
111   new( (*fFastRecParticles)[fNRecParticles] ) AliPHOSFastRecParticle(rp) ;
112   fNRecParticles++ ; 
113 }
114
115 //____________________________________________________________________________
116 void AliPHOSvFast::BuildGeometry()
117 {
118   // Build the PHOS geometry for the ROOT display
119    //BEGIN_HTML
120   /*
121     <H2>
122      PHOS FAST in ALICE displayed by root
123     </H2>
124     <H4> All Views </H4>
125     <P>
126     <CENTER>
127     <IMG Align=BOTTOM ALT="Fast All Views" SRC="../images/AliPHOSvFastAllViews.gif"> 
128     </CENTER></P>
129     <H4> Front View </H4>
130     <P>
131     <CENTER>
132     <IMG Align=BOTTOM ALT="Fast Front View" SRC="../images/AliPHOSvFastFrontView.gif"> 
133     </CENTER></P>
134   */
135   //END_HTML  
136  
137   const Int_t kColorPHOS = kRed ;
138   
139   Double_t const kRADDEG = 180.0 / TMath::Pi() ;
140   
141   new TBRIK( "BigBox", "PHOS box", "void", GetBigBox(0)/2, 
142              GetBigBox(1)/2, 
143              GetBigBox(2)/2 );
144   
145   // position PHOS into ALICE
146
147   Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
148   Int_t number = 988 ; 
149   Float_t pphi =  TMath::ATan( GetBigBox(0)  / ( 2.0 * GetGeometry()->GetIPtoCrystalSurface() ) ) ;
150   pphi *= kRADDEG ;
151   TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
152  
153   char * nodename = new char[20] ;  
154   char * rotname  = new char[20] ; 
155
156   for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) { 
157    Float_t angle = pphi * 2 * ( i - GetGeometry()->GetNModules() / 2.0 - 0.5 ) ;
158    sprintf(rotname, "%s%d", "rot", number++) ;
159    new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
160    top->cd();
161    sprintf(nodename,"%s%d", "Module", i) ;    
162    Float_t x =  r * TMath::Sin( angle / kRADDEG ) ;
163    Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
164    TNode * bigboxnode = new TNode(nodename, nodename, "BigBox", x, y, 0, rotname ) ;
165    bigboxnode->SetLineColor(kColorPHOS) ;
166    fNodes->Add(bigboxnode) ;
167   }
168   delete[] nodename ; 
169   delete[] rotname ; 
170 }
171
172 //____________________________________________________________________________
173 void AliPHOSvFast::CreateGeometry()
174 {
175   // Create the geometry for GEANT
176   
177   AliPHOSvFast *phostmp = (AliPHOSvFast*)gAlice->GetModule("PHOS") ;
178   
179   if ( phostmp == NULL ) {
180     
181     fprintf(stderr, "PHOS detector not found!\n") ;
182     return ;
183     
184   }
185
186   // Get pointer to the array containing media indeces
187   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
188   
189   Float_t bigbox[3] ; 
190   bigbox[0] =   GetBigBox(0) / 2.0 ;
191   bigbox[1] =   GetBigBox(1) / 2.0 ;
192   bigbox[2] =   GetBigBox(2) / 2.0 ;
193   
194   gMC->Gsvolu("PHOS", "BOX ", idtmed[798], bigbox, 3) ;
195   
196   // --- Position  PHOS mdules in ALICE setup ---
197   
198   Int_t idrotm[99] ;
199   Double_t const kRADDEG = 180.0 / TMath::Pi() ;
200   
201   for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) {
202     
203     Float_t angle = GetGeometry()->GetPHOSAngle(i) ;
204     AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
205  
206     Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
207
208     Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
209     Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
210     gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
211  
212   } // for GetNModules
213
214 }
215
216
217 //____________________________________________________________________________
218 void AliPHOSvFast::Init(void)
219 {
220   // Prints out an information message
221   
222   Int_t i;
223
224   printf("\n");
225   for(i=0;i<35;i++) printf("*");
226   printf(" FAST PHOS_INIT ");
227   for(i=0;i<35;i++) printf("*");
228   printf("\n");
229
230   // Here the PHOS initialisation code (if any!)
231
232   for(i=0;i<80;i++) printf("*");
233   printf("\n");
234   
235 }
236
237 //___________________________________________________________________________
238 Float_t AliPHOSvFast::GetBigBox(Int_t index) const
239 {
240   // Get the X, Y or Z dimension of the box describing a PHOS module
241   
242   Float_t rv = 0 ; 
243
244   switch (index) {
245   case 0:
246     rv = fBigBoxX ; 
247     break ; 
248   case 1:
249      rv = fBigBoxY ; 
250     break ; 
251   case 2:
252      rv = fBigBoxZ ; 
253     break ; 
254  }
255   return rv ; 
256 }
257 //___________________________________________________________________________
258
259 void AliPHOSvFast::MakeBranch(Option_t* opt)
260 {  
261   // Create new branch in the current reconstructed Root Tree
262   AliDetector::MakeBranch(opt);
263   const char *cd = strstr(opt,"R");
264   
265   if (fFastRecParticles && fLoader->TreeR() && cd) {
266     MakeBranchInTree(fLoader->TreeR(), GetName(), &fFastRecParticles, fBufferSize, 0);
267   }
268 }
269 //____________________________________________________________________________
270
271 Double_t AliPHOSvFast::MakeEnergy(const Double_t energy)
272 {  
273   // Smears the energy according to the energy dependent energy resolution.
274   // A gaussian distribution is assumed
275
276   Double_t sigma  = SigmaE(energy) ; 
277   return  fRan.Gaus(energy, sigma) ;   
278 }
279 //____________________________________________________________________________
280
281 TVector3 AliPHOSvFast::MakePosition(const Double_t energy, const TVector3 pos, const Double_t theta, const Double_t phi)
282 {
283   // Smears the impact position according to the energy dependent position resolution
284   // A gaussian position distribution is assumed
285
286   TVector3 newpos ;
287   Double_t sigma = SigmaP( energy, theta*180./TMath::Pi() ) ;
288   Double_t x = fRan.Gaus( pos.X(), sigma ) ;
289   sigma = SigmaP( energy, phi*180./TMath::Pi() ) ;
290   Double_t z = fRan.Gaus( pos.Z(), sigma ) ;
291   Double_t y = pos.Y() ; 
292   
293   newpos.SetX(x) ; 
294   newpos.SetY(y) ; 
295   newpos.SetZ(z) ; 
296               
297   return newpos ; 
298 }
299
300 //____________________________________________________________________________
301 void AliPHOSvFast::MakeRecParticle(const Int_t modid, const TVector3 pos, AliPHOSFastRecParticle & rp)
302 {
303   // Modify the primary particle properties according
304   //  1. the response function of PHOS
305   //  2. the performance of the EMC+PPSD setup
306   
307   Int_t type = MakeType( rp ) ;
308   rp.SetType(type) ;
309
310   
311   // get the detected energy
312
313   TLorentzVector momentum ;  
314   rp.Momentum(momentum) ; 
315   Double_t kineticenergy = TMath::Sqrt( TMath::Power(momentum.E(), 2) - TMath::Power(rp.GetMass(), 2) ) ; 
316   Double_t modifiedkineticenergy = MakeEnergy(kineticenergy ) ;
317   Double_t modifiedenergy = TMath::Sqrt( TMath::Power(modifiedkineticenergy, 2)  
318                                          + TMath::Power( rp.GetMass(), 2) ) ;
319  
320   // get the angle of incidence 
321   
322   Double_t incidencetheta = 90. * TMath::Pi() /180 - rp.Theta() ; 
323   Double_t incidencephi   = ( 270 + GetGeometry()->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;   
324
325   // get the detected direction
326   
327   TVector3 modifiedposition = MakePosition(kineticenergy, pos, incidencetheta, incidencephi) ; 
328   modifiedposition *= modifiedkineticenergy / modifiedposition.Mag() ; 
329
330   // Set the modified 4-momentum of the reconstructed particle
331
332   rp.SetMomentum(modifiedposition.X(), modifiedposition.Y(), modifiedposition.Z(), modifiedenergy) ; 
333
334  }
335
336 //____________________________________________________________________________
337 Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
338 {
339   // Generate a particle type using the performance of the EMC+PPSD setup
340
341   Int_t rv =   AliPHOSFastRecParticle::kUNDEFINED ;
342   Int_t charge = (Int_t)rp.GetPDG()->Charge() ;
343   Int_t test ; 
344   Float_t ran ; 
345   if ( charge != 0 && ( TMath::Abs(rp.GetPdgCode()) != 11 ) ) 
346     test = - 1 ;
347   else
348     test = rp.GetPdgCode() ; 
349
350   Info("MakeType", "SHOULD NOT BE USED until values of probabilities are properly set ") ;
351   assert(1==0) ;    // NB: ALL VALUES SHOULD BE CHECKED !!!!
352   switch (test) { 
353
354   case 22:    // it's a photon              // NB: ALL VALUES SHOLD BE CHECKED !!!!
355     ran = fRan.Rndm() ; 
356     if( ran <= 0.9498 )
357       rv =  AliPHOSFastRecParticle::kNEUTRALHAFAST ; 
358     else
359       rv =  AliPHOSFastRecParticle::kNEUTRALEMFAST ;     
360     break ; 
361
362   case 2112:  // it's a neutron
363     ran = fRan.Rndm() ; 
364     if ( ran <= 0.9998 )
365       rv =  AliPHOSFastRecParticle::kNEUTRALHASLOW ; 
366     else 
367       rv = AliPHOSFastRecParticle::kNEUTRALEMSLOW ; 
368     break ; 
369     
370   case -2112: // it's a anti-neutron
371     ran = fRan.Rndm() ; 
372     if ( ran <= 0.9984 )
373       rv =  AliPHOSFastRecParticle::kNEUTRALHASLOW ; 
374     else 
375       rv =  AliPHOSFastRecParticle::kNEUTRALEMSLOW ; 
376     break ; 
377     
378   case 11:    // it's a electron
379     ran = fRan.Rndm() ; 
380     if ( ran <= 0.9996 )
381       rv =  AliPHOSFastRecParticle::kCHARGEDEMFAST ; 
382     else 
383       rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
384     break; 
385
386   case -11:   // it's a positon
387     ran = fRan.Rndm() ; 
388     if ( ran <= 0.9996 )
389       rv =  AliPHOSFastRecParticle::kCHARGEDEMFAST ; 
390     else 
391       rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
392     break; 
393
394   case -1:    // it's a charged
395     ran = fRan.Rndm() ; 
396     if ( ran <= 0.9996 )
397       rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
398     else 
399       rv =  AliPHOSFastRecParticle::kNEUTRALHAFAST ; 
400
401     break ; 
402   }
403     
404   
405   return rv ;
406 }
407
408 //___________________________________________________________________________
409 void AliPHOSvFast::ResetPoints()
410 {
411   // This overloads the method in AliDetector
412   
413   ResetFastRecParticles() ; 
414 }
415
416 //___________________________________________________________________________
417 void AliPHOSvFast::ResetFastRecParticles()
418 {
419   // Resets the list of virtual reconstructed particles
420  
421   if (fFastRecParticles) 
422     fFastRecParticles->Clear() ;
423   fNRecParticles = 0 ; 
424 }
425
426 //___________________________________________________________________________
427 void AliPHOSvFast::SetBigBox(Int_t index, Float_t value)
428 {
429   // Set the size of the Box describing a PHOS module
430   
431   switch (index) {
432   case 0:
433     fBigBoxX = value ; 
434     break ; 
435   case 1:
436     fBigBoxY = value ; 
437     break ; 
438   case 2:
439     fBigBoxZ = value ; 
440     break ; 
441  }
442
443 }
444
445 //____________________________________________________________________________
446 Double_t AliPHOSvFast::SigmaE(Double_t energy)
447 {
448   // Calculates the energy dependent energy resolution
449   
450   Double_t rv = -1 ; 
451   
452   rv = TMath::Sqrt( TMath::Power(fResPara1/energy, 2) 
453                + TMath::Power(fResPara2/TMath::Sqrt(energy), 2) 
454                + TMath::Power(fResPara3, 2) ) ;  
455
456   return rv * energy ; 
457 }
458
459 //____________________________________________________________________________
460 Double_t AliPHOSvFast::SigmaP(Double_t energy, Double_t incidence)
461 {
462   // Calculates the energy dependent position resolution 
463
464   Double_t paraA = fPosParaA0 + fPosParaA1 * incidence ; 
465   Double_t paraB = fPosParaB0 + fPosParaB1 * incidence + fPosParaB2 * incidence * incidence ; 
466
467   return ( paraA / TMath::Sqrt(energy) + paraB ) * 0.1   ; // in cm  
468 }
469
470 //____________________________________________________________________________
471 void AliPHOSvFast::StepManager(void)
472 {
473   // Only verifies if the particle reaches PHOS and stops the tracking 
474
475   TLorentzVector lv ; 
476   gMC->TrackPosition(lv) ;
477   TVector3 pos = lv.Vect() ; 
478   Int_t modid  ; 
479   gMC->CurrentVolID(modid);
480   
481   Float_t energy = gMC->Etot() ; //Total energy of current track
482
483   //Calculating mass of current particle
484   TDatabasePDG * pdg = TDatabasePDG::Instance() ;
485   TParticlePDG * partPDG = pdg->GetParticle(gMC->TrackPid()) ;
486   Float_t mass = partPDG->Mass() ;
487
488   if(energy > mass){
489     pos.SetMag(TMath::Sqrt(energy*energy-mass*mass)) ;
490     TLorentzVector pTrack(pos, energy) ;  
491
492     TParticle * part = new TParticle(gMC->TrackPid(), 0,-1,-1,-1,-1, pTrack, lv)  ;
493         
494     AliPHOSFastRecParticle rp(*part) ;
495
496     // Adds the response of PHOS to the particle
497     MakeRecParticle(modid, pos, rp) ;
498     
499     // add the `track' particle to the FastRecParticles list
500   
501     AddRecParticle(rp) ;
502
503     part->Delete() ;
504   }
505   // stop the track as soon PHOS is reached
506   
507   gMC->StopTrack() ; 
508
509 }
510