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 
56 
58 
60 
61 // To access kinks and bows
65 
66 #include "CLHEP/Matrix/SymMatrix.h"
67 
68 //
69 // class decleration
70 //
71 
73 public:
76 
77 
78 private:
79  virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override;
80 
81  void addBranches();
82 
83  // ----------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  theParameterSet( iConfig ),
125  theCurrentTracker(0),
126  m_rawid(0),
127  m_x(0.), m_y(0.), m_z(0.),
128  m_alpha(0.), m_beta(0.), m_gamma(0.),
129  m_subdetid(0),
130  m_xx(0.), m_xy(0.), m_yy(0.), m_xz(0.), m_yz(0.), m_zz(0.),
131  m_dNpar(0),
132  m_d1(0.), m_d2(0.), m_d3(0.),
133  m_dtype(0),
134  mp_dpar(0)
135 {
136  m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
137  m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
138  m_file = new TFile(m_outputFile.c_str(),"RECREATE");
139  m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
140  m_treeDeformations = new TTree("alignTreeDeformations","alignTreeDeformations");
141  //char errorTreeName[256];
142  //snprintf(errorTreeName, sizeof(errorTreeName), "%sErrors", m_outputTreename);
143  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
144  m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
145 
146 }
147 
148 
150 {
151  delete theCurrentTracker;
152 }
153 
154 
155 //
156 // member functions
157 //
158 
159 // ------------ method called to for each event ------------
161 {
162  // retrieve tracker topology from geometry
163  edm::ESHandle<TrackerTopology> tTopoHandle;
164  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
165  const TrackerTopology* const tTopo = tTopoHandle.product();
166 
167 
168  edm::LogInfo("beginJob") << "Begin Job" << std::endl;
169 
170  //accessing the initial geometry
171  edm::ESHandle<GeometricDet> theGeometricDet;
172  iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
173  TrackerGeomBuilderFromGeometricDet trackerBuilder;
174  //currernt tracker
175  TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet,theParameterSet);
176 
177  //build the tracker
178  edm::ESHandle<Alignments> alignments;
179  edm::ESHandle<AlignmentErrors> alignmentErrors;
181 
182  iSetup.get<TrackerAlignmentRcd>().get(alignments);
183  iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
184  iSetup.get<TrackerSurfaceDeformationRcd>().get(surfaceDeformations);
185 
186  //apply the latest alignments
187  edm::ESHandle<Alignments> globalPositionRcd;
188  iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
189  GeometryAligner aligner;
190  aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
191  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
192  aligner.attachSurfaceDeformations<TrackerGeometry>( &(*theCurTracker), &(*surfaceDeformations)) ;
193 
194 
195  theCurrentTracker = new AlignableTracker(&(*theCurTracker), tTopo);
196 
197  Alignments* theAlignments = theCurrentTracker->alignments();
198  //AlignmentErrors* theAlignmentErrors = theCurrentTracker->alignmentErrors();
199 
200  //alignments
201  addBranches();
202  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
203 
204  m_rawid = i->rawId();
205  CLHEP::Hep3Vector translation = i->translation();
206  m_x = translation.x();
207  m_y = translation.y();
208  m_z = translation.z();
209 
210 
211  CLHEP::HepRotation rotation = i->rotation();
212  m_alpha = rotation.getPhi();
213  m_beta = rotation.getTheta();
214  m_gamma = rotation.getPsi();
215  m_tree->Fill();
216 
217  //DetId detid(m_rawid);
218  //if (detid.subdetId() > 2){
219  //
220  //std::cout << " panel: " << tTopo->pxfPanel( m_rawid ) << ", module: " << tTopo->pxfModule( m_rawid ) << std::endl;
221  //if ((tTopo->pxfPanel( m_rawid ) == 1) && (tTopo->pxfModule( m_rawid ) == 4)) std::cout << m_rawid << ", ";
222  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
223  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
224  //}
225 
226  }
227 
228  delete theAlignments;
229 
230  std::vector<AlignTransformError> alignErrors = alignmentErrors->m_alignError;
231  for (std::vector<AlignTransformError>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i){
232 
233  m_rawid = i->rawId();
234  CLHEP::HepSymMatrix errMatrix = i->matrix();
236  m_subdetid = detid.subdetId();
237  m_xx = errMatrix[0][0];
238  m_xy = errMatrix[0][1];
239  m_xz = errMatrix[0][2];
240  m_yy = errMatrix[1][1];
241  m_yz = errMatrix[1][2];
242  m_zz = errMatrix[2][2];
243  m_treeErrors->Fill();
244  }
245 
246  // Get GeomDetUnits for the current tracker
247  std::vector<GeomDetUnit*>detUnits = theCurTracker->detUnits() ;
248  int detUnit(0) ;
249  //\\for (unsigned int iDet = 0; iDet < detUnits.size(); ++iDet) {
250  for (std::vector<GeomDetUnit*>::const_iterator iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
251 
252  DetId detid = (*iunit)->geographicalId();
253  m_rawid = detid.rawId() ;
254  m_subdetid = detid.subdetId();
255 
256  ++detUnit ;
257  //\\GeomDetUnit* geomDetUnit = detUnits.at(iDet) ;
258  GeomDetUnit* geomDetUnit = *iunit ;
259 
260  // Get SurfaceDeformation for this GeomDetUnit
261  if ( geomDetUnit->surfaceDeformation() ) {
262  std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters() ;
263  //edm::LogInfo("surfaceDeformParamsSize") << " surfaceDeformParams size = " << surfaceDeformParams.size() << std::endl ;
264  m_dNpar = surfaceDeformParams.size() ;
265  m_dtype = (geomDetUnit->surfaceDeformation())->type() ;
266  m_d1 = surfaceDeformParams.at(0) ;
267  m_d2 = surfaceDeformParams.at(1) ;
268  m_d3 = surfaceDeformParams.at(2) ;
269  mp_dpar->clear() ;
270  for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end(); ++it) {
271  mp_dpar->push_back((*it)) ;
272  //edm::LogInfo("surfaceDeformParamsContent") << " surfaceDeformParam = " << (*it) << std::endl ;
273  }
274  m_treeDeformations->Fill() ;
275  }
276  }
277 
278  //write out
279  m_file->cd();
280  m_tree->Write();
281  m_treeDeformations->Write();
282  m_treeErrors->Write();
283  m_file->Close();
284 }
285 
286 
288 
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 
316  //m_tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
317  //m_tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
318 
319 }
320 
321 
322 //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
dictionary parameters
Definition: Parameters.py:2
Class to update a given geometry with a set of alignments.
const edm::ParameterSet theParameterSet
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TrackerGeometry * build(const GeometricDet *gd, const edm::ParameterSet &pSet)
virtual const SurfaceDeformation * surfaceDeformation() const
Definition: GeomDetUnit.h:37
std::vector< AlignTransform > m_align
Definition: Alignments.h:17
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:243
void attachSurfaceDeformations(C *geometry, const AlignmentSurfaceDeformations *surfaceDeformations)
void get(HolderT &iHolder) const
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates)
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
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
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 &)