00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "FWCore/Framework/interface/EDAnalyzer.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024
00025 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00026
00027 #include <algorithm>
00028 #include "TTree.h"
00029 #include "TFile.h"
00030
00031 #include "CondFormats/Alignment/interface/Alignments.h"
00032 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00033 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00034 #include "FWCore/Framework/interface/ESHandle.h"
00035 #include "FWCore/Framework/interface/EventSetup.h"
00036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00037
00038 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00040 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00041 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00042 #include "Alignment/CommonAlignment/interface/Alignable.h"
00043 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00044 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00045 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00046
00047 #include "CLHEP/Matrix/SymMatrix.h"
00048
00049
00050
00051
00052
00053 class TrackerGeometryIntoNtuples : public edm::EDAnalyzer {
00054 public:
00055 explicit TrackerGeometryIntoNtuples(const edm::ParameterSet&);
00056 ~TrackerGeometryIntoNtuples();
00057
00058
00059 private:
00060 virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
00061
00062 void addBranches();
00063
00064
00065
00066 AlignableTracker* theCurrentTracker;
00067
00068 uint32_t m_rawid;
00069 double m_x, m_y, m_z;
00070 double m_alpha, m_beta, m_gamma;
00071 int m_subdetid;
00072 double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
00073
00074 TTree *m_tree;
00075 TTree *m_treeErrors;
00076 std::string m_outputFile;
00077 std::string m_outputTreename;
00078 TFile *m_file;
00079 };
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 TrackerGeometryIntoNtuples::TrackerGeometryIntoNtuples(const edm::ParameterSet& iConfig) :
00093 theCurrentTracker(0),
00094 m_rawid(0),
00095 m_x(0.), m_y(0.), m_z(0.),
00096 m_alpha(0.), m_beta(0.), m_gamma(0.),
00097 m_subdetid(0),
00098 m_xx(0.), m_xy(0.), m_yy(0.), m_xz(0.), m_yz(0.), m_zz(0.)
00099 {
00100 m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
00101 m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
00102 m_file = new TFile(m_outputFile.c_str(),"RECREATE");
00103 m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
00104
00105
00106
00107 m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
00108
00109 }
00110
00111
00112 TrackerGeometryIntoNtuples::~TrackerGeometryIntoNtuples()
00113 {
00114 delete theCurrentTracker;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 void TrackerGeometryIntoNtuples::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00124 {
00125 edm::LogInfo("beginJob") << "Begin Job" << std::endl;
00126
00127
00128 edm::ESHandle<GeometricDet> theGeometricDet;
00129 iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
00130 TrackerGeomBuilderFromGeometricDet trackerBuilder;
00131
00132 TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet);
00133
00134
00135
00136 edm::ESHandle<Alignments> alignments;
00137 edm::ESHandle<AlignmentErrors> alignmentErrors;
00138
00139 iSetup.get<TrackerAlignmentRcd>().get(alignments);
00140 iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
00141
00142
00143 edm::ESHandle<Alignments> globalPositionRcd;
00144 iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
00145 GeometryAligner aligner;
00146 aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
00147 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
00148
00149
00150 theCurrentTracker = new AlignableTracker(&(*theCurTracker));
00151
00152 Alignments* theAlignments = theCurrentTracker->alignments();
00153
00154
00155
00156 addBranches();
00157 for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
00158
00159 m_rawid = i->rawId();
00160 CLHEP::Hep3Vector translation = i->translation();
00161 m_x = translation.x();
00162 m_y = translation.y();
00163 m_z = translation.z();
00164
00165
00166 CLHEP::HepRotation rotation = i->rotation();
00167 m_alpha = rotation.getPhi();
00168 m_beta = rotation.getTheta();
00169 m_gamma = rotation.getPsi();
00170 m_tree->Fill();
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 }
00182
00183 delete theAlignments;
00184
00185 std::vector<AlignTransformError> alignErrors = alignmentErrors->m_alignError;
00186 for (std::vector<AlignTransformError>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i){
00187
00188 m_rawid = i->rawId();
00189 CLHEP::HepSymMatrix errMatrix = i->matrix();
00190 DetId detid(m_rawid);
00191 m_subdetid = detid.subdetId();
00192 m_xx = errMatrix[0][0];
00193 m_xy = errMatrix[0][1];
00194 m_xz = errMatrix[0][2];
00195 m_yy = errMatrix[1][1];
00196 m_yz = errMatrix[1][2];
00197 m_zz = errMatrix[2][2];
00198 m_treeErrors->Fill();
00199 }
00200
00201
00202 m_file->cd();
00203 m_tree->Write();
00204 m_treeErrors->Write();
00205 m_file->Close();
00206 }
00207
00208
00209 void TrackerGeometryIntoNtuples::addBranches() {
00210
00211 m_tree->Branch("rawid", &m_rawid, "rawid/I");
00212 m_tree->Branch("x", &m_x, "x/D");
00213 m_tree->Branch("y", &m_y, "y/D");
00214 m_tree->Branch("z", &m_z, "z/D");
00215 m_tree->Branch("alpha", &m_alpha, "alpha/D");
00216 m_tree->Branch("beta", &m_beta, "beta/D");
00217 m_tree->Branch("gamma", &m_gamma, "gamma/D");
00218
00219
00220 m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
00221 m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
00222 m_treeErrors->Branch("xx", &m_xx, "xx/D");
00223 m_treeErrors->Branch("yy", &m_yy, "yy/D");
00224 m_treeErrors->Branch("zz", &m_zz, "zz/D");
00225 m_treeErrors->Branch("xy", &m_xy, "xy/D");
00226 m_treeErrors->Branch("xz", &m_xz, "xz/D");
00227 m_treeErrors->Branch("yz", &m_yz, "yz/D");
00228
00229 }
00230
00231
00232
00233 DEFINE_FWK_MODULE(TrackerGeometryIntoNtuples);