AliPhysics  958ad07 (958ad07)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEMCALClusterize.cxx
Go to the documentation of this file.
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 
16 // --- Root ---
17 #include <TString.h>
18 #include <TRefArray.h>
19 #include <TClonesArray.h>
20 #include <TTree.h>
21 #include <TGeoManager.h>
22 #include <TROOT.h>
23 #include <TInterpreter.h>
24 #include <TFile.h>
25 
26 // --- AliRoot Analysis Steering
27 #include "AliAnalysisTask.h"
28 #include "AliAnalysisManager.h"
29 #include "AliESDEvent.h"
30 #include "AliGeomManager.h"
31 #include "AliVCaloCells.h"
32 #include "AliAODCaloCluster.h"
33 #include "AliCDBManager.h"
34 #include "AliCDBStorage.h"
35 #include "AliCDBEntry.h"
36 #include "AliLog.h"
37 #include "AliVEventHandler.h"
38 #include "AliAODInputHandler.h"
39 #include "AliOADBContainer.h"
40 #include "AliAODMCParticle.h"
41 #include "AliCentrality.h"
42 #include "AliMultSelection.h"
43 
44 // --- EMCAL
45 #include "AliEMCALAfterBurnerUF.h"
46 #include "AliEMCALGeometry.h"
47 #include "AliEMCALClusterizerNxN.h"
48 #include "AliEMCALClusterizerv1.h"
49 #include "AliEMCALClusterizerv2.h"
50 #include "AliEMCALRecPoint.h"
51 #include "AliEMCALDigit.h"
52 
54 
58 
59 //______________________________________________________________________________
60 // Constructor.
61 //______________________________________________________________________________
63 : AliAnalysisTaskSE(name)
64 , fEvent(0)
65 , fGeom(0), fGeomName("")
66 , fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
67 , fOCDBpath(""), fAccessOCDB(kFALSE)
68 , fDigitsArr(0), fClusterArr(0)
69 , fCaloClusterArr(0), fCaloCells(0)
70 , fRecParam(0), fClusterizer(0)
71 , fUnfolder(0), fJustUnfold(kFALSE)
72 , fOutputAODBranch(0), fOutputAODBranchName(""), fOutputAODBranchSet(0)
73 , fFillAODFile(kFALSE), fFillAODHeader(0)
74 , fFillAODCaloCells(0), fRun(-1)
75 , fRecoUtils(0), fConfigName("")
76 , fOrgClusterCellId()
77 , fCellLabels(), fCellSecondLabels(), fCellTime()
78 , fCellMatchdEta(), fCellMatchdPhi()
79 , fRecalibrateWithClusterTime(0)
80 , fMaxEvent(0), fDoTrackMatching(kFALSE), fUpdateCell(0)
81 , fSelectCell(kFALSE), fSelectCellMinE(0), fSelectCellMinFrac(0)
82 , fRejectBelowThreshold(kFALSE)
83 , fRemoveLEDEvents(kTRUE),fRemoveExoticEvents(kFALSE)
84 , fImportGeometryFromFile(kTRUE), fImportGeometryFilePath("")
85 , fOADBSet(kFALSE), fAccessOADB(kTRUE), fOADBFilePath("")
86 , fConstantTimeShift(0)
87 , fCentralityClass(""), fUseAliCentrality(0), fSelectEMCALEvent(0)
88 , fEMCALEnergyCut(0.), fEMCALNcellsCut (0)
89 , fSetCellMCLabelFromCluster(0)
90 , fSetCellMCLabelFromEdepFrac(0)
91 , fRemapMCLabelForAODs(0)
92 , fInputFromFilter(0)
93 , fTCardCorrEmulation(0), fTCardCorrClusEnerConserv(0)
94 , fRandom(0)
95 {
96  for(Int_t i = 0; i < 22; i++)
97  {
98  fGeomMatrix[i] = 0;
100  }
101 
102  ResetArrays();
103 
104  fCentralityBin[0] = fCentralityBin[1]=-1;
108 }
109 
110 //______________________________________________________________
112 //______________________________________________________________
114 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
115 , fEvent(0)
116 , fGeom(0), fGeomName("")
117 , fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
118 , fOCDBpath(""), fAccessOCDB(kFALSE)
119 , fDigitsArr(0), fClusterArr(0)
120 , fCaloClusterArr(0), fCaloCells(0)
121 , fRecParam(0), fClusterizer(0)
122 , fUnfolder(0), fJustUnfold(kFALSE)
123 , fOutputAODBranch(0), fOutputAODBranchName(""), fOutputAODBranchSet(0)
124 , fFillAODFile(kFALSE), fFillAODHeader(0)
125 , fFillAODCaloCells(0), fRun(-1)
126 , fRecoUtils(0), fConfigName("")
127 , fOrgClusterCellId()
128 , fCellLabels(), fCellSecondLabels(), fCellTime()
129 , fCellMatchdEta(), fCellMatchdPhi()
130 , fRecalibrateWithClusterTime(0)
131 , fMaxEvent(0), fDoTrackMatching(kFALSE), fUpdateCell(0)
132 , fSelectCell(kFALSE), fSelectCellMinE(0), fSelectCellMinFrac(0)
133 , fRejectBelowThreshold(kFALSE)
134 , fRemoveLEDEvents(kTRUE), fRemoveExoticEvents(kFALSE)
135 , fImportGeometryFromFile(kTRUE), fImportGeometryFilePath("")
136 , fOADBSet(kFALSE), fAccessOADB(kTRUE), fOADBFilePath("")
137 , fConstantTimeShift(0)
138 , fCentralityClass(""), fUseAliCentrality(0), fSelectEMCALEvent(0)
139 , fEMCALEnergyCut(0.), fEMCALNcellsCut (0)
140 , fSetCellMCLabelFromCluster(0)
141 , fSetCellMCLabelFromEdepFrac(0)
142 , fRemapMCLabelForAODs(0)
143 , fInputFromFilter(0)
144 , fTCardCorrEmulation(0), fTCardCorrClusEnerConserv(0)
145 , fRandom(0)
146 {
147  for(Int_t i = 0; i < 22; i++)
148  {
149  fGeomMatrix[i] = 0;
151  }
152 
153  ResetArrays();
154 
155  fCentralityBin[0] = fCentralityBin[1]=-1;
159 }
160 
161 //_______________________________________________________________
163 //_______________________________________________________________
165 {
166  if (fDigitsArr)
167  {
168  fDigitsArr->Clear("C");
169  delete fDigitsArr;
170  }
171 
172  if (fClusterArr)
173  {
174  fClusterArr->Delete();
175  delete fClusterArr;
176  }
177 
178  if (fCaloClusterArr)
179  {
180  fCaloClusterArr->Delete();
181  delete fCaloClusterArr;
182  }
183 
184  if(fClusterizer) delete fClusterizer;
185  if(fUnfolder) delete fUnfolder;
186  if(fRecoUtils) delete fRecoUtils;
187 }
188 
189 //_______________________________________________________
193 //_______________________________________________________
195 {
196  if(!fSelectEMCALEvent) return kTRUE; // accept
197 
198  if(fEMCALEnergyCut <= 0) return kTRUE; // accept
199 
200  Int_t nCluster = fEvent -> GetNumberOfCaloClusters();
201  Int_t bc = fEvent -> GetBunchCrossNumber();
202 
203  for(Int_t icalo = 0; icalo < nCluster; icalo++)
204  {
205  AliVCluster *clus = (AliVCluster*) (fEvent->GetCaloCluster(icalo));
206 
207  if( ( clus->IsEMCAL() ) && ( clus->GetNCells() > fEMCALNcellsCut ) && ( clus->E() > fEMCALEnergyCut ) &&
208  fRecoUtils->IsGoodCluster(clus,fGeom,fCaloCells,bc))
209  {
210 
211  AliDebug(1, Form("Accept : E %2.2f > %2.2f, nCells %d > %d",
212  clus->E(), fEMCALEnergyCut, clus->GetNCells(), fEMCALNcellsCut));
213 
214  return kTRUE;
215  }
216 
217  }// loop
218 
219  AliDebug(1,"Reject");
220 
221  return kFALSE;
222 }
223 
224 //_______________________________________________
227 //_______________________________________________
229 {
230  //Set it only once
231  if(fOADBSet) return ;
232 
233  Int_t runnumber = InputEvent()->GetRunNumber() ;
234  TString pass = GetPass();
235 
236  AliInfo(Form("Get AODB parameters from EMCAL in %s for run %d, and <%s>",fOADBFilePath.Data(),runnumber,pass.Data()));
237 
238  Int_t nSM = fGeom->GetNumberOfSuperModules();
239 
240  // Bad map
241  if(fRecoUtils->IsBadChannelsRemovalSwitchedOn())
242  {
243  AliOADBContainer *contBC=new AliOADBContainer("");
244  contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fOADBFilePath.Data()),"AliEMCALBadChannels");
245 
246  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runnumber);
247 
248  if(arrayBC)
249  {
250  fRecoUtils->SwitchOnDistToBadChannelRecalculation();
251  AliInfo("Remove EMCAL bad cells");
252 
253  for (Int_t i=0; i < nSM; ++i)
254  {
255  TH2I *hbm = fRecoUtils->GetEMCALChannelStatusMap(i);
256 
257  if (hbm)
258  delete hbm;
259 
260  hbm=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
261 
262  if (!hbm)
263  {
264  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
265  continue;
266  }
267 
268  hbm->SetDirectory(0);
269  fRecoUtils->SetEMCALChannelStatusMap(i,hbm);
270 
271  } // loop
272  } else AliInfo("Do NOT remove EMCAL bad channels"); // run array
273 
274  delete contBC;
275  } // Remove bad
276 
277  // Energy Recalibration
278  if(fRecoUtils->IsRecalibrationOn())
279  {
280  AliOADBContainer *contRF=new AliOADBContainer("");
281 
282  contRF->InitFromFile(Form("%s/EMCALRecalib.root",fOADBFilePath.Data()),"AliEMCALRecalib");
283 
284  TObjArray *recal=(TObjArray*)contRF->GetObject(runnumber);
285 
286  if(recal)
287  {
288  TObjArray *recalpass=(TObjArray*)recal->FindObject(pass);
289 
290  if(recalpass)
291  {
292  TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
293 
294  if(recalib)
295  {
296  AliInfo("Recalibrate EMCAL");
297  for (Int_t i=0; i<nSM; ++i)
298  {
299  TH2F *h = fRecoUtils->GetEMCALChannelRecalibrationFactors(i);
300 
301  if (h)
302  delete h;
303 
304  h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
305 
306  if (!h)
307  {
308  AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
309  continue;
310  }
311 
312  h->SetDirectory(0);
313 
314  fRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
315  } // SM loop
316  } else AliInfo("Do NOT recalibrate EMCAL, no params object array"); // array ok
317  } else AliInfo("Do NOT recalibrate EMCAL, no params for pass"); // array pass ok
318  } else AliInfo("Do NOT recalibrate EMCAL, no params for run"); // run number array ok
319 
320  delete contRF;
321  } // Recalibration on
322 
323  // Energy Recalibration, apply on top of previous calibration factors
324  if(fRecoUtils->IsRunDepRecalibrationOn())
325  {
326  AliOADBContainer *contRFTD=new AliOADBContainer("");
327 
328  contRFTD->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fOADBFilePath.Data()),"AliEMCALRunDepTempCalibCorrections");
329 
330  TH1S *htd=(TH1S*)contRFTD->GetObject(runnumber);
331 
332  //If it did not exist for this run, get closes one
333  if (!htd)
334  {
335  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runnumber));
336  // let's get the closest runnumber instead then..
337  Int_t lower = 0;
338  Int_t ic = 0;
339  Int_t maxEntry = contRFTD->GetNumberOfEntries();
340 
341  while ( (ic < maxEntry) && (contRFTD->UpperLimit(ic) < runnumber) ) {
342  lower = ic;
343  ic++;
344  }
345 
346  Int_t closest = lower;
347  if ( (ic<maxEntry) &&
348  (contRFTD->LowerLimit(ic)-runnumber) < (runnumber - contRFTD->UpperLimit(lower)) ) {
349  closest = ic;
350  }
351 
352  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRFTD->LowerLimit(closest)));
353  htd = (TH1S*) contRFTD->GetObjectByIndex(closest);
354  }
355 
356  if(htd)
357  {
358  AliInfo("Recalibrate (Temperature) EMCAL");
359 
360  for (Int_t ism=0; ism<nSM; ++ism)
361  {
362  for (Int_t icol=0; icol<48; ++icol)
363  {
364  for (Int_t irow=0; irow<24; ++irow)
365  {
366  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
367 
368  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
369  factor *= htd->GetBinContent(absID) / 10000. ; // correction dependent on T
370  //printf("\t ism %d, icol %d, irow %d,absID %d, corrA %2.3f, corrB %2.3f, corrAB %2.3f\n",ism, icol, irow, absID,
371  // GetEMCALChannelRecalibrationFactor(ism,icol,irow) , htd->GetBinContent(absID) / 10000., factor);
372  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
373  } // columns
374  } // rows
375  } // SM loop
376  } else AliInfo("Do NOT recalibrate EMCAL with T variations, no params TH1");
377 
378  delete contRFTD;
379  } // Run by Run T calibration
380 
381  // Time Recalibration
382  if(fRecoUtils->IsTimeRecalibrationOn())
383  {
384  AliOADBContainer *contTRF=new AliOADBContainer("");
385 
386  contTRF->InitFromFile(Form("%s/EMCALTimeCalib.root",fOADBFilePath.Data()),"AliEMCALTimeCalib");
387 
388  TObjArray *trecal=(TObjArray*)contTRF->GetObject(runnumber);
389 
390  if(trecal)
391  {
392  // pass number should be pass1 except on Run1 and special cases
393  TString passM = pass;
394  if ( pass=="spc_calo" ) passM = "pass3";
395  if ( runnumber > 209121 ) passM = "pass1"; // run2 periods
396  if ( pass == "muon_calo_pass1" && runnumber > 209121 && runnumber < 244284 )
397  passM = "pass0";//period LHC15a-m
398 
399  TObjArray *trecalpass=(TObjArray*)trecal->FindObject(passM);
400 
401  if(trecalpass)
402  {
403  AliInfo("Time Recalibrate EMCAL");
404  for (Int_t ibc = 0; ibc < 4; ++ibc)
405  {
406  TH1F *h = fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(ibc);
407 
408  if (h)
409  delete h;
410 
411  h = (TH1F*)trecalpass->FindObject(Form("hAllTimeAvBC%d",ibc));
412 
413  if (!h)
414  {
415  AliError(Form("Could not load hAllTimeAvBC%d",ibc));
416  continue;
417  }
418 
419  h->SetDirectory(0);
420 
421  fRecoUtils->SetEMCALChannelTimeRecalibrationFactors(ibc,h);
422  } // bunch crossing loop
423  } else AliInfo("Do NOT recalibrate time EMCAL, no params for pass"); // array pass ok
424  } else AliInfo("Do NOT recalibrate time EMCAL, no params for run"); // run number array ok
425 
426  delete contTRF;
427  } // Time recalibration on
428 
429  // L1 Phase Time Recalibration
430  if( fRecoUtils->IsL1PhaseInTimeRecalibrationOn() )
431  {
432  // init default maps first
433  if (!fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationArray())
434  fRecoUtils->InitEMCALL1PhaseInTimeRecalibration() ;
435 
436  AliOADBContainer *contBC = new AliOADBContainer("");
437 
438  TFile *timeFile=new TFile(Form("%s/EMCALTimeL1PhaseCalib.root",fOADBFilePath.Data()),"read");
439  if (!timeFile || timeFile->IsZombie())
440  {
441  AliFatal(Form("EMCALTimeL1PhaseCalib.root was not found in the path provided: %s",fOADBFilePath.Data()));
442  return ;
443  }
444 
445  if (timeFile) delete timeFile;
446 
447  contBC->InitFromFile(Form("%s/EMCALTimeL1PhaseCalib.root",fOADBFilePath.Data()),"AliEMCALTimeL1PhaseCalib");
448 
449  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runnumber);
450  if (!arrayBC)
451  {
452  AliError(Form("No external L1 phase in time calibration set for run number: %d", runnumber));
453  fRecoUtils->SwitchOffL1PhaseInTimeRecalibration();
454  }
455  else
456  {
457  // Only 1 L1 phase correction possible, except special cases
458  TString pass2 = "pass1";
459 
460  if ( pass=="muon_calo_pass1" && runnumber > 209121 && runnumber < 244284 )
461  pass2 = "pass0"; // period LHC15a-m
462 
463  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass2);
464  if (!arrayBCpass)
465  {
466  AliError(Form("No external L1 phase in time calibration set for: %d -%s", runnumber,pass2.Data()));
467  fRecoUtils->SwitchOffL1PhaseInTimeRecalibration();
468  }
469  else AliInfo("Recalibrate L1 Phase time");
470 
471  if(arrayBCpass)
472  {
473  if ( DebugLevel()>0 ) arrayBCpass->Print();
474 
475  TH1C *h = fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationForAllSM();
476  if (h) delete h;
477 
478  h = (TH1C*)arrayBCpass->FindObject(Form("h%d",runnumber));
479 
480  if (!h)
481  {
482  AliFatal(Form("There is no calibration histogram h%d for this run",runnumber));
483  return;
484  }
485 
486  h->SetDirectory(0);
487  fRecoUtils->SetEMCALL1PhaseInTimeRecalibrationForAllSM(h);
488  }
489  }
490 
491  delete contBC;
492  } // L1 Phase Time Recalibration
493 
494  // Parameters already set once, so do not it again
495  fOADBSet = kTRUE;
496 }
497 
498 //_________________________________________________
501 //_________________________________________________
503 {
504  fEvent = InputEvent();
505  if (!fEvent)
506  {
507  Warning("AccessOCDB","Event not available!!!");
508  return kFALSE;
509  }
510 
511  if (fEvent->GetRunNumber()==fRun)
512  return kTRUE;
513  fRun = fEvent->GetRunNumber();
514 
515  AliDebug(1,"Begin");
516 
517  AliCDBManager *cdb = AliCDBManager::Instance();
518 
519 
520  if (fOCDBpath.Length())
521  {
522  cdb->SetDefaultStorage(fOCDBpath.Data());
523  AliInfo(Form("Default storage %s",fOCDBpath.Data()));
524  }
525 
526  cdb->SetRun(fEvent->GetRunNumber());
527 
528  //
529  // EMCAL from RAW OCDB
530  if (fOCDBpath.Contains("alien:"))
531  {
532  cdb->SetSpecificStorage("EMCAL/Calib/Data","raw://");
533  cdb->SetSpecificStorage("EMCAL/Calib/Time","raw://");
534  cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","raw://");
535  }
536 
537  TString path = cdb->GetDefaultStorage()->GetBaseFolder();
538 
539  return kTRUE;
540 }
541 
542 //_____________________________________________________
546 //_____________________________________________________
548 {
549  // Get the number of stored digits, to assign the index of the new ones
550  Int_t idigit = fDigitsArr->GetEntriesFast();
551 
552  Double_t fixTime = 615.*1e-9;
553 
554  for(Int_t j = 0; j < fgkNEMCalCells; j++)
555  {
556  // Newly created?
557  if ( !fTCardCorrCellsNew[j] ) continue;
558 
559  // Accept only if at least 10 MeV
560  if ( fTCardCorrCellsEner[j] < 0.01 ) continue;
561 
562  // Check if it was not masked
563  Float_t amp = 0;
564  Double_t time = 0;
565  if ( !fRecoUtils->AcceptCalibrateCell(j,0,amp,time,fCaloCells) ) continue;
566 
567 // printf("add new digit absId %d, accept? %d, digit %d, induced amp %2.2f\n",
568 // j,fRecoUtils->AcceptCalibrateCell(j,0,amp,time,fCaloCells),idigit,fTCardCorrCellsEner[j]);
569 
570  // Now add the cell to the digits list
571  //AliEMCALDigit* digit =
572  new((*fDigitsArr)[idigit]) AliEMCALDigit( -2, -2, j, fTCardCorrCellsEner[j], fixTime,AliEMCALDigit::kHG,idigit, 0, 0, 0);
573 
574  //digit->SetListOfParents(0,0x0,0x0); // not needed
575 
576  idigit++;
577  }// loop on all possible cells
578 }
579 
580 
581 //_____________________________________________________
586 //_____________________________________________________
588 {
589  fEvent = 0x0;
590 
591  AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
592  Int_t eventN = Entry();
593  if(aodIH) eventN = aodIH->GetReadEntry();
594 
595  if (eventN > fMaxEvent)
596  return ;
597 
598  //printf("Clusterizer --- Event %d-- \n",eventN);
599 
600  // Check if input event are embedded events
601  // If so, take output event
602  if (aodIH && aodIH->GetMergeEvents())
603  {
604  fEvent = AODEvent();
605 
606  if(!aodIH->GetMergeEMCALCells())
607  AliFatal("Events merged but not EMCAL cells, check analysis settings!");
608 
609  AliDebug(1,"Use embedded events");
610 
611  AliDebug(1,Form("\t InputEvent N Clusters %d, N Cells %d",
612  InputEvent()->GetNumberOfCaloClusters(),InputEvent()->GetEMCALCells()->GetNumberOfCells()));
613 
614  AliDebug(1,Form("\t MergedEvent N Clusters %d, N Cells %d",
615  aodIH->GetEventToMerge()->GetNumberOfCaloClusters(), aodIH->GetEventToMerge()->GetEMCALCells()->GetNumberOfCells()));
616 
617 // if(DebugLevel() > 1)
618 // {
619 // for (Int_t icl=0; icl < aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); icl++)
620 // {
621 // AliAODCaloCluster *sigCluster = aodIH->GetEventToMerge()->GetCaloCluster(icl);
622 // if(sigCluster->IsEMCAL()) AliInfo(Form("\t \t Signal cluster: i %d, E %f",icl,sigCluster->E()));
623 // }
624 // }
625 
626  AliDebug(1,Form("\t OutputEvent N Clusters %d, N Cells %d",
627  AODEvent()->GetNumberOfCaloClusters(), AODEvent()->GetEMCALCells()->GetNumberOfCells()));
628  }
629  else if(fInputFromFilter)
630  {
631  //printf("Get Input From Filtered AOD\n");
632  fEvent = AODEvent();
633  }
634  else
635  {
636  fEvent = InputEvent();
639  }
640 
641  if (!fEvent)
642  {
643  AliError("Event not available");
644  return ;
645  }
646 
647  //Recover the pointer to CaloCells container
648  fCaloCells = fEvent->GetEMCALCells();
649 
650  //Process events if there is a high energy cluster
651  if(!AcceptEventEMCAL()) { fEvent = 0x0 ; return ; }
652 
653  //-------------------------------------------------------------------------------------
654  // Reject events if LED was firing, use only for LHC11a data
655  // Reject event if triggered by exotic cell and remove exotic cells if not triggered
656  //-------------------------------------------------------------------------------------
657 
658  if( IsLEDEvent( InputEvent()->GetRunNumber() ) ) { fEvent = 0x0 ; return ; }
659 
660  if( IsExoticEvent() ) { fEvent = 0x0 ; return ; }
661 
662  //-------------------------------------------------------------------------------------
663  // Set the cluster array in the event (output or input)
664  //-------------------------------------------------------------------------------------
665 
666  if ( fFillAODFile )
667  {
668  //Magic line to write events to AOD filem put after event rejection
669  AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
670  }
671  else if( !fOutputAODBranchSet )
672  {
673  // Create array and put it in the input event, if output AOD not selected, only once
674  InputEvent()->AddObject(fOutputAODBranch);
675  fOutputAODBranchSet = kTRUE;
676  AliInfo(Form("Add AOD branch <%s> to input event",fOutputAODBranchName.Data()));
677  }
678 }
679 
680 //____________________________________________________
685 //____________________________________________________
687 {
688  Int_t nClusters = fEvent->GetNumberOfCaloClusters();
689  Int_t nClustersOrg = 0;
690 
691  AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
692  if(aodIH && aodIH->GetEventToMerge()) //Embedding
693  nClusters = aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); //Get clusters directly from embedded signal
694 
695  ResetArrays();
696 
697  // Loop on original clusters, get MC labels, cluster time (OLD AODs),
698  // or track matching residuals (if matching is not requested)
700  {
701  for (Int_t i = 0; i < nClusters; i++)
702  {
703  AliVCluster *clus = 0;
704  if(aodIH && aodIH->GetEventToMerge()) //Embedding
705  clus = aodIH->GetEventToMerge()->GetCaloCluster(i); //Get clusters directly from embedded signal
706  else
707  clus = fEvent->GetCaloCluster(i);
708 
709  if(!clus) return;
710 
711  nClustersOrg++;
712 
713  if(!clus->IsEMCAL()) continue;
714 
715  Int_t label = clus->GetLabel();
716  Int_t label2 = -1 ;
717  if (clus->GetNLabels() >=2 ) label2 = clus->GetLabelAt(1) ;
718 
719  //printf("Org cluster %d) ID = %d, E %2.2f, Time %3.0f, N Cells %d, N MC labels %d, main MC label %d, all MC labels:\n",
720  // i, clus->GetID(), clus->E(), clus->GetTOF()*1e9, clus->GetNCells(), clus->GetNLabels(), label);
721  //
722  //for(Int_t imc = 0; imc < clus->GetNLabels(); imc++)
723  // printf("%d) Label %d, E dep frac %0.2f; ",
724  // imc, clus->GetLabelAt(imc),clus->GetClusterMCEdepFraction(imc));
725  //if(clus->GetNLabels() > 0) printf("\n");
726 
727  UShort_t * index = clus->GetCellsAbsId() ;
728  for(Int_t icell=0; icell < clus->GetNCells(); icell++ )
729  {
730  fOrgClusterCellId[index[icell]] = i;
731  fCellTime[index[icell]] = clus->GetTOF();
732  fCellMatchdEta[index[icell]] = clus->GetTrackDz();
733  fCellMatchdPhi[index[icell]] = clus->GetTrackDx();
734 
736  {
737  fCellLabels[index[icell]] = label;
738  fCellSecondLabels[index[icell]] = label2;
739  }
740  }
741  }
742  }
743 
744  // Do here induced cell energy assignation by T-Card correlation emulation, ONLY MC
746 
747  //
748  // Transform CaloCells into Digits
749  //
750  Int_t idigit = 0;
751  Int_t id = -1;
752  Float_t amp = -1;
753  Double_t time = -1;
754 
755  Int_t bc = InputEvent()->GetBunchCrossNumber();
756 
757  for (Int_t icell = 0; icell < fCaloCells->GetNumberOfCells(); icell++)
758  {
759  // Get cell values, recalibrate and not include bad channels found in analysis, nor cells with too low energy, nor exotic cell
760  id = fCaloCells->GetCellNumber(icell);
761  Bool_t accept = fRecoUtils->AcceptCalibrateCell(id,bc,amp,time,fCaloCells);
762  time-=fConstantTimeShift*1e-9; // only in case of simulations done before 2015
763 
764  // Do not include cells with too low energy, nor exotic cell
765  if( amp < fRecParam->GetMinECut() ||
766  time > fRecParam->GetTimeMax() ||
767  time < fRecParam->GetTimeMin() ) accept = kFALSE;
768 
769  // In case of old AOD analysis cell time is -1 s, approximate replacing by time of the cluster the digit belongs.
771  {
772  time = fCellTime[id];
773  //printf("cell %d time org %f - ",id, time*1.e9);
774  fRecoUtils->RecalibrateCellTime(id,bc,time);
775  //printf("recal %f\n",time*1.e9);
776  }
777 
778  //Exotic?
779  if (accept && fRecoUtils->IsExoticCell(id,fCaloCells,bc))
780  accept = kFALSE;
781 
782  if( !accept )
783  {
784  AliDebug(2,Form("Remove channel absId %d, index %d of %d, amp %f, time %f",
785  id,icell, fCaloCells->GetNumberOfCells(), amp, time*1.e9));
786  continue;
787  }
788 
789  //
790  // MC
791  //
792 
793  // Old way
794  Int_t mcLabel = fCaloCells->GetMCLabel(icell);
795  Float_t eDep = amp;
796 
797  //printf("--- Selected cell %d--- amp %f\n",id,amp);
798 
799  // New way
800  TArrayI labeArr(0);
801  TArrayF eDepArr(0);
802  Int_t nLabels = 0;
803 
805  {
806  // Old way to recover/set the cell MC label
807  // Only possibility for old Run1 productions
808 
809  if ( fSetCellMCLabelFromCluster == 1 ) mcLabel = fCellLabels[id]; // Older aliroot MC productions
810 
811  else if( fSetCellMCLabelFromCluster == 0 &&
813 
814  else mcLabel = -1; // found later
815 
816  // Last parameter of the digit object should be MC deposited energy,
817  // since it is not available in aliroot before year 2016, add just the cell amplitude so that
818  // we give more weight to the MC label of the cell with highest energy in the cluster
819 
820  Float_t efrac = fCaloCells->GetEFraction(icell);
821 
822  // When checking the MC of digits, give weight to cells with embedded signal
823  if (mcLabel > 0 && efrac < 1.e-6) efrac = 1;
824 
825  eDep *= efrac ;
826  }
827  else // fSetCellMCLabelFromEdepFrac = true
828  {
829  // New way, valid only for MC productions with aliroot > v5-07-21
830  mcLabel = -1;
831 
832  // Map the digit to cell index for later to calculate the cell MC energy deposition map
833  fCellLabels[id] = idigit;
834  //printf("\t absId %d, idigit %d\n",id,idigit);
835 
836  if(fOrgClusterCellId[id] < 0) continue; // index can be negative if noisy cell that did not form cluster
837 
838  AliVCluster *clus = 0;
839  Int_t iclus = fOrgClusterCellId[id];
840 
841  if(iclus < 0)
842  {
843  AliInfo("Negative original cluster index, skip \n");
844  continue;
845  }
846 
847  if(aodIH && aodIH->GetEventToMerge()) //Embedding
848  clus = aodIH->GetEventToMerge()->GetCaloCluster(iclus); //Get clusters directly from embedded signal
849  else
850  clus = fEvent->GetCaloCluster(iclus);
851 
852  fRecoUtils->RecalculateCellLabelsRemoveAddedGenerator(id, clus, MCEvent(), amp, labeArr, eDepArr);
853  nLabels = labeArr.GetSize();
854 
855  } // cell MC label, new
856 
857  // Apply here the found induced energies
858  if ( fTCardCorrEmulation )
859  {
860 // if( TMath::Abs(fTCardCorrCellsEner[id]) > 0.001 )
861 // printf("add energy to digit %d, absId %d: amp %2.2f + %2.2f\n",idigit,id,amp,fTCardCorrCellsEner[id]);
862  amp+=fTCardCorrCellsEner[id];
863  }
864 
865  //
866  // Create the digit
867  //
868  if(amp <= 0.01) continue ; // accept if > 10 MeV
869 
870  //if(amp > 1.5)printf("*** Add digit *** amp %f, nlabels %d, label %d, found %d, edep fract tot %f, ncluslabels %d\n",amp, nLabels,mcLabel,found,edepTotFrac,nClusLabels);
871 
872  AliEMCALDigit* digit = new((*fDigitsArr)[idigit]) AliEMCALDigit( mcLabel, mcLabel, id, amp, time,AliEMCALDigit::kHG,idigit, 0, 0, eDep);
873 
874  if(nLabels > 0)
875  digit->SetListOfParents(nLabels,labeArr.GetArray(),eDepArr.GetArray());
876 
877  idigit++;
878 
879  }
880 
881  fDigitsArr->Sort();
882 
883  // Call after Sort, if not it screws up digits index order in clusterization
885 
886 
887  //-------------------------------------------------------------------------------------
888  // Do the clusterization
889  //-------------------------------------------------------------------------------------
890 
891  fClusterizer->Digits2Clusters("");
892 
893  //-------------------------------------------------------------------------------------
894  // Transform the recpoints into AliVClusters
895  //-------------------------------------------------------------------------------------
896 
898 
899  if(!fCaloClusterArr)
900  {
901  AliWarning(Form("No array with CaloClusters, input RecPoints entries %d",fClusterArr->GetEntriesFast()));
902  return;
903  }
904 
905  AliDebug(1,Form("N clusters: before recluster %d, after recluster %d, recpoints %d",
906  nClustersOrg, fCaloClusterArr->GetEntriesFast(),fClusterArr->GetEntriesFast()));
907 
908 // if(fCaloClusterArr->GetEntriesFast() != fClusterArr->GetEntriesFast())
909 // {
910 // AliInfo("\t Some RecRoints not transformed into CaloClusters (clusterizer %d, unfold %d): Input entries %d - Output entries %d - %d (not fast)\n",
911 // fRecParam->GetClusterizerFlag(),fRecParam->GetUnfold(),
912 // fClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntries());
913 // }
914 }
915 
916 
917 //_____________________________________________________
919 //_____________________________________________________
921 {
922  Double_t cellAmplitude = 0;
923  Double_t cellTime = 0;
924  Short_t cellNumber = 0;
925  Int_t cellMCLabel = 0;
926  Double_t cellEFrac = 0;
927  Int_t nClustersOrg = 0;
928 
929  // Fill the array with the EMCAL clusters, copy them
930  for (Int_t i = 0; i < fEvent->GetNumberOfCaloClusters(); i++)
931  {
932  AliVCluster *clus = fEvent->GetCaloCluster(i);
933  if(clus->IsEMCAL())
934  {
935  //recalibrate/remove bad channels/etc if requested
936  if(fRecoUtils->ClusterContainsBadChannel(fGeom,clus->GetCellsAbsId(), clus->GetNCells()))
937  {
938  continue;
939  }
940 
941  if(fRecoUtils->IsRecalibrationOn())
942  {
943  //Calibrate cluster
944  fRecoUtils->RecalibrateClusterEnergy(fGeom, clus, fCaloCells);
945 
946  //CalibrateCells
947  for (Int_t icell = 0; icell < fCaloCells->GetNumberOfCells(); icell++)
948  {
949  if (fCaloCells->GetCell(icell, cellNumber, cellAmplitude, cellTime, cellMCLabel, cellEFrac) != kTRUE)
950  break;
951 
952  Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
953  fGeom->GetCellIndex(cellNumber,imod,iTower,iIphi,iIeta);
954  fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
955 
956  //Do not include bad channels found in analysis?
957  if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
958  fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
959  continue;
960 
961  fCaloCells->SetCell(icell, cellNumber, cellAmplitude*fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),cellTime);
962 
963  }// cells loop
964  }// recalibrate
965 
966  //Cast to ESD or AOD, needed to create the cluster array
967  AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
968  AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
969 
970  if (esdCluster)
971  {
972  fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
973  }//ESD
974  else if(aodCluster)
975  {
976  fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
977  }//AOD
978  else
979  AliWarning("Wrong CaloCluster type?");
980 
981  nClustersOrg++;
982  }
983  }
984 
985  //Do the unfolding
986  fUnfolder->UnfoldClusters(fCaloClusterArr, fCaloCells);
987 
988  //CLEAN-UP
989  fUnfolder->Clear();
990 }
991 
992 //_____________________________________________________
994 //_____________________________________________________
996 {
997  AliVCaloCells &eventEMcells = *(fEvent->GetEMCALCells());
998  Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
999 
1000  AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
1001  aodEMcells.CreateContainer(nEMcell);
1002  aodEMcells.SetType(AliVCaloCells::kEMCALCell);
1003  Double_t calibFactor = 1.;
1004  for (Int_t iCell = 0; iCell < nEMcell; iCell++)
1005  {
1006  Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
1007  fGeom->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
1008  fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
1009 
1010  if(fRecoUtils->IsRecalibrationOn())
1011  {
1012  calibFactor = fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
1013  }
1014 
1015  if(!fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
1016  { //Channel is not declared as bad
1017  aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor,
1018  eventEMcells.GetTime(iCell),eventEMcells.GetMCLabel(iCell),eventEMcells.GetEFraction(iCell));
1019  }
1020  else
1021  {
1022  aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0,-1,-1,0);
1023  }
1024  }
1025 
1026  aodEMcells.Sort();
1027 }
1028 
1029 //__________________________________________________
1031 //__________________________________________________
1033 {
1034  AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (fEvent);
1035  AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (fEvent);
1036 
1037  Double_t pos[3] ;
1038  Double_t covVtx[6];
1039  for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
1040 
1041  AliAODHeader* header = dynamic_cast<AliAODHeader*>(AODEvent()->GetHeader());
1042  if(!header) AliFatal("Not a standard AOD");
1043  header->SetRunNumber(fEvent->GetRunNumber());
1044 
1045  if(esdevent)
1046  {
1047  TTree* tree = fInputHandler->GetTree();
1048  if (tree)
1049  {
1050  TFile* file = tree->GetCurrentFile();
1051  if (file) header->SetESDFileName(file->GetName());
1052  }
1053  }
1054  else if (aodevent) {
1055  AliAODHeader * aodheader = dynamic_cast<AliAODHeader*>(aodevent->GetHeader());
1056  if(!aodheader) AliFatal("Not a standard AOD");
1057  header->SetESDFileName(aodheader->GetESDFileName());
1058  }
1059 
1060  header->SetBunchCrossNumber(fEvent->GetBunchCrossNumber());
1061  header->SetOrbitNumber(fEvent->GetOrbitNumber());
1062  header->SetPeriodNumber(fEvent->GetPeriodNumber());
1063  header->SetEventType(fEvent->GetEventType());
1064 
1065  // Centrality
1066  if(fUseAliCentrality)
1067  {
1068  if(fEvent->GetCentrality())
1069  header->SetCentrality(new AliCentrality(*(fEvent->GetCentrality())));
1070  else
1071  header->SetCentrality(0);
1072  }
1073 
1074  // Trigger
1075  header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
1076 
1077  header->SetFiredTriggerClasses(fEvent->GetFiredTriggerClasses());
1078 
1079  header->SetTriggerMask(fEvent->GetTriggerMask());
1080  header->SetTriggerCluster(fEvent->GetTriggerCluster());
1081 
1082  if (esdevent)
1083  {
1084  header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());
1085  header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());
1086  header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());
1087  }
1088  else if (aodevent)
1089  {
1090  header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());
1091  header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());
1092  header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());
1093  }
1094 
1095  header->SetMagneticField(fEvent->GetMagneticField());
1096  //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.);
1097 
1098  header->SetZDCN1Energy(fEvent->GetZDCN1Energy());
1099  header->SetZDCP1Energy(fEvent->GetZDCP1Energy());
1100  header->SetZDCN2Energy(fEvent->GetZDCN2Energy());
1101  header->SetZDCP2Energy(fEvent->GetZDCP2Energy());
1102  header->SetZDCEMEnergy(fEvent->GetZDCEMEnergy(0),fEvent->GetZDCEMEnergy(1));
1103 
1104  Float_t diamxy[2]={(Float_t)fEvent->GetDiamondX(),(Float_t)fEvent->GetDiamondY()};
1105  Float_t diamcov[3];
1106  fEvent->GetDiamondCovXY(diamcov);
1107  header->SetDiamond(diamxy,diamcov);
1108  if (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
1109  else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
1110 
1111  //
1112  Int_t nVertices = 1 ;/* = prim. vtx*/;
1113  Int_t nCaloClus = fEvent->GetNumberOfCaloClusters();
1114 
1115  AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
1116 
1117  // Access to the AOD container of vertices
1118  TClonesArray &vertices = *(AODEvent()->GetVertices());
1119  Int_t jVertices=0;
1120 
1121  // Add primary vertex. The primary tracks will be defined
1122  // after the loops on the composite objects (V0, cascades, kinks)
1123  fEvent->GetPrimaryVertex()->GetXYZ(pos);
1124  Float_t chi = 0;
1125  if (esdevent)
1126  {
1127  esdevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
1128  chi = esdevent->GetPrimaryVertex()->GetChi2toNDF();
1129  }
1130  else if (aodevent)
1131  {
1132  aodevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
1133  chi = aodevent->GetPrimaryVertex()->GetChi2perNDF();//Different from ESD?
1134  }
1135 
1136  AliAODVertex * primary = new(vertices[jVertices++])
1137  AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
1138  primary->SetName(fEvent->GetPrimaryVertex()->GetName());
1139  primary->SetTitle(fEvent->GetPrimaryVertex()->GetTitle());
1140 }
1141 
1142 //___________________________________________________________
1146 //___________________________________________________________
1148 {
1149  // First recalculate track-matching for the new clusters
1150  if(fDoTrackMatching)
1151  {
1152  fRecoUtils->FindMatches(fEvent,fCaloClusterArr,fGeom,MCEvent());
1153  }
1154 
1155  // Put the new clusters in the AOD list
1156 
1157  Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntriesFast();
1158 
1159  for(Int_t i = 0; i < kNumberOfCaloClusters; i++)
1160  {
1161  AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
1162 
1163  newCluster->SetID(i);
1164 
1165  // Correct cluster energy non linearity
1166  newCluster->SetE(fRecoUtils->CorrectClusterEnergyLinearity(newCluster));
1167 
1168  //Add matched track
1169  if(fDoTrackMatching)
1170  {
1171  Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
1172  if(trackIndex >= 0)
1173  {
1174  newCluster->AddTrackMatched(fEvent->GetTrack(trackIndex));
1175  AliDebug(2,Form("Matched Track index %d to new cluster %d",trackIndex,i));
1176  }
1177 
1178  Float_t dR = 999., dZ = 999.;
1179  fRecoUtils->GetMatchedResiduals(newCluster->GetID(),dZ,dR);
1180  newCluster->SetTrackDistance(dR,dZ);
1181  }
1182  else
1183  {// Assign previously assigned matched track in reco, very very rough
1184  Int_t absId0 = newCluster->GetCellsAbsId()[0]; // Assign match of first cell in cluster
1185  newCluster->SetTrackDistance(fCellMatchdPhi[absId0],fCellMatchdEta[absId0]);
1186  }
1187 
1188  //printf("New cluster E %f, Time %e, Id = ", newCluster->E(), newCluster->GetTOF() );
1189  //for(Int_t icell=0; icell < newCluster->GetNCells(); icell++ ) printf(" %d,", newCluster->GetCellsAbsId() [icell] );
1190  //printf("\n");
1191  //
1192  //printf("New cluster %d) ID = %d, E %2.2f, Time %3.0f, N Cells %d, N MC labels %d, main MC label %d, all MC labels:\n",
1193  // i, newCluster->GetID(), newCluster->E(), newCluster->GetTOF()*1e9, newCluster->GetNCells(), newCluster->GetNLabels(), newCluster->GetLabel());
1194  //
1195  //for(Int_t imc = 0; imc < newCluster->GetNLabels(); imc++)
1196  // printf("%d) Label %d, E dep frac %0.2f; ",
1197  // imc,newCluster->GetLabelAt(imc),newCluster->GetClusterMCEdepFraction(imc));
1198  //if(newCluster->GetNLabels() > 0) printf("\n");
1199 
1200  // Calculate distance to bad channel for new cluster. Make sure you give the list of bad channels.
1201  fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, fCaloCells, newCluster);
1202 
1203  new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
1204 
1205  AliDebug(2,Form("New cluster %d of %d, energy %f, mc label %d",
1206  newCluster->GetID(), kNumberOfCaloClusters, newCluster->E(), newCluster->GetLabel()));
1207 
1208  } // cluster loop
1209 
1210  fOutputAODBranch->Expand(kNumberOfCaloClusters); // resize TObjArray to 'remove' slots
1211 }
1212 
1213 
1214 //________________________________________________________________
1216 //________________________________________________________________
1218 {
1219  if(fUseAliCentrality)
1220  {
1221  if(GetCentrality()) return GetCentrality()->GetCentralityPercentile(fCentralityClass) ;
1222  else return -1. ;
1223  }
1224  else
1225  {
1226  if(GetMultSelCen()) return GetMultSelCen()->GetMultiplicityPercentile(fCentralityClass,kTRUE) ;
1227  else return -1. ;
1228  }
1229 
1230  return -1.;
1231 }
1232 
1233 //_______________________________________________
1235 //_______________________________________________
1237 {
1238  if (!AliAnalysisManager::GetAnalysisManager()->GetTree())
1239  {
1240  AliError("AliAnalysisTaskEMCALClusterize::GetPass() - Pointer to tree = 0, returning null");
1241  return TString("");
1242  }
1243 
1244  if (!AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile())
1245  {
1246  AliError("AliAnalysisTaskEMCALClusterize::GetPass() - Null pointer input file, returning null");
1247  return TString("");
1248  }
1249 
1250  TString pass(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
1251  if (pass.Contains("ass1")) return TString("pass1");
1252  else if (pass.Contains("ass2")) return TString("pass2");
1253  else if (pass.Contains("ass3")) return TString("pass3");
1254  else if (pass.Contains("ass4")) return TString("pass4");
1255  else if (pass.Contains("ass5")) return TString("pass5");
1256  else if (pass.Contains("LHC11c") && pass.Contains("spc_calo") ) return TString("spc_calo");
1257  else if (pass.Contains("calo") || pass.Contains("high_lumi"))
1258  {
1259  AliInfo("Path contains <calo> or <high-lumi>, set as <pass1>");
1260  return TString("pass1");
1261  }
1262  else if (pass.Contains("LHC14a1a"))
1263  {
1264  AliInfo("Enable EMCal energy calibration for this MC production!!");
1265 
1266  fRecoUtils->SwitchOnRecalibration();
1267 
1268  return TString("LHC14a1a");
1269  }
1270 
1271  // No condition fullfilled, give a default value
1272  AliInfo("Pass number string not found");
1273 
1274  return TString("");
1275 }
1276 
1277 //_________________________________________
1280 //_________________________________________
1282 {
1283  if(fDebug >=0) (AliAnalysisManager::GetAnalysisManager())->AddClassDebug(this->ClassName(),fDebug);
1284 
1285  fOADBSet = kFALSE;
1286  if(fOADBFilePath == "") fOADBFilePath = "$ALICE_PHYSICS/OADB/EMCAL" ;
1287 
1288  fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
1289 
1290  if(!fRecParam) fRecParam = new AliEMCALRecParam;
1291  if(!fRecoUtils) fRecoUtils = new AliEMCALRecoUtils();
1292 
1293  if(fMaxEvent <= 0) fMaxEvent = 1000000000;
1294  if(fSelectCellMinE <= 0) fSelectCellMinE = 0.005;
1295  if(fSelectCellMinFrac <= 0) fSelectCellMinFrac = 0.001;
1296  fRejectBelowThreshold = kFALSE;
1297 
1298  // Centrality
1299  if(fCentralityClass == "") fCentralityClass = "V0M";
1300 
1301  if (fOCDBpath == "") fOCDBpath = "raw://" ;
1302  if (fOutputAODBranchName == "") fOutputAODBranchName = "newEMCALClusters" ;
1303 
1304  if(gROOT->LoadMacro(fConfigName) >=0)
1305  {
1306  AliInfo(Form("Configure analysis with %s",fConfigName.Data()));
1307  AliAnalysisTaskEMCALClusterize *clus = (AliAnalysisTaskEMCALClusterize*)gInterpreter->ProcessLine("ConfigEMCALClusterize()");
1308  fGeomName = clus->fGeomName;
1310  fOCDBpath = clus->fOCDBpath;
1311  fAccessOCDB = clus->fAccessOCDB;
1312  fRecParam = clus->fRecParam;
1313  fJustUnfold = clus->fJustUnfold;
1314  fFillAODFile = clus->fFillAODFile;
1315  fRecoUtils = clus->fRecoUtils;
1316  fConfigName = clus->fConfigName;
1317  fMaxEvent = clus->fMaxEvent;
1319  fUpdateCell = clus->fUpdateCell;
1321  for(Int_t i = 0; i < 22; i++) fGeomMatrix[i] = clus->fGeomMatrix[i] ;
1323  fCentralityBin[0] = clus->fCentralityBin[0];
1324  fCentralityBin[1] = clus->fCentralityBin[1];
1326  }
1327 }
1328 
1329 //_______________________________________________________
1332 //_______________________________________________________
1334 {
1335  if (fJustUnfold)
1336  {
1337  // init the unfolding afterburner
1338  delete fUnfolder;
1339  fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut(),fRecParam->GetMinECut());
1340  return;
1341  }
1342 
1343  //First init the clusterizer
1344  delete fClusterizer;
1345  if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
1346  fClusterizer = new AliEMCALClusterizerv1 (fGeom);
1347  else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
1348  fClusterizer = new AliEMCALClusterizerv2(fGeom);
1349  else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
1350  {
1351  fClusterizer = new AliEMCALClusterizerNxN(fGeom);
1352  fClusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
1353  fClusterizer->SetNColDiff(fRecParam->GetNColDiff());
1354  }
1355  else
1356  {
1357  AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
1358  }
1359 
1360  //Now set the parameters
1361  fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
1362  fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
1363  fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
1364  fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
1365  fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
1366  fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
1367  fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
1368  fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
1369  fClusterizer->SetTimeCalibration ( fRecParam->IsTimeCalibrationOn() );
1370  fClusterizer->SetInputCalibrated ( kTRUE );
1371  fClusterizer->SetJustClusters ( kTRUE );
1372 
1373  // Initialize the cluster rec points and digits arrays and get them.
1374  fClusterizer->SetOutput(0);
1375  fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
1376  fDigitsArr = fClusterizer->GetDigits();
1377 
1378  //In case of unfolding after clusterization is requested, set the corresponding parameters
1379  if(fRecParam->GetUnfold())
1380  {
1381  Int_t i=0;
1382  for (i = 0; i < 8; i++)
1383  {
1384  fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
1385  }//end of loop over parameters
1386 
1387  for (i = 0; i < 3; i++)
1388  {
1389  fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
1390  fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
1391  }//end of loop over parameters
1392  fClusterizer->SetRejectBelowThreshold(fRejectBelowThreshold);//here we set option of unfolding: split or reject energy
1393  fClusterizer->InitClusterUnfolding();
1394 
1395  }// to unfold
1396 }
1397 
1398 //_________________________________________________
1402 //_________________________________________________
1404 {
1405  if(fGeomMatrixSet) return;
1406 
1407  Int_t runnumber = InputEvent()->GetRunNumber() ;
1408  if (!fGeom)
1409  {
1410  if(fGeomName=="")
1411  {
1412  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(runnumber);
1413  AliInfo(Form("Get EMCAL geometry name <%s> for run %d",fGeom->GetName(),runnumber));
1414  }
1415  else
1416  {
1417  fGeom = AliEMCALGeometry::GetInstance(fGeomName);
1418  AliInfo(Form("Set EMCAL geometry name to <%s>",fGeomName.Data()));
1419  }
1420 
1421  // Init geometry, I do not like much to do it like this ...
1422  if(fImportGeometryFromFile && !gGeoManager)
1423  {
1424  if(fImportGeometryFilePath=="") // If not specified, set location depending on run number
1425  {
1426  // "$ALICE_ROOT/EVE/alice-data/default_geo.root"
1427  if (runnumber < 140000) fImportGeometryFilePath = "$ALICE_PHYSICS/OADB/EMCAL/geometry_2010.root";
1428  else if (runnumber < 171000) fImportGeometryFilePath = "$ALICE_PHYSICS/OADB/EMCAL/geometry_2011.root";
1429  else if (runnumber < 198000) fImportGeometryFilePath = "$ALICE_PHYSICS/OADB/EMCAL/geometry_2012.root"; // 2012-2013
1430  else fImportGeometryFilePath = "$ALICE_PHYSICS/OADB/EMCAL/geometry_2015.root"; // >=2015
1431  }
1432 
1433  AliInfo(Form("Import %s",fImportGeometryFilePath.Data()));
1434 
1435  TGeoManager::Import(fImportGeometryFilePath) ;
1436  }
1437 
1438  AliDebug(1,Form("Init for run=%d",runnumber));
1439  if (!gGeoManager) AliDebug(1,"Careful!, gGeoManager not loaded, load misalign matrices");
1440  } // geometry pointer did not exist before
1441 
1442  if(fLoadGeomMatrices)
1443  {
1444  AliInfo("Load user defined EMCAL geometry matrices");
1445 
1446  // OADB if available
1447  AliOADBContainer emcGeoMat("AliEMCALgeo");
1448  emcGeoMat.InitFromFile(Form("%s/EMCALlocal2master.root",fOADBFilePath.Data()),"AliEMCALgeo");
1449  TObjArray *matEMCAL=(TObjArray*)emcGeoMat.GetObject(runnumber,"EmcalMatrices");
1450 
1451  for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
1452  {
1453 
1454  if (!fGeomMatrix[mod]) // Get it from OADB
1455  {
1456  AliDebug(2,Form("EMCAL matrices SM %d, %p",mod,((TGeoHMatrix*) matEMCAL->At(mod))));
1457  //((TGeoHMatrix*) matEMCAL->At(mod))->Print();
1458 
1459  fGeomMatrix[mod] = (TGeoHMatrix*) matEMCAL->At(mod) ;
1460  }
1461 
1462  if(fGeomMatrix[mod])
1463  {
1464  if(DebugLevel() > 1)
1465  fGeomMatrix[mod]->Print();
1466 
1467  fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
1468  }
1469  else if(gGeoManager)
1470  {
1471  AliWarning(Form("Set matrix for SM %d from gGeoManager",mod));
1472  fGeom->SetMisalMatrix(fGeom->GetMatrixForSuperModuleFromGeoManager(mod),mod) ;
1473  }
1474  else
1475  {
1476  AliError(Form("Alignment atrix for SM %d is not available",mod));
1477  }
1478 
1479  fGeomMatrixSet=kTRUE;
1480 
1481  }//SM loop
1482  }//Load matrices
1483  else if(!gGeoManager)
1484  {
1485  AliInfo("AliAnalysisTaksEMCALClusterize::InitGeometry() - Get geo matrices from data");
1486  //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
1487  if(!strcmp(fEvent->GetName(),"AliAODEvent"))
1488  {
1489  AliWarning("Use ideal geometry, values geometry matrix not kept in AODs");
1490  }//AOD
1491  else
1492  {
1493  AliDebug(1,"Load Misaligned matrices");
1494 
1495  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(fEvent) ;
1496 
1497  if(!esd)
1498  {
1499  AliError("This event does not contain ESDs?");
1500  if(fFillAODFile) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);
1501  return;
1502  }
1503 
1504  for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
1505  {
1506  if(DebugLevel() > 1)
1507  esd->GetEMCALMatrix(mod)->Print();
1508 
1509  if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
1510 
1511  }
1512 
1513  fGeomMatrixSet=kTRUE;
1514 
1515  } // ESD
1516  } // Load matrices from Data
1517 }
1518 
1519 //____________________________________________________
1524 //____________________________________________________
1526 {
1527  if(!fRemoveExoticEvents) return kFALSE;
1528 
1529  // Loop on cells
1530 
1531  Float_t totCellE = 0;
1532  Int_t bc = InputEvent()->GetBunchCrossNumber();
1533 
1534  for(Int_t icell = 0; icell < fCaloCells->GetNumberOfCells(); icell++)
1535  {
1536  Float_t ecell = 0 ;
1537  Double_t tcell = 0 ;
1538 
1539  Int_t absID = fCaloCells->GetCellNumber(icell);
1540  Bool_t accept = fRecoUtils->AcceptCalibrateCell(absID,bc,ecell,tcell,fCaloCells);
1541  tcell-=fConstantTimeShift*1e-9;// Only for MC simulations done before 2015
1542 
1543  if(accept && !fRecoUtils->IsExoticCell(absID,fCaloCells,bc)) totCellE += ecell;
1544  }
1545 
1546  // TString triggerclasses = event->GetFiredTriggerClasses();
1547  // printf("AliAnalysisTaskEMCALClusterize - reject event %d with cluster - reject event with ncells in SM3 %d and SM4 %d\n",(Int_t)Entry(),ncellsSM3, ncellsSM4);
1548  // if(fFillAODFile) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);;
1549  // return;
1550  //
1551 
1552  //printf("TotE cell %f\n",totCellE);
1553  if(totCellE < 1) return kTRUE;
1554 
1555  return kFALSE;
1556 }
1557 
1558 //________________________________________________________________
1560 //________________________________________________________________
1562 {
1563  if(!fRemoveLEDEvents) return kFALSE;
1564 
1565  //check events of LHC11a period
1566  if(run < 146858 || run > 146860) return kFALSE ;
1567 
1568  // Count number of cells with energy larger than 0.1 in SM3, cut on this number
1569  Int_t ncellsSM3 = 0;
1570  for(Int_t icell = 0; icell < fCaloCells->GetNumberOfCells(); icell++)
1571  {
1572  if ( fCaloCells->GetAmplitude (icell) > 0.1 &&
1573  fCaloCells->GetCellNumber(icell)/(24*48)==3 ) ncellsSM3++;
1574  }
1575 
1576  TString triggerclasses = fEvent->GetFiredTriggerClasses();
1577 
1578  Int_t ncellcut = 21;
1579  if(triggerclasses.Contains("EMC")) ncellcut = 35;
1580 
1581  if( ncellsSM3 >= ncellcut)
1582  {
1583  AliInfo(Form("Reject event %d with ncells in SM3 %d",(Int_t)Entry(),ncellsSM3));
1584  if(fFillAODFile) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kFALSE);;
1585  return kTRUE;
1586  }
1587 
1588  return kFALSE;
1589 }
1590 
1591 
1592 //_______________________________________________________
1595 //_______________________________________________________
1597 {
1598  Int_t id = -1;
1599  Float_t amp = -1;
1600 
1601  // Loop on all cells with signal
1602  for (Int_t icell = 0; icell < fCaloCells->GetNumberOfCells(); icell++)
1603  {
1604  id = fCaloCells->GetCellNumber(icell);
1605  amp = fCaloCells->GetAmplitude (icell); // fCaloCells->GetCellAmplitude(id);
1606 
1607  //
1608  // First get the SM, col-row of this tower
1609  Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
1610  fGeom->GetCellIndex(id,imod,iTower,iIphi,iIeta);
1611  fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
1612 
1613  //
1614  // Determine randomly if we want to create a correlation for this cell,
1615  // depending the SM number of the cell
1616  Float_t rand = fRandom.Uniform(0, 1);
1617 
1618 // printf("icell %d, absId %d, ism %d, icol %d, irow %d, random %2.2f > %2.2f ?; \n \t amp %2.3f added before %2.3f\n",
1619 // icell,id,imod,ieta,iphi,rand,fTCardCorrInduceEnerProb[imod],amp,fTCardCorrCellsEner[id]);
1620 
1621  if ( rand > fTCardCorrInduceEnerProb[imod] ) continue;
1622 
1623  //
1624  // Get the absId of the cells in the cross and same T-Card
1625  Int_t absIDr1 = -1;
1626  Int_t absIDr2 = -1;
1627  Int_t absIDc = -1;
1628  Int_t absIDc1 = -1;
1629  Int_t absIDc2 = -1;
1630 
1631  if ( iphi < AliEMCALGeoParams::fgkEMCALRows-1 ) absIDr1 = fGeom->GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta);
1632  if ( iphi > 0 ) absIDr2 = fGeom->GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta);
1633 
1634  // Only cells in same column and same T-Card
1635  if ( TMath::FloorNint(iphi/8) != TMath::FloorNint((iphi+1)/8) ) absIDr1 = -1;
1636  if ( TMath::FloorNint(iphi/8) != TMath::FloorNint((iphi-1)/8) ) absIDr2 = -1;
1637 
1638  // Only one cell in the same row belongs to the same TCard, +1 for even and -1 for odd
1639  Int_t colShift = 0;
1640  if ( (ieta%2) && ieta <= AliEMCALGeoParams::fgkEMCALCols-1 ) colShift = -1;
1641  if ( !(ieta%2) && ieta >= 0 ) colShift = +1;
1642 
1643  absIDc1 = fGeom->GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta+colShift);
1644  absIDc2 = fGeom->GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta+colShift);
1645  absIDc = fGeom->GetAbsCellIdFromCellIndexes(imod, iphi , ieta+colShift);
1646 
1647 // printf("\t cross absId: r1 %d, r2 %d, c %d\n",absIDr1,absIDr2,absIDc);
1648 // if ( absIDc < 0 ) printf( "\t \t *** ism %d, iphi %d, ieta %d; absId(ieta+1) %d, absId(ieta-1) %d, mod eta %d, max eta %d\n",imod,iphi,ieta,
1649 // fGeom->GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1),fGeom->GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1),
1650 // ieta%2, AliEMCALGeoParams::fgkEMCALCols-1);
1651 // if ( absIDr1 < 0 ) printf( "\t \t *** ism %d, iphi %d, ieta %d; absId(iphi+1) %d\n",imod,iphi,ieta,
1652 // fGeom->GetAbsCellIdFromCellIndexes(imod, iphi, iphi+1));
1653 //
1654 // if ( absIDr2 < 0 ) printf( "\t \t *** ism %d, iphi %d, ieta %d; absId(iphi-1) %d\n",imod,iphi,ieta,
1655 // fGeom->GetAbsCellIdFromCellIndexes(imod, iphi, iphi-1));
1656 
1657  //
1658  // Check if they are not declared bad
1659  // REMEMBER, do it properly instead of taking this complex method!!!!
1660  Bool_t okr1 = kTRUE;
1661  Bool_t okr2 = kTRUE;
1662  Bool_t okc = kTRUE;
1663  Bool_t okc1 = kTRUE;
1664  Bool_t okc2 = kTRUE;
1665 
1666  Float_t ecell = 0.;
1667  Double_t tcell = 0.;
1668 
1669  okr1 = fRecoUtils->AcceptCalibrateCell(absIDr1, 0, ecell, tcell, fCaloCells);
1670  okr2 = fRecoUtils->AcceptCalibrateCell(absIDr2, 0, ecell, tcell, fCaloCells);
1671  okc = fRecoUtils->AcceptCalibrateCell(absIDc , 0, ecell, tcell, fCaloCells);
1672  okc1 = fRecoUtils->AcceptCalibrateCell(absIDc1, 0, ecell, tcell, fCaloCells);
1673  okc2 = fRecoUtils->AcceptCalibrateCell(absIDc2, 0, ecell, tcell, fCaloCells);
1674 
1675 // if(amp > 2)
1676 // printf("ecell %2.2f, amp %2.2f: F1 %2.2e, F2 %2.2e, F3 %2.2e; w1 %2.2e w2 %2.2e w3 %2.2e \n",ecell,amp,
1677 // fTCardCorrInduceEnerFrac[0]+amp*fTCardCorrInduceEnerFracP1[0],
1678 // fTCardCorrInduceEnerFrac[1]+amp*fTCardCorrInduceEnerFracP1[1],
1679 // fTCardCorrInduceEnerFrac[1]+amp*fTCardCorrInduceEnerFracP1[2],
1680 // fTCardCorrInduceEnerFracWidth[0],fTCardCorrInduceEnerFracWidth[1],fTCardCorrInduceEnerFracWidth[2]);
1681  //
1682  // Generate some energy for the nearby cells in same TCard , depending on this cell energy
1683  // Check if originally the tower had no or little energy, in which case tag it as new
1685  Float_t fracCupdown = fRandom.Gaus(fTCardCorrInduceEnerFrac[1]+amp*fTCardCorrInduceEnerFracP1[1],fTCardCorrInduceEnerFracWidth[1]);
1686  Float_t fracC = fRandom.Gaus(fTCardCorrInduceEnerFrac[2]+amp*fTCardCorrInduceEnerFracP1[2],fTCardCorrInduceEnerFracWidth[2]);
1687 
1688 // // CAREFUL: <<Apply the same added shift to all>>.
1689 // Float_t fracCupdown = fracRupdown;
1690 // Float_t fracC = fracRupdown;
1691 
1692 // printf("\t Added energy (fractions %2.3f-%2.3f-%2.3f) -> gaus (%2.3f-%2.3f-%2.3f) on top of previous %2.3f: \n",
1693 // fTCardCorrInduceEnerFrac[0], fTCardCorrInduceEnerFrac[1], fTCardCorrInduceEnerFrac[2],
1694 // fracRupdown,fracC,fracCupdown, fTCardCorrCellsEner[id]);
1695 
1696  if ( okr1 )
1697  {
1698  fTCardCorrCellsEner[absIDr1] += amp*fracRupdown;
1699  if ( fCaloCells->GetCellAmplitude(absIDr1) < 0.01 ) fTCardCorrCellsNew[absIDr1] = kTRUE;
1700 // printf("\t \t r1 absId %d induced amp %2.3f, accumulated %2.3f (new %d); \n",
1701 // absIDr1,amp*fracRupdown,fTCardCorrCellsEner[absIDr1],fTCardCorrCellsNew[absIDr1]);
1702  }
1703 
1704  if ( okr2 )
1705  {
1706  fTCardCorrCellsEner[absIDr2] += amp*fracRupdown;
1707  if ( fCaloCells->GetCellAmplitude(absIDr2) < 0.01 ) fTCardCorrCellsNew[absIDr2] = kTRUE;
1708 // printf("\t \t r2 absId %d induced amp %2.3f, accumulated %2.3f (new %d);\n ",
1709 // absIDr2,amp*fracRupdown,fTCardCorrCellsEner[absIDr2],fTCardCorrCellsNew[absIDr2]);
1710  }
1711 
1712  if ( okc )
1713  {
1714  fTCardCorrCellsEner[absIDc] += amp*fracC;
1715  if ( fCaloCells->GetCellAmplitude(absIDc ) < 0.01 ) fTCardCorrCellsNew[absIDc] = kTRUE;
1716 // printf("\t \t c absId %d induced amp %2.3f, accumulated %2.3f (new %d). \n",
1717 // absIDc,amp*fracC,fTCardCorrCellsEner[absIDc],fTCardCorrCellsNew[absIDc]);
1718  }
1719 
1720  if ( okc1 )
1721  {
1722  fTCardCorrCellsEner[absIDc1] += amp*fracCupdown;
1723  if ( fCaloCells->GetCellAmplitude(absIDc1 ) < 0.01 ) fTCardCorrCellsNew[absIDc1] = kTRUE;
1724  // printf("\t \t c absId %d induced amp %2.3f, accumulated %2.3f (new %d). \n",
1725  // absIDc1,amp*fracCupdown,fTCardCorrCellsEner[absIDc1],fTCardCorrCellsNew[absIDc1]);
1726  }
1727 
1728  if ( okc2 )
1729  {
1730  fTCardCorrCellsEner[absIDc2] += amp*fracCupdown;
1731  if ( fCaloCells->GetCellAmplitude(absIDc2 ) < 0.01 ) fTCardCorrCellsNew[absIDc2] = kTRUE;
1732  // printf("\t \t c absId %d induced amp %2.3f, accumulated %2.3f (new %d). \n",
1733  // absIDc2,amp*fracCupdown,fTCardCorrCellsEner[absIDc2],fTCardCorrCellsNew[absIDc2]);
1734  }
1735 
1736  //
1737  // Subtract the added energy to main cell, if energy conservation is requested
1739  {
1740  if(absIDc >=0 ) fTCardCorrCellsEner[id] -= amp*fracC;
1741  if(absIDc1 >=0 ) fTCardCorrCellsEner[id] -= amp*fracCupdown;
1742  if(absIDc2 >=0 ) fTCardCorrCellsEner[id] -= amp*fracCupdown;
1743  if(absIDr1 >=0 ) fTCardCorrCellsEner[id] -= amp*fracRupdown;
1744  if(absIDr2 >=0 ) fTCardCorrCellsEner[id] -= amp*fracRupdown;
1745  //printf("\t conserve energy, remove %2.3f, from %d\n",fTCardCorrCellsEner[id],id);
1746  } // conserve energy
1747 
1748  } // cell loop
1749 
1750 }
1751 
1752 //_______________________________________________________
1756 //_______________________________________________________
1758 {
1759  Int_t j = 0;
1760  for(Int_t i = 0; i < fClusterArr->GetEntriesFast(); i++)
1761  {
1762  AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) fClusterArr->At(i);
1763 
1764  const Int_t ncells = recPoint->GetMultiplicity();
1765  Int_t ncellsTrue = 0;
1766 
1767  if(recPoint->GetEnergy() < fRecParam->GetClusteringThreshold()) continue;
1768 
1769  // cells and their amplitude fractions
1770  UShort_t absIds[ncells];
1771  Double32_t ratios[ncells];
1772 
1773  //For later check embedding
1774  AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
1775 
1776  Float_t clusterE = 0;
1777  for (Int_t c = 0; c < ncells; c++)
1778  {
1779  AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->At(recPoint->GetDigitsList()[c]);
1780 
1781  absIds[ncellsTrue] = digit->GetId();
1782  ratios[ncellsTrue] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
1783 
1784  if ( !fRecParam->GetUnfold() && (ratios[ncellsTrue] > 1 || ratios[ncellsTrue] < 1) )
1785  AliWarning(Form("recpoint cell E %2.3f but digit E %2.3f and no unfolding", recPoint->GetEnergiesList()[c], digit->GetAmplitude()));
1786 
1787  // In case of unfolding, remove digits with unfolded energy too low
1788  if(fSelectCell)
1789  {
1790  if (recPoint->GetEnergiesList()[c] < fSelectCellMinE || ratios[ncellsTrue] < fSelectCellMinFrac)
1791  {
1792 
1793  AliDebug(2,Form("Too small energy in cell of cluster: cluster cell %f, digit %f",
1794  recPoint->GetEnergiesList()[c],digit->GetAmplitude()));
1795  continue;
1796  } // if cuts
1797  }// Select cells
1798 
1799  //Recalculate cluster energy and number of cluster cells in case any of the cells was rejected
1800  clusterE +=recPoint->GetEnergiesList()[c];
1801 
1802  // In case of embedding, fill ratio with amount of signal,
1803  if (aodIH && aodIH->GetMergeEvents())
1804  {
1805  //AliVCaloCells* inEMCALCells = InputEvent()->GetEMCALCells();
1806  AliVCaloCells* meEMCALCells = aodIH->GetEventToMerge()->GetEMCALCells();
1807  AliVCaloCells* ouEMCALCells = AODEvent()->GetEMCALCells();
1808 
1809  Float_t sigAmplitude = meEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
1810  //Float_t bkgAmplitude = inEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
1811  Float_t sumAmplitude = ouEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
1812  //printf("\t AbsID %d, amplitude : bkg %f, sigAmplitude %f, summed %f - %f\n",absIds[ncellsTrue], bkgAmplitude, sigAmplitude, sumAmplitude, digit->GetAmplitude());
1813 
1814  if(sumAmplitude > 0) ratios[ncellsTrue] = sigAmplitude/sumAmplitude;
1815  //printf("\t \t ratio %f\n",ratios[ncellsTrue]);
1816 
1817  }//Embedding
1818 
1819  ncellsTrue++;
1820 
1821  }// cluster cell loop
1822 
1823  if (ncellsTrue < 1)
1824  {
1825  AliDebug(2,Form("Skipping cluster with no cells avobe threshold E = %f, ncells %d",
1826  recPoint->GetEnergy(), ncells));
1827  continue;
1828  }
1829 
1830  //if(ncellsTrue != ncells) printf("Old E %f, ncells %d; New E %f, ncells %d\n",recPoint->GetEnergy(),ncells,clusterE,ncellsTrue);
1831 
1832  if(clusterE < fRecParam->GetClusteringThreshold())
1833  {
1834  AliDebug(2,Form("Remove cluster with energy below seed threshold %f",clusterE));
1835  continue;
1836  }
1837 
1838  TVector3 gpos;
1839  Float_t g[3];
1840 
1841  // calculate new cluster position
1842 
1843  recPoint->EvalGlobalPosition(fRecParam->GetW0(), fDigitsArr);
1844  recPoint->GetGlobalPosition(gpos);
1845  gpos.GetXYZ(g);
1846 
1847  // create a new cluster
1848 
1849  (*fCaloClusterArr)[j] = new AliAODCaloCluster() ;
1850  AliAODCaloCluster *clus = dynamic_cast<AliAODCaloCluster *>( fCaloClusterArr->At(j) ) ;
1851  j++;
1852  clus->SetType(AliVCluster::kEMCALClusterv1);
1853  clus->SetE(clusterE);
1854  clus->SetPosition(g);
1855  clus->SetNCells(ncellsTrue);
1856  clus->SetCellsAbsId(absIds);
1857  clus->SetCellsAmplitudeFraction(ratios);
1858  clus->SetChi2(-1); //not yet implemented
1859  clus->SetTOF(recPoint->GetTime()) ; //time-of-flight
1860  clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
1861  clus->SetDistanceToBadChannel(recPoint->GetDistanceToBadTower());
1862 
1863  if(ncells == ncellsTrue)
1864  {
1865  Float_t elipAxis[2];
1866  recPoint->GetElipsAxis(elipAxis);
1867  clus->SetM02(elipAxis[0]*elipAxis[0]) ;
1868  clus->SetM20(elipAxis[1]*elipAxis[1]) ;
1869  clus->SetDispersion(recPoint->GetDispersion());
1870  }
1871  else if(fSelectCell)
1872  {
1873  // In case some cells rejected, in unfolding case, recalculate
1874  // shower shape parameters and position
1875  AliDebug(2,Form("Cells removed from cluster (ncells %d, ncellsTrue %d), recalculate Shower Shape",ncells,ncellsTrue));
1876 
1877  AliVCaloCells* cells = 0x0;
1878  if (aodIH && aodIH->GetMergeEvents()) cells = AODEvent() ->GetEMCALCells();
1879  else cells = InputEvent()->GetEMCALCells();
1880 
1881  fRecoUtils->RecalculateClusterShowerShapeParameters(fGeom,cells,clus);
1882  fRecoUtils->RecalculateClusterPID(clus);
1883  fRecoUtils->RecalculateClusterPosition(fGeom,cells,clus);
1884  }
1885 
1886  // MC
1887 
1890  else
1891  {
1892  //
1893  // Normal case, trust what the clusterizer has found
1894  //
1895  Int_t parentMult = 0;
1896  Int_t *parentList = recPoint->GetParents(parentMult);
1897  Float_t *parentListDE = recPoint->GetParentsDE(); // deposited energy
1898 
1899  clus->SetLabel(parentList, parentMult);
1901  clus->SetClusterMCEdepFractionFromEdepArray(parentListDE);
1902 
1903  //
1904  // Set the cell energy deposition fraction map:
1905  //
1906  if( parentMult > 0 && fSetCellMCLabelFromEdepFrac )
1907  {
1908  UInt_t * mcEdepFracPerCell = new UInt_t[ncellsTrue];
1909 
1910  // Get the digit that originated this cell cluster
1911 // AliVCaloCells* cells = 0x0;
1912 // if (aodIH && aodIH->GetMergeEvents()) cells = AODEvent() ->GetEMCALCells();
1913 // else cells = InputEvent()->GetEMCALCells();
1914 
1915  for(Int_t icell = 0; icell < ncellsTrue ; icell++)
1916  {
1917  Int_t idigit = fCellLabels[absIds[icell]];
1918 
1919  const AliEMCALDigit * dig = (const AliEMCALDigit*)fDigitsArr->At(idigit);
1920 
1921  // Find the 4 MC labels that contributed to the cluster and their
1922  // deposited energy in the current digit
1923 
1924  mcEdepFracPerCell[icell] = 0; // init
1925 
1926  Int_t nparents = dig->GetNiparent();
1927  if ( nparents > 0 )
1928  {
1929  Int_t digLabel =-1 ;
1930  Float_t edep = 0 ;
1931  Float_t edepTot = 0 ;
1932  Float_t mcEDepFrac[4] = {0,0,0,0};
1933 
1934  // all parents in digit
1935  for ( Int_t jndex = 0 ; jndex < nparents ; jndex++ )
1936  {
1937  digLabel = dig->GetIparent (jndex+1);
1938  edep = dig->GetDEParent(jndex+1);
1939  edepTot += edep;
1940 
1941  if ( digLabel == parentList[0] ) mcEDepFrac[0] = edep;
1942  else if ( digLabel == parentList[1] ) mcEDepFrac[1] = edep;
1943  else if ( digLabel == parentList[2] ) mcEDepFrac[2] = edep;
1944  else if ( digLabel == parentList[3] ) mcEDepFrac[3] = edep;
1945  } // all prarents in digit
1946 
1947  // Divide energy deposit by total deposited energy
1948  // Do this only when deposited energy is significant, use 10 MeV although 50 MeV should be expected
1949  if(edepTot > 0.01)
1950  {
1951  mcEdepFracPerCell[icell] = clus->PackMCEdepFraction(mcEDepFrac);
1952  }
1953  } // at least one parent label in digit
1954  } // cell in cluster loop
1955 
1956  clus->SetCellsMCEdepFractionMap(mcEdepFracPerCell);
1957 
1958  delete [] mcEdepFracPerCell;
1959 
1960  } // at least one parent in cluster, do the cell primary packing
1961  }
1962  } // recPoints loop
1963 }
1964 
1965 //_____________________________________________________________________
1968 //_____________________________________________________________________
1970 {
1971  if(label < 0) return ;
1972 
1973  AliAODEvent * evt = dynamic_cast<AliAODEvent*> (fEvent) ;
1974  if(!evt) return ;
1975 
1976  TClonesArray * arr = dynamic_cast<TClonesArray*>(evt->FindListObject("mcparticles")) ;
1977  if(!arr) return ;
1978 
1979  if(label < arr->GetEntriesFast())
1980  {
1981  AliAODMCParticle * particle = dynamic_cast<AliAODMCParticle *>(arr->At(label));
1982  if(!particle) return ;
1983 
1984  if(label == particle->Label()) return ; // label already OK
1985  //else printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - Label %d - AOD stack %d \n",label, particle->Label());
1986  }
1987  //else printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - Label %d > AOD labels %d \n",label, arr->GetEntriesFast());
1988 
1989  // loop on the particles list and check if there is one with the same label
1990  for(Int_t ind = 0; ind < arr->GetEntriesFast(); ind++ )
1991  {
1992  AliAODMCParticle * particle = dynamic_cast<AliAODMCParticle *>(arr->At(ind));
1993  if(!particle) continue ;
1994 
1995  if(label == particle->Label())
1996  {
1997  label = ind;
1998  //printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - New Label Index %d \n",label);
1999  return;
2000  }
2001  }
2002 
2003  label = -1;
2004 
2005  //printf("AliAnalysisTaskEMCALClusterize::RemapMCLabelForAODs() - Label not found set to -1 \n");
2006 }
2007 
2008 //________________________________________________
2010 //________________________________________________
2012 {
2013  for(Int_t j = 0; j < fgkNEMCalCells; j++)
2014  {
2015  fOrgClusterCellId[j] = -1;
2016  fCellLabels[j] = -1;
2017  fCellSecondLabels[j] = -1;
2018  fCellTime[j] = 0.;
2019  fCellMatchdEta[j] = -999;
2020  fCellMatchdPhi[j] = -999;
2021 
2022  fTCardCorrCellsEner[j] = 0.;
2023  fTCardCorrCellsNew [j] = kFALSE;
2024  }
2025 }
2026 
2027 //_____________________________________________________________________________________________________
2031 //_____________________________________________________________________________________________________
2033  AliAODCaloCluster * clus)
2034 {
2035  Int_t parentMult = 0;
2036  Int_t *parentList = recPoint->GetParents(parentMult);
2037  clus->SetLabel(parentList, parentMult);
2038 
2039  //Write the second major contributor to each MC cluster.
2040  Int_t iNewLabel ;
2041  for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ )
2042  {
2043 
2044  Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
2045  if(idCell>=0)
2046  {
2047  iNewLabel = 1 ; //iNewLabel makes sure we don't write twice the same label.
2048  for ( UInt_t iLoopLabels = 0 ; iLoopLabels < clus->GetNLabels() ; iLoopLabels++ )
2049  {
2050  if ( fCellSecondLabels[idCell] == -1 ) iNewLabel = 0; // -1 is never a good second label.
2051  if ( fCellSecondLabels[idCell] == clus->GetLabelAt(iLoopLabels) ) iNewLabel = 0;
2052  }
2053  if (iNewLabel == 1)
2054  {
2055  Int_t * newLabelArray = new Int_t[clus->GetNLabels()+1] ;
2056  for ( UInt_t iLoopNewLabels = 0 ; iLoopNewLabels < clus->GetNLabels() ; iLoopNewLabels++ )
2057  {
2058  newLabelArray[iLoopNewLabels] = clus->GetLabelAt(iLoopNewLabels) ;
2059  }
2060 
2061  newLabelArray[clus->GetNLabels()] = fCellSecondLabels[idCell] ;
2062  clus->SetLabel(newLabelArray,clus->GetNLabels()+1) ;
2063  delete [] newLabelArray;
2064  }
2065  } // positive cell number
2066  }
2067 }
2068 
2069 //___________________________________________________________________________________________________
2073 //___________________________________________________________________________________________________
2075 {
2076  TArrayI clArray(300) ; //Weird if more than a few clusters are in the origin ...
2077  clArray.Reset();
2078  Int_t nClu = 0;
2079  Int_t nLabTotOrg = 0;
2080  Float_t emax = -1;
2081  Int_t idMax = -1;
2082 
2083  AliVEvent * event = fEvent;
2084 
2085  // In case of embedding the MC signal is in the added event
2086  AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
2087  if(aodIH && aodIH->GetEventToMerge()) //Embedding
2088  event = aodIH->GetEventToMerge(); //Get clusters directly from embedded signal
2089 
2090 
2091  // Find the clusters that originally had the cells
2092  for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ )
2093  {
2094  Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
2095 
2096  if(idCell>=0)
2097  {
2098  Int_t idCluster = fOrgClusterCellId[idCell];
2099 
2100  Bool_t set = kTRUE;
2101  for(Int_t icl =0; icl < nClu; icl++)
2102  {
2103  if(((Int_t)clArray.GetAt(icl))==-1 ) continue;
2104  if( idCluster == ((Int_t)clArray.GetAt(icl)) ) set = kFALSE;
2105  // printf("\t \t icell %d Cluster in array %d, IdCluster %d, in array %d, set %d\n",
2106  // iLoopCell, icl, idCluster,((Int_t)clArray.GetAt(icl)),set);
2107  }
2108  if( set && idCluster >= 0)
2109  {
2110  clArray.SetAt(idCluster,nClu++);
2111  //printf("******** idCluster %d \n",idCluster);
2112  nLabTotOrg+=(event->GetCaloCluster(idCluster))->GetNLabels();
2113 
2114  //printf("Cluster in array %d, IdCluster %d\n",nClu-1, idCluster);
2115 
2116  //Search highest E cluster
2117  AliVCluster * clOrg = event->GetCaloCluster(idCluster);
2118  //printf("\t E %f\n",clOrg->E());
2119  if(emax < clOrg->E())
2120  {
2121  emax = clOrg->E();
2122  idMax = idCluster;
2123  }
2124  }
2125  }
2126  }// cell loop
2127 
2128  if(nClu==0 || nLabTotOrg == 0)
2129  {
2130  //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());
2131  //for(Int_t icell = 0; icell < clus->GetNCells(); icell++) printf("\t cell %d",clus->GetCellsAbsId()[icell]);
2132  //printf("\n");
2133  }
2134 
2135  // Put the first in the list the cluster with highest energy
2136  if(idMax != ((Int_t)clArray.GetAt(0))) // Max not at first position
2137  {
2138  Int_t maxIndex = -1;
2139  Int_t firstCluster = ((Int_t)clArray.GetAt(0));
2140  for ( Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++ )
2141  {
2142  if(idMax == ((Int_t)clArray.GetAt(iLoopCluster))) maxIndex = iLoopCluster;
2143  }
2144 
2145  if(firstCluster >=0 && idMax >=0)
2146  {
2147  clArray.SetAt(idMax,0);
2148  clArray.SetAt(firstCluster,maxIndex);
2149  }
2150  }
2151 
2152  // Get the labels list in the original clusters, assign all to the new cluster
2153  TArrayI clMCArray(nLabTotOrg) ;
2154  clMCArray.Reset();
2155 
2156  Int_t nLabTot = 0;
2157  for ( Int_t iLoopCluster = 0 ; iLoopCluster < nClu ; iLoopCluster++ )
2158  {
2159  Int_t idCluster = (Int_t) clArray.GetAt(iLoopCluster);
2160  //printf("New Cluster in Array %d, idCluster %d \n",iLoopCluster,idCluster);
2161  AliVCluster * clOrg = event->GetCaloCluster(idCluster);
2162  Int_t nLab = clOrg->GetNLabels();
2163 
2164  for ( Int_t iLab = 0 ; iLab < nLab ; iLab++ )
2165  {
2166  Int_t lab = clOrg->GetLabelAt(iLab) ;
2167  if(lab>=0)
2168  {
2169  Bool_t set = kTRUE;
2170  //printf("\t \t Set Label %d \n", lab);
2171  for(Int_t iLabTot =0; iLabTot < nLabTot; iLabTot++)
2172  {
2173  if( lab == ((Int_t)clMCArray.GetAt(iLabTot)) ) set = kFALSE;
2174  //printf("iLoopCluster %d, Label ID in Org Cluster %d,label %d Label ID in array %d, label in array %d, set %d\n",
2175  // iLoopCluster, iLab, lab, iLabTot, ((Int_t)clMCArray.GetAt(iLabTot)),set);
2176  }
2177  if( set ) clMCArray.SetAt(lab,nLabTot++);
2178  }
2179  }
2180  }// cluster loop
2181 
2182  // Set the final list of labels
2183 
2184  clus->SetLabel(clMCArray.GetArray(), nLabTot);
2185 
2186 // printf("Final list of labels for new cluster : \n");
2187 // for(Int_t ice = 0; ice < clus->GetNCells() ; ice++)
2188 // {
2189 // printf("\t Cell %d ",clus->GetCellsAbsId()[ice]);
2190 // Int_t label = InputEvent()->GetEMCALCells()->GetCellMCLabel(clus->GetCellsAbsId()[ice]);
2191 // printf(" org %d ",label);
2192 // RemapMCLabelForAODs(label);
2193 // printf(" new %d \n",label);
2194 // }
2195 // for(Int_t imc = 0; imc < clus->GetNLabels(); imc++) printf("\t Label %d\n",clus->GetLabelAt(imc));
2196 }
2197 
2198 //____________________________________________________________
2199 // Init geometry, create list of output clusters.
2200 //____________________________________________________________
2202 {
2203  fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
2204 
2205  if(fOutputAODBranchName.Length()==0)
2206  {
2207  fOutputAODBranchName = "newEMCALClustersArray";
2208  AliInfo("Cluster branch name not set, set it to newEMCALClustersArray");
2209  }
2210 
2212 
2213  if( fFillAODFile )
2214  {
2215  //fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
2216 
2217  //fOutputAODBranch->SetOwner(kFALSE);
2218 
2219  AddAODBranch("TClonesArray", &fOutputAODBranch);
2220  }
2221 }
2222 
2223 //_______________________________________________________________________
2226 //________________________________________________________________________
2228 {
2229  if ( !fUpdateCell ) return;
2230 
2231  // Update cells only in case re-calibration was done
2232  // or bad map applied or additional T-Card cells added.
2233  if(!fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
2234  !fRecoUtils->IsRecalibrationOn() &&
2235  !fRecoUtils->IsRunDepRecalibrationOn() &&
2236  !fRecoUtils->IsTimeRecalibrationOn() &&
2237  !fRecoUtils->IsL1PhaseInTimeRecalibrationOn() &&
2238  !fTCardCorrEmulation ) return;
2239 
2240  const Int_t ncells = fCaloCells->GetNumberOfCells();
2241  const Int_t ndigis = fDigitsArr->GetEntries();
2242  if ( ncells != ndigis )
2243  {
2244  fCaloCells->DeleteContainer();
2245  fCaloCells->CreateContainer(ndigis);
2246  }
2247 
2248  for (Int_t idigit = 0; idigit < ndigis; ++idigit)
2249  {
2250  AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(idigit));
2251 
2252  Double_t cellAmplitude = digit->GetAmplitude();
2253  Short_t cellNumber = digit->GetId();
2254  Double_t cellTime = digit->GetTime();
2255 
2256  Bool_t highGain = kFALSE;
2257  if( digit->GetType() == AliEMCALDigit::kHG ) highGain = kTRUE;
2258 
2259  // Only for MC
2260  // Get the label of the primary particle that generated the cell
2261  // Assign the particle that deposited more energy
2262  Int_t nparents = digit->GetNiparent();
2263  Int_t cellMcEDepFrac =-1 ;
2264  Float_t cellMcLabel =-1.;
2265  if ( nparents > 0 )
2266  {
2267  for ( Int_t jndex = 0 ; jndex < nparents ; jndex++ )
2268  {
2269  if(cellMcEDepFrac >= digit->GetDEParent(jndex+1)) continue ;
2270 
2271  cellMcLabel = digit->GetIparent (jndex+1);
2272  cellMcEDepFrac= digit->GetDEParent(jndex+1);
2273  } // all primaries in digit
2274  } // select primary label
2275 
2276  if ( cellMcEDepFrac < 0 ) cellMcEDepFrac = 0.;
2277 
2278  fCaloCells->SetCell(idigit, cellNumber, cellAmplitude, cellTime, cellMcLabel, cellMcEDepFrac, highGain);
2279  }
2280 }
2281 
2282 
2283 //_______________________________________________________
2294 //_______________________________________________________
2296 {
2297  //-------
2298  // Step 1
2299 
2300  // Remove the contents of AOD branch output list set in the previous event
2301  fOutputAODBranch->Clear("C");
2302 
2303  LoadBranches();
2304 
2305  // Check if there is a centrality value, PbPb analysis, and if a centrality bin selection is requested
2306  // If we need a centrality bin, we select only those events in the corresponding bin.
2307  if( fCentralityBin[0] >= 0 && fCentralityBin[1] >= 0 )
2308  {
2309  Float_t cen = GetEventCentrality();
2310  if(cen > fCentralityBin[1] || cen < fCentralityBin[0]) return ; //reject events out of bin.
2311  }
2312 
2313  // Intermediate array with new clusters : init the array only once or clear from previous event
2314  if(!fCaloClusterArr) fCaloClusterArr = new TObjArray(10000);
2315  else fCaloClusterArr->Delete();//Clear("C"); it leaks?
2316 
2317  InitGeometry(); // only once, must be done before OADB, geo OADB accessed here
2318 
2319  // Get the event, do some checks and settings
2320  CheckAndGetEvent() ;
2321 
2322  if (!fEvent)
2323  {
2324  AliDebug(1,Form("Skip Event %d", (Int_t) Entry()));
2325  return ;
2326  }
2327 
2328  // Init pointers, geometry, clusterizer, ocdb, aodb
2329 
2330  if(fAccessOCDB) AccessOCDB();
2331  if(fAccessOADB) AccessOADB(); // only once
2332 
2334 
2335  //-------
2336  // Step 2
2337 
2338  // Make clusters
2340  else ClusterizeCells() ;
2341 
2342  //-------
2343  // Step 3
2344 
2346 
2347  UpdateCells();
2348 }
2349 
2350 
void FillAODCaloCells()
Put calo cells in standard branch.
AliVCaloCells * fCaloCells
! CaloCells container
Bool_t fTCardCorrEmulation
Activate T-Card cells energy correlation.
double Double_t
Definition: External.C:58
virtual void ResetArrays()
Reset arrays containing information for all possible cells.
Definition: External.C:236
TString GetPass()
Get or guess pass number/string from path of filename.
Bool_t fFillAODHeader
Copy header to standard branch.
TClonesArray * fDigitsArr
! Digits array
Bool_t fTCardCorrClusEnerConserv
When making correlation, subtract from the reference cell the induced energy on the neighbour cells...
AliEMCALClusterizer * fClusterizer
! EMCAL clusterizer
Bool_t fJustUnfold
Just unfold, do not recluster.
Bool_t fImportGeometryFromFile
Import geometry settings in geometry.root file.
Bool_t fSelectCell
Reject cells from cluster if energy is too low and recalculate position/energy and other...
TString fConfigName
Name of analysis configuration file.
TCanvas * c
Definition: TestFitELoss.C:172
Int_t fCellSecondLabels[fgkNEMCalCells]
Array with Second MC label to be passed to digit.
void SetClustersMCLabelFrom2SelectedLabels(AliEMCALRecPoint *recPoint, AliAODCaloCluster *clus)
Float_t fCellMatchdEta[fgkNEMCalCells]
Array with cluster-track dPhi.
TClonesArray * fOutputAODBranch
! AOD Branch with output clusters
TString fOADBFilePath
Default path $ALICE_PHYSICS/OADB/EMCAL, if needed change.
Float_t fTCardCorrCellsEner[fgkNEMCalCells]
Array with induced cell energy in T-Card neighbour cells.
Float_t fTCardCorrInduceEnerFrac[3]
Induced energy loss gauss mean on 0-same row, diff col, 1-up/down cells left/right col 2-left/righ co...
TString fImportGeometryFilePath
path fo geometry.root file
Bool_t fSelectEMCALEvent
Process the event if there is some high energy cluster.
Float_t GetEventCentrality() const
Get centrality/multiplicity percentile.
Bool_t fInputFromFilter
Get the input from AODs from the filter.
Float_t fTCardCorrInduceEnerFracWidth[3]
Induced energy loss gauss witdth on 0-same row, diff col, 1-up/down cells left/right col 2-left/righ ...
TString fOutputAODBranchName
New of output AOD branch.
AliEMCALGeometry * fGeom
EMCAL geometry.
void ClusterUnfolding()
Take the event clusters and unfold them.
int Int_t
Definition: External.C:63
Bool_t fAccessOADB
Get calibration from OADB for EMCAL.
Bool_t fRemoveLEDEvents
Remove LED events, use only for LHC11a.
unsigned int UInt_t
Definition: External.C:33
AliEMCALRecoUtils * fRecoUtils
Access to factorized reconstruction algorithms.
float Float_t
Definition: External.C:68
Bool_t fRejectBelowThreshold
split (false-default) or reject (true) cell energy below threshold after UF
Float_t fConstantTimeShift
Apply a 600 ns time shift in case of simulation, shift in ns.
void SetClustersMCLabelFromOriginalClusters(AliAODCaloCluster *clus)
Bool_t fUpdateCell
On/Off the upate of the CaloCells container.
Float_t fSelectCellMinE
Min energy cell threshold, after unfolding.
Bool_t fOADBSet
AODB parameters already set.
Int_t fCellLabels[fgkNEMCalCells]
Array with MC label to be passed to digit.
Bool_t fRemoveExoticEvents
Remove exotic events.
Bool_t fDoTrackMatching
On/Off the matching recalculation to speed up analysis in PbPb.
Float_t fCellMatchdPhi[fgkNEMCalCells]
Array with cluster-track dEta.
Float_t fTCardCorrInduceEnerProb[22]
Probability to induce energy loss per SM.
TGeoHMatrix * fGeomMatrix[22]
Geometry matrices with alignments.
Bool_t IsLEDEvent(const Int_t run)
Check if event is LED, is so remove it. Affected LHC11a runs.
AliEMCALRecParam * fRecParam
Reconstruction parameters container.
TString fGeomName
Name of geometry to use.
Bool_t fOutputAODBranchSet
Set the AOD clusters branch in the input event once.
short Short_t
Definition: External.C:23
TString fOCDBpath
Path with OCDB location.
AliEMCALAfterBurnerUF * fUnfolder
! Unfolding procedure
Float_t fTCardCorrInduceEnerFracP1[3]
Induced energy loss gauss mean on 0-same row, diff col, 1-up/down cells left/right col 2-left/righ co...
ClassImp(AliAnalysisTaskDeltaPt) AliAnalysisTaskDeltaPt
Bool_t fGeomMatrixSet
Set geometry matrices only once, for the first event.
Float_t fCentralityBin[2]
Minimum and maximum value of the centrality for the analysis.
Bool_t fFillAODCaloCells
Copy calocells to standard branch.
TObjArray * fCaloClusterArr
! CaloClusters array
Double_t fCellTime[fgkNEMCalCells]
Array with cluster time to be passed to digit in case of AODs.
TString fCentralityClass
Name of selected centrality class.
TFile * file
TList with histograms for a given trigger.
Bool_t fAccessOCDB
Need to access info from OCDB (not really)
TObjArray * fClusterArr
! Recpoints array
unsigned short UShort_t
Definition: External.C:28
Bool_t fRecalibrateWithClusterTime
Use fCellTime to store time of cells in cluster.
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
void FillAODHeader()
Put event header information in standard AOD branch.
static const Int_t fgkNEMCalCells
Total number of cells in the calorimeter, 10*48*24 (EMCal) + 4*48*8 (EMCal/DCal 1/3) + 6*32*24 (DCal)...
Int_t fEMCALNcellsCut
At least an EMCAL cluster with fNCellsCut cells over fEnergyCut.
Reclusterize EMCal clusters, put them in a new branch for other following analysis.
Bool_t fTCardCorrCellsNew[fgkNEMCalCells]
Array with induced cell energy in T-Card neighbour cells, that before had no signal.
Bool_t fLoadGeomMatrices
Matrices set from configuration, not get from geometry.root or from ESDs/AODs.
Float_t fEMCALEnergyCut
At least an EMCAL cluster with this energy in the event.
Bool_t fUseAliCentrality
Use the centrality estimator from AliCentrality or AliMultSelection.
Int_t fOrgClusterCellId[fgkNEMCalCells]
Array ID of cluster to wich the cell belongs in unmodified clusters.
Float_t fSelectCellMinFrac
Min fraction of cell energy after unfolding cut.
Bool_t fRemapMCLabelForAODs
Remap AOD cells MC label. Needed in old AOD productions.