FairRoot/PandaRoot
PndEmc2DLocMaxFinder.cxx
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // Description:
3 // Class Emc2DLocMaxMaxFinder.
4 // Searches for local maxima in a cluster based on the ratio
5 // between the energy of the maxima crystal and that of
6 // its neighbours
7 //
8 // Environment:
9 // Software developed for the BaBar Detector at the SLAC B-Factory.
10 // Adapted for the PANDA experiment at GSI
11 //
12 // Author List:
13 // Phil Strother
14 // Helmut Schmuecker
15 //
16 // Copyright Information:
17 // Copyright (C) 1997 Imperial College
18 // Modified:
19 // M. Babai
20 //------------------------------------------------------------------------
21 
22 #include "PndEmc2DLocMaxFinder.h"
23 
25 #include "PndEmcTwoCoordIndex.h"
26 #include "PndEmcDigi.h"
27 #include "PndEmcCluster.h"
28 #include "PndEmcRecoPar.h"
29 #include "PndEmcGeoPar.h"
30 #include "PndEmcDigiPar.h"
31 #include "PndEmcStructure.h"
32 #include "PndEmcMapper.h"
33 
34 #include "FairRootManager.h"
35 #include "FairRunAna.h"
36 #include "FairRuntimeDb.h"
37 
38 #include "TClonesArray.h"
39 
40 
41 #include <algorithm>
42 #include <iostream>
43 
44 using std::cout;
45 using std::endl;
46 
47 //----------------
48 // Constructors --
49 //----------------
50 
51 PndEmc2DLocMaxFinder::PndEmc2DLocMaxFinder(Int_t verbose): PndPersistencyTask("PndEmc2DLocMaxFinder", verbose),fClusterArray(0), fDigiArray(0), fGeoPar(new PndEmcGeoPar()), fDigiPar(new PndEmcDigiPar()), fRecoPar(new PndEmcRecoPar()), fMaxECut(0), fNeighbourECut(0), fCutSlope(0), fCutOffset(0), fERatioCorr(0), fTheNeighbourLevel(0)
52 {
53  SetPersistency(kFALSE);
54 }
55 
56 //--------------
57 // Destructor --
58 //--------------
59 
61 {
62 // delete fGeoPar;
63 // delete fDigiPar;
64 // delete fRecoPar;
65 }
66 
76 {
77  // Get RootManager
78  FairRootManager* ioman = FairRootManager::Instance();
79  if ( ! ioman ){
80  cout << "-E- PndEmcMakeBump::Init: "
81  << "RootManager not instantiated!" << endl;
82  return kFATAL;
83  }
84 
85  // Geometry loading
88 
89  // Get input array
90  if(FairRunAna::Instance()->IsTimeStamp()) {
91  fDigiArray = (TClonesArray*) ioman->GetObject("EmcDigiClusterBase");
92  } else {
93  fDigiArray = (TClonesArray*) ioman->GetObject("EmcDigi");
94  }
95  if ( ! fDigiArray ) {
96  cout << "-W- PndEmc2DLocMaxFinder::Init: "
97  << "No PndEmcDigi array!" << endl;
98  return kERROR;
99  }
100 
101  fClusterArray = (TClonesArray*) ioman->GetObject("EmcCluster");
102  if ( ! fClusterArray ) {
103  cout << "-W- PndEmc2DLocMaxFinder::Init: "
104  << "No PndEmcCluster array!" << endl;
105  return kERROR;
106  }
107 
113  // ^
114  // | .... /
115  // 1.0| .... /|
116  // | / | fCutSlope
117  // | splitoffs / |
118  // MaxE of neighbours - fERatioCorr | and /___|
119  // ERatio = ------------------------------- | hadrons /..
120  // MaxE-fERatioCorr | / ..
121  // | .... / ..
122  // | .... / ... <-- merged pions
123  // | / .... and photons
124  // | ... / ....
125  // 0.0| / ....
126  // |------------------->
127  // 0 / 6 7 8
128  // <-------> number of neighbours
129  // fCutOffset with energy > fNeighbourECut
130 
132  // This is the range of the search to figure out whether a particular
133  // digi is a local max or not. Which neighbours are
134  // looked at is decided by this parameter:
135  // 0 = nearest neighbours (this is all logical neighbours including corners)
136  // 1 = nearest and next nearest neighbours
137  // etc.
138 
139  cout << "-I- PndEmc2DLocMaxFinder: Intialization successfull" << endl;
140  return kSUCCESS;
141 }
142 
152 {
153  int nClusters = fClusterArray->GetEntriesFast();
154  PndEmcCoordIndexSet tmp_CoordSet_set;
155 
157 
158  //loop over Clusters
159  for (Int_t iCluster = 0; iCluster < nClusters; iCluster++){
160  PndEmcCluster* theCluster = (PndEmcCluster*) fClusterArray->At(iCluster);
161 
162  // map <detId,digiIndex>
163  std::map<Int_t, Int_t> theClustersDigis = theCluster->MemberDigiMap();
164  std::map<Int_t, Int_t>::iterator theDigiIterator = theClustersDigis.begin();
165 
166  PndEmcCoordIndexSet allTheNeighbours;
167  PndEmcCoordIndexSet theNewNeighbours;
168 
169  if (theClustersDigis.size()==1){
170  while( theDigiIterator != theClustersDigis.end() ){
171  theCluster->addLocalMax(fDigiArray, theDigiIterator->second);
172  ++theDigiIterator;
173  }
174  }
175  else{
176  while( theDigiIterator != theClustersDigis.end() ){
177  Int_t detId = theDigiIterator->first;
178  PndEmcTwoCoordIndex *theTCI = fEmcMap->GetTCI(detId);
179 
180  allTheNeighbours.clear();
181  theNewNeighbours.clear();
182 
183  // Start the newneighbours off, then get all the neighbours from
184  // this. This is kind of curious, since the seed digi shouldn't
185  // end up in the neighbour list, but it should work
186  theNewNeighbours.insert(theTCI);
187 
188  getNeighbourDigis(allTheNeighbours, theNewNeighbours,
189  fTheNeighbourLevel, theClustersDigis);
190  PndEmcDigi *theDigi = (PndEmcDigi *) fDigiArray->At(theDigiIterator->second);
191  if (isALocalMax(theDigi, theCluster, allTheNeighbours)){
192  theCluster->addLocalMax( fDigiArray, theDigiIterator->second);
193  }
194  ++theDigiIterator;
195  }
196  // If no local maxima was added simply add the absolute maxima
197  if ((theCluster->LocalMaxMap()).size()==0)
198  {
199  theCluster->addLocalMax(theCluster->Maxima(fDigiArray));
200  }
201  }
202  }
203 
204 }
205 
220 bool PndEmc2DLocMaxFinder::isALocalMax( const PndEmcDigi *const theDigi, const PndEmcCluster * const theCluster,
221  const PndEmcCoordIndexSet &amongstTheseNeighbours ) const
222 {
223  // Loop over all our neighbours and check to see if the one in hand is a local max
224 
225  Bool_t result=true;
226  Double_t theDigiEnergy = theDigi->GetEnergy();
227 
228  if (theDigiEnergy<fMaxECut) {
229  //std::cout << "Digi is not a local max because its energy "
230  // << theDigiEnergy << " is too low. " << std::endl;
231  result=false;
232  }
233  else {
234  PndEmcCoordIndexSet::const_iterator theNeighbourIterator = amongstTheseNeighbours.begin();
235 
236  const std::map<Int_t, Int_t> theClustersDigis = theCluster->MemberDigiMap();
237 
238  Double_t numberOFneighbours(0.0);
239  Double_t neighbourMaxE(0.0);
240 
241  while( (theNeighbourIterator != amongstTheseNeighbours.end()) && result ){
242 
243  std::map<Int_t, Int_t>::const_iterator position = theClustersDigis.find((*theNeighbourIterator)->Index());
244 
245  if (position != theClustersDigis.end()) {
246  PndEmcDigi *digi = (PndEmcDigi *) fDigiArray->At(position->second);
247  double digiE(digi->GetEnergy());
248  if(digiE>theDigiEnergy)
249  result=false;
250  if(digiE>=neighbourMaxE)
251  neighbourMaxE=digiE;
252  if(digiE>fNeighbourECut)
253  numberOFneighbours+=1.0;
254  }
255  ++theNeighbourIterator;
256  }
257 
258  if(numberOFneighbours==0.0)
259  return false;
260  else {
262  std::cout<< "Hi this is warning from your PndEmc2DLocMaxFinder,\n"
263  <<" please choose a smaller value for fERatioCorr (EmcMakeBump)"
264  << std::endl;
265  return false;
266  }
267  else {
268  if(fCutSlope*(numberOFneighbours-fCutOffset) <
269  (neighbourMaxE-fERatioCorr)/(theDigiEnergy-fERatioCorr))
270  result=false;
271  }
272  }
273  }
274 
275  if ((result)&&(fVerbose>0)) {
276  std::cout << " Digi at (" << theDigi->GetThetaInt() << ", "
277  << theDigi->GetPhiInt() << ") was a local max. Energy = "<<theDigi->GetEnergy()<< std::endl;
278  }
279  return result;
280 }
281 
292  PndEmcCoordIndexSet &currentDigiNeighbours,
293  int , // neighbourLevel //[R.K.03/2017] unused variable(s)
294  std::map<Int_t,Int_t> theClusterDigis ) const
295 {
297 
298  PndEmcCoordIndexSet currentDigisCopy(currentDigiNeighbours);
299  currentDigiNeighbours.clear();
300  PndEmcCoordIndexSet::iterator theCurrentDigiIterator = currentDigisCopy.begin();
301  PndEmcCoordIndexSet theNextDigiNeighbours;
302 
303  while ( theCurrentDigiIterator != currentDigisCopy.end() ) {
304  PndEmcTwoCoordIndex *theCurrentTCI = *theCurrentDigiIterator;
305 
306  std::map<Int_t, Int_t>::const_iterator theDigiIterator = theClusterDigis.begin();
307  while( theDigiIterator != theClusterDigis.end() ) {
308  Int_t detId = theDigiIterator->first;
309  PndEmcTwoCoordIndex *theTCI = fEmcMap->GetTCI(detId);
310  bool isneighbour= theCurrentTCI->IsNeighbour(theTCI);
311  if(isneighbour)
312  allDigiNeighbours.insert(theTCI);
313  ++theDigiIterator;
314  }
315  ++theCurrentDigiIterator;}
316 }
317 
319 
320  // Get run and runtime database
321  FairRun* run = FairRun::Instance();
322  if ( ! run ) Fatal("SetParContainers", "No analysis run");
323 
324  FairRuntimeDb* db = run->GetRuntimeDb();
325  if ( ! db ) Fatal("SetParContainers", "No runtime database");
326  // Get Emc digitisation parameter container
327  fGeoPar = (PndEmcGeoPar*) db->getContainer("PndEmcGeoPar");
328  // Get Emc digitisation parameter container
329  fDigiPar = (PndEmcDigiPar*) db->getContainer("PndEmcDigiPar");
330  // Get Emc reconstruction parameter container
331  fRecoPar = (PndEmcRecoPar*) db->getContainer("PndEmcRecoPar");
332 }
333 
PndEmcGeoPar * fGeoPar
Geometry parameter container.
Double_t GetCutOffset()
Definition: PndEmcRecoPar.h:29
int fVerbose
Definition: poormantracks.C:24
Double_t GetERatioCorr()
Definition: PndEmcRecoPar.h:30
TClonesArray * digi
virtual InitStatus Init()
Init Task.
Int_t run
Definition: autocutx.C:47
Double_t GetNeighbourECut()
Definition: PndEmcRecoPar.h:27
virtual Double_t GetEnergy() const
Definition: PndEmcDigi.cxx:296
represents the reconstructed hit of one emc crystal
Definition: PndEmcDigi.h:40
Int_t GetThetaInt() const
Definition: PndEmcDigi.h:99
#define verbose
void getNeighbourDigis(PndEmcCoordIndexSet &, PndEmcCoordIndexSet &, int, std::map< Int_t, Int_t >) const
Get the TCIs of neighbor digis.
void SetPersistency(Bool_t val=kTRUE)
stores crystal index coordinates (x,y) or (theta,phi)
PndEmcTwoCoordIndex * GetTCI(Int_t DetectorId)
Emc geometry mapper.
Definition: PndEmcMapper.h:22
PndEmcDigiPar * fDigiPar
Digitisation parameter container.
void InitEmcMapper()
virtual void Exec(Option_t *opt)
Runs the task.
Int_t GetTheNeighbourLevel()
Definition: PndEmcRecoPar.h:31
std::set< PndEmcTwoCoordIndex * > PndEmcCoordIndexSet
virtual const PndEmcDigi * Maxima(const TClonesArray *digiArray) const
Double_t
const std::map< Int_t, Int_t > & LocalMaxMap() const
Definition: PndEmcCluster.h:42
parameter set of Emc digitisation
Definition: PndEmcDigiPar.h:12
bool IsNeighbour(PndEmcTwoCoordIndex *_tci)
PndEmc2DLocMaxFinder(Int_t verbose=0)
a cluster (group of neighboring crystals) of hit emc crystals
Definition: PndEmcCluster.h:29
const std::map< Int_t, Int_t > & MemberDigiMap() const
Definition: PndEmcCluster.h:43
Double_t GetMaxECut()
Definition: PndEmcRecoPar.h:26
Double_t GetCutSlope()
Definition: PndEmcRecoPar.h:28
PndEmcRecoPar * fRecoPar
Reconstruction parameter container.
TClonesArray * fClusterArray
ClassImp(PndAnaContFact)
virtual void addLocalMax(const TClonesArray *digiArray, Int_t iDigi)
static PndEmcStructure * Instance()
Searches for local maxima in a cluster.
static PndEmcMapper * Instance()
virtual bool isALocalMax(const PndEmcDigi *const, const PndEmcCluster *const, const PndEmcCoordIndexSet &amongstTheseNeighbours) const
Check if digi is a local maximum in its cluster.
Parameter set for Emc Reco.
Definition: PndEmcRecoPar.h:12
Int_t GetPhiInt() const
Definition: PndEmcDigi.h:100