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>
32 // --- Standard library ---
34 // --- AliRoot header files ---
35 #include "AliEMCALReconstructor.h"
37 #include "AliCodeTimer.h"
38 #include "AliESDEvent.h"
39 #include "AliESDCaloCluster.h"
40 #include "AliESDCaloCells.h"
41 #include "AliESDtrack.h"
42 #include "AliEMCALLoader.h"
43 #include "AliEMCALRawUtils.h"
44 #include "AliEMCALDigit.h"
45 #include "AliEMCALClusterizerv1.h"
46 #include "AliEMCALRecPoint.h"
47 #include "AliEMCALPID.h"
48 #include "AliEMCALTrigger.h"
49 #include "AliRawReader.h"
50 #include "AliCDBEntry.h"
51 #include "AliCDBManager.h"
52 #include "AliEMCALGeometry.h"
54 #include "AliEMCALHistoUtilities.h"
55 #include "AliESDVZERO.h"
57 #include "AliRunLoader.h"
60 ClassImp(AliEMCALReconstructor)
62 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
63 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
64 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
65 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
66 //____________________________________________________________________________
67 AliEMCALReconstructor::AliEMCALReconstructor()
68 : fDebug(kFALSE), fList(0), fGeom(0)
72 fgRawUtils = new AliEMCALRawUtils;
73 fgClusterizer = new AliEMCALClusterizerv1;
75 //To make sure we match with the geometry in a simulation file,
76 //let's try to get it first. If not, take the default geometry
77 AliRunLoader *rl = AliRunLoader::Instance();
78 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
79 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
81 AliInfo(Form("Using default geometry in reconstruction"));
82 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
85 if(!fGeom) AliFatal(Form("Could not get geometry!"));
89 //____________________________________________________________________________
90 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
91 : AliReconstructor(rec),
99 //____________________________________________________________________________
100 AliEMCALReconstructor::~AliEMCALReconstructor()
104 AliCodeTimer::Instance()->Print();
107 //____________________________________________________________________________
108 void AliEMCALReconstructor::Init()
110 // Trigger hists - Oct 24, 2007
111 fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
114 //____________________________________________________________________________
115 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
117 // method called by AliReconstruction;
118 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
119 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
120 // the global tracking.
121 // Works on the current event.
125 ReadDigitsArrayFromTree(digitsTree);
126 fgClusterizer->InitParameters();
127 fgClusterizer->SetOutput(clustersTree);
129 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
131 fgClusterizer->SetInput(digitsTree);
134 fgClusterizer->Digits2Clusters("deb all") ;
136 fgClusterizer->Digits2Clusters("");
138 fgClusterizer->Clear();
144 //____________________________________________________________________________
145 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
148 // Conversion from raw data to
150 // Works on a single-event basis
154 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
155 Int_t bufsize = 32000;
156 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
158 //must be done here because, in constructor, option is not yet known
159 fgRawUtils->SetOption(GetOption());
161 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
162 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
163 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
164 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
165 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
167 fgRawUtils->Raw2Digits(rawReader,digitsArr);
176 //____________________________________________________________________________
177 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
178 AliESDEvent* esd) const
180 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
182 // Works on the current event
183 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
186 //######################################################
187 //#########Calculate trigger and set trigger info###########
188 //######################################################
191 // tr.SetPatchSize(1); // create 4x4 patches
192 tr.SetSimulation(kFALSE); // Reconstruction mode
193 tr.SetDigitsList(fgDigitsArr);
194 // Get VZERO total multiplicity for jet trigger simulation
195 // The simulation of jey trigger will be incorrect if no VZERO data
197 AliESDVZERO* vZero = esd->GetVZEROData();
199 tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
204 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
205 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
206 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
207 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
209 Int_t iSM2x2 = tr.Get2x2SuperModule();
210 Int_t iSMnxn = tr.GetnxnSuperModule();
211 Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
212 Int_t iModulePhinxn = tr.GetnxnModulePhi();
213 Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
214 Int_t iModuleEtanxn = tr.GetnxnModuleEta();
216 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
217 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
219 TVector3 pos2x2(-1,-1,-1);
220 TVector3 posnxn(-1,-1,-1);
222 Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
223 Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
224 fGeom->GetGlobal(iAbsId2x2, pos2x2);
225 fGeom->GetGlobal(iAbsIdnxn, posnxn);
226 //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
228 TArrayF triggerPosition(6);
229 triggerPosition[0] = pos2x2(0) ;
230 triggerPosition[1] = pos2x2(1) ;
231 triggerPosition[2] = pos2x2(2) ;
232 triggerPosition[3] = posnxn(0) ;
233 triggerPosition[4] = posnxn(1) ;
234 triggerPosition[5] = posnxn(2) ;
235 //printf(" triggerPosition ");
236 //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
238 TArrayF triggerAmplitudes(4);
239 triggerAmplitudes[0] = maxAmp2x2 ;
240 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
241 triggerAmplitudes[2] = maxAmpnxn ;
242 triggerAmplitudes[3] = ampOutOfPatchnxn ;
243 //printf("\n triggerAmplitudes ");
244 //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
250 if(tr.GetNJetThreshold()>0) {
252 Int_t n0 = triggerPosition.GetSize();
253 const TH2F *hpatch = tr.GetJetMatrixE();
254 triggerPosition.Set(n0 + 2);
255 for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);
257 n0 = triggerAmplitudes.GetSize();
258 triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
259 Double_t *ampJet = tr.GetL1JetThresholds();
260 for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
261 triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
264 esd->AddEMCALTriggerPosition(triggerPosition);
265 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
266 // Fill trigger hists
267 AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
269 //########################################
270 //##############Fill CaloCells###############
271 //########################################
273 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
274 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
276 AliError("can't get the branch with the PHOS digits !");
279 branchdig->SetAddress(&digits);
280 digitsTree->GetEvent(0);
281 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
282 AliDebug(1,Form("%d digits",nDigits));
284 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
285 emcCells.CreateContainer(nDigits);
286 emcCells.SetType(AliESDCaloCells::kEMCALCell);
287 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
288 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
289 if(dig->GetAmp() > 0 ){
290 emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
294 emcCells.SetNumberOfCells(idignew);
297 //------------------------------------------------------------
298 //-----------------CLUSTERS-----------------------------
299 //------------------------------------------------------------
300 TObjArray *clusters = new TObjArray(100);
301 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
302 branch->SetAddress(&clusters);
303 clustersTree->GetEvent(0);
305 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
306 AliDebug(1,Form("%d clusters",nClusters));
307 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
310 //######################################################
311 //#######################TRACK MATCHING###############
312 //######################################################
313 //Fill list of integers, each one is index of track to which the cluster belongs.
315 // step 1 - initialize array of matched track indexes
316 Int_t *matchedTrack = new Int_t[nClusters];
317 for (Int_t iclus = 0; iclus < nClusters; iclus++)
318 matchedTrack[iclus] = -1; // neg. index --> no matched track
320 // step 2, change the flag for all matched clusters found in tracks
321 Int_t iemcalMatch = -1;
322 Int_t endtpc = esd->GetNumberOfTracks();
323 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
324 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
325 iemcalMatch = track->GetEMCALcluster();
326 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
329 //########################################
330 //##############Fill CaloClusters#############
331 //########################################
332 esd->SetNumberOfEMCALClusters(nClusters);
333 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
334 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
335 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
336 if (Debug()) clust->Print();
337 // Get information from EMCAL reconstruction points
340 clust->GetGlobalPosition(gpos);
341 for (Int_t ixyz=0; ixyz<3; ixyz++)
342 xyz[ixyz] = gpos[ixyz];
344 clust->GetElipsAxis(elipAxis);
345 //Create digits lists
346 Int_t cellMult = clust->GetMultiplicity();
347 //TArrayS digiList(digitMult);
348 Float_t *amplFloat = clust->GetEnergiesList();
349 Int_t *digitInts = clust->GetAbsId();
350 TArrayS absIdList(cellMult);
351 TArrayD fracList(cellMult);
353 Int_t newCellMult = 0;
354 for (Int_t iCell=0; iCell<cellMult; iCell++) {
355 if (amplFloat[iCell] > 0) {
356 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
357 //Uncomment when unfolding is done
358 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
359 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
361 fracList[newCellMult] = 0;
366 absIdList.Set(newCellMult);
367 fracList.Set(newCellMult);
369 if(newCellMult > 0) { // accept cluster if it has some digit
372 Int_t parentMult = 0;
373 Int_t *parentList = clust->GetParents(parentMult);
374 // fills the ESDCaloCluster
375 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
376 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
377 ec->SetPosition(xyz);
378 ec->SetE(clust->GetEnergy());
379 ec->SetNCells(newCellMult);
380 //Change type of list from short to ushort
381 UShort_t *newAbsIdList = new UShort_t[newCellMult];
382 Double_t *newFracList = new Double_t[newCellMult];
383 for(Int_t i = 0; i < newCellMult ; i++) {
384 newAbsIdList[i]=absIdList[i];
385 newFracList[i]=fracList[i];
387 ec->SetCellsAbsId(newAbsIdList);
388 ec->SetCellsAmplitudeFraction(newFracList);
389 ec->SetClusterDisp(clust->GetDispersion());
390 ec->SetClusterChi2(-1); //not yet implemented
391 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
392 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
393 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
394 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
395 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
396 arrayTrackMatched[0]= matchedTrack[iClust];
397 ec->AddTracksMatched(arrayTrackMatched);
399 TArrayI arrayParents(parentMult,parentList);
400 ec->AddLabels(arrayParents);
402 // add the cluster to the esd object
403 esd->AddCaloCluster(ec);
405 delete [] newAbsIdList ;
406 delete [] newFracList ;
408 } // cycle on clusters
410 delete [] matchedTrack;
412 esd->SetNumberOfEMCALClusters(nClustersNew);
413 //if(nClustersNew != nClusters)
414 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
416 //Fill ESDCaloCluster with PID weights
417 AliEMCALPID *pid = new AliEMCALPID;
418 //pid->SetPrintInfo(kTRUE);
419 pid->SetReconstructor(kTRUE);
426 // printf(" ## AliEMCALReconstructor::FillESD() is ended : ncl %i -> %i ### \n ",nClusters, nClustersNew);
429 //__________________________________________________________________________
430 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
432 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
434 // Clear previous digits
435 fgDigitsArr->Delete();
438 // Read the digits from the input tree
439 TBranch *branch = digitsTree->GetBranch("EMCAL");
441 AliError("can't get the branch with the EMCAL digits !");
444 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
445 branch->SetAddress(&fgDigitsArr);