CMS 3D CMS Logo

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