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