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