CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonCkfTrajectoryBuilder.cc
Go to the documentation of this file.
2 
4 
16 #include <sstream>
17 
19  CkfTrajectoryBuilder(conf, iC),
20  theDeltaEta(conf.getParameter<double>("deltaEta")),
21  theDeltaPhi(conf.getParameter<double>("deltaPhi")),
22  theProximityPropagatorName(conf.getParameter<std::string>("propagatorProximity")),
23  theProximityPropagator(nullptr),
24  theEtaPhiEstimator(nullptr)
25 {
26  //and something specific to me ?
27  theUseSeedLayer = conf.getParameter<bool>("useSeedLayer");
28  theRescaleErrorIfFail = conf.getParameter<double>("rescaleErrorIfFail");
29 }
30 
32 {
33 }
34 
36  CkfTrajectoryBuilder::setEvent_(iEvent, iSetup);
37 
38  edm::ESHandle<Propagator> propagatorProximityHandle;
39  iSetup.get<TrackingComponentsRecord>().get(theProximityPropagatorName, propagatorProximityHandle);
40  theProximityPropagator = propagatorProximityHandle.product();
41 
42  // theEstimator is set for this event in the base class
43  if(theEstimatorWatcher.check(iSetup) && theDeltaEta>0 && theDeltaPhi>0)
45 }
46 
47 
48 /*
49 std::string dumpMeasurement(const TrajectoryMeasurement & tm)
50 {
51  std::stringstream buffer;
52  buffer<<"layer pointer: "<<tm.layer()<<"\n"
53  <<"estimate: "<<tm.estimate()<<"\n"
54  <<"forward state: \n"
55  <<"x: "<<tm.forwardPredictedState().globalPosition()<<"\n"
56  <<"p: "<<tm.forwardPredictedState().globalMomentum()<<"\n"
57  <<"geomdet pointer from rechit: "<<tm.recHit()->det()<<"\n"
58  <<"detId: "<<tm.recHit()->geographicalId().rawId();
59  if (tm.recHit()->isValid()){
60  buffer<<"\n hit global x: "<<tm.recHit()->globalPosition()
61  <<"\n hit global error: "<<tm.recHit()->globalPositionError().matrix()
62  <<"\n hit local x:"<<tm.recHit()->localPosition()
63  <<"\n hit local error"<<tm.recHit()->localPositionError();
64  }
65  return buffer.str();
66 }
67 std::string dumpMeasurements(const std::vector<TrajectoryMeasurement> & v)
68 {
69  std::stringstream buffer;
70  buffer<<v.size()<<" total measurements\n";
71  for (std::vector<TrajectoryMeasurement>::const_iterator it = v.begin(); it!=v.end();++it){
72  buffer<<dumpMeasurement(*it);
73  buffer<<"\n";}
74  return buffer.str();
75 }
76 */
77 
79  const std::vector<const DetLayer*>& nl,
80  const TrajectoryStateOnSurface & currentState,
81  std::vector<TM>& result,int& invalidHits,
82  const Propagator * prop) const{
83  for (std::vector<const DetLayer*>::const_iterator il = nl.begin();
84  il != nl.end(); il++) {
85 
86  TSOS stateToUse = currentState;
87 
88  if (layer == (*il)){
89  LogDebug("CkfPattern")<<" self propagating in findCompatibleMeasurements.\n from: \n"<<stateToUse;
90  //self navigation case
91  // go to a middle point first
93  GlobalPoint center(0,0,0);
94  stateToUse = middle.extrapolate(stateToUse, center, *prop);
95 
96  if (!stateToUse.isValid()) continue;
97  LogDebug("CkfPattern")<<"to: "<<stateToUse;
98  }
99 
101  std::vector<TM> tmp =
102  layerMeasurements.measurements((**il),stateToUse, *prop, *theEstimator);
103 
104  if (tmp.size()==1 && theEtaPhiEstimator){
105  LogDebug("CkfPattern")<<"only an invalid hit is found. trying differently";
106  tmp = layerMeasurements.measurements((**il),stateToUse, *prop, *theEtaPhiEstimator);
107  }
108  LogDebug("CkfPattern")<<tmp.size()<<" measurements returned by LayerMeasurements";
109 
110  if ( !tmp.empty()) {
111  // FIXME durty-durty-durty cleaning: never do that please !
112  /* for (vector<TM>::iterator it = tmp.begin(); it!=tmp.end(); ++it)
113  {if (it->recHit()->det()==0) it=tmp.erase(it)--;}*/
114 
115  if ( result.empty()) result = tmp;
116  else {
117  // keep one dummy TM at the end, skip the others
118  result.insert( result.end()-invalidHits, tmp.begin(), tmp.end());
119  }
120  invalidHits++;
121  }
122  }
123 
124  LogDebug("CkfPattern")<<"starting from:\n"
125  <<"x: "<<currentState.globalPosition()<<"\n"
126  <<"p: "<<currentState.globalMomentum()<<"\n"
128 }
129 
130 
131 
132 void
134  const TempTrajectory& traj,
135  std::vector<TrajectoryMeasurement> & result) const
136 {
137  int invalidHits = 0;
138 
139 
140  std::vector<const DetLayer*> nl;
141 
142  if (traj.empty())
143  {
144  LogDebug("CkfPattern")<<"using JR patch for no measurement case";
145  //what if there are no measurement on the Trajectory
146 
147  //set the currentState to be the one from the trajectory seed starting point
149  DetId id(ptod.detId());
151  const Surface * surface=&g->surface();
152 
154 
155  //set the next layers to be that one the state is on
157 
158  if (theUseSeedLayer){
159  {
160  //get the measurements on the layer first
161  LogDebug("CkfPattern")<<"using the layer of the seed first.";
162  nl.push_back(l);
163  collectMeasurement(l,nl,currentState,result,invalidHits,theProximityPropagator);
164  }
165 
166  //if fails: try to rescale locally the state to find measurements
167  if ((unsigned int)invalidHits==result.size() && theRescaleErrorIfFail!=1.0 && result.size()!=0)
168  {
169  result.clear();
170  LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements.";
171  TrajectoryStateOnSurface rescaledCurrentState = currentState;
172  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
173  invalidHits=0;
174  collectMeasurement(l,nl,rescaledCurrentState,result,invalidHits,theProximityPropagator);
175  }
176  }
177 
178  //if fails: go to next layers
179  if (result.size()==0 || (unsigned int)invalidHits==result.size())
180  {
181  result.clear();
182  LogDebug("CkfPattern")<<"Need to go to next layer to get measurements";
183  //the following will "JUMP" the first layer measurements
184  nl = theNavigationSchool->nextLayers(*l, *currentState.freeState(), traj.direction());
185  if (nl.size()==0){
186  LogDebug("CkfPattern")<<" there was no next layer with wellInside. Use the next with no check.";
187  //means you did not get any compatible layer on the next 1/2 tracker layer.
188  // use the next layers with no checking
190  }
191  invalidHits=0;
192  collectMeasurement(l,nl,currentState,result,invalidHits,forwardPropagator(seed));
193  }
194 
195  //if fails: this is on the next layers already, try rescaling locally the state
196  if (result.size()!=0 && (unsigned int)invalidHits==result.size() && theRescaleErrorIfFail!=1.0)
197  {
198  result.clear();
199  LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements on next layers.";
200  TrajectoryStateOnSurface rescaledCurrentState = currentState;
201  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
202  invalidHits=0;
203  collectMeasurement(l,nl,rescaledCurrentState, result,invalidHits,forwardPropagator(seed));
204  }
205 
206  }
207  else //regular case
208  {
209 
210  TSOS currentState( traj.lastMeasurement().updatedState());
211 
212  nl = theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction());
213  if (nl.empty()){LogDebug("CkfPattern")<<" no next layers... going "<<traj.direction()<<"\n from: \n"<<currentState<<"\n from detId: "<<traj.lastMeasurement().recHit()->geographicalId().rawId(); return ;}
214 
215  collectMeasurement(traj.lastLayer(),nl,currentState,result,invalidHits,forwardPropagator(seed));
216  }
217 
218 
219  // sort the final result, keep dummy measurements at the end
220  if ( result.size() > 1) {
221  sort( result.begin(), result.end()-invalidHits, TrajMeasLessEstim());
222  }
223 
224 #ifdef DEBUG_INVALID
225  bool afterInvalid = false;
226  for (std::vector<TM>::const_iterator i=result.begin();
227  i!=result.end(); i++) {
228  if ( ! i->recHit().isValid()) afterInvalid = true;
229  if (afterInvalid && i->recHit().isValid()) {
230  edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: valid hit after invalid!" ;
231  }
232  }
233 #endif
234 
235  //analyseMeasurements( result, traj);
236 
237 }
238 
239 
#define LogDebug(id)
const Propagator * theProximityPropagator
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const TrackingGeometry * geomTracker() const
ConstRecHitPointer const & recHit() const
bool empty() const
True if trajectory has no measurements.
virtual void findCompatibleMeasurements(const TrajectorySeed &seed, const TempTrajectory &traj, std::vector< TrajectoryMeasurement > &result) const
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
GlobalPoint globalPosition() const
tuple magneticField
#define nullptr
static std::string dumpMeasurements(const std::vector< TrajectoryMeasurement > &v)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
tuple result
Definition: mps_fire.py:95
const TrajectoryMeasurement & lastMeasurement() const
PropagationDirection direction() const
int iEvent
Definition: GenABIO.cc:230
const std::string theProximityPropagatorName
FreeTrajectoryState const * freeState(bool withErrors=true) const
void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
unsigned int detId() const
MuonCkfTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector &iC)
const MeasurementTracker & measurementTracker() const
const MeasurementTrackerEvent * theMeasurementTracker
Definition: DetId.h:18
void collectMeasurement(const DetLayer *layer, const std::vector< const DetLayer * > &nl, const TrajectoryStateOnSurface &currentState, std::vector< TM > &result, int &invalidHits, const Propagator *) const
PTrajectoryStateOnDet const & startingState() const
std::unique_ptr< Chi2MeasurementEstimatorBase > theEtaPhiEstimator
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
virtual const GeomDet * idToDet(DetId) const =0
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&...args) const
NavigationDirection.
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
return(e1-e2)*(e1-e2)+dp *dp
edm::ESWatcher< BaseCkfTrajectoryBuilder::Chi2MeasurementEstimatorRecord > theEstimatorWatcher
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
GlobalVector globalMomentum() const
const NavigationSchool * theNavigationSchool
TrajectoryStateOnSurface const & updatedState() const
void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
const GeometricSearchTracker * geometricSearchTracker() const
const Chi2MeasurementEstimatorBase * theEstimator