CMS 3D CMS Logo

ShallowTrackClustersProducer.cc
Go to the documentation of this file.
2 
4 
10 
22 
24 #include <map>
25 
27  : tracks_token_(consumes<edm::View<reco::Track> >(iConfig.getParameter<edm::InputTag>("Tracks"))),
28  association_token_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("Tracks"))),
29  clusters_token_( consumes< edmNew::DetSetVector<SiStripCluster> >( iConfig.getParameter<edm::InputTag>("Clusters") ) ),
30  Suffix ( iConfig.getParameter<std::string>("Suffix") ),
31  Prefix ( iConfig.getParameter<std::string>("Prefix") )
32 {
33  produces<std::vector<int> > ( Prefix + "clusterIdx" + Suffix ); //link: on trk cluster --> general cluster info
34  produces<std::vector<int> > ( Prefix + "onTrkClusterIdx" + Suffix ); //link: general cluster info --> on track cluster
35  produces <std::vector<int> > ( Prefix + "onTrkClustersBegin" + Suffix ); //link: track --> onTrkInfo (range)
36  produces <std::vector<int> > ( Prefix + "onTrkClustersEnd" + Suffix ); //link: track --> onTrkInfo (range)
37  produces <std::vector<int> > ( Prefix + "trackindex" + Suffix ); //link: on trk cluster --> track index
38 
39  produces <std::vector<unsigned int> > ( Prefix + "trackmulti" + Suffix );
40  produces <std::vector<float> > ( Prefix + "localtheta" + Suffix );
41  produces <std::vector<float> > ( Prefix + "localphi" + Suffix );
42  produces <std::vector<float> > ( Prefix + "localpitch" + Suffix );
43  produces <std::vector<float> > ( Prefix + "localx" + Suffix );
44  produces <std::vector<float> > ( Prefix + "localy" + Suffix );
45  produces <std::vector<float> > ( Prefix + "localz" + Suffix );
46  produces <std::vector<float> > ( Prefix + "strip" + Suffix );
47  produces <std::vector<float> > ( Prefix + "globaltheta" + Suffix );
48  produces <std::vector<float> > ( Prefix + "globalphi" + Suffix );
49  produces <std::vector<float> > ( Prefix + "globalx" + Suffix );
50  produces <std::vector<float> > ( Prefix + "globaly" + Suffix );
51  produces <std::vector<float> > ( Prefix + "globalz" + Suffix );
52  produces <std::vector<float> > ( Prefix + "insidistance"+ Suffix );
53  produces <std::vector<float> > ( Prefix + "covered" + Suffix );
54  produces <std::vector<float> > ( Prefix + "projwidth" + Suffix );
55  produces <std::vector<float> > ( Prefix + "BdotY" + Suffix );
56 
57  produces <std::vector<float> > ( Prefix + "rhlocalx" + Suffix );
58  produces <std::vector<float> > ( Prefix + "rhlocaly" + Suffix );
59  produces <std::vector<float> > ( Prefix + "rhlocalxerr" + Suffix );
60  produces <std::vector<float> > ( Prefix + "rhlocalyerr" + Suffix );
61  produces <std::vector<float> > ( Prefix + "rhglobalx" + Suffix );
62  produces <std::vector<float> > ( Prefix + "rhglobaly" + Suffix );
63  produces <std::vector<float> > ( Prefix + "rhglobalz" + Suffix );
64  produces <std::vector<float> > ( Prefix + "rhstrip" + Suffix );
65  produces <std::vector<float> > ( Prefix + "rhmerr" + Suffix );
66 
67  produces <std::vector<float> > ( Prefix + "ubstrip" + Suffix );
68  produces <std::vector<float> > ( Prefix + "ubmerr" + Suffix );
69 
70  produces <std::vector<float> > ( Prefix + "driftx" + Suffix );
71  produces <std::vector<float> > ( Prefix + "drifty" + Suffix );
72  produces <std::vector<float> > ( Prefix + "driftz" + Suffix );
73  produces <std::vector<float> > ( Prefix + "globalZofunitlocalY" + Suffix );
74 }
75 
80 
81  int size = clustermap.size();
82 
83  //links
84  auto clusterIdx = std::make_unique<std::vector<int>>(); //link: on trk cluster --> general cluster info
85  auto onTrkClusterIdx = std::make_unique<std::vector<int>>(size, -1); //link: general cluster info --> on track cluster
86  auto onTrkClustersBegin = std::make_unique<std::vector<int>>( tracks->size(), -1 ); //link: track --> on trk cluster
87  auto onTrkClustersEnd = std::make_unique<std::vector<int>>( tracks->size(), -1 ); //link: track --> on trk cluster
88  auto trackindex = std::make_unique<std::vector<int>>(); //link: on track cluster --> track
89  clusterIdx->reserve(size);
90  trackindex->reserve(size);
91 
92  auto trackmulti = std::make_unique<std::vector<unsigned int>>(); trackmulti ->reserve(size);
93  auto localtheta = std::make_unique<std::vector<float>>(); localtheta ->reserve(size);
94  auto localphi = std::make_unique<std::vector<float>>(); localphi ->reserve(size);
95  auto localpitch = std::make_unique<std::vector<float>>(); localpitch ->reserve(size);
96  auto localx = std::make_unique<std::vector<float>>(); localx ->reserve(size);
97  auto localy = std::make_unique<std::vector<float>>(); localy ->reserve(size);
98  auto localz = std::make_unique<std::vector<float>>(); localz ->reserve(size);
99  auto strip = std::make_unique<std::vector<float>>(); strip ->reserve(size);
100  auto globaltheta = std::make_unique<std::vector<float>>(); globaltheta ->reserve(size);
101  auto globalphi = std::make_unique<std::vector<float>>(); globalphi ->reserve(size);
102  auto globalx = std::make_unique<std::vector<float>>(); globalx ->reserve(size);
103  auto globaly = std::make_unique<std::vector<float>>(); globaly ->reserve(size);
104  auto globalz = std::make_unique<std::vector<float>>(); globalz ->reserve(size);
105  auto insidistance = std::make_unique<std::vector<float>>(); insidistance->reserve(size);
106  auto projwidth = std::make_unique<std::vector<float>>(); projwidth ->reserve(size);
107  auto BdotY = std::make_unique<std::vector<float>>(); BdotY ->reserve(size);
108  auto covered = std::make_unique<std::vector<float>>(); covered ->reserve(size);
109  auto rhlocalx = std::make_unique<std::vector<float>>(); rhlocalx ->reserve(size);
110  auto rhlocaly = std::make_unique<std::vector<float>>(); rhlocaly ->reserve(size);
111  auto rhlocalxerr = std::make_unique<std::vector<float>>(); rhlocalxerr->reserve(size);
112  auto rhlocalyerr = std::make_unique<std::vector<float>>(); rhlocalyerr->reserve(size);
113  auto rhglobalx = std::make_unique<std::vector<float>>(); rhglobalx ->reserve(size);
114  auto rhglobaly = std::make_unique<std::vector<float>>(); rhglobaly ->reserve(size);
115  auto rhglobalz = std::make_unique<std::vector<float>>(); rhglobalz ->reserve(size);
116  auto rhstrip = std::make_unique<std::vector<float>>(); rhstrip ->reserve(size);
117  auto rhmerr = std::make_unique<std::vector<float>>(); rhmerr ->reserve(size);
118  auto ubstrip = std::make_unique<std::vector<float>>(); ubstrip ->reserve(size);
119  auto ubmerr = std::make_unique<std::vector<float>>(); ubmerr ->reserve(size);
120  auto driftx = std::make_unique<std::vector<float>>(); driftx ->reserve(size);
121  auto drifty = std::make_unique<std::vector<float>>(); drifty ->reserve(size);
122  auto driftz = std::make_unique<std::vector<float>>(); driftz ->reserve(size);
123  auto globalZofunitlocalY = std::make_unique<std::vector<float>>(); globalZofunitlocalY->reserve(size);
124 
125  edm::ESHandle<TrackerGeometry> theTrackerGeometry; iSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
126  edm::ESHandle<MagneticField> magfield; iSetup.get<IdealMagneticFieldRecord>().get(magfield);
128 
130 
132 
133  size_t ontrk_cluster_idx=0;
134  std::map<size_t, std::vector<size_t> > mapping; //cluster idx --> on trk cluster idx (multiple)
135 
137  association != associations->end(); association++) {
138  const Trajectory* traj = association->key.get();
139  const reco::Track* track = association->val.get();
140  int trk_idx = shallow::findTrackIndex(tracks, track);
141  size_t trk_strt_idx = ontrk_cluster_idx;
142 
143  for(auto const& measurement : traj->measurements() ) {
144  const TrajectoryStateOnSurface& tsos = measurement.updatedState();
145  const TrajectoryStateOnSurface unbiased = combiner(measurement.forwardPredictedState(), measurement.backwardPredictedState());
146 
147  const TrackingRecHit* hit = measurement.recHit()->hit();
148  const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
149  const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
150  const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
151 
152  for(unsigned h=0; h<2; h++) { //loop over possible Hit options (1D, 2D)
153  const SiStripCluster* cluster_ptr;
154  if(!matchedhit && h==1) continue;
155  else if( matchedhit && h==0) cluster_ptr = &matchedhit->monoCluster();
156  else if( matchedhit && h==1) cluster_ptr = &matchedhit->stereoCluster();
157  else if(hit2D) cluster_ptr = (hit2D->cluster()).get();
158  else if(hit1D) cluster_ptr = (hit1D->cluster()).get();
159  else continue;
160 
161  shallow::CLUSTERMAP::const_iterator cluster = clustermap.find( std::make_pair( hit->geographicalId().rawId(), cluster_ptr->firstStrip() ));
162  if(cluster == clustermap.end() ) throw cms::Exception("Logic Error") << "Cluster not found: this could be a configuration error" << std::endl;
163 
164  unsigned i = cluster->second;
165 
166  //find if cluster was already assigned to a previous track
167  auto already_visited = mapping.find(i);
168  int nassociations = 1;
169  if(already_visited != mapping.end()) {
170  nassociations += already_visited->second.size();
171  for(size_t idx : already_visited->second) {
172  trackmulti->at(idx)++;
173  }
174  already_visited->second.push_back(ontrk_cluster_idx);
175  }
176  else { //otherwise store this
177  std::vector<size_t> single = {ontrk_cluster_idx};
178  mapping.insert( std::make_pair(i, single) );
179  }
180 
181  const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTrackerGeometry->idToDet( hit->geographicalId() ) );
182  LocalVector drift = shallow::drift( theStripDet, *magfield, *SiStripLorentzAngle);
183 
184  if(nassociations == 1) onTrkClusterIdx->at(i) = ontrk_cluster_idx; //link: general cluster info --> on track cluster
185  clusterIdx->push_back( i ); //link: on trk cluster --> general cluster info
186  trackmulti->push_back( nassociations );
187  trackindex->push_back( trk_idx );
188  localtheta->push_back( (theStripDet->toLocal(tsos.globalDirection())).theta() );
189  localphi->push_back( (theStripDet->toLocal(tsos.globalDirection())).phi() );
190  localpitch->push_back( (theStripDet->specificTopology()).localPitch(theStripDet->toLocal(tsos.globalPosition())) );
191  localx->push_back( (theStripDet->toLocal(tsos.globalPosition())).x() );
192  localy->push_back( (theStripDet->toLocal(tsos.globalPosition())).y() );
193  localz->push_back( (theStripDet->toLocal(tsos.globalPosition())).z() );
194  strip->push_back( (theStripDet->specificTopology()).strip(theStripDet->toLocal(tsos.globalPosition())) );
195  globaltheta->push_back( tsos.globalDirection().theta() );
196  globalphi->push_back( tsos.globalDirection().phi() );
197  globalx->push_back( tsos.globalPosition().x() );
198  globaly->push_back( tsos.globalPosition().y() );
199  globalz->push_back( tsos.globalPosition().z() );
200  insidistance->push_back(1./fabs(cos(localtheta->at(ontrk_cluster_idx))) );
201  projwidth->push_back( tan(localtheta->at(ontrk_cluster_idx))*cos(localphi->at(ontrk_cluster_idx)) );
202  BdotY->push_back( (theStripDet->surface()).toLocal( magfield->inTesla(theStripDet->surface().position())).y() );
203  covered->push_back( drift.z()/localpitch->at(ontrk_cluster_idx) * fabs(projwidth->at(ontrk_cluster_idx) - drift.x()/drift.z()) );
204  rhlocalx->push_back( hit->localPosition().x() );
205  rhlocaly->push_back( hit->localPosition().y() );
206  rhlocalxerr->push_back( sqrt(hit->localPositionError().xx()) );
207  rhlocalyerr->push_back( sqrt(hit->localPositionError().yy()) );
208  rhglobalx->push_back( theStripDet->toGlobal(hit->localPosition()).x() );
209  rhglobaly->push_back( theStripDet->toGlobal(hit->localPosition()).y() );
210  rhglobalz->push_back( theStripDet->toGlobal(hit->localPosition()).z() );
211  rhstrip->push_back( theStripDet->specificTopology().strip(hit->localPosition()) );
212  rhmerr->push_back( sqrt(theStripDet->specificTopology().measurementError(hit->localPosition(), hit->localPositionError()).uu()) );
213  ubstrip->push_back( theStripDet->specificTopology().strip(unbiased.localPosition()) );
214  ubmerr->push_back( sqrt(theStripDet->specificTopology().measurementError(unbiased.localPosition(), unbiased.localError().positionError()).uu()) );
215  driftx->push_back( drift.x() );
216  drifty->push_back( drift.y() );
217  driftz->push_back( drift.z() );
218  globalZofunitlocalY->push_back( (theStripDet->toGlobal(LocalVector(0,1,0))).z() );
219 
220  ontrk_cluster_idx++;
221  } //for(unsigned h=0; h<2; h++) { //loop over possible Hit options (1D, 2D)
222  } //for(auto const& measurement : traj->measurements() )
223 
224  onTrkClustersBegin->at(trk_idx) = trk_strt_idx;
225  onTrkClustersEnd->at(trk_idx) = ontrk_cluster_idx;
226 
227  } //for(TrajTrackAssociationCollection::const_iterator association = associations->begin();
228 
229  iEvent.put(std::move(clusterIdx ), Prefix + "clusterIdx" + Suffix );
230  iEvent.put(std::move(onTrkClusterIdx ), Prefix + "onTrkClusterIdx" + Suffix );
231  iEvent.put(std::move(onTrkClustersBegin), Prefix + "onTrkClustersBegin" + Suffix );
232  iEvent.put(std::move(onTrkClustersEnd ), Prefix + "onTrkClustersEnd" + Suffix );
233  iEvent.put(std::move(trackindex), Prefix + "trackindex" + Suffix );
234 
235  iEvent.put(std::move(trackmulti), Prefix + "trackmulti" + Suffix );
236  iEvent.put(std::move(localtheta), Prefix + "localtheta" + Suffix );
237  iEvent.put(std::move(localphi), Prefix + "localphi" + Suffix );
238  iEvent.put(std::move(localpitch), Prefix + "localpitch" + Suffix );
239  iEvent.put(std::move(localx), Prefix + "localx" + Suffix );
240  iEvent.put(std::move(localy), Prefix + "localy" + Suffix );
241  iEvent.put(std::move(localz), Prefix + "localz" + Suffix );
242  iEvent.put(std::move(strip), Prefix + "strip" + Suffix );
243  iEvent.put(std::move(globaltheta), Prefix + "globaltheta" + Suffix );
244  iEvent.put(std::move(globalphi), Prefix + "globalphi" + Suffix );
245  iEvent.put(std::move(globalx), Prefix + "globalx" + Suffix );
246  iEvent.put(std::move(globaly), Prefix + "globaly" + Suffix );
247  iEvent.put(std::move(globalz), Prefix + "globalz" + Suffix );
248  iEvent.put(std::move(insidistance),Prefix + "insidistance"+ Suffix );
249  iEvent.put(std::move(covered), Prefix + "covered" + Suffix );
250  iEvent.put(std::move(projwidth), Prefix + "projwidth" + Suffix );
251  iEvent.put(std::move(BdotY), Prefix + "BdotY" + Suffix );
252  iEvent.put(std::move(rhlocalx), Prefix + "rhlocalx" + Suffix );
253  iEvent.put(std::move(rhlocaly), Prefix + "rhlocaly" + Suffix );
254  iEvent.put(std::move(rhlocalxerr), Prefix + "rhlocalxerr" + Suffix );
255  iEvent.put(std::move(rhlocalyerr), Prefix + "rhlocalyerr" + Suffix );
256  iEvent.put(std::move(rhglobalx), Prefix + "rhglobalx" + Suffix );
257  iEvent.put(std::move(rhglobaly), Prefix + "rhglobaly" + Suffix );
258  iEvent.put(std::move(rhglobalz), Prefix + "rhglobalz" + Suffix );
259  iEvent.put(std::move(rhstrip), Prefix + "rhstrip" + Suffix );
260  iEvent.put(std::move(rhmerr), Prefix + "rhmerr" + Suffix );
261  iEvent.put(std::move(ubstrip), Prefix + "ubstrip" + Suffix );
262  iEvent.put(std::move(ubmerr), Prefix + "ubmerr" + Suffix );
263  iEvent.put(std::move(driftx), Prefix + "driftx" + Suffix );
264  iEvent.put(std::move(drifty), Prefix + "drifty" + Suffix );
265  iEvent.put(std::move(driftz), Prefix + "driftz" + Suffix );
266  iEvent.put(std::move(globalZofunitlocalY), Prefix + "globalZofunitlocalY" + Suffix );
267 }
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:125
ShallowTrackClustersProducer(const edm::ParameterSet &)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
int findTrackIndex(const edm::Handle< edm::View< reco::Track > > &h, const reco::Track *t)
Definition: ShallowTools.cc:27
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:37
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:224
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_
const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > clusters_token_
CLUSTERMAP make_cluster_map(const edm::Event &, const edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > &)
Definition: ShallowTools.cc:13
SiStripCluster const & stereoCluster() const
fixed size matrix
HLT enums.
std::map< std::pair< uint32_t, uint16_t >, unsigned int > CLUSTERMAP
Definition: ShallowTools.h:19
T get() const
Definition: EventSetup.h:71
const TrackerGeomDet * idToDet(DetId) const override
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:511
GlobalVector globalDirection() const