commit last changes from Peter.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSv2.cxx
CommitLineData
bea63bea 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$ */
bea63bea 17//_________________________________________________________________________
5f20d3fb 18// Version of AliPHOSv1 which keeps all hits in TreeH
19// AddHit, StepManager,and FinishEvent are redefined
bea63bea 20//
5f20d3fb 21//*-- Author: Gines MARTINEZ (SUBATECH)
bea63bea 22
23
24// --- ROOT system ---
5f20d3fb 25
26#include "TBRIK.h"
27#include "TNode.h"
bea63bea 28#include "TRandom.h"
29
30// --- Standard library ---
31
32#include <stdio.h>
33#include <string.h>
34#include <stdlib.h>
35#include <strstream.h>
36
37// --- AliRoot header files ---
38
39#include "AliPHOSv2.h"
40#include "AliPHOSHit.h"
41#include "AliPHOSDigit.h"
5f20d3fb 42#include "AliPHOSReconstructioner.h"
bea63bea 43#include "AliRun.h"
44#include "AliConst.h"
45
46ClassImp(AliPHOSv2)
47
48//____________________________________________________________________________
5f20d3fb 49AliPHOSv2::AliPHOSv2()
50{
51 // default ctor
52 fNTmpHits = 0 ;
53 fTmpHits = 0 ;
54}
55
56//____________________________________________________________________________
bea63bea 57AliPHOSv2::AliPHOSv2(const char *name, const char *title):
5f20d3fb 58 AliPHOSv1(name,title)
bea63bea 59{
5f20d3fb 60 // ctor
61 fHits= new TClonesArray("AliPHOSHit",1000) ;
bea63bea 62}
63
64//____________________________________________________________________________
5f20d3fb 65AliPHOSv2::~AliPHOSv2()
bea63bea 66{
5f20d3fb 67 // dtor
68 if ( fTmpHits) {
69 fTmpHits->Delete() ;
70 delete fTmpHits ;
71 fTmpHits = 0 ;
72 }
73
74 if ( fEmcRecPoints ) {
75 fEmcRecPoints->Delete() ;
76 delete fEmcRecPoints ;
77 fEmcRecPoints = 0 ;
78 }
79
80 if ( fPpsdRecPoints ) {
81 fPpsdRecPoints->Delete() ;
82 delete fPpsdRecPoints ;
83 fPpsdRecPoints = 0 ;
84 }
85
86 if ( fTrackSegments ) {
87 fTrackSegments->Delete() ;
88 delete fTrackSegments ;
89 fTrackSegments = 0 ;
90 }
bea63bea 91}
92
93//____________________________________________________________________________
5f20d3fb 94void AliPHOSv2::AddHit(Int_t shunt, Int_t primary, Int_t tracknumber, Int_t Id, Float_t * hits)
95{
96 // Add a hit to the hit list.
97 // In this version of AliPHOSv1, a PHOS hit is real geant
98 // hits in a single crystal or in a single PPSD gas cell
99
100 TClonesArray &ltmphits = *fHits ;
101 AliPHOSHit *newHit ;
102
103 // fHits->Print("");
104
105 newHit = new AliPHOSHit(shunt, primary, tracknumber, Id, hits) ;
106
107 // We DO want to save in TreeH the raw hits
108 new(ltmphits[fNhits]) AliPHOSHit(*newHit) ;
109 fNhits++ ;
110
111 // Please note that the fTmpHits array must survive up to the
112 // end of the events, so it does not appear e.g. in ResetHits() (
113 // which is called at the end of each primary).
114
115 delete newHit;
116
117}
118
119
120
121
122//___________________________________________________________________________
123void AliPHOSv2::FinishEvent()
124{
125 // Makes the digits from the sum of summed hit in a single crystal or PPSD gas cell
126 // Adds to the energy the electronic noise
127 // Keeps digits with energy above fDigitThreshold
128
129 // Save the cumulated hits instead of raw hits (need to create the branch myself)
130 // It is put in the Digit Tree because the TreeH is filled after each primary
131 // and the TreeD at the end of the event.
132
133 Int_t i ;
134 Int_t relid[4];
135 Int_t j ;
136 TClonesArray &lDigits = *fDigits ;
137 AliPHOSHit * hit ;
138 AliPHOSDigit * newdigit ;
139 AliPHOSDigit * curdigit ;
140 Bool_t deja = kFALSE ;
141
142 for ( i = 0 ; i < fNhits ; i++ ) {
143 hit = (AliPHOSHit*)fHits->At(i) ;
144 newdigit = new AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
145 deja =kFALSE ;
146 for ( j = 0 ; j < fNdigits ; j++) {
147 curdigit = (AliPHOSDigit*) lDigits[j] ;
148 if ( *curdigit == *newdigit) {
149 *curdigit = *curdigit + *newdigit ;
150 deja = kTRUE ;
151 }
152 }
153 if ( !deja ) {
154 new(lDigits[fNdigits]) AliPHOSDigit(* newdigit) ;
155 fNdigits++ ;
156 }
157
158 delete newdigit ;
159 }
160
161 // Noise induced by the PIN diode of the PbWO crystals
162
163 Float_t energyandnoise ;
164 for ( i = 0 ; i < fNdigits ; i++ ) {
165 newdigit = (AliPHOSDigit * ) fDigits->At(i) ;
166 fGeom->AbsToRelNumbering(newdigit->GetId(), relid) ;
167
168 if (relid[1]==0){ // Digits belong to EMC (PbW0_4 crystals)
169 energyandnoise = newdigit->GetAmp() + Digitize(gRandom->Gaus(0., fPinElectronicNoise)) ;
170
171 if (energyandnoise < 0 )
172 energyandnoise = 0 ;
173
174 if ( newdigit->GetAmp() < fDigitThreshold ) // if threshold not surpassed, remove digit from list
175 fDigits->RemoveAt(i) ;
176 }
177 }
178
179 fDigits->Compress() ;
180
181 fNdigits = fDigits->GetEntries() ;
182 for (i = 0 ; i < fNdigits ; i++) {
183 newdigit = (AliPHOSDigit *) fDigits->At(i) ;
184 newdigit->SetIndexInList(i) ;
185 }
186
187}
188
bea63bea 189void AliPHOSv2::StepManager(void)
190{
191 // Accumulates hits as long as the track stays in a single crystal or PPSD gas Cell
bea63bea 192
193 Int_t relid[4] ; // (box, layer, row, column) indices
194 Float_t xyze[4] ; // position wrt MRS and energy deposited
195 TLorentzVector pos ;
5f20d3fb 196 Int_t copy ;
bea63bea 197
5f20d3fb 198 Int_t tracknumber = gAlice->CurrentTrack() ;
199 Int_t primary = gAlice->GetPrimary( gAlice->CurrentTrack() );
bea63bea 200
5f20d3fb 201 TString name = fGeom->GetName() ;
bea63bea 202 if ( name == "GPS2" ) { // the CPV is a PPSD
203 if( gMC->CurrentVolID(copy) == gMC->VolId("GCEL") ) // We are inside a gas cell
204 {
205 gMC->TrackPosition(pos) ;
206 xyze[0] = pos[0] ;
207 xyze[1] = pos[1] ;
208 xyze[2] = pos[2] ;
5f20d3fb 209 xyze[3] = gMC->Edep() ;
bea63bea 210
211 if ( xyze[3] != 0 ) { // there is deposited energy
212 gMC->CurrentVolOffID(5, relid[0]) ; // get the PHOS Module number
213 gMC->CurrentVolOffID(3, relid[1]) ; // get the Micromegas Module number
214 // 1-> Geom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() upper
215 // > fGeom->GetNumberOfModulesPhi() * fGeom->GetNumberOfModulesZ() lower
216 gMC->CurrentVolOffID(1, relid[2]) ; // get the row number of the cell
217 gMC->CurrentVolID(relid[3]) ; // get the column number
218
219 // get the absolute Id number
220
221 Int_t absid ;
5f20d3fb 222 fGeom->RelToAbsNumbering(relid, absid) ;
bea63bea 223
5f20d3fb 224 // add current hit to the hit list
225 AddHit(fIshunt, primary, tracknumber, absid, xyze);
bea63bea 226
227 } // there is deposited energy
228 } // We are inside the gas of the CPV
229 } // GPS2 configuration
230
5f20d3fb 231 if(gMC->CurrentVolID(copy) == gMC->VolId("PXTL") ) // We are inside a PBWO crystal
bea63bea 232 {
233 gMC->TrackPosition(pos) ;
234 xyze[0] = pos[0] ;
235 xyze[1] = pos[1] ;
236 xyze[2] = pos[2] ;
bea63bea 237 xyze[3] = gMC->Edep() ;
238
bea63bea 239 if ( xyze[3] != 0 ) {
240 gMC->CurrentVolOffID(10, relid[0]) ; // get the PHOS module number ;
5f20d3fb 241 relid[1] = 0 ; // means PBW04
bea63bea 242 gMC->CurrentVolOffID(4, relid[2]) ; // get the row number inside the module
243 gMC->CurrentVolOffID(3, relid[3]) ; // get the cell number inside the module
244
245 // get the absolute Id number
246
247 Int_t absid ;
5f20d3fb 248 fGeom->RelToAbsNumbering(relid, absid) ;
249
250 // add current hit to the hit list
251
252 AddHit(fIshunt, primary,tracknumber, absid, xyze);
bea63bea 253
254 } // there is deposited energy
255 } // we are inside a PHOS Xtal
bea63bea 256}
257