00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029
00030 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00031
00032 #include <algorithm>
00033 #include "TTree.h"
00034 #include "TFile.h"
00035
00036 #include "FWCore/Framework/interface/ESHandle.h"
00037 #include "FWCore/Framework/interface/EventSetup.h"
00038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00039
00040 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00041 #include "CondFormats/Alignment/interface/Alignments.h"
00042 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h"
00043
00044 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00045 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00046 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00047 #include "CondFormats/AlignmentRecord/interface/TrackerSurfaceDeformationRcd.h"
00048
00049 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00050 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00051
00052 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00053
00054 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00055
00056 #include "Alignment/CommonAlignment/interface/Alignable.h"
00057
00058 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00059
00060
00061 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00062 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00063 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
00064
00065 #include "CLHEP/Matrix/SymMatrix.h"
00066
00067
00068
00069
00070
00071 class TrackerGeometryIntoNtuples : public edm::EDAnalyzer {
00072 public:
00073 explicit TrackerGeometryIntoNtuples(const edm::ParameterSet&);
00074 ~TrackerGeometryIntoNtuples();
00075
00076
00077 private:
00078 virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
00079
00080 void addBranches();
00081
00082
00083
00084 AlignableTracker* theCurrentTracker ;
00085
00086 uint32_t m_rawid;
00087 double m_x, m_y, m_z;
00088 double m_alpha, m_beta, m_gamma;
00089 int m_subdetid;
00090 double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
00091 int m_dNpar ;
00092 double m_d1,m_d2, m_d3;
00093 int m_dtype ;
00094
00095 std::vector<double>* mp_dpar;
00096
00097
00098 UInt_t numDeformationValues_;
00099 enum {kMaxNumPar = 20};
00100 Float_t deformationValues_[kMaxNumPar];
00101
00102 TTree *m_tree;
00103 TTree *m_treeDeformations;
00104 TTree *m_treeErrors;
00105 std::string m_outputFile;
00106 std::string m_outputTreename;
00107 TFile *m_file;
00108 };
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 TrackerGeometryIntoNtuples::TrackerGeometryIntoNtuples(const edm::ParameterSet& iConfig) :
00122 theCurrentTracker(0),
00123 m_rawid(0),
00124 m_x(0.), m_y(0.), m_z(0.),
00125 m_alpha(0.), m_beta(0.), m_gamma(0.),
00126 m_subdetid(0),
00127 m_xx(0.), m_xy(0.), m_yy(0.), m_xz(0.), m_yz(0.), m_zz(0.),
00128 m_dNpar(0),
00129 m_d1(0.), m_d2(0.), m_d3(0.),
00130 m_dtype(0),
00131 mp_dpar(0)
00132 {
00133 m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
00134 m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
00135 m_file = new TFile(m_outputFile.c_str(),"RECREATE");
00136 m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
00137 m_treeDeformations = new TTree("alignTreeDeformations","alignTreeDeformations");
00138
00139
00140
00141 m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
00142
00143 }
00144
00145
00146 TrackerGeometryIntoNtuples::~TrackerGeometryIntoNtuples()
00147 {
00148 delete theCurrentTracker;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 void TrackerGeometryIntoNtuples::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00158 {
00159 edm::LogInfo("beginJob") << "Begin Job" << std::endl;
00160
00161
00162 edm::ESHandle<GeometricDet> theGeometricDet;
00163 iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
00164 TrackerGeomBuilderFromGeometricDet trackerBuilder;
00165
00166 TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet);
00167
00168
00169 edm::ESHandle<Alignments> alignments;
00170 edm::ESHandle<AlignmentErrors> alignmentErrors;
00171 edm::ESHandle<AlignmentSurfaceDeformations> surfaceDeformations;
00172
00173 iSetup.get<TrackerAlignmentRcd>().get(alignments);
00174 iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
00175 iSetup.get<TrackerSurfaceDeformationRcd>().get(surfaceDeformations);
00176
00177
00178 edm::ESHandle<Alignments> globalPositionRcd;
00179 iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
00180 GeometryAligner aligner;
00181 aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
00182 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
00183 aligner.attachSurfaceDeformations<TrackerGeometry>( &(*theCurTracker), &(*surfaceDeformations)) ;
00184
00185
00186 theCurrentTracker = new AlignableTracker(&(*theCurTracker));
00187
00188 Alignments* theAlignments = theCurrentTracker->alignments();
00189
00190
00191
00192 addBranches();
00193 for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
00194
00195 m_rawid = i->rawId();
00196 CLHEP::Hep3Vector translation = i->translation();
00197 m_x = translation.x();
00198 m_y = translation.y();
00199 m_z = translation.z();
00200
00201
00202 CLHEP::HepRotation rotation = i->rotation();
00203 m_alpha = rotation.getPhi();
00204 m_beta = rotation.getTheta();
00205 m_gamma = rotation.getPsi();
00206 m_tree->Fill();
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 }
00218
00219 delete theAlignments;
00220
00221 std::vector<AlignTransformError> alignErrors = alignmentErrors->m_alignError;
00222 for (std::vector<AlignTransformError>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i){
00223
00224 m_rawid = i->rawId();
00225 CLHEP::HepSymMatrix errMatrix = i->matrix();
00226 DetId detid(m_rawid);
00227 m_subdetid = detid.subdetId();
00228 m_xx = errMatrix[0][0];
00229 m_xy = errMatrix[0][1];
00230 m_xz = errMatrix[0][2];
00231 m_yy = errMatrix[1][1];
00232 m_yz = errMatrix[1][2];
00233 m_zz = errMatrix[2][2];
00234 m_treeErrors->Fill();
00235 }
00236
00237
00238 std::vector<GeomDetUnit*>detUnits = theCurTracker->detUnits() ;
00239 int detUnit(0) ;
00240
00241 for (std::vector<GeomDetUnit*>::const_iterator iunit = detUnits.begin(); iunit != detUnits.end(); ++iunit) {
00242
00243 DetId detid = (*iunit)->geographicalId();
00244 m_rawid = detid.rawId() ;
00245 m_subdetid = detid.subdetId();
00246
00247 ++detUnit ;
00248
00249 GeomDetUnit* geomDetUnit = *iunit ;
00250
00251
00252 if ( geomDetUnit->surfaceDeformation() ) {
00253 std::vector<double> surfaceDeformParams = (geomDetUnit->surfaceDeformation())->parameters() ;
00254
00255 m_dNpar = surfaceDeformParams.size() ;
00256 m_dtype = (geomDetUnit->surfaceDeformation())->type() ;
00257 m_d1 = surfaceDeformParams.at(0) ;
00258 m_d2 = surfaceDeformParams.at(1) ;
00259 m_d3 = surfaceDeformParams.at(2) ;
00260 mp_dpar->clear() ;
00261 for (std::vector<double>::const_iterator it = surfaceDeformParams.begin(); it != surfaceDeformParams.end(); ++it) {
00262 mp_dpar->push_back((*it)) ;
00263
00264 }
00265 m_treeDeformations->Fill() ;
00266 }
00267 }
00268
00269
00270 m_file->cd();
00271 m_tree->Write();
00272 m_treeDeformations->Write();
00273 m_treeErrors->Write();
00274 m_file->Close();
00275 }
00276
00277
00278 void TrackerGeometryIntoNtuples::addBranches() {
00279
00280 m_tree->Branch("rawid", &m_rawid, "rawid/I");
00281 m_tree->Branch("x", &m_x, "x/D");
00282 m_tree->Branch("y", &m_y, "y/D");
00283 m_tree->Branch("z", &m_z, "z/D");
00284 m_tree->Branch("alpha", &m_alpha, "alpha/D");
00285 m_tree->Branch("beta", &m_beta, "beta/D");
00286 m_tree->Branch("gamma", &m_gamma, "gamma/D");
00287
00288 m_treeDeformations->Branch("irawid", &m_rawid, "irawid/I");
00289 m_treeDeformations->Branch("subdetid", &m_subdetid, "subdetid/I");
00290 m_treeDeformations->Branch("dNpar", &m_dNpar, "dNpar/I");
00291
00292
00293
00294 m_treeDeformations->Branch("dtype", &m_dtype);
00295 m_treeDeformations->Branch("dpar", "std::vector<double>", &mp_dpar);
00296
00297 m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
00298 m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
00299 m_treeErrors->Branch("xx", &m_xx, "xx/D");
00300 m_treeErrors->Branch("yy", &m_yy, "yy/D");
00301 m_treeErrors->Branch("zz", &m_zz, "zz/D");
00302 m_treeErrors->Branch("xy", &m_xy, "xy/D");
00303 m_treeErrors->Branch("xz", &m_xz, "xz/D");
00304 m_treeErrors->Branch("yz", &m_yz, "yz/D");
00305
00306
00307
00308
00309
00310 }
00311
00312
00313
00314 DEFINE_FWK_MODULE(TrackerGeometryIntoNtuples);