CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L3MuonCombinedRelativeIsolationProducer.cc
Go to the documentation of this file.
2 
3 // Framework
9 
11 
13 
19 
22 
25 
28 
30 
31 #include <string>
32 
33 using namespace edm;
34 using namespace std;
35 using namespace reco;
36 using namespace muonisolation;
37 
40  theConfig(par),
41  theMuonCollectionLabel(par.getParameter<InputTag>("inputMuonCollection")),
42  optOutputIsoDeposits(par.getParameter<bool>("OutputMuIsoDeposits")),
43  useCaloIso(par.existsAs<bool>("UseCaloIso") ?
44  par.getParameter<bool>("UseCaloIso") : true),
45  useRhoCorrectedCaloDeps(par.existsAs<bool>("UseRhoCorrectedCaloDeposits") ?
46  par.getParameter<bool>("UseRhoCorrectedCaloDeposits") : false),
47  theCaloDepsLabel(par.existsAs<InputTag>("CaloDepositsLabel") ?
48  par.getParameter<InputTag>("CaloDepositsLabel") :
49  InputTag("hltL3CaloMuonCorrectedIsolations")),
50  caloExtractor(0),
51  trkExtractor(0),
52  theTrackPt_Min(-1),
53  printDebug (par.getParameter<bool>("printDebug"))
54  {
55  LogDebug("RecoMuon|L3MuonCombinedRelativeIsolationProducer")<<" L3MuonCombinedRelativeIsolationProducer CTOR";
56 
57  theMuonCollectionToken = consumes<RecoChargedCandidateCollection>(theMuonCollectionLabel);
58  theCaloDepsToken = consumes<edm::ValueMap<float> >(theCaloDepsLabel);
59 
61  produces<reco::IsoDepositMap>("trkIsoDeposits");
62  if( useRhoCorrectedCaloDeps==false ) // otherwise, calo deposits have been previously computed
63  produces<reco::IsoDepositMap>("caloIsoDeposits");
64  //produces<std::vector<double> >("combinedRelativeIsoDeposits");
65  produces<edm::ValueMap<double> >("combinedRelativeIsoDeposits");
66  }
67  produces<edm::ValueMap<bool> >();
68 
69  //
70  // Extractor
71  //
72  // Calorimeters (ONLY if not previously computed)
73  //
74  if( useCaloIso && (useRhoCorrectedCaloDeps==false) ) {
75  edm::ParameterSet caloExtractorPSet = theConfig.getParameter<edm::ParameterSet>("CaloExtractorPSet");
76 
77  std::string caloExtractorName = caloExtractorPSet.getParameter<std::string>("ComponentName");
78  caloExtractor = IsoDepositExtractorFactory::get()->create( caloExtractorName, caloExtractorPSet, consumesCollector());
79  //std::string caloDepositType = caloExtractorPSet.getUntrackedParameter<std::string>("DepositLabel"); // N.B. Not used in the following!
80  }
81 
82  // Tracker
83  //
84  edm::ParameterSet trkExtractorPSet = theConfig.getParameter<edm::ParameterSet>("TrkExtractorPSet");
85 
86  theTrackPt_Min = theConfig.getParameter<double>("TrackPt_Min");
87  std::string trkExtractorName = trkExtractorPSet.getParameter<std::string>("ComponentName");
88  trkExtractor = IsoDepositExtractorFactory::get()->create( trkExtractorName, trkExtractorPSet, consumesCollector());
89  //std::string trkDepositType = trkExtractorPSet.getUntrackedParameter<std::string>("DepositLabel"); // N.B. Not used in the following!
90 
91  //
92  // Cuts for track isolation
93  //
95  std::string cutsName = cutsPSet.getParameter<std::string>("ComponentName");
96  if (cutsName == "SimpleCuts") {
97  theCuts = Cuts(cutsPSet);
98  }
99  else if (
100  // (cutsName== "L3NominalEfficiencyCuts_PXLS" && depositType=="PXLS")
101  // || (cutsName== "L3NominalEfficiencyCuts_TRKS" && depositType=="TRKS")
103  (cutsName== "L3NominalEfficiencyCuts_PXLS" )
104  || (cutsName== "L3NominalEfficiencyCuts_TRKS") ) {
106  }
107  else {
108  LogError("L3MuonCombinedRelativeIsolationProducer::beginJob")
109  <<"cutsName: "<<cutsPSet<<" is not recognized:"
110  <<" theCuts not set!";
111  }
112  LogTrace("")<< theCuts.print();
113 
114  // (kludge) additional cut on the number of tracks
115  theMaxNTracks = cutsPSet.getParameter<int>("maxNTracks");
116  theApplyCutsORmaxNTracks = cutsPSet.getParameter<bool>("applyCutsORmaxNTracks");
117 
118 }
119 
122  LogDebug("RecoMuon|L3MuonCombinedRelativeIsolationProducer")<<" L3MuonCombinedRelativeIsolationProducer DTOR";
123  if (caloExtractor) delete caloExtractor;
124  if (trkExtractor) delete trkExtractor;
125 }
126 
130  desc.add<bool>("UseRhoCorrectedCaloDeposits",false);
131  desc.add<bool>("UseCaloIso",true);
132  desc.add<edm::InputTag>("CaloDepositsLabel",edm::InputTag("hltL3CaloMuonCorrectedIsolations"));
133  desc.add<edm::InputTag>("inputMuonCollection",edm::InputTag("hltL3MuonCandidates"));
134  desc.add<bool>("OutputMuIsoDeposits",true);
135  desc.add<double>("TrackPt_Min",-1.0);
136  desc.add<bool>("printDebug",false);
138  {
139  cutsPSet.add<std::vector<double> >("ConeSizes",std::vector<double>(1, 0.24));
140  cutsPSet.add<std::string>("ComponentName","SimpleCuts");
141  cutsPSet.add<std::vector<double> >("Thresholds",std::vector<double>(1, 0.1));
142  cutsPSet.add<int>("maxNTracks",-1);
143  cutsPSet.add<std::vector<double> >("EtaBounds",std::vector<double>(1, 2.411));
144  cutsPSet.add<bool>("applyCutsORmaxNTracks",false);
145  }
146  desc.add<edm::ParameterSetDescription>("CutsPSet",cutsPSet);
147  edm::ParameterSetDescription trkExtractorPSet;
148  {
149  trkExtractorPSet.add<double>("Chi2Prob_Min", -1.0);
150  trkExtractorPSet.add<double>("Chi2Ndof_Max", 1.0E64);
151  trkExtractorPSet.add<double>("Diff_z",0.2);
152  trkExtractorPSet.add<edm::InputTag>("inputTrackCollection",edm::InputTag("hltPixelTracks"));
153  trkExtractorPSet.add<double>("ReferenceRadius",6.0);
154  trkExtractorPSet.add<edm::InputTag>("BeamSpotLabel",edm::InputTag("hltOnlineBeamSpot"));
155  trkExtractorPSet.add<std::string>("ComponentName","PixelTrackExtractor");
156  trkExtractorPSet.add<double>("DR_Max",0.24);
157  trkExtractorPSet.add<double>("Diff_r",0.1);
158  trkExtractorPSet.add<bool>("VetoLeadingTrack",true);
159  trkExtractorPSet.add<double>("DR_VetoPt",0.025);
160  trkExtractorPSet.add<double>("DR_Veto",0.01);
161  trkExtractorPSet.add<unsigned int>("NHits_Min",0);
162  trkExtractorPSet.add<double>("Pt_Min",-1.0);
163  trkExtractorPSet.addUntracked<std::string>("DepositLabel","PXLS");
164  trkExtractorPSet.add<std::string>("BeamlineOption","BeamSpotFromEvent");
165  trkExtractorPSet.add<bool>("PropagateTracksToRadius",true);
166  trkExtractorPSet.add<double>("PtVeto_Min",2.0);
167  }
168  desc.add<edm::ParameterSetDescription>("TrkExtractorPSet",trkExtractorPSet);
169  edm::ParameterSetDescription caloExtractorPSet;
170  {
171  caloExtractorPSet.add<double>("DR_Veto_H",0.1);
172  caloExtractorPSet.add<bool>("Vertex_Constraint_Z",false);
173  caloExtractorPSet.add<double>("Threshold_H",0.5);
174  caloExtractorPSet.add<std::string>("ComponentName","CaloExtractor");
175  caloExtractorPSet.add<double>("Threshold_E",0.2);
176  caloExtractorPSet.add<double>("DR_Max",0.24);
177  caloExtractorPSet.add<double>("DR_Veto_E",0.07);
178  caloExtractorPSet.add<double>("Weight_E",1.5);
179  caloExtractorPSet.add<bool>("Vertex_Constraint_XY",false);
180  caloExtractorPSet.addUntracked<std::string>("DepositLabel","EcalPlusHcal");
181  caloExtractorPSet.add<edm::InputTag>("CaloTowerCollectionLabel",edm::InputTag("hltTowerMakerForMuons"));
182  caloExtractorPSet.add<double>("Weight_H",1.0);
183  }
184  desc.add<edm::ParameterSetDescription>("CaloExtractorPSet",caloExtractorPSet);
185  descriptions.add("hltL3MuonIsolations", desc);
186 }
187 
188 
190  std::string metname = "RecoMuon|L3MuonCombinedRelativeIsolationProducer";
191 
192  if (printDebug) std::cout <<" L3 Muon Isolation producing..."
193  <<" BEGINING OF EVENT " <<"================================" <<std::endl;
194 
195  // Take the SA container
196  if (printDebug) std::cout <<" Taking the muons: "<<theMuonCollectionLabel << std::endl;
198  event.getByToken(theMuonCollectionToken,muons);
199 
200  // Take calo deposits with rho corrections (ONLY if previously computed)
201  Handle< edm::ValueMap<float> > caloDepWithCorrMap;
203  event.getByToken(theCaloDepsToken, caloDepWithCorrMap);
204 
205  std::auto_ptr<reco::IsoDepositMap> caloDepMap( new reco::IsoDepositMap());
206  std::auto_ptr<reco::IsoDepositMap> trkDepMap( new reco::IsoDepositMap());
207 
208  std::auto_ptr<edm::ValueMap<bool> > comboIsoDepMap( new edm::ValueMap<bool> ());
209 
210  //std::auto_ptr<std::vector<double> > combinedRelativeDeps(new std::vector<double>());
211  std::auto_ptr<edm::ValueMap<double> > combinedRelativeDepMap(new edm::ValueMap<double>());
212 
213 
214  //
215  // get Vetos and deposits
216  //
217  unsigned int nMuons = muons->size();
218 
219  IsoDeposit::Vetos trkVetos(nMuons);
220  std::vector<IsoDeposit> trkDeps(nMuons);
221 
222 
223  // IsoDeposit::Vetos caloVetos(nMuons);
224  // std::vector<IsoDeposit> caloDeps(nMuons);
225  // std::vector<float> caloCorrDeps(nMuons, 0.); // if calo deposits with corrections available
226 
227  IsoDeposit::Vetos caloVetos;
228  std::vector<IsoDeposit> caloDeps;
229  std::vector<float> caloCorrDeps; // if calo deposits with corrections available
230 
232  caloCorrDeps.resize(nMuons, 0.);
233  }
234  else if (useCaloIso) {
235  caloVetos.resize(nMuons);
236  caloDeps.resize(nMuons);
237  }
238 
239  std::vector<double> combinedRelativeDeps(nMuons, 0.);
240  std::vector<bool> combinedRelativeIsos(nMuons, false);
241 
242  for (unsigned int i=0; i<nMuons; i++) {
243 
244  RecoChargedCandidateRef candref(muons,i);
245  TrackRef mu = candref->track();
246 
247  trkDeps[i] = trkExtractor->deposit(event, eventSetup, *mu);
248  trkVetos[i] = trkDeps[i].veto();
249 
251  caloCorrDeps[i] = (*caloDepWithCorrMap)[candref];
252  }
253  else if (useCaloIso) {
254  caloDeps[i] = caloExtractor->deposit(event, eventSetup, *mu);
255  caloVetos[i] = caloDeps[i].veto();
256  }
257 
258  }
259 
260  //
261  // add here additional vetos
262  //
263  //.....
264 
265  //
266  // actual cut step
267  //
268 
269  if (printDebug) std::cout << "Looping over deposits...." << std::endl;
270  for(unsigned int iMu=0; iMu < nMuons; ++iMu){
271 
272  if (printDebug) std::cout << "Muon number = " << iMu << std::endl;
273  TrackRef mu = (*muons)[iMu].track();
274 
275  // cuts
276  const Cuts::CutSpec & cut = theCuts( mu->eta());
277 
278 
279  if (printDebug) std::cout << "CUTDEBUG: Muon eta = " << mu->eta() << std::endl
280  << "CUTDEBUG: Muon pt = " << mu->pt() << std::endl
281  << "CUTDEBUG: minEta = " << cut.etaRange.min() << std::endl
282  << "CUTDEBUG: maxEta = " << cut.etaRange.max() << std::endl
283  << "CUTDEBUG: consize = " << cut.conesize << std::endl
284  << "CUTDEBUG: thresho = " << cut.threshold << std::endl;
285 
286  const IsoDeposit & trkDeposit = trkDeps[iMu];
287  if (printDebug) std::cout << trkDeposit.print();
288  std::pair<double, int> trkIsoSumAndCount = trkDeposit.depositAndCountWithin(cut.conesize, trkVetos, theTrackPt_Min);
289 
290  double caloIsoSum = 0.;
292  caloIsoSum = caloCorrDeps[iMu];
293  if(caloIsoSum<0.) caloIsoSum = 0.;
294  if(printDebug) std::cout << "Rho-corrected calo deposit (min. 0) = " << caloIsoSum << std::endl;
295  }
296  else if (useCaloIso) {
297  const IsoDeposit & caloDeposit = caloDeps[iMu];
298  if (printDebug) std::cout << caloDeposit.print();
299  caloIsoSum = caloDeposit.depositWithin(cut.conesize, caloVetos);
300  }
301 
302  double trkIsoSum = trkIsoSumAndCount.first;
303  int count = trkIsoSumAndCount.second;
304 
305  double muPt = mu->pt();
306  if( muPt<1. ) muPt = 1.;
307  double combinedRelativeDeposit = ((trkIsoSum + caloIsoSum ) / muPt);
308  bool result = ( combinedRelativeDeposit < cut.threshold);
309  if (theApplyCutsORmaxNTracks ) result |= count <= theMaxNTracks;
310  if (printDebug) std::cout <<" trk dep in cone: " << trkIsoSum << " with count "<<count <<std::endl
311  <<" calo dep in cone: " << caloIsoSum << std::endl
312  <<" muPt: " << muPt << std::endl
313  <<" relIso: " <<combinedRelativeDeposit << std::endl
314  <<" is isolated: "<<result << std::endl;
315 
316  combinedRelativeIsos[iMu] = result;
317  //combinedRelativeDeps->push_back(combinedRelativeDeposit);
318  combinedRelativeDeps[iMu] = combinedRelativeDeposit;
319  }
320 
321  //
322  // store
323  //
325 
326  reco::IsoDepositMap::Filler depFillerTrk(*trkDepMap);
327  depFillerTrk.insert(muons, trkDeps.begin(), trkDeps.end());
328  depFillerTrk.fill();
329  event.put(trkDepMap, "trkIsoDeposits");
330 
331  if( useCaloIso && (useRhoCorrectedCaloDeps==false) ) {
332  reco::IsoDepositMap::Filler depFillerCalo(*caloDepMap);
333  depFillerCalo.insert(muons, caloDeps.begin(), caloDeps.end());
334  depFillerCalo.fill();
335  event.put(caloDepMap, "caloIsoDeposits");
336  }
337 
338  //event.put(combinedRelativeDeps, "combinedRelativeIsoDeposits");
339  edm::ValueMap<double>::Filler depFillerCombRel(*combinedRelativeDepMap);
340  depFillerCombRel.insert(muons, combinedRelativeDeps.begin(), combinedRelativeDeps.end());
341  depFillerCombRel.fill();
342  event.put(combinedRelativeDepMap, "combinedRelativeIsoDeposits");
343 
344  }
345  edm::ValueMap<bool>::Filler isoFiller(*comboIsoDepMap);
346  isoFiller.insert(muons, combinedRelativeIsos.begin(), combinedRelativeIsos.end());
347  isoFiller.fill();
348  event.put(comboIsoDepMap);
349 
350  if (printDebug) std::cout <<" END OF EVENT " <<"================================";
351 }
#define LogDebug(id)
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > theMuonCollectionToken
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const T & max() const
Definition: Range.h:25
const Veto & veto() const
Get veto area.
Definition: IsoDeposit.h:78
edm::EDGetTokenT< edm::ValueMap< float > > theCaloDepsToken
const std::string metname
bool theApplyCutsORmaxNTracks
apply or not the maxN cut on top of the sumPt (or nominall eff) &lt; cuts
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
double depositWithin(double coneSize, const Vetos &vetos=Vetos(), bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:34
std::string print() const
Definition: Cuts.cc:55
muonisolation::Range< double > etaRange
Definition: Cuts.h:15
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterSet descriptions.
virtual void produce(edm::Event &, const edm::EventSetup &)
Produce isolation maps.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
tuple result
Definition: query.py:137
const int mu
Definition: Constants.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define LogTrace(id)
L3MuonCombinedRelativeIsolationProducer(const edm::ParameterSet &)
constructor with config
const T & min() const
Definition: Range.h:23
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool useCaloIso
flag to include or exclude calo iso from calculation
tuple muons
Definition: patZpeak.py:38
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
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
virtual reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const =0
T get(const Candidate &c)
Definition: component.h:55