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  theTrackPt_Min(-1)
41  {
42  LogDebug("RecoMuon|L3MuonIsolationProducer")<<" L3MuonIsolationProducer CTOR";
43 
44  theMuonCollectionToken = consumes<RecoChargedCandidateCollection>(theMuonCollectionLabel);
45 
46  if (optOutputIsoDeposits) produces<reco::IsoDepositMap>();
47  produces<edm::ValueMap<bool> >();
48 
49  //
50  // Extractor
51  //
52  edm::ParameterSet extractorPSet = theConfig.getParameter<edm::ParameterSet>("ExtractorPSet");
54  theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
55  std::string extractorName = extractorPSet.getParameter<std::string>("ComponentName");
56  theExtractor = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{IsoDepositExtractorFactory::get()->create( extractorName, extractorPSet, consumesCollector())};
57  std::string depositType = extractorPSet.getUntrackedParameter<std::string>("DepositLabel");
58 
59  //
60  // Cuts
61  //
63  std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
64  if (cutsName == "SimpleCuts") {
65  theCuts = Cuts(cutsPSet);
66  }
67  else if (
68 // (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
69 // || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS")
71  (cutsName== "L3NominalEfficiencyCuts_PXLS" )
72  || (cutsName== "L3NominalEfficiencyCuts_TRKS") ) {
74  }
75  else {
76  LogError("L3MuonIsolationProducer::beginJob")
77  <<"cutsName: "<<cutsPSet<<" is not recognized:"
78  <<" theCuts not set!";
79  }
80  LogTrace("")<< theCuts.print();
81 
82  // (kludge) additional cut on the number of tracks
83  theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
84  theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
85 }
86 
89  LogDebug("RecoMuon|L3MuonIsolationProducer")<<" L3MuonIsolationProducer DTOR";
90 }
91 
93  std::string metname = "RecoMuon|L3MuonIsolationProducer";
94 
95  LogDebug(metname)<<" L3 Muon Isolation producing..."
96  <<" BEGINING OF EVENT " <<"================================";
97 
98  // Take the SA container
99  LogTrace(metname)<<" Taking the muons: "<<theMuonCollectionLabel;
101  event.getByToken(theMuonCollectionToken,muons);
102 
103  auto depMap = std::make_unique<reco::IsoDepositMap>();
104  auto isoMap = std::make_unique<edm::ValueMap<bool>>();
105 
106 
107  //
108  // get Vetos and deposits
109  //
110  unsigned int nMuons = muons->size();
111 
112  IsoDeposit::Vetos vetos(nMuons);
113 
114  std::vector<IsoDeposit> deps(nMuons);
115  std::vector<bool> isos(nMuons, false);
116 
117  for (unsigned int i=0; i<nMuons; i++) {
118  TrackRef mu(muons,i);
119  deps[i] = theExtractor->deposit(event, eventSetup, *mu);
120  vetos[i] = deps[i].veto();
121  }
122 
123  //
124  // add here additional vetos
125  //
126  //.....
127 
128  //
129  // actual cut step
130  //
131  for(unsigned int iMu=0; iMu < nMuons; ++iMu){
132  const reco::Track* mu = &(*muons)[iMu];
133 
134  const IsoDeposit & deposit = deps[iMu];
135  LogTrace(metname)<< deposit.print();
136 
137  const Cuts::CutSpec & cut = theCuts( mu->eta());
138  std::pair<double, int> sumAndCount = deposit.depositAndCountWithin(cut.conesize, vetos, theTrackPt_Min);
139 
140  double value = sumAndCount.first;
141  int count = sumAndCount.second;
142 
143  bool result = (value < cut.threshold);
144  if (theApplyCutsORmaxNTracks ) result |= count <= theMaxNTracks;
145  LogTrace(metname)<<"deposit in cone: "<<value<<"with count "<<count<<" is isolated: "<<result;
146 
147  isos[iMu] = result;
148  }
149 
150  //
151  // store
152  //
154  reco::IsoDepositMap::Filler depFiller(*depMap);
155  depFiller.insert(muons, deps.begin(), deps.end());
156  depFiller.fill();
157  event.put(std::move(depMap));
158  }
159  edm::ValueMap<bool> ::Filler isoFiller(*isoMap);
160  isoFiller.insert(muons, isos.begin(), isos.end());
161  isoFiller.fill();
162  event.put(std::move(isoMap));
163 
164  LogTrace(metname) <<" END OF EVENT " <<"================================";
165 }
#define LogDebug(id)
T getParameter(std::string const &) const
const std::string metname
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
~L3MuonIsolationProducer() override
destructor
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
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:684
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theMuonCollectionToken
const int mu
Definition: Constants.h:22
Definition: value.py:1
L3MuonIsolationProducer(const edm::ParameterSet &)
constructor with config
#define LogTrace(id)
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > theExtractor
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
void produce(edm::Event &, const edm::EventSetup &) override
Produce isolation maps.
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
Definition: event.py:1