CMS 3D CMS Logo

TPGCheck.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TPGCheck
4 // Class: TPGCheck
5 //
13 //
14 // Original Author: Muriel Cerutti
15 // Created: Thu Oct 26 10:47:17 CEST 2006
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // user include files
27 
30 
31 #include <string>
32 #include <vector>
33 
34 #include "TFile.h"
35 #include "TH1I.h"
36 
37 using namespace edm;
38 using namespace std;
39 
40 //
41 // class declaration
42 //
43 
44 class TPGCheck : public edm::EDAnalyzer {
45 public:
46  explicit TPGCheck(const edm::ParameterSet &);
47  ~TPGCheck() override;
48 
49 private:
50  void beginJob() override;
51  void analyze(const edm::Event &, const edm::EventSetup &) override;
52  void endJob() override;
53 
54  // ----------member data ---------------------------
55  TH1I *ecal_et_[2];
56  TH1I *ecal_tt_[2];
57  TH1I *ecal_fgvb_[2];
58 
59  TFile *histFile_;
62  std::vector<std::string> ecal_parts_;
63  // fix for consumes
65 };
66 
67 //
68 // constructors and destructor
69 //
71  // now do what ever initialization is needed
72 
73  ecal_parts_.push_back("Barrel");
74  ecal_parts_.push_back("Endcap");
75 
76  histFile_ = new TFile("histos.root", "RECREATE");
77  for (unsigned int i = 0; i < 2; ++i) {
78  // Energy
79  char t[30];
80  sprintf(t, "%s_energy", ecal_parts_[i].c_str());
81  ecal_et_[i] = new TH1I(t, "Et", 255, 0, 255);
82 
83  // Trigger Tower flag
84  char titleTTF[30];
85  sprintf(titleTTF, "%s_ttf", ecal_parts_[i].c_str());
86  ecal_tt_[i] = new TH1I(titleTTF, "TTF", 10, 0, 10);
87 
88  // Fain Grain
89  char titleFG[30];
90  sprintf(titleFG, "%s_fgvb", ecal_parts_[i].c_str());
91  ecal_fgvb_[i] = new TH1I(titleFG, "FGVB", 10, 0, 10);
92  }
93 
94  label_ = iConfig.getParameter<std::string>("Label");
95  producer_ = iConfig.getParameter<std::string>("Producer");
96  ecal_tp_token_ =
97  consumes<EcalTrigPrimDigiCollection>(edm::InputTag(label_, producer_));
98 }
99 
101 
102  // do anything here that needs to be done at desctruction time
103  // (e.g. close files, deallocate resources etc.)
104 
105  histFile_->Write();
106  histFile_->Close();
107 }
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called to for each event ------------
115  const edm::EventSetup &iSetup) {
116 
117  // Get input
119  iEvent.getByToken(ecal_tp_token_, tp);
120  for (unsigned int i = 0; i < tp.product()->size(); i++) {
121  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
122  int subdet = d.id().subDet() - 1;
123  // for endcap, regroup double TP-s that are generated for the 2 interior
124  // rings
125  if (subdet == 0) {
126  ecal_et_[subdet]->Fill(d.compressedEt());
127  } else {
128  if (d.id().ietaAbs() == 27 || d.id().ietaAbs() == 28) {
129  if (i % 2)
130  ecal_et_[subdet]->Fill(d.compressedEt() * 2.);
131  } else
132  ecal_et_[subdet]->Fill(d.compressedEt());
133  }
134  ecal_tt_[subdet]->Fill(d.ttFlag());
135  ecal_fgvb_[subdet]->Fill(d.fineGrain());
136  }
137 }
138 
139 // ------------ method called once each job just before starting event loop
140 // ------------
142 
143 // ------------ method called once each job just after ending the event loop
144 // ------------
146  for (unsigned int i = 0; i < 2; ++i) {
147  ecal_et_[i]->Write();
148  ecal_tt_[i]->Write();
149  ecal_fgvb_[i]->Write();
150  }
151 }
152 
153 // define this as a plug-in
T getParameter(std::string const &) const
std::string label_
Definition: TPGCheck.cc:60
TFile * histFile_
Definition: TPGCheck.cc:59
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: TPGCheck.cc:114
void beginJob()
Definition: Breakpoints.cc:14
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecal_tp_token_
Definition: TPGCheck.cc:64
int compressedEt() const
get the encoded/compressed Et of interesting sample
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginJob() override
Definition: TPGCheck.cc:141
~TPGCheck() override
Definition: TPGCheck.cc:100
int ietaAbs() const
get the absolute value of the tower ieta
const EcalTrigTowerDetId & id() const
T const * product() const
Definition: Handle.h:74
TPGCheck(const edm::ParameterSet &)
Definition: TPGCheck.cc:70
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
void endJob() override
Definition: TPGCheck.cc:145
HLT enums.
size_type size() const
bool fineGrain() const
get the fine-grain bit of interesting sample
std::vector< std::string > ecal_parts_
Definition: TPGCheck.cc:62
std::string producer_
Definition: TPGCheck.cc:61
int ttFlag() const
get the Trigger tower Flag of interesting sample