CMS 3D CMS Logo

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

#include <L1Trigger/MaskedRctInputDigiProducer/src/MaskedRctInputDigiProducer.cc>

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

Public Member Functions

 MaskedRctInputDigiProducer (const edm::ParameterSet &)
 
 ~MaskedRctInputDigiProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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 & itemsToGetFromEvent () 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
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

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
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)
 
- 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 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

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.

15  :
16  useEcal_(iConfig.getParameter<bool>("useEcal")),
17  useHcal_(iConfig.getParameter<bool>("useHcal")),
18  ecalDigisLabel_(iConfig.getParameter<edm::InputTag>("ecalDigisLabel")),
19  hcalDigisLabel_(iConfig.getParameter<edm::InputTag>("hcalDigisLabel")),
20  maskFile_(iConfig.getParameter<edm::FileInPath>("maskFile"))
21 {
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 
35 }
T getParameter(std::string const &) const
MaskedRctInputDigiProducer::~MaskedRctInputDigiProducer ( )

Definition at line 38 of file MaskedRctInputDigiProducer.cc.

39 {
40 
41  // do anything here that needs to be done at desctruction time
42  // (e.g. close files, deallocate resources etc.)
43 
44 }

Member Function Documentation

void MaskedRctInputDigiProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 385 of file MaskedRctInputDigiProducer.cc.

References DEFINE_FWK_MODULE.

385  {
386 }
void MaskedRctInputDigiProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Definition at line 53 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_, i, edm::HandleBase::isValid(), j, maskFile_, eostools::move(), hcalTTPDigis_cfi::presamples, edm::Event::put(), 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_.

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

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().