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 private:
80  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
81 
82  void addBranches();
83 
84  // ----------member data ---------------------------
92 
93  //std::vector<AlignTransform> m_align;
95 
96  uint32_t m_rawid;
97  double m_x, m_y, m_z;
100  double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
101  int m_dNpar;
102  double m_d1, m_d2, m_d3;
103  int m_dtype;
104  //std::vector<double>m_dpar;
105  std::vector<double>* mp_dpar;
106 
107  // Deformation parameters: stored in same tree as the alignment parameters
109  enum { kMaxNumPar = 20 }; // slighly above 'two bowed surfaces' limit
111 
112  TTree* m_tree;
114  TTree* m_treeErrors;
117  TFile* m_file;
118 };
119 
120 //
121 // constants, enums and typedefs
122 //
123 
124 //
125 // static data member definitions
126 //
127 
128 //
129 // constructors and destructor
130 //
132  : topoToken_(esConsumes()),
133  geomDetToken_(esConsumes()),
134  ptpToken_(esConsumes()),
135  aliToken_(esConsumes()),
136  aliErrorToken_(esConsumes()),
137  surfDefToken_(esConsumes()),
138  gprToken_(esConsumes()),
139  theCurrentTracker(nullptr),
140  m_rawid(0),
141  m_x(0.),
142  m_y(0.),
143  m_z(0.),
144  m_alpha(0.),
145  m_beta(0.),
146  m_gamma(0.),
147  m_subdetid(0),
148  m_xx(0.),
149  m_xy(0.),
150  m_yy(0.),
151  m_xz(0.),
152  m_yz(0.),
153  m_zz(0.),
154  m_dNpar(0),
155  m_d1(0.),
156  m_d2(0.),
157  m_d3(0.),
158  m_dtype(0),
159  mp_dpar(nullptr) {
160  m_outputFile = iConfig.getUntrackedParameter<std::string>("outputFile");
161  m_outputTreename = iConfig.getUntrackedParameter<std::string>("outputTreename");
162  m_file = new TFile(m_outputFile.c_str(), "RECREATE");
163  m_tree = new TTree(m_outputTreename.c_str(), m_outputTreename.c_str());
164  m_treeDeformations = new TTree("alignTreeDeformations", "alignTreeDeformations");
165  //char errorTreeName[256];
166  //snprintf(errorTreeName, sizeof(errorTreeName), "%sErrors", m_outputTreename);
167  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
168  m_treeErrors = new TTree("alignTreeErrors", "alignTreeErrors");
169 }
170 
172 
173 //
174 // member functions
175 //
176 
177 // ------------ method called to for each event ------------
179  // retrieve tracker topology from geometry
180  const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
181 
182  edm::LogInfo("beginJob") << "Begin Job";
183 
184  //accessing the initial geometry
185  const GeometricDet* theGeometricDet = &iSetup.getData(geomDetToken_);
186  const PTrackerParameters* ptp = &iSetup.getData(ptpToken_);
187 
188  TrackerGeomBuilderFromGeometricDet trackerBuilder;
189  //currernt tracker
190  TrackerGeometry* theCurTracker = trackerBuilder.build(theGeometricDet, *ptp, tTopo);
191 
192  //build the tracker
193  const Alignments* alignments = &iSetup.getData(aliToken_);
194  const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(aliErrorToken_);
195  const AlignmentSurfaceDeformations* surfaceDeformations = &iSetup.getData(surfDefToken_);
196 
197  //apply the latest alignments
198  const Alignments* globalPositionRcd = &iSetup.getData(gprToken_);
199  GeometryAligner aligner;
200  aligner.applyAlignments<TrackerGeometry>(&(*theCurTracker),
201  alignments,
202  alignmentErrors,
203  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
204  aligner.attachSurfaceDeformations<TrackerGeometry>(&(*theCurTracker), &(*surfaceDeformations));
205 
206  theCurrentTracker = new AlignableTracker(&(*theCurTracker), tTopo);
207 
208  Alignments* theAlignments = theCurrentTracker->alignments();
209  //AlignmentErrorsExtended* theAlignmentErrorsExtended = theCurrentTracker->alignmentErrors();
210 
211  //alignments
212  addBranches();
213  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin();
214  i != theAlignments->m_align.end();
215  ++i) {
216  m_rawid = i->rawId();
217  CLHEP::Hep3Vector translation = i->translation();
218  m_x = translation.x();
219  m_y = translation.y();
220  m_z = translation.z();
221 
222  CLHEP::HepRotation rotation = i->rotation();
223  m_alpha = rotation.getPhi();
224  m_beta = rotation.getTheta();
225  m_gamma = rotation.getPsi();
226  m_tree->Fill();
227 
228  //DetId detid(m_rawid);
229  //if (detid.subdetId() > 2){
230  //
231  //std::cout << " panel: " << tTopo->pxfPanel( m_rawid ) << ", module: " << tTopo->pxfModule( m_rawid ) << std::endl;
232  //if ((tTopo->pxfPanel( m_rawid ) == 1) && (tTopo->pxfModule( m_rawid ) == 4)) std::cout << m_rawid << ", ";
233  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
234  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
235  //}
236  }
237 
238  delete theAlignments;
239 
240  std::vector<AlignTransformErrorExtended> alignErrors = alignmentErrors->m_alignError;
241  for (std::vector<AlignTransformErrorExtended>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i) {
242  m_rawid = i->rawId();
243  CLHEP::HepSymMatrix errMatrix = i->matrix();
244  DetId detid(m_rawid);
245  m_subdetid = detid.subdetId();
246  m_xx = errMatrix[0][0];
247  m_xy = errMatrix[0][1];
248  m_xz = errMatrix[0][2];
249  m_yy = errMatrix[1][1];
250  m_yz = errMatrix[1][2];
251  m_zz = errMatrix[2][2];
252  m_treeErrors->Fill();
253  }
254 
255  // Get GeomDetUnits for the current tracker
256  auto const& detUnits = theCurTracker->detUnits();
257  int detUnit(0);
258  //\\for (unsigned int iDet = 0; iDet < detUnits.size(); ++iDet) {
259  for (auto iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
260  DetId detid = (*iunit)->geographicalId();
261  m_rawid = detid.rawId();
262  m_subdetid = detid.subdetId();
263 
264  ++detUnit;
265  //\\GeomDetUnit* geomDetUnit = detUnits.at(iDet) ;
266  auto geomDetUnit = *iunit;
267 
268  // Get SurfaceDeformation for this GeomDetUnit
269  if (geomDetUnit->surfaceDeformation()) {
270  std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters();
271  //edm::LogInfo("surfaceDeformParamsSize") << " surfaceDeformParams size = " << surfaceDeformParams.size() << std::endl ;
272  m_dNpar = surfaceDeformParams.size();
273  m_dtype = (geomDetUnit->surfaceDeformation())->type();
274  m_d1 = surfaceDeformParams.at(0);
275  m_d2 = surfaceDeformParams.at(1);
276  m_d3 = surfaceDeformParams.at(2);
277  mp_dpar->clear();
278  for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end();
279  ++it) {
280  mp_dpar->push_back((*it));
281  //edm::LogInfo("surfaceDeformParamsContent") << " surfaceDeformParam = " << (*it) << std::endl ;
282  }
283  m_treeDeformations->Fill();
284  }
285  }
286 
287  //write out
288  m_file->cd();
289  m_tree->Write();
290  m_treeDeformations->Write();
291  m_treeErrors->Write();
292  m_file->Close();
293 }
294 
296  m_tree->Branch("rawid", &m_rawid, "rawid/I");
297  m_tree->Branch("x", &m_x, "x/D");
298  m_tree->Branch("y", &m_y, "y/D");
299  m_tree->Branch("z", &m_z, "z/D");
300  m_tree->Branch("alpha", &m_alpha, "alpha/D");
301  m_tree->Branch("beta", &m_beta, "beta/D");
302  m_tree->Branch("gamma", &m_gamma, "gamma/D");
303 
304  m_treeDeformations->Branch("irawid", &m_rawid, "irawid/I");
305  m_treeDeformations->Branch("subdetid", &m_subdetid, "subdetid/I");
306  m_treeDeformations->Branch("dNpar", &m_dNpar, "dNpar/I");
307  //m_treeDeformations->Branch("d1", &m_d1, "d1/D");
308  //m_treeDeformations->Branch("d2", &m_d2, "d2/D");
309  //m_treeDeformations->Branch("d3", &m_d3, "d3/D");
310  m_treeDeformations->Branch("dtype", &m_dtype);
311  m_treeDeformations->Branch("dpar", "std::vector<double>", &mp_dpar);
312 
313  m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
314  m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
315  m_treeErrors->Branch("xx", &m_xx, "xx/D");
316  m_treeErrors->Branch("yy", &m_yy, "yy/D");
317  m_treeErrors->Branch("zz", &m_zz, "zz/D");
318  m_treeErrors->Branch("xy", &m_xy, "xy/D");
319  m_treeErrors->Branch("xz", &m_xz, "xz/D");
320  m_treeErrors->Branch("yz", &m_yz, "yz/D");
321 
322  //m_tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
323  //m_tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
324 }
325 
326 //define this as a plug-in
TrackerGeometryIntoNtuples::numDeformationValues_
UInt_t numDeformationValues_
Definition: TrackerGeometryIntoNtuples.cc:108
TrackerGeometryIntoNtuples::mp_dpar
std::vector< double > * mp_dpar
Definition: TrackerGeometryIntoNtuples.cc:105
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
GlobalPositionRcd.h
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
TrackerGeometry.h
PTrackerParameters
Definition: PTrackerParameters.h:6
TrackerGeometryIntoNtuples::m_d3
double m_d3
Definition: TrackerGeometryIntoNtuples.cc:102
TrackerGeometryIntoNtuples::m_file
TFile * m_file
Definition: TrackerGeometryIntoNtuples.cc:117
TrackerGeometryIntoNtuples::m_xx
double m_xx
Definition: TrackerGeometryIntoNtuples.cc:100
TrackerTopology
Definition: TrackerTopology.h:16
TrackerGeometryIntoNtuples::m_rawid
uint32_t m_rawid
Definition: TrackerGeometryIntoNtuples.cc:96
TrackerGeometryIntoNtuples::theCurrentTracker
AlignableTracker * theCurrentTracker
Definition: TrackerGeometryIntoNtuples.cc:94
TrackerGeometryIntoNtuples::m_treeErrors
TTree * m_treeErrors
Definition: TrackerGeometryIntoNtuples.cc:114
TrackerGeometryIntoNtuples::deformationValues_
Float_t deformationValues_[kMaxNumPar]
Definition: TrackerGeometryIntoNtuples.cc:110
Alignments.h
DetectorGlobalPosition.h
TrackerGeomBuilderFromGeometricDet::build
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
Definition: TrackerGeomBuilderFromGeometricDet.cc:43
TrackerGeometryIntoNtuples::m_outputTreename
std::string m_outputTreename
Definition: TrackerGeometryIntoNtuples.cc:116
PTrackerParameters.h
TrackerGeometryIntoNtuples::m_y
double m_y
Definition: TrackerGeometryIntoNtuples.cc:97
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
TrackerGeometryIntoNtuples::kMaxNumPar
Definition: TrackerGeometryIntoNtuples.cc:109
TrackerGeometryIntoNtuples::m_xz
double m_xz
Definition: TrackerGeometryIntoNtuples.cc:100
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
TrackerGeometryIntoNtuples::m_yy
double m_yy
Definition: TrackerGeometryIntoNtuples.cc:100
ESGetToken.h
GeometryAligner::applyAlignments
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
Definition: GeometryAligner.h:52
TrackerSurfaceDeformationRcd.h
TrackerAlignmentErrorExtendedRcd.h
TrackerGeometryIntoNtuples::ptpToken_
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > ptpToken_
Definition: TrackerGeometryIntoNtuples.cc:87
TrackerGeometryIntoNtuples::aliToken_
const edm::ESGetToken< Alignments, TrackerAlignmentRcd > aliToken_
Definition: TrackerGeometryIntoNtuples.cc:88
DetId
Definition: DetId.h:17
MakerMacros.h
TrackerTopology.h
TrackerGeometryIntoNtuples::m_x
double m_x
Definition: TrackerGeometryIntoNtuples.cc:97
TrackerGeometryIntoNtuples::m_beta
double m_beta
Definition: TrackerGeometryIntoNtuples.cc:98
TrackerTopologyRcd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackerGeometry::detUnits
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Definition: TrackerGeometry.h:61
TrackerGeometryIntoNtuples::m_dtype
int m_dtype
Definition: TrackerGeometryIntoNtuples.cc:103
AlignableTracker
Definition: AlignableTracker.h:17
TrackerGeometryIntoNtuples::surfDefToken_
const edm::ESGetToken< AlignmentSurfaceDeformations, TrackerSurfaceDeformationRcd > surfDefToken_
Definition: TrackerGeometryIntoNtuples.cc:90
GeometricDet
Definition: GeometricDet.h:31
TrackerGeometryIntoNtuples::m_subdetid
int m_subdetid
Definition: TrackerGeometryIntoNtuples.cc:99
TrackerGeometryIntoNtuples::m_outputFile
std::string m_outputFile
Definition: TrackerGeometryIntoNtuples.cc:115
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
TrackerGeometryIntoNtuples::m_z
double m_z
Definition: TrackerGeometryIntoNtuples.cc:97
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SurfaceDeformation.h
TrackerGeometryIntoNtuples::gprToken_
const edm::ESGetToken< Alignments, GlobalPositionRcd > gprToken_
Definition: TrackerGeometryIntoNtuples.cc:91
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
DetId::Tracker
Definition: DetId.h:25
TrackerGeometryIntoNtuples::m_yz
double m_yz
Definition: TrackerGeometryIntoNtuples.cc:100
align::DetectorGlobalPosition
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
Definition: DetectorGlobalPosition.cc:10
TrackerGeometryIntoNtuples::m_zz
double m_zz
Definition: TrackerGeometryIntoNtuples.cc:100
TrackerGeometryIntoNtuples::addBranches
void addBranches()
Definition: TrackerGeometryIntoNtuples.cc:295
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
TrackerGeometryIntoNtuples::m_xy
double m_xy
Definition: TrackerGeometryIntoNtuples.cc:100
PTrackerParametersRcd.h
TrackerGeometryIntoNtuples::TrackerGeometryIntoNtuples
TrackerGeometryIntoNtuples(const edm::ParameterSet &)
Definition: TrackerGeometryIntoNtuples.cc:131
iEvent
int iEvent
Definition: GenABIO.cc:224
AlignmentSurfaceDeformations
Definition: AlignmentSurfaceDeformations.h:20
TrackerAlignmentRcd.h
edm::EventSetup
Definition: EventSetup.h:58
TrackerGeometryIntoNtuples::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: TrackerGeometryIntoNtuples.cc:178
AlignmentErrorsExtended
Definition: AlignmentErrorsExtended.h:10
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
TrackerGeometryIntoNtuples::geomDetToken_
const edm::ESGetToken< GeometricDet, IdealGeometryRecord > geomDetToken_
Definition: TrackerGeometryIntoNtuples.cc:86
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
GeomDet.h
GeometryAligner::attachSurfaceDeformations
void attachSurfaceDeformations(const C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
Definition: GeometryAligner.h:120
TrackerGeometryIntoNtuples::~TrackerGeometryIntoNtuples
~TrackerGeometryIntoNtuples() override
Definition: TrackerGeometryIntoNtuples.cc:171
TrackerGeometryIntoNtuples::m_alpha
double m_alpha
Definition: TrackerGeometryIntoNtuples.cc:98
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
AlignableTracker::alignments
Alignments * alignments() const override
Return alignments, sorted by DetId.
Definition: AlignableTracker.cc:42
GeometryAligner.h
TrackerGeometryIntoNtuples::m_tree
TTree * m_tree
Definition: TrackerGeometryIntoNtuples.cc:112
AlignmentSurfaceDeformations.h
TrackerGeometryIntoNtuples::aliErrorToken_
const edm::ESGetToken< AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd > aliErrorToken_
Definition: TrackerGeometryIntoNtuples.cc:89
TrackerGeometryIntoNtuples::topoToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Definition: TrackerGeometryIntoNtuples.cc:85
Alignable.h
EventSetup.h
TrackerGeomBuilderFromGeometricDet.h
Alignments::m_align
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
TrackerGeomBuilderFromGeometricDet
Definition: TrackerGeomBuilderFromGeometricDet.h:17
AlignableTracker.h
ParameterSet.h
TrackerGeometryIntoNtuples::m_d2
double m_d2
Definition: TrackerGeometryIntoNtuples.cc:102
TrackerGeometryIntoNtuples
Definition: TrackerGeometryIntoNtuples.cc:74
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
Alignments
Definition: Alignments.h:10
TrackerGeometryIntoNtuples::m_gamma
double m_gamma
Definition: TrackerGeometryIntoNtuples.cc:98
TrackerGeometryIntoNtuples::m_d1
double m_d1
Definition: TrackerGeometryIntoNtuples.cc:102
TrackerGeometryIntoNtuples::m_dNpar
int m_dNpar
Definition: TrackerGeometryIntoNtuples.cc:101
GeometryAligner
Class to update a given geometry with a set of alignments.
Definition: GeometryAligner.h:33
TrackerGeometryIntoNtuples::m_treeDeformations
TTree * m_treeDeformations
Definition: TrackerGeometryIntoNtuples.cc:113
TrackerGeometry
Definition: TrackerGeometry.h:14