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.
26 // --- ROOT system ---
27 #include <TClonesArray.h>
28 #include "TGeoManager.h"
29 #include "TGeoMatrix.h"
31 // --- Standard library ---
33 // --- AliRoot header files ---
34 #include "AliEMCALReconstructor.h"
36 #include "AliCodeTimer.h"
37 #include "AliCaloCalibPedestal.h"
38 #include "AliEMCALCalibData.h"
39 #include "AliESDEvent.h"
40 #include "AliESDCaloCluster.h"
41 #include "AliESDCaloCells.h"
42 #include "AliESDtrack.h"
43 #include "AliEMCALLoader.h"
44 #include "AliEMCALRawUtils.h"
45 #include "AliEMCALDigit.h"
46 #include "AliEMCALClusterizerv1.h"
47 #include "AliEMCALClusterizerNxN.h"
48 #include "AliEMCALRecPoint.h"
49 #include "AliEMCALPID.h"
50 #include "AliEMCALTrigger.h"
51 #include "AliRawReader.h"
52 #include "AliCDBEntry.h"
53 #include "AliCDBManager.h"
54 #include "AliEMCALGeometry.h"
56 #include "AliESDVZERO.h"
57 #include "AliCDBManager.h"
58 #include "AliRunLoader.h"
60 #include "AliEMCALTriggerData.h"
61 #include "AliEMCALTriggerElectronics.h"
62 #include "AliEMCALTriggerDCSConfigDB.h"
63 #include "AliEMCALTriggerDCSConfig.h"
64 #include "AliEMCALTriggerData.h"
65 #include "AliEMCALTriggerRawDigit.h"
66 #include "AliEMCALTriggerPatch.h"
67 #include "AliEMCALTriggerTypes.h"
69 ClassImp(AliEMCALReconstructor)
71 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
72 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
73 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
74 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
75 TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
76 TClonesArray* AliEMCALReconstructor::fgTriggerDigits = 0; // list of trigger digits, to be used multiple times
77 AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
78 //____________________________________________________________________________
79 AliEMCALReconstructor::AliEMCALReconstructor()
80 : fGeom(0),fCalibData(0),fPedestalData(0),fTriggerData(0x0)
84 fgRawUtils = new AliEMCALRawUtils;
86 //To make sure we match with the geometry in a simulation file,
87 //let's try to get it first. If not, take the default geometry
88 AliRunLoader *rl = AliRunLoader::Instance();
90 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
91 if(emcal) fGeom = emcal->GetGeometry();
95 AliInfo(Form("Using default geometry in reconstruction"));
96 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
99 //Get calibration parameters
102 AliCDBEntry *entry = (AliCDBEntry*)
103 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
104 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
108 AliFatal("Calibration parameters not found in CDB!");
110 //Get calibration parameters
113 AliCDBEntry *entry = (AliCDBEntry*)
114 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
115 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
119 AliFatal("Dead map not found in CDB!");
121 if(!fGeom) AliFatal(Form("Could not get geometry!"));
123 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
125 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
127 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
128 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
130 fTriggerData = new AliEMCALTriggerData();
132 //Init temporary list of digits
133 fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
134 fgClustersArr = new TObjArray(1000);
135 fgTriggerDigits = new TClonesArray("AliEMCALTriggerRawDigit",1000);
138 //____________________________________________________________________________
139 AliEMCALReconstructor::~AliEMCALReconstructor()
143 if(fGeom) delete fGeom;
145 //No need to delete, recovered from OCDB
146 //if(fCalibData) delete fCalibData;
147 //if(fPedestalData) delete fPedestalData;
150 fgDigitsArr->Clear("C");
155 fgClustersArr->Clear();
156 delete fgClustersArr;
160 fgTriggerDigits->Clear();
161 delete fgTriggerDigits;
164 if(fgRawUtils) delete fgRawUtils;
165 if(fgClusterizer) delete fgClusterizer;
166 if(fgTriggerProcessor) delete fgTriggerProcessor;
168 AliCodeTimer::Instance()->Print();
171 //____________________________________________________________________________
172 void AliEMCALReconstructor::InitClusterizer() const
174 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
175 Int_t clusterizerType = -1;
176 Int_t eventType = -1;
178 clusterizerType = GetRecParam()->GetClusterizerFlag();
179 eventType = GetRecParam()->GetEventSpecie();
182 AliCDBEntry *entry = (AliCDBEntry*)
183 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
184 //Get The reco param for the default event specie
186 AliEMCALRecParam *recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
187 if(recParam) clusterizerType = recParam->GetClusterizerFlag();
191 //Check if clusterizer previously set corresponds to what is needed for this event type
193 if(eventType!=AliRecoParam::kCalib){
194 //printf("ReCreate clusterizer? Clusterizer set <%d>, Clusterizer in use <%s>\n",
195 // clusterizerType, fgClusterizer->Version());
197 if (clusterizerType == AliEMCALRecParam::kClusterizerv1 && !strcmp(fgClusterizer->Version(),"clu-v1")) return;
199 else if(clusterizerType == AliEMCALRecParam::kClusterizerNxN && !strcmp(fgClusterizer->Version(),"clu-NxN")) return;
201 //Need to create new clusterizer, the one set previously is not the correct one
202 delete fgClusterizer;
207 if (clusterizerType == AliEMCALRecParam::kClusterizerv1)
209 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
213 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
217 //____________________________________________________________________________
218 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
220 // method called by AliReconstruction;
221 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
222 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
223 // the global tracking.
224 // Works on the current event.
226 AliCodeTimerAuto("",0)
228 //Get input digits and put them in fgDigitsArr, clear the list before
229 ReadDigitsArrayFromTree(digitsTree);
233 fgClusterizer->InitParameters();
234 fgClusterizer->SetOutput(clustersTree);
236 //Skip clusterization of LED events
237 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
239 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
241 fgClusterizer->SetInput(digitsTree);
243 //fgClusterizer->Digits2Clusters("deb all") ; //For debugging
244 fgClusterizer->Digits2Clusters("");
246 fgClusterizer->Clear();
248 }//digits array exists and has somethind
251 clustersTree->Fill();
254 //____________________________________________________________________________
255 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
258 // Conversion from raw data to
260 // Works on a single-event basis
264 fTriggerData->SetMode(1);
266 if(fgDigitsArr) fgDigitsArr->Clear("C");
268 TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", 32 * 96);
270 Int_t bufsize = 32000;
271 digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
272 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
274 //Skip calibration events do the rest
275 Bool_t doFit = kTRUE;
276 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
278 //must be done here because, in constructor, option is not yet known
279 fgRawUtils->SetOption(GetOption());
281 // fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
283 // fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
284 // fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
285 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
286 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
287 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
288 fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
289 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
291 //fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
292 //fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
294 // fgRawUtils->SetTimeMin(-99999 );
295 // fgRawUtils->SetTimeMax( 99999 );
297 fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg,fTriggerData);
299 }//skip calibration event
301 AliDebug(1," Calibration Event, skip!");
311 //____________________________________________________________________________
312 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
313 AliESDEvent* esd) const
315 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
317 // Works on the current event
318 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
321 //########################################
323 //########################################
325 static int saveOnce = 0;
327 Int_t v0M[2] = {0, 0};
329 AliESDVZERO* esdV0 = esd->GetVZEROData();
333 for (Int_t i = 0; i < 32; i++)
335 v0M[0] += (Int_t)esdV0->GetAdcV0C(i);
336 v0M[1] += (Int_t)esdV0->GetAdcV0A(i);
341 AliWarning("Cannot retrieve V0 ESD! Run w/ null V0 charges");
344 if (fgTriggerDigits) fgTriggerDigits->Clear();
346 TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
350 AliError("Can't get the branch with the EMCAL trigger digits!");
354 branchtrg->SetAddress(&fgTriggerDigits);
355 branchtrg->GetEntry(0);
357 // Note: fgTriggerProcessor reset done at the end of this method
358 fgTriggerProcessor->Digits2Trigger(fgTriggerDigits, v0M, fTriggerData);
361 AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
365 trgESD->Allocate(fgTriggerDigits->GetEntriesFast());
367 for (Int_t i = 0; i < fgTriggerDigits->GetEntriesFast(); i++)
369 AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)fgTriggerDigits->At(i);
372 if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py))
374 Int_t a = -1, t = -1, times[10];
376 rdig->GetMaximum(a, t);
377 rdig->GetL0Times(times);
379 trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum(), rdig->GetTriggerBits());
383 trgESD->SetL1Threshold(0, fTriggerData->GetL1GammaThreshold());
385 trgESD->SetL1Threshold(1, fTriggerData->GetL1JetThreshold() );
388 fTriggerData->GetL1V0(v0);
391 trgESD->SetL1FrameMask(fTriggerData->GetL1FrameMask());
396 fTriggerData->GetL1TriggerType(type);
398 esd->SetCaloTriggerType(type);
405 fTriggerData->Reset();
407 //########################################
408 //##############Fill CaloCells###############
409 //########################################
411 //Get input digits and put them in fgDigitsArr, clear the list before
412 ReadDigitsArrayFromTree(digitsTree);
414 Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
415 AliDebug(1,Form("%d digits",nDigits));
417 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
418 emcCells.CreateContainer(nDigits);
419 emcCells.SetType(AliVCaloCells::kEMCALCell);
421 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
422 const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
423 if(dig->GetAmplitude() > 0 ){
424 energy = fgClusterizer->Calibrate(dig->GetAmplitude(),dig->GetTime(),dig->GetId()); //TimeR or Time?
425 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
426 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
431 emcCells.SetNumberOfCells(idignew);
434 //------------------------------------------------------------
435 //-----------------CLUSTERS-----------------------------
436 //------------------------------------------------------------
437 clustersTree->SetBranchStatus("*",0); //disable all branches
438 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
439 if(fgClustersArr) fgClustersArr->Clear();
440 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
441 branch->SetAddress(&fgClustersArr);
443 //clustersTree->GetEvent(0);
445 Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
446 AliDebug(1,Form("%d clusters",nClusters));
448 //######################################################
449 //#######################TRACK MATCHING###############
450 //######################################################
451 //Fill list of integers, each one is index of track to which the cluster belongs.
453 // step 1 - initialize array of matched track indexes
454 Int_t *matchedTrack = new Int_t[nClusters];
455 for (Int_t iclus = 0; iclus < nClusters; iclus++)
456 matchedTrack[iclus] = -1; // neg. index --> no matched track
458 // step 2, change the flag for all matched clusters found in tracks
459 Int_t iemcalMatch = -1;
460 Int_t endtpc = esd->GetNumberOfTracks();
461 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
462 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
463 iemcalMatch = track->GetEMCALcluster();
464 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
467 //########################################
468 //##############Fill CaloClusters#############
469 //########################################
470 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
471 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
472 //if(clust->GetClusterType()== AliVCluster::kEMCALClusterv1) nRP++; else nPC++;
473 // clust->Print(); //For debugging
474 // Get information from EMCAL reconstruction points
477 clust->GetGlobalPosition(gpos);
478 for (Int_t ixyz=0; ixyz<3; ixyz++)
479 xyz[ixyz] = gpos[ixyz];
481 clust->GetElipsAxis(elipAxis);
482 //Create digits lists
483 Int_t cellMult = clust->GetMultiplicity();
484 //TArrayS digiList(digitMult);
485 Float_t *amplFloat = clust->GetEnergiesList();
486 Int_t *digitInts = clust->GetAbsId();
487 TArrayS absIdList(cellMult);
488 TArrayD fracList(cellMult);
490 Int_t newCellMult = 0;
491 for (Int_t iCell=0; iCell<cellMult; iCell++) {
492 if (amplFloat[iCell] > 0) {
493 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
495 if(emcCells.GetCellAmplitude(digitInts[iCell])>0 && GetRecParam()->GetUnfold()){
496 fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell]));//get cell calibration value
500 fracList[newCellMult] = 0;
506 absIdList.Set(newCellMult);
507 fracList.Set(newCellMult);
509 if(newCellMult > 0) { // accept cluster if it has some digit
512 Int_t parentMult = 0;
513 Int_t *parentList = clust->GetParents(parentMult);
514 // fills the ESDCaloCluster
515 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
516 ec->SetType(AliVCluster::kEMCALClusterv1);
517 ec->SetPosition(xyz);
518 ec->SetE(clust->GetEnergy());
520 //Distance to the nearest bad crystal
521 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
523 ec->SetNCells(newCellMult);
524 //Change type of list from short to ushort
525 UShort_t *newAbsIdList = new UShort_t[newCellMult];
526 Double_t *newFracList = new Double_t[newCellMult];
527 for(Int_t i = 0; i < newCellMult ; i++) {
528 newAbsIdList[i]=absIdList[i];
529 newFracList[i] =fracList[i];
531 ec->SetCellsAbsId(newAbsIdList);
532 ec->SetCellsAmplitudeFraction(newFracList);
533 ec->SetDispersion(clust->GetDispersion());
534 ec->SetChi2(-1); //not yet implemented
535 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
536 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
537 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
538 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
539 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
540 arrayTrackMatched[0]= matchedTrack[iClust];
541 ec->AddTracksMatched(arrayTrackMatched);
543 TArrayI arrayParents(parentMult,parentList);
544 ec->AddLabels(arrayParents);
546 // add the cluster to the esd object
547 esd->AddCaloCluster(ec);
549 delete [] newAbsIdList ;
550 delete [] newFracList ;
552 } // cycle on clusters
554 delete [] matchedTrack;
556 //Fill ESDCaloCluster with PID weights
557 AliEMCALPID *pid = new AliEMCALPID;
558 //pid->SetPrintInfo(kTRUE);
559 pid->SetReconstructor(kTRUE);
563 //Store EMCAL misalignment matrixes
564 FillMisalMatrixes(esd) ;
568 //==================================================================================
569 void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
570 //Store EMCAL matrixes in ESD Header
572 //Check, if matrixes was already stored
573 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
574 if(esd->GetEMCALMatrix(sm)!=0)
578 //Create and store matrixes
580 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
583 //Note, that owner of copied marixes will be header
584 const Int_t bufsize = 255;
586 TGeoHMatrix * m = 0x0;
587 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
588 snprintf(path,bufsize,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
589 if(sm >= 10) snprintf(path,bufsize,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
591 if (gGeoManager->CheckPath(path)){
592 gGeoManager->cd(path);
593 m = gGeoManager->GetCurrentMatrix() ;
594 // printf("================================================= \n");
595 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
597 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
598 // printf("================================================= \n");
601 esd->SetEMCALMatrix(NULL,sm) ;
606 //__________________________________________________________________________
607 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
609 // Read the digits from the input tree
610 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
612 // Clear previous digits in the list
614 fgDigitsArr->Clear("C");
617 // It should not happen, but just in case ...
618 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
621 // Read the digits from the input tree
622 TBranch *branch = digitsTree->GetBranch("EMCAL");
624 AliError("can't get the branch with the EMCAL digits !");
628 branch->SetAddress(&fgDigitsArr);