CMS 3D CMS Logo

RctInputTextToDigi.cc
Go to the documentation of this file.
1 #include "RctInputTextToDigi.h"
2 
3 //
4 // constructors and destructor
5 //
6 
8  : inputFile_(iConfig.getParameter<edm::FileInPath>("inputFile")),
9  inputStream_(inputFile_.fullPath().c_str()), nEvent_(0),
10  oldVersion_(false), lookupTables_(new L1RCTLookupTables) {
11  // register your products
12  /* Examples
13  produces<ExampleData2>();
14 
15  //if do put with a label
16  produces<ExampleData2>("label");
17  */
18 
19  produces<EcalTrigPrimDigiCollection>();
20  produces<HcalTrigPrimDigiCollection>();
21 
22  // now do what ever other initialization is needed
23 
24  if ((!inputStream_.is_open()) || (!inputStream_)) {
25  // not good!!
26  std::cerr << "Input file didn't open!!" << std::endl;
27  }
28  // if (inputStream_.eof()) {std::cout << "Real zeroth eof! " << std::endl;}
29 }
30 
32 
33  // do anything here that needs to be done at desctruction time
34  // (e.g. close files, deallocate resources etc.)
35 
36  inputStream_.close();
37 }
38 
39 //
40 // member functions
41 //
42 
43 // ------------ method called to produce the data ------------
45  const edm::EventSetup &iSetup) {
46  using namespace edm;
47 
48  // std::cout << std::endl << std::endl << "Event number " << nEvent_ <<
49  // std::endl;
50 
51  // This next section taken directly from
52  // L1Trigger/RegionalCaloTrigger/plugins/L1RCTProducer.cc rev. 1.6
53  // Refresh configuration information every event
54  // Hopefully doesn't take too much time
55  ESHandle<L1RCTParameters> rctParameters;
56  iSetup.get<L1RCTParametersRcd>().get(rctParameters);
57  const L1RCTParameters *r = rctParameters.product();
59 
60  std::unique_ptr<EcalTrigPrimDigiCollection> ecalTPs(
62  std::unique_ptr<HcalTrigPrimDigiCollection> hcalTPs(
64  ecalTPs->reserve(56 * 72);
65  hcalTPs->reserve(56 * 72 + 18 * 8); // includes HF
66  const int nEcalSamples = 1; // we only use 1 sample for each
67  const int nHcalSamples = 1;
68 
69  int fileEventNumber;
70 
71  // check to see if need to skip file header and do so before
72  // looping through entire event
73 
74  std::string junk;
75  // bool old_version = false;
76  if (nEvent_ == 0) {
77  // std::string junk;
78  unsigned short junk_counter = 0;
79  // bool old_version = false;
80  do {
81  if (inputStream_ >> junk) { /*std::cout << "Good: ";*/
82  }
83  // std::cout << "header junk was input: \"" << junk << "\"."
84  // << std::endl;
85  // for oldest version, which is same as newest version
86  // if((junk_counter == 11) && (junk.compare("0-32") == 0))
87  // {
88  // oldVersion_ = true;
89  // }
90  if ((junk_counter == 11) && (junk == "1-32")) {
91  oldVersion_ = true;
92  }
93  junk_counter++;
94  } while (junk != "LUTOut");
95  std::cout << "Skipped file header" << std::endl;
96  if (oldVersion_) {
97  std::cout << "oldVersion_ TRUE (tower 1-32)" << std::endl;
98  } else {
99  std::cout << "oldVersion_ FALSE (tower 0-31)" << std::endl;
100  }
101  }
102 
103  // can't actually read in phi and eta, file has crate card tower instead
104  // do a while loop for event number instead?? dunno
105  for (int i = 0; i < 72; i++) {
106  // negative eta, iEta -28 to -1
107  for (int j = 0; j < 56; j++) {
108  // calc ieta, iphi coords of tower
109  // ieta -28 to -1 or 1 to 28, iphi 1 to 72
110  // methods in CondFormats/L1TObjects/src/L1RCTParameters.cc
111 
112  unsigned short crate;
113  unsigned short card;
114  unsigned short tower;
115  unsigned eAddr;
116  unsigned hAddr;
117 
118  inputStream_ >> std::hex >> fileEventNumber >> crate >> card >> tower >>
119  eAddr >> hAddr >> junk >> std::dec;
120 
121  if (oldVersion_) {
122  tower = tower - 1;
123  }
124  int encodedEtEcal = (int)(eAddr >> 1);
125  bool fineGrainEcal = (bool)(eAddr & 1);
126  int encodedEtHcal = (int)(hAddr >> 1);
127  bool fineGrainHcal = (bool)(hAddr & 1); // mip bit
128 
129  // std::cout << "Eventnumber " << fileEventNumber << "\tCrate "
130  // << crate << "\tCard " << card << "\tTower "
131  // << tower << " \teAddr " << eAddr <<"\thAddr "
132  // << hAddr << "\tjunk " << junk << std::endl;
133 
134  int iEta = lookupTables_->rctParameters()->calcIEta(crate, card, tower);
135  int iPhi = lookupTables_->rctParameters()->calcIPhi(crate, card, tower);
136  // transform rct iphi coords into global coords
137  iPhi = ((72 + 18 - iPhi) % 72);
138  if (iPhi == 0) {
139  iPhi = 72;
140  }
141  unsigned absIeta = abs(iEta);
142  int zSide = (iEta / absIeta);
143 
144  /*std::cout << "iEta " << iEta << "\tabsiEta " << absIeta
145  << "\tiPhi " << iPhi << "\tzSide "
146  << zSide << std::endl;
147  */
148 
149  // args to detid are zside, type of tower, absieta, iphi
150  // absieta and iphi must be between 1 and 127 inclusive
151 
152  EcalTriggerPrimitiveDigi ecalDigi(
153  EcalTrigTowerDetId(zSide, EcalTriggerTower, absIeta, iPhi));
154  ecalDigi.setSize(nEcalSamples);
155 
156  // last arg is 3-bit trigger tower flag, which we don't use
157  // we only use 8-bit encoded et and 1-bit fg
158  ecalDigi.setSample(
159  0, EcalTriggerPrimitiveSample(encodedEtEcal, fineGrainEcal, 0));
160  // std::cout << ecalDigi << std::endl;
161  ecalTPs->push_back(ecalDigi);
162 
163  HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId(iEta, iPhi));
164 
165  hcalDigi.setSize(nHcalSamples);
166 
167  // last two arg's are slb and slb channel, which we don't need
168  hcalDigi.setSample(
169  0, HcalTriggerPrimitiveSample(encodedEtHcal, fineGrainHcal, 0, 0));
170  // std::cout << hcalDigi << std::endl;
171  hcalTPs->push_back(hcalDigi);
172  }
173 
174  // also need to push_back HF digis!
175  // file input doesn't include HF, so need empty digis
176  for (int i = 0; i < 18; i++) {
177  for (int j = 0; j < 8; j++) {
178  // HF ieta: +- 29 through 32. HF iphi: 1,5,9,13,etc.
179  int hfIEta = (j % 4) + 29;
180  if (i < 9) {
181  hfIEta = hfIEta * (-1);
182  }
183  // iphi shift not implemented, but not necessary here --
184  // everything's filled with zeros so it's symmetric anyhow
185  int hfIPhi = (i % 9) * 8 + (j / 4) * 4 + 1;
186 
187  HcalTriggerPrimitiveDigi hfDigi(HcalTrigTowerDetId(hfIEta, hfIPhi));
188  hfDigi.setSize(1);
189  hfDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
190  hcalTPs->push_back(hfDigi);
191  }
192  }
193  }
194  iEvent.put(std::move(ecalTPs));
195  iEvent.put(std::move(hcalTPs));
196 
197  nEvent_++;
198  // std::cout << "Produce done" << std::endl;
199 }
200 
201 // ------------ method called once each job just before starting event loop
202 // ------------
204  // open input file to read all events
205  // inputStream_.open(inputFile_.fullPath().c_str());
206  // std::cout << "beginJob entered" << std::endl;
207 }
208 
209 // ------------ method called once each job just after ending the event loop
210 // ------------
212  // close input file
213  // inputStream_.close();
214 }
215 
216 // define this as a plug-in
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::SortedCollection< HcalTriggerPrimitiveDigi > HcalTrigPrimDigiCollection
~RctInputTextToDigi() override
short calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void produce(edm::Event &, const edm::EventSetup &) override
unsigned short calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
RctInputTextToDigi(const edm::ParameterSet &)
edm::SortedCollection< EcalTriggerPrimitiveDigi > EcalTrigPrimDigiCollection
L1RCTLookupTables * lookupTables_
std::ifstream inputStream_
const L1RCTParameters * rctParameters() const
void setRCTParameters(const L1RCTParameters *rctParameters)
HLT enums.
T get() const
Definition: EventSetup.h:71
void beginJob() override
T const * product() const
Definition: ESHandle.h:86
void endJob() override
def move(src, dest)
Definition: eostools.py:511