CMS 3D CMS Logo

CSCComparatorDigiFitter.cc
Go to the documentation of this file.
4 
5 namespace {
6  // CSC LCT patterns
7  // the number quotes the distance to the center
8 
9  // pid=0: no pattern found
10  const std::vector<std::vector<int> > pat0delta(CSCConstants::NUM_LAYERS);
11 
12  // pid=1: layer-OR trigger
13  const std::vector<std::vector<int> > pat1delta{{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5},
14  {-2, -1, 0, 1, 2},
15  {0},
16  {-2, -1, 0, 1, 2},
17  {-4, -3, -2, -1, 0, 1, 2, 3, 4},
18  {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}};
19 
20  // pid=2: right-bending (large)
21  const std::vector<std::vector<int> > pat2delta{{3, 4, 5}, {1, 2}, {0}, {-2, -1, 0}, {-4, -3, -2}, {-5, -4, -3}};
22 
23  // pid=3: left-bending (large)
24  const std::vector<std::vector<int> > pat3delta{{-5, -4, -3}, {-2, -1}, {0}, {0, 1, 2}, {2, 3, 4}, {3, 4, 5}};
25 
26  // pid=4: right-bending (medium)
27  const std::vector<std::vector<int> > pat4delta{{2, 3, 4}, {1, 2}, {0}, {-2, -1}, {-4, -3, -2}, {-4, -3, -2}
28 
29  };
30 
31  // pid=5: left-bending (medium)
32  const std::vector<std::vector<int> > pat5delta{{-4, -3, -2}, {-2, -1}, {0}, {1, 2}, {2, 3, 4}, {2, 3, 4}
33 
34  };
35 
36  // pid=6: right-bending (medium)
37  const std::vector<std::vector<int> > pat6delta{{1, 2, 3}, {0, 1}, {0}, {-1, 0}, {-2, -1}, {-3, -2, -1}};
38 
39  // pid=7: left-bending (medium)
40  const std::vector<std::vector<int> > pat7delta{{-3, -2, -1}, {-1, 0}, {0}, {0, 1}, {1, 2}, {1, 2, 3}};
41 
42  // pid=8: right-bending (small)
43  const std::vector<std::vector<int> > pat8delta{{0, 1, 2}, {0, 1}, {0}, {-1, 0}, {-2, -1, 0}, {-2, -1, 0}};
44 
45  // pid=9: left-bending (small)
46  const std::vector<std::vector<int> > pat9delta{{-2, -1, 0}, {-1, 0}, {0}, {0, 1}, {0, 1, 2}, {0, 1, 2}};
47 
48  // pid=A: straight-through
49  const std::vector<std::vector<int> > patAdelta{{-1, 0, 1}, {0}, {0}, {0}, {-1, 0, 1}, {-1, 0, 1}};
50 
51  const std::vector<std::vector<std::vector<int> > > patIndexToPatternDelta{pat0delta,
52  pat1delta,
53  pat2delta,
54  pat3delta,
55  pat4delta,
56  pat5delta,
57  pat6delta,
58  pat7delta,
59  pat8delta,
60  pat9delta,
61  patAdelta};
62 } // namespace
63 
65  const CSCCorrelatedLCTDigi& stub,
66  const CSCComparatorDigiCollection& hCSCComparators) {
67  // fetch the CSC comparator digis in this chamber
68  for (int iLayer = 1; iLayer <= CSCConstants::NUM_LAYERS; ++iLayer) {
69  const CSCDetId layerId(ch_id.endcap(), ch_id.station(), ch_id.ring(), ch_id.chamber(), iLayer);
70 
71  // get the digis per layer
72  const auto& compRange = hCSCComparators.get(layerId);
74 
75  for (auto compDigiItr = compRange.first; compDigiItr != compRange.second; compDigiItr++) {
76  const auto& compDigi = *compDigiItr;
77 
78  //if (stub.getTimeBin() < 4 or stub.getTimeBin() > 8) continue;
79  const int stubHalfStrip(compDigi.getHalfStrip());
80 
81  // these comparator digis never fit the pattern anyway!
82  if (std::abs(stubHalfStrip - stub.getStrip()) > 5)
83  continue;
84 
85  // check if this comparator digi fits the pattern
86  if (comparatorInLCTPattern(stub.getStrip(), stub.getPattern(), iLayer, stubHalfStrip)) {
87  compDigis.push_back(compDigi);
88  }
89  }
90  compDigisIds_.emplace_back(layerId, compDigis);
91  }
92 }
93 
95  const auto& cscChamber = cscGeometry_->chamber(ch_id);
96 
97  // get the z and phi positions of the comparator digis
98  float radius_ = 0.0;
99 
100  // loop on all matching digis
101  for (const auto& p : compDigisIds_) {
102  const auto& detId = p.first;
103 
104  float phi_tmp = 0.0;
105  float radius_tmp = 0.0;
106  float z_tmp = 0.0;
107 
108  // ignore layers with no digis
109  if (p.second.empty())
110  continue;
111 
112  // loop on all matching digis in this layer
113  for (const auto& hit : p.second) {
114  const float fractional_strip = hit.getFractionalStrip();
115  const auto& layer_geo = cscChamber->layer(detId.layer())->geometry();
116  const float wire = layer_geo->middleWireOfGroup(stub.getKeyWG() + 1);
117 
118  // get the phi of each comparator digi
119  const LocalPoint& csc_intersect = layer_geo->intersectionOfStripAndWire(fractional_strip, wire);
120  const GlobalPoint& csc_gp = cscGeometry_->idToDet(detId)->surface().toGlobal(csc_intersect);
121  const float gpphi = csc_gp.phi();
122 
123  // normalize phi values according to first one
124  if (!phis_.empty() and gpphi > 0 and phis_[0] < 0 and (gpphi - phis_[0]) > M_PI)
125  phi_tmp += (gpphi - 2 * M_PI);
126  else if (!phis_.empty() and gpphi < 0 and phis_[0] > 0 and (gpphi - phis_[0]) < -M_PI)
127  phi_tmp += (gpphi + 2 * M_PI);
128  else
129  phi_tmp += (csc_gp.phi());
130 
131  z_tmp = csc_gp.z();
132  radius_tmp += csc_gp.perp();
133  }
134 
135  //in case there are more than one comparator digis in one layer
136  radius_tmp = radius_tmp / (p.second).size();
137  radius_ += radius_tmp;
138 
139  zs_.push_back(z_tmp);
140  ezs_.push_back(0);
141 
142  phi_tmp = phi_tmp / (p.second).size();
143  phis_.push_back(phi_tmp);
144  // assume that the charge is flat distributed across the half-strip
145  // this is only approximately valid, but good enough for now
146  ephis_.push_back(cscHalfStripWidth(detId) / sqrt(12));
147  }
148 }
149 
151  const CSCCorrelatedLCTDigi& stub,
152  const CSCComparatorDigiCollection& hCSCComparators,
153  std::vector<float>& fit_phi_layers,
154  std::vector<float>& fit_z_layers,
155  float& keyRadius) {
156  // clear fit results
157  fit_phi_layers.clear();
158  fit_z_layers.clear();
159  keyRadius = 0;
160 
161  // first, match the comparator digis to the LCT
162  matchingComparatorDigisLCT(ch_id, stub, hCSCComparators);
163 
164  // second, get the coordinates
165  getComparatorDigiCoordinates(ch_id, stub);
166 
167  // get radius of the stub from key layer
168  const CSCDetId key_id(ch_id.endcap(), ch_id.station(), ch_id.ring(), ch_id.chamber(), CSCConstants::KEY_CLCT_LAYER);
169  const float fractional_strip = stub.getFractionalStrip();
170 
171  const auto& cscChamber = cscGeometry_->chamber(ch_id);
172  const auto& layer_geo = cscChamber->layer(CSCConstants::KEY_CLCT_LAYER)->geometry();
173 
174  // LCT::getKeyWG() also starts from 0
175  const float wire = layer_geo->middleWireOfGroup(stub.getKeyWG() + 1);
176  const LocalPoint& csc_intersect = layer_geo->intersectionOfStripAndWire(fractional_strip, wire);
177  const GlobalPoint& csc_gp = cscGeometry_->idToDet(key_id)->surface().toGlobal(csc_intersect);
178 
179  // get radius from key layer
180  if (useKeyRadius_)
181  radius_ = radius_ / phis_.size();
182  else
183  radius_ = csc_gp.perp();
184 
185  float alpha = -99., beta = 0.;
186  // do a fit to the comparator digis
188  if (phis_.size() <= 2 or std::abs(alpha) >= 99) {
189  alpha = csc_gp.phi();
190  beta = 0.0;
191  }
192 
193  // determine the pitch of the chamber
194  // option to discretize the pitch
195  float stripPhiPitch = layer_geo->stripPhiPitch();
196  if (nStripBits_)
197  stripPhiPitch = stripPhiPitch / nStripBits_;
198 
199  // get the fit results
200  // option to discretize the fitted phi value
201  keyRadius = radius_;
202 
203  for (int i = 0; i < CSCConstants::NUM_LAYERS; i++) {
204  const float fit_z = cscChamber->layer(i + 1)->centerOfStrip(20).z();
205  const float fit_phi = normalizedPhi(alpha + beta * fit_z);
206  fit_z_layers.push_back(fit_z);
207  fit_phi_layers.push_back(fit_phi);
208  if (nStripBits_)
209  fit_phi_layers.push_back((std::floor(fit_phi / stripPhiPitch) + 0.5) * stripPhiPitch);
210  }
211 }
212 
214  // if there are at least 3 hits in the chamber, do a linear fit to the
215  // comparator digi positions with the chi2 method
216  if (phis_.size() >= 3) {
217  float Sxx = 0, Sxy = 0, Sx = 0, Sy = 0, S = 0;
218  for (unsigned i = 0; i < phis_.size(); ++i) {
219  float sigma2_inv = 1. / ephis_[i] * ephis_[i];
220  Sxx += zs_[i] * zs_[i] * sigma2_inv;
221  Sxy += zs_[i] * phis_[i] * sigma2_inv;
222  Sx += zs_[i] * zs_[i] * sigma2_inv;
223  Sy += phis_[i] * sigma2_inv;
224  S += sigma2_inv;
225  }
226  float delta = S * Sxx - Sx * Sx;
227  alpha = (Sxx * Sy - Sx * Sxy) / delta;
228  beta = (S * Sxy - Sx * Sy) / delta;
229  } else {
230  alpha = -99;
231  beta = 0.0;
232  }
233 }
234 
236  // what is the chamber type?
237  int index = id.iChamberType() - 1;
238 
239  // calculate the half strip width of this chamber
240  return degrees_[index] * M_PI / 180. / (2. * strips_[index]);
241 }
242 
243 bool CSCComparatorDigiFitter::comparatorInLCTPattern(int keyStrip, int pattern, int layer, int halfStrip) const {
244  // get the (sub)pattern
245  const std::vector<int>& subpat = patIndexToPatternDelta[pattern].at(layer - 1);
246 
247  // due to comparator digi time extension in the CLCT processor we need to
248  // search a bigger region around the key HS. +/-1, 0 should be sufficient
249  const int halfStripDelta = halfStrip - keyStrip;
250  return (std::find(subpat.begin(), subpat.end(), halfStripDelta + 1) != subpat.end() or
251  std::find(subpat.begin(), subpat.end(), halfStripDelta) != subpat.end() or
252  std::find(subpat.begin(), subpat.end(), halfStripDelta - 1) != subpat.end());
253 }
CSCComparatorDigiFitter::radius_
float radius_
Definition: CSCComparatorDigiFitter.h:92
geometry
ESHandle< TrackerGeometry > geometry
Definition: TkLasBeamFitter.cc:200
mps_fire.i
i
Definition: mps_fire.py:355
CSCComparatorDigiFitter::phis_
std::vector< float > phis_
Definition: CSCComparatorDigiFitter.h:88
CSCChamber::layer
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:30
CSCComparatorDigiFitter::ephis_
std::vector< float > ephis_
Definition: CSCComparatorDigiFitter.h:90
CSCComparatorDigiFitter::calculateSlopeIntercept
void calculateSlopeIntercept(float &alpha, float &beta)
Definition: CSCComparatorDigiFitter.cc:213
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
zMuMuMuonUserData.beta
beta
Definition: zMuMuMuonUserData.py:10
CSCDetId::ring
int ring() const
Definition: CSCDetId.h:68
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CSCCorrelatedLCTDigi::getStrip
uint16_t getStrip(uint16_t n=2) const
return the key halfstrip from 0,159
Definition: CSCCorrelatedLCTDigi.cc:66
CSCGeometry::idToDet
const GeomDet * idToDet(DetId) const override
Definition: CSCGeometry.cc:91
CSCCorrelatedLCTDigi::getKeyWG
uint16_t getKeyWG() const
return the key wire group. counts from 0.
Definition: CSCCorrelatedLCTDigi.h:56
CSCCorrelatedLCTDigi::getFractionalStrip
float getFractionalStrip(uint16_t n=2) const
return the fractional strip. counts from 0.25
Definition: CSCCorrelatedLCTDigi.cc:102
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
CSCComparatorDigiFitter::fit
void fit(const CSCDetId &ch_id, const CSCCorrelatedLCTDigi &, const CSCComparatorDigiCollection &, std::vector< float > &fit_phi_layers, std::vector< float > &fit_z_layers, float &keyRadius)
Definition: CSCComparatorDigiFitter.cc:150
CSCComparatorDigiFitter::degrees_
const std::vector< float > degrees_
Definition: CSCComparatorDigiFitter.h:98
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
CSCComparatorDigiFitter::cscHalfStripWidth
float cscHalfStripWidth(const CSCDetId &id) const
Definition: CSCComparatorDigiFitter.cc:235
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
CSCConstants::NUM_LAYERS
Definition: CSCConstants.h:46
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
normalizedPhi
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
CSCConstants.h
CSCLayerGeometry::middleWireOfGroup
float middleWireOfGroup(int wireGroup) const
Definition: CSCLayerGeometry.h:191
CSCLayer::geometry
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:44
Point3DBase< float, LocalTag >
CSCComparatorDigiFitter::matchingComparatorDigisLCT
void matchingComparatorDigisLCT(const CSCDetId &ch_id, const CSCCorrelatedLCTDigi &, const CSCComparatorDigiCollection &)
Definition: CSCComparatorDigiFitter.cc:64
CSCComparatorDigiFitter::getComparatorDigiCoordinates
void getComparatorDigiCoordinates(const CSCDetId &ch_id, const CSCCorrelatedLCTDigi &stub)
Definition: CSCComparatorDigiFitter.cc:94
CSCComparatorDigiFitter::strips_
const std::vector< int > strips_
Definition: CSCComparatorDigiFitter.h:97
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
CSCDetId
Definition: CSCDetId.h:26
normalizedPhi.h
CSCComparatorDigiFitter::useKeyRadius_
bool useKeyRadius_
Definition: CSCComparatorDigiFitter.h:93
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
CSCComparatorDigiFitter::ezs_
std::vector< float > ezs_
Definition: CSCComparatorDigiFitter.h:91
CSCComparatorDigiCollection
CSCDetId::chamber
int chamber() const
Definition: CSCDetId.h:62
CSCComparatorDigiFitter::compDigisIds_
CSCComparatorDigiContainerIds compDigisIds_
Definition: CSCComparatorDigiFitter.h:85
CSCComparatorDigiFitter::comparatorInLCTPattern
bool comparatorInLCTPattern(int keyStrip, int pattern, int layer, int halfStrip) const
Definition: CSCComparatorDigiFitter.cc:243
CSCCorrelatedLCTDigi::getPattern
uint16_t getPattern() const
Definition: CSCCorrelatedLCTDigi.h:78
CSCDetId::endcap
int endcap() const
Definition: CSCDetId.h:85
CSCConstants::KEY_CLCT_LAYER
Definition: CSCConstants.h:46
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
S
Definition: CSCDBL1TPParametersExtended.h:16
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
CSCComparatorDigiContainer
std::vector< CSCComparatorDigi > CSCComparatorDigiContainer
Definition: CSCComparatorDigiFitter.h:35
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CSCComparatorDigiFitter::nStripBits_
int nStripBits_
Definition: CSCComparatorDigiFitter.h:83
CSCDetId::station
int station() const
Definition: CSCDetId.h:79
CSCComparatorDigiFitter::zs_
std::vector< float > zs_
Definition: CSCComparatorDigiFitter.h:89
CSCComparatorDigiFitter.h
CSCComparatorDigiFitter::cscGeometry_
const CSCGeometry * cscGeometry_
Definition: CSCComparatorDigiFitter.h:80
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
CSCGeometry::chamber
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:100
hit
Definition: SiStripHitEffFromCalibTree.cc:88
CSCCorrelatedLCTDigi
Definition: CSCCorrelatedLCTDigi.h:19
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443