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