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 **************************************************************************/
19 #include <TClonesArray.h>
20 #include <TGeoManager.h>
21 #include <TObjArray.h>
24 #include "AliAODCaloCluster.h"
25 #include "AliAODEvent.h"
26 #include "AliAnalysisManager.h"
27 #include "AliCDBEntry.h"
28 #include "AliCDBManager.h"
29 #include "AliCaloCalibPedestal.h"
30 #include "AliEMCALAfterBurnerUF.h"
31 #include "AliEMCALCalibData.h"
32 #include "AliEMCALClusterizerNxN.h"
33 #include "AliEMCALClusterizerv1.h"
34 #include "AliEMCALDigit.h"
35 #include "AliEMCALGeometry.h"
36 #include "AliEMCALRecParam.h"
37 #include "AliEMCALRecPoint.h"
38 #include "AliEMCALRecoUtils.h"
39 #include "AliESDEvent.h"
42 #include "AliAnalysisTaskEMCALClusterizeFast.h"
44 ClassImp(AliAnalysisTaskEMCALClusterizeFast)
46 //________________________________________________________________________
47 AliAnalysisTaskEMCALClusterizeFast::AliAnalysisTaskEMCALClusterizeFast(const char *name)
48 : AliAnalysisTaskSE(name),
52 fRecParam(new AliEMCALRecParam),
56 fGeomName("EMCAL_FIRSTYEARV1"),
57 fGeomMatrixSet(kFALSE),
58 fLoadGeomMatrices(kFALSE),
70 fBranchNames = "ESD:AliESDHeader.,EMCALCells. AOD:header,emcalCells";
71 for(Int_t i = 0; i < 10; ++i)
75 //________________________________________________________________________
76 AliAnalysisTaskEMCALClusterizeFast::~AliAnalysisTaskEMCALClusterizeFast()
86 //-------------------------------------------------------------------
87 void AliAnalysisTaskEMCALClusterizeFast::UserCreateOutputObjects()
89 // Create output objects.
91 if (!fOutputAODBrName.IsNull()) {
92 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
93 fOutputAODBranch->SetName(fOutputAODBrName);
94 AddAODBranch("TClonesArray", &fOutputAODBranch);
95 AliInfo(Form("Created Branch: %s",fOutputAODBrName.Data()));
99 //________________________________________________________________________
100 void AliAnalysisTaskEMCALClusterizeFast::UserExec(Option_t *)
102 // Main loop, called for each event
104 // remove the contents of output list set in the previous event
105 if (fOutputAODBranch)
106 fOutputAODBranch->Clear("C");
108 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
109 AliAODEvent *aodevent = dynamic_cast<AliAODEvent*>(InputEvent());
111 if (!esdevent&&!aodevent) {
112 Error("UserExec","Event not available");
121 AliWarning("Unfolding not implemented");
124 FillDigitsArray(esdevent);
126 FillDigitsArray(aodevent);
127 fClusterizer->Digits2Clusters("");
128 if (esdevent &&fRecoUtils)
129 fRecoUtils->FindMatches(esdevent,fClusterArr);
130 if (fOutputAODBranch)
131 RecPoints2Clusters();
135 //________________________________________________________________________
136 void AliAnalysisTaskEMCALClusterizeFast::FillDigitsArray(AliAODEvent *event)
138 // Fill digits from cells.
140 fDigitsArr->Clear("C");
141 AliAODCaloCells *cells = event->GetEMCALCells();
142 Int_t ncells = cells->GetNumberOfCells();
143 if (ncells>fDigitsArr->GetSize())
144 fDigitsArr->Expand(2*ncells);
145 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
146 Double_t cellAmplitude=0, cellTime=0;
147 Short_t cellNumber=0;
148 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
150 AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->New(idigit);
151 digit->SetId(cellNumber);
152 digit->SetAmplitude(cellAmplitude);
153 digit->SetTime(cellTime);
154 digit->SetTimeR(cellTime);
155 digit->SetIndexInList(idigit);
156 digit->SetType(AliEMCALDigit::kHG);
161 //________________________________________________________________________
162 void AliAnalysisTaskEMCALClusterizeFast::FillDigitsArray(AliESDEvent *event)
164 // Fill digits from cells.
166 fDigitsArr->Clear("C");
167 AliESDCaloCells *cells = event->GetEMCALCells();
168 Int_t ncells = cells->GetNumberOfCells();
169 if (ncells>fDigitsArr->GetSize())
170 fDigitsArr->Expand(2*ncells);
171 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
172 Double_t cellAmplitude=0, cellTime=0;
173 Short_t cellNumber=0;
174 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
176 AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->New(idigit);
177 digit->SetId(cellNumber);
178 digit->SetAmplitude(cellAmplitude);
179 digit->SetTime(cellTime);
180 digit->SetTimeR(cellTime);
181 digit->SetIndexInList(idigit);
182 digit->SetType(AliEMCALDigit::kHG);
187 //________________________________________________________________________________________
188 void AliAnalysisTaskEMCALClusterizeFast::RecPoints2Clusters()
190 // Cluster energy, global position, cells and their amplitude fractions are restored.
192 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
194 Int_t Ncls = fClusterArr->GetEntriesFast();
195 for(Int_t i=0, nout=0; i < Ncls; ++i) {
196 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
197 Int_t ncells_true = 0;
198 const Int_t ncells = recpoint->GetMultiplicity();
199 UShort_t absIds[ncells];
200 Double32_t ratios[ncells];
201 Int_t *dlist = recpoint->GetDigitsList();
202 Float_t *elist = recpoint->GetEnergiesList();
204 for (Int_t c = 0; c < ncells; ++c) {
205 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
206 absIds[ncells_true] = digit->GetId();
207 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
208 if (ratios[ncells_true] > 0.001)
212 if (ncells_true < 1) {
213 AliWarning("Skipping cluster with no cells");
217 // calculate new cluster position
221 recpoint->EvalGlobalPosition(fRecParam->GetW0(), fDigitsArr);
222 recpoint->GetGlobalPosition(gpos);
225 AliAODCaloCluster *clus = static_cast<AliAODCaloCluster*>(fOutputAODBranch->New(nout++));
226 clus->SetType(AliVCluster::kEMCALClusterv1);
227 clus->SetE(recpoint->GetEnergy());
228 clus->SetPosition(g);
229 clus->SetNCells(ncells_true);
230 clus->SetCellsAbsId(absIds);
231 clus->SetCellsAmplitudeFraction(ratios);
232 clus->SetDispersion(recpoint->GetDispersion());
233 clus->SetChi2(-1); //not yet implemented
234 clus->SetTOF(recpoint->GetTime()) ; //time-of-flight
235 clus->SetNExMax(recpoint->GetNExMax()); //number of local maxima
237 recpoint->GetElipsAxis(elipAxis);
238 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
239 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
240 clus->SetDistToBadChannel(recpoint->GetDistanceToBadTower());
241 if (esdevent && fRecoUtils) {
242 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
243 if(trackIndex >= 0) {
244 clus->AddTrackMatched(esdevent->GetTrack(trackIndex));
246 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
252 //________________________________________________________________________________________
253 void AliAnalysisTaskEMCALClusterizeFast::Init()
255 //Select clusterization/unfolding algorithm and set all the needed parameters
257 AliVEvent * event = InputEvent();
259 AliWarning("Event not available!!!");
263 if (event->GetRunNumber()==fRun)
265 fRun = event->GetRunNumber();
268 // init the unfolding afterburner
270 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
274 AliCDBManager *cdb = AliCDBManager::Instance();
275 if (!cdb->IsDefaultStorageSet() && !fOCDBpath.IsNull())
276 cdb->SetDefaultStorage(fOCDBpath);
277 if (fRun!=cdb->GetRun())
280 AliEMCALGeometry *geometry = AliEMCALGeometry::GetInstance(fGeomName);
282 AliFatal("Geometry not available!!!");
286 if (!fGeomMatrixSet) {
287 if (fLoadGeomMatrices) {
288 for(Int_t mod=0; mod < (geometry->GetEMCGeometry())->GetNumberOfSuperModules(); ++mod) {
289 if(fGeomMatrix[mod]){
291 fGeomMatrix[mod]->Print();
292 geometry->SetMisalMatrix(fGeomMatrix[mod],mod);
296 for(Int_t mod=0; mod < geometry->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
297 if(event->GetEMCALMatrix(mod)) {
299 event->GetEMCALMatrix(mod)->Print();
300 geometry->SetMisalMatrix(event->GetEMCALMatrix(mod),mod);
304 fGeomMatrixSet=kTRUE;
307 // setup digit array if needed
309 fDigitsArr = new TClonesArray("AliEMCALDigit", 1000);
310 fDigitsArr->SetOwner(1);
313 // then setup clusterizer
315 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
316 fClusterizer = new AliEMCALClusterizerv1(geometry);
317 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
318 fClusterizer = new AliEMCALClusterizerNxN(geometry);
319 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerNxN) {
320 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(geometry);
321 clusterizer->SetNRowDiff(2);
322 clusterizer->SetNColDiff(2);
323 fClusterizer = clusterizer;
325 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
327 fClusterizer->InitParameters(fRecParam);
328 if (!fCalibData&&fLoadCalib) {
329 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Data"));
331 fCalibData = static_cast<AliEMCALCalibData*>(entry->GetObject());
333 AliFatal("Calibration parameters not found in CDB!");
335 if (!fPedestalData&&fLoadPed) {
336 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals"));
338 fPedestalData = static_cast<AliCaloCalibPedestal*>(entry->GetObject());
341 fClusterizer->SetInputCalibrated(kFALSE);
342 fClusterizer->SetCalibrationParameters(fCalibData);
343 fClusterizer->SetCaloCalibPedestal(fPedestalData);
345 fClusterizer->SetInputCalibrated(kTRUE);
347 fClusterizer->SetJustClusters(kTRUE);
348 fClusterizer->SetDigitsArr(fDigitsArr);
349 fClusterizer->SetOutput(0);
350 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());