50 #include "TGraphErrors.h" 79 vector<const GeomDetUnit *> &gd,
80 vector<GlobalPoint> &globHit,
81 unsigned int &hitsAtTecPlus);
86 static double tecPlusFunction(
double *x,
double *par);
87 static double tecMinusFunction(
double *x,
double *par);
88 static double atFunction(
double *x,
double *par);
92 unsigned int &hitsAtTecPlus,
93 unsigned int &nFitParams,
94 std::vector<double> &hitPhi,
95 std::vector<double> &hitPhiError,
96 std::vector<double> &hitZprimeError,
104 double &phiAtMinusParam,
105 double &phiAtPlusParam,
106 double &atThetaSplitParam);
114 double &bsAngleParam,
115 double &phiAtMinusParam,
116 double &phiAtPlusParam,
117 double &atThetaSplitParam,
118 std::vector<GlobalPoint> &globHit);
122 unsigned int &hitsAtTecPlus,
125 std::vector<GlobalPoint> &globHit,
126 std::vector<GlobalPoint> &globPtrack,
128 std::vector<double> &hitPhiError);
132 vector<const GeomDetUnit *> &gd,
133 std::vector<GlobalPoint> &globPtrack,
134 vector<TrajectoryStateOnSurface> &tsosLas,
139 unsigned int &hitsAtTecPlus,
140 unsigned int &nFitParams,
143 vector<GlobalPoint> &globPtrack,
144 double &bsAngleParam,
169 TH1F *h_bsAngle, *h_hitX, *h_hitXTecPlus, *h_hitXTecMinus, *h_hitXAt, *h_chi2, *h_chi2ndof, *h_pull, *h_res,
171 TH2F *h_bsAngleVsBeam, *h_hitXvsZTecPlus, *h_hitXvsZTecMinus, *h_hitXvsZAt, *
h_resVsZTecPlus, *h_resVsZTecMinus,
172 *h_resVsZAt, *h_resVsHitTecPlus, *h_resVsHitTecMinus, *h_resVsHitAt;
206 : src_(iConfig.getParameter<
edm::
InputTag>(
"src")),
207 fitBeamSplitters_(iConfig.getParameter<
bool>(
"fitBeamSplitters")),
208 nAtParameters_(iConfig.getParameter<unsigned
int>(
"numberOfFittedAtParameters")),
232 this->produces<TkFittedLasBeamCollection, edm::Transition::EndRun>();
233 this->produces<TsosVectorCollection, edm::Transition::EndRun>();
267 h_hitX =
fs->
make<TH1F>(
"hitX",
"local x of LAS hits;local x [cm];N", 100, -0.5, 0.5);
268 h_hitXTecPlus =
fs->
make<TH1F>(
"hitXTecPlus",
"local x of LAS hits in TECplus;local x [cm];N", 100, -0.5, 0.5);
269 h_hitXTecMinus =
fs->
make<TH1F>(
"hitXTecMinus",
"local x of LAS hits in TECminus;local x [cm];N", 100, -0.5, 0.5);
270 h_hitXAt =
fs->
make<TH1F>(
"hitXAt",
"local x of LAS hits in ATs;local x [cm];N", 100, -2.5, 2.5);
272 fs->
make<TH2F>(
"hitXvsZTecPlus",
"local x vs z in TECplus;z [cm];local x [cm]", 80, 120, 280, 100, -0.5, 0.5);
274 fs->
make<TH2F>(
"hitXvsZTecMinus",
"local x vs z in TECMinus;z [cm];local x [cm]", 80, -280, -120, 100, -0.5, 0.5);
275 h_hitXvsZAt =
fs->
make<TH2F>(
"hitXvsZAt",
"local x vs z in ATs;z [cm];local x [cm]", 200, -200, 200, 100, -0.5, 0.5);
276 h_chi2 =
fs->
make<TH1F>(
"chi2",
"#chi^{2};#chi^{2};N", 100, 0, 2000);
277 h_chi2ndof =
fs->
make<TH1F>(
"chi2ndof",
"#chi^{2} per degree of freedom;#chi^{2}/N_{dof};N", 100, 0, 300);
278 h_pull =
fs->
make<TH1F>(
"pull",
"pulls of #phi residuals;pull;N", 50, -10, 10);
279 h_res =
fs->
make<TH1F>(
"res",
"#phi residuals;#phi_{track} - #phi_{hit} [rad];N", 60, -0.0015, 0.0015);
281 fs->
make<TH1F>(
"resTecPlus",
"#phi residuals in TECplus;#phi_{track} - #phi_{hit} [rad];N", 30, -0.0015, 0.0015);
283 "resTecMinus",
"#phi residuals in TECminus;#phi_{track} - #phi_{hit} [rad];N", 60, -0.0015, 0.0015);
284 h_resAt =
fs->
make<TH1F>(
"resAt",
"#phi residuals in ATs;#phi_{track} - #phi_{hit} [rad];N", 30, -0.0015, 0.0015);
286 "phi residuals vs. z in TECplus;z [cm];#phi_{track} - #phi_{hit} [rad]",
294 "phi residuals vs. z in TECminus;z [cm];#phi_{track} - #phi_{hit} [rad]",
302 "resVsZAt",
"#phi residuals vs. z in ATs;N;#phi_{track} - #phi_{hit} [rad]", 200, -200, 200, 100, -0.0015, 0.0015);
304 "#phi residuals vs. hits in TECplus;hit no.;#phi_{track} - #phi_{hit} [rad]",
312 "#phi residuals vs. hits in TECminus;hit no.;#phi_{track} - #phi_{hit} [rad]",
320 "#phi residuals vs. hits in ATs;hit no.;#phi_{track} - #phi_{hit} [rad]",
327 h_bsAngle =
fs->
make<TH1F>(
"bsAngle",
"fitted beam splitter angle;BS angle [rad];N", 40, -0.004, 0.004);
329 "bsAngleVsBeam",
"fitted beam splitter angle per beam;Beam no.;BS angle [rad]", 40, 0, 300, 100, -0.004, 0.004);
333 auto fittedBeams = std::make_unique<TkFittedLasBeamCollection>();
335 auto tsosesVec = std::make_unique<TsosVectorCollection>();
338 run.
getByLabel(
"LaserAlignment",
"tkLaserBeams", laserBeams);
352 double bsParams[40] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
353 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
356 unsigned int beamNo(0);
360 cout <<
"Fitting BS!" << endl;
362 cout <<
"BS fixed, not fitted!" << endl;
365 for (TkLasBeamCollection::const_iterator iBeam = laserBeams->begin(), iEnd = laserBeams->end(); iBeam != iEnd;
368 vector<TrajectoryStateOnSurface> tsosLas;
377 fittedBeams->push_back(beam);
378 tsosesVec->push_back(tsosLas);
399 cout <<
"---------------------------------------" << endl;
402 <<
" isAt: " << (beam.
isAlignmentTube() ?
"Y" :
"N") <<
" isR6: " << (beam.
isRing6() ?
"Y" :
"N") << endl;
413 vector<const GeomDetUnit *> gd;
414 vector<GlobalPoint> globHit;
415 unsigned int hitsAtTecPlus(0);
424 this->
getLasHits(beam, hit, gd, globHit, hitsAtTecPlus);
425 sumZ += globHit.back().z();
446 gBeamZ0 = sumZ / globHit.size();
468 vector<double> hitPhi, hitPhiError, hitZprimeError;
470 for (
unsigned int hit = 0;
hit < globHit.size(); ++
hit) {
471 hitPhi.push_back(static_cast<double>(globHit[
hit].
phi()));
473 hitPhiError.push_back(0.003 / globHit[
hit].
perp());
475 hitZprimeError.push_back(0.0);
495 unsigned int tecParams(3), atParams(0);
502 unsigned int nFitParams(0);
504 tecParams = tecParams - 1;
505 atParams = atParams - 1;
508 nFitParams = tecParams;
510 nFitParams = atParams;
514 double offset(0.), offsetError(0.),
slope(0.), slopeError(0.), bsAngleParam(0.), phiAtMinusParam(0.),
515 phiAtPlusParam(0.), atThetaSplitParam(0.);
541 vector<GlobalPoint> globPtrack;
547 double trackPhi(0.), trackPhiRef(0.);
562 <<
" r = " << globHit[
hit].perp() << endl;
567 const double phiResidual = globPtrack[
hit].phi() - globHit[
hit].phi();
569 const double phiResidualPull = phiResidual / hitPhiError[
hit];
574 chi2 += phiResidual * phiResidual / (hitPhiError[
hit] * hitPhiError[
hit]);
577 h_res->Fill(phiResidual);
580 h_pull->Fill(phiResidualPull);
594 h_pull->Fill(phiResidualPull);
608 h_pull->Fill(phiResidualPull);
617 cout <<
"chi^2 = " << chi2 <<
", chi^2/ndof = " << chi2 / (
gHitZprime.size() - nFitParams) << endl;
618 this->
fitBeam(beam, covMatrix, hitsAtTecPlus, nFitParams,
offset,
slope, globPtrack, bsAngleParam, chi2);
620 cout <<
"bsAngleParam = " << bsAngleParam << endl;
626 if (bsAngleParam != 0.0) {
627 h_bsAngle->Fill(2.0 * atan(0.5 * bsAngleParam));
635 vector<const GeomDetUnit *> &gd,
636 vector<GlobalPoint> &globHit,
637 unsigned int &hitsAtTecPlus) {
643 globHit.push_back(globPtemp);
646 if (
abs(globPtemp.
z()) > 112.3) {
647 if (globPtemp.
z() < 112.3)
660 return par[0] + par[1] *
z;
675 return par[0] + par[1] *
z;
690 return par[0] + par[1] *
z;
697 return par[0] + par[1] * z +
gTOBparam * (par[2] + par[4]);
701 return par[0] + par[1] * z -
gTIBparam * (par[2] - par[4]);
709 return par[0] + par[1] * z +
gTOBparam * (par[3] - par[4]);
713 return par[0] + par[1] * z -
gTIBparam * (par[3] + par[4]);
730 unsigned int &hitsAtTecPlus,
731 unsigned int &nFitParams,
732 vector<double> &hitPhi,
733 vector<double> &hitPhiError,
734 vector<double> &hitZprimeError,
737 double &bsAngleParam,
742 double &phiAtMinusParam,
743 double &phiAtPlusParam,
744 double &atThetaSplitParam) {
745 TGraphErrors *lasData =
746 new TGraphErrors(
gHitZprime.size(), &(
gHitZprime[0]), &(hitPhi[0]), &(hitZprimeError[0]), &(hitPhiError[0]));
751 tecPlus.SetParameter(1, 0);
752 tecPlus.SetParameter(nFitParams - 1, 0);
753 lasData->Fit(&tecPlus,
"R");
756 tecMinus.SetParameter(1, 0);
757 tecMinus.SetParameter(nFitParams - 1, 0);
758 lasData->Fit(&tecMinus,
"R");
760 TF1 at(
"at",
atFunction, zMin, zMax, nFitParams);
761 at.SetParameter(1, 0);
762 at.SetParameter(nFitParams - 1, 0);
763 lasData->Fit(&at,
"R");
767 gMinuit->GetParameter(0, offset, offsetError);
768 gMinuit->GetParameter(1, slope, slopeError);
772 double bsAngleParamError(0.), phiAtMinusParamError(0.), phiAtPlusParamError(0.), atThetaSplitParamError(0.);
775 gMinuit->GetParameter(2, phiAtMinusParam, phiAtMinusParamError);
776 gMinuit->GetParameter(3, phiAtPlusParam, phiAtPlusParamError);
777 gMinuit->GetParameter(4, atThetaSplitParam, atThetaSplitParamError);
784 gMinuit->GetParameter(nFitParams - 1, bsAngleParam, bsAngleParamError);
791 vector<double> vec(covMatrix.num_col() * covMatrix.num_col());
792 gMinuit->mnemat(&vec[0], covMatrix.num_col());
793 for (
int col = 0;
col < covMatrix.num_col();
col++) {
794 for (
int row = 0; row < covMatrix.num_col(); row++) {
795 covMatrix[
col][row] = vec[row + covMatrix.num_col() *
col];
811 double &bsAngleParam,
812 double &phiAtMinusParam,
813 double &phiAtPlusParam,
814 double &atThetaSplitParam,
815 vector<GlobalPoint> &globHit) {
820 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
823 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0) -
831 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
834 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0) +
843 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
848 trackPhi = offset + slope *
gHitZprime[hit] +
gTOBparam * (phiAtMinusParam + atThetaSplitParam);
850 trackPhi = offset + slope *
gHitZprime[hit] -
gTIBparam * (phiAtMinusParam - atThetaSplitParam);
857 trackPhi = offset + slope *
gHitZprime[hit] +
gTOBparam * (phiAtPlusParam - atThetaSplitParam);
859 trackPhi = offset + slope *
gHitZprime[hit] -
gTIBparam * (phiAtPlusParam + atThetaSplitParam);
866 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0) -
875 unsigned int &hitsAtTecPlus,
878 vector<GlobalPoint> &globHit,
879 vector<GlobalPoint> &globPtrack,
881 vector<double> &hitPhiError) {
895 else if (hit >
gHitZprime.size() - hitsAtTecPlus - 1) {
910 vector<const GeomDetUnit *> &gd,
911 vector<GlobalPoint> &globPtrack,
912 vector<TrajectoryStateOnSurface> &tsosLas,
919 trajectoryState =
GlobalVector(globPref - globPtrack[hit]);
923 trajectoryState =
GlobalVector(globPtrack[hit] - globPref);
929 trajectoryState =
GlobalVector(globPtrack[hit] - globPref);
933 trajectoryState =
GlobalVector(globPref - globPtrack[hit]);
937 trajectoryState =
GlobalVector(globPtrack[hit] - globPref);
948 unsigned int &hitsAtTecPlus,
949 unsigned int &nFitParams,
952 vector<GlobalPoint> &globPtrack,
953 double &bsAngleParam,
956 unsigned int paramType(0);
964 const unsigned int nPedeParams(nFitParams);
967 std::vector<TkFittedLasBeam::Scalar>
params(nPedeParams);
977 derivatives[
hit][0] = 1.0;
982 derivatives[
hit][1] = globPtrack[
hit].z();
992 derivatives[
hit][1] = globPtrack[
hit].z();
1004 derivatives[
hit][1] = globPtrack[
hit].z();
1011 derivatives[
hit][1] = globPtrack[
hit].z();
1026 unsigned int firstFixedParam(covMatrix.num_col());
1031 beam.
setParameters(paramType, params, covMatrix, derivatives, firstFixedParam, chi2);
ESHandle< MagneticField > fieldHandle
static vector< double > gHitZprime
~TkLasBeamFitter() override
bool getByLabel(std::string const &label, Handle< PROD > &result) const
static double tecMinusFunction(double *x, double *par)
static double tecPlusFunction(double *x, double *par)
TkLasBeamFitter(const edm::ParameterSet &config)
static const double slope[3]
Global3DPoint GlobalPoint
bool isRing6(void) const
true if this beam hits TEC R6 (last digit of beamId)
static vector< double > gBarrelModuleRadius
T * make(const Args &...args) const
make new ROOT object
bool fitBeam(TkFittedLasBeam &beam, AlgebraicSymMatrix &covMatrix, unsigned int &hitsAtTecPlus, unsigned int &nFitParams, double &offset, double &slope, vector< GlobalPoint > &globPtrack, double &bsAngleParam, double &chi2)
static bool gFitBeamSplitters
bool isTecInternal(int side=0) const
true if this is a TEC internal beam (from 10^2 digit of beamId). side parameter: -1 = ask if TEC-...
Handle< TkLasBeamCollection > laserBeams
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
static bool gIsInnerBarrel
#define DEFINE_FWK_MODULE(type)
void endRunProduce(edm::Run &run, const edm::EventSetup &setup) override
unsigned int nAtParameters_
CLHEP::HepMatrix AlgebraicMatrix
unsigned int getBeamId(void) const
return the full beam identifier
void globalTrackPoint(TkFittedLasBeam &beam, unsigned int &hit, unsigned int &hitsAtTecPlus, double &trackPhi, double &trackPhiRef, std::vector< GlobalPoint > &globHit, std::vector< GlobalPoint > &globPtrack, GlobalPoint &globPref, std::vector< double > &hitPhiError)
static double gBeamSplitterZprime
std::vector< SiStripLaserRecHit2D >::const_iterator end(void) const
access iterator to the collection of hits
Abs< T >::type abs(const T &t)
TH2F * h_resVsHitTecMinus
void produce(edm::Event &event, const edm::EventSetup &setup) override
std::vector< SiStripLaserRecHit2D >::const_iterator begin(void) const
access iterator to the collection of hits
static unsigned int gHitsAtTecMinus
void fitter(TkFittedLasBeam &beam, AlgebraicSymMatrix &covMatrix, unsigned int &hitsAtTecPlus, unsigned int &nFitParams, std::vector< double > &hitPhi, std::vector< double > &hitPhiError, std::vector< double > &hitZprimeError, double &zMin, double &zMax, double &bsAngleParam, double &offset, double &offsetError, double &slope, double &slopeError, double &phiAtMinusParam, double &phiAtPlusParam, double &atThetaSplitParam)
const SiStripDetId & getDetId(void) const
void buildTrajectory(TkFittedLasBeam &beam, unsigned int &hit, vector< const GeomDetUnit * > &gd, std::vector< GlobalPoint > &globPtrack, vector< TrajectoryStateOnSurface > &tsosLas, GlobalPoint &globPref)
void put(std::unique_ptr< PROD > product)
Put a new product.
LocalPoint localPosition() const override
static vector< double > gBarrelModuleOffset
ESHandle< TrackerGeometry > geometry
T perp() const
Magnitude of transverse component.
void trackPhi(TkFittedLasBeam &beam, unsigned int &hit, double &trackPhi, double &trackPhiRef, double &offset, double &slope, double &bsAngleParam, double &phiAtMinusParam, double &phiAtPlusParam, double &atThetaSplitParam, std::vector< GlobalPoint > &globHit)
CLHEP::HepSymMatrix AlgebraicSymMatrix
static double atFunction(double *x, double *par)
void getLasBeams(TkFittedLasBeam &beam, vector< TrajectoryStateOnSurface > &tsosLas)
void getLasHits(TkFittedLasBeam &beam, const SiStripLaserRecHit2D &hit, vector< const GeomDetUnit * > &gd, vector< GlobalPoint > &globHit, unsigned int &hitsAtTecPlus)
edm::Service< TFileService > fs
T const * product() const
std::vector< SiStripLaserRecHit2D >::const_iterator const_iterator
bool isAlignmentTube(void) const
true if this is an AT beam (from 10^2 digit of beamId)
Global3DVector GlobalVector
void setParameters(unsigned int parametrisation, const std::vector< Scalar > ¶ms, const AlgebraicSymMatrix ¶mCovariance, const AlgebraicMatrix &derivatives, unsigned int firstFixedParam, float chi2)