CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastTSGFromL2Muon.cc
Go to the documentation of this file.
2 
7 
9 
11 
14 
16 
17 //#include <TH1.h>
18 
19 #include <set>
20 
22 {
23  produces<L3MuonTrajectorySeedCollection>();
24 
25  edm::ParameterSet serviceParameters =
26  cfg.getParameter<edm::ParameterSet>("ServiceParameters");
27  theService = new MuonServiceProxy(serviceParameters);
28 
29  thePtCut = cfg.getParameter<double>("PtCut");
30 
31  theL2CollectionLabel = cfg.getParameter<edm::InputTag>("MuonCollectionLabel");
32  theSeedCollectionLabels = cfg.getParameter<std::vector<edm::InputTag> >("SeedCollectionLabels");
33  theSimTrackCollectionLabel = cfg.getParameter<edm::InputTag>("SimTrackCollectionLabel");
34  // useTFileService_ = cfg.getUntrackedParameter<bool>("UseTFileService",false);
35 
36 }
37 
39 {
40 }
41 
42 void
44 {
45  //update muon proxy service
46  theService->update(es);
47 
48  //region builder
49  edm::ParameterSet regionBuilderPSet =
50  theConfig.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
51  theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet,theService);
52 
53  /*
54  if(useTFileService_) {
55  edm::Service<TFileService> fs;
56  h_nSeedPerTrack = fs->make<TH1F>("nSeedPerTrack","nSeedPerTrack",76,-0.5,75.5);
57  h_nGoodSeedPerTrack = fs->make<TH1F>("nGoodSeedPerTrack","nGoodSeedPerTrack",75,-0.5,75.5);
58  h_nGoodSeedPerEvent = fs->make<TH1F>("nGoodSeedPerEvent","nGoodSeedPerEvent",75,-0.5,75.5);
59  } else {
60  h_nSeedPerTrack = 0;
61  h_nGoodSeedPerEvent = 0;
62  h_nGoodSeedPerTrack = 0;
63  }
64  */
65 
66 }
67 
68 
69 void
71 {
72 
73  // Initialize the output product
74  std::auto_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
75 
76  //intialize service
77  theService->update(es);
78 
79  // Region builder
81 
82  // Retrieve the Monte Carlo truth (SimTracks)
84  ev.getByLabel(theSimTrackCollectionLabel,theSimTracks);
85 
86  // Retrieve L2 muon collection
88  ev.getByLabel(theL2CollectionLabel ,l2muonH);
89 
90  // Retrieve Seed collection
91  unsigned seedCollections = theSeedCollectionLabels.size();
92  std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
93  theSeeds.resize(seedCollections);
94  unsigned seed_size = 0;
95  for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
96  ev.getByLabel(theSeedCollectionLabels[iseed], theSeeds[iseed]);
97  seed_size += theSeeds[iseed]->size();
98  }
99 
100  // Loop on L2 muons
101  unsigned int imu=0;
102  unsigned int imuMax=l2muonH->size();
103  // std::cout << "Found " << imuMax << " L2 muons" << std::endl;
104  for (;imu!=imuMax;++imu){
105 
106  // Make a ref to l2 muon
107  reco::TrackRef muRef(l2muonH, imu);
108 
109  // Cut on muons with low momenta
110  if ( muRef->pt() < thePtCut
111  || muRef->innerMomentum().Rho() < thePtCut
112  || muRef->innerMomentum().R() < 2.5 ) continue;
113 
114  // Define the region of interest
116 
117  // Copy the collection of seeds (ahem, this is time consuming!)
118  std::vector<TrajectorySeed> tkSeeds;
119  std::set<unsigned> tkIds;
120  tkSeeds.reserve(seed_size);
121  for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
122  edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
123  unsigned nSeeds = aSeedCollection->size();
124  for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
125 
126  // The seed
127  const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
128 
129  // Find the first hit of the Seed
130  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
131  const SiTrackerGSMatchedRecHit2D * theFirstSeedingRecHit =
132  (const SiTrackerGSMatchedRecHit2D*) (&(*(theSeedingRecHitRange.first)));
133 
134  // The SimTrack id associated to that recHit
135  int simTrackId = theFirstSeedingRecHit->simtrackId();
136 
137  // Track already associated to a seed
138  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
139  if( tkId != tkIds.end() ) continue;
140 
141  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
142 
143  if ( clean(muRef,region,aSeed,theSimTrack) ) tkSeeds.push_back(*aSeed);
144  tkIds.insert(simTrackId);
145 
146  } // End loop on seeds
147 
148  } // End loop on seed collections
149 
150  // Free memory
151  delete region;
152 
153  // A plot
154  // if(h_nSeedPerTrack) h_nSeedPerTrack->Fill(tkSeeds.size());
155 
156  // Another plot
157  // if(h_nGoodSeedPerTrack) h_nGoodSeedPerTrack->Fill(tkSeeds.size());
158 
159 
160  // Now create the Muon Trajectory Seed
161  unsigned int is=0;
162  unsigned int isMax=tkSeeds.size();
163  for (;is!=isMax;++is){
164  result->push_back( L3MuonTrajectorySeed(tkSeeds[is], muRef));
165  } // End of tk seed loop
166 
167  } // End of l2 muon loop
168 
169  // std::cout << "Found " << result->size() << " seeds for muons" << std::endl;
170 
171  // And yet another plot
172  // if(h_nGoodSeedPerEvent) h_nGoodSeedPerEvent->Fill(result->size());
173 
174  //put in the event
175  ev.put(result);
176 
177 }
178 
179 bool
182  const BasicTrajectorySeed* aSeed,
183  const SimTrack& theSimTrack) {
184 
185  // Eta cleaner
186  const PixelRecoRange<float>& etaRange = region->etaRange() ;
187  double etaSeed = theSimTrack.momentum().Eta();
188  double etaLimit = (fabs(fabs(etaRange.max())-fabs(etaRange.mean())) <0.05) ?
189  0.05 : fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) ;
190  bool inEtaRange =
191  etaSeed >= (etaRange.mean() - etaLimit) &&
192  etaSeed <= (etaRange.mean() + etaLimit) ;
193  if ( !inEtaRange ) return false;
194 
195  // Phi cleaner
196  const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
197  double phiSeed = theSimTrack.momentum().Phi();
198  double phiLimit = (phiMargin.right() < 0.05 ) ? 0.05 : phiMargin.right();
199  bool inPhiRange =
200  (fabs(deltaPhi(phiSeed,double(region->direction().phi()))) < phiLimit );
201  if ( !inPhiRange ) return false;
202 
203  // pt cleaner
204  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
205  double ptMin = (region->ptMin()>3.5) ? 3.5: region->ptMin();
206  bool inPtRange = ptSeed >= ptMin && ptSeed<= 2*(muRef->pt());
207  return inPtRange;
208 
209 }
void update(const edm::EventSetup &setup)
update the services each event
RectangularEtaPhiTrackingRegion * region(const reco::TrackRef &) const
define tracking region
T getParameter(std::string const &) const
virtual ~FastTSGFromL2Muon()
MuonServiceProxy * theService
std::vector< edm::InputTag > theSeedCollectionLabels
T max() const
virtual void produce(edm::Event &ev, const edm::EventSetup &es) override
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
std::vector< L3MuonTrajectorySeed > L3MuonTrajectorySeedCollection
edm::InputTag theSimTrackCollectionLabel
MuonTrackingRegionBuilder * theRegionBuilder
edm::ParameterSet theConfig
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
bool clean(reco::TrackRef muRef, RectangularEtaPhiTrackingRegion *region, const BasicTrajectorySeed *aSeed, const SimTrack &theSimTrack)
std::pair< const_iterator, const_iterator > range
FastTSGFromL2Muon(const edm::ParameterSet &cfg)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
int iseed
Definition: AMPTWrapper.h:124
T mean() const
range recHits() const
edm::InputTag theL2CollectionLabel
const math::XYZTLorentzVectorD & momentum() const
particle info...
Definition: CoreSimTrack.h:36
virtual void beginRun(edm::Run const &run, edm::EventSetup const &es) override
Definition: Run.h:36