27 #include <CLHEP/Vector/LorentzVector.h>
37 outputFile =
new TFile(theGenInfoRootFileName.c_str(),
"RECREATE");
53 std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> muFromRes;
56 int mothersFound[] = {0, 0, 0, 0, 0, 0};
58 for( reco::GenParticleCollection::const_iterator mcIter=genParticles->begin(); mcIter!=genParticles->end(); ++mcIter ) {
59 int status = mcIter->status();
63 ( pdgId==23 || pdgId==443 || pdgId==100443 ||
64 pdgId==553 || pdgId==100553 || pdgId==200553 ) ) {
65 genRes = mcIter->p4();
67 if( pdgId == 23 )
mapHisto[
"hGenResZ"]->Fill(genRes);
68 else if( pdgId == 443 || pdgId == 100443 )
mapHisto[
"hGenResJPsi"]->Fill(genRes);
69 else if( pdgId == 553 || pdgId == 100553 || pdgId == 200553 )
mapHisto[
"hGenResUpsilon1S"]->Fill(genRes);
72 if( status==1 && pdgId==13 && !PATmuons) {
73 int momPdgId =
std::abs(mcIter->mother()->pdgId());
74 if( momPdgId==23 || momPdgId==443 || momPdgId==100443 ||
75 momPdgId==553 || momPdgId==100553 || momPdgId==200553 ) {
76 if( momPdgId == 23 ) mothersFound[0] = 1;
77 if( momPdgId == 443 || momPdgId == 100443 ) mothersFound[5] = 1;
78 if( momPdgId == 553 || momPdgId == 100553 || momPdgId == 200553 ) mothersFound[3] = 1;
79 mapHisto[
"hGenMu"]->Fill(mcIter->p4());
80 std::cout<<
"genmu "<<mcIter->p4()<<std::endl;
81 if(mcIter->charge()>0){
82 muFromRes.first = mcIter->p4();
85 else muFromRes.second = mcIter->p4();
88 if( status==1 && pdgId==13 && PATmuons) {
90 mapHisto[
"hGenMu"]->Fill(mcIter->p4());
91 std::cout<<
"genmu "<<mcIter->p4()<<std::endl;
92 if(mcIter->charge()>0){
93 muFromRes.first = mcIter->p4();
96 else muFromRes.second = mcIter->p4();
102 if( mothersFound[0] == 1 ) {
103 mapHisto[
"hGenMuMuZ"]->Fill(muFromRes.first+muFromRes.second);
104 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.first, genRes, 1 );
105 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.second,genRes, -1 );
107 if( mothersFound[3] == 1 ) {
108 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(muFromRes.first+muFromRes.second);
109 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.first, genRes, 1 );
110 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.second,genRes, -1 );
112 if( mothersFound[5] == 1 ) {
113 mapHisto[
"hGenMuMuJPsi"]->Fill(muFromRes.first+muFromRes.second);
114 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.first, genRes, 1 );
115 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.second,genRes, -1 );
118 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
126 const HepMC::GenEvent* Evt = evtMC->
GetEvent();
127 std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> muFromRes;
130 int mothersFound[] = {0, 0, 0, 0, 0, 0};
134 for (HepMC::GenEvent::particle_const_iterator
part=Evt->particles_begin();
135 part!=Evt->particles_end();
part++) {
136 if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
137 bool fromRes =
false;
138 for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
139 mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
140 unsigned int motherPdgId = (*mother)->pdg_id();
141 if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes =
true;
144 if((*part)->pdg_id()==13){
145 muFromRes.first = (
lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
146 (*part)->momentum().pz(),(*part)->momentum().e()));
148 else if((*part)->pdg_id()==-13){
149 muFromRes.second = (
lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
150 (*part)->momentum().pz(),(*part)->momentum().e()));
156 mapHisto[
"hGenResZ"]->Fill(muFromRes.first+muFromRes.second);
159 for (HepMC::GenEvent::particle_const_iterator
part=Evt->particles_begin();
160 part!=Evt->particles_end();
part++) {
161 int status = (*part)->status();
169 if (pdgId==13 && status==1) {
171 ( pdgId==23 || pdgId==443 || pdgId==100443 ||
172 pdgId==553 || pdgId==100553 || pdgId==200553 ) ) {
174 (*part)->momentum().pz(),(*part)->momentum().e());
176 if( pdgId == 23 )
mapHisto[
"hGenResZ"]->Fill(genRes);
177 if( pdgId == 443 )
mapHisto[
"hGenResJPsi"]->Fill(genRes);
180 mapHisto[
"hGenResUpsilon1S"]->Fill(genRes);
185 if (pdgId==13 && status==1) {
187 for (HepMC::GenVertex::particle_iterator mother =
188 (*part)->production_vertex()->particles_begin(HepMC::ancestors);
189 mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
190 int motherPdgId = (*mother)->pdg_id();
191 if (motherPdgId==23 || motherPdgId==443 || motherPdgId==100443 ||
192 motherPdgId==553 || motherPdgId==100553 || motherPdgId==200553) {
194 if( motherPdgId == 23 ) mothersFound[0] = 1;
195 if( motherPdgId == 443 ) mothersFound[3] = 1;
196 if( motherPdgId == 553 ) mothersFound[5] = 1;
202 (*part)->momentum().pz(),(*part)->momentum().e()));
204 (*part)->momentum().pz(),(*part)->momentum().e()));
205 if((*part)->pdg_id()==-13)
207 (*part)->momentum().pz(),(*part)->momentum().e()));
210 (*part)->momentum().pz(),(*part)->momentum().e()));
216 if( mothersFound[0] == 1 ) {
217 mapHisto[
"hGenMuMuZ"]->Fill(muFromRes.first+muFromRes.second);
218 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.first, genRes, 1 );
219 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.second,genRes, -1 );
221 if( mothersFound[3] == 1 ) {
222 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(muFromRes.first+muFromRes.second);
223 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.first, genRes, 1 );
224 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.second,genRes, -1 );
226 if( mothersFound[5] == 1 ) {
227 mapHisto[
"hGenMuMuJPsi"]->Fill(muFromRes.first+muFromRes.second);
228 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.first, genRes, 1 );
229 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.second,genRes, -1 );
231 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
238 std::vector<SimTrack> simMuons;
241 for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
243 if (fabs((*simTrack).type())==13) {
244 simMuons.push_back(*simTrack);
245 mapHisto[
"hSimMu"]->Fill((*simTrack).momentum());
248 mapHisto[
"hSimMu"]->Fill(simMuons.size());
251 if( simMuons.size() >= 2 ) {
252 for( std::vector<SimTrack>::const_iterator imu=simMuons.begin(); imu != simMuons.end(); ++imu ) {
253 for( std::vector<SimTrack>::const_iterator imu2=imu+1; imu2!=simMuons.end(); ++imu2 ) {
254 if (imu==imu2)
continue;
257 if (((*imu).charge()*(*imu2).charge())<0) {
267 mapHisto[
"hSimBestRes"]->Fill(bestSimZ);
268 if (fabs(simMuFromBestRes.first.momentum().eta())<2.5 && fabs(simMuFromBestRes.second.momentum().eta())<2.5 &&
269 simMuFromBestRes.first.momentum().pt()>2.5 && simMuFromBestRes.second.momentum().pt()>2.5) {
270 mapHisto[
"hSimBestResVSMu"]->Fill (simMuFromBestRes.first.momentum(), bestSimZ, int(simMuFromBestRes.first.charge()));
271 mapHisto[
"hSimBestResVSMu"]->Fill (simMuFromBestRes.second.momentum(),bestSimZ, int(simMuFromBestRes.second.charge()));
280 std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> simMuFromRes =
284 mapHisto[
"hSimRightRes"]->Fill(rightSimRes);
294 for(std::vector<reco::LeafCandidate>::const_iterator mu1 = muons.begin(); mu1!=muons.end(); mu1++){
295 mapHisto[
"hRecMu"]->Fill(mu1->p4());
296 mapHisto[
"hRecMuVSEta"]->Fill(mu1->p4());
297 for(std::vector<reco::LeafCandidate>::const_iterator mu2 = muons.begin(); mu2!=muons.end(); mu2++){
298 if (mu1->charge()<0 || mu2->charge()>0)
304 mapHisto[
"hRecMu"]->Fill(muons.size());
310 std::vector<std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> >::const_iterator muonPair = savedPairs.begin();
311 for( ; muonPair != savedPairs.end(); ++muonPair ) {
312 mapHisto[
"hRecMu"]->Fill(muonPair->first);
313 mapHisto[
"hRecMuVSEta"]->Fill(muonPair->first);
314 mapHisto[
"hRecMu"]->Fill(muonPair->second);
315 mapHisto[
"hRecMuVSEta"]->Fill(muonPair->second);
318 mapHisto[
"hRecMu"]->Fill(savedPairs.size());
329 std::vector<std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> >::const_iterator genPair = genPairs.begin();
330 for( ; genPair != genPairs.end(); ++genPair ) {
333 mapHisto[
"hGenMu"]->Fill(genPair->first);
334 mapHisto[
"hGenMuVSEta"]->Fill(genPair->first);
335 mapHisto[
"hGenMuMuZ"]->Fill(genRes);
336 mapHisto[
"hGenResVSMuZ"]->Fill( genPair->first, genRes, 1 );
337 mapHisto[
"hGenResVSMuZ"]->Fill( genPair->second, genRes, -1 );
338 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(genRes);
339 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( genPair->first, genRes, 1 );
340 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( genPair->second, genRes, -1 );
341 mapHisto[
"hGenMuMuJPsi"]->Fill(genRes);
342 mapHisto[
"hGenResVSMuJPsi"]->Fill( genPair->first, genRes, 1 );
343 mapHisto[
"hGenResVSMuJPsi"]->Fill( genPair->second, genRes, -1 );
344 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
393 for (std::map<std::string, Histograms*>::const_iterator
histo=
mapHisto.begin();
395 (*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 fillRec(std::vector< reco::LeafCandidate > &muons)
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 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.