]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSvFast.cxx
Removed global's to comply with Coding Conventions
[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 ---
28
29#include "TBRIK.h"
30#include "TNode.h"
31#include "TParticle.h"
32
33// --- Standard library ---
34
de9ec31b 35#include <stdio.h>
3decf5cb 36
37// --- AliRoot header files ---
38
39#include "AliPHOSvFast.h"
3decf5cb 40#include "AliRun.h"
41#include "AliConst.h"
42
43ClassImp(AliPHOSvFast)
44
45//____________________________________________________________________________
46AliPHOSvFast::AliPHOSvFast()
47{
b2a60966 48 // ctor
49
a73f33f0 50 fFastRecParticles = 0 ;
3decf5cb 51 fNRecParticles = 0 ;
52}
53
54//____________________________________________________________________________
55AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
56 AliPHOS(name,title)
57{
b2a60966 58 // ctor
59
3decf5cb 60 // gets an instance of the geometry parameters class
61
62 fGeom = AliPHOSGeometry::GetInstance(title, "") ;
63
64 if (fGeom->IsInitialized() )
65 cout << "AliPHOSvFast : PHOS geometry intialized for " << fGeom->GetName() << endl ;
66 else
67 cout << "AliPHOSvFast : PHOS geometry initialization failed !" << endl ;
68
69 SetBigBox(0, fGeom->GetOuterBoxSize(0) ) ;
70 SetBigBox(1, fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) ;
71 SetBigBox(2, fGeom->GetOuterBoxSize(0) );
72
73 fNRecParticles = 0 ;
88714635 74 fFastRecParticles = new AliPHOSFastRecParticle::FastRecParticlesList("AliPHOSFastRecParticle", 100) ;
a73f33f0 75
b1aa729d 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 ;
3decf5cb 85}
86
87//____________________________________________________________________________
88AliPHOSvFast::~AliPHOSvFast()
89{
b2a60966 90 // dtor
3decf5cb 91
a73f33f0 92 fFastRecParticles->Delete() ;
93 delete fFastRecParticles ;
94 fFastRecParticles = 0 ;
3decf5cb 95
96}
97
98//____________________________________________________________________________
a73f33f0 99void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
100{
b2a60966 101 // Add a virtually reconstructed particle to the list
102
f96d3dc7 103 new( (*fFastRecParticles)[fNRecParticles] ) AliPHOSFastRecParticle(rp) ;
104 fNRecParticles++ ;
3decf5cb 105}
106
107//____________________________________________________________________________
108void AliPHOSvFast::BuildGeometry()
109{
3decf5cb 110 // Build the PHOS geometry for the ROOT display
b2a60966 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
3decf5cb 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
b2a60966 139 Float_t r = fGeom->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
3decf5cb 140 Int_t number = 988 ;
b2a60966 141 Float_t pphi = TMath::ATan( GetBigBox(0) / ( 2.0 * fGeom->GetIPtoCrystalSurface() ) ) ;
3decf5cb 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 <= fGeom->GetNModules(); i++ ) {
149 Float_t angle = pphi * 2 * ( i - fGeom->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//____________________________________________________________________________
165void AliPHOSvFast::CreateGeometry()
166{
b2a60966 167 // Create the geometry for GEANT
168
3decf5cb 169 AliPHOSvFast *phostmp = (AliPHOSvFast*)gAlice->GetModule("PHOS") ;
b2a60966 170
3decf5cb 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 <= fGeom->GetNModules(); i++ ) {
194
195 Float_t angle = fGeom->GetPHOSAngle(i) ;
196 AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
197
b2a60966 198 Float_t r = fGeom->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
3decf5cb 199
200 Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
201 Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
3decf5cb 202 gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
203
204 } // for GetNModules
205
206}
207
208
209//____________________________________________________________________________
210void AliPHOSvFast::Init(void)
211{
b2a60966 212 // Prints out an information message
213
3decf5cb 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//___________________________________________________________________________
230Float_t AliPHOSvFast::GetBigBox(Int_t index)
231{
b2a60966 232 // Get the X, Y or Z dimension of the box describing a PHOS module
233
3decf5cb 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//___________________________________________________________________________
251void AliPHOSvFast::MakeBranch(Option_t* opt)
252{
b2a60966 253 // Create new branch in the current reconstructed Root Tree
f96d3dc7 254
3decf5cb 255 AliDetector::MakeBranch(opt) ;
256
257 char branchname[10];
258 sprintf(branchname,"%s",GetName());
a73f33f0 259 char *cd = strstr(opt,"R");
3decf5cb 260
a73f33f0 261 if (fFastRecParticles && gAlice->TreeR() && cd) {
262 gAlice->TreeR()->Branch(branchname, &fFastRecParticles, fBufferSize);
3decf5cb 263 }
264}
265
a73f33f0 266//____________________________________________________________________________
267Double_t AliPHOSvFast::MakeEnergy(const Double_t energy)
268{
b2a60966 269 // Smears the energy according to the energy dependent energy resolution.
270 // A gaussian distribution is assumed
271
b1aa729d 272 Double_t sigma = SigmaE(energy) ;
273 return fRan.Gaus(energy, sigma) ;
a73f33f0 274}
275
276//____________________________________________________________________________
b1aa729d 277TVector3 AliPHOSvFast::MakePosition(const Double_t energy, const TVector3 pos, const Double_t theta, const Double_t phi)
a73f33f0 278{
b2a60966 279 // Smears the impact position according to the energy dependent position resolution
280 // A gaussian position distribution is assumed
281
b1aa729d 282 TVector3 newpos ;
283 Double_t sigma = SigmaP( energy, theta*180./TMath::Pi() ) ;
284 Double_t x = fRan.Gaus( pos.X(), sigma ) ;
285 sigma = SigmaP( energy, phi*180./TMath::Pi() ) ;
286 Double_t z = fRan.Gaus( pos.Z(), sigma ) ;
287 Double_t y = pos.Y() ;
288
289 newpos.SetX(x) ;
290 newpos.SetY(y) ;
291 newpos.SetZ(z) ;
292
293 return newpos ;
294}
a73f33f0 295
b1aa729d 296//____________________________________________________________________________
297void AliPHOSvFast::MakeRecParticle(const Int_t modid, const TVector3 pos, AliPHOSFastRecParticle & rp)
298{
b2a60966 299 // Modify the primary particle properties according
300 // 1. the response function of PHOS
301 // 2. the performance of the EMC+PPSD setup
302
b1aa729d 303 Int_t type = MakeType( rp ) ;
a73f33f0 304 rp.SetType(type) ;
305
306
307 // get the detected energy
308
309 TLorentzVector momentum ;
310 rp.Momentum(momentum) ;
311 Double_t kineticenergy = TMath::Sqrt( TMath::Power(momentum.E(), 2) - TMath::Power(rp.GetMass(), 2) ) ;
312 Double_t modifiedkineticenergy = MakeEnergy(kineticenergy ) ;
b1aa729d 313 Double_t modifiedenergy = TMath::Sqrt( TMath::Power(modifiedkineticenergy, 2)
314 + TMath::Power( rp.GetMass(), 2) ) ;
315
316 // get the angle of incidence
317
318 Double_t incidencetheta = 90. * TMath::Pi() /180 - rp.Theta() ;
319 Double_t incidencephi = ( 270 + fGeom->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;
320
321 // get the detected direction
322
323 TVector3 modifiedposition = MakePosition(kineticenergy, pos, incidencetheta, incidencephi) ;
324 modifiedposition *= modifiedkineticenergy / modifiedposition.Mag() ;
325
326 // Set the modified 4-momentum of the reconstructed particle
327
328 rp.SetMomentum(modifiedposition.X(), modifiedposition.Y(), modifiedposition.Z(), modifiedenergy) ;
329
a73f33f0 330 }
331
332//____________________________________________________________________________
b1aa729d 333Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
a73f33f0 334{
b2a60966 335 // Generate a particle type using the performance of the EMC+PPSD setup
336
a73f33f0 337 Int_t rv = kUNDEFINED ;
b1aa729d 338 Int_t charge = (Int_t)rp.GetPDG()->Charge() ;
339 Int_t test ;
340 Float_t ran ;
f96d3dc7 341 if ( charge != 0 && ( TMath::Abs(rp.GetPdgCode()) != 11 ) )
b1aa729d 342 test = - 1 ;
343 else
344 test = rp.GetPdgCode() ;
345
346 switch (test) {
347
348 case 22: // it's a photon
349 ran = fRan.Rndm() ;
350 if ( ran <= 0.5 ) // 50 %
351 rv = kGAMMA ;
352 else {
353 ran = fRan.Rndm() ;
354 if( ran <= 0.9498 )
88714635 355 rv = kNEUTRALEM ;
b1aa729d 356 else
88714635 357 rv = kNEUTRALHA ;
b1aa729d 358 }
359 break ;
360
361 case 2112: // it's a neutron
362 ran = fRan.Rndm() ;
363 if ( ran <= 0.9998 )
88714635 364 rv = kNEUTRALHA ;
b1aa729d 365 else
88714635 366 rv = kNEUTRALEM ;
b1aa729d 367 break ;
368
369 case -2112: // it's a anti-neutron
370 ran = fRan.Rndm() ;
371 if ( ran <= 0.9984 )
88714635 372 rv = kNEUTRALHA ;
b1aa729d 373 else
88714635 374 rv = kNEUTRALEM ;
b1aa729d 375 break ;
376
377 case 11: // it's a electron
378 ran = fRan.Rndm() ;
379 if ( ran <= 0.9996 )
380 rv = kELECTRON ;
381 else
88714635 382 rv = kCHARGEDHA ;
b1aa729d 383 break;
384
f96d3dc7 385 case -11: // it's a positon
b1aa729d 386 ran = fRan.Rndm() ;
387 if ( ran <= 0.9996 )
388 rv = kELECTRON ;
389 else
88714635 390 rv = kCHARGEDHA ;
b1aa729d 391 break;
392
393 case -1: // it's a charged
394 ran = fRan.Rndm() ;
395 if ( ran <= 0.9996 )
88714635 396 rv = kCHARGEDHA ;
b1aa729d 397 else
398 rv = kGAMMA ;
399
400 break ;
401 }
402
403
a73f33f0 404 return rv ;
405}
406
f96d3dc7 407//___________________________________________________________________________
408void AliPHOSvFast::ResetPoints()
409{
b2a60966 410 // This overloads the method in AliDetector
411
f96d3dc7 412 ResetFastRecParticles() ;
413}
414
415//___________________________________________________________________________
416void AliPHOSvFast::ResetFastRecParticles()
417{
b2a60966 418 // Resets the list of virtual reconstructed particles
419
f96d3dc7 420 if (fFastRecParticles)
421 fFastRecParticles->Clear() ;
422 fNRecParticles = 0 ;
423}
424
3decf5cb 425//___________________________________________________________________________
426void AliPHOSvFast::SetBigBox(Int_t index, Float_t value)
427{
b2a60966 428 // Set the size of the Box describing a PHOS module
429
3decf5cb 430 switch (index) {
431 case 0:
432 fBigBoxX = value ;
433 break ;
434 case 1:
435 fBigBoxY = value ;
436 break ;
437 case 2:
438 fBigBoxZ = value ;
439 break ;
440 }
441
442}
443
a73f33f0 444//____________________________________________________________________________
445Double_t AliPHOSvFast::SigmaE(Double_t energy)
446{
b2a60966 447 // Calculates the energy dependent energy resolution
448
a73f33f0 449 Double_t rv = -1 ;
450
451 rv = TMath::Sqrt( TMath::Power(fResPara1/energy, 2)
452 + TMath::Power(fResPara2/TMath::Sqrt(energy), 2)
453 + TMath::Power(fResPara3, 2) ) ;
454
455 return rv * energy ;
456}
457
b1aa729d 458//____________________________________________________________________________
459Double_t AliPHOSvFast::SigmaP(Double_t energy, Int_t incidence)
460{
b2a60966 461 // Calculates the energy dependent position resolution
462
b1aa729d 463 Double_t paraA = fPosParaA0 + fPosParaA1 * incidence ;
464 Double_t paraB = fPosParaB0 + fPosParaB1 * incidence + fPosParaB2 * incidence * incidence ;
465
466 return ( paraA / TMath::Sqrt(energy) + paraB ) * 0.1 ; // in cm
467}
468
3decf5cb 469//____________________________________________________________________________
470void AliPHOSvFast::StepManager(void)
471{
b2a60966 472 // Only verifies if the particle reaches PHOS and stops the tracking
473
3decf5cb 474 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
a73f33f0 475 TLorentzVector lv ;
476 gMC->TrackPosition(lv) ;
b1aa729d 477 TVector3 pos = lv.Vect() ;
478 Int_t modid ;
479 gMC->CurrentVolID(modid);
a73f33f0 480
481 // Makes a reconstructed particle from the primary particle
3decf5cb 482
a73f33f0 483 TClonesArray * particlelist = gAlice->Particles() ;
484 TParticle * part = (TParticle *)particlelist->At(primary) ;
485
486 AliPHOSFastRecParticle rp(*part) ;
b2a60966 487 rp.SetPrimary(primary) ;
a73f33f0 488
489 // Adds the response of PHOS to the particle
b1aa729d 490
491 MakeRecParticle(modid, pos, rp) ;
3decf5cb 492
a73f33f0 493 // add the primary particle to the FastRecParticles list
b1aa729d 494
a73f33f0 495 AddRecParticle(rp) ;
496
497 // stop the track as soon PHOS is reached
b1aa729d 498
3decf5cb 499 gMC->StopTrack() ;
500
501}
502