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