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