CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripFineDelayHit.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripFineDelayHit
4 // Class: SiStripFineDelayHit
5 //
13 //
14 // Original Author: Christophe DELAERE
15 // Created: Fri Nov 17 10:52:42 CET 2006
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <utility>
22 #include <vector>
23 #include <algorithm>
24 
25 // user include files
34 
48 
58 
60 
64 
65 #include "TMath.h"
66 
67 //
68 // constructors and destructor
69 //
71  //register your products
72  produces<edm::DetSetVector<SiStripRawDigi> >("FineDelaySelection");
73  //now do what ever other initialization is needed
75  cosmic_ = iConfig.getParameter<bool>("cosmic");
76  field_ = iConfig.getParameter<bool>("MagneticField");
77  maxAngle_ = iConfig.getParameter<double>("MaxTrackAngle");
78  minTrackP2_ = iConfig.getParameter<double>("MinTrackMomentum") * iConfig.getParameter<double>("MinTrackMomentum");
79  maxClusterDistance_ = iConfig.getParameter<double>("MaxClusterDistance");
80  /*
81  clusterLabel_ = iConfig.getParameter<edm::InputTag>("ClustersLabel");
82  trackLabel_ = iConfig.getParameter<edm::InputTag>("TracksLabel");
83  seedLabel_ = iConfig.getParameter<edm::InputTag>("SeedsLabel");
84  inputModuleLabel_ = iConfig.getParameter<edm::InputTag>( "InputModuleLabel" ) ;
85  digiLabel_ = iConfig.getParameter<edm::InputTag>("DigiLabel");
86  */
88  consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("ClustersLabel"));
89  trackToken_ = consumes<std::vector<Trajectory> >(iConfig.getParameter<edm::InputTag>("TracksLabel"));
90  trackCollectionToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("TracksLabel"));
91  seedcollToken_ = consumes<TrajectorySeedCollection>(iConfig.getParameter<edm::InputTag>("SeedsLabel"));
92  inputModuleToken_ = consumes<SiStripEventSummary>(iConfig.getParameter<edm::InputTag>("InputModuleLabel"));
93  digiToken_ = consumes<edm::DetSetVector<SiStripDigi> >(iConfig.getParameter<edm::InputTag>("DigiLabel"));
94 
95  homeMadeClusters_ = iConfig.getParameter<bool>("NoClustering");
96  explorationWindow_ = iConfig.getParameter<uint32_t>("ExplorationWindow");
97  noTracking_ = iConfig.getParameter<bool>("NoTracking");
98  mode_ = 0;
99 
102  fedCablingToken_ = esConsumes<edm::Transition::BeginRun>();
104 }
105 
107  // do anything here that needs to be done at desctruction time
108  // (e.g. close files, deallocate resources etc.)
109  delete anglefinder_;
110 }
111 
112 //
113 // member functions
114 //
116  const int substructure,
117  const TrackerTopology* tkrTopo) {
118  uint32_t rootDetId = 0;
119  uint32_t maskDetId = 0;
120 
121  switch (subdet) {
122  case StripSubdetector::TIB: {
123  rootDetId = tkrTopo->tibDetId(substructure, 0, 0, 0, 0, 0).rawId();
124  maskDetId = tkrTopo->tibDetId(15, 0, 0, 0, 0, 0).rawId();
125  break;
126  }
127  case StripSubdetector::TID: {
128  rootDetId = tkrTopo->tidDetId(substructure > 0 ? 2 : 1, abs(substructure), 0, 0, 0, 0).rawId();
129  maskDetId = tkrTopo->tidDetId(3, 15, 0, 0, 0, 0).rawId();
130  break;
131  }
132  case StripSubdetector::TOB: {
133  rootDetId = tkrTopo->tobDetId(substructure, 0, 0, 0, 0).rawId();
134  maskDetId = tkrTopo->tobDetId(15, 0, 0, 0, 0).rawId();
135  break;
136  }
137  case StripSubdetector::TEC: {
138  rootDetId = tkrTopo->tecDetId(substructure > 0 ? 2 : 1, abs(substructure), 0, 0, 0, 0, 0).rawId();
139  maskDetId = tkrTopo->tecDetId(3, 15, 0, 0, 0, 0, 0).rawId();
140  break;
141  }
142  default:
143  break;
144  }
145  return std::make_pair(maskDetId, rootDetId);
146 }
147 
148 std::vector<std::pair<uint32_t, std::pair<double, double> > > SiStripFineDelayHit::detId(
149  const TrackerGeometry& tracker,
150  const TrackerTopology* tkrTopo,
151  const reco::Track* tk,
152  const std::vector<Trajectory>& trajVec,
153  const StripSubdetector::SubDetector subdet,
154  const int substructure) {
155  if (substructure == 0xff)
156  return detId(tracker, tkrTopo, tk, trajVec, 0, 0);
157  // first determine the root detId we are looking for
158  DeviceMask mask = deviceMask(subdet, substructure, tkrTopo);
159  // then call the method that loops on recHits
160  return detId(tracker, tkrTopo, tk, trajVec, mask.first, mask.second);
161 }
162 
163 std::vector<std::pair<uint32_t, std::pair<double, double> > > SiStripFineDelayHit::detId(
164  const TrackerGeometry& tracker,
165  const TrackerTopology* tkrTopo,
166  const reco::Track* tk,
167  const std::vector<Trajectory>& trajVec,
168  const uint32_t& maskDetId,
169  const uint32_t& rootDetId) {
170  bool onDisk = ((maskDetId == tkrTopo->tidDetId(3, 15, 0, 0, 0, 0).rawId()) ||
171  (maskDetId == tkrTopo->tecDetId(3, 15, 0, 0, 0, 0, 0).rawId()));
172  std::vector<std::pair<uint32_t, std::pair<double, double> > > result;
173  std::vector<uint32_t> usedDetids;
174  // now loop on recHits to find the right detId plus the track local angle
175  std::vector<std::pair<std::pair<DetId, LocalPoint>, float> > hitangle;
176  if (!cosmic_) {
177  // use trajectories in event.
178  // we have first to find the right trajectory for the considered track.
179  for (std::vector<Trajectory>::const_iterator traj = trajVec.begin(); traj < trajVec.end(); ++traj) {
180  if (((traj->lastMeasurement().recHit()->geographicalId().rawId() ==
181  (*(tk->recHitsEnd() - 1))->geographicalId().rawId()) &&
182  (traj->lastMeasurement().recHit()->localPosition().x() == (*(tk->recHitsEnd() - 1))->localPosition().x())) ||
183  ((traj->firstMeasurement().recHit()->geographicalId().rawId() ==
184  (*(tk->recHitsEnd() - 1))->geographicalId().rawId()) &&
185  (traj->firstMeasurement().recHit()->localPosition().x() == (*(tk->recHitsEnd() - 1))->localPosition().x()))) {
186  hitangle = anglefinder_->findtrackangle(*traj);
187  break;
188  }
189  }
190  } else {
192  // event_->getByLabel(seedLabel_,seedcoll);
193  event_->getByToken(seedcollToken_, seedcoll);
194  // use trajectories in event.
195  hitangle = anglefinder_->findtrackangle(trajVec);
196  }
197  LogDebug("DetId") << "number of hits for the track: " << hitangle.size();
198  std::vector<std::pair<std::pair<DetId, LocalPoint>, float> >::iterator iter;
199  // select the interesting DetIds, based on the ID and TLA
200  for (iter = hitangle.begin(); iter != hitangle.end(); iter++) {
201  // check the detId.
202  // if substructure was 0xff, then maskDetId and rootDetId == 0
203  // this implies all detids are accepted. (also if maskDetId=rootDetId=0 explicitely).
204  // That "unusual" mode of operation allows to analyze also Latency scans
205  LogDebug("DetId") << "check the detid: " << std::hex << (iter->first.first.rawId()) << " vs " << rootDetId
206  << " with a mask of " << maskDetId << std::dec << std::endl;
207 
208  if (((iter->first.first.rawId() & maskDetId) != rootDetId))
209  continue;
210  if (std::find(usedDetids.begin(), usedDetids.end(), iter->first.first.rawId()) != usedDetids.end())
211  continue;
212  // check the local angle (extended to the equivalent angle correction)
213  LogDebug("DetId") << "check the angle: " << fabs((iter->second));
214  if (1 - fabs(fabs(iter->second) - 1) < cos(maxAngle_ / 180. * TMath::Pi()))
215  continue;
216  // returns the detid + the time of flight to there
217  std::pair<uint32_t, std::pair<double, double> > el;
218  std::pair<double, double> subel;
219  el.first = iter->first.first.rawId();
220  // here, we compute the TOF.
221  // For cosmics, some track parameters are missing. Parameters are recomputed.
222  // for our calculation, the track momemtum at any point is enough:
223  // only used without B field or for the sign of Pz.
224  double trackParameters[5];
225  for (int i = 0; i < 5; i++)
226  trackParameters[i] = tk->parameters()[i];
227  if (cosmic_)
228  SiStripFineDelayTOF::trackParameters(*tk, trackParameters);
229  double hit[3];
230  const GeomDetUnit* det(tracker.idToDetUnit(iter->first.first));
231  Surface::GlobalPoint gp = det->surface().toGlobal(iter->first.second);
232  hit[0] = gp.x();
233  hit[1] = gp.y();
234  hit[2] = gp.z();
235  double phit[3];
236  phit[0] = tk->momentum().x();
237  phit[1] = tk->momentum().y();
238  phit[2] = tk->momentum().z();
239  subel.first = SiStripFineDelayTOF::timeOfFlight(cosmic_, field_, trackParameters, hit, phit, onDisk);
240  subel.second = iter->second;
241  el.second = subel;
242  // returns the detid + TOF
243  result.push_back(el);
244  usedDetids.push_back(el.first);
245  }
246  return result;
247 }
248 
249 bool SiStripFineDelayHit::rechit(reco::Track* tk, uint32_t det_id) {
250  for (trackingRecHit_iterator it = tk->recHitsBegin(); it != tk->recHitsEnd(); it++)
251  if ((*it)->geographicalId().rawId() == det_id) {
252  return (*it)->isValid();
253  break;
254  }
255  return false;
256 }
257 
258 // VI January 2012: FIXME
259 // do not understand what is going on here: each hit has a cluster: by definition will be the closest!
260 std::pair<const SiStripCluster*, double> SiStripFineDelayHit::closestCluster(
261  const TrackerGeometry& tracker,
262  const reco::Track* tk,
263  const uint32_t& det_id,
265  const edm::DetSetVector<SiStripDigi>& hits) {
266  std::pair<const SiStripCluster*, double> result(nullptr, 0.);
267  double hitStrip = -1;
268  int nstrips = -1;
269  // localize the crossing point of the track on the module
270  for (trackingRecHit_iterator it = tk->recHitsBegin(); it != tk->recHitsEnd(); it++) {
271  LogDebug("closestCluster") << "(*it)->geographicalId().rawId() vs det_id" << (*it)->geographicalId().rawId() << " "
272  << det_id;
273  //handle the mono rechits
274  if ((*it)->geographicalId().rawId() == det_id) {
275  if (!(*it)->isValid())
276  continue;
277  LogDebug("closestCluster") << " using the single mono hit";
278  LocalPoint lp = (*it)->localPosition();
279  const GeomDetUnit* gdu = static_cast<const GeomDetUnit*>(tracker.idToDet((*it)->geographicalId()));
281  hitStrip = p.x();
282  nstrips = (dynamic_cast<const StripTopology*>(&(gdu->topology())))->nstrips();
283  break;
284  }
285  /* FIXME: local position is not there anymore...
286  //handle stereo part of matched hits
287  //one could try to cast to SiStripMatchedRecHit2D but it is faster to look at the detid
288  else if((det_id - (*it)->geographicalId().rawId())==1) {
289  const SiStripMatchedRecHit2D* hit2D = dynamic_cast<const SiStripMatchedRecHit2D*>(&(**it));
290  if(!hit2D) continue; // this is a security that should never trigger
291  const SiStripRecHit2D* stereo = hit2D->stereoHit();
292  if(!stereo) continue; // this is a security that should never trigger
293  if(!stereo->isValid()) continue;
294  LogDebug("closestCluster") << " using the stereo hit";
295  LocalPoint lp = stereo->localPosition();
296  const GeomDetUnit* gdu = static_cast<const GeomDetUnit*>(tracker.idToDet(stereo->geographicalId()));
297  MeasurementPoint p = gdu->topology().measurementPosition(lp);
298  hitStrip = p.x();
299  nstrips = (dynamic_cast<const StripTopology*>(&(gdu->topology())))->nstrips();
300  break;
301  }
302  //handle mono part of matched hits
303  //one could try to cast to SiStripMatchedRecHit2D but it is faster to look at the detid
304  else if((det_id - (*it)->geographicalId().rawId())==2) {
305  const SiStripMatchedRecHit2D* hit2D = dynamic_cast<const SiStripMatchedRecHit2D*>(&(**it));
306  if(!hit2D) continue; // this is a security that should never trigger
307  const SiStripRecHit2D* mono = hit2D->monoHit();
308  if(!mono) continue; // this is a security that should never trigger
309  if(!mono->isValid()) continue;
310  LogDebug("closestCluster") << " using the mono hit";
311  LocalPoint lp = mono->localPosition();
312  const GeomDetUnit* gdu = static_cast<const GeomDetUnit*>(tracker.idToDet(mono->geographicalId()));
313  MeasurementPoint p = gdu->topology().measurementPosition(lp);
314  hitStrip = p.x();
315  nstrips = (dynamic_cast<const StripTopology*>(&(gdu->topology())))->nstrips();
316  break;
317  }
318  */
319  }
320  LogDebug("closestCluster") << " hit strip = " << hitStrip;
321  if (hitStrip < 0)
322  return result;
323  if (homeMadeClusters_) {
324  // take the list of digis on the module
325  for (edm::DetSetVector<SiStripDigi>::const_iterator DSViter = hits.begin(); DSViter != hits.end(); DSViter++) {
326  if (DSViter->id == det_id) {
327  // loop from hitstrip-n to hitstrip+n (explorationWindow_) and select the highest strip
328  int minStrip = int(round(hitStrip)) - explorationWindow_;
329  minStrip = minStrip < 0 ? 0 : minStrip;
330  int maxStrip = int(round(hitStrip)) + explorationWindow_ + 1;
331  maxStrip = maxStrip >= nstrips ? nstrips - 1 : maxStrip;
332  edm::DetSet<SiStripDigi>::const_iterator rangeStart = DSViter->end();
333  edm::DetSet<SiStripDigi>::const_iterator rangeStop = DSViter->end();
334  for (edm::DetSet<SiStripDigi>::const_iterator digiIt = DSViter->begin(); digiIt != DSViter->end(); ++digiIt) {
335  if (digiIt->strip() >= minStrip && rangeStart == DSViter->end())
336  rangeStart = digiIt;
337  if (digiIt->strip() <= maxStrip)
338  rangeStop = digiIt;
339  }
340  if (rangeStart != DSViter->end()) {
341  if (rangeStop != DSViter->end())
342  ++rangeStop;
343  // build a fake cluster
344  LogDebug("closestCluster") << "build a fake cluster ";
345  SiStripCluster* newCluster =
346  new SiStripCluster(SiStripCluster::SiStripDigiRange(rangeStart, rangeStop)); // /!\ ownership transfered
347  result.first = newCluster;
348  result.second = fabs(newCluster->barycenter() - hitStrip);
349  }
350  break;
351  }
352  }
353  } else {
354  // loop on the detsetvector<cluster> to find the right one
355  for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter = clusters.begin(); DSViter != clusters.end();
356  DSViter++)
357  if (DSViter->id() == det_id) {
358  LogDebug("closestCluster") << " detset with the right detid. ";
361  //find the cluster close to the hitStrip
362  result.second = 1000.;
363  for (edmNew::DetSet<SiStripCluster>::const_iterator iter = begin; iter != end; ++iter) {
364  double dist = fabs(iter->barycenter() - hitStrip);
365  if (dist < result.second) {
366  result.second = dist;
367  result.first = &(*iter);
368  }
369  }
370  break;
371  }
372  }
373  return result;
374 }
375 
376 // ------------ method called to produce the data ------------
378  using namespace edm;
379  // Retrieve commissioning information from "event summary"
381  // iEvent.getByLabel( inputModuleLabel_, runsummary );
382  iEvent.getByToken(inputModuleToken_, runsummary);
383  if (runsummary->runType() == sistrip::APV_LATENCY)
384  mode_ = 2; // LatencyScan
385  else if (runsummary->runType() == sistrip::FINE_DELAY)
386  mode_ = 1; // DelayScan
387  else {
388  mode_ = 0; //unknown
389  return;
390  }
391 
392  if (noTracking_) {
393  produceNoTracking(iEvent, iSetup);
394  return;
395  }
396  event_ = &iEvent;
397  // container for the selected hits
398  std::vector<edm::DetSet<SiStripRawDigi> > output;
399  output.reserve(100);
400  // access the tracks
402  // iEvent.getByLabel(trackLabel_,trackCollection);
404  const reco::TrackCollection* tracks = trackCollection.product();
405  const auto& tracker = iSetup.getData(tkGeomToken_);
406  if (!tracks->empty()) {
407  anglefinder_->init(iEvent, iSetup);
408  LogDebug("produce") << "Found " << tracks->size() << " tracks.";
409  // look at the hits if one needs them
411  const edm::DetSetVector<SiStripDigi>* hitSet = nullptr;
412  if (homeMadeClusters_) {
413  // iEvent.getByLabel(digiLabel_,hits);
414  iEvent.getByToken(digiToken_, hits);
415  hitSet = hits.product();
416  }
417  // look at the clusters
419  // iEvent.getByLabel(clusterLabel_, clusters);
420  iEvent.getByToken(clustersToken_, clusters);
421  const edmNew::DetSetVector<SiStripCluster>* clusterSet = clusters.product();
422  // look at the trajectories if they are in the event
423  std::vector<Trajectory> trajVec;
425  // iEvent.getByLabel(trackLabel_,TrajectoryCollection);
426  iEvent.getByToken(trackToken_, TrajectoryCollection);
427  trajVec = *(TrajectoryCollection.product());
428  // Get TrackerTopology
429  const auto tTopo = &iSetup.getData(tTopoToken_);
430  // loop on tracks
431  for (reco::TrackCollection::const_iterator itrack = tracks->begin(); itrack < tracks->end(); itrack++) {
432  // first check the track Pt
433  if ((itrack->px() * itrack->px() + itrack->py() * itrack->py() + itrack->pz() * itrack->pz()) < minTrackP2_)
434  continue;
435  // check that we have something in the layer we are interested in
436  std::vector<std::pair<uint32_t, std::pair<double, double> > > intersections;
437  if (mode_ == 1) {
438  // Retrieve and decode commissioning information from "event summary"
440  // iEvent.getByLabel( inputModuleLabel_, summary );
441  iEvent.getByToken(inputModuleToken_, summary);
442  uint32_t layerCode = (const_cast<SiStripEventSummary*>(summary.product())->layerScanned()) >> 16;
444  if (((layerCode >> 6) & 0x3) == 0)
445  subdet = StripSubdetector::TIB;
446  else if (((layerCode >> 6) & 0x3) == 1)
447  subdet = StripSubdetector::TOB;
448  else if (((layerCode >> 6) & 0x3) == 2)
449  subdet = StripSubdetector::TID;
450  else if (((layerCode >> 6) & 0x3) == 3)
451  subdet = StripSubdetector::TEC;
452  int32_t layerIdx = (layerCode & 0xF) * (((layerCode >> 4) & 0x3) ? -1 : 1);
453  intersections = detId(tracker, tTopo, &(*itrack), trajVec, subdet, layerIdx);
454  } else {
455  // for latency scans, no layer is specified -> no cut on detid
456  intersections = detId(tracker, tTopo, &(*itrack), trajVec);
457  }
458  LogDebug("produce") << " Found " << intersections.size() << " interesting intersections." << std::endl;
459  for (std::vector<std::pair<uint32_t, std::pair<double, double> > >::iterator it = intersections.begin();
460  it < intersections.end();
461  it++) {
462  std::pair<const SiStripCluster*, double> candidateCluster =
463  closestCluster(tracker, &(*itrack), it->first, *clusterSet, *hitSet);
464  if (candidateCluster.first) {
465  LogDebug("produce") << " Found a cluster." << std::endl;
466  // cut on the distance
467  if (candidateCluster.second > maxClusterDistance_)
468  continue;
469  LogDebug("produce") << " The cluster is close enough." << std::endl;
470  // build the rawdigi corresponding to the leading strip and save it
471  // here, only the leading strip is retained. All other rawdigis in the module are set to 0.
472  const auto& amplitudes = candidateCluster.first->amplitudes();
473  uint8_t leadingCharge = 0;
474  uint8_t leadingStrip = candidateCluster.first->firstStrip();
475  uint8_t leadingPosition = 0;
476  for (auto amplit = amplitudes.begin(); amplit < amplitudes.end(); amplit++, leadingStrip++) {
477  if (leadingCharge < *amplit) {
478  leadingCharge = *amplit;
479  leadingPosition = leadingStrip;
480  }
481  }
482 
483  // look for an existing detset
484  std::vector<edm::DetSet<SiStripRawDigi> >::iterator newdsit = output.begin();
485  for (; newdsit != output.end() && newdsit->detId() != connectionMap_[it->first]; ++newdsit) {
486  }
487  // if there is no detset yet, create it.
488  if (newdsit == output.end()) {
490  output.push_back(newds);
491  newdsit = output.end() - 1;
492  }
493 
494  LogDebug("produce") << " New Hit... TOF:" << it->second.first << ", charge: " << int(leadingCharge)
495  << " at " << int(leadingPosition) << "." << std::endl
496  << "Angular correction: " << it->second.second << " giving a final value of "
497  << int(leadingCharge * fabs(it->second.second))
498  << " for fed key = " << connectionMap_[it->first] << " (detid=" << it->first << ")";
499  // apply corrections to the leading charge, but only if it has not saturated.
500  if (leadingCharge < 255) {
501  // correct the leading charge for the crossing angle
502  leadingCharge = uint8_t(leadingCharge * fabs(it->second.second));
503  // correct for module thickness for TEC and TOB
504  if ((((it->first >> 25) & 0x7f) == 0xd) ||
505  ((((it->first >> 25) & 0x7f) == 0xe) && (((it->first >> 5) & 0x7) > 4)))
506  leadingCharge = uint8_t((leadingCharge * 0.64));
507  }
508  //code the time of flight in the digi
509  unsigned int tof = abs(int(round(it->second.first * 10)));
510  tof = tof > 255 ? 255 : tof;
511  SiStripRawDigi newSiStrip(leadingCharge + (tof << 8));
512  newdsit->push_back(newSiStrip);
513  LogDebug("produce") << "New edm::DetSet<SiStripRawDigi> added.";
514  }
515  if (homeMadeClusters_)
516  delete candidateCluster.first; // we are owner of home-made clusters
517  }
518  }
519  }
520  // add the selected hits to the event.
521  LogDebug("produce") << "Putting " << output.size() << " new hits in the event.";
522  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > formatedOutput(new edm::DetSetVector<SiStripRawDigi>(output));
523  iEvent.put(std::move(formatedOutput), "FineDelaySelection");
524 }
525 
526 // Simple solution when tracking is not available/ not working
528  event_ = &iEvent;
529  // Get TrackerTopology
530  const auto tTopo = &iSetup.getData(tTopoToken_);
531  // container for the selected hits
532  std::vector<edm::DetSet<SiStripRawDigi> > output;
533  output.reserve(100);
534  // Retrieve and decode commissioning information from "event summary"
536  // iEvent.getByLabel( inputModuleLabel_, summary );
537  iEvent.getByToken(inputModuleToken_, summary);
538  uint32_t layerCode = (const_cast<SiStripEventSummary*>(summary.product())->layerScanned()) >> 16;
540  if (((layerCode >> 6) & 0x3) == 0)
541  subdet = StripSubdetector::TIB;
542  else if (((layerCode >> 6) & 0x3) == 1)
543  subdet = StripSubdetector::TOB;
544  else if (((layerCode >> 6) & 0x3) == 2)
545  subdet = StripSubdetector::TID;
546  else if (((layerCode >> 6) & 0x3) == 3)
547  subdet = StripSubdetector::TEC;
548  int32_t layerIdx = (layerCode & 0xF) * (((layerCode >> 4) & 0x3) ? -1 : 1);
549  DeviceMask mask = deviceMask(subdet, layerIdx, tTopo);
550  // look at the clusters
552  // iEvent.getByLabel(clusterLabel_,clusters);
553  iEvent.getByToken(clustersToken_, clusters);
554  for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter = clusters->begin(); DSViter != clusters->end();
555  DSViter++) {
556  // check that we are in the layer of interest
557  if (mode_ == 1 && ((DSViter->id() & mask.first) != mask.second))
558  continue;
559  // iterate over clusters
562  edm::DetSet<SiStripRawDigi> newds(connectionMap_[DSViter->id()]);
563  for (edmNew::DetSet<SiStripCluster>::const_iterator iter = begin; iter != end; ++iter) {
564  // build the rawdigi corresponding to the leading strip and save it
565  // here, only the leading strip is retained. All other rawdigis in the module are set to 0.
566  auto const& amplitudes = iter->amplitudes();
567  uint8_t leadingCharge = 0;
568  uint8_t leadingStrip = iter->firstStrip();
569  uint8_t leadingPosition = 0;
570  for (auto amplit = amplitudes.begin(); amplit < amplitudes.end(); amplit++, leadingStrip++) {
571  if (leadingCharge < *amplit) {
572  leadingCharge = *amplit;
573  leadingPosition = leadingStrip;
574  }
575  }
576  // apply some sanity cuts. This is needed since we don't use tracking to clean clusters
577  // 1.5< noise <8
578  // charge<250
579  // 50 > s/n > 10
580  const auto& noises = iSetup.getData(noiseToken_);
581  SiStripNoises::Range detNoiseRange = noises.getRange(DSViter->id());
582  float noise = noises.getNoise(leadingPosition, detNoiseRange);
583  if (noise < 1.5)
584  continue;
585  if (leadingCharge >= 250 || noise >= 8 || leadingCharge / noise > 50 || leadingCharge / noise < 10)
586  continue;
587  // apply some correction to the leading charge, but only if it has not saturated.
588  if (leadingCharge < 255) {
589  // correct for modulethickness for TEC and TOB
590  if ((((((DSViter->id()) >> 25) & 0x7f) == 0xd) || ((((DSViter->id()) >> 25) & 0x7f) == 0xe)) &&
591  ((((DSViter->id()) >> 5) & 0x7) > 4))
592  leadingCharge = uint8_t((leadingCharge * 0.64));
593  }
594  //code the time of flight == 0 in the digi
595  SiStripRawDigi newSiStrip(leadingCharge);
596  newds.push_back(newSiStrip);
597  }
598  //store into the detsetvector
599  output.push_back(newds);
600  LogDebug("produce") << "New edm::DetSet<SiStripRawDigi> added with fedkey = " << std::hex << std::setfill('0')
601  << std::setw(8) << connectionMap_[DSViter->id()] << std::dec;
602  }
603  // add the selected hits to the event.
604  LogDebug("produce") << "Putting " << output.size() << " new hits in the event.";
605  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > formatedOutput(new edm::DetSetVector<SiStripRawDigi>(output));
606  iEvent.put(std::move(formatedOutput), "FineDelaySelection");
607 }
608 
609 // ------------ method called once each job just before starting event loop ------------
611  // Retrieve FED cabling object
612  const auto& cabling = iSetup.getData(fedCablingToken_);
613  auto feds = cabling.fedIds();
614  for (auto fedid = feds.begin(); fedid < feds.end(); ++fedid) {
615  auto connections = cabling.fedConnections(*fedid);
616  for (std::vector<FedChannelConnection>::const_iterator conn = connections.begin(); conn < connections.end();
617  ++conn) {
618  /*
619  SiStripFedKey key(conn->fedId(),
620  SiStripFedKey::feUnit(conn->fedCh()),
621  SiStripFedKey::feChan(conn->fedCh()));
622  connectionMap_[conn->detId()] = key.key();
623  */
624  // the key is computed using an alternate formula for performance reasons.
625  connectionMap_[conn->detId()] = ((conn->fedId() & sistrip::invalid_) << 16) | (conn->fedCh() & sistrip::invalid_);
626  }
627  }
628 }
iterator end()
Definition: DetSet.h:58
const double Pi
static constexpr auto TEC
virtual void produceNoTracking(edm::Event &, const edm::EventSetup &)
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
virtual const Topology & topology() const
Definition: GeomDet.cc:67
std::pair< SiStripDigiIter, SiStripDigiIter > SiStripDigiRange
edm::EDGetTokenT< SiStripEventSummary > inputModuleToken_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void init(const edm::Event &e, const edm::EventSetup &c)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
auto const & tracks
cannot be loose
Constants and enumerated type for sistrip::RunType.
data_type const * const_iterator
Definition: DetSetNew.h:31
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
tuple result
Definition: mps_fire.py:311
std::vector< std::pair< uint32_t, std::pair< double, double > > > detId(const TrackerGeometry &tracker, const TrackerTopology *tkrTopo, const reco::Track *tk, const std::vector< Trajectory > &trajVec, const StripSubdetector::SubDetector subdet=StripSubdetector::TIB, const int substructure=0xff)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::vector< std::pair< std::pair< DetId, LocalPoint >, float > > findtrackangle(const std::vector< Trajectory > &traj)
list connections
Definition: shell.py:10
SiStripFineDelayHit(const edm::ParameterSet &)
std::pair< const SiStripCluster *, double > closestCluster(const TrackerGeometry &tracker, const reco::Track *tk, const uint32_t &detId, const edmNew::DetSetVector< SiStripCluster > &clusters, const edm::DetSetVector< SiStripDigi > &hits)
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noiseToken_
static double timeOfFlight(bool cosmics, bool field, double *trackParameters, double *hit, double *phit, bool onDisk)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
SiStripFineDelayTLA * anglefinder_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
def move
Definition: eostools.py:511
DetId tobDetId(uint32_t layer, uint32_t rod_fw_bw, uint32_t rod, uint32_t module, uint32_t ster) const
DetId tidDetId(uint32_t side, uint32_t wheel, uint32_t ring, uint32_t module_fw_bw, uint32_t module, uint32_t ster) const
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > clustersToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float barycenter() const
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
static void trackParameters(const reco::Track &tk, double *trackParameters)
static constexpr auto TOB
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
DeviceMask deviceMask(const StripSubdetector::SubDetector subdet, const int substructure, const TrackerTopology *tkrTopo)
const TrackerGeomDet * idToDet(DetId) const override
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
__shared__ int noise
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
edm::EDGetTokenT< TrajectorySeedCollection > seedcollToken_
tuple trackCollection
static constexpr auto TIB
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > digiToken_
T const * product() const
Definition: Handle.h:70
DetId tibDetId(uint32_t layer, uint32_t str_fw_bw, uint32_t str_int_ext, uint32_t str, uint32_t module, uint32_t ster) const
std::pair< uint32_t, uint32_t > DeviceMask
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static const uint16_t invalid_
Definition: Constants.h:16
bool rechit(reco::Track *tk, uint32_t detId)
std::map< uint32_t, uint32_t > connectionMap_
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< Trajectory > TrajectoryCollection
ParameterVector parameters() const
Track parameters with one-to-one correspondence to the covariance matrix.
Definition: TrackBase.h:711
const edm::Event * event_
void event_()
string end
Definition: dataset.py:937
tuple conn
Definition: getInfo.py:9
void produce(edm::Event &, const edm::EventSetup &) override
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
edm::EDGetTokenT< std::vector< Trajectory > > trackToken_
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:314
edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
T x() const
Definition: PV2DBase.h:43
static constexpr auto TID
DetId tecDetId(uint32_t side, uint32_t wheel, uint32_t petal_fw_bw, uint32_t petal, uint32_t ring, uint32_t module, uint32_t ster) const
const_iterator begin(bool update=false) const
Definition: Run.h:45
#define LogDebug(id)
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91