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 
53 
56 
59 
61 
63 
65 
66 // To access kinks and bows
69 
70 #include "CLHEP/Matrix/SymMatrix.h"
71 
72 //
73 // class decleration
74 //
75 
77 public:
79  ~TrackerGeometryIntoNtuples() override;
80 
81  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
82 
83 private:
84  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
85 
86  void addBranches();
87 
88  // ----------member data ---------------------------
97 
98  //std::vector<AlignTransform> m_align;
100 
101  uint32_t m_rawid;
102  double m_x, m_y, m_z;
105  double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
106  int m_dNpar;
107  double m_d1, m_d2, m_d3;
108  int m_dtype;
109  //std::vector<double>m_dpar;
110  std::vector<double>* mp_dpar;
111 
112  // Deformation parameters: stored in same tree as the alignment parameters
114  enum { kMaxNumPar = 20 }; // slighly above 'two bowed surfaces' limit
116 
117  TTree* m_tree;
119  TTree* m_treeErrors;
122  TFile* m_file;
123 };
124 
125 //
126 // constants, enums and typedefs
127 //
128 
129 //
130 // static data member definitions
131 //
132 
133 //
134 // constructors and destructor
135 //
137  : topoToken_(esConsumes()),
138  geomDetToken_(esConsumes()),
139  ptpToken_(esConsumes()),
140  ptitpToken_(esConsumes()),
141  aliToken_(esConsumes()),
142  aliErrorToken_(esConsumes()),
143  surfDefToken_(esConsumes()),
144  gprToken_(esConsumes()),
145  theCurrentTracker(nullptr),
146  m_rawid(0),
147  m_x(0.),
148  m_y(0.),
149  m_z(0.),
150  m_alpha(0.),
151  m_beta(0.),
152  m_gamma(0.),
153  m_subdetid(0),
154  m_xx(0.),
155  m_xy(0.),
156  m_yy(0.),
157  m_xz(0.),
158  m_yz(0.),
159  m_zz(0.),
160  m_dNpar(0),
161  m_d1(0.),
162  m_d2(0.),
163  m_d3(0.),
164  m_dtype(0),
165  mp_dpar(nullptr) {
166  m_outputFile = iConfig.getUntrackedParameter<std::string>("outputFile");
167  m_outputTreename = iConfig.getUntrackedParameter<std::string>("outputTreename");
168  m_file = new TFile(m_outputFile.c_str(), "RECREATE");
169  m_tree = new TTree(m_outputTreename.c_str(), m_outputTreename.c_str());
170  m_treeDeformations = new TTree("alignTreeDeformations", "alignTreeDeformations");
171  //char errorTreeName[256];
172  //snprintf(errorTreeName, sizeof(errorTreeName), "%sErrors", m_outputTreename);
173  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
174  m_treeErrors = new TTree("alignTreeErrors", "alignTreeErrors");
175 }
176 
178 
181  desc.setComment(
182  "Validates alignment payloads by comparing the relative position and orientations of tracker modules");
183  desc.addUntracked<std::string>("outputFile", {});
184  desc.addUntracked<std::string>("outputTreename", {});
185  descriptions.addWithDefaultLabel(desc);
186 }
187 
188 //
189 // member functions
190 //
191 
192 // ------------ method called to for each event ------------
194  // retrieve tracker topology from geometry
195  const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
196 
197  edm::LogInfo("beginJob") << "Begin Job";
198 
199  //accessing the initial geometry
200  const GeometricDet* theGeometricDet = &iSetup.getData(geomDetToken_);
201  const PTrackerParameters* ptp = &iSetup.getData(ptpToken_);
203 
204  TrackerGeomBuilderFromGeometricDet trackerBuilder;
205  //currernt tracker
206  TrackerGeometry* theCurTracker = trackerBuilder.build(theGeometricDet, ptitp, *ptp, tTopo);
207 
208  //build the tracker
209  const Alignments* alignments = &iSetup.getData(aliToken_);
210  const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(aliErrorToken_);
211  const AlignmentSurfaceDeformations* surfaceDeformations = &iSetup.getData(surfDefToken_);
212 
213  //apply the latest alignments
214  const Alignments* globalPositionRcd = &iSetup.getData(gprToken_);
215  GeometryAligner aligner;
216  aligner.applyAlignments<TrackerGeometry>(&(*theCurTracker),
217  alignments,
218  alignmentErrors,
219  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
220  aligner.attachSurfaceDeformations<TrackerGeometry>(&(*theCurTracker), &(*surfaceDeformations));
221 
222  theCurrentTracker = new AlignableTracker(&(*theCurTracker), tTopo);
223 
224  Alignments* theAlignments = theCurrentTracker->alignments();
225  //AlignmentErrorsExtended* theAlignmentErrorsExtended = theCurrentTracker->alignmentErrors();
226 
227  //alignments
228  addBranches();
229  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin();
230  i != theAlignments->m_align.end();
231  ++i) {
232  m_rawid = i->rawId();
233  CLHEP::Hep3Vector translation = i->translation();
234  m_x = translation.x();
235  m_y = translation.y();
236  m_z = translation.z();
237 
238  CLHEP::HepRotation rotation = i->rotation();
239  m_alpha = rotation.getPhi();
240  m_beta = rotation.getTheta();
241  m_gamma = rotation.getPsi();
242  m_tree->Fill();
243 
244  //DetId detid(m_rawid);
245  //if (detid.subdetId() > 2){
246  //
247  //std::cout << " panel: " << tTopo->pxfPanel( m_rawid ) << ", module: " << tTopo->pxfModule( m_rawid ) << std::endl;
248  //if ((tTopo->pxfPanel( m_rawid ) == 1) && (tTopo->pxfModule( m_rawid ) == 4)) std::cout << m_rawid << ", ";
249  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
250  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
251  //}
252  }
253 
254  delete theAlignments;
255 
256  std::vector<AlignTransformErrorExtended> alignErrors = alignmentErrors->m_alignError;
257  for (std::vector<AlignTransformErrorExtended>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i) {
258  m_rawid = i->rawId();
259  CLHEP::HepSymMatrix errMatrix = i->matrix();
261  m_subdetid = detid.subdetId();
262  m_xx = errMatrix[0][0];
263  m_xy = errMatrix[0][1];
264  m_xz = errMatrix[0][2];
265  m_yy = errMatrix[1][1];
266  m_yz = errMatrix[1][2];
267  m_zz = errMatrix[2][2];
268  m_treeErrors->Fill();
269  }
270 
271  // Get GeomDetUnits for the current tracker
272  auto const& detUnits = theCurTracker->detUnits();
273  //\\for (unsigned int iDet = 0; iDet < detUnits.size(); ++iDet) {
274  for (auto iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
275  DetId detid = (*iunit)->geographicalId();
276  m_rawid = detid.rawId();
277  m_subdetid = detid.subdetId();
278 
279  //\\GeomDetUnit* geomDetUnit = detUnits.at(iDet) ;
280  auto geomDetUnit = *iunit;
281 
282  // Get SurfaceDeformation for this GeomDetUnit
283  if (geomDetUnit->surfaceDeformation()) {
284  std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters();
285  //edm::LogInfo("surfaceDeformParamsSize") << " surfaceDeformParams size = " << surfaceDeformParams.size() << std::endl ;
286  m_dNpar = surfaceDeformParams.size();
287  m_dtype = (geomDetUnit->surfaceDeformation())->type();
288  m_d1 = surfaceDeformParams.at(0);
289  m_d2 = surfaceDeformParams.at(1);
290  m_d3 = surfaceDeformParams.at(2);
291  mp_dpar->clear();
292  for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end();
293  ++it) {
294  mp_dpar->push_back((*it));
295  //edm::LogInfo("surfaceDeformParamsContent") << " surfaceDeformParam = " << (*it) << std::endl ;
296  }
297  m_treeDeformations->Fill();
298  }
299  }
300 
301  //write out
302  m_file->cd();
303  m_tree->Write();
304  m_treeDeformations->Write();
305  m_treeErrors->Write();
306  m_file->Close();
307 }
308 
310  m_tree->Branch("rawid", &m_rawid, "rawid/I");
311  m_tree->Branch("x", &m_x, "x/D");
312  m_tree->Branch("y", &m_y, "y/D");
313  m_tree->Branch("z", &m_z, "z/D");
314  m_tree->Branch("alpha", &m_alpha, "alpha/D");
315  m_tree->Branch("beta", &m_beta, "beta/D");
316  m_tree->Branch("gamma", &m_gamma, "gamma/D");
317 
318  m_treeDeformations->Branch("irawid", &m_rawid, "irawid/I");
319  m_treeDeformations->Branch("subdetid", &m_subdetid, "subdetid/I");
320  m_treeDeformations->Branch("dNpar", &m_dNpar, "dNpar/I");
321  //m_treeDeformations->Branch("d1", &m_d1, "d1/D");
322  //m_treeDeformations->Branch("d2", &m_d2, "d2/D");
323  //m_treeDeformations->Branch("d3", &m_d3, "d3/D");
324  m_treeDeformations->Branch("dtype", &m_dtype);
325  m_treeDeformations->Branch("dpar", "std::vector<double>", &mp_dpar);
326 
327  m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
328  m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
329  m_treeErrors->Branch("xx", &m_xx, "xx/D");
330  m_treeErrors->Branch("yy", &m_yy, "yy/D");
331  m_treeErrors->Branch("zz", &m_zz, "zz/D");
332  m_treeErrors->Branch("xy", &m_xy, "xy/D");
333  m_treeErrors->Branch("xz", &m_xz, "xz/D");
334  m_treeErrors->Branch("yz", &m_yz, "yz/D");
335 
336  //m_tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
337  //m_tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
338 }
339 
340 //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_
TrackerGeometry * build(const GeometricDet *gd, const PTrackerAdditionalParametersPerDet *ptitp, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
const edm::ESGetToken< PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd > ptitpToken_
const edm::ESGetToken< AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd > aliErrorToken_
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
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > ptpToken_
Log< level::Info, false > LogInfo
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
TrackerGeometryIntoNtuples(const edm::ParameterSet &)