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()
48 : AliAnalysisTaskSE(),
57 fGeomMatrixSet(kFALSE),
58 fLoadGeomMatrices(kFALSE),
74 //________________________________________________________________________
75 AliAnalysisTaskEMCALClusterizeFast::AliAnalysisTaskEMCALClusterizeFast(const char *name)
76 : AliAnalysisTaskSE(name),
80 fRecParam(new AliEMCALRecParam),
84 fGeomName("EMCAL_FIRSTYEARV1"),
85 fGeomMatrixSet(kFALSE),
86 fLoadGeomMatrices(kFALSE),
101 fBranchNames = "ESD:AliESDHeader.,EMCALCells. AOD:header,emcalCells";
102 for(Int_t i = 0; i < 12; ++i)
106 //________________________________________________________________________
107 AliAnalysisTaskEMCALClusterizeFast::~AliAnalysisTaskEMCALClusterizeFast()
117 //-------------------------------------------------------------------
118 void AliAnalysisTaskEMCALClusterizeFast::UserCreateOutputObjects()
120 // Create output objects.
122 if (!fOutputAODBrName.IsNull()) {
123 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
124 fOutputAODBranch->SetName(fOutputAODBrName);
125 AddAODBranch("TClonesArray", &fOutputAODBranch);
126 AliInfo(Form("Created Branch: %s",fOutputAODBrName.Data()));
130 //________________________________________________________________________
131 void AliAnalysisTaskEMCALClusterizeFast::UserExec(Option_t *)
133 // Main loop, called for each event
135 // remove the contents of output list set in the previous event
136 if (fOutputAODBranch)
137 fOutputAODBranch->Clear("C");
139 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
140 AliAODEvent *aodevent = dynamic_cast<AliAODEvent*>(InputEvent());
142 if (!esdevent&&!aodevent) {
143 Error("UserExec","Event not available");
152 AliWarning("Unfolding not implemented");
160 return; // not requested to run clusterizer
167 if (fOutputAODBranch)
168 RecPoints2Clusters(fOutputAODBranch);
171 //________________________________________________________________________
172 void AliAnalysisTaskEMCALClusterizeFast::Clusterize()
176 if (fSubBackground) {
177 fClusterizer->SetInputCalibrated(kTRUE);
178 fClusterizer->SetCalibrationParameters(0);
180 fClusterizer->Digits2Clusters("");
181 if (fSubBackground) {
182 fClusterizer->SetInputCalibrated(kFALSE);
183 fClusterizer->SetCalibrationParameters(fCalibData);
187 //________________________________________________________________________
188 void AliAnalysisTaskEMCALClusterizeFast::FillDigitsArray()
190 // Fill digits from cells.
192 fDigitsArr->Clear("C");
193 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
194 Double_t avgE = 0; // for background subtraction
195 Int_t ncells = cells->GetNumberOfCells();
196 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
197 Double_t cellAmplitude=0, cellTime=0;
198 Short_t cellNumber=0;
199 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
201 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
202 digit->SetId(cellNumber);
203 digit->SetTime(cellTime);
204 digit->SetTimeR(cellTime);
205 digit->SetIndexInList(idigit);
206 digit->SetType(AliEMCALDigit::kHG);
207 if (fRecalibOnly||fSubBackground) {
208 Double_t energy = fClusterizer->Calibrate(cellAmplitude,cellTime,cellNumber);
209 digit->SetAmplitude(energy);
212 digit->SetAmplitude(cellAmplitude);
217 if (fSubBackground) {
218 avgE /= AliEMCALGeometry::GetInstance(fGeomName)->GetNumberOfSuperModules()*48*24;
219 Int_t ndigis = fDigitsArr->GetEntries();
220 for (Int_t i = 0; i < ndigis; ++i) {
221 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(i));
222 Double_t energy = digit->GetAmplitude() - avgE;
224 //fDigitsArr->RemoveAt(i);
225 digit->SetAmplitude(0);
227 digit->SetAmplitude(energy);
231 fDigitsArr->Compress();
235 //________________________________________________________________________________________
236 void AliAnalysisTaskEMCALClusterizeFast::RecPoints2Clusters(TClonesArray *clus)
238 // Cluster energy, global position, cells and their amplitude fractions are restored.
240 Bool_t esdobjects = 0;
241 if (strcmp(clus->GetClass()->GetName(),"AliESDCaloCluster")==0)
244 Int_t Ncls = fClusterArr->GetEntriesFast();
245 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
246 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
247 Int_t ncells_true = 0;
248 const Int_t ncells = recpoint->GetMultiplicity();
249 UShort_t absIds[ncells];
250 Double32_t ratios[ncells];
251 Int_t *dlist = recpoint->GetDigitsList();
252 Float_t *elist = recpoint->GetEnergiesList();
253 for (Int_t c = 0; c < ncells; ++c) {
254 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
255 absIds[ncells_true] = digit->GetId();
256 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
257 if (ratios[ncells_true] < 0.001)
262 if (ncells_true < 1) {
263 AliWarning("Skipping cluster with no cells");
267 // calculate new cluster position
269 recpoint->GetGlobalPosition(gpos);
273 AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
274 c->SetType(AliVCluster::kEMCALClusterv1);
275 c->SetE(recpoint->GetEnergy());
277 c->SetNCells(ncells_true);
278 c->SetDispersion(recpoint->GetDispersion());
279 c->SetEmcCpvDistance(-1); //not yet implemented
280 c->SetChi2(-1); //not yet implemented
281 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
282 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
284 recpoint->GetElipsAxis(elipAxis);
285 c->SetM02(elipAxis[0]*elipAxis[0]) ;
286 c->SetM20(elipAxis[1]*elipAxis[1]) ;
287 c->SetDistanceToBadChannel(recpoint->GetDistanceToBadTower());
289 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
290 cesd->SetCellsAbsId(absIds);
291 cesd->SetCellsAmplitudeFraction(ratios);
293 AliAODCaloCluster *caod = static_cast<AliAODCaloCluster*>(c);
294 caod->SetCellsAbsId(absIds);
295 caod->SetCellsAmplitudeFraction(ratios);
299 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
305 AliAnalysisManager::GetAnalysisManager()->LoadBranch("Tracks");
306 fRecoUtils->FindMatches(esdevent,clus);
309 Int_t Nclus = clus->GetEntries();
310 for(Int_t i=0; i < Nclus; ++i) {
311 AliAODCaloCluster *c = static_cast<AliAODCaloCluster*>(clus->At(i));
312 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
313 if(trackIndex >= 0) {
315 fRecoUtils->GetMatchedResiduals(i,dR, dZ);
316 c->AddTrackMatched(0x0); //esdevent->GetTrack(trackIndex));
317 c->SetTrackDistance(dR,dZ); // not implemented
318 c->SetEmcCpvDistance(dR);
321 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
325 Int_t Nclus = clus->GetEntries();
326 for(Int_t i=0; i < Nclus; ++i) {
327 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
328 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
329 if(trackIndex >= 0) {
331 fRecoUtils->GetMatchedResiduals(i,dR, dZ);
332 c->SetTrackDistance(dR,dZ);
333 c->SetEmcCpvDistance(dR); //to be consistent with AODs
334 c->SetChi2(dZ); //to be consistent with AODs
335 TArrayI tm(1,&trackIndex);
336 c->AddTracksMatched(tm);
338 AliInfo(Form("Matched Track index %d to new cluster %d\n",trackIndex,i));
344 //________________________________________________________________________
345 void AliAnalysisTaskEMCALClusterizeFast::UpdateCells()
347 // Update cells in case re-calibration was done.
349 if (!fCalibData&&!fSubBackground)
352 AliVCaloCells *cells = InputEvent()->GetEMCALCells();
353 Int_t ncells = cells->GetNumberOfCells();
354 Int_t ndigis = fDigitsArr->GetEntries();
356 if (ncells!=ndigis) {
357 cells->DeleteContainer();
358 cells->CreateContainer(ndigis);
360 for (Int_t idigit = 0; idigit < ndigis; ++idigit) {
361 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(idigit));
362 Double_t cellAmplitude = digit->GetCalibAmp();
363 Short_t cellNumber = digit->GetId();
364 Double_t cellTime = digit->GetTime();
365 cells->SetCell(idigit, cellNumber, cellAmplitude, cellTime);
369 //________________________________________________________________________
370 void AliAnalysisTaskEMCALClusterizeFast::UpdateClusters()
372 // Update cells in case re-calibration was done.
374 if (!fAttachClusters)
377 TClonesArray *clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("caloClusters"));
379 clus = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("CaloClusters"));
383 Int_t nents = clus->GetEntries();
384 for (Int_t i=0;i<nents;++i) {
385 AliVCluster *c = static_cast<AliVCluster*>(clus->At(i));
392 RecPoints2Clusters(clus);
395 //________________________________________________________________________________________
396 void AliAnalysisTaskEMCALClusterizeFast::Init()
398 //Select clusterization/unfolding algorithm and set all the needed parameters
400 AliVEvent * event = InputEvent();
402 AliWarning("Event not available!!!");
406 if (event->GetRunNumber()==fRun)
408 fRun = event->GetRunNumber();
411 // init the unfolding afterburner
413 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
417 AliCDBManager *cdb = AliCDBManager::Instance();
418 if (!cdb->IsDefaultStorageSet() && !fOCDBpath.IsNull())
419 cdb->SetDefaultStorage(fOCDBpath);
420 if (fRun!=cdb->GetRun())
423 AliEMCALGeometry *geometry = AliEMCALGeometry::GetInstance(fGeomName);
425 AliFatal("Geometry not available!!!");
429 if (!fGeomMatrixSet) {
430 if (fLoadGeomMatrices) {
431 for(Int_t mod=0; mod < (geometry->GetEMCGeometry())->GetNumberOfSuperModules(); ++mod) {
432 if(fGeomMatrix[mod]){
434 fGeomMatrix[mod]->Print();
435 geometry->SetMisalMatrix(fGeomMatrix[mod],mod);
438 } else { // get matrix from file (work around bug in aliroot)
439 for(Int_t mod=0; mod < geometry->GetEMCGeometry()->GetNumberOfSuperModules(); ++mod) {
440 const TGeoHMatrix *gm = 0;
441 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(event->GetHeader());
443 gm = esdevent->GetEMCALMatrix(mod);
445 AliAODHeader *aodheader = dynamic_cast<AliAODHeader*>(event->GetHeader());
447 gm = aodheader->GetEMCALMatrix(mod);
453 geometry->SetMisalMatrix(gm,mod);
457 fGeomMatrixSet=kTRUE;
460 // setup digit array if needed
462 fDigitsArr = new TClonesArray("AliEMCALDigit", 1000);
463 fDigitsArr->SetOwner(1);
466 // then setup clusterizer
468 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
469 fClusterizer = new AliEMCALClusterizerv1(geometry);
470 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
471 fClusterizer = new AliEMCALClusterizerNxN(geometry);
472 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerNxN) {
473 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(geometry);
474 clusterizer->SetNRowDiff(2);
475 clusterizer->SetNColDiff(2);
476 fClusterizer = clusterizer;
478 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
480 fClusterizer->InitParameters(fRecParam);
481 if (!fCalibData&&fLoadCalib) {
482 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Data"));
484 fCalibData = static_cast<AliEMCALCalibData*>(entry->GetObject());
486 AliFatal("Calibration parameters not found in CDB!");
488 if (!fPedestalData&&fLoadPed) {
489 AliCDBEntry *entry = static_cast<AliCDBEntry*>(AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals"));
491 fPedestalData = static_cast<AliCaloCalibPedestal*>(entry->GetObject());
494 fClusterizer->SetInputCalibrated(kFALSE);
495 fClusterizer->SetCalibrationParameters(fCalibData);
496 fClusterizer->SetCaloCalibPedestal(fPedestalData);
498 fClusterizer->SetInputCalibrated(kTRUE);
500 fClusterizer->SetJustClusters(kTRUE);
501 fClusterizer->SetDigitsArr(fDigitsArr);
502 fClusterizer->SetOutput(0);
503 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());