CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HCALGPUAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ComparisonPlots/HCALGPUAnalyzer
4 // Class: HCALGPUAnalyzer
5 //
13 //
14 // Original Author: Mariarosaria D'Alfonso
15 // Created: Mon, 17 Dec 2018 16:22:58 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <string>
22 #include <map>
23 #include <iostream>
24 using namespace std;
25 
26 // user include files
29 
32 
38 
42 
45 
47 
48 #include "TH2F.h"
49 
50 //
51 // class declaration
52 //
53 
54 class HCALGPUAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
55 public:
56  explicit HCALGPUAnalyzer(const edm::ParameterSet &);
57  ~HCALGPUAnalyzer() override = default;
58 
59  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
60 
61 private:
62  void beginJob() override;
63  void analyze(const edm::Event &, const edm::EventSetup &) override;
64  void endJob() override;
65 
66  // ----------member data ---------------------------
67  // void ClearVariables();
68 
69  // some variables for storing information
70  double Method0Energy, Method0EnergyGPU;
71  double RecHitEnergy, RecHitEnergyGPU;
72  double RecHitTime, RecHitTimeGPU;
73  double iEta, iEtaGPU;
74  double iPhi, iPhiGPU;
76 
78  TH2F *hEnergy_2dM0;
79  TH2F *hTime_2dMahi;
80 
81  TH2F *Unmatched;
82  TH2F *Matched;
83  TH1F *hEnergy_cpu;
84  TH1F *hEnergy_gpu;
89  TH1F *hTime_cpu;
90  TH1F *hTime_gpu;
91 
92  // create the output file
94  // create the token to retrieve hit information
97 };
98 
99 //
100 // constants, enums and typedefs
101 //
102 
103 //
104 // static data member definitions
105 //
106 
107 //
108 // constructors and destructor
109 //
111  usesResource("TFileService");
112 
113  hRhToken = consumes<HBHERecHitCollection>(iConfig.getUntrackedParameter<string>("HBHERecHits", "hbheprereco"));
114  hRhTokenGPU = consumes<HBHERecHitCollection>(
115  iConfig.getUntrackedParameter<string>("HBHERecHits", "hcalCPURecHitsProducer:recHitsLegacyHBHE"));
116 
117  //
118 
119  hEnergy_2dM0 = FileService->make<TH2F>("hEnergy_2dM0", "hEnergy_2dM0", 1000, 0., 100., 1000, 0., 100.);
120  hEnergy_2dM0->GetXaxis()->SetTitle("Cpu M0 Energy");
121  hEnergy_2dM0->GetYaxis()->SetTitle("GPU M0 Energy");
122 
123  hEnergy_2dMahi = FileService->make<TH2F>("hEnergy_2dMahi", "hEnergy_2dMahi", 1000, 0., 100., 1000, 0., 100.);
124  hEnergy_2dMahi->GetXaxis()->SetTitle("CPU Energy");
125  hEnergy_2dMahi->GetYaxis()->SetTitle("GPU Energy");
126 
127  hTime_2dMahi = FileService->make<TH2F>("hTime_2dMahi", "hTime_2dMahi", 250, -12.5, 12.5, 250, -12.5, 12.5);
128  hTime_2dMahi->GetXaxis()->SetTitle("Mahi Time CPU");
129  hTime_2dMahi->GetYaxis()->SetTitle("Mahi Time GPU");
130 
131  //
132 
133  hEnergyM0_cpu = FileService->make<TH1F>("hEnergyM0_cpu", "hEnergyM0_cpu", 100, 0., 100.);
134  hEnergyM0_cpu->GetXaxis()->SetTitle("CPU Energy");
135 
136  hEnergy_cpu = FileService->make<TH1F>("hEnergy_cpu", "hEnergy_cpu", 50, 0., 50.);
137  hEnergy_cpu->GetXaxis()->SetTitle("CPU Energy");
138 
139  hEnergy_gpu = FileService->make<TH1F>("hEnergy_gpu", "hEnergy_gpu", 50, 0., 50.);
140  hEnergy_gpu->GetXaxis()->SetTitle("GPU Energy");
141 
142  //
143 
144  hEnergy_cpugpu = FileService->make<TH1F>("hEnergy_cpugpu", "hEnergy_cpugpu", 500, -2.5, 2.5);
145  hEnergy_cpugpu->GetXaxis()->SetTitle("GPU Energy - CPU Energy [GeV]");
146  hEnergy_cpugpu->GetYaxis()->SetTitle("# RecHits");
147 
148  hEnergy_cpugpu_rel =
149  FileService->make<TH1F>("hEnergy_cpugpu_rel", "hEnergy_cpugpu_rel ( E > 0.005 GeV)", 500, -2.5, 2.5);
150  hEnergy_cpugpu_rel->GetXaxis()->SetTitle("(GPU Energy - CPU Energy) / CPU energy");
151  hEnergy_cpugpu_rel->GetYaxis()->SetTitle("# RecHits");
152 
153  //
154 
155  hTime_cpu = FileService->make<TH1F>("hTime_cpu", "hTime_cpu", 50, -25., 25.);
156  hTime_cpu->GetXaxis()->SetTitle("CPU Time");
157 
158  hTime_gpu = FileService->make<TH1F>("hTime_gpu", "hTime_gpu", 50, -25., 25.);
159  hTime_gpu->GetXaxis()->SetTitle("GPU Time");
160 
161  Unmatched = FileService->make<TH2F>("Unmatched", "Unmatched (eta,phi)", 100, -50., 50., 85, 0., 85.);
162  Matched = FileService->make<TH2F>("Matched", "Matched (eta,phi)", 100, -50., 50., 85, 0., 85.);
163 
164  //now do what ever initialization is needed
165 }
166 
167 //
168 // member functions
169 //
170 
171 // ------------ method called for each event ------------
173  using namespace edm;
174 
175  // Read events
177  iEvent.getByToken(hRhToken, hRecHits);
178 
179  Handle<HBHERecHitCollection> hRecHitsGPU;
180  iEvent.getByToken(hRhTokenGPU, hRecHitsGPU);
181 
182  // Loop over all rechits in one event
183  for (int i = 0; i < (int)hRecHits->size(); i++) {
184  // get ID information for the reconstructed hit
185  HcalDetId detID_rh = (*hRecHits)[i].id().rawId();
186 
187  // ID information can get us detector coordinates
188  depth = (*hRecHits)[i].id().depth();
189  iEta = detID_rh.ieta();
190  iPhi = detID_rh.iphi();
191 
192  // get some variables
193  Method0Energy = (*hRecHits)[i].eraw();
194  RecHitEnergy = (*hRecHits)[i].energy();
195  RecHitTime = (*hRecHits)[i].time();
196 
197  hEnergy_cpu->Fill(RecHitEnergy);
198  hTime_cpu->Fill(RecHitTime);
199 
200  /*
201  cout << "Run " << i << ": ";
202  cout << "Method0Energy: " << Method0Energy;
203  cout << "RecHitEnergy: " << RecHitEnergy;
204  cout << "depth: " << depth;
205  cout << "iEta: " << iEta;
206  cout << "iPhi: " << iPhi;
207  cout << "RecHitTime" << RecHitTime;
208  */
209  }
210 
211  for (int i = 0; i < (int)hRecHitsGPU->size(); i++) {
212  // get ID information for the reconstructed hit
213  HcalDetId detID_rh = (*hRecHitsGPU)[i].id().rawId();
214 
215  // ID information can get us detector coordinates
216  depthGPU = (*hRecHitsGPU)[i].id().depth();
217  iEtaGPU = detID_rh.ieta();
218  iPhiGPU = detID_rh.iphi();
219 
220  // get some variables
221  Method0EnergyGPU = (*hRecHitsGPU)[i].eraw();
222  RecHitEnergyGPU = (*hRecHitsGPU)[i].energy();
223  RecHitTimeGPU = (*hRecHitsGPU)[i].time();
224 
225  hEnergy_gpu->Fill(RecHitEnergyGPU);
226  hTime_gpu->Fill(RecHitTimeGPU);
227 
228  /*
229  cout << "Run " << i << ": ";
230  cout << "Method0Energy: " << Method0EnergyGPU;
231  cout << "RecHitEnergy: " << RecHitEnergyGPU;
232  cout << "depth: " << depthGPU;
233  cout << "iEta: " << iEtaGPU;
234  cout << "iPhi: " << iPhiGPU;
235  cout << "RecHitTime" << RecHitTimeGPU;
236  */
237  }
238 
239  // Loop over all rechits in one event
240  for (int i = 0; i < (int)hRecHits->size(); i++) {
241  HcalDetId detID_rh = (*hRecHits)[i].id().rawId();
242 
243  bool unmatched = true;
244  // cout << "--------------------------------------------------------" << endl;
245 
246  for (int j = 0; j < (int)hRecHitsGPU->size(); j++) {
247  HcalDetId detID_gpu = (*hRecHitsGPU)[j].id().rawId();
248 
249  if ((detID_rh == detID_gpu)) {
250  /*
251  cout << "Mtime(cpu)" << (*hRecHits)[i].time() << endl;
252  cout << " Mtime(gpu)" << (*hRecHitsGPU)[j].time() << endl;
253 
254  cout << "M0E(cpu)" << (*hRecHits)[i].eraw() << endl;
255  cout << " M0E(gpu)" << (*hRecHitsGPU)[j].eraw() << endl;
256  */
257 
258  auto relValue = ((*hRecHitsGPU)[j].energy() - (*hRecHits)[i].energy()) / (*hRecHits)[i].energy();
259 
260  hEnergy_2dM0->Fill((*hRecHits)[i].eraw(), (*hRecHitsGPU)[j].eraw());
261  hEnergy_2dMahi->Fill((*hRecHits)[i].energy(), (*hRecHitsGPU)[j].energy());
262  hEnergy_cpugpu->Fill((*hRecHitsGPU)[j].energy() - (*hRecHits)[i].energy());
263  if ((*hRecHits)[i].energy() > 0.005)
264  hEnergy_cpugpu_rel->Fill(relValue);
265  hTime_2dMahi->Fill((*hRecHits)[i].time(), (*hRecHitsGPU)[j].time());
266 
267  /*
268  if((relValue < - 0.9) and ((*hRecHits)[i].energy()>0.005)) {
269  cout << "----------------------------------"<< endl;
270  cout << " detID = " << detID_rh.rawId() << endl;
271  cout << "ME(cpu)" << (*hRecHits)[i].energy() << endl;
272  cout << " ME(gpu)" << (*hRecHitsGPU)[j].energy() << endl;
273  }
274  */
275 
276  Matched->Fill(detID_rh.ieta(), detID_rh.iphi());
277 
278  unmatched = false;
279  }
280  }
281 
283 
284  if (unmatched) {
285  Unmatched->Fill(detID_rh.ieta(), detID_rh.iphi());
286  // cout << " recHit not matched =" << detID_rh << " E(raw)=" << (*hRecHits)[i].eraw() << " E=" << (*hRecHits)[i].energy() << endl;
287  }
288  }
289 }
290 
291 // ------------ method called once each job just before starting event loop ------------
293 
294 // ------------ method called once each job just after ending the event loop ------------
296 
297 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
299  //The following says we do not know what parameters are allowed so do no validation
300  // Please change this to state exactly what you do use, even if it is no parameters
302  desc.setUnknown();
303  descriptions.addDefault(desc);
304 }
305 
306 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
void endJob() override
void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
edm::EDGetTokenT< HBHERecHitCollection > hRhToken
HCALGPUAnalyzer(const edm::ParameterSet &)
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
edm::EDGetTokenT< HBHERecHitCollection > hRhTokenGPU
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::Service< TFileService > FileService
void beginJob() override