CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ApeSettingAlgorithm.cc
Go to the documentation of this file.
1 
9 /*
10  * The APE record and the ASCII file contain the covariance matrix elements
11  * in units of cm^2
12  *# Parameters:
13  *# saveApeToASCII -- Do we write out an APE text file?
14  *# saveComposites -- Do we write APEs for composite detectors?
15  *# saveLocalNotGlobal -- Do we write the APEs in the local or global coordinates?
16  *# apeASCIISaveFile -- The name of the save-file.
17  *# readApeFromASCII -- Do we read in APEs from a text file?
18  *# readLocalNotGlobal -- Do we read APEs in the local or the global frame?
19  *# readFullLocalMatrix -- Do we read the full local matrix or just the diagonal elements?
20  *# -- Always write full matrix
21  *# Full matrix format: DetID dxx dxy dyy dxz dyz dzz
22  *# Diagonal element format: DetID sqrt(dxx) sqrt(dyy) sqrt(dzz)
23  *# setComposites -- Do we set the APEs for composite detectors or just ignore them?
24  *# apeASCIIReadFile -- Input file name.
25  *# Also note:
26  *# process.AlignmentProducer.saveApeToDB -- to save as an sqlite file
27  *# and associated entries in _cfg.py
28  */
29 
33 
35 
38 #include "CLHEP/Matrix/SymMatrix.h"
39 
40 #include <fstream>
41 #include <string>
42 #include <set>
43 
46 
50 
51 // includes to make known that they inherit from Alignable:
55 
57 
59 {
60  public:
63 
65  virtual ~ApeSettingAlgorithm();
66 
68  virtual void initialize(const edm::EventSetup &setup,
70  AlignmentParameterStore *store) override;
71 
73  virtual void terminate(const edm::EventSetup& iSetup) override;
74 
76  virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
77 
78  private:
85 };
86 
87 //____________________________________________________
88 //____________________________________________________
89 //____________________________________________________
90 //____________________________________________________
91 
92 
93 // Constructor ----------------------------------------------------------------
94 //____________________________________________________
96  AlignmentAlgorithmBase(cfg), theConfig(cfg),
97  theAlignableNavigator(0)
98 {
99  edm::LogInfo("Alignment") << "@SUB=ApeSettingAlgorithm" << "Start.";
100  saveApeToAscii_ = theConfig.getUntrackedParameter<bool>("saveApeToASCII");
101  saveComposites_ = theConfig.getUntrackedParameter<bool>("saveComposites");
102  saveLocalNotGlobal_ = theConfig.getUntrackedParameter<bool>("saveLocalNotGlobal");
103  readApeFromAscii_ = theConfig.getParameter<bool>("readApeFromASCII");
104  readLocalNotGlobal_ = theConfig.getParameter<bool>("readLocalNotGlobal");
105  readFullLocalMatrix_ = theConfig.getParameter<bool>("readFullLocalMatrix");
106  setComposites_ = theConfig.getParameter<bool>("setComposites");
107 
108 }
109 
110 // Destructor ----------------------------------------------------------------
111 //____________________________________________________
113 {
114  delete theAlignableNavigator;
115 }
116 
117 // Call at beginning of job ---------------------------------------------------
118 //____________________________________________________
122 {
123  theAlignableNavigator = new AlignableNavigator(tracker, muon);
125 
126  if (readApeFromAscii_)
127  { std::ifstream apeReadFile(theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath().c_str()); //requires <fstream>
128  if (!apeReadFile.good())
129  { edm::LogInfo("Alignment") << "@SUB=initialize" <<"Problem opening APE file: skipping"
130  << theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath();
131  return;
132  }
133  std::set<int> apeList; //To avoid duplicates
134  while (!apeReadFile.eof())
135  { int apeId=0; double x11,x21,x22,x31,x32,x33,ignore;
137  { apeReadFile>>apeId>>x11>>x21>>x22>>x31>>x32>>x33>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>ignore>>std::ws;}
138  else
139  { apeReadFile>>apeId>>x11>>x22>>x33>>std::ws;}
140  //idr What sanity checks do we need to put here?
141  if (apeId != 0) //read appears valid?
142  { if (apeList.find(apeId) == apeList.end()) //Not previously done
143  { DetId id(apeId);
145  if (alidet)
146  { if ((alidet->components().size()<1) || setComposites_) //the problem with glued dets...
147  { GlobalErrorExtended globErr;
149  { AlgebraicSymMatrix33 as;
151  { as[0][0]=x11; as[1][0]=x21; as[1][1]=x22;
152  as[2][0]=x31; as[2][1]=x32; as[2][2]=x33;
153  }
154  else
155  { as[0][0]=x11*x11; as[1][1]=x22*x22; as[2][2]=x33*x33;} //local cov.
156  align::RotationType rt=alidet->globalRotation();
158  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
159  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
160  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
161  globErr = GlobalErrorExtended(ROOT::Math::SimilarityT(am,as));
162  }
163  else
164  {
166  globErr = GlobalErrorExtended(x11,x21,x31,0,0,0,x22,x32,0,0,0,x33,0,0,0,0,0,0,0,0,0);
167  else {
168  globErr = GlobalErrorExtended(x11*x11,0,0,0,0,0,x22*x22,0,0,0,0,x33*x33,0,0,0,0,0,0,0,0,0);
169  }
170  }
171  alidet->setAlignmentPositionError(globErr, false); // do not propagate down!
172  apeList.insert(apeId); //Flag it's been set
173  }
174  else
175  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Not Setting APE for Composite DetId "<<apeId;
176  }
177  }
178  }
179  else
180  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Skipping duplicate APE for DetId "<<apeId;
181  }
182  }
183  }
184  apeReadFile.close();
185  edm::LogInfo("Alignment") << "@SUB=initialize" << "Set "<<apeList.size()<<" APE values.";
186  }
187 }
188 
189 
190 // Call at end of job ---------------------------------------------------------
191 //____________________________________________________
193 {
194  if (saveApeToAscii_)
196  int theSize=aliErr->m_alignError.size();
197  std::ofstream apeSaveFile(theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str()); //requires <fstream>
198  for (int i=0; i < theSize; ++i)
199  { int id= aliErr->m_alignError[i].rawId();
201  if (alidet && ((alidet->components().size()<1) || saveComposites_))
202  { apeSaveFile<<id;
203  CLHEP::HepSymMatrix sm = aliErr->m_alignError[i].matrix();
205  { align::RotationType rt=alidet->globalRotation();
206  AlgebraicMatrix am(3,3);
207  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
208  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
209  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
210  sm=sm.similarity(am); //symmetric matrix
211  } //transform to local
212  for (int j=0; j < sm.num_row(); ++j)
213  for (int k=0; k <= j; ++k)
214  apeSaveFile<<" "<<sm[j][k]; //always write full matrix
215 
216  apeSaveFile<<std::endl;
217  }
218  }
219  delete aliErr;
220  apeSaveFile.close();
221  }
222  // clean up at end: // FIXME: should we delete here or in destructor?
223  delete theAlignableNavigator;
225 }
226 
227 // Run the algorithm on trajectories and tracks -------------------------------
228 //____________________________________________________
230 {
231  // nothing to do here?
232 }
233 
234 // Plugin definition for the algorithm
236  ApeSettingAlgorithm, "ApeSettingAlgorithm");
GlobalErrorBaseExtended< double, ErrorMatrixTag > GlobalErrorExtended
Definition: GlobalError.h:13
T xx() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
AlignableTracker * theTracker
AlignmentErrorsExtended * alignmentErrors() const
Return alignment errors, sorted by DetId.
T yx() const
edm::ParameterSet theConfig
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm.
Interface/Base class for alignment algorithms, each alignment algorithm has to be derived from this c...
define event information passed to algorithms
T zx() const
ApeSettingAlgorithm(const edm::ParameterSet &cfg)
Constructor.
T xy() const
T zz() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
CLHEP::HepMatrix AlgebraicMatrix
virtual ~ApeSettingAlgorithm()
Destructor.
T zy() const
AlignableNavigator * theAlignableNavigator
int j
Definition: DBlmapReader.cc:9
T yy() const
Definition: DetId.h:18
std::vector< AlignTransformErrorExtended > m_alignError
virtual void terminate()
Called at end of job (must be implemented in derived class)
T xz() const
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string fullPath() const
Definition: FileInPath.cc:184
Constructor of the full muon geometry.
Definition: AlignableMuon.h:36
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Call at beginning of job.
T yz() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33