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");
52  theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet,theService,iC);
53 
54  /*
55  if(useTFileService_) {
56  edm::Service<TFileService> fs;
57  h_nSeedPerTrack = fs->make<TH1F>("nSeedPerTrack","nSeedPerTrack",76,-0.5,75.5);
58  h_nGoodSeedPerTrack = fs->make<TH1F>("nGoodSeedPerTrack","nGoodSeedPerTrack",75,-0.5,75.5);
59  h_nGoodSeedPerEvent = fs->make<TH1F>("nGoodSeedPerEvent","nGoodSeedPerEvent",75,-0.5,75.5);
60  } else {
61  h_nSeedPerTrack = 0;
62  h_nGoodSeedPerEvent = 0;
63  h_nGoodSeedPerTrack = 0;
64  }
65  */
66 
67 }
68 
69 
70 void
72 {
73 
74  // Initialize the output product
75  std::auto_ptr<L3MuonTrajectorySeedCollection> result(new L3MuonTrajectorySeedCollection());
76 
77  //intialize service
78  theService->update(es);
79 
80  // Region builder
82 
83  // Retrieve the Monte Carlo truth (SimTracks)
85  ev.getByLabel(theSimTrackCollectionLabel,theSimTracks);
86 
87  // Retrieve L2 muon collection
89  ev.getByLabel(theL2CollectionLabel ,l2muonH);
90 
91  // Retrieve Seed collection
92  unsigned seedCollections = theSeedCollectionLabels.size();
93  std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
94  theSeeds.resize(seedCollections);
95  unsigned seed_size = 0;
96  for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
97  ev.getByLabel(theSeedCollectionLabels[iseed], theSeeds[iseed]);
98  seed_size += theSeeds[iseed]->size();
99  }
100 
101  // Loop on L2 muons
102  unsigned int imu=0;
103  unsigned int imuMax=l2muonH->size();
104  // std::cout << "Found " << imuMax << " L2 muons" << std::endl;
105  for (;imu!=imuMax;++imu){
106 
107  // Make a ref to l2 muon
108  reco::TrackRef muRef(l2muonH, imu);
109 
110  // Cut on muons with low momenta
111  if ( muRef->pt() < thePtCut
112  || muRef->innerMomentum().Rho() < thePtCut
113  || muRef->innerMomentum().R() < 2.5 ) continue;
114 
115  // Define the region of interest
117 
118  // Copy the collection of seeds (ahem, this is time consuming!)
119  std::vector<TrajectorySeed> tkSeeds;
120  std::set<unsigned> tkIds;
121  tkSeeds.reserve(seed_size);
122  for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
123  edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
124  unsigned nSeeds = aSeedCollection->size();
125  for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
126 
127  // The seed
128  const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
129 
130  // Find the first hit of the Seed
131  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
132  const SiTrackerGSMatchedRecHit2D * theFirstSeedingRecHit =
133  (const SiTrackerGSMatchedRecHit2D*) (&(*(theSeedingRecHitRange.first)));
134 
135  // The SimTrack id associated to that recHit
136  int simTrackId = theFirstSeedingRecHit->simtrackId();
137 
138  // Track already associated to a seed
139  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
140  if( tkId != tkIds.end() ) continue;
141 
142  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
143 
144  if ( clean(muRef,region,aSeed,theSimTrack) ) tkSeeds.push_back(*aSeed);
145  tkIds.insert(simTrackId);
146 
147  } // End loop on seeds
148 
149  } // End loop on seed collections
150 
151  // Free memory
152  delete region;
153 
154  // A plot
155  // if(h_nSeedPerTrack) h_nSeedPerTrack->Fill(tkSeeds.size());
156 
157  // Another plot
158  // if(h_nGoodSeedPerTrack) h_nGoodSeedPerTrack->Fill(tkSeeds.size());
159 
160 
161  // Now create the Muon Trajectory Seed
162  unsigned int is=0;
163  unsigned int isMax=tkSeeds.size();
164  for (;is!=isMax;++is){
165  result->push_back( L3MuonTrajectorySeed(tkSeeds[is], muRef));
166  } // End of tk seed loop
167 
168  } // End of l2 muon loop
169 
170  // std::cout << "Found " << result->size() << " seeds for muons" << std::endl;
171 
172  // And yet another plot
173  // if(h_nGoodSeedPerEvent) h_nGoodSeedPerEvent->Fill(result->size());
174 
175  //put in the event
176  ev.put(result);
177 
178 }
179 
180 bool
183  const BasicTrajectorySeed* aSeed,
184  const SimTrack& theSimTrack) {
185 
186  // Eta cleaner
187  const PixelRecoRange<float>& etaRange = region->etaRange() ;
188  double etaSeed = theSimTrack.momentum().Eta();
189  double etaLimit = (fabs(fabs(etaRange.max())-fabs(etaRange.mean())) <0.05) ?
190  0.05 : fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) ;
191  bool inEtaRange =
192  etaSeed >= (etaRange.mean() - etaLimit) &&
193  etaSeed <= (etaRange.mean() + etaLimit) ;
194  if ( !inEtaRange ) return false;
195 
196  // Phi cleaner
197  const TkTrackingRegionsMargin<float>& phiMargin = region->phiMargin();
198  double phiSeed = theSimTrack.momentum().Phi();
199  double phiLimit = (phiMargin.right() < 0.05 ) ? 0.05 : phiMargin.right();
200  bool inPhiRange =
201  (fabs(deltaPhi(phiSeed,double(region->direction().phi()))) < phiLimit );
202  if ( !inPhiRange ) return false;
203 
204  // pt cleaner
205  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
206  double ptMin = (region->ptMin()>3.5) ? 3.5: region->ptMin();
207  bool inPtRange = ptSeed >= ptMin && ptSeed<= 2*(muRef->pt());
208  return inPtRange;
209 
210 }
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
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
edm::InputTag theSimTrackCollectionLabel
bool ev
MuonTrackingRegionBuilder * theRegionBuilder
edm::ParameterSet theConfig
GlobalVector const & direction() const
the direction around which region is constructed
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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:402
int iseed
Definition: AMPTWrapper.h:124
T mean() const
range recHits() const
float ptMin() const
minimal pt of interest
edm::InputTag theL2CollectionLabel
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
virtual void beginRun(edm::Run const &run, edm::EventSetup const &es) override
Definition: Run.h:41
const Range & etaRange() const
allowed eta range [eta_min, eta_max] interval