]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSvFast.cxx
MixWith method has been corrected: only one event per file is in the folder
[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 "TNode.h"
31 #include "TParticle.h"
32
33 // --- Standard library ---
34
35 #include <stdio.h>
36
37 // --- AliRoot header files ---
38
39 #include "AliPHOSvFast.h"
40 #include "AliRun.h"
41 #include "AliConst.h"
42
43 ClassImp(AliPHOSvFast)
44
45 //____________________________________________________________________________
46 AliPHOSvFast::AliPHOSvFast()
47 {
48   // ctor
49
50   fFastRecParticles = 0 ; 
51   fNRecParticles = 0 ; 
52 }
53
54 //____________________________________________________________________________
55 AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
56   AliPHOS(name,title)
57 {
58   // ctor
59
60   // gets an instance of the geometry parameters class  
61    
62   fGeom = AliPHOSGeometry::GetInstance(title, "") ; 
63
64   if (GetGeometry()->IsInitialized() ) 
65     cout << "AliPHOSvFast : PHOS geometry intialized for " << GetGeometry()->GetName() << endl ;
66   else
67     cout << "AliPHOSvFast : PHOS geometry initialization failed !" << endl ;   
68   
69   SetBigBox(0, GetGeometry()->GetOuterBoxSize(0) ) ;
70   SetBigBox(1, GetGeometry()->GetOuterBoxSize(1) + GetGeometry()->GetCPVBoxSize(1) ) ; 
71   SetBigBox(2, GetGeometry()->GetOuterBoxSize(0) ); 
72
73   fNRecParticles = 0 ; 
74   fFastRecParticles = new AliPHOSFastRecParticle::FastRecParticlesList("AliPHOSFastRecParticle", 100) ;
75
76   fResPara1 = 0.030 ;    // GeV
77   fResPara2 = 0.00003 ; 
78   fResPara3 = 0.00001 ; 
79
80   fPosParaA0 = 2.87 ;    // mm
81   fPosParaA1 = -0.0975 ;  
82   fPosParaB0 = 0.257 ;   
83   fPosParaB1 = 0.137 ; 
84   fPosParaB2 = 0.00619 ; 
85 }
86
87 //____________________________________________________________________________
88 AliPHOSvFast::~AliPHOSvFast()
89 {
90   // dtor
91  
92   fFastRecParticles->Delete() ; 
93   delete fFastRecParticles ;
94   fFastRecParticles = 0 ; 
95
96 }
97
98 //____________________________________________________________________________
99 void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
100 {  
101   // Add a virtually reconstructed particle to the list 
102
103   new( (*fFastRecParticles)[fNRecParticles] ) AliPHOSFastRecParticle(rp) ;
104   fNRecParticles++ ; 
105 }
106
107 //____________________________________________________________________________
108 void AliPHOSvFast::BuildGeometry()
109 {
110   // Build the PHOS geometry for the ROOT display
111    //BEGIN_HTML
112   /*
113     <H2>
114      PHOS FAST in ALICE displayed by root
115     </H2>
116     <H4> All Views </H4>
117     <P>
118     <CENTER>
119     <IMG Align=BOTTOM ALT="Fast All Views" SRC="../images/AliPHOSvFastAllViews.gif"> 
120     </CENTER></P>
121     <H4> Front View </H4>
122     <P>
123     <CENTER>
124     <IMG Align=BOTTOM ALT="Fast Front View" SRC="../images/AliPHOSvFastFrontView.gif"> 
125     </CENTER></P>
126   */
127   //END_HTML  
128  
129   const Int_t kColorPHOS = kRed ;
130   
131   Double_t const kRADDEG = 180.0 / kPI ;
132   
133   new TBRIK( "BigBox", "PHOS box", "void", GetBigBox(0)/2, 
134              GetBigBox(1)/2, 
135              GetBigBox(2)/2 );
136   
137   // position PHOS into ALICE
138
139   Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
140   Int_t number = 988 ; 
141   Float_t pphi =  TMath::ATan( GetBigBox(0)  / ( 2.0 * GetGeometry()->GetIPtoCrystalSurface() ) ) ;
142   pphi *= kRADDEG ;
143   TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
144  
145   char * nodename = new char[20] ;  
146   char * rotname  = new char[20] ; 
147
148   for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) { 
149    Float_t angle = pphi * 2 * ( i - GetGeometry()->GetNModules() / 2.0 - 0.5 ) ;
150    sprintf(rotname, "%s%d", "rot", number++) ;
151    new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
152    top->cd();
153    sprintf(nodename,"%s%d", "Module", i) ;    
154    Float_t x =  r * TMath::Sin( angle / kRADDEG ) ;
155    Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
156    TNode * bigboxnode = new TNode(nodename, nodename, "BigBox", x, y, 0, rotname ) ;
157    bigboxnode->SetLineColor(kColorPHOS) ;
158    fNodes->Add(bigboxnode) ;
159   }
160   delete[] nodename ; 
161   delete[] rotname ; 
162 }
163
164 //____________________________________________________________________________
165 void AliPHOSvFast::CreateGeometry()
166 {
167   // Create the geometry for GEANT
168   
169   AliPHOSvFast *phostmp = (AliPHOSvFast*)gAlice->GetModule("PHOS") ;
170   
171   if ( phostmp == NULL ) {
172     
173     fprintf(stderr, "PHOS detector not found!\n") ;
174     return ;
175     
176   }
177
178   // Get pointer to the array containing media indeces
179   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
180   
181   Float_t bigbox[3] ; 
182   bigbox[0] =   GetBigBox(0) / 2.0 ;
183   bigbox[1] =   GetBigBox(1) / 2.0 ;
184   bigbox[2] =   GetBigBox(2) / 2.0 ;
185   
186   gMC->Gsvolu("PHOS", "BOX ", idtmed[798], bigbox, 3) ;
187   
188   // --- Position  PHOS mdules in ALICE setup ---
189   
190   Int_t idrotm[99] ;
191   Double_t const kRADDEG = 180.0 / kPI ;
192   
193   for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) {
194     
195     Float_t angle = GetGeometry()->GetPHOSAngle(i) ;
196     AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
197  
198     Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
199
200     Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
201     Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
202     gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
203  
204   } // for GetNModules
205
206 }
207
208
209 //____________________________________________________________________________
210 void AliPHOSvFast::Init(void)
211 {
212   // Prints out an information message
213   
214   Int_t i;
215
216   printf("\n");
217   for(i=0;i<35;i++) printf("*");
218   printf(" FAST PHOS_INIT ");
219   for(i=0;i<35;i++) printf("*");
220   printf("\n");
221
222   // Here the PHOS initialisation code (if any!)
223
224   for(i=0;i<80;i++) printf("*");
225   printf("\n");
226   
227 }
228
229 //___________________________________________________________________________
230 Float_t AliPHOSvFast::GetBigBox(Int_t index)
231 {
232   // Get the X, Y or Z dimension of the box describing a PHOS module
233   
234   Float_t rv = 0 ; 
235
236   switch (index) {
237   case 0:
238     rv = fBigBoxX ; 
239     break ; 
240   case 1:
241      rv = fBigBoxY ; 
242     break ; 
243   case 2:
244      rv = fBigBoxZ ; 
245     break ; 
246  }
247   return rv ; 
248 }
249
250 //___________________________________________________________________________
251 void AliPHOSvFast::MakeBranch(Option_t* opt, const char *file)
252 {  
253   // Create new branch in the current reconstructed Root Tree
254  
255   AliDetector::MakeBranch(opt,file) ;
256   
257   char branchname[10];
258   sprintf(branchname,"%s",GetName());
259   char *cd = strstr(opt,"R");
260   
261   if (fFastRecParticles && gAlice->TreeR() && cd) {
262     MakeBranchInTree(gAlice->TreeR(), 
263                      branchname, &fFastRecParticles, fBufferSize, file);
264   }
265 }
266
267 //____________________________________________________________________________
268 Double_t AliPHOSvFast::MakeEnergy(const Double_t energy)
269 {  
270   // Smears the energy according to the energy dependent energy resolution.
271   // A gaussian distribution is assumed
272
273   Double_t sigma  = SigmaE(energy) ; 
274   return  fRan.Gaus(energy, sigma) ;   
275 }
276
277 //____________________________________________________________________________
278 TVector3 AliPHOSvFast::MakePosition(const Double_t energy, const TVector3 pos, const Double_t theta, const Double_t phi)
279 {
280   // Smears the impact position according to the energy dependent position resolution
281   // A gaussian position distribution is assumed
282
283   TVector3 newpos ;
284   Double_t sigma = SigmaP( energy, theta*180./TMath::Pi() ) ;
285   Double_t x = fRan.Gaus( pos.X(), sigma ) ;
286   sigma = SigmaP( energy, phi*180./TMath::Pi() ) ;
287   Double_t z = fRan.Gaus( pos.Z(), sigma ) ;
288   Double_t y = pos.Y() ; 
289   
290   newpos.SetX(x) ; 
291   newpos.SetY(y) ; 
292   newpos.SetZ(z) ; 
293               
294   return newpos ; 
295 }
296
297 //____________________________________________________________________________
298 void AliPHOSvFast::MakeRecParticle(const Int_t modid, const TVector3 pos, AliPHOSFastRecParticle & rp)
299 {
300   // Modify the primary particle properties according
301   //  1. the response function of PHOS
302   //  2. the performance of the EMC+PPSD setup
303   
304   Int_t type = MakeType( rp ) ;
305   rp.SetType(type) ;
306
307   
308   // get the detected energy
309
310   TLorentzVector momentum ;  
311   rp.Momentum(momentum) ; 
312   Double_t kineticenergy = TMath::Sqrt( TMath::Power(momentum.E(), 2) - TMath::Power(rp.GetMass(), 2) ) ; 
313   Double_t modifiedkineticenergy = MakeEnergy(kineticenergy ) ;
314   Double_t modifiedenergy = TMath::Sqrt( TMath::Power(modifiedkineticenergy, 2)  
315                                          + TMath::Power( rp.GetMass(), 2) ) ;
316  
317   // get the angle of incidence 
318   
319   Double_t incidencetheta = 90. * TMath::Pi() /180 - rp.Theta() ; 
320   Double_t incidencephi   = ( 270 + GetGeometry()->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;   
321
322   // get the detected direction
323   
324   TVector3 modifiedposition = MakePosition(kineticenergy, pos, incidencetheta, incidencephi) ; 
325   modifiedposition *= modifiedkineticenergy / modifiedposition.Mag() ; 
326
327   // Set the modified 4-momentum of the reconstructed particle
328
329   rp.SetMomentum(modifiedposition.X(), modifiedposition.Y(), modifiedposition.Z(), modifiedenergy) ; 
330
331  }
332
333 //____________________________________________________________________________
334 Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
335 {
336   // Generate a particle type using the performance of the EMC+PPSD setup
337
338   Int_t rv =   AliPHOSFastRecParticle::kUNDEFINED ;
339   Int_t charge = (Int_t)rp.GetPDG()->Charge() ;
340   Int_t test ; 
341   Float_t ran ; 
342   if ( charge != 0 && ( TMath::Abs(rp.GetPdgCode()) != 11 ) ) 
343     test = - 1 ;
344   else
345     test = rp.GetPdgCode() ; 
346
347   switch (test) { 
348
349   case 22:    // it's a photon
350     ran = fRan.Rndm() ; 
351     if ( ran <= 0.5 )  // 50 % 
352       rv =  AliPHOSFastRecParticle::kGAMMA ; 
353     else {
354       ran = fRan.Rndm() ; 
355       if( ran <= 0.9498 )
356         rv =  AliPHOSFastRecParticle::kNEUTRALEM ; 
357       else
358         rv =  AliPHOSFastRecParticle::kNEUTRALHA ; 
359     }     
360     break ; 
361
362   case 2112:  // it's a neutron
363     ran = fRan.Rndm() ; 
364     if ( ran <= 0.9998 )
365       rv =  AliPHOSFastRecParticle::kNEUTRALHA ; 
366     else 
367       rv = AliPHOSFastRecParticle::kNEUTRALEM ; 
368     break ; 
369
370   case -2112: // it's a anti-neutron
371     ran = fRan.Rndm() ; 
372     if ( ran <= 0.9984 )
373       rv =  AliPHOSFastRecParticle::kNEUTRALHA ; 
374     else 
375       rv =  AliPHOSFastRecParticle::kNEUTRALEM ; 
376     break ; 
377     
378   case 11:    // it's a electron
379     ran = fRan.Rndm() ; 
380     if ( ran <= 0.9996 )
381       rv =  AliPHOSFastRecParticle::kELECTRON ; 
382     else 
383       rv =  AliPHOSFastRecParticle::kCHARGEDHA ; 
384     break; 
385
386   case -11:   // it's a positon
387     ran = fRan.Rndm() ; 
388     if ( ran <= 0.9996 )
389       rv =  AliPHOSFastRecParticle::kELECTRON ; 
390     else 
391       rv =  AliPHOSFastRecParticle::kCHARGEDHA ; 
392     break; 
393
394   case -1:    // it's a charged
395     ran = fRan.Rndm() ; 
396     if ( ran <= 0.9996 )
397       rv =  AliPHOSFastRecParticle::kCHARGEDHA ; 
398     else 
399       rv =  AliPHOSFastRecParticle::kGAMMA ; 
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, Int_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   Int_t primary =  gAlice->GetPrimary( gAlice->CurrentTrack() ); 
476   TLorentzVector lv ; 
477   gMC->TrackPosition(lv) ;
478   TVector3 pos = lv.Vect() ; 
479   Int_t modid  ; 
480   gMC->CurrentVolID(modid);
481   
482   // Makes a reconstructed particle from the primary particle
483
484   TClonesArray * particlelist = gAlice->Particles() ;
485   TParticle * part = (TParticle *)particlelist->At(primary) ;  
486
487   AliPHOSFastRecParticle rp(*part) ;
488   rp.SetPrimary(primary) ; 
489
490   // Adds the response of PHOS to the particle
491
492   MakeRecParticle(modid, pos, rp) ;
493   
494   // add the primary particle to the FastRecParticles list
495   
496   AddRecParticle(rp) ;
497
498   // stop the track as soon PHOS is reached
499   
500   gMC->StopTrack() ; 
501
502 }
503