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 
14 #include <sstream>
15 
17  const TrajectoryStateUpdator* updator,
18  const Propagator* propagatorAlong,
19  const Propagator* propagatorOpposite,
20  const Propagator* propagatorProximity,
21  const Chi2MeasurementEstimatorBase* estimator,
22  const TransientTrackingRecHitBuilder* RecHitBuilder,
23  const MeasurementTracker* measurementTracker,
24  const TrajectoryFilter* filter):
25  CkfTrajectoryBuilder(conf,updator,propagatorAlong,propagatorOpposite,estimator,RecHitBuilder,measurementTracker,filter),
26  theProximityPropagator(propagatorProximity)
27 {
28  //and something specific to me ?
29  theUseSeedLayer = conf.getParameter<bool>("useSeedLayer");
30  theRescaleErrorIfFail = conf.getParameter<double>("rescaleErrorIfFail");
31  double dEta=conf.getParameter<double>("deltaEta");
32  double dPhi=conf.getParameter<double>("deltaPhi");
33  if (dEta>0 && dPhi>0)
36 
37 
38 }
39 
41 {
43 }
44 
45 /*
46 std::string dumpMeasurement(const TrajectoryMeasurement & tm)
47 {
48  std::stringstream buffer;
49  buffer<<"layer pointer: "<<tm.layer()<<"\n"
50  <<"estimate: "<<tm.estimate()<<"\n"
51  <<"forward state: \n"
52  <<"x: "<<tm.forwardPredictedState().globalPosition()<<"\n"
53  <<"p: "<<tm.forwardPredictedState().globalMomentum()<<"\n"
54  <<"geomdet pointer from rechit: "<<tm.recHit()->det()<<"\n"
55  <<"detId: "<<tm.recHit()->geographicalId().rawId();
56  if (tm.recHit()->isValid()){
57  buffer<<"\n hit global x: "<<tm.recHit()->globalPosition()
58  <<"\n hit global error: "<<tm.recHit()->globalPositionError().matrix()
59  <<"\n hit local x:"<<tm.recHit()->localPosition()
60  <<"\n hit local error"<<tm.recHit()->localPositionError();
61  }
62  return buffer.str();
63 }
64 std::string dumpMeasurements(const std::vector<TrajectoryMeasurement> & v)
65 {
66  std::stringstream buffer;
67  buffer<<v.size()<<" total measurements\n";
68  for (std::vector<TrajectoryMeasurement>::const_iterator it = v.begin(); it!=v.end();++it){
69  buffer<<dumpMeasurement(*it);
70  buffer<<"\n";}
71  return buffer.str();
72 }
73 */
74 
76  const std::vector<const DetLayer*>& nl,
77  const TrajectoryStateOnSurface & currentState,
78  std::vector<TM>& result,int& invalidHits,
79  const Propagator * prop) const{
80  for (std::vector<const DetLayer*>::const_iterator il = nl.begin();
81  il != nl.end(); il++) {
82 
83  TSOS stateToUse = currentState;
84 
85  if (layer == (*il)){
86  LogDebug("CkfPattern")<<" self propagating in findCompatibleMeasurements.\n from: \n"<<stateToUse;
87  //self navigation case
88  // go to a middle point first
90  GlobalPoint center(0,0,0);
91  stateToUse = middle.extrapolate(stateToUse, center, *prop);
92 
93  if (!stateToUse.isValid()) continue;
94  LogDebug("CkfPattern")<<"to: "<<stateToUse;
95  }
96 
97  std::vector<TM> tmp =
98  theLayerMeasurements->measurements((**il),stateToUse, *prop, *theEstimator);
99 
100  if (tmp.size()==1 && theEtaPhiEstimator){
101  LogDebug("CkfPattern")<<"only an invalid hit is found. trying differently";
102  tmp = theLayerMeasurements->measurements((**il),stateToUse, *prop, *theEtaPhiEstimator);
103  }
104  LogDebug("CkfPattern")<<tmp.size()<<" measurements returned by LayerMeasurements";
105 
106  if ( !tmp.empty()) {
107  // FIXME durty-durty-durty cleaning: never do that please !
108  /* for (vector<TM>::iterator it = tmp.begin(); it!=tmp.end(); ++it)
109  {if (it->recHit()->det()==0) it=tmp.erase(it)--;}*/
110 
111  if ( result.empty()) result = tmp;
112  else {
113  // keep one dummy TM at the end, skip the others
114  result.insert( result.end()-invalidHits, tmp.begin(), tmp.end());
115  }
116  invalidHits++;
117  }
118  }
119 
120  LogDebug("CkfPattern")<<"starting from:\n"
121  <<"x: "<<currentState.globalPosition()<<"\n"
122  <<"p: "<<currentState.globalMomentum()<<"\n"
124 }
125 
126 
127 
128 void
130  const TempTrajectory& traj,
131  std::vector<TrajectoryMeasurement> & result) const
132 {
133  int invalidHits = 0;
134 
135 
136  std::vector<const DetLayer*> nl;
137 
138  if (traj.empty())
139  {
140  LogDebug("CkfPattern")<<"using JR patch for no measurement case";
141  //what if there are no measurement on the Trajectory
142 
143  //set the currentState to be the one from the trajectory seed starting point
145  DetId id(ptod.detId());
147  const Surface * surface=&g->surface();
148 
150 
151  //set the next layers to be that one the state is on
153 
154  if (theUseSeedLayer){
155  {
156  //get the measurements on the layer first
157  LogDebug("CkfPattern")<<"using the layer of the seed first.";
158  nl.push_back(l);
159  collectMeasurement(l,nl,currentState,result,invalidHits,theProximityPropagator);
160  }
161 
162  //if fails: try to rescale locally the state to find measurements
163  if ((unsigned int)invalidHits==result.size() && theRescaleErrorIfFail!=1.0 && result.size()!=0)
164  {
165  result.clear();
166  LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements.";
167  TrajectoryStateOnSurface rescaledCurrentState = currentState;
168  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
169  invalidHits=0;
170  collectMeasurement(l,nl,rescaledCurrentState,result,invalidHits,theProximityPropagator);
171  }
172  }
173 
174  //if fails: go to next layers
175  if (result.size()==0 || (unsigned int)invalidHits==result.size())
176  {
177  result.clear();
178  LogDebug("CkfPattern")<<"Need to go to next layer to get measurements";
179  //the following will "JUMP" the first layer measurements
180  nl = l->nextLayers(*currentState.freeState(), traj.direction());
181  if (nl.size()==0){
182  LogDebug("CkfPattern")<<" there was no next layer with wellInside. Use the next with no check.";
183  //means you did not get any compatible layer on the next 1/2 tracker layer.
184  // use the next layers with no checking
186  }
187  invalidHits=0;
188  collectMeasurement(l,nl,currentState,result,invalidHits,theForwardPropagator);
189  }
190 
191  //if fails: this is on the next layers already, try rescaling locally the state
192  if (result.size()!=0 && (unsigned int)invalidHits==result.size() && theRescaleErrorIfFail!=1.0)
193  {
194  result.clear();
195  LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements on next layers.";
196  TrajectoryStateOnSurface rescaledCurrentState = currentState;
197  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
198  invalidHits=0;
199  collectMeasurement(l,nl,rescaledCurrentState, result,invalidHits,theForwardPropagator);
200  }
201 
202  }
203  else //regular case
204  {
205 
206  TSOS currentState( traj.lastMeasurement().updatedState());
207 
208  nl = traj.lastLayer()->nextLayers( *currentState.freeState(), traj.direction());
209  if (nl.empty()){LogDebug("CkfPattern")<<" no next layers... going "<<traj.direction()<<"\n from: \n"<<currentState<<"\n from detId: "<<traj.lastMeasurement().recHit()->geographicalId().rawId(); return ;}
210 
211  collectMeasurement(traj.lastLayer(),nl,currentState,result,invalidHits,theForwardPropagator);
212  }
213 
214 
215  // sort the final result, keep dummy measurements at the end
216  if ( result.size() > 1) {
217  sort( result.begin(), result.end()-invalidHits, TrajMeasLessEstim());
218  }
219 
220 #ifdef DEBUG_INVALID
221  bool afterInvalid = false;
222  for (std::vector<TM>::const_iterator i=result.begin();
223  i!=result.end(); i++) {
224  if ( ! i->recHit().isValid()) afterInvalid = true;
225  if (afterInvalid && i->recHit().isValid()) {
226  edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: valid hit after invalid!" ;
227  }
228  }
229 #endif
230 
231  //analyseMeasurements( result, traj);
232 
233 }
234 
235 
#define LogDebug(id)
const Propagator * theProximityPropagator
T getParameter(std::string const &) const
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
int i
Definition: DBlmapReader.cc:9
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
GlobalPoint globalPosition() const
Chi2MeasurementEstimatorBase * theEtaPhiEstimator
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
const TrajectoryMeasurement & lastMeasurement() const
const LayerMeasurements * theLayerMeasurements
PropagationDirection direction() const
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
FreeTrajectoryState * freeState(bool withErrors=true) const
tuple result
Definition: query.py:137
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
const TrackingGeometry * geomTracker() const
unsigned int detId() const
tuple conf
Definition: dbtoconf.py:185
Definition: DetId.h:20
const MeasurementTracker * theMeasurementTracker
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
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
virtual const GeomDet * idToDet(DetId) const =0
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual const MagneticField * magneticField() const =0
GlobalVector globalMomentum() const
MuonCkfTrajectoryBuilder(const edm::ParameterSet &conf, const TrajectoryStateUpdator *updator, const Propagator *propagatorAlong, const Propagator *propagatorOpposite, const Propagator *propagatorProximity, const Chi2MeasurementEstimatorBase *estimator, const TransientTrackingRecHitBuilder *RecHitBuilder, const MeasurementTracker *measurementTracker, const TrajectoryFilter *filter)
TrajectoryStateOnSurface const & updatedState() const
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
const GeometricSearchTracker * geometricSearchTracker() const
std::vector< const DetLayer * > nextLayers(Args &&...args) const
Definition: DetLayer.h:60
const Chi2MeasurementEstimatorBase * theEstimator
const Propagator * theForwardPropagator