ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/BaseHiGenJetProducer.cc
Revision: 1.9
Committed: Wed Aug 26 15:19:10 2009 UTC (15 years, 8 months ago) by yilmaz
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +1 -1 lines
State: FILE REMOVED
Log Message:
Old genjet module not needed anymore

File Contents

# Content
1 // File: BaseHiGenJetProducer.cc
2 // Author: Y.Yilmaz, 2008
3 // $Id: BaseHiGenJetProducer.cc,v 1.8 2009/08/06 17:35:53 yilmaz Exp $
4 //--------------------------------------------
5 #include <memory>
6
7 #include "DataFormats/Common/interface/EDProduct.h"
8 #include "FWCore/Framework/interface/Event.h"
9 #include "FWCore/Framework/interface/EventSetup.h"
10 #include "DataFormats/Common/interface/View.h"
11 #include "DataFormats/Common/interface/Handle.h"
12 #include "DataFormats/Provenance/interface/ProductID.h"
13 #include "FWCore/MessageLogger/interface/MessageLogger.h"
14
15 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
16 #include "DataFormats/JetReco/interface/GenJetCollection.h"
17 #include "DataFormats/JetReco/interface/PFJetCollection.h"
18 #include "DataFormats/JetReco/interface/BasicJetCollection.h"
19 #include "RecoJets/JetAlgorithms/interface/JetRecoTypes.h"
20 #include "RecoJets/JetAlgorithms/interface/JetAlgoHelper.h"
21 #include "RecoJets/JetAlgorithms/interface/JetMaker.h"
22 #include "RecoJets/JetAlgorithms/interface/ProtoJet.h"
23 #include "DataFormats/Candidate/interface/CandidateFwd.h"
24 #include "DataFormats/Candidate/interface/LeafCandidate.h"
25 #include "FWCore/Framework/interface/ESHandle.h"
26 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
27 #include "Geometry/Records/interface/CaloGeometryRecord.h"
28 #include "SimDataFormats/HiGenData/interface/SubEventMap.h"
29 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
30 #include "FWCore/Framework/interface/ESHandle.h"
31 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
32
33 #include "CmsHi/JetAnalysis/interface/BaseHiGenJetProducer.h"
34
35 using namespace std;
36 using namespace reco;
37 using namespace JetReco;
38
39 namespace {
40
41 bool checkHydro(GenParticleRef& p){
42
43 const Candidate* m1 = p->mother();
44 while(m1){
45 int pdg = abs(m1->pdgId());
46 int st = m1->status();
47 LogDebug("SubEventMothers")<<"Pdg ID : "<<pdg<<endl;
48
49 if(st == 3 || pdg < 9 || pdg == 21){
50 LogDebug("SubEventMothers")<<"Sub-Collision Found! Pdg ID : "<<pdg<<endl;
51 return false;
52 }
53 const Candidate* m = m1->mother();
54 m1 = m;
55
56 if(!m1) LogDebug("SubEventMothers")<<"No Mother, particle is : "<<pdg<<" with status "<<st<<endl;
57
58 }
59 return true;
60 }
61
62 const bool debug = false;
63
64 bool makeCaloJet (const string& fTag) {
65 return fTag == "CaloJet";
66 }
67 bool makePFJet (const string& fTag) {
68 return fTag == "PFJet";
69 }
70 bool makeGenJet (const string& fTag) {
71 return fTag == "GenJet";
72 }
73 bool makeBasicJet (const string& fTag) {
74 return fTag == "BasicJet";
75 }
76
77 bool makeGenericJet (const string& fTag) {
78 return !makeCaloJet (fTag) && !makePFJet (fTag) && !makeGenJet (fTag) && !makeBasicJet (fTag);
79 }
80
81 template <class T>
82 void dumpJets (const T& fJets) {
83 for (unsigned i = 0; i < fJets.size(); ++i) {
84 std::cout<< "Jet # " << i << std::endl << fJets[i].print();
85 }
86 }
87
88 void copyVariables (const ProtoJet& fProtojet, reco::Jet* fJet) {
89 fJet->setJetArea (fProtojet.jetArea ());
90 fJet->setPileup (fProtojet.pileup ());
91 fJet->setNPasses (fProtojet.nPasses ());
92 }
93
94 void copyConstituents (const JetReco::InputCollection& fConstituents, const edm::View <Candidate>& fInput, reco::Jet* fJet) {
95 // put constituents
96 for (unsigned iConstituent = 0; iConstituent < fConstituents.size (); ++iConstituent) {
97 fJet->addDaughter (fInput.ptrAt (fConstituents[iConstituent].index ()));
98 }
99 }
100
101 }
102
103 namespace cms
104 {
105 // Constructor takes input parameters now: to be replaced with parameter set.
106 BaseHiGenJetProducer::BaseHiGenJetProducer(const edm::ParameterSet& conf)
107 : mSrc(conf.getParameter<edm::InputTag>( "src")),
108 mapSrc(conf.getParameter<edm::InputTag>( "srcMap")),
109 mJetType (conf.getParameter<string>( "jetType")),
110 mVerbose (conf.getUntrackedParameter<bool>("verbose", false)),
111 mEtInputCut (conf.getParameter<double>("inputEtMin")),
112 mEInputCut (conf.getParameter<double>("inputEMin")),
113 ignoreHydro_ (conf.getUntrackedParameter<bool>("ignoreHydro", true)),
114 nMax_(conf.getUntrackedParameter<double>("maxParticles", 2000))
115 {
116 std::string alias = conf.getUntrackedParameter<string>( "alias", conf.getParameter<std::string>("@module_label"));
117 if (makeCaloJet (mJetType)) {
118 produces<CaloJetCollection>().setBranchAlias (alias);
119 }
120 else if (makePFJet (mJetType)) produces<PFJetCollection>().setBranchAlias (alias);
121 else if (makeGenJet (mJetType)) produces<GenJetCollection>().setBranchAlias (alias);
122 else if (makeBasicJet (mJetType)) produces<BasicJetCollection>().setBranchAlias (alias);
123 // else if (makeGenericJet (mJetType)) produces<GenericJetCollection>().setBranchAlias (alias);
124 }
125
126 // Virtual destructor needed.
127 BaseHiGenJetProducer::~BaseHiGenJetProducer() { }
128
129 void BaseHiGenJetProducer::beginJob(const edm::EventSetup& fSetup)
130 {
131 fSetup.getData(mPdt);
132 }
133
134 // Functions that gets called by framework every event
135 void BaseHiGenJetProducer::produce(edm::Event& e, const edm::EventSetup& fSetup)
136 {
137 using namespace reco;
138
139 edm::Handle< edm::View<Candidate> > inputHandle;
140 e.getByLabel(mSrc,inputHandle);
141
142 edm::Handle<edm::SubEventMap> subs;
143 e.getByLabel(mapSrc,subs);
144
145 vector <ProtoJet> output;
146 vector<JetReco::InputCollection> inputs;
147
148 vector<int> nsubparticle;
149 vector<int> hydroTag;
150
151 for (unsigned i = 0; i < inputHandle->size(); ++i) {
152
153 GenParticleRef pref = inputHandle->refAt(i).castTo<GenParticleRef>();
154 int subevent = (*subs)[pref];
155 LogDebug("SubEventJets")<<"inputs size "<<inputs.size()<<" subevent "<<subevent;
156
157 if(subevent >= inputs.size()){
158 // hydroTag.push_back(-1);
159 hydroTag.resize(subevent+1);
160 hydroTag[subevent] = -1;
161 inputs.resize(subevent+1);
162 nsubparticle.resize(subevent+1);
163 }
164
165 if(hydroTag[subevent] != 0) hydroTag[subevent] = (int)checkHydro(pref);
166
167 if(nsubparticle[subevent]> nMax_ && hydroTag[subevent] != 1){
168 LogDebug("JetsInHydro")<<"More particles than maximum particles cut, although not previously identified as sub-event, Sub-Event : "<<subevent;
169
170 hydroTag[subevent] = 1;
171 }
172
173
174 if(hydroTag[subevent] != 1){
175 (inputs[subevent]).push_back(JetReco::InputItem(&((*inputHandle)[i]),i));
176 nsubparticle[subevent]++;
177 }
178 }
179
180 int nsub = inputs.size();
181
182 bool hydroDone = false;
183 for(int isub = 0; isub < nsub; ++isub){
184 cout<<"Processing Sub-Event : "<<isub<<endl;
185 JetReco::InputCollection & input = inputs[isub];
186 if(hydroTag[isub] == 1){
187 if(hydroDone){
188 throw cms::Exception("HeavyIonHydroEvent")<<"More than one Hydro sub-event found for the input, please check your MC! Second hydro id : "<<isub<<endl;
189 }
190 cout<<"Sub-Event number "<<isub<<" with more than "<<input.size()<<" particles, skipped as background event. Number of total sub-events: "<<nsub<<endl;
191 hydroDone = true;
192 }else{
193
194 if (mVerbose) {
195 std::cout << "BaseJetProducer::produce-> INPUT COLLECTION selected from" << mSrc
196 << " with ET > " << mEtInputCut << " and/or E > " << mEInputCut << std::endl;
197 for (unsigned index = 0; index < input.size(); ++index) {
198 std::cout << " Input " << index << ", px/py/pz/pt/e: "
199 << input[index]->px() << '/' << input[index]->py() << '/' << input[index]->pz() << '/'
200 << input[index]->pt() << '/' << input[index]->energy()
201 << std::endl;
202 }
203 }
204
205 if (input.empty ()) {
206 edm::LogInfo ("Empty Event") << "empty input for jet algorithm: bypassing..." << std::endl;
207 }
208 else {
209 cout<<"Algorithm running on sub-event..."<<endl;
210 this->runAlgorithm (input, &output);
211 }
212 }
213 }
214
215 // produce output collection
216 if (mVerbose) {
217 std::cout << "OUTPUT JET COLLECTION:" << std::endl;
218 }
219 reco::Jet::Point vertex (0,0,0); // do not have true vertex yet, use default
220
221 // make sure protojets are sorted
222 sortByPt (&output);
223 if (makeGenJet (mJetType)) {
224
225 cout<<"Saving GenJets..."<<endl;
226
227 auto_ptr<GenJetCollection> jets (new GenJetCollection);
228 jets->reserve(output.size());
229 for (unsigned iJet = 0; iJet < output.size (); ++iJet) {
230 ProtoJet* protojet = &(output [iJet]);
231 const JetReco::InputCollection& constituents = protojet->getTowerList();
232 GenJet::Specific specific;
233 JetMaker::makeSpecific (constituents, &specific);
234 jets->push_back (GenJet (protojet->p4(), vertex, specific));
235 Jet* newJet = &(jets->back());
236 copyConstituents (constituents, *inputHandle, newJet);
237 copyVariables (*protojet, newJet);
238 }
239
240 if (mVerbose) dumpJets (*jets);
241 e.put(jets);
242 }
243 }
244 }
245