CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TauRecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TNtuples
4 // Class: L1JetRecoTreeProducer
5 //
14 // system include files
15 #include <memory>
16 
17 // framework
26 
27 // cond formats
29 
30 // data formats
34 
35 
36 //taus
40 
41 // #include "CommonTools/UtilAlgos/interface/PhysObjectMatcher.h"
42 // #include "CommonTools/UtilAlgos/interface/MCMatchSelector.h"
43 // #include "CommonTools/UtilAlgos/interface/DummyMatchSelector.h"
44 // #include "CommonTools/UtilAlgos/interface/MatchByDRDPt.h"
45 // #include "DataFormats/TauReco/interface/PFTauDecayMode.h"
46 // #include "DataFormats/TauReco/interface/PFTauDecayModeFwd.h"
47 // #include "DataFormats/TauReco/interface/PFTau.h"
48 
49 
50 // ROOT output stuff
53 #include "TH1.h"
54 #include "TTree.h"
55 #include "TF1.h"
56 
57 //local data formats
60 
61 //
62 // class declaration
63 //
64 
66 public:
69 
70 
71 private:
72  virtual void beginJob(void) ;
73  virtual void analyze(const edm::Event&, const edm::EventSetup&);
74  virtual void endJob();
75 
76 public:
78 
80 
81 private:
82 
83  // output file
85 
86  // tree
87  TTree * tree_;
88 
89  // EDM input tags
101 
102  // edm::EDGetTokenT<reco::CaloJetCollection> caloJetToken_;
103  // edm::EDGetTokenT<edm::ValueMap<reco::JetID> > caloJetIdToken_;
104  // edm::EDGetTokenT<reco::JetCorrector> jetCorrectorToken_;
105 
106  // debug stuff
109  unsigned int maxCl_;
111  unsigned int maxTau_;
112  unsigned int maxVtx_;
113  unsigned int maxTrk_;
114 };
115 
116 
117 
119  caloJetsMissing_(false)
120 {
121 
122  period_ = iConfig.getParameter<std::string>("period");
123 
124  if(period_=="2015")
125  {
126  maxTau_ = iConfig.getParameter<unsigned int>("maxTau");
127  TauToken_ = consumes<reco::PFTauCollection>(iConfig.getUntrackedParameter("TauToken",edm::InputTag("hpsPFTauProducer")));
128  DMFindingToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("DMFindingToken",edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingNewDMs")));
129  DMFindingOldToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("DMFindingOldToken",edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingOldDMs")));
130  TightIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightIsoToken",edm::InputTag("hpsPFTauDiscriminationByTightIsolation")));
131  TightRawIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightRawIsoToken",edm::InputTag("hpsPFTauDiscriminationByRawCombinedIsolationDBSumPtCorr3Hits")));
132  LooseIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("LooseIsoToken",edm::InputTag("hpsPFTauDiscriminationByLooseIsolation")));
133  LooseAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("LooseAntiMuonToken",edm::InputTag("hpsPFTauDiscriminationByLooseMuonRejection")));
134  TightAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightAntiMuonToken",edm::InputTag("hpsPFTauDiscriminationByTightMuonRejection")));
135  VLooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("VLooseAntiElectronToken",edm::InputTag("hpsPFTauDiscriminationByMVA5VLooseElectronRejection")));
136  LooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("LooseAntiElectronToken",edm::InputTag("hpsPFTauDiscriminationByMVA5LooseElectronRejection")));
137  TightAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightAntiElectronToken",edm::InputTag("hpsPFTauDiscriminationByMVA5TightElectronRejection")));
138  }
139  else if(period_=="2016")
140  {
141  maxTau_ = iConfig.getParameter<unsigned int>("maxTau");
142  TauToken_ = consumes<reco::PFTauCollection>(iConfig.getUntrackedParameter("TauToken",edm::InputTag("hpsPFTauProducer")));
143  DMFindingToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("DMFindingToken",edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingNewDMs")));
144  DMFindingOldToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("DMFindingOldToken",edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingOldDMs")));
145  TightIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightIsoToken",edm::InputTag("hpsPFTauDiscriminationByTightCombinedIsolationDBSumPtCorr3Hits")));
146  TightRawIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightRawIsoToken",edm::InputTag("hpsPFTauDiscriminationByRawCombinedIsolationDBSumPtCorr3Hits")));
147  LooseIsoToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("LooseIsoToken",edm::InputTag("hpsPFTauDiscriminationByLooseCombinedIsolationDBSumPtCorr3Hits")));
148  LooseAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("LooseAntiMuonToken",edm::InputTag("hpsPFTauDiscriminationByLooseMuonRejection3")));
149  TightAntiMuonToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightAntiMuonToken",edm::InputTag("hpsPFTauDiscriminationByTightMuonRejection3")));
150  VLooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("VLooseAntiElectronToken",edm::InputTag("hpsPFTauDiscriminationByMVA6VLooseElectronRejection")));
151  LooseAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("LooseAntiElectronToken",edm::InputTag("hpsPFTauDiscriminationByMVA6LooseElectronRejection")));
152  TightAntiElectronToken_ = consumes<reco::PFTauDiscriminator>(iConfig.getUntrackedParameter("TightAntiElectronToken",edm::InputTag("hpsPFTauDiscriminationByMVA6TightElectronRejection")));
153  }
154 
155  /*
156  caloJetToken_ = consumes<reco::CaloJetCollection>(iConfig.getUntrackedParameter("caloJetToken",edm::InputTag("ak4CaloJets")));
157  // caloJetIdToken_ = consumes<edm::ValueMap<reco::JetID> >(iConfig.getUntrackedParameter("jetIdToken",edm::InputTag("ak4JetID")));
158  jetCorrectorToken_ = consumes<reco::JetCorrector>(iConfig.getUntrackedParameter<edm::InputTag>("jetCorrToken"));
159 
160  jetptThreshold_ = iConfig.getParameter<double> ("jetptThreshold");
161  maxTau_ = iConfig.getParameter<unsigned int>("maxTau");
162  */
163 
165  tau_data = tau->getData();
166 
167  /*
168  // set up output
169  */
170  tree_=fs_->make<TTree>("TauRecoTree", "TauRecoTree");
171  //tree_=fs_->make<TTree>("JetRecoTree", "JetRecoTree");
172  tree_->Branch("Tau", "L1Analysis::L1AnalysisRecoTauDataFormat", &tau_data, 32000, 3);
173 
174 }
175 
176 
178 {
179 
180  // do anything here that needs to be done at desctruction time
181  // (e.g. close files, deallocate resources etc.)
182 
183 }
184 
185 
186 //
187 // member functions
188 //
189 
190 // ------------ method called to for each event ------------
192 {
193 
194  tau->Reset();
196  iEvent.getByToken(TauToken_, recoTaus);
197 
199  iEvent.getByToken(DMFindingToken_, DMFindingTaus);
200 
201  edm::Handle<reco::PFTauDiscriminator> DMFindingOldTaus;
202  iEvent.getByToken(DMFindingOldToken_, DMFindingOldTaus);
203 
205  iEvent.getByToken(TightIsoToken_, TightIsoTaus);
206 
208  iEvent.getByToken(TightRawIsoToken_, TightRawIsoTaus);
209 
211  iEvent.getByToken(LooseIsoToken_, LooseIsoTaus);
212 
214  iEvent.getByToken(LooseAntiMuonToken_, LooseAntiMuon);
215 
217  iEvent.getByToken(TightAntiMuonToken_, TightAntiMuon);
218 
219  edm::Handle<reco::PFTauDiscriminator> VLooseAntiElectron;
220  iEvent.getByToken(VLooseAntiElectronToken_, VLooseAntiElectron);
221 
222  edm::Handle<reco::PFTauDiscriminator> LooseAntiElectron;
223  iEvent.getByToken(LooseAntiElectronToken_, LooseAntiElectron);
224 
225  edm::Handle<reco::PFTauDiscriminator> TightAntiElectron;
226  iEvent.getByToken(TightAntiElectronToken_, TightAntiElectron);
227 
228  //std::cout<<"size of recoTaus = "<<recoTaus->size()<<std::endl;
229 
230  if (recoTaus.isValid()) {
231  //std::cout<<"passing here"<<std::endl;
232  tau->SetTau(iEvent, iSetup, recoTaus, DMFindingOldTaus, DMFindingTaus, TightIsoTaus, TightRawIsoTaus, LooseIsoTaus, LooseAntiMuon, TightAntiMuon, VLooseAntiElectron, LooseAntiElectron, TightAntiElectron, maxTau_);
233  }
234  else {
235  if (!caloJetsMissing_) {edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;}
236  caloJetsMissing_ = true;
237  }
238 
239  /*
240  jet->Reset();
241 
242  // get jets & co...
243  edm::Handle<reco::CaloJetCollection> recoCaloJets;
244  edm::Handle<edm::ValueMap<reco::JetID> > jetsID;
245  edm::Handle<reco::JetCorrector> jetCorr;
246 
247  iEvent.getByToken(caloJetToken_, recoCaloJets);
248  //iEvent.getByLabel(jetIdTag_,jetsID);
249  //iEvent.getByToken(jetCorrectorToken_, jetCorr);
250 
251  if (recoCaloJets.isValid()) {
252  jet->SetCaloJet(iEvent, iSetup, recoCaloJets, maxTau_); //jetsID, maxTau_);
253  }
254  else {
255  if (!caloJetsMissing_) {edm::LogWarning("MissingProduct") << "CaloJets not found. Branch will not be filled" << std::endl;}
256  caloJetsMissing_ = true;
257  }
258  */
259 
260  tree_->Fill();
261 
262 }
263 
264 // ------------ method called once each job just before starting event loop ------------
265 void
267 {
268 }
269 
270 // ------------ method called once each job just after ending the event loop ------------
271 void
273 }
274 
275 //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_
T getParameter(std::string const &) const
L1Analysis::L1AnalysisRecoTauDataFormat * tau_data
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< reco::PFTauDiscriminator > TightRawIsoToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > VLooseAntiElectronToken_
L1AnalysisRecoTauDataFormat * getData()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseIsoToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::PFTauDiscriminator > TightIsoToken_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< reco::PFTauDiscriminator > DMFindingToken_
L1Analysis::L1AnalysisRecoTau * tau
edm::EDGetTokenT< reco::PFTauDiscriminator > DMFindingOldToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > TightAntiElectronToken_
int iEvent
Definition: GenABIO.cc:230
L1TauRecoTreeProducer(const edm::ParameterSet &)
edm::EDGetTokenT< reco::PFTauCollection > TauToken_
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseAntiElectronToken_
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool isValid() const
Definition: HandleBase.h:75
edm::EDGetTokenT< reco::PFTauDiscriminator > LooseAntiMuonToken_
edm::Service< TFileService > fs_
volatile std::atomic< bool > shutdown_flag false