CMS 3D CMS Logo

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
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
HCALGPUAnalyzer::hEnergy_cpugpu_rel
TH1F * hEnergy_cpugpu_rel
Definition: HCALGPUAnalyzer.cc:86
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
HCALGPUAnalyzer::depthGPU
int depthGPU
Definition: HCALGPUAnalyzer.cc:75
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
HCALGPUAnalyzer::hEnergy_2dM0
TH2F * hEnergy_2dM0
Definition: HCALGPUAnalyzer.cc:78
HCALGPUAnalyzer::HCALGPUAnalyzer
HCALGPUAnalyzer(const edm::ParameterSet &)
Definition: HCALGPUAnalyzer.cc:110
HCALGPUAnalyzer::hRhToken
edm::EDGetTokenT< HBHERecHitCollection > hRhToken
Definition: HCALGPUAnalyzer.cc:95
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HCALGPUAnalyzer::FileService
edm::Service< TFileService > FileService
Definition: HCALGPUAnalyzer.cc:93
protons_cff.time
time
Definition: protons_cff.py:35
HCALGPUAnalyzer::hTime_cpu
TH1F * hTime_cpu
Definition: HCALGPUAnalyzer.cc:89
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
HCALGPUAnalyzer::RecHitTimeGPU
double RecHitTimeGPU
Definition: HCALGPUAnalyzer.cc:72
edm::Handle
Definition: AssociativeIterator.h:50
HCALGPUAnalyzer::hTime_gpu
TH1F * hTime_gpu
Definition: HCALGPUAnalyzer.cc:90
HCALGPUAnalyzer::hEnergyM0_gpu
TH1F * hEnergyM0_gpu
Definition: HCALGPUAnalyzer.cc:88
HCALGPUAnalyzer
Definition: HCALGPUAnalyzer.cc:54
HCALGPUAnalyzer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HCALGPUAnalyzer.cc:298
HcalSimParameterMap.h
MakerMacros.h
HCALGPUAnalyzer::hEnergy_2dMahi
TH2F * hEnergy_2dMahi
Definition: HCALGPUAnalyzer.cc:77
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HCALGPUAnalyzer::iPhiGPU
double iPhiGPU
Definition: HCALGPUAnalyzer.cc:74
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
HCALGPUAnalyzer::hTime_2dMahi
TH2F * hTime_2dMahi
Definition: HCALGPUAnalyzer.cc:79
HCALGPUAnalyzer::Unmatched
TH2F * Unmatched
Definition: HCALGPUAnalyzer.cc:81
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HCALGPUAnalyzer::hEnergy_gpu
TH1F * hEnergy_gpu
Definition: HCALGPUAnalyzer.cc:84
TFileService.h
HCALGPUAnalyzer::hEnergyM0_cpu
TH1F * hEnergyM0_cpu
Definition: HCALGPUAnalyzer.cc:87
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
HCALGPUAnalyzer::endJob
void endJob() override
Definition: HCALGPUAnalyzer.cc:295
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
HCALGPUAnalyzer::iEtaGPU
double iEtaGPU
Definition: HCALGPUAnalyzer.cc:73
HcalDetId.h
PCaloHit.h
HcalDetId
Definition: HcalDetId.h:12
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
HCALGPUAnalyzer::hEnergy_cpu
TH1F * hEnergy_cpu
Definition: HCALGPUAnalyzer.cc:83
iEvent
int iEvent
Definition: GenABIO.cc:224
HCALGPUAnalyzer::hEnergy_cpugpu
TH1F * hEnergy_cpugpu
Definition: HCALGPUAnalyzer.cc:85
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:58
InputTag.h
HBHERecHit.h
HCALGPUAnalyzer::hRhTokenGPU
edm::EDGetTokenT< HBHERecHitCollection > hRhTokenGPU
Definition: HCALGPUAnalyzer.cc:96
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
reco::Matched
Definition: TrackInfoEnum.h:16
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Frameworkfwd.h
HcalRecHitCollections.h
PCaloHitContainer.h
HCALGPUAnalyzer::Matched
TH2F * Matched
Definition: HCALGPUAnalyzer.cc:82
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
ParameterSet.h
HCALGPUAnalyzer::RecHitEnergyGPU
double RecHitEnergyGPU
Definition: HCALGPUAnalyzer.cc:71
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
HCALGPUAnalyzer::Method0EnergyGPU
double Method0EnergyGPU
Definition: HCALGPUAnalyzer.cc:70
HCALGPUAnalyzer::beginJob
void beginJob() override
Definition: HCALGPUAnalyzer.cc:292
HCALGPUAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HCALGPUAnalyzer.cc:172