]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALv2.cxx
Merge branch 'master_patch'
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALv2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2004, 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 v2 of EMCAL Manager class; SHASHLYK version
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 : Alexei Pavlinov (WSU)
24 //           : Adapted for DCAL by M.L. Wang CCNU Wuhan & Subatech Oct-23-2012
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 #include <cassert>
29 // --- ROOT system ---
30 #include <TBrowser.h>
31 #include <TClonesArray.h>
32 #include <TH2.h>
33 #include <TParticle.h>
34 #include <TROOT.h>
35 #include <TVirtualMC.h>
36
37 // --- Standard library ---
38
39 // --- AliRoot header files ---
40 #include "AliEMCALv2.h"
41 #include "AliEMCALHit.h"
42 #include "AliEMCALGeometry.h"
43 #include "AliRun.h"
44 #include "AliHeader.h"
45 #include "AliMC.h"
46 #include "AliStack.h"
47 #include "AliTrackReference.h"
48 // for TRD1 case only; May 31,2006
49
50 ClassImp(AliEMCALv2)
51
52 //______________________________________________________________________
53 AliEMCALv2::AliEMCALv2()
54   : AliEMCALv1()
55 {
56   // ctor
57 }
58
59 //______________________________________________________________________
60 AliEMCALv2::AliEMCALv2(const char *name, const char *title, 
61                        const Bool_t checkGeoAndRun)
62   : AliEMCALv1(name,title,checkGeoAndRun)
63 {
64     // Standard Creator.
65
66     //fHits= new TClonesArray("AliEMCALHit",1000); //Already done in ctor of v1
67     gAlice->GetMCApp()->AddHitList(fHits);
68
69     fNhits    = 0;
70     fIshunt   = 2; // All hits are associated with particles entering the calorimeter
71     fTimeCut  = 30e-09;
72   
73     fGeometry = GetGeometry(); 
74 }
75
76 //______________________________________________________________________
77 AliEMCALv2::~AliEMCALv2(){
78     // dtor
79
80   //Already done in dtor of v1
81 //  if ( fHits ) {
82 //    fHits->Clear();
83 //    delete fHits;
84 //    fHits = 0;
85 //  }
86 }
87
88 //______________________________________________________________________
89 void AliEMCALv2::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     static Int_t hitCounter;
95     static AliEMCALHit *newHit, *curHit;
96     static Bool_t deja ;
97   
98     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             //            break; // 30-aug-04 by PAI 
111         } // end if
112     } // end for hitCounter
113     
114     if ( !deja ) {
115         new((*fHits)[fNhits]) AliEMCALHit(*newHit);
116         fNhits++;
117     }
118     //    printf(" fNhits %i \n", fNhits); 
119     delete newHit;
120 }
121
122 //______________________________________________________________________
123 void AliEMCALv2::StepManager(void){
124   // Accumulates hits as long as the track stays in a tower
125
126   // position wrt MRS and energy deposited
127   static Float_t        xyzte[5]={0.,0.,0.,0.,0.};// position wrt MRS, time and energy deposited
128   static Float_t        pmom[4]={0.,0.,0.,0.};
129   static TLorentzVector pos;  // Lorentz vector of the track current position.
130   static TLorentzVector mom;  // Lorentz vector of the track current momentum.
131   static Float_t ienergy = 0; // part->Energy();
132   static TString curVolName="";
133   static int supModuleNumber=-1, moduleNumber=-1, yNumber=-1, xNumber=-1, absid=-1;
134   static int keyGeom=1;  //real TRD1 geometry
135   static const char *vn = "SCMX"; // Apr 13, 2006 - only TRD1 case now
136   static Float_t depositedEnergy=0.0; 
137
138   if(keyGeom == 0) {
139     keyGeom = 2;
140     if(TVirtualMC::GetMC()->VolId("PBMO")==0 || TVirtualMC::GetMC()->VolId("WSUC")==1) {
141       vn      = "SCMX";   // old TRD2(TRD1) or WSUC
142       keyGeom = 1;
143     }    
144     printf("AliEMCALv2::StepManager():  keyGeom %i : Sensetive volume %s \n", 
145     keyGeom, vn); 
146     if(TVirtualMC::GetMC()->VolId("WSUC")==1) printf(" WSUC - cosmic ray stand geometry \n");
147   }
148   Int_t tracknumber =  gAlice->GetMCApp()->GetCurrentTrackNumber();
149   Int_t parent=0;
150   TParticle* part=0;
151
152   curVolName = TVirtualMC::GetMC()->CurrentVolName();
153   if(curVolName.Contains(vn) || curVolName.Contains("SCX")) { // We are in a scintillator layer; SCX for 3X3
154     
155     if( ((depositedEnergy = TVirtualMC::GetMC()->Edep()) > 0.)  && (TVirtualMC::GetMC()->TrackTime() < fTimeCut)){// Track is inside a scintillator and deposits some energy
156       //       Info("StepManager "," entry %i DE %f",++ientry, depositedEnergy); // for testing
157        if (fCurPrimary==-1) 
158         fCurPrimary=gAlice->GetMCApp()->GetPrimary(tracknumber);
159
160       if (fCurParent==-1 || tracknumber != fCurTrack) {
161         // Check parentage
162         parent=tracknumber;
163
164         if (fCurParent != -1) {
165           while (parent != fCurParent && parent != -1) {
166             //TParticle *part=gAlice->GetMCApp()->Particle(parent);
167             part=gAlice->GetMCApp()->Particle(parent);
168             parent=part->GetFirstMother();
169           }
170         }
171         if (fCurParent==-1 || parent==-1) {
172           //Int_t parent=tracknumber;
173           //TParticle *part=gAlice->GetMCApp()->Particle(parent);
174           parent=tracknumber;
175           part=gAlice->GetMCApp()->Particle(parent);
176           while (parent != -1 && fGeometry->IsInEMCALOrDCAL(part->Vx(),part->Vy(),part->Vz())) {
177             parent=part->GetFirstMother();
178             if (parent!=-1) 
179               part=gAlice->GetMCApp()->Particle(parent);
180           } 
181           fCurParent=parent;
182           if (fCurParent==-1)
183             Error("StepManager","Cannot find parent");
184           else {
185             //TParticle *part=gAlice->GetMCApp()->Particle(fCurParent);
186             part=gAlice->GetMCApp()->Particle(fCurParent);
187             ienergy = part->Energy(); 
188
189             //Add reference to parent in TR tree.       
190             AddTrackReference(tracknumber, AliTrackReference::kEMCAL);
191
192           }
193           while (parent != -1) {
194             part=gAlice->GetMCApp()->Particle(parent);
195             part->SetBit(kKeepBit);
196             parent=part->GetFirstMother();
197           }
198         }
199         fCurTrack=tracknumber;
200       }    
201       TVirtualMC::GetMC()->TrackPosition(pos);
202       xyzte[0] = pos[0];
203       xyzte[1] = pos[1];
204       xyzte[2] = pos[2];
205       xyzte[3] = TVirtualMC::GetMC()->TrackTime() ;       
206       
207       TVirtualMC::GetMC()->TrackMomentum(mom);
208       pmom[0] = mom[0];
209       pmom[1] = mom[1];
210       pmom[2] = mom[2];
211       pmom[3] = mom[3];
212       
213       //      if(ientry%200 > 0) return; // testing
214       supModuleNumber = moduleNumber = yNumber = xNumber = absid = 0;
215       if(keyGeom >= 1) { // TRD1 case now
216         TVirtualMC::GetMC()->CurrentVolOffID(4, supModuleNumber);
217         TVirtualMC::GetMC()->CurrentVolOffID(3, moduleNumber);
218         TVirtualMC::GetMC()->CurrentVolOffID(1, yNumber);
219         TVirtualMC::GetMC()->CurrentVolOffID(0, xNumber); // really x number now
220         Int_t CurrentSMType = 0;
221         if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"SMOD")==0)  CurrentSMType = AliEMCALGeometry::kEMCAL_Standard ;
222         else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"SM10")==0)  CurrentSMType = AliEMCALGeometry::kEMCAL_Half ;
223         else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"SM3rd")==0) CurrentSMType = AliEMCALGeometry::kEMCAL_3rd  ;
224         else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"DCSM")==0)  CurrentSMType = AliEMCALGeometry::kDCAL_Standard ;
225         else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"DCEXT")==0) CurrentSMType = AliEMCALGeometry::kDCAL_Ext   ;
226         else AliError("Unkown SM Type!!");
227
228         Int_t preSM = 0;
229         while( fGeometry->GetSMType(preSM) != CurrentSMType ) preSM++;
230         supModuleNumber += preSM;
231         // Nov 10,2006
232         if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(0),vn) != 0) { // 3X3 case
233           if     (strcmp(TVirtualMC::GetMC()->CurrentVolOffName(0),"SCX1")==0) xNumber=1;
234           else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(0),"SCX2")==0) xNumber=2;
235           else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(0),"SCX3")==0) xNumber=3;
236           else Fatal("StepManager()", "Wrong name of sensitive volume in 3X3 case : %s ", TVirtualMC::GetMC()->CurrentVolOffName(0));
237         }
238       } else {
239         TVirtualMC::GetMC()->CurrentVolOffID(5, supModuleNumber);
240         TVirtualMC::GetMC()->CurrentVolOffID(4, moduleNumber);
241         TVirtualMC::GetMC()->CurrentVolOffID(1, yNumber);
242         TVirtualMC::GetMC()->CurrentVolOffID(0, xNumber);
243         if     (strcmp(TVirtualMC::GetMC()->CurrentVolOffName(5),"SMOP")==0) supModuleNumber = 2*(supModuleNumber-1)+1;
244         else if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(5),"SMON")==0) supModuleNumber = 2*(supModuleNumber-1)+2;
245         else   assert(0); // something wrong
246       }
247                 
248       // Due to problem with index ordering conventions the calcultation of absid is no more like this: 
249       //absid = fGeometry->GetAbsCellId(smNumber, moduleNumber-1, yNumber-1, xNumber-1);
250       
251       //Swap A side in Phi and C side in Eta due to wrong indexing.
252       Int_t iphi = -1;
253       Int_t ieta = -1;
254       Int_t smNumber = supModuleNumber-1;
255       Int_t smType   = 1;
256       fGeometry->GetCellPhiEtaIndexInSModule(smNumber,moduleNumber-1,yNumber-1,xNumber-1, iphi, ieta);
257       if (smNumber%2 == 0) {
258         if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"DCSM")==0) smType = 3; //DCal supermodule. previous design/idea
259         else smType = 2;
260         ieta = ((fGeometry->GetCentersOfCellsEtaDir()).GetSize()* 2/smType -1)-ieta;// 47/31-ieta, revert the ordering on A side in order to keep convention.
261       } else {  
262         if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"SM10")==0) smType = 2 ; //half supermodule. previous design/idea
263         if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"SM3rd")==0) smType = 3 ; //one third (installed in 2012) supermodule
264         if(strcmp(TVirtualMC::GetMC()->CurrentVolOffName(4),"DCEXT")==0) smType = 3 ; //one third (installed in 2012) supermodule
265         iphi= ((fGeometry->GetCentersOfCellsPhiDir()).GetSize()/smType-1)-iphi;// 23/7-iphi, revert the ordering on C side in order to keep convention.
266       }
267       
268       //Once we know the indexes, calculate the absolute ID
269       absid = fGeometry->GetAbsCellIdFromCellIndexes(smNumber, iphi, ieta);
270       
271       if (absid < 0) {
272         printf(" supModuleNumber %i : moduleNumber %i : yNumber %i : xNumber %i \n",
273                supModuleNumber, moduleNumber, yNumber, xNumber); 
274         Fatal("StepManager()", "Wrong id : %i ", absid) ; 
275       }
276
277       Float_t lightYield =  depositedEnergy ;
278       // Apply Birk's law (copied from G3BIRK)
279
280       if (TVirtualMC::GetMC()->TrackCharge()!=0) { // Check
281           Float_t birkC1Mod = 0;
282         if (fBirkC0==1){ // Apply correction for higher charge states
283           if (TMath::Abs(TVirtualMC::GetMC()->TrackCharge())>=2) birkC1Mod = fBirkC1*7.2/12.6;
284           else                                   birkC1Mod = fBirkC1;
285         }
286
287         Float_t dedxcm=0.;
288         if (TVirtualMC::GetMC()->TrackStep()>0)  dedxcm=1000.*TVirtualMC::GetMC()->Edep()/TVirtualMC::GetMC()->TrackStep();
289         else                     dedxcm=0;
290         lightYield=lightYield/(1.+birkC1Mod*dedxcm+fBirkC2*dedxcm*dedxcm);
291       } 
292
293       // use sampling fraction to get original energy --HG
294       //      xyzte[4] = lightYield * fGeometry->GetSampling();
295       xyzte[4] = lightYield; // 15-dec-04
296         
297       if (gDebug == -2) 
298       printf("#sm %2i #m %3i #x %1i #z %1i -> absid %i : xyzte[4] = %f\n",
299       supModuleNumber,moduleNumber,yNumber,xNumber,absid, xyzte[4]);
300
301       AddHit(fIshunt, fCurPrimary,tracknumber, fCurParent, ienergy, absid,  xyzte, pmom);
302     } // there is deposited energy
303   }
304 }