CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimpleMTFHitCollector.cc
Go to the documentation of this file.
12 #include <vector>
13 #include <map>
14 
15 #define _debug_SimpleMTFHitCollector_
16 
17 using namespace std;
18 
19 vector<TrajectoryMeasurement>
20 SimpleMTFHitCollector::recHits(const std::map<int, vector<TrajectoryMeasurement> >& tmmap,
21  int i,
22  double annealing) const{
23 
24 
25  //it assumes that the measurements are sorted in the smoothing direction
26  map< int, vector<TrajectoryMeasurement> >::const_iterator itmeas = tmmap.find(i);
27  LogDebug("SimpleMTFHitCollector") << "found the element "<< i << "in the map" << std::endl;
28 
29  vector<TrajectoryMeasurement> meas = itmeas->second;
30  LogDebug("SimpleMTFHitCollector") << "got the vector corresponding to " << i << " element of the map "<< std::endl;
31 
32  if (meas.empty())
33  return vector<TrajectoryMeasurement>();
34 
35 
36  //TransientTrackingRecHit::ConstRecHitContainer result;
37  vector<TrajectoryMeasurement> result;
38  TrajectoryStateCombiner statecombiner;
39 
40  //loop on the vector<TM> from the bottom to the top (assumes the measurement are sorted in the smoothing direction)
41  for(vector<TrajectoryMeasurement>::reverse_iterator imeas = meas.rbegin(); imeas != meas.rend(); imeas++)
42 
43  {
44  //check if the rechit is a valid one: if it is build a MultiRecHit
45  if(imeas->recHit()->geographicalId().rawId())
46  {
47  //define the rechit
48  TransientTrackingRecHit::ConstRecHitPointer rechit = imeas->recHit();
49  //const DetLayer* layer = imeas->layer();
50 
51  uint32_t id = imeas->recHit()->geographicalId().rawId();
52 
53  LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
54 
55 
56  std::vector<std::pair<int, TrajectoryMeasurement> > layermeas;
57  getMeasurements(layermeas, tmmap,*imeas,i);
58 
59 
60  //create a MTM
61  MultiTrajectoryMeasurement mtm = getTSOS(layermeas, rechit, i);
62 
63  //then build a MRH from a vector<TM> and a MTM...the buildMRH method has to be a dedicated one
65 
66  for (vector<std::pair<int, TrajectoryMeasurement> >::const_iterator ittmeas = layermeas.begin(); ittmeas != layermeas.end(); ittmeas++)
67  {
68  //TransientTrackingRecHit::ConstRecHitContainer sharedhits;
69 
70  if(ittmeas->second.recHit()->isValid())
71  {
72 
73  LogDebug("SimpleMTFHitCollector") << "this rechit in the vector layermeas is valid." << std::endl;
74 
75  int k=0;
76  //if the rechit is valid we push back the hit
77  //hits.push_back(ittmeas->second.recHit());
78 
79  if (!hits.size())
80  {
81  hits.push_back(ittmeas->second.recHit());
82 
83 
84  //check if the rechits in hits are the same, and in case remove the hit from the vector
85  }
86 
87  else
88  {
89  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihits = hits.begin(); ihits != hits.end(); ihits++ )
90  {
91 
92 
93  //we check if the rechits are the same and if the vector hits is not made of 1 hit,
94  //if it is made of more than 1 hit we pop back the hit
95  if((*ihits)->hit()->sharesInput(ittmeas->second.recHit()->hit(), TrackingRecHit::all))
96  {
97  LogDebug("SimpleMTFHitCollector") << "the rechit coming from layermeas is the same as the first rechit "
98  << "we skip this rechit in building the multirechit" << std::endl;
99  // sharedhits.push_back(ittmeas->second.recHit());
100 
101  k++;
102  break;
103  }
105  }
106 
107  //if(sharedhits.size()) continue;
108 
109  //else
110  // {
111  // hits.push_back(ittmeas->second.recHit());
112  // sharedhits.clear();
113  // }
114 
115  if(k==0)
116  {
117  LogTrace("SimpleMTFHitCollector") << "This hit is valid ";
118  hits.push_back(ittmeas->second.recHit());
119  }
120 
121  }
122 
123  }
124 
125  else continue;
126 
127  }
128 
129 
130  if(hits.size()==0)
131  {
132  result.push_back(*imeas);
133  LogDebug("SimpleMTFHitCollector") << "we found no valid rechits, so we fill the vector with the initial measurement" << std::endl;
134  }
135 
136  else
137  {
138 
139  // TrajectoryStateOnSurface state = layermeas.front().second.predictedState();
140  TrajectoryStateOnSurface state= statecombiner.combine(layermeas.front().second.predictedState(), layermeas.front().second.backwardPredictedState());
141 
142  LogDebug("SimpleMTFHitCollector") << "we build a trajectory measurement from a vector of hits of size" << hits.size() <<std::endl;
143 
144  result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(state, hits, &mtm, annealing)));
145  }
146 
147  }
148 
149 
150 
151  //if the rechit is not valid, the measurement is pushed back as it is
152  else
153  {
154  result.push_back(*imeas);
155  }
156 
157  }
158 
159 
160  LogTrace("MultiRecHitCollector") << "Original Measurement size "
161  << meas.size() << " SimpleMTFHitCollector returned "
162  << result.size() << " rechits";
163  //results are sorted in the fitting direction
164  return result;
165 
166 }
167 
168 
169 void
170 SimpleMTFHitCollector::getMeasurements(std::vector<std::pair<int, TrajectoryMeasurement> >& layermeas,
171  const std::map<int, vector<TrajectoryMeasurement> >& tmmap,
172  TrajectoryMeasurement& pmeas,
173  int i) const{
174 
175  uint32_t id = pmeas.recHit()->geographicalId().rawId();
176 
177  LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
178 
179  //vector<std::pair<int, TrajectoryMeasurement> > layermeas;
180 
181  if( pmeas.recHit()->geographicalId().rawId() )
182  {
183  //search for hits only on the same detector, comparing the detId. Fill also the vector layermeas with the original measurement.
184 
185 
186  //use the method fastmeas to search for compatible hits and put it into a vector
187  // vector<TrajectoryMeasurement> veclayermeas =
188  // getMeasurementTracker()->idToDet
189  // (pmeas.recHit()->geographicalId().rawId())->fastMeasurements(pmeas.updatedState(),
190  // pmeas.updatedState(),
191  // *thePropagator,
192  // *(getEstimator()));
193 
194 
195  //LogDebug("SimpleMTFHitCollector") << " method veclayermeas returned a vector of size: "
196  // << veclayermeas.size()
197  // << std::endl;
198 
199  // for(vector<TrajectoryMeasurement>::iterator iveclayermeas=veclayermeas.begin();
200  // iveclayermeas!=veclayermeas.end();
201  // iveclayermeas++)
202 
203  // {
204 
205  // layermeas.push_back(make_pair(i,pmeas));
206 
207  for (std::map< int, vector<TrajectoryMeasurement> >::const_iterator immap=tmmap.begin();
208  immap!=tmmap.end();
209  immap++)
210  {
211  int ntraj2 = immap->first;
212  //LogDebug("SimpleMTFHitCollector") << " number of the trajectory examined: " << ntraj2 << std::endl;
213  //map< int, vector<TrajectoryMeasurement> >::const_iterator k = immap->second;
214  const vector<TrajectoryMeasurement> & vecmeas = immap->second;
215 
216  // if(ntraj2 == i) continue;
217 
218 
219  for(vector<TrajectoryMeasurement>::const_reverse_iterator itvmeas = vecmeas.rbegin(); itvmeas!=vecmeas.rend(); itvmeas++)
220  {
221  // if ( ( itvmeas->recHit()->geographicalId().rawId() == id) && (itvmeas->recHit()->isValid()) && !(itvmeas->recHit()->hit()->sharesInput(pmeas.recHit()->hit(), TrackingRecHit::all)) ) //modoficare per inludere il layer nella ricerca
222 
223  //if(itvmeas->recHit()->hit()->sharesInput(iveclayermeas->recHit()->hit(), TrackingRecHit::some) )
224  if ( (itvmeas->recHit()->geographicalId().rawId() == id) )
225  {
226  LogDebug("SimpleMTFHitCollector") << "found a matching rechit in the collector";
227  // if(iveclayermeas->updatedState() == itvmeas->updatedState())
228 
229  layermeas.push_back(make_pair(ntraj2,*itvmeas));
230 
231  }
232 
233  //if(itvmeas->recHit()->geographicalId().rawId() == id)
234 
235  //layermeas.push_back(make_pair(ntraj2,*itvmeas));
236 
237  }
238 
239  }
240 
241 
242  //vector<TrajectoryMeasurement>
243 
244  //currentLayerMeas=getMeasurementTracker()->idToDet(imeas->recHit()->geographicalId().rawId())->fastMeasurements(imeas->updatedState(),
245  // imeas->updatedState(),
246  // *thePropagator,
247  // *(getEstimator()));
248  LogDebug("SimpleMTFHitCollector") << " built a vector of Trajectory Measurements all on the same layer, of size: "
249  << layermeas.size()
250  << std::endl;
251  }
252 
253  else layermeas.push_back(make_pair(i,pmeas));
254 
255 
256 }
257 
258 MultiTrajectoryMeasurement SimpleMTFHitCollector::getTSOS(const vector<std::pair<int, TrajectoryMeasurement> >& layermeas,
260  int i) const{
261 
262  //we should search even for compatible tsos on this layer and build the multirechit with this knowledge...we can build an MTM.
263  uint32_t id = rechit->geographicalId().rawId();
264 
265  LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
266 
267  LogDebug("SimpleMTFHitCollector") << "LayerMeas size: " << layermeas.size() << std::endl;
268 
269  const DetLayer* layer = layermeas.front().second.layer();
270 
271  std::map<int,TSOS> predictions;
272  std::map<int,TSOS> updates;
273  LogDebug("SimpleMTFHitCollector") << " about to build a map with predicted and updated states " << std::endl;
274 
275  //we insert initially at least the original predicted & updated states
276  //if(imeas->predictedState().isValid())
277  // predictions[i] = imeas->predictedState();
278  //else if ( imeas->backwardPredictedState().isValid() )
279  // predictions[i] = imeas->backwardPredictedState();
280  //else viva il dale
281  // LogDebug("SimpleMTFHitCollector") << "error:invalid predicted and backward predicted states" << std::endl;
282 
283  //first fill the map with the state relative to the measurement we are analizing
284  //if(imeas->updatedState().isValid())
285  // updates[i] = imeas->updatedState();
286 
287  //LogDebug("SimpleMTFHitCollector") << "Local Position of predicted state" << imeas->predictedState().localPosition() << std::endl;
288  //LogDebug("SimpleMTFHitCollector") << "Local Position of updated state" << imeas->updatedState().localPosition() << std::endl;
289  TrajectoryStateCombiner statecombiner;
290 
291  for (std::vector<std::pair<int,TrajectoryMeasurement> >::const_iterator itmeas=layermeas.begin(); itmeas!=layermeas.end(); itmeas++)
292  {
293 
294  //we now have to build 2 maps, with the (predicted & updated) tsos for each track; then we can construct a MTM
295  LogDebug("SimpleMTFHitCollector") << " number of the trajectory examined: " << itmeas->first << std::endl;
296 
297  //get the vector from the map
298  //LogDebug("SimpleMTFHitCollector") << " size of the vector examining: " << vmeas.size() << std::endl;
299 
300  //if(ntraj == i)
301  //{
302  // LogDebug("SimpleMTFHitCollector") << " skipping trajectory number: " << ntraj << std::endl;
303  // continue;
304  // }
305 
306  //begin a cicle to search for measurements compatible(same layer)
307  //check if the _detid_ of the original measurement is the same of this one and if the rechits are not the same one
308  if ( (itmeas->second.recHit()->geographicalId().rawId() == id) ) //controlla che siano sullo stesso layer (cambiare!!!)
309  {
310 
311  // LogDebug("SimpleMTFHitCollector") << "found a compatible hit " << std::endl;
312 
313  //add an element to the maps with predicted and updated states
314  if(itmeas->second.predictedState().isValid())
315  {
316  predictions[itmeas->first] = itmeas->second.predictedState();
317  // LogDebug("SimpleMTFHitCollector") << "predicted state inserted in the map " << std::endl;
318  if ( itmeas->second.backwardPredictedState().isValid() ){
319  updates[itmeas->first]= statecombiner.combine(itmeas->second.predictedState(), itmeas->second.backwardPredictedState());
320  }
321  }
322 
323  // else if ( itmeas->second.backwardPredictedState().isValid() )
324  // {
325  // predictions[itmeas->first] = itmeas->second.backwardPredictedState();
326  // LogDebug("SimpleMTFHitCollector") << "bacwardpredicted state inserted in the map " << std::endl;
327  // }
328 
329  else
330  LogDebug("SimpleMTFHitCollector") << "error:invalid predicted state" << std::endl;
331 
332 // if(itmeas->second.updatedState().isValid()){
333 
334 // updates[itmeas->first] = itmeas->second.updatedState();
335 // LogDebug("SimpleMTFHitCollector") << "updated state inserted in the map " << std::endl;
336 // }
337 // else if ( itmeas->second.predictedState().isValid() )
338 // {
339 // LogDebug("SimpleMTFHitCollector") << "error: invalid updated state, taking the predicted one instead " << std::endl;
340 // updates[itmeas->first] = itmeas->second.predictedState();
341 // }
342 
343 // else
344 // LogDebug("SimpleMTFHitCollector") << "error:invalid updated and backward predicted states" << std::endl;
345 
346 
347  //get the iterator to the predicted & updated states of the maps, to print the TSOS predicted and updated
348  // map<int,TSOS>::iterator ipred = predictions.find(itmeas->first);
349  //map<int,TSOS>::iterator iupd = updates.find(itmeas->first);
350 
351  //controlla che siano giusti gli stati!!!
352  //LogDebug("SimpleMTFHitCollector") << "Local Position of predicted state " << ipred->second.localPosition() << std::endl
353  // << " of trajectory number " << ipred->first <<"\n" << std::endl;
354  //LogDebug("SimpleMTFHitCollector") << "Local Position of updated state " << iupd->second.localPosition() << std::endl
355  //<< " of trajectory number " << iupd->first <<"\n" << std::endl;
356 
357  }
358  }
359 
360  //create a MTM
361  MultiTrajectoryMeasurement mtm = MultiTrajectoryMeasurement(rechit,predictions,updates,layer);
362  return mtm;
363 }
364 
365 
366 
367 MultiTrajectoryMeasurement SimpleMTFHitCollector::TSOSfinder(const std::map<int, vector<TrajectoryMeasurement> >& tmmap,
368  TrajectoryMeasurement& pmeas,
369  int i) const{
370 
371 
372  //it assumes that the measurements are sorted in the smoothing direction
373  //map< int, vector<TrajectoryMeasurement> >::const_iterator itmeas = tmmap.find(i);
374  //LogDebug("SimpleMTFHitCollector") << "found the element "<< i << "in the map" << std::endl;
375 
376  //vector<TrajectoryMeasurement> meas = itmeas->second;
377  //LogDebug("SimpleMTFHitCollector") << "got the vector corresponding to " << i << " element of the map "<< std::endl;
378 
379  //if (meas.empty())
380  // return vector<TrajectoryMeasurement>();
381 
382 
383  //TransientTrackingRecHit::ConstRecHitContainer result;
384  vector<TrajectoryMeasurement> result;
385 
386 
387  // if(pmeas.recHit()->isValid())
388 
389 
390 
391  //define the rechit
393 
394  // const DetLayer* layer = pmeas.layer();
395 
396  uint32_t id = pmeas.recHit()->geographicalId().rawId();
397 
398  LogDebug("SimpleMTFHitCollector") << "Detector Id: " << id << std::endl;
399 
400  //get all the measurement on the same layer, searching in the map
401  vector<std::pair<int, TrajectoryMeasurement> > layermeas;
402  getMeasurements(layermeas, tmmap,pmeas,i);
403 
404 
405  //create a MTM, by knowledge of the measurements on the same layer and the rechit...
406  return getTSOS(layermeas, rechit, i);
407 
408 
409  }
410 
411 
412 
413  //then build a MRH from a vector<TM> and a MTM...the buildMRH method has to be a dedicated one
414  //TransientTrackingRecHit::ConstRecHitContainer hits;
415 
416  //for (vector<std::pair<int, TrajectoryMeasurement> >::const_iterator ittmeas = layermeas.begin(); ittmeas != layermeas.end(); ittmeas++){
417  // if (ittmeas->second.recHit()->getType() != TrackingRecHit::missing) {
418  // LogTrace("SimpleMTFHitCollector") << "This hit is valid ";
419  // hits.push_back(ittmeas->second.recHit());
420  //}
421  //}
422  //TrajectoryStateOnSurface state = layermeas.front().second.predictedState();
423 
424 
425 
426 
427  //obsolete method, not used in track reconstruction or MRH building
428 void SimpleMTFHitCollector::buildMultiRecHits(const vector<std::pair<int, TrajectoryMeasurement> >& vmeas,
430  vector<TrajectoryMeasurement>& result,
431  double annealing) const {
432 
433  if (vmeas.empty()) {
434  LogTrace("SimpleMTFHitCollector") << "the search for the measurement on the same layer returned an empty vector...we have got a problem... " ;
435  //should we do something?
436  //result.push_back(InvalidTransientRecHit::build(0,TrackingRecHit::missing));
437  return;
438  }
439 
440 
441  //the state is computed taking the vmeas (all on the same surface) and their predicted state
442  TrajectoryStateOnSurface state = vmeas.front().second.predictedState();
443  LogTrace("SimpleMTFHitCollector") << "Position (local) of the first measurement state: " << state.localPosition();
444  LogTrace("SimpleMTFHitCollector") << "Position (global) of the first measurement state: " << state.globalPosition();
445 
446  if (state.isValid()==false){
447  LogTrace("MultiRecHitCollector") << "first state is invalid; skipping ";
448  return;
449  }
450 
451  //vector<const TrackingRecHit*> hits;
453 
454  for (vector<std::pair<int, TrajectoryMeasurement> >::const_iterator ittmeas = vmeas.begin(); ittmeas != vmeas.end(); ittmeas++){
455  if (ittmeas->second.recHit()->getType() != TrackingRecHit::missing) {
456  LogTrace("SimpleMTFHitCollector") << "This hit is valid ";
457  hits.push_back(ittmeas->second.recHit());
458  }
459  }
460 
461  if (hits.empty()){
462  LogTrace("MultiTrackFilterHitCollector") << "No valid hits found ";
463  return;
464  }
465 
466  LogTrace("SimpleMTFHitCollector") << "The hits vector has size: " << hits.size() << "\n"
467  << "and has first component global position: " << hits.front()->globalPosition();
468 
469 
470  //for(std::map<int,TSOS>::const_iterator imtm=mtm->filteredStates().begin(); imtm!=mtm->filteredStates().end(); imtm++)
471  // {
472  // LogDebug("SimpleMTFHitCollector::BuildMultiRecHits") << "TSOS number " << imtm->first << "\n"
473  // << "TSOS position " << imtm->second.localPosition() << std::endl;
474  // }
475 
476  //LogDebug("SimpleMTFHitCollector::BuildMultiRecHits") << "Map Size:" << mtm->filteredStates().size() << "\n";
477 
478 
479  //the work of building a concrete MRH is done by theUpdator->buildMultiRecHit method (modified, to include an mtm...)
480  result.push_back(TrajectoryMeasurement(state,theUpdator->buildMultiRecHit(state, hits, mtm, annealing)));
481 
482 
483  //result.push_back(TrajectoryMeasurement(state,theUpdator->update(hits, state)));
484 
485 }
486 
487 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
MultiTrajectoryMeasurement TSOSfinder(const std::map< int, std::vector< TrajectoryMeasurement > > &tmmap, TrajectoryMeasurement &pmeas, int i) const
dictionary map
Definition: Association.py:160
virtual std::vector< TrajectoryMeasurement > recHits(const std::map< int, std::vector< TrajectoryMeasurement > > &tmmap, int i, double annealing=1.) const
tuple result
Definition: query.py:137
#define LogTrace(id)
MultiTrajectoryMeasurement getTSOS(const std::vector< std::pair< int, TrajectoryMeasurement > > &layermeas, TransientTrackingRecHit::ConstRecHitPointer rechit, int i) const
int k[5][pyjets_maxn]
std::vector< ConstRecHitPointer > ConstRecHitContainer
char state
Definition: procUtils.cc:75
void buildMultiRecHits(const std::vector< std::pair< int, TrajectoryMeasurement > > &measgroup, MultiTrajectoryMeasurement *mtm, std::vector< TrajectoryMeasurement > &result, double annealing=1.) const
void getMeasurements(std::vector< std::pair< int, TrajectoryMeasurement > > &layermeas, const std::map< int, std::vector< TrajectoryMeasurement > > &tmmap, TrajectoryMeasurement &pmeas, int i) const