CMS 3D CMS Logo

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