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