CMS 3D CMS Logo

MuonGeometryArrange.cc
Go to the documentation of this file.
3 #include "CLHEP/Vector/RotationInterfaces.h"
5 
10 
12 
16 // The following looks generic enough to use
24 
27 
28 #include "MuonGeometryArrange.h"
29 #include "TFile.h"
30 #include "TLatex.h"
31 #include "TArrow.h"
32 #include "TGraph.h"
33 #include "TH1F.h"
34 #include "TH2F.h"
35 #include "CLHEP/Vector/ThreeVector.h"
36 
37 // Database
39 
40 #include <iostream>
41 #include <fstream>
42 
44  theSurveyIndex(0),
45  _levelStrings(cfg.getUntrackedParameter<std::vector<std::string> >("levels")),
46  _writeToDB(false), _commonMuonLevel(align::invalid), firstEvent_(true)
47 {
48  referenceMuon=0x0;
49  currentMuon=0x0;
50  // Input is XML
51  _inputXMLCurrent = cfg.getUntrackedParameter<std::string> ("inputXMLCurrent");
52  _inputXMLReference = cfg.getUntrackedParameter<std::string> ("inputXMLReference");
53 
54  //input is ROOT
56  ("inputROOTFile1");
58  ("inputROOTFile2");
59  _inputTreename = cfg.getUntrackedParameter< std::string > ("treeName");
60 
61  //output file
62  _filename = cfg.getUntrackedParameter< std::string > ("outputFile");
63 
64 
65  _weightBy = cfg.getUntrackedParameter< std::string > ("weightBy");
66  _detIdFlag = cfg.getUntrackedParameter< bool > ("detIdFlag");
68  ("detIdFlagFile");
69  _weightById = cfg.getUntrackedParameter< bool > ("weightById");
71  ("weightByIdFile");
72  _endcap = cfg.getUntrackedParameter<int> ("endcapNumber");
73  _station = cfg.getUntrackedParameter<int> ("stationNumber");
74  _ring = cfg.getUntrackedParameter<int> ("ringNumber");
75 
76 
77  // if want to use, make id cut list
78  if (_detIdFlag){
79  std::ifstream fin;
80  fin.open( _detIdFlagFile.c_str() );
81 
82  while (!fin.eof() && fin.good() ){
83 
84  uint32_t id;
85  fin >> id;
86  _detIdFlagVector.push_back(id);
87  }
88  fin.close();
89  }
90 
91  // turn weightByIdFile into weightByIdVector
92  unsigned int lastID=999999999;
93  if (_weightById){
94  std::ifstream inFile;
95  inFile.open( _weightByIdFile.c_str() );
96  int ctr = 0;
97  while ( !inFile.eof() ){
98  ctr++;
99  unsigned int listId;
100  inFile >> listId;
101  inFile.ignore(256, '\n');
102  if(listId!=lastID){
103  _weightByIdVector.push_back( listId );
104  }
105  lastID=listId;
106  }
107  inFile.close();
108  }
109 
110 
111 
112  //root configuration
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");
153 
154  _mgacollection.clear();
155 }
158  // Unpack the list and create ntuples here.
159 
160  int size=_mgacollection.size();
161  if(size<=0) return; // nothing to do here.
162  std::vector<float> xp(size+1);
163  std::vector<float> yp(size+1);
164  int i;
165  float minV, maxV;
166  int minI, maxI;
167 
168  minV=99999999.; maxV=-minV; minI=9999999; maxI=-minI;
169  TGraph* grx=0x0;
170  TH2F* dxh=0x0;
171 
172 // for position plots:
173  for(i=0; i<size; i++){
174  if(_mgacollection[i].phipos<minI) minI=_mgacollection[i].phipos;
175  if(_mgacollection[i].phipos>maxI) maxI=_mgacollection[i].phipos;
176  xp[i]=_mgacollection[i].phipos;
177  }
178  if(minI>=maxI) return; // can't do anything?
179  xp[size]=xp[size-1]+1; // wraparound point
180 
181  if(1<minI) minI=1;
182  if(size>maxI) maxI=size;
183  maxI++; // allow for wraparound to show neighbors
184  int sizeI=maxI+1-minI;
185  float smi=minI-1;
186  float sma=maxI+1;
187 
188 
189 // Dx plot
190 
191  for(i=0; i<size; i++){
192  if(_mgacollection[i].ldx<minV) minV=_mgacollection[i].ldx;
193  if(_mgacollection[i].ldx>maxV) maxV=_mgacollection[i].ldx;
194  yp[i]=_mgacollection[i].ldx;
195  }
196  yp[size]=yp[0]; // wraparound point
197 
198  makeGraph(sizeI, smi, sma, minV, maxV,
199  dxh, grx, "delX_vs_position", "Local #delta X vs position",
200  "GdelX_vs_position","#delta x in cm", xp.data(), yp.data(), size);
201 // Dy plot
202  minV=99999999.; maxV=-minV;
203  for(i=0; i<size; i++){
204  if(_mgacollection[i].ldy<minV) minV=_mgacollection[i].ldy;
205  if(_mgacollection[i].ldy>maxV) maxV=_mgacollection[i].ldy;
206  yp[i]=_mgacollection[i].ldy;
207  }
208  yp[size]=yp[0]; // wraparound point
209 
210  makeGraph(sizeI, smi, sma, minV, maxV,
211  dxh, grx, "delY_vs_position", "Local #delta Y vs position",
212  "GdelY_vs_position","#delta y in cm", xp.data(), yp.data(), size);
213 
214 // Dz plot
215  minV=99999999.; maxV=-minV;
216  for(i=0; i<size; i++){
217  if(_mgacollection[i].dz<minV) minV=_mgacollection[i].dz;
218  if(_mgacollection[i].dz>maxV) maxV=_mgacollection[i].dz;
219  yp[i]=_mgacollection[i].dz;
220  }
221  yp[size]=yp[0]; // wraparound point
222 
223  makeGraph(sizeI, smi, sma, minV, maxV,
224  dxh, grx, "delZ_vs_position", "Local #delta Z vs position",
225  "GdelZ_vs_position","#delta z in cm", xp.data(), yp.data(), size);
226 
227 // Dphi plot
228  minV=99999999.; maxV=-minV;
229  for(i=0; i<size; i++){
230  if(_mgacollection[i].dphi<minV) minV=_mgacollection[i].dphi;
231  if(_mgacollection[i].dphi>maxV) maxV=_mgacollection[i].dphi;
232  yp[i]=_mgacollection[i].dphi;
233  }
234  yp[size]=yp[0]; // wraparound point
235 
236  makeGraph(sizeI, smi, sma, minV, maxV,
237  dxh, grx, "delphi_vs_position", "#delta #phi vs position",
238  "Gdelphi_vs_position","#delta #phi in radians", xp.data(), yp.data(), size);
239 
240 // Dr plot
241  minV=99999999.; maxV=-minV;
242  for(i=0; i<size; i++){
243  if(_mgacollection[i].dr<minV) minV=_mgacollection[i].dr;
244  if(_mgacollection[i].dr>maxV) maxV=_mgacollection[i].dr;
245  yp[i]=_mgacollection[i].dr;
246  }
247  yp[size]=yp[0]; // wraparound point
248 
249  makeGraph(sizeI, smi, sma, minV, maxV,
250  dxh, grx, "delR_vs_position", "#delta R vs position",
251  "GdelR_vs_position","#delta R in cm", xp.data(), yp.data(), size);
252 
253 // Drphi plot
254  minV=99999999.; maxV=-minV;
255  for(i=0; i<size; i++){
256  float ttemp=_mgacollection[i].r*_mgacollection[i].dphi;
257  if(ttemp<minV) minV=ttemp;
258  if(ttemp>maxV) maxV=ttemp;
259  yp[i]=ttemp;
260  }
261  yp[size]=yp[0]; // wraparound point
262 
263  makeGraph(sizeI, smi, sma, minV, maxV,
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);
266 
267 // Dalpha plot
268  minV=99999999.; maxV=-minV;
269  for(i=0; i<size; i++){
270  if(_mgacollection[i].dalpha<minV) minV=_mgacollection[i].dalpha;
271  if(_mgacollection[i].dalpha>maxV) maxV=_mgacollection[i].dalpha;
272  yp[i]=_mgacollection[i].dalpha;
273  }
274  yp[size]=yp[0]; // wraparound point
275 
276  makeGraph(sizeI, smi, sma, minV, maxV,
277  dxh, grx, "delalpha_vs_position", "#delta #alpha vs position",
278  "Gdelalpha_vs_position","#delta #alpha in rad", xp.data(), yp.data(), size);
279 
280 // Dbeta plot
281  minV=99999999.; maxV=-minV;
282  for(i=0; i<size; i++){
283  if(_mgacollection[i].dbeta<minV) minV=_mgacollection[i].dbeta;
284  if(_mgacollection[i].dbeta>maxV) maxV=_mgacollection[i].dbeta;
285  yp[i]=_mgacollection[i].dbeta;
286  }
287  yp[size]=yp[0]; // wraparound point
288 
289  makeGraph(sizeI, smi, sma, minV, maxV,
290  dxh, grx, "delbeta_vs_position", "#delta #beta vs position",
291  "Gdelbeta_vs_position","#delta #beta in rad", xp.data(), yp.data(), size);
292 
293 // Dgamma plot
294  minV=99999999.; maxV=-minV;
295  for(i=0; i<size; i++){
296  if(_mgacollection[i].dgamma<minV) minV=_mgacollection[i].dgamma;
297  if(_mgacollection[i].dgamma>maxV) maxV=_mgacollection[i].dgamma;
298  yp[i]=_mgacollection[i].dgamma;
299  }
300  yp[size]=yp[0]; // wraparound point
301 
302  makeGraph(sizeI, smi, sma, minV, maxV,
303  dxh, grx, "delgamma_vs_position", "#delta #gamma vs position",
304  "Gdelgamma_vs_position","#delta #gamma in rad", xp.data(), yp.data(), size);
305 
306 // Drotx plot
307  minV=99999999.; maxV=-minV;
308  for(i=0; i<size; i++){
309  if(_mgacollection[i].drotx<minV) minV=_mgacollection[i].drotx;
310  if(_mgacollection[i].drotx>maxV) maxV=_mgacollection[i].drotx;
311  yp[i]=_mgacollection[i].drotx;
312  }
313  yp[size]=yp[0]; // wraparound point
314 
315  makeGraph(sizeI, smi, sma, minV, maxV,
316  dxh, grx, "delrotX_vs_position", "#delta rotX vs position",
317  "GdelrotX_vs_position","#delta rotX in rad", xp.data(), yp.data(), size);
318 
319 // Droty plot
320  minV=99999999.; maxV=-minV;
321  for(i=0; i<size; i++){
322  if(_mgacollection[i].droty<minV) minV=_mgacollection[i].droty;
323  if(_mgacollection[i].droty>maxV) maxV=_mgacollection[i].droty;
324  yp[i]=_mgacollection[i].droty;
325  }
326  yp[size]=yp[0]; // wraparound point
327 
328  makeGraph(sizeI, smi, sma, minV, maxV,
329  dxh, grx, "delrotY_vs_position", "#delta rotY vs position",
330  "GdelrotY_vs_position","#delta rotY in rad", xp.data(), yp.data(), size);
331 
332 // Drotz plot
333  minV=99999999.; maxV=-minV;
334  for(i=0; i<size; i++){
335  if(_mgacollection[i].drotz<minV) minV=_mgacollection[i].drotz;
336  if(_mgacollection[i].drotz>maxV) maxV=_mgacollection[i].drotz;
337  yp[i]=_mgacollection[i].drotz;
338  }
339  yp[size]=yp[0]; // wraparound point
340 
341  makeGraph(sizeI, smi, sma, minV, maxV,
342  dxh, grx, "delrotZ_vs_position", "#delta rotZ vs position",
343  "GdelrotZ_vs_position","#delta rotZ in rad", xp.data(), yp.data(), size);
344 
345 
346 
347 // Vector plots
348 // First find the maximum length of sqrt(dx*dx+dy*dy): we'll have to
349 // scale these for visibility
350  maxV=-99999999.;
351  float ttemp, rtemp;
352  float maxR=-9999999.;
353  for(i=0; i<size; i++){
354  ttemp= sqrt(_mgacollection[i].dx*_mgacollection[i].dx+
356  rtemp= sqrt(_mgacollection[i].x*_mgacollection[i].x+
358  if(ttemp>maxV) maxV=ttemp;
359  if(rtemp>maxR) maxR=rtemp;
360  }
361 
362  // Don't try to scale rediculously small values
363  float smallestVcm=.001; // 10 microns
364  if(maxV<smallestVcm) maxV=smallestVcm;
365  float scale=0.;
366  float lside=1.1*maxR;
367  if(lside<=0) lside=100.;
368  if(maxV>0){scale=.09*lside/maxV;} // units of pad length!
369  char scalename[50];
370  int ret=snprintf(scalename,50,"#delta #bar{x} length =%f cm",maxV);
371  // If ret<=0 we don't want to print the scale!
372 
373  if(ret>0){
374  dxh=new TH2F("vecdrplot",scalename,80,-lside,lside,80,-lside,lside);
375  }
376  else{
377  dxh=new TH2F("vecdrplot","delta #bar{x} Bad scale",80,-lside,lside,80,-lside,lside);
378  }
379  dxh->GetXaxis()->SetTitle("x in cm");
380  dxh->GetYaxis()->SetTitle("y in cm");
381  dxh->SetStats(kFALSE);
382  dxh->Draw();
383  TArrow* arrow;
384  for(i=0; i<size; i++){
385  ttemp= sqrt(_mgacollection[i].dx*_mgacollection[i].dx+
387 // ttemp=ttemp*scale;
388  float nx=_mgacollection[i].x+scale*_mgacollection[i].dx;
389  float ny=_mgacollection[i].y+scale*_mgacollection[i].dy;
390  arrow = new TArrow(_mgacollection[i].x,
391  _mgacollection[i].y, nx, ny);// ttemp*.3*.05, "->");
392  arrow->SetLineWidth(2); arrow->SetArrowSize(ttemp*.2*.05/maxV);
393  arrow->SetLineColor(1); arrow->SetLineStyle(1);
394  arrow->Paint();
395  dxh->GetListOfFunctions()->Add(static_cast<TObject*>(arrow));
396 // arrow->Draw();
397 // arrow->Write();
398  }
399  dxh->Write();
400 
401  _theFile->Write();
402  _theFile->Close();
403 
404 
405 }
407 void MuonGeometryArrange::makeGraph(int sizeI, float smi, float sma,
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){
412 
413  if(minV>=maxV || smi>=sma || sizeI<=1 || xp==0x0 || yp==0x0) return;
414  // out of bounds, bail
415  float diff=maxV-minV;
416  float over=.05*diff;
417  double ylo=minV-over;
418  double yhi=maxV+over;
419  double dsmi, dsma;
420  dsmi=smi; dsma=sma;
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);
426  dxh->Draw();
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);
435  grx->Draw("A*");
436  grx->Write();
437  return;
438 }
441  firstEvent_ = true;
442 }
443 
448  const edm::EventSetup& iSetup){
449  if (firstEvent_) {
450 
451  // My stuff
453  inputAlign1 = new MuonAlignment(iSetup, inputMethod1);
456  inputAlign2 = new MuonAlignment(iSetup, inputMethod2);
459  inputAlign2a = new MuonAlignment(iSetup, inputMethod3);
461 
464  auto inputGeometry2Copy2 = inputAlign2a->getAlignableMuon();
465 
466  //setting the levels being used in the geometry comparator
467  edm::LogInfo("MuonGeometryArrange") << "levels: " << _levelStrings.size();
468  for (const auto& level: _levelStrings){
469  theLevels.push_back(inputGeometry2Copy2->objectIdProvider().stringToId(level));
470  edm::LogInfo("MuonGeometryArrange") << "level: " << level;
471  }
472 
473  //compare the goemetries
474  compare(inputGeometry1, inputGeometry2, inputGeometry2Copy2);
475 
476  //write out ntuple
477  //might be better to do within output module
478  _theFile->cd();
479  _alignTree->Write();
480  endHist();
481  // _theFile->Close();
482 
483  firstEvent_ = false;
484  }
485 }
486 
489  Alignable* curAliCopy2){
490 
491  // First sanity
492  if(refAli==0x0){return;}
493  if(curAli==0x0){return;}
494 
495  const std::vector<Alignable*>& refComp = refAli->components();
496  const std::vector<Alignable*>& curComp = curAli->components();
497  const std::vector<Alignable*>& curComp2 = curAliCopy2->components();
498  compareGeometries(refAli, curAli, curAliCopy2);
499 
500  int nComp=refComp.size();
501  for(int i=0; i<nComp; i++){
502  compare(refComp[i], curComp[i], curComp2[i]);
503  }
504  return;
505 }
506 
509  Alignable* curAli, Alignable* curCopy){
510  // First sanity
511  if(refAli==0x0){return;}
512  if(curAli==0x0){return;}
513  // Is this the Ring we want to align? If so it will contain the
514  // chambers specified in the configuration file
515  if(!isMother(refAli)) return; // Not the desired alignable object
516  // But... There are granddaughters involved--and I don't want to monkey with
517  // the layers of the chambers. So, if the mother of this is also an approved
518  // mother, bail.
519  if(isMother(refAli->mother() )) return;
520  const std::vector<Alignable*>& refComp = refAli->components();
521  const std::vector<Alignable*>& curComp = curCopy->components();
522  if(refComp.size()!=curComp.size()){
523  return;
524  }
525  // GlobalVectors is a vector of GlobalVector which is a 3D vector
526  align::GlobalVectors originalVectors;
527  align::GlobalVectors currentVectors;
528  align::GlobalVectors originalRelativeVectors;
529  align::GlobalVectors currentRelativeVectors;
530 
531 
532  int nComp = refComp.size();
533  int nUsed = 0;
534  // Use the total displacements here:
535  CLHEP::Hep3Vector TotalX, TotalL;
536  TotalX.set(0.,0.,0.); TotalL.set(0., 0., 0.);
537 // CLHEP::Hep3Vector* Rsubtotal, Wsubtotal, DRsubtotal, DWsubtotal;
538  std::vector<CLHEP::Hep3Vector> Positions;
539  std::vector<CLHEP::Hep3Vector> DelPositions;
540 
541  double xrcenter=0.;
542  double yrcenter=0.;
543  double zrcenter=0.;
544  double xccenter=0.;
545  double yccenter=0.;
546  double zccenter=0.;
547 
548  bool useIt;
549  // Create the "center" for the reference alignment chambers, and
550  // load a vector of their centers
551  for(int ich=0; ich<nComp; ich++){
552  useIt=true;
553  if(_weightById){
554  if(!align::readModuleList(curComp[ich]->id(), curComp[ich]->id(), _weightByIdVector))
555  useIt=false;
556  }
557  if(!useIt) continue;
558  align::GlobalVectors curVs;
559  align::createPoints(&curVs, refComp[ich],
561  align::GlobalVector pointsCM = align::centerOfMass(curVs);
562  originalVectors.push_back(pointsCM);
563  nUsed++;
564  xrcenter+= pointsCM.x();
565  yrcenter+= pointsCM.y();
566  zrcenter+= pointsCM.z();
567  }
568  xrcenter=xrcenter/nUsed;
569  yrcenter=yrcenter/nUsed;
570  zrcenter=zrcenter/nUsed;
571 
572  // Create the "center" for the current alignment chambers, and
573  // load a vector of their centers
574  for(int ich=0; ich<nComp; ich++){
575  useIt=true;
576  if(_weightById){
577  if(!align::readModuleList(curComp[ich]->id(), curComp[ich]->id(), _weightByIdVector))
578  useIt=false;
579  }
580  if(!useIt)continue;
581  align::GlobalVectors curVs;
582  align::createPoints(&curVs, curComp[ich],
584  align::GlobalVector pointsCM = align::centerOfMass(curVs);
585  currentVectors.push_back(pointsCM);
586 
587  xccenter+= pointsCM.x();
588  yccenter+= pointsCM.y();
589  zccenter+= pointsCM.z();
590  }
591  xccenter=xccenter/nUsed;
592  yccenter=yccenter/nUsed;
593  zccenter=zccenter/nUsed;
594 
595 
596  // OK, now load the <very approximate> vectors from the ring "centers"
597  align::GlobalVector CCur(xccenter, yccenter, zccenter);
598  align::GlobalVector CRef(xrcenter, yrcenter, zrcenter);
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);
603  }
604 
605  // All right. Now let the hacking begin.
606  // First out of the gate let's try using the raw values and see what
607  // diffRot does for us.
608 
609 
610  align::RotationType rtype3=align::diffRot(currentRelativeVectors,
611  originalRelativeVectors);
612 
613 
615  angles = align::toAngles(rtype3);
616 
617  for(int ich=0; ich<nComp; ich++){
618  if(_weightById){
619  if(!align::readModuleList(curComp[ich]->id(), curComp[ich]->id(), _weightByIdVector))
620  continue;
621  }
622  CLHEP::Hep3Vector Rtotal, Wtotal;
623  Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
624  for (int i = 0; i < 100; i++){
625  AlgebraicVector diff = align::diffAlignables(refComp[ich],curComp[ich],
627  CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
628  Rtotal+=dR;
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());
632  rot*=drot;
633  Wtotal.set(rot.axis().x()*rot.delta(),
634  rot.axis().y()*rot.delta(), rot.axis().z()*rot.delta());
635  align::moveAlignable(curComp[ich], diff);
636  float tolerance = 1e-7;
637  AlgebraicVector check = align::diffAlignables(refComp[ich],curComp[ich],
639  align::GlobalVector checkR(check[0],check[1],check[2]);
640  align::GlobalVector checkW(check[3],check[4],check[5]);
641  DetId detid(refComp[ich]->id());
642  if ((checkR.mag() > tolerance)||(checkW.mag() > tolerance)){
643 // edm::LogInfo("CompareGeoms") << "Tolerance Exceeded!(alObjId: "
644 // << refAli->alignableObjectId()
645 // << ", rawId: " << refComp[ich]->geomDetId().rawId()
646 // << ", subdetId: "<< detid.subdetId() << "): " << diff;
647  }
648  else{
649  TotalX+=Rtotal;
650  break;
651  } // end of else
652  } // end of for on int i
653  } // end of for on ich
654 
655  // At this point we should have a total displacement and total L
656  TotalX=TotalX/nUsed;
657 
658  // Now start again!
659  AlgebraicVector change(6);
660  change(1)=TotalX.x();
661  change(2)=TotalX.y();
662  change(3)=TotalX.z();
663 
664  change(4)=angles[0];
665  change(5)=angles[1];
666  change(6)=angles[2];
667  align::moveAlignable(curAli, change); // move as a chunk
668 
669  // Now get the components again. They should be in new locations
670  const std::vector<Alignable*>& curComp2 = curAli->components();
671 
672  for(int ich=0; ich<nComp; ich++){
673  CLHEP::Hep3Vector Rtotal, Wtotal;
674  Rtotal.set(0.,0.,0.); Wtotal.set(0.,0.,0.);
675  if(_weightById){
676  if(!align::readModuleList(curComp[ich]->id(), curComp[ich]->id(), _weightByIdVector))
677  continue;
678  }
679 
680  for (int i = 0; i < 100; i++){
681  AlgebraicVector diff = align::diffAlignables(refComp[ich],curComp2[ich],
683  CLHEP::Hep3Vector dR(diff[0],diff[1],diff[2]);
684  Rtotal+=dR;
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());
688  rot*=drot;
689  Wtotal.set(rot.axis().x()*rot.delta(), rot.axis().y()*rot.delta(),
690  rot.axis().z()*rot.delta());
691  align::moveAlignable(curComp2[ich], diff);
692  float tolerance = 1e-7;
693  AlgebraicVector check = align::diffAlignables(refComp[ich],curComp2[ich],
695  align::GlobalVector checkR(check[0],check[1],check[2]);
696  align::GlobalVector checkW(check[3],check[4],check[5]);
697  if ((checkR.mag() > tolerance)||(checkW.mag() > tolerance)){}
698  else{break;}
699  } // end of for on int i
700  AlgebraicVector TRtot(6);
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();
703  fillTree(refComp[ich], TRtot);
704  } // end of for on ich
705 
706 
707 
708 }
709 
711 
713 
714 
715  _id = refAli->id();
716  _level = refAli->alignableObjectId();
717  //need if ali has no mother
718  if (refAli->mother()){
719  _mid = refAli->mother()->geomDetId().rawId();
720  _mlevel = refAli->mother()->alignableObjectId();
721  }
722  else{
723  _mid = -1;
724  _mlevel = -1;
725  }
726  DetId detid(_id);
727  _sublevel = detid.subdetId();
728  int ringPhiPos=-99;
729  if(detid.det()==DetId::Muon && detid.subdetId()== MuonSubdetId::CSC){
730  CSCDetId cscId(refAli->geomDetId());
731  ringPhiPos = cscId.chamber();
732  }
733  _xVal = refAli->globalPosition().x();
734  _yVal = refAli->globalPosition().y();
735  _zVal = refAli->globalPosition().z();
737  _rVal = vec.perp();
738  _phiVal = vec.phi();
739  _etaVal = vec.eta();
741  align::EulerAngles eulerAngles = align::toAngles(rot);
742  _rotxVal = atan2(rot.yz(), rot.zz());
743  float ttt=-rot.xz();
744  if(ttt>1.) ttt=1.;
745  if(ttt<-1.) ttt=-1.;
746  _rotyVal = asin(ttt);
747  _rotzVal = atan2(rot.xy(), rot.xx());
748  _alphaVal = eulerAngles[0];
749  _betaVal = eulerAngles[1];
750  _gammaVal = eulerAngles[2];
751  _dxVal = diff[0];
752  _dyVal = diff[1];
753  _dzVal = diff[2];
754  //getting dR and dPhi
757  _drVal = vCur.perp() - vRef.perp();
758  _dphiVal = vCur.phi() - vRef.phi();
759 
760  _dalphaVal = diff[3];
761  _dbetaVal = diff[4];
762  _dgammaVal = diff[5];
763  _drotxVal=-999.; _drotyVal=-999.; _drotzVal=-999.;
764 
765  align::EulerAngles deuler(3);
766  deuler(1)=_dalphaVal;
767  deuler(2)= _dbetaVal;
768  deuler(3)= _dgammaVal;
769  align::RotationType drot = align::toMatrix(deuler);
770  double xx=rot.xx();
771  double xy=rot.xy();
772  double xz=rot.xz();
773  double yx=rot.yx();
774  double yy=rot.yy();
775  double yz=rot.yz();
776  double zx=rot.zx();
777  double zy=rot.zy();
778  double zz=rot.zz();
779  double detrot=(zz*yy - zy*yz)*xx + (-zz*yx + zx*yz)*xy + (zy*yx - zx*yy)*xz;
780  detrot=1/detrot;
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;
790  align::RotationType invrot(ixx,ixy,ixz, iyx,iyy,iyz, izx,izy,izz);
791  align::RotationType prot = rot*drot*invrot;
792 // align::RotationType prot = rot*drot;
793  float protx; //, proty, protz;
794  protx = atan2(prot.yz(), prot.zz());
795  _drotxVal = protx;//_rotxVal-protx; //atan2(drot.yz(), drot.zz());
796  ttt=-prot.xz();
797  if(ttt>1.) ttt=1.;
798  if(ttt<-1.) ttt=-1.;
799  _drotyVal = asin(ttt);// -_rotyVal;
800  _drotzVal = atan2(prot.xy(), prot.xx());// - _rotzVal;
801 // Above does not account for 2Pi wraparounds!
802 // Prior knowledge: these are supposed to be small rotations. Therefore:
803  if(_drotxVal>3.141592656) _drotxVal=-6.2831853072+_drotxVal;
804  if(_drotxVal<-3.141592656) _drotxVal=6.2831853072+_drotxVal;
805  if(_drotyVal>3.141592656) _drotyVal=-6.2831853072+_drotyVal;
806  if(_drotyVal<-3.141592656) _drotyVal=6.2831853072+_drotyVal;
807  if(_drotzVal>3.141592656) _drotzVal=-6.2831853072+_drotzVal;
808  if(_drotzVal<-3.141592656) _drotzVal=6.2831853072+_drotzVal;
809 
810  _ldxVal=-999.; _ldyVal=-999.; _ldxVal=-999.;
811  _ldrVal=-999.; _ldphiVal=-999; // set fake
812 
813 // if(refAli->alignableObjectId() == align::AlignableDetUnit){
815  align::LocalVector pointL = refAli->surface().toLocal(dV);
816  //align::LocalVector pointL = (refAli->mother())->surface().toLocal(dV);
817  _ldxVal=pointL.x(); _ldyVal=pointL.y(); _ldzVal=pointL.z();
818  _ldphiVal=pointL.phi(); _ldrVal=pointL.perp();
819 // }
820  //detIdFlag
821  if (refAli->alignableObjectId() == align::AlignableDetUnit){
822  if (_detIdFlag){
823  if ((passIdCut(refAli->id()))||(passIdCut(refAli->mother()->id()))){
824  _useDetId = 1;
825  }
826  else{
827  _useDetId = 0;
828  }
829  }
830  }
831  // det module dimension
832  if (refAli->alignableObjectId() == align::AlignableDetUnit){
833  if (refAli->mother()->alignableObjectId() != align::AlignableDet){
834  _detDim = 1;}
835  else if (refAli->mother()->alignableObjectId() ==
837  }
838  else _detDim = 0;
839 
840 
841 
842  _surWidth = refAli->surface().width();
843  _surLength = refAli->surface().length();
844  align::RotationType rt = refAli->globalRotation();
845  _surRot[0] = rt.xx(); _surRot[1] = rt.xy(); _surRot[2] = rt.xz();
846  _surRot[3] = rt.yx(); _surRot[4] = rt.yy(); _surRot[5] = rt.yz();
847  _surRot[6] = rt.zx(); _surRot[7] = rt.zy(); _surRot[8] = rt.zz();
848 
849  MGACollection holdit;
850  holdit.id=_id; holdit.level=_level; holdit.mid=_mid;
851  holdit.mlevel=_mlevel;
852  holdit.sublevel=_sublevel;
853  holdit.x=_xVal; holdit.y=_yVal; holdit.z=_zVal;
854  holdit.r=_rVal; holdit.phi=_phiVal; holdit.eta=_etaVal;
855  holdit.alpha=_alphaVal; holdit.beta=_betaVal; holdit.gamma=_gammaVal;
856  holdit.dx=_dxVal; holdit.dy=_dyVal; holdit.dz=_dzVal;
857  holdit.dr=_drVal; holdit.dphi=_dphiVal;
858  holdit.dalpha=_dalphaVal; holdit.dbeta=_dbetaVal;
859  holdit.dgamma=_dgammaVal;
860  holdit.useDetId=_useDetId; holdit.detDim=_detDim;
861  holdit.surW=_surWidth; holdit.surL=_surLength;
862  holdit.ldx=_ldxVal; holdit.ldy=_ldyVal; holdit.ldz=_ldzVal;
863  holdit.ldr=_ldrVal; holdit.ldphi=_ldphiVal;
864  holdit.rotx=_rotxVal; holdit.roty=_rotyVal; holdit.rotz=_rotzVal;
865  holdit.drotx=_drotxVal; holdit.droty=_drotyVal; holdit.drotz=_drotzVal;
866  for(int i=0; i<9; i++){holdit.surRot[i]=_surRot[i];}
867  holdit.phipos=ringPhiPos;
868  _mgacollection.push_back(holdit);
869 
870 
871  //Fill
872  _alignTree->Fill();
873 
874 }
875 
878  // Is this the mother ring?
879  if(ali==0x0) return false; // elementary sanity
880  const std::vector<Alignable*>& aliComp = ali->components();
881 
882  int size=aliComp.size();
883  if(size<=0) return false; // no subcomponents
884 
885  for(int i=0; i<size; i++){
886  if(checkChosen(aliComp[i])) return true; // A ring has CSC chambers
887  } // as subcomponents
888  return false; // 1'st layer of subcomponents weren't CSC chambers
889 }
891 
893  // Check whether the item passed satisfies the criteria given.
894  if(ali==0x0) return false; // elementary sanity
895  // Is this in the CSC section? If not, bail. Later may extend.
896  if(ali->geomDetId().det()!=DetId::Muon ||
897  ali->geomDetId().subdetId()!=MuonSubdetId::CSC) return false;
898  // If it is a CSC alignable, then check that the station, etc are
899  // those requested.
900  // One might think of aligning more than a single ring at a time,
901  // by using a vector of ring numbers. I don't see the sense in
902  // trying to align more than one station at a time for comparison.
903  CSCDetId cscId(ali->geomDetId());
904 #ifdef jnbdebug
905 std::cout<<"JNB "<<ali->id()<<" "<<cscId.endcap()<<" "
906 <<cscId.station()<<" "<<cscId.ring()<<" "<<cscId.chamber()<<" "
907 <<_endcap<<" "<<_station<<" "<<_ring
908 <<"\n"<<std::flush;
909 #endif
910  if(cscId.endcap()==_endcap && cscId.station()==_station &&
911  cscId.ring()==_ring) {
912  return true;
913  }
914  return false;
915 }
917 
919 
920  // Check to see if this contains CSC components of the appropriate ring
921  // Ring will contain N Alignables which represent chambers, each of which
922  // in turn contains M planes. For our purposes we don't care about the
923  // planes.
924  // Hmm. Interesting question: Do I want to try to fit the chamber as
925  // such, or use the geometry?
926  // I want to fit the chamber, so I'll try to use its presence as the marker.
927  // What specifically identifies a chamber as a chamber, and not as a layer?
928  // The fact that it has layers as sub components, or the fact that it is
929  // the first item with a non-zero ID breakdown? Pick the latter.
930  //
931  if(ali==0x0) return false;
932  if(checkChosen(ali)) return true; // If this is one of the desired
933  // CSC chambers, accept it
934  const std::vector<Alignable*>& aliComp = ali->components();
935 
936  int size=aliComp.size();
937  if(size<=0) return false; // no subcomponents
938 
939  for(int i=0; i<size; i++){
940  if(checkChosen(aliComp[i])) return true; // A ring has CSC chambers
941  } // as subcomponents
942  return false; // 1'st layer of subcomponents weren't CSC chambers
943 }
945 bool MuonGeometryArrange::passIdCut( uint32_t id ){
946 
947  bool pass = false;
948  DetId detid(id);
949 // if(detid.det()==DetId::Muon && detid.subdetId()== MuonSubdetId::CSC){
950 // CSCDetId cscId(refAli->geomDetId());
951 // if(cscId.layer()!=1) return false; // ONLY FIRST LAYER!
952 // }
953  int nEntries = _detIdFlagVector.size();
954 
955  for (int i = 0; i < nEntries; i++){
956  if (_detIdFlagVector[i] == id) pass = true;
957  }
958 
959  return pass;
960 
961 }
962 
963 
size
Write out results.
T xx() const
align::Scalar width() const
int chamber() const
Definition: CSCDetId.h:68
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
T getUntrackedParameter(std::string const &, T const &) const
bool passChosen(Alignable *ali)
std::vector< align::StructureType > theLevels
T perp() const
Definition: PV3DBase.h:72
void compareGeometries(Alignable *refAli, Alignable *curAli, Alignable *curAliCopy2)
int iyy[18][41][3]
bool isMother(Alignable *ali)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
MuonGeometryArrange(const edm::ParameterSet &)
Do nothing. Required by framework.
T y() const
Definition: PV3DBase.h:63
T yx() const
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)
Definition: AlignTools.cc:10
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:141
int ixx[18][41][3]
void createPoints(GlobalVectors *Vs, Alignable *ali, const std::string &weightBy, bool weightById, const std::vector< unsigned int > &weightByIdVector)
Definition: AlignTools.cc:92
MuonAlignment * inputAlign2a
virtual void beginJob()
Read from DB and print survey info.
MuonAlignment * inputAlign2
RotationType diffRot(const GlobalVectors &current, const GlobalVectors &nominal)
Definition: Utilities.cc:73
virtual void analyze(const edm::Event &, const edm::EventSetup &)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
T zx() const
T xy() const
void createROOTGeometry(const edm::EventSetup &iSetup)
T zz() const
static const int CSC
Definition: MuonSubdetId.h:13
T mag() const
Definition: PV3DBase.h:67
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()
Definition: MuonAlignment.h:30
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)
T sqrt(T t)
Definition: SSEVec.h:18
void compare(Alignable *refAli, Alignable *curAli, Alignable *curAliCopy2)
T z() const
Definition: PV3DBase.h:64
bool readModuleList(unsigned int, unsigned int, const std::vector< unsigned int > &)
Definition: AlignTools.cc:142
T zy() const
std::vector< uint32_t > _detIdFlagVector
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:9
T yy() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
MuonAlignment * inputAlign1
GlobalVector centerOfMass(const GlobalVectors &theVs)
Find the CM of a set of points.
Definition: Utilities.cc:187
void fillTree(Alignable *refAli, const AlgebraicVector &diff)
Definition: DetId.h:18
CLHEP::HepVector AlgebraicVector
AlgebraicVector EulerAngles
Definition: Definitions.h:36
align::Scalar length() const
void fillGapsInSurvey(double shiftErr, double angleErr)
const std::vector< std::string > _levelStrings
AlignableMuon * referenceMuon
std::vector< GlobalVector > GlobalVectors
Definition: Utilities.h:28
T eta() const
Definition: PV3DBase.h:76
AlignableMuon * currentMuon
T xz() const
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:42
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:138
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
def check(config)
Definition: trackerTree.py:14
T x() const
Definition: PV3DBase.h:62
void moveAlignable(Alignable *ali, AlgebraicVector diff)
Moves the alignable by the AlgebraicVector.
Definition: AlignTools.cc:81
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:94
T yz() const
const DetId & geomDetId() const
Definition: Alignable.h:186
std::vector< MGACollection > _mgacollection