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