Use gMC and not pMC everywhere
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv1.cxx
CommitLineData
fe4da5cc 1/////////////////////////////////////////////////////////
2// Manager and hits classes for set:PHOS version 1 //
3/////////////////////////////////////////////////////////
4
5// --- ROOT system ---
6#include "TH1.h"
7#include "TRandom.h"
8#include "TFile.h"
9#include "TTree.h"
10#include "TBRIK.h"
11#include "TNode.h"
bc9ab547 12#include "TMath.h"
fe4da5cc 13
14// --- galice header files ---
15#include "AliPHOSv1.h"
16#include "AliRun.h"
17#include "TGeant3.h"
18
19ClassImp(AliPHOSv1)
20
21//______________________________________________________________________________
22
23
8c933dd7 24AliPHOSv1::AliPHOSv1()
fe4da5cc 25{
26}
27
28//______________________________________________________________________________
29
30AliPHOSv1::AliPHOSv1(const char *name, const char *title)
31 : AliPHOS(name, title)
32{
33}
34
35//___________________________________________
36void AliPHOSv1::CreateGeometry()
37{
38
6435828c 39 AliPHOS *PHOS_tmp = (AliPHOS*)gAlice->GetModule("PHOS");
fe4da5cc 40 if( NULL==PHOS_tmp )
41 {
42 printf("There isn't PHOS detector!\n");
43 return;
44 }
45// AliPHOS &PHOS = *PHOS_tmp;
46
47 //////////////////////////////////////////////////////////////////////////////
48
49 Int_t rotation_matrix_number=0;
50 Float_t par[11],
51 x,y,z;
52
53 const float cell_length = GetCrystalLength()+GetAirThickness()+GetWrapThickness()+GetPIN_Length(),
54 cell_side_size = GetCrystalSideSize()+2*GetAirThickness()+2*GetWrapThickness(),
bc9ab547 55// cell_angle = 180/kPI * 2 * atan(cell_side_size/2 / GetRadius()), // radians
fe4da5cc 56 cradle_thikness = cell_length + GetCPV_Thickness() + GetCPV_PHOS_Distance(),
57 distance_to_CPV = GetRadius() - GetCPV_Thickness() - GetCPV_PHOS_Distance();
58
59 //////////////////////////////////////////////////////////////////////////////
60 // CELL volume and subvolumes creation
61 //////////////////////////////////////////////////////////////////////////////
62
63 par[0] = GetCrystalSideSize()/2 + GetWrapThickness();
64 par[1] = GetCrystalSideSize()/2 + GetWrapThickness();
65 par[2] = GetCrystalLength() /2 + GetWrapThickness()/2;
cfce8870 66 gMC->Gsvolu("WRAP","BOX ",GetPHOS_IDTMED_Tyvek(),par,3);
fe4da5cc 67
68 par[0] = GetCrystalSideSize()/2;
69 par[1] = GetCrystalSideSize()/2;
70 par[2] = GetCrystalLength()/2;
cfce8870 71 gMC->Gsvolu("CRST","BOX ",GetPHOS_IDTMED_PbWO4(),par,3);
fe4da5cc 72
73 // PIN
74 par[0] = GetPIN_SideSize()/2;
75 par[1] = GetPIN_SideSize()/2;
76 par[2] = GetPIN_Length()/2;
cfce8870 77 gMC->Gsvolu("PIN ","BOX ",GetPHOS_IDTMED_PIN(),par,3);
fe4da5cc 78
79 //////////////////////////////////////////////////////////////////////////////
80 // CRADLE,CPV creation.
81 //////////////////////////////////////////////////////////////////////////////
82
83 par[0] = cell_side_size/2 * GetNz();
84 par[1] = cell_side_size/2 * GetNphi();
85 par[2] = cradle_thikness/2;
cfce8870 86 gMC->Gsvolu("PHOS","BOX ",GetPHOS_IDTMED_AIR(),par,3);
fe4da5cc 87
88//par[0] : the same as above
89//par[1] : the same as above
90 par[2] = GetCPV_Thickness()/2;
cfce8870 91 gMC->Gsvolu("CPV ","BOX ",GetPHOS_IDTMED_CPV(),par,3);
fe4da5cc 92
93 x = 0;
94 y = 0;
95 z = (cell_length+GetCPV_PHOS_Distance())/2;
cfce8870 96 gMC->Gspos("CPV ",1,"PHOS",x,y,z,0,"ONLY");
fe4da5cc 97
98 par[0] = cell_side_size/2 * GetNz();
99 par[1] = cell_side_size/2 * GetNphi();
100 par[2] = cell_length/2;
cfce8870 101 gMC->Gsvolu("CRS0","BOX ",GetPHOS_IDTMED_AIR(),par,3);
fe4da5cc 102
103 x = 0;
104 y = 0;
105 z = -(cradle_thikness-cell_length)/2;
cfce8870 106 gMC->Gspos("CRS0",1,"PHOS",x,y,z,0,"ONLY");
fe4da5cc 107
cfce8870 108 gMC->Gsdvn("CRS1","CRS0",GetNphi(),2);
109 gMC->Gsdvn("CELL","CRS1",GetNz() ,1);
fe4da5cc 110
111 //////////////////////////////////////////////////////////////////////////////
112 // CELL creation
113 //////////////////////////////////////////////////////////////////////////////
114
115 x = 0;
116 y = 0;
117 z = -GetWrapThickness()/2;
cfce8870 118 gMC->Gspos("CRST",1,"WRAP",x,y,z,0,"ONLY");
fe4da5cc 119
120 x = 0;
121 y = 0;
122 z = GetPIN_Length()/2;
cfce8870 123 gMC->Gspos("WRAP",1,"CELL",x,y,z,0,"ONLY");
fe4da5cc 124
125 x = 0;
126 y = 0;
127 z = -GetCrystalLength()/2-GetWrapThickness()/2;
cfce8870 128 gMC->Gspos("PIN ",1,"CELL",x,y,z,0,"ONLY");
fe4da5cc 129
130 //////////////////////////////////////////////////////////////////////////////
131 // CELL has been created.
132 //////////////////////////////////////////////////////////////////////////////
133
134// int n=0;
135// z = -(GetCPV_Thickness()+GetCPV_PHOS_Distance())/2;
136//
137// for( int iy=0; iy<GetNphi(); iy++ )
138// {
139// y = (iy-(GetNphi()-1)/2.)*cell_side_size;
140// for( int ix=0; ix<GetNz(); ix++ )
141// {
142// x = (ix-(GetNz()-1)/2.)*cell_side_size;
cfce8870 143// gMC->Gspos("CELL",++n,"PHOS",x,y,z,0,"ONLY");
fe4da5cc 144// }
145// }
146
147 //////////////////////////////////////////////////////////////////////////////
148 // End of CRADLE creation.
149 //////////////////////////////////////////////////////////////////////////////
150
151
152 //////////////////////////////////////////////////////////////////////////////
153 // PHOS creation
154 //////////////////////////////////////////////////////////////////////////////
155
156 for( int i=0; i<GetCradlesAmount(); i++ )
157 {
158 float c = distance_to_CPV, // Distance to CPV
159 l = cell_side_size*GetNphi()/2, // Cradle half size around beam (for rect. geom.)
bc9ab547 160 cradle_angle = 360/kPI*atan(l/c),
fe4da5cc 161 cradle_angle_pos = -90+(i-(GetCradlesAmount()-1)/2.) * (cradle_angle+GetAngleBetweenCradles());
162 // Cradles are numerated in clock reversed order. (general way of angle increment)
163
164 float r = GetRadius() + cradle_thikness/2;
bc9ab547 165 x = r*cos(cradle_angle_pos*kPI/180);
166 y = r*sin(cradle_angle_pos*kPI/180);
fe4da5cc 167 z = 0;
168 AliMatrix(rotation_matrix_number, 0,0 , 90,90+cradle_angle_pos , 90,180+cradle_angle_pos);
cfce8870 169 gMC->Gspos("PHOS",i+1,"ALIC",x,y,z,rotation_matrix_number,"ONLY");
fe4da5cc 170
171 GetCradleAngle(i) = cradle_angle_pos;
172//
173// int n = PHOS.fCradles->GetEntries();
174// PHOS.fCradles->Add(new AliPHOSCradle( 1, // geometry.
175// GetCrystalSideSize (),
176// GetCrystalLength (),
177// GetWrapThickness (),
178// GetAirThickness (),
179// GetPIN_SideSize (),
180// GetPIN_Length (),
181// GetRadius (),
182// GetCPV_Thickness (),
183// GetCPV_PHOS_Distance (),
184// GetNz (),
185// GetNphi (),
186// cradle_angle_pos ));
187//
188// if( n+1 != PHOS.fCradles->GetEntries() ||
189// NULL == PHOS.fCradles->At(n) )
190// {
191// cout << " Can not create or add AliPHOSCradle.\n";
192// exit(1);
193// }
194 }
195 AddPHOSCradles();
196
197 //////////////////////////////////////////////////////////////////////////////
198 // All is done.
199 // Print some information.
200 //////////////////////////////////////////////////////////////////////////////
201}
202
203void AliPHOSv1::StepManager()
204{
205 static Bool_t inwold=0; // Status of previous ctrak->inwvol
fe4da5cc 206 Int_t copy;
207
fe4da5cc 208 int cradle_number, cell_Z, cell_Phi; // Variables that describe cell position.
209
cfce8870 210 if( gMC->GetMedium() == GetPHOS_IDTMED_PIN() && (gMC->TrackInside() || gMC->TrackExiting()==2) && inwold && gMC->TrackCharge()!=0 )
fe4da5cc 211 {
212 // GEANT particle just have entered into PIN diode.
213
6435828c 214 AliPHOS &PHOS = *(AliPHOS*)gAlice->GetModule("PHOS");
fe4da5cc 215
cfce8870 216 gMC->CurrentVolOff(4,0,copy);
fe4da5cc 217 cradle_number = copy-1;
cfce8870 218 gMC->CurrentVolOff(1,0,copy);
fe4da5cc 219 cell_Z = copy-1;
cfce8870 220 gMC->CurrentVolOff(2,0,copy);
fe4da5cc 221 cell_Phi = copy-1;
222/*
223 cradle_number = cvolu->number[cvolu->nlevel-5]-1;
224 cell_Z = cvolu->number[cvolu->nlevel-2]-1;
225 cell_Phi = cvolu->number[cvolu->nlevel-3]-1;
226*/
227
228 TH2S &h = PHOS.GetCradle(cradle_number).fChargedTracksInPIN;
229 h.AddBinContent(h.GetBin(cell_Z,cell_Phi));
230 }
231
232 //////////////////////////////////////////////////////////////////////////////
233
cfce8870 234 if( gMC->GetMedium() == GetPHOS_IDTMED_PbWO4() )
fe4da5cc 235 {
236 // GEANT particle into crystal.
237
6435828c 238 AliPHOS &PHOS = *(AliPHOS*)gAlice->GetModule("PHOS");
fe4da5cc 239
cfce8870 240 gMC->CurrentVolOff(5,0,copy);
fe4da5cc 241 cradle_number = copy-1;
cfce8870 242 gMC->CurrentVolOff(2,0,copy);
fe4da5cc 243 cell_Z = copy-1;
cfce8870 244 gMC->CurrentVolOff(3,0,copy);
fe4da5cc 245 cell_Phi = copy-1;
246/*
247 cradle_number = cvolu->number[cvolu->nlevel-6]-1;
248 cell_Z = cvolu->number[cvolu->nlevel-3]-1;
249 cell_Phi = cvolu->number[cvolu->nlevel-4]-1;
250*/
251 TH2F &h = PHOS.GetCradle(cradle_number).fCellEnergy;
cfce8870 252 h.AddBinContent(h.GetBin(cell_Z,cell_Phi),gMC->Edep());
fe4da5cc 253 }
254
255 //////////////////////////////////////////////////////////////////////////////
256
cfce8870 257 if( gMC->GetMedium()==GetPHOS_IDTMED_CPV() && (gMC->TrackInside() || gMC->TrackExiting()) && inwold )
fe4da5cc 258 {
259 // GEANT particle just have entered into CPV detector.
260
6435828c 261 AliPHOS &PHOS = *(AliPHOS*)gAlice->GetModule("PHOS");
fe4da5cc 262
cfce8870 263 gMC->CurrentVolOff(1,0,cradle_number);
fe4da5cc 264 cradle_number--;
265// cradle_number = cvolu->number[cvolu->nlevel-2]-1;
266
267 // Save CPV x,y hits position of charged particles.
268
269 AliPHOSCradle &cradle = PHOS.GetCradle(cradle_number);
270
271 Float_t xyz[3];
cfce8870 272 gMC->TrackPosition(xyz);
bc9ab547 273 TVector3 p(xyz[0],xyz[1],xyz[2]),v;
fe4da5cc 274
275 float x,y,l;
276 float R = cradle.GetRadius() - cradle.GetCPV_PHOS_Distance() - cradle.GetCPV_Thikness();
277 cradle.GetXY(p,v,R,x,y,l);
278 if( PHOS.fDebugLevel>0 )
279 if( l<0 )
280 printf("PHOS_STEP: warning: negative distance to CPV!! %f\n", l);
281
282 // Store current particle in the list of Cradle particles.
283 Float_t pmom[4];
cfce8870 284 gMC->TrackMomentum(pmom);
fe4da5cc 285 float Px = pmom[0] * pmom[3],
286 Py = pmom[1] * pmom[3],
287 Pz = pmom[2] * pmom[3];
cfce8870 288 Int_t Ipart = gMC->TrackPid();
fe4da5cc 289
290// TClonesArray &P=cradle.GetParticles();
291// new( P[P.GetEntries()] ) AliPHOSgamma(x,0,y,0,ctrak->getot,0,Px,Py,Pz);
cfce8870 292 cradle.GetParticles().Add(new AliPHOSgamma(x,y,gMC->Etot(),Px,Py,Pz,Ipart));
fe4da5cc 293
cfce8870 294 if( gMC->TrackCharge()!=0 )
fe4da5cc 295 cradle.AddCPVHit(x,y);
296 }
297
cfce8870 298 inwold=gMC->TrackEntering(); // Save current status of GEANT variable.
fe4da5cc 299}
300