CMS 3D CMS Logo

TrackerGeometryIntoNtuples.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackerGeometryIntoNtuples
4 // Class: TrackerGeometryIntoNtuples
5 //
13 //
14 // Original class TrackerGeometryIntoNtuples.cc
15 // Original Author: Nhan Tran
16 // Created: Mon Jul 16m 16:56:34 CDT 2007
17 // $Id: TrackerGeometryIntoNtuples.cc,v 1.14 2012/12/02 22:13:12 devdatta Exp $
18 //
19 // 26 May 2012
20 // ***********
21 // *********** Modified to add tracker module surface deformations ***********
22 //
23 //
24 
25 // system include files
29 
31 
32 #include <algorithm>
33 #include "TTree.h"
34 #include "TFile.h"
35 
39 
43 
48 
51 
54 
57 
59 
61 
63 
64 // To access kinks and bows
67 
68 #include "CLHEP/Matrix/SymMatrix.h"
69 
70 //
71 // class decleration
72 //
73 
75 public:
77  ~TrackerGeometryIntoNtuples() override;
78 
79  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
80 
81 private:
82  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
83 
84  void addBranches();
85 
86  // ----------member data ---------------------------
94 
95  //std::vector<AlignTransform> m_align;
97 
98  uint32_t m_rawid;
99  double m_x, m_y, m_z;
102  double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
103  int m_dNpar;
104  double m_d1, m_d2, m_d3;
105  int m_dtype;
106  //std::vector<double>m_dpar;
107  std::vector<double>* mp_dpar;
108 
109  // Deformation parameters: stored in same tree as the alignment parameters
111  enum { kMaxNumPar = 20 }; // slighly above 'two bowed surfaces' limit
113 
114  TTree* m_tree;
116  TTree* m_treeErrors;
119  TFile* m_file;
120 };
121 
122 //
123 // constants, enums and typedefs
124 //
125 
126 //
127 // static data member definitions
128 //
129 
130 //
131 // constructors and destructor
132 //
134  : topoToken_(esConsumes()),
135  geomDetToken_(esConsumes()),
136  ptpToken_(esConsumes()),
137  aliToken_(esConsumes()),
138  aliErrorToken_(esConsumes()),
139  surfDefToken_(esConsumes()),
140  gprToken_(esConsumes()),
141  theCurrentTracker(nullptr),
142  m_rawid(0),
143  m_x(0.),
144  m_y(0.),
145  m_z(0.),
146  m_alpha(0.),
147  m_beta(0.),
148  m_gamma(0.),
149  m_subdetid(0),
150  m_xx(0.),
151  m_xy(0.),
152  m_yy(0.),
153  m_xz(0.),
154  m_yz(0.),
155  m_zz(0.),
156  m_dNpar(0),
157  m_d1(0.),
158  m_d2(0.),
159  m_d3(0.),
160  m_dtype(0),
161  mp_dpar(nullptr) {
162  m_outputFile = iConfig.getUntrackedParameter<std::string>("outputFile");
163  m_outputTreename = iConfig.getUntrackedParameter<std::string>("outputTreename");
164  m_file = new TFile(m_outputFile.c_str(), "RECREATE");
165  m_tree = new TTree(m_outputTreename.c_str(), m_outputTreename.c_str());
166  m_treeDeformations = new TTree("alignTreeDeformations", "alignTreeDeformations");
167  //char errorTreeName[256];
168  //snprintf(errorTreeName, sizeof(errorTreeName), "%sErrors", m_outputTreename);
169  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
170  m_treeErrors = new TTree("alignTreeErrors", "alignTreeErrors");
171 }
172 
174 
177  desc.setComment(
178  "Validates alignment payloads by comparing the relative position and orientations of tracker modules");
179  desc.addUntracked<std::string>("outputFile", {});
180  desc.addUntracked<std::string>("outputTreename", {});
181  descriptions.addWithDefaultLabel(desc);
182 }
183 
184 //
185 // member functions
186 //
187 
188 // ------------ method called to for each event ------------
190  // retrieve tracker topology from geometry
191  const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
192 
193  edm::LogInfo("beginJob") << "Begin Job";
194 
195  //accessing the initial geometry
196  const GeometricDet* theGeometricDet = &iSetup.getData(geomDetToken_);
197  const PTrackerParameters* ptp = &iSetup.getData(ptpToken_);
198 
199  TrackerGeomBuilderFromGeometricDet trackerBuilder;
200  //currernt tracker
201  TrackerGeometry* theCurTracker = trackerBuilder.build(theGeometricDet, *ptp, tTopo);
202 
203  //build the tracker
204  const Alignments* alignments = &iSetup.getData(aliToken_);
205  const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(aliErrorToken_);
206  const AlignmentSurfaceDeformations* surfaceDeformations = &iSetup.getData(surfDefToken_);
207 
208  //apply the latest alignments
209  const Alignments* globalPositionRcd = &iSetup.getData(gprToken_);
210  GeometryAligner aligner;
211  aligner.applyAlignments<TrackerGeometry>(&(*theCurTracker),
212  alignments,
213  alignmentErrors,
214  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
215  aligner.attachSurfaceDeformations<TrackerGeometry>(&(*theCurTracker), &(*surfaceDeformations));
216 
217  theCurrentTracker = new AlignableTracker(&(*theCurTracker), tTopo);
218 
219  Alignments* theAlignments = theCurrentTracker->alignments();
220  //AlignmentErrorsExtended* theAlignmentErrorsExtended = theCurrentTracker->alignmentErrors();
221 
222  //alignments
223  addBranches();
224  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin();
225  i != theAlignments->m_align.end();
226  ++i) {
227  m_rawid = i->rawId();
228  CLHEP::Hep3Vector translation = i->translation();
229  m_x = translation.x();
230  m_y = translation.y();
231  m_z = translation.z();
232 
233  CLHEP::HepRotation rotation = i->rotation();
234  m_alpha = rotation.getPhi();
235  m_beta = rotation.getTheta();
236  m_gamma = rotation.getPsi();
237  m_tree->Fill();
238 
239  //DetId detid(m_rawid);
240  //if (detid.subdetId() > 2){
241  //
242  //std::cout << " panel: " << tTopo->pxfPanel( m_rawid ) << ", module: " << tTopo->pxfModule( m_rawid ) << std::endl;
243  //if ((tTopo->pxfPanel( m_rawid ) == 1) && (tTopo->pxfModule( m_rawid ) == 4)) std::cout << m_rawid << ", ";
244  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
245  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
246  //}
247  }
248 
249  delete theAlignments;
250 
251  std::vector<AlignTransformErrorExtended> alignErrors = alignmentErrors->m_alignError;
252  for (std::vector<AlignTransformErrorExtended>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i) {
253  m_rawid = i->rawId();
254  CLHEP::HepSymMatrix errMatrix = i->matrix();
255  DetId detid(m_rawid);
256  m_subdetid = detid.subdetId();
257  m_xx = errMatrix[0][0];
258  m_xy = errMatrix[0][1];
259  m_xz = errMatrix[0][2];
260  m_yy = errMatrix[1][1];
261  m_yz = errMatrix[1][2];
262  m_zz = errMatrix[2][2];
263  m_treeErrors->Fill();
264  }
265 
266  // Get GeomDetUnits for the current tracker
267  auto const& detUnits = theCurTracker->detUnits();
268  int detUnit(0);
269  //\\for (unsigned int iDet = 0; iDet < detUnits.size(); ++iDet) {
270  for (auto iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
271  DetId detid = (*iunit)->geographicalId();
272  m_rawid = detid.rawId();
273  m_subdetid = detid.subdetId();
274 
275  ++detUnit;
276  //\\GeomDetUnit* geomDetUnit = detUnits.at(iDet) ;
277  auto geomDetUnit = *iunit;
278 
279  // Get SurfaceDeformation for this GeomDetUnit
280  if (geomDetUnit->surfaceDeformation()) {
281  std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters();
282  //edm::LogInfo("surfaceDeformParamsSize") << " surfaceDeformParams size = " << surfaceDeformParams.size() << std::endl ;
283  m_dNpar = surfaceDeformParams.size();
284  m_dtype = (geomDetUnit->surfaceDeformation())->type();
285  m_d1 = surfaceDeformParams.at(0);
286  m_d2 = surfaceDeformParams.at(1);
287  m_d3 = surfaceDeformParams.at(2);
288  mp_dpar->clear();
289  for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end();
290  ++it) {
291  mp_dpar->push_back((*it));
292  //edm::LogInfo("surfaceDeformParamsContent") << " surfaceDeformParam = " << (*it) << std::endl ;
293  }
294  m_treeDeformations->Fill();
295  }
296  }
297 
298  //write out
299  m_file->cd();
300  m_tree->Write();
301  m_treeDeformations->Write();
302  m_treeErrors->Write();
303  m_file->Close();
304 }
305 
307  m_tree->Branch("rawid", &m_rawid, "rawid/I");
308  m_tree->Branch("x", &m_x, "x/D");
309  m_tree->Branch("y", &m_y, "y/D");
310  m_tree->Branch("z", &m_z, "z/D");
311  m_tree->Branch("alpha", &m_alpha, "alpha/D");
312  m_tree->Branch("beta", &m_beta, "beta/D");
313  m_tree->Branch("gamma", &m_gamma, "gamma/D");
314 
315  m_treeDeformations->Branch("irawid", &m_rawid, "irawid/I");
316  m_treeDeformations->Branch("subdetid", &m_subdetid, "subdetid/I");
317  m_treeDeformations->Branch("dNpar", &m_dNpar, "dNpar/I");
318  //m_treeDeformations->Branch("d1", &m_d1, "d1/D");
319  //m_treeDeformations->Branch("d2", &m_d2, "d2/D");
320  //m_treeDeformations->Branch("d3", &m_d3, "d3/D");
321  m_treeDeformations->Branch("dtype", &m_dtype);
322  m_treeDeformations->Branch("dpar", "std::vector<double>", &mp_dpar);
323 
324  m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
325  m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
326  m_treeErrors->Branch("xx", &m_xx, "xx/D");
327  m_treeErrors->Branch("yy", &m_yy, "yy/D");
328  m_treeErrors->Branch("zz", &m_zz, "zz/D");
329  m_treeErrors->Branch("xy", &m_xy, "xy/D");
330  m_treeErrors->Branch("xz", &m_xz, "xz/D");
331  m_treeErrors->Branch("yz", &m_yz, "yz/D");
332 
333  //m_tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
334  //m_tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
335 }
336 
337 //define this as a plug-in
void attachSurfaceDeformations(const C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< Alignments, GlobalPositionRcd > gprToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
Alignments * alignments() const override
Return alignments, sorted by DetId.
const edm::ESGetToken< AlignmentSurfaceDeformations, TrackerSurfaceDeformationRcd > surfDefToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Class to update a given geometry with a set of alignments.
const edm::ESGetToken< Alignments, TrackerAlignmentRcd > aliToken_
const edm::ESGetToken< AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd > aliErrorToken_
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
T getUntrackedParameter(std::string const &, T const &) const
const edm::ESGetToken< GeometricDet, IdealGeometryRecord > geomDetToken_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > ptpToken_
Log< level::Info, false > LogInfo
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
TrackerGeometryIntoNtuples(const edm::ParameterSet &)