Initial commintment
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
CommitLineData
f6019cda 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 ---
f6019cda 29#include "AliEMCALReconstructor.h"
5dee926e 30
69db97f5 31#include "AliRun.h"
af885e0f 32#include "AliESDEvent.h"
89ffc0b0 33#include "AliESDCaloCluster.h"
6a0cf740 34#include "AliESDtrack.h"
5dee926e 35#include "AliRunLoader.h"
36#include "AliEMCALLoader.h"
98e9578e 37#include "AliEMCALRawUtils.h"
f6019cda 38#include "AliEMCALClusterizerv1.h"
5dee926e 39#include "AliEMCALRecPoint.h"
dc293ae9 40#include "AliEMCALPID.h"
0964c2e9 41#include "AliEMCALTrigger.h"
1d59832c 42#include "AliRawReader.h"
43
f6019cda 44ClassImp(AliEMCALReconstructor)
45
46//____________________________________________________________________________
18a21c7c 47AliEMCALReconstructor::AliEMCALReconstructor()
48 : fDebug(kFALSE)
f6019cda 49{
50 // ctor
f6019cda 51}
52
0a4cb131 53//____________________________________________________________________________
18a21c7c 54AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
55 : AliReconstructor(rec),
56 fDebug(rec.fDebug)
0a4cb131 57{
58 //copy ctor
0a4cb131 59}
f6019cda 60
61//____________________________________________________________________________
62AliEMCALReconstructor::~AliEMCALReconstructor()
63{
64 // dtor
65}
66
67//____________________________________________________________________________
68void 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()) ;
b4975670 76 TString branchName(runLoader->GetEventFolder()->GetName() ) ;
f6019cda 77
78 AliEMCALClusterizerv1 clu(headerFile, branchName);
98e9578e 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() ;
f6019cda 93}
94
95//____________________________________________________________________________
98e9578e 96void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
97
a68156e6 98{
98e9578e 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.
a68156e6 105
a68156e6 106 TString headerFile(runLoader->GetFileName()) ;
107 TString branchName(runLoader->GetEventFolder()->GetName()) ;
85c60a8e 108
98e9578e 109 static AliEMCALRawUtils rawUtils;
a68156e6 110 AliEMCALClusterizerv1 clu(headerFile, branchName);
98e9578e 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 }
a68156e6 127}
128
129//____________________________________________________________________________
af885e0f 130void AliEMCALReconstructor::FillESD(AliRunLoader* runLoader, AliESDEvent* esd) const
f6019cda 131{
98e9578e 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
92da3372 134
b4975670 135 Int_t eventNumber = runLoader->GetEventNumber() ;
136
85c60a8e 137 // Creates AliESDCaloCluster from AliEMCALRecPoints
98e9578e 138 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(runLoader->GetDetectorLoader("EMCAL"));
139 runLoader->LoadRecPoints("EMCAL");
140 runLoader->GetEvent(eventNumber);
5dee926e 141 TObjArray *clusters = emcalLoader->RecPoints();
a7a5421e 142 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
98e9578e 143 AliDebug(1,Form("Event %d: %d clusters",eventNumber,nClusters));
5d9e7bd7 144 // Int_t nRP=0, nPC=0; // in input
a7a5421e 145 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
92da3372 146
6a0cf740 147 //######################################################
0964c2e9 148 //#########Calculate trigger and set trigger info###########
6a0cf740 149 //######################################################
0964c2e9 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
98e9578e 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
0964c2e9 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
6a0cf740 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();
65f4a419 217 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
6a0cf740 218 }
219
220 //########################################
221 //##############Fill CaloClusters#############
222 //########################################
0964c2e9 223
0964c2e9 224
5dee926e 225 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
226 const AliEMCALRecPoint * clust = emcalLoader->RecPoint(iClust);
5d9e7bd7 227 //if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1) nRP++; else nPC++;
85c60a8e 228 if (Debug()) clust->Print();
a7a5421e 229 // Get information from EMCAL reconstruction points
85c60a8e 230 Float_t xyz[3];
5dee926e 231 TVector3 gpos;
232 clust->GetGlobalPosition(gpos);
f6019cda 233 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 234 xyz[ixyz] = gpos[ixyz];
7592dfc4 235
85c60a8e 236 Int_t digitMult = clust->GetMultiplicity();
7592dfc4 237 Short_t *amplList = new Short_t[digitMult];
238 Short_t *timeList = new Short_t[digitMult];
239 Short_t *digiList = new Short_t[digitMult];
85c60a8e 240 Float_t *amplFloat = clust->GetEnergiesList();
241 Float_t *timeFloat = clust->GetTimeList();
242 Int_t *digitInts = clust->GetAbsId();
8a11aef1 243 Float_t elipAxis[2];
92da3372 244 clust->GetElipsAxis(elipAxis);
7592dfc4 245
246 // Convert Float_t* and Int_t* to Short_t* to save memory
a7a5421e 247 // Problem : we should recalculate a cluster characteristics when discard digit(s)
f1487f22 248 Int_t newdigitMult = 0;
92da3372 249 for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
98e9578e 250 if (amplFloat[iDigit] > 0) {
a7a5421e 251 amplList[newdigitMult] = (UShort_t)(amplFloat[iDigit]*500);
98e9578e 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++;
92da3372 259 }
98e9578e 260 else if (clust->GetClusterType() != AliESDCaloCluster::kPseudoCluster)
261 Warning("FillESD()","Negative or 0 digit amplitude in cluster");
92da3372 262 }
7592dfc4 263
a7a5421e 264 if(newdigitMult > 0) { // accept cluster if it has some digit
265 nClustersNew++;
266 if(newdigitMult != digitMult) { // some digits were deleted
7592dfc4 267 Short_t *amplListNew = new Short_t[newdigitMult];
268 Short_t *timeListNew = new Short_t[newdigitMult];
269 Short_t *digiListNew = new Short_t[newdigitMult];
a7a5421e 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 }
7592dfc4 275
a7a5421e 276 delete [] amplList;
277 delete [] timeList;
278 delete [] digiList;
7592dfc4 279
a7a5421e 280 amplList = amplListNew;
281 timeList = timeListNew;
282 digiList = digiListNew;
283 }
7592dfc4 284
65721814 285 //Primaries
7592dfc4 286 Int_t parentMult = 0;
287 Int_t *parentInts = clust->GetParents(parentMult);
288 Short_t *parentList = new Short_t[parentMult];
289 for (Int_t ipr=0; ipr<parentMult; ipr++)
290 parentList[ipr] = (Short_t)(parentInts[ipr]);
291
17773e2e 292
a7a5421e 293 // fills the ESDCaloCluster
294 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
69db97f5 295 ec->SetEMCAL(kTRUE);
a7a5421e 296 ec->SetClusterType(clust->GetClusterType());
7592dfc4 297 ec->SetPosition(xyz);
298 ec->SetE(clust->GetEnergy());
299 TArrayS arrayAmpList(newdigitMult,amplList);
300 TArrayS arrayTimeList(newdigitMult,timeList);
301 TArrayS arrayIndexList(newdigitMult,digiList);
302 ec->AddDigitAmplitude(arrayAmpList);
303 ec->AddDigitTime(arrayTimeList);
304 ec->AddDigitIndex(arrayIndexList);
305
a7a5421e 306 if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1){
7592dfc4 307
a7a5421e 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
7592dfc4 313
314 TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
315 arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
316 ec->AddTracksMatched(arrayTrackMatched);
317
318 TArrayS arrayParents(parentMult,parentList);
319 ec->AddLabels(arrayParents);
a7a5421e 320 }
7592dfc4 321
6a0cf740 322 // add the cluster to the esd object
a7a5421e 323 esd->AddCaloCluster(ec);
324 delete ec;
17773e2e 325 delete [] parentList;
a7a5421e 326 } else { // no new ESD cluster
17773e2e 327
a7a5421e 328 }
17773e2e 329 delete [] amplList;
330 delete [] timeList;
331 delete [] digiList;
332
a7a5421e 333 } // cycle on clusters
17773e2e 334
335 delete [] matchedTrack;
336
a7a5421e 337 esd->SetNumberOfEMCALClusters(nClustersNew);
5d9e7bd7 338 //if(nClustersNew != nClusters)
339 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
7592dfc4 340
dc293ae9 341 //Fill ESDCaloCluster with PID weights
dc293ae9 342 AliEMCALPID *pid = new AliEMCALPID;
343 //pid->SetPrintInfo(kTRUE);
344 pid->SetReconstructor(kTRUE);
345 pid->RunPID(esd);
d0708678 346 delete pid;
f6019cda 347}
dc293ae9 348
98e9578e 349