CMS 3D CMS Logo

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