added run dependent corrections on T for calibration, removed old method
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliEMCALTenderSupply.cxx
CommitLineData
6d67b5a7 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
6d67b5a7 16///////////////////////////////////////////////////////////////////////////////
17// //
dd8e12d1 18// EMCAL tender, apply corrections to EMCAL clusters and do track matching. //
19// //
766cc9de 20// Author: Deepa Thomas (Utrecht University) //
c05ffa77 21// Later mods/rewrite: Jiri Kral (University of Jyvaskyla) //
dd8e12d1 22// S. Aiola, C. Loizides : Make it work for AODs //
6d67b5a7 23// //
24///////////////////////////////////////////////////////////////////////////////
25
766cc9de 26#include <TROOT.h>
27#include <TFile.h>
28#include <TTree.h>
29#include <TInterpreter.h>
30#include <TObjArray.h>
31#include <TClonesArray.h>
32#include <TGeoGlobalMagField.h>
b20bc239 33#include "AliEMCALAfterBurnerUF.h"
dd8e12d1 34#include "AliEMCALClusterizer.h"
b20bc239 35#include "AliEMCALClusterizerNxN.h"
36#include "AliEMCALClusterizerv1.h"
37#include "AliEMCALClusterizerv2.h"
38#include "AliEMCALDigit.h"
dd8e12d1 39#include "AliEMCALGeometry.h"
40#include "AliEMCALRecParam.h"
4d3c549c 41#include "AliEMCALRecParam.h"
dd8e12d1 42#include "AliEMCALRecPoint.h"
43#include "AliEMCALRecoUtils.h"
44#include "AliEMCALTenderSupply.h"
45#include "AliESDCaloCluster.h"
46#include "AliMagF.h"
47#include "AliOADBContainer.h"
48#include "AliAODEvent.h"
49#include "AliAnalysisManager.h"
50#include "AliESDEvent.h"
51#include "AliLog.h"
52#include "AliTender.h"
6d67b5a7 53
3b7d451e 54ClassImp(AliEMCALTenderSupply)
55
6d67b5a7 56AliEMCALTenderSupply::AliEMCALTenderSupply() :
6b7df55d 57AliTenderSupply()
dd8e12d1 58,fTask(0)
59,fRun(0)
6b7df55d 60,fEMCALGeo(0x0)
98e8eede 61,fEMCALGeoName("")
6b7df55d 62,fEMCALRecoUtils(0)
63,fConfigName("")
64,fDebugLevel(0)
50b7a951 65,fNonLinearFunc(-1)
66,fNonLinearThreshold(-1)
67,fReCalibCluster(kFALSE)
acf53135 68,fUpdateCell(kFALSE)
50b7a951 69,fCalibrateEnergy(kFALSE)
70,fCalibrateTime(kFALSE)
71,fDoNonLinearity(kFALSE)
72,fBadCellRemove(kFALSE)
73,fRejectExoticCells(kFALSE)
74,fRejectExoticClusters(kFALSE)
75,fClusterBadChannelCheck(kFALSE)
6b7df55d 76,fRecalClusPos(kFALSE)
77,fFiducial(kFALSE)
50b7a951 78,fNCellsFromEMCALBorder(-1)
79,fRecalDistToBadChannels(kFALSE)
80,fRecalShowerShape(kFALSE)
81,fInputTree(0)
6b7df55d 82,fInputFile(0)
83,fFilepass(0)
50b7a951 84,fMass(-1)
85,fStep(-1)
6b7df55d 86,fCutEtaPhiSum(kTRUE)
87,fCutEtaPhiSeparate(kFALSE)
50b7a951 88,fRcut(-1)
89,fEtacut(-1)
90,fPhicut(-1)
acf53135 91,fBasePath("")
6b7df55d 92,fReClusterize(kFALSE)
93,fClusterizer(0)
94,fGeomMatrixSet(kFALSE)
95,fLoadGeomMatrices(kFALSE)
acf53135 96,fRecParam(0x0)
50b7a951 97,fDoTrackMatch(kFALSE)
a0beb012 98,fDoUpdateOnly(kFALSE)
6b7df55d 99,fUnfolder(0)
100,fDigitsArr(0)
101,fClusterArr(0)
50b7a951 102,fMisalignSurvey(kdefault)
103,fExoticCellFraction(-1)
104,fExoticCellDiffTime(-1)
105,fExoticCellMinAmplitude(-1)
6d67b5a7 106{
766cc9de 107 // Default constructor.
98e8eede 108
109 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
6d67b5a7 110}
111
112//_____________________________________________________
113AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
6b7df55d 114AliTenderSupply(name,tender)
dd8e12d1 115,fTask(0)
116,fRun(0)
117,fEMCALGeo(0x0)
98e8eede 118,fEMCALGeoName("")
dd8e12d1 119,fEMCALRecoUtils(0)
120,fConfigName("")
121,fDebugLevel(0)
122,fNonLinearFunc(-1)
123,fNonLinearThreshold(-1)
124,fReCalibCluster(kFALSE)
125,fUpdateCell(kFALSE)
126,fCalibrateEnergy(kFALSE)
127,fCalibrateTime(kFALSE)
128,fDoNonLinearity(kFALSE)
129,fBadCellRemove(kFALSE)
130,fRejectExoticCells(kFALSE)
131,fRejectExoticClusters(kFALSE)
132,fClusterBadChannelCheck(kFALSE)
133,fRecalClusPos(kFALSE)
134,fFiducial(kFALSE)
135,fNCellsFromEMCALBorder(-1)
136,fRecalDistToBadChannels(kFALSE)
137,fRecalShowerShape(kFALSE)
138,fInputTree(0)
139,fInputFile(0)
140,fFilepass(0)
141,fMass(-1)
142,fStep(-1)
143,fCutEtaPhiSum(kTRUE)
144,fCutEtaPhiSeparate(kFALSE)
145,fRcut(-1)
146,fEtacut(-1)
147,fPhicut(-1)
148,fBasePath("")
149,fReClusterize(kFALSE)
150,fClusterizer(0)
151,fGeomMatrixSet(kFALSE)
152,fLoadGeomMatrices(kFALSE)
153,fRecParam(0x0)
154,fDoTrackMatch(kFALSE)
155,fDoUpdateOnly(kFALSE)
156,fUnfolder(0)
157,fDigitsArr(0)
158,fClusterArr(0)
159,fMisalignSurvey(kdefault)
160,fExoticCellFraction(-1)
161,fExoticCellDiffTime(-1)
162,fExoticCellMinAmplitude(-1)
163{
164 // Named constructor
165
98e8eede 166 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
dd8e12d1 167}
168
169//_____________________________________________________
170AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, AliAnalysisTaskSE *task) :
171AliTenderSupply(name)
172,fTask(task)
173,fRun(0)
6b7df55d 174,fEMCALGeo(0x0)
98e8eede 175,fEMCALGeoName("")
6b7df55d 176,fEMCALRecoUtils(0)
50b7a951 177,fConfigName("")
6b7df55d 178,fDebugLevel(0)
50b7a951 179,fNonLinearFunc(-1)
180,fNonLinearThreshold(-1)
181,fReCalibCluster(kFALSE)
acf53135 182,fUpdateCell(kFALSE)
50b7a951 183,fCalibrateEnergy(kFALSE)
184,fCalibrateTime(kFALSE)
185,fDoNonLinearity(kFALSE)
186,fBadCellRemove(kFALSE)
187,fRejectExoticCells(kFALSE)
188,fRejectExoticClusters(kFALSE)
189,fClusterBadChannelCheck(kFALSE)
6b7df55d 190,fRecalClusPos(kFALSE)
191,fFiducial(kFALSE)
50b7a951 192,fNCellsFromEMCALBorder(-1)
193,fRecalDistToBadChannels(kFALSE)
194,fRecalShowerShape(kFALSE)
195,fInputTree(0)
6b7df55d 196,fInputFile(0)
50b7a951 197,fFilepass(0)
198,fMass(-1)
199,fStep(-1)
6b7df55d 200,fCutEtaPhiSum(kTRUE)
201,fCutEtaPhiSeparate(kFALSE)
50b7a951 202,fRcut(-1)
203,fEtacut(-1)
204,fPhicut(-1)
acf53135 205,fBasePath("")
6b7df55d 206,fReClusterize(kFALSE)
207,fClusterizer(0)
208,fGeomMatrixSet(kFALSE)
209,fLoadGeomMatrices(kFALSE)
acf53135 210,fRecParam(0x0)
50b7a951 211,fDoTrackMatch(kFALSE)
a0beb012 212,fDoUpdateOnly(kFALSE)
6b7df55d 213,fUnfolder(0)
214,fDigitsArr(0)
215,fClusterArr(0)
50b7a951 216,fMisalignSurvey(kdefault)
217,fExoticCellFraction(-1)
218,fExoticCellDiffTime(-1)
219,fExoticCellMinAmplitude(-1)
6d67b5a7 220{
98e8eede 221 // Named constructor.
6b7df55d 222
98e8eede 223 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
6d67b5a7 224}
225
226//_____________________________________________________
227AliEMCALTenderSupply::~AliEMCALTenderSupply()
228{
766cc9de 229 //Destructor
6b7df55d 230
766cc9de 231 delete fEMCALRecoUtils;
8b775c10 232 delete fRecParam;
766cc9de 233 delete fUnfolder;
e768f43c 234 if (!fClusterizer) {
766cc9de 235 fDigitsArr->Clear("C");
236 delete fDigitsArr;
e768f43c 237 } else {
238 delete fClusterizer;
239 fDigitsArr = 0;
766cc9de 240 }
6d67b5a7 241}
242
98e8eede 243//_____________________________________________________
244void AliEMCALTenderSupply::SetDefaults()
245{
246 // Set default settings.
247
248 SwitchOnBadCellRemove();
249 SwitchOnExoticCellRemove();
250 SwitchOnCalibrateEnergy();
251 SwitchOnCalibrateTime();
252 SwitchOnUpdateCell();
253 SwitchOnReclustering();
254 SwitchOnClusterBadChannelCheck();
255 SwitchOnClusterExoticChannelCheck();
256 SwitchOnTrackMatch();
257}
258
dd8e12d1 259//_____________________________________________________
260Bool_t AliEMCALTenderSupply::RunChanged() const
261{
98e8eede 262 // Get run number.
263
dd8e12d1 264 return (fTender && fTender->RunChanged()) || (fTask && fRun != fTask->InputEvent()->GetRunNumber());
265}
266
6d67b5a7 267//_____________________________________________________
268void AliEMCALTenderSupply::Init()
269{
766cc9de 270 // Initialise EMCAL tender.
acf53135 271
766cc9de 272 if (fDebugLevel>0)
886d4ff1 273 AliWarning("Init EMCAL Tender supply");
6b7df55d 274
a0beb012 275 if (fConfigName.Length()>0 && gROOT->LoadMacro(fConfigName) >=0) {
766cc9de 276 AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
277 AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
278 fDebugLevel = tender->fDebugLevel;
279 fEMCALGeoName = tender->fEMCALGeoName;
766cc9de 280 fEMCALRecoUtils = tender->fEMCALRecoUtils;
281 fConfigName = tender->fConfigName;
282 fNonLinearFunc = tender->fNonLinearFunc;
283 fNonLinearThreshold = tender->fNonLinearThreshold;
284 fReCalibCluster = tender->fReCalibCluster;
50b7a951 285 fUpdateCell = tender->fUpdateCell;
766cc9de 286 fRecalClusPos = tender->fRecalClusPos;
50b7a951 287 fCalibrateEnergy = tender->fCalibrateEnergy;
288 fCalibrateTime = tender->fCalibrateTime;
289 fFiducial = tender->fFiducial;
766cc9de 290 fNCellsFromEMCALBorder = tender->fNCellsFromEMCALBorder;
291 fRecalDistToBadChannels = tender->fRecalDistToBadChannels;
50b7a951 292 fRecalShowerShape = tender->fRecalShowerShape;
293 fClusterBadChannelCheck = tender->fClusterBadChannelCheck;
294 fBadCellRemove = tender->fBadCellRemove;
295 fRejectExoticCells = tender->fRejectExoticCells;
296 fRejectExoticClusters = tender->fRejectExoticClusters;
766cc9de 297 fMass = tender->fMass;
298 fStep = tender->fStep;
50b7a951 299 fCutEtaPhiSum = tender->fCutEtaPhiSum;
300 fCutEtaPhiSeparate = tender->fCutEtaPhiSeparate;
766cc9de 301 fRcut = tender->fRcut;
302 fEtacut = tender->fEtacut;
303 fPhicut = tender->fPhicut;
304 fReClusterize = tender->fReClusterize;
305 fLoadGeomMatrices = tender->fLoadGeomMatrices;
306 fRecParam = tender->fRecParam;
50b7a951 307 fDoNonLinearity = tender->fDoNonLinearity;
308 fDoTrackMatch = tender->fDoTrackMatch;
309 fDoUpdateOnly = tender->fDoUpdateOnly;
310 fMisalignSurvey = tender->fMisalignSurvey;
311 fExoticCellFraction = tender->fExoticCellFraction;
312 fExoticCellDiffTime = tender->fExoticCellDiffTime;
313 fExoticCellMinAmplitude = tender->fExoticCellMinAmplitude;
314
98e8eede 315 for(Int_t i = 0; i < 12; i++)
766cc9de 316 fEMCALMatrix[i] = tender->fEMCALMatrix[i] ;
317 }
886d4ff1 318
319 if (fDebugLevel>0){
320 AliInfo( "Emcal Tender settings: ======================================" );
321 AliInfo( "------------ Switches --------------------------" );
322 AliInfo( Form( "BadCellRemove : %d", fBadCellRemove ));
323 AliInfo( Form( "ExoticCellRemove : %d", fRejectExoticCells ));
324 AliInfo( Form( "CalibrateEnergy : %d", fCalibrateEnergy ));
325 AliInfo( Form( "CalibrateTime : %d", fCalibrateTime ));
326 AliInfo( Form( "UpdateCell : %d", fUpdateCell ));
327 AliInfo( Form( "DoUpdateOnly : %d", fDoUpdateOnly ));
328 AliInfo( Form( "Reclustering : %d", fReClusterize ));
329 AliInfo( Form( "ClusterBadChannelCheck : %d", fClusterBadChannelCheck ));
330 AliInfo( Form( "ClusterExoticChannelCheck : %d", fRejectExoticClusters ));
331 AliInfo( Form( "CellFiducialRegion : %d", fFiducial ));
332 AliInfo( Form( "ReCalibrateCluster : %d", fReCalibCluster ));
333 AliInfo( Form( "RecalculateClusPos : %d", fRecalClusPos ));
334 AliInfo( Form( "RecalShowerShape : %d", fRecalShowerShape ));
335 AliInfo( Form( "NonLinearityCorrection : %d", fDoNonLinearity ));
336 AliInfo( Form( "RecalDistBadChannel : %d", fRecalDistToBadChannels ));
337 AliInfo( Form( "TrackMatch : %d", fDoTrackMatch ));
338 AliInfo( "------------ Variables -------------------------" );
339 AliInfo( Form( "DebugLevel : %d", fDebugLevel ));
340 AliInfo( Form( "BasePath : %s", fBasePath.Data() ));
341 AliInfo( Form( "ConfigFileName : %s", fConfigName.Data() ));
342 AliInfo( Form( "EMCALGeometryName : %s", fEMCALGeoName.Data() ));
343 AliInfo( Form( "NonLinearityFunction : %d", fNonLinearFunc ));
344 AliInfo( Form( "NonLinearityThreshold : %d", fNonLinearThreshold ));
345 AliInfo( Form( "MisalignmentMatrixSurvey : %d", fMisalignSurvey ));
346 AliInfo( Form( "NumberOfCellsFromEMCALBorder : %d", fNCellsFromEMCALBorder ));
347 AliInfo( Form( "RCut : %f", fRcut ));
348 AliInfo( Form( "Mass : %f", fMass ));
349 AliInfo( Form( "Step : %f", fStep ));
350 AliInfo( Form( "EtaCut : %f", fEtacut ));
351 AliInfo( Form( "PhiCut : %f", fPhicut ));
352 AliInfo( Form( "ExoticCellFraction : %f", fExoticCellFraction ));
353 AliInfo( Form( "ExoticCellDiffTime : %f", fExoticCellDiffTime ));
354 AliInfo( Form( "ExoticCellMinAmplitude : %f", fExoticCellMinAmplitude ));
355 AliInfo( "=============================================================" );
356 }
a0beb012 357
98e8eede 358 // init reco utils
359 fEMCALRecoUtils = new AliEMCALRecoUtils;
360
361 // init geometry if requested
362 if (fEMCALGeoName.Length()>0)
363 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
886d4ff1 364
365 // digits array
366 fDigitsArr = new TClonesArray("AliEMCALDigit",1000);
367
98e8eede 368 // initialising non-linearity parameters
50b7a951 369 if( fNonLinearThreshold != -1 )
370 fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
371 if( fNonLinearFunc != -1 )
372 fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);
373
374 // missalignment function
375 fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
376
377 // fiducial cut
378 // do not do the eta0 fiducial cut
379 if( fNCellsFromEMCALBorder != -1 )
380 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
381 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
382
383 // exotic cell rejection
384 if( fExoticCellFraction != -1 )
385 fEMCALRecoUtils->SetExoticCellFractionCut( fExoticCellFraction );
386 if( fExoticCellDiffTime != -1 )
387 fEMCALRecoUtils->SetExoticCellDiffTimeCut( fExoticCellDiffTime );
388 if( fExoticCellMinAmplitude != -1 )
389 fEMCALRecoUtils->SetExoticCellMinAmplitudeCut( fExoticCellMinAmplitude );
390
98e8eede 391 // setting track matching parameters ... mass, step size and residual cut
50b7a951 392 if( fMass != -1 )
393 fEMCALRecoUtils->SetMass(fMass);
394 if( fStep != -1 )
395 fEMCALRecoUtils->SetStep(fStep);
6b7df55d 396
50b7a951 397 // spatial cut based on separate eta/phi or common processing
766cc9de 398 if(fCutEtaPhiSum){
399 fEMCALRecoUtils->SwitchOnCutEtaPhiSum();
50b7a951 400 if( fRcut != -1 )
401 fEMCALRecoUtils->SetCutR(fRcut);
766cc9de 402 } else if (fCutEtaPhiSeparate) {
403 fEMCALRecoUtils->SwitchOnCutEtaPhiSeparate();
50b7a951 404 if( fEtacut != -1 )
405 fEMCALRecoUtils->SetCutEta(fEtacut);
406 if( fPhicut != -1 )
407 fEMCALRecoUtils->SetCutPhi(fPhicut);
766cc9de 408 }
6d67b5a7 409}
410
dd8e12d1 411//_____________________________________________________
412AliVEvent* AliEMCALTenderSupply::GetEvent()
413{
98e8eede 414 // Return the event pointer.
dd8e12d1 415
416 if (fTender) {
417 return fTender->GetEvent();
418 }
419 else if (fTask) {
420 return fTask->InputEvent();
421 }
422
423 return 0;
dd8e12d1 424}
425
6d67b5a7 426//_____________________________________________________
427void AliEMCALTenderSupply::ProcessEvent()
428{
766cc9de 429 // Event loop.
b524daab 430
dd8e12d1 431 AliVEvent *event = GetEvent();
6b7df55d 432
766cc9de 433 if (!event) {
dd8e12d1 434 AliError("Event ptr = 0, returning");
766cc9de 435 return;
436 }
8b775c10 437
b524daab 438 // Initialising parameters once per run number
dd8e12d1 439 if (RunChanged()) {
440
98e8eede 441 AliWarning( "Run changed, initializing parameters" );
dd8e12d1 442 fRun = event->GetRunNumber();
443
98e8eede 444 // init geometry if not already done
445 if (fEMCALGeoName.Length()==0) {
446 fEMCALGeoName = "EMCAL_FIRSTYEARV1";
447 if (fRun>139517) {
448 fEMCALGeoName = "EMCAL_COMPLETEV1";
449 }
450 if (fRun>170593) {
451 fEMCALGeoName = "EMCAL_COMPLETE12SMV1";
452 }
453 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName);
454 if (!fEMCALGeo) {
455 AliFatal(Form("Can not create geometry: %s", fEMCALGeoName.Data()));
456 return;
457 }
458 }
a0beb012 459
50b7a951 460 // get pass
766cc9de 461 GetPass();
a0beb012 462
50b7a951 463 // define what recalib parameters are needed for various switches
464 // this is based on implementation in AliEMCALRecoUtils
c05ffa77 465 Bool_t needRecoParam = fReClusterize;
50b7a951 466 Bool_t needBadChannels = fBadCellRemove | fClusterBadChannelCheck | fRecalDistToBadChannels | fReClusterize;
467 Bool_t needRecalib = fCalibrateEnergy | fReClusterize;
468 Bool_t needTimecalib = fCalibrateTime | fReClusterize;
469 Bool_t needMisalign = fRecalClusPos | fReClusterize;
470 Bool_t needClusterizer = fReClusterize;
a0beb012 471
dd8e12d1 472 // initiate reco params with some defaults
473 // will not overwrite, if those have been provided by user
c05ffa77 474 if( needRecoParam ){
475 Int_t initRC = InitRecParam();
476
477 if( initRC == 0 )
dd8e12d1 478 AliInfo("Defaults reco params loaded.");
c05ffa77 479 if( initRC > 1 )
dd8e12d1 480 AliWarning("User defined reco params.");
c05ffa77 481 }
482
dd8e12d1 483 // init bad channels
c05ffa77 484 if( needBadChannels ){
50b7a951 485 Int_t fInitBC = InitBadChannels();
486 if (fInitBC==0)
50b7a951 487 AliError("InitBadChannels returned false, returning");
50b7a951 488 if (fInitBC==1)
886d4ff1 489 AliWarning("InitBadChannels OK");
50b7a951 490 if (fInitBC>1)
886d4ff1 491 AliWarning(Form("No external hot channel set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
8b775c10 492 }
a0beb012 493
50b7a951 494 // init recalibration factors
7bf608c9 495 if( needRecalib )
496 {
a0beb012 497 Int_t fInitRecalib = InitRecalib();
acf53135 498 if (fInitRecalib==0)
8b775c10 499 AliError("InitRecalib returned false, returning");
50b7a951 500 if (fInitRecalib==1)
886d4ff1 501 AliWarning("InitRecalib OK");
a0beb012 502 if (fInitRecalib>1)
886d4ff1 503 AliWarning(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
7bf608c9 504
505 Int_t fInitRunDepRecalib = InitRunDepRecalib();
506 if (fInitRunDepRecalib==0)
507 AliError("InitrunDepRecalib returned false, returning");
508 if (fInitRunDepRecalib==1)
509 AliWarning("InitRecalib OK");
510 if (fInitRunDepRecalib>1)
511 AliWarning(Form("No Temperature recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
512
513 fReCalibCluster = kFALSE;
514
766cc9de 515 }
8b775c10 516
7bf608c9 517
518
50b7a951 519 // init time calibration
c05ffa77 520 if( needTimecalib ){
50b7a951 521 Int_t initTC = InitTimeCalibration();
522 if ( !initTC )
50b7a951 523 AliError("InitTimeCalibration returned false, returning");
50b7a951 524 if (initTC==1)
886d4ff1 525 AliWarning("InitTimeCalib OK");
50b7a951 526 if( initTC > 1 )
886d4ff1 527 AliWarning(Form("No external time calibration set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
50b7a951 528 }
529
530 // init misalignment matrix
c05ffa77 531 if( needMisalign ) {
532 if (!InitMisalignMatrix())
766cc9de 533 AliError("InitMisalignmentMatrix returned false, returning");
50b7a951 534 else
886d4ff1 535 AliWarning("InitMisalignMatrix OK");
766cc9de 536 }
8b775c10 537
50b7a951 538 // init clusterizer
c05ffa77 539 if( needClusterizer ) {
50b7a951 540 if (!InitClusterization())
766cc9de 541 AliError("InitClusterization returned false, returning");
50b7a951 542 else
886d4ff1 543 AliWarning("InitClusterization OK");
766cc9de 544 }
6b7df55d 545
766cc9de 546 if(fDebugLevel>1)
547 fEMCALRecoUtils->Print("");
548 }
8b775c10 549
50b7a951 550 // disable implied switches -------------------------------------------------
551 // AliEMCALRecoUtils or clusterizer functions alredy include some
552 // recalibration so based on those implied callibration te switches
553 // here are disabled to avoid duplication
554
555 // clusterizer does cluster energy recalibration, position recomputation
556 // and shower shape
c05ffa77 557 if( fReClusterize ){
50b7a951 558 fReCalibCluster = kFALSE;
559 fRecalClusPos = kFALSE;
560 fRecalShowerShape = kFALSE;
561 }
562
563 // CONFIGURE THE RECO UTILS -------------------------------------------------
564 // configure the reco utils
565 // this option does energy recalibration
566 if( fCalibrateEnergy )
567 fEMCALRecoUtils->SwitchOnRecalibration();
568 else
569 fEMCALRecoUtils->SwitchOffRecalibration();
570
571 // allows time calibration
572 if( fCalibrateTime )
573 fEMCALRecoUtils->SwitchOnTimeRecalibration();
574 else
575 fEMCALRecoUtils->SwitchOffTimeRecalibration();
576
577 // allows to zero bad cells
578 if( fBadCellRemove )
579 fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
580 else
581 fEMCALRecoUtils->SwitchOffBadChannelsRemoval();
582
583 // distance to bad channel recalibration
584 if( fRecalDistToBadChannels )
585 fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
586 else
587 fEMCALRecoUtils->SwitchOffDistToBadChannelRecalculation();
588
589 // exclude exotic cells
590 if( fRejectExoticCells )
591 fEMCALRecoUtils->SwitchOnRejectExoticCell();
592 else
593 fEMCALRecoUtils->SwitchOffRejectExoticCell();
594
595 // exclude clusters with exotic cells
596 if( fRejectExoticClusters )
597 fEMCALRecoUtils->SwitchOnRejectExoticCluster();
598 else
599 fEMCALRecoUtils->SwitchOffRejectExoticCluster();
600
601 // TODO: not implemented switches
602 // SwitchOnClusterEnergySmearing
603 // SwitchOnRunDepCorrection
604
605 // START PROCESSING ---------------------------------------------------------
766cc9de 606 // Test if cells present
dd8e12d1 607 AliVCaloCells *cells= event->GetEMCALCells();
50b7a951 608 if (cells->GetNumberOfCells()<=0)
609 {
8b775c10 610 if(fDebugLevel>1)
611 AliWarning(Form("Number of EMCAL cells = %d, returning", cells->GetNumberOfCells()));
766cc9de 612 return;
613 }
6b7df55d 614
a0beb012 615 if (fDebugLevel>2)
8b775c10 616 AliInfo(Form("Re-calibrate cluster %d\n",fReCalibCluster));
50b7a951 617
618 // mark the cells not recalibrated in case of selected
619 // time, energy recalibration or bad channel removal
620 if( fCalibrateEnergy || fCalibrateTime || fBadCellRemove )
621 fEMCALRecoUtils->ResetCellsCalibrated();
622
b524daab 623 // CELL RECALIBRATION -------------------------------------------------------
50b7a951 624 // cell objects will be updated
625 // the cell calibrations are also processed locally any time those are needed
626 // in case that the cell objects are not to be updated here for later use
627 if( fUpdateCell )
8b775c10 628 {
50b7a951 629 // do the update
630 // includes exotic cell check in the UpdateCells function - is not provided
631 // by the reco utils
8b775c10 632 UpdateCells();
50b7a951 633
634 // switch off recalibrations so those are not done multiple times
635 // this is just for safety, the recalibrated flag of cell object
636 // should not allow for farther processing anyways
637 fEMCALRecoUtils->SwitchOffRecalibration();
638 fEMCALRecoUtils->SwitchOffTimeRecalibration();
639
a0beb012 640 if (fDoUpdateOnly)
641 return;
8b775c10 642 }
a0beb012 643
50b7a951 644 // RECLUSTERIZATION ---------------------------------------------------------
a0beb012 645 if (fReClusterize)
8b775c10 646 {
647 FillDigitsArray();
648 Clusterize();
649 UpdateClusters();
650 }
b524daab 651
766cc9de 652 // Store good clusters
653 TClonesArray *clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
654 if (!clusArr)
655 clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
656 if (!clusArr) {
657 AliWarning(Form("No cluster array, number of cells in event = %d, returning", cells->GetNumberOfCells()));
658 return;
659 }
50b7a951 660
661 // PROCESS SINGLE CLUSTER RECALIBRATION -------------------------------------
662 // now go through clusters one by one and process separate correction
663 // as those were defined or not
766cc9de 664 Int_t nclusters = clusArr->GetEntriesFast();
50b7a951 665 for (Int_t icluster=0; icluster < nclusters; ++icluster)
666 {
766cc9de 667 AliVCluster *clust = static_cast<AliVCluster*>(clusArr->At(icluster));
668 if (!clust)
669 continue;
670 if (!clust->IsEMCAL())
671 continue;
50b7a951 672
673 // REMOVE CLUSTERS WITH BAD CELLS -----------------------------
674 if( fClusterBadChannelCheck )
675 {
676 // careful, the the ClusterContainsBadChannel is dependent on
677 // SwitchOnBadChannelsRemoval, switching it ON automatically
678 // and returning to original value after processing
679 Bool_t badRemoval = fEMCALRecoUtils->IsBadChannelsRemovalSwitchedOn();
680 fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
681
682 Bool_t badResult = fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells());
683
684 // switch the bad channels removal back
685 if( ! badRemoval )
686 fEMCALRecoUtils->SwitchOffBadChannelsRemoval();
687
688 if( badResult )
689 {
690 delete clusArr->RemoveAt(icluster);
691 continue; //TODO is it really needed to remove it? Or should we flag it?
692 }
693 }
694
695 // REMOVE EXOTIC CLUSTERS -------------------------------------
696 // does process local cell recalibration energy and time without replacing
697 // the global cell values, in case of no cell recalib done yet
698 if( fRejectExoticClusters )
699 {
700 // careful, the IsExoticCluster is dependent on
701 // SwitchOnRejectExoticCell, switching it ON automatically
702 // and returning to original value after processing
703 Bool_t exRemoval = fEMCALRecoUtils->IsRejectExoticCell();
704 fEMCALRecoUtils->SwitchOnRejectExoticCell();
705
706 // get bunch crossing
dd8e12d1 707 Int_t bunchCrossNo = event->GetBunchCrossNumber();
50b7a951 708
709 Bool_t exResult = fEMCALRecoUtils->IsExoticCluster(clust, cells, bunchCrossNo );
710
711 // switch the exotic channels removal back
712 if( ! exRemoval )
713 fEMCALRecoUtils->SwitchOffRejectExoticCell();
714
715 if( exResult )
716 {
717 delete clusArr->RemoveAt(icluster);
718 continue; //TODO is it really needed to remove it? Or should we flag it?
719 }
766cc9de 720 }
6b7df55d 721
50b7a951 722 // FIDUCIAL CUT -----------------------------------------------
723 if (fFiducial)
724 {
725 // depends on SetNumberOfCellsFromEMCALBorder
726 // SwitchOnNoFiducialBorderInEMCALEta0
766cc9de 727 if (!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
728 delete clusArr->RemoveAt(icluster);
50b7a951 729 continue; //TODO it would be nice to store the distance
766cc9de 730 }
731 }
6b7df55d 732
50b7a951 733 // CLUSTER ENERGY ---------------------------------------------
734 // does process local cell recalibration energy and time without replacing
735 // the global cell values, in case of no cell recalib done yet
736 if( fReCalibCluster )
766cc9de 737 fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
50b7a951 738
739 // CLUSTER POSITION -------------------------------------------
740 // does process local cell energy recalibration, if enabled and cells
98e8eede 741 // not calibrated yet
50b7a951 742 if( fRecalClusPos )
766cc9de 743 fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
57131575 744
50b7a951 745 // SHOWER SHAPE -----------------------------------------------
746 if( fRecalShowerShape )
747 fEMCALRecoUtils->RecalculateClusterShowerShapeParameters(fEMCALGeo, cells, clust);
748
749 // NONLINEARITY -----------------------------------------------
750 if( fDoNonLinearity )
751 {
752 Float_t correctedEnergy = fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
753 clust->SetE(correctedEnergy);
754 }
755
756 // DISTANCE TO BAD CHANNELS -----------------------------------
757 if( fRecalDistToBadChannels )
758 fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);
766cc9de 759 }
57131575 760
766cc9de 761 clusArr->Compress();
a0beb012 762
763 if (!fDoTrackMatch)
764 return;
765
50b7a951 766 // TRACK MATCHING -----------------------------------------------------------
dd8e12d1 767 if (!TGeoGlobalMagField::Instance()->GetField()) {
768 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(event);
769 if (esd)
770 esd->InitMagneticField();
771 else {
772 AliAODEvent *aod = dynamic_cast<AliAODEvent*>(event);
773 Double_t curSol = 30000*aod->GetMagneticField()/5.00668;
774 Double_t curDip = 6000 *aod->GetMuonMagFieldScale();
775 AliMagF *field = AliMagF::CreateFieldMap(curSol,curDip);
776 TGeoGlobalMagField::Instance()->SetField(field);
777 }
766cc9de 778 }
dd8e12d1 779
766cc9de 780 fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
57131575 781 fEMCALRecoUtils->SetClusterMatchedToTrack(event);
782 fEMCALRecoUtils->SetTracksMatchedToCluster(event);
6d67b5a7 783}
784
785//_____________________________________________________
786Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
787{
766cc9de 788 // Initialising misalignment matrices
98e8eede 789
dd8e12d1 790 AliVEvent *event = GetEvent();
6b7df55d 791
766cc9de 792 if (!event)
793 return kFALSE;
6b7df55d 794
50b7a951 795 if (fGeomMatrixSet)
796 {
797 AliInfo("Misalignment matrix already set");
766cc9de 798 return kTRUE;
799 }
6b7df55d 800
766cc9de 801 if (fDebugLevel>0)
50b7a951 802 AliInfo("Initialising misalignment matrix");
6b7df55d 803
766cc9de 804 if (fLoadGeomMatrices) {
50b7a951 805 for(Int_t mod=0; mod < fEMCALGeo->GetNumberOfSuperModules(); ++mod)
806 {
766cc9de 807 if (fEMCALMatrix[mod]){
808 if(fDebugLevel > 2)
809 fEMCALMatrix[mod]->Print();
810 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
811 }
812 }
813 fGeomMatrixSet = kTRUE;
814 return kTRUE;
815 }
6b7df55d 816
766cc9de 817 Int_t runGM = event->GetRunNumber();
6b7df55d 818 TObjArray *mobj = 0;
acf53135 819
98e8eede 820 if(fMisalignSurvey == kdefault)
821 { //take default alignment corresponding to run no
acf53135 822 AliOADBContainer emcalgeoCont(Form("emcal"));
823 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
824 mobj=(TObjArray*)emcalgeoCont.GetObject(runGM,"EmcalMatrices");
acf53135 825 }
98e8eede 826
827 if(fMisalignSurvey == kSurveybyS)
828 { //take alignment at sector level
829 if (runGM <= 140000) { //2010 data
830 AliOADBContainer emcalgeoCont(Form("emcal2010"));
831 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
832 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
833 }
834 else if (runGM>140000)
835 { // 2011 LHC11a pass1 data
836 AliOADBContainer emcalgeoCont(Form("emcal2011"));
837 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
838 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
839 }
840 }
acf53135 841
98e8eede 842 if(fMisalignSurvey == kSurveybyM)
843 { //take alignment at module level
844 if (runGM <= 140000) { //2010 data
845 AliOADBContainer emcalgeoCont(Form("emcal2010"));
846 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
847 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
848 }
849 else if (runGM>140000)
850 { // 2011 LHC11a pass1 data
851 AliOADBContainer emcalgeoCont(Form("emcal2011"));
852 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
853 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byM");
854 }
766cc9de 855 }
acf53135 856
50b7a951 857 if(!mobj)
858 {
4d3c549c 859 AliFatal("Geometry matrix array not found");
860 return kFALSE;
861 }
862
98e8eede 863 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
864 {
865 fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
866 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
867 fEMCALMatrix[mod]->Print();
868 }
4d3c549c 869
766cc9de 870 return kTRUE;
6d67b5a7 871}
872
873//_____________________________________________________
acf53135 874Int_t AliEMCALTenderSupply::InitBadChannels()
6d67b5a7 875{
766cc9de 876 // Initialising bad channel maps
dd8e12d1 877
878 AliVEvent *event = GetEvent();
879
766cc9de 880 if (!event)
acf53135 881 return 0;
6b7df55d 882
766cc9de 883 if (fDebugLevel>0)
884 AliInfo("Initialising Bad channel map");
6b7df55d 885
50b7a951 886 // init default maps first
887 if( !fEMCALRecoUtils->GetEMCALBadChannelStatusMapArray() )
888 fEMCALRecoUtils->InitEMCALBadChannelStatusMap() ;
6b7df55d 889
766cc9de 890 Int_t runBC = event->GetRunNumber();
6b7df55d 891
a0beb012 892 AliOADBContainer *contBC = new AliOADBContainer("");
50b7a951 893 if (fBasePath!="")
894 { //if fBasePath specified in the ->SetBasePath()
acf53135 895 if (fDebugLevel>0) AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
4d3c549c 896
acf53135 897 TFile *fbad=new TFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read");
50b7a951 898 if (!fbad || fbad->IsZombie())
899 {
4d3c549c 900 AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
acf53135 901 return 0;
902 }
4d3c549c 903
a0beb012 904 if (fbad) delete fbad;
4d3c549c 905
acf53135 906 contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
50b7a951 907 }
908 else
909 { // Else choose the one in the $ALICE_ROOT directory
a0beb012 910 if (fDebugLevel>0) AliInfo("Loading Bad Channels OADB from $ALICE_ROOT/OADB/EMCAL");
911
912 TFile *fbad=new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALBadChannels.root","read");
50b7a951 913 if (!fbad || fbad->IsZombie())
914 {
a0beb012 915 AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALBadChannels.root was not found");
916 return 0;
917 }
4d3c549c 918
a0beb012 919 if (fbad) delete fbad;
920
921 contBC->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALBadChannels.root","AliEMCALBadChannels");
922 }
acf53135 923
924 TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
50b7a951 925 if (!arrayBC)
926 {
acf53135 927 AliError(Form("No external hot channel set for run number: %d", runBC));
928 return 2;
766cc9de 929 }
acf53135 930
931 Int_t sms = fEMCALGeo->GetEMCGeometry()->GetNumberOfSuperModules();
50b7a951 932 for (Int_t i=0; i<sms; ++i)
933 {
acf53135 934 TH2I *h = fEMCALRecoUtils->GetEMCALChannelStatusMap(i);
935 if (h)
936 delete h;
dd8e12d1 937 h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
acf53135 938
50b7a951 939 if (!h)
940 {
acf53135 941 AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
942 continue;
943 }
944 h->SetDirectory(0);
945 fEMCALRecoUtils->SetEMCALChannelStatusMap(i,h);
766cc9de 946 }
acf53135 947 return 1;
6d67b5a7 948}
949
950//_____________________________________________________
acf53135 951Int_t AliEMCALTenderSupply::InitRecalib()
6d67b5a7 952{
766cc9de 953 // Initialising recalibration factors.
6b7df55d 954
dd8e12d1 955 AliVEvent *event = GetEvent();
956
766cc9de 957 if (!event)
acf53135 958 return 0;
6b7df55d 959
766cc9de 960 if (fDebugLevel>0)
961 AliInfo("Initialising recalibration factors");
6b7df55d 962
50b7a951 963 // init default maps first
964 if( !fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray() )
965 fEMCALRecoUtils->InitEMCALRecalibrationFactors() ;
966
766cc9de 967 Int_t runRC = event->GetRunNumber();
acf53135 968
969 AliOADBContainer *contRF=new AliOADBContainer("");
50b7a951 970 if (fBasePath!="")
971 { //if fBasePath specified in the ->SetBasePath()
972 if (fDebugLevel>0) AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
4d3c549c 973
acf53135 974 TFile *fRecalib= new TFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read");
50b7a951 975 if (!fRecalib || fRecalib->IsZombie())
976 {
4d3c549c 977 AliFatal(Form("EMCALRecalib.root not found in %s",fBasePath.Data()));
acf53135 978 return 0;
766cc9de 979 }
4d3c549c 980
a0beb012 981 if (fRecalib) delete fRecalib;
4d3c549c 982
acf53135 983 contRF->InitFromFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"AliEMCALRecalib");
984 }
98e8eede 985 else
986 { // Else choose the one in the $ALICE_ROOT directory
987 if (fDebugLevel>0) AliInfo("Loading Recalib OADB from $ALICE_ROOT/OADB/EMCAL");
988
989 TFile *fRecalib= new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","read");
990 if (!fRecalib || fRecalib->IsZombie())
991 {
992 AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root was not found");
993 return 0;
766cc9de 994 }
98e8eede 995
996 if (fRecalib) delete fRecalib;
997
998 contRF->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","AliEMCALRecalib");
999 }
acf53135 1000
dd8e12d1 1001 TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
50b7a951 1002 if (!recal)
1003 {
acf53135 1004 AliError(Form("No Objects for run: %d",runRC));
1005 return 2;
1006 }
1007
1008 TObjArray *recalpass=(TObjArray*)recal->FindObject(fFilepass);
50b7a951 1009 if (!recalpass)
1010 {
acf53135 1011 AliError(Form("No Objects for run: %d - %s",runRC,fFilepass.Data()));
1012 return 2;
1013 }
1014
1015 TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
50b7a951 1016 if (!recalib)
1017 {
acf53135 1018 AliError(Form("No Recalib histos found for %d - %s",runRC,fFilepass.Data()));
1019 return 2;
1020 }
1021
a0beb012 1022 if (fDebugLevel>0) recalib->Print();
acf53135 1023
1024 Int_t sms = fEMCALGeo->GetEMCGeometry()->GetNumberOfSuperModules();
50b7a951 1025 for (Int_t i=0; i<sms; ++i)
1026 {
acf53135 1027 TH2F *h = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactors(i);
1028 if (h)
1029 delete h;
1030 h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
50b7a951 1031 if (!h)
1032 {
acf53135 1033 AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
1034 continue;
766cc9de 1035 }
acf53135 1036 h->SetDirectory(0);
1037 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
766cc9de 1038 }
acf53135 1039 return 1;
c958a2f7 1040}
1041
7bf608c9 1042//_____________________________________________________
1043Int_t AliEMCALTenderSupply::InitRunDepRecalib()
1044{
1045 // Initialising recalibration factors.
1046
1047 AliVEvent *event = GetEvent();
1048
1049 if (!event)
1050 return 0;
1051
1052 if (fDebugLevel>0)
1053 AliInfo("Initialising recalibration factors");
1054
1055 // init default maps first
1056 if( !fEMCALRecoUtils->GetEMCALRecalibrationFactorsArray() )
1057 fEMCALRecoUtils->InitEMCALRecalibrationFactors() ;
1058
1059 Int_t runRC = event->GetRunNumber();
1060
1061 AliOADBContainer *contRF=new AliOADBContainer("");
1062 if (fBasePath!="")
1063 { //if fBasePath specified in the ->SetBasePath()
1064 if (fDebugLevel>0) AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
1065
1066 TFile *fRunDepRecalib= new TFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read");
1067 if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
1068 {
1069 AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
1070 return 0;
1071 }
1072
1073 if (fRunDepRecalib) delete fRunDepRecalib;
1074
1075 contRF->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"AliEMCALRunDepTempCalibCorrections");
1076 }
1077 else
1078 { // Else choose the one in the $ALICE_ROOT directory
1079 if (fDebugLevel>0) AliInfo("Loading Recalib OADB from $ALICE_ROOT/OADB/EMCAL");
1080
1081 TFile *fRunDepRecalib= new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root","read");
1082 if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
1083 {
1084 AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
1085 return 0;
1086 }
1087
1088 if (fRunDepRecalib) delete fRunDepRecalib;
1089
1090 contRF->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALTemperatureCorrCalib.root","AliEMCALRunDepTempCalibCorrections");
1091 }
1092
1093 TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
1094 if (!rundeprecal)
1095 {
1096 AliError(Form("No Objects for run: %d",runRC));
1097 return 2;
1098 }
1099
1100 if (fDebugLevel>0) rundeprecal->Print();
1101
1102 Int_t nSM = fEMCALGeo->GetEMCGeometry()->GetNumberOfSuperModules();
1103
1104 for (Int_t ism=0; ism<nSM; ++ism)
1105 {
1106 for (Int_t icol=0; icol<48; ++icol)
1107 {
1108 for (Int_t irow=0; irow<24; ++irow)
1109 {
1110 Float_t factor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
1111
1112 Int_t absID = fEMCALGeo->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
1113 factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
1114 //printf("\t ism %d, icol %d, irow %d,absID %d, corrA %2.3f, corrB %2.3f, corrAB %2.3f\n",ism, icol, irow, absID,
1115 // GetEMCALChannelRecalibrationFactor(ism,icol,irow) , rundeprecal->GetBinContent(absID) / 10000., factor);
1116 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
1117 } // columns
1118 } // rows
1119 } // SM loop
1120
1121 return 1;
1122}
1123
1124
50b7a951 1125//_____________________________________________________
1126Int_t AliEMCALTenderSupply::InitTimeCalibration()
1127{
1128 // Initialising bad channel maps
dd8e12d1 1129 AliVEvent *event = GetEvent();
1130
50b7a951 1131 if (!event)
1132 return 0;
1133
1134 if (fDebugLevel>0)
1135 AliInfo("Initialising time calibration map");
1136
1137 // init default maps first
98e8eede 1138 if ( !fEMCALRecoUtils->GetEMCALTimeRecalibrationFactorsArray() )
50b7a951 1139 fEMCALRecoUtils->InitEMCALTimeRecalibrationFactors() ;
1140
1141 Int_t runBC = event->GetRunNumber();
1142
1143 AliOADBContainer *contBC = new AliOADBContainer("");
1144 if (fBasePath!="")
1145 { //if fBasePath specified in the ->SetBasePath()
1146 if (fDebugLevel>0) AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
1147
1148 TFile *fbad=new TFile(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"read");
1149 if (!fbad || fbad->IsZombie())
1150 {
1151 AliFatal(Form("EMCALTimeCalib.root was not found in the path provided: %s",fBasePath.Data()));
1152 return 0;
1153 }
1154
1155 if (fbad) delete fbad;
1156
1157 contBC->InitFromFile(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"AliEMCALTimeCalib");
1158 }
1159 else
1160 { // Else choose the one in the $ALICE_ROOT directory
1161 if (fDebugLevel>0) AliInfo("Loading time calibration OADB from $ALICE_ROOT/OADB/EMCAL");
1162
1163 TFile *fbad=new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALTimeCalib.root","read");
1164 if (!fbad || fbad->IsZombie())
1165 {
1166 AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALTimeCalib.root was not found");
1167 return 0;
1168 }
1169
1170 if (fbad) delete fbad;
1171
1172 contBC->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALTimeCalib.root","AliEMCALTimeCalib");
1173 }
1174
1175 TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
1176 if (!arrayBC)
1177 {
1178 AliError(Form("No external time calibration set for run number: %d", runBC));
1179 return 2;
1180 }
1181
dd8e12d1 1182 // Here, it looks for a specific pass
1183 TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(fFilepass);
50b7a951 1184 if (!arrayBCpass)
1185 {
1186 AliError(Form("No external time calibration set for: %d -%s", runBC,fFilepass.Data()));
1187 return 2;
1188 }
1189
1190 if (fDebugLevel>0) arrayBCpass->Print();
1191
1192 for( Int_t i = 0; i < 4; i++ )
1193 {
1194 TH1F *h = fEMCALRecoUtils->GetEMCALChannelTimeRecalibrationFactors( i );
1195 if( h )
1196 delete h;
1197
1198 h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
1199
1200 if (!h)
1201 {
1202 AliError(Form("Can not get hAllTimeAvBC%d",i));
1203 continue;
1204 }
1205 h->SetDirectory(0);
1206 fEMCALRecoUtils->SetEMCALChannelTimeRecalibrationFactors(i,h);
1207 }
1208 return 1;
1209}
1210
acf53135 1211//_____________________________________________________
1212void AliEMCALTenderSupply::UpdateCells()
1213{
8b775c10 1214 //Remove bad cells from the cell list
1215 //Recalibrate energy and time cells
acf53135 1216 //This is required for later reclusterization
1217
dd8e12d1 1218 AliVEvent *event = GetEvent();
1219
87acb7a7 1220 if(!event) return ;
1221
dd8e12d1 1222 AliVCaloCells *cells = event->GetEMCALCells();
1223 Int_t bunchCrossNo = event->GetBunchCrossNumber();
acf53135 1224
50b7a951 1225 fEMCALRecoUtils->RecalibrateCells(cells, bunchCrossNo);
1226
1227 // remove exotic cells - loop through cells and zero the exotic ones
1228 // just like with bad cell rejection in reco utils (inside RecalibrateCells)
1229 if( fRejectExoticCells )
1230 {
b524daab 1231 Short_t absId =-1;
1232 Double_t ecell = 0;
1233 Double_t tcell = 0;
1234 Double_t efrac = 0;
1235 Short_t mclabel = -1;
50b7a951 1236 Bool_t isExot = kFALSE;
1237
1238 // loop through cells
1239 Int_t nEMcell = cells->GetNumberOfCells() ;
1240 for (Int_t iCell = 0; iCell < nEMcell; iCell++)
1241 {
b524daab 1242 cells->GetCell( iCell, absId, ecell, tcell, mclabel, efrac );
50b7a951 1243
1244 isExot = fEMCALRecoUtils->IsExoticCell( absId, cells, bunchCrossNo );
1245 // zero if exotic
1246 if( isExot )
b524daab 1247 cells->SetCell( iCell, absId, 0.0, -1.0, mclabel, efrac );
50b7a951 1248 } // cell loop
1249 } // reject exotic cells
a0beb012 1250
1251 cells->Sort();
8b775c10 1252}
acf53135 1253
1254//_____________________________________________________
dd8e12d1 1255TString AliEMCALTenderSupply::GetBeamType()
acf53135 1256{
dd8e12d1 1257 // Get beam type : pp-AA-pA
98e8eede 1258 // ESDs have it directly, AODs get it from hardcoded run number ranges
e768f43c 1259
dd8e12d1 1260 AliVEvent *event = GetEvent();
1261
1262 if (!event) {
1263 AliError("Couldn't retrieve event!");
1264 return "";
c05ffa77 1265 }
1266
dd8e12d1 1267 TString beamType;
1268
98e8eede 1269 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(event);
1270 if (esd) {
dd8e12d1 1271 const AliESDRun *run = esd->GetESDRun();
1272 beamType = run->GetBeamType();
1273 }
98e8eede 1274 else
1275 {
dd8e12d1 1276 Int_t runNumber = event->GetRunNumber();
1277 if ((runNumber >= 136851 && runNumber <= 139517) // LHC10h
b524daab 1278 || (runNumber >= 166529 && runNumber <= 170593)) // LHC11h
98e8eede 1279 {
1280 beamType = "A-A";
1281 }
c05ffa77 1282 else
98e8eede 1283 {
1284 beamType = "p-p";
1285 }
a0beb012 1286 }
dd8e12d1 1287
1288 return beamType;
1289}
1290
1291//_____________________________________________________
1292Int_t AliEMCALTenderSupply::InitRecParam()
1293{
98e8eede 1294 // Init reco params if not yet exist (probably shipped by the user already)
1295
dd8e12d1 1296 if( fRecParam != 0 )
1297 return 2;
1298
1299 TString beamType = GetBeamType();
1300
1301 // set some default reco params
1302 fRecParam = new AliEMCALRecParam();
1303 fRecParam->SetClusteringThreshold(0.100);
1304 fRecParam->SetMinECut(0.050);
1305 fRecParam->SetTimeCut(250);
1306 fRecParam->SetTimeMin(425);
1307 fRecParam->SetTimeMax(825);
1308 if ( beamType == "A-A") {
1309 fRecParam->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv2);
1310 }
1311 else {
1312 fRecParam->SetClusterizerFlag(AliEMCALRecParam::kClusterizerv1);
1313 }
1314
1315 return 0;
acf53135 1316}
1317
b20bc239 1318//_____________________________________________________
766cc9de 1319Bool_t AliEMCALTenderSupply::InitClusterization()
b20bc239 1320{
766cc9de 1321 // Initialing clusterization/unfolding algorithm and set all the needed parameters.
6b7df55d 1322
dd8e12d1 1323 AliVEvent *event = GetEvent();
1324
766cc9de 1325 if (!event)
1326 return kFALSE;
6b7df55d 1327
766cc9de 1328 if (fDebugLevel>0)
a0beb012 1329 AliInfo(Form("Initialising reclustering parameters: Clusterizer type: %d",fRecParam->GetClusterizerFlag()));
6b7df55d 1330
766cc9de 1331 //---setup clusterizer
1332 delete fClusterizer;
1333 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
1334 fClusterizer = new AliEMCALClusterizerv1 (fEMCALGeo);
a0beb012 1335 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
766cc9de 1336 fClusterizer = new AliEMCALClusterizerv2(fEMCALGeo);
50b7a951 1337 else if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
1338 {
766cc9de 1339 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
1340 clusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
1341 clusterizer->SetNColDiff(fRecParam->GetNColDiff());
1342 fClusterizer = clusterizer;
50b7a951 1343 }
1344 else
1345 {
766cc9de 1346 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
1347 return kFALSE;
1348 }
6b7df55d 1349
766cc9de 1350 // Set the clustering parameters
1351 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
1352 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
1353 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
1354 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
1355 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
1356 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
1357 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
1358 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
1359 fClusterizer->SetInputCalibrated ( kTRUE );
1360 fClusterizer->SetJustClusters ( kTRUE );
6b7df55d 1361
766cc9de 1362 // In case of unfolding after clusterization is requested, set the corresponding parameters
50b7a951 1363 if (fRecParam->GetUnfold())
1364 {
1365 for (Int_t i = 0; i < 8; ++i)
1366 {
766cc9de 1367 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
1368 }
50b7a951 1369 for (Int_t i = 0; i < 3; ++i)
1370 {
766cc9de 1371 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
1372 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
1373 }
1374 fClusterizer->InitClusterUnfolding();
1375 }
6b7df55d 1376
766cc9de 1377 fClusterizer->SetDigitsArr(fDigitsArr);
1378 fClusterizer->SetOutput(0);
1379 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
1380 return kTRUE;
b20bc239 1381}
766cc9de 1382
b20bc239 1383//_____________________________________________________
1384void AliEMCALTenderSupply::FillDigitsArray()
1385{
766cc9de 1386 // Fill digits from cells to a TClonesArray.
6b7df55d 1387
dd8e12d1 1388 AliVEvent *event = GetEvent();
1389
b524daab 1390 if (!event)
766cc9de 1391 return;
6b7df55d 1392
766cc9de 1393 fDigitsArr->Clear("C");
dd8e12d1 1394 AliVCaloCells *cells = event->GetEMCALCells();
766cc9de 1395 Int_t ncells = cells->GetNumberOfCells();
50b7a951 1396 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell)
1397 {
77e93dc2 1398 Double_t cellAmplitude=0, cellTime=0, efrac = 0;
1399 Short_t cellNumber=0, mcLabel=-1;
a0beb012 1400
77e93dc2 1401 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime, mcLabel, efrac) != kTRUE)
766cc9de 1402 break;
94f7c836 1403
1404 // Do not add if already too low (some cells set to 0 if bad channels)
a0beb012 1405 if (cellAmplitude < fRecParam->GetMinECut() )
94f7c836 1406 continue;
a0beb012 1407
1408 // If requested, do not include exotic cells
1409 if (fEMCALRecoUtils->IsExoticCell(cellNumber,cells,event->GetBunchCrossNumber()))
94f7c836 1410 continue;
1411
766cc9de 1412 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
1413 digit->SetId(cellNumber);
b524daab 1414 digit->SetTime((Float_t)cellTime);
1415 digit->SetTimeR((Float_t)cellTime);
766cc9de 1416 digit->SetIndexInList(idigit);
1417 digit->SetType(AliEMCALDigit::kHG);
b524daab 1418 digit->SetAmplitude((Float_t)cellAmplitude);
766cc9de 1419 idigit++;
1420 }
b20bc239 1421}
1422
1423//_____________________________________________________
1424void AliEMCALTenderSupply::Clusterize()
1425{
766cc9de 1426 // Clusterize.
6b7df55d 1427
766cc9de 1428 fClusterizer->Digits2Clusters("");
b20bc239 1429}
1430
1431//_____________________________________________________
1432void AliEMCALTenderSupply::UpdateClusters()
1433{
766cc9de 1434 // Update ESD cluster list.
6b7df55d 1435
dd8e12d1 1436 AliVEvent *event = GetEvent();
1437
766cc9de 1438 if (!event)
1439 return;
6b7df55d 1440
766cc9de 1441 TClonesArray *clus = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
1442 if (!clus)
1443 clus = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
50b7a951 1444 if (!clus)
1445 {
6b7df55d 1446 AliError(" Null pointer to calo clusters array, returning");
766cc9de 1447 return;
1448 }
6b7df55d 1449
766cc9de 1450 Int_t nents = clus->GetEntriesFast();
50b7a951 1451 for (Int_t i=0; i < nents; ++i)
1452 {
98e8eede 1453 AliVCluster *c = dynamic_cast<AliVCluster*>(clus->At(i));
766cc9de 1454 if (!c)
1455 continue;
1456 if (c->IsEMCAL())
1457 delete clus->RemoveAt(i);
1458 }
50b7a951 1459
766cc9de 1460 clus->Compress();
50b7a951 1461
766cc9de 1462 RecPoints2Clusters(clus);
b20bc239 1463}
1464
1465//_____________________________________________________
1466void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
1467{
98e8eede 1468 // Convert AliEMCALRecoPoints to AliESDCaloClusters/AliAODCaloClusters.
766cc9de 1469 // Cluster energy, global position, cells and their amplitude fractions are restored.
1470
dd8e12d1 1471 AliVEvent *event = GetEvent();
1472
766cc9de 1473 if (!event)
1474 return;
94f7c836 1475
766cc9de 1476 Int_t ncls = fClusterArr->GetEntriesFast();
50b7a951 1477 for(Int_t i=0, nout=clus->GetEntriesFast(); i < ncls; ++i)
1478 {
766cc9de 1479 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
1480
4d3c549c 1481 Int_t ncellsTrue = 0;
766cc9de 1482 const Int_t ncells = recpoint->GetMultiplicity();
1483 UShort_t absIds[ncells];
1484 Double32_t ratios[ncells];
1485 Int_t *dlist = recpoint->GetDigitsList();
1486 Float_t *elist = recpoint->GetEnergiesList();
50b7a951 1487 for (Int_t c = 0; c < ncells; ++c)
1488 {
766cc9de 1489 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
4d3c549c 1490 absIds[ncellsTrue] = digit->GetId();
1491 ratios[ncellsTrue] = elist[c]/digit->GetAmplitude();
1492 if (ratios[ncellsTrue] < 0.001)
766cc9de 1493 continue;
4d3c549c 1494 ++ncellsTrue;
766cc9de 1495 }
1496
50b7a951 1497 if (ncellsTrue < 1)
1498 {
766cc9de 1499 AliWarning("Skipping cluster with no cells");
1500 continue;
1501 }
1502
1503 // calculate new cluster position
1504 TVector3 gpos;
1505 recpoint->GetGlobalPosition(gpos);
1506 Float_t g[3];
1507 gpos.GetXYZ(g);
1508
98e8eede 1509 AliVCluster *c = static_cast<AliVCluster*>(clus->New(nout++));
94f7c836 1510 c->SetID(nout-1);
766cc9de 1511 c->SetType(AliVCluster::kEMCALClusterv1);
1512 c->SetE(recpoint->GetEnergy());
1513 c->SetPosition(g);
4d3c549c 1514 c->SetNCells(ncellsTrue);
766cc9de 1515 c->SetDispersion(recpoint->GetDispersion());
1516 c->SetEmcCpvDistance(-1); //not yet implemented
1517 c->SetChi2(-1); //not yet implemented
1518 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
1519 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
1520 Float_t elipAxis[2];
1521 recpoint->GetElipsAxis(elipAxis);
1522 c->SetM02(elipAxis[0]*elipAxis[0]) ;
1523 c->SetM20(elipAxis[1]*elipAxis[1]) ;
98e8eede 1524 c->SetCellsAbsId(absIds);
1525 c->SetCellsAmplitudeFraction(ratios);
766cc9de 1526 }
1527}
b20bc239 1528
766cc9de 1529//_____________________________________________________
1530void AliEMCALTenderSupply::GetPass()
1531{
1532 // Get passx from filename.
6b7df55d 1533
766cc9de 1534 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1535 fInputTree = mgr->GetTree();
6b7df55d 1536
50b7a951 1537 if (!fInputTree)
1538 {
6b7df55d 1539 AliError("Pointer to tree = 0, returning");
766cc9de 1540 return;
1541 }
6b7df55d 1542
766cc9de 1543 fInputFile = fInputTree->GetCurrentFile();
1544 if (!fInputFile) {
6b7df55d 1545 AliError("Null pointer input file, returning");
766cc9de 1546 return;
1547 }
6b7df55d 1548
766cc9de 1549 TString fname(fInputFile->GetName());
a0beb012 1550 if (fname.Contains("pass1")) fFilepass = TString("pass1");
1551 else if (fname.Contains("pass2")) fFilepass = TString("pass2");
1552 else if (fname.Contains("pass3")) fFilepass = TString("pass3");
50b7a951 1553 else
1554 {
766cc9de 1555 AliError(Form("Pass number string not found: %s", fname.Data()));
1556 return;
1557 }
b20bc239 1558}