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 "AliEMCALRecParam.h"
53 #include "AliEMCALGeometry.h"
55 #include "AliEMCALHistoUtilities.h"
56 #include "AliESDVZERO.h"
58 #include "AliRunLoader.h"
61 ClassImp(AliEMCALReconstructor)
63 AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
64 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
65 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
66 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
67 //____________________________________________________________________________
68 AliEMCALReconstructor::AliEMCALReconstructor()
69 : fDebug(kFALSE), fList(0), fGeom(0)
74 fgRawUtils = new AliEMCALRawUtils;
75 fgClusterizer = new AliEMCALClusterizerv1;
77 //To make sure we match with the geometry in a simulation file,
78 //let's try to get it first. If not, take the default geometry
79 AliRunLoader *rl = AliRunLoader::GetRunLoader();
80 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
81 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
83 AliInfo(Form("Using default geometry in reconstruction"));
84 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
87 if(!fGeom) AliFatal(Form("Could not get geometry!"));
91 //____________________________________________________________________________
92 AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
93 : AliReconstructor(rec),
101 //____________________________________________________________________________
102 AliEMCALReconstructor::~AliEMCALReconstructor()
106 AliCodeTimer::Instance()->Print();
109 //____________________________________________________________________________
110 void AliEMCALReconstructor::Init()
112 // Trigger hists - Oct 24, 2007
113 fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
116 //____________________________________________________________________________
117 void AliEMCALReconstructor::InitRecParam() const
119 // Check if the instance of AliEMCALRecParam exists,
120 // if not, get it from OCDB if available, otherwise create a default one
122 if (!fgkRecParam && (AliCDBManager::Instance()->IsDefaultStorageSet())) {
123 AliCDBEntry *entry = (AliCDBEntry*)
124 AliCDBManager::Instance()->Get("EMCAL/Config/RecParam");
125 if (entry) fgkRecParam = (AliEMCALRecParam*) entry->GetObject();
129 AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
130 fgkRecParam = new AliEMCALRecParam;
134 //____________________________________________________________________________
135 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
137 // method called by AliReconstruction;
138 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
139 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
140 // the global tracking.
141 // Works on the current event.
145 ReadDigitsArrayFromTree(digitsTree);
147 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
149 fgClusterizer->SetInput(digitsTree);
150 fgClusterizer->SetOutput(clustersTree);
153 fgClusterizer->Digits2Clusters("deb all") ;
155 fgClusterizer->Digits2Clusters("");
157 fgClusterizer->Clear();
163 //____________________________________________________________________________
164 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
167 // Conversion from raw data to
169 // Works on a single-event basis
173 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
174 Int_t bufsize = 32000;
175 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
177 //must be done here because, in constructor, option is not yet known
178 fgRawUtils->SetOption(GetOption());
180 fgRawUtils->SetRawFormatHighLowGainFactor(fgkRecParam->GetHighLowGainFactor());
181 fgRawUtils->SetRawFormatOrder(fgkRecParam->GetOrderParameter());
182 fgRawUtils->SetRawFormatTau(fgkRecParam->GetTau());
183 fgRawUtils->SetNoiseThreshold(fgkRecParam->GetNoiseThreshold());
184 fgRawUtils->SetNPedSamples(fgkRecParam->GetNPedSamples());
186 fgRawUtils->Raw2Digits(rawReader,digitsArr);
195 //____________________________________________________________________________
196 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
197 AliESDEvent* esd) const
199 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
201 // Works on the current event
202 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
205 //######################################################
206 //#########Calculate trigger and set trigger info###########
207 //######################################################
210 // tr.SetPatchSize(1); // create 4x4 patches
211 tr.SetSimulation(kFALSE); // Reconstruction mode
212 tr.SetDigitsList(fgDigitsArr);
213 // Get VZERO total multiplicity for jet trigger simulation
214 // The simulation of jey trigger will be incorrect if no VZERO data
216 AliESDVZERO* vZero = esd->GetVZEROData();
218 tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
223 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
224 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
225 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
226 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
228 Int_t iSM2x2 = tr.Get2x2SuperModule();
229 Int_t iSMnxn = tr.GetnxnSuperModule();
230 Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
231 Int_t iModulePhinxn = tr.GetnxnModulePhi();
232 Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
233 Int_t iModuleEtanxn = tr.GetnxnModuleEta();
235 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
236 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
238 TVector3 pos2x2(-1,-1,-1);
239 TVector3 posnxn(-1,-1,-1);
241 Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
242 Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
243 fGeom->GetGlobal(iAbsId2x2, pos2x2);
244 fGeom->GetGlobal(iAbsIdnxn, posnxn);
245 //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
247 TArrayF triggerPosition(6);
248 triggerPosition[0] = pos2x2(0) ;
249 triggerPosition[1] = pos2x2(1) ;
250 triggerPosition[2] = pos2x2(2) ;
251 triggerPosition[3] = posnxn(0) ;
252 triggerPosition[4] = posnxn(1) ;
253 triggerPosition[5] = posnxn(2) ;
254 //printf(" triggerPosition ");
255 //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
257 TArrayF triggerAmplitudes(4);
258 triggerAmplitudes[0] = maxAmp2x2 ;
259 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
260 triggerAmplitudes[2] = maxAmpnxn ;
261 triggerAmplitudes[3] = ampOutOfPatchnxn ;
262 //printf("\n triggerAmplitudes ");
263 //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
269 if(tr.GetNJetThreshold()>0) {
271 Int_t n0 = triggerPosition.GetSize();
272 const TH2F *hpatch = tr.GetJetMatrixE();
273 triggerPosition.Set(n0 + 2);
274 for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);
276 n0 = triggerAmplitudes.GetSize();
277 triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
278 Double_t *ampJet = tr.GetL1JetThresholds();
279 for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
280 triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
283 esd->AddEMCALTriggerPosition(triggerPosition);
284 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
285 // Fill trigger hists
286 AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
288 //########################################
289 //##############Fill CaloCells###############
290 //########################################
292 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
293 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
295 AliError("can't get the branch with the PHOS digits !");
298 branchdig->SetAddress(&digits);
299 digitsTree->GetEvent(0);
300 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
301 AliDebug(1,Form("%d digits",nDigits));
303 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
304 emcCells.CreateContainer(nDigits);
305 emcCells.SetType(AliESDCaloCells::kEMCALCell);
306 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
307 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
308 if(dig->GetAmp() > 0 ){
309 emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
313 emcCells.SetNumberOfCells(idignew);
316 //------------------------------------------------------------
317 //-----------------CLUSTERS-----------------------------
318 //------------------------------------------------------------
319 TObjArray *clusters = new TObjArray(100);
320 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
321 branch->SetAddress(&clusters);
322 clustersTree->GetEvent(0);
324 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
325 AliDebug(1,Form("%d clusters",nClusters));
326 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
329 //######################################################
330 //#######################TRACK MATCHING###############
331 //######################################################
332 //Fill list of integers, each one is index of track to which the cluster belongs.
334 // step 1 - initialize array of matched track indexes
335 Int_t *matchedTrack = new Int_t[nClusters];
336 for (Int_t iclus = 0; iclus < nClusters; iclus++)
337 matchedTrack[iclus] = -1; // neg. index --> no matched track
339 // step 2, change the flag for all matched clusters found in tracks
340 Int_t iemcalMatch = -1;
341 Int_t endtpc = esd->GetNumberOfTracks();
342 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
343 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
344 iemcalMatch = track->GetEMCALcluster();
345 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
348 //########################################
349 //##############Fill CaloClusters#############
350 //########################################
351 esd->SetNumberOfEMCALClusters(nClusters);
352 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
353 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
354 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
355 if (Debug()) clust->Print();
356 // Get information from EMCAL reconstruction points
359 clust->GetGlobalPosition(gpos);
360 for (Int_t ixyz=0; ixyz<3; ixyz++)
361 xyz[ixyz] = gpos[ixyz];
363 clust->GetElipsAxis(elipAxis);
364 //Create digits lists
365 Int_t cellMult = clust->GetMultiplicity();
366 //TArrayS digiList(digitMult);
367 Float_t *amplFloat = clust->GetEnergiesList();
368 Int_t *digitInts = clust->GetAbsId();
369 TArrayS absIdList(cellMult);
370 //Uncomment when unfolding is done
371 //TArrayD fracList(cellMult);
373 Int_t newCellMult = 0;
374 for (Int_t iCell=0; iCell<cellMult; iCell++) {
375 if (amplFloat[iCell] > 0) {
376 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
377 //Uncomment when unfolding is done
378 //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
382 absIdList.Set(newCellMult);
383 //Uncomment when unfolding is done
384 //fracList.Set(newCellMult);
386 if(newCellMult > 0) { // accept cluster if it has some digit
389 Int_t parentMult = 0;
390 Int_t *parentList = clust->GetParents(parentMult);
391 // fills the ESDCaloCluster
392 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
393 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
394 ec->SetPosition(xyz);
395 ec->SetE(clust->GetEnergy());
396 ec->SetNCells(newCellMult);
397 //Change type of list from short to ushort
398 UShort_t *newAbsIdList = new UShort_t[newCellMult];
399 //Uncomment when unfolding is done
400 //Double_t *newFracList = new Double_t[newCellMult];
401 for(Int_t i = 0; i < newCellMult ; i++) {
402 newAbsIdList[i]=absIdList[i];
403 //Uncomment when unfolding is done
404 //newFracList[i]=fracList[i];
406 ec->SetCellsAbsId(newAbsIdList);
407 //Uncomment when unfolding is done
408 //ec->SetCellsAmplitudeFraction(newFracList);
409 ec->SetClusterDisp(clust->GetDispersion());
410 ec->SetClusterChi2(-1); //not yet implemented
411 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
412 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
413 ec->SetM11(-1) ; //not yet implemented
415 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
416 arrayTrackMatched[0]= matchedTrack[iClust];
417 ec->AddTracksMatched(arrayTrackMatched);
419 TArrayI arrayParents(parentMult,parentList);
420 ec->AddLabels(arrayParents);
422 // add the cluster to the esd object
423 esd->AddCaloCluster(ec);
425 //delete [] newAbsIdList ;
426 //delete [] newFracList ;
428 } // cycle on clusters
430 delete [] matchedTrack;
432 esd->SetNumberOfEMCALClusters(nClustersNew);
433 //if(nClustersNew != nClusters)
434 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
436 //Fill ESDCaloCluster with PID weights
437 AliEMCALPID *pid = new AliEMCALPID;
438 //pid->SetPrintInfo(kTRUE);
439 pid->SetReconstructor(kTRUE);
446 // printf(" ## AliEMCALReconstructor::FillESD() is ended : ncl %i -> %i ### \n ",nClusters, nClustersNew);
449 //__________________________________________________________________________
450 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
452 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
454 // Clear previous digits
455 fgDigitsArr->Delete();
458 // Read the digits from the input tree
459 TBranch *branch = digitsTree->GetBranch("EMCAL");
461 AliError("can't get the branch with the EMCAL digits !");
464 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
465 branch->SetAddress(&fgDigitsArr);