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