CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCRecHitDBuilder.cc
Go to the documentation of this file.
1 // This is CSCRecHitDBuilder.cc
2 
10 
14 
16 
23 
26 
27 #include <iostream>
28 
29 
31 
32  // Receives ParameterSet percolated down from EDProducer
33 
34  useCalib = ps.getParameter<bool>("CSCUseCalibrations");
35  stripWireDeltaT = ps.getParameter<int>("CSCstripWireDeltaTime");
36 
39  make2DHits_ = new CSCMake2DRecHit( ps );
40 }
41 
42 
44  delete hitsFromStripOnly_;
45  delete hitsFromWireOnly_;
46  delete make2DHits_;
47 }
48 
49 
51  CSCRecHit2DCollection& oc ) {
52  LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] build entered";
53  // Clean hit collections sorted by layer
54  std::vector<CSCDetId> stripLayer;
55  std::vector<CSCDetId>::const_iterator sIt;
56  std::vector<CSCDetId> wireLayer;
57  std::vector<CSCDetId>::const_iterator wIt;
58 
59 
60  // Make collection of wire only hits !
61  CSCWireHitCollection clean_woc;
62 
63  for ( CSCWireDigiCollection::DigiRangeIterator it = wiredc->begin(); it != wiredc->end(); ++it ){
64  const CSCDetId& id = (*it).first;
65  const CSCLayer* layer = getLayer( id );
66  const CSCWireDigiCollection::Range rwired = wiredc->get( id );
67  // Skip if no wire digis in this layer
68  if ( rwired.second == rwired.first ) {
69  continue;
70  }
71 
72  std::vector<CSCWireHit> rhv = hitsFromWireOnly_->runWire( id, layer, rwired);
73 
74  if ( rhv.size() > 0 ) wireLayer.push_back( id );
75 
76  // Add the wire hits to master collection
77  clean_woc.put( id, rhv.begin(), rhv.end() );
78  }
79 
80  LogTrace("CSCRecHitBuilder") << "[CSCRecHitDBuilder] wire hits created";
81 
82  // Make collection of strip only hits
83 
84  CSCStripHitCollection clean_soc;
85  for ( CSCStripDigiCollection::DigiRangeIterator it = stripdc->begin(); it != stripdc->end(); ++it ){
86  const CSCDetId& id = (*it).first;
87  const CSCLayer* layer = getLayer( id );
88  const CSCStripDigiCollection::Range& rstripd = (*it).second;
89 
90  // Skip if no strip digis in this layer
91  if ( rstripd.second == rstripd.first ) continue;
92 
93  std::vector<CSCStripHit> rhv = hitsFromStripOnly_->runStrip( id, layer, rstripd);
94 
95  if ( rhv.size() > 0 ) stripLayer.push_back( id );
96 
97  // Add the strip hits to master collection
98  clean_soc.put( id, rhv.begin(), rhv.end() );
99  }
100 
101  LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] strip hits created";
102 
103 
104  // Now create 2-D hits by looking at superposition of strip and wire hit in a layer
105  //
106  // N.B. I've sorted the hits from layer 1-6 always, so can test if there are "holes",
107  // that is layers without hits for a given chamber.
108 
109  // Vector to store rechit within layer
110  std::vector<CSCRecHit2D> hitsInLayer;
111 
112  int layer_idx = 0;
113  int hits_in_layer = 0;
114  CSCDetId old_id;
115 
116  // Now loop over each layer containing strip hits
117  for ( sIt=stripLayer.begin(); sIt != stripLayer.end(); ++sIt ) {
118 
119  hitsInLayer.clear();
120  hits_in_layer = 0;
121 
122  std::vector<CSCStripHit> cscStripHit;
123 
125  CSCStripHitCollection::range range = clean_soc.get(acc.cscDetLayer(*sIt));
126 
127  // Create vector of strip hits for this layer
128  for ( CSCStripHitCollection::const_iterator clean_soc = range.first; clean_soc != range.second; ++clean_soc)
129  cscStripHit.push_back(*clean_soc);
130 
131  const CSCDetId& sDetId = (*sIt);
132  const CSCLayer* layer = getLayer( sDetId );
133 
134  // This is used to test for gaps in layers and needs to be initialized here
135  if ( layer_idx == 0 ) {
136  old_id = sDetId;
137  }
138 
139  CSCDetId compId = sDetId;
140  CSCWireDigiCollection::Range rwired = wiredc->get( sDetId );
141  // Skip if no wire digis in this layer
142  // But for ME11, real wire digis are labelled as belonging to ME1b, so that's where ME1a must look
143  // (We try ME1a - above - anyway, because simulated wire digis are labelled as ME1a.)
144  if ( rwired.second == rwired.first ) {
145  if ( sDetId.station()!=1 || sDetId.ring()!=4 ){
146  continue; // not ME1a, skip to next layer
147  }
148  // So if ME1a has no wire digis (always the case for data) make the
149  // wire digi ID point to ME1b. This is what is compared to the
150  // strip digi ID below (and not used anywhere else).
151  // Later, rechits use the strip digi ID for construction.
152 
153  // It is ME1a but no wire digis there, so try ME1b...
154  int endcap = sDetId.endcap();
155  int chamber = sDetId.chamber();
156  int layer = sDetId.layer();
157  CSCDetId idw( endcap, 1, 1, chamber, layer ); // Set idw to same layer in ME1b
158  compId = idw;
159  }
160 
161  // Now loop over wire hits
162  for ( wIt=wireLayer.begin(); wIt != wireLayer.end(); ++wIt ) {
163 
164  const CSCDetId& wDetId = (*wIt);
165 
166  // Because of ME1a, use the compId to make a comparison between strip and wire hit CSCDetId
167  if ((wDetId.endcap() == compId.endcap() ) &&
168  (wDetId.station() == compId.station()) &&
169  (wDetId.ring() == compId.ring() ) &&
170  (wDetId.chamber() == compId.chamber()) &&
171  (wDetId.layer() == compId.layer() )) {
172 
173  // Create vector of wire hits for this layer
174  std::vector<CSCWireHit> cscWireHit;
175 
177  CSCWireHitCollection::range range = clean_woc.get(acc2.cscDetLayer(*wIt));
178 
179  for ( CSCWireHitCollection::const_iterator clean_woc = range.first; clean_woc != range.second; ++clean_woc)
180  cscWireHit.push_back(*clean_woc);
181 
182  // Build 2D hit for all possible strip-wire pairs
183  // overlapping within this layer
184 
185  LogTrace("CSCRecHitBuilder")<< "[CSCRecHitDBuilder] found " << cscStripHit.size() << " strip and "
186  << cscWireHit.size() << " wire hits in layer " << sDetId;
187 
188  for (unsigned i = 0; i != cscStripHit.size(); ++i ) {
189  const CSCStripHit s_hit = cscStripHit[i];
190  for (unsigned j = 0; j != cscWireHit.size(); ++j ) {
191  const CSCWireHit w_hit = cscWireHit[j];
192  CSCRecHit2D rechit = make2DHits_->hitFromStripAndWire(sDetId, layer, w_hit, s_hit);
193 
194  bool isInFiducial = make2DHits_->isHitInFiducial( layer, rechit );
195  if ( isInFiducial ) {
196  hitsInLayer.push_back( rechit );
197  hits_in_layer++;
198  }
199  }
200  }
201  }
202  }
203 
204  LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] " << hits_in_layer << " rechits found in layer " << sDetId;
205 
206  // output vector of 2D rechits to collection
207  if (hits_in_layer > 0) {
208  oc.put( sDetId, hitsInLayer.begin(), hitsInLayer.end() );
209  hitsInLayer.clear();
210  }
211  hits_in_layer = 0;
212  layer_idx++;
213  old_id = sDetId;
214  }
215 
216  LogTrace("CSCRecHitDBuilder") << "[CSCRecHitDBuilder] " << oc.size() << " 2d rechits created in this event.";
217 
218 }
219 
220 
222  if ( !geom_ ) throw cms::Exception("MissingGeometry") << "[CSCRecHitDBuilder::getLayer] Missing geometry" << std::endl;
223  return geom_->layer(detId);
224 }
225 
226 
230  make2DHits_->setConditions( reco );
231 }
int chamber() const
Definition: CSCDetId.h:70
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
const CSCGeometry * geom_
std::vector< CSCStripHit > runStrip(const CSCDetId &id, const CSCLayer *layer, const CSCStripDigiCollection::Range &rstripd)
int layer() const
Definition: CSCDetId.h:63
void setConditions(const CSCRecoConditions *reco)
Pass pointer to conditions data onwards.
const CSCLayer * getLayer(const CSCDetId &detId)
double acc2
int endcap() const
Definition: CSCDetId.h:95
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
void build(const CSCStripDigiCollection *stripds, const CSCWireDigiCollection *wireds, CSCRecHit2DCollection &oc)
void setConditions(const CSCRecoConditions *reco)
CSCHitFromWireOnly * hitsFromWireOnly_
int j
Definition: DBlmapReader.cc:9
bool isHitInFiducial(const CSCLayer *layer, const CSCRecHit2D &rh)
Test if rechit is in fiducial volume.
#define LogTrace(id)
static std::pair< CSCDetId, CSCDetIdSameDetLayerCompare > cscDetLayer(CSCDetId id)
CSCHitFromStripOnly * hitsFromStripOnly_
int ring() const
Definition: CSCDetId.h:77
void setConditions(const CSCRecoConditions *reco)
std::vector< CSCWireHit > runWire(const CSCDetId &id, const CSCLayer *layer, const CSCWireDigiCollection::Range &rwired)
CSCRecHitDBuilder(const edm::ParameterSet &ps)
CSCRecHit2D hitFromStripAndWire(const CSCDetId &id, const CSCLayer *layer, const CSCWireHit &wHit, const CSCStripHit &sHit)
Make 2D hits when have both wire and strip hit available in same layer.
void setConditions(const CSCRecoConditions *reco)
CSCMake2DRecHit * make2DHits_
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:124
int station() const
Definition: CSCDetId.h:88
std::pair< const_iterator, const_iterator > Range