CMS 3D CMS Logo

L1CaloTowerTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1Ntuples
4 // Class: L1CaloTowerTreeProducer
5 //
13 //
14 // Original Author:
15 // Created:
16 // $Id: L1CaloTowerTreeProducer.cc,v 1.8 2012/08/29 12:44:03 jbrooke Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // framework
31 
32 // data formats
38 
39 // cond formats
42 
43 // ROOT output stuff
46 #include "TTree.h"
47 
51 
54 
57 
58 //
59 // class declaration
60 //
61 
62 class L1CaloTowerTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
63 public:
65  ~L1CaloTowerTreeProducer() override = default;
66 
67 private:
68  void beginJob(void) override;
69  void analyze(const edm::Event&, const edm::EventSetup&) override;
70  void endJob() override;
71 
72 public:
76 
77 private:
78  const double ecalLSB_;
79  const unsigned maxCaloTP_;
80  const unsigned maxL1Tower_;
81  const unsigned maxL1Cluster_;
82 
83  // EDM input tags
89 
90  // output file
92 
93  // tree
94  TTree* tree_;
95 
97 };
98 
100  : ecalLSB_(iConfig.getUntrackedParameter<double>("ecalLSB", 0.5)),
101  maxCaloTP_(iConfig.getUntrackedParameter<unsigned int>("maxCaloTP", 5760)),
102  maxL1Tower_(iConfig.getUntrackedParameter<unsigned int>("maxL1Tower", 5760)),
103  maxL1Cluster_(iConfig.getUntrackedParameter<unsigned int>("maxL1Cluster", 5760)),
104  ecalToken_(consumes<EcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("ecalToken"))),
105  hcalToken_(consumes<HcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("hcalToken"))),
106  l1TowerToken_(consumes<l1t::CaloTowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("l1TowerToken"))),
107  decoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()) {
108  edm::InputTag clusterTag = iConfig.getUntrackedParameter<edm::InputTag>("l1ClusterToken");
109  storeCaloClusters_ = true;
110  if (clusterTag.label() == std::string("") or clusterTag.label() == std::string("none"))
111  storeCaloClusters_ = false;
112 
113  if (clusterTag.instance() != std::string(""))
114  l1ClusterToken_ = consumes<l1t::CaloClusterBxCollection>(clusterTag);
115 
116  usesResource(TFileService::kSharedResource);
117 
118  // set up output
119  tree_ = fs_->make<TTree>("L1CaloTowerTree", "L1CaloTowerTree");
120  tree_->Branch("CaloTP", "L1Analysis::L1AnalysisCaloTPDataFormat", &caloTPData_, 32000, 3);
121  tree_->Branch("L1CaloTower", "L1Analysis::L1AnalysisL1CaloTowerDataFormat", &l1CaloTowerData_, 32000, 3);
122 
123  if (storeCaloClusters_)
124  tree_->Branch("L1CaloCluster", "L1Analysis::L1AnalysisL1CaloClusterDataFormat", &l1CaloClusterData_, 32000, 3);
125 
129 }
130 
131 //
132 // member functions
133 //
134 
135 // ------------ method called to for each event ------------
137  // do calo towers
138  caloTPData_->Reset();
139 
141  decoder = iSetup.getHandle(decoderToken_);
142 
145 
146  iEvent.getByToken(ecalToken_, ecalTPs);
147  iEvent.getByToken(hcalToken_, hcalTPs);
148 
149  if (ecalTPs.isValid()) {
150  for (const auto& itr : *(ecalTPs.product())) {
151  short ieta = (short)itr.id().ieta();
152  // unsigned short absIeta = (unsigned short) abs(ieta);
153  // short sign = ieta/absIeta;
154 
155  unsigned short cal_iphi = (unsigned short)itr.id().iphi();
156  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
157  unsigned short compEt = itr.compressedEt();
158  double et = ecalLSB_ * compEt;
159  unsigned short fineGrain = (unsigned short)itr.fineGrain();
160 
161  if (compEt > 0) {
162  caloTPData_->ecalTPieta.push_back(ieta);
163  caloTPData_->ecalTPCaliphi.push_back(cal_iphi);
164  caloTPData_->ecalTPiphi.push_back(iphi);
165  caloTPData_->ecalTPet.push_back(et);
166  caloTPData_->ecalTPcompEt.push_back(compEt);
167  caloTPData_->ecalTPfineGrain.push_back(fineGrain);
168  caloTPData_->nECALTP++;
169  }
170  }
171 
172  } else {
173  edm::LogWarning("L1TNtuple") << "ECAL TPs not found, branch will not be filled";
174  }
175 
176  if (hcalTPs.isValid()) {
177  for (auto itr : (*hcalTPs.product())) {
178  int ver = itr.id().version();
179  short ieta = (short)itr.id().ieta();
180  unsigned short absIeta = (unsigned short)abs(ieta);
181  // short sign = ieta/absIeta;
182 
183  unsigned short cal_iphi = (unsigned short)itr.id().iphi();
184  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
185 
186  unsigned short compEt = itr.SOI_compressedEt();
187  double et = decoder->hcaletValue(itr.id(), itr.t0());
188 
189  unsigned short fineGrain = (unsigned short)itr.SOI_fineGrain();
190 
191  if (compEt > 0 && (absIeta < 29 || ver == 1)) {
192  caloTPData_->hcalTPieta.push_back(ieta);
193  caloTPData_->hcalTPCaliphi.push_back(cal_iphi);
194  caloTPData_->hcalTPiphi.push_back(iphi);
195  caloTPData_->hcalTPet.push_back(et);
196  caloTPData_->hcalTPcompEt.push_back(compEt);
197  caloTPData_->hcalTPfineGrain.push_back(fineGrain);
198  caloTPData_->nHCALTP++;
199  }
200  }
201 
202  } else {
203  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
204  }
205 
206  // do L1 towers
208 
210  iEvent.getByToken(l1TowerToken_, l1Towers);
211 
212  if (l1Towers.isValid()) {
213  for (int ibx = l1Towers->getFirstBX(); ibx <= l1Towers->getLastBX(); ++ibx) {
214  for (auto itr = l1Towers->begin(ibx); itr != l1Towers->end(ibx); ++itr) {
215  if (itr->hwPt() <= 0)
216  continue;
217 
218  // l1CaloTowerData_->bx.push_back( ibx );
219  l1CaloTowerData_->et.push_back(itr->pt());
220  l1CaloTowerData_->eta.push_back(itr->eta());
221  l1CaloTowerData_->phi.push_back(itr->phi());
222  l1CaloTowerData_->iet.push_back(itr->hwPt());
223  l1CaloTowerData_->ieta.push_back(itr->hwEta());
224  l1CaloTowerData_->iphi.push_back(itr->hwPhi());
225  l1CaloTowerData_->iem.push_back(itr->hwEtEm());
226  l1CaloTowerData_->ihad.push_back(itr->hwEtHad());
227  l1CaloTowerData_->iratio.push_back(itr->hwEtRatio());
228  l1CaloTowerData_->iqual.push_back(itr->hwQual());
229 
231  }
232  }
233 
234  } else {
235  edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
236  }
237 
238  // do L1 clusters
239  if (storeCaloClusters_) {
241 
243  if (!l1ClusterToken_.isUninitialized())
244  iEvent.getByToken(l1ClusterToken_, l1Clusters);
245 
246  if (l1Clusters.isValid()) {
247  for (int ibx = l1Clusters->getFirstBX(); ibx <= l1Clusters->getLastBX(); ++ibx) {
248  for (auto itr = l1Clusters->begin(ibx); itr != l1Clusters->end(ibx); ++itr) {
249  if (itr->hwPt() <= 0)
250  continue;
251 
252  // l1CaloClusterData_->bx.push_back( ibx );
253  l1CaloClusterData_->et.push_back(itr->pt());
254  l1CaloClusterData_->eta.push_back(itr->eta());
255  l1CaloClusterData_->phi.push_back(itr->phi());
256  l1CaloClusterData_->iet.push_back(itr->hwPt());
257  l1CaloClusterData_->ieta.push_back(itr->hwEta());
258  l1CaloClusterData_->iphi.push_back(itr->hwPhi());
259  l1CaloClusterData_->iqual.push_back(itr->hwQual());
260 
262  }
263  }
264 
265  } else {
266  edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
267  }
268  }
269 
270  tree_->Fill();
271 }
272 
273 // ------------ method called once each job just before starting event loop ------------
275 
276 // ------------ method called once each job just after ending the event loop ------------
278 
279 //define this as a plug-in
int getLastBX() const
static const std::string kSharedResource
Definition: TFileService.h:76
L1CaloTowerTreeProducer(const edm::ParameterSet &)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
int getFirstBX() const
const edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalToken_
const edm::ESGetToken< CaloTPGTranscoder, CaloTPGRecord > decoderToken_
T const * product() const
Definition: Handle.h:70
delete x;
Definition: CaloConfig.h:22
L1Analysis::L1AnalysisCaloTPDataFormat * caloTPData_
const_iterator begin(int bx) const
T getUntrackedParameter(std::string const &, T const &) const
const edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalToken_
int iEvent
Definition: GenABIO.cc:224
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::Service< TFileService > fs_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::EDGetTokenT< l1t::CaloClusterBxCollection > l1ClusterToken_
BXVector< CaloTower > CaloTowerBxCollection
Definition: CaloTower.h:9
L1Analysis::L1AnalysisL1CaloClusterDataFormat * l1CaloClusterData_
~L1CaloTowerTreeProducer() override=default
bool isValid() const
Definition: HandleBase.h:70
const_iterator end(int bx) const
void analyze(const edm::Event &, const edm::EventSetup &) override
HLT enums.
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Log< level::Warning, false > LogWarning
L1Analysis::L1AnalysisL1CaloTowerDataFormat * l1CaloTowerData_
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0
const edm::EDGetTokenT< l1t::CaloTowerBxCollection > l1TowerToken_