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"
67 #include "AliEMCALTriggerData.h"
68 #include "AliEMCALTriggerRawDigit.h"
69 #include "AliEMCALTriggerPatch.h"
70 #include "AliEMCALTriggerTypes.h"
72 ClassImp(AliEMCALReconstructor)
74 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
75 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
76 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
77 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
78 TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
79 AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
80 //____________________________________________________________________________
81 AliEMCALReconstructor::AliEMCALReconstructor()
82 : fDebug(kFALSE), fList(0), fGeom(0),fCalibData(0),fPedestalData(0),fTriggerData(0x0)
86 fgRawUtils = new AliEMCALRawUtils;
88 //To make sure we match with the geometry in a simulation file,
89 //let's try to get it first. If not, take the default geometry
90 AliRunLoader *rl = AliRunLoader::Instance();
91 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
92 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
94 AliInfo(Form("Using default geometry in reconstruction"));
95 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
98 //Get calibration parameters
101 AliCDBEntry *entry = (AliCDBEntry*)
102 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
103 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
107 AliFatal("Calibration parameters not found in CDB!");
109 //Get calibration parameters
112 AliCDBEntry *entry = (AliCDBEntry*)
113 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
114 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
118 AliFatal("Dead map not found in CDB!");
122 if(!fGeom) AliFatal(Form("Could not get geometry!"));
124 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
126 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
128 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
129 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
131 fTriggerData = new AliEMCALTriggerData();
133 //Init temporary list of digits
134 fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
135 fgClustersArr = new TObjArray(1000);
139 //____________________________________________________________________________
140 AliEMCALReconstructor::~AliEMCALReconstructor()
144 if(fGeom) delete fGeom;
145 if(fCalibData) delete fCalibData;
146 if(fPedestalData) delete fPedestalData;
149 fgDigitsArr->Clear("C");
154 fgClustersArr->Clear();
155 delete fgClustersArr;
158 if(fgRawUtils) delete fgRawUtils;
159 if(fgClusterizer) delete fgClusterizer;
160 if(fgTriggerProcessor) delete fgTriggerProcessor;
162 AliCodeTimer::Instance()->Print();
165 // //____________________________________________________________________________
166 // void AliEMCALReconstructor::Init()
168 // // Trigger hists - Oct 24, 2007
169 // fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
172 //____________________________________________________________________________
173 void AliEMCALReconstructor::InitClusterizer()
175 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
177 AliEMCALRecParam *recParam = NULL;
178 AliCDBEntry *entry = (AliCDBEntry*)
179 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
180 //Get The reco param for the default event specie
182 recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
185 AliFatal("RecoParam not found in CDB!");
187 if (recParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
189 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
193 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
198 //____________________________________________________________________________
199 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
201 // method called by AliReconstruction;
202 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
203 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
204 // the global tracking.
205 // Works on the current event.
207 AliCodeTimerAuto("",0)
209 ReadDigitsArrayFromTree(digitsTree);
211 fgClusterizer->InitParameters();
212 fgClusterizer->SetOutput(clustersTree);
214 //Skip clusterization of LED events
215 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
217 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
219 fgClusterizer->SetInput(digitsTree);
222 fgClusterizer->Digits2Clusters("deb all") ;
224 fgClusterizer->Digits2Clusters("");
226 fgClusterizer->Clear();
228 }//digits array exists and has somethind
231 clustersTree->Fill();
234 //____________________________________________________________________________
235 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
238 // Conversion from raw data to
240 // Works on a single-event basis
244 fTriggerData->SetMode(1);
246 if(fgDigitsArr) fgDigitsArr->Clear("C");
248 TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", 32 * 96);
250 Int_t bufsize = 32000;
251 digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
252 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
254 //Skip calibration events do the rest
255 Bool_t doFit = kTRUE;
256 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
258 //must be done here because, in constructor, option is not yet known
259 fgRawUtils->SetOption(GetOption());
261 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
262 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
263 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
264 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
265 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
266 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
267 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
268 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
269 fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
270 fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
272 fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg,fTriggerData);
273 }//skip calibration event
275 AliDebug(1," Calibration Event, skip!");
285 //____________________________________________________________________________
286 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
287 AliESDEvent* esd) const
289 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
291 // Works on the current event
292 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
295 //FIXME UNCOMMENT WHEN ESDTRIGGER AVAILABLE
297 // Int_t v0M[2] = {0, 0};
299 // AliESDVZERO* esdV0 = esd->GetVZEROData();
303 // for (Int_t i = 0; i < 32; i++)
305 // v0M[0] += esdV0->GetAdcV0C(i);
306 // v0M[1] += esdV0->GetAdcV0A(i);
311 // AliWarning("Cannot retrieve V0 ESD! Run w/ null V0 charges");
314 // TClonesArray *trgDigits = new TClonesArray("AliEMCALTriggerRawDigit",1000);
316 // TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
320 // AliError("Can't get the branch with the EMCAL trigger digits!");
324 // branchtrg->SetAddress(&trgDigits);
325 // branchtrg->GetEntry(0);
327 // // Note: fgTriggerProcessor reset done at the end of this method
328 // fgTriggerProcessor->Digits2Trigger(trgDigits, v0M, fTriggerData);
331 // AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
335 // trgESD->Allocate(trgDigits->GetEntriesFast());
337 // for (Int_t i = 0; i < trgDigits->GetEntriesFast(); i++)
339 // AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)trgDigits->At(i);
342 // if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py))
344 // Int_t a = -1, t = -1, times[10];
346 // rdig->GetMaximum(a, t);
347 // rdig->GetL0Times(times);
349 // // rdig->Print("");
351 // trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum());
355 // // cout << "End of Adding................." << endl;
357 // trgESD->SetL1Threshold(0, fTriggerData->GetL1GammaThreshold());
359 // trgESD->SetL1Threshold(1, fTriggerData->GetL1JetThreshold() );
361 // for (Int_t i = 0; i < kTriggerTypeEnd; i++)
363 // for (Int_t j = 0; j < 2; j++)
365 // TClonesArray* patches = fTriggerData->GetPatches((TriggerType_t)i, j);
367 // TIter NextPatch(patches);
368 // while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)NextPatch())
370 // TVector2 pos; p->Position(pos);
371 // trgESD->SetTriggerBits(pos.X(), pos.Y(), i, j);
378 // fTriggerData->Reset();
379 // // cout << "Reset trg data" << endl;
380 //FIXME UNCOMMENT WHEN ESDTRIGGER AVAILABLE
382 //########################################
383 //##############Fill CaloCells###############
384 //########################################
385 ReadDigitsArrayFromTree(digitsTree);
387 // TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
388 // TBranch *branchdig = digitsTree->GetBranch("EMCAL");
390 // AliError("can't get the branch with the EMCAL digits !");
393 // branchdig->SetAddress(&digits);
394 // digitsTree->GetEvent(0);
395 Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
396 AliDebug(1,Form("%d digits",nDigits));
398 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
399 emcCells.CreateContainer(nDigits);
400 emcCells.SetType(AliVCaloCells::kEMCALCell);
402 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
403 const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
404 if(dig->GetAmplitude() > 0 ){
405 energy = fgClusterizer->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
406 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
407 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
412 emcCells.SetNumberOfCells(idignew);
415 //------------------------------------------------------------
416 //-----------------CLUSTERS-----------------------------
417 //------------------------------------------------------------
418 clustersTree->SetBranchStatus("*",0); //disable all branches
419 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
420 if(fgClustersArr) fgClustersArr->Clear();
421 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
422 branch->SetAddress(&fgClustersArr);
424 //clustersTree->GetEvent(0);
426 Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
427 AliDebug(1,Form("%d clusters",nClusters));
429 //######################################################
430 //#######################TRACK MATCHING###############
431 //######################################################
432 //Fill list of integers, each one is index of track to which the cluster belongs.
434 // step 1 - initialize array of matched track indexes
435 Int_t *matchedTrack = new Int_t[nClusters];
436 for (Int_t iclus = 0; iclus < nClusters; iclus++)
437 matchedTrack[iclus] = -1; // neg. index --> no matched track
439 // step 2, change the flag for all matched clusters found in tracks
440 Int_t iemcalMatch = -1;
441 Int_t endtpc = esd->GetNumberOfTracks();
442 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
443 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
444 iemcalMatch = track->GetEMCALcluster();
445 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
448 //########################################
449 //##############Fill CaloClusters#############
450 //########################################
451 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
452 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
453 //if(clust->GetClusterType()== AliVCluster::kEMCALClusterv1) nRP++; else nPC++;
454 if (Debug()) clust->Print();
455 // Get information from EMCAL reconstruction points
458 clust->GetGlobalPosition(gpos);
459 for (Int_t ixyz=0; ixyz<3; ixyz++)
460 xyz[ixyz] = gpos[ixyz];
462 clust->GetElipsAxis(elipAxis);
463 //Create digits lists
464 Int_t cellMult = clust->GetMultiplicity();
465 //TArrayS digiList(digitMult);
466 Float_t *amplFloat = clust->GetEnergiesList();
467 Int_t *digitInts = clust->GetAbsId();
468 TArrayS absIdList(cellMult);
469 TArrayD fracList(cellMult);
471 Int_t newCellMult = 0;
472 for (Int_t iCell=0; iCell<cellMult; iCell++) {
473 if (amplFloat[iCell] > 0) {
474 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
475 //Uncomment when unfolding is done
476 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
477 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
479 fracList[newCellMult] = 0;
484 absIdList.Set(newCellMult);
485 fracList.Set(newCellMult);
487 if(newCellMult > 0) { // accept cluster if it has some digit
490 Int_t parentMult = 0;
491 Int_t *parentList = clust->GetParents(parentMult);
492 // fills the ESDCaloCluster
493 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
494 ec->SetType(AliVCluster::kEMCALClusterv1);
495 ec->SetPosition(xyz);
496 ec->SetE(clust->GetEnergy());
498 //Distance to the nearest bad crystal
499 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
501 ec->SetNCells(newCellMult);
502 //Change type of list from short to ushort
503 UShort_t *newAbsIdList = new UShort_t[newCellMult];
504 Double_t *newFracList = new Double_t[newCellMult];
505 for(Int_t i = 0; i < newCellMult ; i++) {
506 newAbsIdList[i]=absIdList[i];
507 newFracList[i] =fracList[i];
509 ec->SetCellsAbsId(newAbsIdList);
510 ec->SetCellsAmplitudeFraction(newFracList);
511 ec->SetDispersion(clust->GetDispersion());
512 ec->SetChi2(-1); //not yet implemented
513 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
514 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
515 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
516 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
517 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
518 arrayTrackMatched[0]= matchedTrack[iClust];
519 ec->AddTracksMatched(arrayTrackMatched);
521 TArrayI arrayParents(parentMult,parentList);
522 ec->AddLabels(arrayParents);
524 // add the cluster to the esd object
525 esd->AddCaloCluster(ec);
527 delete [] newAbsIdList ;
528 delete [] newFracList ;
530 } // cycle on clusters
532 delete [] matchedTrack;
534 //Fill ESDCaloCluster with PID weights
535 AliEMCALPID *pid = new AliEMCALPID;
536 //pid->SetPrintInfo(kTRUE);
537 pid->SetReconstructor(kTRUE);
541 //Store EMCAL misalignment matrixes
542 FillMisalMatrixes(esd) ;
546 //==================================================================================
547 void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
548 //Store EMCAL matrixes in ESD Header
550 //Check, if matrixes was already stored
551 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
552 if(esd->GetEMCALMatrix(sm)!=0)
556 //Create and store matrixes
558 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
561 //Note, that owner of copied marixes will be header
563 TGeoHMatrix * m = 0x0;
564 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
565 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
566 if(sm >= 10) sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
568 if (gGeoManager->CheckPath(path)){
569 gGeoManager->cd(path);
570 m = gGeoManager->GetCurrentMatrix() ;
571 // printf("================================================= \n");
572 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
574 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
575 // printf("================================================= \n");
578 esd->SetEMCALMatrix(NULL,sm) ;
585 //__________________________________________________________________________
586 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
588 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
590 // Clear previous digits
591 fgDigitsArr->Clear("C");
592 //delete fgDigitsArr;
594 // Read the digits from the input tree
595 TBranch *branch = digitsTree->GetBranch("EMCAL");
597 AliError("can't get the branch with the EMCAL digits !");
600 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
601 branch->SetAddress(&fgDigitsArr);