Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:47

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "Fireworks/Geometry/interface/FWRecoGeometry.h"
0007 #include "Fireworks/Geometry/interface/FWRecoGeometryRecord.h"
0008 
0009 #include "TFile.h"
0010 #include "TTree.h"
0011 #include "TError.h"
0012 #include "TSystem.h"
0013 
0014 class DumpFWRecoGeometry : public edm::one::EDAnalyzer<> {
0015 public:
0016   explicit DumpFWRecoGeometry(const edm::ParameterSet& config);
0017   ~DumpFWRecoGeometry(void) override {}
0018 
0019 private:
0020   void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override;
0021   void beginJob(void) override;
0022   void endJob(void) override;
0023 
0024   int m_level;
0025   std::string m_tag;
0026   std::string m_outputFileName;
0027   const edm::ESGetToken<FWRecoGeometry, FWRecoGeometryRecord> m_geomToken;
0028 };
0029 
0030 DumpFWRecoGeometry::DumpFWRecoGeometry(const edm::ParameterSet& config)
0031     : m_level(config.getUntrackedParameter<int>("level", 1)),
0032       m_tag(config.getUntrackedParameter<std::string>("tagInfo", "unknown")),
0033 
0034       m_outputFileName(config.getUntrackedParameter<std::string>("outputFileName", "cmsRecoGeo.root")),
0035       m_geomToken(esConsumes()) {}
0036 
0037 void DumpFWRecoGeometry::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
0038   using namespace edm;
0039 
0040   ESTransientHandle<FWRecoGeometry> geoh = eventSetup.getTransientHandle(m_geomToken);
0041   TFile file(m_outputFileName.c_str(), "RECREATE");
0042 
0043   TTree* tree = new TTree("idToGeo", "raw detector id association with geometry ANT");
0044 
0045   UInt_t v_id;
0046   Float_t v_vertex[24];
0047   Float_t v_params[9];
0048   Float_t v_shape[5];
0049   Float_t v_translation[3];
0050   Float_t v_matrix[9];
0051 
0052   tree->SetBranchStyle(0);
0053   tree->Branch("id", &v_id, "id/i");
0054   tree->Branch("points", &v_vertex, "points[24]/F");
0055   tree->Branch("topology", &v_params, "topology[9]/F");
0056   tree->Branch("shape", &v_shape, "shape[5]/F");
0057   tree->Branch("translation", &v_translation, "translation[3]/F");
0058   tree->Branch("matrix", &v_matrix, "matrix[9]/F");
0059 
0060   for (FWRecoGeom::InfoMapItr it = geoh.product()->idToName.begin(), end = geoh.product()->idToName.end(); it != end;
0061        ++it) {
0062     v_id = it->id;
0063     for (unsigned int i = 0; i < 24; ++i)
0064       v_vertex[i] = it->points[i];
0065     for (unsigned int i = 0; i < 9; ++i)
0066       v_params[i] = it->topology[i];
0067     for (unsigned int i = 0; i < 5; ++i)
0068       v_shape[i] = it->shape[i];
0069     for (unsigned int i = 0; i < 3; ++i)
0070       v_translation[i] = it->translation[i];
0071     for (unsigned int i = 0; i < 9; ++i)
0072       v_matrix[i] = it->matrix[i];
0073     tree->Fill();
0074   }
0075   file.WriteTObject(tree);
0076 
0077   file.WriteTObject(new TNamed("CMSSW_VERSION", gSystem->Getenv("CMSSW_VERSION")));
0078   file.WriteTObject(new TNamed("tag", m_tag.c_str()));
0079   file.WriteTObject(&geoh.product()->extraDet, "ExtraDetectors");
0080   file.WriteTObject(new TNamed("PRODUCER_VERSION", "1"));  // version 2 changes pixel parameters
0081 
0082   file.WriteTObject(new TNamed("TrackerTopology", geoh.product()->trackerTopologyXML));
0083 
0084   file.Close();
0085 }
0086 
0087 void DumpFWRecoGeometry::beginJob(void) {}
0088 
0089 void DumpFWRecoGeometry::endJob(void) {}
0090 
0091 DEFINE_FWK_MODULE(DumpFWRecoGeometry);