CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.getParameter<edm::InputTag>("totemTimingDigiTag"))),
178  tokenRecHit_(consumes<edm::DetSetVector<TotemTimingRecHit>>(ps.getParameter<edm::InputTag>("tagRecHits"))),
179  timingCalibrationToken_(esConsumes<edm::Transition::BeginRun>()),
180  geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
181  verbosity_(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
183 
184 //----------------------------------------------------------------------------------------------------
185 
187 
188 //----------------------------------------------------------------------------------------------------
189 
191  // Get detector shifts from the geometry (if present)
192  const auto &geom = iSetup.getData(geomEsToken_);
193  for (auto it = geom.beginSensor(); it != geom.endSensor(); it++) {
194  if (!CTPPSDiamondDetId::check(it->first))
195  continue;
196  const CTPPSDiamondDetId detid(it->first);
197 
198  const DetGeomDesc *det = geom.sensorNoThrow(detid);
199  if (det)
201  else
202  edm::LogProblem("DiamondSampicCalibrationDQMSource") << "ERROR: no descriptor for detId";
203  }
204 }
205 
206 //----------------------------------------------------------------------------------------------------
207 
209  const edm::Run &,
210  const edm::EventSetup &iSetup) {
211  ibooker.cd();
212  ibooker.setCurrentFolder("CTPPS");
213 
214  globalPlot_ = GlobalPlots(ibooker);
215  const auto &geom = iSetup.getData(geomEsToken_);
216  for (auto it = geom.beginSensor(); it != geom.endSensor(); ++it) {
217  if (!CTPPSDiamondDetId::check(it->first))
218  continue;
219  const CTPPSDiamondDetId detid(it->first);
220 
221  const CTPPSDiamondDetId rpId(detid.arm(), detid.station(), detid.rp());
222  potPlots_[rpId] = PotPlots(ibooker, rpId);
223 
224  const CTPPSDiamondDetId plId(detid.arm(), detid.station(), detid.rp(), detid.plane());
225  planePlots_[plId] = PlanePlots(ibooker, plId);
226 
227  const CTPPSDiamondDetId chId(detid.arm(), detid.station(), detid.rp(), detid.plane(), detid.channel());
228  channelPlots_[chId] = ChannelPlots(ibooker, chId);
229  }
231 }
232 
233 //----------------------------------------------------------------------------------------------------
234 
237  // get event setup data
239  event.getByToken(tokenRecHit_, timingRecHits);
240 
242  event.getByToken(totemTimingDigiToken_, timingDigi);
243 
244  std::unordered_map<uint32_t, uint32_t> detIdToHw;
245 
246  for (const auto &digis : *timingDigi) {
247  const CTPPSDiamondDetId detId(digis.detId());
248  for (const auto &digi : digis)
249  detIdToHw[detId] = digi.hardwareId();
250  }
251 
252  // Using TotemTimingDigi
253  std::set<uint8_t> boardSet;
254  std::unordered_map<unsigned int, unsigned int> channelsPerPlane;
255  std::unordered_map<unsigned int, unsigned int> channelsPerPlaneWithTime;
256 
257  // End digis
258 
259  for (const auto &rechits : *timingRecHits) {
260  const CTPPSDiamondDetId detId(rechits.detId());
261  CTPPSDiamondDetId detId_pot(rechits.detId());
262  detId_pot.setPlane(0);
263  detId_pot.setChannel(0);
264  CTPPSDiamondDetId detId_plane(rechits.detId());
265  detId_plane.setChannel(0);
266 
267  for (const auto &rechit : rechits) {
268  if (potPlots_.find(detId_pot) != potPlots_.end()) {
269  float UFSDShift = 0.0;
270  if (rechit.yWidth() < 3)
271  UFSDShift = 0.5;
272 
273  TH2F *hitHistoTmp = potPlots_[detId_pot].hitDistribution2d->getTH2F();
274  TAxis *hitHistoTmpYAxis = hitHistoTmp->GetYaxis();
275  int startBin =
276  hitHistoTmpYAxis->FindBin(rechit.x() - horizontalShiftOfDiamond_[detId_pot] - 0.5 * rechit.xWidth());
277  int numOfBins = rechit.xWidth() * INV_DISPLAY_RESOLUTION_FOR_HITS_MM;
278  for (int i = 0; i < numOfBins; ++i)
279  potPlots_[detId_pot].hitDistribution2d->Fill(detId.plane() + UFSDShift,
280  hitHistoTmpYAxis->GetBinCenter(startBin + i));
281 
282  //All plots with Time
283  if (rechit.time() != TotemTimingRecHit::NO_T_AVAILABLE) {
284  int db = (detIdToHw[detId] & 0xE0) >> 5;
285  int sampic = (detIdToHw[detId] & 0x10) >> 4;
286  int channel = (detIdToHw[detId] & 0x0F);
287  double offset = calib.timeOffset(db, sampic, channel);
288  potPlots_[detId_pot].recHitTime->Fill(rechit.time() + offset);
289  if (channelPlots_.find(detId) != channelPlots_.end())
290  channelPlots_[detId].recHitTime->Fill(rechit.time() + offset);
291  }
292  }
293  }
294  }
295  // End RecHits
296 
297  timeOfPreviousEvent_ = event.time().value();
298 }
299 
uint32_t station() const
Definition: CTPPSDetId.h:58
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const Translation & translation() const
Definition: DetGeomDesc.h:80
void setPlane(uint32_t channel)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setChannel(uint32_t channel)
void channelName(std::string &name, NameFlag flag=nFull) const
const DiamondDimensions & getDiamondDimensions() const
Definition: DetGeomDesc.h:90
tuple db
Definition: EcalCondDB.py:153
edm::EDGetTokenT< edm::DetSetVector< TotemTimingDigi > > totemTimingDigiToken_
edm::EDGetTokenT< edm::DetSetVector< TotemTimingRecHit > > tokenRecHit_
double timeOffset(int key1, int key2, int key3, int key4=-1) const
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:78
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::unordered_map< unsigned int, double > horizontalShiftOfDiamond_
DiamondSampicCalibrationDQMSource(const edm::ParameterSet &)
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:128
Transition
Definition: Transition.h:12
uint32_t plane() const
uint32_t arm() const
Definition: CTPPSDetId.h:51
unsigned long long TimeValue_t
Definition: Timestamp.h:28
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 channel() const
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:177
edm::ESHandle< PPSTimingCalibration > hTimingCalib_
void planeName(std::string &name, NameFlag flag=nFull) const
plots related to one Diamond detector package
std::unordered_map< unsigned int, ChannelPlots > channelPlots_
edm::ESGetToken< PPSTimingCalibration, PPSTimingCalibrationRcd > timingCalibrationToken_
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
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: Run.h:45
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Error, true > LogProblem
uint32_t rp() const
Definition: CTPPSDetId.h:65