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