CMS 3D CMS Logo

PPSTimingCalibrationPCLHarvester.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of PPS offline software.
4  * Authors:
5  * Edoardo Bossini
6  * Piotr Maciej Cwiklicki
7  * Laurent Forthomme
8  *
9  ****************************************************************************/
10 
12 
19 
22 
25 
28 
29 //------------------------------------------------------------------------------
30 
32 public:
34  void beginRun(const edm::Run&, const edm::EventSetup&) override;
35 
37 
38 private:
41  std::vector<CTPPSDiamondDetId> detids_;
42  const std::string dqmDir_;
43  const std::string formula_;
44  const unsigned int min_entries_;
45  TF1 interp_;
46 };
47 
48 //------------------------------------------------------------------------------
49 
51  : geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
52  dqmDir_(iConfig.getParameter<std::string>("dqmDir")),
53  formula_(iConfig.getParameter<std::string>("formula")),
54  min_entries_(iConfig.getParameter<unsigned int>("minEntries")),
55  interp_("interp", formula_.c_str(), 10.5, 25.) {
56  // first ensure DB output service is available
58  if (!poolDbService.isAvailable())
59  throw cms::Exception("PPSTimingCalibrationPCLHarvester") << "PoolDBService required";
60 
61  // constrain the min/max fit values
62  interp_.SetParLimits(1, 9., 15.);
63  interp_.SetParLimits(2, 0.2, 2.5);
64 }
65 
66 //------------------------------------------------------------------------------
67 
69  const auto& geom = iSetup.getData(geomEsToken_);
70  for (auto it = geom.beginSensor(); it != geom.endSensor(); ++it) {
71  if (!CTPPSDiamondDetId::check(it->first))
72  continue;
73  const CTPPSDiamondDetId detid(it->first);
74  if (detid.station() == 1) // for the time being, only compute for this station (run 2 diamond)
75  detids_.emplace_back(detid);
76  }
77 }
78 
79 //------------------------------------------------------------------------------
80 
82  // book the parameters containers
85 
86  iGetter.cd();
87  iGetter.setCurrentFolder(dqmDir_);
88 
89  // compute the fit parameters for all monitored channels
91  std::string ch_name;
92  for (const auto& detid : detids_) {
93  detid.channelName(ch_name);
94  const auto chid = detid.rawId();
96  (int)detid.arm(), (int)detid.station(), (int)detid.plane(), (int)detid.channel()};
97  hists.leadingTime[chid] = iGetter.get("t_" + ch_name);
98  if (hists.leadingTime[chid] == nullptr) {
99  edm::LogInfo("PPSTimingCalibrationPCLHarvester:dqmEndJob")
100  << "Failed to retrieve leading time monitor for channel (" << detid << ").";
101  continue;
102  }
103  hists.toT[chid] = iGetter.get("tot_" + ch_name);
104  if (hists.toT[chid] == nullptr) {
105  edm::LogInfo("PPSTimingCalibrationPCLHarvester:dqmEndJob")
106  << "Failed to retrieve time over threshold monitor for channel (" << detid << ").";
107  continue;
108  }
109  hists.leadingTimeVsToT[chid] = iGetter.get("tvstot_" + ch_name);
110  if (hists.leadingTimeVsToT[chid] == nullptr) {
111  edm::LogInfo("PPSTimingCalibrationPCLHarvester:dqmEndJob")
112  << "Failed to retrieve leading time vs. time over threshold monitor for channel (" << detid << ").";
113  continue;
114  }
115  if (min_entries_ > 0 && hists.leadingTimeVsToT[chid]->getEntries() < min_entries_) {
116  edm::LogWarning("PPSTimingCalibrationPCLHarvester:dqmEndJob")
117  << "Not enough entries for channel (" << detid << "): " << hists.leadingTimeVsToT[chid]->getEntries() << " < "
118  << min_entries_ << ". Skipping calibration.";
119  continue;
120  }
121  const double upper_tot_range = hists.toT[chid]->getMean() + 2.5;
122  { // scope for x-profile
123  std::unique_ptr<TProfile> prof(hists.leadingTimeVsToT[chid]->getTH2D()->ProfileX("_prof_x", 1, -1));
124  interp_.SetParameters(hists.leadingTime[chid]->getRMS(),
125  hists.toT[chid]->getMean(),
126  0.8,
127  hists.leadingTime[chid]->getMean() - hists.leadingTime[chid]->getRMS());
128  const auto& res = prof->Fit(&interp_, "B+", "", 10.4, upper_tot_range);
129  if ((bool)res) {
130  calib_params[key] = {
131  interp_.GetParameter(0), interp_.GetParameter(1), interp_.GetParameter(2), interp_.GetParameter(3)};
132  calib_time[key] = std::make_pair(0.1, 0.); // hardcoded resolution/offset placeholder for the time being
133  // can possibly do something with interp_.GetChiSquare() in the near future
134  } else
135  edm::LogWarning("PPSTimingCalibrationPCLHarvester:dqmEndJob")
136  << "Fit did not converge for channel (" << detid << ").";
137  }
138  }
139 
140  // fill the DB object record
141  PPSTimingCalibration calib(formula_, calib_params, calib_time);
142 
143  // write the object
145  poolDbService->writeOne(&calib, poolDbService->currentTime(), "PPSTimingCalibrationRcd");
146 }
147 
148 //------------------------------------------------------------------------------
149 
152  desc.add<std::string>("dqmDir", "AlCaReco/PPSTimingCalibrationPCL")
153  ->setComment("input path for the various DQM plots");
154  desc.add<std::string>("formula", "[0]/(exp((x-[1])/[2])+1)+[3]")
155  ->setComment("interpolation formula for the time walk component");
156  desc.add<unsigned int>("minEntries", 100)->setComment("minimal number of hits to extract calibration");
157  descriptions.addWithDefaultLabel(desc);
158 }
159 
DQMEDHarvester.h
PPSTimingCalibrationPCLHarvester::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: PPSTimingCalibrationPCLHarvester.cc:68
PPSTimingCalibration::TimingMap
std::map< Key, std::pair< double, double > > TimingMap
Definition: PPSTimingCalibration.h:38
ESHandle.h
edm::Run
Definition: Run.h:45
PPSTimingCalibrationPCLHarvester::min_entries_
const unsigned int min_entries_
Definition: PPSTimingCalibrationPCLHarvester.cc:51
edm
HLT enums.
Definition: AlignableModifier.h:19
PPSTimingCalibration::Key
Helper structure for indexing calibration data.
Definition: PPSTimingCalibration.h:26
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
compare.hists
hists
Definition: compare.py:318
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
TimingCalibrationHistograms
Definition: TimingCalibrationStruct.h:7
PPSTimingCalibrationPCLHarvester::dqmEndJob
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: PPSTimingCalibrationPCLHarvester.cc:81
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PPSTimingCalibration::ParametersMap
std::map< Key, std::vector< double > > ParametersMap
Definition: PPSTimingCalibration.h:37
CTPPSGeometry.h
MakerMacros.h
PPSTimingCalibrationPCLHarvester::detids_
std::vector< CTPPSDiamondDetId > detids_
Definition: PPSTimingCalibrationPCLHarvester.cc:48
CTPPSDetId::station
uint32_t station() const
Definition: CTPPSDetId.h:62
PoolDBOutputService.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
PPSTimingCalibrationPCLHarvester::interp_
TF1 interp_
Definition: PPSTimingCalibrationPCLHarvester.cc:52
PPSTimingCalibrationPCLHarvester::PPSTimingCalibrationPCLHarvester
PPSTimingCalibrationPCLHarvester(const edm::ParameterSet &)
Definition: PPSTimingCalibrationPCLHarvester.cc:50
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
calib
Definition: CalibElectron.h:12
CTPPSDiamondDetId.h
CTPPSDiamondDetId
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
Definition: CTPPSDiamondDetId.h:24
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
PPSTimingCalibrationPCLHarvester::geomEsToken_
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > geomEsToken_
Definition: PPSTimingCalibrationPCLHarvester.cc:47
edm::Service< cond::service::PoolDBOutputService >
createfilelist.int
int
Definition: createfilelist.py:10
PPSTimingCalibrationPCLHarvester::formula_
const std::string formula_
Definition: PPSTimingCalibrationPCLHarvester.cc:50
CTPPSDiamondDetId::check
static bool check(unsigned int raw)
returns true if the raw ID is a PPS-timing one
Definition: CTPPSDiamondDetId.h:40
edm::EventSetup
Definition: EventSetup.h:58
res
Definition: Electron.h:6
VeryForwardRealGeometryRecord.h
PPSTimingCalibration.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
DQMEDHarvester
Definition: DQMEDHarvester.py:1
L1EGammaCrystalsEmulatorProducer_cfi.calib
calib
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:6
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
PPSTimingCalibrationPCLHarvester::dqmDir_
const std::string dqmDir_
Definition: PPSTimingCalibrationPCLHarvester.cc:49
dqm::implementation::IGetter
Definition: DQMStore.h:484
PPSTimingCalibrationPCLHarvester::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: PPSTimingCalibrationPCLHarvester.cc:150
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:63
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
EventSetup.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
cms::Exception
Definition: Exception.h:70
PPSTimingCalibration
Definition: PPSTimingCalibration.h:17
TimingCalibrationStruct.h
ParameterSet.h
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
crabWrapper.key
key
Definition: crabWrapper.py:19
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:217
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
PPSTimingCalibrationPCLHarvester
Definition: PPSTimingCalibrationPCLHarvester.cc:31