1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // This class derives from AliEMCALClustrerizer but also keeps the API of AliEMCALClusterizerv1
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)
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
43 // --- ROOT system ---
47 #include <TBenchmark.h>
50 #include <TClonesArray.h>
52 // --- Standard library ---
55 // --- AliRoot header files ---
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"
64 #include "AliEMCALUnfolding.h"
66 ClassImp(AliEMCALClusterizerNxN)
68 Bool_t AliEMCALClusterizerNxN::fgkIsInputCalibrated = kFALSE;
70 //____________________________________________________________________________
71 AliEMCALClusterizerNxN::AliEMCALClusterizerNxN()
72 : AliEMCALClusterizer()
74 // ctor with the indication of the file where header Tree and digits Tree are stored
77 //____________________________________________________________________________
78 AliEMCALClusterizerNxN::AliEMCALClusterizerNxN(AliEMCALGeometry* geometry)
79 : AliEMCALClusterizer(geometry)
81 // ctor with the indication of the file where header Tree and digits Tree are stored
82 // use this contructor to avoid usage of Init() which uses runloader
83 // change needed by HLT - MP
87 //____________________________________________________________________________
88 AliEMCALClusterizerNxN::AliEMCALClusterizerNxN(AliEMCALGeometry* geometry, AliEMCALCalibData * calib, AliCaloCalibPedestal * caloped)
89 : AliEMCALClusterizer(geometry, calib, caloped)
91 // ctor, geometry and calibration are initialized elsewhere.
96 //____________________________________________________________________________
97 AliEMCALClusterizerNxN::~AliEMCALClusterizerNxN()
103 //____________________________________________________________________________
104 void AliEMCALClusterizerNxN::Digits2Clusters(Option_t * option)
106 // Steering method to perform clusterization for the current event
109 if(strstr(option,"tim"))
110 gBenchmark->Start("EMCALClusterizer");
112 if(strstr(option,"print"))
115 //Get calibration parameters from file or digitizer default values.
116 GetCalibrationParameters() ;
118 //Get dead channel map from file or digitizer default values.
119 GetCaloCalibPedestal() ;
121 fNumberOfECAClusters = 0;
123 MakeClusters() ; //only the real clusters
126 fClusterUnfolding->SetInput(fNumberOfECAClusters,fRecPoints,fDigitsArr);
127 fClusterUnfolding->MakeUnfolding();
130 //Evaluate position, dispersion and other RecPoint properties for EC section
132 for(index = 0; index < fRecPoints->GetEntries(); index++)
134 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index));
136 rp->EvalAll(fECAW0,fDigitsArr) ;
137 AliDebug(5, Form("MAX INDEX %d ", rp->GetMaximalEnergyIndex()));
138 //For each rec.point set the distance to the nearest bad crystal
139 rp->EvalDistanceToBadChannels(fCaloPed);
145 for(index = 0; index < fRecPoints->GetEntries(); index++)
147 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index));
149 rp->SetIndexInList(index) ;
152 else AliFatal("RecPoint NULL!!");
157 if(strstr(option,"deb") || strstr(option,"all"))
158 PrintRecPoints(option) ;
160 AliDebug(1,Form("EMCAL Clusterizer found %d Rec Points",fRecPoints->GetEntriesFast()));
162 fRecPoints->Delete();
164 if(strstr(option,"tim")){
165 gBenchmark->Stop("EMCALClusterizer");
166 printf("Exec took %f seconds for Clusterizing",
167 gBenchmark->GetCpuTime("EMCALClusterizer"));
171 //____________________________________________________________________________
172 Int_t AliEMCALClusterizerNxN::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2, Bool_t & shared) const
174 // Gives the neighbourness of two digits = 0 are not neighbour ; continue searching
176 // = 2 is in different SM; continue searching
177 // In case it is in different SM, but same phi rack, check if neigbours at eta=0
178 // neighbours are defined as digits having at least a common side
179 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
180 // which is compared to a digit (d2) not yet in a cluster
182 static Int_t nSupMod1=0, nModule1=0, nIphi1=0, nIeta1=0, iphi1=0, ieta1=0;
183 static Int_t nSupMod2=0, nModule2=0, nIphi2=0, nIeta2=0, iphi2=0, ieta2=0;
184 static Int_t rowdiff=0, coldiff=0;
188 fGeom->GetCellIndex(d1->GetId(), nSupMod1,nModule1,nIphi1,nIeta1);
189 fGeom->GetCellIndex(d2->GetId(), nSupMod2,nModule2,nIphi2,nIeta2);
190 fGeom->GetCellPhiEtaIndexInSModule(nSupMod1,nModule1,nIphi1,nIeta1, iphi1,ieta1);
191 fGeom->GetCellPhiEtaIndexInSModule(nSupMod2,nModule2,nIphi2,nIeta2, iphi2,ieta2);
193 //If different SM, check if they are in the same phi, then consider cells close to eta=0 as neighbours; May 2010
194 if(nSupMod1 != nSupMod2 )
196 //Check if the 2 SM are in the same PHI position (0,1), (2,3), ...
197 Float_t smPhi1 = fGeom->GetEMCGeometry()->GetPhiCenterOfSM(nSupMod1);
198 Float_t smPhi2 = fGeom->GetEMCGeometry()->GetPhiCenterOfSM(nSupMod2);
200 if(!TMath::AreEqualAbs(smPhi1, smPhi2, 1e-3)) return 2; //Not phi rack equal, not neighbours
202 // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
203 // C Side impair SM, nSupMod%2=1; A side pair SM nSupMod%2=0
204 if(nSupMod1%2) ieta1+=AliEMCALGeoParams::fgkEMCALCols;
205 else ieta2+=AliEMCALGeoParams::fgkEMCALCols;
207 shared = kTRUE; // maybe a shared cluster, we know this later, set it for the moment.
209 }//Different SM, same phi
211 rowdiff = TMath::Abs(iphi1 - iphi2);
212 coldiff = TMath::Abs(ieta1 - ieta2) ;
214 // neighbours +-1 in col and row
215 if ( TMath::Abs(coldiff) < 2 && TMath::Abs(rowdiff) < 2)
218 AliDebug(9, Form("AliEMCALClusterizerNxN::AreNeighbours(): id1=%d, (row %d, col %d) ; id2=%d, (row %d, col %d), shared %d \n",
219 d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2, shared));
225 AliDebug(9, Form("NOT AliEMCALClusterizerNxN::AreNeighbours(): id1=%d, (row %d, col %d) ; id2=%d, (row %d, col %d), shared %d \n",
226 d1->GetId(), iphi1,ieta1, d2->GetId(), iphi2,ieta2, shared));
232 //____________________________________________________________________________
233 void AliEMCALClusterizerNxN::MakeClusters()
235 // Steering method to construct the clusters stored in a list of Reconstructed Points
236 // A cluster is defined as a list of neighbour digits
237 // Mar 03, 2007 by PAI
239 if (fGeom==0) AliFatal("Did not get geometry from EMCALLoader");
243 // Set up TObjArray with pointers to digits to work on
244 //TObjArray *digitsC = new TObjArray();
246 TIter nextdigit(fDigitsArr);
247 AliEMCALDigit *digit = 0;
248 while ( (digit = dynamic_cast<AliEMCALDigit*>(nextdigit())) ) {
249 digitsC.AddLast(digit);
252 TIter nextdigitC(&digitsC);
254 AliDebug(1,Form("MakeClusters: Number of digits %d -> (e %f)\n",
255 fDigitsArr->GetEntries(),fMinECut));
257 Bool_t bDone = kFALSE;
258 while ( bDone != kTRUE )
260 //first sort the digits:
261 Int_t iMaxEnergyDigit = -1;
262 Float_t dMaxEnergyDigit = -1;
263 AliEMCALDigit *pMaxEnergyDigit = 0;
265 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) )
266 { // scan over the list of digitsC
267 Float_t dEnergyCalibrated = Calibrate(digit->GetAmplitude(), digit->GetTime(),digit->GetId());
268 //AliDebug(5, Form("-> Digit ENERGY: %1.5f", dEnergyCalibrated));
270 //if(fGeom->CheckAbsCellId(digit->GetId()) && dEnergyCalibrated > fECAClusteringThreshold )
271 if(fGeom->CheckAbsCellId(digit->GetId()) && dEnergyCalibrated > 0.0) // no threshold!
273 if (dEnergyCalibrated > dMaxEnergyDigit)
275 dMaxEnergyDigit = dEnergyCalibrated;
276 iMaxEnergyDigit = digit->GetId();
277 pMaxEnergyDigit = digit;
282 if (iMaxEnergyDigit < 0 || digitsC.GetEntries() <= 0)
288 AliDebug (2, Form("Max digit found: %1.2f AbsId: %d", dMaxEnergyDigit, iMaxEnergyDigit));
289 AliDebug(5, Form("Max Digit ENERGY: %1.5f", dMaxEnergyDigit));
291 // keep the candidate digits in a list
292 TList clusterDigitList;
293 clusterDigitList.SetOwner(kFALSE);
294 clusterDigitList.AddLast(pMaxEnergyDigit);
296 Double_t clusterCandidateEnergy = dMaxEnergyDigit;
298 // now loop over the resto of the digits and cluster into NxN cluster
299 // we do not actually cluster yet: we keep them in the list clusterDigitList
301 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigitC())) )
302 { // scan over the list of digitsC
303 if (digit == pMaxEnergyDigit) continue;
304 Float_t dEnergyCalibrated = Calibrate(digit->GetAmplitude(), digit->GetTime(),digit->GetId());
305 AliDebug(5, Form("-> Digit ENERGY: %1.5f", dEnergyCalibrated));
306 //if(fGeom->CheckAbsCellId(digit->GetId()) && dEnergyCalibrated > fECAClusteringThreshold )
307 if(fGeom->CheckAbsCellId(digit->GetId()) && dEnergyCalibrated > 0.0 )
309 Float_t time = pMaxEnergyDigit->GetTime(); //Time or TimeR?
310 if(TMath::Abs(time - digit->GetTime()) > fTimeCut ) continue; //Time or TimeR?
311 Bool_t shared = kFALSE; //cluster shared by 2 SuperModules?
312 if (AreNeighbours(pMaxEnergyDigit, digit, shared) == 1) // call (digit,digitN) in THAT order !!!!!
314 clusterDigitList.AddLast(digit) ;
315 clusterCandidateEnergy += dEnergyCalibrated;
318 }// loop over the next digits
320 // start a cluster here only if a cluster energy is larger than clustering threshold
321 //if (clusterCandidateEnergy > 0.1)
322 AliDebug(5, Form("Clusterization threshold is %f MeV", fECAClusteringThreshold));
323 if (clusterCandidateEnergy > fECAClusteringThreshold)
325 if(fNumberOfECAClusters >= fRecPoints->GetSize()) fRecPoints->Expand(2*fNumberOfECAClusters+1) ;
327 AliEMCALRecPoint *recPoint = new AliEMCALRecPoint("") ;
328 fRecPoints->AddAt(recPoint, fNumberOfECAClusters) ;
329 recPoint = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(fNumberOfECAClusters)) ;
331 fNumberOfECAClusters++ ;
332 recPoint->SetClusterType(AliVCluster::kEMCALClusterv1);
334 AliDebug(9, Form("Number of cells per cluster (max is 9!): %d", clusterDigitList.GetEntries()));
335 for (Int_t idig = 0; idig < clusterDigitList.GetEntries(); idig++)
338 digit = (AliEMCALDigit*)clusterDigitList.At(idig);
339 Float_t dEnergyCalibrated = Calibrate(digit->GetAmplitude(), digit->GetTime(),digit->GetId());
340 AliDebug(5, Form(" Adding digit %d", digit->GetId()));
341 // note: this way the sharing info is lost!
342 recPoint->AddDigit(*digit, dEnergyCalibrated, kFALSE) ; //Time or TimeR?
343 digitsC.Remove(digit);
349 // we do not want to start clustering in the same spot!
350 // but in this case we may NOT reuse this seed for another cluster!
351 // need a better bookeeping?
352 digitsC.Remove(pMaxEnergyDigit);
355 AliDebug (2, Form("Number of digits left: %d", digitsC.GetEntries()));
358 //delete digitsC ; //nope we use an object
360 AliDebug(1,Form("total no of clusters %d from %d digits",fNumberOfECAClusters,fDigitsArr->GetEntriesFast()));
363 //___________________________________________________________________
364 void AliEMCALClusterizerNxN::SetInputCalibrated(Bool_t val)
367 // input is calibrated - the case when we run already on ESD
369 AliEMCALClusterizerNxN::fgkIsInputCalibrated = val;