Script to read impacts generated by AliPHOSvImpacts
[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//
50abc6f8 27//*-- Author: Odd Harald Odland & Gines Martinez (SUBATECH)
5f20d3fb 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 ;
50abc6f8 63 // LightYield is obtained as a Poissonian distribution with a mean at 700000 photons per GeV from Valery Antonenko
64 // PINEfficiency is 0.1875
5f20d3fb 65 // k_0 is 0.0045 from Valery Antonenko
66
e04976bd 67
5f20d3fb 68 fLightYieldMean = 700000. ;
69 fIntrinsicPINEfficiency = 0.1875 ;
50abc6f8 70 //fIntrinsicPINEfficiency = 0.02655 ; //APD= 0.1875/0.1271 * 0.018 (PIN)
5f20d3fb 71 fLightYieldAttenuation = 0.0045 ;
50abc6f8 72 //fRecalibrationFactor = 6.2 / fLightYieldMean ;
73 fRecalibrationFactor = 5.67/ fLightYieldMean ; //25.04.2001 OHO
5f20d3fb 74 fElectronsPerGeV = 2.77e+8 ;
75}
76
97cee223 77// //____________________________________________________________________________
78// AliPHOSv3::AliPHOSv3(AliPHOSReconstructioner * Reconstructioner, const char *name, const char *title):
79// AliPHOSv1(Reconstructioner,name,title)
80// {
81// // ctor
82
83// // Number of electrons created in the PIN due to light collected in the PbWo4 crystal is calculated using
84// // following formula
85// // NumberOfElectrons = EnergyLost * LightYield * PINEfficiency *
86// // exp (-LightYieldAttenuation * DistanceToPINdiodeFromTheHit) *
87// // RecalibrationFactor ;
88// // LightYield is obtained as a Poissonian distribution with a mean at 700000 photons per GeV fromValery Antonenko
50abc6f8 89// // PINEfficiency is 0.1875
97cee223 90// // k_0 is 0.0045 from Valery Antonenko
91
92// fLightYieldMean = 700000.;
93// fIntrinsicPINEfficiency = 0.1875 ;
94// fLightYieldAttenuation = 0.0045 ;
95// fRecalibrationFactor = 6.2 / fLightYieldMean ;
50abc6f8 96// fRecalibrationFactor = 5.67 /fLightYieldMean ;//25.04.2001 OHO
97cee223 97// fElectronsPerGeV = 2.77e+8 ;
98// }
5f20d3fb 99//____________________________________________________________________________
037cc66d 100
5f20d3fb 101void AliPHOSv3::StepManager(void)
102{
103 // Accumulates hits as long as the track stays in a single crystal or PPSD gas Cell
037cc66d 104
105// if (gMC->IsTrackEntering())
106// cout << "Track enters the volume " << gMC->CurrentVolName() << endl;
107// if (gMC->IsTrackExiting())
108// cout << "Track leaves the volume " << gMC->CurrentVolName() << endl;
5f20d3fb 109
5c617c31 110 Int_t relid[4] ; // (box, layer, row, column) indices
111 Int_t absid ; // absolute cell ID number
037cc66d 112 Float_t xyze[4]={0,0,0,0} ; // position wrt MRS and energy deposited
5c617c31 113 TLorentzVector pos ; // Lorentz vector of the track current position
037cc66d 114 Int_t copy ;
50abc6f8 115 Float_t lightyield ; // Light Yield per GeV
116 Float_t apdgain ; // Poisson calculated gain around 300.
117 Float_t nElectrons ; // Number of electrons in the PIN diode
118
5f20d3fb 119 Int_t tracknumber = gAlice->CurrentTrack() ;
037cc66d 120 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
121 TString name = fGeom->GetName() ;
50abc6f8 122 Float_t lostenergy ;
123 Float_t global[3] ;
124 Float_t local[3] ;
037cc66d 125
126
127 if ( name == "GPS2" || name == "MIXT" ) { // ======> CPV is a GPS' PPSD
5f20d3fb 128
dc999bc0 129 if( gMC->CurrentVolID(copy) == gMC->VolId("PPCE") ) // We are inside a gas cell
5f20d3fb 130 {
131 gMC->TrackPosition(pos) ;
132 xyze[0] = pos[0] ;
133 xyze[1] = pos[1] ;
134 xyze[2] = pos[2] ;
037cc66d 135 xyze[3] = gMC->Edep() ;
5f20d3fb 136
b37750a6 137 if ( xyze[3] != 0) { // there is deposited energy
5f20d3fb 138 gMC->CurrentVolOffID(5, relid[0]) ; // get the PHOS Module number
037cc66d 139 if ( name == "MIXT" && strcmp(gMC->CurrentVolOffName(5),"PHO1") == 0 ){
140 relid[0] += fGeom->GetNModules() - fGeom->GetNPPSDModules();
141 }
5f20d3fb 142 gMC->CurrentVolOffID(3, relid[1]) ; // get the Micromegas Module number
037cc66d 143 // 1-> fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() upper
144 // > fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() lower
5f20d3fb 145 gMC->CurrentVolOffID(1, relid[2]) ; // get the row number of the cell
146 gMC->CurrentVolID(relid[3]) ; // get the column number
147
148 // get the absolute Id number
149
037cc66d 150 fGeom->RelToAbsNumbering(relid, absid) ;
151
152 // add current hit to the hit list
b37750a6 153 AddHit(fIshunt, primary, tracknumber, absid, xyze);
5f20d3fb 154
5f20d3fb 155
156 } // there is deposited energy
037cc66d 157 } // We are inside the gas of the CPV
158 } // GPS2 configuration
159
160 if ( name == "IHEP" || name == "MIXT" ) { // ======> CPV is a IHEP's one
161
162 // Yuri Kharlov, 28 September 2000
163
97cee223 164 if( gMC->CurrentVolID(copy) == gMC->VolId("PCPQ") &&
b37750a6 165 gMC->IsTrackEntering() &&
037cc66d 166 gMC->TrackCharge() != 0) {
b37750a6 167
168 gMC -> TrackPosition(pos);
169 Float_t xyzm[3], xyzd[3] ;
170 Int_t i;
171 for (i=0; i<3; i++) xyzm[i] = pos[i];
172 gMC -> Gmtod (xyzm, xyzd, 1); // transform coordinate from master to daughter system
173
174 Float_t xyd[3]={0,0,0} ; //local posiiton of the entering
175 xyd[0] = xyzd[0];
176 xyd[1] =-xyzd[1];
177 xyd[2] =-xyzd[2];
178
179
180 // Current momentum of the hit's track in the local ref. system
181 TLorentzVector pmom ; //momentum of the particle initiated hit
182 gMC -> TrackMomentum(pmom);
183 Float_t pm[3], pd[3];
184 for (i=0; i<3; i++) pm[i] = pmom[i];
185 gMC -> Gmtod (pm, pd, 2); // transform 3-momentum from master to daughter system
186 pmom[0] = pd[0];
187 pmom[1] =-pd[1];
188 pmom[2] =-pd[2];
037cc66d 189
190 // Digitize the current CPV hit:
191
192 // 1. find pad response and
193
194 Int_t moduleNumber;
195 gMC->CurrentVolOffID(3,moduleNumber);
196 moduleNumber--;
197
198
199 TClonesArray *cpvDigits = new TClonesArray("AliPHOSCPVDigit",0); // array of digits for current hit
200 CPVDigitize(pmom,xyd,moduleNumber,cpvDigits);
201
202 Float_t xmean = 0;
203 Float_t zmean = 0;
204 Float_t qsum = 0;
205 Int_t idigit,ndigits;
206
207 // 2. go through the current digit list and sum digits in pads
208
209 ndigits = cpvDigits->GetEntriesFast();
210 for (idigit=0; idigit<ndigits-1; idigit++) {
211 AliPHOSCPVDigit *cpvDigit1 = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(idigit);
212 Float_t x1 = cpvDigit1->GetXpad() ;
213 Float_t z1 = cpvDigit1->GetYpad() ;
214 for (Int_t jdigit=idigit+1; jdigit<ndigits; jdigit++) {
215 AliPHOSCPVDigit *cpvDigit2 = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(jdigit);
216 Float_t x2 = cpvDigit2->GetXpad() ;
217 Float_t z2 = cpvDigit2->GetYpad() ;
218 if (x1==x2 && z1==z2) {
219 Float_t qsum = cpvDigit1->GetQpad() + cpvDigit2->GetQpad() ;
220 cpvDigit2->SetQpad(qsum) ;
221 cpvDigits->RemoveAt(idigit) ;
222 }
223 }
224 }
225 cpvDigits->Compress() ;
226
227 // 3. add digits to temporary hit list fTmpHits
228
229 ndigits = cpvDigits->GetEntriesFast();
230 for (idigit=0; idigit<ndigits; idigit++) {
231 AliPHOSCPVDigit *cpvDigit = (AliPHOSCPVDigit*) cpvDigits->UncheckedAt(idigit);
232 relid[0] = moduleNumber + 1 ; // CPV (or PHOS) module number
233 relid[1] =-1 ; // means CPV
234 relid[2] = cpvDigit->GetXpad() ; // column number of a pad
235 relid[3] = cpvDigit->GetYpad() ; // row number of a pad
236
237 // get the absolute Id number
238 fGeom->RelToAbsNumbering(relid, absid) ;
239
240 // add current digit to the temporary hit list
241 xyze[0] = 0. ;
242 xyze[1] = 0. ;
243 xyze[2] = 0. ;
244 xyze[3] = cpvDigit->GetQpad() ; // amplitude in a pad
245 primary = -1; // No need in primary for CPV
b37750a6 246 AddHit(fIshunt, primary, tracknumber, absid, xyze);
037cc66d 247
248 if (cpvDigit->GetQpad() > 0.02) {
249 xmean += cpvDigit->GetQpad() * (cpvDigit->GetXpad() + 0.5);
250 zmean += cpvDigit->GetQpad() * (cpvDigit->GetYpad() + 0.5);
251 qsum += cpvDigit->GetQpad();
252 }
253 }
254 delete cpvDigits;
255 }
256 } // end of IHEP configuration
5f20d3fb 257
5f20d3fb 258
50abc6f8 259if(gMC->CurrentVolID(copy)==gMC->VolId("PXTL")){// We are inside a PBWO4 crystal
037cc66d 260 gMC->TrackPosition(pos) ;
261 xyze[0] = pos[0] ;
262 xyze[1] = pos[1] ;
263 xyze[2] = pos[2] ;
50abc6f8 264 global[0] = pos[0] ;
265 global[1] = pos[1] ;
266 global[2] = pos[2] ;
267 lostenergy = gMC->Edep();
037cc66d 268 xyze[3] = gMC->Edep() ;
5f20d3fb 269
037cc66d 270
50abc6f8 271 if ( (xyze[3] != 0) ){//Track is inside the crystal and deposits some energy
5f20d3fb 272
037cc66d 273 gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
5f20d3fb 274
037cc66d 275 if ( name == "MIXT" && strcmp(gMC->CurrentVolOffName(10),"PHO1") == 0 )
276 relid[0] += fGeom->GetNModules() - fGeom->GetNPPSDModules();
277
278 relid[1] = 0 ; // means PBW04
50abc6f8 279 gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
280 gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
037cc66d 281
5f20d3fb 282 // get the absolute Id number
50abc6f8 283
037cc66d 284 fGeom->RelToAbsNumbering(relid, absid) ;
285
50abc6f8 286 gMC->Gmtod(global, local, 1) ;
287
288 lightyield = gRandom->Poisson(fLightYieldMean) ;
289
290 apdgain = gRandom->Poisson(300.) ;
291
292 //calculate the number of electrons produced in the PIN due to this energy
293
294 nElectrons = apdgain * lostenergy * lightyield * fIntrinsicPINEfficiency *exp(-fLightYieldAttenuation * (local[1]+fGeom->GetCrystalSize(1)/2.0 ) ) ;
295
296 //nElectrons = lostenergy * lightyield * fIntrinsicPINEfficiency *exp(-fLightYieldAttenuation * (local[1]+fGeom->GetCrystalSize(1)/2.0 ) ) ;
297
298 xyze[3] = nElectrons * fRecalibrationFactor/100. ;
299
037cc66d 300 // add current hit to the hit list
50abc6f8 301
302 AddHit(fIshunt, primary,tracknumber, absid, xyze);
5f20d3fb 303
5f20d3fb 304
037cc66d 305 } // there is deposited energy
306 } // we are inside a PHOS Xtal
307
50abc6f8 308 if(gMC->CurrentVolID(copy) == gMC->VolId("PPIN"))//We are inside the PIN diode
037cc66d 309 {
310 gMC->TrackPosition(pos) ;
50abc6f8 311 global[0] = pos[0] ;
312 global[1] = pos[1] ;
313 global[2] = pos[2] ;
037cc66d 314 xyze[0] = pos[0] ;
315 xyze[1] = pos[1] ;
316 xyze[2] = pos[2] ;
50abc6f8 317 lostenergy = gMC->Edep() ;
037cc66d 318 xyze[3] = gMC->Edep() ;
319
320 if ( xyze[3] != 0 ) {
321 gMC->CurrentVolOffID(11, relid[0]) ; // get the PHOS module number ;
322 relid[1] = 0 ; // means PW04 and PIN
323 gMC->CurrentVolOffID(5, relid[2]) ; // get the row number inside the module
324 gMC->CurrentVolOffID(4, relid[3]) ; // get the cell number inside the module
325
326 // get the absolute Id number
327
328 Int_t absid ;
329 fGeom->RelToAbsNumbering(relid,absid) ;
50abc6f8 330 gMC->Gmtod(global, local, 1) ;
331
332// calculating number of electrons in the PIN diode asociated to this hit
333
334 nElectrons = lostenergy * fElectronsPerGeV ;
335 // xyze[3] = nElectrons * fRecalibrationFactor ;
336 apdgain = gRandom->Poisson(300.) ;
337 if(local[1]<-0.0045) xyze[3] = apdgain * nElectrons * fRecalibrationFactor/100.;
338 if((local[1]>-0.0045)&&(gMC->TrackPid()==-11)) xyze[3] = apdgain * nElectrons * fRecalibrationFactor/100.;
339 if(local[1]>-0.0045) xyze[3] = nElectrons *fRecalibrationFactor/100.;
037cc66d 340
5f20d3fb 341 // add current hit to the hit list
50abc6f8 342
b37750a6 343 AddHit(fIshunt, primary, tracknumber, absid, xyze);
50abc6f8 344
5f20d3fb 345 //printf("PIN volume is %d, %d, %d, %d \n",relid[0],relid[1],relid[2],relid[3]);
346 //printf("Lost energy in the PIN is %f \n",lostenergy) ;
037cc66d 347 } // there is deposited energy
5f20d3fb 348 } // we are inside a PHOS XtalPHOS PIN diode
349}