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
43 
44 // ROOT output stuff
47 #include "TTree.h"
48 
52 
55 
58 
59 
60 //
61 // class declaration
62 //
63 
65 public:
68 
69 
70 private:
71  virtual void beginJob(void) ;
72  virtual void analyze(const edm::Event&, const edm::EventSetup&);
73  virtual void endJob();
74 
75 public:
76 
80 
81 private:
82 
83  double ecalLSB_;
84  unsigned maxCaloTP_;
85  unsigned maxL1Tower_;
86  unsigned maxL1Cluster_;
87 
88  // output file
90 
91  // tree
92  TTree * tree_;
93 
94  // EDM input tags
99 
100 };
101 
102 
103 
105 {
106 
107  ecalToken_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("ecalToken"));
108  hcalToken_ = consumes<HcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("hcalToken"));
109  l1TowerToken_ = consumes<l1t::CaloTowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("l1TowerToken"));
110 
111  edm::InputTag clusterTag = iConfig.getUntrackedParameter<edm::InputTag>("l1ClusterToken");
112  if (clusterTag.instance() != std::string(""))
113  l1ClusterToken_ = consumes<l1t::CaloClusterBxCollection>(clusterTag);
114 
115  ecalLSB_ = iConfig.getUntrackedParameter<double>("ecalLSB", 0.5);
116  maxCaloTP_ = iConfig.getUntrackedParameter<unsigned int>("maxCaloTP", 5760);
117  maxL1Tower_ = iConfig.getUntrackedParameter<unsigned int>("maxL1Tower", 5760);
118  maxL1Cluster_ = iConfig.getUntrackedParameter<unsigned int>("maxL1Cluster", 5760);
119 
120  // set up output
121  tree_=fs_->make<TTree>("L1CaloTowerTree", "L1CaloTowerTree");
122  tree_->Branch("CaloTP", "L1Analysis::L1AnalysisCaloTPDataFormat", &caloTPData_, 32000, 3);
123  tree_->Branch("L1CaloTower", "L1Analysis::L1AnalysisL1CaloTowerDataFormat", &l1CaloTowerData_, 32000, 3);
124  tree_->Branch("L1CaloCluster", "L1Analysis::L1AnalysisL1CaloClusterDataFormat", &l1CaloClusterData_, 32000, 3);
125 
129 
130 }
131 
132 
134 {
135 
136  // do anything here that needs to be done at desctruction time
137  // (e.g. close files, deallocate resources etc.)
138 
139 }
140 
141 
142 //
143 // member functions
144 //
145 
146 // ------------ method called to for each event ------------
147 void
149 {
150 
151  // do calo towers
152  caloTPData_->Reset();
153 
155  iSetup.get<CaloTPGRecord>().get(decoder);
156 
159 
160  iEvent.getByToken(ecalToken_, ecalTPs);
161  iEvent.getByToken(hcalToken_, hcalTPs);
162 
163  if (ecalTPs.isValid()){
164 
165  for ( auto itr : *(ecalTPs.product()) ) {
166 
167  short ieta = (short) itr.id().ieta();
168  // unsigned short absIeta = (unsigned short) abs(ieta);
169  // short sign = ieta/absIeta;
170 
171  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
172  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
173  unsigned short compEt = itr.compressedEt();
174  double et = ecalLSB_ * compEt;
175  unsigned short fineGrain = (unsigned short) itr.fineGrain();
176 
177  if (compEt > 0) {
178  caloTPData_->ecalTPieta.push_back( ieta );
179  caloTPData_->ecalTPCaliphi.push_back( cal_iphi );
180  caloTPData_->ecalTPiphi.push_back( iphi );
181  caloTPData_->ecalTPet.push_back( et );
182  caloTPData_->ecalTPcompEt.push_back( compEt );
183  caloTPData_->ecalTPfineGrain.push_back( fineGrain );
184  caloTPData_->nECALTP++;
185  }
186  }
187 
188  }
189  else {
190  edm::LogWarning("L1TNtuple") << "ECAL TPs not found, branch will not be filled";
191  }
192 
193 
194  if (hcalTPs.isValid()) {
195 
196  for ( auto itr : (*hcalTPs.product()) ) {
197 
198  int ver = itr.id().version();
199  short ieta = (short) itr.id().ieta();
200  unsigned short absIeta = (unsigned short) abs(ieta);
201  // short sign = ieta/absIeta;
202 
203  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
204  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
205 
206  unsigned short compEt = itr.SOI_compressedEt();
207  double et = decoder->hcaletValue(itr.id(), itr.t0());
208 
209  unsigned short fineGrain = (unsigned short) itr.SOI_fineGrain();
210 
211  if (compEt > 0 && (absIeta<29 || ver==1)) {
212  caloTPData_->hcalTPieta.push_back( ieta );
213  caloTPData_->hcalTPCaliphi.push_back( cal_iphi );
214  caloTPData_->hcalTPiphi.push_back( iphi );
215  caloTPData_->hcalTPet.push_back( et );
216  caloTPData_->hcalTPcompEt.push_back( compEt );
217  caloTPData_->hcalTPfineGrain.push_back( fineGrain );
218  caloTPData_->nHCALTP++;
219  }
220  }
221 
222  }
223  else {
224  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
225  }
226 
227  // do L1 towers
229 
231 
232  iEvent.getByToken(l1TowerToken_, l1Towers);
233 
234  if (l1Towers.isValid()){
235 
236  for ( int ibx=l1Towers->getFirstBX(); ibx<=l1Towers->getLastBX(); ++ibx) {
237 
238  for ( auto itr = l1Towers->begin(ibx); itr !=l1Towers->end(ibx); ++itr ) {
239 
240  if (itr->hwPt()<=0) continue;
241 
242  // l1CaloTowerData_->bx.push_back( ibx );
243  l1CaloTowerData_->et.push_back( itr->pt() );
244  l1CaloTowerData_->eta.push_back( itr->eta() );
245  l1CaloTowerData_->phi.push_back( itr->phi() );
246  l1CaloTowerData_->iet.push_back( itr->hwPt() );
247  l1CaloTowerData_->ieta.push_back( itr->hwEta() );
248  l1CaloTowerData_->iphi.push_back( itr->hwPhi() );
249  l1CaloTowerData_->iem.push_back( itr->hwEtEm() );
250  l1CaloTowerData_->ihad.push_back( itr->hwEtHad() );
251  l1CaloTowerData_->iratio.push_back( itr->hwEtRatio() );
252  l1CaloTowerData_->iqual.push_back( itr->hwQual() );
253 
255 
256  }
257 
258  }
259 
260  }
261  else {
262  edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
263  }
264 
265 
266  // do L1 clusters
268 
270 
272  iEvent.getByToken(l1ClusterToken_, l1Clusters);
273 
274  if (l1Clusters.isValid()){
275 
276  for ( int ibx=l1Clusters->getFirstBX(); ibx<=l1Clusters->getLastBX(); ++ibx) {
277 
278  for ( auto itr = l1Clusters->begin(ibx); itr !=l1Clusters->end(ibx); ++itr ) {
279 
280  if (itr->hwPt()<=0) continue;
281 
282  // l1CaloClusterData_->bx.push_back( ibx );
283  l1CaloClusterData_->et.push_back( itr->pt() );
284  l1CaloClusterData_->eta.push_back( itr->eta() );
285  l1CaloClusterData_->phi.push_back( itr->phi() );
286  l1CaloClusterData_->iet.push_back( itr->hwPt() );
287  l1CaloClusterData_->ieta.push_back( itr->hwEta() );
288  l1CaloClusterData_->iphi.push_back( itr->hwPhi() );
289  l1CaloClusterData_->iqual.push_back( itr->hwQual() );
290 
292 
293  }
294 
295  }
296 
297  }
298  else {
299  edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
300  }
301 
302 
303 
304  tree_->Fill();
305 
306 }
307 
308 // ------------ method called once each job just before starting event loop ------------
309 void
311 {
312 }
313 
314 // ------------ method called once each job just after ending the event loop ------------
315 void
317 }
318 
319 //define this as a plug-in
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
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_
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
L1Analysis::L1AnalysisL1CaloTowerDataFormat * l1CaloTowerData_
std::string const & instance() const
Definition: InputTag.h:37