CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
MaskedRctInputDigiProducer Class Reference

#include <MaskedRctInputDigiProducer.h>

Inheritance diagram for MaskedRctInputDigiProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MaskedRctInputDigiProducer (const edm::ParameterSet &)
 
 ~MaskedRctInputDigiProducer () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void endJob () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

edm::InputTag ecalDigisLabel_
 
edm::InputTag hcalDigisLabel_
 
edm::FileInPath maskFile_
 
bool useEcal_
 
bool useHcal_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

L1Trigger/MaskedRctInputDigiProducer/src/MaskedRctInputDigiProducer.cc

Description: Takes collections of ECAL and HCAL digis, masks some towers according to a mask in a text file, and creates new collections for use by the RCT.

Implementation: <Notes on="" implementation>="">

Definition at line 45 of file MaskedRctInputDigiProducer.h.

Constructor & Destructor Documentation

MaskedRctInputDigiProducer::MaskedRctInputDigiProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 15 of file MaskedRctInputDigiProducer.cc.

17  : useEcal_(iConfig.getParameter<bool>("useEcal")),
18  useHcal_(iConfig.getParameter<bool>("useHcal")),
19  ecalDigisLabel_(iConfig.getParameter<edm::InputTag>("ecalDigisLabel")),
20  hcalDigisLabel_(iConfig.getParameter<edm::InputTag>("hcalDigisLabel")),
21  maskFile_(iConfig.getParameter<edm::FileInPath>("maskFile")) {
22  // register your products
23  /* Examples
24  produces<ExampleData2>();
25 
26  //if do put with a label
27  produces<ExampleData2>("label");
28  */
29 
30  produces<EcalTrigPrimDigiCollection>();
31  produces<HcalTrigPrimDigiCollection>();
32 
33  // now do what ever other initialization is needed
34 }
T getParameter(std::string const &) const
MaskedRctInputDigiProducer::~MaskedRctInputDigiProducer ( )
override

Definition at line 36 of file MaskedRctInputDigiProducer.cc.

36  {
37 
38  // do anything here that needs to be done at desctruction time
39  // (e.g. close files, deallocate resources etc.)
40 }

Member Function Documentation

void MaskedRctInputDigiProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 377 of file MaskedRctInputDigiProducer.cc.

References DEFINE_FWK_MODULE.

377 {}
void MaskedRctInputDigiProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 47 of file MaskedRctInputDigiProducer.cc.

References funct::abs(), MessageLogger_cfi::cerr, digitizers_cfi::ecal, ecalDigisLabel_, EcalTriggerTower, Exception, edm::FileInPath::fullPath(), edm::Event::getByLabel(), digitizers_cfi::hcal, hcalDigisLabel_, mps_fire::i, edm::HandleBase::isValid(), maskFile_, eostools::move(), hcalTTPDigis_cfi::presamples, edm::Event::put(), simplePhotonAnalyzer_cfi::sample, HcalTriggerPrimitiveDigi::setPresamples(), EcalTriggerPrimitiveDigi::setSample(), HcalTriggerPrimitiveDigi::setSample(), HcalTriggerPrimitiveDigi::setSize(), EcalTriggerPrimitiveDigi::setSize(), Validation_hcalonly_cfi::sign, edm::SortedCollection< T, SORT >::size(), AlCaHLTBitMon_QueryRunRegistry::string, useEcal_, and useHcal_.

