]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALv1.cxx
First commit of EMCAL Track matching code (A. Pulvirenti)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALv1.cxx
CommitLineData
b13bbe81 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//_________________________________________________________________________
fdebddeb 19//*-- Implementation version v1 of EMCAL Manager class
20//*-- An object of this class does not produce digits
21//*-- It is the one to use if you do want to produce outputs in TREEH
22//*--
b13bbe81 23//*-- Author: Sahal Yacoob (LBL /UCT)
24//*-- : Jennifer Klay (LBL)
fceb09ed 25// This Class not stores information on all particles prior to EMCAL entry - in order to facilitate analysis.
26// This is done by setting fIShunt =2, and flagging all parents of particles entering the EMCAL.
27
1f4d29d2 28// 15/02/2002 .... Yves Schutz
29// 1. fSamplingFraction and fLayerToPreshowerRatio have been removed
30// 2. Timing signal is collected and added to hit
b13bbe81 31
32// --- ROOT system ---
cde6a23d 33#include <TParticle.h>
34#include <TVirtualMC.h>
b13bbe81 35
36// --- Standard library ---
37
b13bbe81 38// --- AliRoot header files ---
b13bbe81 39#include "AliEMCALv1.h"
40#include "AliEMCALHit.h"
41#include "AliEMCALGeometry.h"
b13bbe81 42#include "AliRun.h"
5d12ce38 43#include "AliMC.h"
b13bbe81 44
45ClassImp(AliEMCALv1)
46
47
48//______________________________________________________________________
18a21c7c 49AliEMCALv1::AliEMCALv1()
50 : AliEMCALv0(),
51 fCurPrimary(-1),
52 fCurParent(-1),
53 fCurTrack(-1),
54 fTimeCut(30e-09)
55{
56 // default ctor
b13bbe81 57}
1f4d29d2 58
b13bbe81 59//______________________________________________________________________
18a21c7c 60AliEMCALv1::AliEMCALv1(const char *name, const char *title)
61 : AliEMCALv0(name,title),
62 fCurPrimary(-1),
63 fCurParent(-1),
64 fCurTrack(-1),
65 fTimeCut(30e-09)
66{
b13bbe81 67 // Standard Creator.
68
69 fHits= new TClonesArray("AliEMCALHit",1000);
1963b290 70 // gAlice->GetMCApp()->AddHitList(fHits); // 20-dec-04 - advice of Andreas
b13bbe81 71
72 fNhits = 0;
fceb09ed 73 fIshunt = 2; // All hits are associated with particles entering the calorimeter
b13bbe81 74}
1f4d29d2 75
0a4cb131 76//______________________________________________________________________
18a21c7c 77AliEMCALv1::AliEMCALv1(const AliEMCALv1 & emcal)
78 : AliEMCALv0(emcal),
79 fCurPrimary(emcal.fCurPrimary),
80 fCurParent(emcal.fCurParent),
81 fCurTrack(emcal.fCurTrack),
82 fTimeCut(emcal.fTimeCut)
0a4cb131 83{
84 //copy ctor
0a4cb131 85}
86
b13bbe81 87//______________________________________________________________________
88AliEMCALv1::~AliEMCALv1(){
89 // dtor
90
91 if ( fHits) {
92 fHits->Delete();
93 delete fHits;
94 fHits = 0;
95 }
96}
ab37d09c 97
b13bbe81 98//______________________________________________________________________
61e0abb5 99void AliEMCALv1::AddHit(Int_t shunt, Int_t primary, Int_t tracknumber, Int_t iparent, Float_t ienergy,
100 Int_t id, Float_t * hits,Float_t * p){
b13bbe81 101 // Add a hit to the hit list.
fdebddeb 102 // An EMCAL hit is the sum of all hits in a tower section
7b6cc0b5 103 // originating from the same entering particle
b13bbe81 104 Int_t hitCounter;
105
106 AliEMCALHit *newHit;
107 AliEMCALHit *curHit;
108 Bool_t deja = kFALSE;
109
61e0abb5 110 newHit = new AliEMCALHit(shunt, primary, tracknumber, iparent, ienergy, id, hits, p);
fdebddeb 111 for ( hitCounter = fNhits-1; hitCounter >= 0 && !deja; hitCounter-- ) {
b13bbe81 112 curHit = (AliEMCALHit*) (*fHits)[hitCounter];
61e0abb5 113 // We add hits with the same tracknumber, while GEANT treats
b13bbe81 114 // primaries succesively
7b6cc0b5 115 if(curHit->GetPrimary() != primary)
116 break;
b13bbe81 117 if( *curHit == *newHit ) {
118 *curHit = *curHit + *newHit;
119 deja = kTRUE;
fdebddeb 120 } // end if
b13bbe81 121 } // end for hitCounter
fdebddeb 122
b13bbe81 123 if ( !deja ) {
124 new((*fHits)[fNhits]) AliEMCALHit(*newHit);
125 fNhits++;
126 } // end if
1963b290 127
b13bbe81 128 delete newHit;
129}
130//______________________________________________________________________
131void AliEMCALv1::StepManager(void){
8ddf73e5 132 // Accumulates hits as long as the track stays in a tower
1f4d29d2 133
fdebddeb 134 Int_t id[2]; // (phi, Eta) indices
1f4d29d2 135 // position wrt MRS and energy deposited
136 Float_t xyzte[5]={0.,0.,0.,0.,0.};// position wrt MRS, time and energy deposited
137 Float_t pmom[4]={0.,0.,0.,0.};
138 TLorentzVector pos; // Lorentz vector of the track current position.
139 TLorentzVector mom; // Lorentz vector of the track current momentum.
5d12ce38 140 Int_t tracknumber = gAlice->GetMCApp()->GetCurrentTrackNumber();
1f4d29d2 141 static Float_t ienergy = 0;
142 Int_t copy = 0;
1f4d29d2 143
05a92d59 144 AliEMCALGeometry * geom = GetGeometry() ;
145
d6fb41ac 146 static Int_t idXPHI = gMC->VolId("XPHI");
147 if(gMC->CurrentVolID(copy) == idXPHI ) { // We are in a Scintillator Layer
dfce7eb2 148 Float_t depositedEnergy ;
61e0abb5 149
9b358506 150 if( ((depositedEnergy = gMC->Edep()) > 0.) && (gMC->TrackTime() < fTimeCut)){// Track is inside a scintillator and deposits some energy
ab37d09c 151 if (fCurPrimary==-1)
152 fCurPrimary=gAlice->GetMCApp()->GetPrimary(tracknumber);
153
154 if (fCurParent==-1 || tracknumber != fCurTrack) {
155 // Check parentage
156 Int_t parent=tracknumber;
157 if (fCurParent != -1) {
158 while (parent != fCurParent && parent != -1) {
159 TParticle *part=gAlice->GetMCApp()->Particle(parent);
160 parent=part->GetFirstMother();
161 }
162 }
163 if (fCurParent==-1 || parent==-1) {
164 Int_t parent=tracknumber;
165 TParticle *part=gAlice->GetMCApp()->Particle(parent);
166 while (parent != -1 && geom->IsInEMCAL(part->Vx(),part->Vy(),part->Vz())) {
167 parent=part->GetFirstMother();
168 if (parent!=-1)
169 part=gAlice->GetMCApp()->Particle(parent);
170 }
171 fCurParent=parent;
172 if (fCurParent==-1)
173 Error("StepManager","Cannot find parent");
174 else {
175 TParticle *part=gAlice->GetMCApp()->Particle(fCurParent);
176 ienergy = part->Energy();
177 }
178 while (parent != -1) {
179 part=gAlice->GetMCApp()->Particle(parent);
180 part->SetBit(kKeepBit);
181 parent=part->GetFirstMother();
182 }
183 }
184 fCurTrack=tracknumber;
185 }
dfce7eb2 186 gMC->TrackPosition(pos);
187 xyzte[0] = pos[0];
188 xyzte[1] = pos[1];
189 xyzte[2] = pos[2];
190 xyzte[3] = gMC->TrackTime() ;
191
192 gMC->TrackMomentum(mom);
193 pmom[0] = mom[0];
194 pmom[1] = mom[1];
195 pmom[2] = mom[2];
196 pmom[3] = mom[3];
197
198 gMC->CurrentVolOffID(1, id[0]); // get the POLY copy number;
199 gMC->CurrentVolID(id[1]); // get the phi number inside the layer
dfce7eb2 200
de56e4f9 201 Int_t tower = (id[0]-1) % geom->GetNZ() + 1 + (id[1] - 1) * geom->GetNZ() ;
7b6cc0b5 202 Int_t layer = static_cast<Int_t>((id[0]-1)/(geom->GetNZ())) + 1 ;
fdebddeb 203 Int_t absid = tower;
204 Int_t nlayers = geom->GetNECLayers();
205 if ((layer > nlayers)||(layer<1))
206 Fatal("StepManager", "Wrong calculation of layer number: layer = %d > %d\n", layer, nlayers) ;
207
7b6cc0b5 208 Float_t lightYield = depositedEnergy ;
ab37d09c 209 // Apply Birk's law (copied from G3BIRK)
210
211 if (gMC->TrackCharge()!=0) { // Check
cde6a23d 212 Float_t birkC1Mod = 0;
ab37d09c 213 if (fBirkC0==1){ // Apply correction for higher charge states
41289e86 214 if (TMath::Abs(gMC->TrackCharge())>=2)
cde6a23d 215 birkC1Mod=fBirkC1*7.2/12.6;
ab37d09c 216 else
cde6a23d 217 birkC1Mod=fBirkC1;
ab37d09c 218 }
219 Float_t dedxcm;
220 if (gMC->TrackStep()>0)
221 dedxcm=1000.*gMC->Edep()/gMC->TrackStep();
222 else
223 dedxcm=0;
cde6a23d 224 lightYield=lightYield/(1.+birkC1Mod*dedxcm+fBirkC2*dedxcm*dedxcm);
ab37d09c 225 }
7b6cc0b5 226
ab37d09c 227 // use sampling fraction to get original energy --HG
228 xyzte[4] = lightYield * geom->GetSampling();
229
7b6cc0b5 230 if (gDebug == 2)
fdebddeb 231 printf("StepManager: id0 = %d, id1 = %d, absid = %d tower = %d layer = %d energy = %f\n", id[0], id[1], absid, tower, layer, xyzte[4]) ;
7b6cc0b5 232
ab37d09c 233 AddHit(fIshunt, fCurPrimary,tracknumber, fCurParent, ienergy, absid, xyzte, pmom);
b13bbe81 234 } // there is deposited energy
1f4d29d2 235 }
b13bbe81 236}
ab37d09c 237
238void AliEMCALv1::RemapTrackHitIDs(Int_t *map) {
239 // remap track index numbers for primary and parent indices
240 // (Called by AliStack::PurifyKine)
241 if (Hits()==0)
242 return;
cde6a23d 243 TIter hitIter(Hits());
244 Int_t iHit=0;
245 while (AliEMCALHit *hit=dynamic_cast<AliEMCALHit*>(hitIter()) ) {
ab37d09c 246 if (map[hit->GetIparent()]==-99)
cde6a23d 247 cout << "Remapping, found -99 for parent id " << hit->GetIparent() << ", " << map[hit->GetIparent()] << ", iHit " << iHit << endl;
ab37d09c 248 hit->SetIparent(map[hit->GetIparent()]);
249 if (map[hit->GetPrimary()]==-99)
cde6a23d 250 cout << "Remapping, found -99 for primary id " << hit->GetPrimary() << ", " << map[hit->GetPrimary()] << ", iHit " << iHit << endl;
ab37d09c 251 hit->SetPrimary(map[hit->GetPrimary()]);
cde6a23d 252 iHit++;
ab37d09c 253 }
254}
255
256void AliEMCALv1::FinishPrimary() {
cde6a23d 257 // finish primary
ab37d09c 258 fCurPrimary=-1;
259 fCurParent=-1;
260 fCurTrack=-1;
261}