3 #include "CLHEP/Vector/RotationInterfaces.h"
35 #include "CLHEP/Vector/ThreeVector.h"
62 const std::vector<std::string>& levels =
78 edm::LogInfo(
"MuonGeometryArrange") <<
"levels: " << levels.size();
79 for (
unsigned int l = 0;
l < levels.size(); ++
l){
80 theLevels.push_back( dummy.nameToType(levels[
l]));
81 edm::LogInfo(
"MuonGeometryArrange") <<
"level: " << levels[
l];
88 fin.open( _detIdFlagFile.c_str() );
90 while (!fin.eof() && fin.good() ){
100 unsigned int lastID=999999999;
102 std::ifstream inFile;
103 inFile.open( _weightByIdFile.c_str() );
105 while ( !inFile.eof() ){
109 inFile.ignore(256,
'\n');
121 _theFile =
new TFile(_filename.c_str(),
"RECREATE");
122 _alignTree =
new TTree(
"alignTree",
"alignTree");
123 _alignTree->Branch(
"id", &
_id,
"id/I");
124 _alignTree->Branch(
"level", &
_level,
"level/I");
125 _alignTree->Branch(
"mid", &
_mid,
"mid/I");
126 _alignTree->Branch(
"mlevel", &
_mlevel,
"mlevel/I");
127 _alignTree->Branch(
"sublevel", &
_sublevel,
"sublevel/I");
128 _alignTree->Branch(
"x", &
_xVal,
"x/F");
129 _alignTree->Branch(
"y", &
_yVal,
"y/F");
130 _alignTree->Branch(
"z", &
_zVal,
"z/F");
131 _alignTree->Branch(
"r", &
_rVal,
"r/F");
132 _alignTree->Branch(
"phi", &
_phiVal,
"phi/F");
133 _alignTree->Branch(
"eta", &
_etaVal,
"eta/F");
134 _alignTree->Branch(
"alpha", &
_alphaVal,
"alpha/F");
135 _alignTree->Branch(
"beta", &
_betaVal,
"beta/F");
136 _alignTree->Branch(
"gamma", &
_gammaVal,
"gamma/F");
137 _alignTree->Branch(
"dx", &
_dxVal,
"dx/F");
138 _alignTree->Branch(
"dy", &
_dyVal,
"dy/F");
139 _alignTree->Branch(
"dz", &
_dzVal,
"dz/F");
140 _alignTree->Branch(
"dr", &
_drVal,
"dr/F");
141 _alignTree->Branch(
"dphi", &
_dphiVal,
"dphi/F");
142 _alignTree->Branch(
"dalpha", &
_dalphaVal,
"dalpha/F");
143 _alignTree->Branch(
"dbeta", &
_dbetaVal,
"dbeta/F");
144 _alignTree->Branch(
"dgamma", &
_dgammaVal,
"dgamma/F");
145 _alignTree->Branch(
"ldx", &
_ldxVal,
"ldx/F");
146 _alignTree->Branch(
"ldy", &
_ldyVal,
"ldy/F");
147 _alignTree->Branch(
"ldz", &
_ldzVal,
"ldz/F");
148 _alignTree->Branch(
"ldr", &
_ldrVal,
"ldr/F");
149 _alignTree->Branch(
"ldphi", &
_ldphiVal,
"ldphi/F");
150 _alignTree->Branch(
"useDetId", &
_useDetId,
"useDetId/I");
151 _alignTree->Branch(
"detDim", &
_detDim,
"detDim/I");
152 _alignTree->Branch(
"rotx",&
_rotxVal,
"rotx/F");
153 _alignTree->Branch(
"roty",&
_rotyVal,
"roty/F");
154 _alignTree->Branch(
"rotz",&
_rotzVal,
"rotz/F");
155 _alignTree->Branch(
"drotx",&
_drotxVal,
"drotx/F");
156 _alignTree->Branch(
"droty",&
_drotyVal,
"droty/F");
157 _alignTree->Branch(
"drotz",&
_drotzVal,
"drotz/F");
158 _alignTree->Branch(
"surW", &
_surWidth,
"surW/F");
159 _alignTree->Branch(
"surL", &
_surLength,
"surL/F");
160 _alignTree->Branch(
"surRot", &
_surRot,
"surRot[9]/D");
170 float* xp =
new float[size+1];
171 float* yp =
new float[size+1];
179 minV=99999999.; maxV=-minV; minI=9999999; maxI=-
minI;
184 for(i=0; i<
size; i++){
189 if(minI>=maxI)
return;
190 xp[
size]=xp[size-1]+1;
193 if(size>maxI) maxI=
size;
195 int sizeI=maxI+1-
minI;
202 for(i=0; i<
size; i++){
210 dxh, grx,
"delX_vs_position",
"Local #delta X vs position",
211 "GdelX_vs_position",
"#delta x in cm", xp, yp, size);
213 minV=99999999.; maxV=-minV;
214 for(i=0; i<
size; i++){
222 dxh, grx,
"delY_vs_position",
"Local #delta Y vs position",
223 "GdelY_vs_position",
"#delta y in cm", xp, yp, size);
226 minV=99999999.; maxV=-minV;
227 for(i=0; i<
size; i++){
235 dxh, grx,
"delZ_vs_position",
"Local #delta Z vs position",
236 "GdelZ_vs_position",
"#delta z in cm", xp, yp, size);
239 minV=99999999.; maxV=-minV;
240 for(i=0; i<
size; i++){
248 dxh, grx,
"delphi_vs_position",
"#delta #phi vs position",
249 "Gdelphi_vs_position",
"#delta #phi in radians", xp, yp, size);
252 minV=99999999.; maxV=-minV;
253 for(i=0; i<
size; i++){
261 dxh, grx,
"delR_vs_position",
"#delta R vs position",
262 "GdelR_vs_position",
"#delta R in cm", xp, yp, size);
265 minV=99999999.; maxV=-minV;
266 for(i=0; i<
size; i++){
268 if(ttemp<minV) minV=ttemp;
269 if(ttemp>maxV) maxV=ttemp;
275 dxh, grx,
"delRphi_vs_position",
"R #delta #phi vs position",
276 "GdelRphi_vs_position",
"R #delta #phi in cm", xp, yp, size);
279 minV=99999999.; maxV=-minV;
280 for(i=0; i<
size; i++){
288 dxh, grx,
"delalpha_vs_position",
"#delta #alpha vs position",
289 "Gdelalpha_vs_position",
"#delta #alpha in rad", xp, yp, size);
292 minV=99999999.; maxV=-minV;
293 for(i=0; i<
size; i++){
301 dxh, grx,
"delbeta_vs_position",
"#delta #beta vs position",
302 "Gdelbeta_vs_position",
"#delta #beta in rad", xp, yp, size);
305 minV=99999999.; maxV=-minV;
306 for(i=0; i<
size; i++){
314 dxh, grx,
"delgamma_vs_position",
"#delta #gamma vs position",
315 "Gdelgamma_vs_position",
"#delta #gamma in rad", xp, yp, size);
318 minV=99999999.; maxV=-minV;
319 for(i=0; i<
size; i++){
327 dxh, grx,
"delrotX_vs_position",
"#delta rotX vs position",
328 "GdelrotX_vs_position",
"#delta rotX in rad", xp, yp, size);
331 minV=99999999.; maxV=-minV;
332 for(i=0; i<
size; i++){
340 dxh, grx,
"delrotY_vs_position",
"#delta rotY vs position",
341 "GdelrotY_vs_position",
"#delta rotY in rad", xp, yp, size);
344 minV=99999999.; maxV=-minV;
345 for(i=0; i<
size; i++){
353 dxh, grx,
"delrotZ_vs_position",
"#delta rotZ vs position",
354 "GdelrotZ_vs_position",
"#delta rotZ in rad", xp, yp, size);
363 float maxR=-9999999.;
364 for(i=0; i<
size; i++){
369 if(ttemp>maxV) maxV=ttemp;
370 if(rtemp>maxR) maxR=rtemp;
374 float smallestVcm=.001;
375 if(maxV<smallestVcm) maxV=smallestVcm;
377 float lside=1.1*maxR;
378 if(lside<=0) lside=100.;
379 if(maxV>0){scale=.09*lside/maxV;}
381 int ret=snprintf(scalename,50,
"#delta #bar{x} length =%f cm",maxV);
385 dxh=
new TH2F(
"vecdrplot",scalename,80,-lside,lside,80,-lside,lside);
388 dxh=
new TH2F(
"vecdrplot",
"delta #bar{x} Bad scale",80,-lside,lside,80,-lside,lside);
390 dxh->GetXaxis()->SetTitle(
"x in cm");
391 dxh->GetYaxis()->SetTitle(
"y in cm");
392 dxh->SetStats(kFALSE);
395 for(i=0; i<
size; i++){
403 arrow->SetLineWidth(2); arrow->SetArrowSize(ttemp*.2*.05/maxV);
404 arrow->SetLineColor(1); arrow->SetLineStyle(1);
406 dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
415 delete [] yp;
delete [] xp;
420 float minV,
float maxV,
421 TH2F* dxh, TGraph* grx,
const char*
name,
const char*
title,
422 const char* titleg,
const char* axis,
423 float* xp,
float* yp,
int size){
425 if(minV>=maxV || smi>=sma || sizeI<=1 || xp==0x0 || yp==0x0)
return;
427 float diff=maxV-minV;
429 double ylo=minV-over;
430 double yhi=maxV+over;
433 dxh=
new TH2F(name, title,
434 sizeI+2, dsmi, dsma, 50, ylo, yhi);
435 dxh->GetXaxis()->SetTitle(
"Position around ring");
436 dxh->GetYaxis()->SetTitle(axis);
437 dxh->SetStats(kFALSE);
439 grx =
new TGraph(size, xp, yp);
440 grx->SetName(titleg);
441 grx->SetTitle(title);
442 grx->SetMarkerColor(2); grx->SetMarkerStyle(3);
443 grx->GetXaxis()->SetLimits(dsmi, dsma);
444 grx->GetXaxis()->SetTitle(
"position number");
445 grx->GetYaxis()->SetLimits(ylo,yhi);
446 grx->GetYaxis()->SetTitle(axis);
498 if(refAli==0x0){
return;}
499 if(curAli==0x0){
return;}
501 const std::vector<Alignable*>& refComp = refAli->
components();
502 const std::vector<Alignable*>& curComp = curAli->
components();
503 const std::vector<Alignable*>& curComp2 = curAliCopy2->
components();
506 int nComp=refComp.size();
507 for(
int i=0;
i<nComp;
i++){
508 compare(refComp[
i], curComp[i], curComp2[i]);
517 if(refAli==0x0){
return;}
518 if(curAli==0x0){
return;}
526 const std::vector<Alignable*>& refComp = refAli->
components();
527 const std::vector<Alignable*>& curComp = curCopy->
components();
528 if(refComp.size()!=curComp.size()){
538 int nComp = refComp.size();
541 CLHEP::Hep3Vector TotalX, TotalL;
542 TotalX.set(0.,0.,0.); TotalL.set(0., 0., 0.);
544 std::vector<CLHEP::Hep3Vector> Positions;
545 std::vector<CLHEP::Hep3Vector> DelPositions;
557 for(
int ich=0; ich<nComp; ich++){
568 originalVectors.push_back(pointsCM);
570 xrcenter+= pointsCM.
x();
571 yrcenter+= pointsCM.
y();
572 zrcenter+= pointsCM.
z();
574 xrcenter=xrcenter/nUsed;
575 yrcenter=yrcenter/nUsed;
576 zrcenter=zrcenter/nUsed;
580 for(
int ich=0; ich<nComp; ich++){
591 currentVectors.push_back(pointsCM);
593 xccenter+= pointsCM.
x();
594 yccenter+= pointsCM.
y();
595 zccenter+= pointsCM.
z();
597 xccenter=xccenter/nUsed;
598 yccenter=yccenter/nUsed;
599 zccenter=zccenter/nUsed;
605 int nCompR = currentVectors.size();
606 for(
int ich=0; ich<nCompR; ich++){
607 originalRelativeVectors.push_back(originalVectors[ich]-CRef);
608 currentRelativeVectors.push_back(currentVectors[ich]-CCur);
617 originalRelativeVectors);
623 for(
int ich=0; ich<nComp; ich++){
628 CLHEP::Hep3Vector Rtotal, Wtotal;
629 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
630 for (
int i = 0;
i < 100;
i++){
633 CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
635 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
636 CLHEP::HepRotation rot(Wtotal.unit(),Wtotal.mag());
637 CLHEP::HepRotation drot(dW.unit(),dW.mag());
639 Wtotal.set(rot.axis().x()*rot.delta(),
640 rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
642 float tolerance = 1e-7;
648 if ((checkR.
mag() > tolerance)||(checkW.
mag() > tolerance)){
666 change(1)=TotalX.x();
667 change(2)=TotalX.y();
668 change(3)=TotalX.z();
676 const std::vector<Alignable*>& curComp2 = curAli->
components();
678 for(
int ich=0; ich<nComp; ich++){
679 CLHEP::Hep3Vector Rtotal, Wtotal;
680 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
686 for (
int i = 0;
i < 100;
i++){
689 CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
691 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
692 CLHEP::HepRotation rot(Wtotal.unit(),Wtotal.mag());
693 CLHEP::HepRotation drot(dW.unit(),dW.mag());
695 Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(),
696 rot.axis().z()*rot.delta());
698 float tolerance = 1e-7;
703 if ((checkR.
mag() > tolerance)||(checkW.
mag() > tolerance)){}
707 TRtot(1) = Rtotal.x(); TRtot(2) = Rtotal.y(); TRtot(3) = Rtotal.z();
708 TRtot(4) = Wtotal.x(); TRtot(5) = Wtotal.y(); TRtot(6) = Wtotal.z();
785 double detrot=(zz*yy - zy*yz)*xx + (-zz*yx + zx*yz)*xy + (zy*yx - zx*yy)*xz;
787 double ixx=(zz*yy - zy*yz)*detrot;
788 double ixy=(-zz*xy + zy*xz)*detrot;
789 double ixz=(yz*xy - yy*xz)*detrot;
790 double iyx=(-zz*yx + zx*yz)*detrot;
791 double iyy=(zz*xx - zx*xz)*detrot;
792 double iyz=(-yz*xx + yx*xz)*detrot;
793 double izx=(zy*yx - zx*yy)*detrot;
794 double izy=(-zy*xx + zx*
xy)*detrot;
795 double izz=(yy*xx - yx*
xy)*detrot;
800 protx = atan2(prot.
yz(), prot.
zz());
809 if(_drotxVal>3.141592656) _drotxVal=-6.2831853072+
_drotxVal;
810 if(_drotxVal<-3.141592656) _drotxVal=6.2831853072+
_drotxVal;
885 if(ali==0x0)
return false;
886 const std::vector<Alignable*>& aliComp = ali->
components();
888 int size=aliComp.size();
889 if(size<=0)
return false;
900 if(ali==0x0)
return false;
911 std::cout<<
"JNB "<<ali->
id()<<
" "<<cscId.endcap()<<
" "
912 <<cscId.station()<<
" "<<cscId.ring()<<
" "<<cscId.chamber()<<
" "
917 cscId.ring()==
_ring) {
937 if(ali==0x0)
return false;
940 const std::vector<Alignable*>& aliComp = ali->
components();
942 int size=aliComp.size();
943 if(size<=0)
return false;
961 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)
#define DEFINE_FWK_MODULE(type)
Geom::Phi< T > phi() const
MuonGeometryArrange(const edm::ParameterSet &)
Do nothing. Required by framework.
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.
void createPoints(GlobalVectors *Vs, Alignable *ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
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, float *xp, float *yp, int numEntries)
MuonAlignment * inputAlign2a
virtual Alignables components() const =0
Return vector of all direct components.
virtual void beginJob()
Read from DB and print survey info.
MuonAlignment * inputAlign2
RotationType diffRot(const GlobalVectors ¤t, const GlobalVectors &nominal)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::string _inputXMLReference
uint32_t rawId() const
get the raw id
void createROOTGeometry(const edm::EventSetup &iSetup)
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
AlignableMuon * getAlignableMuon()
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
void compare(Alignable *refAli, Alignable *curAli, Alignable *curAliCopy2)
std::string _inputFilename2
bool readModuleList(unsigned int, unsigned int, const std::vector< unsigned int > &)
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
std::vector< uint32_t > _detIdFlagVector
Allows conversion between type and name, and vice-versa.
std::string _weightByIdFile
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
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.
Basic2DVector< T > xy() const
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
align::Scalar length() const
void fillGapsInSurvey(double shiftErr, double angleErr)
AlignableMuon * referenceMuon
std::vector< GlobalVector > GlobalVectors
AlignableMuon * currentMuon
void fillTree(Alignable *refAli, AlgebraicVector diff)
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
Detector det() const
get the detector field from this detid
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
tuple size
Write out results.
std::vector< MGACollection > _mgacollection