CMS 3D CMS Logo

CSCChamberMasker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimMuon/CSCDigitizer
4 // Class: CSCChamberMasker
5 //
12 //
13 // Original Author: Nick J. Amin
14 // Created: Mon, 27 Feb 2017 15:12:51 GMT
15 //
16 //
17 
18 // system include files
19 #include <algorithm>
20 #include <iostream>
21 #include <map>
22 #include <memory>
23 #include <string>
24 
25 // user include files
30 
34 
38 
40 
43 
46 
57 
60 
61 #include "CLHEP/Random/RandomEngine.h"
64 
65 //
66 // class declaration
67 //
68 
70 public:
71  explicit CSCChamberMasker(const edm::ParameterSet &);
72  ~CSCChamberMasker() override;
73 
75 
76 private:
77  void produce(edm::Event &, const edm::EventSetup &) override;
78 
79  void beginRun(edm::Run const &, edm::EventSetup const &) override;
80 
81  template <typename T, typename C = MuonDigiCollection<CSCDetId, T>>
83  edm::EDGetTokenT<C> &digiToken,
84  CLHEP::HepRandomEngine &randGen,
85  std::unique_ptr<C> &filteredDigis);
86 
87  template <typename T, typename C = MuonDigiCollection<CSCDetId, T>>
88  void copyDigis(edm::Event &event, edm::EDGetTokenT<C> &digiToken, std::unique_ptr<C> &filteredDigis);
89 
90  // ----------member data ---------------------------
91 
98  std::map<CSCDetId, std::pair<unsigned int, float>> m_CSCEffs;
99 };
100 
101 //
102 // constants, enums and typedefs
103 //
104 
105 //
106 // static data member definitions
107 //
108 
109 //
110 // constructors and destructor
111 //
113  : m_stripDigiToken(consumes<CSCStripDigiCollection>(iConfig.getParameter<edm::InputTag>("stripDigiTag"))),
114  m_wireDigiToken(consumes<CSCWireDigiCollection>(iConfig.getParameter<edm::InputTag>("wireDigiTag"))),
115  m_clctDigiToken(consumes<CSCCLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("clctDigiTag"))),
116  m_alctDigiToken(consumes<CSCALCTDigiCollection>(iConfig.getParameter<edm::InputTag>("alctDigiTag"))),
117  m_cscGeomToken(esConsumes<CSCGeometry, MuonGeometryRecord>()),
118  m_agingObjToken(esConsumes<MuonSystemAging, MuonSystemAgingRcd>()) {
119  produces<CSCStripDigiCollection>("MuonCSCStripDigi");
120  produces<CSCWireDigiCollection>("MuonCSCWireDigi");
121  produces<CSCCLCTDigiCollection>("MuonCSCCLCTDigi");
122  produces<CSCALCTDigiCollection>("MuonCSCALCTDigi");
123 }
124 
126 
127 //
128 // member functions
129 //
130 
131 // ------------ method called to produce the data ------------
134  CLHEP::HepRandomEngine &randGen = randGenService->getEngine(event.streamID());
135 
136  std::unique_ptr<CSCStripDigiCollection> filteredStripDigis(new CSCStripDigiCollection());
137  std::unique_ptr<CSCWireDigiCollection> filteredWireDigis(new CSCWireDigiCollection());
138  std::unique_ptr<CSCCLCTDigiCollection> filteredCLCTDigis(new CSCCLCTDigiCollection());
139  std::unique_ptr<CSCALCTDigiCollection> filteredALCTDigis(new CSCALCTDigiCollection());
140 
141  // Handle wire and strip digis
142  ageDigis<CSCStripDigi>(event, m_stripDigiToken, randGen, filteredStripDigis);
143  ageDigis<CSCWireDigi>(event, m_wireDigiToken, randGen, filteredWireDigis);
144 
145  // Don't touch CLCT or ALCT digis
146  copyDigis<CSCCLCTDigi>(event, m_clctDigiToken, filteredCLCTDigis);
147  copyDigis<CSCALCTDigi>(event, m_alctDigiToken, filteredALCTDigis);
148 
149  event.put(std::move(filteredStripDigis), "MuonCSCStripDigi");
150  event.put(std::move(filteredWireDigis), "MuonCSCWireDigi");
151  event.put(std::move(filteredCLCTDigis), "MuonCSCCLCTDigi");
152  event.put(std::move(filteredALCTDigis), "MuonCSCALCTDigi");
153 }
154 
155 // ------------ method called to copy digis into aged collection ------------
156 template <typename T, typename C>
157 void CSCChamberMasker::copyDigis(edm::Event &event, edm::EDGetTokenT<C> &digiToken, std::unique_ptr<C> &filteredDigis) {
158  if (!digiToken.isUninitialized()) {
159  edm::Handle<C> digis;
160  event.getByToken(digiToken, digis);
161  for (const auto &j : (*digis)) {
162  auto digiItr = j.second.first;
163  auto last = j.second.second;
164 
165  CSCDetId const cscDetId = j.first;
166 
167  for (; digiItr != last; ++digiItr) {
168  filteredDigis->insertDigi(cscDetId, *digiItr);
169  }
170  }
171  }
172 }
173 
174 // ------------ method aging digis------------
175 template <typename T, typename C>
177  edm::EDGetTokenT<C> &digiToken,
178  CLHEP::HepRandomEngine &randGen,
179  std::unique_ptr<C> &filteredDigis) {
180  if (!digiToken.isUninitialized()) {
181  edm::Handle<C> digis;
182  event.getByToken(digiToken, digis);
183 
184  for (const auto &j : (*digis)) {
185  auto digiItr = j.second.first;
186  auto last = j.second.second;
187 
188  CSCDetId const cscDetId = j.first;
189 
190  // Since lookups are chamber-centric, make new DetId with layer=0
191  CSCDetId chId = CSCDetId(cscDetId.endcap(), cscDetId.station(), cscDetId.ring(), cscDetId.chamber(), 0);
192 
193  for (; digiItr != last; ++digiItr) {
194  auto chEffIt = m_CSCEffs.find(chId);
195 
196  if (chEffIt != m_CSCEffs.end()) {
197  std::pair<unsigned int, float> typeEff = chEffIt->second;
198  int type = typeEff.first % 10; // second digit gives type of inefficiency
199  int layer = typeEff.first / 10; // first digit gives layer (0 = chamber level)
200 
201  bool doRandomize = false;
204  (layer == 0 || cscDetId.layer() == layer))
205  doRandomize = true;
206 
207  if (!doRandomize || (randGen.flat() <= typeEff.second)) {
208  filteredDigis->insertDigi(cscDetId, *digiItr);
209  }
210  }
211  }
212  }
213  }
214 }
215 
216 // ------------ method called when starting to processes a run ------------
218  m_CSCEffs.clear();
219 
221 
223 
224  const auto chambers = cscGeom->chambers();
225 
226  for (const auto *ch : chambers) {
227  CSCDetId chId = ch->id();
228  unsigned int rawId = chId.rawIdMaker(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), 0);
229  float eff = 1.;
230  int type = 0;
231  for (auto &agingPair : agingObj->m_CSCChambEffs) {
232  if (agingPair.first != rawId)
233  continue;
234 
235  type = agingPair.second.first;
236  eff = agingPair.second.second;
237  m_CSCEffs[chId] = std::make_pair(type, eff);
238  break;
239  }
240  }
241 }
242 
243 // ------------ method fills 'descriptions' with the allowed parameters for the
244 // module ------------
247  desc.add<edm::InputTag>("stripDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCStripDigi"));
248  desc.add<edm::InputTag>("wireDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCWireDigi"));
249  desc.add<edm::InputTag>("comparatorDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCComparatorDigi"));
250  desc.add<edm::InputTag>("rpcDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCRPCDigi"));
251  desc.add<edm::InputTag>("alctDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCALCTDigi"));
252  desc.add<edm::InputTag>("clctDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCCLCTDigi"));
253  descriptions.add("cscChamberMasker", desc);
254 }
255 
256 // define this as a plug-in
EFF_STRIPS
Definition: MuonSystemAging.h:11
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
Handle.h
ESHandle.h
MuonSystemAging.h
MuonSystemAgingRcd
Definition: MuonSystemAgingRcd.h:20
CSCChamberMasker::m_CSCEffs
std::map< CSCDetId, std::pair< unsigned int, float > > m_CSCEffs
Definition: CSCChamberMasker.cc:98
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< C >
CSCStripDigi.h
EFF_WIRES
Definition: MuonSystemAging.h:11
CSCWireDigi.h
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
CSCDetId::ring
int ring() const
Definition: CSCDetId.h:68
CSCStripDigiCollection
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
EDProducer.h
CSCDetId::rawIdMaker
static int rawIdMaker(int iendcap, int istation, int iring, int ichamber, int ilayer)
Definition: CSCDetId.h:131
CSCChamberMasker::m_wireDigiToken
edm::EDGetTokenT< CSCWireDigiCollection > m_wireDigiToken
Definition: CSCChamberMasker.cc:93
CSCChamberMasker::~CSCChamberMasker
~CSCChamberMasker() override
Definition: CSCChamberMasker.cc:125
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
CSCDetId.h
CSCGeometry
Definition: CSCGeometry.h:24
CSCStripDigiCollection
MuonDigiCollection< CSCDetId, CSCStripDigi > CSCStripDigiCollection
Definition: CSCStripDigiCollection.h:14
MakerMacros.h
dqmdumpme.last
last
Definition: dqmdumpme.py:56
CSCALCTDigi.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CSCChamberMasker::CSCChamberMasker
CSCChamberMasker(const edm::ParameterSet &)
Definition: CSCChamberMasker.cc:112
Service.h
CSCDetId::layer
int layer() const
Definition: CSCDetId.h:56
Run.h
edm::ESHandle< CSCGeometry >
MuonSystemAging::m_CSCChambEffs
std::map< unsigned int, std::pair< unsigned int, float > > m_CSCChambEffs
Definition: MuonSystemAging.h:20
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
MuonSystemAgingRcd.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
CSCIndexer.h
CSCChamberMasker::m_alctDigiToken
edm::EDGetTokenT< CSCALCTDigiCollection > m_alctDigiToken
Definition: CSCChamberMasker.cc:95
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
CSCChamberMasker::m_agingObjToken
edm::ESGetToken< MuonSystemAging, MuonSystemAgingRcd > m_agingObjToken
Definition: CSCChamberMasker.cc:97
CSCDetId
Definition: CSCDetId.h:26
edm::Service< edm::RandomNumberGenerator >
CSCChamberMasker::m_clctDigiToken
edm::EDGetTokenT< CSCCLCTDigiCollection > m_clctDigiToken
Definition: CSCChamberMasker.cc:94
CSCALCTDigiCollection
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
CSCALCTDigiCollection
MuonDigiCollection< CSCDetId, CSCALCTDigi > CSCALCTDigiCollection
Definition: CSCALCTDigiCollection.h:15
edm::stream::EDProducer
Definition: EDProducer.h:38
chambers
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
CSCStripDigiCollection.h
CSCDetId::chamber
int chamber() const
Definition: CSCDetId.h:62
CSCChamberMasker::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: CSCChamberMasker.cc:245
edm::EventSetup
Definition: EventSetup.h:57
CSCChamberMasker::m_cscGeomToken
edm::ESGetToken< CSCGeometry, MuonGeometryRecord > m_cscGeomToken
Definition: CSCChamberMasker.cc:96
CSCChamberMasker::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: CSCChamberMasker.cc:217
EFF_CHAMBER
Definition: MuonSystemAging.h:11
edm::ESGetToken< CSCGeometry, MuonGeometryRecord >
MuonSystemAging
Definition: MuonSystemAging.h:13
CSCChamberMasker
Definition: CSCChamberMasker.cc:69
CSCWireDigiCollection
MuonDigiCollection< CSCDetId, CSCWireDigi > CSCWireDigiCollection
Definition: CSCWireDigiCollection.h:15
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
submitPVValidationJobs.conditions
list conditions
Definition: submitPVValidationJobs.py:674
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
CSCCLCTDigiCollection
MuonDigiCollection< CSCDetId, CSCCLCTDigi > CSCCLCTDigiCollection
Definition: CSCCLCTDigiCollection.h:15
CSCWireDigiCollection
CSCChamberMasker::copyDigis
void copyDigis(edm::Event &event, edm::EDGetTokenT< C > &digiToken, std::unique_ptr< C > &filteredDigis)
Definition: CSCChamberMasker.cc:157
CSCLayer.h
Frameworkfwd.h
CSCChamberMasker::ageDigis
void ageDigis(edm::Event &event, edm::EDGetTokenT< C > &digiToken, CLHEP::HepRandomEngine &randGen, std::unique_ptr< C > &filteredDigis)
Definition: CSCChamberMasker.cc:176
CSCDetId::endcap
int endcap() const
Definition: CSCDetId.h:85
CSCCLCTDigiCollection
relativeConstraints.value
value
Definition: relativeConstraints.py:53
CSCCLCTDigi.h
EventSetup.h
CSCGeometry::chambers
const ChamberContainer & chambers() const
Return a vector of all chambers.
Definition: CSCGeometry.cc:96
CSCChamberMasker::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CSCChamberMasker.cc:132
CSCChamberMasker::m_stripDigiToken
edm::EDGetTokenT< CSCStripDigiCollection > m_stripDigiToken
Definition: CSCChamberMasker.cc:92
CSCWireDigiCollection.h
CSCALCTDigiCollection.h
ConsumesCollector.h
ParameterSet.h
CSCDetId::station
int station() const
Definition: CSCDetId.h:79
CSCCLCTDigiCollection.h
MuonGeometryRecord.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
CSCChamber.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
edm::InputTag
Definition: InputTag.h:15
CSCGeometry.h