CMS 3D CMS Logo

L3MuonIsolationProducer.cc
Go to the documentation of this file.
2 
3 // Framework
8 
10 
12 
16 
19 
22 
25 
27 
28 #include <string>
29 
30 using namespace edm;
31 using namespace std;
32 using namespace reco;
33 using namespace muonisolation;
34 
37  theConfig(par),
38  theMuonCollectionLabel(par.getParameter<InputTag>("inputMuonCollection")),
39  optOutputIsoDeposits(par.getParameter<bool>("OutputMuIsoDeposits")),
40  theExtractor(0),
41  theTrackPt_Min(-1)
42  {
43  LogDebug("RecoMuon|L3MuonIsolationProducer")<<" L3MuonIsolationProducer CTOR";
44 
45  theMuonCollectionToken = consumes<RecoChargedCandidateCollection>(theMuonCollectionLabel);
46 
47  if (optOutputIsoDeposits) produces<reco::IsoDepositMap>();
48  produces<edm::ValueMap<bool> >();
49 
50  //
51  // Extractor
52  //
53  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
55  theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
56  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
57  theExtractor = IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet, consumesCollector());
58  std::string depositType = extractorPSet.getUntrackedParameter<std::string>("DepositLabel");
59 
60  //
61  // Cuts
62  //
64  std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
65  if (cutsName == "SimpleCuts") {
66  theCuts = Cuts(cutsPSet);
67  }
68  else if (
69 // (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
70 // || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS")
72  (cutsName== "L3NominalEfficiencyCuts_PXLS" )
73  || (cutsName== "L3NominalEfficiencyCuts_TRKS") ) {
75  }
76  else {
77  LogError("L3MuonIsolationProducer::beginJob")
78  <<"cutsName: "<<cutsPSet<<" is not recognized:"
79  <<" theCuts not set!";
80  }
81  LogTrace("")<< theCuts.print();
82 
83  // (kludge) additional cut on the number of tracks
84  theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
85  theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
86 }
87 
90  LogDebug("RecoMuon|L3MuonIsolationProducer")<<" L3MuonIsolationProducer DTOR";
91  if (theExtractor) delete theExtractor;
92 }
93 
95  std::string metname = "RecoMuon|L3MuonIsolationProducer";
96 
97  LogDebug(metname)<<" L3 Muon Isolation producing..."
98  <<" BEGINING OF EVENT " <<"================================";
99 
100  // Take the SA container
101  LogTrace(metname)<<" Taking the muons: "<<theMuonCollectionLabel;
103  event.getByToken(theMuonCollectionToken,muons);
104 
105  auto depMap = std::make_unique<reco::IsoDepositMap>();
106  auto isoMap = std::make_unique<edm::ValueMap<bool>>();
107 
108 
109  //
110  // get Vetos and deposits
111  //
112  unsigned int nMuons = muons->size();
113 
114  IsoDeposit::Vetos vetos(nMuons);
115 
116  std::vector<IsoDeposit> deps(nMuons);
117  std::vector<bool> isos(nMuons, false);
118 
119  for (unsigned int i=0; i<nMuons; i++) {
120  TrackRef mu(muons,i);
121  deps[i] = theExtractor->deposit(event, eventSetup, *mu);
122  vetos[i] = deps[i].veto();
123  }
124 
125  //
126  // add here additional vetos
127  //
128  //.....
129 
130  //
131  // actual cut step
132  //
133  for(unsigned int iMu=0; iMu < nMuons; ++iMu){
134  const reco::Track* mu = &(*muons)[iMu];
135 
136  const IsoDeposit & deposit = deps[iMu];
137  LogTrace(metname)<< deposit.print();
138 
139  const Cuts::CutSpec & cut = theCuts( mu->eta());
140  std::pair<double, int> sumAndCount = deposit.depositAndCountWithin(cut.conesize, vetos, theTrackPt_Min);
141 
142  double value = sumAndCount.first;
143  int count = sumAndCount.second;
144 
145  bool result = (value < cut.threshold);
146  if (theApplyCutsORmaxNTracks ) result |= count <= theMaxNTracks;
147  LogTrace(metname)<<"deposit in cone: "<<value<<"with count "<<count<<" is isolated: "<<result;
148 
149  isos[iMu] = result;
150  }
151 
152  //
153  // store
154  //
156  reco::IsoDepositMap::Filler depFiller(*depMap);
157  depFiller.insert(muons, deps.begin(), deps.end());
158  depFiller.fill();
159  event.put(std::move(depMap));
160  }
161  edm::ValueMap<bool> ::Filler isoFiller(*isoMap);
162  isoFiller.insert(muons, isos.begin(), isos.end());
163  isoFiller.fill();
164  event.put(std::move(isoMap));
165 
166  LogTrace(metname) <<" END OF EVENT " <<"================================";
167 }
#define LogDebug(id)
T getParameter(std::string const &) const
const Veto & veto() const
Get veto area.
Definition: IsoDeposit.h:78
const std::string metname
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::string print() const
Definition: Cuts.cc:55
bool theApplyCutsORmaxNTracks
apply or not the maxN cut on top of the sumPt (or nominall eff) < cuts
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const =0
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theMuonCollectionToken
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const int mu
Definition: Constants.h:22
Definition: value.py:1
L3MuonIsolationProducer(const edm::ParameterSet &)
constructor with config
#define LogTrace(id)
fixed size matrix
HLT enums.
std::pair< double, int > depositAndCountWithin(double coneSize, const Vetos &vetos=Vetos(), double threshold=-1e+36, bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:44
std::string print() const
Definition: IsoDeposit.cc:181
virtual void produce(edm::Event &, const edm::EventSetup &) override
Produce isolation maps.
virtual ~L3MuonIsolationProducer()
destructor
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55
Definition: event.py:1
reco::isodeposit::IsoDepositExtractor * theExtractor