CMS 3D CMS Logo

SiStripGainCalibTableProducer.cc
Go to the documentation of this file.
3 
9 
12 
14 
16 public:
18  : SiStripOnTrackClusterTableProducerBase(params), m_tkGeomToken{esConsumes<>()}, m_gainToken{esConsumes<>()} {}
19 
20  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
22  desc.add<std::string>("name", "cluster");
23  desc.add<std::string>("doc", "");
24  desc.add<bool>("extension", false);
25  desc.add<edm::InputTag>("Tracks", edm::InputTag{"generalTracks"});
26  descriptions.add("siStripGainCalibTable", desc);
27  }
28 
29  void fillTable(const std::vector<OnTrackCluster>& clusters,
32  const edm::EventSetup& iSetup) final;
33 
34 private:
37 
38  std::map<DetId, double> m_thicknessMap;
39  double thickness(DetId id, const TrackerGeometry* tGeom);
40 };
41 
42 namespace {
43  bool isFarFromBorder(const TrajectoryStateOnSurface& trajState, uint32_t detId, const TrackerGeometry* tGeom) {
44  const auto gdu = tGeom->idToDetUnit(detId);
45  if ((!dynamic_cast<const StripGeomDetUnit*>(gdu)) && (!dynamic_cast<const PixelGeomDetUnit*>(gdu))) {
46  edm::LogWarning("SiStripGainCalibTableProducer")
47  << "DetId " << detId << " does not seem to belong to the tracker";
48  return false;
49  }
50  const auto plane = gdu->surface();
51  const auto trapBounds = dynamic_cast<const TrapezoidalPlaneBounds*>(&plane.bounds());
52  const auto rectBounds = dynamic_cast<const RectangularPlaneBounds*>(&plane.bounds());
53 
54  static constexpr double distFromBorder = 1.0;
55  double halfLength = 0.;
56  if (trapBounds) {
57  halfLength = trapBounds->parameters()[3];
58  } else if (rectBounds) {
59  halfLength = .5 * gdu->surface().bounds().length();
60  } else {
61  return false;
62  }
63 
64  const auto pos = trajState.localPosition();
65  const auto posError = trajState.localError().positionError();
66  if (std::abs(pos.y()) + posError.yy() >= (halfLength - distFromBorder))
67  return false;
68 
69  return true;
70  }
71 } // namespace
72 
74  const auto it = m_thicknessMap.find(id);
75  if (m_thicknessMap.end() != it) {
76  return it->second;
77  } else {
78  double detThickness = 1.;
79  const auto gdu = tGeom->idToDetUnit(id);
80  const auto isPixel = (dynamic_cast<const PixelGeomDetUnit*>(gdu) != nullptr);
81  const auto isStrip = (dynamic_cast<const StripGeomDetUnit*>(gdu) != nullptr);
82  if (!isPixel && !isStrip) {
83  edm::LogWarning("SiStripGainCalibTableProducer")
84  << "DetId " << id.rawId() << " doesn't seem to belong to the Tracker";
85  } else {
86  detThickness = gdu->surface().bounds().thickness();
87  }
88  m_thicknessMap[id] = detThickness;
89  return detThickness;
90  }
91 }
92 
93 void SiStripGainCalibTableProducer::fillTable(const std::vector<OnTrackCluster>& clusters,
96  const edm::EventSetup& iSetup) {
99 
100  std::vector<double> c_localdirx;
101  std::vector<double> c_localdiry;
102  std::vector<double> c_localdirz;
103  std::vector<uint16_t> c_firststrip;
104  std::vector<uint16_t> c_nstrips;
105  std::vector<bool> c_saturation;
106  std::vector<bool> c_overlapping;
107  std::vector<bool> c_farfromedge;
108  std::vector<int> c_charge;
109  std::vector<double> c_path;
110  // NOTE only very few types are supported by NanoAOD, but more could be added (to discuss with XPOG / core software)
111  // NOTE removed amplitude vector, I don't think it was used anywhere
112  std::vector<float> c_gainused; // NOTE was double
113  std::vector<float> c_gainusedTick; // NOTE was double
114  for (const auto clus : clusters) {
115  const auto& ampls = clus.cluster->amplitudes();
116  const int firstStrip = clus.cluster->firstStrip();
117  const int nStrips = ampls.size();
118  double prevGain = -1;
119  double prevGainTick = -1;
120  if (stripGains.isValid()) {
121  prevGain = stripGains->getApvGain(firstStrip / 128, stripGains->getRange(clus.det, 1), 1);
122  prevGainTick = stripGains->getApvGain(firstStrip / 128, stripGains->getRange(clus.det, 0), 1);
123  }
124  const unsigned int charge = clus.cluster->charge();
125  const bool saturation = std::any_of(ampls.begin(), ampls.end(), [](uint8_t amp) { return amp >= 254; });
126 
127  const bool overlapping = (((firstStrip % 128) == 0) || ((firstStrip / 128) != ((firstStrip + nStrips) / 128)) ||
128  (((firstStrip + nStrips) % 128) == 127));
129  const auto& trajState = clus.measurement.updatedState();
130  const auto trackDir = trajState.localDirection();
131  const auto cosine = trackDir.z() / trackDir.mag();
132  const auto path = (10. * thickness(clus.det, tGeom.product())) / std::abs(cosine);
133  const auto farFromEdge = isFarFromBorder(trajState, clus.det, tGeom.product());
134  c_localdirx.push_back(trackDir.x());
135  c_localdiry.push_back(trackDir.y());
136  c_localdirz.push_back(trackDir.z());
137  c_firststrip.push_back(firstStrip);
138  c_nstrips.push_back(nStrips);
139  c_saturation.push_back(saturation);
140  c_overlapping.push_back(overlapping);
141  c_farfromedge.push_back(farFromEdge);
142  c_charge.push_back(charge);
143  c_path.push_back(path);
144  c_gainused.push_back(prevGain);
145  c_gainusedTick.push_back(prevGainTick);
146  }
147  // addColumn(table, "localdirx", c_localdirx, "<doc>");
148  // addColumn(table, "localdiry", c_localdiry, "<doc>");
149  // addColumn(table, "localdirz", c_localdirz, "<doc>");
150  // addColumn(table, "firststrip", c_firststrip, "<doc>");
151  // addColumn(table, "nstrips", c_nstrips, "<doc>");
152  addColumn(table, "saturation", c_saturation, "<doc>");
153  addColumn(table, "overlapping", c_overlapping, "<doc>");
154  addColumn(table, "farfromedge", c_farfromedge, "<doc>");
155  addColumn(table, "charge", c_charge, "<doc>");
156  // addColumn(table, "path", c_path, "<doc>");
157  // ExtendedCalibTree: also charge/path
158  addColumn(table, "gainused", c_gainused, "<doc>");
159  addColumn(table, "gainusedTick", c_gainusedTick, "<doc>");
160 }
161 
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const LocalTrajectoryError & localError() const
T z() const
Definition: PV3DBase.h:61
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:75
LocalError positionError() const
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
double thickness(DetId id, const TrackerGeometry *tGeom)
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:80
T const * product() const
Definition: ESHandle.h:86
void fillTable(const std::vector< OnTrackCluster > &clusters, const edm::View< reco::Track > &tracks, nanoaod::FlatTable *table, const edm::EventSetup &iSetup) final
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
LocalVector localDirection() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isFarFromBorder(const TrajectoryStateOnSurface &trajState, const GeomDetUnit *it)
Definition: DeDxTools.cc:426
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
bool isValid() const
Definition: ESHandle.h:44
Definition: DetId.h:17
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void addColumn(nanoaod::FlatTable *table, const std::string &name, VALUES &&values, const std::string &doc)
const edm::ESGetToken< SiStripGain, SiStripGainRcd > m_gainToken
bool isPixel(HitType hitType)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > m_tkGeomToken
Log< level::Warning, false > LogWarning
SiStripGainCalibTableProducer(const edm::ParameterSet &params)