- added OCDB folder and entry for the cluster finders' comparison component
[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"
af885e0f 40#include "AliESDEvent.h"
89ffc0b0 41#include "AliESDCaloCluster.h"
0e7c6655 42#include "AliESDCaloCells.h"
6a0cf740 43#include "AliESDtrack.h"
5dee926e 44#include "AliEMCALLoader.h"
98e9578e 45#include "AliEMCALRawUtils.h"
0e7c6655 46#include "AliEMCALDigit.h"
f6019cda 47#include "AliEMCALClusterizerv1.h"
5dee926e 48#include "AliEMCALRecPoint.h"
dc293ae9 49#include "AliEMCALPID.h"
0964c2e9 50#include "AliEMCALTrigger.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"
1d59832c 64
85c25c2e 65ClassImp(AliEMCALReconstructor)
f6019cda 66
ba6de5ea 67const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
65bdc82f 68AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
9517d886 69AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
85c25c2e 70TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
916f1e76 71AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
f6019cda 72//____________________________________________________________________________
18a21c7c 73AliEMCALReconstructor::AliEMCALReconstructor()
40164976 74 : fDebug(kFALSE), fList(0), fGeom(0),fCalibData(0),fPedestalData(0)
f6019cda 75{
76 // ctor
65bdc82f 77
78 fgRawUtils = new AliEMCALRawUtils;
72c58de0 79
80 //To make sure we match with the geometry in a simulation file,
81 //let's try to get it first. If not, take the default geometry
33c3c91a 82 AliRunLoader *rl = AliRunLoader::Instance();
72c58de0 83 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
84 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
85 } else {
86 AliInfo(Form("Using default geometry in reconstruction"));
937d0661 87 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
65bdc82f 88 }
0e7c6655 89
0c5b726e 90 //Get calibration parameters
91 if(!fCalibData)
92 {
93 AliCDBEntry *entry = (AliCDBEntry*)
94 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
95 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
96 }
97
98 if(!fCalibData)
99 AliFatal("Calibration parameters not found in CDB!");
100
40164976 101 //Get calibration parameters
102 if(!fPedestalData)
103 {
104 AliCDBEntry *entry = (AliCDBEntry*)
105 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
106 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
107 }
108
109 if(!fPedestalData)
110 AliFatal("Dead map not found in CDB!");
111
112
0c5b726e 113 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
40164976 114 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
0c5b726e 115
72c58de0 116 if(!fGeom) AliFatal(Form("Could not get geometry!"));
117
fff39dd1 118 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
119
120 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
121
122 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
123 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
f6019cda 124}
125
0a4cb131 126//____________________________________________________________________________
f6019cda 127AliEMCALReconstructor::~AliEMCALReconstructor()
128{
129 // dtor
65bdc82f 130 delete fGeom;
5e3106bc 131 delete fgRawUtils;
132 delete fgClusterizer;
916f1e76 133 delete fgTriggerProcessor;
134
aaa3cb7c 135 AliCodeTimer::Instance()->Print();
f6019cda 136}
137
40871053 138// //____________________________________________________________________________
139// void AliEMCALReconstructor::Init()
140// {
141// // Trigger hists - Oct 24, 2007
142// fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
143// }
85c25c2e 144
145//____________________________________________________________________________
c47157cd 146void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
f6019cda 147{
148 // method called by AliReconstruction;
149 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
150 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
151 // the global tracking.
c47157cd 152 // Works on the current event.
fa42b1f3 153
1a429a6b 154 AliCodeTimerAuto("",0)
aaa3cb7c 155
85c25c2e 156 ReadDigitsArrayFromTree(digitsTree);
0832a2bf 157 fgClusterizer->InitParameters();
4601e3a7 158 fgClusterizer->SetOutput(clustersTree);
916f1e76 159
160 AliEMCALTriggerData* trgData = new AliEMCALTriggerData();
161
162 Int_t bufferSize = 32000;
163
164 if (TBranch* triggerBranch = clustersTree->GetBranch("EMTRG"))
165 triggerBranch->SetAddress(&trgData);
166 else
167 clustersTree->Branch("EMTRG","AliEMCALTriggerData",&trgData,bufferSize);
168
916f1e76 169 TClonesArray *trgDigits = new TClonesArray("AliEMCALRawDigit",1000);
170 TBranch *branchdig = digitsTree->GetBranch("EMTRG");
171 if (!branchdig)
172 {
173 AliError("Can't get the branch with the EMCAL trigger digits !");
174 return;
175 }
176
177 branchdig->SetAddress(&trgDigits);
178 branchdig->GetEntry(0);
179
fff39dd1 180 Int_t v0M[2] = {0,0};
181 fgTriggerProcessor->Digits2Trigger(trgDigits, v0M, trgData);
916f1e76 182
183 trgDigits->Delete();
fff39dd1 184 delete trgDigits; trgDigits = 0x0;
0341167b 185
85c25c2e 186 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
187
9517d886 188 fgClusterizer->SetInput(digitsTree);
9517d886 189
85c25c2e 190 if(Debug())
9517d886 191 fgClusterizer->Digits2Clusters("deb all") ;
85c25c2e 192 else
9517d886 193 fgClusterizer->Digits2Clusters("");
194
195 fgClusterizer->Clear();
85c25c2e 196
197 }
9517d886 198
916f1e76 199 clustersTree->Fill();
200
fff39dd1 201 delete trgData; trgData = 0x0;
f6019cda 202}
203
204//____________________________________________________________________________
c47157cd 205void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
98e9578e 206
a68156e6 207{
c47157cd 208 // Conversion from raw data to
209 // EMCAL digits.
210 // Works on a single-event basis
85c60a8e 211
98e9578e 212 rawReader->Reset() ;
98e9578e 213
3e5fa09c 214 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
916f1e76 215 TClonesArray *digitsTrg = new TClonesArray("AliEMCALRawDigit", 200);
216
c47157cd 217 Int_t bufsize = 32000;
218 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
916f1e76 219 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
98e9578e 220
65bdc82f 221 //must be done here because, in constructor, option is not yet known
222 fgRawUtils->SetOption(GetOption());
b4133f05 223
0832a2bf 224 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
225 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
226 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
227 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
228 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
9f467289 229 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
230 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
46f1d25f 231 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
f4a4dc82 232 fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
233 fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
46f1d25f 234
916f1e76 235 fgRawUtils->Raw2Digits(rawReader,digitsArr,fPedestalData,digitsTrg);
c615db53 236
237 digitsTree->Fill();
89d338a6 238 digitsArr->Delete();
916f1e76 239 digitsTrg->Delete();
89d338a6 240 delete digitsArr;
916f1e76 241 delete digitsTrg;
c615db53 242
a68156e6 243}
244
85c25c2e 245
a68156e6 246//____________________________________________________________________________
0e7c6655 247void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
c47157cd 248 AliESDEvent* esd) const
f6019cda 249{
98e9578e 250 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
85c25c2e 251 // and V0
c47157cd 252 // Works on the current event
85c25c2e 253 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
254 //return;
92da3372 255
0e7c6655 256 //########################################
257 //##############Fill CaloCells###############
258 //########################################
aaa3cb7c 259
0e7c6655 260 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
261 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
262 if (!branchdig) {
0c5b726e 263 AliError("can't get the branch with the EMCAL digits !");
0e7c6655 264 return;
265 }
266 branchdig->SetAddress(&digits);
267 digitsTree->GetEvent(0);
268 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
269 AliDebug(1,Form("%d digits",nDigits));
270
271 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
272 emcCells.CreateContainer(nDigits);
273 emcCells.SetType(AliESDCaloCells::kEMCALCell);
0c5b726e 274 Float_t energy = 0;
0e7c6655 275 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
276 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
829ba234 277 if(dig->GetAmplitude() > 0 ){
278 energy = (static_cast<AliEMCALClusterizerv1*> (fgClusterizer))->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
40164976 279 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
280 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
281 idignew++;
282 }
0e7c6655 283 }
284 }
285 emcCells.SetNumberOfCells(idignew);
286 emcCells.Sort();
287
288 //------------------------------------------------------------
289 //-----------------CLUSTERS-----------------------------
290 //------------------------------------------------------------
9dce5a21 291 clustersTree->SetBranchStatus("*",0); //disable all branches
292 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
293
0e7c6655 294 TObjArray *clusters = new TObjArray(100);
295 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
296 branch->SetAddress(&clusters);
9dce5a21 297 branch->GetEntry(0);
298 //clustersTree->GetEvent(0);
0e7c6655 299
300 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
301 AliDebug(1,Form("%d clusters",nClusters));
85c25c2e 302
6a0cf740 303 //######################################################
304 //#######################TRACK MATCHING###############
305 //######################################################
306 //Fill list of integers, each one is index of track to which the cluster belongs.
307
308 // step 1 - initialize array of matched track indexes
309 Int_t *matchedTrack = new Int_t[nClusters];
310 for (Int_t iclus = 0; iclus < nClusters; iclus++)
311 matchedTrack[iclus] = -1; // neg. index --> no matched track
312
313 // step 2, change the flag for all matched clusters found in tracks
314 Int_t iemcalMatch = -1;
315 Int_t endtpc = esd->GetNumberOfTracks();
316 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
317 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
318 iemcalMatch = track->GetEMCALcluster();
65f4a419 319 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
6a0cf740 320 }
85c25c2e 321
6a0cf740 322 //########################################
85c25c2e 323 //##############Fill CaloClusters#############
6a0cf740 324 //########################################
5dee926e 325 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
c47157cd 326 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
8ada0ffe 327 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
85c60a8e 328 if (Debug()) clust->Print();
a7a5421e 329 // Get information from EMCAL reconstruction points
85c60a8e 330 Float_t xyz[3];
5dee926e 331 TVector3 gpos;
332 clust->GetGlobalPosition(gpos);
35397e76 333 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 334 xyz[ixyz] = gpos[ixyz];
85c25c2e 335 Float_t elipAxis[2];
336 clust->GetElipsAxis(elipAxis);
35397e76 337 //Create digits lists
338 Int_t cellMult = clust->GetMultiplicity();
339 //TArrayS digiList(digitMult);
340 Float_t *amplFloat = clust->GetEnergiesList();
341 Int_t *digitInts = clust->GetAbsId();
342 TArrayS absIdList(cellMult);
eb972628 343 TArrayD fracList(cellMult);
35397e76 344
345 Int_t newCellMult = 0;
346 for (Int_t iCell=0; iCell<cellMult; iCell++) {
347 if (amplFloat[iCell] > 0) {
348 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
eb972628 349 //Uncomment when unfolding is done
350 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
351 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
352 //else
353 fracList[newCellMult] = 0;
35397e76 354 newCellMult++;
92da3372 355 }
92da3372 356 }
85c25c2e 357
eb972628 358 absIdList.Set(newCellMult);
359 fracList.Set(newCellMult);
360
35397e76 361 if(newCellMult > 0) { // accept cluster if it has some digit
362 nClustersNew++;
65721814 363 //Primaries
7592dfc4 364 Int_t parentMult = 0;
fa42b1f3 365 Int_t *parentList = clust->GetParents(parentMult);
a7a5421e 366 // fills the ESDCaloCluster
35397e76 367 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
368 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
7592dfc4 369 ec->SetPosition(xyz);
370 ec->SetE(clust->GetEnergy());
40164976 371
372 //Distance to the nearest bad crystal
373 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
374
35397e76 375 ec->SetNCells(newCellMult);
376 //Change type of list from short to ushort
377 UShort_t *newAbsIdList = new UShort_t[newCellMult];
eb972628 378 Double_t *newFracList = new Double_t[newCellMult];
35397e76 379 for(Int_t i = 0; i < newCellMult ; i++) {
380 newAbsIdList[i]=absIdList[i];
eb972628 381 newFracList[i]=fracList[i];
35397e76 382 }
383 ec->SetCellsAbsId(newAbsIdList);
eb972628 384 ec->SetCellsAmplitudeFraction(newFracList);
35397e76 385 ec->SetClusterDisp(clust->GetDispersion());
386 ec->SetClusterChi2(-1); //not yet implemented
387 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
388 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
78902954 389 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
225cd96d 390 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
35397e76 391 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
392 arrayTrackMatched[0]= matchedTrack[iClust];
393 ec->AddTracksMatched(arrayTrackMatched);
394
395 TArrayI arrayParents(parentMult,parentList);
396 ec->AddLabels(arrayParents);
397
6a0cf740 398 // add the cluster to the esd object
eb972628 399 esd->AddCaloCluster(ec);
a7a5421e 400 delete ec;
85d4cbde 401 delete [] newAbsIdList ;
eb972628 402 delete [] newFracList ;
35397e76 403 }
404 } // cycle on clusters
85c25c2e 405
35397e76 406 delete [] matchedTrack;
85c25c2e 407
35397e76 408 //Fill ESDCaloCluster with PID weights
1942834a 409 AliEMCALPID *pid = new AliEMCALPID;
410 //pid->SetPrintInfo(kTRUE);
411 pid->SetReconstructor(kTRUE);
412 pid->RunPID(esd);
413 delete pid;
eb972628 414
1942834a 415 delete digits;
416 delete clusters;
eb972628 417
1942834a 418 //Store EMCAL misalignment matrixes
419 FillMisalMatrixes(esd) ;
0c5b726e 420
421}
422
423//==================================================================================
424void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
425 //Store EMCAL matrixes in ESD Header
426
427 //Check, if matrixes was already stored
cb8a44fb 428 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
0c5b726e 429 if(esd->GetEMCALMatrix(sm)!=0)
430 return ;
431 }
432
433 //Create and store matrixes
434 if(!gGeoManager){
435 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
436 return ;
437 }
438 //Note, that owner of copied marixes will be header
439 char path[255] ;
5e3106bc 440 TGeoHMatrix * m = 0x0;
cb8a44fb 441 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
0c5b726e 442 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
443 if(sm >= 10) sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
444
9ddc5deb 445 if (gGeoManager->CheckPath(path)){
cb8a44fb 446 gGeoManager->cd(path);
0c5b726e 447 m = gGeoManager->GetCurrentMatrix() ;
cb8a44fb 448// printf("================================================= \n");
449// printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
450// m->Print("");
0c5b726e 451 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
cb8a44fb 452// printf("================================================= \n");
0c5b726e 453 }
454 else{
455 esd->SetEMCALMatrix(NULL,sm) ;
456 }
457 }
f6019cda 458}
dc293ae9 459
0c5b726e 460
461
9517d886 462//__________________________________________________________________________
85c25c2e 463void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
464{
465 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
466 if(fgDigitsArr) {
467 // Clear previous digits
468 fgDigitsArr->Delete();
469 delete fgDigitsArr;
470 }
471 // Read the digits from the input tree
472 TBranch *branch = digitsTree->GetBranch("EMCAL");
473 if (!branch) {
474 AliError("can't get the branch with the EMCAL digits !");
475 return;
476 }
477 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
478 branch->SetAddress(&fgDigitsArr);
479 branch->GetEntry(0);
480}
98e9578e 481
916f1e76 482