1 |
vuko |
1.1 |
// -*- C++ -*-
|
2 |
|
|
//
|
3 |
|
|
// Package: WZAnalyzer
|
4 |
|
|
// Class: WZAnalyzer
|
5 |
|
|
//
|
6 |
|
|
/**\class WZAnalyzer WZAnalyzer.cc Vuko/WZAnalysis/src/WZAnalyzer.cc
|
7 |
|
|
|
8 |
|
|
Description: <one line class summary>
|
9 |
|
|
|
10 |
|
|
Implementation:
|
11 |
|
|
<Notes on implementation>
|
12 |
|
|
*/
|
13 |
|
|
//
|
14 |
|
|
// Original Author: Vuko Brigljevic
|
15 |
|
|
// Created: Fri Nov 9 11:07:27 CET 2007
|
16 |
|
|
// $Id$
|
17 |
|
|
//
|
18 |
|
|
//
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
// system include files
|
23 |
|
|
#include <memory>
|
24 |
|
|
|
25 |
|
|
// user include files
|
26 |
|
|
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
27 |
|
|
#include "FWCore/Framework/interface/EDAnalyzer.h"
|
28 |
|
|
|
29 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
30 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
31 |
|
|
|
32 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
33 |
|
|
|
34 |
|
|
#include "Vuko/WZAnalysis/interface/MuonSimAnalyzer.h"
|
35 |
|
|
#include "DataFormats/Candidate/interface/OverlapChecker.h"
|
36 |
|
|
|
37 |
|
|
#include "Vuko/WZAnalysis/interface/ElectronProperties.h"
|
38 |
|
|
#include "Vuko/WZAnalysis/interface/MuonProperties.h"
|
39 |
|
|
|
40 |
|
|
#include "DataFormats/Common/interface/TriggerResults.h"
|
41 |
|
|
|
42 |
|
|
//--- muon AOD:
|
43 |
|
|
#include "DataFormats/JetReco/interface/CaloJetCollection.h"
|
44 |
|
|
#include "DataFormats/EgammaCandidates/interface/Electron.h"
|
45 |
|
|
#include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
|
46 |
|
|
#include "DataFormats/MuonReco/interface/MuonFwd.h"
|
47 |
|
|
#include "DataFormats/MuonReco/interface/Muon.h"
|
48 |
|
|
#include "DataFormats/MuonReco/interface/MuIsoDeposit.h"
|
49 |
|
|
#include "DataFormats/EgammaReco/interface/BasicCluster.h"
|
50 |
|
|
#include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
|
51 |
|
|
#include "DataFormats/EgammaCandidates/interface/PixelMatchGsfElectron.h"
|
52 |
|
|
|
53 |
|
|
#include "DataFormats/METReco/interface/CaloMET.h"
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
//generator level + CLHEP
|
57 |
|
|
#include "CLHEP/HepMC/GenEvent.h"
|
58 |
|
|
#include "CLHEP/HepMC/GenVertex.h"
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
// --- Simulation
|
62 |
|
|
#include "SimDataFormats/Track/interface/SimTrack.h"
|
63 |
|
|
#include "SimDataFormats/Track/interface/SimTrackContainer.h"
|
64 |
|
|
#include "SimDataFormats/Vertex/interface/SimVertex.h"
|
65 |
|
|
#include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
|
66 |
|
|
#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
|
67 |
|
|
|
68 |
|
|
#include "TFile.h"
|
69 |
|
|
#include "TH1F.h"
|
70 |
|
|
#include "TH2F.h"
|
71 |
|
|
#include "TTree.h"
|
72 |
|
|
|
73 |
|
|
#include <map>
|
74 |
|
|
|
75 |
|
|
//
|
76 |
|
|
// constants, enums and typedefs
|
77 |
|
|
//
|
78 |
|
|
|
79 |
|
|
//
|
80 |
|
|
// static data member definitions
|
81 |
|
|
//
|
82 |
|
|
|
83 |
|
|
//
|
84 |
|
|
// constructors and destructor
|
85 |
|
|
//
|
86 |
|
|
MuonSimAnalyzer::MuonSimAnalyzer(const edm::ParameterSet& iConfig)
|
87 |
|
|
|
88 |
|
|
{
|
89 |
|
|
|
90 |
|
|
//now do what ever initialization is needed
|
91 |
|
|
|
92 |
|
|
fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
|
93 |
|
|
theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticles");
|
94 |
|
|
|
95 |
|
|
// theMCTruthCollection = iConfig.getParameter<edm::InputTag>("genParticleCollection");
|
96 |
|
|
|
97 |
|
|
simG4_ = iConfig.getParameter<edm::InputTag>( "simG4" );
|
98 |
|
|
|
99 |
|
|
hepMC_ = iConfig.getParameter<edm::InputTag>("HepMC");
|
100 |
|
|
|
101 |
|
|
theLooseMuonCollection = iConfig.getParameter<edm::InputTag>("LooseMuons");
|
102 |
|
|
theGoodMuonCollection = iConfig.getParameter<edm::InputTag>("GoodMuons");
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
MuonSimAnalyzer::~MuonSimAnalyzer()
|
110 |
|
|
{
|
111 |
|
|
|
112 |
|
|
// do anything here that needs to be done at desctruction time
|
113 |
|
|
// (e.g. close files, deallocate resources etc.)
|
114 |
|
|
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
//
|
119 |
|
|
// member functions
|
120 |
|
|
//
|
121 |
|
|
|
122 |
|
|
// ------------ method called to for each event ------------
|
123 |
|
|
void
|
124 |
|
|
MuonSimAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
|
125 |
|
|
{
|
126 |
|
|
|
127 |
|
|
cout <<" ulazi u analyze metodu" << endl;
|
128 |
|
|
using namespace edm;
|
129 |
|
|
using namespace reco;
|
130 |
|
|
using namespace std;
|
131 |
|
|
|
132 |
|
|
///////////////////////////////////////
|
133 |
|
|
//
|
134 |
|
|
/// EVENT INITIALISATION
|
135 |
|
|
///
|
136 |
|
|
|
137 |
|
|
VtxR = -10.;
|
138 |
|
|
muPt = -10.;
|
139 |
|
|
|
140 |
|
|
/////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
///
|
142 |
|
|
/// GEANT TRACK ANALYSIS
|
143 |
|
|
///
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
// std::vector<edm::Handle<edm::SimTrackContainer> > trackCollections;
|
147 |
|
|
// std::vector<edm::Handle<edm::SimVertexContainer> > vertexCollections;
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
Handle<SimVertexContainer> simVtxs;
|
151 |
|
|
iEvent.getByLabel( simG4_, simVtxs);
|
152 |
|
|
|
153 |
|
|
Handle<SimTrackContainer> simTrks;
|
154 |
|
|
iEvent.getByLabel( simG4_, simTrks);
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
Handle<HepMCProduct> evt;
|
158 |
|
|
iEvent.getByLabel(hepMC_, evt);
|
159 |
|
|
|
160 |
|
|
//HepMC::GenEvent *myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
|
161 |
|
|
const HepMC::GenEvent *evtMC = evt->GetEvent();
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
cout << "# Sim tracks : " << simTrks->size() << endl;
|
168 |
|
|
|
169 |
|
|
int i=1;
|
170 |
|
|
for(SimTrackContainer::const_iterator t=simTrks->begin();
|
171 |
|
|
t!=simTrks->end(); ++t){
|
172 |
|
|
//HepMC::GenParticle* gp=evtMC->GetEvent()->particle( (*t).genpartIndex() );
|
173 |
|
|
std::cout << i++ << ")"
|
174 |
|
|
<< (*t)
|
175 |
|
|
<< " index="
|
176 |
|
|
<< (*t).genpartIndex();
|
177 |
|
|
//if (gp) {
|
178 |
|
|
// HepMC::GenVertex *gv=gp->production_vertex();
|
179 |
|
|
// std::cout << " genvertex =" << (*gv);
|
180 |
|
|
//}
|
181 |
|
|
std::cout << std::endl;
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
// Is it a muon?
|
185 |
|
|
int pid = t->type();
|
186 |
|
|
int nback=0;
|
187 |
|
|
if (abs(pid) == 13 || abs(pid) == 211) {
|
188 |
|
|
|
189 |
|
|
nback++;
|
190 |
|
|
if (abs(pid) == 13 ) {
|
191 |
|
|
cout << "Sim Muon \n";
|
192 |
|
|
} else if (abs(pid) == 211 ) {
|
193 |
|
|
cout << "Sim Pion \n";
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
muPt = t->momentum().perp();
|
197 |
|
|
|
198 |
|
|
const SimTrack * mut = &(*t);
|
199 |
|
|
while (mut->vertIndex()>1) {
|
200 |
|
|
nback++;
|
201 |
|
|
int ivtx = mut->vertIndex();
|
202 |
|
|
float rad = (*simVtxs)[ivtx].position().perp();
|
203 |
|
|
float VtxZ = (*simVtxs)[ivtx].position().z();
|
204 |
|
|
int parent = (*simVtxs)[ivtx].parentIndex();
|
205 |
|
|
cout << "\t Vertex: R = " << rad
|
206 |
|
|
<< "\t z = " << VtxZ
|
207 |
|
|
<< "\t parent index = " << parent
|
208 |
|
|
<< endl;
|
209 |
|
|
if ( parent > 0 ) {
|
210 |
|
|
mut = & (*simTrks)[parent];
|
211 |
|
|
} else {
|
212 |
|
|
break;
|
213 |
|
|
}
|
214 |
|
|
cout << "\t parent " << (*mut) << endl;
|
215 |
|
|
if (nback>100) {
|
216 |
|
|
cout << "\t neverending loop... exiting \n";
|
217 |
|
|
break;
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
// Is it matched to gen muon?
|
223 |
|
|
if (mut->noGenpart()) {
|
224 |
|
|
cout << "\t not matched to gen \n";
|
225 |
|
|
int vertex = t->vertIndex();
|
226 |
|
|
const HepLorentzVector & v =(*simVtxs)[t->vertIndex()].position();
|
227 |
|
|
|
228 |
|
|
// Does it decay / get stopped?
|
229 |
|
|
|
230 |
|
|
} else {
|
231 |
|
|
|
232 |
|
|
HepMC::GenParticle* gp=evtMC->particle( (*mut).genpartIndex() );
|
233 |
|
|
|
234 |
|
|
cout << "Associated Gen particle : ID = " << gp->pdg_id()
|
235 |
|
|
<< "\t status " << gp->status()
|
236 |
|
|
<< "\t pt =" << gp->momentum().perp()
|
237 |
|
|
<< "\t eta =" << gp->momentum().eta()
|
238 |
|
|
<< "\t phi =" << gp->momentum().phi()
|
239 |
|
|
<< endl;
|
240 |
|
|
|
241 |
|
|
}
|
242 |
|
|
muonSimTree->Fill();
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
}
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
// ------------ method called once each job just before starting event loop ------------
|
251 |
|
|
void
|
252 |
|
|
MuonSimAnalyzer::beginJob(const edm::EventSetup&)
|
253 |
|
|
{
|
254 |
|
|
|
255 |
|
|
using namespace wzana;
|
256 |
|
|
|
257 |
|
|
// theFile = new TFile( "wz.root", "RECREATE" ) ;
|
258 |
|
|
theFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
muonSimTree = new TTree("MuonSimTree","Muon G4 informations");
|
262 |
|
|
|
263 |
|
|
// MET branch
|
264 |
|
|
muonSimTree->Branch("Pt", &muPt, "Pt/F");
|
265 |
|
|
muonSimTree->Branch("vtxR", &VtxR, "vtxR/F");
|
266 |
|
|
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
// ------------ method called once each job just after ending the event loop ------------
|
270 |
|
|
void
|
271 |
|
|
MuonSimAnalyzer::endJob() {
|
272 |
|
|
|
273 |
|
|
theFile->Write();
|
274 |
|
|
theFile->Close();
|
275 |
|
|
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
//define this as a plug-in
|
280 |
|
|
// DEFINE_FWK_MODULE(WZAnalyzer);
|
281 |
|
|
|