CMS 3D CMS Logo

L1TauRecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TNtuples
4 // Class: L1JetRecoTreeProducer
5 //
13 // system include files
14 #include <memory>
15 
16 // framework
25 
26 // cond formats
28 
29 // data formats
33 
34 //taus
38 
39 // #include "CommonTools/UtilAlgos/interface/PhysObjectMatcher.h"
40 // #include "CommonTools/UtilAlgos/interface/MCMatchSelector.h"
41 // #include "CommonTools/UtilAlgos/interface/DummyMatchSelector.h"
42 // #include "CommonTools/UtilAlgos/interface/MatchByDRDPt.h"
43 // #include "DataFormats/TauReco/interface/PFTauDecayMode.h"
44 // #include "DataFormats/TauReco/interface/PFTauDecayModeFwd.h"
45 // #include "DataFormats/TauReco/interface/PFTau.h"
46 
47 // ROOT output stuff
50 #include "TH1.h"
51 #include "TTree.h"
52 #include "TF1.h"
53 
54 //local data formats
57 
58 //
59 // class declaration
60 //
61 
63 public:
65  ~L1TauRecoTreeProducer() override;
66 
67 private:
68  void beginJob(void) override;
69  void analyze(const edm::Event&, const edm::EventSetup&) override;
70  void endJob() override;
71 
72 public:
74 
76 
77 private:
78  // output file
80 
81  // tree
82  TTree* tree_;
83 
84  // EDM input tags
96 
97  // edm::EDGetTokenT<reco::CaloJetCollection> caloJetToken_;
98  // edm::EDGetTokenT<edm::ValueMap<reco::JetID> > caloJetIdToken_;
99  // edm::EDGetTokenT<reco::JetCorrector> jetCorrectorToken_;
100 
101  // debug stuff
104  unsigned int maxCl_;
106  unsigned int maxTau_;
107  unsigned int maxVtx_;
108  unsigned int maxTrk_;
109 };
110 
112  period_ = iConfig.getParameter<std::string>("period");
113 
114  if (period_ == "2015") {
115  maxTau_ = iConfig.getParameter<unsigned int>("maxTau");
116  TauToken_ =
117  consumes<reco::PFTauCollection>(iConfig.getUntrackedParameter("TauToken", edm::InputTag("hpsPFTauProducer")));
118  DMFindingToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
119  "DMFindingToken", edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingNewDMs")));
120  DMFindingOldToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
121  "DMFindingOldToken", edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingOldDMs")));
122  TightIsoToken_ = consumes<reco::PFTauDiscriminator>(
123  iConfig.getUntrackedParameter("TightIsoToken", edm::InputTag("hpsPFTauDiscriminationByTightIsolation")));
124  TightRawIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
125  "TightRawIsoToken", edm::InputTag("hpsPFTauDiscriminationByRawCombinedIsolationDBSumPtCorr3Hits")));
126  LooseIsoToken_ = consumes<reco::PFTauDiscriminator>(
127  iConfig.getUntrackedParameter("LooseIsoToken", edm::InputTag("hpsPFTauDiscriminationByLooseIsolation")));
128  LooseAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
129  "LooseAntiMuonToken", edm::InputTag("hpsPFTauDiscriminationByLooseMuonRejection")));
130  TightAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
131  "TightAntiMuonToken", edm::InputTag("hpsPFTauDiscriminationByTightMuonRejection")));
132  VLooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
133  "VLooseAntiElectronToken", edm::InputTag("hpsPFTauDiscriminationByMVA5VLooseElectronRejection")));
134  LooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
135  "LooseAntiElectronToken", edm::InputTag("hpsPFTauDiscriminationByMVA5LooseElectronRejection")));
136  TightAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
137  "TightAntiElectronToken", edm::InputTag("hpsPFTauDiscriminationByMVA5TightElectronRejection")));
138  } else if (period_ == "2016") {
139  maxTau_ = iConfig.getParameter<unsigned int>("maxTau");
140  TauToken_ =
141  consumes<reco::PFTauCollection>(iConfig.getUntrackedParameter("TauToken", edm::InputTag("hpsPFTauProducer")));
142  DMFindingToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
143  "DMFindingToken", edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingNewDMs")));
144  DMFindingOldToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
145  "DMFindingOldToken", edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingOldDMs")));
146  TightIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
147  "TightIsoToken", edm::InputTag("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3Hits")));
148  TightRawIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
149  "TightRawIsoToken", edm::InputTag("hpsPFTauDiscriminationByRawCombinedIsolationDBSumPtCorr3Hits")));
150  LooseIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
151  "LooseIsoToken", edm::InputTag("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits")));
152  LooseAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
153  "LooseAntiMuonToken", edm::InputTag("hpsPFTauDiscriminationByLooseMuonRejection3")));
154  TightAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
155  "TightAntiMuonToken", edm::InputTag("hpsPFTauDiscriminationByTightMuonRejection3")));
156  VLooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
157  "VLooseAntiElectronToken", edm::InputTag("hpsPFTauDiscriminationByMVA6VLooseElectronRejection")));
158  LooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
159  "LooseAntiElectronToken", edm::InputTag("hpsPFTauDiscriminationByMVA6LooseElectronRejection")));
160  TightAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter(
161  "TightAntiElectronToken", edm::InputTag("hpsPFTauDiscriminationByMVA6TightElectronRejection")));
162  }
163 
164  /*
165  caloJetToken_ = consumes<reco::CaloJetCollection>(iConfig.getUntrackedParameter("caloJetToken",edm::InputTag("ak4CaloJets")));
166  // caloJetIdToken_ = consumes<edm::ValueMap<reco::JetID> >(iConfig.getUntrackedParameter("jetIdToken",edm::InputTag("ak4JetID")));
167  jetCorrectorToken_ = consumes<reco::JetCorrector>(iConfig.getUntrackedParameter<edm::InputTag>("jetCorrToken"));
168 
169  jetptThreshold_ = iConfig.getParameter<double> ("jetptThreshold");
170  maxTau_ = iConfig.getParameter<unsigned int>("maxTau");
171  */
172 
174  tau_data = tau->getData();
175 
176  /*
177  // set up output
178  */
179  tree_ = fs_->make<TTree>("TauRecoTree", "TauRecoTree");
180  //tree_=fs_->make<TTree>("JetRecoTree", "JetRecoTree");
181  tree_->Branch("Tau", "L1Analysis::L1AnalysisRecoTauDataFormat", &tau_data, 32000, 3);
182 }
183 
185  // do anything here that needs to be done at desctruction time
186  // (e.g. close files, deallocate resources etc.)
187 }
188 
189 //
190 // member functions
191 //
192 
193 // ------------ method called to for each event ------------
195  tau->Reset();
197  iEvent.getByToken(TauToken_, recoTaus);
198 
200  iEvent.getByToken(DMFindingToken_, DMFindingTaus);
201 
202  edm::Handle<reco::PFTauDiscriminator> DMFindingOldTaus;
203  iEvent.getByToken(DMFindingOldToken_, DMFindingOldTaus);
204 
206  iEvent.getByToken(TightIsoToken_, TightIsoTaus);
207 
209  iEvent.getByToken(TightRawIsoToken_, TightRawIsoTaus);
210 
212  iEvent.getByToken(LooseIsoToken_, LooseIsoTaus);
213 
215  iEvent.getByToken(LooseAntiMuonToken_, LooseAntiMuon);
216 
218  iEvent.getByToken(TightAntiMuonToken_, TightAntiMuon);
219 
220  edm::Handle<reco::PFTauDiscriminator> VLooseAntiElectron;
221  iEvent.getByToken(VLooseAntiElectronToken_, VLooseAntiElectron);
222 
223  edm::Handle<reco::PFTauDiscriminator> LooseAntiElectron;
224  iEvent.getByToken(LooseAntiElectronToken_, LooseAntiElectron);
225 
226  edm::Handle<reco::PFTauDiscriminator> TightAntiElectron;
227  iEvent.getByToken(TightAntiElectronToken_, TightAntiElectron);
228 
229  //std::cout<<"size of recoTaus = "<<recoTaus->size()<<std::endl;
230 
231  if (recoTaus.isValid()) {
232  //std::cout<<"passing here"<<std::endl;
233  tau->SetTau(iEvent,
234  iSetup,
235  recoTaus,
236  DMFindingOldTaus,
237  DMFindingTaus,
238  TightIsoTaus,
239  TightRawIsoTaus,
240  LooseIsoTaus,
241  LooseAntiMuon,
242  TightAntiMuon,
243  VLooseAntiElectron,
244  LooseAntiElectron,
245  TightAntiElectron,
246  maxTau_);
247  } else {
248  if (!caloJetsMissing_) {
249  edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;
250  }
251  caloJetsMissing_ = true;
252  }
253 
254  /*
255  jet->Reset();
256 
257  // get jets & co...
258  edm::Handle<reco::CaloJetCollection> recoCaloJets;
259  edm::Handle<edm::ValueMap<reco::JetID> > jetsID;
260  edm::Handle<reco::JetCorrector> jetCorr;
261 
262  iEvent.getByToken(caloJetToken_, recoCaloJets);
263  //iEvent.getByLabel(jetIdTag_,jetsID);
264  //iEvent.getByToken(jetCorrectorToken_, jetCorr);
265 
266  if (recoCaloJets.isValid()) {
267  jet->SetCaloJet(iEvent, iSetup, recoCaloJets, maxTau_); //jetsID, maxTau_);
268  }
269  else {
270  if (!caloJetsMissing_) {edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;}
271  caloJetsMissing_ = true;
272  }
273  */
274 
275  tree_->Fill();
276 }
277 
278 // ------------ method called once each job just before starting event loop ------------
280 
281 // ------------ method called once each job just after ending the event loop ------------
283 
284 //define this as a plug-in
void SetTau(const edm::Event &event, const edm::EventSetup &setup, const edm::Handle< reco::PFTauCollection > taus, const edm::Handle< reco::PFTauDiscriminator > DMFindingOldTaus, const edm::Handle< reco::PFTauDiscriminator > DMFindingTaus, const edm::Handle< reco::PFTauDiscriminator > TightIsoTaus, const edm::Handle< reco::PFTauDiscriminator > TightRawIsoTaus, const edm::Handle< reco::PFTauDiscriminator > LooseIsoTaus, const edm::Handle< reco::PFTauDiscriminator > LooseAntiMuon, const edm::Handle< reco::PFTauDiscriminator > TightAntiMuon, const edm::Handle< reco::PFTauDiscriminator > VLooseAntiElectron, const edm::Handle< reco::PFTauDiscriminator > LooseAntiElectron, const edm::Handle< reco::PFTauDiscriminator > TightAntiElectron, unsigned maxTau)
edm::EDGetTokenT< reco::PFTauDiscriminator > TightAntiMuonToken_
L1Analysis::L1AnalysisRecoTauDataFormat * tau_data
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::PFTauDiscriminator > TightRawIsoToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > VLooseAntiElectronToken_
L1AnalysisRecoTauDataFormat * getData()
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseIsoToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::PFTauDiscriminator > TightIsoToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > DMFindingToken_
L1Analysis::L1AnalysisRecoTau * tau
edm::EDGetTokenT< reco::PFTauDiscriminator > DMFindingOldToken_
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::PFTauDiscriminator > TightAntiElectronToken_
int iEvent
Definition: GenABIO.cc:224
L1TauRecoTreeProducer(const edm::ParameterSet &)
edm::EDGetTokenT< reco::PFTauCollection > TauToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseAntiElectronToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseAntiMuonToken_
bool isValid() const
Definition: HandleBase.h:70
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::Service< TFileService > fs_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Log< level::Warning, false > LogWarning
void beginJob(void) override