CMS 3D CMS Logo

SimpleDAFHitCollector.cc
Go to the documentation of this file.
10 
11 #ifdef EDM_ML_DEBUG
18 #endif
19 
20 
21 #include <vector>
22 #include <map>
23 
24 #define _debug_SimpleDAFHitCollector_
25 
26 using namespace std;
27 
28 vector<TrajectoryMeasurement> SimpleDAFHitCollector::recHits(const Trajectory& traj, const MeasurementTrackerEvent *theMTE) const{
29 
30  LogTrace("MultiRecHitCollector") << " Calling SimpleDAFHitCollector::recHits" << std::endl;
31 
32  //WARNING: At the moment the trajectories has the measurements
33  //with reversed sorting after the track smoothing
34  const vector<TrajectoryMeasurement>& meas = traj.measurements();
35  unsigned int hitcounter = 1;
36 
37  if (meas.empty()) return vector<TrajectoryMeasurement>();
38 
39  LogTrace("MultiRecHitCollector") << " Original measurements are:";
40  Debug(meas);
41 
42  //groups hits on a sensor by sensor with same Id of previous TM
43  //we have to sort the TrajectoryMeasurements in the opposite way in the fitting direction
44  vector<TrajectoryMeasurement> result;
45  for(vector<TrajectoryMeasurement>::const_reverse_iterator itrajmeas = meas.rbegin(); itrajmeas < meas.rend();
46  itrajmeas++, hitcounter++) {
47 
48  DetId id = itrajmeas->recHit()->geographicalId();
49  MeasurementDetWithData measDet = theMTE->idToDet(id);
51 
52  std::vector<const TrackingRecHit*> hits;
53  std::vector<std::unique_ptr<const TrackingRecHit>> hitsOwner;
54 
55  TrajectoryStateOnSurface smoothtsos = itrajmeas->updatedState();
56  //the error is scaled in order to take more "compatible" hits
57 // if( smoothtsos.isValid() ) smoothtsos.rescaleError(10);
58 
59  TrajectoryStateOnSurface predtsos_fwd = itrajmeas->predictedState();
60  TrajectoryStateOnSurface predtsos_bwd = itrajmeas->backwardPredictedState();
61  if( !predtsos_fwd.isValid() || !predtsos_bwd.isValid() ){
62  LogTrace("MultiRecHitCollector") << "Something wrong! no valid TSOS found in current group ";
63  continue;
64  }
65 
67  TrajectoryStateOnSurface combtsos;
68  if (hitcounter == meas.size()) combtsos = predtsos_fwd;
69  else if (hitcounter == 1) combtsos = predtsos_bwd;
70  else combtsos = combiner(predtsos_bwd, predtsos_fwd);
71 
72  //collected hits compatible with the itrajmeas
73  if( measDet.measurements(smoothtsos, *(getEstimator()), tmps)){
74 
75  LogTrace("MultiRecHitCollector") << " Found " << tmps.size() << " compatible measurements";
76 
77  for (std::size_t i=0; i!=tmps.size(); ++i){
78 
79  DetId idtemps = tmps.hits[i]->geographicalId();
80 
81  if( idtemps == id && tmps.hits[i]->hit()->isValid() ) {
82  LogTrace("MultiRecHitCollector") << " This is valid with position " << tmps.hits[i]->hit()->localPosition() << " and error " << tmps.hits[i]->hit()->localPositionError();
83 
85  theUpdator->getBuilder()->build(tmps.hits[i]->hit());
86  TrackingRecHit::ConstRecHitPointer preciseHit = theHitCloner.makeShared(transient,combtsos);
87  auto righthit = rightdimension(*preciseHit);
88  hitsOwner.push_back(std::move(righthit));
89  hits.push_back(hitsOwner.back().get());
90  }
91 
92  }
93 
94  //the error was scaled, now is scaled back (even if this is not tightly necessary)
95 // if (smoothtsos.isValid()) smoothtsos.rescaleError(0.1);
96 
97  //I will keep the Invalid hit, IF this is not the first one
98  if (hits.empty()){
99  LogTrace("MultiRecHitCollector") << " -> but no valid hits found in current group.";
100 
101  if( result.empty() ) continue;
102 
103  result.push_back(TrajectoryMeasurement(predtsos_fwd,
104  std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
105  } else {
106  //measurements in groups are sorted with increating chi2
107  //sort( *hits.begin(), *hits.end(), TrajMeasLessEstim());
108  if(!itrajmeas->recHit()->isValid())
109  LogTrace("MultiRecHitCollector") << " -> " << hits.size() << " valid hits for this sensor. (IT WAS INVALID!!!)";
110  else LogTrace("MultiRecHitCollector") << " -> " << hits.size() << " valid hits for this sensor.";
111 
112  //building a MultiRecHit out of each sensor group
113  result.push_back(TrajectoryMeasurement(predtsos_fwd,theUpdator->buildMultiRecHit(hits, combtsos, measDet)));
114  }
115  } else {
116  LogTrace("MultiRecHitCollector") << " No measurements found in current group.";
117  //the error was scaled, now is scaled back (even if this is not tightly necessary)
118 // if (smoothtsos.isValid()) smoothtsos.rescaleError(0.1);
119 
120  if( result.empty() ) continue;
121 
122  result.push_back(TrajectoryMeasurement(predtsos_fwd,
123  std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
124 
125  }
126 
127 
128  }
129  LogTrace("MultiRecHitCollector") << " Ending SimpleDAFHitCollector::recHits >> " << result.size();
130 
131  //LogTrace("MultiRecHitCollector") << " New measurements are:";
132  //Debug(result);
133 
134  //adding a protection against too few hits and invalid hits
135  //(due to failed propagation on the same surface of the original hits)
136  if (result.size()>2)
137  {
138  int hitcounter=0;
139  //check if the vector result has more than 3 valid hits
140  for (vector<TrajectoryMeasurement>::const_iterator iimeas = result.begin(); iimeas != result.end(); ++iimeas) {
141  if(iimeas->recHit()->isValid()) hitcounter++;
142  }
143 
144  if(hitcounter>2)
145  return result;
146  else return vector<TrajectoryMeasurement>();
147  }
148 
149  else{return vector<TrajectoryMeasurement>();}
150 
151 }
152 
153 
154 void SimpleDAFHitCollector::Debug( const std::vector<TrajectoryMeasurement> TM ) const
155 {
156 #ifdef EDM_ML_DEBUG
157  for(vector<TrajectoryMeasurement>::const_iterator itrajmeas = TM.begin(); itrajmeas < TM.end();
158  itrajmeas++) {
159  if (itrajmeas->recHit()->isValid()){
160 
161  LogTrace("MultiRecHitCollector") << " Valid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId() << " and dim:" << itrajmeas->recHit()->dimension()
162  //<< " type " << typeid(itrajmeas->recHit()).name()
163  << " local position " << itrajmeas->recHit()->hit()->localPosition()
164  << " global position " << itrajmeas->recHit()->hit()->globalPosition()
165  << " and r " << itrajmeas->recHit()->hit()->globalPosition().perp() ;
166 
167  DetId hitId = itrajmeas->recHit()->geographicalId();
168 
169  if(hitId.det() == DetId::Tracker) {
170  switch (hitId.subdetId()) {
172  LogTrace("MultiRecHitCollector") << " I am TIB " << theTopology->tibLayer(hitId); break;
174  LogTrace("MultiRecHitCollector") << " I am TOB " << theTopology->tobLayer(hitId); break;
176  LogTrace("MultiRecHitCollector") << " I am TEC " << theTopology->tecWheel(hitId); break;
178  LogTrace("MultiRecHitCollector") << " I am TID " << theTopology->tidWheel(hitId); break;
180  LogTrace("MultiRecHitCollector") << " I am PixBar " << theTopology->pxbLayer(hitId); break;
182  LogTrace("MultiRecHitCollector") << " I am PixFwd " << theTopology->pxfDisk(hitId); break;
183  default:
184  LogTrace("MultiRecHitCollector") << " UNKNOWN TRACKER HIT TYPE "; break;
185  }
186  }
187  else if(hitId.det() == DetId::Muon) {
188  if(hitId.subdetId() == MuonSubdetId::DT)
189  LogTrace("MultiRecHitCollector") << " I am DT " << DTWireId(hitId);
190  else if (hitId.subdetId() == MuonSubdetId::CSC )
191  LogTrace("MultiRecHitCollector") << " I am CSC " << CSCDetId(hitId);
192  else if (hitId.subdetId() == MuonSubdetId::RPC )
193  LogTrace("MultiRecHitCollector") << " I am RPC " << RPCDetId(hitId);
194  else
195  LogTrace("MultiRecHitCollector") << " UNKNOWN MUON HIT TYPE ";
196  }
197  else
198  LogTrace("MultiRecHitCollector") << " UNKNOWN HIT TYPE ";
199 
200 
201  LogTrace("MultiRecHitCollector") << " TSOS predicted_fwd " << itrajmeas->predictedState().localPosition() ;
202  LogTrace("MultiRecHitCollector") << " TSOS predicted_bwd " << itrajmeas->backwardPredictedState().localPosition() ;
203  LogTrace("MultiRecHitCollector") << " TSOS smoothtsos " << itrajmeas->updatedState().localPosition() ;
204  } else {
205  LogTrace("MultiRecHitCollector") << " Invalid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId();
206  }
207  LogTrace("MultiRecHitCollector") << "\n";
208  }
209 #endif
210 }
void Debug(const std::vector< TrajectoryMeasurement > TM) const
std::size_t size() const
virtual const GeomDet & geomDet() const
DataContainer const & measurements() const
Definition: Trajectory.h:196
static const int CSC
Definition: MuonSubdetId.h:13
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
const MeasurementDet & mdet() const
#define LogTrace(id)
std::shared_ptr< TrackingRecHit const > RecHitPointer
Definition: DetId.h:18
std::vector< TrajectoryMeasurement > recHits(const Trajectory &, const MeasurementTrackerEvent *theMTE) const override
static const int RPC
Definition: MuonSubdetId.h:14
static const int DT
Definition: MuonSubdetId.h:12
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const
const bool Debug
def move(src, dest)
Definition: eostools.py:510
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39