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