PPSPixelTopologyESSource

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
/****************************************************************************
 *
 *  CondFormats/PPSObjects/plugins/PPSPixelTopologyESSource.cc
 *
 *  Description :  - Loads PPSPixelTopology from the PPSPixelTopologyESSource_cfi.py
 *                   config file.
 *
 *
 * Author: F.Ferro ferro@ge.infn.it
 * 
 *
 ****************************************************************************/

#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/SourceFactory.h"
#include "FWCore/Framework/interface/ModuleFactory.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/ESProducts.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CondFormats/PPSObjects/interface/PPSPixelTopology.h"
#include "CondFormats/DataRecord/interface/PPSPixelTopologyRcd.h"
#include "FWCore/Utilities/interface/Exception.h"

#include <memory>

/**
 * \brief Loads PPSPixelTopology from a config file.
 **/

class PPSPixelTopologyESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
public:
  PPSPixelTopologyESSource(const edm::ParameterSet&);
  ~PPSPixelTopologyESSource() override = default;

  std::unique_ptr<PPSPixelTopology> produce(const PPSPixelTopologyRcd&);
  static void fillDescriptions(edm::ConfigurationDescriptions&);

private:
  /// Set PPS Topology parameters to their values from config
  void setPPSPixelTopology(const edm::ParameterSet&);
  ///  Fill PPSPixelTopology object
  std::unique_ptr<PPSPixelTopology> fillPPSPixelTopology();

  // Topology parameters
  std::string runType_;
  double pitch_simY_;
  double pitch_simX_;
  double thickness_;
  unsigned short no_of_pixels_simX_;
  unsigned short no_of_pixels_simY_;
  unsigned short no_of_pixels_;
  double simX_width_;
  double simY_width_;
  double dead_edge_width_;
  double active_edge_sigma_;
  double phys_active_edge_dist_;

protected:
  /// sets infinite validity of this data
  void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
                      const edm::IOVSyncValue&,
                      edm::ValidityInterval&) override;
};

//----------------------------------------------------------------------------------------------------

PPSPixelTopologyESSource::PPSPixelTopologyESSource(const edm::ParameterSet& iConfig)
    : runType_(""),
      pitch_simY_(0.),
      pitch_simX_(0.),
      thickness_(0.),
      no_of_pixels_simX_(0.),
      no_of_pixels_simY_(0.),
      no_of_pixels_(0.),
      simX_width_(0.),
      simY_width_(0.),
      dead_edge_width_(0.),
      active_edge_sigma_(0.),
      phys_active_edge_dist_(0.) {
  setPPSPixelTopology(iConfig);

  // validate input
  if (runType_ != "Run2" && runType_ != "Run3")
    throw cms::Exception("PPS") << runType_ << " is not valid runType.";

  setWhatProduced(this);
  findingRecord<PPSPixelTopologyRcd>();
}

//----------------------------------------------------------------------------------------------------

std::unique_ptr<PPSPixelTopology> PPSPixelTopologyESSource::produce(const PPSPixelTopologyRcd&) {
  auto topo = fillPPSPixelTopology();

  edm::LogInfo("PPS") << "PixelTopologyESSource::produce \n" << *topo;

  return topo;
}

//----------------------------------------------------------------------------------------------------

void PPSPixelTopologyESSource::setPPSPixelTopology(const edm::ParameterSet& iConfig) {
  runType_ = iConfig.getParameter<std::string>("RunType");
  pitch_simY_ = iConfig.getParameter<double>("PitchSimY");
  pitch_simX_ = iConfig.getParameter<double>("PitchSimX");
  thickness_ = iConfig.getParameter<double>("thickness");
  no_of_pixels_simX_ = iConfig.getParameter<int>("noOfPixelSimX");
  no_of_pixels_simY_ = iConfig.getParameter<int>("noOfPixelSimY");
  no_of_pixels_ = iConfig.getParameter<int>("noOfPixels");
  simX_width_ = iConfig.getParameter<double>("simXWidth");
  simY_width_ = iConfig.getParameter<double>("simYWidth");
  dead_edge_width_ = iConfig.getParameter<double>("deadEdgeWidth");
  active_edge_sigma_ = iConfig.getParameter<double>("activeEdgeSigma");
  phys_active_edge_dist_ = iConfig.getParameter<double>("physActiveEdgeDist");
}

//----------------------------------------------------------------------------------------------------

std::unique_ptr<PPSPixelTopology> PPSPixelTopologyESSource::fillPPSPixelTopology() {
  auto p = std::make_unique<PPSPixelTopology>();

  p->setRunType(runType_);
  p->setPitchSimY(pitch_simY_);
  p->setPitchSimX(pitch_simX_);
  p->setThickness(thickness_);
  p->setNoPixelsSimX(no_of_pixels_simX_);
  p->setNoPixelsSimY(no_of_pixels_simY_);
  p->setNoPixels(no_of_pixels_);
  p->setSimXWidth(simX_width_);
  p->setSimYWidth(simY_width_);
  p->setDeadEdgeWidth(dead_edge_width_);
  p->setActiveEdgeSigma(active_edge_sigma_);
  p->setPhysActiveEdgeDist(phys_active_edge_dist_);
  p->setActiveEdgeX(simX_width_ / 2. - phys_active_edge_dist_);
  p->setActiveEdgeY(simY_width_ / 2. - phys_active_edge_dist_);

  return p;
}

//----------------------------------------------------------------------------------------------------

void PPSPixelTopologyESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& key,
                                              const edm::IOVSyncValue& iosv,
                                              edm::ValidityInterval& oValidity) {
  edm::LogInfo("PPS") << ">> PPSPixelTopologyESSource::setIntervalFor(" << key.name() << ")\n"
                      << "    run=" << iosv.eventID().run() << ", event=" << iosv.eventID().event();

  edm::ValidityInterval infinity(iosv.beginOfTime(), iosv.endOfTime());
  oValidity = infinity;
}

//----------------------------------------------------------------------------------------------------

void PPSPixelTopologyESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
  edm::ParameterSetDescription desc;
  desc.add<std::string>("RunType", "Run3");
  desc.add<double>("PitchSimY", 150e-3);
  desc.add<double>("PitchSimX", 100e-3);
  desc.add<double>("thickness", 0.23);
  desc.add<int>("noOfPixelSimX", 160);
  desc.add<int>("noOfPixelSimY", 104);
  desc.add<int>("noOfPixels", 160 * 104);
  desc.add<double>("simXWidth", 16.6);
  desc.add<double>("simYWidth", 16.2);
  desc.add<double>("deadEdgeWidth", 200e-3);
  desc.add<double>("activeEdgeSigma", 0.02);
  desc.add<double>("physActiveEdgeDist", 0.150);

  descriptions.add("ppsPixelTopologyESSource", desc);
}

//----------------------------------------------------------------------------------------------------

DEFINE_FWK_EVENTSETUP_SOURCE(PPSPixelTopologyESSource);