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 
62 class L1TauRecoTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
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  usesResource(TFileService::kSharedResource);
177  /*
178  // set up output
179  */
180  tree_ = fs_->make<TTree>("TauRecoTree", "TauRecoTree");
181  //tree_=fs_->make<TTree>("JetRecoTree", "JetRecoTree");
182  tree_->Branch("Tau", "L1Analysis::L1AnalysisRecoTauDataFormat", &tau_data, 32000, 3);
183 }
184 
186  // do anything here that needs to be done at desctruction time
187  // (e.g. close files, deallocate resources etc.)
188 }
189 
190 //
191 // member functions
192 //
193 
194 // ------------ method called to for each event ------------
196  tau->Reset();
198  iEvent.getByToken(TauToken_, recoTaus);
199 
201  iEvent.getByToken(DMFindingToken_, DMFindingTaus);
202 
203  edm::Handle<reco::PFTauDiscriminator> DMFindingOldTaus;
204  iEvent.getByToken(DMFindingOldToken_, DMFindingOldTaus);
205 
207  iEvent.getByToken(TightIsoToken_, TightIsoTaus);
208 
210  iEvent.getByToken(TightRawIsoToken_, TightRawIsoTaus);
211 
213  iEvent.getByToken(LooseIsoToken_, LooseIsoTaus);
214 
216  iEvent.getByToken(LooseAntiMuonToken_, LooseAntiMuon);
217 
219  iEvent.getByToken(TightAntiMuonToken_, TightAntiMuon);
220 
221  edm::Handle<reco::PFTauDiscriminator> VLooseAntiElectron;
222  iEvent.getByToken(VLooseAntiElectronToken_, VLooseAntiElectron);
223 
224  edm::Handle<reco::PFTauDiscriminator> LooseAntiElectron;
225  iEvent.getByToken(LooseAntiElectronToken_, LooseAntiElectron);
226 
227  edm::Handle<reco::PFTauDiscriminator> TightAntiElectron;
228  iEvent.getByToken(TightAntiElectronToken_, TightAntiElectron);
229 
230  //std::cout<<"size of recoTaus = "<<recoTaus->size()<<std::endl;
231 
232  if (recoTaus.isValid()) {
233  //std::cout<<"passing here"<<std::endl;
234  tau->SetTau(iEvent,
235  iSetup,
236  recoTaus,
237  DMFindingOldTaus,
238  DMFindingTaus,
239  TightIsoTaus,
240  TightRawIsoTaus,
241  LooseIsoTaus,
242  LooseAntiMuon,
243  TightAntiMuon,
244  VLooseAntiElectron,
245  LooseAntiElectron,
246  TightAntiElectron,
247  maxTau_);
248  } else {
249  if (!caloJetsMissing_) {
250  edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;
251  }
252  caloJetsMissing_ = true;
253  }
254 
255  /*
256  jet->Reset();
257 
258  // get jets & co...
259  edm::Handle<reco::CaloJetCollection> recoCaloJets;
260  edm::Handle<edm::ValueMap<reco::JetID> > jetsID;
261  edm::Handle<reco::JetCorrector> jetCorr;
262 
263  iEvent.getByToken(caloJetToken_, recoCaloJets);
264  //iEvent.getByLabel(jetIdTag_,jetsID);
265  //iEvent.getByToken(jetCorrectorToken_, jetCorr);
266 
267  if (recoCaloJets.isValid()) {
268  jet->SetCaloJet(iEvent, iSetup, recoCaloJets, maxTau_); //jetsID, maxTau_);
269  }
270  else {
271  if (!caloJetsMissing_) {edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;}
272  caloJetsMissing_ = true;
273  }
274  */
275 
276  tree_->Fill();
277 }
278 
279 // ------------ method called once each job just before starting event loop ------------
281 
282 // ------------ method called once each job just after ending the event loop ------------
284 
285 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
edm::EDGetTokenT< reco::PFTauDiscriminator > TightAntiMuonToken_
L1Analysis::L1AnalysisRecoTauDataFormat * tau_data
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< reco::PFTauDiscriminator > TightRawIsoToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > VLooseAntiElectronToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseIsoToken_
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_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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