Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcClusterCleaner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcClusterCleaner.cc
1 #include "TpcClusterCleaner.h"
2 
4 
5 #include <trackbase/TrkrCluster.h> // for TrkrCluster
6 #include <trackbase/TrkrDefs.h> // for cluskey, getLayer, TrkrId
8 #include <trackbase/TrkrHitSet.h>
10 #include <trackbase/TpcDefs.h>
11 
13 
14 #include <phool/getClass.h>
15 #include <phool/phool.h>
16 
17 #include <TMatrixFfwd.h> // for TMatrixF
18 #include <TMatrixT.h> // for TMatrixT, ope...
19 #include <TMatrixTUtils.h> // for TMatrixTRow
20 
21 #include <cmath> // for sqrt, fabs, atan2, cos
22 #include <iostream> // for operator<<, basic_ostream
23 #include <map> // for map
24 #include <set> // for _Rb_tree_const_iterator
25 #include <utility> // for pair, make_pair
26 
27 //____________________________________________________________________________..
29  : SubsysReco(name)
30 {
31 
32 }
33 
34 //____________________________________________________________________________..
36 {
37 
38 }
39 
40 //____________________________________________________________________________..
42 {
43  int ret = GetNodes(topNode);
44  if (ret != Fun4AllReturnCodes::EVENT_OK) return ret;
45 
46  return ret;
47 }
48 
49 //____________________________________________________________________________..
51 {
52 
53  _cluster_map = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
54  if (!_cluster_map)
55  {
56  std::cout << PHWHERE << " ERROR: Can't find node TRKR_CLUSTER" << std::endl;
58  }
59 
60  std::set<TrkrDefs::cluskey> discard_set;
61 
62  unsigned int count_discards = 0;
63 
64  // loop over all TPC clusters
65  if(Verbosity() > 0) std::cout << std::endl << "original size of cluster map: " << _cluster_map->size() << std::endl;
67  {
69 
70  for ( auto clusiter = clusRange.first;
71  clusiter != clusRange.second; ++clusiter)
72  {
73  TrkrDefs::cluskey cluskey = clusiter->first;
74  TrkrCluster *cluster = clusiter->second;
75 
76  unsigned int trkrId = TrkrDefs::getTrkrId(cluskey);
77  unsigned int layer = TrkrDefs::getLayer(cluskey);
78 
79  if(trkrId != TrkrDefs::tpcId) continue; // we want only TPC clusters
80 
81  if (Verbosity() > 1)
82  {
83  std::cout << " layer " << layer << " cluster : " << cluskey
84  << " ADC " << cluster->getAdc() << " errors: r-phi " << cluster->getRPhiError() << " Z " << cluster->getZError()
85  << std::endl;
86  }
87 
88  bool discard_cluster = false;
89 
90  // We have a TPC cluster, look for reasons to discard it
91 
92  // errors too small
93  // associated with very large ADC values
94  if(cluster->getRPhiError() < _rphi_error_low_cut)
95  discard_cluster = true;
96 
97  // errors too large
98  // associated with very small ADC values
99  //if(cluster->getRPhiError() > _rphi_error_high_cut)
100  //discard_cluster = true;
101 
102  if(discard_cluster)
103  {
104  count_discards++;
105  // mark it for modification
106  discard_set.insert(cluskey);
107  if(Verbosity() > 0)
108  std::cout << " discard cluster " << cluskey << " with ephi " << cluster->getRPhiError() << " adc " << cluster->getAdc()
109  << std::endl;
110  }
111  }
112  }
113 
114  for(auto iter = discard_set.begin(); iter != discard_set.end(); ++iter)
115  {
116 
117  // remove bad clusters from the node tree map
118  _cluster_map->removeCluster(*iter);
119 
120  }
121 
122  if(Verbosity() > 0)
123  {
124  std::cout << "Clusters discarded this event: " << count_discards << std::endl;
125  std::cout << "Clusters remaining: " << _cluster_map->size() << std::endl;
126  }
127 
128  /*
129  // check the map on the node tree
130  std::cout << " Readback modified cluster map - size is: " << _cluster_map->size() << std::endl;
131  clusRange = _cluster_map->getClusters();
132 
133  for (auto clusiter = clusRange.first;
134  clusiter != clusRange.second; ++clusiter)
135  {
136  TrkrDefs::cluskey cluskey = clusiter->first;
137  TrkrCluster *cluster = clusiter->second;
138 
139  unsigned int trkrId = TrkrDefs::getTrkrId(cluskey);
140  unsigned int layer = TrkrDefs::getLayer(cluskey);
141 
142  if(trkrId != TrkrDefs::tpcId) continue; // we want only TPC clusters
143 
144  if (Verbosity() >= 1)
145  {
146  std::cout << " cluster : " << cluskey << " layer " << layer
147  << " position x,y,z " << cluster->getX() << " " << cluster->getY() << " " << cluster->getZ()
148  << " ADC " << cluster->getAdc()
149  << std::endl;
150  //std::cout << " errors: r-phi " << cluster->getRPhiError() << " Z " << cluster->getZError()
151  // << " phi size " << cluster->getPhiSize() << " Z size " << cluster->getZSize()
152  // << std::endl;
153  }
154  }
155  */
156 
158 }
159 
161 {
163 }
164 
166 {
167 
169 }
170 
171 void TpcClusterCleaner::rotate_error(double erphi, double ez, double clusphi, double error[][3])
172 {
173  TMatrixF ROT(3, 3);
174  TMatrixF ERR(3,3);
175  for(int i=0;i<3;++i)
176  for(int j=0;j<3;++j)
177  {
178  ROT[i][j] = 0;
179  ERR[i][j] = 0;
180  }
181 
182  ROT[0][0] = cos(clusphi);
183  ROT[0][1] = -sin(clusphi);
184  ROT[1][0] = sin(clusphi);
185  ROT[1][1] = cos(clusphi);
186  ROT[2][2] = 1.0;
187 
188  ERR[1][1] = erphi*erphi;
189  ERR[2][2] = ez*ez;
190 
191  TMatrixF ROT_T(3, 3);
192  ROT_T.Transpose(ROT);
193 
194  TMatrixF COVAR_ERR(3, 3);
195  COVAR_ERR = ROT * ERR * ROT_T;
196 
197  for(int i=0;i<3;++i)
198  for(int j=0;j<3;++j)
199  error[i][j] = COVAR_ERR[i][j];
200 
201 }