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.8 2011/12/20 15:11:41 mussgill 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 
53 
55 
57 
59 
60 // To access kinks and bows
64 
65 #include "CLHEP/Matrix/SymMatrix.h"
66 
67 //
68 // class decleration
69 //
70 
72 public:
75 
76 
77 private:
78  virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
79 
80  void addBranches();
81 
82  // ----------member data ---------------------------
83  //std::vector<AlignTransform> m_align;
85 
86  uint32_t m_rawid;
87  double m_x, m_y, m_z;
90  double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
91  int m_dNpar ;
92  double m_d1,m_d2, m_d3;
93  int m_dtype ;
94  //std::vector<double>m_dpar;
95  std::vector<double>* mp_dpar;
96 
97  // Deformation parameters: stored in same tree as the alignment parameters
99  enum {kMaxNumPar = 20}; // slighly above 'two bowed surfaces' limit
101 
102  TTree *m_tree;
104  TTree *m_treeErrors;
105  std::string m_outputFile;
106  std::string m_outputTreename;
107  TFile *m_file;
108 };
109 
110 //
111 // constants, enums and typedefs
112 //
113 
114 //
115 // static data member definitions
116 //
117 
118 //
119 // constructors and destructor
120 //
122  theCurrentTracker(0),
123  m_rawid(0),
124  m_x(0.), m_y(0.), m_z(0.),
125  m_alpha(0.), m_beta(0.), m_gamma(0.),
126  m_subdetid(0),
127  m_xx(0.), m_xy(0.), m_yy(0.), m_xz(0.), m_yz(0.), m_zz(0.),
128  m_dNpar(0),
129  m_d1(0.), m_d2(0.), m_d3(0.),
130  m_dtype(0),
131  mp_dpar(0)
132 {
133  m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
134  m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
135  m_file = new TFile(m_outputFile.c_str(),"RECREATE");
136  m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
137  m_treeDeformations = new TTree("alignTreeDeformations","alignTreeDeformations");
138  //char errorTreeName[256];
139  //snprintf(errorTreeName, sizeof(errorTreeName), "%sErrors", m_outputTreename);
140  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
141  m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
142 
143 }
144 
145 
147 {
148  delete theCurrentTracker;
149 }
150 
151 
152 //
153 // member functions
154 //
155 
156 // ------------ method called to for each event ------------
158 {
159  edm::LogInfo("beginJob") << "Begin Job" << std::endl;
160 
161  //accessing the initial geometry
162  edm::ESHandle<GeometricDet> theGeometricDet;
163  iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
164  TrackerGeomBuilderFromGeometricDet trackerBuilder;
165  //currernt tracker
166  TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet);
167 
168  //build the tracker
169  edm::ESHandle<Alignments> alignments;
170  edm::ESHandle<AlignmentErrors> alignmentErrors;
172 
173  iSetup.get<TrackerAlignmentRcd>().get(alignments);
174  iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
175  iSetup.get<TrackerSurfaceDeformationRcd>().get(surfaceDeformations);
176 
177  //apply the latest alignments
178  edm::ESHandle<Alignments> globalPositionRcd;
179  iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
180  GeometryAligner aligner;
181  aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
182  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
183  aligner.attachSurfaceDeformations<TrackerGeometry>( &(*theCurTracker), &(*surfaceDeformations)) ;
184 
185 
186  theCurrentTracker = new AlignableTracker(&(*theCurTracker));
187 
188  Alignments* theAlignments = theCurrentTracker->alignments();
189  //AlignmentErrors* theAlignmentErrors = theCurrentTracker->alignmentErrors();
190 
191  //alignments
192  addBranches();
193  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
194 
195  m_rawid = i->rawId();
196  CLHEP::Hep3Vector translation = i->translation();
197  m_x = translation.x();
198  m_y = translation.y();
199  m_z = translation.z();
200 
201 
202  CLHEP::HepRotation rotation = i->rotation();
203  m_alpha = rotation.getPhi();
204  m_beta = rotation.getTheta();
205  m_gamma = rotation.getPsi();
206  m_tree->Fill();
207 
208  //DetId detid(m_rawid);
209  //if (detid.subdetId() > 2){
210  //PXFDetId pxfid( m_rawid );
211  //std::cout << " panel: " << pxfid.panel() << ", module: " << pxfid.module() << std::endl;
212  //if ((pxfid.panel() == 1) && (pxfid.module() == 4)) std::cout << m_rawid << ", ";
213  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
214  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
215  //}
216 
217  }
218 
219  delete theAlignments;
220 
221  std::vector<AlignTransformError> alignErrors = alignmentErrors->m_alignError;
222  for (std::vector<AlignTransformError>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i){
223 
224  m_rawid = i->rawId();
225  CLHEP::HepSymMatrix errMatrix = i->matrix();
227  m_subdetid = detid.subdetId();
228  m_xx = errMatrix[0][0];
229  m_xy = errMatrix[0][1];
230  m_xz = errMatrix[0][2];
231  m_yy = errMatrix[1][1];
232  m_yz = errMatrix[1][2];
233  m_zz = errMatrix[2][2];
234  m_treeErrors->Fill();
235  }
236 
237  // Get GeomDetUnits for the current tracker
238  std::vector<GeomDetUnit*>detUnits = theCurTracker->detUnits() ;
239  int detUnit(0) ;
240  //\\for (unsigned int iDet = 0; iDet < detUnits.size(); ++iDet) {
241  for (std::vector<GeomDetUnit*>::const_iterator iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
242 
243  DetId detid = (*iunit)->geographicalId();
244  m_rawid = detid.rawId() ;
245  m_subdetid = detid.subdetId();
246 
247  ++detUnit ;
248  //\\GeomDetUnit* geomDetUnit = detUnits.at(iDet) ;
249  GeomDetUnit* geomDetUnit = *iunit ;
250 
251  // Get SurfaceDeformation for this GeomDetUnit
252  if ( geomDetUnit->surfaceDeformation() ) {
253  std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters() ;
254  //edm::LogInfo("surfaceDeformParamsSize") << " surfaceDeformParams size = " << surfaceDeformParams.size() << std::endl ;
255  m_dNpar = surfaceDeformParams.size() ;
256  m_dtype = (geomDetUnit->surfaceDeformation())->type() ;
257  m_d1 = surfaceDeformParams.at(0) ;
258  m_d2 = surfaceDeformParams.at(1) ;
259  m_d3 = surfaceDeformParams.at(2) ;
260  mp_dpar->clear() ;
261  for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end(); ++it) {
262  mp_dpar->push_back((*it)) ;
263  //edm::LogInfo("surfaceDeformParamsContent") << " surfaceDeformParam = " << (*it) << std::endl ;
264  }
265  m_treeDeformations->Fill() ;
266  }
267  }
268 
269  //write out
270  m_file->cd();
271  m_tree->Write();
272  m_treeDeformations->Write();
273  m_treeErrors->Write();
274  m_file->Close();
275 }
276 
277 
279 
280  m_tree->Branch("rawid", &m_rawid, "rawid/I");
281  m_tree->Branch("x", &m_x, "x/D");
282  m_tree->Branch("y", &m_y, "y/D");
283  m_tree->Branch("z", &m_z, "z/D");
284  m_tree->Branch("alpha", &m_alpha, "alpha/D");
285  m_tree->Branch("beta", &m_beta, "beta/D");
286  m_tree->Branch("gamma", &m_gamma, "gamma/D");
287 
288  m_treeDeformations->Branch("irawid", &m_rawid, "irawid/I");
289  m_treeDeformations->Branch("subdetid", &m_subdetid, "subdetid/I");
290  m_treeDeformations->Branch("dNpar", &m_dNpar, "dNpar/I");
291  //m_treeDeformations->Branch("d1", &m_d1, "d1/D");
292  //m_treeDeformations->Branch("d2", &m_d2, "d2/D");
293  //m_treeDeformations->Branch("d3", &m_d3, "d3/D");
294  m_treeDeformations->Branch("dtype", &m_dtype);
295  m_treeDeformations->Branch("dpar", "std::vector<double>", &mp_dpar);
296 
297  m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
298  m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
299  m_treeErrors->Branch("xx", &m_xx, "xx/D");
300  m_treeErrors->Branch("yy", &m_yy, "yy/D");
301  m_treeErrors->Branch("zz", &m_zz, "zz/D");
302  m_treeErrors->Branch("xy", &m_xy, "xy/D");
303  m_treeErrors->Branch("xz", &m_xz, "xz/D");
304  m_treeErrors->Branch("yz", &m_yz, "yz/D");
305 
306 
307  //m_tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
308  //m_tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
309 
310 }
311 
312 
313 //define this as a plug-in
type
Definition: HCALResponse.h:22
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.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual const SurfaceDeformation * surfaceDeformation() const
Definition: GeomDetUnit.h:37
std::vector< AlignTransform > m_align
Definition: Alignments.h:14
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
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:39
unsigned int UInt_t
Definition: FUTypes.h:12
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
TrackerGeometry * build(const GeometricDet *gd)
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
TrackerGeometryIntoNtuples(const edm::ParameterSet &)