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 
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:
67  ~L1CaloTowerTreeProducer() override;
68 
69 
70 private:
71  void beginJob(void) override ;
72  void analyze(const edm::Event&, const edm::EventSetup&) override;
73  void endJob() override;
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 
101 };
102 
103 
104 
106 {
107 
108  ecalToken_ = consumes<EcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("ecalToken"));
109  hcalToken_ = consumes<HcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("hcalToken"));
110  l1TowerToken_ = consumes<l1t::CaloTowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("l1TowerToken"));
111 
112  edm::InputTag clusterTag = iConfig.getUntrackedParameter<edm::InputTag>("l1ClusterToken");
113  storeCaloClusters_=true;
114  if ( clusterTag.label() == std::string("") or clusterTag.label() == std::string("none")) storeCaloClusters_=false;
115 
116  if (clusterTag.instance() != std::string(""))
117  l1ClusterToken_ = consumes<l1t::CaloClusterBxCollection>(clusterTag);
118 
119  ecalLSB_ = iConfig.getUntrackedParameter<double>("ecalLSB", 0.5);
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 
129  if (storeCaloClusters_)
130  tree_->Branch("L1CaloCluster", "L1Analysis::L1AnalysisL1CaloClusterDataFormat", &l1CaloClusterData_, 32000, 3);
131 
135 
136 }
137 
138 
140 {
141 
142  // do anything here that needs to be done at desctruction time
143  // (e.g. close files, deallocate resources etc.)
144 
145 }
146 
147 
148 //
149 // member functions
150 //
151 
152 // ------------ method called to for each event ------------
153 void
155 {
156 
157  // do calo towers
158  caloTPData_->Reset();
159 
161  iSetup.get<CaloTPGRecord>().get(decoder);
162 
165 
166  iEvent.getByToken(ecalToken_, ecalTPs);
167  iEvent.getByToken(hcalToken_, hcalTPs);
168 
169  if (ecalTPs.isValid()){
170 
171  for ( auto itr : *(ecalTPs.product()) ) {
172 
173  short ieta = (short) itr.id().ieta();
174  // unsigned short absIeta = (unsigned short) abs(ieta);
175  // short sign = ieta/absIeta;
176 
177  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
178  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
179  unsigned short compEt = itr.compressedEt();
180  double et = ecalLSB_ * compEt;
181  unsigned short fineGrain = (unsigned short) itr.fineGrain();
182 
183  if (compEt > 0) {
184  caloTPData_->ecalTPieta.push_back( ieta );
185  caloTPData_->ecalTPCaliphi.push_back( cal_iphi );
186  caloTPData_->ecalTPiphi.push_back( iphi );
187  caloTPData_->ecalTPet.push_back( et );
188  caloTPData_->ecalTPcompEt.push_back( compEt );
189  caloTPData_->ecalTPfineGrain.push_back( fineGrain );
190  caloTPData_->nECALTP++;
191  }
192  }
193 
194  }
195  else {
196  edm::LogWarning("L1TNtuple") << "ECAL TPs not found, branch will not be filled";
197  }
198 
199 
200  if (hcalTPs.isValid()) {
201 
202  for ( auto itr : (*hcalTPs.product()) ) {
203 
204  int ver = itr.id().version();
205  short ieta = (short) itr.id().ieta();
206  unsigned short absIeta = (unsigned short) abs(ieta);
207  // short sign = ieta/absIeta;
208 
209  unsigned short cal_iphi = (unsigned short) itr.id().iphi();
210  unsigned short iphi = (72 + 18 - cal_iphi) % 72;
211 
212  unsigned short compEt = itr.SOI_compressedEt();
213  double et = decoder->hcaletValue(itr.id(), itr.t0());
214 
215  unsigned short fineGrain = (unsigned short) itr.SOI_fineGrain();
216 
217  if (compEt > 0 && (absIeta<29 || ver==1)) {
218  caloTPData_->hcalTPieta.push_back( ieta );
219  caloTPData_->hcalTPCaliphi.push_back( cal_iphi );
220  caloTPData_->hcalTPiphi.push_back( iphi );
221  caloTPData_->hcalTPet.push_back( et );
222  caloTPData_->hcalTPcompEt.push_back( compEt );
223  caloTPData_->hcalTPfineGrain.push_back( fineGrain );
224  caloTPData_->nHCALTP++;
225  }
226  }
227 
228  }
229  else {
230  edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
231  }
232 
233  // do L1 towers
235 
237 
238  iEvent.getByToken(l1TowerToken_, l1Towers);
239 
240  if (l1Towers.isValid()){
241 
242  for ( int ibx=l1Towers->getFirstBX(); ibx<=l1Towers->getLastBX(); ++ibx) {
243 
244  for ( auto itr = l1Towers->begin(ibx); itr !=l1Towers->end(ibx); ++itr ) {
245 
246  if (itr->hwPt()<=0) continue;
247 
248  // l1CaloTowerData_->bx.push_back( ibx );
249  l1CaloTowerData_->et.push_back( itr->pt() );
250  l1CaloTowerData_->eta.push_back( itr->eta() );
251  l1CaloTowerData_->phi.push_back( itr->phi() );
252  l1CaloTowerData_->iet.push_back( itr->hwPt() );
253  l1CaloTowerData_->ieta.push_back( itr->hwEta() );
254  l1CaloTowerData_->iphi.push_back( itr->hwPhi() );
255  l1CaloTowerData_->iem.push_back( itr->hwEtEm() );
256  l1CaloTowerData_->ihad.push_back( itr->hwEtHad() );
257  l1CaloTowerData_->iratio.push_back( itr->hwEtRatio() );
258  l1CaloTowerData_->iqual.push_back( itr->hwQual() );
259 
261 
262  }
263 
264  }
265 
266  }
267  else {
268  edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
269  }
270 
271 
272  // do L1 clusters
273  if (storeCaloClusters_){
275 
277 
279  iEvent.getByToken(l1ClusterToken_, l1Clusters);
280 
281  if (l1Clusters.isValid()){
282 
283  for ( int ibx=l1Clusters->getFirstBX(); ibx<=l1Clusters->getLastBX(); ++ibx) {
284 
285  for ( auto itr = l1Clusters->begin(ibx); itr !=l1Clusters->end(ibx); ++itr ) {
286 
287  if (itr->hwPt()<=0) continue;
288 
289  // l1CaloClusterData_->bx.push_back( ibx );
290  l1CaloClusterData_->et.push_back( itr->pt() );
291  l1CaloClusterData_->eta.push_back( itr->eta() );
292  l1CaloClusterData_->phi.push_back( itr->phi() );
293  l1CaloClusterData_->iet.push_back( itr->hwPt() );
294  l1CaloClusterData_->ieta.push_back( itr->hwEta() );
295  l1CaloClusterData_->iphi.push_back( itr->hwPhi() );
296  l1CaloClusterData_->iqual.push_back( itr->hwQual() );
297 
299 
300  }
301 
302  }
303 
304  }
305  else {
306  edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
307  }
308  }
309 
310 
311  tree_->Fill();
312 
313 }
314 
315 // ------------ method called once each job just before starting event loop ------------
316 void
318 {
319 }
320 
321 // ------------ method called once each job just after ending the event loop ------------
322 void
324 }
325 
326 //define this as a plug-in
const_iterator end(int bx) const
L1CaloTowerTreeProducer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
L1Analysis::L1AnalysisCaloTPDataFormat * caloTPData_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
edm::Service< TFileService > fs_
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalToken_
bool isValid() const
Definition: HandleBase.h:74
int getFirstBX() const
T const * product() const
Definition: Handle.h:74
edm::EDGetTokenT< l1t::CaloClusterBxCollection > l1ClusterToken_
L1Analysis::L1AnalysisL1CaloClusterDataFormat * l1CaloClusterData_
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalToken_
et
define resolution functions of each parameter
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:71
int getLastBX() const
bool isUninitialized() const
Definition: EDGetToken.h:70
virtual double hcaletValue(const int &ieta, const int &iphi, const int &version, const int &compressedValue) const =0
L1Analysis::L1AnalysisL1CaloTowerDataFormat * l1CaloTowerData_
const_iterator begin(int bx) const
std::string const & instance() const
Definition: InputTag.h:37