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  std::vector<TrajectoryMeasurement> & result) const
131 {
132  int invalidHits = 0;
133 
134 
135  std::vector<const DetLayer*> nl;
136 
137  if (traj.empty())
138  {
139  LogDebug("CkfPattern")<<"using JR patch for no measurement case";
140  //what if there are no measurement on the Trajectory
141 
142  //set the currentState to be the one from the trajectory seed starting point
144  DetId id(ptod.detId());
146  const Surface * surface=&g->surface();
147 
149 
150  //set the next layers to be that one the state is on
152 
153  if (theUseSeedLayer){
154  {
155  //get the measurements on the layer first
156  LogDebug("CkfPattern")<<"using the layer of the seed first.";
157  nl.push_back(l);
158  collectMeasurement(l,nl,currentState,result,invalidHits,theProximityPropagator);
159  }
160 
161  //if fails: try to rescale locally the state to find measurements
162  if ((unsigned int)invalidHits==result.size() && theRescaleErrorIfFail!=1.0 && result.size()!=0)
163  {
164  result.clear();
165  LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements.";
166  TrajectoryStateOnSurface rescaledCurrentState = currentState;
167  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
168  invalidHits=0;
169  collectMeasurement(l,nl,rescaledCurrentState,result,invalidHits,theProximityPropagator);
170  }
171  }
172 
173  //if fails: go to next layers
174  if (result.size()==0 || (unsigned int)invalidHits==result.size())
175  {
176  result.clear();
177  LogDebug("CkfPattern")<<"Need to go to next layer to get measurements";
178  //the following will "JUMP" the first layer measurements
179  nl = l->nextLayers(*currentState.freeState(), traj.direction());
180  if (nl.size()==0){
181  LogDebug("CkfPattern")<<" there was no next layer with wellInside. Use the next with no check.";
182  //means you did not get any compatible layer on the next 1/2 tracker layer.
183  // use the next layers with no checking
185  }
186  invalidHits=0;
187  collectMeasurement(l,nl,currentState,result,invalidHits,theForwardPropagator);
188  }
189 
190  //if fails: this is on the next layers already, try rescaling locally the state
191  if (result.size()!=0 && (unsigned int)invalidHits==result.size() && theRescaleErrorIfFail!=1.0)
192  {
193  result.clear();
194  LogDebug("CkfPattern")<<"using a rescale by "<< theRescaleErrorIfFail <<" to find measurements on next layers.";
195  TrajectoryStateOnSurface rescaledCurrentState = currentState;
196  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
197  invalidHits=0;
198  collectMeasurement(l,nl,rescaledCurrentState, result,invalidHits,theForwardPropagator);
199  }
200 
201  }
202  else //regular case
203  {
204 
205  TSOS currentState( traj.lastMeasurement().updatedState());
206 
207  nl = traj.lastLayer()->nextLayers( *currentState.freeState(), traj.direction());
208  if (nl.empty()){LogDebug("CkfPattern")<<" no next layers... going "<<traj.direction()<<"\n from: \n"<<currentState<<"\n from detId: "<<traj.lastMeasurement().recHit()->geographicalId().rawId(); return ;}
209 
210  collectMeasurement(traj.lastLayer(),nl,currentState,result,invalidHits,theForwardPropagator);
211  }
212 
213 
214  // sort the final result, keep dummy measurements at the end
215  if ( result.size() > 1) {
216  sort( result.begin(), result.end()-invalidHits, TrajMeasLessEstim());
217  }
218 
219 #ifdef DEBUG_INVALID
220  bool afterInvalid = false;
221  for (std::vector<TM>::const_iterator i=result.begin();
222  i!=result.end(); i++) {
223  if ( ! i->recHit().isValid()) afterInvalid = true;
224  if (afterInvalid && i->recHit().isValid()) {
225  edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: valid hit after invalid!" ;
226  }
227  }
228 #endif
229 
230  //analyseMeasurements( result, traj);
231 
232 }
233 
234 
#define LogDebug(id)
const Propagator * theProximityPropagator
T getParameter(std::string const &) const
const TrajectorySeed & seed() const
Access to the seed used to reconstruct the Trajectory.
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
int i
Definition: DBlmapReader.cc:9
bool empty() const
True if trajectory has no measurements.
virtual std::vector< const DetLayer * > nextLayers(NavigationDirection direction) const
Definition: DetLayer.cc:35
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() 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
TrajectoryStateOnSurface updatedState() const
virtual void findCompatibleMeasurements(const TempTrajectory &traj, std::vector< TrajectoryMeasurement > &result) 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)
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
const GeometricSearchTracker * geometricSearchTracker() const
const Chi2MeasurementEstimatorBase * theEstimator
const Propagator * theForwardPropagator