test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ShallowTrackClustersProducer.cc
Go to the documentation of this file.
2 
4 
10 
22 #include "boost/foreach.hpp"
23 
25 #include <map>
26 
28  : tracks_token_(consumes<edm::View<reco::Track> >(iConfig.getParameter<edm::InputTag>("Tracks"))),
29  association_token_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("Tracks"))),
30  clusters_token_( consumes< edmNew::DetSetVector<SiStripCluster> >( iConfig.getParameter<edm::InputTag>("Clusters") ) ),
31  Suffix ( iConfig.getParameter<std::string>("Suffix") ),
32  Prefix ( iConfig.getParameter<std::string>("Prefix") )
33 {
34  produces<std::vector<int> > ( Prefix + "clusterIdx" + Suffix ); //link: on trk cluster --> general cluster info
35  produces<std::vector<int> > ( Prefix + "onTrkClusterIdx" + Suffix ); //link: general cluster info --> on track cluster
36  produces <std::vector<int> > ( Prefix + "onTrkClustersBegin" + Suffix ); //link: track --> onTrkInfo (range)
37  produces <std::vector<int> > ( Prefix + "onTrkClustersEnd" + Suffix ); //link: track --> onTrkInfo (range)
38  produces <std::vector<int> > ( Prefix + "trackindex" + Suffix ); //link: on trk cluster --> track index
39 
40  produces <std::vector<unsigned int> > ( Prefix + "trackmulti" + Suffix );
41  produces <std::vector<float> > ( Prefix + "localtheta" + Suffix );
42  produces <std::vector<float> > ( Prefix + "localphi" + Suffix );
43  produces <std::vector<float> > ( Prefix + "localpitch" + Suffix );
44  produces <std::vector<float> > ( Prefix + "localx" + Suffix );
45  produces <std::vector<float> > ( Prefix + "localy" + Suffix );
46  produces <std::vector<float> > ( Prefix + "localz" + Suffix );
47  produces <std::vector<float> > ( Prefix + "strip" + Suffix );
48  produces <std::vector<float> > ( Prefix + "globaltheta" + Suffix );
49  produces <std::vector<float> > ( Prefix + "globalphi" + Suffix );
50  produces <std::vector<float> > ( Prefix + "globalx" + Suffix );
51  produces <std::vector<float> > ( Prefix + "globaly" + Suffix );
52  produces <std::vector<float> > ( Prefix + "globalz" + Suffix );
53  produces <std::vector<float> > ( Prefix + "insidistance"+ Suffix );
54  produces <std::vector<float> > ( Prefix + "covered" + Suffix );
55  produces <std::vector<float> > ( Prefix + "projwidth" + Suffix );
56  produces <std::vector<float> > ( Prefix + "BdotY" + Suffix );
57 
58  produces <std::vector<float> > ( Prefix + "rhlocalx" + Suffix );
59  produces <std::vector<float> > ( Prefix + "rhlocaly" + Suffix );
60  produces <std::vector<float> > ( Prefix + "rhlocalxerr" + Suffix );
61  produces <std::vector<float> > ( Prefix + "rhlocalyerr" + Suffix );
62  produces <std::vector<float> > ( Prefix + "rhglobalx" + Suffix );
63  produces <std::vector<float> > ( Prefix + "rhglobaly" + Suffix );
64  produces <std::vector<float> > ( Prefix + "rhglobalz" + Suffix );
65  produces <std::vector<float> > ( Prefix + "rhstrip" + Suffix );
66  produces <std::vector<float> > ( Prefix + "rhmerr" + Suffix );
67 
68  produces <std::vector<float> > ( Prefix + "ubstrip" + Suffix );
69  produces <std::vector<float> > ( Prefix + "ubmerr" + Suffix );
70 
71  produces <std::vector<float> > ( Prefix + "driftx" + Suffix );
72  produces <std::vector<float> > ( Prefix + "drifty" + Suffix );
73  produces <std::vector<float> > ( Prefix + "driftz" + Suffix );
74  produces <std::vector<float> > ( Prefix + "globalZofunitlocalY" + Suffix );
75 }
76 
81 
82  int size = clustermap.size();
83 
84  //links
85  std::auto_ptr<std::vector<int> > clusterIdx ( new std::vector<int>() ); //link: on trk cluster --> general cluster info
86  std::auto_ptr<std::vector<int> > onTrkClusterIdx ( new std::vector<int>(size, -1) ); //link: general cluster info --> on track cluster
87  std::auto_ptr<std::vector<int> > onTrkClustersBegin (new std::vector<int>( tracks->size(), -1 ) ); //link: track --> on trk cluster
88  std::auto_ptr<std::vector<int> > onTrkClustersEnd (new std::vector<int>( tracks->size(), -1 ) ); //link: track --> on trk cluster
89  std::auto_ptr<std::vector<int> > trackindex ( new std::vector<int>() ); //link: on track cluster --> track
90  clusterIdx->reserve(size);
91  trackindex->reserve(size);
92 
93  std::auto_ptr<std::vector<unsigned int> > trackmulti ( new std::vector<unsigned int>()); trackmulti ->reserve(size);
94  std::auto_ptr<std::vector<float> > localtheta ( new std::vector<float> ()); localtheta ->reserve(size);
95  std::auto_ptr<std::vector<float> > localphi ( new std::vector<float> ()); localphi ->reserve(size);
96  std::auto_ptr<std::vector<float> > localpitch ( new std::vector<float> ()); localpitch ->reserve(size);
97  std::auto_ptr<std::vector<float> > localx ( new std::vector<float> ()); localx ->reserve(size);
98  std::auto_ptr<std::vector<float> > localy ( new std::vector<float> ()); localy ->reserve(size);
99  std::auto_ptr<std::vector<float> > localz ( new std::vector<float> ()); localz ->reserve(size);
100  std::auto_ptr<std::vector<float> > strip ( new std::vector<float> ()); strip ->reserve(size);
101  std::auto_ptr<std::vector<float> > globaltheta ( new std::vector<float> ()); globaltheta ->reserve(size);
102  std::auto_ptr<std::vector<float> > globalphi ( new std::vector<float> ()); globalphi ->reserve(size);
103  std::auto_ptr<std::vector<float> > globalx ( new std::vector<float> ()); globalx ->reserve(size);
104  std::auto_ptr<std::vector<float> > globaly ( new std::vector<float> ()); globaly ->reserve(size);
105  std::auto_ptr<std::vector<float> > globalz ( new std::vector<float> ()); globalz ->reserve(size);
106  std::auto_ptr<std::vector<float> > insidistance ( new std::vector<float> ()); insidistance->reserve(size);
107  std::auto_ptr<std::vector<float> > projwidth ( new std::vector<float> ()); projwidth ->reserve(size);
108  std::auto_ptr<std::vector<float> > BdotY ( new std::vector<float> ()); BdotY ->reserve(size);
109  std::auto_ptr<std::vector<float> > covered ( new std::vector<float> ()); covered ->reserve(size);
110  std::auto_ptr<std::vector<float> > rhlocalx ( new std::vector<float>()); rhlocalx ->reserve(size);
111  std::auto_ptr<std::vector<float> > rhlocaly ( new std::vector<float>()); rhlocaly ->reserve(size);
112  std::auto_ptr<std::vector<float> > rhlocalxerr( new std::vector<float>()); rhlocalxerr->reserve(size);
113  std::auto_ptr<std::vector<float> > rhlocalyerr( new std::vector<float>()); rhlocalyerr->reserve(size);
114  std::auto_ptr<std::vector<float> > rhglobalx ( new std::vector<float>()); rhglobalx ->reserve(size);
115  std::auto_ptr<std::vector<float> > rhglobaly ( new std::vector<float>()); rhglobaly ->reserve(size);
116  std::auto_ptr<std::vector<float> > rhglobalz ( new std::vector<float>()); rhglobalz ->reserve(size);
117  std::auto_ptr<std::vector<float> > rhstrip ( new std::vector<float>()); rhstrip ->reserve(size);
118  std::auto_ptr<std::vector<float> > rhmerr ( new std::vector<float>()); rhmerr ->reserve(size);
119  std::auto_ptr<std::vector<float> > ubstrip ( new std::vector<float>()); ubstrip ->reserve(size);
120  std::auto_ptr<std::vector<float> > ubmerr ( new std::vector<float>()); ubmerr ->reserve(size);
121  std::auto_ptr<std::vector<float> > driftx ( new std::vector<float>()); driftx ->reserve(size);
122  std::auto_ptr<std::vector<float> > drifty ( new std::vector<float>()); drifty ->reserve(size);
123  std::auto_ptr<std::vector<float> > driftz ( new std::vector<float>()); driftz ->reserve(size);
124  std::auto_ptr<std::vector<float> > globalZofunitlocalY ( new std::vector<float>()); globalZofunitlocalY->reserve(size);
125 
126  edm::ESHandle<TrackerGeometry> theTrackerGeometry; iSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
129 
131 
133 
134  size_t ontrk_cluster_idx=0;
135  std::map<size_t, std::vector<size_t> > mapping; //cluster idx --> on trk cluster idx (multiple)
136 
137  for( TrajTrackAssociationCollection::const_iterator association = associations->begin();
138  association != associations->end(); association++) {
139  const Trajectory* traj = association->key.get();
140  const reco::Track* track = association->val.get();
141  int trk_idx = shallow::findTrackIndex(tracks, track);
142  size_t trk_strt_idx = ontrk_cluster_idx;
143 
144  BOOST_FOREACH( const TrajectoryMeasurement measurement, traj->measurements() ) {
145  const TrajectoryStateOnSurface tsos = measurement.updatedState();
146  const TrajectoryStateOnSurface unbiased = combiner(measurement.forwardPredictedState(), measurement.backwardPredictedState());
147 
148  const TrackingRecHit* hit = measurement.recHit()->hit();
149  const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
150  const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
151  const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
152 
153  for(unsigned h=0; h<2; h++) { //loop over possible Hit options (1D, 2D)
154  const SiStripCluster* cluster_ptr;
155  if(!matchedhit && h==1) continue;
156  else if( matchedhit && h==0) cluster_ptr = &matchedhit->monoCluster();
157  else if( matchedhit && h==1) cluster_ptr = &matchedhit->stereoCluster();
158  else if(hit2D) cluster_ptr = (hit2D->cluster()).get();
159  else if(hit1D) cluster_ptr = (hit1D->cluster()).get();
160  else continue;
161 
162  shallow::CLUSTERMAP::const_iterator cluster = clustermap.find( std::make_pair( hit->geographicalId().rawId(), cluster_ptr->firstStrip() ));
163  if(cluster == clustermap.end() ) throw cms::Exception("Logic Error") << "Cluster not found: this could be a configuration error" << std::endl;
164 
165  unsigned i = cluster->second;
166 
167  //find if cluster was already assigned to a previous track
168  auto already_visited = mapping.find(i);
169  int nassociations = 1;
170  if(already_visited != mapping.end()) {
171  nassociations += already_visited->second.size();
172  for(size_t idx : already_visited->second) {
173  trackmulti->at(idx)++;
174  }
175  already_visited->second.push_back(ontrk_cluster_idx);
176  }
177  else { //otherwise store this
178  std::vector<size_t> single = {ontrk_cluster_idx};
179  mapping.insert( std::make_pair(i, single) );
180  }
181 
182  const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTrackerGeometry->idToDet( hit->geographicalId() ) );
183  LocalVector drift = shallow::drift( theStripDet, *magfield, *SiStripLorentzAngle);
184 
185  if(nassociations == 1) onTrkClusterIdx->at(i) = ontrk_cluster_idx; //link: general cluster info --> on track cluster
186  clusterIdx->push_back( i ); //link: on trk cluster --> general cluster info
187  trackmulti->push_back( nassociations );
188  trackindex->push_back( trk_idx );
189  localtheta->push_back( (theStripDet->toLocal(tsos.globalDirection())).theta() );
190  localphi->push_back( (theStripDet->toLocal(tsos.globalDirection())).phi() );
191  localpitch->push_back( (theStripDet->specificTopology()).localPitch(theStripDet->toLocal(tsos.globalPosition())) );
192  localx->push_back( (theStripDet->toLocal(tsos.globalPosition())).x() );
193  localy->push_back( (theStripDet->toLocal(tsos.globalPosition())).y() );
194  localz->push_back( (theStripDet->toLocal(tsos.globalPosition())).z() );
195  strip->push_back( (theStripDet->specificTopology()).strip(theStripDet->toLocal(tsos.globalPosition())) );
196  globaltheta->push_back( tsos.globalDirection().theta() );
197  globalphi->push_back( tsos.globalDirection().phi() );
198  globalx->push_back( tsos.globalPosition().x() );
199  globaly->push_back( tsos.globalPosition().y() );
200  globalz->push_back( tsos.globalPosition().z() );
201  insidistance->push_back(1./fabs(cos(localtheta->at(ontrk_cluster_idx))) );
202  projwidth->push_back( tan(localtheta->at(ontrk_cluster_idx))*cos(localphi->at(ontrk_cluster_idx)) );
203  BdotY->push_back( (theStripDet->surface()).toLocal( magfield->inTesla(theStripDet->surface().position())).y() );
204  covered->push_back( drift.z()/localpitch->at(ontrk_cluster_idx) * fabs(projwidth->at(ontrk_cluster_idx) - drift.x()/drift.z()) );
205  rhlocalx->push_back( hit->localPosition().x() );
206  rhlocaly->push_back( hit->localPosition().y() );
207  rhlocalxerr->push_back( sqrt(hit->localPositionError().xx()) );
208  rhlocalyerr->push_back( sqrt(hit->localPositionError().yy()) );
209  rhglobalx->push_back( theStripDet->toGlobal(hit->localPosition()).x() );
210  rhglobaly->push_back( theStripDet->toGlobal(hit->localPosition()).y() );
211  rhglobalz->push_back( theStripDet->toGlobal(hit->localPosition()).z() );
212  rhstrip->push_back( theStripDet->specificTopology().strip(hit->localPosition()) );
213  rhmerr->push_back( sqrt(theStripDet->specificTopology().measurementError(hit->localPosition(), hit->localPositionError()).uu()) );
214  ubstrip->push_back( theStripDet->specificTopology().strip(unbiased.localPosition()) );
215  ubmerr->push_back( sqrt(theStripDet->specificTopology().measurementError(unbiased.localPosition(), unbiased.localError().positionError()).uu()) );
216  driftx->push_back( drift.x() );
217  drifty->push_back( drift.y() );
218  driftz->push_back( drift.z() );
219  globalZofunitlocalY->push_back( (theStripDet->toGlobal(LocalVector(0,1,0))).z() );
220 
221  ontrk_cluster_idx++;
222  } //for(unsigned h=0; h<2; h++) { //loop over possible Hit options (1D, 2D)
223  } //BOOST_FOREACH( const TrajectoryMeasurement measurement, traj->measurements() )
224 
225  onTrkClustersBegin->at(trk_idx) = trk_strt_idx;
226  onTrkClustersEnd->at(trk_idx) = ontrk_cluster_idx;
227 
228  } //for(TrajTrackAssociationCollection::const_iterator association = associations->begin();
229 
230  iEvent.put(clusterIdx , Prefix + "clusterIdx" + Suffix );
231  iEvent.put(onTrkClusterIdx , Prefix + "onTrkClusterIdx" + Suffix );
232  iEvent.put(onTrkClustersBegin, Prefix + "onTrkClustersBegin" + Suffix );
233  iEvent.put(onTrkClustersEnd , Prefix + "onTrkClustersEnd" + Suffix );
234  iEvent.put(trackindex, Prefix + "trackindex" + Suffix );
235 
236  iEvent.put(trackmulti, Prefix + "trackmulti" + Suffix );
237  iEvent.put(localtheta, Prefix + "localtheta" + Suffix );
238  iEvent.put(localphi, Prefix + "localphi" + Suffix );
239  iEvent.put(localpitch, Prefix + "localpitch" + Suffix );
240  iEvent.put(localx, Prefix + "localx" + Suffix );
241  iEvent.put(localy, Prefix + "localy" + Suffix );
242  iEvent.put(localz, Prefix + "localz" + Suffix );
243  iEvent.put(strip, Prefix + "strip" + Suffix );
244  iEvent.put(globaltheta, Prefix + "globaltheta" + Suffix );
245  iEvent.put(globalphi, Prefix + "globalphi" + Suffix );
246  iEvent.put(globalx, Prefix + "globalx" + Suffix );
247  iEvent.put(globaly, Prefix + "globaly" + Suffix );
248  iEvent.put(globalz, Prefix + "globalz" + Suffix );
249  iEvent.put(insidistance,Prefix + "insidistance"+ Suffix );
250  iEvent.put(covered, Prefix + "covered" + Suffix );
251  iEvent.put(projwidth, Prefix + "projwidth" + Suffix );
252  iEvent.put(BdotY, Prefix + "BdotY" + Suffix );
253  iEvent.put(rhlocalx, Prefix + "rhlocalx" + Suffix );
254  iEvent.put(rhlocaly, Prefix + "rhlocaly" + Suffix );
255  iEvent.put(rhlocalxerr, Prefix + "rhlocalxerr" + Suffix );
256  iEvent.put(rhlocalyerr, Prefix + "rhlocalyerr" + Suffix );
257  iEvent.put(rhglobalx, Prefix + "rhglobalx" + Suffix );
258  iEvent.put(rhglobaly, Prefix + "rhglobaly" + Suffix );
259  iEvent.put(rhglobalz, Prefix + "rhglobalz" + Suffix );
260  iEvent.put(rhstrip, Prefix + "rhstrip" + Suffix );
261  iEvent.put(rhmerr, Prefix + "rhmerr" + Suffix );
262  iEvent.put(ubstrip, Prefix + "ubstrip" + Suffix );
263  iEvent.put(ubmerr, Prefix + "ubmerr" + Suffix );
264  iEvent.put( driftx, Prefix + "driftx" + Suffix );
265  iEvent.put( drifty, Prefix + "drifty" + Suffix );
266  iEvent.put( driftz, Prefix + "driftz" + Suffix );
267  iEvent.put( globalZofunitlocalY, Prefix + "globalZofunitlocalY" + Suffix );
268 }
ClusterRef cluster() const
int i
Definition: DBlmapReader.cc:9
tuple SiStripLorentzAngle
Definition: redigi_cff.py:15
ConstRecHitPointer const & recHit() const
ShallowTrackClustersProducer(const edm::ParameterSet &)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
int findTrackIndex(const edm::Handle< edm::View< reco::Track > > &h, const reco::Track *t)
Definition: ShallowTools.cc:28
SiStripCluster const & monoCluster() const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:38
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
tuple magfield
Definition: HLT_ES_cff.py:2311
T y() const
Definition: PV3DBase.h:63
void produce(edm::Event &, const edm::EventSetup &)
GlobalPoint globalPosition() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
uint16_t firstStrip() const
const edm::EDGetTokenT< edm::View< reco::Track > > tracks_token_
LocalVector toLocal(const reco::Track::Vector &v, const Surface &s)
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
LocalError positionError() const
virtual float strip(const LocalPoint &) const =0
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
DataContainer const & measurements() const
Definition: Trajectory.h:250
int iEvent
Definition: GenABIO.cc:230
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
ClusterRef cluster() const
const LocalTrajectoryError & localError() const
const edm::EDGetTokenT< TrajTrackAssociationCollection > association_token_
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > clusters_token_
tuple tracks
Definition: testEve_cfg.py:39
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const T & get() const
Definition: EventSetup.h:56
CLUSTERMAP make_cluster_map(const edm::Event &, const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > &)
Definition: ShallowTools.cc:14
SiStripCluster const & stereoCluster() const
std::map< std::pair< uint32_t, uint16_t >, unsigned int > CLUSTERMAP
Definition: ShallowTools.h:19
TrajectoryStateOnSurface const & updatedState() const
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
tuple size
Write out results.
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
GlobalVector globalDirection() const