CMS 3D CMS Logo

CaloTPTableProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: CaloTPTableProducer
5 //
13 //
14 // Original Author: localusers user
15 // Created: Wed, 08 Nov 2023 13:16:40 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
34 
36 
39 
42 
45 
46 //
47 // class declaration
48 //
49 
51 public:
52  explicit CaloTPTableProducer(const edm::ParameterSet&);
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void beginStream(edm::StreamID) override;
58  void produce(edm::Event&, const edm::EventSetup&) override;
59  void endStream() override;
60 
61  // ----------member data ---------------------------
62  const double ecalLSB_;
63 
66 
69 
71 };
72 
74  : ecalLSB_(iConfig.getUntrackedParameter<double>("ecalLSB", 0.5)),
75  ecalTPsToken_(consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("ecalTPsSrc"))),
76  ecalTPsName_(iConfig.getParameter<std::string>("ecalTPsName")),
77  hcalTPsToken_(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalTPsSrc"))),
78  hcalTPsName_(iConfig.getParameter<std::string>("hcalTPsName")),
79  decoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()) {
80  produces<nanoaod::FlatTable>("EcalTP");
81  produces<nanoaod::FlatTable>("HcalTP");
82 
83  //now do what ever other initialization is needed
84 }
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called to produce the data ------------
92  using namespace edm;
93 
95  decoder = iSetup.getHandle(decoderToken_);
96 
98  iEvent.getByToken(ecalTPsToken_, ecalTPs);
99 
101  iEvent.getByToken(hcalTPsToken_, hcalTPs);
102 
103  vector<int> ecalTPieta;
104  vector<int> ecalTPCaliphi;
105  vector<int> ecalTPiphi;
106  vector<float> ecalTPet;
107  vector<int> ecalTPcompEt;
108  vector<int> ecalTPfineGrain;
109  int nECALTP(0);
110  if (ecalTPs.isValid()) {
111  for (const auto& itr : *(ecalTPs.product())) {
112  short ieta = (short)itr.id().ieta();
113 
114  unsigned short cal_iphi = (unsigned short)itr.id().iphi();
115  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
116  unsigned short compEt = itr.compressedEt();
117  double et = ecalLSB_ * compEt;
118  unsigned short fineGrain = (unsigned short)itr.fineGrain();
119 
120  if (compEt > 0) {
121  ecalTPieta.push_back(ieta);
122  ecalTPCaliphi.push_back(cal_iphi);
123  ecalTPiphi.push_back(iphi);
124  ecalTPet.push_back(et);
125  ecalTPcompEt.push_back(compEt);
126  ecalTPfineGrain.push_back(fineGrain);
127  nECALTP++;
128  }
129  }
130  }
131  auto ecalTPTable = std::make_unique<nanoaod::FlatTable>(nECALTP, ecalTPsName_, false);
132  ecalTPTable->addColumn<int16_t>("ieta", ecalTPieta, "");
133  ecalTPTable->addColumn<int16_t>("Caliphi", ecalTPCaliphi, "");
134  ecalTPTable->addColumn<int16_t>("iphi", ecalTPiphi, "");
135  ecalTPTable->addColumn<float>("et", ecalTPet, "", 12);
136  ecalTPTable->addColumn<int16_t>("compEt", ecalTPcompEt, "");
137  ecalTPTable->addColumn<int16_t>("fineGrain", ecalTPfineGrain, "");
138 
139  vector<int> hcalTPieta;
140  vector<int> hcalTPCaliphi;
141  vector<int> hcalTPiphi;
142  vector<float> hcalTPet;
143  vector<int> hcalTPcompEt;
144  vector<int> hcalTPfineGrain;
145  int nHCALTP(0);
146  if (hcalTPs.isValid()) {
147  for (auto itr : (*hcalTPs.product())) {
148  int ver = itr.id().version();
149  short ieta = (short)itr.id().ieta();
150  unsigned short absIeta = (unsigned short)abs(ieta);
151  unsigned short cal_iphi = (unsigned short)itr.id().iphi();
152  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
153 
154  unsigned short compEt = itr.SOI_compressedEt();
155  double et = decoder->hcaletValue(itr.id(), itr.t0());
156  unsigned short fineGrain = (unsigned short)itr.SOI_fineGrain();
157 
158  if (compEt > 0 && (absIeta < 29 || ver == 1)) {
159  hcalTPieta.push_back(ieta);
160  hcalTPCaliphi.push_back(cal_iphi);
161  hcalTPiphi.push_back(iphi);
162  hcalTPet.push_back(et);
163  hcalTPcompEt.push_back(compEt);
164  hcalTPfineGrain.push_back(fineGrain);
165  nHCALTP++;
166  }
167  }
168  }
169 
170  auto hcalTPTable = std::make_unique<nanoaod::FlatTable>(nHCALTP, hcalTPsName_, false);
171  hcalTPTable->addColumn<int16_t>("ieta", hcalTPieta, "");
172  hcalTPTable->addColumn<int16_t>("Caliphi", hcalTPCaliphi, "");
173  hcalTPTable->addColumn<int16_t>("iphi", hcalTPiphi, "");
174  hcalTPTable->addColumn<float>("et", hcalTPet, "", 12);
175  hcalTPTable->addColumn<int16_t>("compEt", hcalTPcompEt, "");
176  hcalTPTable->addColumn<int16_t>("fineGrain", hcalTPfineGrain, "");
177 
178  iEvent.put(std::move(ecalTPTable), "HcalTP");
179  iEvent.put(std::move(hcalTPTable), "EcalTP");
180 }
181 
182 // ------------ method called once each stream before processing any runs, lumis or events ------------
184  // please remove this method if not needed
185 }
186 
187 // ------------ method called once each stream after processing all runs, lumis and events ------------
189  // please remove this method if not needed
190 }
191 
192 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
195 
196  desc.add<std::string>("name", "l1calotowerflattableproducer");
197  desc.addUntracked<double>("ecalLSB", 0.5);
198  desc.add<edm::InputTag>("ecalTPsSrc", edm::InputTag{"ecalDigis", "EcalTriggerPrimitives"});
199  desc.add<string>("ecalTPsName", "EcalUnpackedTPs");
200  desc.add<edm::InputTag>("hcalTPsSrc", edm::InputTag{"hcalDigis"});
201  desc.add<string>("hcalTPsName", "HcalUnpackedTPs");
202 
203  descriptions.addWithDefaultLabel(desc);
204 }
205 
206 //define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
CaloTPTableProducer(const edm::ParameterSet &)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:70
const std::string hcalTPsName_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalTPsToken_
int iEvent
Definition: GenABIO.cc:224
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void beginStream(edm::StreamID) override
const std::string ecalTPsName_
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
const edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord > decoderToken_
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalTPsToken_