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