3 #include "CLHEP/Vector/RotationInterfaces.h" 35 #include "CLHEP/Vector/ThreeVector.h" 45 _levelStrings(cfg.getUntrackedParameter<
std::vector<
std::
string> >(
"levels")),
80 fin.open( _detIdFlagFile.c_str() );
82 while (!fin.eof() && fin.good() ){
92 unsigned int lastID=999999999;
95 inFile.open( _weightByIdFile.c_str() );
97 while ( !inFile.eof() ){
101 inFile.ignore(256,
'\n');
113 _theFile =
new TFile(_filename.c_str(),
"RECREATE");
114 _alignTree =
new TTree(
"alignTree",
"alignTree");
115 _alignTree->Branch(
"id", &
_id,
"id/I");
116 _alignTree->Branch(
"level", &
_level,
"level/I");
117 _alignTree->Branch(
"mid", &
_mid,
"mid/I");
118 _alignTree->Branch(
"mlevel", &
_mlevel,
"mlevel/I");
119 _alignTree->Branch(
"sublevel", &
_sublevel,
"sublevel/I");
120 _alignTree->Branch(
"x", &
_xVal,
"x/F");
121 _alignTree->Branch(
"y", &
_yVal,
"y/F");
122 _alignTree->Branch(
"z", &
_zVal,
"z/F");
123 _alignTree->Branch(
"r", &
_rVal,
"r/F");
124 _alignTree->Branch(
"phi", &
_phiVal,
"phi/F");
125 _alignTree->Branch(
"eta", &
_etaVal,
"eta/F");
126 _alignTree->Branch(
"alpha", &
_alphaVal,
"alpha/F");
127 _alignTree->Branch(
"beta", &
_betaVal,
"beta/F");
128 _alignTree->Branch(
"gamma", &
_gammaVal,
"gamma/F");
129 _alignTree->Branch(
"dx", &
_dxVal,
"dx/F");
130 _alignTree->Branch(
"dy", &
_dyVal,
"dy/F");
131 _alignTree->Branch(
"dz", &
_dzVal,
"dz/F");
132 _alignTree->Branch(
"dr", &
_drVal,
"dr/F");
133 _alignTree->Branch(
"dphi", &
_dphiVal,
"dphi/F");
134 _alignTree->Branch(
"dalpha", &
_dalphaVal,
"dalpha/F");
135 _alignTree->Branch(
"dbeta", &
_dbetaVal,
"dbeta/F");
136 _alignTree->Branch(
"dgamma", &
_dgammaVal,
"dgamma/F");
137 _alignTree->Branch(
"ldx", &
_ldxVal,
"ldx/F");
138 _alignTree->Branch(
"ldy", &
_ldyVal,
"ldy/F");
139 _alignTree->Branch(
"ldz", &
_ldzVal,
"ldz/F");
140 _alignTree->Branch(
"ldr", &
_ldrVal,
"ldr/F");
141 _alignTree->Branch(
"ldphi", &
_ldphiVal,
"ldphi/F");
142 _alignTree->Branch(
"useDetId", &
_useDetId,
"useDetId/I");
143 _alignTree->Branch(
"detDim", &
_detDim,
"detDim/I");
144 _alignTree->Branch(
"rotx",&
_rotxVal,
"rotx/F");
145 _alignTree->Branch(
"roty",&
_rotyVal,
"roty/F");
146 _alignTree->Branch(
"rotz",&
_rotzVal,
"rotz/F");
147 _alignTree->Branch(
"drotx",&
_drotxVal,
"drotx/F");
148 _alignTree->Branch(
"droty",&
_drotyVal,
"droty/F");
149 _alignTree->Branch(
"drotz",&
_drotzVal,
"drotz/F");
150 _alignTree->Branch(
"surW", &
_surWidth,
"surW/F");
151 _alignTree->Branch(
"surL", &
_surLength,
"surL/F");
152 _alignTree->Branch(
"surRot", &
_surRot,
"surRot[9]/D");
162 std::vector<float> xp(size+1);
163 std::vector<float> yp(size+1);
168 minV=99999999.; maxV=-minV; minI=9999999; maxI=-
minI;
173 for(i=0; i<
size; i++){
178 if(minI>=maxI)
return;
179 xp[
size]=xp[size-1]+1;
182 if(size>maxI) maxI=
size;
184 int sizeI=maxI+1-
minI;
191 for(i=0; i<
size; i++){
199 dxh, grx,
"delX_vs_position",
"Local #delta X vs position",
200 "GdelX_vs_position",
"#delta x in cm", xp.data(), yp.data(),
size);
202 minV=99999999.; maxV=-minV;
203 for(i=0; i<
size; i++){
211 dxh, grx,
"delY_vs_position",
"Local #delta Y vs position",
212 "GdelY_vs_position",
"#delta y in cm", xp.data(), yp.data(),
size);
215 minV=99999999.; maxV=-minV;
216 for(i=0; i<
size; i++){
224 dxh, grx,
"delZ_vs_position",
"Local #delta Z vs position",
225 "GdelZ_vs_position",
"#delta z in cm", xp.data(), yp.data(),
size);
228 minV=99999999.; maxV=-minV;
229 for(i=0; i<
size; i++){
237 dxh, grx,
"delphi_vs_position",
"#delta #phi vs position",
238 "Gdelphi_vs_position",
"#delta #phi in radians", xp.data(), yp.data(),
size);
241 minV=99999999.; maxV=-minV;
242 for(i=0; i<
size; i++){
250 dxh, grx,
"delR_vs_position",
"#delta R vs position",
251 "GdelR_vs_position",
"#delta R in cm", xp.data(), yp.data(),
size);
254 minV=99999999.; maxV=-minV;
255 for(i=0; i<
size; i++){
257 if(ttemp<minV) minV=ttemp;
258 if(ttemp>maxV) maxV=ttemp;
264 dxh, grx,
"delRphi_vs_position",
"R #delta #phi vs position",
265 "GdelRphi_vs_position",
"R #delta #phi in cm", xp.data(), yp.data(),
size);
268 minV=99999999.; maxV=-minV;
269 for(i=0; i<
size; i++){
277 dxh, grx,
"delalpha_vs_position",
"#delta #alpha vs position",
278 "Gdelalpha_vs_position",
"#delta #alpha in rad", xp.data(), yp.data(),
size);
281 minV=99999999.; maxV=-minV;
282 for(i=0; i<
size; i++){
290 dxh, grx,
"delbeta_vs_position",
"#delta #beta vs position",
291 "Gdelbeta_vs_position",
"#delta #beta in rad", xp.data(), yp.data(),
size);
294 minV=99999999.; maxV=-minV;
295 for(i=0; i<
size; i++){
303 dxh, grx,
"delgamma_vs_position",
"#delta #gamma vs position",
304 "Gdelgamma_vs_position",
"#delta #gamma in rad", xp.data(), yp.data(),
size);
307 minV=99999999.; maxV=-minV;
308 for(i=0; i<
size; i++){
316 dxh, grx,
"delrotX_vs_position",
"#delta rotX vs position",
317 "GdelrotX_vs_position",
"#delta rotX in rad", xp.data(), yp.data(),
size);
320 minV=99999999.; maxV=-minV;
321 for(i=0; i<
size; i++){
329 dxh, grx,
"delrotY_vs_position",
"#delta rotY vs position",
330 "GdelrotY_vs_position",
"#delta rotY in rad", xp.data(), yp.data(),
size);
333 minV=99999999.; maxV=-minV;
334 for(i=0; i<
size; i++){
342 dxh, grx,
"delrotZ_vs_position",
"#delta rotZ vs position",
343 "GdelrotZ_vs_position",
"#delta rotZ in rad", xp.data(), yp.data(),
size);
352 float maxR=-9999999.;
353 for(i=0; i<
size; i++){
358 if(ttemp>maxV) maxV=ttemp;
359 if(rtemp>maxR) maxR=rtemp;
363 float smallestVcm=.001;
364 if(maxV<smallestVcm) maxV=smallestVcm;
366 float lside=1.1*maxR;
367 if(lside<=0) lside=100.;
368 if(maxV>0){scale=.09*lside/maxV;}
370 int ret=snprintf(scalename,50,
"#delta #bar{x} length =%f cm",maxV);
374 dxh=
new TH2F(
"vecdrplot",scalename,80,-lside,lside,80,-lside,lside);
377 dxh=
new TH2F(
"vecdrplot",
"delta #bar{x} Bad scale",80,-lside,lside,80,-lside,lside);
379 dxh->GetXaxis()->SetTitle(
"x in cm");
380 dxh->GetYaxis()->SetTitle(
"y in cm");
381 dxh->SetStats(kFALSE);
384 for(i=0; i<
size; i++){
392 arrow->SetLineWidth(2); arrow->SetArrowSize(ttemp*.2*.05/maxV);
393 arrow->SetLineColor(1); arrow->SetLineStyle(1);
395 dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
408 float minV,
float maxV,
409 TH2F* dxh, TGraph* grx,
const char*
name,
const char*
title,
410 const char* titleg,
const char* axis,
411 const float* xp,
const float* yp,
int size){
413 if(minV>=maxV || smi>=sma || sizeI<=1 || xp==0x0 || yp==0x0)
return;
415 float diff=maxV-minV;
417 double ylo=minV-over;
418 double yhi=maxV+over;
421 dxh=
new TH2F(name, title,
422 sizeI+2, dsmi, dsma, 50, ylo, yhi);
423 dxh->GetXaxis()->SetTitle(
"Position around ring");
424 dxh->GetYaxis()->SetTitle(axis);
425 dxh->SetStats(kFALSE);
427 grx =
new TGraph(size, xp, yp);
428 grx->SetName(titleg);
429 grx->SetTitle(title);
430 grx->SetMarkerColor(2); grx->SetMarkerStyle(3);
431 grx->GetXaxis()->SetLimits(dsmi, dsma);
432 grx->GetXaxis()->SetTitle(
"position number");
433 grx->GetYaxis()->SetLimits(ylo,yhi);
434 grx->GetYaxis()->SetTitle(axis);
469 theLevels.push_back(inputGeometry2Copy2->objectIdProvider().stringToId(
level));
492 if(refAli==0x0){
return;}
493 if(curAli==0x0){
return;}
495 const std::vector<Alignable*>& refComp = refAli->
components();
496 const std::vector<Alignable*>& curComp = curAli->
components();
497 const std::vector<Alignable*>& curComp2 = curAliCopy2->
components();
500 int nComp=refComp.size();
501 for(
int i=0;
i<nComp;
i++){
502 compare(refComp[
i], curComp[i], curComp2[i]);
511 if(refAli==0x0){
return;}
512 if(curAli==0x0){
return;}
520 const std::vector<Alignable*>& refComp = refAli->
components();
521 const std::vector<Alignable*>& curComp = curCopy->
components();
522 if(refComp.size()!=curComp.size()){
532 int nComp = refComp.size();
535 CLHEP::Hep3Vector TotalX, TotalL;
536 TotalX.set(0.,0.,0.); TotalL.set(0., 0., 0.);
538 std::vector<CLHEP::Hep3Vector> Positions;
539 std::vector<CLHEP::Hep3Vector> DelPositions;
551 for(
int ich=0; ich<nComp; ich++){
562 originalVectors.push_back(pointsCM);
564 xrcenter+= pointsCM.
x();
565 yrcenter+= pointsCM.
y();
566 zrcenter+= pointsCM.
z();
568 xrcenter=xrcenter/nUsed;
569 yrcenter=yrcenter/nUsed;
570 zrcenter=zrcenter/nUsed;
574 for(
int ich=0; ich<nComp; ich++){
585 currentVectors.push_back(pointsCM);
587 xccenter+= pointsCM.
x();
588 yccenter+= pointsCM.
y();
589 zccenter+= pointsCM.
z();
591 xccenter=xccenter/nUsed;
592 yccenter=yccenter/nUsed;
593 zccenter=zccenter/nUsed;
599 int nCompR = currentVectors.size();
600 for(
int ich=0; ich<nCompR; ich++){
601 originalRelativeVectors.push_back(originalVectors[ich]-CRef);
602 currentRelativeVectors.push_back(currentVectors[ich]-CCur);
611 originalRelativeVectors);
617 for(
int ich=0; ich<nComp; ich++){
622 CLHEP::Hep3Vector Rtotal, Wtotal;
623 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
624 for (
int i = 0;
i < 100;
i++){
627 CLHEP::Hep3Vector
dR(diff[0],diff[1],diff[2]);
629 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
630 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
631 CLHEP::HepRotation drot(dW.unit(),dW.mag());
633 Wtotal.set(rot.axis().x()*rot.delta(),
634 rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
641 DetId detid(refComp[ich]->
id());
660 change(1)=TotalX.x();
661 change(2)=TotalX.y();
662 change(3)=TotalX.z();
670 const std::vector<Alignable*>& curComp2 = curAli->
components();
672 for(
int ich=0; ich<nComp; ich++){
673 CLHEP::Hep3Vector Rtotal, Wtotal;
674 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
680 for (
int i = 0;
i < 100;
i++){
683 CLHEP::Hep3Vector
dR(diff[0],diff[1],diff[2]);
685 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
686 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
687 CLHEP::HepRotation drot(dW.unit(),dW.mag());
689 Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(),
690 rot.axis().z()*rot.delta());
701 TRtot(1) = Rtotal.x(); TRtot(2) = Rtotal.y(); TRtot(3) = Rtotal.z();
702 TRtot(4) = Wtotal.x(); TRtot(5) = Wtotal.y(); TRtot(6) = Wtotal.z();
779 double detrot=(zz*yy - zy*
yz)*xx + (-zz*yx + zx*yz)*xy + (zy*yx - zx*
yy)*xz;
781 double ixx=(zz*yy - zy*
yz)*detrot;
782 double ixy=(-zz*xy + zy*
xz)*detrot;
783 double ixz=(yz*xy - yy*
xz)*detrot;
784 double iyx=(-zz*yx + zx*
yz)*detrot;
785 double iyy=(zz*xx - zx*
xz)*detrot;
786 double iyz=(-yz*xx + yx*
xz)*detrot;
787 double izx=(zy*yx - zx*
yy)*detrot;
788 double izy=(-zy*xx + zx*
xy)*detrot;
789 double izz=(yy*xx - yx*
xy)*detrot;
794 protx = atan2(prot.
yz(), prot.
zz());
803 if(_drotxVal>3.141592656) _drotxVal=-6.2831853072+
_drotxVal;
804 if(_drotxVal<-3.141592656) _drotxVal=6.2831853072+
_drotxVal;
879 if(ali==0x0)
return false;
880 const std::vector<Alignable*>& aliComp = ali->
components();
882 int size=aliComp.size();
883 if(size<=0)
return false;
894 if(ali==0x0)
return false;
905 std::cout<<
"JNB "<<ali->
id()<<
" "<<cscId.endcap()<<
" " 906 <<cscId.station()<<
" "<<cscId.ring()<<
" "<<cscId.chamber()<<
" " 911 cscId.ring()==
_ring) {
931 if(ali==0x0)
return false;
934 const std::vector<Alignable*>& aliComp = ali->
components();
936 int size=aliComp.size();
937 if(size<=0)
return false;
955 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)
MuonAlignment * inputAlign2a
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.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
virtual Alignables components() const =0
Return vector of all direct components.
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 > &)
std::vector< uint32_t > _detIdFlagVector
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.
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
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
std::vector< MGACollection > _mgacollection