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