Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawClusterDeadHotMask.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawClusterDeadHotMask.cc
2 
3 #include <calobase/RawCluster.h>
4 #include <calobase/RawClusterContainer.h>
5 #include <calobase/RawTower.h>
6 #include <calobase/RawTowerContainer.h>
7 #include <calobase/TowerInfo.h>
8 #include <calobase/TowerInfoContainer.h>
9 #include <calobase/TowerInfoDefs.h>
10 #include <calobase/RawTowerDeadMap.h>
11 #include <calobase/RawTowerGeomContainer.h>
12 #include <calobase/RawTowerGeom.h>
13 
14 #include <fun4all/Fun4AllBase.h>
16 #include <fun4all/SubsysReco.h>
17 
18 #include <phool/PHCompositeNode.h>
19 #include <phool/PHNode.h>
20 #include <phool/PHNodeIterator.h>
21 #include <phool/getClass.h>
22 
23 #include <cassert>
24 #include <cmath>
25 #include <fstream>
26 #include <iostream>
27 #include <map>
28 #include <sstream>
29 #include <stdexcept>
30 #include <string>
31 #include <utility> // for pair
32 #include <vector>
33 
35  : SubsysReco(name)
36  , m_detector("NONE")
37  , m_deadTowerMaskHalfWidth(1.6)
38  , m_rawClusters(nullptr)
39  , m_towerinfoClusters(nullptr)
40  , m_deadMap(nullptr)
41  , m_calibTowers(nullptr)
42  , m_calibTowerInfos(nullptr)
43  , m_geometry(nullptr)
44 {
45 }
46 
48 {
49  CreateNodeTree(topNode);
50 
52 }
53 
55 {
56  if (Verbosity() >= VERBOSITY_SOME)
57  {
58  std::cout << Name() << "::" << m_detector << "::process_event - Entry" << std::endl;
59  }
60  int nMasked = 0;
61 
62  const int eta_bins = m_geometry->get_etabins();
63  const int phi_bins = m_geometry->get_phibins();
64  assert(eta_bins > 0);
65  assert(phi_bins > 0);
66 
67  // loop over the clusters
69  if(m_UseTowerInfo)
70  {
71  begin_end = m_towerinfoClusters->getClusters();
72  }
73  else
74  {
75  begin_end = m_rawClusters->getClusters();
76  }
78 
79  for (iter = begin_end.first; iter != begin_end.second;)
80  {
81  // RawClusterDefs::keytype key = iter->first;
82  const RawCluster *cluster = iter->second;
83 
84  std::vector<float> toweretas;
85  std::vector<float> towerphis;
86  std::vector<float> towerenergies;
87 
88  // loop over the towers in the cluster
89  RawCluster::TowerConstRange towers = cluster->get_towers();
91 
92  for (toweriter = towers.first; toweriter != towers.second; ++toweriter)
93  {
94  if(m_UseTowerInfo)
95  {
96  int towereta = m_geometry->get_tower_geometry(toweriter->first)->get_bineta();
97  int towerphi = m_geometry->get_tower_geometry(toweriter->first)->get_binphi();
98  unsigned int key = TowerInfoDefs::encode_emcal(towereta, towerphi);
99  TowerInfo *towerinfo = m_calibTowerInfos->get_tower_at_key(key);
100 
101  assert(towerinfo);
102 
103  double towerenergy = towerinfo->get_energy();
104 
105  toweretas.push_back(towereta);
106  towerphis.push_back(towerphi);
107  towerenergies.push_back(towerenergy);
108  }
109  else
110  {
111  RawTower *tower = m_calibTowers->getTower(toweriter->first);
112 
113  assert(tower);
114 
115  int towereta = tower->get_bineta();
116  int towerphi = tower->get_binphi();
117  double towerenergy = tower->get_energy();
118 
119  // put the etabin, phibin, and energy into the corresponding vectors
120  toweretas.push_back(towereta);
121  towerphis.push_back(towerphi);
122  towerenergies.push_back(towerenergy);
123  }
124  }
125 
126  int ntowers = toweretas.size();
127  assert(ntowers >= 1);
128 
129  // loop over the towers to determine the energy
130  // weighted eta and phi position of the cluster
131 
132  float etamult = 0;
133  float etasum = 0;
134  float phimult = 0;
135  float phisum = 0;
136 
137  for (int j = 0; j < ntowers; j++)
138  {
139  float energymult = towerenergies.at(j) * toweretas.at(j);
140  etamult += energymult;
141  etasum += towerenergies.at(j);
142 
143  int phibin = towerphis.at(j);
144 
145  if (phibin - towerphis.at(0) < -phi_bins / 2.0)
146  {
147  phibin += phi_bins;
148  }
149  else if (phibin - towerphis.at(0) > +phi_bins / 2.0)
150  {
151  phibin -= phi_bins;
152  }
153  assert(std::abs(phibin - towerphis.at(0)) <= phi_bins / 2.0);
154 
155  energymult = towerenergies.at(j) * phibin;
156  phimult += energymult;
157  phisum += towerenergies.at(j);
158  }
159 
160  float avgphi = phimult / phisum;
161  float avgeta = etamult / etasum;
162 
163  if (Verbosity() > VERBOSITY_MORE)
164  {
165  std::cout << Name() << "::" << m_detector << "::process_event - process cluster at average location " << avgeta << "," << avgphi << " : ";
166  cluster->identify();
167  }
168 
169  // rejection if close to a dead tower
170  bool rejecCluster = false;
171 
172  for (int search_eta = ceil(avgeta - m_deadTowerMaskHalfWidth); search_eta <= floor(avgeta + m_deadTowerMaskHalfWidth); ++search_eta)
173  {
174  for (int search_phi = ceil(avgphi - m_deadTowerMaskHalfWidth); search_phi <= floor(avgphi + m_deadTowerMaskHalfWidth); ++search_phi)
175  {
176  int ieta = search_eta;
177  int iphi = search_phi;
178 
179  if (ieta >= eta_bins)
180  {
181  continue;
182  }
183  if (ieta < 0)
184  {
185  continue;
186  }
187 
188  if (iphi >= phi_bins)
189  {
190  iphi -= phi_bins;
191  }
192  if (iphi < 0)
193  {
194  iphi += phi_bins;
195  }
196 
197  const bool isDead = m_deadMap->isDeadTower(ieta, iphi);
198 
199  // dead tower found in cluster
200  if (Verbosity() > VERBOSITY_MORE)
201  {
202  std::cout << "\t"
203  << "tower " << ieta
204  << "," << iphi
205  << (isDead ? ": is dead." : "OK")
206  << std::endl;
207  }
208 
209  if (isDead)
210  {
211  rejecCluster = true;
212  break;
213  }
214  }
215 
216  if (rejecCluster)
217  {
218  break;
219  }
220  }
221 
222  // container operation
223  if (rejecCluster)
224  {
225  if (Verbosity() > VERBOSITY_MORE)
226  {
227  std::cout << Name() << "::" << m_detector << "::process_event - " << "reject cluster " << cluster->get_id() << std::endl;
228  cluster->identify();
229  }
230 
231  ++nMasked;
232  if(m_UseTowerInfo)
233  {
234  m_towerinfoClusters->getClustersMap().erase(iter++);
235  }
236  else
237  {
238  m_rawClusters->getClustersMap().erase(iter++);
239  }
240  }
241  else
242  {
243  if (Verbosity() > VERBOSITY_MORE)
244  {
245  std::cout << Name() << "::" << m_detector << "::process_event - " << "keep cluster " << cluster->get_id() << std::endl;
246  }
247  ++iter;
248  }
249 
250  } // for (iter = begin_end.first; iter != begin_end.second;)
251 
252  if (Verbosity() >= VERBOSITY_SOME)
253  {
254  unsigned int clus_size;
255  if(m_UseTowerInfo)
256  {
257  clus_size = m_towerinfoClusters->size();
258  }
259  else
260  {
261  clus_size = m_rawClusters->size();
262  }
263  std::cout << Name() << "::" << m_detector << "::process_event - masked "
264  << nMasked << " clusters. Final cluster containers has "
265  << clus_size << " clusters"
266  << std::endl;
267  }
269 }
270 
272 {
273  PHNodeIterator iter(topNode);
274 
275  // Get the DST Node
276  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
277 
278  // Check that it is there
279  if (!dstNode)
280  {
281  std::cout << "DST Node missing, quitting" << std::endl;
282  throw std::runtime_error("failed to find DST node in RawClusterDeadHotMask::CreateNodeTree");
283  }
284 
285  m_rawClusters = findNode::getClass<RawClusterContainer>(topNode, "CLUSTER_" + m_detector);
286  if (!m_rawClusters && m_UseTowerInfo == false)
287  {
288  std::cout << Name() << "::" << m_detector << "::"
289  << "CreateNodeTree "
290  "No "
291  << m_detector << " Cluster Container found while in RawClusterDeadHotMask, can't proceed!!!" << std::endl;
292  topNode->print();
293  throw std::runtime_error("failed to find CLUSTER node in RawClusterDeadHotMask::CreateNodeTree");
294  }
295 
296  m_towerinfoClusters = findNode::getClass<RawClusterContainer>(topNode, "CLUSTERINFO_" + m_detector);
297  if (!m_towerinfoClusters && m_UseTowerInfo == true)
298  {
299  std::cout << Name() << "::" << m_detector << "::"
300  << "CreateNodeTree "
301  "No "
302  << m_detector << " Cluster Container found while in RawClusterDeadHotMask, can't proceed!!!" << std::endl;
303  topNode->print();
304  throw std::runtime_error("failed to find CLUSTERINFO node in RawClusterDeadHotMask::CreateNodeTree");
305  }
306 
307  m_calibTowers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_" + m_detector);
308  if (!m_calibTowers && m_UseTowerInfo == false)
309  {
310  std::cout << Name() << "::" << m_detector << "::"
311  << "CreateNodeTree "
312  << "No calibrated " << m_detector << " tower info found while in RawClusterDeadHotMask, can't proceed!!!" << std::endl;
313  throw std::runtime_error("failed to find TOWER_CALIB node in RawClusterDeadHotMask::CreateNodeTree");
314  }
315 
316  m_calibTowerInfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_" + m_detector);
317  if (!m_calibTowerInfos && m_UseTowerInfo == true)
318  {
319  std::cout << Name() << "::" << m_detector << "::"
320  << "CreateNodeTree "
321  << "No calibrated " << m_detector << " tower info found while in RawClusterDeadHotMask, can't proceed!!!" << std::endl;
322  throw std::runtime_error("failed to find TOWERINFO_CALIB node in RawClusterDeadHotMask::CreateNodeTree");
323  }
324 
325  std::string towergeomnodename = "TOWERGEOM_" + m_detector;
326  m_geometry = findNode::getClass<RawTowerGeomContainer>(topNode, towergeomnodename);
327  if (!m_geometry)
328  {
329  std::cout << Name() << "::" << m_detector << "::"
330  << "CreateNodeTree"
331  << ": Could not find node " << towergeomnodename << std::endl;
332  throw std::runtime_error("failed to find TOWERGEOM node in RawClusterDeadHotMask::CreateNodeTree");
333  }
334 
335  const std::string deadMapName = "DEADMAP_" + m_detector;
336  m_deadMap = findNode::getClass<RawTowerDeadMap>(topNode, deadMapName);
337  if (m_deadMap)
338  {
339  std::cout << Name() << "::" << m_detector << "::"
340  << "CreateNodeTree"
341  << " use dead map: ";
342  m_deadMap->identify();
343  }
344 }
345 
347 {
349 }