CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SimMuon/GEMDigitizer/src/GEMCSCPadDigiProducer.cc

Go to the documentation of this file.
00001 #include "SimMuon/GEMDigitizer/src/GEMCSCPadDigiProducer.h"
00002 
00003 #include "FWCore/Framework/interface/EDProducer.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00008 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include <string>
00012 #include <map>
00013 #include <vector>
00014 
00015 
00016 GEMCSCPadDigiProducer::GEMCSCPadDigiProducer(const edm::ParameterSet& ps)
00017 : geometry_(nullptr)
00018 {
00019   produces<GEMCSCPadDigiCollection>();
00020   produces<GEMCSCPadDigiCollection>("Coincidence");
00021 
00022   input_ = ps.getParameter<edm::InputTag>("InputCollection");
00023   maxDeltaBX_ = ps.getParameter<int>("maxDeltaBX");
00024 }
00025 
00026 
00027 GEMCSCPadDigiProducer::~GEMCSCPadDigiProducer()
00028 {}
00029 
00030 
00031 void GEMCSCPadDigiProducer::beginRun( edm::Run& r, const edm::EventSetup& eventSetup)
00032 {
00033   edm::ESHandle<GEMGeometry> hGeom;
00034   eventSetup.get<MuonGeometryRecord>().get( hGeom );
00035   geometry_ = &*hGeom;
00036 }
00037 
00038 
00039 void GEMCSCPadDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup)
00040 {
00041   edm::Handle<GEMDigiCollection> hdigis;
00042   e.getByLabel(input_, hdigis);
00043 
00044   // Create empty output
00045   std::auto_ptr<GEMCSCPadDigiCollection> pPads(new GEMCSCPadDigiCollection());
00046   std::auto_ptr<GEMCSCPadDigiCollection> pCoPads(new GEMCSCPadDigiCollection());
00047 
00048   // build the pads
00049   buildPads(*(hdigis.product()), *pPads, *pCoPads);
00050 
00051   // store them in the event
00052   e.put(pPads);
00053   e.put(pCoPads, "Coincidence");
00054 }
00055 
00056 
00057 void GEMCSCPadDigiProducer::buildPads(const GEMDigiCollection &det_digis,
00058     GEMCSCPadDigiCollection &out_pads, GEMCSCPadDigiCollection &out_co_pads)
00059 {
00060   auto etaPartitions = geometry_->etaPartitions();
00061   for(auto p: etaPartitions)
00062   {
00063     // set of <pad, bx> pairs, sorted first by pad then by bx
00064     std::set<std::pair<int, int> > proto_pads;
00065   
00066     // walk over digis in this partition, 
00067     // and stuff them into a set of unique pads (equivalent of OR operation)
00068     auto digis = det_digis.get(p->id());
00069     for (auto d = digis.first; d != digis.second; ++d)
00070     {
00071       int pad_num = 1 + static_cast<int>( p->padOfStrip(d->strip()) );
00072       auto pad = std::make_pair(pad_num, d->bx());
00073       proto_pads.insert(pad);
00074     }
00075   
00076     // in the future, do some dead-time handling
00077     // emulateDeadTime(proto_pads)
00078   
00079     // fill the output collections
00080     for (auto & d: proto_pads)
00081     {
00082       GEMCSCPadDigi pad_digi(d.first, d.second);
00083       out_pads.insertDigi(p->id(), pad_digi);
00084     }
00085   }
00086 
00087   // build coincidences
00088   for (auto det_range = out_pads.begin(); det_range != out_pads.end(); ++det_range)
00089   {
00090     const GEMDetId& id = (*det_range).first;
00091 
00092     // all coincidences detIDs will have layer=1
00093     if (id.layer() != 1) continue;
00094 
00095     // find the corresponding id with layer=2
00096     GEMDetId co_id(id.region(), id.ring(), id.station(), 2, id.chamber(), id.roll());
00097 
00098     auto co_pads_range = out_pads.get(co_id);
00099     // empty range = no possible coincidence pads
00100     if (co_pads_range.first == co_pads_range.second) continue;
00101 
00102     // now let's correlate the pads in two layers of this partition
00103     const auto& pads_range = (*det_range).second;
00104     for (auto p = pads_range.first; p != pads_range.second; ++p)
00105     {
00106       for (auto co_p = co_pads_range.first; co_p != co_pads_range.second; ++co_p)
00107       {
00108         // check the match!
00109         if (p->pad() != co_p->pad() || std::abs(p->bx() - co_p->bx()) > maxDeltaBX_ ) continue;
00110 
00111         // always use layer1 pad's BX as a copad's BX
00112         GEMCSCPadDigi co_pad_digi(p->pad(), p->bx());
00113         out_co_pads.insertDigi(id, co_pad_digi);
00114       }
00115     }
00116   }
00117 }