CMS 3D CMS Logo

SimpleDAFHitCollector.cc
Go to the documentation of this file.
10 
11 #ifdef EDM_ML_DEBUG
18 #endif
19 
20 #include <vector>
21 #include <map>
22 
23 #define _debug_SimpleDAFHitCollector_
24 
25 using namespace std;
26 
27 vector<TrajectoryMeasurement> SimpleDAFHitCollector::recHits(const Trajectory& traj,
28  const MeasurementTrackerEvent* theMTE) const {
29  LogTrace("MultiRecHitCollector") << " Calling SimpleDAFHitCollector::recHits" << std::endl;
30 
31  //WARNING: At the moment the trajectories has the measurements
32  //with reversed sorting after the track smoothing
33  const vector<TrajectoryMeasurement>& meas = traj.measurements();
34  unsigned int hitcounter = 1;
35 
36  if (meas.empty())
37  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  DetId id = itrajmeas->recHit()->geographicalId();
48  MeasurementDetWithData measDet = theMTE->idToDet(id);
50 
51  std::vector<const TrackingRecHit*> hits;
52  std::vector<std::unique_ptr<const TrackingRecHit>> hitsOwner;
53 
54  TrajectoryStateOnSurface smoothtsos = itrajmeas->updatedState();
55  //the error is scaled in order to take more "compatible" hits
56  // if( smoothtsos.isValid() ) smoothtsos.rescaleError(10);
57 
58  TrajectoryStateOnSurface predtsos_fwd = itrajmeas->predictedState();
59  TrajectoryStateOnSurface predtsos_bwd = itrajmeas->backwardPredictedState();
60  if (!predtsos_fwd.isValid() || !predtsos_bwd.isValid()) {
61  LogTrace("MultiRecHitCollector") << "Something wrong! no valid TSOS found in current group ";
62  continue;
63  }
64 
66  TrajectoryStateOnSurface combtsos;
67  if (hitcounter == meas.size())
68  combtsos = predtsos_fwd;
69  else if (hitcounter == 1)
70  combtsos = predtsos_bwd;
71  else
72  combtsos = combiner(predtsos_bwd, predtsos_fwd);
73 
74  //collected hits compatible with the itrajmeas
75  if (measDet.measurements(smoothtsos, *(getEstimator()), tmps)) {
76  LogTrace("MultiRecHitCollector") << " Found " << tmps.size() << " compatible measurements";
77 
78  for (std::size_t i = 0; i != tmps.size(); ++i) {
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()
83  << " and error " << tmps.hits[i]->hit()->localPositionError();
84 
85  TransientTrackingRecHit::RecHitPointer transient = 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  //the error was scaled, now is scaled back (even if this is not tightly necessary)
94  // if (smoothtsos.isValid()) smoothtsos.rescaleError(0.1);
95 
96  //I will keep the Invalid hit, IF this is not the first one
97  if (hits.empty()) {
98  LogTrace("MultiRecHitCollector") << " -> but no valid hits found in current group.";
99 
100  if (result.empty())
101  continue;
102 
103  result.push_back(TrajectoryMeasurement(
104  predtsos_fwd, 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")
110  << " -> " << hits.size() << " valid hits for this sensor. (IT WAS INVALID!!!)";
111  else
112  LogTrace("MultiRecHitCollector") << " -> " << hits.size() << " valid hits for this sensor.";
113 
114  //building a MultiRecHit out of each sensor group
115  result.push_back(TrajectoryMeasurement(predtsos_fwd, theUpdator->buildMultiRecHit(hits, combtsos, measDet)));
116  }
117  } else {
118  LogTrace("MultiRecHitCollector") << " No measurements found in current group.";
119  //the error was scaled, now is scaled back (even if this is not tightly necessary)
120  // if (smoothtsos.isValid()) smoothtsos.rescaleError(0.1);
121 
122  if (result.empty())
123  continue;
124 
125  result.push_back(TrajectoryMeasurement(
126  predtsos_fwd, std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
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  int hitcounter = 0;
138  //check if the vector result has more than 3 valid hits
139  for (vector<TrajectoryMeasurement>::const_iterator iimeas = result.begin(); iimeas != result.end(); ++iimeas) {
140  if (iimeas->recHit()->isValid())
141  hitcounter++;
142  }
143 
144  if (hitcounter > 2)
145  return result;
146  else
147  return vector<TrajectoryMeasurement>();
148  }
149 
150  else {
151  return vector<TrajectoryMeasurement>();
152  }
153 }
154 
155 void SimpleDAFHitCollector::Debug(const std::vector<TrajectoryMeasurement> TM) const {
156 #ifdef EDM_ML_DEBUG
157  for (vector<TrajectoryMeasurement>::const_iterator itrajmeas = TM.begin(); itrajmeas < TM.end(); itrajmeas++) {
158  if (itrajmeas->recHit()->isValid()) {
159  LogTrace("MultiRecHitCollector") << " Valid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId()
160  << " and dim:"
161  << 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);
173  break;
175  LogTrace("MultiRecHitCollector") << " I am TOB " << theTopology->tobLayer(hitId);
176  break;
178  LogTrace("MultiRecHitCollector") << " I am TEC " << theTopology->tecWheel(hitId);
179  break;
181  LogTrace("MultiRecHitCollector") << " I am TID " << theTopology->tidWheel(hitId);
182  break;
184  LogTrace("MultiRecHitCollector") << " I am PixBar " << theTopology->pxbLayer(hitId);
185  break;
187  LogTrace("MultiRecHitCollector") << " I am PixFwd " << theTopology->pxfDisk(hitId);
188  break;
189  default:
190  LogTrace("MultiRecHitCollector") << " UNKNOWN TRACKER HIT TYPE ";
191  break;
192  }
193  } else if (hitId.det() == DetId::Muon) {
194  if (hitId.subdetId() == MuonSubdetId::DT)
195  LogTrace("MultiRecHitCollector") << " I am DT " << DTWireId(hitId);
196  else if (hitId.subdetId() == MuonSubdetId::CSC)
197  LogTrace("MultiRecHitCollector") << " I am CSC " << CSCDetId(hitId);
198  else if (hitId.subdetId() == MuonSubdetId::RPC)
199  LogTrace("MultiRecHitCollector") << " I am RPC " << RPCDetId(hitId);
200  else
201  LogTrace("MultiRecHitCollector") << " UNKNOWN MUON HIT TYPE ";
202  } else
203  LogTrace("MultiRecHitCollector") << " UNKNOWN HIT TYPE ";
204 
205  LogTrace("MultiRecHitCollector") << " TSOS predicted_fwd " << itrajmeas->predictedState().localPosition();
206  LogTrace("MultiRecHitCollector") << " TSOS predicted_bwd "
207  << itrajmeas->backwardPredictedState().localPosition();
208  LogTrace("MultiRecHitCollector") << " TSOS smoothtsos " << itrajmeas->updatedState().localPosition();
209  } else {
210  LogTrace("MultiRecHitCollector") << " Invalid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId();
211  }
212  LogTrace("MultiRecHitCollector") << "\n";
213  }
214 #endif
215 }
static constexpr auto TEC
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:178
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:48
static constexpr auto TOB
const MeasurementDet & mdet() const
#define LogTrace(id)
std::shared_ptr< TrackingRecHit const > RecHitPointer
Definition: DetId.h:17
static constexpr auto TIB
static constexpr int RPC
Definition: MuonSubdetId.h:13
std::vector< TrajectoryMeasurement > recHits(const Trajectory &, const MeasurementTrackerEvent *theMTE) const override
static constexpr int DT
Definition: MuonSubdetId.h:11
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const
static constexpr int CSC
Definition: MuonSubdetId.h:12
static constexpr auto TID
const bool Debug
def move(src, dest)
Definition: eostools.py:511
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46