CMS 3D CMS Logo

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