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