CMS 3D CMS Logo

DiamondSampicCalibrationDQMSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQM/CTPPS/DiamondSampicCalibrationDQMSource
4 // Class: DiamondSampicCalibrationDQMSource
5 //
13 //
14 // Original Author: Christopher Misan
15 // Created: Mon, 24 Aug 2021 14:21:17 GMT
16 //
17 //
18 
26 
29 
36 
40 
47 
48 #include <string>
49 
50 //----------------------------------------------------------------------------------------------------
51 
53 public:
56 
57 protected:
58  void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
59  void bookHistograms(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &) override;
60  void analyze(const edm::Event &, const edm::EventSetup &) override;
61 
62 private:
63  // Constants
64  static const double DISPLAY_RESOLUTION_FOR_HITS_MM; // Bin width of histograms
65  // showing hits and tracks
66  // (in mm)
68 
73  unsigned int verbosity_;
75 
77  std::unordered_map<unsigned int, double> horizontalShiftOfDiamond_;
78 
80  struct GlobalPlots {
83  };
84 
86 
88  struct PotPlots {
89  // RecHits
92 
93  PotPlots(){};
94  PotPlots(DQMStore::IBooker &ibooker, unsigned int id);
95  };
96 
97  std::unordered_map<unsigned int, PotPlots> potPlots_;
98 
100  struct PlanePlots {
102  PlanePlots(DQMStore::IBooker &ibooker, unsigned int id);
103  };
104 
105  std::unordered_map<unsigned int, PlanePlots> planePlots_;
106 
108  struct ChannelPlots {
109  // RecHits
111 
113  ChannelPlots(DQMStore::IBooker &ibooker, unsigned int id);
114  };
115 
117  std::unordered_map<unsigned int, ChannelPlots> channelPlots_;
118 };
119 
120 //----------------------------------------------------------------------------------------------------
121 
122 // Values for all constants
125  1. / DISPLAY_RESOLUTION_FOR_HITS_MM;
126 
127 //----------------------------------------------------------------------------------------------------
128 
130  ibooker.setCurrentFolder("CTPPS/TimingFastSilicon");
131 }
132 
133 //----------------------------------------------------------------------------------------------------
134 
138  ibooker.setCurrentFolder(path);
139 
141 
142  hitDistribution2d = ibooker.book2D("hits in planes",
143  title + " hits in planes;plane number;x (mm)",
144  10,
145  -0.5,
146  4.5,
148  -0.5,
149  18.5);
150 
151  recHitTime = ibooker.book1D("recHit time", title + " time in the recHits; t (ns)", 500, -25, 25);
152 }
153 
154 //----------------------------------------------------------------------------------------------------
155 
159  ibooker.setCurrentFolder(path);
160 }
161 
162 //----------------------------------------------------------------------------------------------------
163 
167  ibooker.setCurrentFolder(path);
168 
170  recHitTime = ibooker.book1D("recHit Time", title + " recHit Time; t (ns)", 500, -25, 25);
171 }
172 
173 //----------------------------------------------------------------------------------------------------
174 
177  consumes<edm::DetSetVector<TotemTimingDigi>>(ps.getUntrackedParameter<edm::InputTag>("totemTimingDigiTag"))),
178  tokenRecHit_(
179  consumes<edm::DetSetVector<TotemTimingRecHit>>(ps.getUntrackedParameter<edm::InputTag>("tagRecHits"))),
181  geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
182  verbosity_(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
184 
185 //----------------------------------------------------------------------------------------------------
186 
188 
189 //----------------------------------------------------------------------------------------------------
190 
192  // Get detector shifts from the geometry (if present)
193  const auto &geom = iSetup.getData(geomEsToken_);
194  for (auto it = geom.beginSensor(); it != geom.endSensor(); it++) {
195  if (!CTPPSDiamondDetId::check(it->first))
196  continue;
197  const CTPPSDiamondDetId detid(it->first);
198 
199  const DetGeomDesc *det = geom.sensorNoThrow(detid);
200  if (det)
202  else
203  edm::LogProblem("DiamondSampicCalibrationDQMSource") << "ERROR: no descriptor for detId";
204  }
205 }
206 
207 //----------------------------------------------------------------------------------------------------
208 
210  const edm::Run &,
211  const edm::EventSetup &iSetup) {
212  ibooker.cd();
213  ibooker.setCurrentFolder("CTPPS");
214 
215  globalPlot_ = GlobalPlots(ibooker);
216  const auto &geom = iSetup.getData(geomEsToken_);
217  for (auto it = geom.beginSensor(); it != geom.endSensor(); ++it) {
218  if (!CTPPSDiamondDetId::check(it->first))
219  continue;
220  const CTPPSDiamondDetId detid(it->first);
221 
222  const CTPPSDiamondDetId rpId(detid.arm(), detid.station(), detid.rp());
223  potPlots_[rpId] = PotPlots(ibooker, rpId);
224 
225  const CTPPSDiamondDetId plId(detid.arm(), detid.station(), detid.rp(), detid.plane());
226  planePlots_[plId] = PlanePlots(ibooker, plId);
227 
228  const CTPPSDiamondDetId chId(detid.arm(), detid.station(), detid.rp(), detid.plane(), detid.channel());
229  channelPlots_[chId] = ChannelPlots(ibooker, chId);
230  }
232 }
233 
234 //----------------------------------------------------------------------------------------------------
235 
238  // get event setup data
240  event.getByToken(tokenRecHit_, timingRecHits);
241 
243  event.getByToken(totemTimingDigiToken_, timingDigi);
244 
245  std::unordered_map<uint32_t, uint32_t> detIdToHw;
246 
247  for (const auto &digis : *timingDigi) {
248  const CTPPSDiamondDetId detId(digis.detId());
249  for (const auto &digi : digis)
250  detIdToHw[detId] = digi.hardwareId();
251  }
252 
253  // Using TotemTimingDigi
254  std::set<uint8_t> boardSet;
255  std::unordered_map<unsigned int, unsigned int> channelsPerPlane;
256  std::unordered_map<unsigned int, unsigned int> channelsPerPlaneWithTime;
257 
258  // End digis
259 
260  for (const auto &rechits : *timingRecHits) {
261  const CTPPSDiamondDetId detId(rechits.detId());
262  CTPPSDiamondDetId detId_pot(rechits.detId());
263  detId_pot.setPlane(0);
264  detId_pot.setChannel(0);
265  CTPPSDiamondDetId detId_plane(rechits.detId());
266  detId_plane.setChannel(0);
267 
268  for (const auto &rechit : rechits) {
269  if (potPlots_.find(detId_pot) != potPlots_.end()) {
270  float UFSDShift = 0.0;
271  if (rechit.yWidth() < 3)
272  UFSDShift = 0.5;
273 
274  TH2F *hitHistoTmp = potPlots_[detId_pot].hitDistribution2d->getTH2F();
275  TAxis *hitHistoTmpYAxis = hitHistoTmp->GetYaxis();
276  int startBin =
277  hitHistoTmpYAxis->FindBin(rechit.x() - horizontalShiftOfDiamond_[detId_pot] - 0.5 * rechit.xWidth());
278  int numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
279  for (int i = 0; i < numOfBins; ++i)
280  potPlots_[detId_pot].hitDistribution2d->Fill(detId.plane() + UFSDShift,
281  hitHistoTmpYAxis->GetBinCenter(startBin + i));
282 
283  //All plots with Time
284  if (rechit.time() != TotemTimingRecHit::NO_T_AVAILABLE) {
285  int db = (detIdToHw[detId] & 0xE0) >> 5;
286  int sampic = (detIdToHw[detId] & 0x10) >> 4;
287  int channel = (detIdToHw[detId] & 0x0F);
288  double offset = calib.timeOffset(db, sampic, channel);
289  potPlots_[detId_pot].recHitTime->Fill(rechit.time() + offset);
290  if (channelPlots_.find(detId) != channelPlots_.end())
291  channelPlots_[detId].recHitTime->Fill(rechit.time() + offset);
292  }
293  }
294  }
295  }
296  // End RecHits
297 
298  timeOfPreviousEvent_ = event.time().value();
299 }
300 
const Translation & translation() const
Definition: DetGeomDesc.h:80
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void setPlane(uint32_t channel)
uint32_t arm() const
Definition: CTPPSDetId.h:57
void setChannel(uint32_t channel)
uint32_t plane() const
edm::EDGetTokenT< edm::DetSetVector< TotemTimingDigi > > totemTimingDigiToken_
edm::EDGetTokenT< edm::DetSetVector< TotemTimingRecHit > > tokenRecHit_
void planeName(std::string &name, NameFlag flag=nFull) const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
std::unordered_map< unsigned int, double > horizontalShiftOfDiamond_
DiamondSampicCalibrationDQMSource(const edm::ParameterSet &)
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:134
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:84
uint32_t channel() const
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:90
unsigned long long TimeValue_t
Definition: Timestamp.h:21
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void channelName(std::string &name, NameFlag flag=nFull) const
std::unordered_map< unsigned int, PlanePlots > planePlots_
static bool check(unsigned int raw)
returns true if the raw ID is a PPS-timing one
std::unordered_map< unsigned int, PotPlots > potPlots_
void bookHistograms(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &) override
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > geomEsToken_
uint32_t rp() const
Definition: CTPPSDetId.h:71
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
edm::ESHandle< PPSTimingCalibration > hTimingCalib_
uint32_t station() const
Definition: CTPPSDetId.h:64
plots related to one Diamond detector package
std::unordered_map< unsigned int, ChannelPlots > channelPlots_
HLT enums.
edm::ESGetToken< PPSTimingCalibration, PPSTimingCalibrationRcd > timingCalibrationToken_
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: event.py:1
Definition: Run.h:45
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Error, true > LogProblem