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