CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_;
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->writeOneIOV(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 
uint32_t station() const
Definition: CTPPSDetId.h:58
std::map< Key, std::pair< double, double > > TimingMap
PPSTimingCalibrationPCLHarvester(const edm::ParameterSet &)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > geomEsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
Helper structure for indexing calibration data.
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
bool isAvailable() const
Definition: Service.h:40
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
tuple key
prepare the HTCondor submission files and eventually submit them
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Transition
Definition: Transition.h:12
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static bool check(unsigned int raw)
returns true if the raw ID is a PPS-timing one
Log< level::Info, false > LogInfo
void beginRun(const edm::Run &, const edm::EventSetup &) override
list hists
Definition: compare.py:318
std::map< Key, std::vector< double > > ParametersMap
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
Log< level::Warning, false > LogWarning
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45