48  {
49  using namespace edm;
50  /* This is an event example
51  //Read 'ExampleData' from the Event
52  Handle<ExampleData> pIn;
53  iEvent.getByLabel("example",pIn);
54 
55  //Use the ExampleData to create an ExampleData2 which
56  // is put into the Event
57  std::unique_ptr<ExampleData2> pOut(new ExampleData2(*pIn));
58  iEvent.put(std::move(pOut));
59  */
60 
63 
64  if (useEcal_) {
65  iEvent.getByLabel(ecalDigisLabel_, ecal);
66  }
67  if (useHcal_) {
68  iEvent.getByLabel(hcalDigisLabel_, hcal);
69  }
70 
73  if (ecal.isValid()) {
74  ecalColl = *ecal;
75  }
76  if (hcal.isValid()) {
77  hcalColl = *hcal;
78  }
79 
80  /* this is an EventSetup example
81  //Read SetupData from the SetupRecord in the EventSetup
82  ESHandle<SetupData> pSetup;
83  iSetup.get<SetupRecord>().get(pSetup);
84  */
85 
86  ifstream maskFileStream(maskFile_.fullPath().c_str());
87  if (!maskFileStream.is_open()) {
88  throw cms::Exception("FileInPathError")
89  << "RCT mask file not opened" << std::endl;
90  ;
91  }
92 
93  // read and process file (transform mask to new position in phi to match
94  // digis)
95  // char junk[256];
96  std::string junk;
97  // char junk[32];
98  do {
99  // maskFileStream.getline(junk, 256);
100  maskFileStream >> junk;
101  } while (junk != "ECAL:");
102 
103  // std::vector<std::vector<std::vector<unsigned short> > >
104  // temp(2,std::vector<std::vector<unsigned short> >(72,std::vector<unsigned
105  // short>(28,1)));
106  std::vector<std::vector<std::vector<unsigned short>>> ecalMask(
107  2, std::vector<std::vector<unsigned short>>(
108  72, std::vector<unsigned short>(28, 1)));
109  std::vector<std::vector<std::vector<unsigned short>>> hcalMask(
110  2, std::vector<std::vector<unsigned short>>(
111  72, std::vector<unsigned short>(28, 1)));
112  std::vector<std::vector<std::vector<unsigned short>>> hfMask(
113  2, std::vector<std::vector<unsigned short>>(
114  18, std::vector<unsigned short>(8, 1)));
115 
116  // read ECAL mask first
117  // loop through rct iphi
118  for (int i = 1; i <= 72; i++) {
119  int phi_index = (72 + 18 - i) % 72; // transfrom from RCT coords
120  if (phi_index == 0) {
121  phi_index = 72;
122  }
123  // std::cout << "ecal phi index is " << phi_index << std::endl;
124  for (int j = 28; j >= 1; j--) {
125  maskFileStream >> junk;
126  if (junk == "-") {
127  } else if ((junk == "X") || (junk == "x")) {
128  ecalMask.at(0).at(phi_index - 1).at(j - 1) = 0;
129  } else {
130  std::cerr << "RCT mask producer: error -- unrecognized character"
131  << std::endl;
132  }
133  }
134  for (int j = 1; j <= 28; j++) {
135  maskFileStream >> junk;
136  if (junk == "-") {
137  } else if ((junk == "X") || (junk == "x")) {
138  ecalMask.at(1).at(phi_index - 1).at(j - 1) = 0;
139  } else {
140  std::cerr << "RCT mask producer: error -- unrecognized character"
141  << std::endl;
142  }
143  }
144  }
145  // std::cout << "done reading ECAL" << std::endl;
146 
147  maskFileStream >> junk;
148  if (junk != "HCAL:") {
149  throw cms::Exception("FileInPathError")
150  << "RCT mask producer: error reading ECAL mask" << std::endl;
151  ;
152  }
153 
154  // std::cout << "Starting HCAL read" << std::endl;
155 
156  // now read HCAL mask
157  // loop through rct iphi
158  for (int i = 1; i <= 72; i++) {
159  int phi_index = (72 + 18 - i) % 72; // transfrom from RCT coords
160  if (phi_index == 0) {
161  phi_index = 72;
162  }
163  // std::cout << "hcal phi index is " << phi_index << std::endl;
164  for (int j = 28; j >= 1; j--) {
165  maskFileStream >> junk;
166  if (junk == "-") {
167  } else if ((junk == "X") || (junk == "x")) {
168  hcalMask.at(0).at(phi_index - 1).at(j - 1) = 0;
169  } else {
170  std::cerr << "RCT mask producer: error -- unrecognized character"
171  << std::endl;
172  }
173  }
174  for (int j = 1; j <= 28; j++) {
175  maskFileStream >> junk;
176  if (junk == "-") {
177  } else if ((junk == "X") || (junk == "x")) {
178  hcalMask.at(1).at(phi_index - 1).at(j - 1) = 0;
179  } else {
180  std::cerr << "RCT mask producer: error -- unrecognized character"
181  << std::endl;
182  }
183  }
184  }
185 
186  maskFileStream >> junk;
187  if (junk != "HF:") {
188  throw cms::Exception("FileInPathError")
189  << "RCT mask producer: error reading HCAL mask" << std::endl;
190  ;
191  }
192 
193  // loop through the hf phi columns in file
194  for (int i = 0; i < 18; i++) {
195  // std::cout << "iphi for hf file read is " << i << std::endl;
196  for (int j = 4; j >= 1; j--) {
197  if (maskFileStream >> junk) {
198  } else {
199  std::cerr << "RCT mask producer: error reading HF mask" << std::endl;
200  }
201  if (junk == "-") {
202  } else if ((junk == "X") || (junk == "x")) {
203  hfMask.at(0).at(i).at(j - 1) =
204  0; // just save iphi as 0-17, transform later
205  } else {
206  std::cerr << "RCT mask producer: error -- unrecognized character"
207  << std::endl;
208  }
209  }
210  for (int j = 1; j <= 4; j++) {
211  if (maskFileStream >> junk) {
212  } else {
213  std::cerr << "RCT mask producer: error reading HF mask" << std::endl;
214  }
215  if (junk == "-") {
216  } else if ((junk == "X") || (junk == "x")) {
217  hfMask.at(1).at(i).at(j - 1) = 0;
218  } else {
219  std::cerr << "RCT mask producer: error -- unrecognized character"
220  << std::endl;
221  }
222  }
223  }
224 
225  // std::cout << "HF read done" << std::endl;
226 
227  maskFileStream.close();
228 
229  // std::cout << "file closed" << std::endl;
230 
231  // apply mask
232 
233  std::unique_ptr<EcalTrigPrimDigiCollection> maskedEcalTPs(
235  std::unique_ptr<HcalTrigPrimDigiCollection> maskedHcalTPs(
237  maskedEcalTPs->reserve(56 * 72);
238  maskedHcalTPs->reserve(56 * 72 + 18 * 8);
239  int nEcalSamples = 0;
240  int nHcalSamples = 0;
241 
242  for (unsigned int i = 0; i < ecalColl.size(); i++) {
243  nEcalSamples = ecalColl[i].size();
244  short ieta = (short)ecalColl[i].id().ieta();
245  unsigned short absIeta = (unsigned short)abs(ieta);
246  int sign = ieta / absIeta;
247  short iphi = (unsigned short)ecalColl[i].id().iphi();
248  // if (i < 20) {std::cout << "ieta is " << ieta << ", absIeta is " <<
249  // absIeta
250  // << ", iphi is " << iphi << std::endl;}
251 
252  EcalTriggerPrimitiveDigi ecalDigi(
253  EcalTrigTowerDetId(sign, EcalTriggerTower, absIeta, iphi));
254  ecalDigi.setSize(nEcalSamples);
255 
256  for (int nSample = 0; nSample < nEcalSamples; nSample++) {
257 
258  int energy = 0;
259  bool fineGrain = false;
260 
261  if (sign < 0) {
262  // std::cout << "eta-: mask is " <<
263  // ecalMask.at(0).at(iphi-1).at(absIeta-1) << std::endl;
264  energy = ecalMask.at(0).at(iphi - 1).at(absIeta - 1) *
265  ecalColl[i].sample(nSample).compressedEt();
266  fineGrain = (ecalMask.at(0).at(iphi - 1).at(absIeta - 1) != 0) &&
267  ecalColl[i].sample(nSample).fineGrain();
268  } else if (sign > 0) {
269  // std::cout << "eta+: mask is " <<
270  // ecalMask.at(1).at(iphi-1).at(absIeta-1) << std::endl;
271  energy = ecalMask.at(1).at(iphi - 1).at(absIeta - 1) *
272  ecalColl[i].sample(nSample).compressedEt();
273  fineGrain = (ecalMask.at(1).at(iphi - 1).at(absIeta - 1) != 0) &&
274  ecalColl[i].sample(nSample).fineGrain();
275  }
276 
277  ecalDigi.setSample(nSample,
278  EcalTriggerPrimitiveSample(energy, fineGrain, 0));
279  }
280  maskedEcalTPs->push_back(ecalDigi);
281  }
282  // std::cout << "End of ecal digi masking" << std::endl;
283 
284  // std::cout << "nHcalDigis is " << hcalColl.size() << std::endl;
285  for (unsigned int i = 0; i < hcalColl.size(); i++) {
286  nHcalSamples = hcalColl[i].size();
287  // if ((i % 100) == 0 ) {std::cout << "Loop " << i << std::endl;}
288  short ieta = (short)hcalColl[i].id().ieta();
289  unsigned short absIeta = (unsigned short)abs(ieta);
290  int sign = ieta / absIeta;
291  short iphi = (unsigned short)hcalColl[i].id().iphi();
292  // if (i < 20) {std::cout << "ieta is " << ieta << ", absIeta is " <<
293  // absIeta
294  // << ", iphi is " << iphi << std::endl;}
295  /*
296  if (hcalColl[i].SOI_compressedEt() != 0)
297  {
298  std::cout << "original et " << hcalColl[i].SOI_compressedEt()
299  << " fg " << hcalColl[i].SOI_fineGrain() << " iphi "
300  << iphi << " ieta " << ieta << std::endl;
301  }
302  */
303  HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId(ieta, iphi));
304  hcalDigi.setSize(nHcalSamples);
305  hcalDigi.setPresamples(hcalColl[i].presamples());
306 
307  for (int nSample = 0; nSample < nHcalSamples; nSample++) {
308 
309  int energy = 0;
310  bool fineGrain = false;
311 
312  if (absIeta < 29) {
313  if (sign < 0) {
314  energy = hcalMask.at(0).at(iphi - 1).at(absIeta - 1) *
315  hcalColl[i].sample(nSample).compressedEt();
316  fineGrain = (hcalMask.at(0).at(iphi - 1).at(absIeta - 1) != 0) &&
317  hcalColl[i].sample(nSample).fineGrain();
318  } else if (sign > 0) {
319  energy = hcalMask.at(1).at(iphi - 1).at(absIeta - 1) *
320  hcalColl[i].sample(nSample).compressedEt();
321  fineGrain = (hcalMask.at(1).at(iphi - 1).at(absIeta - 1) != 0) &&
322  hcalColl[i].sample(nSample).fineGrain();
323  }
324  } else if ((absIeta >= 29) && (absIeta <= 32)) {
325  // std::cout << "hf iphi: " << iphi << std::endl;
326  short hf_phi_index = iphi / 4;
327  // iphi = iphi/4; // change from 1,5,9, etc to access vector positions
328  // std::cout << "hf phi index: " << hf_phi_index << std::endl;
329  if (sign < 0) {
330  // std::cout << "ieta is " << ieta << ", absIeta is " << absIeta << ",
331  // iphi is " << iphi << std::endl; std::cout << "eta-: mask is " <<
332  // hfMask.at(0).at(hf_phi_index).at(absIeta-29) << std::endl; // hf
333  // ieta 0-3
334  energy = hfMask.at(0).at(hf_phi_index).at(absIeta - 29) *
335  hcalColl[i]
336  .sample(nSample)
337  .compressedEt(); // for hf, iphi starts at 0
338  fineGrain = (hfMask.at(0).at(hf_phi_index).at(absIeta - 29) != 0) &&
339  hcalColl[i].sample(nSample).fineGrain();
340  } else if (sign > 0) {
341  // std::cout << "ieta is " << ieta << ", absIeta is " << absIeta << ",
342  // iphi is " << iphi << std::endl; std::cout << "eta+: mask is " <<
343  // hfMask.at(1).at(hf_phi_index).at(absIeta-29) << std::endl;
344  energy = hfMask.at(1).at(hf_phi_index).at(absIeta - 29) *
345  hcalColl[i].sample(nSample).compressedEt();
346  fineGrain = (hfMask.at(1).at(hf_phi_index).at(absIeta - 29) != 0) &&
347  hcalColl[i].sample(nSample).fineGrain();
348  }
349  // iphi = iphi*4 + 1; // change back to original
350  // std::cout << "New hf iphi = " << iphi << std::endl;
351  }
352 
353  hcalDigi.setSample(nSample,
354  HcalTriggerPrimitiveSample(energy, fineGrain, 0, 0));
355 
356  // if (hcalDigi.SOI_compressedEt() != 0)
357  //{
358  // std::cout << "et " << hcalDigi.SOI_compressedEt()
359  // << "fg " << hcalDigi.SOI_fineGrain() << std::endl;
360  //}
361  }
362  maskedHcalTPs->push_back(hcalDigi);
363  }
364  // std::cout << "End of hcal digi masking" << std::endl;
365 
366  // put new data into event
367 
368  iEvent.put(std::move(maskedEcalTPs));
369  iEvent.put(std::move(maskedHcalTPs));
370 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::SortedCollection< HcalTriggerPrimitiveDigi > HcalTrigPrimDigiCollection
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
edm::SortedCollection< EcalTriggerPrimitiveDigi > EcalTrigPrimDigiCollection
HLT enums.
size_type size() const
std::string fullPath() const
Definition: FileInPath.cc:163
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

edm::InputTag MaskedRctInputDigiProducer::ecalDigisLabel_
private

Definition at line 58 of file MaskedRctInputDigiProducer.h.

Referenced by produce().

edm::InputTag MaskedRctInputDigiProducer::hcalDigisLabel_
private

Definition at line 59 of file MaskedRctInputDigiProducer.h.

Referenced by produce().

edm::FileInPath MaskedRctInputDigiProducer::maskFile_
private

Definition at line 60 of file MaskedRctInputDigiProducer.h.

Referenced by produce().

bool MaskedRctInputDigiProducer::useEcal_
private

Definition at line 56 of file MaskedRctInputDigiProducer.h.

Referenced by produce().

bool MaskedRctInputDigiProducer::useHcal_
private

Definition at line 57 of file MaskedRctInputDigiProducer.h.

Referenced by produce().