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