ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Betchart/TopRefTuple/interface/Tuple_Gen.h
Revision: 1.3
Committed: Thu Nov 8 21:39:59 2012 UTC (12 years, 5 months ago) by bbetchar
Content type: text/plain
Branch: MAIN
Changes since 1.2: +17 -15 lines
Log Message:
floatify

File Contents

# User Rev Content
1 bbetchar 1.1 #ifndef TUPLE_GEN
2     #define TUPLE_GEN
3    
4     #include "FWCore/Framework/interface/EDProducer.h"
5     #include "FWCore/Framework/interface/Frameworkfwd.h"
6     #include "FWCore/Utilities/interface/InputTag.h"
7     #include "FWCore/Framework/interface/Event.h"
8     #include "FWCore/Framework/interface/ESHandle.h"
9     #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
10     #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
11 bbetchar 1.3 #include "fTypes.h"
12 bbetchar 1.1
13     #include <map>
14    
15     template< typename T >
16     class Tuple_Gen : public edm::EDProducer {
17     public:
18     explicit Tuple_Gen(const edm::ParameterSet&);
19     private:
20     void produce(edm::Event &, const edm::EventSetup & );
21     void produceGenJets(edm::Event &);
22     static int index(const reco::Candidate*, const std::vector<const T*>&);
23 bbetchar 1.3 typedef fTypes::dPolarLorentzV LorentzVector;
24 bbetchar 1.1 const edm::InputTag inputTag;
25     const std::vector<edm::InputTag> jetCollections;
26     const std::string Prefix,Suffix;
27     const double GenStatus1PtCut;
28     const double GenJetPtCut;
29     };
30    
31     template< typename T > Tuple_Gen<T>::
32 bbetchar 1.2 Tuple_Gen(const edm::ParameterSet& conf)
33     : inputTag(conf.getParameter<edm::InputTag>("InputTag")),
34     jetCollections(conf.getParameter<std::vector<edm::InputTag> >("JetCollections")),
35     Prefix(conf.getParameter<std::string>("Prefix")),
36     Suffix(conf.getParameter<std::string>("Suffix")),
37     GenStatus1PtCut(conf.getParameter<double>("GenStatus1PtCut")),
38     GenJetPtCut(conf.getParameter<double>("GenJetPtCut"))
39     {
40 bbetchar 1.1 produces <unsigned int> (Prefix + "signalProcessID" + Suffix);
41     produces <bool> (Prefix + "GenInfoHandleValid" + Suffix);
42     produces <bool > (Prefix + "HandleValid" + Suffix);
43 bbetchar 1.3 produces <float> (Prefix + "pthat" + Suffix);
44 bbetchar 1.1 produces <int> (Prefix + "id1" + Suffix);
45     produces <int> (Prefix + "id2" + Suffix);
46 bbetchar 1.3 produces <float> (Prefix + "x1" + Suffix);
47     produces <float> (Prefix + "x2" + Suffix);
48     produces <float> (Prefix + "pdf1" + Suffix);
49     produces <float> (Prefix + "pdf2" + Suffix);
50     produces <std::vector<float> > (Prefix + "BinningValues" + Suffix);
51 bbetchar 1.1 produces <float> (Prefix + "Q" + Suffix);
52     produces <std::vector<LorentzVector> > ( Prefix + "P4" + Suffix );
53     produces <std::vector<int> > (Prefix + "PdgId" + Suffix);
54     produces <std::vector<int> > (Prefix + "Status" + Suffix);
55     produces <std::vector<int> > (Prefix + "MotherIndex" + Suffix);
56     produces <std::vector<int> > (Prefix + "MotherPdgId" + Suffix);
57    
58    
59     for(unsigned i=0; i<jetCollections.size(); ++i)
60     produces<std::vector<LorentzVector> >(Prefix + jetCollections[i].label() +"P4" + Suffix);
61     }
62    
63     template< typename T > int Tuple_Gen<T>::
64     index(const reco::Candidate* item, const typename std::vector<const T*>& collection) {
65     typename std::vector<const T*>::const_iterator it(collection.begin()), begin(collection.begin()), end(collection.end());
66     for(; it!=end; it++) if ((*it)==item) return it-begin; //Compare addresses
67     return -1;
68     }
69    
70     template< typename T > void Tuple_Gen<T>::
71     produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
72     produceGenJets(iEvent);
73    
74     edm::Handle<std::vector<T> > collection; iEvent.getByLabel(inputTag,collection);
75     edm::Handle<GenEventInfoProduct> geninfo; iEvent.getByLabel("generator",geninfo);
76    
77     std::auto_ptr<unsigned int> signalProcessID(new unsigned int(geninfo->signalProcessID()));
78     std::auto_ptr<float> Q (new float(geninfo->pdf()->scalePDF));
79     std::auto_ptr<int> id1 (new int( geninfo->pdf()->id.first));
80     std::auto_ptr<int> id2 (new int( geninfo->pdf()->id.second));
81 bbetchar 1.3 std::auto_ptr<float> x1 (new float( geninfo->pdf()->x.first));
82     std::auto_ptr<float> x2 (new float( geninfo->pdf()->x.second));
83     std::auto_ptr<float> pdf1 (new float( geninfo->pdf()->xPDF.first));
84     std::auto_ptr<float> pdf2 (new float( geninfo->pdf()->xPDF.second));
85 bbetchar 1.1
86     std::auto_ptr<bool> handleValid ( new bool(collection.isValid()) );
87     std::auto_ptr<bool> genInfoValid ( new bool( geninfo.isValid() && !geninfo->binningValues().empty()));
88 bbetchar 1.3 std::auto_ptr<float> pthat (new float(*genInfoValid ? geninfo->binningValues()[0] : -1.));
89     std::auto_ptr<std::vector<float> > binningValues (*genInfoValid ? new std::vector<float>(geninfo->binningValues().begin(),
90     geninfo->binningValues().end()) : new std::vector<float>());
91 bbetchar 1.1 std::auto_ptr<std::vector<LorentzVector> > p4 ( new std::vector<LorentzVector>() ) ;
92     std::auto_ptr<std::vector<int> > status ( new std::vector<int>() ) ;
93     std::auto_ptr<std::vector<int> > pdgId ( new std::vector<int>() ) ;
94     std::auto_ptr<std::vector<int> > motherIndex ( new std::vector<int>() ) ;
95     std::auto_ptr<std::vector<int> > motherPdgId ( new std::vector<int>() ) ;
96    
97     std::vector<const T*> self;
98     std::vector<const reco::Candidate*> mom;
99    
100     if(collection.isValid()){
101     for(typename std::vector<T>::const_iterator it = collection->begin(); it != collection->end(); ++it) {
102     if ( it->status() == 3 // any status 3 genParticle
103     || abs(it->pdgId()) == 11 // any electron
104     || abs(it->pdgId()) == 13 // any muon
105     || abs(it->pdgId()) == 15 // any tau
106     || ( it->status() == 1 // status 1 particles
107     && it->pt() > GenStatus1PtCut) // above threshold
108     ) {
109 bbetchar 1.3 p4->push_back(LorentzVector(it->pt(),it->eta(),it->phi(),it->mass()));
110 bbetchar 1.1 status->push_back(it->status());
111     pdgId->push_back(it->pdgId());
112     motherPdgId->push_back( it->numberOfMothers() ? it->mother()->pdgId() : 0 );
113     self.push_back(&*it);
114     mom.push_back( it->numberOfMothers() ? it->mother(): 0);
115     }
116     }
117     } //collection
118    
119    
120     for(typename std::vector<const reco::Candidate*>::const_iterator it = mom.begin(); it!=mom.end(); ++it)
121     motherIndex->push_back( index(*it,self) );
122    
123     iEvent.put( handleValid, Prefix + "HandleValid" + Suffix);
124     iEvent.put( genInfoValid, Prefix + "GenInfoHandleValid" + Suffix);
125     iEvent.put( pthat, Prefix + "pthat" + Suffix);
126     iEvent.put( binningValues,Prefix + "BinningValues" + Suffix);
127     iEvent.put( p4, Prefix + "P4" + Suffix );
128     iEvent.put( status, Prefix + "Status" + Suffix );
129     iEvent.put( pdgId, Prefix + "PdgId" + Suffix );
130     iEvent.put( motherIndex, Prefix + "MotherIndex" + Suffix );
131     iEvent.put( motherPdgId, Prefix + "MotherPdgId" + Suffix );
132     iEvent.put( signalProcessID, Prefix + "signalProcessID" + Suffix );
133     iEvent.put( Q, Prefix + "Q" + Suffix );
134     iEvent.put( x1, Prefix + "x1" + Suffix );
135     iEvent.put( x2, Prefix + "x2" + Suffix );
136     iEvent.put( pdf1, Prefix + "pdf1" + Suffix );
137     iEvent.put( pdf2, Prefix + "pdf2" + Suffix );
138     iEvent.put( id1, Prefix + "id1" + Suffix );
139     iEvent.put( id2, Prefix + "id2" + Suffix );
140     }
141    
142     template< typename T > void Tuple_Gen<T>::
143     produceGenJets(edm::Event& iEvent) {
144     for(unsigned i=0; i<jetCollections.size(); ++i) {
145     std::auto_ptr<std::vector<LorentzVector> > p4(new std::vector<LorentzVector>());
146     edm::Handle<edm::View<reco::GenJet> > genjets;
147     iEvent.getByLabel(jetCollections[i], genjets);
148     if(genjets.isValid())
149     for(edm::View<reco::GenJet>::const_iterator it(genjets->begin()), end(genjets->end()); it!=end; ++it) {
150 bbetchar 1.3 if (it->pt() >= GenJetPtCut) p4->push_back(LorentzVector(it->pt(),it->eta(),it->phi(),it->mass()));
151 bbetchar 1.1 }
152     iEvent.put(p4, Prefix + jetCollections[i].label() + "P4" + Suffix);
153     }
154     }
155    
156     #endif