CMS 3D CMS Logo

TrackerGeometryIntoNtuples.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TrackerGeometryIntoNtuples
00004 // Class:      TrackerGeometryIntoNtuples
00005 // 
00013 //
00014 // Original Author:  Nhan Tran
00015 //         Created:  Mon Jul 16m 16:56:34 CDT 2007
00016 // $Id: TrackerGeometryIntoNtuples.cc,v 1.1 2008/02/27 17:33:54 ebutz Exp $
00017 //
00018 //
00019 
00020 // system include files
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 //
00048 // class decleration
00049 //
00050 
00051 class TrackerGeometryIntoNtuples : public edm::EDAnalyzer {
00052 public:
00053         explicit TrackerGeometryIntoNtuples(const edm::ParameterSet&);
00054         ~TrackerGeometryIntoNtuples();
00055         
00056         
00057 private:
00058         virtual void beginJob(const edm::EventSetup &iSetup);
00059         virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
00060         virtual void endJob() ;
00061         
00062         void addBranches();
00063         
00064         // ----------member data ---------------------------
00065         //std::vector<AlignTransform> m_align;
00066         Alignments* theAlignments;
00067         AlignableTracker* theCurrentTracker;
00068 
00069         uint32_t m_rawid;
00070         double m_x, m_y, m_z;
00071         double m_alpha, m_beta, m_gamma;
00072         double m_xx, m_yx, m_yy, m_zx, m_zy, 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 // constants, enums and typedefs
00083 //
00084 
00085 //
00086 // static data member definitions
00087 //
00088 
00089 //
00090 // constructors and destructor
00091 //
00092 TrackerGeometryIntoNtuples::TrackerGeometryIntoNtuples(const edm::ParameterSet& iConfig)
00093 {
00094         m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
00095         m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
00096         m_file = new TFile(m_outputFile.c_str(),"RECREATE");
00097         m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
00098 
00099         
00100 }
00101 
00102 
00103 TrackerGeometryIntoNtuples::~TrackerGeometryIntoNtuples()
00104 {}
00105 
00106 
00107 //
00108 // member functions
00109 //
00110 
00111 // ------------ method called to for each event  ------------
00112 void TrackerGeometryIntoNtuples::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00113 {}
00114 
00115 
00116 // ------------ method called once each job just before starting event loop  ------------
00117 void TrackerGeometryIntoNtuples::beginJob(const edm::EventSetup& iSetup)
00118 {
00119         edm::LogInfo("beginJob") << "Begin Job" << std::endl;
00120         
00121         //accessing the initial geometry
00122         edm::ESHandle<GeometricDet> theGeometricDet;
00123         iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
00124         TrackerGeomBuilderFromGeometricDet trackerBuilder;
00125         //currernt tracker
00126         TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet); 
00127 
00128         
00129         //build the tracker
00130         edm::ESHandle<Alignments> alignments;
00131         edm::ESHandle<AlignmentErrors> alignmentErrors;
00132         
00133         iSetup.get<TrackerAlignmentRcd>().get(alignments);
00134         iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
00135         
00136         //apply the latest alignments
00137         edm::ESHandle<Alignments> globalPositionRcd;
00138         iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
00139         GeometryAligner aligner;
00140         aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
00141                                                   align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
00142         
00143         
00144         theCurrentTracker = new AlignableTracker(&(*theCurTracker));    
00145         
00146         Alignments* theAlignments = theCurrentTracker->alignments();
00147         //not used AlignmentErrors* theAlignmentErrors = theCurrentTracker->alignmentErrors();  
00148         //alignments
00149         addBranches();
00150         for (std::vector<AlignTransform>::const_iterator i = theAlignments->m_align.begin(); i != theAlignments->m_align.end(); ++i){
00151 
00152                 m_rawid = i->rawId();
00153                 Hep3Vector translation = i->translation();
00154                 m_x = translation.x();
00155                 m_y = translation.y();
00156                 m_z = translation.z();
00157 
00158                 
00159                 HepRotation rotation = i->rotation();
00160                 m_alpha = rotation.getPhi();
00161                 m_beta = rotation.getTheta();
00162                 m_gamma = rotation.getPsi();
00163                 m_tree->Fill();
00164                 
00165         }
00166 
00167         //write out 
00168         m_file->cd();
00169         m_tree->Write();
00170         m_file->Close();
00171 }
00172 
00173 
00174 
00175 void TrackerGeometryIntoNtuples::addBranches() {
00176 
00177    m_tree->Branch("rawid", &m_rawid, "rawid/I");
00178    m_tree->Branch("x", &m_x, "x/D");
00179    m_tree->Branch("y", &m_y, "y/D");
00180    m_tree->Branch("z", &m_z, "z/D");
00181          m_tree->Branch("alpha", &m_alpha, "alpha/D");
00182          m_tree->Branch("beta", &m_beta, "beta/D");
00183          m_tree->Branch("gamma", &m_gamma, "gamma/D");
00184 
00185 }
00186 
00187 
00188 // ------------ method called once each job just after ending the event loop  ------------
00189 void TrackerGeometryIntoNtuples::endJob() {
00190 }
00191 
00192 
00193 
00194 //define this as a plug-in
00195 DEFINE_FWK_MODULE(TrackerGeometryIntoNtuples);

Generated on Tue Jun 9 17:24:57 2009 for CMSSW by  doxygen 1.5.4