CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonReSeeder.cc
Go to the documentation of this file.
1 
2 //
3 // $Id: MuonReSeeder.cc,v 1.3 2013/02/27 14:58:17 muzaffar Exp $
4 //
5 
19 
21 
31 
32 
33 class MuonReSeeder : public edm::EDProducer {
34  public:
35  explicit MuonReSeeder(const edm::ParameterSet & iConfig);
36  virtual ~MuonReSeeder() { }
37 
38  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
39 
40  private:
43 
46 
49 
51  bool insideOut_;
52 
54  bool debug_;
55 
58 
59 };
60 
62  src_(iConfig.getParameter<edm::InputTag>("src")),
63  selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
64  layersToKeep_(iConfig.getParameter<int32_t>("layersToKeep")),
65  insideOut_(iConfig.getParameter<bool>("insideOut")),
66  debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
67  refitter_(iConfig)
68 {
69  produces<std::vector<TrajectorySeed> >();
70 }
71 
72 void
74  using namespace edm;
75  using namespace std;
76 
77  refitter_.setServices(iSetup);
78 
80  iEvent.getByLabel(src_, src);
81 
82  //Retrieve tracker topology from geometry
84  iSetup.get<IdealGeometryRecord>().get(tTopo);
85 
86  auto_ptr<vector<TrajectorySeed> > out(new vector<TrajectorySeed>());
87  unsigned int nsrc = src->size();
88  out->reserve(nsrc);
89 
90  for (View<reco::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
91  const reco::Muon &mu = *it;
92  if (mu.track().isNull() || !selector_(mu)) continue;
93  std::vector<Trajectory> traj = refitter_.transform(*mu.track());
94  if (traj.size() != 1) continue;
96  const std::vector<TrajectoryMeasurement> & tms = traj.front().measurements();
98  bool fromInside = (insideOut_ == (traj.front().direction() == alongMomentum));
99  if (debug_) {
100  std::cout << "Considering muon of pt " << mu.pt() << ", eta = " << mu.eta() << ", phi = " << mu.phi() << std::endl;
101  std::cout << "Trajectory is " << (traj.front().direction() == alongMomentum ? "along" : "opposite") << " to momentum, so will start from " << (fromInside ? "inside" : "outside") << std::endl;
102  }
103  const TrajectoryMeasurement & tin = (fromInside ? tms.front() : tms.back());
104  const TrajectoryMeasurement & tou = (fromInside ? tms.front() : tms.back());
105  if (debug_) {
106  std::cout << "IN state: subdetector = " << tin.recHit()->geographicalId().subdetId() << std::endl;
107  std::cout << " global pos Rho " << tin.updatedState().globalPosition().perp() << ", Z " << tin.updatedState().globalPosition().z() << std::endl;
108  std::cout << "OU state: subdetector = " << tou.recHit()->geographicalId().subdetId() << std::endl;
109  std::cout << " global pos Rho " << tou.updatedState().globalPosition().perp() << ", Z " << tou.updatedState().globalPosition().z() << std::endl;
110  }
111  int lastSubdet = 0, lastLayer = -1;
112  for (int i = (fromInside ? 0 : tms.size()-1),
113  end = (fromInside ? tms.size() : -1),
114  step = (fromInside ? +1 : -1),
115  taken = 0; (end-i)*step > 0; i += step) {
116  const TrackingRecHit *lastHit = hit;
117  hit = tms[i].recHit()->hit();
118  if (debug_) std::cout << " considering hit " << i << ": rechit on " << (hit ? hit->geographicalId().rawId() : -1) << std::endl;
119  if (!hit) continue;
120  int subdet = hit->geographicalId().subdetId();
121  int lay = tTopo->layer(hit->geographicalId());
122  if (subdet != lastSubdet || lay != lastLayer) {
123  // I'm on a new layer
124  if (lastHit != 0 && taken == layersToKeep_) {
125  // I've had enough layers, I can stop here
126  hit = lastHit;
127  break;
128  }
129  lastSubdet = subdet; lastLayer = lay;
130  taken++;
131  }
132  seedHits.push_back(*hit);
133  tsos = tms[i].updatedState().isValid() ? tms[i].updatedState() :
134  (abs(i-end) < abs(i) ? tms[i].forwardPredictedState() : tms[i].backwardPredictedState());
135  if (debug_) {
136  std::cout << " hit : subdetector = " << tms[i].recHit()->geographicalId().subdetId() << std::endl;
137  if (hit->isValid()) {
138  std::cout << " global pos Rho " << tms[i].recHit()->globalPosition().perp() << ", Z " << tms[i].recHit()->globalPosition().z() << std::endl;
139  } else {
140  std::cout << " invalid tracking rec hit, so no global position" << std::endl;
141  }
142  std::cout << " state: global pos Rho " << tsos.globalPosition().perp() << ", Z " << tsos.globalPosition().z() << std::endl;
143  }
144  }
145  if (!tsos.isValid()) continue;
147  TrajectorySeed seed(PTraj,std::move(seedHits),insideOut_ ? alongMomentum : oppositeToMomentum);
148  out->push_back(seed);
149  }
150 
151  iEvent.put(out);
152 }
153 
154 
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
TrackTransformer refitter_
Track Transformer.
Definition: MuonReSeeder.cc:57
T perp() const
Definition: PV3DBase.h:72
ConstRecHitPointer const & recHit() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
StringCutObjectSelector< reco::Muon > selector_
Muon selection.
Definition: MuonReSeeder.cc:45
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
edm::InputTag src_
Labels for input collections.
Definition: MuonReSeeder.cc:42
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:50
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
bool debug_
Dump deug information.
Definition: MuonReSeeder.cc:54
int layersToKeep_
How many hits to keep from the muon trajectory.
Definition: MuonReSeeder.cc:48
virtual ~MuonReSeeder()
Definition: MuonReSeeder.cc:36
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
void push_back(D *&d)
Definition: OwnVector.h:273
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T z() const
Definition: PV3DBase.h:64
const int mu
Definition: Constants.h:23
#define end
Definition: vmac.h:38
bool insideOut_
Do inside-out.
Definition: MuonReSeeder.cc:51
virtual void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: MuonReSeeder.cc:73
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
tuple out
Definition: dbtoconf.py:99
const T & get() const
Definition: EventSetup.h:55
bool isValid() const
virtual std::vector< Trajectory > transform(const reco::Track &) const
Convert a reco::Track into Trajectory.
tuple cout
Definition: gather_cfg.py:121
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
virtual float pt() const GCC11_FINAL
transverse momentum
MuonReSeeder(const edm::ParameterSet &iConfig)
Definition: MuonReSeeder.cc:61
reference front()
Definition: OwnVector.h:348