CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
68 
69 #include "CLHEP/Matrix/SymMatrix.h"
70 
71 //
72 // class decleration
73 //
74 
76 public:
79 
80 
81 private:
82  virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override;
83 
84  void addBranches();
85 
86  // ----------member data ---------------------------
87  //std::vector<AlignTransform> m_align;
89 
90  uint32_t m_rawid;
91  double m_x, m_y, m_z;
94  double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
95  int m_dNpar ;
96  double m_d1,m_d2, m_d3;
97  int m_dtype ;
98  //std::vector<double>m_dpar;
99  std::vector<double>* mp_dpar;
100 
101  // Deformation parameters: stored in same tree as the alignment parameters
103  enum {kMaxNumPar = 20}; // slighly above 'two bowed surfaces' limit
105 
106  TTree *m_tree;
108  TTree *m_treeErrors;
111  TFile *m_file;
112 };
113 
114 //
115 // constants, enums and typedefs
116 //
117 
118 //
119 // static data member definitions
120 //
121 
122 //
123 // constructors and destructor
124 //
126  theCurrentTracker(0),
127  m_rawid(0),
128  m_x(0.), m_y(0.), m_z(0.),
129  m_alpha(0.), m_beta(0.), m_gamma(0.),
130  m_subdetid(0),
131  m_xx(0.), m_xy(0.), m_yy(0.), m_xz(0.), m_yz(0.), m_zz(0.),
132  m_dNpar(0),
133  m_d1(0.), m_d2(0.), m_d3(0.),
134  m_dtype(0),
135  mp_dpar(0)
136 {
137  m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
138  m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
139  m_file = new TFile(m_outputFile.c_str(),"RECREATE");
140  m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
141  m_treeDeformations = new TTree("alignTreeDeformations","alignTreeDeformations");
142  //char errorTreeName[256];
143  //snprintf(errorTreeName, sizeof(errorTreeName), "%sErrors", m_outputTreename);
144  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
145  m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
146 
147 }
148 
149 
151 {
152  delete theCurrentTracker;
153 }
154 
155 
156 //
157 // member functions
158 //
159 
160 // ------------ method called to for each event ------------
162 {
163  // retrieve tracker topology from geometry
164  edm::ESHandle<TrackerTopology> tTopoHandle;
165  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
166  const TrackerTopology* const tTopo = tTopoHandle.product();
167 
168 
169  edm::LogInfo("beginJob") << "Begin Job" << std::endl;
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), &(*alignments), &(*alignmentErrors),
194  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
195  aligner.attachSurfaceDeformations<TrackerGeometry>( &(*theCurTracker), &(*surfaceDeformations)) ;
196 
197 
198  theCurrentTracker = new AlignableTracker(&(*theCurTracker), tTopo);
199 
200  Alignments* theAlignments = theCurrentTracker->alignments();
201  //AlignmentErrorsExtended* theAlignmentErrorsExtended = theCurrentTracker->alignmentErrors();
202 
203  //alignments
204  addBranches();
205  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
206 
207  m_rawid = i->rawId();
208  CLHEP::Hep3Vector translation = i->translation();
209  m_x = translation.x();
210  m_y = translation.y();
211  m_z = translation.z();
212 
213 
214  CLHEP::HepRotation rotation = i->rotation();
215  m_alpha = rotation.getPhi();
216  m_beta = rotation.getTheta();
217  m_gamma = rotation.getPsi();
218  m_tree->Fill();
219 
220  //DetId detid(m_rawid);
221  //if (detid.subdetId() > 2){
222  //
223  //std::cout << " panel: " << tTopo->pxfPanel( m_rawid ) << ", module: " << tTopo->pxfModule( m_rawid ) << std::endl;
224  //if ((tTopo->pxfPanel( m_rawid ) == 1) && (tTopo->pxfModule( m_rawid ) == 4)) std::cout << m_rawid << ", ";
225  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
226  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
227  //}
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 
236  m_rawid = i->rawId();
237  CLHEP::HepSymMatrix errMatrix = i->matrix();
238  DetId detid(m_rawid);
239  m_subdetid = detid.subdetId();
240  m_xx = errMatrix[0][0];
241  m_xy = errMatrix[0][1];
242  m_xz = errMatrix[0][2];
243  m_yy = errMatrix[1][1];
244  m_yz = errMatrix[1][2];
245  m_zz = errMatrix[2][2];
246  m_treeErrors->Fill();
247  }
248 
249  // Get GeomDetUnits for the current tracker
250  auto const & detUnits = theCurTracker->detUnits() ;
251  int detUnit(0) ;
252  //\\for (unsigned int iDet = 0; iDet < detUnits.size(); ++iDet) {
253  for (auto iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
254 
255  DetId detid = (*iunit)->geographicalId();
256  m_rawid = detid.rawId() ;
257  m_subdetid = detid.subdetId();
258 
259  ++detUnit ;
260  //\\GeomDetUnit* geomDetUnit = detUnits.at(iDet) ;
261  auto geomDetUnit = *iunit ;
262 
263  // Get SurfaceDeformation for this GeomDetUnit
264  if ( geomDetUnit->surfaceDeformation() ) {
265  std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters() ;
266  //edm::LogInfo("surfaceDeformParamsSize") << " surfaceDeformParams size = " << surfaceDeformParams.size() << std::endl ;
267  m_dNpar = surfaceDeformParams.size() ;
268  m_dtype = (geomDetUnit->surfaceDeformation())->type() ;
269  m_d1 = surfaceDeformParams.at(0) ;
270  m_d2 = surfaceDeformParams.at(1) ;
271  m_d3 = surfaceDeformParams.at(2) ;
272  mp_dpar->clear() ;
273  for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end(); ++it) {
274  mp_dpar->push_back((*it)) ;
275  //edm::LogInfo("surfaceDeformParamsContent") << " surfaceDeformParam = " << (*it) << std::endl ;
276  }
277  m_treeDeformations->Fill() ;
278  }
279  }
280 
281  //write out
282  m_file->cd();
283  m_tree->Write();
284  m_treeDeformations->Write();
285  m_treeErrors->Write();
286  m_file->Close();
287 }
288 
289 
291 
292  m_tree->Branch("rawid", &m_rawid, "rawid/I");
293  m_tree->Branch("x", &m_x, "x/D");
294  m_tree->Branch("y", &m_y, "y/D");
295  m_tree->Branch("z", &m_z, "z/D");
296  m_tree->Branch("alpha", &m_alpha, "alpha/D");
297  m_tree->Branch("beta", &m_beta, "beta/D");
298  m_tree->Branch("gamma", &m_gamma, "gamma/D");
299 
300  m_treeDeformations->Branch("irawid", &m_rawid, "irawid/I");
301  m_treeDeformations->Branch("subdetid", &m_subdetid, "subdetid/I");
302  m_treeDeformations->Branch("dNpar", &m_dNpar, "dNpar/I");
303  //m_treeDeformations->Branch("d1", &m_d1, "d1/D");
304  //m_treeDeformations->Branch("d2", &m_d2, "d2/D");
305  //m_treeDeformations->Branch("d3", &m_d3, "d3/D");
306  m_treeDeformations->Branch("dtype", &m_dtype);
307  m_treeDeformations->Branch("dpar", "std::vector<double>", &mp_dpar);
308 
309  m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
310  m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
311  m_treeErrors->Branch("xx", &m_xx, "xx/D");
312  m_treeErrors->Branch("yy", &m_yy, "yy/D");
313  m_treeErrors->Branch("zz", &m_zz, "zz/D");
314  m_treeErrors->Branch("xy", &m_xy, "xy/D");
315  m_treeErrors->Branch("xz", &m_xz, "xz/D");
316  m_treeErrors->Branch("yz", &m_yz, "yz/D");
317 
318 
319  //m_tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
320  //m_tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
321 
322 }
323 
324 
325 //define this as a plug-in
type
Definition: HCALResponse.h:21
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
Class to update a given geometry with a set of alignments.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual const DetUnitContainer & detUnits() const
Returm a vector of all GeomDetUnit.
int iEvent
Definition: GenABIO.cc:230
void attachSurfaceDeformations(C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
void get(HolderT &iHolder) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
TrackerGeometryIntoNtuples(const edm::ParameterSet &)