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  *# Parameters:
11  *# saveApeToASCII -- Do we write out an APE text file?
12  *# saveComposites -- Do we write APEs for composite detectors?
13  *# saveLocalNotGlobal -- Do we write the APEs in the local or global coordinates?
14  *# apeASCIISaveFile -- The name of the save-file.
15  *# readApeFromASCII -- Do we read in APEs from a text file?
16  *# readLocalNotGlobal -- Do we read APEs in the local or the global frame?
17  *# readFullLocalMatrix -- Do we read the full local matrix or just the diagonal elements?
18  *# -- Always write full matrix
19  *# Full matrix format: DetID dxx dxy dyy dxz dyz dzz
20  *# Diagonal element format: DetID sqrt(dxx) sqrt(dyy) sqrt(dzz)
21  *# setComposites -- Do we set the APEs for composite detectors or just ignore them?
22  *# apeASCIIReadFile -- Input file name.
23  *# Also note:
24  *# process.AlignmentProducer.saveApeToDB -- to save as an sqlite file
25  *# and associated entries in _cfg.py
26  */
27 
31 
33 
36 #include "CLHEP/Matrix/SymMatrix.h"
37 
38 #include <fstream>
39 #include <string>
40 #include <set>
41 
44 
48 
49 // includes to make known that they inherit from Alignable:
53 
55 
57 {
58  public:
61 
63  virtual ~ApeSettingAlgorithm();
64 
66  virtual void initialize(const edm::EventSetup &setup,
68  AlignmentParameterStore *store) override;
69 
71  virtual void terminate(const edm::EventSetup& iSetup) override;
72 
74  virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override;
75 
76  private:
83 };
84 
85 //____________________________________________________
86 //____________________________________________________
87 //____________________________________________________
88 //____________________________________________________
89 
90 
91 // Constructor ----------------------------------------------------------------
92 //____________________________________________________
94  AlignmentAlgorithmBase(cfg), theConfig(cfg),
95  theAlignableNavigator(0)
96 {
97  edm::LogInfo("Alignment") << "@SUB=ApeSettingAlgorithm" << "Start.";
98  saveApeToAscii_ = theConfig.getUntrackedParameter<bool>("saveApeToASCII");
99  saveComposites_ = theConfig.getUntrackedParameter<bool>("saveComposites");
100  saveLocalNotGlobal_ = theConfig.getUntrackedParameter<bool>("saveLocalNotGlobal");
101  readApeFromAscii_ = theConfig.getParameter<bool>("readApeFromASCII");
102  readLocalNotGlobal_ = theConfig.getParameter<bool>("readLocalNotGlobal");
103  readFullLocalMatrix_ = theConfig.getParameter<bool>("readFullLocalMatrix");
104  setComposites_ = theConfig.getParameter<bool>("setComposites");
105 
106 }
107 
108 // Destructor ----------------------------------------------------------------
109 //____________________________________________________
111 {
112  delete theAlignableNavigator;
113 }
114 
115 // Call at beginning of job ---------------------------------------------------
116 //____________________________________________________
120 {
121  theAlignableNavigator = new AlignableNavigator(tracker, muon);
123 
124  if (readApeFromAscii_)
125  { std::ifstream apeReadFile(theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath().c_str()); //requires <fstream>
126  if (!apeReadFile.good())
127  { edm::LogInfo("Alignment") << "@SUB=initialize" <<"Problem opening APE file: skipping"
128  << theConfig.getParameter<edm::FileInPath>("apeASCIIReadFile").fullPath();
129  return;
130  }
131  std::set<int> apeList; //To avoid duplicates
132  while (!apeReadFile.eof())
133  { int apeId=0; double x11,x21,x22,x31,x32,x33;
135  { apeReadFile>>apeId>>x11>>x21>>x22>>x31>>x32>>x33>>std::ws;}
136  else
137  { apeReadFile>>apeId>>x11>>x22>>x33>>std::ws;}
138  //idr What sanity checks do we need to put here?
139  if (apeId != 0) //read appears valid?
140  { if (apeList.find(apeId) == apeList.end()) //Not previously done
141  { DetId id(apeId);
143  if (alidet)
144  { if ((alidet->components().size()<1) || setComposites_) //the problem with glued dets...
145  { GlobalErrorExtended globErr;
147  { AlgebraicSymMatrix33 as;
149  { as[0][0]=x11; as[1][0]=x21; as[1][1]=x22;
150  as[2][0]=x31; as[2][1]=x32; as[2][2]=x33;
151  }
152  else
153  { as[0][0]=x11*x11; as[1][1]=x22*x22; as[2][2]=x33*x33;} //local cov.
154  align::RotationType rt=alidet->globalRotation();
156  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
157  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
158  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
159  globErr = GlobalErrorExtended(ROOT::Math::SimilarityT(am,as));
160  }
161  else
162  {
164  globErr = GlobalErrorExtended(x11,x21,x31,0,0,0,x22,x32,0,0,0,x33,0,0,0,0,0,0,0,0,0);
165  else {
166  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);
167  }
168  }
169  alidet->setAlignmentPositionError(globErr, false); // do not propagate down!
170  apeList.insert(apeId); //Flag it's been set
171  }
172  else
173  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Not Setting APE for Composite DetId "<<apeId;
174  }
175  }
176  }
177  else
178  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Skipping duplicate APE for DetId "<<apeId;
179  }
180  }
181  }
182  apeReadFile.close();
183  edm::LogInfo("Alignment") << "@SUB=initialize" << "Set "<<apeList.size()<<" APE values.";
184  }
185 }
186 
187 
188 // Call at end of job ---------------------------------------------------------
189 //____________________________________________________
191 {
192  if (saveApeToAscii_)
194  int theSize=aliErr->m_alignError.size();
195  std::ofstream apeSaveFile(theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str()); //requires <fstream>
196  for (int i=0; i < theSize; ++i)
197  { int id= aliErr->m_alignError[i].rawId();
199  if (alidet && ((alidet->components().size()<1) || saveComposites_))
200  { apeSaveFile<<id;
201  CLHEP::HepSymMatrix sm = aliErr->m_alignError[i].matrix();
203  { align::RotationType rt=alidet->globalRotation();
204  AlgebraicMatrix am(3,3);
205  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
206  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
207  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
208  sm=sm.similarity(am); //symmetric matrix
209  } //transform to local
210  for (int j=0; j < theSize; ++j)
211  for (int k=0; k <= j; ++k)
212  apeSaveFile<<" "<<sm[j][k]; //always write full matrix
213 
214  apeSaveFile<<std::endl;
215  }
216  }
217  delete aliErr;
218  apeSaveFile.close();
219  }
220  // clean up at end: // FIXME: should we delete here or in destructor?
221  delete theAlignableNavigator;
223 }
224 
225 // Run the algorithm on trajectories and tracks -------------------------------
226 //____________________________________________________
228 {
229  // nothing to do here?
230 }
231 
232 // Plugin definition for the algorithm
234  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:259
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.
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
T xz() const
#define DEFINE_EDM_PLUGIN(factory, type, name)
virtual void terminate(const edm::EventSetup &iSetup) override
Call at end of job.
std::string fullPath() const
Definition: FileInPath.cc:165
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.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T yz() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33