CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StandAloneMuonFilter.cc
Go to the documentation of this file.
1 
10 
12 
13 // FIXME: remove this
15 
22 
24 
26 
28 
32 
35 
36 #include <vector>
37 
38 using namespace edm;
39 using namespace std;
40 
42  const MuonServiceProxy* service,
44 :theService(service),
45  theOverlappingChambersFlag(true)
46 {
47  // Fit direction
48  string fitDirectionName = par.getParameter<string>("FitDirection");
49 
50  if (fitDirectionName == "insideOut" ) theFitDirection = insideOut;
51  else if (fitDirectionName == "outsideIn" ) theFitDirection = outsideIn;
52  else
53  throw cms::Exception("StandAloneMuonFilter constructor")
54  <<"Wrong fit direction chosen in StandAloneMuonFilter::StandAloneMuonFilter ParameterSet"
55  << "\n"
56  << "Possible choices are:"
57  << "\n"
58  << "FitDirection = insideOut or FitDirection = outsideIn";
59 
60  // The max allowed chi2 to accept a rechit in the fit
61  theMaxChi2 = par.getParameter<double>("MaxChi2");
62 
63  // The errors of the trajectory state are multiplied by nSigma
64  // to define acceptance of BoundPlane and maximalLocalDisplacement
65  theNSigma = par.getParameter<double>("NumberOfSigma"); // default = 3.
66 
67  // The navigation type:
68  // "Direct","Standard"
69  theNavigationType = par.getParameter<string>("NavigationType");
70 
71  // The estimator: makes the decision wheter a measure is good or not
72  // it isn't used by the updator which does the real fit. In fact, in principle,
73  // a looser request onto the measure set can be requested
74  // (w.r.t. the request on the accept/reject measure in the fit)
76 
77  thePropagatorName = par.getParameter<string>("Propagator");
78 
80 
81  // Muon trajectory updator parameters
82  ParameterSet muonUpdatorPSet = par.getParameter<ParameterSet>("MuonTrajectoryUpdatorParameters");
83 
84  // the updator needs the fit direction
85  theMuonUpdator = new MuonTrajectoryUpdator(muonUpdatorPSet,
86  fitDirection() );
87 
88  // Measurement Extractor: enable the measure for each muon sub detector
89  bool enableDTMeasurement = par.getParameter<bool>("EnableDTMeasurement");
90  bool enableCSCMeasurement = par.getParameter<bool>("EnableCSCMeasurement");
91  bool enableRPCMeasurement = par.getParameter<bool>("EnableRPCMeasurement");
92  bool enableGEMMeasurement = par.getParameter<bool>("EnableGEMMeasurement");
93 
95  par.getParameter<InputTag>("CSCRecSegmentLabel"),
96  par.getParameter<InputTag>("RPCRecSegmentLabel"),
97  par.getParameter<InputTag>("GEMRecSegmentLabel"),
98  iC,
99  enableDTMeasurement,
100  enableCSCMeasurement,
101  enableRPCMeasurement,
102  enableGEMMeasurement);
103 
104  theRPCLoneliness = (!(enableDTMeasurement && enableCSCMeasurement)) ? enableRPCMeasurement : false;
105 }
106 
108 
109  LogTrace("Muon|RecoMuon|StandAloneMuonFilter")
110  <<"StandAloneMuonFilter destructor called"<<endl;
111 
112  delete theEstimator;
113  delete theMuonUpdator;
116 }
117 
119  return &*theService->propagator(thePropagatorName);
120 }
121 
124  if( fitDirection() == 0 ) return alongMomentum;
125  else if ( fitDirection() == 1 ) return oppositeToMomentum;
126  else return anyDirection;
127 }
128 
129 
133 
135 
137 
138  theDetLayers.clear();
139 }
140 
143 }
144 
145 
147 
149  else if(layer->subDetector()==GeomDetEnumerators::CSC) cscChambers++;
151  else if(layer->subDetector()==GeomDetEnumerators::GEM) gemChambers++;
152  else
153  LogError("Muon|RecoMuon|StandAloneMuonFilter")
154  << "Unrecognized module type in incrementChamberCounters";
155  // FIXME:
156  // << layer->module() << " " <<layer->Part() << endl;
157 
158  totalChambers++;
159 }
160 
162 
167  else
168  LogError("Muon|RecoMuon|StandAloneMuonFilter")
169  << "Unrecognized module type in incrementCompatibleChamberCounters";
170 
172 }
173 
174 
175 vector<const DetLayer*> StandAloneMuonFilter::compatibleLayers(const DetLayer *initialLayer,
176  const FreeTrajectoryState& fts,
177  PropagationDirection propDir){
178  vector<const DetLayer*> detLayers;
179 
180  if(theNavigationType == "Standard"){
181  // ask for compatible layers
182  detLayers = theService->muonNavigationSchool()->compatibleLayers(*initialLayer,fts,propDir);
183  // I have to fit by hand the first layer until the seedTSOS is defined on the first rechit layer
184  // In fact the first layer is not returned by initialLayer->compatibleLayers.
185  detLayers.insert(detLayers.begin(),initialLayer);
186  }
187  else if (theNavigationType == "Direct"){
188  DirectMuonNavigation navigation(theService->detLayerGeometry());
189  detLayers = navigation.compatibleLayers(fts,propDir);
190  }
191  else
192  edm::LogError("Muon|RecoMuon|StandAloneMuonFilter") << "No Properly Navigation Selected!!"<<endl;
193 
194  return detLayers;
195 }
196 
197 
199  const DetLayer* initialLayer, Trajectory &trajectory){
200 
201  const std::string metname = "Muon|RecoMuon|StandAloneMuonFilter";
202 
203  // reset the refitter each seed refinement
204  reset();
205 
207 
208  LogTrace(metname) << "Starting the refit"<<endl;
209 
210  // this is the most outward TSOS (updated or predicted) onto a DetLayer
212 
213  double eta0 = initialTSOS.freeTrajectoryState()->momentum().eta();
214  vector<const DetLayer*> detLayers = compatibleLayers(initialLayer,*initialTSOS.freeTrajectoryState(),
216 
217  LogTrace(metname)<<"compatible layers found: "<<detLayers.size()<<endl;
218 
219  vector<const DetLayer*>::const_iterator layer;
220 
221  // the layers are ordered in agreement with the fit/propagation direction
222  for ( layer = detLayers.begin(); layer!= detLayers.end(); ++layer ) {
223 
224  // bool firstTime = true;
225 
226  LogTrace(metname) << debug.dumpLayer(*layer);
227 
228  LogTrace(metname) << "search Trajectory Measurement from: " << lastTSOS.globalPosition();
229 
230  // pick the best measurement from each group
231  std::vector<TrajectoryMeasurement> bestMeasurements = findBestMeasurements(*layer, lastTSOS);
232 
233  // RB: Different ways can be choosen if no bestMeasurement is available:
234  // 1- check on lastTSOS-initialTSOS eta difference
235  // 2- check on lastTSOS-lastButOneUpdatedTSOS eta difference
236  // After this choice:
237  // A- extract the measurements compatible with the initialTSOS (seed)
238  // B- extract the measurements compatible with the lastButOneUpdatedTSOS
239  // In ORCA the choice was 1A. Here I will try 1B and if it fail I'll try 1A
240  // another possibility could be 2B and then 1A.
241 
242  // if no measurement found and the current TSOS has an eta very different
243  // wrt the initial one (i.e. seed), then try to find the measurements
244  // according to the lastButOne FTS. (1B)
245  double lastdEta = fabs(lastTSOS.freeTrajectoryState()->momentum().eta() - eta0);
246  if( bestMeasurements.empty() && lastdEta > 0.1) {
247  LogTrace(metname) << "No measurement and big eta variation wrt seed" << endl
248  << "trying with lastButOneUpdatedTSOS";
249  bestMeasurements = findBestMeasurements(*layer, theLastButOneUpdatedTSOS);
250  }
251 
252  //if no measurement found and the current FTS has an eta very different
253  //wrt the initial one (i.e. seed), then try to find the measurements
254  //according to the initial FTS. (1A)
255  if( bestMeasurements.empty() && lastdEta > 0.1) {
256  LogTrace(metname) << "No measurement and big eta variation wrt seed" << endl
257  << "tryng with seed TSOS";
258  bestMeasurements = findBestMeasurements(*layer, initialTSOS);
259  }
260 
261  // FIXME: uncomment this line!!
262  // if(!bestMeasurement && firstTime) break;
263 
264  if(!bestMeasurements.empty()) {
266  bool added = false;
267  for(std::vector<TrajectoryMeasurement>::const_iterator tmItr = bestMeasurements.begin();
268  tmItr != bestMeasurements.end(); ++tmItr){
269  added |= update(*layer, &(*tmItr), trajectory);
270  lastTSOS = theLastUpdatedTSOS;
271  }
272  if(added) {
273  incrementChamberCounters(*layer);
274  theDetLayers.push_back(*layer);
275  }
276  }
277  // SL in case no valid mesurement is found, still I want to use the predicted
278  // state for the following measurement serches. I take the first in the
279  // container. FIXME!!! I want to carefully check this!!!!!
280  else{
281  LogTrace(metname)<<"No best measurement found"<<endl;
282  // if (!theMeasurementCache.empty()){
283  // LogTrace(metname)<<"but the #of measurement is "<<theMeasurementCache.size()<<endl;
284  // lastTSOS = theMeasurementCache.front().predictedState();
285  // }
286  }
287  } // loop over layers
288 }
289 
290 
291 std::vector<TrajectoryMeasurement>
293  const TrajectoryStateOnSurface& tsos){
294 
295  const std::string metname = "Muon|RecoMuon|StandAloneMuonFilter";
296 
297  std::vector<TrajectoryMeasurement> result;
298  std::vector<TrajectoryMeasurement> measurements;
299 
300  if(theOverlappingChambersFlag && layer->hasGroups()){
301 
302  std::vector<TrajectoryMeasurementGroup> measurementGroups =
304 
305  if(theFitDirection == outsideIn){
306  LogTrace(metname) << "Reversing the order of groupedMeasurements as the direction of the fit is outside-in";
307  reverse(measurementGroups.begin(),measurementGroups.end());
308  // this should be fixed either in RecoMuon/MeasurementDet/MuonDetLayerMeasurements or
309  // RecoMuon/DetLayers/MuRingForwardDoubleLayer
310  }
311 
312 
313  for(std::vector<TrajectoryMeasurementGroup>::const_iterator tmGroupItr = measurementGroups.begin();
314  tmGroupItr != measurementGroups.end(); ++tmGroupItr){
315 
316  measurements = tmGroupItr->measurements();
317  LogTrace(metname) << "Number of Trajectory Measurement: " << measurements.size();
318 
319  const TrajectoryMeasurement* bestMeasurement
321 
322  if(bestMeasurement) result.push_back(*bestMeasurement);
323  }
324  }
325  else{
326  measurements = theMeasurementExtractor->measurements(layer, tsos, *propagator(), *estimator());
327  LogTrace(metname) << "Number of Trajectory Measurement: " << measurements.size();
328  const TrajectoryMeasurement* bestMeasurement
329  = bestMeasurementFinder()->findBestMeasurement(measurements,
330  propagator());
331  if(bestMeasurement) result.push_back(*bestMeasurement);
332  }
333  return result;
334 }
335 
336 
337 
338 
340  const TrajectoryMeasurement * meas,
341  Trajectory & trajectory)
342 {
343  const std::string metname = "Muon|RecoMuon|StandAloneMuonFilter";
345 
346  LogTrace(metname)<<"best measurement found" << "\n"
347  <<"updating the trajectory..."<<endl;
348  pair<bool,TrajectoryStateOnSurface> result = updator()->update(meas,
349  trajectory,
350  propagator());
351  LogTrace(metname)<<"trajectory updated: "<<result.first<<endl;
352  LogTrace(metname) << debug.dumpTSOS(result.second);
353 
354  if(result.first){
356  theLastUpdatedTSOS = result.second;
357  }
358 
359  if(result.second.isValid())
360  theLastCompatibleTSOS = result.second;
361 
362  return result.first;
363 }
364 
365 
367 
368  Trajectory::DataContainer const & oldMeas = oldTraj.measurements();
369  defTraj.reserve(oldMeas.size());
370 
371  for (Trajectory::DataContainer::const_iterator itm = oldMeas.begin(); itm != oldMeas.end(); itm++) {
372  if( !(*itm).recHit()->isValid() )
373  defTraj.push( *itm, (*itm).estimate() );
374  else {
375  MuonTransientTrackingRecHit::MuonRecHitPointer invRhPtr = MuonTransientTrackingRecHit::specificBuild( (*itm).recHit()->det(), (*itm).recHit()->hit() );
376  invRhPtr->invalidateHit();
377  TrajectoryMeasurement invRhMeas( (*itm).forwardPredictedState(), (*itm).updatedState(), invRhPtr, (*itm).estimate(), (*itm).layer() );
378  defTraj.push( std::move(invRhMeas), (*itm).estimate() );
379  }
380 
381  } // end for
382 }
T getParameter(std::string const &) const
MeasurementEstimator * estimator() const
access at the estimator
NavigationDirection fitDirection() const
Return the fit direction.
double theMaxChi2
The max allowed chi2 to accept a rechit in the fit.
MuonTrajectoryUpdator * theMuonUpdator
the muon updator (it doesn&#39;t inhert from an updator, but it has one!)
void createDefaultTrajectory(const Trajectory &, Trajectory &)
std::string dumpLayer(const DetLayer *layer) const
const std::string metname
void incrementCompatibleChamberCounters(const DetLayer *layer)
void makeFirstTime()
reset the theFirstTSOSFlag
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
GlobalPoint globalPosition() const
PropagationDirection
TrajectoryStateOnSurface theLastCompatibleTSOS
the trajectory state on the last compatible surface
void reserve(unsigned int n)
Definition: Trajectory.h:155
bool theRPCLoneliness
True if there are only the RPC measurements.
void refit(const TrajectoryStateOnSurface &initialState, const DetLayer *, Trajectory &trajectory)
Perform the inner-outward fitting.
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, const edm::Event &iEvent)
std::string thePropagatorName
the propagator name
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
DataContainer const & measurements() const
Definition: Trajectory.h:203
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
MuonDetLayerMeasurements * theMeasurementExtractor
The Measurement extractor.
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
void incrementChamberCounters(const DetLayer *layer)
Increment the DT,CSC,RPC counters.
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
tuple result
Definition: query.py:137
def move
Definition: eostools.py:510
virtual void setEvent(const edm::Event &event)
Pass the Event to the algo at each event.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
MeasurementContainer measurements(const DetLayer *layer, const GeomDet *det, const TrajectoryStateOnSurface &stateOnDet, const MeasurementEstimator &est, const edm::Event &iEvent)
GlobalVector momentum() const
#define LogTrace(id)
const Propagator * propagator() const
access at the propagator
StandAloneMuonFilter(const edm::ParameterSet &par, const MuonServiceProxy *service, edm::ConsumesCollector &iC)
Constructor.
PropagationDirection propagationDirection() const
Return the propagation direction.
#define debug
Definition: HDRShower.cc:19
MuonTrajectoryUpdator * updator() const
access at the muon updator
bool update(const DetLayer *layer, const TrajectoryMeasurement *meas, Trajectory &trajectory)
std::vector< const DetLayer * > theDetLayers
the det layer used in the reconstruction
NavigationDirection theFitDirection
the propagation direction
std::vector< const DetLayer * > compatibleLayers(const DetLayer *initialLayer, const FreeTrajectoryState &fts, PropagationDirection propDir)
Set the rigth Navigation.
MeasurementEstimator * theEstimator
The Estimator.
TrajectoryStateOnSurface theLastButOneUpdatedTSOS
the trajectory state on the last but one available surface
T eta() const
Definition: PV3DBase.h:76
void setEvent(const edm::Event &)
set event
TrajectoryStateOnSurface theLastUpdatedTSOS
the trajectory state on the last available surface
TrajectoryMeasurement * findBestMeasurement(std::vector< TrajectoryMeasurement > &measC, const Propagator *propagator)
return the Tm with the best chi2: no cut applied.
MuonBestMeasurementFinder * bestMeasurementFinder() const
Access to the best measurement finder.
virtual ~StandAloneMuonFilter()
Destructor.
virtual std::pair< bool, TrajectoryStateOnSurface > update(const TrajectoryMeasurement *measurement, Trajectory &trajectory, const Propagator *propagator)
update the Trajectory with the TrajectoryMeasurement
std::vector< TrajectoryMeasurement > findBestMeasurements(const DetLayer *layer, const TrajectoryStateOnSurface &tsos)
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:30
MuonBestMeasurementFinder * theBestMeasurementFinder
The best measurement finder: search for the best measurement among the TMs available.
const MuonServiceProxy * theService