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