]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALReconstructor.cxx
return diff phi between -pi and pi
[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//
29c9d15f 24
85c25c2e 25
f6019cda 26// --- ROOT system ---
85c25c2e 27#include <TClonesArray.h>
0c5b726e 28#include "TGeoManager.h"
29#include "TGeoMatrix.h"
f6019cda 30
31// --- Standard library ---
32
33// --- AliRoot header files ---
f6019cda 34#include "AliEMCALReconstructor.h"
5dee926e 35
aaa3cb7c 36#include "AliCodeTimer.h"
23ca956b 37#include "AliCaloCalibPedestal.h"
38#include "AliEMCALCalibData.h"
af885e0f 39#include "AliESDEvent.h"
89ffc0b0 40#include "AliESDCaloCluster.h"
0e7c6655 41#include "AliESDCaloCells.h"
6a0cf740 42#include "AliESDtrack.h"
5dee926e 43#include "AliEMCALLoader.h"
98e9578e 44#include "AliEMCALRawUtils.h"
0e7c6655 45#include "AliEMCALDigit.h"
f6019cda 46#include "AliEMCALClusterizerv1.h"
783153ff 47#include "AliEMCALClusterizerv2.h"
ee08edde 48#include "AliEMCALClusterizerNxN.h"
5dee926e 49#include "AliEMCALRecPoint.h"
dc293ae9 50#include "AliEMCALPID.h"
1d59832c 51#include "AliRawReader.h"
fa42b1f3 52#include "AliCDBEntry.h"
53#include "AliCDBManager.h"
65bdc82f 54#include "AliEMCALGeometry.h"
ac8ae9fe 55#include "AliEMCAL.h"
85c25c2e 56#include "AliESDVZERO.h"
0c5b726e 57#include "AliCDBManager.h"
72c58de0 58#include "AliRunLoader.h"
59#include "AliRun.h"
916f1e76 60#include "AliEMCALTriggerData.h"
61#include "AliEMCALTriggerElectronics.h"
fff39dd1 62#include "AliEMCALTriggerDCSConfigDB.h"
63#include "AliEMCALTriggerDCSConfig.h"
de39a0ff 64#include "AliEMCALTriggerData.h"
65#include "AliEMCALTriggerRawDigit.h"
66#include "AliEMCALTriggerPatch.h"
67#include "AliEMCALTriggerTypes.h"
1d59832c 68
85c25c2e 69ClassImp(AliEMCALReconstructor)
95ffa314 70
5970dfe2 71const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
b57cc9b9 72AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
73AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
74TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
75TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
4bd37bd4 76TClonesArray* AliEMCALReconstructor::fgTriggerDigits = 0; // list of trigger digits, to be used multiple times
916f1e76 77AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
f6019cda 78//____________________________________________________________________________
18a21c7c 79AliEMCALReconstructor::AliEMCALReconstructor()
5970dfe2 80 : fGeom(0),fCalibData(0),fPedestalData(0),fTriggerData(0x0), fMatches(0x0)
f6019cda 81{
82 // ctor
c828bc97 83
84 // AliDebug(2, "Mark.");
85
65bdc82f 86 fgRawUtils = new AliEMCALRawUtils;
29c9d15f 87
72c58de0 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 }
29c9d15f 100
0c5b726e 101 //Get calibration parameters
102 if(!fCalibData)
103 {
29c9d15f 104 AliCDBEntry *entry = (AliCDBEntry*)
105 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
106 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
0c5b726e 107 }
29c9d15f 108
0c5b726e 109 if(!fCalibData)
29c9d15f 110 AliFatal("Calibration parameters not found in CDB!");
111
40164976 112 //Get calibration parameters
113 if(!fPedestalData)
114 {
de39a0ff 115 AliCDBEntry *entry = (AliCDBEntry*)
29c9d15f 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!");
29c9d15f 122
72c58de0 123 if(!fGeom) AliFatal(Form("Could not get geometry!"));
29c9d15f 124
f62c044a 125 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
29c9d15f 126
f62c044a 127 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
29c9d15f 128
f62c044a 129 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
130 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
29c9d15f 131
f62c044a 132 fTriggerData = new AliEMCALTriggerData();
29c9d15f 133
f62c044a 134 //Init temporary list of digits
4bd37bd4 135 fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
136 fgClustersArr = new TObjArray(1000);
137 fgTriggerDigits = new TClonesArray("AliEMCALTriggerRawDigit",1000);
5970dfe2 138
139 //Track matching
140 fMatches = new TList();
141 fMatches->SetOwner(kTRUE);
f6019cda 142}
143
f6019cda 144//____________________________________________________________________________
145AliEMCALReconstructor::~AliEMCALReconstructor()
146{
147 // dtor
c828bc97 148
149 //AliDebug(2, "Mark.");
150
23ca956b 151 if(fGeom) delete fGeom;
80453a9f 152
153 //No need to delete, recovered from OCDB
154 //if(fCalibData) delete fCalibData;
155 //if(fPedestalData) delete fPedestalData;
de39a0ff 156
b57cc9b9 157 if(fgDigitsArr){
158 fgDigitsArr->Clear("C");
159 delete fgDigitsArr;
160 }
161
162 if(fgClustersArr){
163 fgClustersArr->Clear();
164 delete fgClustersArr;
165 }
166
4bd37bd4 167 if(fgTriggerDigits){
7dbb454b 168 fgTriggerDigits->Clear();
4bd37bd4 169 delete fgTriggerDigits;
170 }
171
23ca956b 172 if(fgRawUtils) delete fgRawUtils;
173 if(fgClusterizer) delete fgClusterizer;
f62c044a 174 if(fgTriggerProcessor) delete fgTriggerProcessor;
b57cc9b9 175
5970dfe2 176 if(fMatches) { fMatches->Delete(); delete fMatches; fMatches = 0;}
177
aaa3cb7c 178 AliCodeTimer::Instance()->Print();
f6019cda 179}
180
9519e3e3 181//____________________________________________________________________________
182void AliEMCALReconstructor::InitClusterizer() const
ee08edde 183{
9519e3e3 184 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
185 Int_t clusterizerType = -1;
186 Int_t eventType = -1;
187 if(GetRecParam()) {
188 clusterizerType = GetRecParam()->GetClusterizerFlag();
189 eventType = GetRecParam()->GetEventSpecie();
7e1d9a9b 190 }
191 else{
9519e3e3 192 AliCDBEntry *entry = (AliCDBEntry*)
29c9d15f 193 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
9519e3e3 194 //Get The reco param for the default event specie
195 if (entry) {
196 AliEMCALRecParam *recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
197 if(recParam) clusterizerType = recParam->GetClusterizerFlag();
de39a0ff 198 }
7e1d9a9b 199 }
ee08edde 200
9519e3e3 201 //Check if clusterizer previously set corresponds to what is needed for this event type
202 if(fgClusterizer){
203 if(eventType!=AliRecoParam::kCalib){
204 //printf("ReCreate clusterizer? Clusterizer set <%d>, Clusterizer in use <%s>\n",
29c9d15f 205 // clusterizerType, fgClusterizer->Version());
9519e3e3 206
783153ff 207 if (clusterizerType == AliEMCALRecParam::kClusterizerv1 && !strcmp(fgClusterizer->Version(),"clu-v1")) return;
9519e3e3 208
209 else if(clusterizerType == AliEMCALRecParam::kClusterizerNxN && !strcmp(fgClusterizer->Version(),"clu-NxN")) return;
210
783153ff 211 else if(clusterizerType == AliEMCALRecParam::kClusterizerv2 && !strcmp(fgClusterizer->Version(),"clu-v2")) return;
212
9519e3e3 213 //Need to create new clusterizer, the one set previously is not the correct one
214 delete fgClusterizer;
215 }
216 else return;
217 }
29c9d15f 218
783153ff 219 if (clusterizerType == AliEMCALRecParam::kClusterizerv1)
29c9d15f 220 {
783153ff 221 fgClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData,fPedestalData);
29c9d15f 222 }
783153ff 223 else if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
29c9d15f 224 {
225 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
226 }
783153ff 227 else if (clusterizerType == AliEMCALRecParam::kClusterizerv2)
228 {
229 fgClusterizer = new AliEMCALClusterizerv2 (fGeom, fCalibData,fPedestalData);
230 }
231 else
232 {
233 AliFatal(Form("Unknown clusterizer %d ", clusterizerType));
234 }
ee08edde 235}
236
f6019cda 237//____________________________________________________________________________
c47157cd 238void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
f6019cda 239{
240 // method called by AliReconstruction;
241 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
242 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
243 // the global tracking.
c47157cd 244 // Works on the current event.
29c9d15f 245
1a429a6b 246 AliCodeTimerAuto("",0)
29c9d15f 247
248 //Get input digits and put them in fgDigitsArr, clear the list before
85c25c2e 249 ReadDigitsArrayFromTree(digitsTree);
29c9d15f 250
9519e3e3 251 InitClusterizer();
252
0832a2bf 253 fgClusterizer->InitParameters();
4601e3a7 254 fgClusterizer->SetOutput(clustersTree);
9519e3e3 255
e853f058 256 //Skip clusterization of LED events
257 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
9517d886 258
29c9d15f 259 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
260
261 fgClusterizer->SetInput(digitsTree);
262
263 //fgClusterizer->Digits2Clusters("deb all") ; //For debugging
264 fgClusterizer->Digits2Clusters("");
265
266 fgClusterizer->Clear();
267
268 }//digits array exists and has somethind
e853f058 269 }//not a LED event
29c9d15f 270
916f1e76 271 clustersTree->Fill();
c828bc97 272
273 // Deleting the recpoints at the end of the reconstruction call
274 fgClusterizer->DeleteRecPoints();
f6019cda 275}
276
a68156e6 277//____________________________________________________________________________
c47157cd 278void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
29c9d15f 279
a68156e6 280{
c47157cd 281 // Conversion from raw data to
282 // EMCAL digits.
283 // Works on a single-event basis
95ffa314 284
98e9578e 285 rawReader->Reset() ;
29c9d15f 286
de39a0ff 287 fTriggerData->SetMode(1);
29c9d15f 288
b57cc9b9 289 if(fgDigitsArr) fgDigitsArr->Clear("C");
29c9d15f 290
de39a0ff 291 TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", 32 * 96);
29c9d15f 292
c47157cd 293 Int_t bufsize = 32000;
b57cc9b9 294 digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
916f1e76 295 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
29c9d15f 296
e853f058 297 //Skip calibration events do the rest
298 Bool_t doFit = kTRUE;
95ffa314 299 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
e853f058 300 if (doFit){
29c9d15f 301 //must be done here because, in constructor, option is not yet known
302 fgRawUtils->SetOption(GetOption());
303
92d9f317 304 // fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
95ffa314 305
92d9f317 306 // fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
307 // fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
29c9d15f 308 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
309 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
310 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
48b634ff 311 if (!fgRawUtils->GetFittingAlgorithm()) fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
29c9d15f 312 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
92d9f317 313
314 //fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
315 //fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
316
317 // fgRawUtils->SetTimeMin(-99999 );
318 // fgRawUtils->SetTimeMax( 99999 );
29c9d15f 319
320 fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg,fTriggerData);
92d9f317 321
793176c1 322 }//skip calibration event
e853f058 323 else{
29c9d15f 324 AliDebug(1," Calibration Event, skip!");
e853f058 325 }
29c9d15f 326
c615db53 327 digitsTree->Fill();
916f1e76 328 digitsTrg->Delete();
916f1e76 329 delete digitsTrg;
29c9d15f 330
a68156e6 331}
332
85c25c2e 333
f6019cda 334//____________________________________________________________________________
0e7c6655 335void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
c47157cd 336 AliESDEvent* esd) const
f6019cda 337{
98e9578e 338 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
85c25c2e 339 // and V0
c47157cd 340 // Works on the current event
de39a0ff 341 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
85c25c2e 342 //return;
29c9d15f 343
7ba18c0e 344 //########################################
345 // Trigger
346 //########################################
de39a0ff 347
da6062af 348 static int saveOnce = 0;
95ffa314 349
29c9d15f 350 Int_t v0M[2] = {0, 0};
351
352 AliESDVZERO* esdV0 = esd->GetVZEROData();
353
354 if (esdV0)
355 {
356 for (Int_t i = 0; i < 32; i++)
357 {
358 v0M[0] += (Int_t)esdV0->GetAdcV0C(i);
359 v0M[1] += (Int_t)esdV0->GetAdcV0A(i);
360 }
361 }
362 else
363 {
364 AliWarning("Cannot retrieve V0 ESD! Run w/ null V0 charges");
365 }
366
367 if (fgTriggerDigits) fgTriggerDigits->Clear();
368
369 TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
370
371 if (!branchtrg)
372 {
373 AliError("Can't get the branch with the EMCAL trigger digits!");
374 return;
375 }
376
377 branchtrg->SetAddress(&fgTriggerDigits);
378 branchtrg->GetEntry(0);
379
380 // Note: fgTriggerProcessor reset done at the end of this method
381 fgTriggerProcessor->Digits2Trigger(fgTriggerDigits, v0M, fTriggerData);
382
383 // Fill ESD
384 AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
385
386 if (trgESD)
387 {
388 trgESD->Allocate(fgTriggerDigits->GetEntriesFast());
389
390 for (Int_t i = 0; i < fgTriggerDigits->GetEntriesFast(); i++)
391 {
392 AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)fgTriggerDigits->At(i);
de39a0ff 393
29c9d15f 394 Int_t px, py;
395 if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py))
396 {
397 Int_t a = -1, t = -1, times[10];
398
399 rdig->GetMaximum(a, t);
400 rdig->GetL0Times(times);
401
402 trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum(), rdig->GetTriggerBits());
403 }
404 }
405
406 trgESD->SetL1Threshold(0, fTriggerData->GetL1GammaThreshold());
407
408 trgESD->SetL1Threshold(1, fTriggerData->GetL1JetThreshold() );
95ffa314 409
410 Int_t v0[2];
411 fTriggerData->GetL1V0(v0);
412
413 trgESD->SetL1V0(v0);
414 trgESD->SetL1FrameMask(fTriggerData->GetL1FrameMask());
415
416 if (!saveOnce && fTriggerData->GetL1DataDecoded())
417 {
418 int type[8] = {0};
419 fTriggerData->GetL1TriggerType(type);
420
421 esd->SetCaloTriggerType(type);
422
423 saveOnce = 1;
424 }
29c9d15f 425 }
426
427 // Resetting
428 fTriggerData->Reset();
de39a0ff 429
0e7c6655 430 //########################################
431 //##############Fill CaloCells###############
432 //########################################
29c9d15f 433
434 //Get input digits and put them in fgDigitsArr, clear the list before
b57cc9b9 435 ReadDigitsArrayFromTree(digitsTree);
29c9d15f 436
b57cc9b9 437 Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
0e7c6655 438 AliDebug(1,Form("%d digits",nDigits));
0e7c6655 439 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
440 emcCells.CreateContainer(nDigits);
c8fe2783 441 emcCells.SetType(AliVCaloCells::kEMCALCell);
0c5b726e 442 Float_t energy = 0;
783153ff 443 Float_t time = 0;
0e7c6655 444 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
b57cc9b9 445 const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
783153ff 446 time = dig->GetTime(); // Time already calibrated in clusterizer
447 energy = dig->GetAmplitude(); // energy calibrated in clusterizer
448 if(energy > 0 ){
449 fgClusterizer->Calibrate(energy,time,dig->GetId()); //Digits already calibrated in clusterizers
450 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
451 emcCells.SetCell(idignew,dig->GetId(),energy, time);
95ffa314 452 idignew++;
29c9d15f 453 }
0e7c6655 454 }
455 }
456 emcCells.SetNumberOfCells(idignew);
457 emcCells.Sort();
29c9d15f 458
0e7c6655 459 //------------------------------------------------------------
460 //-----------------CLUSTERS-----------------------------
461 //------------------------------------------------------------
9dce5a21 462 clustersTree->SetBranchStatus("*",0); //disable all branches
463 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
b57cc9b9 464 if(fgClustersArr) fgClustersArr->Clear();
0e7c6655 465 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
b57cc9b9 466 branch->SetAddress(&fgClustersArr);
9dce5a21 467 branch->GetEntry(0);
468 //clustersTree->GetEvent(0);
29c9d15f 469
b57cc9b9 470 Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
0e7c6655 471 AliDebug(1,Form("%d clusters",nClusters));
5970dfe2 472
85c25c2e 473
6a0cf740 474 //########################################
85c25c2e 475 //##############Fill CaloClusters#############
6a0cf740 476 //########################################
5dee926e 477 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
b57cc9b9 478 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
5970dfe2 479 if(!clust) continue;
c8fe2783 480 //if(clust->GetClusterType()== AliVCluster::kEMCALClusterv1) nRP++; else nPC++;
29c9d15f 481 // clust->Print(); //For debugging
a7a5421e 482 // Get information from EMCAL reconstruction points
85c60a8e 483 Float_t xyz[3];
5dee926e 484 TVector3 gpos;
485 clust->GetGlobalPosition(gpos);
35397e76 486 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 487 xyz[ixyz] = gpos[ixyz];
85c25c2e 488 Float_t elipAxis[2];
489 clust->GetElipsAxis(elipAxis);
29c9d15f 490 //Create digits lists
35397e76 491 Int_t cellMult = clust->GetMultiplicity();
492 //TArrayS digiList(digitMult);
493 Float_t *amplFloat = clust->GetEnergiesList();
494 Int_t *digitInts = clust->GetAbsId();
495 TArrayS absIdList(cellMult);
eb972628 496 TArrayD fracList(cellMult);
29c9d15f 497
35397e76 498 Int_t newCellMult = 0;
499 for (Int_t iCell=0; iCell<cellMult; iCell++) {
500 if (amplFloat[iCell] > 0) {
95ffa314 501 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
502 //Calculate Fraction
503 if(emcCells.GetCellAmplitude(digitInts[iCell])>0 && GetRecParam()->GetUnfold()){
504 fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell]));//get cell calibration value
505
506 }
507 else{
508 fracList[newCellMult] = 0;
509 }
510 newCellMult++;
92da3372 511 }
92da3372 512 }
29c9d15f 513
eb972628 514 absIdList.Set(newCellMult);
515 fracList.Set(newCellMult);
516
35397e76 517 if(newCellMult > 0) { // accept cluster if it has some digit
518 nClustersNew++;
65721814 519 //Primaries
7592dfc4 520 Int_t parentMult = 0;
fa42b1f3 521 Int_t *parentList = clust->GetParents(parentMult);
a7a5421e 522 // fills the ESDCaloCluster
35397e76 523 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
c8fe2783 524 ec->SetType(AliVCluster::kEMCALClusterv1);
7592dfc4 525 ec->SetPosition(xyz);
526 ec->SetE(clust->GetEnergy());
29c9d15f 527
ee08edde 528 //Distance to the nearest bad crystal
529 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
29c9d15f 530
35397e76 531 ec->SetNCells(newCellMult);
532 //Change type of list from short to ushort
533 UShort_t *newAbsIdList = new UShort_t[newCellMult];
ee08edde 534 Double_t *newFracList = new Double_t[newCellMult];
35397e76 535 for(Int_t i = 0; i < newCellMult ; i++) {
536 newAbsIdList[i]=absIdList[i];
de39a0ff 537 newFracList[i] =fracList[i];
35397e76 538 }
539 ec->SetCellsAbsId(newAbsIdList);
eb972628 540 ec->SetCellsAmplitudeFraction(newFracList);
c8fe2783 541 ec->SetDispersion(clust->GetDispersion());
542 ec->SetChi2(-1); //not yet implemented
35397e76 543 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
544 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
78902954 545 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
225cd96d 546 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
5970dfe2 547
29c9d15f 548
35397e76 549 TArrayI arrayParents(parentMult,parentList);
550 ec->AddLabels(arrayParents);
5970dfe2 551 //
552 //Track matching
553 //
554 fMatches->Clear();
555 Int_t nTracks = esd->GetNumberOfTracks();
556 for (Int_t itrack = 0; itrack < nTracks; itrack++)
557 {
558 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
559 if(track->GetEMCALcluster()==iClust)
560 {
561 Double_t dEta=-999, dPhi=-999;
562 Bool_t isMatch = CalculateResidual(track, ec, dEta, dPhi);
563 if(!isMatch)
564 {
a8fbdc61 565 // AliDebug(10, "Not good");
5970dfe2 566 continue;
5970dfe2 567 }
568 AliEMCALMatch *match = new AliEMCALMatch();
569 match->SetIndexT(itrack);
570 match->SetDistance(TMath::Sqrt(dEta*dEta+dPhi*dPhi));
571 match->SetdEta(dEta);
572 match->SetdPhi(dPhi);
573 fMatches->Add(match);
574 }
575 }
576 fMatches->Sort(kSortAscending); //Sort matched tracks from closest to furthest
577 Int_t nMatch = fMatches->GetEntries();
578 TArrayI arrayTrackMatched(nMatch);
579 for(Int_t imatch=0; imatch<nMatch; imatch++)
580 {
581 AliEMCALMatch *match = (AliEMCALMatch*)fMatches->At(imatch);
582 arrayTrackMatched[imatch] = match->GetIndexT();
583 if(imatch==0)
584 {
585 ec->SetTrackDistance(match->GetdPhi(), match->GetdEta());
586 }
587 }
588 ec->AddTracksMatched(arrayTrackMatched);
589
590 //add the cluster to the esd object
eb972628 591 esd->AddCaloCluster(ec);
5970dfe2 592
a7a5421e 593 delete ec;
85d4cbde 594 delete [] newAbsIdList ;
eb972628 595 delete [] newFracList ;
29c9d15f 596 }
597 } // cycle on clusters
5970dfe2 598
599 //
600 //Reset the index of matched cluster for tracks
601 //to the one in CaloCluster array
602 Int_t ncls = esd->GetNumberOfCaloClusters();
603 for(Int_t icl=0; icl<ncls; icl++)
604 {
605 AliESDCaloCluster *cluster = esd->GetCaloCluster(icl);
606 if(!cluster || !cluster->IsEMCAL()) continue;
607 TArrayI *trackIndex = cluster->GetTracksMatched();
608 for(Int_t itr=0; itr<trackIndex->GetSize(); itr++)
609 {
610 AliESDtrack *track = esd->GetTrack(trackIndex->At(itr));
611 track->SetEMCALcluster(cluster->GetID());
612 }
613 }
29c9d15f 614
29c9d15f 615
616 //Fill ESDCaloCluster with PID weights
617 AliEMCALPID *pid = new AliEMCALPID;
618 //pid->SetPrintInfo(kTRUE);
619 pid->SetReconstructor(kTRUE);
620 pid->RunPID(esd);
621 delete pid;
622
623 //Store EMCAL misalignment matrixes
624 FillMisalMatrixes(esd) ;
625
0c5b726e 626}
627
628//==================================================================================
629void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
29c9d15f 630 //Store EMCAL matrixes in ESD Header
631
632 //Check, if matrixes was already stored
633 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
634 if(esd->GetEMCALMatrix(sm)!=0)
635 return ;
636 }
637
638 //Create and store matrixes
639 if(!gGeoManager){
640 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
641 return ;
642 }
643 //Note, that owner of copied marixes will be header
7e1d9a9b 644 const Int_t bufsize = 255;
29c9d15f 645 char path[bufsize] ;
646 TGeoHMatrix * m = 0x0;
647 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
648 snprintf(path,bufsize,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
649 if(sm >= 10) snprintf(path,bufsize,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
650
651 if (gGeoManager->CheckPath(path)){
652 gGeoManager->cd(path);
653 m = gGeoManager->GetCurrentMatrix() ;
654 // printf("================================================= \n");
655 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
656 // m->Print("");
657 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
658 // printf("================================================= \n");
659 }
660 else{
661 esd->SetEMCALMatrix(NULL,sm) ;
662 }
663 }
f6019cda 664}
dc293ae9 665
9517d886 666//__________________________________________________________________________
85c25c2e 667void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
668{
29c9d15f 669 // Read the digits from the input tree
670 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
671
672 // Clear previous digits in the list
673 if(fgDigitsArr){
b57cc9b9 674 fgDigitsArr->Clear("C");
85c25c2e 675 }
29c9d15f 676 else{
677 // It should not happen, but just in case ...
678 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
679 }
680
85c25c2e 681 // Read the digits from the input tree
682 TBranch *branch = digitsTree->GetBranch("EMCAL");
683 if (!branch) {
684 AliError("can't get the branch with the EMCAL digits !");
685 return;
29c9d15f 686 }
687
85c25c2e 688 branch->SetAddress(&fgDigitsArr);
689 branch->GetEntry(0);
690}
98e9578e 691
5970dfe2 692//==================================================================================
693Bool_t AliEMCALReconstructor::CalculateResidual(AliESDtrack *track, AliESDCaloCluster *cluster, Double_t &dEta, Double_t &dPhi)const
694{
695 //
696 // calculate the residual between track and cluster
697 //
698
699 // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
700 // Otherwise use the TPCInner point
456126ad 701 AliExternalTrackParam *trkParam = 0;
5970dfe2 702 const AliESDfriendTrack* friendTrack = track->GetFriendTrack();
703 if(friendTrack && friendTrack->GetTPCOut())
704 trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
705 else
706 trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
707 if(!trkParam) return kFALSE;
708
709 //Perform extrapolation
710 Double_t trkPos[3];
711 Float_t clsPos[3];
712
456126ad 713 AliExternalTrackParam trkParamTmp (*trkParam);
5970dfe2 714 cluster->GetPosition(clsPos);
715 TVector3 vec(clsPos[0],clsPos[1],clsPos[2]);
716 Double_t alpha = ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
717 //Rotate to proper local coordinate
718 vec.RotateZ(-alpha);
456126ad 719 trkParamTmp.Rotate(alpha);
5970dfe2 720 //extrapolation is done here
456126ad 721 if(!AliTrackerBase::PropagateTrackToBxByBz(&trkParamTmp, vec.X(), track->GetMass(), GetRecParam()->GetExtrapolateStep(), kFALSE, 0.8, -1))
5970dfe2 722 return kFALSE;
723
724 //Calculate the residuals
456126ad 725 trkParamTmp.GetXYZ(trkPos);
5970dfe2 726
727 TVector3 clsPosVec(clsPos[0],clsPos[1],clsPos[2]);
728 TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
729
730 Double_t clsPhi = clsPosVec.Phi();
731 if(clsPhi<0) clsPhi+=2*TMath::Pi();
732 Double_t trkPhi = trkPosVec.Phi();
733 if(trkPhi<0) trkPhi+=2*TMath::Pi();
734
735 dPhi = clsPhi-trkPhi;
736 dEta = clsPosVec.Eta()-trkPosVec.Eta();
737
738 return kTRUE;
739}
740
741//
742//==================================================================================
743//
744AliEMCALReconstructor::AliEMCALMatch::AliEMCALMatch()
745 : TObject(),
746 fIndexT(-1),
747 fDistance(-999.),
748 fdEta(-999.),
749 fdPhi(-999.)
750{
751 //default constructor
916f1e76 752
5970dfe2 753}
754
755//
756//==================================================================================
757//
758AliEMCALReconstructor::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
759 : TObject(),
760 fIndexT(copy.fIndexT),
761 fDistance(copy.fDistance),
762 fdEta(copy.fdEta),
763 fdPhi(copy.fdPhi)
764{
765 //copy ctor
766}
767
768//
769//==================================================================================
770//
771Int_t AliEMCALReconstructor::AliEMCALMatch::Compare(const TObject *obj) const
772{
773 //
774 // Compare wrt the residual
775 //
776
777 AliEMCALReconstructor::AliEMCALMatch *that = (AliEMCALReconstructor::AliEMCALMatch*)obj;
778
779 Double_t thisDist = fDistance;//fDistance;
780 Double_t thatDist = that->fDistance;//that->GetDistance();
781
782 if (thisDist > thatDist) return 1;
783 else if (thisDist < thatDist) return -1;
784 return 0;
785}