]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliAnalysisTaskEMCALClusterize.cxx
New splines for LHC11a pass4
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliAnalysisTaskEMCALClusterize.cxx
CommitLineData
eef481c6 1 /**************************************************************************
6fdd30c4 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 **************************************************************************/
6fdd30c4 15
16//_________________________________________________________________________
17// This analysis provides a new list of clusters to be used in other analysis
18//
19// Author: Gustavo Conesa Balbastre,
20// Adapted from analysis class from Deepa Thomas
21//
cd231d42 22// $Id$
6fdd30c4 23//_________________________________________________________________________
24
25// --- Root ---
04fcfa08 26#include <TString.h>
27#include <TRefArray.h>
28#include <TClonesArray.h>
29#include <TTree.h>
30#include <TGeoManager.h>
31#include <TROOT.h>
32#include <TInterpreter.h>
33#include <TFile.h>
6fdd30c4 34
35// --- AliRoot Analysis Steering
36#include "AliAnalysisTask.h"
37#include "AliAnalysisManager.h"
38#include "AliESDEvent.h"
39#include "AliGeomManager.h"
40#include "AliVCaloCells.h"
41#include "AliAODCaloCluster.h"
42#include "AliCDBManager.h"
43#include "AliCDBStorage.h"
44#include "AliCDBEntry.h"
45#include "AliLog.h"
46#include "AliVEventHandler.h"
6060ed91 47#include "AliAODInputHandler.h"
3769e0cb 48#include "AliOADBContainer.h"
6edb4448 49#include "AliAODMCParticle.h"
6fdd30c4 50
51// --- EMCAL
6fdd30c4 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"
61
62#include "AliAnalysisTaskEMCALClusterize.h"
63
64ClassImp(AliAnalysisTaskEMCALClusterize)
65
6544055e 66//______________________________________________________________________________
6fdd30c4 67AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize(const char *name)
6544055e 68: AliAnalysisTaskSE(name)
69, fEvent(0)
3769e0cb 70, fGeom(0), fGeomName("")
6544055e 71, fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
72, fCalibData(0), fPedestalData(0)
3769e0cb 73, fOCDBpath(""), fAccessOCDB(kFALSE)
6544055e 74, fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
75, fRecParam(0), fClusterizer(0)
76, fUnfolder(0), fJustUnfold(kFALSE)
6a797202 77, fOutputAODBranch(0), fOutputAODBranchName(""), fOutputAODBranchSet(0)
78, fFillAODFile(kFALSE), fFillAODHeader(0)
6544055e 79, fFillAODCaloCells(0), fRun(-1)
80, fRecoUtils(0), fConfigName("")
6edb4448 81, fOrgClusterCellId()
1e0ff9d3 82, fCellLabels(), fCellSecondLabels(), fCellTime()
adad4ea9 83, fCellMatchdEta(), fCellMatchdPhi()
1e0ff9d3 84, fRecalibrateWithClusterTime(0)
3769e0cb 85, fMaxEvent(0), fDoTrackMatching(kFALSE)
86, fSelectCell(kFALSE), fSelectCellMinE(0), fSelectCellMinFrac(0)
cb68426a 87, fRemoveLEDEvents(kTRUE),fRemoveExoticEvents(kFALSE)
3769e0cb 88, fImportGeometryFromFile(kFALSE), fImportGeometryFilePath("")
cb68426a 89, fOADBSet(kFALSE), fAccessOADB(kTRUE), fOADBFilePath("")
5aa88029 90, fCentralityClass(""), fSelectEMCALEvent(0)
91, fEMCALEnergyCut(0.), fEMCALNcellsCut (0)
6edb4448 92, fSetCellMCLabelFromCluster(0)
93, fRemapMCLabelForAODs(0)
6a8be5c3 94{
b43bdd14 95 // Constructor
96
e3990982 97 for(Int_t i = 0; i < 12; i++) fGeomMatrix[i] = 0;
6edb4448 98
99 ResetArrays();
a39f5b70 100
cb68426a 101 fCentralityBin[0] = fCentralityBin[1]=-1;
a39f5b70 102
6fdd30c4 103}
104
6544055e 105//______________________________________________________________
6fdd30c4 106AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize()
6544055e 107: AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
108, fEvent(0)
3769e0cb 109, fGeom(0), fGeomName("")
6544055e 110, fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
111, fCalibData(0), fPedestalData(0)
3769e0cb 112, fOCDBpath(""), fAccessOCDB(kFALSE)
6544055e 113, fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
114, fRecParam(0), fClusterizer(0)
115, fUnfolder(0), fJustUnfold(kFALSE)
6a797202 116, fOutputAODBranch(0), fOutputAODBranchName(""), fOutputAODBranchSet(0)
117, fFillAODFile(kFALSE), fFillAODHeader(0)
6544055e 118, fFillAODCaloCells(0), fRun(-1)
119, fRecoUtils(0), fConfigName("")
6edb4448 120, fOrgClusterCellId()
1e0ff9d3 121, fCellLabels(), fCellSecondLabels(), fCellTime()
adad4ea9 122, fCellMatchdEta(), fCellMatchdPhi()
1e0ff9d3 123, fRecalibrateWithClusterTime(0)
3769e0cb 124, fMaxEvent(0), fDoTrackMatching(kFALSE)
125, fSelectCell(kFALSE), fSelectCellMinE(0), fSelectCellMinFrac(0)
cb68426a 126, fRemoveLEDEvents(kTRUE), fRemoveExoticEvents(kFALSE)
9ac44255 127, fImportGeometryFromFile(kFALSE), fImportGeometryFilePath("")
cb68426a 128, fOADBSet(kFALSE), fAccessOADB(kTRUE), fOADBFilePath("")
6c79bfc8 129, fCentralityClass(""), fSelectEMCALEvent(0)
130, fEMCALEnergyCut(0.), fEMCALNcellsCut (0)
6edb4448 131, fSetCellMCLabelFromCluster(0)
132, fRemapMCLabelForAODs(0)
6fdd30c4 133{
134 // Constructor
b43bdd14 135
e3990982 136 for(Int_t i = 0; i < 12; i++) fGeomMatrix[i] = 0;
6edb4448 137
138 ResetArrays();
139
3af5a372 140 fCentralityBin[0] = fCentralityBin[1]=-1;
141
6fdd30c4 142}
143
5994e71f 144
6544055e 145//_______________________________________________________________
6fdd30c4 146AliAnalysisTaskEMCALClusterize::~AliAnalysisTaskEMCALClusterize()
147{
148 //dtor
149
b43bdd14 150 if (fDigitsArr)
151 {
6fdd30c4 152 fDigitsArr->Clear("C");
542e1379 153 delete fDigitsArr;
6fdd30c4 154 }
155
b43bdd14 156 if (fClusterArr)
157 {
6fdd30c4 158 fClusterArr->Delete();
542e1379 159 delete fClusterArr;
6fdd30c4 160 }
161
b43bdd14 162 if (fCaloClusterArr)
163 {
6fdd30c4 164 fCaloClusterArr->Delete();
1e0ff9d3 165 delete fCaloClusterArr;
6fdd30c4 166 }
6a8be5c3 167
385b7abf 168 if(fClusterizer) delete fClusterizer;
169 if(fUnfolder) delete fUnfolder;
170 if(fRecoUtils) delete fRecoUtils;
6a8be5c3 171
6fdd30c4 172}
173
5aa88029 174//_______________________________________________________
175Bool_t AliAnalysisTaskEMCALClusterize::AcceptEventEMCAL()
176{
177 // Accept event given there is a EMCAL cluster with enough energy, and not noisy, exotic
178
179 if(!fSelectEMCALEvent) return kTRUE; // accept
180
181 if(fEMCALEnergyCut <= 0) return kTRUE; // accept
182
183 Int_t nCluster = InputEvent() -> GetNumberOfCaloClusters();
184 AliVCaloCells * caloCell = InputEvent() -> GetEMCALCells();
185 Int_t bc = InputEvent() -> GetBunchCrossNumber();
186
187 for(Int_t icalo = 0; icalo < nCluster; icalo++)
188 {
189 AliVCluster *clus = (AliVCluster*) (InputEvent()->GetCaloCluster(icalo));
190
191 if( ( clus->IsEMCAL() ) && ( clus->GetNCells() > fEMCALNcellsCut ) && ( clus->E() > fEMCALEnergyCut ) &&
192 fRecoUtils->IsGoodCluster(clus,fGeom,caloCell,bc))
193 {
194
195 if (fDebug > 0)
196 printf("AliAnalysisTaskEMCALClusterize::AcceptEventEMCAL() - Accept : E %2.2f > %2.2f, nCells %d > %d \n",
197 clus->E(), fEMCALEnergyCut, clus->GetNCells(), fEMCALNcellsCut);
198
199 return kTRUE;
200 }
201
202 }// loop
203
204 if (fDebug > 0)
205 printf("AliAnalysisTaskEMCALClusterize::AcceptEventEMCAL() - Reject \n");
206
207 return kFALSE;
208
209}
210
3769e0cb 211//_______________________________________________
212void AliAnalysisTaskEMCALClusterize::AccessOADB()
213{
214 // Set the AODB calibration, bad channels etc. parameters at least once
215 // alignment matrices from OADB done in SetGeometryMatrices
216
217 //Set it only once
218 if(fOADBSet) return ;
219
220 Int_t runnumber = InputEvent()->GetRunNumber() ;
221 TString pass = GetPass();
222
223 printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Get AODB parameters from EMCAL in %s for run %d, and <%s> \n",fOADBFilePath.Data(),runnumber,pass.Data());
224
225 Int_t nSM = fGeom->GetNumberOfSuperModules();
226
227 // Bad map
228 if(fRecoUtils->IsBadChannelsRemovalSwitchedOn())
229 {
230 AliOADBContainer *contBC=new AliOADBContainer("");
231 contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fOADBFilePath.Data()),"AliEMCALBadChannels");
232
233 TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runnumber);
234
235 if(arrayBC)
236 {
3769e0cb 237 fRecoUtils->SwitchOnDistToBadChannelRecalculation();
238 printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Remove EMCAL bad cells \n");
239
240 for (Int_t i=0; i<nSM; ++i)
241 {
242 TH2I *hbm = fRecoUtils->GetEMCALChannelStatusMap(i);
243
244 if (hbm)
245 delete hbm;
246
17e1c80e 247 hbm=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
3769e0cb 248
249 if (!hbm)
250 {
251 AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
252 continue;
253 }
254
255 hbm->SetDirectory(0);
256 fRecoUtils->SetEMCALChannelStatusMap(i,hbm);
257
258 } // loop
17e1c80e 259 } else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT remove EMCAL bad channels\n"); // run array
3769e0cb 260 } // Remove bad
261
262 // Energy Recalibration
263 if(fRecoUtils->IsRecalibrationOn())
264 {
265 AliOADBContainer *contRF=new AliOADBContainer("");
266
267 contRF->InitFromFile(Form("%s/EMCALRecalib.root",fOADBFilePath.Data()),"AliEMCALRecalib");
268
269 TObjArray *recal=(TObjArray*)contRF->GetObject(runnumber);
270
271 if(recal)
272 {
273 TObjArray *recalpass=(TObjArray*)recal->FindObject(pass);
274
275 if(recalpass)
276 {
277 TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
278
279 if(recalib)
280 {
281 printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Recalibrate EMCAL \n");
282 for (Int_t i=0; i<nSM; ++i)
283 {
284 TH2F *h = fRecoUtils->GetEMCALChannelRecalibrationFactors(i);
285
286 if (h)
287 delete h;
288
289 h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
290
291 if (!h)
292 {
293 AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
294 continue;
295 }
296
297 h->SetDirectory(0);
298
299 fRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
300 } // SM loop
17e1c80e 301 }else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT recalibrate EMCAL, no params object array \n"); // array ok
302 }else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT recalibrate EMCAL, no params for pass\n"); // array pass ok
303 }else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT recalibrate EMCAL, no params for run\n"); // run number array ok
7bf608c9 304
3769e0cb 305 } // Recalibration on
306
7bf608c9 307 // Energy Recalibration, apply on top of previous calibration factors
308 if(fRecoUtils->IsRunDepRecalibrationOn())
309 {
310 AliOADBContainer *contRFTD=new AliOADBContainer("");
311
312 contRFTD->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fOADBFilePath.Data()),"AliEMCALRunDepTempCalibCorrections");
313
314 TH1S *htd=(TH1S*)contRFTD->GetObject(runnumber);
315
74d2310f 316 //If it did not exist for this run, get closes one
317 if (!htd)
318 {
319 AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runnumber));
320 // let's get the closest runnumber instead then..
321 Int_t lower = 0;
322 Int_t ic = 0;
323 Int_t maxEntry = contRFTD->GetNumberOfEntries();
324
325 while ( (ic < maxEntry) && (contRFTD->UpperLimit(ic) < runnumber) ) {
326 lower = ic;
327 ic++;
328 }
329
330 Int_t closest = lower;
331 if ( (ic<maxEntry) &&
332 (contRFTD->LowerLimit(ic)-runnumber) < (runnumber - contRFTD->UpperLimit(lower)) ) {
333 closest = ic;
334 }
335
336 AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRFTD->LowerLimit(closest)));
337 htd = (TH1S*) contRFTD->GetObjectByIndex(closest);
338 }
339
7bf608c9 340 if(htd)
341 {
342 printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Recalibrate (Temperature) EMCAL \n");
343
344 for (Int_t ism=0; ism<nSM; ++ism)
345 {
346 for (Int_t icol=0; icol<48; ++icol)
347 {
348 for (Int_t irow=0; irow<24; ++irow)
349 {
350 Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
351
352 Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
353 factor *= htd->GetBinContent(absID) / 10000. ; // correction dependent on T
354 //printf("\t ism %d, icol %d, irow %d,absID %d, corrA %2.3f, corrB %2.3f, corrAB %2.3f\n",ism, icol, irow, absID,
355 // GetEMCALChannelRecalibrationFactor(ism,icol,irow) , htd->GetBinContent(absID) / 10000., factor);
356 fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
357 } // columns
358 } // rows
359 } // SM loop
360 }else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT recalibrate EMCAL with T variations, no params TH1 \n");
361 } // Run by Run T calibration
3769e0cb 362
363 // Time Recalibration
364 if(fRecoUtils->IsTimeRecalibrationOn())
365 {
366 AliOADBContainer *contTRF=new AliOADBContainer("");
367
f46af216 368 contTRF->InitFromFile(Form("%s/EMCALTimeCalib.root",fOADBFilePath.Data()),"AliEMCALTimeCalib");
3769e0cb 369
370 TObjArray *trecal=(TObjArray*)contTRF->GetObject(runnumber);
371
372 if(trecal)
373 {
61841488 374 TString passTmp = pass;
7764134d 375 if(pass!="pass1" && pass!="pass2") passTmp = "pass2"; // TEMPORARY FIX FOR LHC11a analysis
61841488 376 TObjArray *trecalpass=(TObjArray*)trecal->FindObject(passTmp);
377
3769e0cb 378 if(trecalpass)
379 {
b43bdd14 380 printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Time Recalibrate EMCAL \n");
f46af216 381 for (Int_t ibc = 0; ibc < 4; ++ibc)
3769e0cb 382 {
f46af216 383 TH1F *h = fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(ibc);
384
385 if (h)
386 delete h;
387
388 h = (TH1F*)trecalpass->FindObject(Form("hAllTimeAvBC%d",ibc));
389
390 if (!h)
3769e0cb 391 {
f46af216 392 AliError(Form("Could not load hAllTimeAvBC%d",ibc));
393 continue;
394 }
395
396 h->SetDirectory(0);
397
398 fRecoUtils->SetEMCALChannelTimeRecalibrationFactors(ibc,h);
399 } // bunch crossing loop
17e1c80e 400 }else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT recalibrate time EMCAL, no params for pass\n"); // array pass ok
401 }else printf("AliAnalysisTaskEMCALClusterize::SetOADBParameters() - Do NOT recalibrate time EMCAL, no params for run\n"); // run number array ok
3769e0cb 402
403 } // Time recalibration on
404
405 // Parameters already set once, so do not it again
406 fOADBSet = kTRUE;
407
408}
409
6544055e 410//_________________________________________________
411Bool_t AliAnalysisTaskEMCALClusterize::AccessOCDB()
412{
413 //Access to OCDB stuff
1f77507b 414
6544055e 415 fEvent = InputEvent();
416 if (!fEvent)
417 {
418 Warning("AccessOCDB","Event not available!!!");
419 return kFALSE;
1f77507b 420 }
1f77507b 421
6544055e 422 if (fEvent->GetRunNumber()==fRun)
423 return kTRUE;
424 fRun = fEvent->GetRunNumber();
1f77507b 425
6544055e 426 if(DebugLevel() > 1 )
596697e6 427 printf("AliAnalysisTaksEMCALClusterize::AccessOCDB() - Begin");
b43bdd14 428
6544055e 429 AliCDBManager *cdb = AliCDBManager::Instance();
1f77507b 430
1f77507b 431
b43bdd14 432 if (fOCDBpath.Length())
433 {
6544055e 434 cdb->SetDefaultStorage(fOCDBpath.Data());
435 printf("AliAnalysisTaksEMCALClusterize::AccessOCDB() - Default storage %s",fOCDBpath.Data());
436 }
437
438 cdb->SetRun(fEvent->GetRunNumber());
1f77507b 439
440 //
6544055e 441 // EMCAL from RAW OCDB
442 if (fOCDBpath.Contains("alien:"))
443 {
444 cdb->SetSpecificStorage("EMCAL/Calib/Data","alien://Folder=/alice/data/2010/OCDB");
445 cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","alien://Folder=/alice/data/2010/OCDB");
446 }
1f77507b 447
6544055e 448 TString path = cdb->GetDefaultStorage()->GetBaseFolder();
1f77507b 449
6544055e 450 // init parameters:
1f77507b 451
6544055e 452 //Get calibration parameters
453 if(!fCalibData)
454 {
455 AliCDBEntry *entry = (AliCDBEntry*)
456 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
457
458 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
1f77507b 459 }
6544055e 460
461 if(!fCalibData)
462 AliFatal("Calibration parameters not found in CDB!");
463
464 //Get calibration parameters
465 if(!fPedestalData)
466 {
467 AliCDBEntry *entry = (AliCDBEntry*)
468 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
469
470 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
1f77507b 471 }
472
6544055e 473 if(!fPedestalData)
474 AliFatal("Dead map not found in CDB!");
1f77507b 475
6544055e 476 return kTRUE;
6fdd30c4 477}
478
9ac44255 479//_____________________________________________________
6544055e 480void AliAnalysisTaskEMCALClusterize::CheckAndGetEvent()
6fdd30c4 481{
6544055e 482 // Get the input event, it can depend in embedded events what you want to get
483 // Also check if the quality of the event is good if not reject it
484
485 fEvent = 0x0;
6a8be5c3 486
5aa88029 487 //Process events if there is a high energy cluster
488 if(!AcceptEventEMCAL()) return ;
489
220447cd 490 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
491 Int_t eventN = Entry();
492 if(aodIH) eventN = aodIH->GetReadEntry();
493
6544055e 494 if (eventN > fMaxEvent)
495 return ;
f5036bcb 496
c50e6949 497 //printf("Clusterizer --- Event %d-- \n",eventN);
b43bdd14 498
6060ed91 499 //Check if input event are embedded events
500 //If so, take output event
3769e0cb 501 if (aodIH && aodIH->GetMergeEvents())
502 {
6544055e 503 fEvent = AODEvent();
1f77507b 504
505 if(!aodIH->GetMergeEMCALCells())
506 AliFatal("Events merged but not EMCAL cells, check analysis settings!");
507
3769e0cb 508 if(DebugLevel() > 1)
509 {
510 printf("AliAnalysisTaksEMCALClusterize::UserExec() - Use embedded events\n");
511
512 printf("\t InputEvent N Clusters %d, N Cells %d\n",InputEvent()->GetNumberOfCaloClusters(),
513 InputEvent()->GetEMCALCells()->GetNumberOfCells());
514
515 printf("\t MergedEvent N Clusters %d, N Cells %d\n",aodIH->GetEventToMerge()->GetNumberOfCaloClusters(),
516 aodIH->GetEventToMerge()->GetEMCALCells()->GetNumberOfCells());
517
518 for (Int_t icl=0; icl < aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); icl++)
519 {
520 AliAODCaloCluster *sigCluster = aodIH->GetEventToMerge()->GetCaloCluster(icl);
521 if(sigCluster->IsEMCAL()) printf("\t \t Signal cluster: i %d, E %f\n",icl,sigCluster->E());
522 }
523
524 printf("\t OutputEvent N Clusters %d, N Cells %d\n", AODEvent()->GetNumberOfCaloClusters(),
525 AODEvent()->GetEMCALCells()->GetNumberOfCells());
6544055e 526 }
6060ed91 527 }
3769e0cb 528 else
529 {
6544055e 530 fEvent = InputEvent();
1f77507b 531 if(fFillAODCaloCells) FillAODCaloCells();
532 if(fFillAODHeader) FillAODHeader();
6060ed91 533 }
534
3769e0cb 535 if (!fEvent)
536 {
3fa4fb85 537 Error("UserExec","Event not available");
6544055e 538 return ;
6fdd30c4 539 }
6a8be5c3 540
cd2e4ce6 541 //-------------------------------------------------------------------------------------
6544055e 542 // Reject events if LED was firing, use only for LHC11a data
543 // Reject event if triggered by exotic cell and remove exotic cells if not triggered
cd2e4ce6 544 //-------------------------------------------------------------------------------------
6544055e 545
3769e0cb 546 if( IsLEDEvent( InputEvent()->GetRunNumber() ) ) { fEvent = 0x0 ; return ; }
6544055e 547
3769e0cb 548 if( IsExoticEvent() ) { fEvent = 0x0 ; return ; }
cd2e4ce6 549
6a797202 550 //-------------------------------------------------------------------------------------
551 // Set the cluster array in the event (output or input)
552 //-------------------------------------------------------------------------------------
553
554 if ( fFillAODFile )
555 {
556 //Magic line to write events to AOD filem put after event rejection
557 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
558 }
559 else if( !fOutputAODBranchSet )
560 {
561 // Create array and put it in the input event, if output AOD not selected, only once
562 InputEvent()->AddObject(fOutputAODBranch);
563 fOutputAODBranchSet = kTRUE;
564 printf("AliAnalysisTaskEMCALClusterize::UserExec() - Add AOD branch <%s> to input event\n",fOutputAODBranchName.Data());
565 }
6544055e 566
567}
568
569//____________________________________________________
570void AliAnalysisTaskEMCALClusterize::ClusterizeCells()
571{
572 // Recluster calocells, transform them into digits,
573 // feed the clusterizer with them and get new list of clusters
574
575 //In case of MC, first loop on the clusters and fill MC label to array
576 Int_t nClusters = fEvent->GetNumberOfCaloClusters();
577 Int_t nClustersOrg = 0;
b43bdd14 578
6544055e 579 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
580 if(aodIH && aodIH->GetEventToMerge()) //Embedding
581 nClusters = aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); //Get clusters directly from embedded signal
6edb4448 582
583 ResetArrays();
584
6544055e 585 for (Int_t i = 0; i < nClusters; i++)
586 {
587 AliVCluster *clus = 0;
588 if(aodIH && aodIH->GetEventToMerge()) //Embedding
589 clus = aodIH->GetEventToMerge()->GetCaloCluster(i); //Get clusters directly from embedded signal
590 else
591 clus = fEvent->GetCaloCluster(i);
5994e71f 592
6544055e 593 if(!clus) return;
6a8be5c3 594
f46af216 595 if(clus->IsEMCAL())
6edb4448 596 {
6544055e 597 Int_t label = clus->GetLabel();
598 Int_t label2 = -1 ;
6edb4448 599 //printf("Org cluster E %f, Time %e, Index = %d, ID %d, MC label %d\n", clus->E(), clus->GetTOF(),i, clus->GetID(),label );
e59a6a2e 600 //printf("Original list of labels from old cluster : \n");
6edb4448 601 //for(Int_t imc = 0; imc < clus->GetNLabels(); imc++) printf("\t Label %d\n",clus->GetLabelAt(imc));
e59a6a2e 602
6544055e 603 if (clus->GetNLabels()>=2) label2 = clus->GetLabelAt(1) ;
604 UShort_t * index = clus->GetCellsAbsId() ;
f46af216 605 for(Int_t icell=0; icell < clus->GetNCells(); icell++ )
606 {
6edb4448 607 //printf("\t cell %d, MC label %d\n",index[icell],fEvent->GetEMCALCells()->GetCellMCLabel(index[icell]));
608 fOrgClusterCellId[index[icell]] = i;
6544055e 609 fCellLabels[index[icell]] = label;
610 fCellSecondLabels[index[icell]] = label2;
6edb4448 611 fCellTime[index[icell]] = clus->GetTOF();
73a4ed8f 612 fCellMatchdEta[index[icell]] = clus->GetTrackDz();
613 fCellMatchdPhi[index[icell]] = clus->GetTrackDx();
6fdd30c4 614 }
6544055e 615 nClustersOrg++;
6fdd30c4 616 }
b43bdd14 617 // printf("\n");
6544055e 618 }
619
620 // Transform CaloCells into Digits
b43bdd14 621
6544055e 622 Int_t idigit = 0;
623 Int_t id = -1;
624 Float_t amp = -1;
625 Double_t time = -1;
626
6edb4448 627 AliVCaloCells *cells = fEvent->GetEMCALCells();
b43bdd14 628
a7e5a381 629 Int_t bc = InputEvent()->GetBunchCrossNumber();
11e7733f 630
6544055e 631 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
632 {
6544055e 633 // Get cell values, recalibrate and not include bad channels found in analysis, nor cells with too low energy, nor exotic cell
634 id = cells->GetCellNumber(icell);
a7e5a381 635 Bool_t accept = fRecoUtils->AcceptCalibrateCell(id,bc,amp,time,cells);
636
1e0ff9d3 637 // Do not include cells with too low energy, nor exotic cell
d95102d2 638 if( amp < fRecParam->GetMinECut() ||
639 time > fRecParam->GetTimeMax() ||
640 time < fRecParam->GetTimeMin() ) accept = kFALSE;
1e0ff9d3 641
642 // In case of old AOD analysis cell time is -1 s, approximate replacing by time of the cluster the digit belongs.
643 if (fRecalibrateWithClusterTime)
644 {
645 time = fCellTime[id];
646 //printf("cell %d time org %f - ",id, time*1.e9);
647 fRecoUtils->RecalibrateCellTime(id,bc,time);
648 //printf("recal %f\n",time*1.e9);
649 }
a7e5a381 650
d95102d2 651 //Exotic?
652 if (accept && fRecoUtils->IsExoticCell(id,cells,bc))
653 accept = kFALSE;
b43bdd14 654
f46af216 655 if( !accept )
656 {
f46af216 657 if( DebugLevel() > 2 )
658 printf("AliAnalysisTaksEMCALClusterize::ClusterizeCells() - Remove channel absId %d, index %d of %d, amp %f, time %f\n",
b43bdd14 659 id,icell, cells->GetNumberOfCells(), amp, time*1.e9);
6544055e 660 continue;
661 }
b43bdd14 662
bdd50327 663 Int_t mcLabel = cells->GetMCLabel(icell);
e59a6a2e 664 //printf("AliAnalysisTaksEMCALClusterize::ClusterizeCells() - cell %d, mc label %d\n",id,mcLabel);
6edb4448 665
bdd50327 666 //if(fCellLabels[id]!=mcLabel)printf("mcLabel %d - %d\n",mcLabel,fCellLabels[id]);
6edb4448 667 if ( fSetCellMCLabelFromCluster == 1 ) mcLabel = fCellLabels[id]; // Older aliroot MC productions
668 else if( fSetCellMCLabelFromCluster == 0 && fRemapMCLabelForAODs) RemapMCLabelForAODs(mcLabel);
e59a6a2e 669 else mcLabel = -1; // found later
670
671 //printf("\t new label %d\n",mcLabel);
bdd50327 672
673 // Create the digit, put a fake primary deposited energy to trick the clusterizer
674 // when checking the most likely primary
11e7733f 675
676 Float_t efrac = cells->GetEFraction(icell);
677
678 //When checking the MC of digits, give weight to cells with embedded signal
679 if (mcLabel > 0 && efrac < 1.e-6) efrac = 1;
680
681 //printf("******* Cell %d, id %d, e %f, fraction %f, MC label %d, used MC label %d\n",icell,id,amp,cells->GetEFraction(icell),cells->GetMCLabel(icell),mcLabel);
682
683 new((*fDigitsArr)[idigit]) AliEMCALDigit( mcLabel, mcLabel, id, amp, time,AliEMCALDigit::kHG,idigit, 0, 0, amp*efrac);
e59a6a2e 684 // Last parameter should be MC deposited energy, since it is not available, add just the cell amplitude so that
685 // we give more weight to the MC label of the cell with highest energy in the cluster
6edb4448 686
6544055e 687 idigit++;
688 }
6a8be5c3 689
04fcfa08 690 fDigitsArr->Sort();
b43bdd14 691
6544055e 692 //-------------------------------------------------------------------------------------
693 //Do the clusterization
694 //-------------------------------------------------------------------------------------
b43bdd14 695
6544055e 696 fClusterizer->Digits2Clusters("");
697
698 //-------------------------------------------------------------------------------------
699 //Transform the recpoints into AliVClusters
700 //-------------------------------------------------------------------------------------
701
b43bdd14 702 RecPoints2Clusters();
6544055e 703
3769e0cb 704 if(!fCaloClusterArr)
705 {
6544055e 706 printf("AliAnalysisTaksEMCALClusterize::UserExec() - No array with CaloClusters, input RecPoints entries %d\n",fClusterArr->GetEntriesFast());
707 return;
708 }
709
3769e0cb 710 if( DebugLevel() > 0 )
711 {
6544055e 712 printf("AliAnalysisTaksEMCALClusterize::ClusterizeCells() - N clusters: before recluster %d, after recluster %d\n",nClustersOrg, fCaloClusterArr->GetEntriesFast());
b43bdd14 713
714 if(fCaloClusterArr->GetEntriesFast() != fClusterArr->GetEntriesFast())
715 {
6544055e 716 printf("\t Some RecRoints not transformed into CaloClusters (clusterizer %d, unfold %d): Input entries %d - Output entries %d - %d (not fast)\n",
717 fRecParam->GetClusterizerFlag(),fRecParam->GetUnfold(),
718 fClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntries());
719 }
720 }
6544055e 721}
a39f5b70 722
73a4ed8f 723//_____________________________________________________
6544055e 724void AliAnalysisTaskEMCALClusterize::ClusterUnfolding()
725{
726 // Take the event clusters and unfold them
727
728 AliVCaloCells *cells = fEvent->GetEMCALCells();
729 Double_t cellAmplitude = 0;
730 Double_t cellTime = 0;
731 Short_t cellNumber = 0;
48d9e9e7 732 Int_t cellMCLabel = 0;
77e93dc2 733 Double_t cellEFrac = 0;
6544055e 734 Int_t nClustersOrg = 0;
735
736 // Fill the array with the EMCAL clusters, copy them
737 for (Int_t i = 0; i < fEvent->GetNumberOfCaloClusters(); i++)
738 {
739 AliVCluster *clus = fEvent->GetCaloCluster(i);
b43bdd14 740 if(clus->IsEMCAL())
741 {
6544055e 742 //recalibrate/remove bad channels/etc if requested
b43bdd14 743 if(fRecoUtils->ClusterContainsBadChannel(fGeom,clus->GetCellsAbsId(), clus->GetNCells()))
744 {
5994e71f 745 continue;
6544055e 746 }
3bfc4732 747
b43bdd14 748 if(fRecoUtils->IsRecalibrationOn())
749 {
6544055e 750 //Calibrate cluster
751 fRecoUtils->RecalibrateClusterEnergy(fGeom, clus, cells);
752
753 //CalibrateCells
754 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
755 {
77e93dc2 756 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime, cellMCLabel, cellEFrac) != kTRUE)
6544055e 757 break;
758
759 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
760 fGeom->GetCellIndex(cellNumber,imod,iTower,iIphi,iIeta);
761 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
762
763 //Do not include bad channels found in analysis?
764 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
6edb4448 765 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
6544055e 766 continue;
6544055e 767
768 cells->SetCell(icell, cellNumber, cellAmplitude*fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),cellTime);
769
770 }// cells loop
771 }// recalibrate
5994e71f 772
6544055e 773 //Cast to ESD or AOD, needed to create the cluster array
774 AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
775 AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
b43bdd14 776
777 if (esdCluster)
778 {
6544055e 779 fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
780 }//ESD
b43bdd14 781 else if(aodCluster)
782 {
6544055e 783 fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
784 }//AOD
785 else
786 Warning("UserExec()"," - Wrong CaloCluster type?");
b43bdd14 787
6544055e 788 nClustersOrg++;
6a8be5c3 789 }
6fdd30c4 790 }
791
6544055e 792 //Do the unfolding
793 fUnfolder->UnfoldClusters(fCaloClusterArr, cells);
6a8be5c3 794
6544055e 795 //CLEAN-UP
796 fUnfolder->Clear();
385b7abf 797
6544055e 798}
799
800//_____________________________________________________
801void AliAnalysisTaskEMCALClusterize::FillAODCaloCells()
802{
803 // Put calo cells in standard branch
804 AliVCaloCells &eventEMcells = *(fEvent->GetEMCALCells());
805 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
6fdd30c4 806
6544055e 807 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
808 aodEMcells.CreateContainer(nEMcell);
809 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
810 Double_t calibFactor = 1.;
b43bdd14 811 for (Int_t iCell = 0; iCell < nEMcell; iCell++)
812 {
6544055e 813 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
814 fGeom->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
815 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
385b7abf 816
b43bdd14 817 if(fRecoUtils->IsRecalibrationOn())
818 {
6544055e 819 calibFactor = fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
385b7abf 820 }
0821ba9f 821
b43bdd14 822 if(!fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
823 { //Channel is not declared as bad
77e93dc2 824 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor,
825 eventEMcells.GetTime(iCell),eventEMcells.GetMCLabel(iCell),eventEMcells.GetEFraction(iCell));
6544055e 826 }
b43bdd14 827 else
828 {
77e93dc2 829 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0,-1,-1,0);
5994e71f 830 }
6fdd30c4 831 }
6544055e 832 aodEMcells.Sort();
6fdd30c4 833
6544055e 834}
6fdd30c4 835
6544055e 836//__________________________________________________
837void AliAnalysisTaskEMCALClusterize::FillAODHeader()
6fdd30c4 838{
6544055e 839 //Put event header information in standard AOD branch
e9dd2d80 840
6544055e 841 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (fEvent);
842 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (fEvent);
e9dd2d80 843
6544055e 844 Double_t pos[3] ;
845 Double_t covVtx[6];
846 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
847
848 AliAODHeader* header = AODEvent()->GetHeader();
849 header->SetRunNumber(fEvent->GetRunNumber());
850
b43bdd14 851 if(esdevent)
852 {
6544055e 853 TTree* tree = fInputHandler->GetTree();
b43bdd14 854 if (tree)
855 {
6544055e 856 TFile* file = tree->GetCurrentFile();
857 if (file) header->SetESDFileName(file->GetName());
858 }
859 }
860 else if (aodevent) header->SetESDFileName(aodevent->GetHeader()->GetESDFileName());
e9dd2d80 861
6544055e 862 header->SetBunchCrossNumber(fEvent->GetBunchCrossNumber());
863 header->SetOrbitNumber(fEvent->GetOrbitNumber());
864 header->SetPeriodNumber(fEvent->GetPeriodNumber());
865 header->SetEventType(fEvent->GetEventType());
385b7abf 866
6544055e 867 //Centrality
b43bdd14 868 if(fEvent->GetCentrality())
6544055e 869 header->SetCentrality(new AliCentrality(*(fEvent->GetCentrality())));
b43bdd14 870 else
6544055e 871 header->SetCentrality(0);
385b7abf 872
6544055e 873 //Trigger
874 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
875 if (esdevent) header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
876 else if (aodevent) header->SetFiredTriggerClasses(aodevent->GetFiredTriggerClasses());
b43bdd14 877
6544055e 878 header->SetTriggerMask(fEvent->GetTriggerMask());
879 header->SetTriggerCluster(fEvent->GetTriggerCluster());
b43bdd14 880
881 if (esdevent)
882 {
6544055e 883 header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());
884 header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());
885 header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());
886 }
b43bdd14 887 else if (aodevent)
888 {
6544055e 889 header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());
890 header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());
891 header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());
892 }
e9dd2d80 893
6544055e 894 header->SetMagneticField(fEvent->GetMagneticField());
895 //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.);
e9dd2d80 896
6544055e 897 header->SetZDCN1Energy(fEvent->GetZDCN1Energy());
898 header->SetZDCP1Energy(fEvent->GetZDCP1Energy());
899 header->SetZDCN2Energy(fEvent->GetZDCN2Energy());
900 header->SetZDCP2Energy(fEvent->GetZDCP2Energy());
901 header->SetZDCEMEnergy(fEvent->GetZDCEMEnergy(0),fEvent->GetZDCEMEnergy(1));
385b7abf 902
6544055e 903 Float_t diamxy[2]={fEvent->GetDiamondX(),fEvent->GetDiamondY()};
904 Float_t diamcov[3];
905 fEvent->GetDiamondCovXY(diamcov);
906 header->SetDiamond(diamxy,diamcov);
907 if (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
908 else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
e9dd2d80 909
6544055e 910 //
911 Int_t nVertices = 1 ;/* = prim. vtx*/;
912 Int_t nCaloClus = fEvent->GetNumberOfCaloClusters();
e9dd2d80 913
6544055e 914 AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
385b7abf 915
6544055e 916 // Access to the AOD container of vertices
917 TClonesArray &vertices = *(AODEvent()->GetVertices());
918 Int_t jVertices=0;
385b7abf 919
6544055e 920 // Add primary vertex. The primary tracks will be defined
921 // after the loops on the composite objects (V0, cascades, kinks)
922 fEvent->GetPrimaryVertex()->GetXYZ(pos);
923 Float_t chi = 0;
b43bdd14 924 if (esdevent)
925 {
6544055e 926 esdevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
927 chi = esdevent->GetPrimaryVertex()->GetChi2toNDF();
928 }
b43bdd14 929 else if (aodevent)
930 {
6544055e 931 aodevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
932 chi = aodevent->GetPrimaryVertex()->GetChi2perNDF();//Different from ESD?
6fdd30c4 933 }
bd9e8ebd 934
6544055e 935 AliAODVertex * primary = new(vertices[jVertices++])
936 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
937 primary->SetName(fEvent->GetPrimaryVertex()->GetName());
938 primary->SetTitle(fEvent->GetPrimaryVertex()->GetTitle());
e9dd2d80 939
6544055e 940}
941
afc22931 942//___________________________________________________________
943void AliAnalysisTaskEMCALClusterize::FillCaloClusterInEvent()
b43bdd14 944{
945 // Get the CaloClusters array, do some final calculations
afc22931 946 // and put the clusters in the output or input event
947 // as a separate branch
b43bdd14 948
949 //First recalculate track-matching for the new clusters
950 if(fDoTrackMatching)
951 {
952 fRecoUtils->FindMatches(fEvent,fCaloClusterArr,fGeom);
953 }
954 //Put the new clusters in the AOD list
955
956 Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntriesFast();
596697e6 957
b43bdd14 958 for(Int_t i = 0; i < kNumberOfCaloClusters; i++)
959 {
960 AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
961
962 newCluster->SetID(i);
963
afc22931 964 // Correct cluster energy non linearity
965 newCluster->SetE(fRecoUtils->CorrectClusterEnergyLinearity(newCluster));
966
b43bdd14 967 //Add matched track
968 if(fDoTrackMatching)
969 {
970 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
971 if(trackIndex >= 0)
972 {
973 newCluster->AddTrackMatched(fEvent->GetTrack(trackIndex));
974 if(DebugLevel() > 1)
975 printf("AliAnalysisTaksEMCALClusterize::UserExec() - Matched Track index %d to new cluster %d \n",trackIndex,i);
976 }
977
978 Float_t dR = 999., dZ = 999.;
979 fRecoUtils->GetMatchedResiduals(newCluster->GetID(),dR,dZ);
980 newCluster->SetTrackDistance(dR,dZ);
981
982 }
983 else
984 {// Assign previously assigned matched track in reco, very very rough
985 Int_t absId0 = newCluster->GetCellsAbsId()[0]; // Assign match of first cell in cluster
986 newCluster->SetTrackDistance(fCellMatchdPhi[absId0],fCellMatchdEta[absId0]);
987 }
1e0ff9d3 988
989 //printf("New cluster E %f, Time %e, Id = ", newCluster->E(), newCluster->GetTOF() );
990 //for(Int_t icell=0; icell < newCluster->GetNCells(); icell++ ) printf(" %d,", newCluster->GetCellsAbsId() [icell] );
991 //printf("\n");
992
b43bdd14 993 // Calculate distance to bad channel for new cluster. Make sure you give the list of bad channels.
994 fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, fEvent->GetEMCALCells(), newCluster);
995
996 new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
997
11e7733f 998 if(DebugLevel() > 1 )
999 printf("AliAnalysisTaksEMCALClusterize::UserExec() - New cluster %d of %d, energy %f, mc label %d \n",newCluster->GetID(), kNumberOfCaloClusters, newCluster->E(), newCluster->GetLabel());
b43bdd14 1000
1001 } // cluster loop
1002
1003 fOutputAODBranch->Expand(kNumberOfCaloClusters); // resize TObjArray to 'remove' slots
1004
b43bdd14 1005
1006}
1007
3769e0cb 1008//_______________________________________________
1009TString AliAnalysisTaskEMCALClusterize::GetPass()
1010{
1011 // Get passx from filename.
1012
1013 if (!AliAnalysisManager::GetAnalysisManager()->GetTree())
1014 {
1015 AliError("AliAnalysisTaskEMCALClusterize::GetPass() - Pointer to tree = 0, returning null\n");
1016 return TString("");
1017 }
1018
1019 if (!AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile())
1020 {
1021 AliError("AliAnalysisTaskEMCALClusterize::GetPass() - Null pointer input file, returning null\n");
1022 return TString("");
1023 }
1024
1025 TString pass(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
1026 if (pass.Contains("ass1")) return TString("pass1");
1027 else if (pass.Contains("ass2")) return TString("pass2");
1028 else if (pass.Contains("ass3")) return TString("pass3");
61841488 1029 else if (pass.Contains("ass4")) return TString("pass4");
1030 else if (pass.Contains("ass5")) return TString("pass5");
3769e0cb 1031
1032 // No condition fullfilled, give a default value
1033 printf("AliAnalysisTaskEMCALClusterize::GetPass() - Pass number string not found \n");
1034 return TString("");
1035
1036}
1037
6544055e 1038//_________________________________________
1039void AliAnalysisTaskEMCALClusterize::Init()
1040{
1041 //Init analysis with configuration macro if available
1042
3769e0cb 1043 fOADBSet = kFALSE;
1044 if(fOADBFilePath == "") fOADBFilePath = "$ALICE_ROOT/OADB/EMCAL" ;
1045
3769e0cb 1046 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
1047
1048 if(!fRecParam) fRecParam = new AliEMCALRecParam;
1049 if(!fRecoUtils) fRecoUtils = new AliEMCALRecoUtils();
1050
1051 if(fMaxEvent <= 0) fMaxEvent = 1000000000;
1052 if(fSelectCellMinE <= 0) fSelectCellMinE = 0.005;
1053 if(fSelectCellMinFrac <= 0) fSelectCellMinFrac = 0.001;
1054
cb68426a 1055 //Centrality
1056 if(fCentralityClass == "") fCentralityClass = "V0M";
cb68426a 1057
3769e0cb 1058 if (fOCDBpath == "") fOCDBpath = "raw://" ;
1059 if (fOutputAODBranchName == "") fOutputAODBranchName = "newEMCALClusters" ;
1060
1061 if(gROOT->LoadMacro(fConfigName) >=0)
1062 {
6544055e 1063 printf("AliAnalysisTaksEMCALClusterize::Init() - Configure analysis with %s\n",fConfigName.Data());
1064 AliAnalysisTaskEMCALClusterize *clus = (AliAnalysisTaskEMCALClusterize*)gInterpreter->ProcessLine("ConfigEMCALClusterize()");
1065 fGeomName = clus->fGeomName;
1066 fLoadGeomMatrices = clus->fLoadGeomMatrices;
1067 fOCDBpath = clus->fOCDBpath;
1068 fAccessOCDB = clus->fAccessOCDB;
1069 fRecParam = clus->fRecParam;
1070 fJustUnfold = clus->fJustUnfold;
1071 fFillAODFile = clus->fFillAODFile;
1072 fRecoUtils = clus->fRecoUtils;
1073 fConfigName = clus->fConfigName;
1074 fMaxEvent = clus->fMaxEvent;
1075 fDoTrackMatching = clus->fDoTrackMatching;
1076 fOutputAODBranchName = clus->fOutputAODBranchName;
e3990982 1077 for(Int_t i = 0; i < 12; i++) fGeomMatrix[i] = clus->fGeomMatrix[i] ;
cb68426a 1078 fCentralityClass = clus->fCentralityClass;
1079 fCentralityBin[0] = clus->fCentralityBin[0];
1080 fCentralityBin[1] = clus->fCentralityBin[1];
6fdd30c4 1081 }
e9dd2d80 1082
9ac44255 1083 // Init geometry, I do not like much to do it like this ...
3769e0cb 1084 if(fImportGeometryFromFile && !gGeoManager)
1085 {
d86974bb 1086 if (fImportGeometryFilePath == "") fImportGeometryFilePath = "$ALICE_ROOT/OADB/EMCAL/geometry_2011.root" ; // "$ALICE_ROOT/EVE/alice-data/default_geo.root"
3769e0cb 1087 printf("AliAnalysisTaskEMCALClusterize::Init() - Import %s\n",fImportGeometryFilePath.Data());
1088 TGeoManager::Import(fImportGeometryFilePath) ;
9ac44255 1089 }
b43bdd14 1090
6544055e 1091}
6fdd30c4 1092
6544055e 1093//_______________________________________________________
6fdd30c4 1094void AliAnalysisTaskEMCALClusterize::InitClusterization()
1095{
1096 //Select clusterization/unfolding algorithm and set all the needed parameters
1097
04fcfa08 1098 if (fJustUnfold)
1099 {
bd9e8ebd 1100 // init the unfolding afterburner
1101 delete fUnfolder;
1759f743 1102 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut(),fRecParam->GetMinECut());
bd9e8ebd 1103 return;
6a8be5c3 1104 }
1105
bd9e8ebd 1106 //First init the clusterizer
1107 delete fClusterizer;
1108 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
1109 fClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData, fPedestalData);
cfcbe5d2 1110 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
1111 fClusterizer = new AliEMCALClusterizerv2(fGeom, fCalibData, fPedestalData);
b43bdd14 1112 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
1113 {
bd9e8ebd 1114 fClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
212ac797 1115 fClusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
1116 fClusterizer->SetNColDiff(fRecParam->GetNColDiff());
04fcfa08 1117 }
1118 else
1119 {
bd9e8ebd 1120 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
1121 }
6a8be5c3 1122
bd9e8ebd 1123 //Now set the parameters
1124 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
1125 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
1126 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
1127 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
1128 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
1129 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
1130 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
1131 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
1132 fClusterizer->SetInputCalibrated ( kTRUE );
2af35150 1133 fClusterizer->SetJustClusters ( kTRUE );
04fcfa08 1134
1135 // Initialize the cluster rec points and digits arrays and get them.
1136 fClusterizer->SetOutput(0);
1137 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
1138 fDigitsArr = fClusterizer->GetDigits();
1139
bd9e8ebd 1140 //In case of unfolding after clusterization is requested, set the corresponding parameters
04fcfa08 1141 if(fRecParam->GetUnfold())
1142 {
bd9e8ebd 1143 Int_t i=0;
04fcfa08 1144 for (i = 0; i < 8; i++)
1145 {
bd9e8ebd 1146 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
1147 }//end of loop over parameters
04fcfa08 1148
1149 for (i = 0; i < 3; i++)
1150 {
bd9e8ebd 1151 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
1152 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
1153 }//end of loop over parameters
6fdd30c4 1154
bd9e8ebd 1155 fClusterizer->InitClusterUnfolding();
6544055e 1156
bd9e8ebd 1157 }// to unfold
6fdd30c4 1158}
3fa4fb85 1159
6544055e 1160//_________________________________________________
1161void AliAnalysisTaskEMCALClusterize::InitGeometry()
1162{
3769e0cb 1163 // Init geometry and set the geometry matrix, for the first event, skip the rest
6544055e 1164 // Also set once the run dependent calibrations
1165
3769e0cb 1166 if(fGeomMatrixSet) return;
1167
1168 Int_t runnumber = InputEvent()->GetRunNumber() ;
1169 if (!fGeom)
1170 {
1171 if(fGeomName=="")
1172 {
1173 if (runnumber < 140000) fGeomName = "EMCAL_FIRSTYEARV1";
1174 else if(runnumber < 171000) fGeomName = "EMCAL_COMPLETEV1";
1175 else fGeomName = "EMCAL_COMPLETE12SMV1";
1176 printf("AliAnalysisTaskEMCALClusterize::InitGeometry() - Set EMCAL geometry name to <%s> for run %d\n",fGeomName.Data(),runnumber);
1177 }
6544055e 1178
3769e0cb 1179 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
6544055e 1180
3769e0cb 1181 if(fDebug > 0)
1182 {
1183 printf("AliAnalysisTaskEMCALClusterize::InitGeometry(run=%d)",runnumber);
1184 if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
1185 printf("\n");
1186 }
1187 } // geometry pointer did not exist before
1188
1189 if(fLoadGeomMatrices)
1190 {
1191 printf("AliAnalysisTaskEMCALClusterize::InitGeometry() - Load user defined EMCAL geometry matrices\n");
1192
1193 // OADB if available
1194 AliOADBContainer emcGeoMat("AliEMCALgeo");
1195 emcGeoMat.InitFromFile(Form("%s/EMCALlocal2master.root",fOADBFilePath.Data()),"AliEMCALgeo");
1196 TObjArray *matEMCAL=(TObjArray*)emcGeoMat.GetObject(runnumber,"EmcalMatrices");
1197
1198
1199 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
1200 {
1201
1202 if (!fGeomMatrix[mod]) // Get it from OADB
1203 {
1204 if(fDebug > 1 )
1205 printf("AliAnalysisTaskEMCALClusterize::InitGeometry() - EMCAL matrices SM %d, %p\n",
1206 mod,((TGeoHMatrix*) matEMCAL->At(mod)));
1207 //((TGeoHMatrix*) matEMCAL->At(mod))->Print();
1208
1209 fGeomMatrix[mod] = (TGeoHMatrix*) matEMCAL->At(mod) ;
1210 }
1211
1212 if(fGeomMatrix[mod])
1213 {
1214 if(DebugLevel() > 1)
1215 fGeomMatrix[mod]->Print();
1216
1217 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
1218 }
1219
1220 fGeomMatrixSet=kTRUE;
1221
1222 }//SM loop
1223 }//Load matrices
1224 else if(!gGeoManager)
1225 {
1226 printf("AliAnalysisTaksEMCALClusterize::InitGeometry() - Get geo matrices from data");
1227 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
1228 if(!strcmp(fEvent->GetName(),"AliAODEvent"))
1229 {
1230 if(DebugLevel() > 1)
1231 Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
1232 }//AOD
1233 else
1234 {
1235 if(DebugLevel() > 1)
1236 printf("AliAnalysisTaksEMCALClusterize::InitGeometry() - AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
1237
1238 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(fEvent) ;
1239
1240 if(!esd)
1241 {
1242 Error("InitGeometry"," - This event does not contain ESDs?");
6a797202 1243 if(fFillAODFile) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);
3769e0cb 1244 return;
1245 }
1246
1247 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
1248 {
1249 if(DebugLevel() > 1)
1250 esd->GetEMCALMatrix(mod)->Print();
1251
1252 if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
1253
1254 }
1255
1256 fGeomMatrixSet=kTRUE;
1257
1258 }//ESD
1259 }//Load matrices from Data
1260
6544055e 1261}
1262
6544055e 1263//____________________________________________________
1264Bool_t AliAnalysisTaskEMCALClusterize::IsExoticEvent()
1265{
1266
1267 // Check if event is exotic, get an exotic cell and compare with triggered patch
1268 // If there is a match remove event ... to be completed, filled with something provisional
1269
1270 if(!fRemoveExoticEvents) return kFALSE;
1271
1272 // Loop on cells
1273 AliVCaloCells * cells = fEvent->GetEMCALCells();
1274 Float_t totCellE = 0;
a7e5a381 1275 Int_t bc = InputEvent()->GetBunchCrossNumber();
b43bdd14 1276 for(Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
1277 {
6544055e 1278
1279 Float_t ecell = 0 ;
1280 Double_t tcell = 0 ;
1281
1282 Int_t absID = cells->GetCellNumber(icell);
a7e5a381 1283 Bool_t accept = fRecoUtils->AcceptCalibrateCell(absID,bc,ecell,tcell,cells);
1284 if(accept && !fRecoUtils->IsExoticCell(absID,cells,bc)) totCellE += ecell;
6544055e 1285 }
1286
1287 // TString triggerclasses = "";
1288 // if(esdevent) triggerclasses = esdevent ->GetFiredTriggerClasses();
1289 // else triggerclasses = ((AliAODEvent*)event)->GetFiredTriggerClasses();
1290 // //
1291 // printf("AliAnalysisTaskEMCALClusterize - reject event %d with cluster - reject event with ncells in SM3 %d and SM4 %d\n",(Int_t)Entry(),ncellsSM3, ncellsSM4);
6a797202 1292 // if(fFillAODFile) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);;
6544055e 1293 // return;
1294 //
1295
1296 //printf("TotE cell %f\n",totCellE);
1297 if(totCellE < 1) return kTRUE;
1298
1299 return kFALSE;
1300
1301}
1302
3769e0cb 1303//________________________________________________________________
1304Bool_t AliAnalysisTaskEMCALClusterize::IsLEDEvent(const Int_t run)
6544055e 1305{
1306 //Check if event is LED
1307
1308 if(!fRemoveLEDEvents) return kFALSE;
3769e0cb 1309
1310 //check events of LHC11a period
b9d6234e 1311 if(run < 146858 || run > 146860) return kFALSE ;
3769e0cb 1312
6544055e 1313 // Count number of cells with energy larger than 0.1 in SM3, cut on this number
1314 Int_t ncellsSM3 = 0;
6544055e 1315 AliVCaloCells * cells = fEvent->GetEMCALCells();
3769e0cb 1316 for(Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
1317 {
6544055e 1318 if(cells->GetAmplitude(icell) > 0.1 && cells->GetCellNumber(icell)/(24*48)==3) ncellsSM3++;
6544055e 1319 }
1320
1321 TString triggerclasses = "";
1322
1323 AliESDEvent *esdevent = dynamic_cast<AliESDEvent*>(fEvent);
1324 if(esdevent) triggerclasses = esdevent ->GetFiredTriggerClasses();
1325 else triggerclasses = ((AliAODEvent*)fEvent)->GetFiredTriggerClasses();
1326
1327 Int_t ncellcut = 21;
1328 if(triggerclasses.Contains("EMC")) ncellcut = 35;
1329
b9d6234e 1330 if( ncellsSM3 >= ncellcut)
3769e0cb 1331 {
b9d6234e 1332 printf("AliAnalysisTaksEMCALClusterize::IsLEDEvent() - reject event %d with ncells in SM3 %d\n",(Int_t)Entry(),ncellsSM3);
6a797202 1333 if(fFillAODFile) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);;
6544055e 1334 return kTRUE;
1335 }
1336
1337 return kFALSE;
1338
1339}
1340
b43bdd14 1341//_______________________________________________________
1342void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters()
6fdd30c4 1343{
1344 // Restore clusters from recPoints
b43bdd14 1345 // Cluster energy, global position, cells and their amplitude
1346 // fractions are restored
1347
6a8be5c3 1348 Int_t j = 0;
b43bdd14 1349 for(Int_t i = 0; i < fClusterArr->GetEntriesFast(); i++)
6fdd30c4 1350 {
b43bdd14 1351 AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) fClusterArr->At(i);
6fdd30c4 1352
1353 const Int_t ncells = recPoint->GetMultiplicity();
f6e45fe0 1354 Int_t ncellsTrue = 0;
6fdd30c4 1355
6a8be5c3 1356 if(recPoint->GetEnergy() < fRecParam->GetClusteringThreshold()) continue;
1357
6fdd30c4 1358 // cells and their amplitude fractions
1359 UShort_t absIds[ncells];
1360 Double32_t ratios[ncells];
1361
f6e45fe0 1362 //For later check embedding
1363 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
f053064e 1364
1365 Float_t clusterE = 0;
f46af216 1366 for (Int_t c = 0; c < ncells; c++)
1367 {
b43bdd14 1368 AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->At(recPoint->GetDigitsList()[c]);
6fdd30c4 1369
f6e45fe0 1370 absIds[ncellsTrue] = digit->GetId();
1371 ratios[ncellsTrue] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
11e7733f 1372
d390e7cb 1373 // In case of unfolding, remove digits with unfolded energy too low
b43bdd14 1374 if(fSelectCell)
1375 {
f46af216 1376 if (recPoint->GetEnergiesList()[c] < fSelectCellMinE || ratios[ncellsTrue] < fSelectCellMinFrac)
1377 {
11e7733f 1378 if(DebugLevel() > 1)
f46af216 1379 {
6544055e 1380 printf("AliAnalysisTaksEMCALClusterize::RecPoints2Clusters() - Too small energy in cell of cluster: cluster cell %f, digit %f\n",
d390e7cb 1381 recPoint->GetEnergiesList()[c],digit->GetAmplitude());
1382 }
1383
1384 continue;
1385
1386 } // if cuts
1387 }// Select cells
6544055e 1388
d390e7cb 1389 //Recalculate cluster energy and number of cluster cells in case any of the cells was rejected
d390e7cb 1390 clusterE +=recPoint->GetEnergiesList()[c];
f053064e 1391
f6e45fe0 1392 // In case of embedding, fill ratio with amount of signal,
f46af216 1393 if (aodIH && aodIH->GetMergeEvents())
1394 {
f6e45fe0 1395 //AliVCaloCells* inEMCALCells = InputEvent()->GetEMCALCells();
1396 AliVCaloCells* meEMCALCells = aodIH->GetEventToMerge()->GetEMCALCells();
1397 AliVCaloCells* ouEMCALCells = AODEvent()->GetEMCALCells();
1398
1399 Float_t sigAmplitude = meEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
1400 //Float_t bkgAmplitude = inEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
1401 Float_t sumAmplitude = ouEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
1402 //printf("\t AbsID %d, amplitude : bkg %f, sigAmplitude %f, summed %f - %f\n",absIds[ncellsTrue], bkgAmplitude, sigAmplitude, sumAmplitude, digit->GetAmplitude());
1403
1404 if(sumAmplitude > 0) ratios[ncellsTrue] = sigAmplitude/sumAmplitude;
1405 //printf("\t \t ratio %f\n",ratios[ncellsTrue]);
1406
1407 }//Embedding
1408
11e7733f 1409 ncellsTrue++;
1410
f6e45fe0 1411 }// cluster cell loop
6fdd30c4 1412
f46af216 1413 if (ncellsTrue < 1)
1414 {
f053064e 1415 if (DebugLevel() > 1)
1416 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Skipping cluster with no cells avobe threshold E = %f, ncells %d\n",
1417 recPoint->GetEnergy(), ncells);
1418 continue;
1419 }
1420
1421 //if(ncellsTrue != ncells) printf("Old E %f, ncells %d; New E %f, ncells %d\n",recPoint->GetEnergy(),ncells,clusterE,ncellsTrue);
1422
f46af216 1423 if(clusterE < fRecParam->GetClusteringThreshold())
1424 {
f053064e 1425 if (DebugLevel()>1)
1426 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Remove cluster with energy below seed threshold %f\n",clusterE);
6fdd30c4 1427 continue;
1428 }
1429
1430 TVector3 gpos;
1431 Float_t g[3];
1432
1433 // calculate new cluster position
596697e6 1434
b43bdd14 1435 recPoint->EvalGlobalPosition(fRecParam->GetW0(), fDigitsArr);
6fdd30c4 1436 recPoint->GetGlobalPosition(gpos);
1437 gpos.GetXYZ(g);
1438
1439 // create a new cluster
596697e6 1440
b43bdd14 1441 (*fCaloClusterArr)[j] = new AliAODCaloCluster() ;
1442 AliAODCaloCluster *clus = dynamic_cast<AliAODCaloCluster *>( fCaloClusterArr->At(j) ) ;
6a8be5c3 1443 j++;
6fdd30c4 1444 clus->SetType(AliVCluster::kEMCALClusterv1);
6544055e 1445 clus->SetE(clusterE);
6fdd30c4 1446 clus->SetPosition(g);
f6e45fe0 1447 clus->SetNCells(ncellsTrue);
6fdd30c4 1448 clus->SetCellsAbsId(absIds);
1449 clus->SetCellsAmplitudeFraction(ratios);
6fdd30c4 1450 clus->SetChi2(-1); //not yet implemented
bd9e8ebd 1451 clus->SetTOF(recPoint->GetTime()) ; //time-of-flight
6fdd30c4 1452 clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
5994e71f 1453 clus->SetDistanceToBadChannel(recPoint->GetDistanceToBadTower());
b43bdd14 1454
f46af216 1455 if(ncells == ncellsTrue)
1456 {
f053064e 1457 Float_t elipAxis[2];
1458 recPoint->GetElipsAxis(elipAxis);
1459 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
1460 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
1461 clus->SetDispersion(recPoint->GetDispersion());
1462 }
f46af216 1463 else if(fSelectCell)
1464 {
afaaef51 1465 // In case some cells rejected, in unfolding case, recalculate
1466 // shower shape parameters and position
d20bc070 1467 if(DebugLevel() > 1)
f46af216 1468 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Cells removed from cluster (ncells %d, ncellsTrue %d), recalculate Shower Shape\n",ncells,ncellsTrue);
b43bdd14 1469
f053064e 1470 AliVCaloCells* cells = 0x0;
1471 if (aodIH && aodIH->GetMergeEvents()) cells = AODEvent() ->GetEMCALCells();
1472 else cells = InputEvent()->GetEMCALCells();
b43bdd14 1473
f053064e 1474 fRecoUtils->RecalculateClusterShowerShapeParameters(fGeom,cells,clus);
1475 fRecoUtils->RecalculateClusterPID(clus);
afaaef51 1476 fRecoUtils->RecalculateClusterPosition(fGeom,cells,clus);
f053064e 1477
f053064e 1478 }
6060ed91 1479
6edb4448 1480 // MC
1481
1482 if ( fSetCellMCLabelFromCluster == 1 ) SetClustersMCLabelFrom2SelectedLabels(recPoint,clus) ;
1483 else if( fSetCellMCLabelFromCluster == 2 ) SetClustersMCLabelFromOriginalClusters(clus) ;
1484 else
1485 {
1486 // Normal case, trust what the clusterizer has found
1487 Int_t parentMult = 0;
1488 Int_t *parentList = recPoint->GetParents(parentMult);
1489 clus->SetLabel(parentList, parentMult);
1b5f58b6 1490// printf("Label list : ");
1491// for(Int_t ilabel = 0; ilabel < parentMult; ilabel++ ) printf(" %d ",parentList[ilabel]);
1492// printf("\n");
6edb4448 1493 }
1494
1495 } // recPoints loop
1496
1497}
1498
1499//___________________________________________________________________________
1500void AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs(Int_t & label)
1501{
1502 // MC label for Cells not remapped after ESD filtering, do it here.
e59a6a2e 1503
6edb4448 1504 if(label < 0) return ;
1505
1506 AliAODEvent * evt = dynamic_cast<AliAODEvent*> (fEvent) ;
1507 if(!evt) return ;
1508
1509 TClonesArray * arr = dynamic_cast<TClonesArray*>(evt->FindListObject("mcparticles")) ;
1510 if(!arr) return ;
6060ed91 1511
6edb4448 1512 if(label < arr->GetEntriesFast())
1513 {
1514 AliAODMCParticle * particle = dynamic_cast<AliAODMCParticle *>(arr->At(label));
1515 if(!particle) return ;
1516
1517 if(label == particle->Label()) return ; // label already OK
1518 //else printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - Label %d - AOD stack %d \n",label, particle->Label());
1519 }
1520 //else printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - Label %d > AOD labels %d \n",label, arr->GetEntriesFast());
1521
1522 // loop on the particles list and check if there is one with the same label
1523 for(Int_t ind = 0; ind < arr->GetEntriesFast(); ind++ )
1524 {
1525 AliAODMCParticle * particle = dynamic_cast<AliAODMCParticle *>(arr->At(ind));
48d9e9e7 1526 if(!particle) continue ;
1527
6edb4448 1528 if(label == particle->Label())
f46af216 1529 {
6edb4448 1530 label = ind;
1531 //printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - New Label Index %d \n",label);
1532 return;
1533 }
1534 }
1535
1536 label = -1;
1537
1538 //printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - Label not found set to -1 \n");
e59a6a2e 1539
6edb4448 1540}
1541
1542//________________________________________________
1543void AliAnalysisTaskEMCALClusterize::ResetArrays()
1544{
1545 // Reset arrays containing information for all possible cells
1546 for(Int_t j = 0; j < 12672; j++)
1547 {
1548 fOrgClusterCellId[j] = -1;
1549 fCellLabels[j] = -1;
1550 fCellSecondLabels[j] = -1;
1551 fCellTime[j] = 0.;
1552 fCellMatchdEta[j] = -999;
1553 fCellMatchdPhi[j] = -999;
1554 }
1555}
1556
1557//_____________________________________________________________________________________________________
1558void AliAnalysisTaskEMCALClusterize::SetClustersMCLabelFrom2SelectedLabels(AliEMCALRecPoint * recPoint,
1559 AliAODCaloCluster * clus)
1560{
1561 // Set the cluster MC label, the digizer was filled with most likely MC label for all cells in original cluster
1562 // Now check the second most likely MC label and add it to the new cluster
1563
1564 Int_t parentMult = 0;
1565 Int_t *parentList = recPoint->GetParents(parentMult);
1566 clus->SetLabel(parentList, parentMult);
1567
1568 //Write the second major contributor to each MC cluster.
1569 Int_t iNewLabel ;
1570 for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ )
1571 {
1572
1573 Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
1574 if(idCell>=0)
1575 {
1576 iNewLabel = 1 ; //iNewLabel makes sure we don't write twice the same label.
1577 for ( UInt_t iLoopLabels = 0 ; iLoopLabels < clus->GetNLabels() ; iLoopLabels++ )
b43bdd14 1578 {
6edb4448 1579 if ( fCellSecondLabels[idCell] == -1 ) iNewLabel = 0; // -1 is never a good second label.
6ffa213f 1580 if ( fCellSecondLabels[idCell] == clus->GetLabelAt(iLoopLabels) ) iNewLabel = 0;
6edb4448 1581 }
1582 if (iNewLabel == 1)
1583 {
1584 Int_t * newLabelArray = new Int_t[clus->GetNLabels()+1] ;
1585 for ( UInt_t iLoopNewLabels = 0 ; iLoopNewLabels < clus->GetNLabels() ; iLoopNewLabels++ )
6ffa213f 1586 {
6edb4448 1587 newLabelArray[iLoopNewLabels] = clus->GetLabelAt(iLoopNewLabels) ;
6ffa213f 1588 }
6edb4448 1589
1590 newLabelArray[clus->GetNLabels()] = fCellSecondLabels[idCell] ;
1591 clus->SetLabel(newLabelArray,clus->GetNLabels()+1) ;
1592 delete [] newLabelArray;
1593 }
1594 }//positive cell number
1595 }
1596}
1597
1598//___________________________________________________________________________________________________
1599void AliAnalysisTaskEMCALClusterize::SetClustersMCLabelFromOriginalClusters(AliAODCaloCluster * clus)
1600{
1601 // Get the original clusters that contribute to the new cluster, assign the labels of such clusters
1602 // to the new cluster.
1603 // Only approximatedly valid when output are V1 clusters, handle with care
e59a6a2e 1604
11e7733f 1605 TArrayI clArray(300) ; //Weird if more than a few clusters are in the origin ...
6edb4448 1606 clArray.Reset();
1607 Int_t nClu = 0;
1608 Int_t nLabTotOrg = 0;
4d0b0c70 1609 Float_t emax = -1;
1610 Int_t idMax = -1;
11e7733f 1611
1612 AliVEvent * event = fEvent;
1613
1614 //In case of embedding the MC signal is in the added event
1615 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
1616 if(aodIH && aodIH->GetEventToMerge()) //Embedding
1617 event = aodIH->GetEventToMerge(); //Get clusters directly from embedded signal
1618
1619
6edb4448 1620 //Find the clusters that originally had the cells
1621 for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ )
1622 {
1623 Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
1624
1625 if(idCell>=0)
1626 {
1627 Int_t idCluster = fOrgClusterCellId[idCell];
1628
1629 Bool_t set = kTRUE;
1630 for(Int_t icl =0; icl < nClu; icl++)
1631 {
11e7733f 1632 if(((Int_t)clArray.GetAt(icl))==-1 ) continue;
6edb4448 1633 if( idCluster == ((Int_t)clArray.GetAt(icl)) ) set = kFALSE;
1634 // printf("\t \t icell %d Cluster in array %d, IdCluster %d, in array %d, set %d\n",
1635 // iLoopCell, icl, idCluster,((Int_t)clArray.GetAt(icl)),set);
1636 }
1637 if( set && idCluster >= 0)
1638 {
1639 clArray.SetAt(idCluster,nClu++);
1640 //printf("******** idCluster %d \n",idCluster);
11e7733f 1641 nLabTotOrg+=(event->GetCaloCluster(idCluster))->GetNLabels();
4d0b0c70 1642
1643 //printf("Cluster in array %d, IdCluster %d\n",nClu-1, idCluster);
1644
1645 //Search highest E cluster
11e7733f 1646 AliVCluster * clOrg = event->GetCaloCluster(idCluster);
4d0b0c70 1647 //printf("\t E %f\n",clOrg->E());
1648 if(emax < clOrg->E())
1649 {
1650 emax = clOrg->E();
1651 idMax = idCluster;
1652 }
6edb4448 1653 }
37d2296c 1654 }
6edb4448 1655 }// cell loop
11e7733f 1656
6edb4448 1657 if(nClu==0 || nLabTotOrg == 0)
1658 {
11e7733f 1659 //if(clus->E() > 0.25) printf("AliAnalysisTaskEMCALClusterize::SetClustersMCLabelFromOriginalClusters() - Check: N org clusters %d, n tot labels %d, cluster E %f, n cells %d\n",nClu,nLabTotOrg,clus->E(), clus->GetNCells());
6edb4448 1660 //for(Int_t icell = 0; icell < clus->GetNCells(); icell++) printf("\t cell %d",clus->GetCellsAbsId()[icell]);
1661 //printf("\n");
1662 }
1663
4d0b0c70 1664 // Put the first in the list the cluster with highest energy
1665 if(idMax != ((Int_t)clArray.GetAt(0))) // Max not at first position
1666 {
1667 Int_t maxIndex = -1;
1668 Int_t firstCluster = ((Int_t)clArray.GetAt(0));
1669 for ( Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++ )
1670 {
1671 if(idMax == ((Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
1672 }
1673
11e7733f 1674 if(firstCluster >=0 && idMax >=0)
1675 {
1676 clArray.SetAt(idMax,0);
1677 clArray.SetAt(firstCluster,maxIndex);
1678 }
4d0b0c70 1679 }
11e7733f 1680
6edb4448 1681 // Get the labels list in the original clusters, assign all to the new cluster
1682 TArrayI clMCArray(nLabTotOrg) ;
1683 clMCArray.Reset();
1684
1685 Int_t nLabTot = 0;
1686 for ( Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++ )
1687 {
1688 Int_t idCluster = clArray.GetAt(iLoopCluster);
4d0b0c70 1689 //printf("New Cluster in Array %d, idCluster %d \n",iLoopCluster,idCluster);
11e7733f 1690 AliVCluster * clOrg = event->GetCaloCluster(idCluster);
6edb4448 1691 Int_t nLab = clOrg->GetNLabels();
37d2296c 1692
6edb4448 1693 for ( Int_t iLab = 0 ; iLab < nLab ; iLab++ )
1694 {
1695 Int_t lab = clOrg->GetLabelAt(iLab) ;
1696 if(lab>=0)
1697 {
1698 Bool_t set = kTRUE;
1699 //printf("\t \t Set Label %d \n", lab);
1700 for(Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
1701 {
1702 if( lab == ((Int_t)clMCArray.GetAt(iLabTot)) ) set = kFALSE;
1703 //printf("iLoopCluster %d, Label ID in Org Cluster %d,label %d Label ID in array %d, label in array %d, set %d\n",
1704 // iLoopCluster, iLab, lab, iLabTot, ((Int_t)clMCArray.GetAt(iLabTot)),set);
1705 }
1706 if( set ) clMCArray.SetAt(lab,nLabTot++);
1707 }
1708 }
1709 }// cluster loop
1710
1711 // Set the final list of labels
1712
1713 clus->SetLabel(clMCArray.GetArray(), nLabTot);
1714
e59a6a2e 1715// printf("Final list of labels for new cluster : \n");
1716// for(Int_t ice = 0; ice < clus->GetNCells() ; ice++)
1717// {
1718// printf("\t Cell %d ",clus->GetCellsAbsId()[ice]);
1719// Int_t label = InputEvent()->GetEMCALCells()->GetCellMCLabel(clus->GetCellsAbsId()[ice]);
1720// printf(" org %d ",label);
1721// RemapMCLabelForAODs(label);
1722// printf(" new %d \n",label);
1723// }
1724// for(Int_t imc = 0; imc < clus->GetNLabels(); imc++) printf("\t Label %d\n",clus->GetLabelAt(imc));
6544055e 1725}
1726
3769e0cb 1727
6544055e 1728//____________________________________________________________
1729void AliAnalysisTaskEMCALClusterize::UserCreateOutputObjects()
1730{
1731 // Init geometry, create list of output clusters
1732
6a797202 1733
1734 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
1735
1736 if(fOutputAODBranchName.Length()==0)
3769e0cb 1737 {
6a797202 1738 fOutputAODBranchName = "newEMCALClustersArray";
1739 printf("Cluster branch name not set, set it to newEMCALClustersArray \n");
6544055e 1740 }
6a797202 1741
1742 fOutputAODBranch->SetName(fOutputAODBranchName);
1743
1744 if( fFillAODFile )
3769e0cb 1745 {
6a797202 1746 //fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
1747
1748
1749 //fOutputAODBranch->SetOwner(kFALSE);
1750
1751 AddAODBranch("TClonesArray", &fOutputAODBranch);
6544055e 1752 }
b43bdd14 1753
6fdd30c4 1754}
6544055e 1755
1756//_______________________________________________________
1757void AliAnalysisTaskEMCALClusterize::UserExec(Option_t *)
1758{
b43bdd14 1759 // Do clusterization event by event, execute different steps
596697e6 1760 // 1) Do some checks on the kind of events (ESD, AOD) or if some filtering is needed, initializations
1761 // load things and clear arrays
b43bdd14 1762 // 2) Clusterize a) just unfolding existing clusters (fJustUnfold)
1763 // b) recluster cells
1764 // + convert cells into digits (calibrating them)
1765 // + recluster digits into recPoints with the chosen clusterizer (V1, V1+Unfold,V2, NxN)
1766 // with methods in AliEMCALClusterizer
1767 // + transform recPoints into CaloClusters
1768 // 3) Do some final calculations in the found clusters (track-matching) and put them in an AOD branch
1769
596697e6 1770 //-------
b43bdd14 1771 // Step 1
1772
b0f874d4 1773
b43bdd14 1774 //Remove the contents of AOD branch output list set in the previous event
6544055e 1775 fOutputAODBranch->Clear("C");
596697e6 1776
cb68426a 1777 LoadBranches();
1778
1779 //Check if there is a centrality value, PbPb analysis, and if a centrality bin selection is requested
1780 //If we need a centrality bin, we select only those events in the corresponding bin.
1781 if( GetCentrality() && fCentralityBin[0] >= 0 && fCentralityBin[1] >= 0 )
1782 {
8fa7608a 1783 Float_t cen = GetEventCentrality();
cb68426a 1784 if(cen > fCentralityBin[1] || cen < fCentralityBin[0]) return ; //reject events out of bin.
1785 }
b0f874d4 1786
596697e6 1787 // intermediate array with new clusters : init the array only once or clear from previous event
1788 if(!fCaloClusterArr) fCaloClusterArr = new TObjArray(10000);
1789 else fCaloClusterArr->Delete();//Clear("C"); it leaks?
1790
5aa88029 1791 InitGeometry(); // only once, must be done before OADB, geo OADB accessed here
1792
6544055e 1793 //Get the event, do some checks and settings
1794 CheckAndGetEvent() ;
1795
a1eeb25d 1796 if (!fEvent)
1797 {
6544055e 1798 if(DebugLevel() > 0 ) printf("AliAnalysisTaksEMCALClusterize::UserExec() - Skip Event %d", (Int_t) Entry());
1799 return ;
1800 }
6a797202 1801
3769e0cb 1802 //Init pointers, geometry, clusterizer, ocdb, aodb
6544055e 1803
6544055e 1804
3769e0cb 1805 if(fAccessOCDB) AccessOCDB();
1806 if(fAccessOADB) AccessOADB(); // only once
b43bdd14 1807
3769e0cb 1808 InitClusterization();
6544055e 1809
596697e6 1810 //-------
b43bdd14 1811 // Step 2
1812
6544055e 1813 // Make clusters
1814 if (fJustUnfold) ClusterUnfolding();
1815 else ClusterizeCells() ;
6544055e 1816
596697e6 1817 //-------
b43bdd14 1818 // Step 3
6544055e 1819
afc22931 1820 FillCaloClusterInEvent();
b65291bf 1821
6544055e 1822}
1823