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 
37 
39 
42 
45 
56 
59 
60 #include "CLHEP/Random/RandomEngine.h"
63 
64 //
65 // class declaration
66 //
67 
69 public:
70  explicit CSCChamberMasker(const edm::ParameterSet &);
71  ~CSCChamberMasker() override;
72 
74 
75 private:
76  void produce(edm::Event &, const edm::EventSetup &) override;
77 
78  void beginRun(edm::Run const &, edm::EventSetup const &) override;
79 
81 
82  template <typename T, typename C = MuonDigiCollection<CSCDetId, T>>
84  edm::EDGetTokenT<C> &digiToken,
85  CLHEP::HepRandomEngine &randGen,
86  std::unique_ptr<C> &filteredDigis);
87 
88  template <typename T, typename C = MuonDigiCollection<CSCDetId, T>>
89  void copyDigis(edm::Event &event, edm::EDGetTokenT<C> &digiToken, std::unique_ptr<C> &filteredDigis);
90 
91  // ----------member data ---------------------------
92 
97  std::map<CSCDetId, std::pair<unsigned int, float>> m_CSCEffs;
98 };
99 
100 //
101 // constants, enums and typedefs
102 //
103 
104 //
105 // static data member definitions
106 //
107 
108 //
109 // constructors and destructor
110 //
112  : m_stripDigiToken(consumes<CSCStripDigiCollection>(iConfig.getParameter<edm::InputTag>("stripDigiTag"))),
113  m_wireDigiToken(consumes<CSCWireDigiCollection>(iConfig.getParameter<edm::InputTag>("wireDigiTag"))),
114  m_clctDigiToken(consumes<CSCCLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("clctDigiTag"))),
115  m_alctDigiToken(consumes<CSCALCTDigiCollection>(iConfig.getParameter<edm::InputTag>("alctDigiTag"))) {
116  produces<CSCStripDigiCollection>("MuonCSCStripDigi");
117  produces<CSCWireDigiCollection>("MuonCSCWireDigi");
118  produces<CSCCLCTDigiCollection>("MuonCSCCLCTDigi");
119  produces<CSCALCTDigiCollection>("MuonCSCALCTDigi");
120 }
121 
123 
124 //
125 // member functions
126 //
127 
128 // ------------ method called to produce the data ------------
131  CLHEP::HepRandomEngine &randGen = randGenService->getEngine(event.streamID());
132 
133  std::unique_ptr<CSCStripDigiCollection> filteredStripDigis(new CSCStripDigiCollection());
134  std::unique_ptr<CSCWireDigiCollection> filteredWireDigis(new CSCWireDigiCollection());
135  std::unique_ptr<CSCCLCTDigiCollection> filteredCLCTDigis(new CSCCLCTDigiCollection());
136  std::unique_ptr<CSCALCTDigiCollection> filteredALCTDigis(new CSCALCTDigiCollection());
137 
138  // Handle wire and strip digis
139  ageDigis<CSCStripDigi>(event, m_stripDigiToken, randGen, filteredStripDigis);
140  ageDigis<CSCWireDigi>(event, m_wireDigiToken, randGen, filteredWireDigis);
141 
142  // Don't touch CLCT or ALCT digis
143  copyDigis<CSCCLCTDigi>(event, m_clctDigiToken, filteredCLCTDigis);
144  copyDigis<CSCALCTDigi>(event, m_alctDigiToken, filteredALCTDigis);
145 
146  event.put(std::move(filteredStripDigis), "MuonCSCStripDigi");
147  event.put(std::move(filteredWireDigis), "MuonCSCWireDigi");
148  event.put(std::move(filteredCLCTDigis), "MuonCSCCLCTDigi");
149  event.put(std::move(filteredALCTDigis), "MuonCSCALCTDigi");
150 }
151 
152 // ------------ method called to copy digis into aged collection ------------
153 template <typename T, typename C>
154 void CSCChamberMasker::copyDigis(edm::Event &event, edm::EDGetTokenT<C> &digiToken, std::unique_ptr<C> &filteredDigis) {
155  if (!digiToken.isUninitialized()) {
156  edm::Handle<C> digis;
157  event.getByToken(digiToken, digis);
158  for (const auto &j : (*digis)) {
159  auto digiItr = j.second.first;
160  auto last = j.second.second;
161 
162  CSCDetId const cscDetId = j.first;
163 
164  for (; digiItr != last; ++digiItr) {
165  filteredDigis->insertDigi(cscDetId, *digiItr);
166  }
167  }
168  }
169 }
170 
171 // ------------ method aging digis------------
172 template <typename T, typename C>
174  edm::EDGetTokenT<C> &digiToken,
175  CLHEP::HepRandomEngine &randGen,
176  std::unique_ptr<C> &filteredDigis) {
177  if (!digiToken.isUninitialized()) {
178  edm::Handle<C> digis;
179  event.getByToken(digiToken, digis);
180 
181  for (const auto &j : (*digis)) {
182  auto digiItr = j.second.first;
183  auto last = j.second.second;
184 
185  CSCDetId const cscDetId = j.first;
186 
187  // Since lookups are chamber-centric, make new DetId with layer=0
188  CSCDetId chId = CSCDetId(cscDetId.endcap(), cscDetId.station(), cscDetId.ring(), cscDetId.chamber(), 0);
189 
190  for (; digiItr != last; ++digiItr) {
191  auto chEffIt = m_CSCEffs.find(chId);
192 
193  if (chEffIt != m_CSCEffs.end()) {
194  std::pair<unsigned int, float> typeEff = chEffIt->second;
195  int type = typeEff.first % 10; // second digit gives type of inefficiency
196  int layer = typeEff.first / 10; // first digit gives layer (0 = chamber level)
197 
198  bool doRandomize = false;
201  (layer == 0 || cscDetId.layer() == layer))
202  doRandomize = true;
203 
204  if (!doRandomize || (randGen.flat() <= typeEff.second)) {
205  filteredDigis->insertDigi(cscDetId, *digiItr);
206  }
207  }
208  }
209  }
210  }
211 }
212 
213 // ------------ method called when starting to processes a run ------------
215  m_CSCEffs.clear();
216 
218  iSetup.get<MuonGeometryRecord>().get(cscGeom);
219 
221  iSetup.get<MuonSystemAgingRcd>().get(agingObj);
222 
223  const auto chambers = cscGeom->chambers();
224 
225  for (const auto *ch : chambers) {
226  CSCDetId chId = ch->id();
227  unsigned int rawId = chId.rawIdMaker(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), 0);
228  float eff = 1.;
229  int type = 0;
230  for (auto &agingPair : agingObj->m_CSCChambEffs) {
231  if (agingPair.first != rawId)
232  continue;
233 
234  type = agingPair.second.first;
235  eff = agingPair.second.second;
236  m_CSCEffs[chId] = std::make_pair(type, eff);
237  break;
238  }
239  }
240 }
241 
242 // ------------ method fills 'descriptions' with the allowed parameters for the
243 // module ------------
246  desc.add<edm::InputTag>("stripDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCStripDigi"));
247  desc.add<edm::InputTag>("wireDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCWireDigi"));
248  desc.add<edm::InputTag>("comparatorDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCComparatorDigi"));
249  desc.add<edm::InputTag>("rpcDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCRPCDigi"));
250  desc.add<edm::InputTag>("alctDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCALCTDigi"));
251  desc.add<edm::InputTag>("clctDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCCLCTDigi"));
252  descriptions.add("cscChamberMasker", desc);
253 }
254 
255 // 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
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
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:97
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
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
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:94
CSCChamberMasker::~CSCChamberMasker
~CSCChamberMasker() override
Definition: CSCChamberMasker.cc:122
edm::Handle
Definition: AssociativeIterator.h:50
CSCDetId.h
CSCStripDigiCollection
MuonDigiCollection< CSCDetId, CSCStripDigi > CSCStripDigiCollection
Definition: CSCStripDigiCollection.h:14
MakerMacros.h
dqmdumpme.last
last
Definition: dqmdumpme.py:56
CSCALCTDigi.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
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:111
Service.h
edm::EDGetTokenT::isUninitialized
bool isUninitialized() const
Definition: EDGetToken.h:70
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
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
CSCIndexer.h
CSCChamberMasker::m_alctDigiToken
edm::EDGetTokenT< CSCALCTDigiCollection > m_alctDigiToken
Definition: CSCChamberMasker.cc:96
CSCChamberMasker::createMaskedChamberCollection
void createMaskedChamberCollection(edm::ESHandle< CSCGeometry > &)
CSCDetId
Definition: CSCDetId.h:26
edm::Service< edm::RandomNumberGenerator >
CSCChamberMasker::m_clctDigiToken
edm::EDGetTokenT< CSCCLCTDigiCollection > m_clctDigiToken
Definition: CSCChamberMasker.cc:95
CSCALCTDigiCollection
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:244
edm::EventSetup
Definition: EventSetup.h:57
CSCChamberMasker::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: CSCChamberMasker.cc:214
EFF_CHAMBER
Definition: MuonSystemAging.h:11
get
#define get
CSCChamberMasker
Definition: CSCChamberMasker.cc:68
CSCWireDigiCollection
MuonDigiCollection< CSCDetId, CSCWireDigi > CSCWireDigiCollection
Definition: CSCWireDigiCollection.h:15
type
type
Definition: HCALResponse.h:21
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:154
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:173
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:129
CSCChamberMasker::m_stripDigiToken
edm::EDGetTokenT< CSCStripDigiCollection > m_stripDigiToken
Definition: CSCChamberMasker.cc:93
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