CMS 3D CMS Logo

CSCHitFromWireOnly.cc
Go to the documentation of this file.
1 /* This is CSCHitFromWireOnly
2  *
3  * Finds wiregroup with hits, and fill in CSCWireHitCollection
4  * which includes only DetId and wiregroup #
5  *
6  */
7 
10 
13 
15 
17 
18 #include <iostream>
19 
20 CSCHitFromWireOnly::CSCHitFromWireOnly(const edm::ParameterSet& ps) : recoConditions_(nullptr) {
21  deltaT = ps.getParameter<int>("CSCWireClusterDeltaT");
22  useReducedWireTime = ps.getParameter<bool>("CSCUseReducedWireTimeWindow");
23  wireTimeWindow_low = ps.getParameter<int>("CSCWireTimeWindowLow");
24  wireTimeWindow_high = ps.getParameter<int>("CSCWireTimeWindowHigh");
25 
26  //clusterSize = ps.getParameter<int>("CSCWireClusterMaxSize");
27 }
28 
30 
31 std::vector<CSCWireHit> CSCHitFromWireOnly::runWire(const CSCDetId& id,
32  const CSCLayer* layer,
33  const CSCWireDigiCollection::Range& rwired) {
34  std::vector<CSCWireHit> hitsInLayer;
35 
36  id_ = id;
37  layer_ = layer;
38  layergeom_ = layer->geometry();
39  bool any_digis = true;
40  int n_wgroup = 0;
41 
42  // Loop over wire digi collection
43  for (CSCWireDigiCollection::const_iterator it = rwired.first; it != rwired.second; ++it) {
44  const CSCWireDigi wdigi = *it;
45 
46  if (isDeadWG(id, wdigi.getWireGroup())) {
47  continue;
48  }
49  if (any_digis) {
50  any_digis = false;
51  makeWireCluster(wdigi);
52  n_wgroup = 1;
53  } else {
54  if (!addToCluster(wdigi)) {
55  // Make Wire Hit from cluster, delete old cluster and start new one
56  float whit_pos = findWireHitPosition();
57  bool deadWG_left = isDeadWG(id, wire_in_cluster.at(0) - 1);
58  bool deadWG_right = isDeadWG(id, wire_in_cluster.at(wire_in_cluster.size() - 1) + 1);
59  short int aDeadWG = 0;
60  if (!deadWG_left && !deadWG_right) {
61  aDeadWG = 0;
62  } else if (deadWG_left && deadWG_right) {
63  aDeadWG = 255;
64  } else {
65  if (deadWG_left) {
66  aDeadWG = wire_in_cluster.at(0) - 1;
67  } else {
68  aDeadWG = wire_in_cluster.at(wire_in_cluster.size() - 1) + 1;
69  }
70  }
71  // Set time bins for wire hit as the time bins of the central wire digi, lower of central two if an even number of digis.
72  std::vector<int> timeBinsOn = wire_cluster[n_wgroup / 2].getTimeBinsOn();
73  //CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, isDeadWGAround, timeBinsOn );
74  CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, aDeadWG, timeBinsOn);
75 
76  if (!useReducedWireTime) {
77  hitsInLayer.push_back(whit);
79  hitsInLayer.push_back(whit);
80  }
81 
82  makeWireCluster(wdigi);
83  n_wgroup = 1;
84  } else {
85  n_wgroup++;
86  }
87  }
88  // Don't forget to fill last wire hit !!!
89  if (rwired.second - it == 1) {
90  float whit_pos = findWireHitPosition();
91  bool deadWG_left = isDeadWG(id, wire_in_cluster.at(0) - 1);
92  bool deadWG_right = isDeadWG(id, wire_in_cluster.at(wire_in_cluster.size() - 1) + 1);
93  short int aDeadWG = 0;
94  if (!deadWG_left && !deadWG_right) {
95  aDeadWG = 0;
96  } else if (deadWG_left && deadWG_right) {
97  aDeadWG = 255;
98  } else {
99  if (deadWG_left) {
100  aDeadWG = wire_in_cluster.at(0) - 1;
101  } else {
102  aDeadWG = wire_in_cluster.at(wire_in_cluster.size() - 1) + 1;
103  }
104  }
105  std::vector<int> timeBinsOn = wire_cluster[n_wgroup / 2].getTimeBinsOn();
107  //CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, isDeadWGAround, timeBinsOn );
108  CSCWireHit whit(id, whit_pos, wire_in_clusterAndBX, theTime, aDeadWG, timeBinsOn);
109 
110  if (!useReducedWireTime) {
111  hitsInLayer.push_back(whit);
113  hitsInLayer.push_back(whit);
114  }
115 
116  n_wgroup++;
117  }
118  }
119 
121  /*
122  for(std::vector<CSCWireHit>::const_iterator itWHit=hitsInLayer.begin(); itWHit!=hitsInLayer.end(); ++itWHit){
123  (*itWHit).print();
124  }
125  */
126 
127  return hitsInLayer;
128 }
129 
131  wire_cluster.clear();
132  wire_in_cluster.clear();
133  wire_in_clusterAndBX.clear();
134  theLastChannel = digi.getWireGroup();
135  theTime = digi.getTimeBin();
136  wire_cluster.push_back(digi);
137 }
138 
140  int iwg = digi.getWireGroup();
141 
142  if (iwg == theLastChannel) {
143  return true; // Same wire group but different tbin -> ignore
144  } else {
145  if ((iwg == theLastChannel + 1) && (abs(digi.getTimeBin() - theTime) <= deltaT)) {
146  theLastChannel = iwg;
147  wire_cluster.push_back(digi);
148  return true;
149  }
150  }
151 
152  return false;
153 }
154 
155 /* findWireHitPosition
156  *
157  * This position is expressed in terms of wire #... is a float since it may be a fraction.
158  */
160  // Again use center of mass to determine position of wire hit
161  // To do so, need to know wire spacing and # of wires
162 
163  float y = 0.0;
164 
165  for (unsigned i = 0; i < wire_cluster.size(); ++i) {
166  CSCWireDigi wdigi = wire_cluster[i];
167  int wgroup = wdigi.getWireGroup();
168  wire_in_cluster.push_back(wgroup);
169  int wgroupAndBX = wdigi.getBXandWireGroup();
170  //std::cout << " wgroupAndBX: " << std::hex << wgroupAndBX << std::dec << std::endl;
171  wire_in_clusterAndBX.push_back(wgroupAndBX);
172  y += float(wgroup);
173  }
174 
175  float wiregpos = y / wire_cluster.size();
176 
177  return wiregpos;
178 }
179 
180 bool CSCHitFromWireOnly::isDeadWG(const CSCDetId& id, int WG) {
181  const std::bitset<112>& deadWG = recoConditions_->badWireWord(id);
182  bool isDead = false;
183  if (WG > -1 && WG < 112) {
184  isDead = deadWG.test(WG);
185  }
186  return isDead;
187 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::bitset< 112 > & badWireWord(const CSCDetId &id) const
Get bad wiregroup word.
int deltaT
To fill BX + wiregroup in CSCWireHit.
int getTimeBin() const
return first tbin ON number
Definition: CSCWireDigi.cc:35
std::vector< int > wire_in_cluster
void makeWireCluster(const CSCWireDigi &digi)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const CSCLayer * layer_
bool addToCluster(const CSCWireDigi &digi)
CSCHitFromWireOnly(const edm::ParameterSet &ps)
std::vector< CSCWireHit > runWire(const CSCDetId &id, const CSCLayer *layer, const CSCWireDigiCollection::Range &rwired)
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
std::vector< int > wire_in_clusterAndBX
int getBXandWireGroup() const
Definition: CSCWireDigi.h:27
const CSCRecoConditions * recoConditions_
Hold pointer to current conditions data.
const CSCLayerGeometry * layergeom_
bool isDeadWG(const CSCDetId &id, int WG)
std::vector< CSCWireDigi > wire_cluster
int getWireGroup() const
default
Definition: CSCWireDigi.h:22