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")),
211 h_hitXTecPlus(nullptr),
212 h_hitXTecMinus(nullptr),
218 h_resTecPlus(nullptr),
219 h_resTecMinus(nullptr),
221 h_bsAngleVsBeam(nullptr),
222 h_hitXvsZTecPlus(nullptr),
223 h_hitXvsZTecMinus(nullptr),
224 h_hitXvsZAt(nullptr),
225 h_resVsZTecPlus(nullptr),
226 h_resVsZTecMinus(nullptr),
228 h_resVsHitTecPlus(nullptr),
229 h_resVsHitTecMinus(nullptr),
230 h_resVsHitAt(nullptr) {
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;
400 cout <<
"beam id: " <<
beam.getBeamId()
401 <<
" isTec+: " << (
beam.isTecInternal(1) ?
"Y" :
"N") <<
" isTec-: " << (
beam.isTecInternal(-1) ?
"Y" :
"N")
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);
425 sumZ += globHit.back().z();
430 if (
beam.isTecInternal(1)) {
435 else if (
beam.isTecInternal(-1)) {
446 gBeamZ0 = sumZ / globHit.size();
449 if (
beam.isTecInternal(1)) {
455 else if (
beam.isTecInternal(-1)) {
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);
477 if (
beam.isAlignmentTube() &&
abs(globHit[
hit].
z()) < 112.3) {
495 unsigned int tecParams(3), atParams(0);
502 unsigned int nFitParams(0);
504 tecParams = tecParams - 1;
505 atParams = atParams - 1;
507 if (
beam.isTecInternal()) {
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);
579 if (
beam.isTecInternal(1)) {
580 h_pull->Fill(phiResidualPull);
584 if (
beam.isRing6()) {
593 else if (
beam.isTecInternal(-1)) {
594 h_pull->Fill(phiResidualPull);
598 if (
beam.isRing6()) {
608 h_pull->Fill(phiResidualPull);
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) {
639 gd.push_back(
geometry->idToDetUnit(
hit.getDetId()));
643 globHit.push_back(globPtemp);
645 if (
beam.isAlignmentTube()) {
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]));
749 if (
beam.isTecInternal(1)) {
751 tecPlus.SetParameter(1, 0);
752 tecPlus.SetParameter(nFitParams - 1, 0);
753 lasData->Fit(&tecPlus,
"R");
754 }
else if (
beam.isTecInternal(-1)) {
756 tecMinus.SetParameter(1, 0);
757 tecMinus.SetParameter(nFitParams - 1, 0);
758 lasData->Fit(&tecMinus,
"R");
761 at.SetParameter(1, 0);
762 at.SetParameter(nFitParams - 1, 0);
763 lasData->Fit(&at,
"R");
772 double bsAngleParamError(0.), phiAtMinusParamError(0.), phiAtPlusParamError(0.), atThetaSplitParamError(0.);
774 if (
beam.isAlignmentTube()) {
775 gMinuit->GetParameter(2, phiAtMinusParam, phiAtMinusParamError);
776 gMinuit->GetParameter(3, phiAtPlusParam, phiAtPlusParamError);
777 gMinuit->GetParameter(4, atThetaSplitParam, atThetaSplitParamError);
781 if (
beam.isAlignmentTube() && hitsAtTecPlus == 0) {
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) {
817 if (
beam.isTecInternal(1)) {
828 else if (
beam.isTecInternal(-1)) {
875 unsigned int &hitsAtTecPlus,
878 vector<GlobalPoint> &globHit,
879 vector<GlobalPoint> &globPtrack,
881 vector<double> &hitPhiError) {
883 if (
beam.isTecInternal(0)) {
910 vector<const GeomDetUnit *> &gd,
911 vector<GlobalPoint> &globPtrack,
912 vector<TrajectoryStateOnSurface> &tsosLas,
918 if (
beam.isTecInternal(1)) {
922 else if (
beam.isTecInternal(-1)) {
948 unsigned int &hitsAtTecPlus,
949 unsigned int &nFitParams,
952 vector<GlobalPoint> &globPtrack,
953 double &bsAngleParam,
956 unsigned int paramType(0);
959 if (
beam.isAlignmentTube() && hitsAtTecPlus == 0)
964 const unsigned int nPedeParams(nFitParams);
967 std::vector<TkFittedLasBeam::Scalar>
params(nPedeParams);
977 derivatives[
hit][0] = 1.0;
981 if (
beam.isTecInternal(1)) {
982 derivatives[
hit][1] = globPtrack[
hit].z();
991 else if (
beam.isTecInternal(-1)) {
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);