26 #include "FWCore/Framework/interface/Frameworkfwd.h"
27 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
28 #include "FWCore/Framework/interface/Event.h"
29 #include "FWCore/Framework/interface/MakerMacros.h"
30 #include "FWCore/ParameterSet/interface/ParameterSet.h"
31 #include "FWCore/ServiceRegistry/interface/Service.h"
32 #include "HGCal/DataFormats/interface/HGCalTBRecHitCollections.h"
33 #include "HGCal/DataFormats/interface/HGCalTBDetId.h"
34 #include "HGCal/DataFormats/interface/HGCalTBRecHit.h"
35 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
36 #include "HGCal/Geometry/interface/HGCalTBTopology.h"
37 #include "CommonTools/UtilAlgos/interface/TFileService.h"
49 static const double delta = 0.00001;
51 class RecHitPlotter :
public edm::one::EDAnalyzer<edm::one::SharedResources>
55 explicit RecHitPlotter(
const edm::ParameterSet&);
57 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
60 virtual void beginJob()
override;
61 void analyze(
const edm::Event& ,
const edm::EventSetup&)
override;
62 virtual void endJob()
override;
65 edm::EDGetToken HGCalTBRecHitCollection_;
69 std::vector<std::pair<double, double>> CellXY;
70 std::pair<double, double> CellCentreXY;
71 std::vector<std::pair<double, double>>::const_iterator it;
72 const static int NLAYERS = 2;
73 TH2Poly *h_RecHit_layer[NLAYERS];
74 TH1F *h_RecHit_layer_summed[NLAYERS];
75 TH2Poly *h_RecHit_layer_Occupancy[NLAYERS];
76 const static int cellx = 15;
77 const static int celly = 15;
80 TH1F *h_RecHit_layer_cell[NLAYERS][cellx][celly];
81 char name[50], title[50];
95 RecHitPlotter::RecHitPlotter(
const edm::ParameterSet& iConfig)
98 usesResource(
"TFileService");
99 edm::Service<TFileService>
fs;
100 HGCalTBRecHitCollection_ = consumes<HGCalTBRecHitCollection>(iConfig.getParameter<edm::InputTag>(
"HGCALTBRECHITS"));
103 const int HalfHexVertices = 4;
104 double HalfHexX[HalfHexVertices] = {0.};
105 double HalfHexY[HalfHexVertices] = {0.};
106 const int FullHexVertices = 6;
107 double FullHexX[FullHexVertices] = {0.};
108 double FullHexY[FullHexVertices] = {0.};
110 for(
int nlayers = 0; nlayers < NLAYERS; nlayers++) {
111 sprintf(name,
"FullLayer_RecHits_Layer%i", nlayers + 1);
112 sprintf(title,
"Sum of RecHits Layer%i", nlayers + 1);
113 h_RecHit_layer[nlayers] =
fs->make<TH2Poly>();
114 h_RecHit_layer[nlayers]->SetName(name);
115 h_RecHit_layer[nlayers]->SetTitle(title);
116 sprintf(name,
"FullLayer_RecHits_Layer%i_Summed", nlayers + 1);
117 sprintf(title,
"Sum of RecHits Layer%i Summed over the cells", nlayers + 1);
118 h_RecHit_layer_summed[nlayers] =
fs->make<TH1F>(name, title, 200, -100., 100.);
119 h_RecHit_layer_summed[nlayers]->GetXaxis()->SetTitle(
"RecHits[GeV]");
120 sprintf(name,
"FullLayer_Occupancy_Layer%i", nlayers + 1);
121 sprintf(title,
"Sum of Occupancy Layer%i", nlayers + 1);
122 h_RecHit_layer_Occupancy[nlayers] =
fs->make<TH2Poly>();
123 h_RecHit_layer_Occupancy[nlayers]->SetName(name);
124 h_RecHit_layer_Occupancy[nlayers]->SetTitle(title);
125 for(
int iv = -7; iv < 8; iv++) {
126 for(
int iu = -7; iu < 8; iu++) {
127 if(!IsCellValid.iu_iv_valid(nlayers, Sensor_Iu, Sensor_Iv, iu, iv, sensorsize))
continue;
129 sprintf(name,
"Cell_RecHits_u_%i_v_%i_Layer%i", iu, iv, nlayers + 1);
130 sprintf(title,
"RecHits for Cell_u_%i_v_%i Layer%i", iu, iv, nlayers + 1);
131 h_RecHit_layer_cell[nlayers][iu + 7][iv + 7] =
fs->make<TH1F>(name, title, 200, -100., 100.);
132 h_RecHit_layer_cell[nlayers][iu + 7][iv + 7]->GetXaxis()->SetTitle(
"RecHits[GeV]");
133 CellXY = TheCell.GetCellCoordinatesForPlots(nlayers, Sensor_Iu, Sensor_Iv, iu, iv, sensorsize);
134 int NumberOfCellVertices = CellXY.size();
136 if(NumberOfCellVertices == 4) {
137 for(it = CellXY.begin(); it != CellXY.end(); it++) {
138 HalfHexX[iii] = it->first;
139 HalfHexY[iii++] = it->second;
142 h_RecHit_layer[nlayers]->AddBin(NumberOfCellVertices, HalfHexX, HalfHexY);
143 h_RecHit_layer_Occupancy[nlayers]->AddBin(NumberOfCellVertices, HalfHexX, HalfHexY);
144 }
else if(NumberOfCellVertices == 6) {
146 for(it = CellXY.begin(); it != CellXY.end(); it++) {
147 FullHexX[iii] = it->first;
148 FullHexY[iii++] = it->second;
150 h_RecHit_layer[nlayers]->AddBin(NumberOfCellVertices, FullHexX, FullHexY);
151 h_RecHit_layer_Occupancy[nlayers]->AddBin(NumberOfCellVertices, FullHexX, FullHexY);
162 RecHitPlotter::~RecHitPlotter()
177 RecHitPlotter::analyze(
const edm::Event& event,
const edm::EventSetup& setup)
183 edm::Handle<HGCalTBRecHitCollection> Rechits;
184 event.getByToken(HGCalTBRecHitCollection_, Rechits);
185 edm::Handle<HGCalTBRecHitCollection> Rechits1;
186 event.getByToken(HGCalTBRecHitCollection_, Rechits1);
188 double Average_Pedestal_Per_Event1_Full = 0;
189 int Cell_counter1_Full = 0;
190 for(
auto RecHit1 : *Rechits1) {
191 Average_Pedestal_Per_Event1_Full+=RecHit1.energyHigh();
192 Cell_counter1_Full++;
195 for(
auto RecHit : *Rechits) {
196 if(!IsCellValid.iu_iv_valid((RecHit.id()).layer(), (RecHit.id()).sensorIU(), (RecHit.id()).sensorIV(), (RecHit.id()).iu(), (RecHit.id()).iv(), sensorsize))
continue;
197 int n_layer = (RecHit.id()).layer();
198 int n_cell_type = (RecHit.id()).cellType();
199 double n_cell_area = IsCellValid.Cell_Area(n_cell_type);
201 CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((RecHit.id()).layer(), (RecHit.id()).sensorIU(), (RecHit.id()).sensorIV(), (RecHit.id()).iu(), (RecHit.id()).iv(), sensorsize);
202 double iux = (CellCentreXY.first < 0 ) ? (CellCentreXY.first +
delta) : (CellCentreXY.first -
delta) ;
203 double iyy = (CellCentreXY.second < 0 ) ? (CellCentreXY.second +
delta) : (CellCentreXY.second -
delta);
204 h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, RecHit.energyHigh());
205 h_RecHit_layer_summed[n_layer - 1]->Fill(RecHit.energyHigh());
207 if(RecHit.energyHigh() > 5) h_RecHit_layer_Occupancy[n_layer - 1]->Fill(iux , iyy, 1. / n_cell_area);
209 h_RecHit_layer_cell[n_layer - 1][7 + (RecHit.id()).iu()][7 + (RecHit.id()).iv()]->Fill(RecHit.energyHigh() - Average_Pedestal_Per_Event1_Full/Cell_counter1_Full);
218 RecHitPlotter::beginJob()
225 RecHitPlotter::endJob()
231 RecHitPlotter::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
235 edm::ParameterSetDescription desc;
237 descriptions.addDefault(desc);
DEFINE_FWK_MODULE(Pedestals)
edm::Service< TFileService > fs