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