Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:49:11

0001 /// CSCLayerGeometryInside.cc
0002 /// Test CSCLayerGeometry::inside fiducial function
0003 /// Tim Cox - 06.05.2009
0004 
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0011 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0012 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0013 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
0014 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
0015 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0016 
0017 #include "TH2F.h"
0018 #include "TFile.h"
0019 #include "TRandom3.h"
0020 
0021 #include <string>
0022 
0023 class CSCLayerGeometryInside : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0024 public:
0025   explicit CSCLayerGeometryInside(const edm::ParameterSet&);
0026   ~CSCLayerGeometryInside() override;
0027 
0028   void beginJob() override {}
0029   void analyze(edm::Event const&, edm::EventSetup const&) override;
0030   void endJob() override {}
0031 
0032   const std::string& myName() { return myName_; }
0033 
0034 private:
0035   const int dashedLineWidth_;
0036   const std::string dashedLine_;
0037   const std::string myName_;
0038 
0039   const int ntries;  // no. of points to generate (set in config)
0040 
0041   // No,. of bins and range of x and y generation (set in config)
0042   const int nbx;
0043   const int nby;
0044   const double xlo;
0045   const double xhi;
0046   const double ylo;
0047   const double yhi;
0048 
0049   const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> tokGeom_;
0050 
0051   //      TH1F* h1as;
0052   //      TH1F* h1bs;
0053 
0054   TH2F* h1ai;
0055   TH2F* h1ao;
0056   TH2F* h1bi;
0057   TH2F* h1bo;
0058   TH2F* hall;
0059 
0060   TRandom3* tro;
0061 };
0062 
0063 CSCLayerGeometryInside::CSCLayerGeometryInside(const edm::ParameterSet& ps)
0064     : dashedLineWidth_(194),
0065       dashedLine_(std::string(dashedLineWidth_, '-')),
0066       myName_("CSCLayerGeometryInside"),
0067       ntries(ps.getUntrackedParameter<int>("ntries")),
0068       nbx(ps.getUntrackedParameter<int>("nbx")),
0069       nby(ps.getUntrackedParameter<int>("nby")),
0070       xlo(ps.getUntrackedParameter<double>("xlo")),
0071       xhi(ps.getUntrackedParameter<double>("xhi")),
0072       ylo(ps.getUntrackedParameter<double>("ylo")),
0073       yhi(ps.getUntrackedParameter<double>("yhi")),
0074       tokGeom_(esConsumes()) {
0075   usesResource("TFileService");
0076 
0077   std::cout << myName_ << " constructor:" << std::endl;
0078   std::cout << "x range is " << nbx << " bins from " << xlo << " to " << xhi << std::endl;
0079   std::cout << "y range is " << nby << " bins from " << ylo << " to " << yhi << std::endl;
0080 
0081   edm::Service<TFileService> fs;
0082 
0083   tro = new TRandom3();
0084 
0085   //  h1as = fs->make<TH1F>( "h1as", "ME1a strip", 800, 0., 80. );
0086   //  h1bs = fs->make<TH1F>( "h1bs", "ME1b strip", 800, 0., 80. );
0087 
0088   hall = fs->make<TH2F>("hall", "All      y vs x", nbx, xlo, xhi, nby, ylo, yhi);
0089   h1ai = fs->make<TH2F>("h1ai", "ME1a  in y vs x", nbx, xlo, xhi, nby, ylo, yhi);
0090   h1bi = fs->make<TH2F>("h1bi", "ME1b  in y vs x", nbx, xlo, xhi, nby, ylo, yhi);
0091   h1ao = fs->make<TH2F>("h1ao", "ME1a out y vs x", nbx, xlo, xhi, nby, ylo, yhi);
0092   h1bo = fs->make<TH2F>("h1bo", "ME1b out y vs x", nbx, xlo, xhi, nby, ylo, yhi);
0093 }
0094 
0095 CSCLayerGeometryInside::~CSCLayerGeometryInside() { delete tro; }
0096 
0097 void CSCLayerGeometryInside::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0098   std::cout << myName() << ": Analyzer..." << std::endl;
0099   std::cout << "start " << dashedLine_ << std::endl;
0100 
0101   // Build the geometry
0102   const edm::ESHandle<CSCGeometry>& pgeom = iSetup.getHandle(tokGeom_);
0103 
0104   std::cout << "CSCGeometry contains " << pgeom->chambers().size() << " chambers" << std::endl;
0105   std::cout << "CSCGeometry contains " << pgeom->layers().size() << " layers" << std::endl;
0106 
0107   std::cout << dashedLine_ << std::endl;
0108 
0109   // Construct an ME1a and a ME1b layer
0110   CSCDetId id1a(1, 1, 4, 1, 1);
0111   CSCDetId id1b(1, 1, 1, 1, 1);
0112   // Get a pointer to each layer
0113   const CSCLayer* p1a = pgeom->layer(id1a);
0114   const CSCLayer* p1b = pgeom->layer(id1b);
0115   // Get a pointer to each layer's layergeometry
0116   const CSCLayerGeometry* lg1a = p1a->geometry();
0117   const CSCLayerGeometry* lg1b = p1b->geometry();
0118 
0119   // Now generate a whole load of random LocalPoints and check whether they'e inside or outside the strip region
0120 
0121   //   float fstrips1a = lg1a->numberOfStrips();
0122   //   float fstrips1b = lg1b->numberOfStrips();
0123   //   float epsilon = 1.0e-06;
0124 
0125   for (int i = 1; i <= ntries; ++i) {
0126     float x = tro->Uniform(xlo, xhi);
0127     float y = tro->Uniform(ylo, yhi);
0128     LocalPoint lp(x, y);
0129 
0130     // Examine the float strip value returned by the StripTopology
0131     //     float strip1a = lg1a->topology()->strip( lp );
0132     //     float strip1b = lg1b->topology()->strip( lp );
0133 
0134     //     if ( strip1a > epsilon && strip1a < fstrips1a-epsilon ) h1as->Fill( strip1a );
0135     //     if ( strip1b > epsilon && strip1b < fstrips1b-epsilon ) h1bs->Fill( strip1b );
0136 
0137     // histogram each generated point
0138     hall->Fill(x, y);
0139 
0140     // histogram according to inside/outside 1a and 1b
0141     if (lg1a->inside(lp))
0142       h1ai->Fill(x, y);
0143     else
0144       h1ao->Fill(x, y);
0145 
0146     if (lg1b->inside(lp))
0147       h1bi->Fill(x, y);
0148     else
0149       h1bo->Fill(x, y);
0150   }
0151 
0152   std::cout << dashedLine_ << " end" << std::endl;
0153 }
0154 
0155 // This is a plug-in
0156 DEFINE_FWK_MODULE(CSCLayerGeometryInside);