]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/CaloCalib/AliAnalysisTaskEMCALClusterize.cxx
Improve LED events rejection, based on Rongrong studies
[u/mrichter/AliRoot.git] / PWG4 / CaloCalib / AliAnalysisTaskEMCALClusterize.cxx
CommitLineData
6fdd30c4 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15/* $Id: $ */
16
17//_________________________________________________________________________
18// This analysis provides a new list of clusters to be used in other analysis
19//
20// Author: Gustavo Conesa Balbastre,
21// Adapted from analysis class from Deepa Thomas
22//
23//
24//_________________________________________________________________________
25
26// --- Root ---
27#include "TString.h"
28#include "TRefArray.h"
29#include "TClonesArray.h"
30#include "TTree.h"
31#include "TGeoManager.h"
5994e71f 32#include "TROOT.h"
33#include "TInterpreter.h"
1f77507b 34#include "TFile.h"
01313069 35//#include "string.h"
6fdd30c4 36
37// --- AliRoot Analysis Steering
38#include "AliAnalysisTask.h"
39#include "AliAnalysisManager.h"
40#include "AliESDEvent.h"
41#include "AliGeomManager.h"
42#include "AliVCaloCells.h"
43#include "AliAODCaloCluster.h"
44#include "AliCDBManager.h"
45#include "AliCDBStorage.h"
46#include "AliCDBEntry.h"
47#include "AliLog.h"
48#include "AliVEventHandler.h"
6060ed91 49#include "AliAODInputHandler.h"
6fdd30c4 50
51// --- EMCAL
52#include "AliEMCALRecParam.h"
53#include "AliEMCALAfterBurnerUF.h"
54#include "AliEMCALGeometry.h"
55#include "AliEMCALClusterizerNxN.h"
56#include "AliEMCALClusterizerv1.h"
cfcbe5d2 57#include "AliEMCALClusterizerv2.h"
6fdd30c4 58#include "AliEMCALRecPoint.h"
59#include "AliEMCALDigit.h"
60#include "AliCaloCalibPedestal.h"
61#include "AliEMCALCalibData.h"
385b7abf 62#include "AliEMCALRecoUtils.h"
6fdd30c4 63
64#include "AliAnalysisTaskEMCALClusterize.h"
65
66ClassImp(AliAnalysisTaskEMCALClusterize)
67
68//________________________________________________________________________
69AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize(const char *name)
70 : AliAnalysisTaskSE(name)
0b080dc9 71 , fGeom(0), fGeomName("EMCAL_COMPLETEV1")
72 , fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
73 , fCalibData(0), fPedestalData(0)
74 , fOCDBpath("raw://"), fAccessOCDB(kFALSE)
75 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
76 , fRecParam(0), fClusterizer(0)
77 , fUnfolder(0), fJustUnfold(kFALSE)
78 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
79 , fFillAODFile(kTRUE), fFillAODHeader(0)
80 , fFillAODCaloCells(0), fRun(-1)
81 , fRecoUtils(0), fConfigName("")
82 , fCellLabels(), fCellSecondLabels(), fCellTime()
a39f5b70 83 , fMaxEvent(1000000000), fDoTrackMatching(kFALSE)
0b080dc9 84 , fSelectCell(kFALSE), fSelectCellMinE(0.005), fSelectCellMinFrac(0.001)
85 , fRemoveLEDEvents(kFALSE)
6a8be5c3 86{
6fdd30c4 87 //ctor
6060ed91 88 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
6a8be5c3 89 for(Int_t j = 0; j < 24*48*11; j++) {
90 fCellLabels[j] = -1;
91 fCellSecondLabels[j] = -1;
a39f5b70 92 fCellTime[j] = 0.;
6a8be5c3 93 }
a39f5b70 94
6fdd30c4 95 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
96 fClusterArr = new TObjArray(100);
c0feb73e 97 fCaloClusterArr = new TObjArray(1000);
6fdd30c4 98 fRecParam = new AliEMCALRecParam;
385b7abf 99 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
100 fRecoUtils = new AliEMCALRecoUtils();
a39f5b70 101
6fdd30c4 102}
103
104//________________________________________________________________________
105AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize()
106 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
0b080dc9 107, fGeom(0), fGeomName("EMCAL_COMPLETEV1")
108, fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
109, fCalibData(0), fPedestalData(0)
110, fOCDBpath("raw://"), fAccessOCDB(kFALSE)
111, fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
112, fRecParam(0), fClusterizer(0)
113, fUnfolder(0), fJustUnfold(kFALSE)
114, fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
115, fFillAODFile(kTRUE), fFillAODHeader(0)
116, fFillAODCaloCells(0), fRun(-1)
117, fRecoUtils(0), fConfigName("")
118, fCellLabels(), fCellSecondLabels(), fCellTime()
119, fMaxEvent(1000000000), fDoTrackMatching(kFALSE)
120, fSelectCell(kFALSE), fSelectCellMinE(0.005), fSelectCellMinFrac(0.001)
121, fRemoveLEDEvents(kFALSE)
122
6fdd30c4 123{
124 // Constructor
6060ed91 125 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
37d2296c 126 for(Int_t j = 0; j < 24*48*11; j++) {
127 fCellLabels[j] = -1;
128 fCellSecondLabels[j] = -1;
a39f5b70 129 fCellTime[j] = 0.;
37d2296c 130 }
6fdd30c4 131 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
132 fClusterArr = new TObjArray(100);
133 fCaloClusterArr = new TObjArray(100);
134 fRecParam = new AliEMCALRecParam;
385b7abf 135 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
136 fRecoUtils = new AliEMCALRecoUtils();
6fdd30c4 137}
138
5994e71f 139
6fdd30c4 140//________________________________________________________________________
141AliAnalysisTaskEMCALClusterize::~AliAnalysisTaskEMCALClusterize()
142{
143 //dtor
144
145 if (fDigitsArr){
146 fDigitsArr->Clear("C");
542e1379 147 delete fDigitsArr;
6fdd30c4 148 }
149
150 if (fClusterArr){
151 fClusterArr->Delete();
542e1379 152 delete fClusterArr;
6fdd30c4 153 }
154
155 if (fCaloClusterArr){
156 fCaloClusterArr->Delete();
542e1379 157 delete fCaloClusterArr;
6fdd30c4 158 }
6a8be5c3 159
385b7abf 160 if(fClusterizer) delete fClusterizer;
161 if(fUnfolder) delete fUnfolder;
162 if(fRecoUtils) delete fRecoUtils;
6a8be5c3 163
6fdd30c4 164}
165
5994e71f 166//-------------------------------------------------------------------
167void AliAnalysisTaskEMCALClusterize::Init()
168{
169 //Init analysis with configuration macro if available
170
171 if(gROOT->LoadMacro(fConfigName) >=0){
172 printf("Configure analysis with %s\n",fConfigName.Data());
173 AliAnalysisTaskEMCALClusterize *clus = (AliAnalysisTaskEMCALClusterize*)gInterpreter->ProcessLine("ConfigEMCALClusterize()");
174 fGeomName = clus->fGeomName;
175 fLoadGeomMatrices = clus->fLoadGeomMatrices;
2ef5608f 176 fOCDBpath = clus->fOCDBpath;
177 fAccessOCDB = clus->fAccessOCDB;
5994e71f 178 fRecParam = clus->fRecParam;
179 fJustUnfold = clus->fJustUnfold;
180 fFillAODFile = clus->fFillAODFile;
181 fRecoUtils = clus->fRecoUtils;
182 fConfigName = clus->fConfigName;
2ef5608f 183 fMaxEvent = clus->fMaxEvent;
184 fDoTrackMatching = clus->fDoTrackMatching;
5994e71f 185 fOutputAODBranchName = clus->fOutputAODBranchName;
186 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = clus->fGeomMatrix[i] ;
6a8be5c3 187
5994e71f 188 }
6a8be5c3 189
5994e71f 190}
191
6fdd30c4 192//-------------------------------------------------------------------
193void AliAnalysisTaskEMCALClusterize::UserCreateOutputObjects()
194{
195 // Init geometry, create list of output clusters
6a8be5c3 196
6fdd30c4 197 fGeom = AliEMCALGeometry::GetInstance(fGeomName) ;
1f77507b 198 if(fOutputAODBranchName.Length()!=0){
199 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
200 fOutputAODBranch->SetName(fOutputAODBranchName);
201 AddAODBranch("TClonesArray", &fOutputAODBranch);
202 }
203 else {
204 AliFatal("fOutputAODBranchName not set\n");
205 }
206}
207
208//________________________________________________________________________
209void AliAnalysisTaskEMCALClusterize::FillAODCaloCells() {
210 // Put calo cells in standard branch
211 AliVEvent * event = InputEvent();
212 AliVCaloCells &eventEMcells = *(event->GetEMCALCells());
213 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
214
215 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
216 aodEMcells.CreateContainer(nEMcell);
217 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
218 Double_t calibFactor = 1.;
219 for (Int_t iCell = 0; iCell < nEMcell; iCell++) {
220 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
221 fGeom->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
222 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
223
224 if(fRecoUtils->IsRecalibrationOn()){
225 calibFactor = fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
226 }
227
228 if(!fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){ //Channel is not declared as bad
229 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor);
1f77507b 230 }
231 else {
232 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0);
1f77507b 233 }
234 }
235 aodEMcells.Sort();
236
237}
6fdd30c4 238
1f77507b 239//________________________________________________________________________
240void AliAnalysisTaskEMCALClusterize::FillAODHeader() {
241 //Put event header information in standard AOD branch
242
243 AliVEvent* event = InputEvent();
244 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
245 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);
6a8be5c3 246
1f77507b 247 Double_t pos[3] ;
248 Double_t covVtx[6];
249 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
250
251 AliAODHeader* header = AODEvent()->GetHeader();
252 header->SetRunNumber(event->GetRunNumber());
253
254 if(esdevent){
255 TTree* tree = fInputHandler->GetTree();
256 if (tree) {
257 TFile* file = tree->GetCurrentFile();
258 if (file) header->SetESDFileName(file->GetName());
259 }
260 }
9a42b255 261 else if (aodevent) header->SetESDFileName(aodevent->GetHeader()->GetESDFileName());
1f77507b 262
263 header->SetBunchCrossNumber(event->GetBunchCrossNumber());
264 header->SetOrbitNumber(event->GetOrbitNumber());
265 header->SetPeriodNumber(event->GetPeriodNumber());
266 header->SetEventType(event->GetEventType());
267
268 //Centrality
269 if(event->GetCentrality()){
270 header->SetCentrality(new AliCentrality(*(event->GetCentrality())));
271 }
272 else{
273 header->SetCentrality(0);
274 }
275
276 //Trigger
277 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
9a42b255 278 if (esdevent) header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
279 else if (aodevent) header->SetFiredTriggerClasses(aodevent->GetFiredTriggerClasses());
1f77507b 280 header->SetTriggerMask(event->GetTriggerMask());
281 header->SetTriggerCluster(event->GetTriggerCluster());
282 if(esdevent){
283 header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());
284 header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());
285 header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());
286 }
9a42b255 287 else if (aodevent){
1f77507b 288 header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());
289 header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());
290 header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());
291 }
292
293 header->SetMagneticField(event->GetMagneticField());
294 //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.);
295
296 header->SetZDCN1Energy(event->GetZDCN1Energy());
297 header->SetZDCP1Energy(event->GetZDCP1Energy());
298 header->SetZDCN2Energy(event->GetZDCN2Energy());
299 header->SetZDCP2Energy(event->GetZDCP2Energy());
300 header->SetZDCEMEnergy(event->GetZDCEMEnergy(0),event->GetZDCEMEnergy(1));
301
302 Float_t diamxy[2]={event->GetDiamondX(),event->GetDiamondY()};
303 Float_t diamcov[3];
304 event->GetDiamondCovXY(diamcov);
305 header->SetDiamond(diamxy,diamcov);
9a42b255 306 if (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
307 else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
1f77507b 308
309 //
310 //
311 Int_t nVertices = 1 ;/* = prim. vtx*/;
312 Int_t nCaloClus = event->GetNumberOfCaloClusters();
313
314 AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
315
316 // Access to the AOD container of vertices
317 TClonesArray &vertices = *(AODEvent()->GetVertices());
318 Int_t jVertices=0;
319
320 // Add primary vertex. The primary tracks will be defined
321 // after the loops on the composite objects (V0, cascades, kinks)
322 event->GetPrimaryVertex()->GetXYZ(pos);
323 Float_t chi = 0;
324 if (esdevent){
325 esdevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
326 chi = esdevent->GetPrimaryVertex()->GetChi2toNDF();
327 }
328 else if (aodevent){
329 aodevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
330 chi = aodevent->GetPrimaryVertex()->GetChi2perNDF();//Different from ESD?
331 }
332
333 AliAODVertex * primary = new(vertices[jVertices++])
334 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
335 primary->SetName(event->GetPrimaryVertex()->GetName());
336 primary->SetTitle(event->GetPrimaryVertex()->GetTitle());
337
6fdd30c4 338}
339
340//________________________________________________________________________
341void AliAnalysisTaskEMCALClusterize::UserExec(Option_t *)
342{
343 // Main loop
344 // Called for each event
6a8be5c3 345
220447cd 346 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
347 Int_t eventN = Entry();
348 if(aodIH) eventN = aodIH->GetReadEntry();
349
1f77507b 350 if (eventN > fMaxEvent) return;
c50e6949 351 //printf("Clusterizer --- Event %d-- \n",eventN);
6a8be5c3 352
6fdd30c4 353 //Remove the contents of output list set in the previous event
354 fOutputAODBranch->Clear("C");
355
1f77507b 356 //Magic line to write events to AOD file
357 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
358 LoadBranches();
359
e9dd2d80 360 //Init pointers, clusterizer, ocdb
361 if(fAccessOCDB) AccessOCDB();
362 InitClusterization();
6a8be5c3 363
6060ed91 364 //Get the event
365 AliVEvent * event = 0;
366 AliESDEvent * esdevent = 0;
6a8be5c3 367
368 //Fill output event with header
369
6060ed91 370 //Check if input event are embedded events
371 //If so, take output event
6060ed91 372 if (aodIH && aodIH->GetMergeEvents()) {
e9dd2d80 373 //printf("AliAnalysisTaskEMCALClusterize::UserExec() - Use embedded events\n");
6060ed91 374 event = AODEvent();
1f77507b 375
376 if(!aodIH->GetMergeEMCALCells())
377 AliFatal("Events merged but not EMCAL cells, check analysis settings!");
378
6a8be5c3 379 // printf("InputEvent N Clusters %d, N Cells %d\n",InputEvent()->GetNumberOfCaloClusters(),
380 // InputEvent()->GetEMCALCells()->GetNumberOfCells());
381 // printf("MergedEvent N Clusters %d, N Cells %d\n",aodIH->GetEventToMerge()->GetNumberOfCaloClusters(),
382 // aodIH->GetEventToMerge()->GetEMCALCells()->GetNumberOfCells());
383 // for (Int_t icl=0; icl < aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); icl++) {
384 // AliAODCaloCluster *sigCluster = aodIH->GetEventToMerge()->GetCaloCluster(icl);
385 // if(sigCluster->IsEMCAL()) printf("Signal cluster: i %d, E %f\n",icl,sigCluster->E());
386 // }
387 // printf("OutputEvent N Clusters %d, N Cells %d\n", AODEvent()->GetNumberOfCaloClusters(),
388 // AODEvent()->GetEMCALCells()->GetNumberOfCells());
1f77507b 389
6060ed91 390 }
391 else {
392 event = InputEvent();
393 esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
1f77507b 394 if(fFillAODCaloCells) FillAODCaloCells();
395 if(fFillAODHeader) FillAODHeader();
6060ed91 396 }
397
6fdd30c4 398 if (!event) {
3fa4fb85 399 Error("UserExec","Event not available");
6fdd30c4 400 return;
401 }
6a8be5c3 402
cd2e4ce6 403 //-------------------------------------------------------------------------------------
404 // Reject event if large clusters with large energy
405 // Use only for LHC11a data for the moment, and if input is clusterizer V1 or V1+unfolding
406 // If clusterzer NxN or V2 it does not help
407 //-------------------------------------------------------------------------------------
408 if(fRemoveLEDEvents){
409 for (Int_t i = 0; i < InputEvent()->GetNumberOfCaloClusters(); i++)
410 {
411 AliVCluster *clus = InputEvent()->GetCaloCluster(i);
412 if(clus->IsEMCAL()){
413
414 if ((clus->E() > 500 && clus->GetNCells() > 200 ) || clus->GetNCells() > 200) {
415 Int_t absID = clus->GetCellsAbsId()[0];
416 Int_t sm = fGeom->GetSuperModuleNumber(absID);
417 printf("AliAnalysisTaskEMCALClusterize - reject event with cluster : E %f, ncells %d, absId(0) %d, SM %d\n",clus->E(), clus->GetNCells(),absID, sm);
418
419 return;
420 }
421 }
422 }
423
424 // Count number of cells with energy larger than 0.1 in SM3, cut on this number
425 Int_t ncells = 0;
426 for(Int_t icell = 0; icell < event->GetEMCALCells()->GetNumberOfCells(); icell++){
427 if(event->GetEMCALCells()->GetAmplitude(icell) > 0.1 && event->GetEMCALCells()->GetCellNumber(icell)/(24*48)==3) ncells++;
428 }
429
430 TString triggerclasses = "";
431 if(esdevent) triggerclasses = esdevent ->GetFiredTriggerClasses();
432 else triggerclasses = ((AliAODEvent*)event)->GetFiredTriggerClasses();
433
434 Int_t ncellcut = 21;
435 if(triggerclasses.Contains("EMC")) ncellcut = 35;
436
437 if(ncells >= ncellcut ){
438 printf("AliAnalysisTaskEMCALClusterize - reject event with cluster - reject event with ncells in SM3: ncells %d\n",ncells);
439
440 return;
441 }
442
443 }// Remove LED events
444
6fdd30c4 445 //-------------------------------------------------------------------------------------
446 //Set the geometry matrix, for the first event, skip the rest
447 //-------------------------------------------------------------------------------------
448 if(!fGeomMatrixSet){
449 if(fLoadGeomMatrices){
450 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
451 if(fGeomMatrix[mod]){
452 if(DebugLevel() > 1)
453 fGeomMatrix[mod]->Print();
454 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
455 }
456 fGeomMatrixSet=kTRUE;
457 }//SM loop
458 }//Load matrices
459 else if(!gGeoManager){
3fa4fb85 460 Info("UserExec","Get geo matrices from data");
6fdd30c4 461 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
462 if(!strcmp(event->GetName(),"AliAODEvent")) {
463 if(DebugLevel() > 1)
3fa4fb85 464 Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
6fdd30c4 465 }//AOD
466 else {
3fa4fb85 467 if(DebugLevel() > 1)
468 Info("UserExec","AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
6fdd30c4 469 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event) ;
470 if(!esd) {
3fa4fb85 471 Error("UserExec","This event does not contain ESDs?");
6fdd30c4 472 return;
473 }
474 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
475 if(DebugLevel() > 1)
476 esd->GetEMCALMatrix(mod)->Print();
477 if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
478 }
479 fGeomMatrixSet=kTRUE;
480 }//ESD
481 }//Load matrices from Data
5994e71f 482
483 //Recover time dependent corrections, put then in recalibration histograms. Do it once
3bfc4732 484 fRecoUtils->SetRunDependentCorrections(InputEvent()->GetRunNumber());
6a8be5c3 485
6fdd30c4 486 }//first event
6a8be5c3 487
6fdd30c4 488 //Get the list of cells needed for unfolding and reclustering
6a8be5c3 489 AliVCaloCells *cells = event->GetEMCALCells();
490 Int_t nClustersOrg = 0;
491 Double_t cellAmplitude = 0;
492 Double_t cellTime = 0;
493 Short_t cellNumber = 0;
494
6fdd30c4 495 //-------------------------------------------
496 //---------Unfolding clusters----------------
497 //-------------------------------------------
498 if (fJustUnfold) {
499
500 //Fill the array with the EMCAL clusters, copy them
501 for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++)
502 {
503 AliVCluster *clus = event->GetCaloCluster(i);
504 if(clus->IsEMCAL()){
5994e71f 505
506 //recalibrate/remove bad channels/etc if requested
507 if(fRecoUtils->ClusterContainsBadChannel(fGeom,clus->GetCellsAbsId(), clus->GetNCells())){
5994e71f 508 continue;
509 }
510
511 if(fRecoUtils->IsRecalibrationOn()){
6a8be5c3 512
513 //Calibrate cluster
5994e71f 514 //printf("Energy before %f ",clus->E());
515 fRecoUtils->RecalibrateClusterEnergy(fGeom, clus, cells);
516 //printf("; after %f\n",clus->E());
6a8be5c3 517
518 //CalibrateCells
519 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
520 {
521 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
522 break;
523
524
525 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
526 fGeom->GetCellIndex(cellNumber,imod,iTower,iIphi,iIeta);
527 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
528
529 //Do not include bad channels found in analysis?
530 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
531 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){
532 fCellLabels[cellNumber] =-1; //reset the entry in the array for next event
533 fCellSecondLabels[cellNumber]=-1; //reset the entry in the array for next event
a39f5b70 534 fCellTime[cellNumber] = 0.;
6a8be5c3 535 continue;
536 }
537
538 cells->SetCell(icell, cellNumber, cellAmplitude*fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),cellTime);
539
540 }// cells loop
541 }// recalibrate
542
5994e71f 543 //Cast to ESD or AOD, needed to create the cluster array
e615d952 544 AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
545 AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
546 if (esdCluster){
547 fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
6fdd30c4 548 }//ESD
e615d952 549 else if(aodCluster){
550 fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
6fdd30c4 551 }//AOD
3fa4fb85 552 else
553 Warning("UserExec()"," - Wrong CaloCluster type?");
6fdd30c4 554 nClustersOrg++;
555 }
556 }
557
558 //Do the unfolding
559 fUnfolder->UnfoldClusters(fCaloClusterArr, cells);
560
561 //CLEAN-UP
562 fUnfolder->Clear();
563
6a8be5c3 564 } // just unfold ESD/AOD cluster
565
6fdd30c4 566 //-------------------------------------------
567 //---------- Recluster cells ----------------
568 //-------------------------------------------
569
570 else{
571 //-------------------------------------------------------------------------------------
572 //Transform CaloCells into Digits
573 //-------------------------------------------------------------------------------------
6060ed91 574
575 //In case of MC, first loop on the clusters and fill MC label to array
576 //.....................................................................
577
6a8be5c3 578 // for(Int_t j = 0; j < 24*48*11; j++) {
579 // if(fCellLabels[j] !=-1) printf("Not well initialized cell %d, label1 %d\n",j,fCellLabels[j] ) ;
580 // if(fCellSecondLabels[j]!=-1) printf("Not well initialized cell %d, label2 %d\n",j,fCellSecondLabels[j]) ;
581 // }
6060ed91 582
1f77507b 583 Int_t nClusters = event->GetNumberOfCaloClusters();
006e9636 584 if(aodIH && aodIH->GetEventToMerge()) //Embedding
1f77507b 585 nClusters = aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); //Get clusters directly from embedded signal
586 for (Int_t i = 0; i < nClusters; i++)
6060ed91 587 {
1f77507b 588 AliVCluster *clus = 0;
006e9636 589 if(aodIH && aodIH->GetEventToMerge()) //Embedding
590 clus = aodIH->GetEventToMerge()->GetCaloCluster(i); //Get clusters directly from embedded signal
591 else
592 clus = event->GetCaloCluster(i);
6a8be5c3 593
1f77507b 594 if(!clus) {
595 printf("AliEMCALReclusterize::UserExec() - No Clusters\n");
596 return;
597 }
598
6060ed91 599 if(clus->IsEMCAL()){
1f77507b 600 //printf("Cluster Signal %d, energy %f\n",clus->GetID(),clus->E());
6060ed91 601 Int_t label = clus->GetLabel();
1f77507b 602 Int_t label2 = -1 ;
603 if (clus->GetNLabels()>=2) label2 = clus->GetLabelAt(1) ;
6060ed91 604 UShort_t * index = clus->GetCellsAbsId() ;
605 for(Int_t icell=0; icell < clus->GetNCells(); icell++ ){
a39f5b70 606 fCellLabels[index[icell]] = label;
607 fCellSecondLabels[index[icell]] = label2;
3bfc4732 608 //printf("Clusterizer in : TOF %g\n",clus->GetTOF()*1.e9);
609
a39f5b70 610 fCellTime[icell] = clus->GetTOF();
611
abf0860a 612 //printf("1) absID %d, label[0] %d label[1] %d\n",index[icell], fCellLabels[index[icell]],fCellSecondLabels[index[icell]]);
6060ed91 613 }
614 nClustersOrg++;
615 }
616 }
6a8be5c3 617
6060ed91 618 // Create digits
619 //.................
3bfc4732 620 Int_t idigit = 0;
621 Int_t id = -1;
622 Float_t amp = -1;
623 Double_t time = -1;
6fdd30c4 624
6fdd30c4 625 TTree *digitsTree = new TTree("digitstree","digitstree");
626 digitsTree->Branch("EMCAL","TClonesArray", &fDigitsArr, 32000);
627
3bfc4732 628 Int_t bc = InputEvent()->GetBunchCrossNumber();
629
6fdd30c4 630 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
631 {
632 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
633 break;
634
635 time = cellTime;
636 amp = cellAmplitude;
637 id = cellNumber;
638
5994e71f 639 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
640 fGeom->GetCellIndex(id,imod,iTower,iIphi,iIeta);
641 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
642
643 //Do not include bad channels found in analysis?
644 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
6a8be5c3 645 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){
646 fCellLabels[id] =-1; //reset the entry in the array for next event
647 fCellSecondLabels[id]=-1; //reset the entry in the array for next event
a39f5b70 648 fCellTime[id] = 0.;
5994e71f 649 //printf("Remove channel %d\n",id);
650 continue;
651 }
6a8be5c3 652
5994e71f 653 //Recalibrate?
654 if(fRecoUtils->IsRecalibrationOn()){
655 //printf("CalibFactor %f times %f for id %d\n",fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),amp,id);
656 amp *=fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
657 }
3bfc4732 658
a39f5b70 659 // In case of AOD analysis cell time is 0, approximate replacing by time of the cluster the digit belongs.
660 if (time*1e9 < 1.) time = fCellTime[id];
661
3bfc4732 662 // Recalibrate time
663 fRecoUtils->RecalibrateCellTime(id,bc,time);
664
665// printf("Clusterizer: Id %d, Time org %e, Time new %e; Amp org %f, Amp new %f\n",
666// id, cells->GetTime(icell),time, cells->GetAmplitude(icell),amp);
667
668
6060ed91 669 //Create the digit, put a fake primary deposited energy to trick the clusterizer when checking the most likely primary
670 new((*fDigitsArr)[idigit]) AliEMCALDigit( fCellLabels[id], fCellLabels[id],id, amp, time,AliEMCALDigit::kHG,idigit, 0, 0, 1);
671 //if(fCellLabels[id]>=0)printf("2) Digit cell %d, label %d\n",id,fCellLabels[id]) ;
672 //else printf("2) Digit cell %d, no label, amp %f \n",id,amp) ;
220447cd 673 fCellLabels[id] =-1; //reset the entry in the array for next event
5994e71f 674
675 //printf("Digit: Id %d, amp %f, time %e, index %d\n",id, amp,time,idigit);
6fdd30c4 676 idigit++;
677 }
678
679 //Fill the tree with digits
680 digitsTree->Fill();
681
682 //-------------------------------------------------------------------------------------
683 //Do the clusterization
684 //-------------------------------------------------------------------------------------
685 TTree *clustersTree = new TTree("clustertree","clustertree");
6a8be5c3 686
6fdd30c4 687 fClusterizer->SetInput(digitsTree);
688 fClusterizer->SetOutput(clustersTree);
689 fClusterizer->Digits2Clusters("");
6a8be5c3 690
6fdd30c4 691 //-------------------------------------------------------------------------------------
692 //Transform the recpoints into AliVClusters
693 //-------------------------------------------------------------------------------------
694
695 clustersTree->SetBranchStatus("*",0); //disable all branches
696 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
697
698 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
699 branch->SetAddress(&fClusterArr);
700 branch->GetEntry(0);
6a8be5c3 701
6fdd30c4 702 RecPoints2Clusters(fDigitsArr, fClusterArr, fCaloClusterArr);
703
6a8be5c3 704 if(!fCaloClusterArr){
705 printf("AliAnalisysTaskEMCALClusterize::UserExec() - No array with CaloClusters, input RecPoints entries %d\n",fClusterArr->GetEntriesFast());
706 return;
707 }
708
bf0ff47b 709 if( DebugLevel() > 0 && fCaloClusterArr->GetEntriesFast() != fClusterArr->GetEntriesFast()){
710 printf("AliAnalisysTaskEMCALClusterize::UserExec() - Some RecRoints not transformed into CaloClusters (clusterizer %d, unfold %d): Input entries %d - Output entries %d - %d (not fast)\n",
711 fRecParam->GetClusterizerFlag(),fRecParam->GetUnfold(),
6a8be5c3 712 fClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntries());
713 }
714
01313069 715 //Reset the array with second labels for this event
716 memset(fCellSecondLabels, -1, sizeof(fCellSecondLabels));
717
6fdd30c4 718 //---CLEAN UP-----
719 fClusterizer->Clear();
720 fDigitsArr ->Clear("C");
721 fClusterArr ->Delete(); // Do not Clear(), it leaks, why?
6a8be5c3 722
6fdd30c4 723 clustersTree->Delete("all");
724 digitsTree ->Delete("all");
6fdd30c4 725 }
726
385b7abf 727 //Recalculate track-matching for the new clusters, only with ESDs
cb3001b9 728 if(fDoTrackMatching) fRecoUtils->FindMatches(event,fCaloClusterArr,fGeom);
6a8be5c3 729
385b7abf 730
6fdd30c4 731 //-------------------------------------------------------------------------------------
732 //Put the new clusters in the AOD list
733 //-------------------------------------------------------------------------------------
734
dd9a9f63 735 Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntriesFast();
6060ed91 736 //printf("New clusters %d, Org clusters %d\n",kNumberOfCaloClusters, nClustersOrg);
6fdd30c4 737 for(Int_t i = 0; i < kNumberOfCaloClusters; i++){
738 AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
3fa4fb85 739 //if(Entry()==0) Info("UserExec","newCluster E %f\n", newCluster->E());
385b7abf 740
3bfc4732 741 //Add matched track
742 if(fDoTrackMatching){
385b7abf 743 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
744 if(trackIndex >= 0){
745 newCluster->AddTrackMatched(event->GetTrack(trackIndex));
746 if(DebugLevel() > 1)
747 Info("UserExec","Matched Track index %d to new cluster %d \n",trackIndex,i);
748 }
749 }
0821ba9f 750
5994e71f 751 //In case of new bad channels, recalculate distance to bad channels
752 if(fRecoUtils->IsBadChannelsRemovalSwitchedOn()){
753 //printf("DistToBad before %f ",newCluster->GetDistanceToBadChannel());
754 fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, event->GetEMCALCells(), newCluster);
755 //printf("; after %f \n",newCluster->GetDistanceToBadChannel());
756 }
757
6a8be5c3 758 // if(newCluster->GetNLabels()>0){
759 // printf("3) MC: N labels %d, label %d ; ", newCluster->GetNLabels(), newCluster->GetLabel() );
760 // UShort_t * newindex = newCluster->GetCellsAbsId() ;
761 // for(Int_t icell=0; icell < newCluster->GetNCells(); icell++ ){
762 // printf("\t absID %d\n",newindex[icell]);
763 // }
764 // }
1f77507b 765
6a8be5c3 766 // printf("Cluster %d, energy %f\n",newCluster->GetID(),newCluster->E());
767 // printf("labels: ");
768 // for(UInt_t ilab = 0; ilab < newCluster->GetNLabels(); ilab++)
769 // printf("Label[%d]: %d ",ilab, newCluster->GetLabelAt(ilab));
770 // printf("\n ");
6060ed91 771
0821ba9f 772 newCluster->SetID(i);
6fdd30c4 773 new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
774 }
775
1f77507b 776 //if(fOutputAODBranchName.Length()!=0)
777 fOutputAODBranch->Expand(kNumberOfCaloClusters); // resize TObjArray to 'remove' slots
778
6fdd30c4 779 //---CLEAN UP-----
780 fCaloClusterArr->Delete(); // Do not Clear(), it leaks, why?
3fa4fb85 781}
6fdd30c4 782
783//_____________________________________________________________________
bd9e8ebd 784Bool_t AliAnalysisTaskEMCALClusterize::AccessOCDB()
6fdd30c4 785{
786 //Access to OCDB stuff
e9dd2d80 787
6fdd30c4 788 AliVEvent * event = InputEvent();
bd9e8ebd 789 if (!event)
6fdd30c4 790 {
385b7abf 791 Warning("AccessOCDB","Event not available!!!");
bd9e8ebd 792 return kFALSE;
793 }
e9dd2d80 794
bd9e8ebd 795 if (event->GetRunNumber()==fRun)
796 return kTRUE;
797 fRun = event->GetRunNumber();
e9dd2d80 798
bd9e8ebd 799 if(DebugLevel() > 1 )
800 Info("AccessODCD()"," Begin");
385b7abf 801
e9dd2d80 802 //fGeom = AliEMCALGeometry::GetInstance(fGeomName);
385b7abf 803
bd9e8ebd 804 AliCDBManager *cdb = AliCDBManager::Instance();
e9dd2d80 805
806
385b7abf 807 if (fOCDBpath.Length()){
6fdd30c4 808 cdb->SetDefaultStorage(fOCDBpath.Data());
385b7abf 809 Info("AccessOCDB","Default storage %s",fOCDBpath.Data());
810 }
811
bd9e8ebd 812 cdb->SetRun(event->GetRunNumber());
e9dd2d80 813
bd9e8ebd 814 //
815 // EMCAL from RAW OCDB
816 if (fOCDBpath.Contains("alien:"))
817 {
818 cdb->SetSpecificStorage("EMCAL/Calib/Data","alien://Folder=/alice/data/2010/OCDB");
819 cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","alien://Folder=/alice/data/2010/OCDB");
820 }
e9dd2d80 821
bd9e8ebd 822 TString path = cdb->GetDefaultStorage()->GetBaseFolder();
385b7abf 823
bd9e8ebd 824 // init parameters:
385b7abf 825
bd9e8ebd 826 //Get calibration parameters
827 if(!fCalibData)
828 {
829 AliCDBEntry *entry = (AliCDBEntry*)
e9dd2d80 830 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
385b7abf 831
bd9e8ebd 832 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
6fdd30c4 833 }
bd9e8ebd 834
835 if(!fCalibData)
836 AliFatal("Calibration parameters not found in CDB!");
e9dd2d80 837
bd9e8ebd 838 //Get calibration parameters
839 if(!fPedestalData)
6fdd30c4 840 {
bd9e8ebd 841 AliCDBEntry *entry = (AliCDBEntry*)
e9dd2d80 842 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
385b7abf 843
bd9e8ebd 844 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
6fdd30c4 845 }
e9dd2d80 846
bd9e8ebd 847 if(!fPedestalData)
848 AliFatal("Dead map not found in CDB!");
385b7abf 849
6fdd30c4 850 return kTRUE;
6fdd30c4 851}
852
853//________________________________________________________________________________________
854void AliAnalysisTaskEMCALClusterize::InitClusterization()
855{
856 //Select clusterization/unfolding algorithm and set all the needed parameters
857
bd9e8ebd 858 if (fJustUnfold){
859 // init the unfolding afterburner
860 delete fUnfolder;
861 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
862 return;
6a8be5c3 863 }
864
bd9e8ebd 865 //First init the clusterizer
866 delete fClusterizer;
867 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
868 fClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData, fPedestalData);
cfcbe5d2 869 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
870 fClusterizer = new AliEMCALClusterizerv2(fGeom, fCalibData, fPedestalData);
212ac797 871 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN){
bd9e8ebd 872 fClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
212ac797 873 fClusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
874 fClusterizer->SetNColDiff(fRecParam->GetNColDiff());
d390e7cb 875 } else {
bd9e8ebd 876 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
877 }
6a8be5c3 878
bd9e8ebd 879 //Now set the parameters
880 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
881 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
882 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
883 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
884 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
885 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
886 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
887 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
888 fClusterizer->SetInputCalibrated ( kTRUE );
2af35150 889 fClusterizer->SetJustClusters ( kTRUE );
bd9e8ebd 890 //In case of unfolding after clusterization is requested, set the corresponding parameters
891 if(fRecParam->GetUnfold()){
892 Int_t i=0;
893 for (i = 0; i < 8; i++) {
894 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
895 }//end of loop over parameters
896 for (i = 0; i < 3; i++) {
897 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
898 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
899 }//end of loop over parameters
6fdd30c4 900
bd9e8ebd 901 fClusterizer->InitClusterUnfolding();
212ac797 902
bd9e8ebd 903 }// to unfold
6fdd30c4 904}
3fa4fb85 905
6fdd30c4 906//________________________________________________________________________________________
907void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters(TClonesArray *digitsArr, TObjArray *recPoints, TObjArray *clusArray)
908{
909 // Restore clusters from recPoints
910 // Cluster energy, global position, cells and their amplitude fractions are restored
6a8be5c3 911 Int_t j = 0;
6fdd30c4 912 for(Int_t i = 0; i < recPoints->GetEntriesFast(); i++)
913 {
914 AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) recPoints->At(i);
915
916 const Int_t ncells = recPoint->GetMultiplicity();
f6e45fe0 917 Int_t ncellsTrue = 0;
6fdd30c4 918
6a8be5c3 919 if(recPoint->GetEnergy() < fRecParam->GetClusteringThreshold()) continue;
920
6fdd30c4 921 // cells and their amplitude fractions
922 UShort_t absIds[ncells];
923 Double32_t ratios[ncells];
924
f6e45fe0 925 //For later check embedding
926 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
f053064e 927
928 Float_t clusterE = 0;
6fdd30c4 929 for (Int_t c = 0; c < ncells; c++) {
930 AliEMCALDigit *digit = (AliEMCALDigit*) digitsArr->At(recPoint->GetDigitsList()[c]);
931
f6e45fe0 932 absIds[ncellsTrue] = digit->GetId();
933 ratios[ncellsTrue] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
d390e7cb 934
935 // In case of unfolding, remove digits with unfolded energy too low
afaaef51 936 if(fSelectCell){
d390e7cb 937 if (recPoint->GetEnergiesList()[c] < fSelectCellMinE || ratios[ncellsTrue] < fSelectCellMinFrac) {
938
939 if(DebugLevel() > 1) {
940 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Too small energy in cell of cluster: cluster cell %f, digit %f\n",
941 recPoint->GetEnergiesList()[c],digit->GetAmplitude());
942 }
943
944 continue;
945
946 } // if cuts
947 }// Select cells
948
949 //Recalculate cluster energy and number of cluster cells in case any of the cells was rejected
950 ncellsTrue++;
951 clusterE +=recPoint->GetEnergiesList()[c];
f053064e 952
f6e45fe0 953 // In case of embedding, fill ratio with amount of signal,
f6e45fe0 954 if (aodIH && aodIH->GetMergeEvents()) {
955
956 //AliVCaloCells* inEMCALCells = InputEvent()->GetEMCALCells();
957 AliVCaloCells* meEMCALCells = aodIH->GetEventToMerge()->GetEMCALCells();
958 AliVCaloCells* ouEMCALCells = AODEvent()->GetEMCALCells();
959
960 Float_t sigAmplitude = meEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
961 //Float_t bkgAmplitude = inEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
962 Float_t sumAmplitude = ouEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
963 //printf("\t AbsID %d, amplitude : bkg %f, sigAmplitude %f, summed %f - %f\n",absIds[ncellsTrue], bkgAmplitude, sigAmplitude, sumAmplitude, digit->GetAmplitude());
964
965 if(sumAmplitude > 0) ratios[ncellsTrue] = sigAmplitude/sumAmplitude;
966 //printf("\t \t ratio %f\n",ratios[ncellsTrue]);
967
968 }//Embedding
969
f6e45fe0 970 }// cluster cell loop
6fdd30c4 971
f6e45fe0 972 if (ncellsTrue < 1) {
f053064e 973 if (DebugLevel() > 1)
974 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Skipping cluster with no cells avobe threshold E = %f, ncells %d\n",
975 recPoint->GetEnergy(), ncells);
976 continue;
977 }
978
979 //if(ncellsTrue != ncells) printf("Old E %f, ncells %d; New E %f, ncells %d\n",recPoint->GetEnergy(),ncells,clusterE,ncellsTrue);
980
981 if(clusterE < fRecParam->GetClusteringThreshold()) {
982 if (DebugLevel()>1)
983 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Remove cluster with energy below seed threshold %f\n",clusterE);
6fdd30c4 984 continue;
985 }
986
987 TVector3 gpos;
988 Float_t g[3];
989
990 // calculate new cluster position
991 recPoint->EvalGlobalPosition(fRecParam->GetW0(), digitsArr);
992 recPoint->GetGlobalPosition(gpos);
993 gpos.GetXYZ(g);
994
995 // create a new cluster
937b6c91 996 //AliAODCaloCluster *clus = new AliAODCaloCluster();
6a8be5c3 997 (*clusArray)[j] = new AliAODCaloCluster() ;
998 AliAODCaloCluster *clus = dynamic_cast<AliAODCaloCluster *>( clusArray->At(j) ) ;
999 j++;
6fdd30c4 1000 clus->SetType(AliVCluster::kEMCALClusterv1);
f053064e 1001 clus->SetE(clusterE);//recPoint->GetEnergy());
6fdd30c4 1002 clus->SetPosition(g);
f6e45fe0 1003 clus->SetNCells(ncellsTrue);
6fdd30c4 1004 clus->SetCellsAbsId(absIds);
1005 clus->SetCellsAmplitudeFraction(ratios);
6fdd30c4 1006 clus->SetChi2(-1); //not yet implemented
bd9e8ebd 1007 clus->SetTOF(recPoint->GetTime()) ; //time-of-flight
6fdd30c4 1008 clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
5994e71f 1009 clus->SetDistanceToBadChannel(recPoint->GetDistanceToBadTower());
f053064e 1010
1011 if(ncells == ncellsTrue){
1012 Float_t elipAxis[2];
1013 recPoint->GetElipsAxis(elipAxis);
1014 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
1015 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
1016 clus->SetDispersion(recPoint->GetDispersion());
1017 }
afaaef51 1018 else if(fSelectCell){
1019 // In case some cells rejected, in unfolding case, recalculate
1020 // shower shape parameters and position
f053064e 1021 AliVCaloCells* cells = 0x0;
1022 if (aodIH && aodIH->GetMergeEvents()) cells = AODEvent() ->GetEMCALCells();
1023 else cells = InputEvent()->GetEMCALCells();
1024 fRecoUtils->RecalculateClusterShowerShapeParameters(fGeom,cells,clus);
1025 fRecoUtils->RecalculateClusterPID(clus);
afaaef51 1026 fRecoUtils->RecalculateClusterPosition(fGeom,cells,clus);
f053064e 1027
1028// Float_t elipAxis[2];
1029// recPoint->GetElipsAxis(elipAxis);
1030// if(ncellsTrue > 2)
1031// printf("SS, old: l0 %f, l1 %f, D %f; New l0 %f, l1 %f, D %f\n",
1032// elipAxis[0]*elipAxis[0],elipAxis[1]*elipAxis[1], recPoint->GetDispersion(),
1033// clus->GetM02(),clus->GetM20(),clus->GetDispersion());
1034 }
6060ed91 1035
1036 //MC
1037 Int_t parentMult = 0;
1038 Int_t *parentList = recPoint->GetParents(parentMult);
1039 clus->SetLabel(parentList, parentMult);
1040
6a8be5c3 1041 // if(parentMult)printf("RecToESD: Labels %d",parentMult);
1042 // for (Int_t iii = 0; iii < parentMult; iii++) {
1043 // printf("\t label %d\n",parentList[iii]);
1044 // }
1045
37d2296c 1046 //Write the second major contributor to each MC cluster.
1047 Int_t iNewLabel ;
1048 for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ ){
1049
1050 Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
6ffa213f 1051 if(idCell>=0){
1052 iNewLabel = 1 ; //iNewLabel makes sure we don't write twice the same label.
1053 for ( UInt_t iLoopLabels = 0 ; iLoopLabels < clus->GetNLabels() ; iLoopLabels++ )
1054 {
1055 if ( fCellSecondLabels[idCell] == -1 ) iNewLabel = 0; // -1 is never a good second label.
1056 if ( fCellSecondLabels[idCell] == clus->GetLabelAt(iLoopLabels) ) iNewLabel = 0;
1057 }
1058 if (iNewLabel == 1)
1059 {
937b6c91 1060 //Int_t * newLabelArray = (Int_t*)malloc((clus->GetNLabels()+1)*sizeof(Int_t)) ;
1061 Int_t * newLabelArray = new Int_t[clus->GetNLabels()+1] ;
6ffa213f 1062 for ( UInt_t iLoopNewLabels = 0 ; iLoopNewLabels < clus->GetNLabels() ; iLoopNewLabels++ ){
1063 newLabelArray[iLoopNewLabels] = clus->GetLabelAt(iLoopNewLabels) ;
1064 }
6a8be5c3 1065
6ffa213f 1066 newLabelArray[clus->GetNLabels()] = fCellSecondLabels[idCell] ;
220447cd 1067 //if(fCellSecondLabels[idCell]>-1)printf("\t new label %d\n",fCellSecondLabels[idCell]);
6ffa213f 1068 clus->SetLabel(newLabelArray,clus->GetNLabels()+1) ;
abf0860a 1069 delete [] newLabelArray;
6ffa213f 1070 }
1071 }//positive cell number
37d2296c 1072 }
1073
6fdd30c4 1074 } // recPoints loop
6a8be5c3 1075
6fdd30c4 1076}