52 #include "TGraphErrors.h" 79 void getLasBeams(
TkFittedLasBeam &beam,vector<TrajectoryStateOnSurface> &tsosLas);
81 vector<const GeomDetUnit*> &gd, vector<GlobalPoint> &globHit,
82 unsigned int &hitsAtTecPlus);
87 static double tecPlusFunction(
double *
x,
double *par);
88 static double tecMinusFunction(
double *x,
double *par);
89 static double atFunction(
double *x,
double *par);
92 unsigned int &hitsAtTecPlus,
unsigned int &nFitParams,
93 std::vector<double> &hitPhi, std::vector<double> &hitPhiError, std::vector<double> &hitZprimeError,
94 double &
zMin,
double &
zMax,
double &bsAngleParam,
95 double &
offset,
double &offsetError,
double &
slope,
double &slopeError,
96 double &phiAtMinusParam,
double &phiAtPlusParam,
97 double &atThetaSplitParam);
100 double &
trackPhi,
double &trackPhiRef,
101 double &offset,
double &slope,
double &bsAngleParam,
102 double &phiAtMinusParam,
double &phiAtPlusParam,
103 double &atThetaSplitParam, std::vector<GlobalPoint> &globHit);
106 unsigned int &hit,
unsigned int &hitsAtTecPlus,
107 double &trackPhi,
double &trackPhiRef,
108 std::vector<GlobalPoint> &globHit, std::vector<GlobalPoint> &globPtrack,
109 GlobalPoint &globPref, std::vector<double> &hitPhiError);
112 vector<const GeomDetUnit*> &gd, std::vector<GlobalPoint> &globPtrack,
113 vector<TrajectoryStateOnSurface> &tsosLas,
GlobalPoint &globPref);
116 unsigned int &hitsAtTecPlus,
unsigned int &nFitParams,
117 double &offset,
double &slope, vector<GlobalPoint> &globPtrack,
118 double &bsAngleParam,
double &
chi2);
142 TH1F *h_bsAngle, *h_hitX, *h_hitXTecPlus, *h_hitXTecMinus,
143 *h_hitXAt, *h_chi2, *h_chi2ndof, *h_pull, *h_res,
145 TH2F *h_bsAngleVsBeam, *h_hitXvsZTecPlus, *h_hitXvsZTecMinus,
147 *h_resVsHitTecPlus, *h_resVsHitTecMinus, *h_resVsHitAt;
183 fitBeamSplitters_(iConfig.getParameter<bool>(
"fitBeamSplitters")),
184 nAtParameters_(iConfig.getParameter<unsigned
int>(
"numberOfFittedAtParameters")),
185 h_bsAngle(0), h_hitX(0), h_hitXTecPlus(0), h_hitXTecMinus(0),
186 h_hitXAt(0), h_chi2(0), h_chi2ndof(0), h_pull(0), h_res(0),
187 h_resTecPlus(0), h_resTecMinus(0), h_resAt(0),
188 h_bsAngleVsBeam(0), h_hitXvsZTecPlus(0), h_hitXvsZTecMinus(0),
189 h_hitXvsZAt(0), h_resVsZTecPlus(0), h_resVsZTecMinus(0), h_resVsZAt(0),
190 h_resVsHitTecPlus(0), h_resVsHitTecMinus(0), h_resVsHitAt(0)
193 this->produces<TkFittedLasBeamCollection, edm::Transition::EndRun>();
194 this->produces<TsosVectorCollection, edm::Transition::EndRun>();
234 h_hitX =
fs->
make<TH1F>(
"hitX",
"local x of LAS hits;local x [cm];N",100,-0.5,0.5);
235 h_hitXTecPlus =
fs->
make<TH1F>(
"hitXTecPlus",
"local x of LAS hits in TECplus;local x [cm];N",100,-0.5,0.5);
236 h_hitXTecMinus =
fs->
make<TH1F>(
"hitXTecMinus",
"local x of LAS hits in TECminus;local x [cm];N",100,-0.5,0.5);
237 h_hitXAt =
fs->
make<TH1F>(
"hitXAt",
"local x of LAS hits in ATs;local x [cm];N",100,-2.5,2.5);
238 h_hitXvsZTecPlus =
fs->
make<TH2F>(
"hitXvsZTecPlus",
"local x vs z in TECplus;z [cm];local x [cm]",80,120,280,100,-0.5,0.5);
239 h_hitXvsZTecMinus =
fs->
make<TH2F>(
"hitXvsZTecMinus",
"local x vs z in TECMinus;z [cm];local x [cm]",80,-280,-120,100,-0.5,0.5);
240 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);
241 h_chi2 =
fs->
make<TH1F>(
"chi2",
"#chi^{2};#chi^{2};N",100,0,2000);
242 h_chi2ndof =
fs->
make<TH1F>(
"chi2ndof",
"#chi^{2} per degree of freedom;#chi^{2}/N_{dof};N",100,0,300);
243 h_pull =
fs->
make<TH1F>(
"pull",
"pulls of #phi residuals;pull;N",50,-10,10);
244 h_res =
fs->
make<TH1F>(
"res",
"#phi residuals;#phi_{track} - #phi_{hit} [rad];N",60,-0.0015,0.0015);
245 h_resTecPlus =
fs->
make<TH1F>(
"resTecPlus",
"#phi residuals in TECplus;#phi_{track} - #phi_{hit} [rad];N",30,-0.0015,0.0015);
246 h_resTecMinus =
fs->
make<TH1F>(
"resTecMinus",
"#phi residuals in TECminus;#phi_{track} - #phi_{hit} [rad];N",60,-0.0015,0.0015);
247 h_resAt =
fs->
make<TH1F>(
"resAt",
"#phi residuals in ATs;#phi_{track} - #phi_{hit} [rad];N",30,-0.0015,0.0015);
248 h_resVsZTecPlus =
fs->
make<TH2F>(
"resVsZTecPlus",
"phi residuals vs. z in TECplus;z [cm];#phi_{track} - #phi_{hit} [rad]",
249 80,120,280,100,-0.0015,0.0015);
250 h_resVsZTecMinus =
fs->
make<TH2F>(
"resVsZTecMinus",
"phi residuals vs. z in TECminus;z [cm];#phi_{track} - #phi_{hit} [rad]",
251 80,-280,-120,100,-0.0015,0.0015);
252 h_resVsZAt =
fs->
make<TH2F>(
"resVsZAt",
"#phi residuals vs. z in ATs;N;#phi_{track} - #phi_{hit} [rad]",
253 200,-200,200,100,-0.0015,0.0015);
254 h_resVsHitTecPlus =
fs->
make<TH2F>(
"resVsHitTecPlus",
"#phi residuals vs. hits in TECplus;hit no.;#phi_{track} - #phi_{hit} [rad]",
255 144,0,144,100,-0.0015,0.0015);
256 h_resVsHitTecMinus =
fs->
make<TH2F>(
"resVsHitTecMinus",
"#phi residuals vs. hits in TECminus;hit no.;#phi_{track} - #phi_{hit} [rad]",
257 144,0,144,100,-0.0015,0.0015);
258 h_resVsHitAt =
fs->
make<TH2F>(
"resVsHitAt",
"#phi residuals vs. hits in ATs;hit no.;#phi_{track} - #phi_{hit} [rad]",
259 176,0,176,100,-0.0015,0.0015);
260 h_bsAngle =
fs->
make<TH1F>(
"bsAngle",
"fitted beam splitter angle;BS angle [rad];N",40,-0.004,0.004);
261 h_bsAngleVsBeam =
fs->
make<TH2F>(
"bsAngleVsBeam",
"fitted beam splitter angle per beam;Beam no.;BS angle [rad]",
262 40,0,300,100,-0.004,0.004);
266 auto fittedBeams = std::make_unique<TkFittedLasBeamCollection>();
268 auto tsosesVec = std::make_unique<TsosVectorCollection>();
271 run.
getByLabel(
"LaserAlignment",
"tkLaserBeams", laserBeams );
285 double bsParams[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
286 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
289 unsigned int beamNo(0);
293 else cout <<
"BS fixed, not fitted!" << endl;
296 for(TkLasBeamCollection::const_iterator iBeam = laserBeams->begin(), iEnd = laserBeams->end();
297 iBeam != iEnd; ++iBeam){
300 vector<TrajectoryStateOnSurface> tsosLas;
309 fittedBeams->push_back(beam);
310 tsosesVec->push_back(tsosLas);
332 cout <<
"---------------------------------------" << endl;
347 vector<const GeomDetUnit*> gd;
348 vector<GlobalPoint> globHit;
349 unsigned int hitsAtTecPlus(0);
358 this->
getLasHits(beam, hit, gd, globHit, hitsAtTecPlus);
359 sumZ += globHit.back().z();
380 gBeamZ0 = sumZ / globHit.size();
402 vector<double> hitPhi, hitPhiError, hitZprimeError;
404 for(
unsigned int hit = 0;
hit < globHit.size(); ++
hit){
405 hitPhi.push_back(static_cast<double>(globHit[
hit].
phi()));
407 hitPhiError.push_back( 0.003 / globHit[
hit].
perp());
409 hitZprimeError.push_back(0.0);
430 unsigned int tecParams(3), atParams(0);
434 unsigned int nFitParams(0);
437 tecParams = tecParams - 1;
438 atParams = atParams - 1;
441 nFitParams = tecParams;
444 nFitParams = atParams;
448 double offset(0.), offsetError(0.),
slope(0.), slopeError(0.),
449 bsAngleParam(0.), phiAtMinusParam(0.), phiAtPlusParam(0.),
450 atThetaSplitParam(0.);
459 this->
fitter(beam, covMatrix,
460 hitsAtTecPlus, nFitParams,
461 hitPhi, hitPhiError, hitZprimeError,
462 zMin, zMax, bsAngleParam,
464 phiAtMinusParam, phiAtPlusParam,
467 vector<GlobalPoint> globPtrack;
474 double trackPhi(0.), trackPhiRef(0.);
478 phiAtMinusParam, phiAtPlusParam,
479 atThetaSplitParam, globHit);
482 <<
", hit phi = " << hitPhi[
hit]
484 <<
" r = " << globHit[
hit].perp() << endl;
488 globHit, globPtrack, globPref,
492 const double phiResidual = globPtrack[
hit].phi() - globHit[
hit].phi();
494 const double phiResidualPull = phiResidual / hitPhiError[
hit];
499 chi2 += phiResidual*phiResidual / (hitPhiError[
hit]*hitPhiError[
hit]);
502 h_res->Fill(phiResidual);
505 h_pull->Fill(phiResidualPull);
519 h_pull->Fill(phiResidualPull);
533 h_pull->Fill(phiResidualPull);
542 cout <<
"chi^2 = " << chi2 <<
", chi^2/ndof = " << chi2/(
gHitZprime.size() - nFitParams) << endl;
543 this->
fitBeam(beam, covMatrix, hitsAtTecPlus, nFitParams,
546 cout <<
"bsAngleParam = " << bsAngleParam << endl;
552 if(bsAngleParam != 0.0){
553 h_bsAngle->Fill(2.0*atan(0.5*bsAngleParam));
561 vector<const GeomDetUnit*> &gd, vector<GlobalPoint> &globHit,
562 unsigned int &hitsAtTecPlus)
569 globHit.push_back(globPtemp);
572 if(
abs(globPtemp.
z()) > 112.3){
574 else hitsAtTecPlus++ ;
586 return par[0] + par[1] *
z;
605 return par[0] + par[1] *
z;
623 return par[0] + par[1] *
z;
630 return par[0] + par[1] * z +
gTOBparam * (par[2] + par[4]);
634 return par[0] + par[1] * z -
gTIBparam * (par[2] - par[4]);
642 return par[0] + par[1] * z +
gTOBparam * (par[3] - par[4]);
646 return par[0] + par[1] * z -
gTIBparam * (par[3] + par[4]);
664 unsigned int &hitsAtTecPlus,
unsigned int &nFitParams,
665 vector<double> &hitPhi, vector<double> &hitPhiError, vector<double> &hitZprimeError,
666 double &
zMin,
double &
zMax,
double &bsAngleParam,
667 double &
offset,
double &offsetError,
double &
slope,
double &slopeError,
668 double &phiAtMinusParam,
double &phiAtPlusParam,
double &atThetaSplitParam)
670 TGraphErrors *lasData =
new TGraphErrors(
gHitZprime.size(),
672 &(hitZprimeError[0]), &(hitPhiError[0]));
677 tecPlus.SetParameter( 1, 0 );
678 tecPlus.SetParameter( nFitParams - 1, 0 );
679 lasData->Fit(&tecPlus,
"R");
683 tecMinus.SetParameter( 1, 0 );
684 tecMinus.SetParameter( nFitParams - 1, 0 );
685 lasData->Fit(&tecMinus,
"R");
688 TF1 at(
"at",
atFunction, zMin, zMax, nFitParams );
689 at.SetParameter( 1, 0 );
690 at.SetParameter( nFitParams - 1, 0 );
691 lasData->Fit(&at,
"R");
695 gMinuit->GetParameter(0, offset, offsetError);
696 gMinuit->GetParameter(1, slope, slopeError);
700 double bsAngleParamError(0.), phiAtMinusParamError(0.),
701 phiAtPlusParamError(0.), atThetaSplitParamError(0.);
704 gMinuit->GetParameter(2, phiAtMinusParam, phiAtMinusParamError);
705 gMinuit->GetParameter(3, phiAtPlusParam, phiAtPlusParamError);
706 gMinuit->GetParameter(4, atThetaSplitParam, atThetaSplitParamError);
714 gMinuit->GetParameter( nFitParams - 1 , bsAngleParam, bsAngleParamError);
722 vector<double> vec( covMatrix.num_col() * covMatrix.num_col() );
723 gMinuit->mnemat( &vec[0], covMatrix.num_col() );
724 for(
int col = 0;
col < covMatrix.num_col();
col++){
725 for(
int row = 0; row < covMatrix.num_col(); row++){
726 covMatrix[
col][row] = vec[row + covMatrix.num_col()*
col];
738 double &
trackPhi,
double &trackPhiRef,
739 double &
offset,
double &
slope,
double &bsAngleParam,
740 double &phiAtMinusParam,
double &phiAtPlusParam,
741 double &atThetaSplitParam, vector<GlobalPoint> &globHit)
747 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
752 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0)
760 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
765 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0)
774 trackPhiRef = offset + slope * (gHitZprime[hit] + 1.0);
779 trackPhi = offset + slope *
gHitZprime[hit] +
gTOBparam * (phiAtMinusParam + atThetaSplitParam);
782 trackPhi = offset + slope *
gHitZprime[hit] -
gTIBparam * (phiAtMinusParam - atThetaSplitParam);
789 trackPhi = offset + slope *
gHitZprime[hit] +
gTOBparam * (phiAtPlusParam - atThetaSplitParam);
792 trackPhi = offset + slope *
gHitZprime[hit] -
gTIBparam * (phiAtPlusParam + atThetaSplitParam);
800 trackPhiRef = offset + slope * (
gHitZprime[hit] + 1.0)
809 unsigned int &
hit,
unsigned int &hitsAtTecPlus,
810 double &
trackPhi,
double &trackPhiRef,
811 vector<GlobalPoint> &globHit, vector<GlobalPoint> &globPtrack,
812 GlobalPoint &globPref, vector<double> &hitPhiError)
827 else if(hit >
gHitZprime.size() - hitsAtTecPlus - 1){
842 vector<const GeomDetUnit*> &gd, vector<GlobalPoint> &globPtrack,
843 vector<TrajectoryStateOnSurface> &tsosLas,
GlobalPoint &globPref)
850 trajectoryState =
GlobalVector(globPref-globPtrack[hit]);
854 trajectoryState =
GlobalVector(globPtrack[hit]-globPref);
860 trajectoryState =
GlobalVector(globPtrack[hit]-globPref);
864 trajectoryState =
GlobalVector(globPref-globPtrack[hit]);
868 trajectoryState =
GlobalVector(globPtrack[hit]-globPref);
880 unsigned int &hitsAtTecPlus,
unsigned int &nFitParams,
881 double &
offset,
double &
slope, vector<GlobalPoint> &globPtrack,
882 double &bsAngleParam,
double &
chi2)
885 unsigned int paramType(0);
891 const unsigned int nPedeParams(nFitParams);
894 std::vector<TkFittedLasBeam::Scalar> params(nPedeParams);
905 derivatives[
hit][0] = 1.0;
910 derivatives[
hit][1] = globPtrack[
hit].z();
920 derivatives[
hit][1] = globPtrack[
hit].z();
932 derivatives[
hit][1] = globPtrack[
hit].z();
939 derivatives[
hit][1] = globPtrack[
hit].z();
954 unsigned int firstFixedParam(covMatrix.num_col());
959 beam.
setParameters(paramType, params, covMatrix, derivatives, firstFixedParam, chi2);
ESHandle< MagneticField > fieldHandle
static vector< double > gHitZprime
bool getByLabel(std::string const &label, Handle< PROD > &result) const
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)
def setup(process, global_tag, zero_tesla=False)
static vector< double > gBarrelModuleRadius
T * make(const Args &...args) const
make new ROOT object
virtual LocalPoint localPosition() const
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
T x() const
Cartesian x coordinate.
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
static bool gIsInnerBarrel
virtual 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
virtual 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.
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)