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
void copyDigis(edm::Event &event, edm::EDGetTokenT< C > &digiToken, std::unique_ptr< C > &filteredDigis)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void ageDigis(edm::Event &event, edm::EDGetTokenT< C > &digiToken, CLHEP::HepRandomEngine &randGen, std::unique_ptr< C > &filteredDigis)
edm::EDGetTokenT< CSCWireDigiCollection > m_wireDigiToken
static int rawIdMaker(int iendcap, int istation, int iring, int ichamber, int ilayer)
Definition: CSCDetId.h:146
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
MuonDigiCollection< CSCDetId, CSCStripDigi > CSCStripDigiCollection
edm::EDGetTokenT< CSCStripDigiCollection > m_stripDigiToken
MuonDigiCollection< CSCDetId, CSCCLCTDigi > CSCCLCTDigiCollection
edm::EDGetTokenT< CSCCLCTDigiCollection > m_clctDigiToken
int layer() const
Definition: CSCDetId.h:56
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
edm::ESGetToken< CSCGeometry, MuonGeometryRecord > m_cscGeomToken
edm::ESGetToken< MuonSystemAging, MuonSystemAgingRcd > m_agingObjToken
std::map< CSCDetId, std::pair< unsigned int, float > > m_CSCEffs
std::map< unsigned int, std::pair< unsigned int, float > > m_CSCChambEffs
~CSCChamberMasker() override
int chamber() const
Definition: CSCDetId.h:62
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginRun(edm::Run const &, edm::EventSetup const &) override
void produce(edm::Event &, const edm::EventSetup &) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::EDGetTokenT< CSCALCTDigiCollection > m_alctDigiToken
MuonDigiCollection< CSCDetId, CSCWireDigi > CSCWireDigiCollection
CSCChamberMasker(const edm::ParameterSet &)
int station() const
Definition: CSCDetId.h:79
int endcap() const
Definition: CSCDetId.h:85
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
int ring() const
Definition: CSCDetId.h:68
const ChamberContainer & chambers() const
Return a vector of all chambers.
Definition: CSCGeometry.cc:96
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
static void fillDescriptions(edm::ConfigurationDescriptions &)
MuonDigiCollection< CSCDetId, CSCALCTDigi > CSCALCTDigiCollection
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45