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 "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 "AliEMCALHistoUtilities.h"
57 #include "AliESDVZERO.h"
58 #include "AliCDBManager.h"
59 #include "AliRunLoader.h"
61 #include "AliEMCALTriggerData.h"
62 #include "AliEMCALTriggerElectronics.h"
63 #include "AliVZEROLoader.h"
65 ClassImp(AliEMCALReconstructor)
67 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
68 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
69 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
70 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
71 AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
72 //____________________________________________________________________________
73 AliEMCALReconstructor::AliEMCALReconstructor()
74 : fDebug(kFALSE), fList(0), fGeom(0),fCalibData(0),fPedestalData(0)
78 fgRawUtils = new AliEMCALRawUtils;
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
82 AliRunLoader *rl = AliRunLoader::Instance();
83 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
84 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
86 AliInfo(Form("Using default geometry in reconstruction"));
87 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
90 //Get calibration parameters
93 AliCDBEntry *entry = (AliCDBEntry*)
94 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
95 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
99 AliFatal("Calibration parameters not found in CDB!");
101 //Get calibration parameters
104 AliCDBEntry *entry = (AliCDBEntry*)
105 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
106 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
110 AliFatal("Dead map not found in CDB!");
113 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
114 fgClusterizer = new AliEMCALClusterizerv1(fGeom, fCalibData,fPedestalData);
116 if(!fGeom) AliFatal(Form("Could not get geometry!"));
118 fgTriggerProcessor = new AliEMCALTriggerElectronics();
121 //____________________________________________________________________________
122 AliEMCALReconstructor::~AliEMCALReconstructor()
127 delete fgClusterizer;
128 delete fgTriggerProcessor;
130 AliCodeTimer::Instance()->Print();
133 //____________________________________________________________________________
134 void AliEMCALReconstructor::Init()
136 // Trigger hists - Oct 24, 2007
137 fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
140 //____________________________________________________________________________
141 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
143 // method called by AliReconstruction;
144 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
145 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
146 // the global tracking.
147 // Works on the current event.
149 AliCodeTimerAuto("",0)
151 ReadDigitsArrayFromTree(digitsTree);
152 fgClusterizer->InitParameters();
153 fgClusterizer->SetOutput(clustersTree);
155 AliEMCALTriggerData* trgData = new AliEMCALTriggerData();
157 Int_t bufferSize = 32000;
159 if (TBranch* triggerBranch = clustersTree->GetBranch("EMTRG"))
160 triggerBranch->SetAddress(&trgData);
162 clustersTree->Branch("EMTRG","AliEMCALTriggerData",&trgData,bufferSize);
164 AliVZEROLoader* vzeroLoader = dynamic_cast<AliVZEROLoader*>(AliRunLoader::Instance()->GetDetectorLoader("VZERO"));
170 vzeroLoader->LoadDigits("READ");
171 treeV0 = vzeroLoader->TreeD();
174 TClonesArray *trgDigits = new TClonesArray("AliEMCALRawDigit",1000);
175 TBranch *branchdig = digitsTree->GetBranch("EMTRG");
178 AliError("Can't get the branch with the EMCAL trigger digits !");
182 branchdig->SetAddress(&trgDigits);
183 branchdig->GetEntry(0);
185 fgTriggerProcessor->Digits2Trigger(trgDigits, treeV0, trgData);
189 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
191 fgClusterizer->SetInput(digitsTree);
194 fgClusterizer->Digits2Clusters("deb all") ;
196 fgClusterizer->Digits2Clusters("");
198 fgClusterizer->Clear();
204 vzeroLoader->UnloadDigits();
207 clustersTree->Fill();
212 //____________________________________________________________________________
213 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
216 // Conversion from raw data to
218 // Works on a single-event basis
222 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
223 TClonesArray *digitsTrg = new TClonesArray("AliEMCALRawDigit", 200);
225 Int_t bufsize = 32000;
226 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
227 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
229 //must be done here because, in constructor, option is not yet known
230 fgRawUtils->SetOption(GetOption());
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());
241 fgRawUtils->Raw2Digits(rawReader,digitsArr,fPedestalData,digitsTrg);
252 //____________________________________________________________________________
253 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
254 AliESDEvent* esd) const
256 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
258 // Works on the current event
259 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
262 //######################################################
263 //#########Calculate trigger and set trigger info###########
264 //######################################################
265 // Obsolete, to be changed with new trigger emulator when consensus is achieved about what is stored in ESDs.
267 // tr.SetPatchSize(1); // create 4x4 patches
268 tr.SetSimulation(kFALSE); // Reconstruction mode
269 tr.SetDigitsList(fgDigitsArr);
270 // Get VZERO total multiplicity for jet trigger simulation
271 // The simulation of jey trigger will be incorrect if no VZERO data
273 AliESDVZERO* vZero = esd->GetVZEROData();
275 tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
280 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
281 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
282 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
283 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
285 Int_t iSM2x2 = tr.Get2x2SuperModule();
286 Int_t iSMnxn = tr.GetnxnSuperModule();
287 Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
288 Int_t iModulePhinxn = tr.GetnxnModulePhi();
289 Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
290 Int_t iModuleEtanxn = tr.GetnxnModuleEta();
292 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
293 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
295 TVector3 pos2x2(-1,-1,-1);
296 TVector3 posnxn(-1,-1,-1);
298 Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
299 Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
300 fGeom->GetGlobal(iAbsId2x2, pos2x2);
301 fGeom->GetGlobal(iAbsIdnxn, posnxn);
302 //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
304 TArrayF triggerPosition(6);
305 triggerPosition[0] = pos2x2(0) ;
306 triggerPosition[1] = pos2x2(1) ;
307 triggerPosition[2] = pos2x2(2) ;
308 triggerPosition[3] = posnxn(0) ;
309 triggerPosition[4] = posnxn(1) ;
310 triggerPosition[5] = posnxn(2) ;
311 //printf(" triggerPosition ");
312 //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
314 TArrayF triggerAmplitudes(4);
315 triggerAmplitudes[0] = maxAmp2x2 ;
316 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
317 triggerAmplitudes[2] = maxAmpnxn ;
318 triggerAmplitudes[3] = ampOutOfPatchnxn ;
319 //printf("\n triggerAmplitudes ");
320 //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
326 if(tr.GetNJetThreshold()>0) {
328 Int_t n0 = triggerPosition.GetSize();
329 const TH2F *hpatch = tr.GetJetMatrixE();
330 triggerPosition.Set(n0 + 2);
331 for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);
333 n0 = triggerAmplitudes.GetSize();
334 triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
335 Double_t *ampJet = tr.GetL1JetThresholds();
336 for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
337 triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
340 esd->AddEMCALTriggerPosition(triggerPosition);
341 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
342 // Fill trigger hists
343 AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
345 //########################################
346 //##############Fill CaloCells###############
347 //########################################
349 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
350 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
352 AliError("can't get the branch with the EMCAL digits !");
355 branchdig->SetAddress(&digits);
356 digitsTree->GetEvent(0);
357 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
358 AliDebug(1,Form("%d digits",nDigits));
360 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
361 emcCells.CreateContainer(nDigits);
362 emcCells.SetType(AliESDCaloCells::kEMCALCell);
364 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
365 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
366 if(dig->GetAmp() > 0 ){
367 energy = (static_cast<AliEMCALClusterizerv1*> (fgClusterizer))->Calibrate(dig->GetAmp(),dig->GetId());
368 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
369 emcCells.SetCell(idignew,dig->GetId(),energy, dig->GetTime());
374 emcCells.SetNumberOfCells(idignew);
377 //------------------------------------------------------------
378 //-----------------CLUSTERS-----------------------------
379 //------------------------------------------------------------
380 TObjArray *clusters = new TObjArray(100);
381 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
382 branch->SetAddress(&clusters);
383 clustersTree->GetEvent(0);
385 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
386 AliDebug(1,Form("%d clusters",nClusters));
388 //######################################################
389 //#######################TRACK MATCHING###############
390 //######################################################
391 //Fill list of integers, each one is index of track to which the cluster belongs.
393 // step 1 - initialize array of matched track indexes
394 Int_t *matchedTrack = new Int_t[nClusters];
395 for (Int_t iclus = 0; iclus < nClusters; iclus++)
396 matchedTrack[iclus] = -1; // neg. index --> no matched track
398 // step 2, change the flag for all matched clusters found in tracks
399 Int_t iemcalMatch = -1;
400 Int_t endtpc = esd->GetNumberOfTracks();
401 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
402 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
403 iemcalMatch = track->GetEMCALcluster();
404 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
407 //########################################
408 //##############Fill CaloClusters#############
409 //########################################
410 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
411 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
412 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
413 if (Debug()) clust->Print();
414 // Get information from EMCAL reconstruction points
417 clust->GetGlobalPosition(gpos);
418 for (Int_t ixyz=0; ixyz<3; ixyz++)
419 xyz[ixyz] = gpos[ixyz];
421 clust->GetElipsAxis(elipAxis);
422 //Create digits lists
423 Int_t cellMult = clust->GetMultiplicity();
424 //TArrayS digiList(digitMult);
425 Float_t *amplFloat = clust->GetEnergiesList();
426 Int_t *digitInts = clust->GetAbsId();
427 TArrayS absIdList(cellMult);
428 TArrayD fracList(cellMult);
430 Int_t newCellMult = 0;
431 for (Int_t iCell=0; iCell<cellMult; iCell++) {
432 if (amplFloat[iCell] > 0) {
433 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
434 //Uncomment when unfolding is done
435 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
436 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
438 fracList[newCellMult] = 0;
443 absIdList.Set(newCellMult);
444 fracList.Set(newCellMult);
446 if(newCellMult > 0) { // accept cluster if it has some digit
449 Int_t parentMult = 0;
450 Int_t *parentList = clust->GetParents(parentMult);
451 // fills the ESDCaloCluster
452 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
453 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
454 ec->SetPosition(xyz);
455 ec->SetE(clust->GetEnergy());
457 //Distance to the nearest bad crystal
458 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
460 ec->SetNCells(newCellMult);
461 //Change type of list from short to ushort
462 UShort_t *newAbsIdList = new UShort_t[newCellMult];
463 Double_t *newFracList = new Double_t[newCellMult];
464 for(Int_t i = 0; i < newCellMult ; i++) {
465 newAbsIdList[i]=absIdList[i];
466 newFracList[i]=fracList[i];
468 ec->SetCellsAbsId(newAbsIdList);
469 ec->SetCellsAmplitudeFraction(newFracList);
470 ec->SetClusterDisp(clust->GetDispersion());
471 ec->SetClusterChi2(-1); //not yet implemented
472 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
473 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
474 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
475 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
476 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
477 arrayTrackMatched[0]= matchedTrack[iClust];
478 ec->AddTracksMatched(arrayTrackMatched);
480 TArrayI arrayParents(parentMult,parentList);
481 ec->AddLabels(arrayParents);
483 // add the cluster to the esd object
484 esd->AddCaloCluster(ec);
486 delete [] newAbsIdList ;
487 delete [] newFracList ;
489 } // cycle on clusters
491 delete [] matchedTrack;
493 //Fill ESDCaloCluster with PID weights
494 AliEMCALPID *pid = new AliEMCALPID;
495 //pid->SetPrintInfo(kTRUE);
496 pid->SetReconstructor(kTRUE);
503 //Store EMCAL misalignment matrixes
504 FillMisalMatrixes(esd) ;
508 //==================================================================================
509 void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
510 //Store EMCAL matrixes in ESD Header
512 //Check, if matrixes was already stored
513 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
514 if(esd->GetEMCALMatrix(sm)!=0)
518 //Create and store matrixes
520 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
523 //Note, that owner of copied marixes will be header
525 TGeoHMatrix * m = 0x0;
526 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
527 sprintf(path,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
528 if(sm >= 10) sprintf(path,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
530 if (gGeoManager->CheckPath(path)){
531 gGeoManager->cd(path);
532 m = gGeoManager->GetCurrentMatrix() ;
533 // printf("================================================= \n");
534 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
536 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
537 // printf("================================================= \n");
540 esd->SetEMCALMatrix(NULL,sm) ;
547 //__________________________________________________________________________
548 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
550 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
552 // Clear previous digits
553 fgDigitsArr->Delete();
556 // Read the digits from the input tree
557 TBranch *branch = digitsTree->GetBranch("EMCAL");
559 AliError("can't get the branch with the EMCAL digits !");
562 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
563 branch->SetAddress(&fgDigitsArr);