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