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