CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonCkfTrajectoryBuilder.cc
Go to the documentation of this file.
2 
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  thePropagatorToken(iC.esConsumes(edm::ESInputTag("", theProximityPropagatorName))),
25  theEtaPhiEstimator(nullptr) {
26  //and something specific to me ?
27  theUseSeedLayer = conf.getParameter<bool>("useSeedLayer");
28  theRescaleErrorIfFail = conf.getParameter<double>("rescaleErrorIfFail");
29 }
30 
32 
34  CkfTrajectoryBuilder::setEvent_(iEvent, iSetup);
35 
37 
38  // theEstimator is set for this event in the base class
39  if (theEstimatorWatcher.check(iSetup) && theDeltaEta > 0 && theDeltaPhi > 0)
40  theEtaPhiEstimator = std::make_unique<EtaPhiEstimator>(theDeltaEta, theDeltaPhi, theEstimator);
41 }
42 
43 /*
44 std::string dumpMeasurement(const TrajectoryMeasurement & tm)
45 {
46  std::stringstream buffer;
47  buffer<<"layer pointer: "<<tm.layer()<<"\n"
48  <<"estimate: "<<tm.estimate()<<"\n"
49  <<"forward state: \n"
50  <<"x: "<<tm.forwardPredictedState().globalPosition()<<"\n"
51  <<"p: "<<tm.forwardPredictedState().globalMomentum()<<"\n"
52  <<"geomdet pointer from rechit: "<<tm.recHit()->det()<<"\n"
53  <<"detId: "<<tm.recHit()->geographicalId().rawId();
54  if (tm.recHit()->isValid()){
55  buffer<<"\n hit global x: "<<tm.recHit()->globalPosition()
56  <<"\n hit global error: "<<tm.recHit()->globalPositionError().matrix()
57  <<"\n hit local x:"<<tm.recHit()->localPosition()
58  <<"\n hit local error"<<tm.recHit()->localPositionError();
59  }
60  return buffer.str();
61 }
62 std::string dumpMeasurements(const std::vector<TrajectoryMeasurement> & v)
63 {
64  std::stringstream buffer;
65  buffer<<v.size()<<" total measurements\n";
66  for (std::vector<TrajectoryMeasurement>::const_iterator it = v.begin(); it!=v.end();++it){
67  buffer<<dumpMeasurement(*it);
68  buffer<<"\n";}
69  return buffer.str();
70 }
71 */
72 
74  const std::vector<const DetLayer*>& nl,
75  const TrajectoryStateOnSurface& currentState,
76  std::vector<TM>& result,
77  int& invalidHits,
78  const Propagator* prop) const {
79  for (std::vector<const DetLayer*>::const_iterator il = nl.begin(); il != nl.end(); il++) {
80  TSOS stateToUse = currentState;
81 
82  if (layer == (*il)) {
83  LogDebug("CkfPattern") << " self propagating in findCompatibleMeasurements.\n from: \n" << stateToUse;
84  //self navigation case
85  // go to a middle point first
87  GlobalPoint center(0, 0, 0);
88  stateToUse = middle.extrapolate(stateToUse, center, *prop);
89 
90  if (!stateToUse.isValid())
91  continue;
92  LogDebug("CkfPattern") << "to: " << stateToUse;
93  }
94 
96  std::vector<TM> tmp = layerMeasurements.measurements((**il), stateToUse, *prop, *theEstimator);
97 
98  if (tmp.size() == 1 && theEtaPhiEstimator) {
99  LogDebug("CkfPattern") << "only an invalid hit is found. trying differently";
100  tmp = layerMeasurements.measurements((**il), stateToUse, *prop, *theEtaPhiEstimator);
101  }
102  LogDebug("CkfPattern") << tmp.size() << " measurements returned by LayerMeasurements";
103 
104  if (!tmp.empty()) {
105  // FIXME durty-durty-durty cleaning: never do that please !
106  /* for (vector<TM>::iterator it = tmp.begin(); it!=tmp.end(); ++it)
107  {if (it->recHit()->det()==0) it=tmp.erase(it)--;}*/
108 
109  if (result.empty())
110  result = tmp;
111  else {
112  // keep one dummy TM at the end, skip the others
113  result.insert(result.end() - invalidHits, tmp.begin(), tmp.end());
114  }
115  invalidHits++;
116  }
117  }
118 
119  LogDebug("CkfPattern") << "starting from:\n"
120  << "x: " << currentState.globalPosition() << "\n"
121  << "p: " << currentState.globalMomentum() << "\n"
123 }
124 
126  const TempTrajectory& traj,
127  std::vector<TrajectoryMeasurement>& result) const {
128  int invalidHits = 0;
129 
130  std::vector<const DetLayer*> nl;
131 
132  if (traj.empty()) {
133  LogDebug("CkfPattern") << "using JR patch for no measurement case";
134  //what if there are no measurement on the Trajectory
135 
136  //set the currentState to be the one from the trajectory seed starting point
137  PTrajectoryStateOnDet ptod = seed.startingState();
138  DetId id(ptod.detId());
140  const Surface* surface = &g->surface();
141 
142  TrajectoryStateOnSurface currentState(
144 
145  //set the next layers to be that one the state is on
147 
148  if (theUseSeedLayer) {
149  {
150  //get the measurements on the layer first
151  LogDebug("CkfPattern") << "using the layer of the seed first.";
152  nl.push_back(l);
153  collectMeasurement(l, nl, currentState, result, invalidHits, theProximityPropagator);
154  }
155 
156  //if fails: try to rescale locally the state to find measurements
157  if ((unsigned int)invalidHits == result.size() && theRescaleErrorIfFail != 1.0 && !result.empty()) {
158  result.clear();
159  LogDebug("CkfPattern") << "using a rescale by " << theRescaleErrorIfFail << " to find measurements.";
160  TrajectoryStateOnSurface rescaledCurrentState = currentState;
161  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
162  invalidHits = 0;
163  collectMeasurement(l, nl, rescaledCurrentState, result, invalidHits, theProximityPropagator);
164  }
165  }
166 
167  //if fails: go to next layers
168  if (result.empty() || (unsigned int)invalidHits == result.size()) {
169  result.clear();
170  LogDebug("CkfPattern") << "Need to go to next layer to get measurements";
171  //the following will "JUMP" the first layer measurements
172  nl = theNavigationSchool->nextLayers(*l, *currentState.freeState(), traj.direction());
173  if (nl.empty()) {
174  LogDebug("CkfPattern") << " there was no next layer with wellInside. Use the next with no check.";
175  //means you did not get any compatible layer on the next 1/2 tracker layer.
176  // use the next layers with no checking
178  }
179  invalidHits = 0;
180  collectMeasurement(l, nl, currentState, result, invalidHits, forwardPropagator(seed));
181  }
182 
183  //if fails: this is on the next layers already, try rescaling locally the state
184  if (!result.empty() && (unsigned int)invalidHits == result.size() && theRescaleErrorIfFail != 1.0) {
185  result.clear();
186  LogDebug("CkfPattern") << "using a rescale by " << theRescaleErrorIfFail
187  << " to find measurements on next layers.";
188  TrajectoryStateOnSurface rescaledCurrentState = currentState;
189  rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
190  invalidHits = 0;
191  collectMeasurement(l, nl, rescaledCurrentState, result, invalidHits, forwardPropagator(seed));
192  }
193 
194  } else //regular case
195  {
196  TSOS currentState(traj.lastMeasurement().updatedState());
197 
198  nl = theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction());
199  if (nl.empty()) {
200  LogDebug("CkfPattern") << " no next layers... going " << traj.direction() << "\n from: \n"
201  << currentState
202  << "\n from detId: " << traj.lastMeasurement().recHit()->geographicalId().rawId();
203  return;
204  }
205 
206  collectMeasurement(traj.lastLayer(), nl, currentState, result, invalidHits, forwardPropagator(seed));
207  }
208 
209  // sort the final result, keep dummy measurements at the end
210  if (result.size() > 1) {
211  sort(result.begin(), result.end() - invalidHits, TrajMeasLessEstim());
212  }
213 
214 #ifdef DEBUG_INVALID
215  bool afterInvalid = false;
216  for (std::vector<TM>::const_iterator i = result.begin(); i != result.end(); i++) {
217  if (!i->recHit().isValid())
218  afterInvalid = true;
219  if (afterInvalid && i->recHit().isValid()) {
220  edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: valid hit after invalid!";
221  }
222  }
223 #endif
224 
225  //analyseMeasurements( result, traj);
226 }
const Propagator * theProximityPropagator
ConstRecHitPointer const & recHit() const
bool empty() const
True if trajectory has no measurements.
uint16_t *__restrict__ id
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorToken
GlobalPoint globalPosition() const
tuple magneticField
Log< level::Error, false > LogError
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
constexpr std::array< uint8_t, layerIndexSize > layer
tuple result
Definition: mps_fire.py:311
const TrajectoryMeasurement & lastMeasurement() const
bool getData(T &iHolder) const
Definition: EventSetup.h:128
PropagationDirection direction() const
int iEvent
Definition: GenABIO.cc:224
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 TrackerGeomDet * idToDet(DetId) const override
const MeasurementTracker & measurementTracker() const
const MeasurementTrackerEvent * theMeasurementTracker
Definition: DetId.h:17
void collectMeasurement(const DetLayer *layer, const std::vector< const DetLayer * > &nl, const TrajectoryStateOnSurface &currentState, std::vector< TM > &result, int &invalidHits, const Propagator *) const
const TrackerGeometry * geomTracker() const
PTrajectoryStateOnDet const & startingState() const
std::unique_ptr< Chi2MeasurementEstimatorBase > theEtaPhiEstimator
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&...args) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void findCompatibleMeasurements(const TrajectorySeed &seed, const TempTrajectory &traj, std::vector< TrajectoryMeasurement > &result) const override
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESWatcher< BaseCkfTrajectoryBuilder::Chi2MeasurementEstimatorRecord > theEstimatorWatcher
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
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() .
tmp
align.sh
Definition: createJobs.py:716
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const GeometricSearchTracker * geometricSearchTracker() const
const Chi2MeasurementEstimatorBase * theEstimator
#define LogDebug(id)