CMS 3D CMS Logo

PPSPixelDigiAnalyzer.cc
Go to the documentation of this file.
1 #ifndef SimPPS_RPIXDigiAnalyzer_h
2 #define SimPPS_RPIXDigiAnalyzer_h
3 
13 
25 
26 #include <iostream>
27 #include <string>
28 
29 #include "TH2D.h"
30 
31 #define SELECTED_PIXEL_ROW 89
32 #define SELECTED_PIXEL_COLUMN 23
33 #define SELECTED_UNITID 2014314496
34 #define TG184 0.332655724
35 
36 #define USE_MIDDLE_OF_PIXEL_2
37 #define CENTERX 1.05
38 #define CENTERY -8.475
39 
40 using namespace edm;
41 using namespace std;
42 
43 class PSimHit;
44 
45 namespace edm {
46  class ParameterSet;
47  class Event;
48  class EventSetup;
49 } // namespace edm
50 
51 class PPSPixelDigiAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
52 public:
54  ~PPSPixelDigiAnalyzer() override;
55  void endJob() override;
56  void beginJob() override;
57  void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override;
58 
59 private:
60  TH2D *hAllHits;
65  //TFile *file;
67 
72 
74  unsigned int cumulative_cluster_size_[3];
75 };
76 
78  : hAllHits(nullptr),
79  hOneHitperEvent(nullptr),
80  hOneHitperEvent2(nullptr),
81  hOneHitperEventCenter(nullptr),
82  hOneHitperEvent2Center(nullptr) {
83  label_ = pset.getUntrackedParameter<string>("label");
84  verbosity_ = pset.getParameter<int>("Verbosity");
86 #ifdef USE_MIDDLE_OF_PIXEL
87  hOneHitperEvent = file->make<TH2D>("OneHitperEvent", "One Hit per Event", 30, -8.511, -8.361, 20, 1, 1.1);
88  hOneHitperEvent2 = file->make<TH2D>("OneHitperEvent2", "One Hit per Event 2", 30, -8.511, -8.361, 20, 1, 1.1);
89 #else
90  hOneHitperEvent = file->make<TH2D>("OneHitperEvent", "One Hit per Event", 30, -8.55, -8.4, 20, 1, 1.1);
91  hOneHitperEvent2 = file->make<TH2D>("OneHitperEvent2", "One Hit per Event 2", 30, -8.55, -8.4, 20, 1, 1.1);
93  file->make<TH2D>("OneHitperEventCenter", "One Hit per Event Center", 30, -0.075, 0.075, 20, -0.05, 0.05);
95  file->make<TH2D>("OneHitperEvent2Center", "Cluster Size 2", 30, -0.075, 0.075, 20, -0.05, 0.05);
96 #endif
97  file->cd();
98  hAllHits = file->make<TH2D>("AllHits", "All Hits", 10, 1, 1.1, 10, -8.55, -8.4);
99 
100  psim_token = consumes<PSimHitContainer>(edm::InputTag("g4SimHits", "CTPPSPixelHits"));
101  pixel_token = consumes<edm::DetSetVector<CTPPSPixelDigi>>(edm::InputTag(label_, "")); //label=RPixDetDigitizer???
102  pixelTopologyToken_ = esConsumes<PPSPixelTopology, PPSPixelTopologyRcd>();
103 }
104 
106 
109  for (int a = 0; a < 3; a++)
111 }
113  edm::LogInfo("PPSPixelDigiAnalyzer") << "found_corresponding_digi_count_: " << found_corresponding_digi_count_;
114  edm::LogInfo("PPSPixelDigiAnalyzer") << "Cumulative cluster size (1,2,>2) = " << cumulative_cluster_size_[0] << ", "
116 }
117 
119  if (verbosity_ > 0)
120  edm::LogInfo("PPSPixelDigiAnalyzer") << "--- Run: " << event.id().run() << " Event: " << event.id().event();
121 
122  edm::LogInfo("PPSPixelDigiAnalyzer")
123  << " I do love Pixels ";
125  event.getByToken(psim_token, simHits);
126 
128  event.getByToken(pixel_token, CTPPSPixelDigis);
129 
130  edm::ESHandle<PPSPixelTopology> thePixelTopology = eventSetup.getHandle(pixelTopologyToken_);
131 
132  if (verbosity_ > 0)
133  edm::LogInfo("PPSPixelDigiAnalyzer") << "\n=================== RPDA Starting SimHit access"
134  << " ===================";
135 
136  if (verbosity_ > 1)
137  edm::LogInfo("PPSPixelDigiAnalyzer") << simHits->size();
138 
139  double selected_pixel_lower_x;
140  double selected_pixel_lower_y;
141  double selected_pixel_upper_x;
142  double selected_pixel_upper_y;
143  double myX = 0;
144  double myY = 0;
145 
146  thePixelTopology->pixelRange(SELECTED_PIXEL_ROW,
148  selected_pixel_lower_x,
149  selected_pixel_upper_x,
150  selected_pixel_lower_y,
151  selected_pixel_upper_y);
152 
153  double hit_inside_selected_pixel[2];
154  bool found_hit_inside_selected_pixel = false;
155 
156  for (vector<PSimHit>::const_iterator hit = simHits->begin(); hit != simHits->end(); hit++) {
157  LocalPoint entryP = hit->entryPoint();
158  LocalPoint exitP = hit->exitPoint();
159  LocalPoint midP((entryP.x() + exitP.x()) / 2., (entryP.y() + exitP.y()) / 2.);
160 
161 #ifdef USE_MIDDLE_OF_PIXEL
162  if (entryP.x() > selected_pixel_lower_x && entryP.x() < selected_pixel_upper_x &&
163  entryP.y() > (selected_pixel_lower_y + 0.115 * TG184) && entryP.y() < (selected_pixel_upper_y + 0.115 * TG184)
164 #else
166  if (midP.x() > selected_pixel_lower_x && midP.x() < selected_pixel_upper_x && midP.y() > selected_pixel_lower_y &&
167  midP.y() < selected_pixel_upper_y
168 #else
169  if (entryP.x() > selected_pixel_lower_x && entryP.x() < selected_pixel_upper_x &&
170  entryP.y() > selected_pixel_lower_y && entryP.y() < selected_pixel_upper_y
171 #endif
172 #endif
173  && hit->detUnitId() == SELECTED_UNITID) {
174  hit_inside_selected_pixel[0] = entryP.x();
175  hit_inside_selected_pixel[1] = entryP.y();
176  found_hit_inside_selected_pixel = true;
177 #ifdef USE_MIDDLE_OF_PIXEL_2
178  hAllHits->Fill(midP.x(), midP.y());
179  myX = midP.x();
180  myY = midP.y();
181 #else
182  hAllHits->Fill(entryP.x(), entryP.y());
183  myX = entryP.x();
184  myY = entryP.y();
185 #endif
186  if (verbosity_ > 2)
187  edm::LogInfo("PPSPixelDigiAnalyzer") << hit_inside_selected_pixel[0] << " " << hit_inside_selected_pixel[1];
188  }
189 
190  //--------------
191 
192  if (verbosity_ > 1)
193  if (hit->timeOfFlight() > 0) {
194  edm::LogInfo("PPSPixelDigiAnalyzer")
195  << "DetId: " << hit->detUnitId() << "PID: " << hit->particleType() << " TOF: " << hit->timeOfFlight()
196  << " Proc Type: " << hit->processType() << " p: " << hit->pabs() << " x = " << entryP.x()
197  << " y = " << entryP.y() << " z = " << entryP.z();
198  }
199  }
200 
201  if (verbosity_ > 0)
202  edm::LogInfo("PPSPixelDigiAnalyzer") << "\n=================== RPDA Starting Digi access"
203  << " ===================";
204  int numberOfDetUnits = 0;
205 
206  // Iterate on detector units
207  edm::DetSetVector<CTPPSPixelDigi>::const_iterator DSViter = CTPPSPixelDigis->begin();
208 
209  for (; DSViter != CTPPSPixelDigis->end(); DSViter++) {
210  ++numberOfDetUnits;
211 
212  DetId detIdObject(DSViter->detId());
213  if (verbosity_ > 1)
214  edm::LogInfo("PPSPixelDigiAnalyzer") << "DetId: " << DSViter->detId();
215 
216  bool found_corresponding_digi = false;
217  unsigned int corresponding_digi_cluster_size = 0;
218 
219  // looping over digis in a unit id
220  edm::DetSet<CTPPSPixelDigi>::const_iterator begin = (*DSViter).begin();
222 
223  if (verbosity_ > 2) {
224  edm::LogInfo("PPSPixelDigiAnalyzer") << "FF " << DSViter->detId();
225  for (edm::DetSet<CTPPSPixelDigi>::const_iterator di = begin; di != end; di++) {
226  edm::LogInfo("PPSPixelDigiAnalyzer") << " Digi row " << di->row() << ", col " << di->column();
227 
228  // reconvert the digi to local coordinates
229  double lx;
230  double ly;
231  double ux;
232  double uy;
233  unsigned int rr = di->row();
234  unsigned int cc = di->column();
235  thePixelTopology->pixelRange(rr, cc, lx, ux, ly, uy);
236 
237  edm::LogInfo("PPSPixelDigiAnalyzer")
238  << " pixel boundaries x low up, y low up " << lx << " " << ux << " " << ly << " " << uy;
239  }
240  }
241  if (DSViter->detId() == SELECTED_UNITID && found_hit_inside_selected_pixel) {
242  for (edm::DetSet<CTPPSPixelDigi>::const_iterator di = begin; di != end; di++) {
243  if (verbosity_ > 1)
244  edm::LogInfo("PPSPixelDigiAnalyzer") << " Digi row " << di->row() << ", col " << di->column();
245 
246  if (di->row() == SELECTED_PIXEL_ROW && di->column() == SELECTED_PIXEL_COLUMN) {
248  found_corresponding_digi = true;
249  corresponding_digi_cluster_size = 1;
250  }
251  }
252  //if coresponding digi found, re-loop to look for adjacent pixels
253  if (found_corresponding_digi) {
254  for (edm::DetSet<CTPPSPixelDigi>::const_iterator di = begin; di != end; di++) {
255  if (verbosity_ > 1)
256  edm::LogInfo("PPSPixelDigiAnalyzer") << " Digi row " << di->row() << ", col " << di->column();
257 
258  if ((di->row() == SELECTED_PIXEL_ROW + 1 && di->column() == SELECTED_PIXEL_COLUMN) ||
259  (di->row() == SELECTED_PIXEL_ROW - 1 && di->column() == SELECTED_PIXEL_COLUMN) ||
260  (di->row() == SELECTED_PIXEL_ROW && di->column() == SELECTED_PIXEL_COLUMN + 1) ||
261  (di->row() == SELECTED_PIXEL_ROW && di->column() == SELECTED_PIXEL_COLUMN - 1)) {
262  corresponding_digi_cluster_size++;
263  edm::LogInfo("PPSPixelDigiAnalyzer") << " Digi row " << di->row() << ", col " << di->column();
264  }
265  }
266  }
267  }
268  if (corresponding_digi_cluster_size > 0) {
269  edm::LogInfo("PPSPixelDigiAnalyzer")
270  << "corresponding_digi_cluster_size in the event: " << corresponding_digi_cluster_size;
271  hOneHitperEvent->Fill(myY, myX);
272  hOneHitperEventCenter->Fill(myY - CENTERY, myX - CENTERX);
273  if (corresponding_digi_cluster_size < 3) {
274  cumulative_cluster_size_[corresponding_digi_cluster_size - 1]++;
275  if (corresponding_digi_cluster_size > 1) {
276  hOneHitperEvent2->Fill(myY, myX);
277  hOneHitperEvent2Center->Fill(myY - CENTERY, myX - CENTERX);
278  }
279  } else {
281  hOneHitperEvent2->Fill(myY, myX);
282  hOneHitperEvent2Center->Fill(myY - CENTERY, myX - CENTERX);
283  }
284  }
285  }
286 
287  if (verbosity_ > 1)
288  edm::LogInfo("PPSPixelDigiAnalyzer") << "numberOfDetUnits in the event: " << numberOfDetUnits;
289 }
290 
293 
295 
296 #endif
unsigned int cumulative_cluster_size_[3]
T z() const
Definition: PV3DBase.h:61
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
unsigned int found_corresponding_digi_count_
void beginJob()
Definition: Breakpoints.cc:14
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
#define SELECTED_PIXEL_ROW
#define TG184
#define CENTERX
edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelDigi > > pixel_token
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
#define CENTERY
edm::ESGetToken< PPSPixelTopology, PPSPixelTopologyRcd > pixelTopologyToken_
void pixelRange(unsigned int arow, unsigned int acol, double &lower_x, double &higher_x, double &lower_y, double &higher_y) const
Log< level::Info, false > LogInfo
Definition: DetId.h:17
#define SELECTED_PIXEL_COLUMN
edm::EDGetTokenT< edm::PSimHitContainer > psim_token
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
#define SELECTED_UNITID
#define USE_MIDDLE_OF_PIXEL_2
HLT enums.
double a
Definition: hdecay.h:121
PPSPixelDigiAnalyzer(const edm::ParameterSet &pset)
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
Definition: event.py:1