23 #include "FWCore/Framework/interface/Frameworkfwd.h"
24 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
25 #include "FWCore/Framework/interface/Event.h"
26 #include "FWCore/Framework/interface/MakerMacros.h"
27 #include "FWCore/ParameterSet/interface/ParameterSet.h"
28 #include "FWCore/ServiceRegistry/interface/Service.h"
29 #include "HGCal/DataFormats/interface/HGCalTBRecHitCollections.h"
30 #include "HGCal/DataFormats/interface/HGCalTBDetId.h"
31 #include "HGCal/DataFormats/interface/HGCalTBRecHit.h"
32 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
33 #include "HGCal/Geometry/interface/HGCalTBTopology.h"
34 #include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
35 #include "CommonTools/UtilAlgos/interface/TFileService.h"
36 #include "HGCal/CondObjects/interface/HGCalElectronicsMap.h"
37 #include "HGCal/CondObjects/interface/HGCalCondObjectTextIO.h"
38 #include "HGCal/DataFormats/interface/HGCalTBElectronicsId.h"
39 #include "HGCal/DataFormats/interface/HGCalTBDataFrameContainers.h"
40 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
41 #include "HGCal/Geometry/interface/HGCalTBCellParameters.h"
42 #include "HGCal/Geometry/interface/HGCalTBSpillParameters.h"
49 double Layer_Z[16] = {1.2,2.,3.5,4.3,5.8,6.3,8.7,9.5,11.4,12.2,13.8,14.6,16.6,17.4,20.,20.8};
78 class Layer_Sum_Analyzer :
public edm::one::EDAnalyzer<edm::one::SharedResources>
82 explicit Layer_Sum_Analyzer(
const edm::ParameterSet&);
83 ~Layer_Sum_Analyzer();
84 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
87 virtual void beginJob()
override;
88 void analyze(
const edm::Event& ,
const edm::EventSetup&)
override;
89 virtual void endJob()
override;
92 edm::EDGetToken HGCalTBRecHitCollection_;
96 string mapfile_ =
"HGCal/CondObjects/data/map_FNAL_SB2_Layer16.txt";
98 std::vector<std::pair<double, double>> CellXY;
99 std::pair<double, double> CellCentreXY;
101 double maxdist = (1 + sqrt (3) / 2) * HGCAL_TB_CELL::FULL_CELL_SIDE;
105 TH2F *HighGain_LowGain_2D;
106 int SPILL = 0, EVENT = 0, LAYER = 0;
114 double Time_Temp = 0.;
119 Layer_Sum_Analyzer::Layer_Sum_Analyzer(
const edm::ParameterSet& iConfig)
123 usesResource(
"TFileService");
124 edm::Service<TFileService>
fs;
125 HGCalTBRecHitCollection_ = consumes<HGCalTBRecHitCollection>(iConfig.getParameter<edm::InputTag>(
"HGCALTBRECHITS"));
128 for(
int layer = 0; layer <
MAXLAYERS; layer++){
129 stringstream name, sevenname, nineteenname, Xname, Yname, X_Y_name;
130 name <<
"AllCells_Sum_Layer" << layer + 1;
131 sevenname <<
"Cells7_Sum_Layer" << layer + 1;
132 nineteenname <<
"Cells19_Sum_Layer" << layer + 1;
133 Xname <<
"X_Layer" << layer + 1;
134 Yname <<
"Y_Layer" << layer + 1;
135 X_Y_name<<
"X_Y_Layer"<< layer + 1;
137 h_sum_layer[layer] =
fs->make<TH1F>(name.str().c_str(), name.str().c_str(), 622, -10, 612);
138 h_layer_seven[layer] =
fs->make<TH1F>(sevenname.str().c_str(), sevenname.str().c_str(), 622, -10, 612);
139 h_layer_nineteen[layer] =
fs->make<TH1F>(nineteenname.str().c_str(), nineteenname.str().c_str(), 622, -10, 612);
140 h_x_layer[layer] =
fs->make<TH1F>(Xname.str().c_str(), Xname.str().c_str(),2000,-10.,10. );
141 h_y_layer[layer] =
fs->make<TH1F>(Yname.str().c_str(), Yname.str().c_str(),2000,-10.,10. );
142 h_x_y_layer[layer] =
fs->make<TH2F>(X_Y_name.str().c_str(), X_Y_name.str().c_str(),2000,-10.,10.,2000,-10.,10. );
145 h_sum_all =
fs->make<TH1F>(
"AllCells_Sum_AllLayers",
"AllCells_Sum_AllLayers", 40010, -10, 40000);
147 h_seven_all =
fs->make<TH1F>(
"Cells7_Sum_AllLayers",
"7Cells_Sum_AllLayers", 40010, -10, 40000);
148 h_seven_all->Sumw2();
149 h_nineteen_all =
fs->make<TH1F>(
"Cells19_Sum_AllLayers",
"19Cells_Sum_AllLayers", 40010, -10, 40000);
150 h_nineteen_all->Sumw2();
151 HighGain_LowGain_2D =
fs->make<TH2F>(
"HighGain_LowGain_2D",
"HighGain_LowGain_2D",4000,0,4000,4000,0,4000);
155 Layer_Sum_Analyzer::~Layer_Sum_Analyzer()
166 Layer_Sum_Analyzer::analyze(
const edm::Event& event,
const edm::EventSetup& setup)
170 if(((event.id()).event() - 1) % (
EVENTSPERSPILL * MAXLAYERS) == 0 && (
event.id()).event() != 1){
176 Time_Temp =
event.time().value();
177 Time_Stamp[EVENT] = Time_Temp;
178 Delta_Time_Stamp[EVENT] = 0.;
181 Time_Stamp[EVENT] =
event.time().value();
182 Delta_Time_Stamp[EVENT] =
event.time().value() - Time_Temp;
183 Time_Temp =
event.time().value();
186 edm::Handle<HGCalTBRecHitCollection> Rechits;
187 event.getByToken(HGCalTBRecHitCollection_, Rechits);
191 double commonmode, max, max_x, max_y;
192 commonmode = max = max_x = max_y = 0.;
194 for(
auto Rechit : *Rechits){
197 uint32_t EID = essource_.emap_.detId2eid(Rechit.id());
201 CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((Rechit.id()).layer(), (Rechit.id()).sensorIU(), (Rechit.id()).sensorIV(), (Rechit.id()).iu(), (Rechit.id()).iv(), sensorsize);
202 HighGain_LowGain_2D->Fill(Rechit.energyLow(),Rechit.energyHigh());
203 if((Rechit.id()).cellType() != 0)
continue;
207 max = Rechit.energyHigh();
208 max_x = CellCentreXY.first;
209 max_y = CellCentreXY.second;
213 if(Rechit.energyHigh() > max){
215 max = Rechit.energyHigh();
216 max_x = CellCentreXY.first;
217 max_y = CellCentreXY.second;
222 commonmode += Rechit.energyHigh();
228 commonmode /= cm_num;
230 edm::Handle<HGCalTBRecHitCollection> Rechits1;
231 event.getByToken(HGCalTBRecHitCollection_, Rechits1);
234 double allcells_sum, sevencells_sum, nineteencells_sum, radius;
235 allcells_sum = sevencells_sum = nineteencells_sum = radius = 0.;
236 double x_tmp = 0., y_tmp = 0.;
237 int num, sevennum, nineteennum;
238 num = sevennum = nineteennum = 0;
239 for(
auto Rechit1 : *Rechits1){
242 uint32_t EID = essource_.emap_.detId2eid(Rechit1.id());
246 CellCentreXY = TheCell.GetCellCentreCoordinatesForPlots((Rechit1.id()).layer(), (Rechit1.id()).sensorIU(), (Rechit1.id()).sensorIV(), (Rechit1.id()).iu(), (Rechit1.id()).iv(), sensorsize);
248 if((Rechit1.id()).cellType() != 0)
continue;
250 radius = sqrt( pow(CellCentreXY.first - max_x, 2) + pow(CellCentreXY.second - max_y, 2) );
253 allcells_sum += (Rechit1.energyHigh() - commonmode) /
ADCtoMIP[LAYER];
256 if((radius < maxdist && sevennum < 7) && ((Rechit1.energyHigh() - commonmode)/
ADCtoMIP[LAYER] >
CMTHRESHOLD)){
258 sevencells_sum += (Rechit1.energyHigh() - commonmode) /
ADCtoMIP[LAYER];
262 if((radius < 1.95 * maxdist && nineteennum < 19) && ((Rechit1.energyHigh() - commonmode)/
ADCtoMIP[LAYER] >
CMTHRESHOLD)){
265 nineteencells_sum += ((Rechit1.energyHigh() - commonmode))/
ADCtoMIP[LAYER];
267 x_tmp += CellCentreXY.first*((Rechit1.energyHigh() - commonmode) /
ADCtoMIP[LAYER]);
268 y_tmp += CellCentreXY.second*((Rechit1.energyHigh() - commonmode) /
ADCtoMIP[LAYER]);
273 AllCells[LAYER][EVENT] = allcells_sum;
274 SevenCells[LAYER][EVENT] = sevencells_sum;
275 NineteenCells[LAYER][EVENT] = nineteencells_sum;
276 if(nineteennum> 1 && nineteencells_sum > 0) X_Layer[LAYER][EVENT] = x_tmp/nineteencells_sum ;
277 if(nineteennum> 1 && nineteencells_sum > 0) Y_Layer[LAYER][EVENT] = y_tmp/nineteencells_sum ;
284 Layer_Sum_Analyzer::beginJob()
287 edm::FileInPath fip(mapfile_);
288 if (!io.load(fip.fullPath(), essource_.emap_)) {
289 throw cms::Exception(
"Unable to load electronics map");
292 for(
int iii = 0; iii< 16;iii++)
306 Layer_Sum_Analyzer::endJob()
309 double allcells, sevencells, nineteencells;
310 bool doAllCells, do7Cells, do19Cells;
312 fs1.open(
"/home/daq/CMSSW_8_0_1/src/HGCal/HGC_CERN_Time_Synch.txt");
313 fs1<<
"# "<<
"Event Num"<<
"\t"<<
"Time(us)"<<
"\t"<<
"Delta t(us)"<<
"\t"<<
"Cluster x[cm]"<<
"\t"<<
"Cluster y[cm]"<<endl;
314 for(
int event = 0;
event < (SPILL + 1) *
EVENTSPERSPILL;
event++){
315 allcells = sevencells = nineteencells = 0.;
316 doAllCells = do7Cells = do19Cells =
false;
319 for(
int layer = 0; layer <
MAXLAYERS; layer++){
320 allcells += AllCells[layer][event];
321 sevencells += SevenCells[layer][event];
322 nineteencells += NineteenCells[layer][event];
327 h_sum_all->Fill(allcells);
331 h_seven_all->Fill(sevencells);
342 h_sum_all->Fill(allcells);
346 h_seven_all->Fill(sevencells);
356 for(
int layer = 0; layer <
MAXLAYERS; layer++){
358 h_sum_layer[layer]->Fill(AllCells[layer][event]);
361 h_layer_seven[layer]->Fill(SevenCells[layer][event]);
364 h_layer_nineteen[layer]->Fill(NineteenCells[layer][event]);
365 h_x_layer[layer]->Fill(X_Layer[layer][event]);
366 h_y_layer[layer]->Fill(Y_Layer[layer][event]);
367 h_x_y_layer[layer]->Fill(X_Layer[layer][event],Y_Layer[layer][event]);
368 cout<<endl<<
" "<<layer<<
" "<<X_Layer[layer][event]<<
" "<<Y_Layer[layer][event]<<endl;
369 fs1<<
event+1<<
"\t"<<200*Time_Stamp[
event+1]/1000.<<
"\t"<<200*Delta_Time_Stamp[
event+1]/1000.<<
"\t"<<X_Layer[layer][event]<<
"\t"<<Y_Layer[layer][event]<<endl;
379 Layer_Sum_Analyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
383 edm::ParameterSetDescription desc;
385 descriptions.addDefault(desc);
DEFINE_FWK_MODULE(Pedestals)
const double PION_ALLCELLS_THRESHOLD
const double PION_19CELLS_THRESHOLD
edm::Service< TFileService > fs
const double PION_7CELLS_THRESHOLD
const double ALLCELLS_THRESHOLD
const double NINETEENCELLS_THRESHOLD
const double SEVENCELLS_THRESHOLD
provides the conversion between electronics Id to DetId