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 {
62  public:
65 
67  ~ApeSettingAlgorithm() override;
68 
70  void initialize(const edm::EventSetup &setup,
72  AlignmentParameterStore *store) override;
73 
75  void terminate(const edm::EventSetup& iSetup) override;
76 
78  void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
79 
80  private:
87 };
88 
89 //____________________________________________________
90 //____________________________________________________
91 //____________________________________________________
92 //____________________________________________________
93 
94 
95 // Constructor ----------------------------------------------------------------
96 //____________________________________________________
100 {
101  edm::LogInfo("Alignment") << "@SUB=ApeSettingAlgorithm" << "Start.";
102  saveApeToAscii_ = theConfig.getUntrackedParameter<bool>("saveApeToASCII");
103  saveComposites_ = theConfig.getUntrackedParameter<bool>("saveComposites");
104  saveLocalNotGlobal_ = theConfig.getUntrackedParameter<bool>("saveLocalNotGlobal");
105  readApeFromAscii_ = theConfig.getParameter<bool>("readApeFromASCII");
106  readLocalNotGlobal_ = theConfig.getParameter<bool>("readLocalNotGlobal");
107  readFullLocalMatrix_ = theConfig.getParameter<bool>("readFullLocalMatrix");
108  setComposites_ = theConfig.getParameter<bool>("setComposites");
109 
110 }
111 
112 // Destructor ----------------------------------------------------------------
113 //____________________________________________________
115 {
116  delete theAlignableNavigator;
117 }
118 
119 // Call at beginning of job ---------------------------------------------------
120 //____________________________________________________
124 {
125  theAlignableNavigator = new AlignableNavigator(tracker, muon);
127 
128  if (readApeFromAscii_)
129  { std::ifstream apeReadFile(theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath().c_str()); //requires <fstream>
130  if (!apeReadFile.good())
131  { edm::LogInfo("Alignment") << "@SUB=initialize" <<"Problem opening APE file: skipping"
132  << theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath();
133  return;
134  }
135  std::set<int> apeList; //To avoid duplicates
136  while (!apeReadFile.eof())
137  { int apeId=0; double x11,x21,x22,x31,x32,x33,ignore;
139  { 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;}
140  else
141  { apeReadFile>>apeId>>x11>>x22>>x33>>std::ws;}
142  //idr What sanity checks do we need to put here?
143  if (apeId != 0) //read appears valid?
144  { if (apeList.find(apeId) == apeList.end()) //Not previously done
145  { DetId id(apeId);
147  if (alidet)
148  { if ((alidet->components().empty()) || setComposites_) //the problem with glued dets...
149  { GlobalErrorExtended globErr;
151  { AlgebraicSymMatrix33 as;
153  { as[0][0]=x11; as[1][0]=x21; as[1][1]=x22;
154  as[2][0]=x31; as[2][1]=x32; as[2][2]=x33;
155  }
156  else
157  { as[0][0]=x11*x11; as[1][1]=x22*x22; as[2][2]=x33*x33;} //local cov.
158  align::RotationType rt=alidet->globalRotation();
160  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
161  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
162  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
163  globErr = GlobalErrorExtended(ROOT::Math::SimilarityT(am,as));
164  }
165  else
166  {
168  globErr = GlobalErrorExtended(x11,x21,x31,0,0,0,x22,x32,0,0,0,x33,0,0,0,0,0,0,0,0,0);
169  else {
170  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);
171  }
172  }
173  alidet->setAlignmentPositionError(globErr, false); // do not propagate down!
174  apeList.insert(apeId); //Flag it's been set
175  }
176  else
177  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Not Setting APE for Composite DetId "<<apeId;
178  }
179  }
180  }
181  else
182  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Skipping duplicate APE for DetId "<<apeId;
183  }
184  }
185  }
186  apeReadFile.close();
187  edm::LogInfo("Alignment") << "@SUB=initialize" << "Set "<<apeList.size()<<" APE values.";
188  }
189 }
190 
191 
192 // Call at end of job ---------------------------------------------------------
193 //____________________________________________________
195 {
196  if (saveApeToAscii_)
198  int theSize=aliErr->m_alignError.size();
199  std::ofstream apeSaveFile(theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str()); //requires <fstream>
200  for (int i=0; i < theSize; ++i)
201  { int id= aliErr->m_alignError[i].rawId();
203  if (alidet && ((alidet->components().empty()) || saveComposites_))
204  { apeSaveFile<<id;
205  CLHEP::HepSymMatrix sm = aliErr->m_alignError[i].matrix();
207  { align::RotationType rt=alidet->globalRotation();
208  AlgebraicMatrix am(3,3);
209  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
210  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
211  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
212  sm=sm.similarity(am); //symmetric matrix
213  } //transform to local
214  for (int j=0; j < sm.num_row(); ++j)
215  for (int k=0; k <= j; ++k)
216  apeSaveFile<<" "<<sm[j][k]; //always write full matrix
217 
218  apeSaveFile<<std::endl;
219  }
220  }
221  delete aliErr;
222  apeSaveFile.close();
223  }
224  // clean up at end: // FIXME: should we delete here or in destructor?
225  delete theAlignableNavigator;
226  theAlignableNavigator = nullptr;
227 }
228 
229 // Run the algorithm on trajectories and tracks -------------------------------
230 //____________________________________________________
232 {
233  // nothing to do here?
234 }
235 
236 // Plugin definition for the algorithm
238  ApeSettingAlgorithm, "ApeSettingAlgorithm");
GlobalErrorBaseExtended< double, ErrorMatrixTag > GlobalErrorExtended
Definition: GlobalError.h:14
T xx() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
AlignableTracker * theTracker
~ApeSettingAlgorithm() override
Destructor.
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.
#define nullptr
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)
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:197
#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