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 "AliCaloCalibPedestal.h"
41 #include "AliEMCALCalibData.h"
42 #include "AliESDEvent.h"
43 #include "AliESDCaloCluster.h"
44 #include "AliESDCaloCells.h"
45 #include "AliESDtrack.h"
46 #include "AliEMCALLoader.h"
47 #include "AliEMCALRawUtils.h"
48 #include "AliEMCALDigit.h"
49 #include "AliEMCALClusterizerv1.h"
50 #include "AliEMCALClusterizerNxN.h"
51 #include "AliEMCALRecPoint.h"
52 #include "AliEMCALPID.h"
53 #include "AliEMCALTrigger.h"
54 #include "AliRawReader.h"
55 #include "AliCDBEntry.h"
56 #include "AliCDBManager.h"
57 #include "AliEMCALGeometry.h"
59 #include "AliESDVZERO.h"
60 #include "AliCDBManager.h"
61 #include "AliRunLoader.h"
63 #include "AliEMCALTriggerData.h"
64 #include "AliEMCALTriggerElectronics.h"
65 #include "AliEMCALTriggerDCSConfigDB.h"
66 #include "AliEMCALTriggerDCSConfig.h"
68 ClassImp(AliEMCALReconstructor)
70 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
71 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
72 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
73 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
74 TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
75 AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
76 //____________________________________________________________________________
77 AliEMCALReconstructor::AliEMCALReconstructor()
78 : fDebug(kFALSE), fList(0), fGeom(0),fCalibData(0),fPedestalData(0)
82 fgRawUtils = new AliEMCALRawUtils;
84 //To make sure we match with the geometry in a simulation file,
85 //let's try to get it first. If not, take the default geometry
86 AliRunLoader *rl = AliRunLoader::Instance();
87 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
88 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
90 AliInfo(Form("Using default geometry in reconstruction"));
91 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
94 //Get calibration parameters
97 AliCDBEntry *entry = (AliCDBEntry*)
98 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
99 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
103 AliFatal("Calibration parameters not found in CDB!");
105 //Get calibration parameters
108 AliCDBEntry *entry = (AliCDBEntry*)
109 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
110 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
114 AliFatal("Dead map not found in CDB!");
118 if(!fGeom) AliFatal(Form("Could not get geometry!"));
120 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
122 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
124 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
125 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
127 //Init temporary list of digits
128 fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
129 fgClustersArr = new TObjArray(1000);
133 //____________________________________________________________________________
134 AliEMCALReconstructor::~AliEMCALReconstructor()
138 if(fGeom) delete fGeom;
139 if(fCalibData) delete fCalibData;
140 if(fPedestalData) delete fPedestalData;
143 fgDigitsArr->Clear("C");
148 fgClustersArr->Clear();
149 delete fgClustersArr;
152 if(fgRawUtils) delete fgRawUtils;
153 if(fgClusterizer) delete fgClusterizer;
154 if(fgTriggerProcessor) delete fgTriggerProcessor;
156 AliCodeTimer::Instance()->Print();
159 // //____________________________________________________________________________
160 // void AliEMCALReconstructor::Init()
162 // // Trigger hists - Oct 24, 2007
163 // fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
166 //____________________________________________________________________________
167 void AliEMCALReconstructor::InitClusterizer()
169 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
171 AliEMCALRecParam *recParam = NULL;
172 AliCDBEntry *entry = (AliCDBEntry*)
173 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
174 //Get The reco param for the default event specie
176 recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
179 AliFatal("RecoParam not found in CDB!");
181 if (recParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
183 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
187 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
192 //____________________________________________________________________________
193 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
195 // method called by AliReconstruction;
196 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
197 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
198 // the global tracking.
199 // Works on the current event.
201 AliCodeTimerAuto("",0)
203 ReadDigitsArrayFromTree(digitsTree);
205 fgClusterizer->InitParameters();
206 fgClusterizer->SetOutput(clustersTree);
208 AliEMCALTriggerData* trgData = new AliEMCALTriggerData();
210 Int_t bufferSize = 32000;
212 if (TBranch* triggerBranch = clustersTree->GetBranch("EMTRG"))
213 triggerBranch->SetAddress(&trgData);
215 clustersTree->Branch("EMTRG","AliEMCALTriggerData",&trgData,bufferSize);
217 TClonesArray *trgDigits = new TClonesArray("AliEMCALRawDigit",1000);
218 TBranch *branchdig = digitsTree->GetBranch("EMTRG");
221 AliError("Can't get the branch with the EMCAL trigger digits !");
225 branchdig->SetAddress(&trgDigits);
226 branchdig->GetEntry(0);
228 //Skip clusterization of LED events
229 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
231 Int_t v0M[2] = {0,0};
232 fgTriggerProcessor->Digits2Trigger(trgDigits, v0M, trgData);
235 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
237 fgClusterizer->SetInput(digitsTree);
240 fgClusterizer->Digits2Clusters("deb all") ;
242 fgClusterizer->Digits2Clusters("");
244 fgClusterizer->Clear();
246 }//digits array exists and has somethind
249 clustersTree->Fill();
251 delete trgDigits; trgDigits = 0x0;
252 delete trgData; trgData = 0x0;
256 //____________________________________________________________________________
257 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
260 // Conversion from raw data to
262 // Works on a single-event basis
265 if(fgDigitsArr) fgDigitsArr->Clear("C");
267 TClonesArray *digitsTrg = new TClonesArray("AliEMCALRawDigit", 200);
269 Int_t bufsize = 32000;
270 digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
271 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
273 //Skip calibration events do the rest
274 Bool_t doFit = kTRUE;
275 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
277 //must be done here because, in constructor, option is not yet known
278 fgRawUtils->SetOption(GetOption());
280 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
281 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
282 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
283 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
284 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
285 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
286 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
287 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
288 fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
289 fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
291 fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg);
292 }//skip calibration event
294 AliDebug(1," Calibration Event, skip!");
304 //____________________________________________________________________________
305 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
306 AliESDEvent* esd) const
308 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
310 // Works on the current event
311 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
314 //########################################
315 //##############Fill CaloCells###############
316 //########################################
317 ReadDigitsArrayFromTree(digitsTree);
319 // TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
320 // TBranch *branchdig = digitsTree->GetBranch("EMCAL");
322 // AliError("can't get the branch with the EMCAL digits !");
325 // branchdig->SetAddress(&digits);
326 // digitsTree->GetEvent(0);
327 Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
328 AliDebug(1,Form("%d digits",nDigits));
330 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
331 emcCells.CreateContainer(nDigits);
332 emcCells.SetType(AliVCaloCells::kEMCALCell);
334 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
335 const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
336 if(dig->GetAmplitude() > 0 ){
337 energy = fgClusterizer->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
338 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
339 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
344 emcCells.SetNumberOfCells(idignew);
347 //------------------------------------------------------------
348 //-----------------CLUSTERS-----------------------------
349 //------------------------------------------------------------
350 clustersTree->SetBranchStatus("*",0); //disable all branches
351 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
352 if(fgClustersArr) fgClustersArr->Clear();
353 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
354 branch->SetAddress(&fgClustersArr);
356 //clustersTree->GetEvent(0);
358 Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
359 AliDebug(1,Form("%d clusters",nClusters));
361 //######################################################
362 //#######################TRACK MATCHING###############
363 //######################################################
364 //Fill list of integers, each one is index of track to which the cluster belongs.
366 // step 1 - initialize array of matched track indexes
367 Int_t *matchedTrack = new Int_t[nClusters];
368 for (Int_t iclus = 0; iclus < nClusters; iclus++)
369 matchedTrack[iclus] = -1; // neg. index --> no matched track
371 // step 2, change the flag for all matched clusters found in tracks
372 Int_t iemcalMatch = -1;
373 Int_t endtpc = esd->GetNumberOfTracks();
374 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
375 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
376 iemcalMatch = track->GetEMCALcluster();
377 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
380 //########################################
381 //##############Fill CaloClusters#############
382 //########################################
383 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
384 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
385 //if(clust->GetClusterType()== AliVCluster::kEMCALClusterv1) nRP++; else nPC++;
386 if (Debug()) clust->Print();
387 // Get information from EMCAL reconstruction points
390 clust->GetGlobalPosition(gpos);
391 for (Int_t ixyz=0; ixyz<3; ixyz++)
392 xyz[ixyz] = gpos[ixyz];
394 clust->GetElipsAxis(elipAxis);
395 //Create digits lists
396 Int_t cellMult = clust->GetMultiplicity();
397 //TArrayS digiList(digitMult);
398 Float_t *amplFloat = clust->GetEnergiesList();
399 Int_t *digitInts = clust->GetAbsId();
400 TArrayS absIdList(cellMult);
401 TArrayD fracList(cellMult);
403 Int_t newCellMult = 0;
404 for (Int_t iCell=0; iCell<cellMult; iCell++) {
405 if (amplFloat[iCell] > 0) {
406 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
407 //Uncomment when unfolding is done
408 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
409 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
411 fracList[newCellMult] = 0;
416 absIdList.Set(newCellMult);
417 fracList.Set(newCellMult);
419 if(newCellMult > 0) { // accept cluster if it has some digit
422 Int_t parentMult = 0;
423 Int_t *parentList = clust->GetParents(parentMult);
424 // fills the ESDCaloCluster
425 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
426 ec->SetType(AliVCluster::kEMCALClusterv1);
427 ec->SetPosition(xyz);
428 ec->SetE(clust->GetEnergy());
430 //Distance to the nearest bad crystal
431 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
433 ec->SetNCells(newCellMult);
434 //Change type of list from short to ushort
435 UShort_t *newAbsIdList = new UShort_t[newCellMult];
436 Double_t *newFracList = new Double_t[newCellMult];
437 for(Int_t i = 0; i < newCellMult ; i++) {
438 newAbsIdList[i]=absIdList[i];
439 newFracList[i]=fracList[i];
441 ec->SetCellsAbsId(newAbsIdList);
442 ec->SetCellsAmplitudeFraction(newFracList);
443 ec->SetDispersion(clust->GetDispersion());
444 ec->SetChi2(-1); //not yet implemented
445 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
446 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
447 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
448 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
449 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
450 arrayTrackMatched[0]= matchedTrack[iClust];
451 ec->AddTracksMatched(arrayTrackMatched);
453 TArrayI arrayParents(parentMult,parentList);
454 ec->AddLabels(arrayParents);
456 // add the cluster to the esd object
457 esd->AddCaloCluster(ec);
459 delete [] newAbsIdList ;
460 delete [] newFracList ;
462 } // cycle on clusters
464 delete [] matchedTrack;
466 //Fill ESDCaloCluster with PID weights
467 AliEMCALPID *pid = new AliEMCALPID;
468 //pid->SetPrintInfo(kTRUE);
469 pid->SetReconstructor(kTRUE);
476 //Store EMCAL misalignment matrixes
477 FillMisalMatrixes(esd) ;
481 //==================================================================================
482 void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
483 //Store EMCAL matrixes in ESD Header
485 //Check, if matrixes was already stored
486 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
487 if(esd->GetEMCALMatrix(sm)!=0)
491 //Create and store matrixes
493 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
496 //Note, that owner of copied marixes will be header
498 TGeoHMatrix * m = 0x0;
499 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
500 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
501 if(sm >= 10) sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
503 if (gGeoManager->CheckPath(path)){
504 gGeoManager->cd(path);
505 m = gGeoManager->GetCurrentMatrix() ;
506 // printf("================================================= \n");
507 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
509 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
510 // printf("================================================= \n");
513 esd->SetEMCALMatrix(NULL,sm) ;
520 //__________________________________________________________________________
521 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
523 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
525 // Clear previous digits
526 fgDigitsArr->Clear("C");
527 //delete fgDigitsArr;
529 // Read the digits from the input tree
530 TBranch *branch = digitsTree->GetBranch("EMCAL");
532 AliError("can't get the branch with the EMCAL digits !");
535 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
536 branch->SetAddress(&fgDigitsArr);