]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSvFast.cxx
Stand-alone library for ESD. Possibility to use only root and lidESD.so for analysis...
[u/mrichter/AliRoot.git] / PHOS / AliPHOSvFast.cxx
CommitLineData
88cb7938 1 /**************************************************************************
3decf5cb 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
88cb7938 29#include <TBRIK.h>
88cb7938 30#include <TGeometry.h>
31#include <TNode.h>
32#include <TParticle.h>
e957fea8 33#include "TClonesArray.h"
88cb7938 34#include <TVirtualMC.h>
3decf5cb 35
36// --- Standard library ---
37
3decf5cb 38// --- AliRoot header files ---
3a4295ee 39#include "AliPHOSFastRecParticle.h"
88cb7938 40#include "AliPHOSGeometry.h"
41#include "AliPHOSLoader.h"
3decf5cb 42#include "AliPHOSvFast.h"
3decf5cb 43#include "AliRun.h"
3decf5cb 44
45ClassImp(AliPHOSvFast)
46
47//____________________________________________________________________________
3a4295ee 48AliPHOSvFast::AliPHOSvFast() : AliPHOS()
3decf5cb 49{
3a4295ee 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. ;
b2a60966 65
3decf5cb 66}
67
68//____________________________________________________________________________
69AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
70 AliPHOS(name,title)
71{
b2a60966 72 // ctor
73
3decf5cb 74
88cb7938 75 // create the Loader
7a9d98f9 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 ;
3decf5cb 93}
94
95//____________________________________________________________________________
96AliPHOSvFast::~AliPHOSvFast()
97{
b2a60966 98 // dtor
3decf5cb 99
a73f33f0 100 fFastRecParticles->Delete() ;
101 delete fFastRecParticles ;
102 fFastRecParticles = 0 ;
3decf5cb 103
104}
105
780fda6d 106//____________________________________________________________________________
107void 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
3decf5cb 129//____________________________________________________________________________
a73f33f0 130void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
131{
b2a60966 132 // Add a virtually reconstructed particle to the list
133
f96d3dc7 134 new( (*fFastRecParticles)[fNRecParticles] ) AliPHOSFastRecParticle(rp) ;
135 fNRecParticles++ ;
3decf5cb 136}
137
138//____________________________________________________________________________
139void AliPHOSvFast::BuildGeometry()
140{
3decf5cb 141 // Build the PHOS geometry for the ROOT display
b2a60966 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
3decf5cb 160 const Int_t kColorPHOS = kRed ;
161
a8c47ab6 162 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
3decf5cb 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
fa7cce36 170 Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
3decf5cb 171 Int_t number = 988 ;
fa7cce36 172 Float_t pphi = TMath::ATan( GetBigBox(0) / ( 2.0 * GetGeometry()->GetIPtoCrystalSurface() ) ) ;
3decf5cb 173 pphi *= kRADDEG ;
174 TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
175
176 char * nodename = new char[20] ;
177 char * rotname = new char[20] ;
178
fa7cce36 179 for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) {
180 Float_t angle = pphi * 2 * ( i - GetGeometry()->GetNModules() / 2.0 - 0.5 ) ;
3decf5cb 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//____________________________________________________________________________
196void AliPHOSvFast::CreateGeometry()
197{
b2a60966 198 // Create the geometry for GEANT
199
3decf5cb 200 AliPHOSvFast *phostmp = (AliPHOSvFast*)gAlice->GetModule("PHOS") ;
b2a60966 201
3decf5cb 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] ;
a8c47ab6 222 Double_t const kRADDEG = 180.0 / TMath::Pi() ;
3decf5cb 223
fa7cce36 224 for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) {
3decf5cb 225
fa7cce36 226 Float_t angle = GetGeometry()->GetPHOSAngle(i) ;
3decf5cb 227 AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
228
fa7cce36 229 Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
3decf5cb 230
231 Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
232 Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
3decf5cb 233 gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
234
235 } // for GetNModules
236
237}
238
239
240//____________________________________________________________________________
241void AliPHOSvFast::Init(void)
242{
b2a60966 243 // Prints out an information message
244
3decf5cb 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//___________________________________________________________________________
3a4295ee 261Float_t AliPHOSvFast::GetBigBox(Int_t index) const
3decf5cb 262{
b2a60966 263 // Get the X, Y or Z dimension of the box describing a PHOS module
264
3decf5cb 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}
3decf5cb 280//___________________________________________________________________________
88cb7938 281
282void AliPHOSvFast::MakeBranch(Option_t* opt)
3decf5cb 283{
b2a60966 284 // Create new branch in the current reconstructed Root Tree
88cb7938 285 AliDetector::MakeBranch(opt);
3a4295ee 286 const char *cd = strstr(opt,"R");
3decf5cb 287
88cb7938 288 if (fFastRecParticles && fLoader->TreeR() && cd) {
289 MakeBranchInTree(fLoader->TreeR(), GetName(), &fFastRecParticles, fBufferSize, 0);
3decf5cb 290 }
291}
a73f33f0 292//____________________________________________________________________________
88cb7938 293
fc7e2f43 294Double_t AliPHOSvFast::MakeEnergy(Double_t energy)
a73f33f0 295{
b2a60966 296 // Smears the energy according to the energy dependent energy resolution.
297 // A gaussian distribution is assumed
298
b1aa729d 299 Double_t sigma = SigmaE(energy) ;
300 return fRan.Gaus(energy, sigma) ;
a73f33f0 301}
a73f33f0 302//____________________________________________________________________________
88cb7938 303
fc7e2f43 304TVector3 AliPHOSvFast::MakePosition(Double_t energy, TVector3 pos, Double_t theta, Double_t phi)
a73f33f0 305{
b2a60966 306 // Smears the impact position according to the energy dependent position resolution
307 // A gaussian position distribution is assumed
308
b1aa729d 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}
a73f33f0 322
b1aa729d 323//____________________________________________________________________________
fc7e2f43 324void AliPHOSvFast::MakeRecParticle(Int_t modid, TVector3 pos, AliPHOSFastRecParticle & rp)
b1aa729d 325{
b2a60966 326 // Modify the primary particle properties according
327 // 1. the response function of PHOS
328 // 2. the performance of the EMC+PPSD setup
329
b1aa729d 330 Int_t type = MakeType( rp ) ;
a73f33f0 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 ) ;
b1aa729d 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() ;
fa7cce36 346 Double_t incidencephi = ( 270 + GetGeometry()->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;
b1aa729d 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
a73f33f0 357 }
358
359//____________________________________________________________________________
b1aa729d 360Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
a73f33f0 361{
b2a60966 362 // Generate a particle type using the performance of the EMC+PPSD setup
363
9ec91567 364 Int_t rv = AliPHOSFastRecParticle::kUNDEFINED ;
b1aa729d 365 Int_t charge = (Int_t)rp.GetPDG()->Charge() ;
366 Int_t test ;
367 Float_t ran ;
f96d3dc7 368 if ( charge != 0 && ( TMath::Abs(rp.GetPdgCode()) != 11 ) )
b1aa729d 369 test = - 1 ;
370 else
371 test = rp.GetPdgCode() ;
372
a4765fe4 373 Fatal("MakeType", "SHOULD NOT BE USED until values of probabilities are properly set ") ;
374 // NB: ALL VALUES SHOULD BE CHECKED !!!!
b1aa729d 375 switch (test) {
376
3a4295ee 377 case 22: // it's a photon // NB: ALL VALUES SHOLD BE CHECKED !!!!
b1aa729d 378 ran = fRan.Rndm() ;
3a4295ee 379 if( ran <= 0.9498 )
380 rv = AliPHOSFastRecParticle::kNEUTRALHAFAST ;
381 else
382 rv = AliPHOSFastRecParticle::kNEUTRALEMFAST ;
b1aa729d 383 break ;
384
385 case 2112: // it's a neutron
386 ran = fRan.Rndm() ;
387 if ( ran <= 0.9998 )
3a4295ee 388 rv = AliPHOSFastRecParticle::kNEUTRALHASLOW ;
b1aa729d 389 else
3a4295ee 390 rv = AliPHOSFastRecParticle::kNEUTRALEMSLOW ;
b1aa729d 391 break ;
3a4295ee 392
b1aa729d 393 case -2112: // it's a anti-neutron
394 ran = fRan.Rndm() ;
395 if ( ran <= 0.9984 )
3a4295ee 396 rv = AliPHOSFastRecParticle::kNEUTRALHASLOW ;
b1aa729d 397 else
3a4295ee 398 rv = AliPHOSFastRecParticle::kNEUTRALEMSLOW ;
b1aa729d 399 break ;
400
401 case 11: // it's a electron
402 ran = fRan.Rndm() ;
403 if ( ran <= 0.9996 )
3a4295ee 404 rv = AliPHOSFastRecParticle::kCHARGEDEMFAST ;
b1aa729d 405 else
3a4295ee 406 rv = AliPHOSFastRecParticle::kCHARGEDHAFAST ;
b1aa729d 407 break;
408
f96d3dc7 409 case -11: // it's a positon
b1aa729d 410 ran = fRan.Rndm() ;
411 if ( ran <= 0.9996 )
3a4295ee 412 rv = AliPHOSFastRecParticle::kCHARGEDEMFAST ;
b1aa729d 413 else
3a4295ee 414 rv = AliPHOSFastRecParticle::kCHARGEDHAFAST ;
b1aa729d 415 break;
416
417 case -1: // it's a charged
418 ran = fRan.Rndm() ;
419 if ( ran <= 0.9996 )
3a4295ee 420 rv = AliPHOSFastRecParticle::kCHARGEDHAFAST ;
b1aa729d 421 else
3a4295ee 422 rv = AliPHOSFastRecParticle::kNEUTRALHAFAST ;
b1aa729d 423
424 break ;
425 }
426
427
a73f33f0 428 return rv ;
429}
430
f96d3dc7 431//___________________________________________________________________________
432void AliPHOSvFast::ResetPoints()
433{
b2a60966 434 // This overloads the method in AliDetector
435
f96d3dc7 436 ResetFastRecParticles() ;
437}
438
439//___________________________________________________________________________
440void AliPHOSvFast::ResetFastRecParticles()
441{
b2a60966 442 // Resets the list of virtual reconstructed particles
443
f96d3dc7 444 if (fFastRecParticles)
445 fFastRecParticles->Clear() ;
446 fNRecParticles = 0 ;
447}
448
3decf5cb 449//___________________________________________________________________________
450void AliPHOSvFast::SetBigBox(Int_t index, Float_t value)
451{
b2a60966 452 // Set the size of the Box describing a PHOS module
453
3decf5cb 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
a73f33f0 468//____________________________________________________________________________
469Double_t AliPHOSvFast::SigmaE(Double_t energy)
470{
b2a60966 471 // Calculates the energy dependent energy resolution
472
a73f33f0 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
b1aa729d 482//____________________________________________________________________________
7a9d98f9 483Double_t AliPHOSvFast::SigmaP(Double_t energy, Double_t incidence)
b1aa729d 484{
b2a60966 485 // Calculates the energy dependent position resolution
486
b1aa729d 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
3decf5cb 493//____________________________________________________________________________
494void AliPHOSvFast::StepManager(void)
495{
b2a60966 496 // Only verifies if the particle reaches PHOS and stops the tracking
3a4295ee 497
a73f33f0 498 TLorentzVector lv ;
499 gMC->TrackPosition(lv) ;
b1aa729d 500 TVector3 pos = lv.Vect() ;
501 Int_t modid ;
502 gMC->CurrentVolID(modid);
a73f33f0 503
3a4295ee 504 Float_t energy = gMC->Etot() ; //Total energy of current track
3decf5cb 505
3a4295ee 506 //Calculating mass of current particle
507 TDatabasePDG * pdg = TDatabasePDG::Instance() ;
508 TParticlePDG * partPDG = pdg->GetParticle(gMC->TrackPid()) ;
509 Float_t mass = partPDG->Mass() ;
a73f33f0 510
3a4295ee 511 if(energy > mass){
512 pos.SetMag(TMath::Sqrt(energy*energy-mass*mass)) ;
513 TLorentzVector pTrack(pos, energy) ;
a73f33f0 514
3a4295ee 515 TParticle * part = new TParticle(gMC->TrackPid(), 0,-1,-1,-1,-1, pTrack, lv) ;
516
517 AliPHOSFastRecParticle rp(*part) ;
b1aa729d 518
3a4295ee 519 // Adds the response of PHOS to the particle
520 MakeRecParticle(modid, pos, rp) ;
521
522 // add the `track' particle to the FastRecParticles list
b1aa729d 523
3a4295ee 524 AddRecParticle(rp) ;
a73f33f0 525
3a4295ee 526 part->Delete() ;
527 }
a73f33f0 528 // stop the track as soon PHOS is reached
b1aa729d 529
3decf5cb 530 gMC->StopTrack() ;
531
532}
533