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;
213 src_(iConfig.getParameter<edm::
InputTag>(
"src")),
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>();
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;
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);
431 this->
getLasHits(beam, hit, gd, globHit, hitsAtTecPlus);
432 sumZ += globHit.back().z();
453 gBeamZ0 = sumZ / globHit.size();
454 double zMin(0.), zMax(0.);
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);
502 unsigned int tecParams(3), atParams(0);
509 unsigned int nFitParams(0);
511 tecParams = tecParams - 1;
512 atParams = atParams - 1;
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);
587 h_pull->Fill(phiResidualPull);
601 h_pull->Fill(phiResidualPull);
615 h_pull->Fill(phiResidualPull);
624 cout <<
"chi^2 = " << chi2 <<
", chi^2/ndof = " << chi2 / (
gHitZprime.size() - nFitParams) << endl;
625 this->
fitBeam(beam, covMatrix, hitsAtTecPlus, nFitParams,
offset,
slope, globPtrack, bsAngleParam, chi2);
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) {
650 globHit.push_back(globPtemp);
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]));
758 tecPlus.SetParameter(1, 0);
759 tecPlus.SetParameter(nFitParams - 1, 0);
760 lasData->Fit(&tecPlus,
"R");
763 tecMinus.SetParameter(1, 0);
764 tecMinus.SetParameter(nFitParams - 1, 0);
765 lasData->Fit(&tecMinus,
"R");
767 TF1 at(
"at",
atFunction, zMin, zMax, nFitParams);
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.);
782 gMinuit->GetParameter(2, phiAtMinusParam, phiAtMinusParamError);
783 gMinuit->GetParameter(3, phiAtPlusParam, phiAtPlusParamError);
784 gMinuit->GetParameter(4, atThetaSplitParam, atThetaSplitParamError);
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) {
827 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
830 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0) -
838 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
841 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0) +
850 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
855 trackPhi = offset + slope *
gHitZprime[hit] +
gTOBparam * (phiAtMinusParam + atThetaSplitParam);
857 trackPhi = offset + slope *
gHitZprime[hit] -
gTIBparam * (phiAtMinusParam - atThetaSplitParam);
864 trackPhi = offset + slope *
gHitZprime[hit] +
gTOBparam * (phiAtPlusParam - atThetaSplitParam);
866 trackPhi = offset + slope *
gHitZprime[hit] -
gTIBparam * (phiAtPlusParam + atThetaSplitParam);
873 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0) -
882 unsigned int &hitsAtTecPlus,
885 vector<GlobalPoint> &globHit,
886 vector<GlobalPoint> &globPtrack,
888 vector<double> &hitPhiError) {
902 else if (hit >
gHitZprime.size() - hitsAtTecPlus - 1) {
917 vector<const GeomDetUnit *> &gd,
918 vector<GlobalPoint> &globPtrack,
919 vector<TrajectoryStateOnSurface> &tsosLas,
926 trajectoryState =
GlobalVector(globPref - globPtrack[hit]);
930 trajectoryState =
GlobalVector(globPtrack[hit] - globPref);
936 trajectoryState =
GlobalVector(globPtrack[hit] - globPref);
940 trajectoryState =
GlobalVector(globPref - globPtrack[hit]);
944 trajectoryState =
GlobalVector(globPtrack[hit] - globPref);
955 unsigned int &hitsAtTecPlus,
956 unsigned int &nFitParams,
959 vector<GlobalPoint> &globPtrack,
960 double &bsAngleParam,
963 unsigned int paramType(0);
971 const unsigned int nPedeParams(nFitParams);
974 std::vector<TkFittedLasBeam::Scalar>
params(nPedeParams);
984 derivatives[
hit][0] = 1.0;
989 derivatives[
hit][1] = globPtrack[
hit].z();
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);
static vector< double > gHitZprime
~TkLasBeamFitter() override
bool getByLabel(std::string const &label, Handle< PROD > &result) const
LocalPoint localPosition() const override
static double tecMinusFunction(double *x, double *par)
static double tecPlusFunction(double *x, double *par)
#define DEFINE_FWK_MODULE(type)
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-...
edm::ESHandle< MagneticField > fieldHandle
static bool gIsInnerBarrel
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
edm::Handle< TkLasBeamCollection > laserBeams
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 edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
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)
T const * product() const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
void put(std::unique_ptr< PROD > product)
Put a new product.
static vector< double > gBarrelModuleOffset
tuple config
parse the configuration file
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)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
void getLasHits(TkFittedLasBeam &beam, const SiStripLaserRecHit2D &hit, vector< const GeomDetUnit * > &gd, vector< GlobalPoint > &globHit, unsigned int &hitsAtTecPlus)
edm::Service< TFileService > fs
std::vector< SiStripLaserRecHit2D >::const_iterator const_iterator
edm::ESHandle< TrackerGeometry > geometry
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)