CMS 3D CMS Logo

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 
61 public:
64 
66  ~ApeSettingAlgorithm() override;
67 
69  void initialize(const edm::EventSetup &setup,
72  AlignableExtras *extras,
73  AlignmentParameterStore *store) override;
74 
76  void terminate(const edm::EventSetup &iSetup) override;
77 
79  void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
80 
81 private:
88 };
89 
90 //____________________________________________________
91 //____________________________________________________
92 //____________________________________________________
93 //____________________________________________________
94 
95 // Constructor ----------------------------------------------------------------
96 //____________________________________________________
99  edm::LogInfo("Alignment") << "@SUB=ApeSettingAlgorithm"
100  << "Start.";
101  saveApeToAscii_ = theConfig.getUntrackedParameter<bool>("saveApeToASCII");
102  saveComposites_ = theConfig.getUntrackedParameter<bool>("saveComposites");
103  saveLocalNotGlobal_ = theConfig.getUntrackedParameter<bool>("saveLocalNotGlobal");
104  readApeFromAscii_ = theConfig.getParameter<bool>("readApeFromASCII");
105  readLocalNotGlobal_ = theConfig.getParameter<bool>("readLocalNotGlobal");
106  readFullLocalMatrix_ = theConfig.getParameter<bool>("readFullLocalMatrix");
107  setComposites_ = theConfig.getParameter<bool>("setComposites");
108 }
109 
110 // Destructor ----------------------------------------------------------------
111 //____________________________________________________
113 
114 // Call at beginning of job ---------------------------------------------------
115 //____________________________________________________
119  AlignableExtras *extras,
120  AlignmentParameterStore *store) {
121  theAlignableNavigator = new AlignableNavigator(tracker, muon);
123 
124  if (readApeFromAscii_) {
125  std::ifstream apeReadFile(
126  theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath().c_str()); //requires <fstream>
127  if (!apeReadFile.good()) {
128  edm::LogInfo("Alignment") << "@SUB=initialize"
129  << "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;
136  double x11, x21, x22, x31, x32, x33, ignore;
138  apeReadFile >> apeId >> x11 >> x21 >> x22 >> x31 >> x32 >> x33 >> ignore >> ignore >> ignore >> ignore >>
139  ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >>
140  ignore >> std::ws;
141  } else {
142  apeReadFile >> apeId >> x11 >> x22 >> x33 >> std::ws;
143  }
144  //idr What sanity checks do we need to put here?
145  if (apeId != 0) //read appears valid?
146  {
147  if (apeList.find(apeId) == apeList.end()) //Not previously done
148  {
149  DetId id(apeId);
151  if (alidet) {
152  if ((alidet->components().empty()) || setComposites_) //the problem with glued dets...
153  {
154  GlobalErrorExtended globErr;
155  if (readLocalNotGlobal_) {
157  if (readFullLocalMatrix_) {
158  as[0][0] = x11;
159  as[1][0] = x21;
160  as[1][1] = x22;
161  as[2][0] = x31;
162  as[2][1] = x32;
163  as[2][2] = x33;
164  } else {
165  as[0][0] = x11 * x11;
166  as[1][1] = x22 * x22;
167  as[2][2] = x33 * x33;
168  } //local cov.
169  align::RotationType rt = alidet->globalRotation();
171  am[0][0] = rt.xx();
172  am[0][1] = rt.xy();
173  am[0][2] = rt.xz();
174  am[1][0] = rt.yx();
175  am[1][1] = rt.yy();
176  am[1][2] = rt.yz();
177  am[2][0] = rt.zx();
178  am[2][1] = rt.zy();
179  am[2][2] = rt.zz();
180  globErr = GlobalErrorExtended(ROOT::Math::SimilarityT(am, as));
181  } else {
183  globErr =
184  GlobalErrorExtended(x11, x21, x31, 0, 0, 0, x22, x32, 0, 0, 0, x33, 0, 0, 0, 0, 0, 0, 0, 0, 0);
185  else {
186  globErr = GlobalErrorExtended(
187  x11 * x11, 0, 0, 0, 0, 0, x22 * x22, 0, 0, 0, 0, x33 * x33, 0, 0, 0, 0, 0, 0, 0, 0, 0);
188  }
189  }
190  alidet->setAlignmentPositionError(globErr, false); // do not propagate down!
191  apeList.insert(apeId); //Flag it's been set
192  } else {
193  edm::LogInfo("Alignment") << "@SUB=initialize"
194  << "Not Setting APE for Composite DetId " << apeId;
195  }
196  }
197  } else {
198  edm::LogInfo("Alignment") << "@SUB=initialize"
199  << "Skipping duplicate APE for DetId " << apeId;
200  }
201  }
202  }
203  apeReadFile.close();
204  edm::LogInfo("Alignment") << "@SUB=initialize"
205  << "Set " << apeList.size() << " APE values.";
206  }
207 }
208 
209 // Call at end of job ---------------------------------------------------------
210 //____________________________________________________
212  if (saveApeToAscii_) {
214  int theSize = aliErr->m_alignError.size();
215  std::ofstream apeSaveFile(
216  theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str()); //requires <fstream>
217  for (int i = 0; i < theSize; ++i) {
218  int id = aliErr->m_alignError[i].rawId();
220  if (alidet && ((alidet->components().empty()) || saveComposites_)) {
221  apeSaveFile << id;
222  CLHEP::HepSymMatrix sm = aliErr->m_alignError[i].matrix();
223  if (saveLocalNotGlobal_) {
224  align::RotationType rt = alidet->globalRotation();
225  AlgebraicMatrix am(3, 3);
226  am[0][0] = rt.xx();
227  am[0][1] = rt.xy();
228  am[0][2] = rt.xz();
229  am[1][0] = rt.yx();
230  am[1][1] = rt.yy();
231  am[1][2] = rt.yz();
232  am[2][0] = rt.zx();
233  am[2][1] = rt.zy();
234  am[2][2] = rt.zz();
235  sm = sm.similarity(am); //symmetric matrix
236  } //transform to local
237  for (int j = 0; j < sm.num_row(); ++j)
238  for (int k = 0; k <= j; ++k)
239  apeSaveFile << " " << sm[j][k]; //always write full matrix
240 
241  apeSaveFile << std::endl;
242  }
243  }
244  delete aliErr;
245  apeSaveFile.close();
246  }
247  // clean up at end: // FIXME: should we delete here or in destructor?
248  delete theAlignableNavigator;
249  theAlignableNavigator = nullptr;
250 }
251 
252 // Run the algorithm on trajectories and tracks -------------------------------
253 //____________________________________________________
255  // nothing to do here?
256 }
257 
258 // Plugin definition for the algorithm
T xx() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
AlignableTracker * theTracker
~ApeSettingAlgorithm() override
Destructor.
#define nullptr
T yx() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
edm::ParameterSet theConfig
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
T zy() const
AlignableNavigator * theAlignableNavigator
T yy() const
def ignore(seq)
GlobalErrorBaseExtended< double, ErrorMatrixTag > GlobalErrorExtended
Definition: GlobalError.h:14
int k[5][pyjets_maxn]
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
AlignmentErrorsExtended * alignmentErrors() const override
Return alignment errors, sorted by DetId.
std::string fullPath() const
Definition: FileInPath.cc:163
#define DEFINE_EDM_PLUGIN(factory, type, name)
eventInfo
add run, event number and lumi section
Constructor of the full muon geometry.
Definition: AlignableMuon.h:37
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
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