49 std::stringstream
name, name2, name3,
title;
53 m_slopeResiduals = tFileService->
make<TH1F>(name.str().c_str(), title.str().c_str(), 300, -30., 30.);
56 m_offsetResiduals = tFileService->
make<TH1F>(name2.str().c_str(), title.str().c_str(), 300, -30., 30.);
59 m_radial = tFileService->
make<TH1F>(name3.str().c_str(), title.str().c_str(), 700, 0., 700.);
94 std::vector<const TransientTrackingRecHit*> hits_i;
95 std::vector<const TransientTrackingRecHit*> hits_j;
97 for (std::vector<TrajectoryMeasurement>::const_iterator measurement = measurements.begin(); measurement != measurements.end(); ++measurement) {
106 if (chamberId ==
m_id_i) hits_i.push_back(hit);
107 if (chamberId ==
m_id_j) hits_j.push_back(hit);
122 double intercept_i = 0.;
123 double interceptError2_i = 0.;
125 double slopeError2_i = 0.;
126 double intercept_j = 0.;
127 double interceptError2_j = 0.;
129 double slopeError2_j = 0.;
138 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits_i.begin();
hit != hits_i.end(); ++
hit) {
141 double z = (*hit)->globalPosition().z() -
m_Zplane;
146 sumy_i += weight * (phi - z*dphidz);
151 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits_j.begin();
hit != hits_j.end(); ++
hit) {
154 double z = (*hit)->globalPosition().z() -
m_Zplane;
159 sumy_j += weight * (phi - z*dphidz);
162 if (sum1_i != 0. && sum1_j != 0.) {
163 slope_i = slope_j = dphidz;
165 intercept_i = sumy_i / sum1_i;
166 interceptError2_i = 1. / sum1_i;
168 intercept_j = sumy_j / sum1_j;
169 interceptError2_j = 1. / sum1_j;
181 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits_i.begin();
hit != hits_i.end(); ++
hit) {
184 double z = (*hit)->globalPosition().z() -
m_Zplane;
189 sumx_i += weight *
z;
190 sumy_i += weight *
phi;
191 sumxx_i += weight * z*
z;
192 sumxy_i += weight * z*
phi;
200 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits_j.begin();
hit != hits_j.end(); ++
hit) {
203 double z = (*hit)->globalPosition().z() -
m_Zplane;
208 sumx_j += weight *
z;
209 sumy_j += weight *
phi;
210 sumxx_j += weight * z*
z;
211 sumxy_j += weight * z*
phi;
214 double delta_i = (sum1_i*sumxx_i) - (sumx_i*sumx_i);
215 double delta_j = (sum1_j*sumxx_j) - (sumx_j*sumx_j);
216 if (delta_i != 0. && delta_j != 0.) {
217 intercept_i = ((sumxx_i*sumy_i) - (sumx_i*sumxy_i))/delta_i;
218 interceptError2_i = sumxx_i/delta_i;
219 slope_i = ((sum1_i*sumxy_i) - (sumx_i*sumy_i))/delta_i;
220 slopeError2_i = sum1_i/delta_i;
222 intercept_j = ((sumxx_j*sumy_j) - (sumx_j*sumxy_j))/delta_j;
223 interceptError2_j = sumxx_j/delta_j;
224 slope_j = ((sum1_j*sumxy_j) - (sumx_j*sumy_j))/delta_j;
225 slopeError2_j = sum1_j/delta_j;
234 double sumxx_ri = 0.;
235 double sumxy_ri = 0.;
236 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits_i.begin();
hit != hits_i.end(); ++
hit) {
237 double r = (*hit)->globalPosition().perp();
238 double z = (*hit)->globalPosition().z() -
m_Zplane;
245 double radial_delta_i = (sum1_ri*sumxx_ri) - (sumx_ri*sumx_ri);
246 if (radial_delta_i == 0.)
return false;
247 double radial_slope_i = ((sum1_ri*sumxy_ri) - (sumx_ri*sumy_ri))/radial_delta_i;
248 double radial_intercept_i = ((sumxx_ri*sumy_ri) - (sumx_ri*sumxy_ri))/radial_delta_i + radial_slope_i*(
m_iZ -
m_Zplane);
253 double sumxx_rj = 0.;
254 double sumxy_rj = 0.;
255 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits_j.begin();
hit != hits_j.end(); ++
hit) {
256 double r = (*hit)->globalPosition().perp();
257 double z = (*hit)->globalPosition().z() -
m_Zplane;
264 double radial_delta_j = (sum1_rj*sumxx_rj) - (sumx_rj*sumx_rj);
265 if (radial_delta_j == 0.)
return false;
266 double radial_slope_j = ((sum1_rj*sumxy_rj) - (sumx_rj*sumy_rj))/radial_delta_j;
267 double radial_intercept_j = ((sumxx_rj*sumy_rj) - (sumx_rj*sumxy_rj))/radial_delta_j + radial_slope_j*(
m_jZ -
m_Zplane);
269 double radial_delta = ((sum1_ri + sum1_rj)*(sumxx_ri + sumxx_rj)) - ((sumx_ri + sumx_rj)*(sumx_ri + sumx_rj));
270 if (radial_delta == 0.)
return false;
271 double radial_intercept = (((sumxx_ri + sumxx_rj)*(sumy_ri + sumy_rj)) - ((sumx_ri + sumx_rj)*(sumxy_ri + sumxy_rj)))/radial_delta;
272 double radial_slope = (((sum1_ri + sum1_rj)*(sumxy_ri + sumxy_rj)) - ((sumx_ri + sumx_rj)*(sumy_ri + sumy_rj)))/radial_delta;
279 double quantity = 0.;
280 double quantityError2 = 0.;
282 quantity = (slope_i*radial_intercept_i) - (slope_j*radial_intercept_j);
283 quantityError2 = (slopeError2_i)*
pow(radial_intercept_i, 2) + (slopeError2_j)*
pow(radial_intercept_j, 2);
286 quantity = intercept_i - intercept_j;
287 quantityError2 = interceptError2_i + interceptError2_j;
290 quantity = (intercept_i - intercept_j) * radial_intercept;
291 quantityError2 = (interceptError2_i + interceptError2_j) *
pow(radial_intercept, 2);
295 if (quantityError2 == 0.)
return false;
297 double slopeResid = ((slope_i*radial_intercept_i) - (slope_j*radial_intercept_j)) * 1000.;
298 double slopeResidError2 = ((slopeError2_i)*
pow(radial_intercept_i, 2) + (slopeError2_j)*
pow(radial_intercept_j, 2)) * 1000. * 1000.;
299 double offsetResid = (intercept_i - intercept_j) * radial_intercept * 10.;
300 double offsetResidError2 = (interceptError2_i + interceptError2_j) *
pow(radial_intercept, 2) * 10. * 10.;
312 m_sumy += weight * quantity;
314 m_sumyy += weight * quantity*quantity;
318 double rphi_slope_i = slope_i * radial_intercept_i;
319 double rphi_slope_j = slope_j * radial_intercept_j;
390 for (std::vector<TrajectoryMeasurement>::const_iterator measurement = measurements.begin(); measurement != measurements.end(); ++measurement) {
391 DetId id = measurement->recHit()->geographicalId();
399 if (stations.find(station) == stations.end()) {
405 cscHits.push_back(measurement->recHit());
412 for (std::map<int,int>::const_iterator
station = stations.begin();
station != stations.end(); ++
station) {
422 if (!trajectories.empty()) {
423 const std::vector<TrajectoryMeasurement> &measurements2 = trajectories.begin()->measurements();
426 bool found_plus =
false;
427 bool found_minus =
false;
429 for (std::vector<TrajectoryMeasurement>::const_iterator measurement = measurements2.begin(); measurement != measurements2.end(); ++measurement) {
430 double z = measurement->recHit()->globalPosition().z();
435 if (tsos_plus.
isValid()) found_plus =
true;
441 if (tsos_minus.
isValid()) found_minus =
true;
456 if (found_plus && from_plus.
isValid() && found_minus && from_minus.
isValid()) {
459 else if (found_plus && from_plus.
isValid()) {
462 else if (found_minus && from_minus.
isValid()) {
471 double dxdz = direction.
x() / direction.
z();
472 double dydz = direction.
y() / direction.
z();
483 output << std::setprecision(14) << std::fixed;
484 output <<
"CSCPairResidualsConstraint " <<
m_identifier <<
" " <<
i() <<
" " <<
j() <<
" "
497 std::vector<std::ifstream*>::const_iterator inputiter = input.begin();
498 std::vector<std::string>::const_iterator
filename = filenames.begin();
499 for (; inputiter != input.end(); ++inputiter, ++
filename) {
501 bool touched =
false;
502 while (!(*inputiter)->eof()) {
505 unsigned int identifier;
508 double sum1, sumx, sumy, sumxx, sumyy, sumxy;
510 (**inputiter) >> name >> identifier >> i >> j >> sumN >> sum1 >> sumx >> sumy >> sumxx >> sumyy >> sumxy >> eoln;
512 if (!(*inputiter)->eof() && (name !=
"CSCPairResidualsConstraint" || eoln !=
"EOLN"))
throw cms::Exception(
"CorruptTempFile") <<
"Temporary file " << *filename <<
" is incorrectly formatted on line " << linenumber << std::endl;
515 if (i !=
m_i || j !=
m_j)
throw cms::Exception(
"CorruptTempFile") <<
"Wrong (i,j) for CSCPairResidualsConstraint " <<
m_identifier <<
" (" <<
m_i <<
"," <<
m_j <<
") in file " << *filename <<
" on line " << linenumber << std::endl;
528 (*inputiter)->clear();
529 (*inputiter)->seekg(0, std::ios::beg);
531 if (!touched)
throw cms::Exception(
"CorruptTempFile") <<
"CSCPairResidualsConstraint " <<
m_identifier <<
" is missing from file " << *filename << std::endl;
554 const double R_ME11 = 181.5;
555 const double R_ME12 = 369.7;
556 const double R_ME21 = 242.7;
557 const double R_ME31 = 252.7;
558 const double R_ME41 = 262.65;
559 const double R_MEx2 = 526.5;
562 if (cscid.
station() == 1 && (cscid.
ring() == 1 || cscid.
ring() == 4)) R = R_ME11;
563 else if (cscid.
station() == 1 && cscid.
ring() == 2) R = R_ME12;
564 else if (cscid.
station() == 2 && cscid.
ring() == 1) R = R_ME21;
565 else if (cscid.
station() == 3 && cscid.
ring() == 1) R = R_ME31;
566 else if (cscid.
station() == 4 && cscid.
ring() == 1) R = R_ME41;
567 else if (cscid.
station() > 1 && cscid.
ring() == 2) R = R_MEx2;
571 phi = atan2(pos.
x(),
r);
574 else if (cscid.
endcap() == 2 && cscid.
station() <= 2) phi *= -1;
579 double sinAngle =
sin(angle);
580 double cosAngle =
cos(angle);
584 phierr2 = (xx*cosAngle*cosAngle + 2.*xy*sinAngle*cosAngle + yy*sinAngle*sinAngle) / (r*r);
594 const double cut_ME11 = 0.086;
595 const double cut_ME12 = 0.090;
596 const double cut_MEx1 = 0.180;
597 const double cut_MEx2 = 0.090;
604 for (std::vector<const TransientTrackingRecHit*>::const_iterator
hit = hits.begin();
hit != hits.end(); ++
hit) {
628 sumy += weight *
phi;
629 sumxx += weight * z*
z;
630 sumxy += weight * z*
phi;
632 double delta = (sum1*sumxx) - (sumx*sumx);
633 if (delta == 0.)
return false;
634 double intercept = ((sumxx*sumy) - (sumx*sumxy))/delta;
635 double slope = ((sum1*sumxy) - (sumx*sumy))/delta;
637 double phi1 = intercept + slope*(is_i ?
m_iZ1 :
m_jZ1);
638 double phi6 = intercept + slope*(is_i ?
m_iZ6 :
m_jZ6);
641 return (fabs(phi1) < cut_ME11 && fabs(phi6) < cut_ME11);
644 return (fabs(phi1) < cut_ME12 && fabs(phi6) < cut_ME12);
647 return (fabs(phi1) < cut_MEx1 && fabs(phi6) < cut_MEx1);
650 return (fabs(phi1) < cut_MEx2 && fabs(phi6) < cut_MEx2);
double m_truncateSlopeResid
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
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
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
virtual GlobalPoint globalPosition() const
const Plane & surface() const
The nominal surface of the GeomDet.
static std::string const input
TH1F * m_slopeResiduals_weighted
int m_minStationsInTrackRefits
LocalPoint toLocal(const GlobalPoint &gp) const
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
std::vector< ConstRecHitPointer > ConstRecHitContainer
int nearestStrip(const LocalPoint &lp) const
TProfile * m_fiducial_MEx1
virtual LocalError localPositionError() const =0
Geom::Phi< T > phi() 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
virtual const GeomDet * idToDet(DetId) const override