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