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