]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALReconstructor.cxx
Using TArrayI instead of TArrayS for the labels and track indexes (Gustavo)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.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 //*--
20 //*-- Yves Schutz (SUBATECH) 
21 // Reconstruction class. Redesigned from the old AliReconstructionner class and 
22 // derived from STEER/AliReconstructor. 
23 // 
24 // --- ROOT system ---
25
26 // --- Standard library ---
27
28 // --- AliRoot header files ---
29 #include "AliEMCALReconstructor.h"
30
31 #include "AliESDEvent.h"
32 #include "AliESDCaloCluster.h"
33 #include "AliESDtrack.h"
34 #include "AliEMCALLoader.h"
35 #include "AliEMCALRawUtils.h"
36 #include "AliEMCALClusterizerv1.h"
37 #include "AliEMCALRecPoint.h"
38 #include "AliEMCALPID.h"
39 #include "AliEMCALTrigger.h"
40 #include "AliRawReader.h"
41 // to be removed - it is here just because of geom
42 #include "AliRun.h"
43 #include "AliRunLoader.h"
44
45 ClassImp(AliEMCALReconstructor)
46
47 AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0;  // EMCAL rec. parameters
48
49 //____________________________________________________________________________
50 AliEMCALReconstructor::AliEMCALReconstructor() 
51   : fDebug(kFALSE) 
52 {
53   // ctor
54   if (!fgkRecParam) {
55     AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
56     fgkRecParam = new AliEMCALRecParam;
57   }
58
59
60 //____________________________________________________________________________
61 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
62   : AliReconstructor(rec),
63     fDebug(rec.fDebug)
64 {
65   //copy ctor
66 }
67
68 //____________________________________________________________________________
69 AliEMCALReconstructor::~AliEMCALReconstructor()
70 {
71   // dtor
72
73
74 //____________________________________________________________________________
75 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
76 {
77   // method called by AliReconstruction; 
78   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
79   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
80   // the global tracking.
81   // Works on the current event.
82  
83   AliEMCALClusterizerv1 clu;
84   clu.SetInput(digitsTree);
85   clu.SetOutput(clustersTree);
86   if ( Debug() ) 
87     clu.Digits2Clusters("deb all") ; 
88   else 
89     clu.Digits2Clusters("pseudo") ;  
90 }
91
92 //____________________________________________________________________________
93 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
94
95 {
96   // Conversion from raw data to
97   // EMCAL digits.
98   // Works on a single-event basis
99
100   rawReader->Reset() ; 
101
102   TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
103   Int_t bufsize = 32000;
104   digitsTree->Branch("EMCAL", &digitsArr, bufsize);
105
106   static AliEMCALRawUtils rawUtils;
107   rawUtils.Raw2Digits(rawReader,digitsArr);
108
109   digitsTree->Fill();
110   digitsArr->Delete();
111   delete digitsArr;
112
113 }
114
115 //____________________________________________________________________________
116 void AliEMCALReconstructor::FillESD(TTree* /*digitsTree*/, TTree* clustersTree, 
117                                     AliESDEvent* esd) const
118 {
119   // Called by AliReconstruct after Reconstruct() and global tracking and vertexing 
120   // Works on the current event
121   const double timeScale = 1.e+11; // transition constant from sec to 0.01 ns 
122
123   // Creates AliESDCaloCluster from AliEMCALRecPoints 
124
125   TObjArray *clusters = new TObjArray(100);
126   TBranch *branch = clustersTree->GetBranch("EMCALECARP");
127   branch->SetAddress(&clusters);
128   clustersTree->GetEvent(0);
129
130   Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
131   AliDebug(1,Form("%d clusters",nClusters));
132   //  Int_t nRP=0, nPC=0; // in input
133   esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
134
135   //######################################################
136   //#########Calculate trigger and set trigger info###########
137   //######################################################
138  
139   AliEMCALTrigger tr ;
140   //   tr.SetPatchSize(1);//create 4x4 patches
141   tr.Trigger();
142   
143   Float_t maxAmp2x2  = tr.Get2x2MaxAmplitude();
144   Float_t maxAmpnxn  = tr.GetnxnMaxAmplitude();
145   Float_t ampOutOfPatch2x2  = tr.Get2x2AmpOutOfPatch() ;
146   Float_t ampOutOfPatchnxn  = tr.GetnxnAmpOutOfPatch() ;
147
148   AliEMCALGeometry * geom = 0;
149   AliRunLoader *runLoader = AliRunLoader::GetRunLoader();
150   if (runLoader->GetAliRun() && runLoader->GetAliRun()->GetDetector("EMCAL"))
151     geom = dynamic_cast<AliEMCAL*>(runLoader->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
152   if (geom == 0) 
153     geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
154
155   Int_t iSM2x2      = tr.Get2x2SuperModule();
156   Int_t iSMnxn      = tr.GetnxnSuperModule();
157   Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
158   Int_t iCellPhinxn = tr.GetnxnCellPhi();
159   Int_t iCellEta2x2 = tr.Get2x2CellEta();
160   Int_t iCellEtanxn = tr.GetnxnCellEta();
161
162   AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
163   AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",  maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
164
165   TVector3    pos2x2(-1,-1,-1);
166   TVector3    posnxn(-1,-1,-1);
167
168   Int_t iAbsId2x2 = geom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
169   Int_t iAbsIdnxn = geom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
170   geom->GetGlobal(iAbsId2x2, pos2x2);
171   geom->GetGlobal(iAbsIdnxn, posnxn);
172   
173   TArrayF triggerPosition(6);
174   triggerPosition[0] = pos2x2(0) ;   
175   triggerPosition[1] = pos2x2(1) ;   
176   triggerPosition[2] = pos2x2(2) ;  
177   triggerPosition[3] = posnxn(0) ;   
178   triggerPosition[4] = posnxn(1) ;   
179   triggerPosition[5] = posnxn(2) ;  
180
181   TArrayF triggerAmplitudes(4);
182   triggerAmplitudes[0] = maxAmp2x2 ;   
183   triggerAmplitudes[1] = ampOutOfPatch2x2 ;    
184   triggerAmplitudes[2] = maxAmpnxn ;   
185   triggerAmplitudes[3] = ampOutOfPatchnxn ;   
186
187   esd->AddEMCALTriggerPosition(triggerPosition);
188   esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
189   
190   //######################################################
191   //#######################TRACK MATCHING###############
192   //######################################################
193   //Fill list of integers, each one is index of track to which the cluster belongs.
194
195   // step 1 - initialize array of matched track indexes
196   Int_t *matchedTrack = new Int_t[nClusters];
197   for (Int_t iclus = 0; iclus < nClusters; iclus++)
198     matchedTrack[iclus] = -1;  // neg. index --> no matched track
199   
200   // step 2, change the flag for all matched clusters found in tracks
201   Int_t iemcalMatch = -1;
202   Int_t endtpc = esd->GetNumberOfTracks();
203   for (Int_t itrack = 0; itrack < endtpc; itrack++) {
204     AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
205     iemcalMatch = track->GetEMCALcluster();
206     if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
207   } 
208   
209   //########################################
210   //##############Fill CaloClusters#############
211   //########################################
212
213
214   for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
215     const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
216     //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
217     if (Debug()) clust->Print();
218     // Get information from EMCAL reconstruction points
219     Float_t xyz[3];
220     TVector3 gpos;
221     clust->GetGlobalPosition(gpos);
222     for (Int_t ixyz=0; ixyz<3; ixyz++) 
223       xyz[ixyz] = gpos[ixyz];
224     
225     Int_t digitMult = clust->GetMultiplicity();
226     TArrayS amplList(digitMult);
227     TArrayS timeList(digitMult);
228     TArrayS digiList(digitMult);
229     Float_t *amplFloat = clust->GetEnergiesList();
230     Float_t *timeFloat = clust->GetTimeList();
231     Int_t   *digitInts = clust->GetAbsId();
232     Float_t elipAxis[2];
233     clust->GetElipsAxis(elipAxis);
234     
235     // Convert Float_t* and Int_t* to Short_t* to save memory
236     // Problem : we should recalculate a cluster characteristics when discard digit(s)
237     Int_t newdigitMult = 0; 
238     for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
239       if (amplFloat[iDigit] > 0) {
240         amplList[newdigitMult] = (UShort_t)(amplFloat[iDigit]*500);
241         // Time in units of 0.01 ns = 10 ps
242         if(timeFloat[iDigit] < 65536./timeScale) 
243           timeList[newdigitMult] = (UShort_t)(timeFloat[iDigit]*timeScale);
244         else
245           timeList[newdigitMult] = 65535;
246         digiList[newdigitMult] = (UShort_t)(digitInts[iDigit]);
247         newdigitMult++;
248       }
249       else if (clust->GetClusterType() != AliESDCaloCluster::kEMCALPseudoCluster)
250         Warning("FillESD()","Negative or 0 digit amplitude in cluster");
251     }
252     
253     if(newdigitMult > 0) { // accept cluster if it has some digit
254       nClustersNew++;
255       
256       amplList.Set(newdigitMult);
257       timeList.Set(newdigitMult);
258       digiList.Set(newdigitMult);
259
260       //Primaries
261       Int_t  parentMult  = 0;
262       Int_t *parentList =  clust->GetParents(parentMult); 
263     
264       // fills the ESDCaloCluster
265       AliESDCaloCluster * ec = new AliESDCaloCluster() ; 
266       ec->SetClusterType(clust->GetClusterType());
267       ec->SetPosition(xyz);
268       ec->SetE(clust->GetEnergy());
269       ec->AddDigitAmplitude(amplList);
270       ec->AddDigitTime(timeList);
271       ec->AddDigitIndex(digiList);
272     
273       if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1){
274
275         ec->SetClusterDisp(clust->GetDispersion());
276         ec->SetClusterChi2(-1); //not yet implemented
277         ec->SetM02(elipAxis[0]*elipAxis[0]) ;
278         ec->SetM20(elipAxis[1]*elipAxis[1]) ;
279         ec->SetM11(-1) ;        //not yet implemented
280         
281        TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
282        arrayTrackMatched[0]= matchedTrack[iClust];
283        ec->AddTracksMatched(arrayTrackMatched);
284         
285        TArrayI arrayParents(parentMult,parentList);
286        ec->AddLabels(arrayParents);
287       } 
288       
289       // add the cluster to the esd object
290       esd->AddCaloCluster(ec);
291       delete ec;
292     }
293
294   } // cycle on clusters
295
296   delete [] matchedTrack;
297
298   esd->SetNumberOfEMCALClusters(nClustersNew);
299   //if(nClustersNew != nClusters) 
300   //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
301   
302   //Fill ESDCaloCluster with PID weights
303   AliEMCALPID *pid = new AliEMCALPID;
304   //pid->SetPrintInfo(kTRUE);
305   pid->SetReconstructor(kTRUE);
306   pid->RunPID(esd);
307   delete pid;
308 }
309
310