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 Author: Nhan Tran
15 // Created: Mon Jul 16m 16:56:34 CDT 2007
16 // $Id: TrackerGeometryIntoNtuples.cc,v 1.4 2009/11/19 10:57:23 ntran Exp $
17 //
18 //
19 
20 // system include files
24 
26 
27 #include <algorithm>
28 #include "TTree.h"
29 #include "TFile.h"
30 
37 
46 
47 #include "CLHEP/Matrix/SymMatrix.h"
48 
49 //
50 // class decleration
51 //
52 
54 public:
57 
58 
59 private:
60  virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
61 
62  void addBranches();
63 
64  // ----------member data ---------------------------
65  //std::vector<AlignTransform> m_align;
68 
69  uint32_t m_rawid;
70  double m_x, m_y, m_z;
73  double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
74 
75  TTree *m_tree;
76  TTree *m_treeErrors;
77  std::string m_outputFile;
78  std::string m_outputTreename;
79  TFile *m_file;
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94 {
95  m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
96  m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
97  m_file = new TFile(m_outputFile.c_str(),"RECREATE");
98  m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
99  //char errorTreeName[256];
100  //sprintf(errorTreeName, "%sErrors", m_outputTreename);
101  //m_treeErrors = new TTree(errorTreeName,errorTreeName);
102  m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
103 
104 }
105 
106 
108 {}
109 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called to for each event ------------
117 {
118  edm::LogInfo("beginJob") << "Begin Job" << std::endl;
119 
120  //accessing the initial geometry
121  edm::ESHandle<GeometricDet> theGeometricDet;
122  iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
123  TrackerGeomBuilderFromGeometricDet trackerBuilder;
124  //currernt tracker
125  TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet);
126 
127 
128  //build the tracker
129  edm::ESHandle<Alignments> alignments;
130  edm::ESHandle<AlignmentErrors> alignmentErrors;
131 
132  iSetup.get<TrackerAlignmentRcd>().get(alignments);
133  iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
134 
135  //apply the latest alignments
136  edm::ESHandle<Alignments> globalPositionRcd;
137  iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
138  GeometryAligner aligner;
139  aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
140  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
141 
142 
143  theCurrentTracker = new AlignableTracker(&(*theCurTracker));
144 
145  Alignments* theAlignments = theCurrentTracker->alignments();
146  //AlignmentErrors* theAlignmentErrors = theCurrentTracker->alignmentErrors();
147 
148  //alignments
149  addBranches();
150  for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
151 
152  m_rawid = i->rawId();
153  CLHEP::Hep3Vector translation = i->translation();
154  m_x = translation.x();
155  m_y = translation.y();
156  m_z = translation.z();
157 
158 
159  CLHEP::HepRotation rotation = i->rotation();
160  m_alpha = rotation.getPhi();
161  m_beta = rotation.getTheta();
162  m_gamma = rotation.getPsi();
163  m_tree->Fill();
164 
165  //DetId detid(m_rawid);
166  //if (detid.subdetId() > 2){
167  //PXFDetId pxfid( m_rawid );
168  //std::cout << " panel: " << pxfid.panel() << ", module: " << pxfid.module() << std::endl;
169  //if ((pxfid.panel() == 1) && (pxfid.module() == 4)) std::cout << m_rawid << ", ";
170  //std::cout << m_rawid << std::setprecision(9) << " " << m_x << " " << m_y << " " << m_z;
171  //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;
172  //}
173 
174  }
175 
176  std::vector<AlignTransformError> alignErrors = alignmentErrors->m_alignError;
177  for (std::vector<AlignTransformError>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i){
178 
179  m_rawid = i->rawId();
180  CLHEP::HepSymMatrix errMatrix = i->matrix();
182  m_subdetid = detid.subdetId();
183  m_xx = errMatrix[0][0];
184  m_xy = errMatrix[0][1];
185  m_xz = errMatrix[0][2];
186  m_yy = errMatrix[1][1];
187  m_yz = errMatrix[1][2];
188  m_zz = errMatrix[2][2];
189  m_treeErrors->Fill();
190  }
191 
192  //write out
193  m_file->cd();
194  m_tree->Write();
195  m_treeErrors->Write();
196  m_file->Close();
197 }
198 
199 
201 
202  m_tree->Branch("rawid", &m_rawid, "rawid/I");
203  m_tree->Branch("x", &m_x, "x/D");
204  m_tree->Branch("y", &m_y, "y/D");
205  m_tree->Branch("z", &m_z, "z/D");
206  m_tree->Branch("alpha", &m_alpha, "alpha/D");
207  m_tree->Branch("beta", &m_beta, "beta/D");
208  m_tree->Branch("gamma", &m_gamma, "gamma/D");
209 
210 
211  m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
212  m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
213  m_treeErrors->Branch("xx", &m_xx, "xx/D");
214  m_treeErrors->Branch("yy", &m_yy, "yy/D");
215  m_treeErrors->Branch("zz", &m_zz, "zz/D");
216  m_treeErrors->Branch("xy", &m_xy, "xy/D");
217  m_treeErrors->Branch("xz", &m_xz, "xz/D");
218  m_treeErrors->Branch("yz", &m_yz, "yz/D");
219 
220 }
221 
222 
223 //define this as a plug-in
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
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
std::vector< AlignTransform > m_align
Definition: Alignments.h:14
int iEvent
Definition: GenABIO.cc:243
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
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 &)