1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
20 //-- Yves Schutz (SUBATECH)
21 // Reconstruction class. Redesigned from the old AliReconstructionner class and
22 // derived from STEER/AliReconstructor.
24 //-- Aleksei Pavlinov : added staf for EMCAL jet trigger 9Apr 25, 2008)
25 // : fgDigitsArr should read just once at event
27 // --- ROOT system ---
29 #include <TClonesArray.h>
31 #include "TGeoManager.h"
32 #include "TGeoMatrix.h"
34 // --- Standard library ---
36 // --- AliRoot header files ---
37 #include "AliEMCALReconstructor.h"
39 #include "AliCodeTimer.h"
40 #include "AliESDEvent.h"
41 #include "AliESDCaloCluster.h"
42 #include "AliESDCaloCells.h"
43 #include "AliESDtrack.h"
44 #include "AliEMCALLoader.h"
45 #include "AliEMCALRawUtils.h"
46 #include "AliEMCALDigit.h"
47 #include "AliEMCALClusterizerv1.h"
48 #include "AliEMCALClusterizerNxN.h"
49 #include "AliEMCALRecPoint.h"
50 #include "AliEMCALPID.h"
51 #include "AliEMCALTrigger.h"
52 #include "AliRawReader.h"
53 #include "AliCDBEntry.h"
54 #include "AliCDBManager.h"
55 #include "AliEMCALGeometry.h"
57 #include "AliESDVZERO.h"
58 #include "AliCDBManager.h"
59 #include "AliRunLoader.h"
61 #include "AliEMCALTriggerData.h"
62 #include "AliEMCALTriggerElectronics.h"
63 #include "AliEMCALTriggerDCSConfigDB.h"
64 #include "AliEMCALTriggerDCSConfig.h"
66 ClassImp(AliEMCALReconstructor)
68 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
69 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
70 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
71 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
72 AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
73 //____________________________________________________________________________
74 AliEMCALReconstructor::AliEMCALReconstructor()
75 : fDebug(kFALSE), fList(0), fGeom(0),fCalibData(0),fPedestalData(0)
79 fgRawUtils = new AliEMCALRawUtils;
81 //To make sure we match with the geometry in a simulation file,
82 //let's try to get it first. If not, take the default geometry
83 AliRunLoader *rl = AliRunLoader::Instance();
84 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
85 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
87 AliInfo(Form("Using default geometry in reconstruction"));
88 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
91 //Get calibration parameters
94 AliCDBEntry *entry = (AliCDBEntry*)
95 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
96 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
100 AliFatal("Calibration parameters not found in CDB!");
102 //Get calibration parameters
105 AliCDBEntry *entry = (AliCDBEntry*)
106 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
107 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
111 AliFatal("Dead map not found in CDB!");
115 if(!fGeom) AliFatal(Form("Could not get geometry!"));
117 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
119 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
121 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
122 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
125 //____________________________________________________________________________
126 AliEMCALReconstructor::~AliEMCALReconstructor()
131 delete fgClusterizer;
132 delete fgTriggerProcessor;
134 AliCodeTimer::Instance()->Print();
137 // //____________________________________________________________________________
138 // void AliEMCALReconstructor::Init()
140 // // Trigger hists - Oct 24, 2007
141 // fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
144 //____________________________________________________________________________
145 void AliEMCALReconstructor::InitClusterizer()
147 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
149 AliEMCALRecParam *recParam = NULL;
150 AliCDBEntry *entry = (AliCDBEntry*)
151 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
152 //Get The reco param for the default event specie
154 recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
157 AliFatal("RecoParam not found in CDB!");
159 if (recParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
161 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
165 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
170 //____________________________________________________________________________
171 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
173 // method called by AliReconstruction;
174 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
175 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
176 // the global tracking.
177 // Works on the current event.
179 AliCodeTimerAuto("",0)
181 ReadDigitsArrayFromTree(digitsTree);
183 fgClusterizer->InitParameters();
184 fgClusterizer->SetOutput(clustersTree);
186 AliEMCALTriggerData* trgData = new AliEMCALTriggerData();
188 Int_t bufferSize = 32000;
190 if (TBranch* triggerBranch = clustersTree->GetBranch("EMTRG"))
191 triggerBranch->SetAddress(&trgData);
193 clustersTree->Branch("EMTRG","AliEMCALTriggerData",&trgData,bufferSize);
195 TClonesArray *trgDigits = new TClonesArray("AliEMCALRawDigit",1000);
196 TBranch *branchdig = digitsTree->GetBranch("EMTRG");
199 AliError("Can't get the branch with the EMCAL trigger digits !");
203 branchdig->SetAddress(&trgDigits);
204 branchdig->GetEntry(0);
206 //Skip clusterization of LED events
207 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
209 Int_t v0M[2] = {0,0};
210 fgTriggerProcessor->Digits2Trigger(trgDigits, v0M, trgData);
213 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
215 fgClusterizer->SetInput(digitsTree);
218 fgClusterizer->Digits2Clusters("deb all") ;
220 fgClusterizer->Digits2Clusters("");
222 fgClusterizer->Clear();
224 }//digits array exists and has somethind
227 clustersTree->Fill();
229 delete trgDigits; trgDigits = 0x0;
230 delete trgData; trgData = 0x0;
234 //____________________________________________________________________________
235 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
238 // Conversion from raw data to
240 // Works on a single-event basis
244 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
245 TClonesArray *digitsTrg = new TClonesArray("AliEMCALRawDigit", 200);
247 Int_t bufsize = 32000;
248 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
249 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
251 //Skip calibration events do the rest
252 Bool_t doFit = kTRUE;
253 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
255 //must be done here because, in constructor, option is not yet known
256 fgRawUtils->SetOption(GetOption());
258 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
259 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
260 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
261 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
262 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
263 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
264 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
265 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
266 fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
267 fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
269 fgRawUtils->Raw2Digits(rawReader,digitsArr,fPedestalData,digitsTrg);
270 }//skip calibration event
272 AliDebug(1," Calibration Event, skip!");
284 //____________________________________________________________________________
285 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
286 AliESDEvent* esd) const
288 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
290 // Works on the current event
291 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
294 //########################################
295 //##############Fill CaloCells###############
296 //########################################
298 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
299 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
301 AliError("can't get the branch with the EMCAL digits !");
304 branchdig->SetAddress(&digits);
305 digitsTree->GetEvent(0);
306 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
307 AliDebug(1,Form("%d digits",nDigits));
309 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
310 emcCells.CreateContainer(nDigits);
311 emcCells.SetType(AliESDCaloCells::kEMCALCell);
313 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
314 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
315 if(dig->GetAmplitude() > 0 ){
316 energy = fgClusterizer->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
317 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
318 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
323 emcCells.SetNumberOfCells(idignew);
326 //------------------------------------------------------------
327 //-----------------CLUSTERS-----------------------------
328 //------------------------------------------------------------
329 clustersTree->SetBranchStatus("*",0); //disable all branches
330 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
332 TObjArray *clusters = new TObjArray(100);
333 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
334 branch->SetAddress(&clusters);
336 //clustersTree->GetEvent(0);
338 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
339 AliDebug(1,Form("%d clusters",nClusters));
341 //######################################################
342 //#######################TRACK MATCHING###############
343 //######################################################
344 //Fill list of integers, each one is index of track to which the cluster belongs.
346 // step 1 - initialize array of matched track indexes
347 Int_t *matchedTrack = new Int_t[nClusters];
348 for (Int_t iclus = 0; iclus < nClusters; iclus++)
349 matchedTrack[iclus] = -1; // neg. index --> no matched track
351 // step 2, change the flag for all matched clusters found in tracks
352 Int_t iemcalMatch = -1;
353 Int_t endtpc = esd->GetNumberOfTracks();
354 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
355 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
356 iemcalMatch = track->GetEMCALcluster();
357 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
360 //########################################
361 //##############Fill CaloClusters#############
362 //########################################
363 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
364 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
365 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
366 if (Debug()) clust->Print();
367 // Get information from EMCAL reconstruction points
370 clust->GetGlobalPosition(gpos);
371 for (Int_t ixyz=0; ixyz<3; ixyz++)
372 xyz[ixyz] = gpos[ixyz];
374 clust->GetElipsAxis(elipAxis);
375 //Create digits lists
376 Int_t cellMult = clust->GetMultiplicity();
377 //TArrayS digiList(digitMult);
378 Float_t *amplFloat = clust->GetEnergiesList();
379 Int_t *digitInts = clust->GetAbsId();
380 TArrayS absIdList(cellMult);
381 TArrayD fracList(cellMult);
383 Int_t newCellMult = 0;
384 for (Int_t iCell=0; iCell<cellMult; iCell++) {
385 if (amplFloat[iCell] > 0) {
386 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
387 //Uncomment when unfolding is done
388 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
389 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
391 fracList[newCellMult] = 0;
396 absIdList.Set(newCellMult);
397 fracList.Set(newCellMult);
399 if(newCellMult > 0) { // accept cluster if it has some digit
402 Int_t parentMult = 0;
403 Int_t *parentList = clust->GetParents(parentMult);
404 // fills the ESDCaloCluster
405 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
406 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
407 ec->SetPosition(xyz);
408 ec->SetE(clust->GetEnergy());
410 //Distance to the nearest bad crystal
411 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
413 ec->SetNCells(newCellMult);
414 //Change type of list from short to ushort
415 UShort_t *newAbsIdList = new UShort_t[newCellMult];
416 Double_t *newFracList = new Double_t[newCellMult];
417 for(Int_t i = 0; i < newCellMult ; i++) {
418 newAbsIdList[i]=absIdList[i];
419 newFracList[i]=fracList[i];
421 ec->SetCellsAbsId(newAbsIdList);
422 ec->SetCellsAmplitudeFraction(newFracList);
423 ec->SetClusterDisp(clust->GetDispersion());
424 ec->SetClusterChi2(-1); //not yet implemented
425 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
426 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
427 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
428 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
429 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
430 arrayTrackMatched[0]= matchedTrack[iClust];
431 ec->AddTracksMatched(arrayTrackMatched);
433 TArrayI arrayParents(parentMult,parentList);
434 ec->AddLabels(arrayParents);
436 // add the cluster to the esd object
437 esd->AddCaloCluster(ec);
439 delete [] newAbsIdList ;
440 delete [] newFracList ;
442 } // cycle on clusters
444 delete [] matchedTrack;
446 //Fill ESDCaloCluster with PID weights
447 AliEMCALPID *pid = new AliEMCALPID;
448 //pid->SetPrintInfo(kTRUE);
449 pid->SetReconstructor(kTRUE);
456 //Store EMCAL misalignment matrixes
457 FillMisalMatrixes(esd) ;
461 //==================================================================================
462 void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
463 //Store EMCAL matrixes in ESD Header
465 //Check, if matrixes was already stored
466 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
467 if(esd->GetEMCALMatrix(sm)!=0)
471 //Create and store matrixes
473 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
476 //Note, that owner of copied marixes will be header
478 TGeoHMatrix * m = 0x0;
479 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
480 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
481 if(sm >= 10) sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
483 if (gGeoManager->CheckPath(path)){
484 gGeoManager->cd(path);
485 m = gGeoManager->GetCurrentMatrix() ;
486 // printf("================================================= \n");
487 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
489 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
490 // printf("================================================= \n");
493 esd->SetEMCALMatrix(NULL,sm) ;
500 //__________________________________________________________________________
501 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
503 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
505 // Clear previous digits
506 fgDigitsArr->Delete();
509 // Read the digits from the input tree
510 TBranch *branch = digitsTree->GetBranch("EMCAL");
512 AliError("can't get the branch with the EMCAL digits !");
515 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
516 branch->SetAddress(&fgDigitsArr);