]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALClusterizerNxN.cxx
Added function to make relative calibration objects
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizerNxN.cxx
CommitLineData
ee08edde 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// This class derives from AliEMCALClustrerizer but also keeps the API of AliEMCALClusterizerv1
17// Algorithm:
18// 1. peek the most energetic cell
19// 2. assign it as a center of the cluster and add cells surrounding it: 3x3, 5x5...
20// 3. remove the cells contributing to the cluster
21// 4. start from 1 for the remaining clusters
22// 5. cluster splitting (not implemented yet) - use the shape analysis to resolve the energy sharing
23// - for high energy clusters check the surrounding of the 3x3 clusters for extra energy
24// (merge 3x3 clusters and resolve the internal energy sharing - case for 2 clusters merged)
25// Use Case:
26// root [0] AliEMCALClusterizerNxN * cl = new AliEMCALClusterizerNxN("galice.root")
27// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
28// //reads gAlice from header file "..."
29// root [1] cl->ExecuteTask()
30// //finds RecPoints in all events stored in galice.root
31// root [2] cl->SetDigitsBranch("digits2")
32// //sets another title for Digitis (input) branch
33// root [3] cl->SetRecPointsBranch("recp2")
34// //sets another title four output branches
35// root [4] cl->SetTowerLocalMaxCut(0.03)
36// //set clusterization parameters
37// root [5] cl->ExecuteTask("deb all time")
38// //once more finds RecPoints options are
39// // deb - print number of found rec points
40// // deb all - print number of found RecPoints and some their characteristics
41// // time - print benchmarking results
42
43// --- ROOT system ---
44#include <TMath.h>
45#include <TMinuit.h>
46#include <TTree.h>
47#include <TBenchmark.h>
48#include <TBrowser.h>
49#include <TROOT.h>
50#include <TClonesArray.h>
51
52// --- Standard library ---
53#include <cassert>
54
55// --- AliRoot header files ---
56#include "AliLog.h"
57#include "AliEMCALClusterizerNxN.h"
58#include "AliEMCALRecPoint.h"
59#include "AliEMCALDigit.h"
60#include "AliEMCALGeometry.h"
61#include "AliCaloCalibPedestal.h"
62#include "AliEMCALCalibData.h"
63#include "AliESDCaloCluster.h"
65bec413 64#include "AliEMCALUnfolding.h"
ee08edde 65
66ClassImp(AliEMCALClusterizerNxN)
67
ee08edde 68//____________________________________________________________________________
69AliEMCALClusterizerNxN::AliEMCALClusterizerNxN()
8a84b948 70: AliEMCALClusterizer(), fNRowDiff(1), fNColDiff(1)
ee08edde 71{
72 // ctor with the indication of the file where header Tree and digits Tree are stored
73}
74
75//____________________________________________________________________________
76AliEMCALClusterizerNxN::AliEMCALClusterizerNxN(AliEMCALGeometry* geometry)
8a84b948 77 : AliEMCALClusterizer(geometry), fNRowDiff(1), fNColDiff(1)
ee08edde 78{
79 // ctor with the indication of the file where header Tree and digits Tree are stored
80 // use this contructor to avoid usage of Init() which uses runloader
81 // change needed by HLT - MP
ee08edde 82}
83
84//____________________________________________________________________________
85AliEMCALClusterizerNxN::AliEMCALClusterizerNxN(AliEMCALGeometry* geometry, AliEMCALCalibData * calib, AliCaloCalibPedestal * caloped)
8a84b948 86: AliEMCALClusterizer(geometry, calib, caloped), fNRowDiff(1), fNColDiff(1)
ee08edde 87{
8a84b948 88 // ctor, geometry and calibration are initialized elsewhere.
ee08edde 89}
90
ee08edde 91//____________________________________________________________________________
8a84b948 92AliEMCALClusterizerNxN::~AliEMCALClusterizerNxN()
ee08edde 93{
94 // dtor
95}
96
ee08edde 97//____________________________________________________________________________
98void AliEMCALClusterizerNxN::Digits2Clusters(Option_t * option)
99{
100 // Steering method to perform clusterization for the current event
101 // in AliEMCALLoader
51e4198e 102
bd0552e8 103 if (strstr(option,"tim"))
ee08edde 104 gBenchmark->Start("EMCALClusterizer");
105
bd0552e8 106 if (strstr(option,"print"))
107 Print("");
51e4198e 108
ee08edde 109 //Get calibration parameters from file or digitizer default values.
bd0552e8 110 GetCalibrationParameters();
51e4198e 111
ee08edde 112 //Get dead channel map from file or digitizer default values.
bd0552e8 113 GetCaloCalibPedestal();
ee08edde 114
bd0552e8 115 MakeClusters(); //only the real clusters
51e4198e 116
bd0552e8 117 if (fToUnfold) {
65bec413 118 fClusterUnfolding->SetInput(fNumberOfECAClusters,fRecPoints,fDigitsArr);
119 fClusterUnfolding->MakeUnfolding();
120 }
51e4198e 121
65bec413 122 //Evaluate position, dispersion and other RecPoint properties for EC section
bd0552e8 123 for (Int_t index = 0; index < fRecPoints->GetEntries(); index++) {
51e4198e 124 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index));
bd0552e8 125 if (rp) {
126 rp->EvalAll(fECAW0,fDigitsArr,fIsInputCalibrated);
51e4198e 127 AliDebug(5, Form("MAX INDEX %d ", rp->GetMaximalEnergyIndex()));
ee08edde 128 //For each rec.point set the distance to the nearest bad crystal
bd0552e8 129 if (fCaloPed)
130 rp->EvalDistanceToBadChannels(fCaloPed);
ee08edde 131 }
51e4198e 132 }
ee08edde 133
bd0552e8 134 fRecPoints->Sort();
51e4198e 135
bd0552e8 136 for (Int_t index = 0; index < fRecPoints->GetEntries(); index++) {
137 AliEMCALRecPoint *rp = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index));
138 if (rp) {
139 rp->SetIndexInList(index);
7e1d9a9b 140 }
141 else AliFatal("RecPoint NULL!!");
51e4198e 142 }
ee08edde 143
bd0552e8 144 if (fTreeR)
145 fTreeR->Fill();
ee08edde 146
bd0552e8 147 if (strstr(option,"deb") || strstr(option,"all"))
148 PrintRecPoints(option);
51e4198e 149
ee08edde 150 AliDebug(1,Form("EMCAL Clusterizer found %d Rec Points",fRecPoints->GetEntriesFast()));
51e4198e 151
bd0552e8 152 if (strstr(option,"tim")) {
ee08edde 153 gBenchmark->Stop("EMCALClusterizer");
154 printf("Exec took %f seconds for Clusterizing",
51e4198e 155 gBenchmark->GetCpuTime("EMCALClusterizer"));
ee08edde 156 }
157}
158
159//____________________________________________________________________________
160Int_t AliEMCALClusterizerNxN::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2, Bool_t & shared) const
161{
c526514b 162 // Gives the neighbourness of two digits = 0 are not neighbour ; continue searching
163 // = 1 are neighbour
164 // = 2 is in different SM; continue searching
165 // In case it is in different SM, but same phi rack, check if neigbours at eta=0
166 // neighbours are defined as digits having at least a common side
167 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
168 // which is compared to a digit (d2) not yet in a cluster
169
bd0552e8 170 Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0, iphi1=0, ieta1=0;
171 Int_t nSupMod2=0, nModule2=0, nIphi2=0, nIeta2=0, iphi2=0, ieta2=0;
172 Int_t rowdiff=0, coldiff=0;
c526514b 173
174 shared = kFALSE;
175
176 fGeom->GetCellIndex(d1->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
177 fGeom->GetCellIndex(d2->GetId(), nSupMod2,nModule2,nIphi2,nIeta2);
178 fGeom->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, iphi1,ieta1);
179 fGeom->GetCellPhiEtaIndexInSModule(nSupMod2,nModule2,nIphi2,nIeta2, iphi2,ieta2);
180
181 //If different SM, check if they are in the same phi, then consider cells close to eta=0 as neighbours; May 2010
bd0552e8 182 if (nSupMod1 != nSupMod2 )
c526514b 183 {
184 //Check if the 2 SM are in the same PHI position (0,1), (2,3), ...
185 Float_t smPhi1 = fGeom->GetEMCGeometry()->GetPhiCenterOfSM(nSupMod1);
186 Float_t smPhi2 = fGeom->GetEMCGeometry()->GetPhiCenterOfSM(nSupMod2);
187
bd0552e8 188 if (!TMath::AreEqualAbs(smPhi1, smPhi2, 1e-3)) return 2; //Not phi rack equal, not neighbours
c526514b 189
190 // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
191 // C Side impair SM, nSupMod%2=1; A side pair SM nSupMod%2=0
bd0552e8 192 if (nSupMod1%2) ieta1+=AliEMCALGeoParams::fgkEMCALCols;
c526514b 193 else ieta2+=AliEMCALGeoParams::fgkEMCALCols;
194
195 shared = kTRUE; // maybe a shared cluster, we know this later, set it for the moment.
196
197 }//Different SM, same phi
198
199 rowdiff = TMath::Abs(iphi1 - iphi2);
bd0552e8 200 coldiff = TMath::Abs(ieta1 - ieta2);
c526514b 201
202 // neighbours +-1 in col and row
8a84b948 203 if ( TMath::Abs(coldiff) <= fNColDiff && TMath::Abs(rowdiff) <= fNRowDiff)
c526514b 204 {
205
206 AliDebug(9, Form("AliEMCALClusterizerNxN::AreNeighbours(): id1=%d, (row %d, col %d) ; id2=%d, (row %d, col %d), shared %d \n",
207 d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2, shared));
208
209 return 1;
210 }//Neighbours
211 else
212 {
213 AliDebug(9, Form("NOT AliEMCALClusterizerNxN::AreNeighbours(): id1=%d, (row %d, col %d) ; id2=%d, (row %d, col %d), shared %d \n",
214 d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2, shared));
215 shared = kFALSE;
bd0552e8 216 return 2;
c526514b 217 }//Not neighbours
ee08edde 218}
219
220//____________________________________________________________________________
221void AliEMCALClusterizerNxN::MakeClusters()
222{
8a84b948 223 // Make clusters
51e4198e 224
8a84b948 225 if (fGeom==0)
226 AliFatal("Did not get geometry from EMCALLoader");
51e4198e 227
bd0552e8 228 fNumberOfECAClusters = 0;
229 fRecPoints->Delete();
51e4198e 230
ee08edde 231 // Set up TObjArray with pointers to digits to work on
ee08edde 232 TObjArray digitsC;
233 TIter nextdigit(fDigitsArr);
234 AliEMCALDigit *digit = 0;
bd0552e8 235 while ( (digit = static_cast<AliEMCALDigit*>(nextdigit())) ) {
8a84b948 236 Float_t dEnergyCalibrated = Calibrate(digit->GetAmplitude(), digit->GetTime(),digit->GetId());
237 digit->SetCalibAmp(dEnergyCalibrated);
ee08edde 238 digitsC.AddLast(digit);
239 }
51e4198e 240
ee08edde 241 TIter nextdigitC(&digitsC);
51e4198e 242
ee08edde 243 AliDebug(1,Form("MakeClusters: Number of digits %d -> (e %f)\n",
51e4198e 244 fDigitsArr->GetEntries(),fMinECut));
245
ee08edde 246 Bool_t bDone = kFALSE;
247 while ( bDone != kTRUE )
51e4198e 248 {
249 //first sort the digits:
250 Int_t iMaxEnergyDigit = -1;
251 Float_t dMaxEnergyDigit = -1;
252 AliEMCALDigit *pMaxEnergyDigit = 0;
253 nextdigitC.Reset();
8a84b948 254 while ( (digit = static_cast<AliEMCALDigit *>(nextdigitC())) )
51e4198e 255 { // scan over the list of digitsC
8a84b948 256 Float_t dEnergyCalibrated = digit->GetCalibAmp();
257
bd0552e8 258 if (fGeom->CheckAbsCellId(digit->GetId()) && dEnergyCalibrated > 0.0) // no threshold!
8a84b948 259 {
260 if (dEnergyCalibrated > dMaxEnergyDigit)
51e4198e 261 {
262 dMaxEnergyDigit = dEnergyCalibrated;
263 iMaxEnergyDigit = digit->GetId();
264 pMaxEnergyDigit = digit;
265 }
8a84b948 266 }
51e4198e 267 }
51e4198e 268 if (iMaxEnergyDigit < 0 || digitsC.GetEntries() <= 0)
269 {
270 bDone = kTRUE;
271 continue;
272 }
273
8a84b948 274 AliDebug (2, Form("Max digit found: %1.5f AbsId: %d", dMaxEnergyDigit, iMaxEnergyDigit));
51e4198e 275
276 // keep the candidate digits in a list
277 TList clusterDigitList;
278 clusterDigitList.SetOwner(kFALSE);
279 clusterDigitList.AddLast(pMaxEnergyDigit);
280
281 Double_t clusterCandidateEnergy = dMaxEnergyDigit;
282
8a84b948 283 // now loop over the rest of the digits and cluster into NxN cluster
51e4198e 284 // we do not actually cluster yet: we keep them in the list clusterDigitList
285 nextdigitC.Reset();
bd0552e8 286 while ( (digit = static_cast<AliEMCALDigit *>(nextdigitC())) )
51e4198e 287 { // scan over the list of digitsC
288 if (digit == pMaxEnergyDigit) continue;
8a84b948 289 Float_t dEnergyCalibrated = digit->GetCalibAmp();
51e4198e 290 AliDebug(5, Form("-> Digit ENERGY: %1.5f", dEnergyCalibrated));
bd0552e8 291 if (fGeom->CheckAbsCellId(digit->GetId()) && dEnergyCalibrated > 0.0 )
8a84b948 292 {
293 Float_t time = pMaxEnergyDigit->GetTime(); //Time or TimeR?
bd0552e8 294 if (TMath::Abs(time - digit->GetTime()) > fTimeCut ) continue; //Time or TimeR?
8a84b948 295 Bool_t shared = kFALSE; //cluster shared by 2 SuperModules?
296 if (AreNeighbours(pMaxEnergyDigit, digit, shared) == 1) // call (digit,digitN) in THAT order !!!!!
51e4198e 297 {
bd0552e8 298 clusterDigitList.AddLast(digit);
51e4198e 299 clusterCandidateEnergy += dEnergyCalibrated;
300 }
8a84b948 301 }
51e4198e 302 }// loop over the next digits
303
304 // start a cluster here only if a cluster energy is larger than clustering threshold
51e4198e 305 AliDebug(5, Form("Clusterization threshold is %f MeV", fECAClusteringThreshold));
306 if (clusterCandidateEnergy > fECAClusteringThreshold)
307 {
bd0552e8 308 if (fNumberOfECAClusters >= fRecPoints->GetSize())
309 fRecPoints->Expand(2*fNumberOfECAClusters+1);
ee08edde 310
bd0552e8 311 AliEMCALRecPoint *recPoint = new AliEMCALRecPoint("");
312 fRecPoints->AddAt(recPoint, fNumberOfECAClusters);
313 recPoint = static_cast<AliEMCALRecPoint *>(fRecPoints->At(fNumberOfECAClusters));
314 if (recPoint) {
315 fNumberOfECAClusters++;
51e4198e 316 recPoint->SetClusterType(AliVCluster::kEMCALClusterv1);
317
318 AliDebug(9, Form("Number of cells per cluster (max is 9!): %d", clusterDigitList.GetEntries()));
319 for (Int_t idig = 0; idig < clusterDigitList.GetEntries(); idig++)
320 {
51e4198e 321 digit = (AliEMCALDigit*)clusterDigitList.At(idig);
8a84b948 322 Float_t dEnergyCalibrated = digit->GetCalibAmp();
51e4198e 323 AliDebug(5, Form(" Adding digit %d", digit->GetId()));
324 // note: this way the sharing info is lost!
bd0552e8 325 recPoint->AddDigit(*digit, dEnergyCalibrated, kFALSE); //Time or TimeR?
51e4198e 326 digitsC.Remove(digit);
327 }
328 }// recpoint
329 }
330 else
331 {
332 // we do not want to start clustering in the same spot!
333 // but in this case we may NOT reuse this seed for another cluster!
334 // need a better bookeeping?
335 digitsC.Remove(pMaxEnergyDigit);
336 }
337
338 AliDebug (2, Form("Number of digits left: %d", digitsC.GetEntries()));
339 } // while ! done
340
ee08edde 341 AliDebug(1,Form("total no of clusters %d from %d digits",fNumberOfECAClusters,fDigitsArr->GetEntriesFast()));
342}