HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RecHitPlotter_HighGain_Correlation_CM.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HGCal/RecHitPlotter_HighGain_Correlation_CM
4 // Class: RecHitPlotter_HighGain_Correlation_CM
5 //
6 /**\class RecHitPlotter_HighGain_Correlation_CM RecHitPlotter_HighGain_Correlation_CM.cc HGCal/RecHitPlotter_HighGain_Correlation_CM/plugins/RecHitPlotter_HighGain_Correlation_CM.cc
7 
8  Description: [one line class summary]
9 
10  Implementation:
11  [Notes on implementation]
12 */
13 //
14 // Original Author: Rajdeep Mohan Chatterjee
15 // Created: Mon, 15 Feb 2016 09:47:43 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 #include "TH2Poly.h"
24 #include "TProfile.h"
25 #include "TH1F.h"
26 #include "TH2F.h"
27 #include "TF1.h"
28 // user include files
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 "HGCal/DataFormats/interface/HGCalTBRecHitCollections.h"
36 #include "HGCal/DataFormats/interface/HGCalTBDetId.h"
37 #include "HGCal/DataFormats/interface/HGCalTBRecHit.h"
38 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
39 #include "HGCal/Geometry/interface/HGCalTBTopology.h"
40 #include "CommonTools/UtilAlgos/interface/TFileService.h"
41 #include "HGCal/CondObjects/interface/HGCalElectronicsMap.h"
42 #include "HGCal/CondObjects/interface/HGCalCondObjectTextIO.h"
43 #include "HGCal/DataFormats/interface/HGCalTBElectronicsId.h"
44 #include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
45 using namespace std;
46 //
47 // class declaration
48 //
49 
50 // If the analyzer does not use TFileService, please remove
51 // the template argument to the base class so the class inherits
52 // from edm::one::EDAnalyzer<> and also remove the line from
53 // constructor "usesResource("TFileService");"
54 // This will improve performance in multithreaded jobs.
55 
56 static const double delta = 0.00001;//Add/subtract delta = 0.00001 to x,y of a cell centre so the TH2Poly::Fill doesnt have a problem at the edges where the centre of a half-hex cell passes through the sennsor boundary line.
57 bool doCommonMode_CM = 1;
58 double return_RMS_CM(double mean_sq, double mean){
59  return sqrt(mean_sq - mean*mean);
60  }
61 
62 class RecHitPlotter_HighGain_Correlation_CM : public edm::one::EDAnalyzer<edm::one::SharedResources>
63 {
64 
65 public:
66  explicit RecHitPlotter_HighGain_Correlation_CM(const edm::ParameterSet&);
67  ~RecHitPlotter_HighGain_Correlation_CM();
68  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
69 
70 private:
71  virtual void beginJob() override;
72  void analyze(const edm::Event& , const edm::EventSetup&) override;
73  virtual void endJob() override;
74 
75  // ----------member data ---------------------------
76  edm::EDGetToken HGCalTBRecHitCollection_;
77  HGCalTBTopology IsCellValid;
78  HGCalTBCellVertices TheCell;
79  std::string mapfile_ = "HGCal/CondObjects/data/map_FNAL_SB2_Layer16.txt";
80  struct {
81  HGCalElectronicsMap emap_;
82  } essource_;
83  int sensorsize = 128;// The geometry for a 256 cell sensor hasnt been implemted yet. Need a picture to do this.
84  std::vector<std::pair<double, double>> CellXY;
85  std::pair<double, double> CellCentreXY;
86  std::vector<std::pair<double, double>>::const_iterator it;
87 //TH2D *Covar_hist = new TH2D("Covar_hist","Covar_hist",nphistar_bins-1,phistar_var,nphistar_bins-1,phistar_var);
88 //TH2D *Correl_hist = new TH2D("Correl_hist","Correl_hist",nphistar_bins-1,phistar_var,nphistar_bins-1,phistar_var);
89 
90  const static int NLAYERS = 128;
91  TH2Poly *h_RecHit_layer[128];
92  const static int cellx = 15;
93  const static int celly = 15;
94  int Sensor_Iu = 0;
95  int Sensor_Iv = 0;
96  TH1F* Full_Cell[MAXLAYERS];
97  TH1F* Half_Cell[MAXLAYERS];
98  TH1F* MB_Cell[MAXLAYERS];
99  TH1F* Calib_Pads[MAXLAYERS];
100  TH1F* Merged_Cell[MAXLAYERS];
101  TH1F *h_digi_layer_channel[MAXSKIROCS][64][MAXLAYERS];
102 // TH2F *h_digi_layer_channel_CM[2][64];
103  TH1F* Sum_Cluster_ADC;
104  TH1F* AllCells_Ped;
105  TH1F* AllCells_CM;
106  TH2F* Noise_2D_Profile;
107  char name[50], title[50];
108 };
109 
110 //
111 // constants, enums and typedefs
112 //
113 
114 //
115 // static data member definitions
116 //
117 
118 //
119 // constructors and destructor
120 //
121 RecHitPlotter_HighGain_Correlation_CM::RecHitPlotter_HighGain_Correlation_CM(const edm::ParameterSet& iConfig)
122 {
123  //now do what ever initialization is needed
124  usesResource("TFileService");
125  edm::Service<TFileService> fs;
126  HGCalTBRecHitCollection_ = consumes<HGCalTBRecHitCollection>(iConfig.getParameter<edm::InputTag>("HGCALTBRECHITS"));
127 
128 //Booking 2 "hexagonal" histograms to display the sum of Rechits and the Occupancy(Hit > 5 GeV) in 1 sensor in 1 layer. To include all layers soon. Also the 1D Rechits per cell in a sensor is booked here.
129  AllCells_Ped = fs->make<TH1F>("AllCells_Ped","AllCells_Ped",500,-250,250);
130  AllCells_CM = fs->make<TH1F>("AllCells_CM","AllCells_CM",500,-250,250);
131  sprintf(name, "Noise_2D_Profile_Layer");
132  sprintf(title, "Noise 2D Profile Layer");
133  Noise_2D_Profile = fs->make<TH2F>(name,title,2048,0,2048,8000,-4000,4000);
134  for(int ILayer=0;ILayer<MAXLAYERS;ILayer++){
135  sprintf(name, "Full_Cell_Layer_%i",ILayer);
136  sprintf(title, "Full Cell Layer %i",ILayer);
137  Full_Cell[ILayer] = fs->make<TH1F>(name, title, 1000,-500., 500.);
138  sprintf(name, "Half_Cell_Layer_%i",ILayer);
139  sprintf(title, "Half Cell Layer %i",ILayer);
140  Half_Cell[ILayer] = fs->make<TH1F>(name, title, 1000,-500., 500.);
141  sprintf(name, "MB_Cell_Layer_%i",ILayer);
142  sprintf(title, "MB Cell Layer %i",ILayer);
143  MB_Cell[ILayer] = fs->make<TH1F>(name, title, 1000,-500., 500.);
144  sprintf(name, "Calib_Pads_Layer_%i",ILayer);
145  sprintf(title, "Calib Pads Layer %i",ILayer);
146  Calib_Pads[ILayer] = fs->make<TH1F>(name, title, 1000,-500., 500.);
147  sprintf(name, "Merged_Cell_Layer_%i",ILayer);
148  sprintf(title, "Merged Cell Layer %i",ILayer);
149  Merged_Cell[ILayer] = fs->make<TH1F>(name, title, 1000,-500., 500.);
150  for(int ISkiroc = 1;ISkiroc<=MAXSKIROCS;ISkiroc++){
151  for(int Channel=0; Channel<64;Channel++){
152  sprintf(name, "Ski_%i_Channel_%i_Layer_%i",ISkiroc,Channel,ILayer);
153  sprintf(title, "Ski %i Channel %i Layer %i",ISkiroc,Channel,ILayer);
154  h_digi_layer_channel[ISkiroc-1][Channel][ILayer] = fs->make<TH1F>(name, title, 1000,-500., 500.);
155 /*
156  sprintf(name, "Ski_%i_Channel_%i_CM",ISkiroc,Channel);
157  sprintf(title, "Ski %i Channel %i CM",ISkiroc,Channel);
158  h_digi_layer_channel_CM[ISkiroc-1][Channel] = fs->make<TH2F>(name, title, 1000,-500., 500.,1000,-500., 500.);
159 */
160  }
161  }
162  }
163 
164 }//contructor ends here
165 
166 
167 RecHitPlotter_HighGain_Correlation_CM::~RecHitPlotter_HighGain_Correlation_CM()
168 {
169 
170  // do anything here that needs to be done at desctruction time
171  // (e.g. close files, deallocate resources etc.)
172 
173 }
174 
175 
176 //
177 // member functions
178 //
179 
180 // ------------ method called for each event ------------
181 void
182 RecHitPlotter_HighGain_Correlation_CM::analyze(const edm::Event& event, const edm::EventSetup& setup)
183 {
184 
185  using namespace edm;
186 
187  edm::Handle<HGCalTBRecHitCollection> Rechits;
188  event.getByToken(HGCalTBRecHitCollection_, Rechits);
189  edm::Handle<HGCalTBRecHitCollection> Rechits1;
190  event.getByToken(HGCalTBRecHitCollection_, Rechits1);
191 
192  double Average_Pedestal_Per_Event_Full[MAXLAYERS] = {0};
193  int Cell_counter[MAXLAYERS] = {0};
194  double Average_Pedestal_Per_Event_Half[MAXLAYERS] = {0};
195  int Cell_counter_Half[MAXLAYERS] = {0};
196  double Average_Pedestal_Per_Event_MB[MAXLAYERS] = {0};
197  int Cell_counter_MB[MAXLAYERS] = {0};
198  double Average_Pedestal_Per_Event_Calib_Pad[MAXLAYERS] = {0};
199  int Cell_counter_Calib_Pad[MAXLAYERS] = {0};
200  double Average_Pedestal_Per_Event_Merged_Cell[MAXLAYERS] = {0};
201  int Cell_counter_Merged_Cell[MAXLAYERS] = {0};
202  for(auto RecHit1 : *Rechits1) {
203  CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((RecHit1.id()).layer(), (RecHit1.id()).sensorIU(), (RecHit1.id()).sensorIV(), (RecHit1.id()).iu(), (RecHit1.id()).iv(), sensorsize);
204  uint32_t EID = essource_.emap_.detId2eid(RecHit1.id());
205  HGCalTBElectronicsId eid(EID);
206 // if((eid.iskiroc()%2 == 1) && (eid.ichan() == 0 || eid.ichan() == 1 )) continue;
207 // double iux = (CellCentreXY.first < 0 ) ? (CellCentreXY.first + delta) : (CellCentreXY.first - delta) ;
208 // double iyy = (CellCentreXY.second < 0 ) ? (CellCentreXY.second + delta) : (CellCentreXY.second - delta);
209 // Cell_counter++;
210 // Average_Pedestal_Per_Event_Full += RecHit1.energyHigh();
211 // if(RecHit1.energyHigh() > 100) continue;
212  if((RecHit1.id()).cellType() == 0){
213 // Full_Cell[(RecHit1.id()).layer() - 1]->Fill(RecHit1.energyHigh());
214  Cell_counter[(RecHit1.id()).layer() - 1]++;
215  Average_Pedestal_Per_Event_Full[(RecHit1.id()).layer() - 1] += RecHit1.energyHigh();
216  }
217  else if((RecHit1.id()).cellType() == 2){
218 // Half_Cell[(RecHit1.id()).layer() - 1]->Fill(RecHit1.energyHigh());
219  Cell_counter_Half[(RecHit1.id()).layer() - 1]++;
220  Average_Pedestal_Per_Event_Half[(RecHit1.id()).layer() - 1] += RecHit1.energyHigh();
221  }
222  else if(((RecHit1.id()).cellType() == 3) && ( ((RecHit1.id()).iu() == 4 && (RecHit1.id()).iv() == 3) || ((RecHit1.id()).iu() == -7 && (RecHit1.id()).iv() == 4) || ((RecHit1.id()).iu() == 7 && (RecHit1.id()).iv() == -3) || ((RecHit1.id()).iu() == -4 && (RecHit1.id()).iv() == -3) )){
223 // MB_Cell[(RecHit1.id()).layer() - 1]->Fill(RecHit1.energyHigh());
224  Cell_counter_MB[(RecHit1.id()).layer() - 1]++;
225  Average_Pedestal_Per_Event_MB[(RecHit1.id()).layer() - 1] += RecHit1.energyHigh();
226  }
227  else if(((RecHit1.id()).cellType() == 3) && (((RecHit1.id()).iu() == -4 && (RecHit1.id()).iv() == 6) || ((RecHit1.id()).iu() == -2 && (RecHit1.id()).iv() == 6) || ((RecHit1.id()).iu() == 4 && (RecHit1.id()).iv() == -7) || ((RecHit1.id()).iu() == 2 && (RecHit1.id()).iv() == -6))){
228 // Merged_Cell[(RecHit1.id()).layer() - 1]->Fill(RecHit1.energyHigh());
229  Cell_counter_Merged_Cell[(RecHit1.id()).layer() - 1]++;
230  Average_Pedestal_Per_Event_Merged_Cell[(RecHit1.id()).layer() - 1] += RecHit1.energyHigh();
231  }
232  else if((RecHit1.id()).cellType() == 1){
233 // Calib_Pads[(RecHit1.id()).layer() - 1]->Fill(RecHit1.energyHigh());
234  Cell_counter_Calib_Pad[(RecHit1.id()).layer() - 1]++;
235  Average_Pedestal_Per_Event_Calib_Pad[(RecHit1.id()).layer() - 1] += RecHit1.energyHigh();
236  }
237 
238  }
239 
240 
241  for(int iii = 0; iii < MAXLAYERS; iii++){
242  if(Cell_counter[iii] != 0) Full_Cell[iii]->Fill(Average_Pedestal_Per_Event_Full[iii]/Cell_counter[iii]);
243  if(Cell_counter_Half[iii] != 0) Half_Cell[iii]->Fill(Average_Pedestal_Per_Event_Half[iii]/Cell_counter_Half[iii]);
244  if(Cell_counter_MB[iii] != 0) MB_Cell[iii]->Fill(Average_Pedestal_Per_Event_MB[iii]/Cell_counter_MB[iii]);
245  if(Cell_counter_Merged_Cell[iii] != 0) Merged_Cell[iii]->Fill(Average_Pedestal_Per_Event_Merged_Cell[iii]/Cell_counter_Merged_Cell[iii]);
246  if(Cell_counter_Calib_Pad[iii] != 0) Calib_Pads[iii]->Fill(Average_Pedestal_Per_Event_Calib_Pad[iii]/Cell_counter_Calib_Pad[iii]);
247 // cout<<endl<<"iii= "<<iii<<" "<<Cell_counter[iii]<<" "<<Cell_counter_Half[iii]<<" "<<Cell_counter_MB[iii]<<" "<<Cell_counter_Calib_Pad[iii]<<" "<<Cell_counter_Merged_Cell[iii]<<endl;
248  }
249 
250  for(auto RecHit : *Rechits) {
251 // if(RecHit.energyHigh() > 100) continue;
252  if(!IsCellValid.iu_iv_valid((RecHit.id()).layer(), (RecHit.id()).sensorIU(), (RecHit.id()).sensorIV(), (RecHit.id()).iu(), (RecHit.id()).iv(), sensorsize)) continue;
253  CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((RecHit.id()).layer(), (RecHit.id()).sensorIU(), (RecHit.id()).sensorIV(), (RecHit.id()).iu(), (RecHit.id()).iv(), sensorsize);
254 // double iux = (CellCentreXY.first < 0 ) ? (CellCentreXY.first + delta) : (CellCentreXY.first - delta) ;
255 // double iyy = (CellCentreXY.second < 0 ) ? (CellCentreXY.second + delta) : (CellCentreXY.second - delta);
256  uint32_t EID = essource_.emap_.detId2eid(RecHit.id());
257  HGCalTBElectronicsId eid(EID);
258 // TF1* Fit2= (TF1*) h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()]->GetFunction("gaus");
259  if(!doCommonMode_CM){
260  h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()][(RecHit.id()).layer() -1]->Fill(RecHit.energyHigh());
261  Noise_2D_Profile->Fill((64*(eid.iskiroc()-1) + eid.ichan()),RecHit.energyHigh());
262  }
263  if(doCommonMode_CM){
264  AllCells_Ped->Fill(RecHit.energyHigh());
265 // cout<<endl<<" Energy= "<<RecHit.energyHigh()<<" CM = "<<Average_Pedestal_Per_Event_Full[(RecHit.id()).layer() - 1]<<" Cells= "<<Cell_counter[(RecHit.id()).layer() -1]<<endl;
266  if((RecHit.id()).cellType() == 0 || (RecHit.id()).cellType() == 4) h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()][(RecHit.id()).layer() -1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event_Full[(RecHit.id()).layer() - 1]/(Cell_counter[(RecHit.id()).layer() -1])));
267  else if((RecHit.id()).cellType() == 2 ) h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()][(RecHit.id()).layer() -1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event_Half[(RecHit.id()).layer() -1]/(Cell_counter_Half[(RecHit.id()).layer() -1])));
268  else if((RecHit.id()).cellType() == 1) h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()][(RecHit.id()).layer() -1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event_Calib_Pad[(RecHit.id()).layer() - 1]/(Cell_counter_Calib_Pad[(RecHit.id()).layer() -1])));
269  else if(((RecHit.id()).cellType() == 3) && ( ((RecHit.id()).iu() == 4 && (RecHit.id()).iv() == 3) || ((RecHit.id()).iu() == -7 && (RecHit.id()).iv() == 4) || ((RecHit.id()).iu() == 7 && (RecHit.id()).iv() == -3) || ((RecHit.id()).iu() == -4 && (RecHit.id()).iv() == -3) ) ){
270  h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()][(RecHit.id()).layer() -1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event_MB[(RecHit.id()).layer() -1]/(Cell_counter_MB[(RecHit.id()).layer() -1])));
271  }
272  else if(((RecHit.id()).cellType() == 3) && (((RecHit.id()).iu() == -4 && (RecHit.id()).iv() == 6) || ((RecHit.id()).iu() == -2 && (RecHit.id()).iv() == 6) || ((RecHit.id()).iu() == 4 && (RecHit.id()).iv() == -7) || ((RecHit.id()).iu() == 2 && (RecHit.id()).iv() == -6))){
273  h_digi_layer_channel[eid.iskiroc()-1][eid.ichan()][(RecHit.id()).layer() -1]->Fill(RecHit.energyHigh() - (Average_Pedestal_Per_Event_Merged_Cell[(RecHit.id()).layer() -1]/(Cell_counter_Merged_Cell[(RecHit.id()).layer() -1])));
274  }
275  Noise_2D_Profile->Fill((64*(eid.iskiroc()-1) + eid.ichan()),RecHit.energyHigh() - (Average_Pedestal_Per_Event_Full[(RecHit.id()).layer() -1]/(Cell_counter[(RecHit.id()).layer() -1])));
276  }
277 
278 
279  }
280 
281 
282 }//analyze method ends here
283 
284 
285 // ------------ method called once each job just before starting event loop ------------
286 void
287 RecHitPlotter_HighGain_Correlation_CM::beginJob()
288 {
290  edm::FileInPath fip(mapfile_);
291  if (!io.load(fip.fullPath(), essource_.emap_)) {
292  throw cms::Exception("Unable to load electronics map");
293  }
294 }
295 
296 // ------------ method called once each job just after ending the event loop ------------
297 void
298 RecHitPlotter_HighGain_Correlation_CM::endJob()
299 {
300 
301 }
302 
303 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
304 void
305 RecHitPlotter_HighGain_Correlation_CM::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
306 {
307  //The following says we do not know what parameters are allowed so do no validation
308  // Please change this to state exactly what you do use, even if it is no parameters
309  edm::ParameterSetDescription desc;
310  desc.setUnknown();
311  descriptions.addDefault(desc);
312 }
313 
314 //define this as a plug-in
315 DEFINE_FWK_MODULE(RecHitPlotter_HighGain_Correlation_CM);
DEFINE_FWK_MODULE(Pedestals)
edm::Service< TFileService > fs
#define MAXLAYERS
double delta
#define MAXSKIROCS
provides the conversion between electronics Id to DetId
double return_RMS_CM(double mean_sq, double mean)