Coding rule violation corrected
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv3.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 version v0 of PHOS Manager class
20// Layout EMC + PPSD has name GPS2
21// The main goal of this version of AliPHOS is to calculte the
22// induced charged in the PIN diode, taking into account light
23// tracking in the PbWO4 crystal, induced signal in the
24// PIN due to MIPS particle and electronic noise.
25// This is done in the StepManager
26//
27//*-- Author: Odd Harald Oddland & Gines Martinez (SUBATECH)
28
29
30// --- ROOT system ---
31#include "TRandom.h"
32
33// --- Standard library ---
34
35#include <stdio.h>
36#include <string.h>
37#include <stdlib.h>
38#include <strstream.h>
39
40// --- AliRoot header files ---
41
42#include "AliPHOSv3.h"
43#include "AliPHOSHit.h"
97cee223 44#include "AliPHOSCPVDigit.h"
5f20d3fb 45#include "AliRun.h"
46#include "AliConst.h"
94de3818 47#include "AliMC.h"
97cee223 48#include "AliPHOSGeometry.h"
5f20d3fb 49
50ClassImp(AliPHOSv3)
51
52//____________________________________________________________________________
e04976bd 53 AliPHOSv3::AliPHOSv3(const char *name, const char *title):
54AliPHOSv1(name,title)
5f20d3fb 55{
56 // ctor
57
58 // Number of electrons created in the PIN due to light collected in the PbWo4 crystal is calculated using
59 // following formula
60 // NumberOfElectrons = EnergyLost * LightYield * PINEfficiency *
61 // exp (-LightYieldAttenuation * DistanceToPINdiodeFromTheHit) *
62 // RecalibrationFactor ;
63 // LightYield is obtained as a Poissonian distribution with a mean at 700000 photons per GeV fromValery Antonenko
64 // PINEfficiency is 0.1875 from Odd Harald Odland work
65 // k_0 is 0.0045 from Valery Antonenko
66
e04976bd 67
5f20d3fb 68 fLightYieldMean = 700000. ;
69 fIntrinsicPINEfficiency = 0.1875 ;
70 fLightYieldAttenuation = 0.0045 ;
71 fRecalibrationFactor = 6.2 / fLightYieldMean ;
72 fElectronsPerGeV = 2.77e+8 ;
73}
74
97cee223 75// //____________________________________________________________________________
76// AliPHOSv3::AliPHOSv3(AliPHOSReconstructioner * Reconstructioner, const char *name, const char *title):
77// AliPHOSv1(Reconstructioner,name,title)
78// {
79// // ctor
80
81// // Number of electrons created in the PIN due to light collected in the PbWo4 crystal is calculated using
82// // following formula
83// // NumberOfElectrons = EnergyLost * LightYield * PINEfficiency *
84// // exp (-LightYieldAttenuation * DistanceToPINdiodeFromTheHit) *
85// // RecalibrationFactor ;
86// // LightYield is obtained as a Poissonian distribution with a mean at 700000 photons per GeV fromValery Antonenko
87// // PINEfficiency is 0.1875 from Odd Harald Odland work
88// // k_0 is 0.0045 from Valery Antonenko
89
90// fLightYieldMean = 700000.;
91// fIntrinsicPINEfficiency = 0.1875 ;
92// fLightYieldAttenuation = 0.0045 ;
93// fRecalibrationFactor = 6.2 / fLightYieldMean ;
94// fElectronsPerGeV = 2.77e+8 ;
95// }
5f20d3fb 96//____________________________________________________________________________
037cc66d 97
5f20d3fb 98void AliPHOSv3::StepManager(void)
99{
100 // Accumulates hits as long as the track stays in a single crystal or PPSD gas Cell
037cc66d 101
102// if (gMC->IsTrackEntering())
103// cout << "Track enters the volume " << gMC->CurrentVolName() << endl;
104// if (gMC->IsTrackExiting())
105// cout << "Track leaves the volume " << gMC->CurrentVolName() << endl;
5f20d3fb 106
5c617c31 107 Int_t relid[4] ; // (box, layer, row, column) indices
108 Int_t absid ; // absolute cell ID number
037cc66d 109 Float_t xyze[4]={0,0,0,0} ; // position wrt MRS and energy deposited
5c617c31 110 TLorentzVector pos ; // Lorentz vector of the track current position
037cc66d 111 Int_t copy ;
5f20d3fb 112
113 Int_t tracknumber = gAlice->CurrentTrack() ;
037cc66d 114 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
115 TString name = fGeom->GetName() ;
037cc66d 116
117
118 if ( name == "GPS2" || name == "MIXT" ) { // ======> CPV is a GPS' PPSD
5f20d3fb 119
dc999bc0 120 if( gMC->CurrentVolID(copy) == gMC->VolId("PPCE") ) // We are inside a gas cell
5f20d3fb 121 {
122 gMC->TrackPosition(pos) ;
123 xyze[0] = pos[0] ;
124 xyze[1] = pos[1] ;
125 xyze[2] = pos[2] ;
037cc66d 126 xyze[3] = gMC->Edep() ;
5f20d3fb 127
b37750a6 128 if ( xyze[3] != 0) { // there is deposited energy
5f20d3fb 129 gMC->CurrentVolOffID(5, relid[0]) ; // get the PHOS Module number
037cc66d 130 if ( name == "MIXT" && strcmp(gMC->CurrentVolOffName(5),"PHO1") == 0 ){
131 relid[0] += fGeom->GetNModules() - fGeom->GetNPPSDModules();
132 }
5f20d3fb 133 gMC->CurrentVolOffID(3, relid[1]) ; // get the Micromegas Module number
037cc66d 134 // 1-> fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() upper
135 // > fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() lower
5f20d3fb 136 gMC->CurrentVolOffID(1, relid[2]) ; // get the row number of the cell
137 gMC->CurrentVolID(relid[3]) ; // get the column number
138
139 // get the absolute Id number
140
037cc66d 141 fGeom->RelToAbsNumbering(relid, absid) ;
142
143 // add current hit to the hit list
b37750a6 144 AddHit(fIshunt, primary, tracknumber, absid, xyze);
5f20d3fb 145
5f20d3fb 146
147 } // there is deposited energy
037cc66d 148 } // We are inside the gas of the CPV
149 } // GPS2 configuration
150
151 if ( name == "IHEP" || name == "MIXT" ) { // ======> CPV is a IHEP's one
152
153 // Yuri Kharlov, 28 September 2000
154
97cee223 155 if( gMC->CurrentVolID(copy) == gMC->VolId("PCPQ") &&
b37750a6 156 gMC->IsTrackEntering() &&
037cc66d 157 gMC->TrackCharge() != 0) {
b37750a6 158
159 gMC -> TrackPosition(pos);
160 Float_t xyzm[3], xyzd[3] ;
161 Int_t i;
162 for (i=0; i<3; i++) xyzm[i] = pos[i];
163 gMC -> Gmtod (xyzm, xyzd, 1); // transform coordinate from master to daughter system
164
165 Float_t xyd[3]={0,0,0} ; //local posiiton of the entering
166 xyd[0] = xyzd[0];
167 xyd[1] =-xyzd[1];
168 xyd[2] =-xyzd[2];
169
170
171 // Current momentum of the hit's track in the local ref. system
172 TLorentzVector pmom ; //momentum of the particle initiated hit
173 gMC -> TrackMomentum(pmom);
174 Float_t pm[3], pd[3];
175 for (i=0; i<3; i++) pm[i] = pmom[i];
176 gMC -> Gmtod (pm, pd, 2); // transform 3-momentum from master to daughter system
177 pmom[0] = pd[0];
178 pmom[1] =-pd[1];
179 pmom[2] =-pd[2];
037cc66d 180
181 // Digitize the current CPV hit:
182
183 // 1. find pad response and
184
185 Int_t moduleNumber;
186 gMC->CurrentVolOffID(3,moduleNumber);
187 moduleNumber--;
188
189
190 TClonesArray *cpvDigits = new TClonesArray("AliPHOSCPVDigit",0); // array of digits for current hit
191 CPVDigitize(pmom,xyd,moduleNumber,cpvDigits);
192
193 Float_t xmean = 0;
194 Float_t zmean = 0;
195 Float_t qsum = 0;
196 Int_t idigit,ndigits;
197
198 // 2. go through the current digit list and sum digits in pads
199
200 ndigits = cpvDigits->GetEntriesFast();
201 for (idigit=0; idigit<ndigits-1; idigit++) {
202 AliPHOSCPVDigit *cpvDigit1 = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(idigit);
203 Float_t x1 = cpvDigit1->GetXpad() ;
204 Float_t z1 = cpvDigit1->GetYpad() ;
205 for (Int_t jdigit=idigit+1; jdigit<ndigits; jdigit++) {
206 AliPHOSCPVDigit *cpvDigit2 = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(jdigit);
207 Float_t x2 = cpvDigit2->GetXpad() ;
208 Float_t z2 = cpvDigit2->GetYpad() ;
209 if (x1==x2 && z1==z2) {
210 Float_t qsum = cpvDigit1->GetQpad() + cpvDigit2->GetQpad() ;
211 cpvDigit2->SetQpad(qsum) ;
212 cpvDigits->RemoveAt(idigit) ;
213 }
214 }
215 }
216 cpvDigits->Compress() ;
217
218 // 3. add digits to temporary hit list fTmpHits
219
220 ndigits = cpvDigits->GetEntriesFast();
221 for (idigit=0; idigit<ndigits; idigit++) {
222 AliPHOSCPVDigit *cpvDigit = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(idigit);
223 relid[0] = moduleNumber + 1 ; // CPV (or PHOS) module number
224 relid[1] =-1 ; // means CPV
225 relid[2] = cpvDigit->GetXpad() ; // column number of a pad
226 relid[3] = cpvDigit->GetYpad() ; // row number of a pad
227
228 // get the absolute Id number
229 fGeom->RelToAbsNumbering(relid, absid) ;
230
231 // add current digit to the temporary hit list
232 xyze[0] = 0. ;
233 xyze[1] = 0. ;
234 xyze[2] = 0. ;
235 xyze[3] = cpvDigit->GetQpad() ; // amplitude in a pad
236 primary = -1; // No need in primary for CPV
b37750a6 237 AddHit(fIshunt, primary, tracknumber, absid, xyze);
037cc66d 238
239 if (cpvDigit->GetQpad() > 0.02) {
240 xmean += cpvDigit->GetQpad() * (cpvDigit->GetXpad() + 0.5);
241 zmean += cpvDigit->GetQpad() * (cpvDigit->GetYpad() + 0.5);
242 qsum += cpvDigit->GetQpad();
243 }
244 }
245 delete cpvDigits;
246 }
247 } // end of IHEP configuration
5f20d3fb 248
5f20d3fb 249
037cc66d 250 if(gMC->CurrentVolID(copy) == gMC->VolId("PXTL") ) { // We are inside a PBWO crystal
251 gMC->TrackPosition(pos) ;
252 xyze[0] = pos[0] ;
253 xyze[1] = pos[1] ;
254 xyze[2] = pos[2] ;
255 xyze[3] = gMC->Edep() ;
5f20d3fb 256
037cc66d 257
b37750a6 258 if ( (xyze[3] != 0) ) { // Track is inside the crystal and deposits some energy
5f20d3fb 259
037cc66d 260 gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
5f20d3fb 261
037cc66d 262 if ( name == "MIXT" && strcmp(gMC->CurrentVolOffName(10),"PHO1") == 0 )
263 relid[0] += fGeom->GetNModules() - fGeom->GetNPPSDModules();
264
265 relid[1] = 0 ; // means PBW04
266 gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
267 gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
268
5f20d3fb 269 // get the absolute Id number
037cc66d 270 fGeom->RelToAbsNumbering(relid, absid) ;
271
272 // add current hit to the hit list
b37750a6 273 AddHit(fIshunt, primary,tracknumber, absid, xyze);
5f20d3fb 274
5f20d3fb 275
037cc66d 276 } // there is deposited energy
277 } // we are inside a PHOS Xtal
278
279 if(gMC->CurrentVolID(copy) == gMC->VolId("PPIN") ) // We are inside de PIN diode
280 {
281 gMC->TrackPosition(pos) ;
282 xyze[0] = pos[0] ;
283 xyze[1] = pos[1] ;
284 xyze[2] = pos[2] ;
285 Float_t lostenergy = gMC->Edep() ;
286 xyze[3] = gMC->Edep() ;
287
288 if ( xyze[3] != 0 ) {
289 gMC->CurrentVolOffID(11, relid[0]) ; // get the PHOS module number ;
290 relid[1] = 0 ; // means PW04 and PIN
291 gMC->CurrentVolOffID(5, relid[2]) ; // get the row number inside the module
292 gMC->CurrentVolOffID(4, relid[3]) ; // get the cell number inside the module
293
294 // get the absolute Id number
295
296 Int_t absid ;
297 fGeom->RelToAbsNumbering(relid,absid) ;
298
299 // calculating number of electrons in the PIN diode asociated to this hit
300 Float_t nElectrons = lostenergy * fElectronsPerGeV ;
301 xyze[3] = nElectrons * fRecalibrationFactor ;
302
5f20d3fb 303 // add current hit to the hit list
b37750a6 304 AddHit(fIshunt, primary, tracknumber, absid, xyze);
5f20d3fb 305 //printf("PIN volume is %d, %d, %d, %d \n",relid[0],relid[1],relid[2],relid[3]);
306 //printf("Lost energy in the PIN is %f \n",lostenergy) ;
037cc66d 307 } // there is deposited energy
5f20d3fb 308 } // we are inside a PHOS XtalPHOS PIN diode
309}