29 #include "FWCore/Framework/interface/Frameworkfwd.h"
30 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
31 #include "FWCore/Framework/interface/Event.h"
32 #include "FWCore/Framework/interface/MakerMacros.h"
33 #include "FWCore/ParameterSet/interface/ParameterSet.h"
34 #include "FWCore/ServiceRegistry/interface/Service.h"
35 #include "DataFormats/Math/interface/Error.h"
36 #include "DataFormats/Math/interface/Vector3D.h"
37 #include "DataFormats/Math/interface/Point3D.h"
38 #include "HGCal/DataFormats/interface/HGCalTBRecHitCollections.h"
39 #include "HGCal/DataFormats/interface/HGCalTBDetId.h"
40 #include "HGCal/DataFormats/interface/HGCalTBRecHit.h"
41 #include "HGCal/DataFormats/interface/HGCalTBTrackCollection.h"
42 #include "HGCal/DataFormats/interface/HGCalTBTrack.h"
43 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
44 #include "HGCal/Geometry/interface/HGCalTBTopology.h"
45 #include "CommonTools/UtilAlgos/interface/TFileService.h"
46 #include "HGCal/CondObjects/interface/HGCalElectronicsMap.h"
47 #include "HGCal/CondObjects/interface/HGCalCondObjectTextIO.h"
48 #include "HGCal/DataFormats/interface/HGCalTBElectronicsId.h"
49 #include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
63 static const double delta = 0.00001;
66 return sqrt(mean_sq - mean * mean);
72 edm::Service<TFileService>
fs;
73 class RecHitPlotter_HighGain_New :
public edm::one::EDAnalyzer<edm::one::SharedResources>
77 explicit RecHitPlotter_HighGain_New(
const edm::ParameterSet&);
78 ~RecHitPlotter_HighGain_New();
79 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
82 virtual void beginJob()
override;
83 void analyze(
const edm::Event& ,
const edm::EventSetup&)
override;
84 virtual void endJob()
override;
85 void InitTH2Poly(TH2Poly& poly);
88 edm::EDGetToken HGCalTBRecHitCollection_;
89 edm::EDGetToken HGCalTBTrackCollection_;
92 std::string mapfile_ =
"HGCal/CondObjects/data/map_FNAL_SB2_Layer16.txt";
97 std::vector<std::pair<double, double>> CellXY;
98 std::pair<double, double> CellCentreXY;
99 std::vector<std::pair<double, double>>::const_iterator it;
100 const static int NLAYERS = 1;
101 double Mean_SUM[128] = {0.};
102 double Mean_SQ_SUM[128] = {0.};
103 double Mean_PROD_SUM[128][128] = { {0.} };
104 double Diff_IJ_SUM[128][128] = { {0.} };
109 double Correlation = 0.;
110 double Covariance = 0.;
120 double ADC_Chan[128][9000];
122 TH1F* Sum_Cluster_ADC;
123 TH1F* Sum_Cluster_Max;
126 TProfile* SKI1_Ped_Event;
127 TProfile* SKI2_Ped_Event;
130 char name[50], title[50];
131 double ExtrapolateZ = 20.;
145 RecHitPlotter_HighGain_New::RecHitPlotter_HighGain_New(
const edm::ParameterSet& iConfig)
148 HGCalTBRecHitCollection_ = consumes<HGCalTBRecHitCollection>(iConfig.getParameter<edm::InputTag>(
"HGCALTBRECHITS"));
150 Covar_hist =
fs->make<TH2F>(
"Covar_hist",
"Covar_hist", 128, 0, 128, 128, 0, 128);
151 Correl_hist =
fs->make<TH2F>(
"Correl_hist",
"Correl_hist", 128, 0, 128, 128, 0, 128);
152 DiffIJ_hist =
fs->make<TH2F>(
"DiffIJ_hist",
"DiffIJ_hist", 128, 0, 128, 128, 0, 128);
153 CG_X =
fs->make<TH1F>(
"CG_X",
"CG X[cm]", 100, -5, 5);
154 CG_Y =
fs->make<TH1F>(
"CG_Y",
"CG Y[cm]", 100, -5, 5);
155 AllCells_Ped =
fs->make<TH1F>(
"AllCells_Ped",
"AllCells_Ped", 500, -250, 250);
156 AllCells_CM =
fs->make<TH1F>(
"AllCells_CM",
"AllCells_CM", 500, -250, 250);
157 SKI1_Ped_Event =
fs->make<TProfile>(
"SKI1_Ped_Event",
"Profile per event of pedestal for SKI1", 5000, 1, 5000, 0, 400);
158 SKI2_Ped_Event =
fs->make<TProfile>(
"SKI2_Ped_Event",
"Profile per event of pedestal for SKI2", 5000, 1, 5000, 0, 400);
159 Sum_Cluster_ADC =
fs->make<TH1F>(
"Sum_Cluster_ADC",
"Sum_Cluster_ADC", 1000, -4000., 4000.);
160 Sum_Cluster_Max =
fs->make<TH1F>(
"Sum_Cluster_Max",
"Sum_Cluster_Max", 1000, -4000., 4000.);
161 for(
int nlayers = 0; nlayers <
MAXLAYERS; nlayers++) {
162 sprintf(name,
"FullLayer_RecHits_Layer%i_Summed", nlayers + 1);
163 sprintf(title,
"Sum of RecHits Layer%i Summed over the cells", nlayers + 1);
164 h_RecHit_layer_summed[nlayers] =
fs->make<TH1F>(name, title, 4000, -2000., 2000.);
165 h_RecHit_layer_summed[nlayers]->GetXaxis()->SetTitle(
"RecHits[GeV]");
172 RecHitPlotter_HighGain_New::~RecHitPlotter_HighGain_New()
185 void RecHitPlotter_HighGain_New::InitTH2Poly(TH2Poly& poly)
190 for(
int iv = -7; iv < 8; iv++) {
191 for(
int iu = -7; iu < 8; iu++) {
192 if(!IsCellValid.iu_iv_valid(NLAYERS, Sensor_Iu, Sensor_Iv, iu, iv, sensorsize))
continue;
193 CellXY = TheCell.GetCellCoordinatesForPlots(NLAYERS, Sensor_Iu, Sensor_Iv, iu, iv, sensorsize);
194 assert(CellXY.size() == 4 || CellXY.size() == 6);
195 unsigned int iVertex = 0;
196 for(it = CellXY.begin(); it != CellXY.end(); it++) {
197 HexX[iVertex] = it->first;
198 HexY[iVertex] = it->second;
202 poly.AddBin(CellXY.size(), HexX, HexY);
210 RecHitPlotter_HighGain_New::analyze(
const edm::Event& event,
const edm::EventSetup& setup)
216 edm::Handle<HGCalTBRecHitCollection> Rechits;
217 event.getByToken(HGCalTBRecHitCollection_, Rechits);
218 edm::Handle<HGCalTBRecHitCollection> Rechits1;
219 event.getByToken(HGCalTBRecHitCollection_, Rechits1);
221 double Average_Pedestal_Per_Event1_Full = 0, Average_Pedestal_Per_Event1_Half = 0, Average_Pedestal_Per_Event2_Full = 0, Average_Pedestal_Per_Event2_Half = 0;
222 int Cell_counter1_Full = 0, Cell_counter2_Full = 0, Cell_counter1_Half = 0, Cell_counter2_Half = 0;
223 double iux_Max = 0., iyy_Max = 0.;
226 int Sum_Cluster_Tmp = 0;
234 for(
auto RecHit1 : *Rechits1) {
235 CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((RecHit1.id()).layer(), (RecHit1.id()).sensorIU(), (RecHit1.id()).sensorIV(), (RecHit1.id()).iu(), (RecHit1.id()).iv(), sensorsize);
236 double iux = (CellCentreXY.first < 0 ) ? (CellCentreXY.first +
delta) : (CellCentreXY.first -
delta) ;
237 double iyy = (CellCentreXY.second < 0 ) ? (CellCentreXY.second +
delta) : (CellCentreXY.second -
delta);
238 if((RecHit1.energyHigh() > ADC_TMP)) {
240 ADC_TMP = RecHit1.energyHigh();
244 if(RecHit1.energyHigh() > 20.)
continue;
246 if(((RecHit1.id()).cellType() == 0) || ((RecHit1.id()).cellType() == 5)) {
248 if(( iyy >= -0.25 )) {
249 Cell_counter1_Full++;
250 Average_Pedestal_Per_Event1_Full += RecHit1.energyHigh();
254 Cell_counter2_Full++;
255 Average_Pedestal_Per_Event2_Full += RecHit1.energyHigh();
266 if(((RecHit1.id()).cellType() == 2) || ((RecHit1.id()).cellType() == 3) || ((RecHit1.id()).cellType() == 4) ) {
268 if(((iyy >= -0.25 ))) {
269 Cell_counter1_Half++;
270 Average_Pedestal_Per_Event1_Half += RecHit1.energyHigh();
272 if(((iyy <= -0.5))) {
273 Cell_counter2_Half++;
274 Average_Pedestal_Per_Event2_Half += RecHit1.energyHigh();
282 if(((RecHit1.id()).cellType() == 0)) {
284 if((iux <= -0.25 && iux >= -3.25) && (iyy <= -0.25 && iyy >= -5.25 ) && (RecHit1.id()).cellType() == 0) {
285 Cell_counter1_Full++;
286 Average_Pedestal_Per_Event1_Full += RecHit1.energyHigh();
289 if((iux >= -0.25 && iux <= 3.25) && (iyy <= -0.25 && iyy >= -5.25 ) && (RecHit1.id()).cellType() == 0) {
290 Cell_counter2_Full++;
291 Average_Pedestal_Per_Event2_Full += RecHit1.energyHigh();
295 if(((RecHit1.id()).cellType() == 2) || ((RecHit1.id()).cellType() == 3) || ((RecHit1.id()).cellType() == 4) ) {
297 if((iux <= 0.25 && iyy >= -0.25 ) || (iux < -0.5) ) {
298 Cell_counter1_Half++;
299 Average_Pedestal_Per_Event1_Half += RecHit1.energyHigh();
301 if((iux >= 0.25 && iyy <= -0.5) || (iux >= 0.5) ) {
302 Cell_counter2_Half++;
303 Average_Pedestal_Per_Event2_Half += RecHit1.energyHigh();
314 Sum_Cluster_Max->Fill(ADC_TMP);
319 int evId =
event.id().event() - 1;
320 int iLayer = (evId%2400)/150;
321 h_RecHit_layer[iLayer] =
fs->make<TH2Poly>();
322 sprintf(name,
"FullLayer_ADC%i_Layer%i_Event%i", 0, iLayer + 1, evId);
323 sprintf(title,
"ADC counts in Layer%i",iLayer + 1);
324 h_RecHit_layer[iLayer]->SetName(name);
325 h_RecHit_layer[iLayer]->SetTitle(title);
326 InitTH2Poly(*h_RecHit_layer[iLayer]);
328 for(
auto RecHit : *Rechits) {
329 if(!IsCellValid.iu_iv_valid((RecHit.id()).layer(), (RecHit.id()).sensorIU(), (RecHit.id()).sensorIV(), (RecHit.id()).iu(), (RecHit.id()).iv(), sensorsize))
continue;
330 int n_layer = (RecHit.id()).layer();
331 CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((RecHit.id()).layer(), (RecHit.id()).sensorIU(), (RecHit.id()).sensorIV(), (RecHit.id()).iu(), (RecHit.id()).iv(), sensorsize);
332 double iux = (CellCentreXY.first < 0 ) ? (CellCentreXY.first +
delta) : (CellCentreXY.first -
delta) ;
333 double iyy = (CellCentreXY.second < 0 ) ? (CellCentreXY.second +
delta) : (CellCentreXY.second -
delta);
334 uint32_t EID = essource_.emap_.detId2eid(RecHit.id());
336 AllCells_Ped->Fill(RecHit.energyHigh());
337 if(RecHit.energyHigh() > 55) cout<<endl<<
" Energy= "<<RecHit.energyHigh()<<
" u= "<<iux<<
" v= "<<iyy<<
" event number= "<<
event.id().event()<<endl;
340 h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, RecHit.energyHigh());
342 if(((RecHit.id()).cellType() == 0 ) || ((RecHit.id()).cellType() == 5) ) {
343 if((iyy >= -0.25 ) ) {
345 if((RecHit.id()).cellType() == 0){
346 h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, (RecHit.energyHigh() - (Average_Pedestal_Per_Event1_Full / (Cell_counter1_Full))) );
349 Sum_Cluster_Tmp += (RecHit.energyHigh());
351 h_RecHit_layer_summed[n_layer - 1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event1_Full / (Cell_counter1_Full)));
353 AllCells_CM->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event1_Full / (Cell_counter1_Full)));
358 }
else if(( iyy < -0.50 )) {
360 if((RecHit.id()).cellType() == 0) h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, (RecHit.energyHigh() - (Average_Pedestal_Per_Event2_Full / (Cell_counter2_Full))) );
361 Sum_Cluster_Tmp += (RecHit.energyHigh());
364 h_RecHit_layer_summed[n_layer - 1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event2_Full / (Cell_counter2_Full)));
366 AllCells_CM->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event2_Full / (Cell_counter2_Full)));
373 if((RecHit.id()).cellType() == 1 ) {
374 if(!
PED) h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, RecHit.energyHigh());
376 AllCells_CM->Fill(RecHit.energyHigh());
379 if(((RecHit.id()).cellType() != 5) && ((RecHit.id()).cellType() != 1) && ((RecHit.id()).cellType() != 0)) {
380 if((iyy >= -0.25 ) ) {
382 h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, RecHit.energyHigh() - (Average_Pedestal_Per_Event1_Half / Cell_counter1_Half) );
387 AllCells_CM->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event1_Half / (Cell_counter1_Half)));
390 if(( iyy < -0.50 )) {
392 h_RecHit_layer[n_layer - 1]->Fill(iux , iyy, RecHit.energyHigh() - (Average_Pedestal_Per_Event2_Half / Cell_counter2_Half) );
395 h_RecHit_layer_summed[n_layer - 1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event2_Half / Cell_counter2_Half));
397 AllCells_CM->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event2_Half / (Cell_counter2_Half)));
405 if(Sum_Cluster_Tmp > 2. ) Sum_Cluster_ADC->Fill(Sum_Cluster_Tmp);
413 RecHitPlotter_HighGain_New::beginJob()
416 edm::FileInPath fip(mapfile_);
417 if (!io.load(fip.fullPath(), essource_.emap_)) {
418 throw cms::Exception(
"Unable to load electronics map");
420 ofs.open(
"ShowerMax_X_Y_Ped_20532.txt", std::ofstream::out);
425 RecHitPlotter_HighGain_New::endJob()
434 RecHitPlotter_HighGain_New::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
438 edm::ParameterSetDescription desc;
440 descriptions.addDefault(desc);
DEFINE_FWK_MODULE(Pedestals)
edm::Service< TFileService > fs
double Return_RMS(double mean_sq, double mean)
provides the conversion between electronics Id to DetId