]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALReconstructor.cxx
Return supermodule number from eta and phi, taking into account the number of supermo...
[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
f6019cda 126//____________________________________________________________________________
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
f6019cda 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);
e853f058 159
916f1e76 160 AliEMCALTriggerData* trgData = new AliEMCALTriggerData();
161
162 Int_t bufferSize = 32000;
163
164 if (TBranch* triggerBranch = clustersTree->GetBranch("EMTRG"))
e853f058 165 triggerBranch->SetAddress(&trgData);
166 else
167 clustersTree->Branch("EMTRG","AliEMCALTriggerData",&trgData,bufferSize);
916f1e76 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);
916f1e76 179
e853f058 180 //Skip clusterization of LED events
181 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
0341167b 182
e853f058 183 Int_t v0M[2] = {0,0};
184 fgTriggerProcessor->Digits2Trigger(trgDigits, v0M, trgData);
185
186
187 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
85c25c2e 188
e853f058 189 fgClusterizer->SetInput(digitsTree);
9517d886 190
e853f058 191 if(Debug())
192 fgClusterizer->Digits2Clusters("deb all") ;
193 else
194 fgClusterizer->Digits2Clusters("");
9517d886 195
e853f058 196 fgClusterizer->Clear();
9517d886 197
e853f058 198 }//digits array exists and has somethind
199 }//not a LED event
200
916f1e76 201 clustersTree->Fill();
e853f058 202 trgDigits->Delete();
203 delete trgDigits; trgDigits = 0x0;
204 delete trgData; trgData = 0x0;
916f1e76 205
f6019cda 206}
207
a68156e6 208//____________________________________________________________________________
c47157cd 209void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
98e9578e 210
a68156e6 211{
c47157cd 212 // Conversion from raw data to
213 // EMCAL digits.
214 // Works on a single-event basis
85c60a8e 215
98e9578e 216 rawReader->Reset() ;
98e9578e 217
3e5fa09c 218 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
916f1e76 219 TClonesArray *digitsTrg = new TClonesArray("AliEMCALRawDigit", 200);
220
c47157cd 221 Int_t bufsize = 32000;
222 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
916f1e76 223 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
46f1d25f 224
e853f058 225 //Skip calibration events do the rest
226 Bool_t doFit = kTRUE;
227 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
228 if (doFit){
229 //must be done here because, in constructor, option is not yet known
230 fgRawUtils->SetOption(GetOption());
231
232 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
233 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
234 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
235 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
236 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
237 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
238 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
239 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
240 fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
241 fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
242
243 fgRawUtils->Raw2Digits(rawReader,digitsArr,fPedestalData,digitsTrg);
793176c1 244 }//skip calibration event
e853f058 245 else{
246 AliDebug(1," Calibration Event, skip!");
e853f058 247 }
248
c615db53 249 digitsTree->Fill();
89d338a6 250 digitsArr->Delete();
916f1e76 251 digitsTrg->Delete();
89d338a6 252 delete digitsArr;
916f1e76 253 delete digitsTrg;
c615db53 254
a68156e6 255}
256
85c25c2e 257
f6019cda 258//____________________________________________________________________________
0e7c6655 259void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
c47157cd 260 AliESDEvent* esd) const
f6019cda 261{
98e9578e 262 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
85c25c2e 263 // and V0
c47157cd 264 // Works on the current event
85c25c2e 265 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
266 //return;
92da3372 267
0e7c6655 268 //########################################
269 //##############Fill CaloCells###############
270 //########################################
aaa3cb7c 271
0e7c6655 272 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
273 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
274 if (!branchdig) {
0c5b726e 275 AliError("can't get the branch with the EMCAL digits !");
0e7c6655 276 return;
277 }
278 branchdig->SetAddress(&digits);
279 digitsTree->GetEvent(0);
280 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
281 AliDebug(1,Form("%d digits",nDigits));
282
283 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
284 emcCells.CreateContainer(nDigits);
285 emcCells.SetType(AliESDCaloCells::kEMCALCell);
0c5b726e 286 Float_t energy = 0;
0e7c6655 287 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
288 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
829ba234 289 if(dig->GetAmplitude() > 0 ){
290 energy = (static_cast<AliEMCALClusterizerv1*> (fgClusterizer))->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
40164976 291 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
292 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
293 idignew++;
294 }
0e7c6655 295 }
296 }
297 emcCells.SetNumberOfCells(idignew);
298 emcCells.Sort();
299
300 //------------------------------------------------------------
301 //-----------------CLUSTERS-----------------------------
302 //------------------------------------------------------------
9dce5a21 303 clustersTree->SetBranchStatus("*",0); //disable all branches
304 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
305
0e7c6655 306 TObjArray *clusters = new TObjArray(100);
307 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
308 branch->SetAddress(&clusters);
9dce5a21 309 branch->GetEntry(0);
310 //clustersTree->GetEvent(0);
0e7c6655 311
312 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
313 AliDebug(1,Form("%d clusters",nClusters));
85c25c2e 314
6a0cf740 315 //######################################################
316 //#######################TRACK MATCHING###############
317 //######################################################
318 //Fill list of integers, each one is index of track to which the cluster belongs.
319
320 // step 1 - initialize array of matched track indexes
321 Int_t *matchedTrack = new Int_t[nClusters];
322 for (Int_t iclus = 0; iclus < nClusters; iclus++)
323 matchedTrack[iclus] = -1; // neg. index --> no matched track
324
325 // step 2, change the flag for all matched clusters found in tracks
326 Int_t iemcalMatch = -1;
327 Int_t endtpc = esd->GetNumberOfTracks();
328 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
329 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
330 iemcalMatch = track->GetEMCALcluster();
65f4a419 331 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
6a0cf740 332 }
85c25c2e 333
6a0cf740 334 //########################################
85c25c2e 335 //##############Fill CaloClusters#############
6a0cf740 336 //########################################
5dee926e 337 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
c47157cd 338 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
8ada0ffe 339 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
85c60a8e 340 if (Debug()) clust->Print();
a7a5421e 341 // Get information from EMCAL reconstruction points
85c60a8e 342 Float_t xyz[3];
5dee926e 343 TVector3 gpos;
344 clust->GetGlobalPosition(gpos);
35397e76 345 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 346 xyz[ixyz] = gpos[ixyz];
85c25c2e 347 Float_t elipAxis[2];
348 clust->GetElipsAxis(elipAxis);
35397e76 349 //Create digits lists
350 Int_t cellMult = clust->GetMultiplicity();
351 //TArrayS digiList(digitMult);
352 Float_t *amplFloat = clust->GetEnergiesList();
353 Int_t *digitInts = clust->GetAbsId();
354 TArrayS absIdList(cellMult);
eb972628 355 TArrayD fracList(cellMult);
35397e76 356
357 Int_t newCellMult = 0;
358 for (Int_t iCell=0; iCell<cellMult; iCell++) {
359 if (amplFloat[iCell] > 0) {
360 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
eb972628 361 //Uncomment when unfolding is done
362 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
363 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
364 //else
365 fracList[newCellMult] = 0;
35397e76 366 newCellMult++;
92da3372 367 }
92da3372 368 }
85c25c2e 369
eb972628 370 absIdList.Set(newCellMult);
371 fracList.Set(newCellMult);
372
35397e76 373 if(newCellMult > 0) { // accept cluster if it has some digit
374 nClustersNew++;
65721814 375 //Primaries
7592dfc4 376 Int_t parentMult = 0;
fa42b1f3 377 Int_t *parentList = clust->GetParents(parentMult);
a7a5421e 378 // fills the ESDCaloCluster
35397e76 379 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
380 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
7592dfc4 381 ec->SetPosition(xyz);
382 ec->SetE(clust->GetEnergy());
40164976 383
384 //Distance to the nearest bad crystal
385 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
386
35397e76 387 ec->SetNCells(newCellMult);
388 //Change type of list from short to ushort
389 UShort_t *newAbsIdList = new UShort_t[newCellMult];
eb972628 390 Double_t *newFracList = new Double_t[newCellMult];
35397e76 391 for(Int_t i = 0; i < newCellMult ; i++) {
392 newAbsIdList[i]=absIdList[i];
eb972628 393 newFracList[i]=fracList[i];
35397e76 394 }
395 ec->SetCellsAbsId(newAbsIdList);
eb972628 396 ec->SetCellsAmplitudeFraction(newFracList);
35397e76 397 ec->SetClusterDisp(clust->GetDispersion());
398 ec->SetClusterChi2(-1); //not yet implemented
399 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
400 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
78902954 401 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
225cd96d 402 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
35397e76 403 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
404 arrayTrackMatched[0]= matchedTrack[iClust];
405 ec->AddTracksMatched(arrayTrackMatched);
406
407 TArrayI arrayParents(parentMult,parentList);
408 ec->AddLabels(arrayParents);
409
6a0cf740 410 // add the cluster to the esd object
eb972628 411 esd->AddCaloCluster(ec);
a7a5421e 412 delete ec;
85d4cbde 413 delete [] newAbsIdList ;
eb972628 414 delete [] newFracList ;
35397e76 415 }
416 } // cycle on clusters
85c25c2e 417
35397e76 418 delete [] matchedTrack;
85c25c2e 419
35397e76 420 //Fill ESDCaloCluster with PID weights
1942834a 421 AliEMCALPID *pid = new AliEMCALPID;
422 //pid->SetPrintInfo(kTRUE);
423 pid->SetReconstructor(kTRUE);
424 pid->RunPID(esd);
425 delete pid;
eb972628 426
1942834a 427 delete digits;
428 delete clusters;
eb972628 429
1942834a 430 //Store EMCAL misalignment matrixes
431 FillMisalMatrixes(esd) ;
0c5b726e 432
433}
434
435//==================================================================================
436void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
437 //Store EMCAL matrixes in ESD Header
438
439 //Check, if matrixes was already stored
cb8a44fb 440 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
0c5b726e 441 if(esd->GetEMCALMatrix(sm)!=0)
442 return ;
443 }
444
445 //Create and store matrixes
446 if(!gGeoManager){
447 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
448 return ;
449 }
450 //Note, that owner of copied marixes will be header
451 char path[255] ;
5e3106bc 452 TGeoHMatrix * m = 0x0;
cb8a44fb 453 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
0c5b726e 454 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
455 if(sm >= 10) sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
456
9ddc5deb 457 if (gGeoManager->CheckPath(path)){
cb8a44fb 458 gGeoManager->cd(path);
0c5b726e 459 m = gGeoManager->GetCurrentMatrix() ;
cb8a44fb 460// printf("================================================= \n");
461// printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
462// m->Print("");
0c5b726e 463 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
cb8a44fb 464// printf("================================================= \n");
0c5b726e 465 }
466 else{
467 esd->SetEMCALMatrix(NULL,sm) ;
468 }
469 }
f6019cda 470}
dc293ae9 471
0c5b726e 472
473
9517d886 474//__________________________________________________________________________
85c25c2e 475void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
476{
477 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
478 if(fgDigitsArr) {
479 // Clear previous digits
480 fgDigitsArr->Delete();
481 delete fgDigitsArr;
482 }
483 // Read the digits from the input tree
484 TBranch *branch = digitsTree->GetBranch("EMCAL");
485 if (!branch) {
486 AliError("can't get the branch with the EMCAL digits !");
487 return;
488 }
489 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
490 branch->SetAddress(&fgDigitsArr);
491 branch->GetEntry(0);
492}
98e9578e 493
916f1e76 494