CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
63 public:
65  ~L1CaloTowerTreeProducer() override;
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  double ecalLSB_;
79  unsigned maxCaloTP_;
80  unsigned maxL1Tower_;
81  unsigned maxL1Cluster_;
82 
83  // output file
85 
86  // tree
87  TTree* tree_;
88 
89  // EDM input tags
94 
96 };
97 
99  ecalToken_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("ecalToken"));
100  hcalToken_ = consumes<HcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("hcalToken"));
101  l1TowerToken_ = consumes<l1t::CaloTowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("l1TowerToken"));
102 
103  edm::InputTag clusterTag = iConfig.getUntrackedParameter<edm::InputTag>("l1ClusterToken");
104  storeCaloClusters_ = true;
105  if (clusterTag.label() == std::string("") or clusterTag.label() == std::string("none"))
106  storeCaloClusters_ = false;
107 
108  if (clusterTag.instance() != std::string(""))
109  l1ClusterToken_ = consumes<l1t::CaloClusterBxCollection>(clusterTag);
110 
111  ecalLSB_ = iConfig.getUntrackedParameter<double>("ecalLSB", 0.5);
112  maxCaloTP_ = iConfig.getUntrackedParameter<unsigned int>("maxCaloTP", 5760);
113  maxL1Tower_ = iConfig.getUntrackedParameter<unsigned int>("maxL1Tower", 5760);
114  maxL1Cluster_ = iConfig.getUntrackedParameter<unsigned int>("maxL1Cluster", 5760);
115 
116  // set up output
117  tree_ = fs_->make<TTree>("L1CaloTowerTree", "L1CaloTowerTree");
118  tree_->Branch("CaloTP", "L1Analysis::L1AnalysisCaloTPDataFormat", &caloTPData_, 32000, 3);
119  tree_->Branch("L1CaloTower", "L1Analysis::L1AnalysisL1CaloTowerDataFormat", &l1CaloTowerData_, 32000, 3);
120 
121  if (storeCaloClusters_)
122  tree_->Branch("L1CaloCluster", "L1Analysis::L1AnalysisL1CaloClusterDataFormat", &l1CaloClusterData_, 32000, 3);
123 
127 }
128 
130  // do anything here that needs to be done at desctruction time
131  // (e.g. close files, deallocate resources etc.)
132 }
133 
134 //
135 // member functions
136 //
137 
138 // ------------ method called to for each event ------------
140  // do calo towers
141  caloTPData_->Reset();
142 
144  iSetup.get<CaloTPGRecord>().get(decoder);
145 
148 
149  iEvent.getByToken(ecalToken_, ecalTPs);
150  iEvent.getByToken(hcalToken_, hcalTPs);
151 
152  if (ecalTPs.isValid()) {
153  for (const auto& itr : *(ecalTPs.product())) {
154  short ieta = (short)itr.id().ieta();
155  // unsigned short absIeta = (unsigned short) abs(ieta);
156  // short sign = ieta/absIeta;
157 
158  unsigned short cal_iphi = (unsigned short)itr.id().iphi();
159  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
160  unsigned short compEt = itr.compressedEt();
161  double et = ecalLSB_ * compEt;
162  unsigned short fineGrain = (unsigned short)itr.fineGrain();
163 
164  if (compEt > 0) {
165  caloTPData_->ecalTPieta.push_back(ieta);
166  caloTPData_->ecalTPCaliphi.push_back(cal_iphi);
167  caloTPData_->ecalTPiphi.push_back(iphi);
168  caloTPData_->ecalTPet.push_back(et);
169  caloTPData_->ecalTPcompEt.push_back(compEt);
170  caloTPData_->ecalTPfineGrain.push_back(fineGrain);
171  caloTPData_->nECALTP++;
172  }
173  }
174 
175  } else {
176  edm::LogWarning("L1TNtuple") << "ECAL TPs not found, branch will not be filled";
177  }
178 
179  if (hcalTPs.isValid()) {
180  for (auto itr : (*hcalTPs.product())) {
181  int ver = itr.id().version();
182  short ieta = (short)itr.id().ieta();
183  unsigned short absIeta = (unsigned short)abs(ieta);
184  // short sign = ieta/absIeta;
185 
186  unsigned short cal_iphi = (unsigned short)itr.id().iphi();
187  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
188 
189  unsigned short compEt = itr.SOI_compressedEt();
190  double et = decoder->hcaletValue(itr.id(), itr.t0());
191 
192  unsigned short fineGrain = (unsigned short)itr.SOI_fineGrain();
193 
194  if (compEt > 0 && (absIeta < 29 || ver == 1)) {
195  caloTPData_->hcalTPieta.push_back(ieta);
196  caloTPData_->hcalTPCaliphi.push_back(cal_iphi);
197  caloTPData_->hcalTPiphi.push_back(iphi);
198  caloTPData_->hcalTPet.push_back(et);
199  caloTPData_->hcalTPcompEt.push_back(compEt);
200  caloTPData_->hcalTPfineGrain.push_back(fineGrain);
201  caloTPData_->nHCALTP++;
202  }
203  }
204 
205  } else {
206  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
207  }
208 
209  // do L1 towers
211 
213 
214  iEvent.getByToken(l1TowerToken_, l1Towers);
215 
216  if (l1Towers.isValid()) {
217  for (int ibx = l1Towers->getFirstBX(); ibx <= l1Towers->getLastBX(); ++ibx) {
218  for (auto itr = l1Towers->begin(ibx); itr != l1Towers->end(ibx); ++itr) {
219  if (itr->hwPt() <= 0)
220  continue;
221 
222  // l1CaloTowerData_->bx.push_back( ibx );
223  l1CaloTowerData_->et.push_back(itr->pt());
224  l1CaloTowerData_->eta.push_back(itr->eta());
225  l1CaloTowerData_->phi.push_back(itr->phi());
226  l1CaloTowerData_->iet.push_back(itr->hwPt());
227  l1CaloTowerData_->ieta.push_back(itr->hwEta());
228  l1CaloTowerData_->iphi.push_back(itr->hwPhi());
229  l1CaloTowerData_->iem.push_back(itr->hwEtEm());
230  l1CaloTowerData_->ihad.push_back(itr->hwEtHad());
231  l1CaloTowerData_->iratio.push_back(itr->hwEtRatio());
232  l1CaloTowerData_->iqual.push_back(itr->hwQual());
233 
235  }
236  }
237 
238  } else {
239  edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
240  }
241 
242  // do L1 clusters
243  if (storeCaloClusters_) {
245 
247 
249  iEvent.getByToken(l1ClusterToken_, l1Clusters);
250 
251  if (l1Clusters.isValid()) {
252  for (int ibx = l1Clusters->getFirstBX(); ibx <= l1Clusters->getLastBX(); ++ibx) {
253  for (auto itr = l1Clusters->begin(ibx); itr != l1Clusters->end(ibx); ++itr) {
254  if (itr->hwPt() <= 0)
255  continue;
256 
257  // l1CaloClusterData_->bx.push_back( ibx );
258  l1CaloClusterData_->et.push_back(itr->pt());
259  l1CaloClusterData_->eta.push_back(itr->eta());
260  l1CaloClusterData_->phi.push_back(itr->phi());
261  l1CaloClusterData_->iet.push_back(itr->hwPt());
262  l1CaloClusterData_->ieta.push_back(itr->hwEta());
263  l1CaloClusterData_->iphi.push_back(itr->hwPhi());
264  l1CaloClusterData_->iqual.push_back(itr->hwQual());
265 
267  }
268  }
269 
270  } else {
271  edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
272  }
273  }
274 
275  tree_->Fill();
276 }
277 
278 // ------------ method called once each job just before starting event loop ------------
280 
281 // ------------ method called once each job just after ending the event loop ------------
283 
284 //define this as a plug-in
L1CaloTowerTreeProducer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
L1Analysis::L1AnalysisCaloTPDataFormat * caloTPData_
int iEvent
Definition: GenABIO.cc:224
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Service< TFileService > fs_
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalToken_
bool isValid() const
Definition: HandleBase.h:70
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< l1t::CaloClusterBxCollection > l1ClusterToken_
L1Analysis::L1AnalysisL1CaloClusterDataFormat * l1CaloClusterData_
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalToken_
std::string const & label() const
Definition: InputTag.h:36
edm::EDGetTokenT< l1t::CaloTowerBxCollection > l1TowerToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
T get() const
Definition: EventSetup.h:88
Log< level::Warning, false > LogWarning
L1Analysis::L1AnalysisL1CaloTowerDataFormat * l1CaloTowerData_
std::string const & instance() const
Definition: InputTag.h:37