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 // --- ROOT system ---
26 // --- Standard library ---
28 // --- AliRoot header files ---
29 #include "AliEMCALReconstructor.h"
31 #include "AliCodeTimer.h"
32 #include "AliESDEvent.h"
33 #include "AliESDCaloCluster.h"
34 #include "AliESDCaloCells.h"
35 #include "AliESDtrack.h"
36 #include "AliEMCALLoader.h"
37 #include "AliEMCALRawUtils.h"
38 #include "AliEMCALDigit.h"
39 #include "AliEMCALClusterizerv1.h"
40 #include "AliEMCALRecPoint.h"
41 #include "AliEMCALPID.h"
42 #include "AliEMCALTrigger.h"
43 #include "AliRawReader.h"
44 #include "AliCDBEntry.h"
45 #include "AliCDBManager.h"
46 #include "AliEMCALRecParam.h"
47 #include "AliEMCALGeometry.h"
50 #include "AliRunLoader.h"
53 ClassImp(AliEMCALReconstructor)
55 AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
56 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
57 //____________________________________________________________________________
58 AliEMCALReconstructor::AliEMCALReconstructor()
59 : fDebug(kFALSE),fGeom(0)
64 fgRawUtils = new AliEMCALRawUtils;
66 //To make sure we match with the geometry in a simulation file,
67 //let's try to get it first. If not, take the default geometry
68 AliRunLoader *rl = AliRunLoader::GetRunLoader();
69 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
70 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
72 AliInfo(Form("Using default geometry in reconstruction"));
73 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
76 if(!fGeom) AliFatal(Form("Could not get geometry!"));
80 //____________________________________________________________________________
81 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
82 : AliReconstructor(rec),
89 //____________________________________________________________________________
90 AliEMCALReconstructor::~AliEMCALReconstructor()
94 AliCodeTimer::Instance()->Print();
97 //____________________________________________________________________________
98 void AliEMCALReconstructor::InitRecParam() const
100 // Check if the instance of AliEMCALRecParam exists,
101 // if not, get it from OCDB if available, otherwise create a default one
103 if (!fgkRecParam && (AliCDBManager::Instance()->IsDefaultStorageSet())) {
104 AliCDBEntry *entry = (AliCDBEntry*)
105 AliCDBManager::Instance()->Get("EMCAL/Config/RecParam");
106 if (entry) fgkRecParam = (AliEMCALRecParam*) entry->GetObject();
110 AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
111 fgkRecParam = new AliEMCALRecParam;
115 //____________________________________________________________________________
116 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
118 // method called by AliReconstruction;
119 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
120 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
121 // the global tracking.
122 // Works on the current event.
126 AliEMCALClusterizerv1 clu;
127 clu.SetInput(digitsTree);
128 clu.SetOutput(clustersTree);
130 clu.Digits2Clusters("deb all") ;
132 clu.Digits2Clusters("") ;
136 //____________________________________________________________________________
137 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
140 // Conversion from raw data to
142 // Works on a single-event basis
146 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
147 Int_t bufsize = 32000;
148 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
150 //must be done here because, in constructor, option is not yet known
151 fgRawUtils->SetOption(GetOption());
153 fgRawUtils->SetRawFormatHighLowGainFactor(fgkRecParam->GetHighLowGainFactor());
154 fgRawUtils->SetRawFormatOrder(fgkRecParam->GetOrderParameter());
155 fgRawUtils->SetRawFormatTau(fgkRecParam->GetTau());
156 fgRawUtils->SetNoiseThreshold(fgkRecParam->GetNoiseThreshold());
157 fgRawUtils->SetNPedSamples(fgkRecParam->GetNPedSamples());
159 fgRawUtils->Raw2Digits(rawReader,digitsArr);
167 //____________________________________________________________________________
168 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
169 AliESDEvent* esd) const
171 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
172 // Works on the current event
173 // Creates AliESDCaloCluster from AliEMCALRecPoints
174 // and AliESDCaloCells from AliEMCALDigits
175 // Also, fills ESD with calorimeter trigger information
177 //######################################################
178 //#########Calculate trigger and set trigger info###########
179 //######################################################
182 // tr.SetPatchSize(1);//create 4x4 patches
185 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
186 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
187 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
188 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
190 Int_t iSM2x2 = tr.Get2x2SuperModule();
191 Int_t iSMnxn = tr.GetnxnSuperModule();
192 Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
193 Int_t iCellPhinxn = tr.GetnxnCellPhi();
194 Int_t iCellEta2x2 = tr.Get2x2CellEta();
195 Int_t iCellEtanxn = tr.GetnxnCellEta();
197 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
198 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
200 TVector3 pos2x2(-1,-1,-1);
201 TVector3 posnxn(-1,-1,-1);
203 Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
204 Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
205 fGeom->GetGlobal(iAbsId2x2, pos2x2);
206 fGeom->GetGlobal(iAbsIdnxn, posnxn);
208 TArrayF triggerPosition(6);
209 triggerPosition[0] = pos2x2(0) ;
210 triggerPosition[1] = pos2x2(1) ;
211 triggerPosition[2] = pos2x2(2) ;
212 triggerPosition[3] = posnxn(0) ;
213 triggerPosition[4] = posnxn(1) ;
214 triggerPosition[5] = posnxn(2) ;
216 TArrayF triggerAmplitudes(4);
217 triggerAmplitudes[0] = maxAmp2x2 ;
218 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
219 triggerAmplitudes[2] = maxAmpnxn ;
220 triggerAmplitudes[3] = ampOutOfPatchnxn ;
222 esd->AddEMCALTriggerPosition(triggerPosition);
223 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
225 //########################################
226 //##############Fill CaloCells###############
227 //########################################
229 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
230 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
232 AliError("can't get the branch with the PHOS digits !");
235 branchdig->SetAddress(&digits);
236 digitsTree->GetEvent(0);
237 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
238 AliDebug(1,Form("%d digits",nDigits));
240 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
241 emcCells.CreateContainer(nDigits);
242 emcCells.SetType(AliESDCaloCells::kEMCALCell);
243 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
244 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
245 if(dig->GetAmp() > 0 ){
246 emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
250 emcCells.SetNumberOfCells(idignew);
253 //------------------------------------------------------------
254 //-----------------CLUSTERS-----------------------------
255 //------------------------------------------------------------
256 TObjArray *clusters = new TObjArray(100);
257 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
258 branch->SetAddress(&clusters);
259 clustersTree->GetEvent(0);
261 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
262 AliDebug(1,Form("%d clusters",nClusters));
263 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
265 //######################################################
266 //#######################TRACK MATCHING###############
267 //######################################################
268 //Fill list of integers, each one is index of track to which the cluster belongs.
270 // step 1 - initialize array of matched track indexes
271 Int_t *matchedTrack = new Int_t[nClusters];
272 for (Int_t iclus = 0; iclus < nClusters; iclus++)
273 matchedTrack[iclus] = -1; // neg. index --> no matched track
275 // step 2, change the flag for all matched clusters found in tracks
276 Int_t iemcalMatch = -1;
277 Int_t endtpc = esd->GetNumberOfTracks();
278 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
279 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
280 iemcalMatch = track->GetEMCALcluster();
281 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
284 //########################################
285 //##############Fill CaloClusters############
286 //########################################
288 esd->SetNumberOfEMCALClusters(nClusters);
289 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
290 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
291 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
292 if (Debug()) clust->Print();
293 // Get information from EMCAL reconstruction points
296 clust->GetGlobalPosition(gpos);
297 for (Int_t ixyz=0; ixyz<3; ixyz++)
298 xyz[ixyz] = gpos[ixyz];
300 clust->GetElipsAxis(elipAxis);
302 //Create digits lists
303 Int_t cellMult = clust->GetMultiplicity();
304 //TArrayS digiList(digitMult);
305 Float_t *amplFloat = clust->GetEnergiesList();
306 Int_t *digitInts = clust->GetAbsId();
307 TArrayS absIdList(cellMult);
308 //Uncomment when unfolding is done
309 //TArrayD fracList(cellMult);
311 Int_t newCellMult = 0;
312 for (Int_t iCell=0; iCell<cellMult; iCell++) {
313 if (amplFloat[iCell] > 0) {
314 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
315 //Uncomment when unfolding is done
316 //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
320 absIdList.Set(newCellMult);
321 //Uncomment when unfolding is done
322 //fracList.Set(newCellMult);
324 if(newCellMult > 0) { // accept cluster if it has some digit
327 Int_t parentMult = 0;
328 Int_t *parentList = clust->GetParents(parentMult);
330 // fills the ESDCaloCluster
331 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
332 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
333 ec->SetPosition(xyz);
334 ec->SetE(clust->GetEnergy());
335 ec->SetNCells(newCellMult);
336 //Change type of list from short to ushort
337 UShort_t *newAbsIdList = new UShort_t[newCellMult];
338 //Uncomment when unfolding is done
339 //Double_t *newFracList = new Double_t[newCellMult];
340 for(Int_t i = 0; i < newCellMult ; i++) {
341 newAbsIdList[i]=absIdList[i];
342 //Uncomment when unfolding is done
343 //newFracList[i]=fracList[i];
345 ec->SetCellsAbsId(newAbsIdList);
346 //Uncomment when unfolding is done
347 //ec->SetCellsAmplitudeFraction(newFracList);
349 ec->SetClusterDisp(clust->GetDispersion());
350 ec->SetClusterChi2(-1); //not yet implemented
351 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
352 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
353 ec->SetM11(-1) ; //not yet implemented
355 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
356 arrayTrackMatched[0]= matchedTrack[iClust];
357 ec->AddTracksMatched(arrayTrackMatched);
359 TArrayI arrayParents(parentMult,parentList);
360 ec->AddLabels(arrayParents);
363 // add the cluster to the esd object
364 esd->AddCaloCluster(ec);
366 //delete [] newAbsIdList ;
367 //delete [] newFracList ;
369 } // cycle on clusters
371 delete [] matchedTrack;
373 esd->SetNumberOfEMCALClusters(nClustersNew);
374 //if(nClustersNew != nClusters)
375 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
377 //Fill ESDCaloCluster with PID weights
378 AliEMCALPID *pid = new AliEMCALPID;
379 //pid->SetPrintInfo(kTRUE);
380 pid->SetReconstructor(kTRUE);