3 #include "CLHEP/Vector/RotationInterfaces.h" 34 #include "CLHEP/Vector/ThreeVector.h" 44 _levelStrings(cfg.getUntrackedParameter<
std::vector<
std::
string> >(
"levels")),
46 _commonMuonLevel(
align::invalid),
74 fin.open(_detIdFlagFile.c_str());
76 while (!fin.eof() && fin.good()) {
85 unsigned int lastID = 999999999;
88 inFile.open(_weightByIdFile.c_str());
90 while (!inFile.eof()) {
94 inFile.ignore(256,
'\n');
95 if (listId != lastID) {
104 _theFile =
new TFile(_filename.c_str(),
"RECREATE");
105 _alignTree =
new TTree(
"alignTree",
"alignTree");
106 _alignTree->Branch(
"id", &
_id,
"id/I");
107 _alignTree->Branch(
"level", &
_level,
"level/I");
108 _alignTree->Branch(
"mid", &
_mid,
"mid/I");
109 _alignTree->Branch(
"mlevel", &
_mlevel,
"mlevel/I");
110 _alignTree->Branch(
"sublevel", &
_sublevel,
"sublevel/I");
111 _alignTree->Branch(
"x", &
_xVal,
"x/F");
112 _alignTree->Branch(
"y", &
_yVal,
"y/F");
113 _alignTree->Branch(
"z", &
_zVal,
"z/F");
114 _alignTree->Branch(
"r", &
_rVal,
"r/F");
115 _alignTree->Branch(
"phi", &
_phiVal,
"phi/F");
116 _alignTree->Branch(
"eta", &
_etaVal,
"eta/F");
117 _alignTree->Branch(
"alpha", &
_alphaVal,
"alpha/F");
118 _alignTree->Branch(
"beta", &
_betaVal,
"beta/F");
119 _alignTree->Branch(
"gamma", &
_gammaVal,
"gamma/F");
120 _alignTree->Branch(
"dx", &
_dxVal,
"dx/F");
121 _alignTree->Branch(
"dy", &
_dyVal,
"dy/F");
122 _alignTree->Branch(
"dz", &
_dzVal,
"dz/F");
123 _alignTree->Branch(
"dr", &
_drVal,
"dr/F");
124 _alignTree->Branch(
"dphi", &
_dphiVal,
"dphi/F");
125 _alignTree->Branch(
"dalpha", &
_dalphaVal,
"dalpha/F");
126 _alignTree->Branch(
"dbeta", &
_dbetaVal,
"dbeta/F");
127 _alignTree->Branch(
"dgamma", &
_dgammaVal,
"dgamma/F");
128 _alignTree->Branch(
"ldx", &
_ldxVal,
"ldx/F");
129 _alignTree->Branch(
"ldy", &
_ldyVal,
"ldy/F");
130 _alignTree->Branch(
"ldz", &
_ldzVal,
"ldz/F");
131 _alignTree->Branch(
"ldr", &
_ldrVal,
"ldr/F");
132 _alignTree->Branch(
"ldphi", &
_ldphiVal,
"ldphi/F");
133 _alignTree->Branch(
"useDetId", &
_useDetId,
"useDetId/I");
134 _alignTree->Branch(
"detDim", &
_detDim,
"detDim/I");
135 _alignTree->Branch(
"rotx", &
_rotxVal,
"rotx/F");
136 _alignTree->Branch(
"roty", &
_rotyVal,
"roty/F");
137 _alignTree->Branch(
"rotz", &
_rotzVal,
"rotz/F");
138 _alignTree->Branch(
"drotx", &
_drotxVal,
"drotx/F");
139 _alignTree->Branch(
"droty", &
_drotyVal,
"droty/F");
140 _alignTree->Branch(
"drotz", &
_drotzVal,
"drotz/F");
141 _alignTree->Branch(
"surW", &
_surWidth,
"surW/F");
142 _alignTree->Branch(
"surL", &
_surLength,
"surL/F");
143 _alignTree->Branch(
"surRot", &
_surRot,
"surRot[9]/D");
154 std::vector<float> xp(size + 1);
155 std::vector<float> yp(size + 1);
164 TGraph* grx =
nullptr;
168 for (i = 0; i <
size; i++) {
177 xp[
size] = xp[size - 1] + 1;
184 int sizeI = maxI + 1 -
minI;
185 float smi = minI - 1;
186 float sma = maxI + 1;
190 for (i = 0; i <
size; i++) {
207 "Local #delta X vs position",
216 for (i = 0; i <
size; i++) {
233 "Local #delta Y vs position",
243 for (i = 0; i <
size; i++) {
260 "Local #delta Z vs position",
270 for (i = 0; i <
size; i++) {
286 "delphi_vs_position",
287 "#delta #phi vs position",
288 "Gdelphi_vs_position",
289 "#delta #phi in radians",
297 for (i = 0; i <
size; i++) {
314 "#delta R vs position",
324 for (i = 0; i <
size; i++) {
341 "delRphi_vs_position",
342 "R #delta #phi vs position",
343 "GdelRphi_vs_position",
344 "R #delta #phi in cm",
352 for (i = 0; i <
size; i++) {
368 "delalpha_vs_position",
369 "#delta #alpha vs position",
370 "Gdelalpha_vs_position",
371 "#delta #alpha in rad",
379 for (i = 0; i <
size; i++) {
395 "delbeta_vs_position",
396 "#delta #beta vs position",
397 "Gdelbeta_vs_position",
398 "#delta #beta in rad",
406 for (i = 0; i <
size; i++) {
422 "delgamma_vs_position",
423 "#delta #gamma vs position",
424 "Gdelgamma_vs_position",
425 "#delta #gamma in rad",
433 for (i = 0; i <
size; i++) {
449 "delrotX_vs_position",
450 "#delta rotX vs position",
451 "GdelrotX_vs_position",
452 "#delta rotX in rad",
460 for (i = 0; i <
size; i++) {
476 "delrotY_vs_position",
477 "#delta rotY vs position",
478 "GdelrotY_vs_position",
479 "#delta rotY in rad",
487 for (i = 0; i <
size; i++) {
503 "delrotZ_vs_position",
504 "#delta rotZ vs position",
505 "GdelrotZ_vs_position",
506 "#delta rotZ in rad",
516 float maxR = -9999999.;
517 for (i = 0; i <
size; i++) {
527 float smallestVcm = .001;
528 if (maxV < smallestVcm)
531 float lside = 1.1 * maxR;
535 scale = .09 * lside / maxV;
538 int ret = snprintf(scalename, 50,
"#delta #bar{x} length =%f cm", maxV);
542 dxh =
new TH2F(
"vecdrplot", scalename, 80, -lside, lside, 80, -lside, lside);
544 dxh =
new TH2F(
"vecdrplot",
"delta #bar{x} Bad scale", 80, -lside, lside, 80, -lside, lside);
546 dxh->GetXaxis()->SetTitle(
"x in cm");
547 dxh->GetYaxis()->SetTitle(
"y in cm");
548 dxh->SetStats(kFALSE);
551 for (i = 0; i <
size; i++) {
557 arrow->SetLineWidth(2);
558 arrow->SetArrowSize(ttemp * .2 * .05 / maxV);
559 arrow->SetLineColor(1);
560 arrow->SetLineStyle(1);
562 dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
586 if (minV >= maxV || smi >= sma || sizeI <= 1 || xp ==
nullptr || yp ==
nullptr)
589 float diff = maxV - minV;
590 float over = .05 *
diff;
591 double ylo = minV - over;
592 double yhi = maxV + over;
596 dxh =
new TH2F(name, title, sizeI + 2, dsmi, dsma, 50, ylo, yhi);
597 dxh->GetXaxis()->SetTitle(
"Position around ring");
598 dxh->GetYaxis()->SetTitle(axis);
599 dxh->SetStats(kFALSE);
601 grx =
new TGraph(size, xp, yp);
602 grx->SetName(titleg);
603 grx->SetTitle(title);
604 grx->SetMarkerColor(2);
605 grx->SetMarkerStyle(3);
606 grx->GetXaxis()->SetLimits(dsmi, dsma);
607 grx->GetXaxis()->SetTitle(
"position number");
608 grx->GetYaxis()->SetLimits(ylo, yhi);
609 grx->GetYaxis()->SetTitle(axis);
640 theLevels.push_back(inputGeometry2Copy2->objectIdProvider().stringToId(
level));
661 if (refAli ==
nullptr) {
664 if (curAli ==
nullptr) {
670 const auto& curComp2 = curAliCopy2->
components();
673 int nComp = refComp.size();
674 for (
int i = 0;
i < nComp;
i++) {
675 compare(refComp[
i], curComp[i], curComp2[i]);
683 if (refAli ==
nullptr) {
686 if (curAli ==
nullptr) {
700 if (refComp.size() != curComp.size()) {
709 int nComp = refComp.size();
712 CLHEP::Hep3Vector TotalX, TotalL;
713 TotalX.set(0., 0., 0.);
714 TotalL.set(0., 0., 0.);
716 std::vector<CLHEP::Hep3Vector> Positions;
717 std::vector<CLHEP::Hep3Vector> DelPositions;
719 double xrcenter = 0.;
720 double yrcenter = 0.;
721 double zrcenter = 0.;
722 double xccenter = 0.;
723 double yccenter = 0.;
724 double zccenter = 0.;
729 for (
int ich = 0; ich < nComp; ich++) {
740 originalVectors.push_back(pointsCM);
742 xrcenter += pointsCM.
x();
743 yrcenter += pointsCM.
y();
744 zrcenter += pointsCM.
z();
746 xrcenter = xrcenter / nUsed;
747 yrcenter = yrcenter / nUsed;
748 zrcenter = zrcenter / nUsed;
752 for (
int ich = 0; ich < nComp; ich++) {
763 currentVectors.push_back(pointsCM);
765 xccenter += pointsCM.
x();
766 yccenter += pointsCM.
y();
767 zccenter += pointsCM.
z();
769 xccenter = xccenter / nUsed;
770 yccenter = yccenter / nUsed;
771 zccenter = zccenter / nUsed;
776 int nCompR = currentVectors.size();
777 for (
int ich = 0; ich < nCompR; ich++) {
778 originalRelativeVectors.push_back(originalVectors[ich] - CRef);
779 currentRelativeVectors.push_back(currentVectors[ich] - CCur);
791 for (
int ich = 0; ich < nComp; ich++) {
796 CLHEP::Hep3Vector Rtotal, Wtotal;
797 Rtotal.set(0., 0., 0.);
798 Wtotal.set(0., 0., 0.);
799 for (
int i = 0;
i < 100;
i++) {
802 CLHEP::Hep3Vector
dR(diff[0], diff[1], diff[2]);
804 CLHEP::Hep3Vector dW(diff[3], diff[4], diff[5]);
805 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
806 CLHEP::HepRotation drot(dW.unit(), dW.mag());
808 Wtotal.set(rot.axis().x() * rot.delta(), rot.axis().y() * rot.delta(), rot.axis().z() * rot.delta());
815 DetId detid(refComp[ich]->
id());
829 TotalX = TotalX / nUsed;
833 change(1) = TotalX.x();
834 change(2) = TotalX.y();
835 change(3) = TotalX.z();
837 change(4) = angles[0];
838 change(5) = angles[1];
839 change(6) = angles[2];
845 for (
int ich = 0; ich < nComp; ich++) {
846 CLHEP::Hep3Vector Rtotal, Wtotal;
847 Rtotal.set(0., 0., 0.);
848 Wtotal.set(0., 0., 0.);
854 for (
int i = 0;
i < 100;
i++) {
857 CLHEP::Hep3Vector
dR(diff[0], diff[1], diff[2]);
859 CLHEP::Hep3Vector dW(diff[3], diff[4], diff[5]);
860 CLHEP::HepRotation
rot(Wtotal.unit(), Wtotal.mag());
861 CLHEP::HepRotation drot(dW.unit(), dW.mag());
863 Wtotal.set(rot.axis().x() * rot.delta(), rot.axis().y() * rot.delta(), rot.axis().z() * rot.delta());
876 TRtot(1) = Rtotal.x();
877 TRtot(2) = Rtotal.y();
878 TRtot(3) = Rtotal.z();
879 TRtot(4) = Wtotal.x();
880 TRtot(5) = Wtotal.y();
881 TRtot(6) = Wtotal.z();
901 int ringPhiPos = -99;
916 float ttt = -rot.
xz();
947 double xx = rot.
xx();
948 double xy = rot.
xy();
949 double xz = rot.
xz();
950 double yx = rot.
yx();
951 double yy = rot.
yy();
952 double yz = rot.
yz();
953 double zx = rot.
zx();
954 double zy = rot.
zy();
955 double zz = rot.
zz();
956 double detrot = (zz * yy - zy *
yz) * xx + (-zz * yx + zx * yz) * xy + (zy * yx - zx *
yy) * xz;
958 double ixx = (zz * yy - zy *
yz) * detrot;
959 double ixy = (-zz * xy + zy *
xz) * detrot;
960 double ixz = (yz * xy - yy *
xz) * detrot;
961 double iyx = (-zz * yx + zx *
yz) * detrot;
962 double iyy = (zz * xx - zx *
xz) * detrot;
963 double iyz = (-yz * xx + yx *
xz) * detrot;
964 double izx = (zy * yx - zx *
yy) * detrot;
965 double izy = (-zy * xx + zx *
xy) * detrot;
966 double izz = (yy * xx - yx *
xy) * detrot;
971 protx = atan2(prot.
yz(), prot.
zz());
982 if (_drotxVal > 3.141592656)
984 if (_drotxVal < -3.141592656)
1082 for (
int i = 0;
i < 9;
i++) {
1085 holdit.
phipos = ringPhiPos;
1099 int size = aliComp.size();
1103 for (
int i = 0;
i <
size;
i++) {
1125 std::cout <<
"JNB " << ali->
id() <<
" " << cscId.endcap() <<
" " << cscId.station() <<
" " << cscId.ring() <<
" " 1155 int size = aliComp.size();
1159 for (
int i = 0;
i <
size;
i++) {
1175 for (
int i = 0;
i < nEntries;
i++) {
align::Scalar width() const
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
T getUntrackedParameter(std::string const &, T const &) const
std::string _inputTreename
bool passChosen(Alignable *ali)
std::vector< align::StructureType > theLevels
Alignable * inputGeometry1
std::string _inputFilename1
void compareGeometries(Alignable *refAli, Alignable *curAli, Alignable *curAliCopy2)
bool isMother(Alignable *ali)
ret
prodAgent to be discontinued
Geom::Phi< T > phi() const
MuonGeometryArrange(const edm::ParameterSet &)
Do nothing. Required by framework.
constexpr uint32_t rawId() const
get the raw id
bool checkChosen(Alignable *ali)
AlgebraicVector diffAlignables(Alignable *refAli, Alignable *curAli, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
const RotationType & globalRotation() const
Return the global orientation of the object.
virtual const Alignables & components() const =0
Return vector of all direct components.
void analyze(const edm::Event &, const edm::EventSetup &) override
void createPoints(GlobalVectors *Vs, Alignable *ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
MuonAlignment * inputAlign2a
MuonAlignment * inputAlign2
RotationType diffRot(const GlobalVectors ¤t, const GlobalVectors &nominal)
std::vector< unsigned int > _weightByIdVector
std::string _inputXMLReference
void createROOTGeometry(const edm::EventSetup &iSetup)
#define DEFINE_FWK_MODULE(type)
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignableMuon * getAlignableMuon()
void makeGraph(int sizeI, float smi, float sma, float minV, float maxV, TH2F *dxh, TGraph *grx, const char *name, const char *title, const char *titleg, const char *axis, const float *xp, const float *yp, int numEntries)
void compare(Alignable *refAli, Alignable *curAli, Alignable *curAliCopy2)
std::string _inputFilename2
bool readModuleList(unsigned int, unsigned int, const std::vector< unsigned int > &)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::string _weightByIdFile
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
MuonAlignment * inputAlign1
GlobalVector centerOfMass(const GlobalVectors &theVs)
Find the CM of a set of points.
void fillTree(Alignable *refAli, const AlgebraicVector &diff)
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
align::Scalar length() const
void fillGapsInSurvey(double shiftErr, double angleErr)
const std::vector< std::string > _levelStrings
AlignableMuon * referenceMuon
std::vector< GlobalVector > GlobalVectors
AlignableMuon * currentMuon
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
std::string _detIdFlagFile
Alignable * inputGeometry2
const PositionType & globalPosition() const
Return the global position of the object.
std::string _inputXMLCurrent
void moveAlignable(Alignable *ali, AlgebraicVector diff)
Moves the alignable by the AlgebraicVector.
Alignable * mother() const
Return pointer to container alignable (if any)
const DetId & geomDetId() const
void beginJob() override
Read from DB and print survey info.
std::vector< uint32_t > _detIdFlagVector
constexpr Detector det() const
get the detector field from this detid
std::vector< MGACollection > _mgacollection