44 std::stringstream
name, name2, name3,
title;
48 m_slopeResiduals = tFileService->
make<TH1F>(name.str().c_str(), title.str().c_str(), 300, -30., 30.);
51 m_offsetResiduals = tFileService->
make<TH1F>(name2.str().c_str(), title.str().c_str(), 300, -30., 30.);
54 m_radial = tFileService->
make<TH1F>(name3.str().c_str(), title.str().c_str(), 700, 0., 700.);
92 std::vector<const TransientTrackingRecHit *> hits_i;
93 std::vector<const TransientTrackingRecHit *> hits_j;
95 for (std::vector<TrajectoryMeasurement>::const_iterator measurement = measurements.begin();
96 measurement != measurements.end();
108 hits_i.push_back(hit);
110 hits_j.push_back(hit);
127 double intercept_i = 0.;
128 double interceptError2_i = 0.;
130 double slopeError2_i = 0.;
131 double intercept_j = 0.;
132 double interceptError2_j = 0.;
134 double slopeError2_j = 0.;
143 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits_i.begin();
hit != hits_i.end();
147 double z = (*hit)->globalPosition().z() -
m_Zplane;
151 weight = 1. / phierr2;
153 sumy_i += weight * (phi - z * dphidz);
158 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits_j.begin();
hit != hits_j.end();
162 double z = (*hit)->globalPosition().z() -
m_Zplane;
166 weight = 1. / phierr2;
168 sumy_j += weight * (phi - z * dphidz);
171 if (sum1_i != 0. && sum1_j != 0.) {
172 slope_i = slope_j = dphidz;
174 intercept_i = sumy_i / sum1_i;
175 interceptError2_i = 1. / sum1_i;
177 intercept_j = sumy_j / sum1_j;
178 interceptError2_j = 1. / sum1_j;
190 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits_i.begin();
hit != hits_i.end();
194 double z = (*hit)->globalPosition().z() -
m_Zplane;
198 weight = 1. / phierr2;
200 sumx_i += weight *
z;
201 sumy_i += weight *
phi;
202 sumxx_i += weight * z *
z;
203 sumxy_i += weight * z *
phi;
211 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits_j.begin();
hit != hits_j.end();
215 double z = (*hit)->globalPosition().z() -
m_Zplane;
219 weight = 1. / phierr2;
221 sumx_j += weight *
z;
222 sumy_j += weight *
phi;
223 sumxx_j += weight * z *
z;
224 sumxy_j += weight * z *
phi;
227 double delta_i = (sum1_i * sumxx_i) - (sumx_i * sumx_i);
228 double delta_j = (sum1_j * sumxx_j) - (sumx_j * sumx_j);
229 if (delta_i != 0. && delta_j != 0.) {
230 intercept_i = ((sumxx_i * sumy_i) - (sumx_i * sumxy_i)) / delta_i;
231 interceptError2_i = sumxx_i / delta_i;
232 slope_i = ((sum1_i * sumxy_i) - (sumx_i * sumy_i)) / delta_i;
233 slopeError2_i = sum1_i / delta_i;
235 intercept_j = ((sumxx_j * sumy_j) - (sumx_j * sumxy_j)) / delta_j;
236 interceptError2_j = sumxx_j / delta_j;
237 slope_j = ((sum1_j * sumxy_j) - (sumx_j * sumy_j)) / delta_j;
238 slopeError2_j = sum1_j / delta_j;
247 double sumxx_ri = 0.;
248 double sumxy_ri = 0.;
249 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits_i.begin();
hit != hits_i.end(); ++
hit) {
250 double r = (*hit)->globalPosition().perp();
251 double z = (*hit)->globalPosition().z() -
m_Zplane;
258 double radial_delta_i = (sum1_ri * sumxx_ri) - (sumx_ri * sumx_ri);
259 if (radial_delta_i == 0.)
261 double radial_slope_i = ((sum1_ri * sumxy_ri) - (sumx_ri * sumy_ri)) / radial_delta_i;
262 double radial_intercept_i =
263 ((sumxx_ri * sumy_ri) - (sumx_ri * sumxy_ri)) / radial_delta_i + radial_slope_i * (
m_iZ -
m_Zplane);
268 double sumxx_rj = 0.;
269 double sumxy_rj = 0.;
270 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits_j.begin();
hit != hits_j.end(); ++
hit) {
271 double r = (*hit)->globalPosition().perp();
272 double z = (*hit)->globalPosition().z() -
m_Zplane;
279 double radial_delta_j = (sum1_rj * sumxx_rj) - (sumx_rj * sumx_rj);
280 if (radial_delta_j == 0.)
282 double radial_slope_j = ((sum1_rj * sumxy_rj) - (sumx_rj * sumy_rj)) / radial_delta_j;
283 double radial_intercept_j =
284 ((sumxx_rj * sumy_rj) - (sumx_rj * sumxy_rj)) / radial_delta_j + radial_slope_j * (
m_jZ -
m_Zplane);
286 double radial_delta = ((sum1_ri + sum1_rj) * (sumxx_ri + sumxx_rj)) - ((sumx_ri + sumx_rj) * (sumx_ri + sumx_rj));
287 if (radial_delta == 0.)
289 double radial_intercept =
290 (((sumxx_ri + sumxx_rj) * (sumy_ri + sumy_rj)) - ((sumx_ri + sumx_rj) * (sumxy_ri + sumxy_rj))) / radial_delta;
291 double radial_slope =
292 (((sum1_ri + sum1_rj) * (sumxy_ri + sumxy_rj)) - ((sumx_ri + sumx_rj) * (sumy_ri + sumy_rj))) / radial_delta;
300 double quantity = 0.;
301 double quantityError2 = 0.;
303 quantity = (slope_i * radial_intercept_i) - (slope_j * radial_intercept_j);
304 quantityError2 = (slopeError2_i)*
pow(radial_intercept_i, 2) + (slopeError2_j)*
pow(radial_intercept_j, 2);
306 quantity = intercept_i - intercept_j;
307 quantityError2 = interceptError2_i + interceptError2_j;
309 quantity = (intercept_i - intercept_j) * radial_intercept;
310 quantityError2 = (interceptError2_i + interceptError2_j) *
pow(radial_intercept, 2);
314 if (quantityError2 == 0.)
317 double slopeResid = ((slope_i * radial_intercept_i) - (slope_j * radial_intercept_j)) * 1000.;
318 double slopeResidError2 =
319 ((slopeError2_i)*
pow(radial_intercept_i, 2) + (slopeError2_j)*
pow(radial_intercept_j, 2)) * 1000. * 1000.;
320 double offsetResid = (intercept_i - intercept_j) * radial_intercept * 10.;
321 double offsetResidError2 = (interceptError2_i + interceptError2_j) *
pow(radial_intercept, 2) * 10. * 10.;
330 weight = 1. / quantityError2;
336 m_sumy += weight * quantity;
338 m_sumyy += weight * quantity * quantity;
342 double rphi_slope_i = slope_i * radial_intercept_i;
343 double rphi_slope_j = slope_j * radial_intercept_j;
469 for (std::vector<TrajectoryMeasurement>::const_iterator measurement = measurements.begin();
470 measurement != measurements.end();
472 DetId id = measurement->recHit()->geographicalId();
481 if (stations.find(station) == stations.end()) {
487 cscHits.push_back(measurement->recHit());
494 for (std::map<int, int>::const_iterator
station = stations.begin();
station != stations.end(); ++
station) {
504 if (!trajectories.empty()) {
505 const std::vector<TrajectoryMeasurement> &measurements2 = trajectories.begin()->measurements();
508 bool found_plus =
false;
509 bool found_minus =
false;
511 for (std::vector<TrajectoryMeasurement>::const_iterator measurement = measurements2.begin();
512 measurement != measurements2.end();
514 double z = measurement->recHit()->globalPosition().z();
518 measurement->backwardPredictedState());
525 measurement->backwardPredictedState());
543 if (found_plus && from_plus.
isValid() && found_minus && from_minus.
isValid()) {
545 }
else if (found_plus && from_plus.
isValid()) {
547 }
else if (found_minus && from_minus.
isValid()) {
556 double dxdz = direction.
x() / direction.
z();
557 double dydz = direction.
y() / direction.
z();
568 output << std::setprecision(14) << std::fixed;
583 std::vector<std::ifstream *>::const_iterator inputiter = input.begin();
584 std::vector<std::string>::const_iterator
filename = filenames.begin();
585 for (; inputiter != input.end(); ++inputiter, ++
filename) {
587 bool touched =
false;
588 while (!(*inputiter)->eof()) {
591 unsigned int identifier;
594 double sum1, sumx, sumy, sumxx, sumyy, sumxy;
596 (**inputiter) >> name >> identifier >> i >> j >> sumN >> sum1 >> sumx >> sumy >> sumxx >> sumyy >> sumxy >> eoln;
598 if (!(*inputiter)->eof() && (name !=
"CSCPairResidualsConstraint" || eoln !=
"EOLN"))
600 <<
"Temporary file " << *filename <<
" is incorrectly formatted on line " << linenumber << std::endl;
605 <<
"Wrong (i,j) for CSCPairResidualsConstraint " <<
m_identifier <<
" (" <<
m_i <<
"," <<
m_j
606 <<
") in file " << *filename <<
" on line " << linenumber << std::endl;
619 (*inputiter)->clear();
620 (*inputiter)->seekg(0, std::ios::beg);
624 <<
"CSCPairResidualsConstraint " <<
m_identifier <<
" is missing from file " << *filename << std::endl;
647 const double R_ME11 = 181.5;
648 const double R_ME12 = 369.7;
649 const double R_ME21 = 242.7;
650 const double R_ME31 = 252.7;
651 const double R_ME41 = 262.65;
652 const double R_MEx2 = 526.5;
657 else if (cscid.
station() == 1 && cscid.
ring() == 2)
659 else if (cscid.
station() == 2 && cscid.
ring() == 1)
661 else if (cscid.
station() == 3 && cscid.
ring() == 1)
663 else if (cscid.
station() == 4 && cscid.
ring() == 1)
671 phi = atan2(pos.
x(),
r);
681 double sinAngle =
sin(angle);
682 double cosAngle =
cos(angle);
686 phierr2 = (xx * cosAngle * cosAngle + 2. * xy * sinAngle * cosAngle + yy * sinAngle * sinAngle) / (r * r);
696 const double cut_ME11 = 0.086;
697 const double cut_ME12 = 0.090;
698 const double cut_MEx1 = 0.180;
699 const double cut_MEx2 = 0.090;
706 for (std::vector<const TransientTrackingRecHit *>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
710 .
toLocal((*hit)->globalPosition())
727 weight = 1. / phierr2;
730 sumy += weight *
phi;
731 sumxx += weight * z *
z;
732 sumxy += weight * z *
phi;
734 double delta = (sum1 * sumxx) - (sumx * sumx);
737 double intercept = ((sumxx * sumy) - (sumx * sumxy)) / delta;
738 double slope = ((sum1 * sumxy) - (sumx * sumy)) / delta;
740 double phi1 = intercept + slope * (is_i ?
m_iZ1 :
m_jZ1);
741 double phi6 = intercept + slope * (is_i ?
m_iZ6 :
m_jZ6);
744 return (fabs(phi1) < cut_ME11 && fabs(phi6) < cut_ME11);
746 return (fabs(phi1) < cut_ME12 && fabs(phi6) < cut_ME12);
748 return (fabs(phi1) < cut_MEx1 && fabs(phi6) < cut_MEx1);
750 return (fabs(phi1) < cut_MEx2 && fabs(phi6) < cut_MEx2);
double m_truncateSlopeResid
void read(std::vector< std::ifstream * > &input, std::vector< std::string > &filenames)
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
static const double slope[3]
Sin< T >::type sin(const T &t)
Geom::Phi< T > phi() const
const Propagator * m_propagator
GlobalPoint globalPosition() const
T * make(const Args &...args) const
make new ROOT object
void setZplane(const CSCGeometry *cscGeometry)
double m_truncateOffsetResid
virtual GlobalPoint globalPosition() const
const Plane & surface() const
The nominal surface of the GeomDet.
static std::string const input
TH1F * m_slopeResiduals_weighted
double error() const override
int m_minStationsInTrackRefits
double value() const override
LocalPoint toLocal(const GlobalPoint &gp) const
static PlanePointer build(Args &&...args)
Cos< T >::type cos(const T &t)
void configure(CSCOverlapsAlignmentAlgorithm *parent)
void write(std::ofstream &output)
TProfile * m_fiducial_MEx2
bool isFiducial(std::vector< const TransientTrackingRecHit * > &hits, bool is_i)
TH1F * m_offsetResiduals_weighted
void calculatePhi(const TransientTrackingRecHit *hit, double &phi, double &phierr2, bool doRphi=false, bool globalPhi=false)
TH1F * m_offsetResiduals_normalized
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
std::vector< ConstRecHitPointer > ConstRecHitContainer
int nearestStrip(const LocalPoint &lp) const
Basic2DVector< T > xy() const
bool valid() const override
TProfile * m_fiducial_MEx1
virtual LocalError localPositionError() const =0
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
bool addTrack(const std::vector< TrajectoryMeasurement > &measurements, const reco::TransientTrack &track, const TrackTransformer *trackTransformer)
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
bool m_slopeFromTrackRefit
CSCOverlapsAlignmentAlgorithm * m_parent
int m_minTracksPerOverlap
unsigned int m_identifier
Plane::PlanePointer m_Zsurface
DetId geographicalId() const
bool dphidzFromTrack(const std::vector< TrajectoryMeasurement > &measurements, const reco::TransientTrack &track, const TrackTransformer *trackTransformer, double &drphidz)
virtual LocalPoint localPosition() const =0
const PositionType & position() const
float stripAngle(int strip) const
const CSCLayerGeometry * geometry() const
Power< A, B >::type pow(const A &a, const B &b)
TProfile * m_fiducial_ME12
TProfile * m_fiducial_ME11
void setPropagator(const Propagator *propagator)
TH1F * m_slopeResiduals_normalized
GlobalVector globalDirection() const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
const CSCGeometry * m_cscGeometry
const GeomDet * idToDet(DetId) const override