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  { GlobalError 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 = GlobalError(ROOT::Math::SimilarityT(am,as));
160  }
161  else
162  {
163  globErr = GlobalError(x11,x21,x22,x31,x32,x33);
164  }
165  alidet->setAlignmentPositionError(globErr, false); // do not propagate down!
166  apeList.insert(apeId); //Flag it's been set
167  }
168  else
169  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Not Setting APE for Composite DetId "<<apeId;
170  }
171  }
172  }
173  else
174  { edm::LogInfo("Alignment") << "@SUB=initialize" << "Skipping duplicate APE for DetId "<<apeId;
175  }
176  }
177  }
178  apeReadFile.close();
179  edm::LogInfo("Alignment") << "@SUB=initialize" << "Set "<<apeList.size()<<" APE values.";
180  }
181 }
182 
183 
184 // Call at end of job ---------------------------------------------------------
185 //____________________________________________________
187 {
188  if (saveApeToAscii_)
190  int theSize=aliErr->m_alignError.size();
191  std::ofstream apeSaveFile(theConfig.getUntrackedParameter<std::string>("apeASCIISaveFile").c_str()); //requires <fstream>
192  for (int i=0; i < theSize; ++i)
193  { int id= aliErr->m_alignError[i].rawId();
195  if (alidet && ((alidet->components().size()<1) || saveComposites_))
196  { apeSaveFile<<id;
197  CLHEP::HepSymMatrix sm = aliErr->m_alignError[i].matrix();
199  { align::RotationType rt=alidet->globalRotation();
200  AlgebraicMatrix am(3,3);
201  am[0][0]=rt.xx(); am[0][1]=rt.xy(); am[0][2]=rt.xz();
202  am[1][0]=rt.yx(); am[1][1]=rt.yy(); am[1][2]=rt.yz();
203  am[2][0]=rt.zx(); am[2][1]=rt.zy(); am[2][2]=rt.zz();
204  sm=sm.similarity(am); //symmetric matrix
205  } //transform to local
206  for (int j=0; j < 3; ++j)
207  for (int k=0; k <= j; ++k)
208  apeSaveFile<<" "<<sm[j][k]; //always write full matrix
209 
210  apeSaveFile<<std::endl;
211  }
212  }
213  delete aliErr;
214  apeSaveFile.close();
215  }
216  // clean up at end: // FIXME: should we delete here or in destructor?
217  delete theAlignableNavigator;
219 }
220 
221 // Run the algorithm on trajectories and tracks -------------------------------
222 //____________________________________________________
224 {
225  // nothing to do here?
226 }
227 
228 // Plugin definition for the algorithm
230  ApeSettingAlgorithm, "ApeSettingAlgorithm");
231 
232 
233 
T xx() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
AlignableTracker * theTracker
std::vector< AlignTransformError > m_alignError
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
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:11
T zz() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
CLHEP::HepMatrix AlgebraicMatrix
virtual ~ApeSettingAlgorithm()
Destructor.
AlignmentErrors * alignmentErrors() const
Return alignment errors, sorted by DetId.
T zy() const
AlignableNavigator * theAlignableNavigator
int j
Definition: DBlmapReader.cc:9
T yy() const
int k[5][pyjets_maxn]
Definition: DetId.h:18
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