CMS 3D CMS Logo

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