CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/OfflineValidation/plugins/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.5 2010/01/04 18:24:37 mussgill 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 #include "CLHEP/Matrix/SymMatrix.h"
00048 
00049 //
00050 // class decleration
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         // ----------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         int m_subdetid;
00073         double m_xx, m_xy, m_yy, m_xz, m_yz, m_zz;
00074         
00075         TTree *m_tree;
00076         TTree *m_treeErrors;
00077         std::string m_outputFile;
00078         std::string m_outputTreename;
00079         TFile *m_file;
00080 };
00081 
00082 //
00083 // constants, enums and typedefs
00084 //
00085 
00086 //
00087 // static data member definitions
00088 //
00089 
00090 //
00091 // constructors and destructor
00092 //
00093 TrackerGeometryIntoNtuples::TrackerGeometryIntoNtuples(const edm::ParameterSet& iConfig)
00094 {
00095         m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
00096         m_outputTreename = iConfig.getUntrackedParameter< std::string > ("outputTreename");
00097         m_file = new TFile(m_outputFile.c_str(),"RECREATE");
00098         m_tree = new TTree(m_outputTreename.c_str(),m_outputTreename.c_str());
00099         //char errorTreeName[256];
00100         //sprintf(errorTreeName, "%sErrors", m_outputTreename);
00101         //m_treeErrors = new TTree(errorTreeName,errorTreeName);
00102         m_treeErrors = new TTree("alignTreeErrors","alignTreeErrors");
00103         
00104 }
00105 
00106 
00107 TrackerGeometryIntoNtuples::~TrackerGeometryIntoNtuples()
00108 {}
00109 
00110 
00111 //
00112 // member functions
00113 //
00114 
00115 // ------------ method called to for each event  ------------
00116 void TrackerGeometryIntoNtuples::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00117 {
00118         edm::LogInfo("beginJob") << "Begin Job" << std::endl;
00119         
00120         //accessing the initial geometry
00121         edm::ESHandle<GeometricDet> theGeometricDet;
00122         iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
00123         TrackerGeomBuilderFromGeometricDet trackerBuilder;
00124         //currernt tracker
00125         TrackerGeometry* theCurTracker = trackerBuilder.build(&*theGeometricDet); 
00126         
00127         
00128         //build the tracker
00129         edm::ESHandle<Alignments> alignments;
00130         edm::ESHandle<AlignmentErrors> alignmentErrors;
00131         
00132         iSetup.get<TrackerAlignmentRcd>().get(alignments);
00133         iSetup.get<TrackerAlignmentErrorRcd>().get(alignmentErrors);
00134         
00135         //apply the latest alignments
00136         edm::ESHandle<Alignments> globalPositionRcd;
00137         iSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
00138         GeometryAligner aligner;
00139         aligner.applyAlignments<TrackerGeometry>( &(*theCurTracker), &(*alignments), &(*alignmentErrors),
00140                                                                                          align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
00141         
00142         
00143         theCurrentTracker = new AlignableTracker(&(*theCurTracker));    
00144         
00145         Alignments* theAlignments = theCurrentTracker->alignments();
00146         //AlignmentErrors* theAlignmentErrors = theCurrentTracker->alignmentErrors();   
00147         
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                 CLHEP::Hep3Vector translation = i->translation();
00154                 m_x = translation.x();
00155                 m_y = translation.y();
00156                 m_z = translation.z();
00157                 
00158         
00159                 CLHEP::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                 //DetId detid(m_rawid);
00166                 //if (detid.subdetId() > 2){
00167                 //PXFDetId pxfid( m_rawid );
00168                 //std::cout << " panel: " << pxfid.panel() << ", module: " << pxfid.module() << std::endl;
00169                 //if ((pxfid.panel() == 1) && (pxfid.module() == 4)) std::cout << m_rawid << ", ";
00170                 //std::cout << m_rawid << std::setprecision(9) <<  " " << m_x << " " << m_y << " " << m_z;
00171                 //std::cout << std::setprecision(9) << " " << m_alpha << " " << m_beta << " " << m_gamma << std::endl;  
00172                 //}
00173                 
00174         }
00175         
00176         std::vector<AlignTransformError> alignErrors = alignmentErrors->m_alignError;
00177         for (std::vector<AlignTransformError>::const_iterator i = alignErrors.begin(); i != alignErrors.end(); ++i){
00178 
00179                 m_rawid = i->rawId();
00180                 CLHEP::HepSymMatrix errMatrix = i->matrix();
00181                 DetId detid(m_rawid);
00182                 m_subdetid = detid.subdetId();
00183                 m_xx = errMatrix[0][0];
00184                 m_xy = errMatrix[0][1];
00185                 m_xz = errMatrix[0][2];
00186                 m_yy = errMatrix[1][1];
00187                 m_yz = errMatrix[1][2];
00188                 m_zz = errMatrix[2][2];
00189                 m_treeErrors->Fill();
00190         }
00191         
00192         //write out 
00193         m_file->cd();
00194         m_tree->Write();
00195         m_treeErrors->Write();
00196         m_file->Close();
00197 }
00198 
00199 
00200 void TrackerGeometryIntoNtuples::addBranches() {
00201         
00202         m_tree->Branch("rawid", &m_rawid, "rawid/I");
00203         m_tree->Branch("x", &m_x, "x/D");
00204         m_tree->Branch("y", &m_y, "y/D");
00205         m_tree->Branch("z", &m_z, "z/D");
00206         m_tree->Branch("alpha", &m_alpha, "alpha/D");
00207         m_tree->Branch("beta", &m_beta, "beta/D");
00208         m_tree->Branch("gamma", &m_gamma, "gamma/D");
00209         
00210         
00211         m_treeErrors->Branch("rawid", &m_rawid, "rawid/I");
00212         m_treeErrors->Branch("subdetid", &m_subdetid, "subdetid/I");
00213         m_treeErrors->Branch("xx", &m_xx, "xx/D");
00214         m_treeErrors->Branch("yy", &m_yy, "yy/D");
00215         m_treeErrors->Branch("zz", &m_zz, "zz/D");
00216         m_treeErrors->Branch("xy", &m_xy, "xy/D");
00217         m_treeErrors->Branch("xz", &m_xz, "xz/D");
00218         m_treeErrors->Branch("yz", &m_yz, "yz/D");
00219                 
00220 }
00221 
00222 
00223 //define this as a plug-in
00224 DEFINE_FWK_MODULE(TrackerGeometryIntoNtuples);