cosmetics only
[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
16//_________________________________________________________________________
17// Manager class for PHOS version for fast simulations
18//*-- Author : Y. Schutz SUBATECH
19//////////////////////////////////////////////////////////////////////////////
20
21// --- ROOT system ---
22
23#include "TBRIK.h"
24#include "TNode.h"
25#include "TParticle.h"
26
27// --- Standard library ---
28
29#include <cstdio>
30#include <cassert>
31
32// --- AliRoot header files ---
33
34#include "AliPHOSvFast.h"
3decf5cb 35#include "AliRun.h"
36#include "AliConst.h"
37
38ClassImp(AliPHOSvFast)
39
40//____________________________________________________________________________
41AliPHOSvFast::AliPHOSvFast()
42{
a73f33f0 43 fFastRecParticles = 0 ;
3decf5cb 44 fNRecParticles = 0 ;
45}
46
47//____________________________________________________________________________
48AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
49 AliPHOS(name,title)
50{
51 // gets an instance of the geometry parameters class
52
53 fGeom = AliPHOSGeometry::GetInstance(title, "") ;
54
55 if (fGeom->IsInitialized() )
56 cout << "AliPHOSvFast : PHOS geometry intialized for " << fGeom->GetName() << endl ;
57 else
58 cout << "AliPHOSvFast : PHOS geometry initialization failed !" << endl ;
59
60 SetBigBox(0, fGeom->GetOuterBoxSize(0) ) ;
61 SetBigBox(1, fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) ;
62 SetBigBox(2, fGeom->GetOuterBoxSize(0) );
63
64 fNRecParticles = 0 ;
a73f33f0 65 fFastRecParticles = new FastRecParticlesList("AliPHOSFastRecParticle", 100) ;
66
67 fResPara1 = 30.0 ;
68 fResPara2 = 0.03 ;
69 fResPara3 = 0.01 ;
70
3decf5cb 71}
72
73//____________________________________________________________________________
74AliPHOSvFast::~AliPHOSvFast()
75{
76
a73f33f0 77 fFastRecParticles->Delete() ;
78 delete fFastRecParticles ;
79 fFastRecParticles = 0 ;
3decf5cb 80
81}
82
83//____________________________________________________________________________
a73f33f0 84void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
85{
86 new( (*fFastRecParticles)[fNRecParticles] ) AliPHOSFastRecParticle(rp) ;
87 fNRecParticles++ ;
3decf5cb 88}
89
90//____________________________________________________________________________
91void AliPHOSvFast::BuildGeometry()
92{
93
94 // Build the PHOS geometry for the ROOT display
95
96 const Int_t kColorPHOS = kRed ;
97
98 Double_t const kRADDEG = 180.0 / kPI ;
99
100 new TBRIK( "BigBox", "PHOS box", "void", GetBigBox(0)/2,
101 GetBigBox(1)/2,
102 GetBigBox(2)/2 );
103
104 // position PHOS into ALICE
105
106 Float_t r = fGeom->GetIPtoOuterCoverDistance() + GetBigBox(1) / 2.0 ;
107 Int_t number = 988 ;
108 Float_t pphi = TMath::ATan( GetBigBox(0) / ( 2.0 * fGeom->GetIPtoOuterCoverDistance() ) ) ;
109 pphi *= kRADDEG ;
110 TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
111
112 char * nodename = new char[20] ;
113 char * rotname = new char[20] ;
114
115 for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) {
116 Float_t angle = pphi * 2 * ( i - fGeom->GetNModules() / 2.0 - 0.5 ) ;
117 sprintf(rotname, "%s%d", "rot", number++) ;
118 new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
119 top->cd();
120 sprintf(nodename,"%s%d", "Module", i) ;
121 Float_t x = r * TMath::Sin( angle / kRADDEG ) ;
122 Float_t y = -r * TMath::Cos( angle / kRADDEG ) ;
123 TNode * bigboxnode = new TNode(nodename, nodename, "BigBox", x, y, 0, rotname ) ;
124 bigboxnode->SetLineColor(kColorPHOS) ;
125 fNodes->Add(bigboxnode) ;
126 }
127 delete[] nodename ;
128 delete[] rotname ;
129}
130
131//____________________________________________________________________________
132void AliPHOSvFast::CreateGeometry()
133{
134
135 AliPHOSvFast *phostmp = (AliPHOSvFast*)gAlice->GetModule("PHOS") ;
136
137 if ( phostmp == NULL ) {
138
139 fprintf(stderr, "PHOS detector not found!\n") ;
140 return ;
141
142 }
143
144 // Get pointer to the array containing media indeces
145 Int_t *idtmed = fIdtmed->GetArray() - 699 ;
146
147 Float_t bigbox[3] ;
148 bigbox[0] = GetBigBox(0) / 2.0 ;
149 bigbox[1] = GetBigBox(1) / 2.0 ;
150 bigbox[2] = GetBigBox(2) / 2.0 ;
151
152 gMC->Gsvolu("PHOS", "BOX ", idtmed[798], bigbox, 3) ;
153
154 // --- Position PHOS mdules in ALICE setup ---
155
156 Int_t idrotm[99] ;
157 Double_t const kRADDEG = 180.0 / kPI ;
158
159 for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) {
160
161 Float_t angle = fGeom->GetPHOSAngle(i) ;
162 AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
163
164 Float_t r = fGeom->GetIPtoOuterCoverDistance() + GetBigBox(1) / 2.0 ;
165
166 Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
167 Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
168
169 gMC->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
170
171 } // for GetNModules
172
173}
174
175
176//____________________________________________________________________________
177void AliPHOSvFast::Init(void)
178{
179
180 Int_t i;
181
182 printf("\n");
183 for(i=0;i<35;i++) printf("*");
184 printf(" FAST PHOS_INIT ");
185 for(i=0;i<35;i++) printf("*");
186 printf("\n");
187
188 // Here the PHOS initialisation code (if any!)
189
190 for(i=0;i<80;i++) printf("*");
191 printf("\n");
192
193}
194
195//___________________________________________________________________________
196Float_t AliPHOSvFast::GetBigBox(Int_t index)
197{
198 Float_t rv = 0 ;
199
200 switch (index) {
201 case 0:
202 rv = fBigBoxX ;
203 break ;
204 case 1:
205 rv = fBigBoxY ;
206 break ;
207 case 2:
208 rv = fBigBoxZ ;
209 break ;
210 }
211 return rv ;
212}
213
214//___________________________________________________________________________
215void AliPHOSvFast::MakeBranch(Option_t* opt)
216{
217 //
218 // Create a new branch in the current Root Tree
219 // The branch of fHits is automatically split
220 //
221 AliDetector::MakeBranch(opt) ;
222
223 char branchname[10];
224 sprintf(branchname,"%s",GetName());
a73f33f0 225 char *cd = strstr(opt,"R");
3decf5cb 226
a73f33f0 227 if (fFastRecParticles && gAlice->TreeR() && cd) {
228 gAlice->TreeR()->Branch(branchname, &fFastRecParticles, fBufferSize);
3decf5cb 229 }
230}
231
a73f33f0 232//____________________________________________________________________________
233Double_t AliPHOSvFast::MakeEnergy(const Double_t energy)
234{
235 Double_t sigma = SigmaE(energy*1000.) ;
236 return fRan.Gaus(energy*1000., sigma)/1000. ;
237}
238
239//____________________________________________________________________________
240void AliPHOSvFast::MakeRecParticle(AliPHOSFastRecParticle & rp)
241{
242
243 // get the detected type of particle
244 Int_t type = MakeType( rp.GetName() ) ;
245 rp.SetType(type) ;
246
247
248 // get the detected energy
249
250 TLorentzVector momentum ;
251 rp.Momentum(momentum) ;
252 Double_t kineticenergy = TMath::Sqrt( TMath::Power(momentum.E(), 2) - TMath::Power(rp.GetMass(), 2) ) ;
253 Double_t modifiedkineticenergy = MakeEnergy(kineticenergy ) ;
254 cout << modifiedkineticenergy << endl ;
255 // rp.SetMomentum(tempo) ;
256 }
257
258//____________________________________________________________________________
259Int_t AliPHOSvFast::MakeType(const Text_t * name)
260{
261 Int_t rv = kUNDEFINED ;
262 return rv ;
263}
264
3decf5cb 265//___________________________________________________________________________
266void AliPHOSvFast::SetBigBox(Int_t index, Float_t value)
267{
268
269 switch (index) {
270 case 0:
271 fBigBoxX = value ;
272 break ;
273 case 1:
274 fBigBoxY = value ;
275 break ;
276 case 2:
277 fBigBoxZ = value ;
278 break ;
279 }
280
281}
282
a73f33f0 283//____________________________________________________________________________
284Double_t AliPHOSvFast::SigmaE(Double_t energy)
285{
286 Double_t rv = -1 ;
287
288 rv = TMath::Sqrt( TMath::Power(fResPara1/energy, 2)
289 + TMath::Power(fResPara2/TMath::Sqrt(energy), 2)
290 + TMath::Power(fResPara3, 2) ) ;
291
292 return rv * energy ;
293}
294
3decf5cb 295//____________________________________________________________________________
296void AliPHOSvFast::StepManager(void)
297{
298
299 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
a73f33f0 300 TLorentzVector lv ;
301 gMC->TrackPosition(lv) ;
302
303 // Makes a reconstructed particle from the primary particle
3decf5cb 304
a73f33f0 305 TClonesArray * particlelist = gAlice->Particles() ;
306 TParticle * part = (TParticle *)particlelist->At(primary) ;
307
308 AliPHOSFastRecParticle rp(*part) ;
309
310 // Adds the response of PHOS to the particle
311 MakeRecParticle(rp) ;
3decf5cb 312
a73f33f0 313 // add the primary particle to the FastRecParticles list
314 AddRecParticle(rp) ;
315
316 // stop the track as soon PHOS is reached
3decf5cb 317 gMC->StopTrack() ;
318
319}
320