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,
179 TH1F *h_bsAngle, *h_hitX, *h_hitXTecPlus, *h_hitXTecMinus, *h_hitXAt, *h_chi2, *h_chi2ndof, *h_pull, *h_res,
181 TH2F *h_bsAngleVsBeam, *h_hitXvsZTecPlus, *h_hitXvsZTecMinus, *h_hitXvsZAt, *
h_resVsZTecPlus, *h_resVsZTecMinus,
182 *h_resVsZAt, *h_resVsHitTecPlus, *h_resVsHitTecMinus, *h_resVsHitAt;
214 fitBeamSplitters_(iConfig.getParameter<
bool>(
"fitBeamSplitters")),
215 nAtParameters_(iConfig.getParameter<unsigned
int>(
"numberOfFittedAtParameters")),
218 h_hitXTecPlus(nullptr),
219 h_hitXTecMinus(nullptr),
225 h_resTecPlus(nullptr),
226 h_resTecMinus(nullptr),
228 h_bsAngleVsBeam(nullptr),
229 h_hitXvsZTecPlus(nullptr),
230 h_hitXvsZTecMinus(nullptr),
231 h_hitXvsZAt(nullptr),
232 h_resVsZTecPlus(nullptr),
233 h_resVsZTecMinus(nullptr),
235 h_resVsHitTecPlus(nullptr),
236 h_resVsHitTecMinus(nullptr),
237 h_resVsHitAt(nullptr) {
239 this->produces<TkFittedLasBeamCollection, edm::Transition::EndRun>();
240 this->produces<TsosVectorCollection, edm::Transition::EndRun>();
274 h_hitX =
fs->
make<TH1F>(
"hitX",
"local x of LAS hits;local x [cm];N", 100, -0.5, 0.5);
275 h_hitXTecPlus =
fs->
make<TH1F>(
"hitXTecPlus",
"local x of LAS hits in TECplus;local x [cm];N", 100, -0.5, 0.5);
276 h_hitXTecMinus =
fs->
make<TH1F>(
"hitXTecMinus",
"local x of LAS hits in TECminus;local x [cm];N", 100, -0.5, 0.5);
277 h_hitXAt =
fs->
make<TH1F>(
"hitXAt",
"local x of LAS hits in ATs;local x [cm];N", 100, -2.5, 2.5);
279 fs->
make<TH2F>(
"hitXvsZTecPlus",
"local x vs z in TECplus;z [cm];local x [cm]", 80, 120, 280, 100, -0.5, 0.5);
281 fs->
make<TH2F>(
"hitXvsZTecMinus",
"local x vs z in TECMinus;z [cm];local x [cm]", 80, -280, -120, 100, -0.5, 0.5);
282 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);
283 h_chi2 =
fs->
make<TH1F>(
"chi2",
"#chi^{2};#chi^{2};N", 100, 0, 2000);
284 h_chi2ndof =
fs->
make<TH1F>(
"chi2ndof",
"#chi^{2} per degree of freedom;#chi^{2}/N_{dof};N", 100, 0, 300);
285 h_pull =
fs->
make<TH1F>(
"pull",
"pulls of #phi residuals;pull;N", 50, -10, 10);
286 h_res =
fs->
make<TH1F>(
"res",
"#phi residuals;#phi_{track} - #phi_{hit} [rad];N", 60, -0.0015, 0.0015);
288 fs->
make<TH1F>(
"resTecPlus",
"#phi residuals in TECplus;#phi_{track} - #phi_{hit} [rad];N", 30, -0.0015, 0.0015);
290 "resTecMinus",
"#phi residuals in TECminus;#phi_{track} - #phi_{hit} [rad];N", 60, -0.0015, 0.0015);
291 h_resAt =
fs->
make<TH1F>(
"resAt",
"#phi residuals in ATs;#phi_{track} - #phi_{hit} [rad];N", 30, -0.0015, 0.0015);
293 "phi residuals vs. z in TECplus;z [cm];#phi_{track} - #phi_{hit} [rad]",
301 "phi residuals vs. z in TECminus;z [cm];#phi_{track} - #phi_{hit} [rad]",
309 "resVsZAt",
"#phi residuals vs. z in ATs;N;#phi_{track} - #phi_{hit} [rad]", 200, -200, 200, 100, -0.0015, 0.0015);
311 "#phi residuals vs. hits in TECplus;hit no.;#phi_{track} - #phi_{hit} [rad]",
319 "#phi residuals vs. hits in TECminus;hit no.;#phi_{track} - #phi_{hit} [rad]",
327 "#phi residuals vs. hits in ATs;hit no.;#phi_{track} - #phi_{hit} [rad]",
334 h_bsAngle =
fs->
make<TH1F>(
"bsAngle",
"fitted beam splitter angle;BS angle [rad];N", 40, -0.004, 0.004);
336 "bsAngleVsBeam",
"fitted beam splitter angle per beam;Beam no.;BS angle [rad]", 40, 0, 300, 100, -0.004, 0.004);
340 auto fittedBeams = std::make_unique<TkFittedLasBeamCollection>();
342 auto tsosesVec = std::make_unique<TsosVectorCollection>();
345 run.getByLabel(
"LaserAlignment",
"tkLaserBeams",
laserBeams);
359 double bsParams[40] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
360 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
363 unsigned int beamNo(0);
367 cout <<
"Fitting BS!" << endl;
369 cout <<
"BS fixed, not fitted!" << endl;
372 for (TkLasBeamCollection::const_iterator iBeam =
laserBeams->begin(), iEnd =
laserBeams->end(); iBeam != iEnd;
375 vector<TrajectoryStateOnSurface> tsosLas;
384 fittedBeams->push_back(
beam);
385 tsosesVec->push_back(tsosLas);
406 cout <<
"---------------------------------------" << endl;
407 cout <<
"beam id: " <<
beam.getBeamId()
408 <<
" isTec+: " << (
beam.isTecInternal(1) ?
"Y" :
"N") <<
" isTec-: " << (
beam.isTecInternal(-1) ?
"Y" :
"N")
409 <<
" isAt: " << (
beam.isAlignmentTube() ?
"Y" :
"N") <<
" isR6: " << (
beam.isRing6() ?
"Y" :
"N") << endl;
420 vector<const GeomDetUnit *> gd;
421 vector<GlobalPoint> globHit;
422 unsigned int hitsAtTecPlus(0);
432 sumZ += globHit.back().z();
437 if (
beam.isTecInternal(1)) {
442 else if (
beam.isTecInternal(-1)) {
453 gBeamZ0 = sumZ / globHit.size();
456 if (
beam.isTecInternal(1)) {
462 else if (
beam.isTecInternal(-1)) {
475 vector<double> hitPhi, hitPhiError, hitZprimeError;
477 for (
unsigned int hit = 0;
hit < globHit.size(); ++
hit) {
478 hitPhi.push_back(static_cast<double>(globHit[
hit].
phi()));
480 hitPhiError.push_back(0.003 / globHit[
hit].
perp());
482 hitZprimeError.push_back(0.0);
484 if (
beam.isAlignmentTube() &&
abs(globHit[
hit].
z()) < 112.3) {
502 unsigned int tecParams(3), atParams(0);
509 unsigned int nFitParams(0);
511 tecParams = tecParams - 1;
512 atParams = atParams - 1;
514 if (
beam.isTecInternal()) {
515 nFitParams = tecParams;
517 nFitParams = atParams;
521 double offset(0.), offsetError(0.),
slope(0.), slopeError(0.), bsAngleParam(0.), phiAtMinusParam(0.),
522 phiAtPlusParam(0.), atThetaSplitParam(0.);
548 vector<GlobalPoint> globPtrack;
554 double trackPhi(0.), trackPhiRef(0.);
569 <<
" r = " << globHit[
hit].perp() << endl;
574 const double phiResidual = globPtrack[
hit].phi() - globHit[
hit].phi();
576 const double phiResidualPull = phiResidual / hitPhiError[
hit];
581 chi2 += phiResidual * phiResidual / (hitPhiError[
hit] * hitPhiError[
hit]);
584 h_res->Fill(phiResidual);
586 if (
beam.isTecInternal(1)) {
587 h_pull->Fill(phiResidualPull);
591 if (
beam.isRing6()) {
600 else if (
beam.isTecInternal(-1)) {
601 h_pull->Fill(phiResidualPull);
605 if (
beam.isRing6()) {
615 h_pull->Fill(phiResidualPull);
627 cout <<
"bsAngleParam = " << bsAngleParam << endl;
633 if (bsAngleParam != 0.0) {
634 h_bsAngle->Fill(2.0 * atan(0.5 * bsAngleParam));
642 vector<const GeomDetUnit *> &gd,
643 vector<GlobalPoint> &globHit,
644 unsigned int &hitsAtTecPlus) {
646 gd.push_back(
geometry->idToDetUnit(
hit.getDetId()));
650 globHit.push_back(globPtemp);
652 if (
beam.isAlignmentTube()) {
653 if (
abs(globPtemp.
z()) > 112.3) {
654 if (globPtemp.
z() < 112.3)
667 return par[0] + par[1] *
z;
682 return par[0] + par[1] *
z;
697 return par[0] + par[1] *
z;
704 return par[0] + par[1] *
z +
gTOBparam * (par[2] + par[4]);
708 return par[0] + par[1] *
z -
gTIBparam * (par[2] - par[4]);
716 return par[0] + par[1] *
z +
gTOBparam * (par[3] - par[4]);
720 return par[0] + par[1] *
z -
gTIBparam * (par[3] + par[4]);
737 unsigned int &hitsAtTecPlus,
738 unsigned int &nFitParams,
739 vector<double> &hitPhi,
740 vector<double> &hitPhiError,
741 vector<double> &hitZprimeError,
744 double &bsAngleParam,
749 double &phiAtMinusParam,
750 double &phiAtPlusParam,
751 double &atThetaSplitParam) {
752 TGraphErrors *lasData =
753 new TGraphErrors(
gHitZprime.size(), &(
gHitZprime[0]), &(hitPhi[0]), &(hitZprimeError[0]), &(hitPhiError[0]));
756 if (
beam.isTecInternal(1)) {
758 tecPlus.SetParameter(1, 0);
759 tecPlus.SetParameter(nFitParams - 1, 0);
760 lasData->Fit(&tecPlus,
"R");
761 }
else if (
beam.isTecInternal(-1)) {
763 tecMinus.SetParameter(1, 0);
764 tecMinus.SetParameter(nFitParams - 1, 0);
765 lasData->Fit(&tecMinus,
"R");
768 at.SetParameter(1, 0);
769 at.SetParameter(nFitParams - 1, 0);
770 lasData->Fit(&at,
"R");
774 gMinuit->GetParameter(0,
offset, offsetError);
775 gMinuit->GetParameter(1,
slope, slopeError);
779 double bsAngleParamError(0.), phiAtMinusParamError(0.), phiAtPlusParamError(0.), atThetaSplitParamError(0.);
781 if (
beam.isAlignmentTube()) {
782 gMinuit->GetParameter(2, phiAtMinusParam, phiAtMinusParamError);
783 gMinuit->GetParameter(3, phiAtPlusParam, phiAtPlusParamError);
784 gMinuit->GetParameter(4, atThetaSplitParam, atThetaSplitParamError);
788 if (
beam.isAlignmentTube() && hitsAtTecPlus == 0) {
791 gMinuit->GetParameter(nFitParams - 1, bsAngleParam, bsAngleParamError);
798 vector<double> vec(covMatrix.num_col() * covMatrix.num_col());
799 gMinuit->mnemat(&vec[0], covMatrix.num_col());
800 for (
int col = 0;
col < covMatrix.num_col();
col++) {
801 for (
int row = 0; row < covMatrix.num_col(); row++) {
802 covMatrix[
col][row] = vec[row + covMatrix.num_col() *
col];
818 double &bsAngleParam,
819 double &phiAtMinusParam,
820 double &phiAtPlusParam,
821 double &atThetaSplitParam,
822 vector<GlobalPoint> &globHit) {
824 if (
beam.isTecInternal(1)) {
835 else if (
beam.isTecInternal(-1)) {
882 unsigned int &hitsAtTecPlus,
885 vector<GlobalPoint> &globHit,
886 vector<GlobalPoint> &globPtrack,
888 vector<double> &hitPhiError) {
890 if (
beam.isTecInternal(0)) {
917 vector<const GeomDetUnit *> &gd,
918 vector<GlobalPoint> &globPtrack,
919 vector<TrajectoryStateOnSurface> &tsosLas,
925 if (
beam.isTecInternal(1)) {
929 else if (
beam.isTecInternal(-1)) {
955 unsigned int &hitsAtTecPlus,
956 unsigned int &nFitParams,
959 vector<GlobalPoint> &globPtrack,
960 double &bsAngleParam,
963 unsigned int paramType(0);
966 if (
beam.isAlignmentTube() && hitsAtTecPlus == 0)
971 const unsigned int nPedeParams(nFitParams);
974 std::vector<TkFittedLasBeam::Scalar>
params(nPedeParams);
984 derivatives[
hit][0] = 1.0;
988 if (
beam.isTecInternal(1)) {
989 derivatives[
hit][1] = globPtrack[
hit].z();
998 else if (
beam.isTecInternal(-1)) {
999 derivatives[
hit][1] = globPtrack[
hit].z();
1011 derivatives[
hit][1] = globPtrack[
hit].z();
1018 derivatives[
hit][1] = globPtrack[
hit].z();
1033 unsigned int firstFixedParam(covMatrix.num_col());
1038 beam.setParameters(paramType,
params, covMatrix, derivatives, firstFixedParam,
chi2);