]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALReconstructor.cxx
Cluster with index 0 now considered for track matching
[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 "AliRun.h"
32 #include "AliESD.h"
33 #include "AliESDtrack.h"
34 #include "AliRunLoader.h"
35 #include "AliEMCALLoader.h"
36 #include "AliEMCALRawUtils.h"
37 #include "AliEMCALClusterizerv1.h"
38 #include "AliEMCALRecPoint.h"
39 #include "AliEMCALPID.h"
40 #include "AliEMCALTrigger.h"
41 #include "AliRawReader.h"
42
43
44 ClassImp(AliEMCALReconstructor)
45
46 //____________________________________________________________________________
47 AliEMCALReconstructor::AliEMCALReconstructor() 
48   : fDebug(kFALSE) 
49 {
50   // ctor
51
52
53 //____________________________________________________________________________
54 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
55   : AliReconstructor(rec),
56     fDebug(rec.fDebug)
57 {
58   //copy ctor
59 }
60
61 //____________________________________________________________________________
62 AliEMCALReconstructor::~AliEMCALReconstructor()
63 {
64   // dtor
65
66
67 //____________________________________________________________________________
68 void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader) const 
69 {
70   // method called by AliReconstruction; 
71   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
72   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
73   // the global tracking.
74  
75   TString headerFile(runLoader->GetFileName()) ; 
76   TString branchName(runLoader->GetEventFolder()->GetName() ) ;  
77   
78   AliEMCALClusterizerv1 clu(headerFile, branchName);
79   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(runLoader->GetDetectorLoader("EMCAL"));    
80
81   Int_t nEvents   = runLoader->GetNumberOfEvents();
82   runLoader->LoadDigits("EMCAL");
83   for (Int_t ievent = 0; ievent < nEvents; ievent++) {
84     runLoader->GetEvent(ievent);
85     if ( Debug() ) 
86       clu.ExecuteTask("deb all") ; 
87     else 
88       clu.ExecuteTask("pseudo") ;  
89   }   
90   // Unload the Digits and RecPoints
91   emcalLoader->UnloadDigits() ; 
92   emcalLoader->UnloadRecPoints() ; 
93 }
94
95 //____________________________________________________________________________
96 void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const 
97
98 {
99   // Reconstruction loop for Raw Data processing
100   //
101   // Only the clusterization is performed
102   // Track-cluster matching is done in FillESD because the track
103   // segment maker needs access to the AliESD object to retrieve 
104   // the tracks reconstructed by the global tracking.
105   
106   TString headerFile(runLoader->GetFileName()) ; 
107   TString branchName(runLoader->GetEventFolder()->GetName()) ;  
108
109   static AliEMCALRawUtils rawUtils;
110   AliEMCALClusterizerv1 clu(headerFile, branchName);
111   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(runLoader->GetDetectorLoader("EMCAL"));    
112  
113   Int_t iEvent = 0;
114   rawReader->Reset() ; 
115   while (rawReader->NextEvent()) {  
116     runLoader->GetEvent(iEvent++);
117
118     rawUtils.Raw2Digits(rawReader);
119
120     if ( Debug() ) 
121       clu.ExecuteTask("deb pseudo all") ; 
122     else 
123       clu.ExecuteTask("pseudo") ;  
124     // Unload the RecPoints
125     emcalLoader->UnloadRecPoints() ; 
126   }
127 }
128
129 //____________________________________________________________________________
130 void AliEMCALReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
131 {
132   // Called by AliReconstruct after Reconstruct() and global tracking and vertexing 
133   const double timeScale = 1.e+11; // transition constant from sec to 0.01 ns 
134
135   Int_t eventNumber = runLoader->GetEventNumber() ;
136
137   // Creates AliESDCaloCluster from AliEMCALRecPoints 
138   AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(runLoader->GetDetectorLoader("EMCAL"));
139   runLoader->LoadRecPoints("EMCAL");
140   runLoader->GetEvent(eventNumber);
141   TObjArray *clusters = emcalLoader->RecPoints();
142   Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
143   AliDebug(1,Form("Event %d: %d clusters",eventNumber,nClusters));
144   //  Int_t nRP=0, nPC=0; // in input
145   esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
146
147   //######################################################
148   //#########Calculate trigger and set trigger info###########
149   //######################################################
150  
151   AliEMCALTrigger tr ;
152   //   tr.SetPatchSize(1);//create 4x4 patches
153   tr.Trigger();
154   
155   Float_t maxAmp2x2  = tr.Get2x2MaxAmplitude();
156   Float_t maxAmpnxn  = tr.GetnxnMaxAmplitude();
157   Float_t ampOutOfPatch2x2  = tr.Get2x2AmpOutOfPatch() ;
158   Float_t ampOutOfPatchnxn  = tr.GetnxnAmpOutOfPatch() ;
159
160   AliEMCALGeometry * geom = 0;
161   if (runLoader->GetAliRun() && runLoader->GetAliRun()->GetDetector("EMCAL"))
162     geom = dynamic_cast<AliEMCAL*>(runLoader->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
163   if (geom == 0) 
164     geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
165
166   Int_t iSM2x2      = tr.Get2x2SuperModule();
167   Int_t iSMnxn      = tr.GetnxnSuperModule();
168   Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
169   Int_t iCellPhinxn = tr.GetnxnCellPhi();
170   Int_t iCellEta2x2 = tr.Get2x2CellEta();
171   Int_t iCellEtanxn = tr.GetnxnCellEta();
172
173   AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",  maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
174   AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",  maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
175
176   TVector3    pos2x2(-1,-1,-1);
177   TVector3    posnxn(-1,-1,-1);
178
179   Int_t iAbsId2x2 = geom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
180   Int_t iAbsIdnxn = geom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
181   geom->GetGlobal(iAbsId2x2, pos2x2);
182   geom->GetGlobal(iAbsIdnxn, posnxn);
183   
184   TArrayF triggerPosition(6);
185   triggerPosition[0] = pos2x2(0) ;   
186   triggerPosition[1] = pos2x2(1) ;   
187   triggerPosition[2] = pos2x2(2) ;  
188   triggerPosition[3] = posnxn(0) ;   
189   triggerPosition[4] = posnxn(1) ;   
190   triggerPosition[5] = posnxn(2) ;  
191
192   TArrayF triggerAmplitudes(4);
193   triggerAmplitudes[0] = maxAmp2x2 ;   
194   triggerAmplitudes[1] = ampOutOfPatch2x2 ;    
195   triggerAmplitudes[2] = maxAmpnxn ;   
196   triggerAmplitudes[3] = ampOutOfPatchnxn ;   
197
198   esd->AddEMCALTriggerPosition(triggerPosition);
199   esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
200   
201   //######################################################
202   //#######################TRACK MATCHING###############
203   //######################################################
204   //Fill list of integers, each one is index of track to which the cluster belongs.
205
206   // step 1 - initialize array of matched track indexes
207   Int_t *matchedTrack = new Int_t[nClusters];
208   for (Int_t iclus = 0; iclus < nClusters; iclus++)
209     matchedTrack[iclus] = -1;  // neg. index --> no matched track
210   
211   // step 2, change the flag for all matched clusters found in tracks
212   Int_t iemcalMatch = -1;
213   Int_t endtpc = esd->GetNumberOfTracks();
214   for (Int_t itrack = 0; itrack < endtpc; itrack++) {
215     AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
216     iemcalMatch = track->GetEMCALcluster();
217     if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
218   } 
219   
220   //########################################
221   //##############Fill CaloClusters#############
222   //########################################
223
224
225   for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
226     const AliEMCALRecPoint * clust = emcalLoader->RecPoint(iClust);
227     //if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1) nRP++; else nPC++;
228     if (Debug()) clust->Print();
229     // Get information from EMCAL reconstruction points
230     Float_t xyz[3];
231     TVector3 gpos;
232     clust->GetGlobalPosition(gpos);
233     for (Int_t ixyz=0; ixyz<3; ixyz++) 
234       xyz[ixyz] = gpos[ixyz];
235
236     Int_t digitMult = clust->GetMultiplicity();
237     UShort_t *amplList = new UShort_t[digitMult];
238     UShort_t *timeList = new UShort_t[digitMult];
239     UShort_t *digiList = new UShort_t[digitMult];
240     Float_t *amplFloat = clust->GetEnergiesList();
241     Float_t *timeFloat = clust->GetTimeList();
242     Int_t   *digitInts = clust->GetAbsId();
243     Float_t elipAxis[2];
244     clust->GetElipsAxis(elipAxis);
245
246     // Convert Float_t* and Int_t* to UShort_t* to save memory
247     // Problem : we should recalculate a cluster characteristics when discard digit(s)
248     Int_t newdigitMult = 0; 
249     for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
250       if (amplFloat[iDigit] > 0) {
251         amplList[newdigitMult] = (UShort_t)(amplFloat[iDigit]*500);
252         // Time in units of 0.01 ns = 10 ps
253         if(timeFloat[iDigit] < 65536./timeScale) 
254           timeList[newdigitMult] = (UShort_t)(timeFloat[iDigit]*timeScale);
255         else
256           timeList[newdigitMult] = 65535;
257         digiList[newdigitMult] = (UShort_t)(digitInts[iDigit]);
258         newdigitMult++;
259       }
260       else if (clust->GetClusterType() != AliESDCaloCluster::kPseudoCluster)
261         Warning("FillESD()","Negative or 0 digit amplitude in cluster");
262     }
263
264     if(newdigitMult > 0) { // accept cluster if it has some digit
265       nClustersNew++;
266       if(newdigitMult != digitMult) { // some digits were deleted
267         UShort_t *amplListNew = new UShort_t[newdigitMult];
268         UShort_t *timeListNew = new UShort_t[newdigitMult];
269         UShort_t *digiListNew = new UShort_t[newdigitMult];
270         for (Int_t iDigit=0; iDigit<newdigitMult; iDigit++) {
271           amplListNew[iDigit] = amplList[iDigit];
272           timeListNew[iDigit] = timeList[iDigit];
273           digiListNew[iDigit] = digiList[iDigit];
274         }
275
276         delete [] amplList;
277         delete [] timeList;
278         delete [] digiList;
279
280         amplList = amplListNew;
281         timeList = timeListNew;
282         digiList = digiListNew;
283       }
284
285       //Primaries
286       Int_t  primMult  = 0;
287       Int_t *primInts =  clust->GetPrimaries(primMult);
288       UShort_t *primList = new UShort_t[primMult];
289       for (Int_t ipr=0; ipr<primMult; ipr++) 
290         primList[ipr] = (UShort_t)(primInts[ipr]);       
291
292
293       // fills the ESDCaloCluster
294       AliESDCaloCluster * ec = new AliESDCaloCluster() ; 
295       ec->SetEMCAL(kTRUE);
296       ec->SetClusterType(clust->GetClusterType());
297       ec->SetGlobalPosition(xyz);
298       ec->SetClusterEnergy(clust->GetEnergy());
299       
300       ec->SetNumberOfDigits(newdigitMult);
301       ec->SetDigitAmplitude(amplList); //energies
302       ec->SetDigitTime(timeList);      //times
303       ec->SetDigitIndex(digiList);     //indices
304       if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1){
305         ec->SetPrimaryIndex(clust->GetPrimaryIndex());
306         ec->SetNumberOfPrimaries(primMult);           //primary multiplicity
307         ec->SetListOfPrimaries(primList);                  //primary List for a cluster  
308         ec->SetClusterDisp(clust->GetDispersion());
309         ec->SetClusterChi2(-1); //not yet implemented
310         ec->SetM02(elipAxis[0]*elipAxis[0]) ;
311         ec->SetM20(elipAxis[1]*elipAxis[1]) ;
312         ec->SetM11(-1) ;        //not yet implemented
313         ec->SetTrackMatchedIndex( matchedTrack[iClust]); //track matched 
314       } 
315
316       // add the cluster to the esd object
317       esd->AddCaloCluster(ec);
318       delete ec;
319
320     } else { // no new ESD cluster
321         delete [] amplList;
322         delete [] timeList;
323         delete [] digiList;
324     }
325   } // cycle on clusters
326   esd->SetNumberOfEMCALClusters(nClustersNew);
327   //if(nClustersNew != nClusters) 
328   //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
329
330   //Fill ESDCaloCluster with PID weights
331   AliEMCALPID *pid = new AliEMCALPID;
332   //pid->SetPrintInfo(kTRUE);
333   pid->SetReconstructor(kTRUE);
334   pid->RunPID(esd);
335 }
336
337