CMS 3D CMS Logo

L1RCTSaveInput.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <iostream>
3 #include <memory>
4 #include <string>
5 using std::cerr;
6 using std::cout;
7 using std::endl;
8 using std::ostream;
9 
10 #include <iomanip>
11 
17 
19 
23 
28 
29 // also include old-style scales -- same as L1RCTProducer?
33 
36 
41 
44 
46  : fileName(conf.getUntrackedParameter<std::string>("rctTestInputFile")),
47  rctLookupTables(new L1RCTLookupTables),
48  rct(new L1RCT(rctLookupTables)),
49  useEcal(conf.getParameter<bool>("useEcal")),
50  useHcal(conf.getParameter<bool>("useHcal")),
51  ecalDigisLabel(conf.getParameter<edm::InputTag>("ecalDigisLabel")),
52  hcalDigisLabel(conf.getParameter<edm::InputTag>("hcalDigisLabel")),
53  useDebugTpgScales(conf.getParameter<bool>("useDebugTpgScales")) {
54  ofs.open(fileName.c_str(), std::ios::app);
55  if (!ofs) {
56  std::cerr << "Could not create " << fileName << std::endl;
57  exit(1);
58  }
59 }
60 
62  if (rct != nullptr)
63  delete rct;
64  if (rctLookupTables != nullptr)
65  delete rctLookupTables;
66 }
67 
68 void L1RCTSaveInput::analyze(const edm::Event &event, const edm::EventSetup &eventSetup) {
69  edm::ESHandle<L1RCTParameters> rctParameters;
70  eventSetup.get<L1RCTParametersRcd>().get(rctParameters);
71  const L1RCTParameters *r = rctParameters.product();
73  eventSetup.get<L1RCTChannelMaskRcd>().get(channelMask);
74  const L1RCTChannelMask *c = channelMask.product();
76  eventSetup.get<L1EmEtScaleRcd>().get(emScale);
77  const L1CaloEtScale *s = emScale.product();
78 
82 
83  if (useDebugTpgScales) {
84  // use old-style scales
86  eventSetup.get<CaloTPGRecord>().get(transcoder);
87  const CaloTPGTranscoder *h_tpg = transcoder.product();
88 
89  EcalTPGScale *e_tpg = new EcalTPGScale();
90  e_tpg->setEventSetup(eventSetup);
91 
92  L1CaloEcalScale *ecalScale = new L1CaloEcalScale();
93  L1CaloHcalScale *hcalScale = new L1CaloHcalScale();
94 
95  // create input scales, werner's code
96  // ECAL
97  std::cout << "ECAL Pos " << L1CaloEcalScale::nBinRank << std::endl;
98  for (unsigned short ieta = 1; ieta <= L1CaloEcalScale::nBinEta; ++ieta) {
99  for (unsigned short irank = 0; irank < L1CaloEcalScale::nBinRank; ++irank) {
100  std::cout << ieta << " " << irank;
101  EcalSubdetector subdet = (ieta <= 17) ? EcalBarrel : EcalEndcap;
102  double etGeVPos = e_tpg->getTPGInGeV(irank,
103  EcalTrigTowerDetId(1, // +ve eta
104  subdet,
105  ieta,
106  1)); // dummy phi value
107  ecalScale->setBin(irank, ieta, 1, etGeVPos);
108  std::cout << etGeVPos << ", ";
109  }
110  std::cout << std::endl;
111  }
112  std::cout << std::endl;
113 
114  std::cout << "ECAL Neg" << std::endl;
115  for (unsigned short ieta = 1; ieta <= L1CaloEcalScale::nBinEta; ++ieta) {
116  for (unsigned short irank = 0; irank < L1CaloEcalScale::nBinRank; ++irank) {
117  EcalSubdetector subdet = (ieta <= 17) ? EcalBarrel : EcalEndcap;
118 
119  std::cout << ieta << " " << irank;
120  double etGeVNeg = e_tpg->getTPGInGeV(irank,
121  EcalTrigTowerDetId(-1, // -ve eta
122  subdet,
123  ieta,
124  2)); // dummy phi value
125  ecalScale->setBin(irank, ieta, -1, etGeVNeg);
126  std::cout << etGeVNeg << ", ";
127  }
128  std::cout << std::endl;
129  }
130  std::cout << std::endl;
131 
132  // HCAL
133  std::cout << "HCAL" << std::endl;
134  for (unsigned short ieta = 1; ieta <= L1CaloHcalScale::nBinEta; ++ieta) {
135  for (unsigned short irank = 0; irank < L1CaloHcalScale::nBinRank; ++irank) {
136  double etGeV = h_tpg->hcaletValue(ieta, irank);
137 
138  hcalScale->setBin(irank, ieta, 1, etGeV);
139  hcalScale->setBin(irank, ieta, -1, etGeV);
140  std::cout << etGeV << ", ";
141  std::cout << std::endl;
142  }
143  std::cout << std::endl;
144  }
145 
146  // set the input scales
147  rctLookupTables->setEcalScale(ecalScale);
148  rctLookupTables->setHcalScale(hcalScale);
149 
150  delete e_tpg;
151 
152  } else {
154  eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
155  const L1CaloHcalScale *h = hcalScale.product();
157  eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
158  const L1CaloEcalScale *e = ecalScale.product();
159 
162  }
163 
166  event.getByLabel(ecalDigisLabel, ecal);
167  event.getByLabel(hcalDigisLabel, hcal);
170  if (ecal.isValid()) {
171  ecalColl = *ecal;
172  }
173  if (hcal.isValid()) {
174  hcalColl = *hcal;
175  }
176  rct->digiInput(ecalColl, hcalColl);
177  static int nEvents = 0;
178  if (nEvents == 0) {
179  ofs << "Crate = 0-17" << std::endl
180  << "Card = 0-7 within the crate" << std::endl
181  << "Tower = 0-31 covers 4 x 8 covered by the card" << std::endl
182  << "EMAddr(0:8) = EMFGBit(0:0)+CompressedEMET(1:8)" << std::endl
183  << "HDAddr(0:8) = HDFGBit(0:0)+CompressedHDET(1:8) - note: "
184  "HDFGBit(0:0) is not part of the hardware LUT address"
185  << std::endl
186  << "LutOut(0:17)= "
187  "LinearEMET(0:6)+HoEFGVetoBit(7:7)+LinearJetET(8:16)+ActivityBit(17:"
188  "17)"
189  << std::endl
190  << "Event"
191  << "\t"
192  << "Crate"
193  << "\t"
194  << "Card"
195  << "\t"
196  << "Tower"
197  << "\t"
198  << "EMAddr"
199  << "\t"
200  << "HDAddr"
201  << "\t"
202  << "LUTOut" << std::endl;
203  }
204  if (nEvents < 64) {
205  for (unsigned short iCrate = 0; iCrate < 18; iCrate++) {
206  for (unsigned short iCard = 0; iCard < 7; iCard++) {
207  // tower numbered from 0-31
208  for (unsigned short iTower = 0; iTower < 32; iTower++) {
209  unsigned short ecal = rct->ecalCompressedET(iCrate, iCard, iTower);
210  unsigned short hcal = rct->hcalCompressedET(iCrate, iCard, iTower);
211  unsigned short fgbit = rct->ecalFineGrainBit(iCrate, iCard, iTower);
212  unsigned short mubit = rct->hcalFineGrainBit(iCrate, iCard, iTower);
213  unsigned long lutOutput = rctLookupTables->lookup(ecal, hcal, fgbit, iCrate, iCard, iTower);
214  ofs << std::hex << nEvents << "\t" << iCrate << "\t" << iCard << "\t" << iTower << "\t" << ecal * 2 + fgbit
215  << "\t" << hcal * 2 + mubit << "\t" << lutOutput << std::dec << std::endl;
216  }
217  }
218  }
219  }
220  nEvents++;
221 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalTPGScale.cc:16
unsigned short hcalCompressedET(int crate, int card, int tower)
Definition: L1RCT.h:65
edm::InputTag ecalDigisLabel
void setBin(unsigned short rank, unsigned short eta, short etaSign, double et)
set scale element; use this to create non-linear scales
L1RCTSaveInput(const edm::ParameterSet &)
L1RCTLookupTables * rctLookupTables
void setBin(unsigned short rank, unsigned short eta, short etaSign, double et)
set scale element; use this to create non-linear scales
unsigned short hcalFineGrainBit(int crate, int card, int tower)
Definition: L1RCT.h:68
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi)
Definition: EcalTPGScale.cc:18
void setHcalScale(const L1CaloHcalScale *hcalScale)
unsigned short ecalFineGrainBit(int crate, int card, int tower)
Definition: L1RCT.h:64
unsigned short ecalCompressedET(int crate, int card, int tower)
Definition: L1RCT.h:63
static const unsigned short nBinRank
std::string fileName
bool isValid() const
Definition: HandleBase.h:70
void setL1CaloEtScale(const L1CaloEtScale *etScale)
std::ofstream ofs
void analyze(const edm::Event &, const edm::EventSetup &) override
void setEcalScale(const L1CaloEcalScale *ecalScale)
void setRCTParameters(const L1RCTParameters *rctParameters)
HLT enums.
static const unsigned short nBinRank
void digiInput(const EcalTrigPrimDigiCollection &ecalCollection, const HcalTrigPrimDigiCollection &hcalCollection)
Definition: L1RCT.cc:109
T get() const
Definition: EventSetup.h:73
static const unsigned short nBinEta
static const unsigned short nBinEta
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0
Definition: L1RCT.h:20
UInt_t nEvents
Definition: hcalCalib.cc:41
EcalSubdetector
T const * product() const
Definition: ESHandle.h:86
void setChannelMask(const L1RCTChannelMask *channelMask)
Definition: event.py:1
~L1RCTSaveInput() override
unsigned int lookup(unsigned short ecalInput, unsigned short hcalInput, unsigned short fgbit, unsigned short crtNo, unsigned short crdNo, unsigned short twrNo) const
edm::InputTag hcalDigisLabel
def exit(msg="")