CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
21 // system include files
22 #include <memory>
23 
24 // framework
32 
33 // data formats
39 
40 // cond formats
45 
46 // ROOT output stuff
49 #include "TTree.h"
50 
54 
57 
60 
61 
62 //
63 // class declaration
64 //
65 
67 public:
70 
71 
72 private:
73  virtual void beginJob(void) ;
74  virtual void analyze(const edm::Event&, const edm::EventSetup&);
75  virtual void endJob();
76 
77 public:
78 
82 
83 private:
84 
85  unsigned maxCaloTP_;
86  unsigned maxL1Tower_;
87  unsigned maxL1Cluster_;
88 
89  // output file
91 
92  // tree
93  TTree * tree_;
94 
96  unsigned long long ecalScaleCacheID_;
97  unsigned long long hcalScaleCacheID_;
98 
99  // EDM input tags
104 
105 };
106 
107 
108 
110 {
111 
112  ecalToken_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("ecalToken"));
113  hcalToken_ = consumes<HcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("hcalToken"));
114  l1TowerToken_ = consumes<l1t::CaloTowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("l1TowerToken"));
115 
116  edm::InputTag clusterTag = iConfig.getUntrackedParameter<edm::InputTag>("l1ClusterToken");
117  if (clusterTag.instance() != std::string(""))
118  l1ClusterToken_ = consumes<l1t::CaloClusterBxCollection>(clusterTag);
119 
120  maxCaloTP_ = iConfig.getUntrackedParameter<unsigned int>("maxCaloTP", 5760);
121  maxL1Tower_ = iConfig.getUntrackedParameter<unsigned int>("maxL1Tower", 5760);
122  maxL1Cluster_ = iConfig.getUntrackedParameter<unsigned int>("maxL1Cluster", 5760);
123 
124  // set up output
125  tree_=fs_->make<TTree>("L1CaloTowerTree", "L1CaloTowerTree");
126  tree_->Branch("CaloTP", "L1Analysis::L1AnalysisCaloTPDataFormat", &caloTPData_, 32000, 3);
127  tree_->Branch("L1CaloTower", "L1Analysis::L1AnalysisL1CaloTowerDataFormat", &l1CaloTowerData_, 32000, 3);
128  tree_->Branch("L1CaloCluster", "L1Analysis::L1AnalysisL1CaloClusterDataFormat", &l1CaloClusterData_, 32000, 3);
129 
133 
134 }
135 
136 
138 {
139 
140  // do anything here that needs to be done at desctruction time
141  // (e.g. close files, deallocate resources etc.)
142 
143 }
144 
145 
146 //
147 // member functions
148 //
149 
150 // ------------ method called to for each event ------------
151 void
153 {
154 
155  // do calo towers
156  caloTPData_->Reset();
157 
159  if( iSetup.get< L1CaloEcalScaleRcd > ().cacheIdentifier() != ecalScaleCacheID_ ) {
160  iSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
161  ecalScaleCacheID_ = iSetup.get< L1CaloEcalScaleRcd > ().cacheIdentifier();
162  }
163 
165  iSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
166  hcalScaleCacheID_ = iSetup.get< L1CaloHcalScaleRcd > ().cacheIdentifier();
167 
170 
171  iEvent.getByToken(ecalToken_, ecalTPs);
172  iEvent.getByToken(hcalToken_, hcalTPs);
173 
174  if (ecalTPs.isValid()){
175 
176  for ( auto itr : *(ecalTPs.product()) ) {
177 
178  short ieta = (short) itr.id().ieta();
179  unsigned short absIeta = (unsigned short) abs(ieta);
180  short sign = ieta/absIeta;
181 
182  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
183  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
184  unsigned short compEt = itr.compressedEt();
185  double et = 0.;
186  if (ecalScale.isValid()) et = ecalScale->et( compEt, absIeta, sign );
187 
188  unsigned short fineGrain = (unsigned short) itr.fineGrain();
189 
190  if (compEt > 0) {
191  caloTPData_->ecalTPieta.push_back( ieta );
192  caloTPData_->ecalTPCaliphi.push_back( cal_iphi );
193  caloTPData_->ecalTPiphi.push_back( iphi );
194  caloTPData_->ecalTPet.push_back( et );
195  caloTPData_->ecalTPcompEt.push_back( compEt );
196  caloTPData_->ecalTPfineGrain.push_back( fineGrain );
197  caloTPData_->nECALTP++;
198  }
199  }
200 
201  }
202  else {
203  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
204  }
205 
206 
207  if (hcalTPs.isValid()) {
208 
209  for ( auto itr : (*hcalTPs.product()) ) {
210 
211  short ieta = (short) itr.id().ieta();
212  unsigned short absIeta = (unsigned short) abs(ieta);
213  short sign = ieta/absIeta;
214 
215  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
216  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
217  if (absIeta >= 29) { // special treatment for HF
218  iphi = iphi/4;
219  }
220 
221  unsigned short compEt = itr.SOI_compressedEt();
222  double et = 0.;
223  if (hcalScale.isValid()) et = hcalScale->et( compEt, absIeta, sign );
224 
225  unsigned short fineGrain = (unsigned short) itr.SOI_fineGrain();
226 
227  if (compEt > 0) {
228  caloTPData_->hcalTPieta.push_back( ieta );
229  caloTPData_->hcalTPCaliphi.push_back( cal_iphi );
230  caloTPData_->hcalTPiphi.push_back( iphi );
231  caloTPData_->hcalTPet.push_back( et );
232  caloTPData_->hcalTPcompEt.push_back( compEt );
233  caloTPData_->hcalTPfineGrain.push_back( fineGrain );
234  caloTPData_->nHCALTP++;
235  }
236  }
237 
238  }
239  else {
240  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
241  }
242 
243  // do L1 towers
245 
247 
248  iEvent.getByToken(l1TowerToken_, l1Towers);
249 
250  if (l1Towers.isValid()){
251 
252  for ( int ibx=l1Towers->getFirstBX(); ibx<=l1Towers->getLastBX(); ++ibx) {
253 
254  for ( auto itr = l1Towers->begin(ibx); itr !=l1Towers->end(ibx); ++itr ) {
255 
256  if (itr->hwPt()<=0) continue;
257 
258  // l1CaloTowerData_->bx.push_back( ibx );
259  l1CaloTowerData_->et.push_back( itr->pt() );
260  l1CaloTowerData_->eta.push_back( itr->eta() );
261  l1CaloTowerData_->phi.push_back( itr->phi() );
262  l1CaloTowerData_->iet.push_back( itr->hwPt() );
263  l1CaloTowerData_->ieta.push_back( itr->hwEta() );
264  l1CaloTowerData_->iphi.push_back( itr->hwPhi() );
265  l1CaloTowerData_->iem.push_back( itr->hwEtEm() );
266  l1CaloTowerData_->ihad.push_back( itr->hwEtHad() );
267  l1CaloTowerData_->iratio.push_back( itr->hwEtRatio() );
268  l1CaloTowerData_->iqual.push_back( itr->hwQual() );
269 
271 
272  }
273 
274  }
275 
276  }
277  else {
278  edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
279  }
280 
281 
282  // do L1 clusters
284 
286 
288  iEvent.getByToken(l1ClusterToken_, l1Clusters);
289 
290  if (l1Clusters.isValid()){
291 
292  for ( int ibx=l1Clusters->getFirstBX(); ibx<=l1Clusters->getLastBX(); ++ibx) {
293 
294  for ( auto itr = l1Clusters->begin(ibx); itr !=l1Clusters->end(ibx); ++itr ) {
295 
296  if (itr->hwPt()<=0) continue;
297 
298  // l1CaloClusterData_->bx.push_back( ibx );
299  l1CaloClusterData_->et.push_back( itr->pt() );
300  l1CaloClusterData_->eta.push_back( itr->eta() );
301  l1CaloClusterData_->phi.push_back( itr->phi() );
302  l1CaloClusterData_->iet.push_back( itr->hwPt() );
303  l1CaloClusterData_->ieta.push_back( itr->hwEta() );
304  l1CaloClusterData_->iphi.push_back( itr->hwPhi() );
305  l1CaloClusterData_->iqual.push_back( itr->hwQual() );
306 
308 
309  }
310 
311  }
312 
313  }
314  else {
315  edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
316  }
317 
318 
319 
320  tree_->Fill();
321 
322 }
323 
324 // ------------ method called once each job just before starting event loop ------------
325 void
327 {
328 }
329 
330 // ------------ method called once each job just after ending the event loop ------------
331 void
333 }
334 
335 //define this as a plug-in
unsigned long long cacheIdentifier() const
L1CaloTowerTreeProducer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double sign(double x)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
L1Analysis::L1AnalysisCaloTPDataFormat * caloTPData_
int iEvent
Definition: GenABIO.cc:230
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:75
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< l1t::CaloClusterBxCollection > l1ClusterToken_
unsigned long long hcalScaleCacheID_
const T & get() const
Definition: EventSetup.h:56
virtual void analyze(const edm::Event &, const edm::EventSetup &)
L1Analysis::L1AnalysisL1CaloClusterDataFormat * l1CaloClusterData_
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalToken_
edm::EDGetTokenT< l1t::CaloTowerBxCollection > l1TowerToken_
bool isUninitialized() const
Definition: EDGetToken.h:73
bool isValid() const
Definition: ESHandle.h:47
L1Analysis::L1AnalysisL1CaloTowerDataFormat * l1CaloTowerData_
std::string const & instance() const
Definition: InputTag.h:37
unsigned long long ecalScaleCacheID_
scales