CMS 3D CMS Logo

CSCSegAlgoPreClustering.cc
Go to the documentation of this file.
1 
14 
18 
21 
22 #include <algorithm>
23 #include <cmath>
24 #include <iostream>
25 #include <string>
26 
27 /* Constructor
28  *
29  */
31  dXclusBoxMax = ps.getParameter<double>("dXclusBoxMax");
32  dYclusBoxMax = ps.getParameter<double>("dYclusBoxMax");
33  debug = ps.getUntrackedParameter<bool>("CSCSegmentDebug");
34 }
35 
36 /* Destructor:
37  *
38  */
40 
41 /* clusterHits
42  *
43  */
44 std::vector<std::vector<const CSCRecHit2D*> > CSCSegAlgoPreClustering::clusterHits(const CSCChamber* aChamber,
46  theChamber = aChamber;
47 
48  std::vector<ChamberHitContainer> rechits_clusters; // this is a collection of groups of rechits
49 
50  //float dXclus = 0.0;
51  //float dYclus = 0.0;
52  float dXclus_box = 0.0;
53  float dYclus_box = 0.0;
54 
55  std::vector<const CSCRecHit2D*> temp;
56 
57  std::vector<ChamberHitContainer> seeds;
58 
59  std::vector<float> running_meanX;
60  std::vector<float> running_meanY;
61 
62  std::vector<float> seed_minX;
63  std::vector<float> seed_maxX;
64  std::vector<float> seed_minY;
65  std::vector<float> seed_maxY;
66 
67  // split rechits into subvectors and return vector of vectors:
68  // Loop over rechits
69  // Create one seed per hit
70  for (unsigned int i = 0; i < rechits.size(); ++i) {
71  temp.clear();
72 
73  temp.push_back(rechits[i]);
74 
75  seeds.push_back(temp);
76 
77  // First added hit in seed defines the mean to which the next hit is compared
78  // for this seed.
79 
80  running_meanX.push_back(rechits[i]->localPosition().x());
81  running_meanY.push_back(rechits[i]->localPosition().y());
82 
83  // set min/max X and Y for box containing the hits in the precluster:
84  seed_minX.push_back(rechits[i]->localPosition().x());
85  seed_maxX.push_back(rechits[i]->localPosition().x());
86  seed_minY.push_back(rechits[i]->localPosition().y());
87  seed_maxY.push_back(rechits[i]->localPosition().y());
88  }
89 
90  // merge clusters that are too close
91  // measure distance between final "running mean"
92  for (size_t NNN = 0; NNN < seeds.size(); ++NNN) {
93  for (size_t MMM = NNN + 1; MMM < seeds.size(); ++MMM) {
94  if (running_meanX[MMM] == 999999. || running_meanX[NNN] == 999999.) {
95  std::cout << "We should never see this line now!!!" << std::endl;
96  continue; //skip seeds that have been used
97  }
98 
99  // calculate cut criteria for simple running mean distance cut:
100  //dXclus = fabs(running_meanX[NNN] - running_meanX[MMM]);
101  //dYclus = fabs(running_meanY[NNN] - running_meanY[MMM]);
102 
103  // calculate minmal distance between precluster boxes containing the hits:
104  if (running_meanX[NNN] > running_meanX[MMM])
105  dXclus_box = seed_minX[NNN] - seed_maxX[MMM];
106  else
107  dXclus_box = seed_minX[MMM] - seed_maxX[NNN];
108  if (running_meanY[NNN] > running_meanY[MMM])
109  dYclus_box = seed_minY[NNN] - seed_maxY[MMM];
110  else
111  dYclus_box = seed_minY[MMM] - seed_maxY[NNN];
112 
113  if (dXclus_box < dXclusBoxMax && dYclus_box < dYclusBoxMax) {
114  // merge clusters!
115  // merge by adding seed NNN to seed MMM and erasing seed NNN
116 
117  // calculate running mean for the merged seed:
118  running_meanX[MMM] = (running_meanX[NNN] * seeds[NNN].size() + running_meanX[MMM] * seeds[MMM].size()) /
119  (seeds[NNN].size() + seeds[MMM].size());
120  running_meanY[MMM] = (running_meanY[NNN] * seeds[NNN].size() + running_meanY[MMM] * seeds[MMM].size()) /
121  (seeds[NNN].size() + seeds[MMM].size());
122 
123  // update min/max X and Y for box containing the hits in the merged cluster:
124  if (seed_minX[NNN] <= seed_minX[MMM])
125  seed_minX[MMM] = seed_minX[NNN];
126  if (seed_maxX[NNN] > seed_maxX[MMM])
127  seed_maxX[MMM] = seed_maxX[NNN];
128  if (seed_minY[NNN] <= seed_minY[MMM])
129  seed_minY[MMM] = seed_minY[NNN];
130  if (seed_maxY[NNN] > seed_maxY[MMM])
131  seed_maxY[MMM] = seed_maxY[NNN];
132 
133  // add seed NNN to MMM (lower to larger number)
134  seeds[MMM].insert(seeds[MMM].end(), seeds[NNN].begin(), seeds[NNN].end());
135 
136  // mark seed NNN as used (at the moment just set running mean to 999999.)
137  running_meanX[NNN] = 999999.;
138  running_meanY[NNN] = 999999.;
139  // we have merged a seed (NNN) to the highter seed (MMM) - need to contimue to
140  // next seed (NNN+1)
141  break;
142  }
143  }
144  }
145 
146  // hand over the final seeds to the output
147  // would be more elegant if we could do the above step with
148  // erasing the merged ones, rather than the
149  for (size_t NNN = 0; NNN < seeds.size(); ++NNN) {
150  if (running_meanX[NNN] == 999999.)
151  continue; //skip seeds that have been marked as used up in merging
152  rechits_clusters.push_back(seeds[NNN]);
153  mean_x = running_meanX[NNN];
154  mean_y = running_meanY[NNN];
155  err_x =
156  (seed_maxX[NNN] - seed_minX[NNN]) / 3.464101615; // use box size divided by sqrt(12) as position error estimate
157  err_y =
158  (seed_maxY[NNN] - seed_minY[NNN]) / 3.464101615; // use box size divided by sqrt(12) as position error estimate
159  }
160 
161  return rechits_clusters;
162 }
CSCSegAlgoPreClustering::mean_y
float mean_y
Definition: CSCSegAlgoPreClustering.h:39
CSCSegAlgoPreClustering::err_x
float err_x
Definition: CSCSegAlgoPreClustering.h:39
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
CSCSegAlgoPreClustering::debug
bool debug
Definition: CSCSegAlgoPreClustering.h:35
CSCSegAlgoPreClustering::dXclusBoxMax
double dXclusBoxMax
Definition: CSCSegAlgoPreClustering.h:36
CSCSegAlgoPreClustering.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
CSCSegAlgoPreClustering::ChamberHitContainer
std::vector< const CSCRecHit2D * > ChamberHitContainer
Definition: CSCSegAlgoPreClustering.h:22
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DDAxes::x
CSCSegAlgoPreClustering::~CSCSegAlgoPreClustering
~CSCSegAlgoPreClustering()
destructor
Definition: CSCSegAlgoPreClustering.cc:39
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
end
#define end
Definition: vmac.h:39
CSCSegAlgoPreClustering::CSCSegAlgoPreClustering
CSCSegAlgoPreClustering(const edm::ParameterSet &ps)
constructor
Definition: CSCSegAlgoPreClustering.cc:30
CSCChamber
Definition: CSCChamber.h:22
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:232
edm::ParameterSet
Definition: ParameterSet.h:36
TrackInfoProducer_cfi.rechits
rechits
Definition: TrackInfoProducer_cfi.py:9
CSCSegAlgoPreClustering::dYclusBoxMax
double dYclusBoxMax
Definition: CSCSegAlgoPreClustering.h:37
CSCSegAlgoPreClustering::err_y
float err_y
Definition: CSCSegAlgoPreClustering.h:39
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
CSCLayer.h
CSCSegAlgoPreClustering::clusterHits
std::vector< std::vector< const CSCRecHit2D * > > clusterHits(const CSCChamber *aChamber, const ChamberHitContainer &rechits)
clusterize
Definition: CSCSegAlgoPreClustering.cc:44
CSCSegAlgoPreClustering::mean_x
float mean_x
Definition: CSCSegAlgoPreClustering.h:39
CSCSegAlgoPreClustering::theChamber
const CSCChamber * theChamber
Definition: CSCSegAlgoPreClustering.h:40
ParameterSet.h
CSCChamber.h
GlobalPoint.h
begin
#define begin
Definition: vmac.h:32
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443