Minor fixes
[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//
85c25c2e 24//-- Aleksei Pavlinov : added staf for EMCAL jet trigger 9Apr 25, 2008)
25// : fgDigitsArr should read just once at event
26
f6019cda 27// --- ROOT system ---
85c25c2e 28#include <TList.h>
29#include <TClonesArray.h>
60d8ad94 30#include <TH2.h>
0c5b726e 31#include "TGeoManager.h"
32#include "TGeoMatrix.h"
f6019cda 33
34// --- Standard library ---
35
36// --- AliRoot header files ---
f6019cda 37#include "AliEMCALReconstructor.h"
5dee926e 38
aaa3cb7c 39#include "AliCodeTimer.h"
23ca956b 40#include "AliCaloCalibPedestal.h"
41#include "AliEMCALCalibData.h"
af885e0f 42#include "AliESDEvent.h"
89ffc0b0 43#include "AliESDCaloCluster.h"
0e7c6655 44#include "AliESDCaloCells.h"
6a0cf740 45#include "AliESDtrack.h"
5dee926e 46#include "AliEMCALLoader.h"
98e9578e 47#include "AliEMCALRawUtils.h"
0e7c6655 48#include "AliEMCALDigit.h"
f6019cda 49#include "AliEMCALClusterizerv1.h"
ee08edde 50#include "AliEMCALClusterizerNxN.h"
5dee926e 51#include "AliEMCALRecPoint.h"
dc293ae9 52#include "AliEMCALPID.h"
0964c2e9 53#include "AliEMCALTrigger.h"
1d59832c 54#include "AliRawReader.h"
fa42b1f3 55#include "AliCDBEntry.h"
56#include "AliCDBManager.h"
65bdc82f 57#include "AliEMCALGeometry.h"
ac8ae9fe 58#include "AliEMCAL.h"
85c25c2e 59#include "AliESDVZERO.h"
0c5b726e 60#include "AliCDBManager.h"
72c58de0 61#include "AliRunLoader.h"
62#include "AliRun.h"
916f1e76 63#include "AliEMCALTriggerData.h"
64#include "AliEMCALTriggerElectronics.h"
fff39dd1 65#include "AliEMCALTriggerDCSConfigDB.h"
66#include "AliEMCALTriggerDCSConfig.h"
de39a0ff 67#include "AliEMCALTriggerData.h"
68#include "AliEMCALTriggerRawDigit.h"
69#include "AliEMCALTriggerPatch.h"
70#include "AliEMCALTriggerTypes.h"
1d59832c 71
85c25c2e 72ClassImp(AliEMCALReconstructor)
f6019cda 73
b57cc9b9 74const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
75AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
76AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
77TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
78TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
916f1e76 79AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
f6019cda 80//____________________________________________________________________________
18a21c7c 81AliEMCALReconstructor::AliEMCALReconstructor()
de39a0ff 82 : fDebug(kFALSE), fList(0), fGeom(0),fCalibData(0),fPedestalData(0),fTriggerData(0x0)
f6019cda 83{
84 // ctor
65bdc82f 85
86 fgRawUtils = new AliEMCALRawUtils;
72c58de0 87
88 //To make sure we match with the geometry in a simulation file,
89 //let's try to get it first. If not, take the default geometry
33c3c91a 90 AliRunLoader *rl = AliRunLoader::Instance();
7e1d9a9b 91 if (rl->GetAliRun()){
92 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
93 if(emcal) fGeom = emcal->GetGeometry();
94 }
95
96 if(!fGeom) {
72c58de0 97 AliInfo(Form("Using default geometry in reconstruction"));
937d0661 98 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
65bdc82f 99 }
0e7c6655 100
0c5b726e 101 //Get calibration parameters
102 if(!fCalibData)
103 {
104 AliCDBEntry *entry = (AliCDBEntry*)
105 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
106 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
107 }
108
109 if(!fCalibData)
110 AliFatal("Calibration parameters not found in CDB!");
111
40164976 112 //Get calibration parameters
113 if(!fPedestalData)
114 {
de39a0ff 115 AliCDBEntry *entry = (AliCDBEntry*)
80453a9f 116 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
de39a0ff 117 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
40164976 118 }
de39a0ff 119
ee08edde 120 if(!fPedestalData)
121 AliFatal("Dead map not found in CDB!");
de39a0ff 122
ee08edde 123 InitClusterizer();
de39a0ff 124
72c58de0 125 if(!fGeom) AliFatal(Form("Could not get geometry!"));
126
f62c044a 127 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
fff39dd1 128
f62c044a 129 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
fff39dd1 130
f62c044a 131 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
132 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
de39a0ff 133
f62c044a 134 fTriggerData = new AliEMCALTriggerData();
de39a0ff 135
f62c044a 136 //Init temporary list of digits
b57cc9b9 137 fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
138 fgClustersArr = new TObjArray(1000);
de39a0ff 139
f6019cda 140}
141
0a4cb131 142//____________________________________________________________________________
f6019cda 143AliEMCALReconstructor::~AliEMCALReconstructor()
144{
145 // dtor
23ca956b 146
147 if(fGeom) delete fGeom;
80453a9f 148
149 //No need to delete, recovered from OCDB
150 //if(fCalibData) delete fCalibData;
151 //if(fPedestalData) delete fPedestalData;
de39a0ff 152
b57cc9b9 153 if(fgDigitsArr){
154 fgDigitsArr->Clear("C");
155 delete fgDigitsArr;
156 }
157
158 if(fgClustersArr){
159 fgClustersArr->Clear();
160 delete fgClustersArr;
161 }
162
23ca956b 163 if(fgRawUtils) delete fgRawUtils;
164 if(fgClusterizer) delete fgClusterizer;
f62c044a 165 if(fgTriggerProcessor) delete fgTriggerProcessor;
b57cc9b9 166
aaa3cb7c 167 AliCodeTimer::Instance()->Print();
f6019cda 168}
169
40871053 170// //____________________________________________________________________________
171// void AliEMCALReconstructor::Init()
172// {
173// // Trigger hists - Oct 24, 2007
174// fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
175// }
85c25c2e 176
177//____________________________________________________________________________
ee08edde 178void AliEMCALReconstructor::InitClusterizer()
179{
180 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
181
182 AliEMCALRecParam *recParam = NULL;
183 AliCDBEntry *entry = (AliCDBEntry*)
7e1d9a9b 184 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
ee08edde 185 //Get The reco param for the default event specie
186 if (entry)
de39a0ff 187 recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
188
7e1d9a9b 189 if(!recParam){
ee08edde 190 AliFatal("RecoParam not found in CDB!");
7e1d9a9b 191 }
192 else{
193 if (recParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
de39a0ff 194 {
195 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
196 }
7e1d9a9b 197 else
de39a0ff 198 {
199 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
200 }
7e1d9a9b 201 }
ee08edde 202
203}
204
205//____________________________________________________________________________
c47157cd 206void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
f6019cda 207{
208 // method called by AliReconstruction;
209 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
210 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
211 // the global tracking.
c47157cd 212 // Works on the current event.
fa42b1f3 213
1a429a6b 214 AliCodeTimerAuto("",0)
aaa3cb7c 215
85c25c2e 216 ReadDigitsArrayFromTree(digitsTree);
de39a0ff 217
0832a2bf 218 fgClusterizer->InitParameters();
4601e3a7 219 fgClusterizer->SetOutput(clustersTree);
de39a0ff 220
e853f058 221 //Skip clusterization of LED events
222 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
0341167b 223
de39a0ff 224 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
85c25c2e 225
e853f058 226 fgClusterizer->SetInput(digitsTree);
9517d886 227
e853f058 228 if(Debug())
229 fgClusterizer->Digits2Clusters("deb all") ;
230 else
231 fgClusterizer->Digits2Clusters("");
9517d886 232
e853f058 233 fgClusterizer->Clear();
9517d886 234
e853f058 235 }//digits array exists and has somethind
236 }//not a LED event
237
916f1e76 238 clustersTree->Fill();
f6019cda 239}
240
241//____________________________________________________________________________
c47157cd 242void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
98e9578e 243
a68156e6 244{
c47157cd 245 // Conversion from raw data to
246 // EMCAL digits.
247 // Works on a single-event basis
85c60a8e 248
98e9578e 249 rawReader->Reset() ;
de39a0ff 250
251 fTriggerData->SetMode(1);
252
b57cc9b9 253 if(fgDigitsArr) fgDigitsArr->Clear("C");
de39a0ff 254
255 TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", 32 * 96);
916f1e76 256
c47157cd 257 Int_t bufsize = 32000;
b57cc9b9 258 digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
916f1e76 259 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
46f1d25f 260
e853f058 261 //Skip calibration events do the rest
262 Bool_t doFit = kTRUE;
263 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
264 if (doFit){
265 //must be done here because, in constructor, option is not yet known
266 fgRawUtils->SetOption(GetOption());
267
268 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
269 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
270 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
271 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
272 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
273 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
274 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
275 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
276 fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
277 fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
278
de39a0ff 279 fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg,fTriggerData);
793176c1 280 }//skip calibration event
e853f058 281 else{
282 AliDebug(1," Calibration Event, skip!");
e853f058 283 }
284
c615db53 285 digitsTree->Fill();
916f1e76 286 digitsTrg->Delete();
916f1e76 287 delete digitsTrg;
c615db53 288
a68156e6 289}
290
85c25c2e 291
a68156e6 292//____________________________________________________________________________
0e7c6655 293void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
c47157cd 294 AliESDEvent* esd) const
f6019cda 295{
98e9578e 296 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
85c25c2e 297 // and V0
c47157cd 298 // Works on the current event
de39a0ff 299 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
85c25c2e 300 //return;
92da3372 301
7ba18c0e 302 //########################################
303 // Trigger
304 //########################################
de39a0ff 305
7ba18c0e 306 Int_t v0M[2] = {0, 0};
de39a0ff 307
7ba18c0e 308 AliESDVZERO* esdV0 = esd->GetVZEROData();
309
310 if (esdV0)
311 {
312 for (Int_t i = 0; i < 32; i++)
313 {
073fa222 314 v0M[0] += (Int_t)esdV0->GetAdcV0C(i);
315 v0M[1] += (Int_t)esdV0->GetAdcV0A(i);
7ba18c0e 316 }
317 }
318 else
319 {
320 AliWarning("Cannot retrieve V0 ESD! Run w/ null V0 charges");
321 }
322
323 TClonesArray *trgDigits = new TClonesArray("AliEMCALTriggerRawDigit",1000);
de39a0ff 324
7ba18c0e 325 TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
de39a0ff 326
7ba18c0e 327 if (!branchtrg)
328 {
329 AliError("Can't get the branch with the EMCAL trigger digits!");
330 return;
331 }
332
333 branchtrg->SetAddress(&trgDigits);
334 branchtrg->GetEntry(0);
de39a0ff 335
7ba18c0e 336 // Note: fgTriggerProcessor reset done at the end of this method
337 fgTriggerProcessor->Digits2Trigger(trgDigits, v0M, fTriggerData);
de39a0ff 338
7ba18c0e 339 // Fill ESD
340 AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
de39a0ff 341
7ba18c0e 342 if (trgESD)
343 {
344 trgESD->Allocate(trgDigits->GetEntriesFast());
de39a0ff 345
7ba18c0e 346 for (Int_t i = 0; i < trgDigits->GetEntriesFast(); i++)
347 {
348 AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)trgDigits->At(i);
de39a0ff 349
7ba18c0e 350 Int_t px, py;
351 if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py))
352 {
353 Int_t a = -1, t = -1, times[10];
de39a0ff 354
7ba18c0e 355 rdig->GetMaximum(a, t);
356 rdig->GetL0Times(times);
357
358 trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum());
359 }
360 }
de39a0ff 361
7ba18c0e 362 trgESD->SetL1Threshold(0, fTriggerData->GetL1GammaThreshold());
de39a0ff 363
7ba18c0e 364 trgESD->SetL1Threshold(1, fTriggerData->GetL1JetThreshold() );
de39a0ff 365
7ba18c0e 366 for (Int_t i = 0; i < kTriggerTypeEnd; i++)
367 {
368 for (Int_t j = 0; j < 2; j++)
369 {
370 TClonesArray* patches = fTriggerData->GetPatches((TriggerType_t)i, j);
de39a0ff 371
7ba18c0e 372 TIter NextPatch(patches);
373 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)NextPatch())
374 {
375 TVector2 pos; p->Position(pos);
073fa222 376 trgESD->SetTriggerBits((Int_t) pos.X(), (Int_t) pos.Y(), i, j);
7ba18c0e 377 }
378 }
379 }
380 }
381
382 // Resetting
383 fTriggerData->Reset();
de39a0ff 384
0e7c6655 385 //########################################
386 //##############Fill CaloCells###############
387 //########################################
b57cc9b9 388 ReadDigitsArrayFromTree(digitsTree);
aaa3cb7c 389
de39a0ff 390// TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
391// TBranch *branchdig = digitsTree->GetBranch("EMCAL");
392// if (!branchdig) {
393// AliError("can't get the branch with the EMCAL digits !");
394// return;
395// }
396// branchdig->SetAddress(&digits);
397// digitsTree->GetEvent(0);
b57cc9b9 398 Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
0e7c6655 399 AliDebug(1,Form("%d digits",nDigits));
400
401 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
402 emcCells.CreateContainer(nDigits);
c8fe2783 403 emcCells.SetType(AliVCaloCells::kEMCALCell);
0c5b726e 404 Float_t energy = 0;
0e7c6655 405 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
b57cc9b9 406 const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
829ba234 407 if(dig->GetAmplitude() > 0 ){
ee08edde 408 energy = fgClusterizer->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
40164976 409 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
410 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
411 idignew++;
412 }
0e7c6655 413 }
414 }
415 emcCells.SetNumberOfCells(idignew);
416 emcCells.Sort();
417
418 //------------------------------------------------------------
419 //-----------------CLUSTERS-----------------------------
420 //------------------------------------------------------------
9dce5a21 421 clustersTree->SetBranchStatus("*",0); //disable all branches
422 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
b57cc9b9 423 if(fgClustersArr) fgClustersArr->Clear();
0e7c6655 424 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
b57cc9b9 425 branch->SetAddress(&fgClustersArr);
9dce5a21 426 branch->GetEntry(0);
427 //clustersTree->GetEvent(0);
0e7c6655 428
b57cc9b9 429 Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
0e7c6655 430 AliDebug(1,Form("%d clusters",nClusters));
85c25c2e 431
6a0cf740 432 //######################################################
433 //#######################TRACK MATCHING###############
434 //######################################################
435 //Fill list of integers, each one is index of track to which the cluster belongs.
436
437 // step 1 - initialize array of matched track indexes
438 Int_t *matchedTrack = new Int_t[nClusters];
439 for (Int_t iclus = 0; iclus < nClusters; iclus++)
440 matchedTrack[iclus] = -1; // neg. index --> no matched track
441
442 // step 2, change the flag for all matched clusters found in tracks
443 Int_t iemcalMatch = -1;
444 Int_t endtpc = esd->GetNumberOfTracks();
445 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
446 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
447 iemcalMatch = track->GetEMCALcluster();
65f4a419 448 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
6a0cf740 449 }
85c25c2e 450
6a0cf740 451 //########################################
85c25c2e 452 //##############Fill CaloClusters#############
6a0cf740 453 //########################################
5dee926e 454 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
b57cc9b9 455 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
c8fe2783 456 //if(clust->GetClusterType()== AliVCluster::kEMCALClusterv1) nRP++; else nPC++;
85c60a8e 457 if (Debug()) clust->Print();
a7a5421e 458 // Get information from EMCAL reconstruction points
85c60a8e 459 Float_t xyz[3];
5dee926e 460 TVector3 gpos;
461 clust->GetGlobalPosition(gpos);
35397e76 462 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 463 xyz[ixyz] = gpos[ixyz];
85c25c2e 464 Float_t elipAxis[2];
465 clust->GetElipsAxis(elipAxis);
35397e76 466 //Create digits lists
467 Int_t cellMult = clust->GetMultiplicity();
468 //TArrayS digiList(digitMult);
469 Float_t *amplFloat = clust->GetEnergiesList();
470 Int_t *digitInts = clust->GetAbsId();
471 TArrayS absIdList(cellMult);
eb972628 472 TArrayD fracList(cellMult);
35397e76 473
474 Int_t newCellMult = 0;
475 for (Int_t iCell=0; iCell<cellMult; iCell++) {
476 if (amplFloat[iCell] > 0) {
477 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
e3968910 478 //Calculate Fraction
479 if(emcCells.GetCellAmplitude(digitInts[iCell])>0 && GetRecParam()->GetUnfold())
480 fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell]));//get cell calibration value
481 else
482 fracList[newCellMult] = 0;
35397e76 483 newCellMult++;
92da3372 484 }
92da3372 485 }
85c25c2e 486
eb972628 487 absIdList.Set(newCellMult);
488 fracList.Set(newCellMult);
489
35397e76 490 if(newCellMult > 0) { // accept cluster if it has some digit
491 nClustersNew++;
65721814 492 //Primaries
7592dfc4 493 Int_t parentMult = 0;
fa42b1f3 494 Int_t *parentList = clust->GetParents(parentMult);
a7a5421e 495 // fills the ESDCaloCluster
35397e76 496 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
c8fe2783 497 ec->SetType(AliVCluster::kEMCALClusterv1);
7592dfc4 498 ec->SetPosition(xyz);
499 ec->SetE(clust->GetEnergy());
40164976 500
ee08edde 501 //Distance to the nearest bad crystal
502 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
40164976 503
35397e76 504 ec->SetNCells(newCellMult);
505 //Change type of list from short to ushort
506 UShort_t *newAbsIdList = new UShort_t[newCellMult];
ee08edde 507 Double_t *newFracList = new Double_t[newCellMult];
35397e76 508 for(Int_t i = 0; i < newCellMult ; i++) {
509 newAbsIdList[i]=absIdList[i];
de39a0ff 510 newFracList[i] =fracList[i];
35397e76 511 }
512 ec->SetCellsAbsId(newAbsIdList);
eb972628 513 ec->SetCellsAmplitudeFraction(newFracList);
c8fe2783 514 ec->SetDispersion(clust->GetDispersion());
515 ec->SetChi2(-1); //not yet implemented
35397e76 516 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
517 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
78902954 518 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
225cd96d 519 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
35397e76 520 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
521 arrayTrackMatched[0]= matchedTrack[iClust];
522 ec->AddTracksMatched(arrayTrackMatched);
523
524 TArrayI arrayParents(parentMult,parentList);
525 ec->AddLabels(arrayParents);
526
6a0cf740 527 // add the cluster to the esd object
eb972628 528 esd->AddCaloCluster(ec);
a7a5421e 529 delete ec;
85d4cbde 530 delete [] newAbsIdList ;
eb972628 531 delete [] newFracList ;
35397e76 532 }
533 } // cycle on clusters
85c25c2e 534
35397e76 535 delete [] matchedTrack;
85c25c2e 536
35397e76 537 //Fill ESDCaloCluster with PID weights
1942834a 538 AliEMCALPID *pid = new AliEMCALPID;
539 //pid->SetPrintInfo(kTRUE);
540 pid->SetReconstructor(kTRUE);
541 pid->RunPID(esd);
542 delete pid;
de39a0ff 543
1942834a 544 //Store EMCAL misalignment matrixes
545 FillMisalMatrixes(esd) ;
0c5b726e 546
547}
548
549//==================================================================================
550void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
551 //Store EMCAL matrixes in ESD Header
552
553 //Check, if matrixes was already stored
cb8a44fb 554 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
0c5b726e 555 if(esd->GetEMCALMatrix(sm)!=0)
556 return ;
557 }
558
559 //Create and store matrixes
560 if(!gGeoManager){
561 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
562 return ;
563 }
564 //Note, that owner of copied marixes will be header
7e1d9a9b 565 const Int_t bufsize = 255;
566 char path[bufsize] ;
5e3106bc 567 TGeoHMatrix * m = 0x0;
cb8a44fb 568 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
7e1d9a9b 569 snprintf(path,bufsize,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
570 if(sm >= 10) snprintf(path,bufsize,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
0c5b726e 571
9ddc5deb 572 if (gGeoManager->CheckPath(path)){
cb8a44fb 573 gGeoManager->cd(path);
0c5b726e 574 m = gGeoManager->GetCurrentMatrix() ;
cb8a44fb 575// printf("================================================= \n");
576// printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
577// m->Print("");
0c5b726e 578 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
cb8a44fb 579// printf("================================================= \n");
0c5b726e 580 }
581 else{
582 esd->SetEMCALMatrix(NULL,sm) ;
583 }
584 }
f6019cda 585}
dc293ae9 586
0c5b726e 587
588
9517d886 589//__________________________________________________________________________
85c25c2e 590void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
591{
592 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
593 if(fgDigitsArr) {
594 // Clear previous digits
b57cc9b9 595 fgDigitsArr->Clear("C");
596 //delete fgDigitsArr;
85c25c2e 597 }
598 // Read the digits from the input tree
599 TBranch *branch = digitsTree->GetBranch("EMCAL");
600 if (!branch) {
601 AliError("can't get the branch with the EMCAL digits !");
602 return;
603 }
604 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
605 branch->SetAddress(&fgDigitsArr);
606 branch->GetEntry(0);
607}
98e9578e 608
916f1e76 609