28 #include <CLHEP/Vector/LorentzVector.h>
38 outputFile =
new TFile(theGenInfoRootFileName.c_str(),
"RECREATE");
54 std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> muFromRes;
57 int mothersFound[] = {0, 0, 0, 0, 0, 0};
59 for( reco::GenParticleCollection::const_iterator mcIter=genParticles->begin(); mcIter!=genParticles->end(); ++mcIter ) {
60 int status = mcIter->status();
64 ( pdgId==23 || pdgId==443 || pdgId==100443 ||
65 pdgId==553 || pdgId==100553 || pdgId==200553 ) ) {
66 genRes = mcIter->p4();
68 if( pdgId == 23 )
mapHisto[
"hGenResZ"]->Fill(genRes);
69 else if( pdgId == 443 || pdgId == 100443 )
mapHisto[
"hGenResJPsi"]->Fill(genRes);
70 else if( pdgId == 553 || pdgId == 100553 || pdgId == 200553 )
mapHisto[
"hGenResUpsilon1S"]->Fill(genRes);
73 if( status==1 && pdgId==13 && !PATmuons) {
74 int momPdgId =
std::abs(mcIter->mother()->pdgId());
75 if( momPdgId==23 || momPdgId==443 || momPdgId==100443 ||
76 momPdgId==553 || momPdgId==100553 || momPdgId==200553 ) {
77 if( momPdgId == 23 ) mothersFound[0] = 1;
78 if( momPdgId == 443 || momPdgId == 100443 ) mothersFound[5] = 1;
79 if( momPdgId == 553 || momPdgId == 100553 || momPdgId == 200553 ) mothersFound[3] = 1;
80 mapHisto[
"hGenMu"]->Fill(mcIter->p4());
81 std::cout<<
"genmu "<<mcIter->p4()<<std::endl;
82 if(mcIter->charge()>0){
83 muFromRes.first = mcIter->p4();
86 else muFromRes.second = mcIter->p4();
89 if( status==1 && pdgId==13 && PATmuons) {
91 mapHisto[
"hGenMu"]->Fill(mcIter->p4());
92 std::cout<<
"genmu "<<mcIter->p4()<<std::endl;
93 if(mcIter->charge()>0){
94 muFromRes.first = mcIter->p4();
97 else muFromRes.second = mcIter->p4();
103 if( mothersFound[0] == 1 ) {
104 mapHisto[
"hGenMuMuZ"]->Fill(muFromRes.first+muFromRes.second);
105 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.first, genRes, 1 );
106 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.second,genRes, -1 );
108 if( mothersFound[3] == 1 ) {
109 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(muFromRes.first+muFromRes.second);
110 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.first, genRes, 1 );
111 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.second,genRes, -1 );
113 if( mothersFound[5] == 1 ) {
114 mapHisto[
"hGenMuMuJPsi"]->Fill(muFromRes.first+muFromRes.second);
115 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.first, genRes, 1 );
116 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.second,genRes, -1 );
119 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
127 const HepMC::GenEvent* Evt = evtMC->
GetEvent();
128 std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> muFromRes;
131 int mothersFound[] = {0, 0, 0, 0, 0, 0};
135 for (HepMC::GenEvent::particle_const_iterator
part=Evt->particles_begin();
136 part!=Evt->particles_end();
part++) {
137 if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
138 bool fromRes =
false;
139 for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
140 mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
141 unsigned int motherPdgId = (*mother)->pdg_id();
142 if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes =
true;
145 if((*part)->pdg_id()==13){
146 muFromRes.first = (
lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
147 (*part)->momentum().pz(),(*part)->momentum().e()));
149 else if((*part)->pdg_id()==-13){
150 muFromRes.second = (
lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
151 (*part)->momentum().pz(),(*part)->momentum().e()));
157 mapHisto[
"hGenResZ"]->Fill(muFromRes.first+muFromRes.second);
160 for (HepMC::GenEvent::particle_const_iterator
part=Evt->particles_begin();
161 part!=Evt->particles_end();
part++) {
162 int status = (*part)->status();
170 if (pdgId==13 && status==1) {
172 ( pdgId==23 || pdgId==443 || pdgId==100443 ||
173 pdgId==553 || pdgId==100553 || pdgId==200553 ) ) {
175 (*part)->momentum().pz(),(*part)->momentum().e());
177 if( pdgId == 23 )
mapHisto[
"hGenResZ"]->Fill(genRes);
178 if( pdgId == 443 )
mapHisto[
"hGenResJPsi"]->Fill(genRes);
181 mapHisto[
"hGenResUpsilon1S"]->Fill(genRes);
186 if (pdgId==13 && status==1) {
188 for (HepMC::GenVertex::particle_iterator mother =
189 (*part)->production_vertex()->particles_begin(HepMC::ancestors);
190 mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
191 int motherPdgId = (*mother)->pdg_id();
192 if (motherPdgId==23 || motherPdgId==443 || motherPdgId==100443 ||
193 motherPdgId==553 || motherPdgId==100553 || motherPdgId==200553) {
195 if( motherPdgId == 23 ) mothersFound[0] = 1;
196 if( motherPdgId == 443 ) mothersFound[3] = 1;
197 if( motherPdgId == 553 ) mothersFound[5] = 1;
203 (*part)->momentum().pz(),(*part)->momentum().e()));
205 (*part)->momentum().pz(),(*part)->momentum().e()));
206 if((*part)->pdg_id()==-13)
208 (*part)->momentum().pz(),(*part)->momentum().e()));
211 (*part)->momentum().pz(),(*part)->momentum().e()));
217 if( mothersFound[0] == 1 ) {
218 mapHisto[
"hGenMuMuZ"]->Fill(muFromRes.first+muFromRes.second);
219 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.first, genRes, 1 );
220 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.second,genRes, -1 );
222 if( mothersFound[3] == 1 ) {
223 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(muFromRes.first+muFromRes.second);
224 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.first, genRes, 1 );
225 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.second,genRes, -1 );
227 if( mothersFound[5] == 1 ) {
228 mapHisto[
"hGenMuMuJPsi"]->Fill(muFromRes.first+muFromRes.second);
229 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.first, genRes, 1 );
230 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.second,genRes, -1 );
232 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
239 std::vector<SimTrack> simMuons;
242 for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
244 if (fabs((*simTrack).type())==13) {
245 simMuons.push_back(*simTrack);
246 mapHisto[
"hSimMu"]->Fill((*simTrack).momentum());
249 mapHisto[
"hSimMu"]->Fill(simMuons.size());
252 if( simMuons.size() >= 2 ) {
253 for( std::vector<SimTrack>::const_iterator imu=simMuons.begin(); imu != simMuons.end(); ++imu ) {
254 for( std::vector<SimTrack>::const_iterator imu2=imu+1; imu2!=simMuons.end(); ++imu2 ) {
255 if (imu==imu2)
continue;
258 if (((*imu).charge()*(*imu2).charge())<0) {
268 mapHisto[
"hSimBestRes"]->Fill(bestSimZ);
269 if (fabs(simMuFromBestRes.first.momentum().eta())<2.5 && fabs(simMuFromBestRes.second.momentum().eta())<2.5 &&
270 simMuFromBestRes.first.momentum().pt()>2.5 && simMuFromBestRes.second.momentum().pt()>2.5) {
271 mapHisto[
"hSimBestResVSMu"]->Fill (simMuFromBestRes.first.momentum(), bestSimZ, int(simMuFromBestRes.first.charge()));
272 mapHisto[
"hSimBestResVSMu"]->Fill (simMuFromBestRes.second.momentum(),bestSimZ, int(simMuFromBestRes.second.charge()));
281 std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> simMuFromRes =
285 mapHisto[
"hSimRightRes"]->Fill(rightSimRes);
311 for(std::vector<MuScleFitMuon>::const_iterator mu1 = muons.begin(); mu1!=muons.end(); mu1++){
312 mapHisto[
"hRecMu"]->Fill(mu1->p4());
313 mapHisto[
"hRecMuVSEta"]->Fill(mu1->p4());
314 for(std::vector<MuScleFitMuon>::const_iterator mu2 = muons.begin(); mu2!=muons.end(); mu2++){
315 if (mu1->charge()<0 || mu2->charge()>0)
321 mapHisto[
"hRecMu"]->Fill(muons.size());
328 std::vector<std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> >::const_iterator muonPair = savedPairs.begin();
329 for( ; muonPair != savedPairs.end(); ++muonPair ) {
330 mapHisto[
"hRecMu"]->Fill(muonPair->first);
331 mapHisto[
"hRecMuVSEta"]->Fill(muonPair->first);
332 mapHisto[
"hRecMu"]->Fill(muonPair->second);
333 mapHisto[
"hRecMuVSEta"]->Fill(muonPair->second);
336 mapHisto[
"hRecMu"]->Fill(savedPairs.size());
347 std::vector<std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> >::const_iterator genPair = genPairs.begin();
348 for( ; genPair != genPairs.end(); ++genPair ) {
351 mapHisto[
"hGenMu"]->Fill(genPair->first);
352 mapHisto[
"hGenMuVSEta"]->Fill(genPair->first);
353 mapHisto[
"hGenMuMuZ"]->Fill(genRes);
354 mapHisto[
"hGenResVSMuZ"]->Fill( genPair->first, genRes, 1 );
355 mapHisto[
"hGenResVSMuZ"]->Fill( genPair->second, genRes, -1 );
356 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(genRes);
357 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( genPair->first, genRes, 1 );
358 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( genPair->second, genRes, -1 );
359 mapHisto[
"hGenMuMuJPsi"]->Fill(genRes);
360 mapHisto[
"hGenResVSMuJPsi"]->Fill( genPair->first, genRes, 1 );
361 mapHisto[
"hGenResVSMuJPsi"]->Fill( genPair->second, genRes, -1 );
362 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
411 for (std::map<std::string, Histograms*>::const_iterator
histo=
mapHisto.begin();
413 (*histo).second->Write();
const double Z[kNumberCalorimeter]
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
std::map< std::string, Histograms * > mapHisto
static std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
void fillGenSim(edm::Handle< edm::HepMCProduct > evtMC, edm::Handle< edm::SimTrackContainer > simTracks)
void fillTreeRec(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &savedPairs)
Used when running on the root tree containing preselected muon pairs.
virtual ~MuScleFitPlotter()
MuScleFitPlotter(std::string)
reco::Particle::LorentzVector lorentzVector
static std::pair< SimTrack, SimTrack > findBestSimuRes(const std::vector< SimTrack > &simMuons)
void fillRec(std::vector< MuScleFitMuon > &muons)
Used when running on the root tree containing preselected muon pairs.
void fillSim(edm::Handle< edm::SimTrackContainer > simTracks)
const HepMC::GenEvent * GetEvent() const
void fillTreeGen(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &genPairs)
void fillGen(const reco::GenParticleCollection *genParticles, bool=false)
math::XYZTLorentzVector LorentzVector
Lorentz vector.