CMS 3D CMS Logo

MuDTSegmentExtTableProducer.cc
Go to the documentation of this file.
1 
11 
14 
16 
17 #include <vector>
18 #include <array>
19 
22 
25 
28 
31 
33 public:
36 
39 
40 protected:
42  void fillTable(edm::Event&) final;
43 
45  void getFromES(const edm::Run&, const edm::EventSetup&) final;
46 
48  void getFromES(const edm::EventSetup&) final;
49 
50 private:
51  static const int FIRST_LAYER{1};
52  static const int LAST_LAYER{4};
53  static const int THETA_SL{2};
56 
58  bool m_fillHits;
59 
61  bool m_fillExtr;
62 
65 
68 
70  std::unique_ptr<DTTTrigBaseSync> m_dtSync;
71 };
72 
75  m_token{config, consumesCollector(), "src"},
76  m_fillHits{config.getParameter<bool>("fillHits")},
77  m_fillExtr{config.getParameter<bool>("fillExtrapolation")},
78  m_dtGeometry{consumesCollector()},
79  m_trackingGeometry{consumesCollector()} {
80  produces<nanoaod::FlatTable>();
81  if (m_fillHits) {
82  produces<nanoaod::FlatTable>("hits");
83  }
84  if (m_fillExtr) {
85  produces<nanoaod::FlatTable>("extr");
86  }
87 
88  m_dtSync = DTTTrigSyncFactory::get()->create(config.getParameter<std::string>("tTrigMode"),
89  config.getParameter<edm::ParameterSet>("tTrigModeConfig"),
90  consumesCollector());
91 }
92 
95 
96  desc.add<std::string>("name", "dtSegment");
97  desc.add<edm::InputTag>("src", edm::InputTag{"dt4DSegments"});
98  desc.add<bool>("fillExtrapolation", true);
99  desc.add<bool>("fillHits", true);
100 
101  desc.add<std::string>("tTrigMode", "DTTTrigSyncFromDB");
102 
103  edm::ParameterSetDescription tTrigModeParams;
104  tTrigModeParams.add<bool>("doTOFCorrection", true);
105  tTrigModeParams.add<int>("tofCorrType", 2);
106 
107  tTrigModeParams.add<double>("vPropWire", 24.4);
108  tTrigModeParams.add<bool>("doWirePropCorrection", true);
109  tTrigModeParams.add<int>("wirePropCorrType", 0);
110 
111  tTrigModeParams.add<std::string>("tTrigLabel", "");
112  tTrigModeParams.add<bool>("doT0Correction", true);
113  tTrigModeParams.add<std::string>("t0Label", "");
114  tTrigModeParams.addUntracked<bool>("debug", false);
115 
116  desc.add<edm::ParameterSetDescription>("tTrigModeConfig", tTrigModeParams);
117 
118  descriptions.addWithDefaultLabel(desc);
119 }
120 
123 }
124 
127  m_dtSync->setES(environment);
128 }
129 
131  unsigned int nSegments{0};
132 
133  std::vector<float> seg4D_posLoc_x_SL1;
134  std::vector<float> seg4D_posLoc_x_SL3;
135  std::vector<float> seg4D_posLoc_x_midPlane;
136 
137  std::vector<uint32_t> seg4D_extr_begin;
138  std::vector<uint32_t> seg4D_extr_end;
139 
140  std::vector<uint32_t> seg2D_hits_begin;
141  std::vector<uint32_t> seg2D_hits_end;
142 
143  // segment extrapolation to DT layers filled, if m_fillExtr == true
144  unsigned int nExtr{0};
145 
146  std::vector<float> seg4D_hitsExpPos;
147  std::vector<float> seg4D_hitsExpPosCh;
148  std::vector<int16_t> seg4D_hitsExpWire;
149 
150  // rec-hits vectors, filled if m_fillHits == true
151  unsigned int nHits{0};
152 
153  std::vector<float> seg2D_hits_pos;
154  std::vector<float> seg2D_hits_posCh;
155  std::vector<float> seg2D_hits_posErr;
156  std::vector<int16_t> seg2D_hits_side;
157  std::vector<int16_t> seg2D_hits_wire;
158  std::vector<int16_t> seg2D_hits_wirePos;
159  std::vector<int16_t> seg2D_hits_layer;
160  std::vector<int16_t> seg2D_hits_superLayer;
161  std::vector<float> seg2D_hits_time;
162  std::vector<float> seg2D_hits_timeCali;
163 
164  auto fillHits = [&](const DTRecSegment2D* seg, const GeomDet* chamb) {
165  const auto& recHits = seg->specificRecHits();
166 
167  for (const auto& recHit : recHits) {
168  ++nHits;
169 
170  const auto wireId = recHit.wireId();
171  const auto layerId = wireId.layerId();
172  const auto* layer = m_dtGeometry->layer(layerId);
173 
174  seg2D_hits_pos.push_back(recHit.localPosition().x());
175  seg2D_hits_posCh.push_back(chamb->toLocal(layer->toGlobal(recHit.localPosition())).x());
176  seg2D_hits_posErr.push_back(recHit.localPositionError().xx());
177 
178  seg2D_hits_side.push_back(recHit.lrSide());
179  seg2D_hits_wire.push_back(wireId.wire());
180  seg2D_hits_wirePos.push_back(layer->specificTopology().wirePosition(wireId.wire()));
181  seg2D_hits_layer.push_back(layerId.layer());
182  seg2D_hits_superLayer.push_back(layerId.superlayer());
183 
184  auto digiTime = recHit.digiTime();
185 
186  auto tTrig = m_dtSync->offset(wireId);
187 
188  seg2D_hits_time.push_back(digiTime);
189  seg2D_hits_timeCali.push_back(digiTime - tTrig);
190  }
191  };
192 
193  auto segments4D = m_token.conditionalGet(ev);
194 
195  if (segments4D.isValid()) {
196  auto chambIt = segments4D->id_begin();
197  const auto chambEnd = segments4D->id_end();
198 
199  for (; chambIt != chambEnd; ++chambIt) {
200  const auto& range = segments4D->get(*chambIt);
201 
202  for (auto segment4D = range.first; segment4D != range.second; ++segment4D) {
203  auto station = (*chambIt).station();
204  auto wheel = (*chambIt).wheel();
205  auto sector = (*chambIt).sector();
206 
207  bool hasPhi = segment4D->hasPhi();
208  bool hasZed = segment4D->hasZed();
209 
210  auto pos = segment4D->localPosition();
211  auto dir = segment4D->localDirection();
212 
213  std::array<float, 2> xPosLocSL{{DEFAULT_DOUBLE_VAL, DEFAULT_DOUBLE_VAL}};
214  std::array<bool, 2> hasPptSL{{false, false}};
215  auto xPosLocMidPlane = DEFAULT_DOUBLE_VAL;
216 
217  const auto* chamb = m_dtGeometry->chamber(*chambIt);
218 
219  StraightLinePlaneCrossing segmentPlaneCrossing{
220  chamb->toGlobal(pos).basicVector(), chamb->toGlobal(dir).basicVector(), anyDirection};
221 
222  if (hasPhi) {
223  for (int iSL = 0; iSL < 2; ++iSL) {
224  const auto* sl = chamb->superLayer(1 + iSL * 2);
225 
226  auto pptSL = segmentPlaneCrossing.position(sl->surface());
227  hasPptSL[iSL] = pptSL.first;
228 
229  if (hasPptSL[iSL]) {
230  GlobalPoint segExrapolationToSL(pptSL.second);
231  xPosLocSL[iSL] = chamb->toLocal(segExrapolationToSL).x();
232  }
233  }
234  }
235 
236  seg4D_posLoc_x_SL1.push_back(xPosLocSL[0]);
237  seg4D_posLoc_x_SL3.push_back(xPosLocSL[1]);
238 
239  if (hasPptSL[0] && hasPptSL[1])
240  xPosLocMidPlane = (xPosLocSL[0] + xPosLocSL[1]) * 0.5;
241 
242  seg4D_posLoc_x_midPlane.push_back(xPosLocMidPlane);
243 
244  const auto begin = seg4D_hitsExpPos.size();
245 
246  const auto size{station == 4 ? 8 : 12};
247 
248  nExtr += size;
249  seg4D_extr_begin.push_back(begin);
250  seg4D_extr_end.push_back(begin + size);
251 
252  const auto iSLs = station < 4 ? std::vector{1, 2, 3} : std::vector{1, 3};
253 
254  for (int iL = FIRST_LAYER; iL <= LAST_LAYER; ++iL) {
255  for (const auto iSL : iSLs) {
256  auto* layer = m_dtGeometry->layer(DTWireId{wheel, station, sector, iSL, iL, 2});
257  auto ppt = segmentPlaneCrossing.position(layer->surface());
258 
259  bool success{ppt.first}; // check for failure
260 
261  auto expPos{DEFAULT_DOUBLE_VAL};
262  auto expPosCh{DEFAULT_DOUBLE_VAL};
263  auto expWire{DEFAULT_INT_VAL_POS};
264 
265  if (success) {
266  GlobalPoint segExrapolationToLayer(ppt.second);
267  LocalPoint segPosAtZWireLayer = layer->toLocal(segExrapolationToLayer);
268  LocalPoint segPosAtZWireChamber = chamb->toLocal(segExrapolationToLayer);
269 
270  if (hasPhi && iSL != THETA_SL) {
271  expPos = segPosAtZWireLayer.x();
272  expPosCh = segPosAtZWireChamber.x();
273  expWire = layer->specificTopology().channel(segPosAtZWireLayer);
274  } else if (hasZed && iSL == THETA_SL) {
275  expPos = segPosAtZWireLayer.x();
276  expPosCh = segPosAtZWireChamber.y();
277  expWire = layer->specificTopology().channel(segPosAtZWireLayer);
278  }
279  }
280 
281  seg4D_hitsExpPos.push_back(expPos);
282  seg4D_hitsExpPosCh.push_back(expPosCh);
283  seg4D_hitsExpWire.push_back(expWire);
284  }
285  }
286 
287  seg2D_hits_begin.push_back(seg2D_hits_pos.size());
288 
289  const GeomDet* geomDet = m_trackingGeometry->idToDet(segment4D->geographicalId());
290  if (hasPhi) {
291  fillHits(segment4D->phiSegment(), geomDet);
292  }
293 
294  if (hasZed) {
295  fillHits(segment4D->zSegment(), geomDet);
296  }
297 
298  seg2D_hits_end.push_back(seg2D_hits_pos.size());
299  ++nSegments;
300  }
301  }
302  }
303 
304  auto table = std::make_unique<nanoaod::FlatTable>(nSegments, m_name, false, true);
305 
306  table->setDoc("DT segment information");
307 
308  addColumn(table, "seg4D_posLoc_x_SL1", seg4D_posLoc_x_SL1, "position x at SL1 in local coordinates - cm");
309  addColumn(table, "seg4D_posLoc_x_SL3", seg4D_posLoc_x_SL3, "position x at SL3 in local coordinates - cm");
311  "seg4D_posLoc_x_midPlane",
312  seg4D_posLoc_x_midPlane,
313  "position x at SL1 - SL3 mid plane in local coordinates - cm");
314 
315  addColumn(table, "seg2D_hits_begin", seg2D_hits_begin, "begin() of range of quantities in the *_hits_* vectors");
316  addColumn(table, "seg2D_hits_end", seg2D_hits_end, "end() of range of quantities in the *_hits_* vectors");
317 
318  addColumn(table, "seg4D_extr_begin", seg4D_extr_begin, "begin() of range of quantities in the *_extr_* vectors");
319  addColumn(table, "seg4D_extr_end", seg4D_extr_end, "end() of range of quantities in the *_extr_* vectors");
320 
321  ev.put(std::move(table));
322 
323  if (m_fillHits) {
324  auto tabHits = std::make_unique<nanoaod::FlatTable>(nHits, m_name + "_hits", false, false);
325 
326  tabHits->setDoc("Size of DT segment *_hits_* vectors");
327 
328  addColumn(tabHits, "pos", seg2D_hits_pos, "local x position of a hit in layer local coordinates");
329  addColumn(tabHits, "posCh", seg2D_hits_posCh, "local x position of a hit in chamber local coordinates");
330  addColumn(tabHits,
331  "posErr",
332  seg2D_hits_posErr,
333  "local position error of a hit in layer local coordinates - xx component of error matrix");
334  addColumn(tabHits, "side", seg2D_hits_side, "is hit on L/R side of a cell wire - 1/2 is R/L");
335  addColumn(tabHits, "wire", seg2D_hits_wire, "hit wire number - range depends on chamber size");
336  addColumn(tabHits, "wirePos", seg2D_hits_wirePos, "hit wire x position in layer local coordinates");
337  addColumn(tabHits, "layer", seg2D_hits_layer, "hit layer number - range [1:4]");
338  addColumn(tabHits,
339  "superLayer",
340  seg2D_hits_superLayer,
341  "hit superlayer - [1:3] range"
342  "<br />SL 1 and 3 are phi SLs"
343  "<br />SL 2 is theta SL");
344  addColumn(tabHits, "time", seg2D_hits_time, "digi time - ns, pedestal not subtracted");
345  addColumn(tabHits, "timeCali", seg2D_hits_timeCali, "digi time - ns, pedestal subtracted");
346 
347  ev.put(std::move(tabHits), "hits");
348  }
349 
350  if (m_fillExtr) {
351  auto tabExtr = std::make_unique<nanoaod::FlatTable>(nExtr, m_name + "_extr", false, false);
352 
353  tabExtr->setDoc("Size of DT segment *_extr_* vectors");
354  addColumn(tabExtr,
355  "ExpPos",
356  seg4D_hitsExpPos,
357  "expected position of segment extrapolated"
358  "<br />to a given layer in layer local coordinates - cm");
359 
360  addColumn(tabExtr,
361  "ExpPosCh",
362  seg4D_hitsExpPosCh,
363  "expected position of segment extrapolated"
364  "<br />to a given layer in chhamber local coordinates - cm");
365 
366  addColumn(tabExtr,
367  "ExpWire",
368  seg4D_hitsExpWire,
369  "expected wire crossed by segment extrapolated"
370  "<br />to a given layer - range depends on chamber size");
371 
372  ev.put(std::move(tabExtr), "extr");
373  }
374 }
375 
378 
size
Write out results.
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void fillTable(edm::Event &) final
Fill tree branches for a given event.
nano_mu::ESTokenHandle< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > m_trackingGeometry
Tracking Geometry.
void getFromES(const edm::Run &, const edm::EventSetup &) final
Get info from the ES by run.
MuDTSegmentExtTableProducer(const edm::ParameterSet &)
Constructor.
Definition: config.py:1
auto conditionalGet(const edm::Event &ev) const
Definition: MuNtupleUtils.h:49
static constexpr double DEFAULT_DOUBLE_VAL
Definition of default values for float variables.
const GeomDet * idToDet(DetId) const override
void addColumn(std::unique_ptr< nanoaod::FlatTable > &table, const std::string name, const std::vector< T > &vec, const std::string descr)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
nano_mu::EDTokenHandle< DTRecSegment4DCollection > m_token
The segment token.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool m_fillExtr
Fill segment extrapolation table.
static constexpr int DEFAULT_INT_VAL_POS
Definition of default values for positive int variables.
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
std::string m_name
The label name of the FlatTableProducer.
static void fillDescriptions(edm::ConfigurationDescriptions &)
Fill descriptors.
void getFromES(const edm::EventSetup &environment)
Get Handle from ES.
Definition: MuNtupleUtils.h:73
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
std::unique_ptr< DTTTrigBaseSync > m_dtSync
Handle DT trigger time pedestals.
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
#define get
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
nano_mu::ESTokenHandle< DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun > m_dtGeometry
DT Geometry.
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96