CMS 3D CMS Logo

CSCChamberMasker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimMuon/CSCDigitizer
4 // Class: CSCChamberMasker
5 //
11 //
12 // Original Author: Nick J. Amin
13 // Created: Mon, 27 Feb 2017 15:12:51 GMT
14 //
15 //
16 
17 
18 // system include files
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <iostream>
23 #include <algorithm>
24 
25 // user include files
30 
34 
37 
39 
42 
45 
56 
59 
62 #include "CLHEP/Random/RandomEngine.h"
63 
64 
65 //
66 // class declaration
67 //
68 
70 {
71 
72 public:
73  explicit CSCChamberMasker(const edm::ParameterSet&);
74  ~CSCChamberMasker() override;
75 
77 
78 private:
79  void produce(edm::Event&, const edm::EventSetup&) override;
80 
81  void beginRun(edm::Run const&, edm::EventSetup const&) override;
82 
84 
85  template<typename T, typename C = MuonDigiCollection<CSCDetId, T> >
86  void ageDigis(edm::Event & event,
87  edm::EDGetTokenT<C> & digiToken,
88  CLHEP::HepRandomEngine & randGen,
89  std::unique_ptr<C> & filteredDigis);
90 
91  template<typename T, typename C = MuonDigiCollection<CSCDetId, T> >
92  void copyDigis(edm::Event & event,
93  edm::EDGetTokenT<C> & digiToken,
94  std::unique_ptr<C> & filteredDigis);
95 
96  // ----------member data ---------------------------
97 
102  std::map<CSCDetId, std::pair<unsigned int,float> > m_CSCEffs;
103 
104 };
105 
106 //
107 // constants, enums and typedefs
108 //
109 
110 
111 //
112 // static data member definitions
113 //
114 
115 //
116 // constructors and destructor
117 //
119  :
120  m_stripDigiToken(consumes<CSCStripDigiCollection>(iConfig.getParameter<edm::InputTag>("stripDigiTag")) )
121  ,m_wireDigiToken(consumes<CSCWireDigiCollection>(iConfig.getParameter<edm::InputTag>("wireDigiTag")) )
122  ,m_clctDigiToken(consumes<CSCCLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("clctDigiTag")) )
123  ,m_alctDigiToken(consumes<CSCALCTDigiCollection>(iConfig.getParameter<edm::InputTag>("alctDigiTag")) )
124 {
125 
126  produces<CSCStripDigiCollection>("MuonCSCStripDigi");
127  produces<CSCWireDigiCollection>("MuonCSCWireDigi");
128  produces<CSCCLCTDigiCollection>("MuonCSCCLCTDigi");
129  produces<CSCALCTDigiCollection>("MuonCSCALCTDigi");
130 
131 }
132 
133 
135 {
136 
137 }
138 
139 
140 //
141 // member functions
142 //
143 
144 // ------------ method called to produce the data ------------
145 void
147 {
148 
150  CLHEP::HepRandomEngine& randGen = randGenService->getEngine(event.streamID());
151 
152  std::unique_ptr<CSCStripDigiCollection> filteredStripDigis(new CSCStripDigiCollection());
153  std::unique_ptr<CSCWireDigiCollection> filteredWireDigis(new CSCWireDigiCollection());
154  std::unique_ptr<CSCCLCTDigiCollection> filteredCLCTDigis(new CSCCLCTDigiCollection());
155  std::unique_ptr<CSCALCTDigiCollection> filteredALCTDigis(new CSCALCTDigiCollection());
156 
157  // Handle wire and strip digis
158  ageDigis<CSCStripDigi>(event,m_stripDigiToken,randGen,filteredStripDigis);
159  ageDigis<CSCWireDigi>(event,m_wireDigiToken,randGen,filteredWireDigis);
160 
161  // Don't touch CLCT or ALCT digis
162  copyDigis<CSCCLCTDigi>(event,m_clctDigiToken,filteredCLCTDigis);
163  copyDigis<CSCALCTDigi>(event,m_alctDigiToken,filteredALCTDigis);
164 
165  event.put(std::move(filteredStripDigis), "MuonCSCStripDigi");
166  event.put(std::move(filteredWireDigis), "MuonCSCWireDigi");
167  event.put(std::move(filteredCLCTDigis), "MuonCSCCLCTDigi");
168  event.put(std::move(filteredALCTDigis), "MuonCSCALCTDigi");
169 
170 }
171 
172 // ------------ method called to copy digis into aged collection ------------
173 template<typename T, typename C>
174 void
176  edm::EDGetTokenT<C> & digiToken,
177  std::unique_ptr<C> & filteredDigis)
178 {
179 
180  if (!digiToken.isUninitialized())
181  {
182  edm::Handle<C> digis;
183  event.getByToken(digiToken, digis);
184  for ( const auto & j : (*digis) )
185  {
186  auto digiItr = j.second.first;
187  auto last = j.second.second;
188 
189  CSCDetId const cscDetId = j.first;
190 
191  for( ; digiItr != last; ++digiItr)
192  {
193  filteredDigis->insertDigi(cscDetId,*digiItr);
194  }
195  }
196  }
197 
198 }
199 
200 // ------------ method aging digis------------
201 template<typename T, typename C>
202 void
204  edm::EDGetTokenT<C> & digiToken,
205  CLHEP::HepRandomEngine & randGen,
206  std::unique_ptr<C> & filteredDigis)
207 {
208 
209  if(!digiToken.isUninitialized())
210  {
211  edm::Handle<C> digis;
212  event.getByToken(digiToken, digis);
213 
214  for ( const auto & j : (*digis) )
215  {
216  auto digiItr = j.second.first;
217  auto last = j.second.second;
218 
219  CSCDetId const cscDetId = j.first;
220 
221  // Since lookups are chamber-centric, make new DetId with layer=0
222  CSCDetId chId = CSCDetId(cscDetId.endcap(), cscDetId.station(), cscDetId.ring(), cscDetId.chamber(), 0);
223 
224  for( ; digiItr != last; ++digiItr) {
225 
226  auto chEffIt = m_CSCEffs.find(chId);
227 
228  if (chEffIt != m_CSCEffs.end())
229  {
230 
231  std::pair<unsigned int, float> typeEff = chEffIt->second;
232  int type = typeEff.first % 10; // second digit gives type of inefficiency
233  int layer = typeEff.first/10; // first digit gives layer (0 = chamber level)
234 
235  bool doRandomize = false;
236  if (((std::is_same<T,CSCStripDigi>::value && type == EFF_WIRES) ||
238  type == EFF_CHAMBER) && (layer == 0 || cscDetId.layer() == layer)) doRandomize = true;
239 
240  if (!doRandomize || (randGen.flat() <= typeEff.second)) {
241  filteredDigis->insertDigi(cscDetId,*digiItr);
242  }
243  }
244 
245  }
246  }
247  }
248 }
249 
250 
251 // ------------ method called when starting to processes a run ------------
252 void
254 {
255 
256  m_CSCEffs.clear();
257 
259  iSetup.get<MuonGeometryRecord>().get(cscGeom);
260 
262  iSetup.get<MuonSystemAgingRcd>().get(agingObj);
263 
264  const auto chambers = cscGeom->chambers();
265 
266  for ( const auto * ch : chambers)
267  {
268 
269  CSCDetId chId = ch->id();
270  unsigned int rawId = chId.rawIdMaker(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), 0);
271  float eff = 1.;
272  int type = 0;
273  for ( auto & agingPair : agingObj->m_CSCChambEffs)
274  {
275  if ( agingPair.first != rawId) continue;
276 
277  type = agingPair.second.first;
278  eff = agingPair.second.second;
279  m_CSCEffs[chId] = std::make_pair(type, eff);
280  break;
281  }
282 
283  }
284 
285 }
286 
287 
288 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
289 void
291 {
292 
294  desc.add<edm::InputTag>("stripDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCStripDigi"));
295  desc.add<edm::InputTag>("wireDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCWireDigi"));
296  desc.add<edm::InputTag>("comparatorDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCComparatorDigi"));
297  desc.add<edm::InputTag>("rpcDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCRPCDigi"));
298  desc.add<edm::InputTag>("alctDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCALCTDigi"));
299  desc.add<edm::InputTag>("clctDigiTag", edm::InputTag("simMuonCSCDigis:MuonCSCCLCTDigi"));
300  descriptions.add("cscChamberMasker",desc);
301 
302 }
303 
304 //define this as a plug-in
int chamber() const
Definition: CSCDetId.h:68
type
Definition: HCALResponse.h:21
void copyDigis(edm::Event &event, edm::EDGetTokenT< C > &digiToken, std::unique_ptr< C > &filteredDigis)
void ageDigis(edm::Event &event, edm::EDGetTokenT< C > &digiToken, CLHEP::HepRandomEngine &randGen, std::unique_ptr< C > &filteredDigis)
edm::EDGetTokenT< CSCWireDigiCollection > m_wireDigiToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static int rawIdMaker(int iendcap, int istation, int iring, int ichamber, int ilayer)
Definition: CSCDetId.h:144
MuonDigiCollection< CSCDetId, CSCStripDigi > CSCStripDigiCollection
edm::EDGetTokenT< CSCStripDigiCollection > m_stripDigiToken
MuonDigiCollection< CSCDetId, CSCCLCTDigi > CSCCLCTDigiCollection
const ChamberContainer & chambers() const
Return a vector of all chambers.
Definition: CSCGeometry.cc:106
edm::EDGetTokenT< CSCCLCTDigiCollection > m_clctDigiToken
int layer() const
Definition: CSCDetId.h:61
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void createMaskedChamberCollection(edm::ESHandle< CSCGeometry > &)
int endcap() const
Definition: CSCDetId.h:93
std::map< unsigned int, std::pair< unsigned int, float > > m_CSCChambEffs
~CSCChamberMasker() override
void beginRun(edm::Run const &, edm::EventSetup const &) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< CSCALCTDigiCollection > m_alctDigiToken
MuonDigiCollection< CSCDetId, CSCWireDigi > CSCWireDigiCollection
int ring() const
Definition: CSCDetId.h:75
CSCChamberMasker(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:59
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
StreamID streamID() const
Definition: Event.h:95
bool isUninitialized() const
Definition: EDGetToken.h:73
int station() const
Definition: CSCDetId.h:86
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
static void fillDescriptions(edm::ConfigurationDescriptions &)
std::map< CSCDetId, std::pair< unsigned int, float > > m_CSCEffs
MuonDigiCollection< CSCDetId, CSCALCTDigi > CSCALCTDigiCollection
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
Definition: Run.h:43