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