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
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
RctInputTextToDigi::lookupTables_
L1RCTLookupTables * lookupTables_
Definition: RctInputTextToDigi.h:66
RctInputTextToDigi::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: RctInputTextToDigi.cc:45
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
L1RCTParameters::calcIEta
short calcIEta(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
Definition: L1RCTParameters.cc:141
HcalTriggerPrimitiveSample
Definition: HcalTriggerPrimitiveSample.h:11
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
L1RCTParametersRcd
Definition: L1RCTParametersRcd.h:12
RctInputTextToDigi::nEvent_
int nEvent_
Definition: RctInputTextToDigi.h:64
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:4
RctInputTextToDigi
Definition: RctInputTextToDigi.h:50
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
HcalTriggerPrimitiveDigi::setSample
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
Definition: HcalTriggerPrimitiveDigi.h:43
RctInputTextToDigi::endJob
void endJob() override
Definition: RctInputTextToDigi.cc:205
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
RctInputTextToDigi::RctInputTextToDigi
RctInputTextToDigi(const edm::ParameterSet &)
Definition: RctInputTextToDigi.cc:7
edm::ESHandle
Definition: DTSurvey.h:22
RctInputTextToDigi::inputStream_
std::ifstream inputStream_
Definition: RctInputTextToDigi.h:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalTrigPrimDigiCollection
edm::SortedCollection< EcalTriggerPrimitiveDigi > EcalTrigPrimDigiCollection
Definition: EcalDigiCollections.h:121
RctInputTextToDigi::oldVersion_
bool oldVersion_
Definition: RctInputTextToDigi.h:65
EcalTriggerPrimitiveDigi::setSize
void setSize(int size)
Definition: EcalTriggerPrimitiveDigi.cc:60
L1RCTLookupTables
Definition: L1RCTLookupTables.h:11
HcalTriggerPrimitiveDigi
Definition: HcalTriggerPrimitiveDigi.h:13
edm::ParameterSet
Definition: ParameterSet.h:47
RctInputTextToDigi::~RctInputTextToDigi
~RctInputTextToDigi() override
Definition: RctInputTextToDigi.cc:33
EcalTriggerPrimitiveDigi::setSample
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
Definition: EcalTriggerPrimitiveDigi.h:36
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
L1RCTLookupTables::rctParameters
const L1RCTParameters * rctParameters() const
Definition: L1RCTLookupTables.h:33
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
alignCSCRings.r
r
Definition: alignCSCRings.py:93
L1RCTParameters::calcIPhi
unsigned short calcIPhi(unsigned short iCrate, unsigned short iCard, unsigned short iTower) const
Definition: L1RCTParameters.cc:152
eostools.move
def move(src, dest)
Definition: eostools.py:511
EcalTriggerTower
Definition: EcalSubdetector.h:10
EcalTriggerPrimitiveDigi
Definition: EcalTriggerPrimitiveDigi.h:16
L1RCTLookupTables::setRCTParameters
void setRCTParameters(const L1RCTParameters *rctParameters)
Definition: L1RCTLookupTables.h:21
L1RCTParameters
Definition: L1RCTParameters.h:27
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
EcalTriggerPrimitiveSample
Definition: EcalTriggerPrimitiveSample.h:12
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
HcalTriggerPrimitiveDigi::setSize
void setSize(int size)
Definition: HcalTriggerPrimitiveDigi.cc:7
HcalTrigPrimDigiCollection
edm::SortedCollection< HcalTriggerPrimitiveDigi > HcalTrigPrimDigiCollection
Definition: HcalDigiCollections.h:24
RctInputTextToDigi::beginJob
void beginJob() override
Definition: RctInputTextToDigi.cc:197
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14
RctInputTextToDigi.h