CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
26 
28  : fileName(conf.getUntrackedParameter<std::string>("rctTestInputFile")),
29  rctLookupTables(new L1RCTLookupTables),
30  rct(new L1RCT(rctLookupTables)),
31  useEcal(conf.getParameter<bool>("useEcal")),
32  useHcal(conf.getParameter<bool>("useHcal")),
33  ecalDigisLabel(conf.getParameter<edm::InputTag>("ecalDigisLabel")),
34  hcalDigisLabel(conf.getParameter<edm::InputTag>("hcalDigisLabel")),
35  rctParametersToken_(esConsumes<L1RCTParameters, L1RCTParametersRcd>()),
36  channelMaskToken_(esConsumes<L1RCTChannelMask, L1RCTChannelMaskRcd>()),
37  emScaleToken_(esConsumes<L1CaloEtScale, L1EmEtScaleRcd>()),
38  transcoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()),
39  hcalScaleToken_(esConsumes<L1CaloHcalScale, L1CaloHcalScaleRcd>()),
40  ecalScaleToken_(esConsumes<L1CaloEcalScale, L1CaloEcalScaleRcd>()),
41  useDebugTpgScales(conf.getParameter<bool>("useDebugTpgScales")),
42  tokens_(consumesCollector()) {
43  ofs.open(fileName.c_str(), std::ios::app);
44  if (!ofs) {
45  std::cerr << "Could not create " << fileName << std::endl;
46  exit(1);
47  }
48 }
49 
51  if (rct != nullptr)
52  delete rct;
53  if (rctLookupTables != nullptr)
54  delete rctLookupTables;
55 }
56 
57 void L1RCTSaveInput::analyze(const edm::Event &event, const edm::EventSetup &eventSetup) {
59  const L1RCTParameters *r = rctParameters.product();
61  const L1RCTChannelMask *c = channelMask.product();
63  const L1CaloEtScale *s = emScale.product();
64 
68 
69  if (useDebugTpgScales) {
70  // use old-style scales
72  const CaloTPGTranscoder *h_tpg = transcoder.product();
73 
74  EcalTPGScale e_tpg(tokens_, eventSetup);
75 
76  L1CaloEcalScale *ecalScale = new L1CaloEcalScale();
77  L1CaloHcalScale *hcalScale = new L1CaloHcalScale();
78 
79  // create input scales, werner's code
80  // ECAL
81  std::cout << "ECAL Pos " << L1CaloEcalScale::nBinRank << std::endl;
82  for (unsigned short ieta = 1; ieta <= L1CaloEcalScale::nBinEta; ++ieta) {
83  for (unsigned short irank = 0; irank < L1CaloEcalScale::nBinRank; ++irank) {
84  std::cout << ieta << " " << irank;
85  EcalSubdetector subdet = (ieta <= 17) ? EcalBarrel : EcalEndcap;
86  double etGeVPos = e_tpg.getTPGInGeV(irank,
87  EcalTrigTowerDetId(1, // +ve eta
88  subdet,
89  ieta,
90  1)); // dummy phi value
91  ecalScale->setBin(irank, ieta, 1, etGeVPos);
92  std::cout << etGeVPos << ", ";
93  }
94  std::cout << std::endl;
95  }
96  std::cout << std::endl;
97 
98  std::cout << "ECAL Neg" << std::endl;
99  for (unsigned short ieta = 1; ieta <= L1CaloEcalScale::nBinEta; ++ieta) {
100  for (unsigned short irank = 0; irank < L1CaloEcalScale::nBinRank; ++irank) {
101  EcalSubdetector subdet = (ieta <= 17) ? EcalBarrel : EcalEndcap;
102 
103  std::cout << ieta << " " << irank;
104  double etGeVNeg = e_tpg.getTPGInGeV(irank,
105  EcalTrigTowerDetId(-1, // -ve eta
106  subdet,
107  ieta,
108  2)); // dummy phi value
109  ecalScale->setBin(irank, ieta, -1, etGeVNeg);
110  std::cout << etGeVNeg << ", ";
111  }
112  std::cout << std::endl;
113  }
114  std::cout << std::endl;
115 
116  // HCAL
117  std::cout << "HCAL" << std::endl;
118  for (unsigned short ieta = 1; ieta <= L1CaloHcalScale::nBinEta; ++ieta) {
119  for (unsigned short irank = 0; irank < L1CaloHcalScale::nBinRank; ++irank) {
120  double etGeV = h_tpg->hcaletValue(ieta, irank);
121 
122  hcalScale->setBin(irank, ieta, 1, etGeV);
123  hcalScale->setBin(irank, ieta, -1, etGeV);
124  std::cout << etGeV << ", ";
125  std::cout << std::endl;
126  }
127  std::cout << std::endl;
128  }
129 
130  // set the input scales
131  rctLookupTables->setEcalScale(ecalScale);
132  rctLookupTables->setHcalScale(hcalScale);
133 
134  } else {
136  const L1CaloHcalScale *h = hcalScale.product();
138  const L1CaloEcalScale *e = ecalScale.product();
139 
142  }
143 
146  event.getByLabel(ecalDigisLabel, ecal);
147  event.getByLabel(hcalDigisLabel, hcal);
150  if (ecal.isValid()) {
151  ecalColl = *ecal;
152  }
153  if (hcal.isValid()) {
154  hcalColl = *hcal;
155  }
156  rct->digiInput(ecalColl, hcalColl);
157  static int nEvents = 0;
158  if (nEvents == 0) {
159  ofs << "Crate = 0-17" << std::endl
160  << "Card = 0-7 within the crate" << std::endl
161  << "Tower = 0-31 covers 4 x 8 covered by the card" << std::endl
162  << "EMAddr(0:8) = EMFGBit(0:0)+CompressedEMET(1:8)" << std::endl
163  << "HDAddr(0:8) = HDFGBit(0:0)+CompressedHDET(1:8) - note: "
164  "HDFGBit(0:0) is not part of the hardware LUT address"
165  << std::endl
166  << "LutOut(0:17)= "
167  "LinearEMET(0:6)+HoEFGVetoBit(7:7)+LinearJetET(8:16)+ActivityBit(17:"
168  "17)"
169  << std::endl
170  << "Event"
171  << "\t"
172  << "Crate"
173  << "\t"
174  << "Card"
175  << "\t"
176  << "Tower"
177  << "\t"
178  << "EMAddr"
179  << "\t"
180  << "HDAddr"
181  << "\t"
182  << "LUTOut" << std::endl;
183  }
184  if (nEvents < 64) {
185  for (unsigned short iCrate = 0; iCrate < 18; iCrate++) {
186  for (unsigned short iCard = 0; iCard < 7; iCard++) {
187  // tower numbered from 0-31
188  for (unsigned short iTower = 0; iTower < 32; iTower++) {
189  unsigned short ecal = rct->ecalCompressedET(iCrate, iCard, iTower);
190  unsigned short hcal = rct->hcalCompressedET(iCrate, iCard, iTower);
191  unsigned short fgbit = rct->ecalFineGrainBit(iCrate, iCard, iTower);
192  unsigned short mubit = rct->hcalFineGrainBit(iCrate, iCard, iTower);
193  unsigned long lutOutput = rctLookupTables->lookup(ecal, hcal, fgbit, iCrate, iCard, iTower);
194  ofs << std::hex << nEvents << "\t" << iCrate << "\t" << iCard << "\t" << iTower << "\t" << ecal * 2 + fgbit
195  << "\t" << hcal * 2 + mubit << "\t" << lutOutput << std::dec << std::endl;
196  }
197  }
198  }
199  }
200  nEvents++;
201 }
const edm::EventSetup & c
unsigned short hcalCompressedET(int crate, int card, int tower)
Definition: L1RCT.h:65
EcalTPGScale::Tokens tokens_
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
edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord > transcoderToken_
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
edm::ESGetToken< L1CaloEcalScale, L1CaloEcalScaleRcd > ecalScaleToken_
edm::ESGetToken< L1RCTChannelMask, L1RCTChannelMaskRcd > channelMaskToken_
bool isValid() const
Definition: HandleBase.h:70
void setL1CaloEtScale(const L1CaloEtScale *etScale)
double getTPGInGeV(const EcalTriggerPrimitiveDigi &tpDigi) const
Definition: EcalTPGScale.cc:17
std::vector< edm::EDGetTokenT< int > > tokens_
std::ofstream ofs
edm::ESGetToken< L1CaloHcalScale, L1CaloHcalScaleRcd > hcalScaleToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: ESHandle.h:86
edm::ESGetToken< L1CaloEtScale, L1EmEtScaleRcd > emScaleToken_
void setEcalScale(const L1CaloEcalScale *ecalScale)
edm::ESGetToken< L1RCTParameters, L1RCTParametersRcd > rctParametersToken_
void setRCTParameters(const L1RCTParameters *rctParameters)
static const unsigned short nBinRank
void digiInput(const EcalTrigPrimDigiCollection &ecalCollection, const HcalTrigPrimDigiCollection &hcalCollection)
Definition: L1RCT.cc:109
static const unsigned short nBinEta
static const unsigned short nBinEta
tuple cout
Definition: gather_cfg.py:144
Definition: L1RCT.h:20
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0
EcalSubdetector
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void setChannelMask(const L1RCTChannelMask *channelMask)
~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