test
CMS 3D CMS Logo

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