28 #include "FWCore/Framework/interface/Frameworkfwd.h"
29 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
30 #include "FWCore/Framework/interface/Event.h"
31 #include "FWCore/Framework/interface/MakerMacros.h"
32 #include "FWCore/ParameterSet/interface/ParameterSet.h"
33 #include "FWCore/ServiceRegistry/interface/Service.h"
34 #include "HGCal/DataFormats/interface/HGCalTBRecHitCollections.h"
35 #include "HGCal/DataFormats/interface/HGCalTBDetId.h"
36 #include "HGCal/DataFormats/interface/HGCalTBRecHit.h"
37 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
38 #include "HGCal/Geometry/interface/HGCalTBTopology.h"
39 #include "CommonTools/UtilAlgos/interface/TFileService.h"
40 #include "HGCal/CondObjects/interface/HGCalElectronicsMap.h"
41 #include "HGCal/CondObjects/interface/HGCalCondObjectTextIO.h"
42 #include "HGCal/DataFormats/interface/HGCalTBElectronicsId.h"
43 #include "HGCal/DataFormats/interface/HGCalTBDataFrameContainers.h"
44 #include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
59 class DigiPlotter :
public edm::one::EDAnalyzer<edm::one::SharedResources>
63 explicit DigiPlotter(
const edm::ParameterSet&);
65 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
67 virtual void beginJob()
override;
68 void analyze(
const edm::Event& ,
const edm::EventSetup&)
override;
69 virtual void endJob()
override;
74 std::string mapfile_ =
"HGCal/CondObjects/data/map_FNAL_SB2_Layer16.txt";
79 std::vector<std::pair<double, double>> CellXY;
80 std::pair<double, double> CellCentreXY;
81 std::vector<std::pair<double, double>>::const_iterator it;
82 const static int NSAMPLES = 2;
83 TH2Poly *h_digi_layer[NSAMPLES][
MAXLAYERS];
84 TH1F *h_digi_layer_summed[NSAMPLES][
MAXLAYERS];
85 TProfile *h_digi_layer_profile[NSAMPLES][
MAXLAYERS];
86 const static int cellx = 15;
87 const static int celly = 15;
90 TH2F* Noise_2D_Profile[NSAMPLES][
MAXLAYERS];
91 TH1F *h_digi_layer_channel[
MAXSKIROCS][64][NSAMPLES];
93 char name[50], title[50];
94 double ADC_Sum_SKI_Layer[2][
MAXLAYERS][2];
95 int Cell_Count_SKI_Layer[2][4];
110 DigiPlotter::DigiPlotter(
const edm::ParameterSet& iConfig)
113 usesResource(
"TFileService");
114 edm::Service<TFileService>
fs;
115 consumesMany<SKIROC2DigiCollection>();
116 const int HalfHexVertices = 4;
117 double HalfHexX[HalfHexVertices] = {0.};
118 double HalfHexY[HalfHexVertices] = {0.};
119 const int FullHexVertices = 6;
120 double FullHexX[FullHexVertices] = {0.};
121 double FullHexY[FullHexVertices] = {0.};
122 for(
int nsample = 0; nsample < NSAMPLES; nsample++) {
123 for(
int nlayers = 0; nlayers <
MAXLAYERS; nlayers++) {
124 sprintf(name,
"Noise_2D_Profile_ADC%i_Layer%i", nsample, nlayers);
125 sprintf(title,
"Noise 2D Profile ADC%i Layer%i", nsample, nlayers);
126 Noise_2D_Profile[nsample][nlayers] = fs->make<TH2F>(name,title,128,0,127,500,-250,250);
129 for(
int ISkiroc = 1; ISkiroc <=
MAXSKIROCS; ISkiroc++) {
130 for(
int Channel = 0; Channel < 64; Channel++) {
131 for(
int iii = 0; iii < NSAMPLES; iii++) {
132 sprintf(name,
"Ski_%i_Channel_%i_ADC%i", ISkiroc, Channel, iii);
133 sprintf(title,
"Ski %i Channel %i ADC%i", ISkiroc, Channel, iii);
134 h_digi_layer_channel[ISkiroc - 1][Channel][iii] = fs->make<TH1F>(name, title, 4096, 0., 4095.);
139 for(
int nsample = 0; nsample < NSAMPLES; nsample++) {
140 for(
int nlayers = 0; nlayers <
MAXLAYERS; nlayers++) {
142 sprintf(name,
"FullLayer_ADC%i_Layer%i", nsample, nlayers + 1);
143 sprintf(title,
"Sum of adc counts per cell for ADC%i Layer%i", nsample, nlayers + 1);
144 h_digi_layer[nsample][nlayers] = fs->make<TH2Poly>();
145 h_digi_layer[nsample][nlayers]->SetName(name);
146 h_digi_layer[nsample][nlayers]->SetTitle(title);
147 sprintf(name,
"FullLayer_ADC%i_Layer%i_summed", nsample, nlayers + 1);
148 sprintf(title,
"Sum of adc counts for all cells in ADC%i Layer%i", nsample, nlayers + 1);
149 h_digi_layer_summed[nsample][nlayers] = fs->make<TH1F>(name, title, 4096, 0., 4095.);
150 h_digi_layer_summed[nsample][nlayers]->GetXaxis()->SetTitle(
"Digis[adc counts]");
151 sprintf(name,
"FullLayer_ADC%i_Layer%i_profile", nsample, nlayers + 1);
152 sprintf(title,
"profile of adc counts for all cells in ADC%i Layer%i", nsample, nlayers + 1);
153 h_digi_layer_profile[nsample][nlayers] = fs->make<TProfile>(name, title, 128, 0, 127, 0., 4095.);
154 h_digi_layer_profile[nsample][nlayers]->GetXaxis()->SetTitle(
"Channel #");
155 h_digi_layer_profile[nsample][nlayers]->GetYaxis()->SetTitle(
"ADC counts");
158 for(
int iv = -7; iv < 8; iv++) {
159 for(
int iu = -7; iu < 8; iu++) {
160 if(!IsCellValid.iu_iv_valid(nlayers, Sensor_Iu, Sensor_Iv, iu, iv, sensorsize))
continue;
161 CellXY = TheCell.GetCellCoordinatesForPlots(nlayers, Sensor_Iu, Sensor_Iv, iu, iv, sensorsize);
162 int NumberOfCellVertices = CellXY.size();
164 if(NumberOfCellVertices == 4) {
165 for(it = CellXY.begin(); it != CellXY.end(); it++) {
166 HalfHexX[iii] = it->first;
167 HalfHexY[iii++] = it->second;
170 h_digi_layer[nsample][nlayers]->AddBin(NumberOfCellVertices, HalfHexX, HalfHexY);
171 }
else if(NumberOfCellVertices == 6) {
173 for(it = CellXY.begin(); it != CellXY.end(); it++) {
174 FullHexX[iii] = it->first;
175 FullHexY[iii++] = it->second;
177 h_digi_layer[nsample][nlayers]->AddBin(NumberOfCellVertices, FullHexX, FullHexY);
187 DigiPlotter::~DigiPlotter()
202 DigiPlotter::analyze(
const edm::Event& event,
const edm::EventSetup& setup)
205 std::vector<edm::Handle<SKIROC2DigiCollection> > ski;
206 event.getManyByType(ski);
220 std::vector<edm::Handle<SKIROC2DigiCollection> >::iterator i;
221 int counter1 = 0, counter2 = 0;
222 for(i = ski.begin(); i != ski.end(); i++) {
226 for(SKIROC2DigiCollection::const_iterator k = Coll.begin(); k != Coll.end(); k++) {
228 int n_layer = (SKI_1.
detid()).layer();
229 int n_sensor_IU = (SKI_1.
detid()).sensorIU();
230 int n_sensor_IV = (SKI_1.
detid()).sensorIV();
231 int n_cell_iu = (SKI_1.
detid()).iu();
232 int n_cell_iv = (SKI_1.
detid()).iv();
233 uint32_t EID = essource_.emap_.detId2eid(SKI_1.
detid());
235 if(DEBUG) cout << endl <<
" Layer = " << n_layer <<
" Sensor IU = " << n_sensor_IU <<
" Sensor IV = " << n_sensor_IV <<
" Cell iu = " << n_cell_iu <<
" Cell iu = " << n_cell_iv << endl;
236 if(!IsCellValid.iu_iv_valid(n_layer, n_sensor_IU, n_sensor_IV, n_cell_iu, n_cell_iv, sensorsize))
continue;
245 for(SKIROC2DigiCollection::const_iterator j = Coll.begin(); j != Coll.end(); j++) {
247 int n_layer = (SKI.
detid()).layer();
248 int n_sensor_IU = (SKI.
detid()).sensorIU();
249 int n_sensor_IV = (SKI.
detid()).sensorIV();
250 int n_cell_iu = (SKI.
detid()).iu();
251 int n_cell_iv = (SKI.
detid()).iv();
252 uint32_t EID = essource_.emap_.detId2eid(SKI.
detid());
254 if(DEBUG) cout << endl <<
" Layer = " << n_layer <<
" Sensor IU = " << n_sensor_IU <<
" Sensor IV = " << n_sensor_IV <<
" Cell iu = " << n_cell_iu <<
" Cell iu = " << n_cell_iv << endl;
255 if(!IsCellValid.iu_iv_valid(n_layer, n_sensor_IU, n_sensor_IV, n_cell_iu, n_cell_iv, sensorsize))
continue;
256 CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots(n_layer, n_sensor_IU, n_sensor_IV, n_cell_iu, n_cell_iv, sensorsize);
257 double iux = (CellCentreXY.first < 0 ) ? (CellCentreXY.first + 0.0001) : (CellCentreXY.first - 0.0001) ;
258 double iyy = (CellCentreXY.second < 0 ) ? (CellCentreXY.second + 0.0001) : (CellCentreXY.second - 0.0001);
260 h_digi_layer[nsample][n_layer - 1]->Fill(iux , iyy, SKI[nsample].adcLow());
261 h_digi_layer_profile[nsample][n_layer - 1]->Fill(counter1++, SKI[nsample].adcLow(), 1);
263 if(eid.iskiroc() > 0) h_digi_layer_channel[eid.iskiroc() - 1][eid.ichan()][nsample]->Fill(SKI[nsample].adcLow());
265 h_digi_layer[nsample][n_layer - 1]->Fill(iux , iyy, SKI[nsample - 1].adcHigh());
266 h_digi_layer_profile[nsample][n_layer - 1]->Fill(counter2++, SKI[nsample - 1].adcHigh(), 1);
269 if(eid.iskiroc() > 0) h_digi_layer_channel[eid.iskiroc() - 1][eid.ichan()][nsample]->Fill(SKI[nsample - 1].adcHigh());
274 edm::LogWarning(
"DQM") <<
"No SKIROC2 Digis";
282 DigiPlotter::beginJob()
285 edm::FileInPath fip(mapfile_);
286 if (!io.load(fip.fullPath(), essource_.emap_)) {
287 throw cms::Exception(
"Unable to load electronics map");
293 DigiPlotter::endJob()
299 fs1.open(
"/afs/cern.ch/work/r/rchatter/FNAL_June_TestBeam/CMSSW_8_0_1/src/HGCal/Ped_HighGain_L16.txt");
300 fs1<<
"SCHEME_CODE 0"<<endl;
301 fs1<<
"# CODE LAYER SENSOR_IX SENSOR_IV IX IV TYPE VALUE"<<endl;
302 fs2.open(
"/afs/cern.ch/work/r/rchatter/FNAL_June_TestBeam/CMSSW_8_0_1/src/HGCal/Ped_LowGain_L16.txt");
303 fs2<<
"SCHEME_CODE 0"<<endl;
304 fs2<<
"# CODE LAYER SENSOR_IX SENSOR_IV IX IV TYPE VALUE"<<endl;
306 for(
int ISkiroc = 1; ISkiroc <=
MAXSKIROCS; ISkiroc++) {
307 for(
int Channel = 0; Channel < 64; Channel++) {
310 if(DetId.
layer() != 0){
311 fs1<<
" "<<Code<<
" "<<DetId.
layer()<<
" "<<SENSOR_IX<<
" "<<SENSOR_IV<<
" "<<DetId.
iu()<<
" "<<DetId.
iv()<<
" "<<
" "<<DetId.
cellType()<<
" "<<h_digi_layer_channel[ISkiroc - 1][Channel][1]->GetMean()<<endl;
312 fs2<<
" "<<Code<<
" "<<DetId.
layer()<<
" "<<SENSOR_IX<<
" "<<SENSOR_IV<<
" "<<DetId.
iu()<<
" "<<DetId.
iv()<<
" "<<
" "<<DetId.
cellType()<<
" "<<h_digi_layer_channel[ISkiroc - 1][Channel][0]->GetMean()<<endl;
320 DigiPlotter::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
324 edm::ParameterSetDescription desc;
326 descriptions.addDefault(desc);
int layer() const
get the layer #
DEFINE_FWK_MODULE(Pedestals)
HGCalTBDetId detid() const
Get the detector id.
edm::Service< TFileService > fs
int cellType() const
cell type
int iu() const
get the absolute value of the cell #'s
provides the conversion between electronics Id to DetId