3 #include "CLHEP/Vector/RotationInterfaces.h" 34 #include "CLHEP/Vector/ThreeVector.h" 44 _levelStrings(cfg.getUntrackedParameter<
std::vector<
std::
string> >(
"levels")),
45 _writeToDB(
false), _commonMuonLevel(
align::invalid), firstEvent_(
true)
79 fin.open( _detIdFlagFile.c_str() );
81 while (!fin.eof() && fin.good() ){
91 unsigned int lastID=999999999;
94 inFile.open( _weightByIdFile.c_str() );
96 while ( !inFile.eof() ){
100 inFile.ignore(256,
'\n');
112 _theFile =
new TFile(_filename.c_str(),
"RECREATE");
113 _alignTree =
new TTree(
"alignTree",
"alignTree");
114 _alignTree->Branch(
"id", &
_id,
"id/I");
115 _alignTree->Branch(
"level", &
_level,
"level/I");
116 _alignTree->Branch(
"mid", &
_mid,
"mid/I");
117 _alignTree->Branch(
"mlevel", &
_mlevel,
"mlevel/I");
118 _alignTree->Branch(
"sublevel", &
_sublevel,
"sublevel/I");
119 _alignTree->Branch(
"x", &
_xVal,
"x/F");
120 _alignTree->Branch(
"y", &
_yVal,
"y/F");
121 _alignTree->Branch(
"z", &
_zVal,
"z/F");
122 _alignTree->Branch(
"r", &
_rVal,
"r/F");
123 _alignTree->Branch(
"phi", &
_phiVal,
"phi/F");
124 _alignTree->Branch(
"eta", &
_etaVal,
"eta/F");
125 _alignTree->Branch(
"alpha", &
_alphaVal,
"alpha/F");
126 _alignTree->Branch(
"beta", &
_betaVal,
"beta/F");
127 _alignTree->Branch(
"gamma", &
_gammaVal,
"gamma/F");
128 _alignTree->Branch(
"dx", &
_dxVal,
"dx/F");
129 _alignTree->Branch(
"dy", &
_dyVal,
"dy/F");
130 _alignTree->Branch(
"dz", &
_dzVal,
"dz/F");
131 _alignTree->Branch(
"dr", &
_drVal,
"dr/F");
132 _alignTree->Branch(
"dphi", &
_dphiVal,
"dphi/F");
133 _alignTree->Branch(
"dalpha", &
_dalphaVal,
"dalpha/F");
134 _alignTree->Branch(
"dbeta", &
_dbetaVal,
"dbeta/F");
135 _alignTree->Branch(
"dgamma", &
_dgammaVal,
"dgamma/F");
136 _alignTree->Branch(
"ldx", &
_ldxVal,
"ldx/F");
137 _alignTree->Branch(
"ldy", &
_ldyVal,
"ldy/F");
138 _alignTree->Branch(
"ldz", &
_ldzVal,
"ldz/F");
139 _alignTree->Branch(
"ldr", &
_ldrVal,
"ldr/F");
140 _alignTree->Branch(
"ldphi", &
_ldphiVal,
"ldphi/F");
141 _alignTree->Branch(
"useDetId", &
_useDetId,
"useDetId/I");
142 _alignTree->Branch(
"detDim", &
_detDim,
"detDim/I");
143 _alignTree->Branch(
"rotx",&
_rotxVal,
"rotx/F");
144 _alignTree->Branch(
"roty",&
_rotyVal,
"roty/F");
145 _alignTree->Branch(
"rotz",&
_rotzVal,
"rotz/F");
146 _alignTree->Branch(
"drotx",&
_drotxVal,
"drotx/F");
147 _alignTree->Branch(
"droty",&
_drotyVal,
"droty/F");
148 _alignTree->Branch(
"drotz",&
_drotzVal,
"drotz/F");
149 _alignTree->Branch(
"surW", &
_surWidth,
"surW/F");
150 _alignTree->Branch(
"surL", &
_surLength,
"surL/F");
151 _alignTree->Branch(
"surRot", &
_surRot,
"surRot[9]/D");
161 std::vector<float> xp(size+1);
162 std::vector<float> yp(size+1);
167 minV=99999999.; maxV=-minV; minI=9999999; maxI=-
minI;
172 for(i=0; i<
size; i++){
177 if(minI>=maxI)
return;
178 xp[
size]=xp[size-1]+1;
181 if(size>maxI) maxI=
size;
183 int sizeI=maxI+1-
minI;
190 for(i=0; i<
size; i++){
198 dxh, grx,
"delX_vs_position",
"Local #delta X vs position",
199 "GdelX_vs_position",
"#delta x in cm", xp.data(), yp.data(),
size);
201 minV=99999999.; maxV=-minV;
202 for(i=0; i<
size; i++){
210 dxh, grx,
"delY_vs_position",
"Local #delta Y vs position",
211 "GdelY_vs_position",
"#delta y in cm", xp.data(), yp.data(),
size);
214 minV=99999999.; maxV=-minV;
215 for(i=0; i<
size; i++){
223 dxh, grx,
"delZ_vs_position",
"Local #delta Z vs position",
224 "GdelZ_vs_position",
"#delta z in cm", xp.data(), yp.data(),
size);
227 minV=99999999.; maxV=-minV;
228 for(i=0; i<
size; i++){
236 dxh, grx,
"delphi_vs_position",
"#delta #phi vs position",
237 "Gdelphi_vs_position",
"#delta #phi in radians", xp.data(), yp.data(),
size);
240 minV=99999999.; maxV=-minV;
241 for(i=0; i<
size; i++){
249 dxh, grx,
"delR_vs_position",
"#delta R vs position",
250 "GdelR_vs_position",
"#delta R in cm", xp.data(), yp.data(),
size);
253 minV=99999999.; maxV=-minV;
254 for(i=0; i<
size; i++){
256 if(ttemp<minV) minV=ttemp;
257 if(ttemp>maxV) maxV=ttemp;
263 dxh, grx,
"delRphi_vs_position",
"R #delta #phi vs position",
264 "GdelRphi_vs_position",
"R #delta #phi in cm", xp.data(), yp.data(),
size);
267 minV=99999999.; maxV=-minV;
268 for(i=0; i<
size; i++){
276 dxh, grx,
"delalpha_vs_position",
"#delta #alpha vs position",
277 "Gdelalpha_vs_position",
"#delta #alpha in rad", xp.data(), yp.data(),
size);
280 minV=99999999.; maxV=-minV;
281 for(i=0; i<
size; i++){
289 dxh, grx,
"delbeta_vs_position",
"#delta #beta vs position",
290 "Gdelbeta_vs_position",
"#delta #beta in rad", xp.data(), yp.data(),
size);
293 minV=99999999.; maxV=-minV;
294 for(i=0; i<
size; i++){
302 dxh, grx,
"delgamma_vs_position",
"#delta #gamma vs position",
303 "Gdelgamma_vs_position",
"#delta #gamma in rad", xp.data(), yp.data(),
size);
306 minV=99999999.; maxV=-minV;
307 for(i=0; i<
size; i++){
315 dxh, grx,
"delrotX_vs_position",
"#delta rotX vs position",
316 "GdelrotX_vs_position",
"#delta rotX in rad", xp.data(), yp.data(),
size);
319 minV=99999999.; maxV=-minV;
320 for(i=0; i<
size; i++){
328 dxh, grx,
"delrotY_vs_position",
"#delta rotY vs position",
329 "GdelrotY_vs_position",
"#delta rotY in rad", xp.data(), yp.data(),
size);
332 minV=99999999.; maxV=-minV;
333 for(i=0; i<
size; i++){
341 dxh, grx,
"delrotZ_vs_position",
"#delta rotZ vs position",
342 "GdelrotZ_vs_position",
"#delta rotZ in rad", xp.data(), yp.data(),
size);
351 float maxR=-9999999.;
352 for(i=0; i<
size; i++){
357 if(ttemp>maxV) maxV=ttemp;
358 if(rtemp>maxR) maxR=rtemp;
362 float smallestVcm=.001;
363 if(maxV<smallestVcm) maxV=smallestVcm;
365 float lside=1.1*maxR;
366 if(lside<=0) lside=100.;
367 if(maxV>0){scale=.09*lside/maxV;}
369 int ret=snprintf(scalename,50,
"#delta #bar{x} length =%f cm",maxV);
373 dxh=
new TH2F(
"vecdrplot",scalename,80,-lside,lside,80,-lside,lside);
376 dxh=
new TH2F(
"vecdrplot",
"delta #bar{x} Bad scale",80,-lside,lside,80,-lside,lside);
378 dxh->GetXaxis()->SetTitle(
"x in cm");
379 dxh->GetYaxis()->SetTitle(
"y in cm");
380 dxh->SetStats(kFALSE);
383 for(i=0; i<
size; i++){
391 arrow->SetLineWidth(2); arrow->SetArrowSize(ttemp*.2*.05/maxV);
392 arrow->SetLineColor(1); arrow->SetLineStyle(1);
394 dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
407 float minV,
float maxV,
408 TH2F* dxh, TGraph* grx,
const char*
name,
const char*
title,
409 const char* titleg,
const char* axis,
410 const float* xp,
const float* yp,
int size){
412 if(minV>=maxV || smi>=sma || sizeI<=1 || xp==
nullptr || yp==
nullptr)
return;
414 float diff=maxV-minV;
416 double ylo=minV-over;
417 double yhi=maxV+over;
420 dxh=
new TH2F(name, title,
421 sizeI+2, dsmi, dsma, 50, ylo, yhi);
422 dxh->GetXaxis()->SetTitle(
"Position around ring");
423 dxh->GetYaxis()->SetTitle(axis);
424 dxh->SetStats(kFALSE);
426 grx =
new TGraph(size, xp, yp);
427 grx->SetName(titleg);
428 grx->SetTitle(title);
429 grx->SetMarkerColor(2); grx->SetMarkerStyle(3);
430 grx->GetXaxis()->SetLimits(dsmi, dsma);
431 grx->GetXaxis()->SetTitle(
"position number");
432 grx->GetYaxis()->SetLimits(ylo,yhi);
433 grx->GetYaxis()->SetTitle(axis);
468 theLevels.push_back(inputGeometry2Copy2->objectIdProvider().stringToId(
level));
491 if(refAli==
nullptr){
return;}
492 if(curAli==
nullptr){
return;}
496 const auto& curComp2 = curAliCopy2->
components();
499 int nComp=refComp.size();
500 for(
int i=0;
i<nComp;
i++){
501 compare(refComp[
i], curComp[i], curComp2[i]);
510 if(refAli==
nullptr){
return;}
511 if(curAli==
nullptr){
return;}
521 if(refComp.size()!=curComp.size()){
531 int nComp = refComp.size();
534 CLHEP::Hep3Vector TotalX, TotalL;
535 TotalX.set(0.,0.,0.); TotalL.set(0., 0., 0.);
537 std::vector<CLHEP::Hep3Vector> Positions;
538 std::vector<CLHEP::Hep3Vector> DelPositions;
550 for(
int ich=0; ich<nComp; ich++){
561 originalVectors.push_back(pointsCM);
563 xrcenter+= pointsCM.
x();
564 yrcenter+= pointsCM.
y();
565 zrcenter+= pointsCM.
z();
567 xrcenter=xrcenter/nUsed;
568 yrcenter=yrcenter/nUsed;
569 zrcenter=zrcenter/nUsed;
573 for(
int ich=0; ich<nComp; ich++){
584 currentVectors.push_back(pointsCM);
586 xccenter+= pointsCM.
x();
587 yccenter+= pointsCM.
y();
588 zccenter+= pointsCM.
z();
590 xccenter=xccenter/nUsed;
591 yccenter=yccenter/nUsed;
592 zccenter=zccenter/nUsed;
598 int nCompR = currentVectors.size();
599 for(
int ich=0; ich<nCompR; ich++){
600 originalRelativeVectors.push_back(originalVectors[ich]-CRef);
601 currentRelativeVectors.push_back(currentVectors[ich]-CCur);
610 originalRelativeVectors);
616 for(
int ich=0; ich<nComp; ich++){
621 CLHEP::Hep3Vector Rtotal, Wtotal;
622 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
623 for (
int i = 0;
i < 100;
i++){
626 CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
628 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
629 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
630 CLHEP::HepRotation drot(dW.unit(),dW.mag());
632 Wtotal.set(rot.axis().x()*rot.delta(),
633 rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
640 DetId detid(refComp[ich]->
id());
659 change(1)=TotalX.x();
660 change(2)=TotalX.y();
661 change(3)=TotalX.z();
671 for(
int ich=0; ich<nComp; ich++){
672 CLHEP::Hep3Vector Rtotal, Wtotal;
673 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
679 for (
int i = 0;
i < 100;
i++){
682 CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
684 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
685 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
686 CLHEP::HepRotation drot(dW.unit(),dW.mag());
688 Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(),
689 rot.axis().z()*rot.delta());
700 TRtot(1) = Rtotal.x(); TRtot(2) = Rtotal.y(); TRtot(3) = Rtotal.z();
701 TRtot(4) = Wtotal.x(); TRtot(5) = Wtotal.y(); TRtot(6) = Wtotal.z();
778 double detrot=(zz*yy - zy*
yz)*xx + (-zz*yx + zx*yz)*xy + (zy*yx - zx*
yy)*xz;
780 double ixx=(zz*yy - zy*
yz)*detrot;
781 double ixy=(-zz*xy + zy*
xz)*detrot;
782 double ixz=(yz*xy - yy*
xz)*detrot;
783 double iyx=(-zz*yx + zx*
yz)*detrot;
784 double iyy=(zz*xx - zx*
xz)*detrot;
785 double iyz=(-yz*xx + yx*
xz)*detrot;
786 double izx=(zy*yx - zx*
yy)*detrot;
787 double izy=(-zy*xx + zx*
xy)*detrot;
788 double izz=(yy*xx - yx*
xy)*detrot;
793 protx = atan2(prot.
yz(), prot.
zz());
802 if(_drotxVal>3.141592656) _drotxVal=-6.2831853072+
_drotxVal;
803 if(_drotxVal<-3.141592656) _drotxVal=6.2831853072+
_drotxVal;
878 if(ali==
nullptr)
return false;
881 int size=aliComp.size();
882 if(size<=0)
return false;
893 if(ali==
nullptr)
return false;
904 std::cout<<
"JNB "<<ali->
id()<<
" "<<cscId.endcap()<<
" " 905 <<cscId.station()<<
" "<<cscId.ring()<<
" "<<cscId.chamber()<<
" " 910 cscId.ring()==
_ring) {
930 if(ali==
nullptr)
return false;
935 int size=aliComp.size();
936 if(size<=0)
return false;
954 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)
Geom::Phi< T > phi() const
MuonGeometryArrange(const edm::ParameterSet &)
Do nothing. Required by framework.
constexpr uint32_t rawId() const
get the raw id
std::vector< unsigned int > _weightByIdVector
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::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::vector< uint32_t > _detIdFlagVector
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.
constexpr Detector det() const
get the detector field from this detid
std::vector< MGACollection > _mgacollection