3 #include "CLHEP/Vector/RotationInterfaces.h"
35 #include "CLHEP/Vector/ThreeVector.h"
44 theSurveyIndex(0), _writeToDB(
false), _commonMuonLevel(align::
invalid), firstEvent_(
true)
63 const std::vector<std::string>& levels =
79 edm::LogInfo(
"MuonGeometryArrange") <<
"levels: " << levels.size();
80 for (
unsigned int l = 0;
l < levels.size(); ++
l){
81 theLevels.push_back( dummy.nameToType(levels[
l]));
82 edm::LogInfo(
"MuonGeometryArrange") <<
"level: " << levels[
l];
89 fin.open( _detIdFlagFile.c_str() );
91 while (!fin.eof() && fin.good() ){
101 unsigned int lastID=999999999;
103 std::ifstream inFile;
104 inFile.open( _weightByIdFile.c_str() );
106 while ( !inFile.eof() ){
110 inFile.ignore(256,
'\n');
122 _theFile =
new TFile(_filename.c_str(),
"RECREATE");
123 _alignTree =
new TTree(
"alignTree",
"alignTree");
124 _alignTree->Branch(
"id", &
_id,
"id/I");
125 _alignTree->Branch(
"level", &
_level,
"level/I");
126 _alignTree->Branch(
"mid", &
_mid,
"mid/I");
127 _alignTree->Branch(
"mlevel", &
_mlevel,
"mlevel/I");
128 _alignTree->Branch(
"sublevel", &
_sublevel,
"sublevel/I");
129 _alignTree->Branch(
"x", &
_xVal,
"x/F");
130 _alignTree->Branch(
"y", &
_yVal,
"y/F");
131 _alignTree->Branch(
"z", &
_zVal,
"z/F");
132 _alignTree->Branch(
"r", &
_rVal,
"r/F");
133 _alignTree->Branch(
"phi", &
_phiVal,
"phi/F");
134 _alignTree->Branch(
"eta", &
_etaVal,
"eta/F");
135 _alignTree->Branch(
"alpha", &
_alphaVal,
"alpha/F");
136 _alignTree->Branch(
"beta", &
_betaVal,
"beta/F");
137 _alignTree->Branch(
"gamma", &
_gammaVal,
"gamma/F");
138 _alignTree->Branch(
"dx", &
_dxVal,
"dx/F");
139 _alignTree->Branch(
"dy", &
_dyVal,
"dy/F");
140 _alignTree->Branch(
"dz", &
_dzVal,
"dz/F");
141 _alignTree->Branch(
"dr", &
_drVal,
"dr/F");
142 _alignTree->Branch(
"dphi", &
_dphiVal,
"dphi/F");
143 _alignTree->Branch(
"dalpha", &
_dalphaVal,
"dalpha/F");
144 _alignTree->Branch(
"dbeta", &
_dbetaVal,
"dbeta/F");
145 _alignTree->Branch(
"dgamma", &
_dgammaVal,
"dgamma/F");
146 _alignTree->Branch(
"ldx", &
_ldxVal,
"ldx/F");
147 _alignTree->Branch(
"ldy", &
_ldyVal,
"ldy/F");
148 _alignTree->Branch(
"ldz", &
_ldzVal,
"ldz/F");
149 _alignTree->Branch(
"ldr", &
_ldrVal,
"ldr/F");
150 _alignTree->Branch(
"ldphi", &
_ldphiVal,
"ldphi/F");
151 _alignTree->Branch(
"useDetId", &
_useDetId,
"useDetId/I");
152 _alignTree->Branch(
"detDim", &
_detDim,
"detDim/I");
153 _alignTree->Branch(
"rotx",&
_rotxVal,
"rotx/F");
154 _alignTree->Branch(
"roty",&
_rotyVal,
"roty/F");
155 _alignTree->Branch(
"rotz",&
_rotzVal,
"rotz/F");
156 _alignTree->Branch(
"drotx",&
_drotxVal,
"drotx/F");
157 _alignTree->Branch(
"droty",&
_drotyVal,
"droty/F");
158 _alignTree->Branch(
"drotz",&
_drotzVal,
"drotz/F");
159 _alignTree->Branch(
"surW", &
_surWidth,
"surW/F");
160 _alignTree->Branch(
"surL", &
_surLength,
"surL/F");
161 _alignTree->Branch(
"surRot", &
_surRot,
"surRot[9]/D");
171 float* xp =
new float[size+1];
172 float* yp =
new float[size+1];
177 minV=99999999.; maxV=-minV; minI=9999999; maxI=-
minI;
182 for(i=0; i<
size; i++){
187 if(minI>=maxI)
return;
188 xp[
size]=xp[size-1]+1;
191 if(size>maxI) maxI=
size;
193 int sizeI=maxI+1-
minI;
200 for(i=0; i<
size; i++){
208 dxh, grx,
"delX_vs_position",
"Local #delta X vs position",
209 "GdelX_vs_position",
"#delta x in cm", xp, yp, size);
211 minV=99999999.; maxV=-minV;
212 for(i=0; i<
size; i++){
220 dxh, grx,
"delY_vs_position",
"Local #delta Y vs position",
221 "GdelY_vs_position",
"#delta y in cm", xp, yp, size);
224 minV=99999999.; maxV=-minV;
225 for(i=0; i<
size; i++){
233 dxh, grx,
"delZ_vs_position",
"Local #delta Z vs position",
234 "GdelZ_vs_position",
"#delta z in cm", xp, yp, size);
237 minV=99999999.; maxV=-minV;
238 for(i=0; i<
size; i++){
246 dxh, grx,
"delphi_vs_position",
"#delta #phi vs position",
247 "Gdelphi_vs_position",
"#delta #phi in radians", xp, yp, size);
250 minV=99999999.; maxV=-minV;
251 for(i=0; i<
size; i++){
259 dxh, grx,
"delR_vs_position",
"#delta R vs position",
260 "GdelR_vs_position",
"#delta R in cm", xp, yp, size);
263 minV=99999999.; maxV=-minV;
264 for(i=0; i<
size; i++){
266 if(ttemp<minV) minV=ttemp;
267 if(ttemp>maxV) maxV=ttemp;
273 dxh, grx,
"delRphi_vs_position",
"R #delta #phi vs position",
274 "GdelRphi_vs_position",
"R #delta #phi in cm", xp, yp, size);
277 minV=99999999.; maxV=-minV;
278 for(i=0; i<
size; i++){
286 dxh, grx,
"delalpha_vs_position",
"#delta #alpha vs position",
287 "Gdelalpha_vs_position",
"#delta #alpha in rad", xp, yp, size);
290 minV=99999999.; maxV=-minV;
291 for(i=0; i<
size; i++){
299 dxh, grx,
"delbeta_vs_position",
"#delta #beta vs position",
300 "Gdelbeta_vs_position",
"#delta #beta in rad", xp, yp, size);
303 minV=99999999.; maxV=-minV;
304 for(i=0; i<
size; i++){
312 dxh, grx,
"delgamma_vs_position",
"#delta #gamma vs position",
313 "Gdelgamma_vs_position",
"#delta #gamma in rad", xp, yp, size);
316 minV=99999999.; maxV=-minV;
317 for(i=0; i<
size; i++){
325 dxh, grx,
"delrotX_vs_position",
"#delta rotX vs position",
326 "GdelrotX_vs_position",
"#delta rotX in rad", xp, yp, size);
329 minV=99999999.; maxV=-minV;
330 for(i=0; i<
size; i++){
338 dxh, grx,
"delrotY_vs_position",
"#delta rotY vs position",
339 "GdelrotY_vs_position",
"#delta rotY in rad", xp, yp, size);
342 minV=99999999.; maxV=-minV;
343 for(i=0; i<
size; i++){
351 dxh, grx,
"delrotZ_vs_position",
"#delta rotZ vs position",
352 "GdelrotZ_vs_position",
"#delta rotZ in rad", xp, yp, size);
361 float maxR=-9999999.;
362 for(i=0; i<
size; i++){
367 if(ttemp>maxV) maxV=ttemp;
368 if(rtemp>maxR) maxR=rtemp;
372 float smallestVcm=.001;
373 if(maxV<smallestVcm) maxV=smallestVcm;
375 float lside=1.1*maxR;
376 if(lside<=0) lside=100.;
377 if(maxV>0){scale=.09*lside/maxV;}
379 int ret=snprintf(scalename,50,
"#delta #bar{x} length =%f cm",maxV);
383 dxh=
new TH2F(
"vecdrplot",scalename,80,-lside,lside,80,-lside,lside);
386 dxh=
new TH2F(
"vecdrplot",
"delta #bar{x} Bad scale",80,-lside,lside,80,-lside,lside);
388 dxh->GetXaxis()->SetTitle(
"x in cm");
389 dxh->GetYaxis()->SetTitle(
"y in cm");
390 dxh->SetStats(kFALSE);
393 for(i=0; i<
size; i++){
401 arrow->SetLineWidth(2); arrow->SetArrowSize(ttemp*.2*.05/maxV);
402 arrow->SetLineColor(1); arrow->SetLineStyle(1);
404 dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
413 delete [] yp;
delete [] xp;
418 float minV,
float maxV,
419 TH2F* dxh, TGraph* grx,
const char*
name,
const char*
title,
420 const char* titleg,
const char* axis,
421 float* xp,
float* yp,
int size){
423 if(minV>=maxV || smi>=sma || sizeI<=1 || xp==0x0 || yp==0x0)
return;
425 float diff=maxV-minV;
427 double ylo=minV-over;
428 double yhi=maxV+over;
431 dxh=
new TH2F(name, title,
432 sizeI+2, dsmi, dsma, 50, ylo, yhi);
433 dxh->GetXaxis()->SetTitle(
"Position around ring");
434 dxh->GetYaxis()->SetTitle(axis);
435 dxh->SetStats(kFALSE);
437 grx =
new TGraph(size, xp, yp);
438 grx->SetName(titleg);
439 grx->SetTitle(title);
440 grx->SetMarkerColor(2); grx->SetMarkerStyle(3);
441 grx->GetXaxis()->SetLimits(dsmi, dsma);
442 grx->GetXaxis()->SetTitle(
"position number");
443 grx->GetYaxis()->SetLimits(ylo,yhi);
444 grx->GetYaxis()->SetTitle(axis);
496 if(refAli==0x0){
return;}
497 if(curAli==0x0){
return;}
499 const std::vector<Alignable*>& refComp = refAli->
components();
500 const std::vector<Alignable*>& curComp = curAli->
components();
501 const std::vector<Alignable*>& curComp2 = curAliCopy2->
components();
504 int nComp=refComp.size();
505 for(
int i=0;
i<nComp;
i++){
506 compare(refComp[
i], curComp[i], curComp2[i]);
515 if(refAli==0x0){
return;}
516 if(curAli==0x0){
return;}
524 const std::vector<Alignable*>& refComp = refAli->
components();
525 const std::vector<Alignable*>& curComp = curCopy->
components();
526 if(refComp.size()!=curComp.size()){
536 int nComp = refComp.size();
539 CLHEP::Hep3Vector TotalX, TotalL;
540 TotalX.set(0.,0.,0.); TotalL.set(0., 0., 0.);
542 std::vector<CLHEP::Hep3Vector> Positions;
543 std::vector<CLHEP::Hep3Vector> DelPositions;
555 for(
int ich=0; ich<nComp; ich++){
566 originalVectors.push_back(pointsCM);
568 xrcenter+= pointsCM.
x();
569 yrcenter+= pointsCM.
y();
570 zrcenter+= pointsCM.
z();
572 xrcenter=xrcenter/nUsed;
573 yrcenter=yrcenter/nUsed;
574 zrcenter=zrcenter/nUsed;
578 for(
int ich=0; ich<nComp; ich++){
589 currentVectors.push_back(pointsCM);
591 xccenter+= pointsCM.
x();
592 yccenter+= pointsCM.
y();
593 zccenter+= pointsCM.
z();
595 xccenter=xccenter/nUsed;
596 yccenter=yccenter/nUsed;
597 zccenter=zccenter/nUsed;
603 int nCompR = currentVectors.size();
604 for(
int ich=0; ich<nCompR; ich++){
605 originalRelativeVectors.push_back(originalVectors[ich]-CRef);
606 currentRelativeVectors.push_back(currentVectors[ich]-CCur);
615 originalRelativeVectors);
621 for(
int ich=0; ich<nComp; ich++){
626 CLHEP::Hep3Vector Rtotal, Wtotal;
627 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
628 for (
int i = 0;
i < 100;
i++){
631 CLHEP::Hep3Vector
dR(diff[0],diff[1],diff[2]);
633 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
634 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
635 CLHEP::HepRotation drot(dW.unit(),dW.mag());
637 Wtotal.set(rot.axis().x()*rot.delta(),
638 rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
640 float tolerance = 1
e-7;
646 if ((checkR.
mag() > tolerance)||(checkW.
mag() > tolerance)){
664 change(1)=TotalX.x();
665 change(2)=TotalX.y();
666 change(3)=TotalX.z();
674 const std::vector<Alignable*>& curComp2 = curAli->
components();
676 for(
int ich=0; ich<nComp; ich++){
677 CLHEP::Hep3Vector Rtotal, Wtotal;
678 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
684 for (
int i = 0;
i < 100;
i++){
687 CLHEP::Hep3Vector
dR(diff[0],diff[1],diff[2]);
689 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
690 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
691 CLHEP::HepRotation drot(dW.unit(),dW.mag());
693 Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(),
694 rot.axis().z()*rot.delta());
696 float tolerance = 1
e-7;
701 if ((checkR.
mag() > tolerance)||(checkW.
mag() > tolerance)){}
705 TRtot(1) = Rtotal.x(); TRtot(2) = Rtotal.y(); TRtot(3) = Rtotal.z();
706 TRtot(4) = Wtotal.x(); TRtot(5) = Wtotal.y(); TRtot(6) = Wtotal.z();
783 double detrot=(zz*yy - zy*yz)*xx + (-zz*yx + zx*yz)*xy + (zy*yx - zx*yy)*xz;
785 double ixx=(zz*yy - zy*yz)*detrot;
786 double ixy=(-zz*xy + zy*xz)*detrot;
787 double ixz=(yz*xy - yy*xz)*detrot;
788 double iyx=(-zz*yx + zx*yz)*detrot;
789 double iyy=(zz*xx - zx*xz)*detrot;
790 double iyz=(-yz*xx + yx*xz)*detrot;
791 double izx=(zy*yx - zx*yy)*detrot;
792 double izy=(-zy*xx + zx*
xy)*detrot;
793 double izz=(yy*xx - yx*
xy)*detrot;
798 protx = atan2(prot.
yz(), prot.
zz());
807 if(_drotxVal>3.141592656) _drotxVal=-6.2831853072+
_drotxVal;
808 if(_drotxVal<-3.141592656) _drotxVal=6.2831853072+
_drotxVal;
883 if(ali==0x0)
return false;
884 const std::vector<Alignable*>& aliComp = ali->
components();
886 int size=aliComp.size();
887 if(size<=0)
return false;
898 if(ali==0x0)
return false;
909 std::cout<<
"JNB "<<ali->
id()<<
" "<<cscId.endcap()<<
" "
910 <<cscId.station()<<
" "<<cscId.ring()<<
" "<<cscId.chamber()<<
" "
915 cscId.ring()==
_ring) {
935 if(ali==0x0)
return false;
938 const std::vector<Alignable*>& aliComp = ali->
components();
940 int size=aliComp.size();
941 if(size<=0)
return false;
959 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.
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