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") << "ECAL TPs not found, branch will not be filled";
204  }
205 
206 
207  if (hcalTPs.isValid()) {
208 
209  for ( auto itr : (*hcalTPs.product()) ) {
210 
211  int ver = itr.id().version();
212  short ieta = (short) itr.id().ieta();
213  unsigned short absIeta = (unsigned short) abs(ieta);
214  short sign = ieta/absIeta;
215 
216  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
217  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
218  if (absIeta >= 29) { // special treatment for HF
219  iphi = iphi/4;
220  }
221 
222  unsigned short compEt = itr.SOI_compressedEt();
223  double et = 0.;
224  if (hcalScale.isValid()) et = hcalScale->et( compEt, absIeta, sign );
225 
226  unsigned short fineGrain = (unsigned short) itr.SOI_fineGrain();
227 
228  if (compEt > 0 && (absIeta<29 || ver==1)) {
229  caloTPData_->hcalTPieta.push_back( ieta );
230  caloTPData_->hcalTPCaliphi.push_back( cal_iphi );
231  caloTPData_->hcalTPiphi.push_back( iphi );
232  caloTPData_->hcalTPet.push_back( et );
233  caloTPData_->hcalTPcompEt.push_back( compEt );
234  caloTPData_->hcalTPfineGrain.push_back( fineGrain );
235  caloTPData_->nHCALTP++;
236  }
237  }
238 
239  }
240  else {
241  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
242  }
243 
244  // do L1 towers
246 
248 
249  iEvent.getByToken(l1TowerToken_, l1Towers);
250 
251  if (l1Towers.isValid()){
252 
253  for ( int ibx=l1Towers->getFirstBX(); ibx<=l1Towers->getLastBX(); ++ibx) {
254 
255  for ( auto itr = l1Towers->begin(ibx); itr !=l1Towers->end(ibx); ++itr ) {
256 
257  if (itr->hwPt()<=0) continue;
258 
259  // l1CaloTowerData_->bx.push_back( ibx );
260  l1CaloTowerData_->et.push_back( itr->pt() );
261  l1CaloTowerData_->eta.push_back( itr->eta() );
262  l1CaloTowerData_->phi.push_back( itr->phi() );
263  l1CaloTowerData_->iet.push_back( itr->hwPt() );
264  l1CaloTowerData_->ieta.push_back( itr->hwEta() );
265  l1CaloTowerData_->iphi.push_back( itr->hwPhi() );
266  l1CaloTowerData_->iem.push_back( itr->hwEtEm() );
267  l1CaloTowerData_->ihad.push_back( itr->hwEtHad() );
268  l1CaloTowerData_->iratio.push_back( itr->hwEtRatio() );
269  l1CaloTowerData_->iqual.push_back( itr->hwQual() );
270 
272 
273  }
274 
275  }
276 
277  }
278  else {
279  edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
280  }
281 
282 
283  // do L1 clusters
285 
287 
289  iEvent.getByToken(l1ClusterToken_, l1Clusters);
290 
291  if (l1Clusters.isValid()){
292 
293  for ( int ibx=l1Clusters->getFirstBX(); ibx<=l1Clusters->getLastBX(); ++ibx) {
294 
295  for ( auto itr = l1Clusters->begin(ibx); itr !=l1Clusters->end(ibx); ++itr ) {
296 
297  if (itr->hwPt()<=0) continue;
298 
299  // l1CaloClusterData_->bx.push_back( ibx );
300  l1CaloClusterData_->et.push_back( itr->pt() );
301  l1CaloClusterData_->eta.push_back( itr->eta() );
302  l1CaloClusterData_->phi.push_back( itr->phi() );
303  l1CaloClusterData_->iet.push_back( itr->hwPt() );
304  l1CaloClusterData_->ieta.push_back( itr->hwEta() );
305  l1CaloClusterData_->iphi.push_back( itr->hwPhi() );
306  l1CaloClusterData_->iqual.push_back( itr->hwQual() );
307 
309 
310  }
311 
312  }
313 
314  }
315  else {
316  edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
317  }
318 
319 
320 
321  tree_->Fill();
322 
323 }
324 
325 // ------------ method called once each job just before starting event loop ------------
326 void
328 {
329 }
330 
331 // ------------ method called once each job just after ending the event loop ------------
332 void
334 }
335 
336 //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