CMS 3D CMS Logo

SiStripLorentzAngleRunInfoTableProducer.cc
Go to the documentation of this file.
5 
8 
16 
18 
20 public:
22  : m_name{params.getParameter<std::string>("name")},
23  m_magFieldName{params.getParameter<std::string>("magFieldName")},
24  m_doc{params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""},
25  m_tkGeomToken{esConsumes<edm::Transition::BeginRun>()},
26  m_magFieldToken{esConsumes<edm::Transition::BeginRun>()},
27  m_lorentzAngleToken{esConsumes<edm::Transition::BeginRun>()} {
28  produces<nanoaod::FlatTable, edm::Transition::BeginRun>();
29  produces<nanoaod::FlatTable, edm::Transition::BeginRun>("magField");
30  }
31 
32  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}
33 
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
36  desc.add<std::string>("name", "Det");
37  desc.add<std::string>("magFieldName", "magField");
38  desc.add<std::string>("doc", "Run info for the Lorentz angle measurement");
39  descriptions.add("siStripLorentzAngleRunInfoTable", desc);
40  }
41 
42  void globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const& iSetup) const override;
43 
44 private:
50 };
51 
52 namespace {
53  template <typename VALUES>
54  void addColumn(nanoaod::FlatTable* table, const std::string& name, VALUES&& values, const std::string& doc) {
56  table->template addColumn<value_type>(name, values, doc);
57  }
58 } // namespace
59 
61  edm::EventSetup const& iSetup) const {
62  const auto& tkGeom = iSetup.getData(m_tkGeomToken);
63  const auto& magField = iSetup.getData(m_magFieldToken);
64  const auto& lorentzAngle = iSetup.getData(m_lorentzAngleToken);
65  std::vector<uint32_t> c_rawid;
66  std::vector<float> c_globalZofunitlocalY, c_localB, c_BdotY, c_driftx, c_drifty, c_driftz, c_lorentzAngle;
67 
68  auto dets = tkGeom.detsTIB();
69  dets.insert(dets.end(), tkGeom.detsTID().begin(), tkGeom.detsTID().end());
70  dets.insert(dets.end(), tkGeom.detsTOB().begin(), tkGeom.detsTOB().end());
71  dets.insert(dets.end(), tkGeom.detsTEC().begin(), tkGeom.detsTEC().end());
72  for (auto det : dets) {
73  auto detid = det->geographicalId().rawId();
74  const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(tkGeom.idToDet(det->geographicalId()));
75  if (stripDet) {
76  c_rawid.push_back(detid);
77  c_globalZofunitlocalY.push_back(stripDet->toGlobal(LocalVector(0, 1, 0)).z());
78  const auto locB = magField.inTesla(stripDet->surface().position());
79  c_localB.push_back(locB.mag());
80  c_BdotY.push_back(stripDet->surface().toLocal(locB).y());
81  const auto drift = shallow::drift(stripDet, magField, lorentzAngle);
82  c_driftx.push_back(drift.x());
83  c_drifty.push_back(drift.y());
84  c_driftz.push_back(drift.z());
85  c_lorentzAngle.push_back(lorentzAngle.getLorentzAngle(detid));
86  }
87  }
88  auto out = std::make_unique<nanoaod::FlatTable>(c_rawid.size(), m_name, false, false);
89  addColumn(out.get(), "rawid", c_rawid, "DetId");
90  addColumn(out.get(), "globalZofunitlocalY", c_globalZofunitlocalY, "z component of a local unit vector along y");
91  addColumn(out.get(), "localB", c_localB, "Local magnitude of the magnetic field");
92  addColumn(out.get(), "BdotY", c_BdotY, "Magnetic field projection on the local y axis");
93  addColumn(out.get(), "driftx", c_driftx, "x component of the drift vector");
94  addColumn(out.get(), "drifty", c_drifty, "y component of the drift vector");
95  addColumn(out.get(), "driftz", c_driftz, "z component of the drift vector");
96  addColumn(out.get(), "lorentzAngle", c_lorentzAngle, "Lorentz angle from database");
97  iRun.put(std::move(out));
98 
99  auto out2 = std::make_unique<nanoaod::FlatTable>(1, m_magFieldName, true, false);
100  out2->addColumnValue<float>(
101  "origin", magField.inTesla(GlobalPoint(0, 0, 0)).z(), "z-component of the magnetic field at (0,0,0) in Tesla");
102  iRun.put(std::move(out2), "magField");
103 }
104 
T z() const
Definition: PV3DBase.h:61
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:36
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > m_tkGeomToken
LocalPoint toLocal(const GlobalPoint &gp) const
void globalBeginRunProduce(edm::Run &iRun, edm::EventSetup const &iSetup) const override
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
bool getData(T &iHolder) const
Definition: EventSetup.h:122
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const PositionType & position() const
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:109
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleDepRcd > m_lorentzAngleToken
SiStripLorentzAngleRunInfoTableProducer(const edm::ParameterSet &params)
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_magFieldToken
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45