track number corrected
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
... / ...
CommitLineData
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//-- Aleksei Pavlinov : added staf for EMCAL jet trigger 9Apr 25, 2008)
25// : fgDigitsArr should read just once at event
26
27// --- ROOT system ---
28#include <TList.h>
29#include <TClonesArray.h>
30#include <TH2.h>
31
32// --- Standard library ---
33
34// --- AliRoot header files ---
35#include "AliEMCALReconstructor.h"
36
37#include "AliCodeTimer.h"
38#include "AliESDEvent.h"
39#include "AliESDCaloCluster.h"
40#include "AliESDCaloCells.h"
41#include "AliESDtrack.h"
42#include "AliEMCALLoader.h"
43#include "AliEMCALRawUtils.h"
44#include "AliEMCALDigit.h"
45#include "AliEMCALClusterizerv1.h"
46#include "AliEMCALRecPoint.h"
47#include "AliEMCALPID.h"
48#include "AliEMCALTrigger.h"
49#include "AliRawReader.h"
50#include "AliCDBEntry.h"
51#include "AliCDBManager.h"
52#include "AliEMCALGeometry.h"
53#include "AliEMCAL.h"
54#include "AliEMCALHistoUtilities.h"
55#include "AliESDVZERO.h"
56
57#include "AliRunLoader.h"
58#include "AliRun.h"
59
60ClassImp(AliEMCALReconstructor)
61
62const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
63AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
64AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
65TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
66//____________________________________________________________________________
67AliEMCALReconstructor::AliEMCALReconstructor()
68 : fDebug(kFALSE), fList(0), fGeom(0)
69{
70 // ctor
71
72 fgRawUtils = new AliEMCALRawUtils;
73 fgClusterizer = new AliEMCALClusterizerv1;
74
75 //To make sure we match with the geometry in a simulation file,
76 //let's try to get it first. If not, take the default geometry
77 AliRunLoader *rl = AliRunLoader::GetRunLoader();
78 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
79 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
80 } else {
81 AliInfo(Form("Using default geometry in reconstruction"));
82 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
83 }
84
85 if(!fGeom) AliFatal(Form("Could not get geometry!"));
86
87}
88
89//____________________________________________________________________________
90AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
91 : AliReconstructor(rec),
92 fDebug(rec.fDebug),
93 fList(rec.fList),
94 fGeom(rec.fGeom)
95{
96 //copy ctor
97}
98
99//____________________________________________________________________________
100AliEMCALReconstructor::~AliEMCALReconstructor()
101{
102 // dtor
103 delete fGeom;
104 AliCodeTimer::Instance()->Print();
105}
106
107//____________________________________________________________________________
108void AliEMCALReconstructor::Init()
109{
110 // Trigger hists - Oct 24, 2007
111 fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
112}
113
114//____________________________________________________________________________
115void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
116{
117 // method called by AliReconstruction;
118 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
119 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
120 // the global tracking.
121 // Works on the current event.
122
123 AliCodeTimerAuto("")
124
125 ReadDigitsArrayFromTree(digitsTree);
126 fgClusterizer->InitParameters();
127 fgClusterizer->SetOutput(clustersTree);
128
129 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
130
131 fgClusterizer->SetInput(digitsTree);
132
133 if(Debug())
134 fgClusterizer->Digits2Clusters("deb all") ;
135 else
136 fgClusterizer->Digits2Clusters("");
137
138 fgClusterizer->Clear();
139
140 }
141
142}
143
144//____________________________________________________________________________
145void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
146
147{
148 // Conversion from raw data to
149 // EMCAL digits.
150 // Works on a single-event basis
151
152 rawReader->Reset() ;
153
154 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
155 Int_t bufsize = 32000;
156 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
157
158 //must be done here because, in constructor, option is not yet known
159 fgRawUtils->SetOption(GetOption());
160
161 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
162 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
163 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
164 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
165 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
166
167 fgRawUtils->Raw2Digits(rawReader,digitsArr);
168
169 digitsTree->Fill();
170 digitsArr->Delete();
171 delete digitsArr;
172
173}
174
175
176//____________________________________________________________________________
177void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
178 AliESDEvent* esd) const
179{
180 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
181 // and V0
182 // Works on the current event
183 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
184 //return;
185
186 //######################################################
187 //#########Calculate trigger and set trigger info###########
188 //######################################################
189
190 AliEMCALTrigger tr;
191 // tr.SetPatchSize(1); // create 4x4 patches
192 tr.SetSimulation(kFALSE); // Reconstruction mode
193 tr.SetDigitsList(fgDigitsArr);
194 // Get VZERO total multiplicity for jet trigger simulation
195 // The simulation of jey trigger will be incorrect if no VZERO data
196 // at ESD
197 AliESDVZERO* vZero = esd->GetVZEROData();
198 if(vZero) {
199 tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
200 }
201 //
202 tr.Trigger();
203
204 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
205 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
206 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
207 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
208
209 Int_t iSM2x2 = tr.Get2x2SuperModule();
210 Int_t iSMnxn = tr.GetnxnSuperModule();
211 Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
212 Int_t iModulePhinxn = tr.GetnxnModulePhi();
213 Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
214 Int_t iModuleEtanxn = tr.GetnxnModuleEta();
215
216 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
217 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
218
219 TVector3 pos2x2(-1,-1,-1);
220 TVector3 posnxn(-1,-1,-1);
221
222 Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
223 Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
224 fGeom->GetGlobal(iAbsId2x2, pos2x2);
225 fGeom->GetGlobal(iAbsIdnxn, posnxn);
226 //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
227
228 TArrayF triggerPosition(6);
229 triggerPosition[0] = pos2x2(0) ;
230 triggerPosition[1] = pos2x2(1) ;
231 triggerPosition[2] = pos2x2(2) ;
232 triggerPosition[3] = posnxn(0) ;
233 triggerPosition[4] = posnxn(1) ;
234 triggerPosition[5] = posnxn(2) ;
235 //printf(" triggerPosition ");
236 //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
237
238 TArrayF triggerAmplitudes(4);
239 triggerAmplitudes[0] = maxAmp2x2 ;
240 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
241 triggerAmplitudes[2] = maxAmpnxn ;
242 triggerAmplitudes[3] = ampOutOfPatchnxn ;
243 //printf("\n triggerAmplitudes ");
244 //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
245 //printf("\n");
246 //tr.Print("");
247 //
248 // Trigger jet staff
249 //
250 if(tr.GetNJetThreshold()>0) {
251 // Jet phi/eta
252 Int_t n0 = triggerPosition.GetSize();
253 const TH2F *hpatch = tr.GetJetMatrixE();
254 triggerPosition.Set(n0 + 2);
255 for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);
256 // Add jet ampitudes
257 n0 = triggerAmplitudes.GetSize();
258 triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
259 Double_t *ampJet = tr.GetL1JetThresholds();
260 for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
261 triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
262 }
263 }
264 esd->AddEMCALTriggerPosition(triggerPosition);
265 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
266 // Fill trigger hists
267 AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
268
269 //########################################
270 //##############Fill CaloCells###############
271 //########################################
272
273 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
274 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
275 if (!branchdig) {
276 AliError("can't get the branch with the PHOS digits !");
277 return;
278 }
279 branchdig->SetAddress(&digits);
280 digitsTree->GetEvent(0);
281 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
282 AliDebug(1,Form("%d digits",nDigits));
283
284 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
285 emcCells.CreateContainer(nDigits);
286 emcCells.SetType(AliESDCaloCells::kEMCALCell);
287 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
288 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
289 if(dig->GetAmp() > 0 ){
290 emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
291 idignew++;
292 }
293 }
294 emcCells.SetNumberOfCells(idignew);
295 emcCells.Sort();
296
297 //------------------------------------------------------------
298 //-----------------CLUSTERS-----------------------------
299 //------------------------------------------------------------
300 TObjArray *clusters = new TObjArray(100);
301 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
302 branch->SetAddress(&clusters);
303 clustersTree->GetEvent(0);
304
305 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
306 AliDebug(1,Form("%d clusters",nClusters));
307 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
308
309
310 //######################################################
311 //#######################TRACK MATCHING###############
312 //######################################################
313 //Fill list of integers, each one is index of track to which the cluster belongs.
314
315 // step 1 - initialize array of matched track indexes
316 Int_t *matchedTrack = new Int_t[nClusters];
317 for (Int_t iclus = 0; iclus < nClusters; iclus++)
318 matchedTrack[iclus] = -1; // neg. index --> no matched track
319
320 // step 2, change the flag for all matched clusters found in tracks
321 Int_t iemcalMatch = -1;
322 Int_t endtpc = esd->GetNumberOfTracks();
323 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
324 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
325 iemcalMatch = track->GetEMCALcluster();
326 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
327 }
328
329 //########################################
330 //##############Fill CaloClusters#############
331 //########################################
332 esd->SetNumberOfEMCALClusters(nClusters);
333 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
334 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
335 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
336 if (Debug()) clust->Print();
337 // Get information from EMCAL reconstruction points
338 Float_t xyz[3];
339 TVector3 gpos;
340 clust->GetGlobalPosition(gpos);
341 for (Int_t ixyz=0; ixyz<3; ixyz++)
342 xyz[ixyz] = gpos[ixyz];
343 Float_t elipAxis[2];
344 clust->GetElipsAxis(elipAxis);
345 //Create digits lists
346 Int_t cellMult = clust->GetMultiplicity();
347 //TArrayS digiList(digitMult);
348 Float_t *amplFloat = clust->GetEnergiesList();
349 Int_t *digitInts = clust->GetAbsId();
350 TArrayS absIdList(cellMult);
351 TArrayD fracList(cellMult);
352
353 Int_t newCellMult = 0;
354 for (Int_t iCell=0; iCell<cellMult; iCell++) {
355 if (amplFloat[iCell] > 0) {
356 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
357 //Uncomment when unfolding is done
358 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
359 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
360 //else
361 fracList[newCellMult] = 0;
362 newCellMult++;
363 }
364 }
365
366 absIdList.Set(newCellMult);
367 fracList.Set(newCellMult);
368
369 if(newCellMult > 0) { // accept cluster if it has some digit
370 nClustersNew++;
371 //Primaries
372 Int_t parentMult = 0;
373 Int_t *parentList = clust->GetParents(parentMult);
374 // fills the ESDCaloCluster
375 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
376 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
377 ec->SetPosition(xyz);
378 ec->SetE(clust->GetEnergy());
379 ec->SetNCells(newCellMult);
380 //Change type of list from short to ushort
381 UShort_t *newAbsIdList = new UShort_t[newCellMult];
382 Double_t *newFracList = new Double_t[newCellMult];
383 for(Int_t i = 0; i < newCellMult ; i++) {
384 newAbsIdList[i]=absIdList[i];
385 newFracList[i]=fracList[i];
386 }
387 ec->SetCellsAbsId(newAbsIdList);
388 ec->SetCellsAmplitudeFraction(newFracList);
389 ec->SetClusterDisp(clust->GetDispersion());
390 ec->SetClusterChi2(-1); //not yet implemented
391 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
392 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
393 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
394 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
395 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
396 arrayTrackMatched[0]= matchedTrack[iClust];
397 ec->AddTracksMatched(arrayTrackMatched);
398
399 TArrayI arrayParents(parentMult,parentList);
400 ec->AddLabels(arrayParents);
401
402 // add the cluster to the esd object
403 esd->AddCaloCluster(ec);
404 delete ec;
405 delete [] newAbsIdList ;
406 delete [] newFracList ;
407 }
408 } // cycle on clusters
409
410 delete [] matchedTrack;
411
412 esd->SetNumberOfEMCALClusters(nClustersNew);
413 //if(nClustersNew != nClusters)
414 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
415
416 //Fill ESDCaloCluster with PID weights
417 AliEMCALPID *pid = new AliEMCALPID;
418 //pid->SetPrintInfo(kTRUE);
419 pid->SetReconstructor(kTRUE);
420 pid->RunPID(esd);
421 delete pid;
422
423 delete digits;
424 delete clusters;
425
426 // printf(" ## AliEMCALReconstructor::FillESD() is ended : ncl %i -> %i ### \n ",nClusters, nClustersNew);
427}
428
429//__________________________________________________________________________
430void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
431{
432 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
433 if(fgDigitsArr) {
434 // Clear previous digits
435 fgDigitsArr->Delete();
436 delete fgDigitsArr;
437 }
438 // Read the digits from the input tree
439 TBranch *branch = digitsTree->GetBranch("EMCAL");
440 if (!branch) {
441 AliError("can't get the branch with the EMCAL digits !");
442 return;
443 }
444 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
445 branch->SetAddress(&fgDigitsArr);
446 branch->GetEntry(0);
447}
448