CMS 3D CMS Logo

MuonGeometryIntoNtuples.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuonGeometryIntoNtuples
00004 // Class:      MuonGeometryIntoNtuples
00005 // 
00013 //
00014 // Original Author:  Jim Pivarski
00015 //         Created:  Mon Jul 16 16:56:34 CDT 2007
00016 // $Id: MuonGeometryIntoNtuples.cc,v 1.1 2008/02/27 17:31:44 ebutz Exp $
00017 //
00018 //
00019 
00020 // system include files
00021 #include <memory>
00022 #include <map>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/EDAnalyzer.h"
00026 #include "FWCore/Framework/interface/EventSetup.h"
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031 
00032 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
00033 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00034 #include "CondFormats/Alignment/interface/AlignmentErrors.h" 
00035 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00036 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00037 #include "Geometry/Records/interface/MuonNumberingRecord.h"
00038 #include "Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h"
00039 #include "Geometry/CSCGeometryBuilder/src/CSCGeometryBuilderFromDDD.h"
00040 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00041 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
00042 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
00043 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
00044 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorRcd.h"
00045 #include "CondFormats/Alignment/interface/SurveyErrors.h"
00046 #include "CondFormats/AlignmentRecord/interface/DTSurveyRcd.h"
00047 #include "CondFormats/AlignmentRecord/interface/DTSurveyErrorRcd.h"
00048 #include "CondFormats/AlignmentRecord/interface/CSCSurveyRcd.h"
00049 #include "CondFormats/AlignmentRecord/interface/CSCSurveyErrorRcd.h"
00050 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
00051 #include "Alignment/CommonAlignment/interface/StructureType.h"
00052 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00053 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
00054 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
00055 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00056 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00057 #include "CLHEP/Matrix/SymMatrix.h"
00058 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00059 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00060 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00061 
00062 #include "FWCore/ServiceRegistry/interface/Service.h"
00063 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00064 #include "TTree.h"
00065 
00066 //
00067 // class decleration
00068 //
00069 
00070 class MuonGeometryIntoNtuples : public edm::EDAnalyzer {
00071    public:
00072       explicit MuonGeometryIntoNtuples(const edm::ParameterSet&);
00073       ~MuonGeometryIntoNtuples();
00074 
00075 
00076    private:
00077       virtual void beginJob(const edm::EventSetup &iSetup);
00078       virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
00079       virtual void endJob() ;
00080 
00081       void getOriginals(Alignable *ali);
00082       void addBranches(TTree* tree);
00083       void recursiveWalk(Alignable *ali);
00084       int getId(Alignable *ali);
00085 
00086       // ----------member data ---------------------------
00087 
00088       AlignableObjectId m_alignableObjectId;
00089       enum { kMaxChildren = 256 };
00090 
00091       std::map<int, GlobalPoint> m_originalPositions;
00092       std::map<int, align::RotationType> m_originalRotations;
00093 
00094       bool m_dtApplyAlignment, m_cscApplyAlignment;
00095       bool m_dtFromSurvey, m_cscFromSurvey;
00096       std::string m_dtLabel, m_cscLabel;
00097       bool m_doMisalignmentScenario;
00098       edm::ParameterSet m_misalignmentScenario;
00099 
00100       bool m_book_dtWheels, m_book_dtStations, m_book_dtChambers, m_book_dtSuperLayers, m_book_dtLayers,
00101          m_book_cscStations, m_book_cscChambers, m_book_cscLayers;
00102       
00103       TTree *m_dtWheels, *m_dtStations, *m_dtChambers, *m_dtSuperLayers, *m_dtLayers,
00104          *m_cscStations, *m_cscChambers, *m_cscLayers;
00105 
00106       Int_t m_rawid;
00107       Char_t m_structa, m_structb, m_structc, m_slayer, m_layer;
00108       Float_t m_x, m_y, m_z;
00109       Float_t m_xhatx, m_xhaty, m_xhatz, m_yhatx, m_yhaty, m_yhatz, m_zhatx, m_zhaty, m_zhatz;
00110       Float_t m_dx, m_dy, m_dz;
00111       Float_t m_dxx, m_dxy, m_dxz, m_dyx, m_dyy, m_dyz, m_dzx, m_dzy, m_dzz;
00112       Int_t m_parent, m_numChildren, m_children[kMaxChildren];
00113 };
00114 
00115 //
00116 // constants, enums and typedefs
00117 //
00118 
00119 //
00120 // static data member definitions
00121 //
00122 
00123 //
00124 // constructors and destructor
00125 //
00126 MuonGeometryIntoNtuples::MuonGeometryIntoNtuples(const edm::ParameterSet& iConfig)
00127 {
00128    m_dtApplyAlignment = iConfig.getParameter<bool>("DTApplyAlignment");
00129    m_cscApplyAlignment = iConfig.getParameter<bool>("CSCApplyAlignment");
00130    m_dtFromSurvey = iConfig.getParameter<bool>("DTFromSurveyRcd");
00131    m_cscFromSurvey = iConfig.getParameter<bool>("CSCFromSurveyRcd");
00132    m_dtLabel = iConfig.getParameter<std::string>("DTAlignmentLabel");
00133    m_cscLabel = iConfig.getParameter<std::string>("CSCAlignmentLabel");
00134    m_doMisalignmentScenario = iConfig.getParameter<bool>("ApplyMisalignmentScenario");
00135    m_misalignmentScenario = iConfig.getParameter<edm::ParameterSet>("MisalignmentScenario");
00136 
00137    m_book_dtWheels = iConfig.getUntrackedParameter<bool>("DTWheels", true);
00138    m_book_dtStations = iConfig.getUntrackedParameter<bool>("DTStations", true);
00139    m_book_dtChambers = iConfig.getUntrackedParameter<bool>("DTChambers", true);
00140    m_book_dtSuperLayers = iConfig.getUntrackedParameter<bool>("DTSuperLayers", true);
00141    m_book_dtLayers = iConfig.getUntrackedParameter<bool>("DTLayers", true);
00142    m_book_cscStations = iConfig.getUntrackedParameter<bool>("CSCStations", true);
00143    m_book_cscChambers = iConfig.getUntrackedParameter<bool>("CSCChambers", true);
00144    m_book_cscLayers = iConfig.getUntrackedParameter<bool>("CSCLayers", true);
00145 }
00146 
00147 
00148 MuonGeometryIntoNtuples::~MuonGeometryIntoNtuples()
00149 {}
00150 
00151 
00152 //
00153 // member functions
00154 //
00155 
00156 // ------------ method called to for each event  ------------
00157 void
00158 MuonGeometryIntoNtuples::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00159 {}
00160 
00161 
00162 // ------------ method called once each job just before starting event loop  ------------
00163 void 
00164 MuonGeometryIntoNtuples::beginJob(const edm::EventSetup& iSetup)
00165 {
00166    edm::LogWarning("MuonGeometryIntoNtuples") << "begin";
00167 
00168    // Build ideal geometry
00169    edm::ESHandle<DDCompactView> cpv;
00170    iSetup.get<IdealGeometryRecord>().get(cpv);
00171 
00172    edm::ESHandle<MuonDDDConstants> mdc;
00173    iSetup.get<MuonNumberingRecord>().get(mdc);
00174    DTGeometryBuilderFromDDD DTGeometryBuilder;
00175    CSCGeometryBuilderFromDDD CSCGeometryBuilder;
00176 
00177    // Before 1_7_X
00178 //    DTGeometry *dtGeometry = DTGeometryBuilder.build(&(*cpv), *mdc);
00179 //    CSCGeometry *cscGeometry = CSCGeometryBuilder.build(&(*cpv), *mdc);
00180 
00181    // 1_7_X and later
00182    DTGeometry *dtGeometry = DTGeometryBuilder.build(&(*cpv), *mdc);
00183    boost::shared_ptr<CSCGeometry> boost_cscGeometry;
00184    CSCGeometryBuilder.build(boost_cscGeometry, &(*cpv), *mdc);
00185    CSCGeometry *cscGeometry = &(*boost_cscGeometry);
00186 
00187    edm::LogWarning("MuonGeometryIntoNtuples") << "built ideal geometry";
00188 
00189    AlignableMuon originals(dtGeometry, cscGeometry);
00190    getOriginals(&originals);
00191 
00192    edm::LogWarning("MuonGeometryIntoNtuples") << "recorded original positions/orientations";
00193 
00194    // Apply a (mis)aligned geometry
00195 
00196    GeometryAligner aligner;
00197    edm::ESHandle<Alignments> dtAlignments, cscAlignments;
00198    edm::ESHandle<AlignmentErrors> dtAlignmentErrors, cscAlignmentErrors;
00199 
00200    edm::ESHandle<Alignments> globalPositionRcd;
00201    iSetup.get<MuonGeometryRecord>().getRecord<GlobalPositionRcd>().get(globalPositionRcd);
00202 
00203    if (m_dtApplyAlignment) {
00204       if (m_dtFromSurvey) {
00205          edm::LogWarning("MuonGeometryIntoNtuples") << "applying (mis)alignment from DTSurveyRcd \"" << m_dtLabel << "\"";
00206          iSetup.get<DTSurveyRcd>().get(m_dtLabel, dtAlignments);
00207          edm::ESHandle<SurveyErrors> surveyErrors;
00208          iSetup.get<DTSurveyErrorRcd>().get(m_dtLabel, surveyErrors);
00209 
00210          AlignmentErrors alignmentErrors;
00211          for (std::vector<SurveyError>::const_iterator iter = surveyErrors->m_surveyErrors.begin();  iter != surveyErrors->m_surveyErrors.end();  ++iter) {
00212             align::ErrorMatrix matrix6by6 = iter->matrix();  // start from 0,0
00213             CLHEP::HepSymMatrix matrix3by3(3);               // start from 1,1
00214             for (int i = 0;  i < 3;  i++) {
00215                for (int j = 0;  j < 3;  j++) {
00216                   matrix3by3(i+1, j+1) = matrix6by6(i, j);
00217                }
00218             }
00219             alignmentErrors.m_alignError.push_back(AlignTransformError(matrix3by3, iter->rawId()));
00220          }
00221          aligner.applyAlignments<DTGeometry>(dtGeometry, &(*dtAlignments), &alignmentErrors,
00222                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
00223       }
00224       else {
00225          edm::LogWarning("MuonGeometryIntoNtuples") << "applying (mis)alignment from DTAlignmentRcd \"" << m_dtLabel << "\"";
00226          iSetup.get<DTAlignmentRcd>().get(m_dtLabel, dtAlignments);
00227          iSetup.get<DTAlignmentErrorRcd>().get(m_dtLabel, dtAlignmentErrors);
00228          aligner.applyAlignments<DTGeometry>(dtGeometry, &(*dtAlignments), &(*dtAlignmentErrors),
00229                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
00230       }
00231       edm::LogWarning("MuonGeometryIntoNtuples") << "done!";
00232    }
00233    else {
00234       edm::LogWarning("MuonGeometryIntoNtuples") << "NOT applying a DT alignment or misalignment";
00235    }
00236 
00237    if (m_cscApplyAlignment) {
00238       if (m_cscFromSurvey) {
00239          edm::LogWarning("MuonGeometryIntoNtuples") << "applying (mis)alignment from CSCSurveyRcd \"" << m_cscLabel << "\"";
00240          iSetup.get<CSCSurveyRcd>().get(m_cscLabel, cscAlignments);
00241          edm::ESHandle<SurveyErrors> surveyErrors;
00242          iSetup.get<CSCSurveyErrorRcd>().get(m_cscLabel, surveyErrors);
00243 
00244          AlignmentErrors alignmentErrors;
00245          for (std::vector<SurveyError>::const_iterator iter = surveyErrors->m_surveyErrors.begin();  iter != surveyErrors->m_surveyErrors.end();  ++iter) {
00246             align::ErrorMatrix matrix6by6 = iter->matrix();  // start from 0,0
00247             CLHEP::HepSymMatrix matrix3by3(3);               // start from 1,1
00248             for (int i = 0;  i < 3;  i++) {
00249                for (int j = 0;  j < 3;  j++) {
00250                   matrix3by3(i+1, j+1) = matrix6by6(i, j);
00251                }
00252             }
00253             alignmentErrors.m_alignError.push_back(AlignTransformError(matrix3by3, iter->rawId()));
00254          }
00255          aligner.applyAlignments<CSCGeometry>(cscGeometry, &(*cscAlignments), &alignmentErrors,
00256                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
00257       }
00258       else {
00259          edm::LogWarning("MuonGeometryIntoNtuples") << "applying (mis)alignment from CSCAlignmentRcd \"" << m_cscLabel << "\"";
00260          iSetup.get<CSCAlignmentRcd>().get(m_cscLabel, cscAlignments);
00261          iSetup.get<CSCAlignmentErrorRcd>().get(m_cscLabel, cscAlignmentErrors);
00262          aligner.applyAlignments<CSCGeometry>(cscGeometry, &(*cscAlignments), &(*cscAlignmentErrors),
00263                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
00264       }
00265       edm::LogWarning("MuonGeometryIntoNtuples") << "done!";
00266    }
00267    else {
00268       edm::LogWarning("MuonGeometryIntoNtuples") << "NOT applying a CSC alignment or misalignment";
00269    }
00270 
00271    // Create an alignable geometry (I'm more familiar with this version)
00272    AlignableMuon alignableMuon(dtGeometry, cscGeometry);
00273    edm::LogWarning("MuonGeometryIntoNtuples") << "created AlignableMuon tree";
00274 
00275    if (m_doMisalignmentScenario) {
00276       edm::LogWarning("MuonGeometryIntoNtuples") << "applying the MisalignmentScenario";
00277       MuonScenarioBuilder muonScenarioBuilder(&alignableMuon);
00278       muonScenarioBuilder.applyScenario(m_misalignmentScenario);
00279       edm::LogWarning("MuonGeometryIntoNtuples") << "done!";
00280    }
00281    else {
00282       edm::LogWarning("MuonGeometryIntoNtuples") << "NOT applying any MisalignmentScenario";
00283    }
00284 
00285    // Prepare the output
00286    edm::Service<TFileService> tfile;
00287 
00288    m_dtWheels = m_dtStations = m_dtChambers = m_dtSuperLayers = m_dtLayers = m_cscStations = m_cscChambers = m_cscLayers = NULL;
00289 
00290    if (m_book_dtWheels) {
00291       edm::LogWarning("MuonGeometryIntoNtuples") << "booking DTWheels TTree";
00292       m_dtWheels      = tfile->make<TTree>("DTWheels", "DTWheels");
00293       addBranches(m_dtWheels);
00294    }
00295    if (m_book_dtStations) {
00296       edm::LogWarning("MuonGeometryIntoNtuples") << "booking DTStations TTree";
00297       m_dtStations    = tfile->make<TTree>("DTStations", "DTStations");
00298       addBranches(m_dtStations);
00299    }
00300    if (m_book_dtChambers) {
00301       edm::LogWarning("MuonGeometryIntoNtuples") << "booking DTChambers TTree";
00302       m_dtChambers    = tfile->make<TTree>("DTChambers", "DTChambers");
00303       addBranches(m_dtChambers);
00304    }
00305    if (m_book_dtSuperLayers) {
00306       edm::LogWarning("MuonGeometryIntoNtuples") << "booking DTSuperLayers TTree";
00307       m_dtSuperLayers = tfile->make<TTree>("DTSuperLayers", "DTSuperLayers");
00308       addBranches(m_dtSuperLayers);
00309    }
00310    if (m_book_dtLayers) {
00311       edm::LogWarning("MuonGeometryIntoNtuples") << "booking DTLayers TTree";
00312       m_dtLayers      = tfile->make<TTree>("DTLayers", "DTLayers");
00313       addBranches(m_dtLayers);
00314    }
00315    if (m_book_cscStations) {
00316       edm::LogWarning("MuonGeometryIntoNtuples") << "booking CSCStations TTree";
00317       m_cscStations   = tfile->make<TTree>("CSCStations", "CSCStations");
00318       addBranches(m_cscStations);
00319    }
00320    if (m_book_cscChambers) {
00321       edm::LogWarning("MuonGeometryIntoNtuples") << "booking CSCChambers TTree";
00322       m_cscChambers   = tfile->make<TTree>("CSCChambers", "CSCChambers");
00323       addBranches(m_cscChambers);
00324    }
00325    if (m_book_cscLayers) {
00326       edm::LogWarning("MuonGeometryIntoNtuples") << "booking CSCLayers TTree";
00327       m_cscLayers     = tfile->make<TTree>("CSCLayers", "CSCLayers");
00328       addBranches(m_cscLayers);
00329    }
00330 
00331    edm::LogWarning("MuonGeometryIntoNtuples") << "filling ntuples";
00332 
00333    // Write it out
00334    recursiveWalk(&alignableMuon);
00335 
00336    edm::LogWarning("MuonGeometryIntoNtuples") << "done with everything!";
00337 }
00338 
00339 void MuonGeometryIntoNtuples::getOriginals(Alignable *ali) {
00340    int id = getId(ali) * 100 + ali->alignableObjectId();
00341    m_originalPositions[id] = ali->globalPosition();
00342    m_originalRotations[id] = ali->globalRotation();
00343 
00344    std::vector<Alignable*> components = ali->components();
00345    for (std::vector<Alignable*>::const_iterator iter = components.begin();  iter != components.end();  ++iter) {
00346       getOriginals(*iter);
00347    }
00348 }
00349 
00350 void MuonGeometryIntoNtuples::addBranches(TTree* tree) {
00351    // The branches are nearly the same on all eight TTrees
00352 
00353    tree->Branch("rawid", &m_rawid, "rawid/I");
00354    tree->Branch("structa", &m_structa, "structa/B");
00355    tree->Branch("structb", &m_structb, "structb/B");
00356    tree->Branch("structc", &m_structc, "structc/B");
00357    tree->Branch("slayer", &m_slayer, "slayer/B");
00358    tree->Branch("layer", &m_layer, "layer/B");
00359 
00360    tree->Branch("x", &m_x, "x/F");
00361    tree->Branch("y", &m_y, "y/F");
00362    tree->Branch("z", &m_z, "z/F");
00363 
00364    tree->Branch("xhatx", &m_xhatx, "xhatx/F");
00365    tree->Branch("xhaty", &m_xhaty, "xhaty/F");
00366    tree->Branch("xhatz", &m_xhatz, "xhatz/F");
00367    tree->Branch("yhatx", &m_yhatx, "yhatx/F");
00368    tree->Branch("yhaty", &m_yhaty, "yhaty/F");
00369    tree->Branch("yhatz", &m_yhatz, "yhatz/F");
00370    tree->Branch("zhatx", &m_zhatx, "zhatx/F");
00371    tree->Branch("zhaty", &m_zhaty, "zhaty/F");
00372    tree->Branch("zhatz", &m_zhatz, "zhatz/F");
00373 
00374    tree->Branch("dx", &m_dx, "dx/F");
00375    tree->Branch("dy", &m_dy, "dy/F");
00376    tree->Branch("dz", &m_dz, "dz/F");
00377 
00378    tree->Branch("dxx", &m_dxx, "dxx/F");
00379    tree->Branch("dxy", &m_dxy, "dxy/F");
00380    tree->Branch("dxz", &m_dxz, "dxz/F");
00381    tree->Branch("dyx", &m_dyx, "dyx/F");
00382    tree->Branch("dyy", &m_dyy, "dyy/F");
00383    tree->Branch("dyz", &m_dyz, "dyz/F");
00384    tree->Branch("dzx", &m_dzx, "dzx/F");
00385    tree->Branch("dzy", &m_dzy, "dzy/F");
00386    tree->Branch("dzz", &m_dzz, "dzz/F");
00387 
00388    tree->Branch("parent", &m_parent, "parent/I");
00389    tree->Branch("numChildren", &m_numChildren, "numChildren/I");
00390    tree->Branch("children", &m_children, "children[numChildren]/I");
00391 }
00392 
00393 int MuonGeometryIntoNtuples::getId(Alignable *ali) {
00394    if (ali == NULL) return 0;
00395 
00396    int rawid = ali->geomDetId().rawId();
00397    while (rawid == 0) {
00398       std::vector<Alignable*> components = ali->components();
00399       if (components.size() == 0) {
00400          return rawid;
00401       }
00402       else {
00403          ali = components[0];
00404          rawid = ali->geomDetId().rawId();
00405       }
00406    }
00407    return rawid;
00408 }
00409 
00410 void MuonGeometryIntoNtuples::recursiveWalk(Alignable *ali) {
00411    edm::LogInfo("MuonGeometryIntoNtuples") << "filling ntuple for " << m_alignableObjectId.typeToName(ali->alignableObjectId()) << " " << getId(ali);
00412 
00413    // Depth first, so that you can skip the largest structures without
00414    // skipping all of their components
00415    std::vector<Alignable*> components = ali->components();
00416    for (std::vector<Alignable*>::const_iterator iter = components.begin();  iter != components.end();  ++iter) {
00417       recursiveWalk(*iter);
00418    }
00419 
00420    // Get a pointer to whatever ntuple we're filling (they're all so similar)
00421    TTree *tree;
00422    if (ali->alignableObjectId() == align::AlignableDTWheel) tree = m_dtWheels;
00423    else if (ali->alignableObjectId() == align::AlignableDTStation) tree = m_dtStations;
00424    else if (ali->alignableObjectId() == align::AlignableDTChamber) tree = m_dtChambers;
00425    else if (ali->alignableObjectId() == align::AlignableDTSuperLayer  ||
00426             (ali->alignableObjectId() == align::AlignableDet  &&  ali->geomDetId().subdetId() == MuonSubdetId::DT)) tree = m_dtSuperLayers;
00427    else if (ali->alignableObjectId() == align::AlignableDTLayer  ||
00428             (ali->alignableObjectId() == align::AlignableDetUnit  &&  ali->geomDetId().subdetId() == MuonSubdetId::DT)) tree = m_dtLayers;
00429    else if (ali->alignableObjectId() == align::AlignableCSCStation) tree = m_cscStations;
00430    else if (ali->alignableObjectId() == align::AlignableCSCChamber) tree = m_cscChambers;
00431    else if (ali->alignableObjectId() == align::AlignableCSCLayer  ||
00432             ((ali->alignableObjectId() == align::AlignableDet  ||
00433               ali->alignableObjectId() == align::AlignableDetUnit)  &&  ali->geomDetId().subdetId() == MuonSubdetId::CSC)) tree = m_cscLayers;
00434    else if (ali->alignableObjectId() == align::AlignableDTBarrel  ||
00435             ali->alignableObjectId() == align::AlignableCSCEndcap  ||
00436             ali->alignableObjectId() == align::AlignableMuon) {
00437       // skip these
00438       return;
00439    }
00440    else {
00441       throw cms::Exception("BadAssociation") << "Alignable in AlignableMuon has an unidentified type: " << ali->alignableObjectId() << std::endl;
00442    }
00443 
00444    if (tree == NULL) return;  // maybe I've chosen not to book this one
00445 
00446    // get a surface and start filling the ntuple entries
00447    AlignableSurface surface = ali->surface();
00448 
00449    m_rawid = getId(ali);
00450 
00451    if (DetId(m_rawid).subdetId() == MuonSubdetId::DT) {
00452       if (tree == m_dtLayers) {
00453          DTLayerId id(m_rawid);
00454          m_structa = id.wheel();
00455          m_structb = id.station();
00456          m_structc = id.sector();
00457          m_slayer = id.superLayer();
00458          m_layer = id.layer();
00459       }
00460       else if (tree == m_dtSuperLayers) {
00461          DTSuperLayerId id(m_rawid);
00462          m_structa = id.wheel();
00463          m_structb = id.station();
00464          m_structc = id.sector();
00465          m_slayer = id.superLayer();
00466          m_layer = 127;
00467       }
00468       else {
00469          DTChamberId id(m_rawid);
00470          m_structa = id.wheel();
00471          m_structb = id.station();
00472          m_structc = id.sector();
00473          m_slayer = 127;
00474          m_layer = 127;
00475       }
00476    }
00477    else if (DetId(m_rawid).subdetId() == MuonSubdetId::CSC) {
00478       CSCDetId id(m_rawid);
00479       m_structa = (id.endcap() == 1? 1: -1)*id.station();
00480       m_structb = id.ring();
00481       m_structc = id.chamber();
00482       m_slayer = 127;
00483       m_layer = (id.layer() == 0? 127: id.layer());
00484    }
00485    else {
00486       throw cms::Exception("BadAssociation") << "This alignable is neither a DT nor a CSC: " << m_rawid << std::endl;
00487    }
00488 
00489    GlobalPoint position = surface.toGlobal(LocalPoint(0., 0., 0.));
00490    m_x = position.x();
00491    m_y = position.y();
00492    m_z = position.z();
00493 
00494    GlobalVector xhat = surface.toGlobal(LocalVector(1., 0., 0.));
00495    GlobalVector yhat = surface.toGlobal(LocalVector(0., 1., 0.));
00496    GlobalVector zhat = surface.toGlobal(LocalVector(0., 0., 1.));
00497    m_xhatx = xhat.x();
00498    m_xhaty = xhat.y();
00499    m_xhatz = xhat.z();
00500    m_yhatx = yhat.x();
00501    m_yhaty = yhat.y();
00502    m_yhatz = yhat.z();
00503    m_zhatx = zhat.x();
00504    m_zhaty = zhat.y();
00505    m_zhatz = zhat.z();
00506 
00507    // get original position/orientation
00508    int id = m_rawid * 100 + ali->alignableObjectId();
00509    GlobalPoint originalPosition = m_originalPositions[id];
00510    align::RotationType originalRotation = m_originalRotations[id];
00511 
00512    // subtract off the ideal position (left to right)
00513    GlobalVector displacement = ali->globalPosition() - originalPosition;
00514    m_dx = displacement.x();
00515    m_dy = displacement.y();
00516    m_dz = displacement.z();
00517    
00518    // rotate off the ideal orientation (right to left: matrix multiplication)
00519    align::RotationType rotation = originalRotation.multiplyInverse(ali->globalRotation());
00520    m_dxx = rotation.xx();
00521    m_dxy = rotation.xy();
00522    m_dxz = rotation.xz();
00523    m_dyx = rotation.yx();
00524    m_dyy = rotation.yy();
00525    m_dyz = rotation.yz();
00526    m_dzx = rotation.zx();
00527    m_dzy = rotation.zy();
00528    m_dzz = rotation.zz();
00529 
00530    m_parent = getId(ali->mother());
00531    m_numChildren = 0;
00532    for (std::vector<Alignable*>::const_iterator iter = components.begin();  iter != components.end();  ++iter) {
00533       m_children[m_numChildren] = getId(*iter);
00534       m_numChildren++;
00535 
00536       if (m_numChildren > kMaxChildren) {
00537          throw cms::Exception("BadAssociation") << "More than " << (m_numChildren-1) << " descend from a single alignable." << std::endl;
00538       }
00539    }
00540 
00541    // Pad it for safety...
00542    for (int i = m_numChildren;  i < kMaxChildren;  i++) {
00543       m_children[i] = 0;
00544    }
00545 
00546    // Fill 'er up
00547    tree->Fill();
00548    return;
00549 }
00550 
00551 // ------------ method called once each job just after ending the event loop  ------------
00552 void 
00553 MuonGeometryIntoNtuples::endJob() {
00554 }
00555 
00556 //define this as a plug-in
00557 DEFINE_FWK_MODULE(MuonGeometryIntoNtuples);

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