CMS 3D CMS Logo

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  auto clusterIdx = std::make_unique<std::vector<int>>(); //link: on trk cluster --> general cluster info
86  auto onTrkClusterIdx = std::make_unique<std::vector<int>>(size, -1); //link: general cluster info --> on track cluster
87  auto onTrkClustersBegin = std::make_unique<std::vector<int>>( tracks->size(), -1 ); //link: track --> on trk cluster
88  auto onTrkClustersEnd = std::make_unique<std::vector<int>>( tracks->size(), -1 ); //link: track --> on trk cluster
89  auto trackindex = std::make_unique<std::vector<int>>(); //link: on track cluster --> track
90  clusterIdx->reserve(size);
91  trackindex->reserve(size);
92 
93  auto trackmulti = std::make_unique<std::vector<unsigned int>>(); trackmulti ->reserve(size);
94  auto localtheta = std::make_unique<std::vector<float>>(); localtheta ->reserve(size);
95  auto localphi = std::make_unique<std::vector<float>>(); localphi ->reserve(size);
96  auto localpitch = std::make_unique<std::vector<float>>(); localpitch ->reserve(size);
97  auto localx = std::make_unique<std::vector<float>>(); localx ->reserve(size);
98  auto localy = std::make_unique<std::vector<float>>(); localy ->reserve(size);
99  auto localz = std::make_unique<std::vector<float>>(); localz ->reserve(size);
100  auto strip = std::make_unique<std::vector<float>>(); strip ->reserve(size);
101  auto globaltheta = std::make_unique<std::vector<float>>(); globaltheta ->reserve(size);
102  auto globalphi = std::make_unique<std::vector<float>>(); globalphi ->reserve(size);
103  auto globalx = std::make_unique<std::vector<float>>(); globalx ->reserve(size);
104  auto globaly = std::make_unique<std::vector<float>>(); globaly ->reserve(size);
105  auto globalz = std::make_unique<std::vector<float>>(); globalz ->reserve(size);
106  auto insidistance = std::make_unique<std::vector<float>>(); insidistance->reserve(size);
107  auto projwidth = std::make_unique<std::vector<float>>(); projwidth ->reserve(size);
108  auto BdotY = std::make_unique<std::vector<float>>(); BdotY ->reserve(size);
109  auto covered = std::make_unique<std::vector<float>>(); covered ->reserve(size);
110  auto rhlocalx = std::make_unique<std::vector<float>>(); rhlocalx ->reserve(size);
111  auto rhlocaly = std::make_unique<std::vector<float>>(); rhlocaly ->reserve(size);
112  auto rhlocalxerr = std::make_unique<std::vector<float>>(); rhlocalxerr->reserve(size);
113  auto rhlocalyerr = std::make_unique<std::vector<float>>(); rhlocalyerr->reserve(size);
114  auto rhglobalx = std::make_unique<std::vector<float>>(); rhglobalx ->reserve(size);
115  auto rhglobaly = std::make_unique<std::vector<float>>(); rhglobaly ->reserve(size);
116  auto rhglobalz = std::make_unique<std::vector<float>>(); rhglobalz ->reserve(size);
117  auto rhstrip = std::make_unique<std::vector<float>>(); rhstrip ->reserve(size);
118  auto rhmerr = std::make_unique<std::vector<float>>(); rhmerr ->reserve(size);
119  auto ubstrip = std::make_unique<std::vector<float>>(); ubstrip ->reserve(size);
120  auto ubmerr = std::make_unique<std::vector<float>>(); ubmerr ->reserve(size);
121  auto driftx = std::make_unique<std::vector<float>>(); driftx ->reserve(size);
122  auto drifty = std::make_unique<std::vector<float>>(); drifty ->reserve(size);
123  auto driftz = std::make_unique<std::vector<float>>(); driftz ->reserve(size);
124  auto globalZofunitlocalY = std::make_unique<std::vector<float>>(); globalZofunitlocalY->reserve(size);
125 
126  edm::ESHandle<TrackerGeometry> theTrackerGeometry; iSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
127  edm::ESHandle<MagneticField> magfield; iSetup.get<IdealMagneticFieldRecord>().get(magfield);
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 
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(std::move(clusterIdx ), Prefix + "clusterIdx" + Suffix );
231  iEvent.put(std::move(onTrkClusterIdx ), Prefix + "onTrkClusterIdx" + Suffix );
232  iEvent.put(std::move(onTrkClustersBegin), Prefix + "onTrkClustersBegin" + Suffix );
233  iEvent.put(std::move(onTrkClustersEnd ), Prefix + "onTrkClustersEnd" + Suffix );
234  iEvent.put(std::move(trackindex), Prefix + "trackindex" + Suffix );
235 
236  iEvent.put(std::move(trackmulti), Prefix + "trackmulti" + Suffix );
237  iEvent.put(std::move(localtheta), Prefix + "localtheta" + Suffix );
238  iEvent.put(std::move(localphi), Prefix + "localphi" + Suffix );
239  iEvent.put(std::move(localpitch), Prefix + "localpitch" + Suffix );
240  iEvent.put(std::move(localx), Prefix + "localx" + Suffix );
241  iEvent.put(std::move(localy), Prefix + "localy" + Suffix );
242  iEvent.put(std::move(localz), Prefix + "localz" + Suffix );
243  iEvent.put(std::move(strip), Prefix + "strip" + Suffix );
244  iEvent.put(std::move(globaltheta), Prefix + "globaltheta" + Suffix );
245  iEvent.put(std::move(globalphi), Prefix + "globalphi" + Suffix );
246  iEvent.put(std::move(globalx), Prefix + "globalx" + Suffix );
247  iEvent.put(std::move(globaly), Prefix + "globaly" + Suffix );
248  iEvent.put(std::move(globalz), Prefix + "globalz" + Suffix );
249  iEvent.put(std::move(insidistance),Prefix + "insidistance"+ Suffix );
250  iEvent.put(std::move(covered), Prefix + "covered" + Suffix );
251  iEvent.put(std::move(projwidth), Prefix + "projwidth" + Suffix );
252  iEvent.put(std::move(BdotY), Prefix + "BdotY" + Suffix );
253  iEvent.put(std::move(rhlocalx), Prefix + "rhlocalx" + Suffix );
254  iEvent.put(std::move(rhlocaly), Prefix + "rhlocaly" + Suffix );
255  iEvent.put(std::move(rhlocalxerr), Prefix + "rhlocalxerr" + Suffix );
256  iEvent.put(std::move(rhlocalyerr), Prefix + "rhlocalyerr" + Suffix );
257  iEvent.put(std::move(rhglobalx), Prefix + "rhglobalx" + Suffix );
258  iEvent.put(std::move(rhglobaly), Prefix + "rhglobaly" + Suffix );
259  iEvent.put(std::move(rhglobalz), Prefix + "rhglobalz" + Suffix );
260  iEvent.put(std::move(rhstrip), Prefix + "rhstrip" + Suffix );
261  iEvent.put(std::move(rhmerr), Prefix + "rhmerr" + Suffix );
262  iEvent.put(std::move(ubstrip), Prefix + "ubstrip" + Suffix );
263  iEvent.put(std::move(ubmerr), Prefix + "ubmerr" + Suffix );
264  iEvent.put(std::move(driftx), Prefix + "driftx" + Suffix );
265  iEvent.put(std::move(drifty), Prefix + "drifty" + Suffix );
266  iEvent.put(std::move(driftz), Prefix + "driftz" + Suffix );
267  iEvent.put(std::move(globalZofunitlocalY), Prefix + "globalZofunitlocalY" + Suffix );
268 }
ClusterRef cluster() const
void produce(edm::Event &, const edm::EventSetup &) override
size
Write out results.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
ConstRecHitPointer const & recHit() const
ShallowTrackClustersProducer(const edm::ParameterSet &)
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
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
T y() const
Definition: PV3DBase.h:63
virtual float strip(const LocalPoint &) const =0
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
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
DataContainer const & measurements() const
Definition: Trajectory.h:196
int iEvent
Definition: GenABIO.cc:230
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
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
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_
const T & get() const
Definition: EventSetup.h:55
CLUSTERMAP make_cluster_map(const edm::Event &, const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > &)
Definition: ShallowTools.cc:14
SiStripCluster const & stereoCluster() const
fixed size matrix
HLT enums.
std::map< std::pair< uint32_t, uint16_t >, unsigned int > CLUSTERMAP
Definition: ShallowTools.h:19
const TrackerGeomDet * idToDet(DetId) const override
TrajectoryStateOnSurface const & updatedState() const
const_iterator begin() const
first iterator over the map (read only)
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
def move(src, dest)
Definition: eostools.py:510
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
GlobalVector globalDirection() const