test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StandAloneTrajectoryBuilder.cc
Go to the documentation of this file.
1 
12 
18 
22 
26 
28 
36 
37 
38 using namespace edm;
39 using namespace std;
40 
42  const MuonServiceProxy* service,
43  edm::ConsumesCollector& iC):theService(service){
44  const std::string metname = "Muon|RecoMuon|StandAloneMuonTrajectoryBuilder";
45 
46  LogTrace(metname) << "constructor called" << endl;
47 
48  // The navigation type:
49  // "Direct","Standard"
50  theNavigationType = par.getParameter<string>("NavigationType");
51 
52  // The inward-outward fitter (starts from seed state)
53  ParameterSet filterPSet = par.getParameter<ParameterSet>("FilterParameters");
54  filterPSet.addParameter<string>("NavigationType",theNavigationType);
55  theFilter = new StandAloneMuonFilter(filterPSet,theService,iC);
56 
57  // Fit direction
58  string seedPosition = par.getParameter<string>("SeedPosition");
59 
60  if (seedPosition == "in" ) theSeedPosition = recoMuon::in;
61  else if (seedPosition == "out" ) theSeedPosition = recoMuon::out;
62  else
63  throw cms::Exception("StandAloneMuonFilter constructor")
64  <<"Wrong seed position chosen in StandAloneMuonFilter::StandAloneMuonFilter ParameterSet"
65  << "\n"
66  << "Possible choices are:"
67  << "\n"
68  << "SeedPosition = in or SeedPosition = out";
69 
70  // Propagator for the seed extrapolation
71  theSeedPropagatorName = par.getParameter<string>("SeedPropagator");
72 
73  // Disable/Enable the backward filter
74  doBackwardFilter = par.getParameter<bool>("DoBackwardFilter");
75 
76  // Disable/Enable the refit of the trajectory
77  doRefit = par.getParameter<bool>("DoRefit");
78 
79  // Disable/Enable the refit of the trajectory seed
80  doSeedRefit = par.getParameter<bool>("DoSeedRefit");
81 
82  if(doBackwardFilter){
83  // The outward-inward fitter (starts from theFilter outermost state)
84  ParameterSet bwFilterPSet = par.getParameter<ParameterSet>("BWFilterParameters");
85  // theBWFilter = new StandAloneMuonBackwardFilter(bwFilterPSet,theService); // FIXME
86  bwFilterPSet.addParameter<string>("NavigationType",theNavigationType);
87  theBWFilter = new StandAloneMuonFilter(bwFilterPSet,theService,iC);
88 
89  theBWSeedType = bwFilterPSet.getParameter<string>("BWSeedType");
90  }
91 
92  if(doRefit){
93  // The outward-inward fitter (starts from theBWFilter innermost state)
94  ParameterSet refitterPSet = par.getParameter<ParameterSet>("RefitterParameters");
95  theRefitter = new StandAloneMuonRefitter(refitterPSet, theService);
96  }
97 
98  // The seed transformer (used to refit the seed and get the seed transient state)
99  // ParameterSet seedTransformerPSet = par.getParameter<ParameterSet>("SeedTransformerParameters");
100  ParameterSet seedTransformerParameters = par.getParameter<ParameterSet>("SeedTransformerParameters");
101  theSeedTransformer = new SeedTransformer(seedTransformerParameters);
102 
103 }
104 
106  theFilter->setEvent(event);
108 }
109 
111 
112  LogTrace("Muon|RecoMuon|StandAloneMuonTrajectoryBuilder")
113  << "StandAloneMuonTrajectoryBuilder destructor called" << endl;
114 
115  if(theFilter) delete theFilter;
117  if(doRefit && theRefitter) delete theRefitter;
119 }
120 
121 
122 namespace {
123  struct Resetter {
125  explicit Resetter(StandAloneMuonFilter * imf) : mf(imf){}
126  ~Resetter() { if(mf) mf->reset();}
127  };
128 }
129 
132  Resetter fwReset(filter());
133  Resetter bwReset(bwfilter());
134 
135  const std::string metname = "Muon|RecoMuon|StandAloneMuonTrajectoryBuilder";
137 
138  // Set the services for the seed transformer
139  theSeedTransformer->setServices(theService->eventSetup());
140 
141  // the trajectory container. In principle starting from one seed we can
142  // obtain more than one trajectory. TODO: this feature is not yet implemented!
143  TrajectoryContainer trajectoryContainer;
144 
146  Trajectory trajectoryFW(seed,fwDirection);
147 
148  TrajectoryStateOnSurface lastTSOS;
149  DetId lastDetId;
150 
151  vector<Trajectory> seedTrajectories;
152 
153  if(doSeedRefit) {
154  seedTrajectories = theSeedTransformer->seedTransform(seed);
155  if(!seedTrajectories.empty()) {
156  TrajectoryMeasurement lastTM(seedTrajectories.front().lastMeasurement());
157  lastTSOS = lastTM.updatedState();
158  lastDetId = lastTM.recHit()->geographicalId();
159  }
160  }
161 
162  if(!doSeedRefit || seedTrajectories.empty()) {
163  lastTSOS = theSeedTransformer->seedTransientState(seed);
164  lastDetId = seed.startingState().detId();
165  }
166 
167  LogTrace(metname) << "Trajectory State on Surface before the extrapolation"<<endl;
168  LogTrace(metname) << debug.dumpTSOS(lastTSOS);
169 
170  // Segment layer
171  LogTrace(metname) << "The RecSegment relies on: "<<endl;
172  LogTrace(metname) << debug.dumpMuonId(lastDetId);
173 
174  DetLayerWithState inputFromSeed = propagateTheSeedTSOS(lastTSOS, lastDetId);
175 
176  // refine the FTS given by the seed
177 
178  // the trajectory is filled in the refitter::refit
179  filter()->refit(inputFromSeed.second,inputFromSeed.first,trajectoryFW);
180 
181  // "0th order" check...
182  if( trajectoryFW.empty() ) {
183  LogTrace(metname) << "Forward trajectory EMPTY! No trajectory will be loaded!" << endl;
184  return trajectoryContainer;
185  }
186 
187  // Get the last TSOS
188  // TrajectoryStateOnSurface tsosAfterRefit = filter()->lastUpdatedTSOS(); // this is the last UPDATED TSOS
189  TrajectoryStateOnSurface tsosAfterRefit = filter()->lastCompatibleTSOS(); // this is the last COMPATIBLE TSOS
190 
191  LogTrace(metname) << "StandAloneMuonTrajectoryBuilder filter output " << endl;
192  LogTrace(metname) << debug.dumpTSOS(tsosAfterRefit);
193 
194 
195  /*
196  // -- 1st attempt
197  if( filter()->isCompatibilitySatisfied() ) {
198  if( filter()->layers().size() ) // OR if( filter()->goodState() ) ??? Maybe when only RPC hits are used...
199  LogTrace(metname) << debug.dumpLayer( filter()->lastDetLayer() );
200  else {
201  LogTrace(metname) << "Compatibility satisfied, but all RecHits are invalid! A trajectory with only invalid hits will be loaded!" << endl;
202  trajectoryContainer.push_back(new Trajectory(trajectoryFW));
203  return trajectoryContainer;
204  }
205  }
206  else {
207  LogTrace(metname) << "Compatibility NOT satisfied after Forward filter! No trajectory will be loaded!" << endl;
208  LogTrace(metname) << "Total chambers: " << filter()->getTotalCompatibleChambers() << "; DT: "
209  << filter()->getDTCompatibleChambers() << "; CSC: " << filter()->getCSCCompatibleChambers() << endl;
210  return trajectoryContainer;
211  }
212  // -- end 1st attempt
213  */
214 
215  // -- 2nd attempt
216  if( filter()->goodState() ) {
217  LogTrace(metname) << debug.dumpLayer( filter()->lastDetLayer() );
218  }
219  else if( filter()->isCompatibilitySatisfied() ) {
220  int foundValidRh = trajectoryFW.foundHits(); // number of valid hits
221  LogTrace(metname) << "Compatibility satisfied after Forward filter, but too few valid RecHits ("
222  << foundValidRh << ")." << endl
223  << "A trajectory with only invalid RecHits will be loaded!" << endl;
224  if(!foundValidRh) {
225  trajectoryContainer.push_back(new Trajectory(trajectoryFW));
226  return trajectoryContainer;
227  }
228  Trajectory defaultTraj(seed,fwDirection);
229  filter()->createDefaultTrajectory(trajectoryFW, defaultTraj);
230  trajectoryContainer.push_back(new Trajectory(defaultTraj));
231  return trajectoryContainer;
232  }
233  else {
234  LogTrace(metname) << "Compatibility NOT satisfied after Forward filter! No trajectory will be loaded!" << endl;
235  LogTrace(metname) << "Total compatible chambers: " << filter()->getTotalCompatibleChambers() << "; DT: "
236  << filter()->getDTCompatibleChambers() << "; CSC: " << filter()->getCSCCompatibleChambers()
237  << "; RPC: " << filter()->getRPCCompatibleChambers()
238  << "; GEM: " << filter()->getGEMCompatibleChambers() << endl;
239  return trajectoryContainer;
240  }
241  // -- end 2nd attempt
242 
243  LogTrace(metname) << "Number of DT/CSC/RPC/GEM chamber used (fw): "
244  << filter()->getDTChamberUsed() << "/"
245  << filter()->getCSCChamberUsed() << "/"
246  << filter()->getRPCChamberUsed() << "/"
247  << filter()->getGEMChamberUsed() <<endl;
248  LogTrace(metname) << "Momentum: " <<tsosAfterRefit.freeState()->momentum();
249 
250 
251  if(!doBackwardFilter) {
252  LogTrace(metname) << "Only forward refit requested. No backward refit will be performed!"<<endl;
253 
254  // ***** Refit of fwd step *****
255  // if (doRefit && !trajectoryFW.empty() && filter()->goodState()){ // CHECK!!! Can trajectoryFW really be empty at this point??? And goodState...?
256  if(doRefit) {
257  pair<bool,Trajectory> refitResult = refitter()->refit(trajectoryFW);
258  if(refitResult.first) {
259  trajectoryContainer.push_back(new Trajectory(refitResult.second));
260  LogTrace(metname) << "StandAloneMuonTrajectoryBuilder refit output " << endl ;
261  LogTrace(metname) << debug.dumpTSOS(refitResult.second.lastMeasurement().updatedState());
262  }
263  else
264  trajectoryContainer.push_back(new Trajectory(trajectoryFW));
265  }
266  else
267  trajectoryContainer.push_back(new Trajectory(trajectoryFW));
268 
269  LogTrace(metname) << "Trajectory saved" << endl;
270  return trajectoryContainer;
271  }
272 
273 
274  // ***** Backward filtering *****
275 
276  TrajectorySeed seedForBW;
277 
278  if(theBWSeedType == "noSeed") {
279  TrajectorySeed seedVoid;
280  seedForBW = seedVoid;
281  }
282  else if(theBWSeedType == "fromFWFit") {
283 
284 
285 
286  PTrajectoryStateOnDet seedTSOS =
287  trajectoryStateTransform::persistentState( tsosAfterRefit, trajectoryFW.lastMeasurement().recHit()->geographicalId().rawId());
288 
289  edm::OwnVector<TrackingRecHit> recHitsContainer;
291  TrajectorySeed fwFit(seedTSOS,recHitsContainer,seedDirection);
292 
293  seedForBW = fwFit;
294  }
295  else if(theBWSeedType == "fromGenerator") {
296  seedForBW = seed;
297  }
298  else
299  LogWarning(metname) << "Wrong seed type for the backward filter!";
300 
302  Trajectory trajectoryBW(seedForBW,bwDirection);
303 
304  // FIXME! under check!
305  bwfilter()->refit(tsosAfterRefit,filter()->lastDetLayer(),trajectoryBW);
306 
307  // Get the last TSOS
308  TrajectoryStateOnSurface tsosAfterBWRefit = bwfilter()->lastUpdatedTSOS();
309 
310  LogTrace(metname) << "StandAloneMuonTrajectoryBuilder BW filter output " << endl ;
311  LogTrace(metname) << debug.dumpTSOS(tsosAfterBWRefit);
312 
313  LogTrace(metname)
314  << "Number of RecHits: " << trajectoryBW.foundHits() << "\n"
315  << "Number of DT/CSC/RPC/GEM chamber used (bw): "
316  << bwfilter()->getDTChamberUsed() << "/"
317  << bwfilter()->getCSCChamberUsed() << "/"
318  << bwfilter()->getRPCChamberUsed() << "/"
319  << bwfilter()->getGEMChamberUsed();
320 
321  // -- The trajectory is "good" if there are at least 2 chambers used in total and at
322  // least 1 is "tracking" (DT or CSC)
323  // -- The trajectory satisfies the "compatibility" requirements if there are at least
324  // 2 compatible chambers (not necessarily used!) in total and at
325  // least 1 is "tracking" (DT or CSC)
326  // 1st attempt
327  /*
328  if (bwfilter()->isCompatibilitySatisfied()) {
329 
330  if (doRefit && !trajectoryBW.empty() && bwfilter()->goodState()){
331  pair<bool,Trajectory> refitResult = refitter()->refit(trajectoryBW);
332  if (refitResult.first){
333  trajectoryContainer.push_back(new Trajectory(refitResult.second));
334  LogTrace(metname) << "StandAloneMuonTrajectoryBuilder Refit output " << endl;
335  LogTrace(metname) << debug.dumpTSOS(refitResult.second.lastMeasurement().updatedState());
336  }
337  else
338  trajectoryContainer.push_back(new Trajectory(trajectoryBW));
339  }
340  else
341  trajectoryContainer.push_back(new Trajectory(trajectoryBW));
342 
343  LogTrace(metname)<< "Trajectory saved" << endl;
344 
345  }
346  //if the trajectory is not saved, but at least two chamber are used in the
347  //forward filtering, try to build a new trajectory starting from the old
348  //trajectory w/o the latest measurement and a looser chi2 cut
349  else if ( filter()->getTotalChamberUsed() >= 2 ) {
350  LogTrace(metname)<< "Trajectory NOT saved. Second Attempt." << endl;
351  // FIXME:
352  // a better choice could be: identify the poorest one, exclude it, redo
353  // the fw and bw filtering. Or maybe redo only the bw without the excluded
354  // measure. As first step I will port the ORCA algo, then I will move to the
355  // above pattern.
356 
357  }
358 
359  else {
360  LogTrace(metname) << "Compatibility NOT satisfied after Backward filter!" << endl;
361  LogTrace(metname) << "The result of Forward filter will be loaded!" << endl;
362 
363  trajectoryContainer.push_back(new Trajectory(trajectoryFW));
364  }
365  */
366  // end 1st attempt
367 
368  // 2nd attempt
369  if( bwfilter()->goodState() ) {
370  LogTrace(metname) << debug.dumpLayer( bwfilter()->lastDetLayer() );
371  }
372  else if( bwfilter()->isCompatibilitySatisfied() ) {
373  LogTrace(metname) << "Compatibility satisfied after Backward filter, but too few valid RecHits ("
374  << trajectoryBW.foundHits() << ")." << endl
375  << "The (good) result of FW filter will be loaded!" << endl;
376  trajectoryContainer.push_back(new Trajectory(trajectoryFW));
377  return trajectoryContainer;
378  }
379  else {
380  LogTrace(metname) << "Compatibility NOT satisfied after Backward filter!" << endl
381  << "The Forward trajectory will be invalidated and then loaded!" << endl;
382  Trajectory defaultTraj(seed,fwDirection);
383  filter()->createDefaultTrajectory(trajectoryFW, defaultTraj);
384  trajectoryContainer.push_back(new Trajectory(defaultTraj));
385  return trajectoryContainer;
386  }
387  // end 2nd attempt
388 
389  if(doRefit) {
390  pair<bool,Trajectory> refitResult = refitter()->refit(trajectoryBW);
391  if(refitResult.first) {
392  trajectoryContainer.push_back(new Trajectory(refitResult.second));
393  LogTrace(metname) << "StandAloneMuonTrajectoryBuilder Refit output " << endl;
394  LogTrace(metname) << debug.dumpTSOS(refitResult.second.lastMeasurement().updatedState());
395  }
396  else
397  trajectoryContainer.push_back(new Trajectory(trajectoryBW));
398  }
399  else
400  trajectoryContainer.push_back(new Trajectory(trajectoryBW));
401 
402  LogTrace(metname) << "Trajectory saved" << endl;
403 
404  return trajectoryContainer;
405 }
406 
407 
410 
411  const std::string metname = "Muon|RecoMuon|StandAloneMuonTrajectoryBuilder";
413 
414  DetId seedDetId(aDetId);
415  // const GeomDet* gdet = theService->trackingGeometry()->idToDet( seedDetId );
416 
417  TrajectoryStateOnSurface initialState(aTSOS);
418 
419  LogTrace(metname)<<"Seed's Pt: "<<initialState.freeState()->momentum().perp()<<endl;
420 
421  LogTrace(metname)<< "Seed's id: "<< endl ;
422  LogTrace(metname) << debug.dumpMuonId(seedDetId);
423 
424  // Get the layer on which the seed relies
425  const DetLayer *initialLayer = theService->detLayerGeometry()->idToLayer( seedDetId );
426 
427  LogTrace(metname)<< "Seed's detLayer: "<< endl ;
428  LogTrace(metname) << debug.dumpLayer(initialLayer);
429 
430  LogTrace(metname)<< "TrajectoryStateOnSurface before propagation:" << endl;
431  LogTrace(metname) << debug.dumpTSOS(initialState);
432 
433 
435 
436  // ask for compatible layers
437  vector<const DetLayer*> detLayers;
438 
439  if(theNavigationType == "Standard")
440  detLayers = theService->muonNavigationSchool()->compatibleLayers(*initialLayer, *initialState.freeState(),detLayerOrder);
441  else if (theNavigationType == "Direct"){
442  DirectMuonNavigation navigation( &*theService->detLayerGeometry() );
443  detLayers = navigation.compatibleLayers( *initialState.freeState(),detLayerOrder);
444  }
445  else
446  edm::LogError(metname) << "No Properly Navigation Selected!!"<<endl;
447 
448 
449  LogTrace(metname) << "There are "<< detLayers.size() <<" compatible layers"<<endl;
450 
451  DetLayerWithState result = DetLayerWithState(initialLayer,initialState);
452 
453  if(detLayers.size()){
454 
455  LogTrace(metname) << "Compatible layers:"<<endl;
456  for( vector<const DetLayer*>::const_iterator layer = detLayers.begin();
457  layer != detLayers.end(); layer++){
458  LogTrace(metname) << debug.dumpMuonId((*layer)->basicComponents().front()->geographicalId());
459  LogTrace(metname) << debug.dumpLayer(*layer);
460  }
461 
462  const DetLayer* finalLayer = detLayers.back();
463 
464  if(theSeedPosition == recoMuon::in) LogTrace(metname) << "Most internal one:"<<endl;
465  else LogTrace(metname) << "Most external one:"<<endl;
466 
467  LogTrace(metname) << debug.dumpLayer(finalLayer);
468 
469  const TrajectoryStateOnSurface propagatedState =
470  theService->propagator(theSeedPropagatorName)->propagate(initialState,
471  finalLayer->surface());
472 
473  if(propagatedState.isValid()){
474  result = DetLayerWithState(finalLayer,propagatedState);
475 
476  LogTrace(metname) << "Trajectory State on Surface after the extrapolation"<<endl;
477  LogTrace(metname) << debug.dumpTSOS(propagatedState);
478  LogTrace(metname) << debug.dumpLayer(finalLayer);
479  }
480  else
481  LogTrace(metname)<< "Extrapolation failed. Keep the original seed state" <<endl;
482  }
483  else
484  LogTrace(metname)<< "No compatible layers. Keep the original seed state" <<endl;
485 
486  return result;
487 }
488 
489 
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:244
T getParameter(std::string const &) const
int foundHits() const
Definition: Trajectory.h:234
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
T perp() const
Definition: PV3DBase.h:72
ConstRecHitPointer const & recHit() const
void createDefaultTrajectory(const Trajectory &, Trajectory &)
std::string dumpLayer(const DetLayer *layer) const
StandAloneMuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &iC)
Constructor with Parameter set and MuonServiceProxy.
const std::string metname
void setServices(const edm::EventSetup &)
Set the services needed by the SeedTransformer.
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
MuonCandidate::TrajectoryContainer TrajectoryContainer
int getRPCCompatibleChambers() const
PropagationDirection
TrajectoryStateOnSurface lastUpdatedTSOS() const
the Trajectory state on the last surface of the fitting
void refit(const TrajectoryStateOnSurface &initialState, const DetLayer *, Trajectory &trajectory)
Perform the inner-outward fitting.
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
std::string dumpMuonId(const DetId &id) const
std::vector< Trajectory > seedTransform(const TrajectorySeed &) const
Performs the fit.
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
int getCSCCompatibleChambers() const
int getDTCompatibleChambers() const
virtual void setEvent(const edm::Event &event)
Pass the Event to the algo at each event.
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
FreeTrajectoryState const * freeState(bool withErrors=true) const
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
tuple result
Definition: query.py:137
StandAloneMuonFilter * bwfilter() const
actual filter
unsigned int detId() const
RefitResult refit(const Trajectory &)
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
GlobalVector momentum() const
#define LogTrace(id)
std::pair< const DetLayer *, TrajectoryStateOnSurface > DetLayerWithState
Definition: DetId.h:18
PTrajectoryStateOnDet const & startingState() const
#define debug
Definition: HDRShower.cc:19
int getGEMCompatibleChambers() const
TrajectoryStateOnSurface seedTransientState(const TrajectorySeed &) const
StandAloneMuonFilter * filter() const
pre-filter
TrajectoryContainer trajectories(const TrajectorySeed &)
return a container of the reconstructed trajectories compatible with a given seed ...
int getTotalCompatibleChambers() const
std::string theSeedPropagatorName
Propagator for the seed extrapolation.
virtual ~StandAloneMuonTrajectoryBuilder()
Destructor.
StandAloneMuonRefitter * refitter() const
refitter of the hits container
TrajectoryStateOnSurface lastCompatibleTSOS() const
the Trajectory state on the last compatible surface
DetLayerWithState propagateTheSeedTSOS(TrajectoryStateOnSurface &aTSOS, DetId &aDetId)