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 =
78 edm::LogInfo(
"MuonGeometryArrange") <<
"levels: " << levels.size();
79 for (
unsigned int l = 0;
l < levels.size(); ++
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];
176 minV=99999999.; maxV=-minV; minI=9999999; maxI=-
minI;
181 for(i=0; i<
size; i++){
186 if(minI>=maxI)
return;
187 xp[
size]=xp[size-1]+1;
190 if(size>maxI) maxI=
size;
192 int sizeI=maxI+1-
minI;
199 for(i=0; i<
size; i++){
207 dxh, grx,
"delX_vs_position",
"Local #delta X vs position",
208 "GdelX_vs_position",
"#delta x in cm", xp, yp, size);
210 minV=99999999.; maxV=-minV;
211 for(i=0; i<
size; i++){
219 dxh, grx,
"delY_vs_position",
"Local #delta Y vs position",
220 "GdelY_vs_position",
"#delta y in cm", xp, yp, size);
223 minV=99999999.; maxV=-minV;
224 for(i=0; i<
size; i++){
232 dxh, grx,
"delZ_vs_position",
"Local #delta Z vs position",
233 "GdelZ_vs_position",
"#delta z in cm", xp, yp, size);
236 minV=99999999.; maxV=-minV;
237 for(i=0; i<
size; i++){
245 dxh, grx,
"delphi_vs_position",
"#delta #phi vs position",
246 "Gdelphi_vs_position",
"#delta #phi in radians", xp, yp, size);
249 minV=99999999.; maxV=-minV;
250 for(i=0; i<
size; i++){
258 dxh, grx,
"delR_vs_position",
"#delta R vs position",
259 "GdelR_vs_position",
"#delta R in cm", xp, yp, size);
262 minV=99999999.; maxV=-minV;
263 for(i=0; i<
size; i++){
265 if(ttemp<minV) minV=ttemp;
266 if(ttemp>maxV) maxV=ttemp;
272 dxh, grx,
"delRphi_vs_position",
"R #delta #phi vs position",
273 "GdelRphi_vs_position",
"R #delta #phi in cm", xp, yp, size);
276 minV=99999999.; maxV=-minV;
277 for(i=0; i<
size; i++){
285 dxh, grx,
"delalpha_vs_position",
"#delta #alpha vs position",
286 "Gdelalpha_vs_position",
"#delta #alpha in rad", xp, yp, size);
289 minV=99999999.; maxV=-minV;
290 for(i=0; i<
size; i++){
298 dxh, grx,
"delbeta_vs_position",
"#delta #beta vs position",
299 "Gdelbeta_vs_position",
"#delta #beta in rad", xp, yp, size);
302 minV=99999999.; maxV=-minV;
303 for(i=0; i<
size; i++){
311 dxh, grx,
"delgamma_vs_position",
"#delta #gamma vs position",
312 "Gdelgamma_vs_position",
"#delta #gamma in rad", xp, yp, size);
315 minV=99999999.; maxV=-minV;
316 for(i=0; i<
size; i++){
324 dxh, grx,
"delrotX_vs_position",
"#delta rotX vs position",
325 "GdelrotX_vs_position",
"#delta rotX in rad", xp, yp, size);
328 minV=99999999.; maxV=-minV;
329 for(i=0; i<
size; i++){
337 dxh, grx,
"delrotY_vs_position",
"#delta rotY vs position",
338 "GdelrotY_vs_position",
"#delta rotY in rad", xp, yp, size);
341 minV=99999999.; maxV=-minV;
342 for(i=0; i<
size; i++){
350 dxh, grx,
"delrotZ_vs_position",
"#delta rotZ vs position",
351 "GdelrotZ_vs_position",
"#delta rotZ in rad", xp, yp, size);
360 float maxR=-9999999.;
361 for(i=0; i<
size; i++){
366 if(ttemp>maxV) maxV=ttemp;
367 if(rtemp>maxR) maxR=rtemp;
371 float smallestVcm=.001;
372 if(maxV<smallestVcm) maxV=smallestVcm;
374 float lside=1.1*maxR;
375 if(lside<=0) lside=100.;
376 if(maxV>0){scale=.09*lside/maxV;}
378 int ret=snprintf(scalename,50,
"#delta #bar{x} length =%f cm",maxV);
382 dxh=
new TH2F(
"vecdrplot",scalename,80,-lside,lside,80,-lside,lside);
385 dxh=
new TH2F(
"vecdrplot",
"delta #bar{x} Bad scale",80,-lside,lside,80,-lside,lside);
387 dxh->GetXaxis()->SetTitle(
"x in cm");
388 dxh->GetYaxis()->SetTitle(
"y in cm");
389 dxh->SetStats(kFALSE);
392 for(i=0; i<
size; i++){
400 arrow->SetLineWidth(2); arrow->SetArrowSize(ttemp*.2*.05/maxV);
401 arrow->SetLineColor(1); arrow->SetLineStyle(1);
403 dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
412 delete [] yp;
delete [] xp;
417 float minV,
float maxV,
418 TH2F* dxh, TGraph* grx,
const char*
name,
const char*
title,
419 const char* titleg,
const char* axis,
420 float* xp,
float* yp,
int size){
422 if(minV>=maxV || smi>=sma || sizeI<=1 || xp==0x0 || yp==0x0)
return;
424 float diff=maxV-minV;
426 double ylo=minV-over;
427 double yhi=maxV+over;
430 dxh=
new TH2F(name, title,
431 sizeI+2, dsmi, dsma, 50, ylo, yhi);
432 dxh->GetXaxis()->SetTitle(
"Position around ring");
433 dxh->GetYaxis()->SetTitle(axis);
434 dxh->SetStats(kFALSE);
436 grx =
new TGraph(size, xp, yp);
437 grx->SetName(titleg);
438 grx->SetTitle(title);
439 grx->SetMarkerColor(2); grx->SetMarkerStyle(3);
440 grx->GetXaxis()->SetLimits(dsmi, dsma);
441 grx->GetXaxis()->SetTitle(
"position number");
442 grx->GetYaxis()->SetLimits(ylo,yhi);
443 grx->GetYaxis()->SetTitle(axis);
495 if(refAli==0x0){
return;}
496 if(curAli==0x0){
return;}
498 const std::vector<Alignable*>& refComp = refAli->
components();
499 const std::vector<Alignable*>& curComp = curAli->
components();
500 const std::vector<Alignable*>& curComp2 = curAliCopy2->
components();
503 int nComp=refComp.size();
504 for(
int i=0;
i<nComp;
i++){
505 compare(refComp[
i], curComp[i], curComp2[i]);
514 if(refAli==0x0){
return;}
515 if(curAli==0x0){
return;}
523 const std::vector<Alignable*>& refComp = refAli->
components();
524 const std::vector<Alignable*>& curComp = curCopy->
components();
525 if(refComp.size()!=curComp.size()){
535 int nComp = refComp.size();
538 CLHEP::Hep3Vector TotalX, TotalL;
539 TotalX.set(0.,0.,0.); TotalL.set(0., 0., 0.);
541 std::vector<CLHEP::Hep3Vector> Positions;
542 std::vector<CLHEP::Hep3Vector> DelPositions;
554 for(
int ich=0; ich<nComp; ich++){
565 originalVectors.push_back(pointsCM);
567 xrcenter+= pointsCM.
x();
568 yrcenter+= pointsCM.
y();
569 zrcenter+= pointsCM.
z();
571 xrcenter=xrcenter/nUsed;
572 yrcenter=yrcenter/nUsed;
573 zrcenter=zrcenter/nUsed;
577 for(
int ich=0; ich<nComp; ich++){
588 currentVectors.push_back(pointsCM);
590 xccenter+= pointsCM.
x();
591 yccenter+= pointsCM.
y();
592 zccenter+= pointsCM.
z();
594 xccenter=xccenter/nUsed;
595 yccenter=yccenter/nUsed;
596 zccenter=zccenter/nUsed;
602 int nCompR = currentVectors.size();
603 for(
int ich=0; ich<nCompR; ich++){
604 originalRelativeVectors.push_back(originalVectors[ich]-CRef);
605 currentRelativeVectors.push_back(currentVectors[ich]-CCur);
614 originalRelativeVectors);
620 for(
int ich=0; ich<nComp; ich++){
625 CLHEP::Hep3Vector Rtotal, Wtotal;
626 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
627 for (
int i = 0;
i < 100;
i++){
630 CLHEP::Hep3Vector
dR(diff[0],diff[1],diff[2]);
632 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
633 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
634 CLHEP::HepRotation drot(dW.unit(),dW.mag());
636 Wtotal.set(rot.axis().x()*rot.delta(),
637 rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
639 float tolerance = 1
e-7;
645 if ((checkR.
mag() > tolerance)||(checkW.
mag() > tolerance)){
663 change(1)=TotalX.x();
664 change(2)=TotalX.y();
665 change(3)=TotalX.z();
673 const std::vector<Alignable*>& curComp2 = curAli->
components();
675 for(
int ich=0; ich<nComp; ich++){
676 CLHEP::Hep3Vector Rtotal, Wtotal;
677 Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
683 for (
int i = 0;
i < 100;
i++){
686 CLHEP::Hep3Vector
dR(diff[0],diff[1],diff[2]);
688 CLHEP::Hep3Vector dW(diff[3],diff[4],diff[5]);
689 CLHEP::HepRotation
rot(Wtotal.unit(),Wtotal.mag());
690 CLHEP::HepRotation drot(dW.unit(),dW.mag());
692 Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(),
693 rot.axis().z()*rot.delta());
695 float tolerance = 1
e-7;
700 if ((checkR.
mag() > tolerance)||(checkW.
mag() > tolerance)){}
704 TRtot(1) = Rtotal.x(); TRtot(2) = Rtotal.y(); TRtot(3) = Rtotal.z();
705 TRtot(4) = Wtotal.x(); TRtot(5) = Wtotal.y(); TRtot(6) = Wtotal.z();
782 double detrot=(zz*yy - zy*yz)*xx + (-zz*yx + zx*yz)*xy + (zy*yx - zx*yy)*xz;
784 double ixx=(zz*yy - zy*yz)*detrot;
785 double ixy=(-zz*xy + zy*xz)*detrot;
786 double ixz=(yz*xy - yy*xz)*detrot;
787 double iyx=(-zz*yx + zx*yz)*detrot;
788 double iyy=(zz*xx - zx*xz)*detrot;
789 double iyz=(-yz*xx + yx*xz)*detrot;
790 double izx=(zy*yx - zx*yy)*detrot;
791 double izy=(-zy*xx + zx*
xy)*detrot;
792 double izz=(yy*xx - yx*
xy)*detrot;
797 protx = atan2(prot.
yz(), prot.
zz());
806 if(_drotxVal>3.141592656) _drotxVal=-6.2831853072+
_drotxVal;
807 if(_drotxVal<-3.141592656) _drotxVal=6.2831853072+
_drotxVal;
882 if(ali==0x0)
return false;
883 const std::vector<Alignable*>& aliComp = ali->
components();
885 int size=aliComp.size();
886 if(size<=0)
return false;
897 if(ali==0x0)
return false;
908 std::cout<<
"JNB "<<ali->
id()<<
" "<<cscId.endcap()<<
" "
909 <<cscId.station()<<
" "<<cscId.ring()<<
" "<<cscId.chamber()<<
" "
914 cscId.ring()==
_ring) {
934 if(ali==0x0)
return false;
937 const std::vector<Alignable*>& aliComp = ali->
components();
939 int size=aliComp.size();
940 if(size<=0)
return false;
958 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 &)
static align::StructureType stringToId(const char *)
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
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