CMS 3D CMS Logo

SimpleDAFHitCollector.cc
Go to the documentation of this file.
10 
11 #ifdef EDM_ML_DEBUG
19 #endif
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,
29  const MeasurementTrackerEvent* theMTE) const {
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())
38  return vector<TrajectoryMeasurement>();
39 
40  LogTrace("MultiRecHitCollector") << " Original measurements are:";
41  Debug(meas);
42 
43  //groups hits on a sensor by sensor with same Id of previous TM
44  //we have to sort the TrajectoryMeasurements in the opposite way in the fitting direction
45  vector<TrajectoryMeasurement> result;
46  for (vector<TrajectoryMeasurement>::const_reverse_iterator itrajmeas = meas.rbegin(); itrajmeas < meas.rend();
47  itrajmeas++, hitcounter++) {
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())
69  combtsos = predtsos_fwd;
70  else if (hitcounter == 1)
71  combtsos = predtsos_bwd;
72  else
73  combtsos = combiner(predtsos_bwd, predtsos_fwd);
74 
75  //collected hits compatible with the itrajmeas
76  if (measDet.measurements(smoothtsos, *(getEstimator()), tmps)) {
77  LogTrace("MultiRecHitCollector") << " Found " << tmps.size() << " compatible measurements";
78 
79  for (std::size_t i = 0; i != tmps.size(); ++i) {
80  DetId idtemps = tmps.hits[i]->geographicalId();
81 
82  if (idtemps == id && tmps.hits[i]->hit()->isValid()) {
83  LogTrace("MultiRecHitCollector") << " This is valid with position " << tmps.hits[i]->hit()->localPosition()
84  << " and error " << tmps.hits[i]->hit()->localPositionError();
85 
86  TransientTrackingRecHit::RecHitPointer transient = theUpdator->getBuilder()->build(tmps.hits[i]->hit());
87  TrackingRecHit::ConstRecHitPointer preciseHit = theHitCloner.makeShared(transient, combtsos);
88  auto righthit = rightdimension(*preciseHit);
89  hitsOwner.push_back(std::move(righthit));
90  hits.push_back(hitsOwner.back().get());
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())
102  continue;
103 
104  result.push_back(TrajectoryMeasurement(
105  predtsos_fwd, std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
106  } else {
107  //measurements in groups are sorted with increating chi2
108  //sort( *hits.begin(), *hits.end(), TrajMeasLessEstim());
109  if (!itrajmeas->recHit()->isValid())
110  LogTrace("MultiRecHitCollector")
111  << " -> " << hits.size() << " valid hits for this sensor. (IT WAS INVALID!!!)";
112  else
113  LogTrace("MultiRecHitCollector") << " -> " << hits.size() << " valid hits for this sensor.";
114 
115  //building a MultiRecHit out of each sensor group
116  result.push_back(TrajectoryMeasurement(predtsos_fwd, theUpdator->buildMultiRecHit(hits, combtsos, measDet)));
117  }
118  } else {
119  LogTrace("MultiRecHitCollector") << " No measurements found in current group.";
120  //the error was scaled, now is scaled back (even if this is not tightly necessary)
121  // if (smoothtsos.isValid()) smoothtsos.rescaleError(0.1);
122 
123  if (result.empty())
124  continue;
125 
126  result.push_back(TrajectoryMeasurement(
127  predtsos_fwd, std::make_shared<InvalidTrackingRecHit>(measDet.mdet().geomDet(), TrackingRecHit::missing)));
128  }
129  }
130  LogTrace("MultiRecHitCollector") << " Ending SimpleDAFHitCollector::recHits >> " << result.size();
131 
132  //LogTrace("MultiRecHitCollector") << " New measurements are:";
133  //Debug(result);
134 
135  //adding a protection against too few hits and invalid hits
136  //(due to failed propagation on the same surface of the original hits)
137  if (result.size() > 2) {
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())
142  hitcounter++;
143  }
144 
145  if (hitcounter > 2)
146  return result;
147  else
148  return vector<TrajectoryMeasurement>();
149  }
150 
151  else {
152  return vector<TrajectoryMeasurement>();
153  }
154 }
155 
156 void SimpleDAFHitCollector::Debug(const std::vector<TrajectoryMeasurement> TM) const {
157 #ifdef EDM_ML_DEBUG
158  for (vector<TrajectoryMeasurement>::const_iterator itrajmeas = TM.begin(); itrajmeas < TM.end(); itrajmeas++) {
159  if (itrajmeas->recHit()->isValid()) {
160  LogTrace("MultiRecHitCollector") << " Valid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId()
161  << " and dim:"
162  << itrajmeas->recHit()->dimension()
163  //<< " type " << typeid(itrajmeas->recHit()).name()
164  << " local position " << itrajmeas->recHit()->hit()->localPosition()
165  << " global position " << itrajmeas->recHit()->hit()->globalPosition()
166  << " and r " << itrajmeas->recHit()->hit()->globalPosition().perp();
167 
168  DetId hitId = itrajmeas->recHit()->geographicalId();
169 
170  if (hitId.det() == DetId::Tracker) {
171  switch (hitId.subdetId()) {
173  LogTrace("MultiRecHitCollector") << " I am TIB " << theTopology->tibLayer(hitId);
174  break;
176  LogTrace("MultiRecHitCollector") << " I am TOB " << theTopology->tobLayer(hitId);
177  break;
179  LogTrace("MultiRecHitCollector") << " I am TEC " << theTopology->tecWheel(hitId);
180  break;
182  LogTrace("MultiRecHitCollector") << " I am TID " << theTopology->tidWheel(hitId);
183  break;
185  LogTrace("MultiRecHitCollector") << " I am PixBar " << theTopology->pxbLayer(hitId);
186  break;
188  LogTrace("MultiRecHitCollector") << " I am PixFwd " << theTopology->pxfDisk(hitId);
189  break;
190  default:
191  LogTrace("MultiRecHitCollector") << " UNKNOWN TRACKER HIT TYPE ";
192  break;
193  }
194  } else if (hitId.det() == DetId::Muon) {
195  if (hitId.subdetId() == MuonSubdetId::DT)
196  LogTrace("MultiRecHitCollector") << " I am DT " << DTWireId(hitId);
197  else if (hitId.subdetId() == MuonSubdetId::CSC)
198  LogTrace("MultiRecHitCollector") << " I am CSC " << CSCDetId(hitId);
199  else if (hitId.subdetId() == MuonSubdetId::RPC)
200  LogTrace("MultiRecHitCollector") << " I am RPC " << RPCDetId(hitId);
201  else
202  LogTrace("MultiRecHitCollector") << " UNKNOWN MUON HIT TYPE ";
203  } else
204  LogTrace("MultiRecHitCollector") << " UNKNOWN HIT TYPE ";
205 
206  LogTrace("MultiRecHitCollector") << " TSOS predicted_fwd " << itrajmeas->predictedState().localPosition();
207  LogTrace("MultiRecHitCollector") << " TSOS predicted_bwd "
208  << itrajmeas->backwardPredictedState().localPosition();
209  LogTrace("MultiRecHitCollector") << " TSOS smoothtsos " << itrajmeas->updatedState().localPosition();
210  } else {
211  LogTrace("MultiRecHitCollector") << " Invalid Hit with DetId " << itrajmeas->recHit()->geographicalId().rawId();
212  }
213  LogTrace("MultiRecHitCollector") << "\n";
214  }
215 #endif
216 }
TrajectoryStateCombiner.h
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
mps_fire.i
i
Definition: mps_fire.py:428
MeasurementTrackerEvent.h
SimpleDAFHitCollector::Debug
void Debug(const std::vector< TrajectoryMeasurement > TM) const
Definition: SimpleDAFHitCollector.cc:156
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
tracking::TempMeasurements::size
std::size_t size() const
Definition: TempMeasurements.h:20
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
RPCDetId
Definition: RPCDetId.h:16
TrackingRecHit::RecHitPointer
std::shared_ptr< TrackingRecHit const > RecHitPointer
Definition: TrackingRecHit.h:24
tracking::TempMeasurements
Definition: TempMeasurements.h:10
CSCDetId.h
DetId
Definition: DetId.h:17
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
TrackerTopology.h
Debug
const bool Debug
Definition: CosmicMuonParameters.h:12
DTWireId
Definition: DTWireId.h:12
MeasurementEstimator.h
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
RPCDetId.h
TrajectoryStateCombiner
Definition: TrajectoryStateCombiner.h:13
DetId::Tracker
Definition: DetId.h:25
TrackingRecHit::missing
Definition: TrackingRecHit.h:47
CSCDetId
Definition: CSCDetId.h:26
TrackingRecHit::ConstRecHitPointer
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
Definition: TrackingRecHit.h:25
IdealGeometryRecord.h
MuonSubdetId.h
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
SiStripRecHit1D.h
MeasurementDetWithData::mdet
const MeasurementDet & mdet() const
Definition: MeasurementDetWithData.h:15
Trajectory.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
MeasurementDetWithData
Definition: MeasurementDetWithData.h:6
DTWireId.h
SimpleDAFHitCollector.h
Trajectory
Definition: Trajectory.h:38
SimpleDAFHitCollector::recHits
std::vector< TrajectoryMeasurement > recHits(const Trajectory &, const MeasurementTrackerEvent *theMTE) const override
Definition: SimpleDAFHitCollector.cc:28
MuonSubdetId::RPC
static constexpr int RPC
Definition: MuonSubdetId.h:13
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
mps_fire.result
result
Definition: mps_fire.py:311
DetId::Muon
Definition: DetId.h:26
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
heavyFlavorValidationHarvestingSequence_cff.combiner
combiner
Definition: heavyFlavorValidationHarvestingSequence_cff.py:107
InvalidTrackingRecHit.h
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
StripSubdetector.h
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
MeasurementDetWithData::measurements
bool measurements(const TrajectoryStateOnSurface &stateOnThisDet, const MeasurementEstimator &est, TempMeasurements &result) const
Definition: MeasurementDetWithData.h:54
SiTrackerMultiRecHitUpdator.h
MeasurementDet.h
HLTSiStripMonitoring_cff.MeasurementTrackerEvent
MeasurementTrackerEvent
Definition: HLTSiStripMonitoring_cff.py:224
tracking::TempMeasurements::hits
RecHitContainer hits
Definition: TempMeasurements.h:40
MeasurementDet::geomDet
virtual const GeomDet & geomDet() const
Definition: MeasurementDet.h:81