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