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