Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-08 22:26:18

0001 // -*- C++ -*-
0002 //
0003 // Package:    DumpSimGeometry
0004 // Class:      DumpSimGeometry
0005 //
0006 /**\class DumpSimGeometry DumpSimGeometry.cc Reve/DumpSimGeometry/src/DumpSimGeometry.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris D Jones
0015 //         Created:  Wed Sep 26 08:27:23 EDT 2007
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include "FWCore/Framework/interface/ESHandle.h"
0033 #include "FWCore/Framework/interface/EventSetup.h"
0034 #include "FWCore/Framework/interface/ESTransientHandle.h"
0035 
0036 #include "Fireworks/Geometry/interface/DisplayGeomRecord.h"
0037 
0038 #include "TGeoManager.h"
0039 #include "TGeoMatrix.h"
0040 
0041 #include "TFile.h"
0042 #include "TError.h"
0043 #include "TSystem.h"
0044 
0045 //
0046 // class declaration
0047 //
0048 
0049 class DumpSimGeometry : public edm::one::EDAnalyzer<> {
0050 public:
0051   explicit DumpSimGeometry(const edm::ParameterSet&);
0052   ~DumpSimGeometry() override;
0053 
0054 private:
0055   void analyze(const edm::Event&, const edm::EventSetup&) override;
0056 
0057   std::string m_tag;
0058   std::string m_outputFileName;
0059   const edm::ESGetToken<TGeoManager, DisplayGeomRecord> m_geomToken;
0060 };
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 DumpSimGeometry::DumpSimGeometry(const edm::ParameterSet& ps) : m_geomToken(esConsumes()) {
0066   m_tag = ps.getUntrackedParameter<std::string>("tag", "unknown");
0067   m_outputFileName = ps.getUntrackedParameter<std::string>("outputFileName", "cmsSimGeom.root");
0068 }
0069 
0070 DumpSimGeometry::~DumpSimGeometry() {
0071   // do anything here that needs to be done at desctruction time
0072   // (e.g. close files, deallocate resources etc.)
0073 }
0074 
0075 // ------------ method called to for each event  ------------
0076 void DumpSimGeometry::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077   std::cout << "In the DumpSimGeometry::analyze method..." << std::endl;
0078   using namespace edm;
0079 
0080   ESTransientHandle<TGeoManager> geoh = iSetup.getTransientHandle(m_geomToken);
0081   const TGeoManager* geom = geoh.product();  // const_cast<TGeoManager*>(geoh.product());
0082 
0083   int level = 1 + geom->GetTopVolume()->CountNodes(100, 3);
0084 
0085   std::cout << "In the DumpSimGeometry::analyze method...obtained main geometry, level=" << level << std::endl;
0086 
0087   // TFile f(TString::Format("cmsSimGeom-%d.root", level), "RECREATE");
0088   TFile f(m_outputFileName.c_str(), "RECREATE");
0089   f.WriteTObject(geom);
0090   f.WriteTObject(new TNamed("CMSSW_VERSION", gSystem->Getenv("CMSSW_VERSION")));
0091   f.WriteTObject(new TNamed("tag", m_tag.c_str()));
0092   f.Close();
0093 }
0094 
0095 //define this as a plug-in
0096 DEFINE_FWK_MODULE(DumpSimGeometry);