25 #include <CLHEP/Vector/LorentzVector.h>
35 outputFile =
new TFile(theGenInfoRootFileName.c_str(),
"RECREATE");
51 std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> muFromRes;
54 int mothersFound[] = {0, 0, 0, 0, 0, 0};
56 for( reco::GenParticleCollection::const_iterator mcIter=genParticles->begin(); mcIter!=genParticles->end(); ++mcIter ) {
57 int status = mcIter->status();
61 ( pdgId==23 || pdgId==443 || pdgId==100443 ||
62 pdgId==553 || pdgId==100553 || pdgId==200553 ) ) {
63 genRes = mcIter->p4();
65 if( pdgId == 23 )
mapHisto[
"hGenResZ"]->Fill(genRes);
66 else if( pdgId == 443 || pdgId == 100443 )
mapHisto[
"hGenResJPsi"]->Fill(genRes);
67 else if( pdgId == 553 || pdgId == 100553 || pdgId == 200553 )
mapHisto[
"hGenResUpsilon1S"]->Fill(genRes);
70 if( status==1 && pdgId==13 && !PATmuons) {
71 int momPdgId =
std::abs(mcIter->mother()->pdgId());
72 if( momPdgId==23 || momPdgId==443 || momPdgId==100443 ||
73 momPdgId==553 || momPdgId==100553 || momPdgId==200553 ) {
74 if( momPdgId == 23 ) mothersFound[0] = 1;
75 if( momPdgId == 443 || momPdgId == 100443 ) mothersFound[5] = 1;
76 if( momPdgId == 553 || momPdgId == 100553 || momPdgId == 200553 ) mothersFound[3] = 1;
77 mapHisto[
"hGenMu"]->Fill(mcIter->p4());
78 std::cout<<
"genmu "<<mcIter->p4()<<std::endl;
79 if(mcIter->charge()>0){
80 muFromRes.first = mcIter->p4();
83 else muFromRes.second = mcIter->p4();
86 if( status==1 && pdgId==13 && PATmuons) {
88 mapHisto[
"hGenMu"]->Fill(mcIter->p4());
89 std::cout<<
"genmu "<<mcIter->p4()<<std::endl;
90 if(mcIter->charge()>0){
91 muFromRes.first = mcIter->p4();
94 else muFromRes.second = mcIter->p4();
100 if( mothersFound[0] == 1 ) {
101 mapHisto[
"hGenMuMuZ"]->Fill(muFromRes.first+muFromRes.second);
102 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.first, genRes, 1 );
103 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.second,genRes, -1 );
105 if( mothersFound[3] == 1 ) {
106 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(muFromRes.first+muFromRes.second);
107 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.first, genRes, 1 );
108 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.second,genRes, -1 );
110 if( mothersFound[5] == 1 ) {
111 mapHisto[
"hGenMuMuJPsi"]->Fill(muFromRes.first+muFromRes.second);
112 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.first, genRes, 1 );
113 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.second,genRes, -1 );
116 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
124 const HepMC::GenEvent* Evt = evtMC->
GetEvent();
125 std::pair<reco::Particle::LorentzVector,reco::Particle::LorentzVector> muFromRes;
128 int mothersFound[] = {0, 0, 0, 0, 0, 0};
132 for (HepMC::GenEvent::particle_const_iterator
part=Evt->particles_begin();
133 part!=Evt->particles_end();
part++) {
134 if (fabs((*part)->pdg_id())==13 && (*part)->status()==1) {
135 bool fromRes =
false;
136 for (HepMC::GenVertex::particle_iterator mother = (*part)->production_vertex()->particles_begin(HepMC::ancestors);
137 mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
138 unsigned int motherPdgId = (*mother)->pdg_id();
139 if( motherPdgId == 13 && (*mother)->status() == 3 ) fromRes =
true;
142 if((*part)->pdg_id()==13){
143 muFromRes.first = (
lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
144 (*part)->momentum().pz(),(*part)->momentum().e()));
146 else if((*part)->pdg_id()==-13){
147 muFromRes.second = (
lorentzVector((*part)->momentum().px(),(*part)->momentum().py(),
148 (*part)->momentum().pz(),(*part)->momentum().e()));
154 mapHisto[
"hGenResZ"]->Fill(muFromRes.first+muFromRes.second);
157 for (HepMC::GenEvent::particle_const_iterator
part=Evt->particles_begin();
158 part!=Evt->particles_end();
part++) {
159 int status = (*part)->status();
167 if (pdgId==13 && status==1) {
169 ( pdgId==23 || pdgId==443 || pdgId==100443 ||
170 pdgId==553 || pdgId==100553 || pdgId==200553 ) ) {
172 (*part)->momentum().pz(),(*part)->momentum().e());
174 if( pdgId == 23 )
mapHisto[
"hGenResZ"]->Fill(genRes);
175 if( pdgId == 443 )
mapHisto[
"hGenResJPsi"]->Fill(genRes);
178 mapHisto[
"hGenResUpsilon1S"]->Fill(genRes);
183 if (pdgId==13 && status==1) {
185 for (HepMC::GenVertex::particle_iterator mother =
186 (*part)->production_vertex()->particles_begin(HepMC::ancestors);
187 mother != (*part)->production_vertex()->particles_end(HepMC::ancestors); ++mother) {
188 int motherPdgId = (*mother)->pdg_id();
189 if (motherPdgId==23 || motherPdgId==443 || motherPdgId==100443 ||
190 motherPdgId==553 || motherPdgId==100553 || motherPdgId==200553) {
192 if( motherPdgId == 23 ) mothersFound[0] = 1;
193 if( motherPdgId == 443 ) mothersFound[3] = 1;
194 if( motherPdgId == 553 ) mothersFound[5] = 1;
200 (*part)->momentum().pz(),(*part)->momentum().e()));
202 (*part)->momentum().pz(),(*part)->momentum().e()));
203 if((*part)->pdg_id()==-13)
205 (*part)->momentum().pz(),(*part)->momentum().e()));
208 (*part)->momentum().pz(),(*part)->momentum().e()));
214 if( mothersFound[0] == 1 ) {
215 mapHisto[
"hGenMuMuZ"]->Fill(muFromRes.first+muFromRes.second);
216 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.first, genRes, 1 );
217 mapHisto[
"hGenResVSMuZ"]->Fill( muFromRes.second,genRes, -1 );
219 if( mothersFound[3] == 1 ) {
220 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(muFromRes.first+muFromRes.second);
221 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.first, genRes, 1 );
222 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( muFromRes.second,genRes, -1 );
224 if( mothersFound[5] == 1 ) {
225 mapHisto[
"hGenMuMuJPsi"]->Fill(muFromRes.first+muFromRes.second);
226 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.first, genRes, 1 );
227 mapHisto[
"hGenResVSMuJPsi"]->Fill( muFromRes.second,genRes, -1 );
229 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
236 std::vector<SimTrack> simMuons;
239 for( edm::SimTrackContainer::const_iterator simTrack=simTracks->begin(); simTrack!=simTracks->end(); ++simTrack ) {
241 if (fabs((*simTrack).type())==13) {
242 simMuons.push_back(*simTrack);
243 mapHisto[
"hSimMu"]->Fill((*simTrack).momentum());
246 mapHisto[
"hSimMu"]->Fill(simMuons.size());
249 if( simMuons.size() >= 2 ) {
250 for( std::vector<SimTrack>::const_iterator imu=simMuons.begin(); imu != simMuons.end(); ++imu ) {
251 for( std::vector<SimTrack>::const_iterator imu2=imu+1; imu2!=simMuons.end(); ++imu2 ) {
252 if (imu==imu2)
continue;
255 if (((*imu).charge()*(*imu2).charge())<0) {
265 mapHisto[
"hSimBestRes"]->Fill(bestSimZ);
266 if (fabs(simMuFromBestRes.first.momentum().eta())<2.5 && fabs(simMuFromBestRes.second.momentum().eta())<2.5 &&
267 simMuFromBestRes.first.momentum().pt()>2.5 && simMuFromBestRes.second.momentum().pt()>2.5) {
268 mapHisto[
"hSimBestResVSMu"]->Fill (simMuFromBestRes.first.momentum(), bestSimZ, int(simMuFromBestRes.first.charge()));
269 mapHisto[
"hSimBestResVSMu"]->Fill (simMuFromBestRes.second.momentum(),bestSimZ, int(simMuFromBestRes.second.charge()));
278 std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> simMuFromRes =
282 mapHisto[
"hSimRightRes"]->Fill(rightSimRes);
292 for(std::vector<reco::LeafCandidate>::const_iterator mu1 = muons.begin(); mu1!=muons.end(); mu1++){
293 mapHisto[
"hRecMu"]->Fill(mu1->p4());
294 mapHisto[
"hRecMuVSEta"]->Fill(mu1->p4());
295 for(std::vector<reco::LeafCandidate>::const_iterator mu2 = muons.begin(); mu2!=muons.end(); mu2++){
296 if (mu1->charge()<0 || mu2->charge()>0)
302 mapHisto[
"hRecMu"]->Fill(muons.size());
308 std::vector<std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> >::const_iterator muonPair = savedPairs.begin();
309 for( ; muonPair != savedPairs.end(); ++muonPair ) {
310 mapHisto[
"hRecMu"]->Fill(muonPair->first);
311 mapHisto[
"hRecMuVSEta"]->Fill(muonPair->first);
312 mapHisto[
"hRecMu"]->Fill(muonPair->second);
313 mapHisto[
"hRecMuVSEta"]->Fill(muonPair->second);
316 mapHisto[
"hRecMu"]->Fill(savedPairs.size());
327 std::vector<std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> >::const_iterator genPair = genPairs.begin();
328 for( ; genPair != genPairs.end(); ++genPair ) {
331 mapHisto[
"hGenMu"]->Fill(genPair->first);
332 mapHisto[
"hGenMuVSEta"]->Fill(genPair->first);
333 mapHisto[
"hGenMuMuZ"]->Fill(genRes);
334 mapHisto[
"hGenResVSMuZ"]->Fill( genPair->first, genRes, 1 );
335 mapHisto[
"hGenResVSMuZ"]->Fill( genPair->second, genRes, -1 );
336 mapHisto[
"hGenMuMuUpsilon1S"]->Fill(genRes);
337 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( genPair->first, genRes, 1 );
338 mapHisto[
"hGenResVSMuUpsilon1S"]->Fill( genPair->second, genRes, -1 );
339 mapHisto[
"hGenMuMuJPsi"]->Fill(genRes);
340 mapHisto[
"hGenResVSMuJPsi"]->Fill( genPair->first, genRes, 1 );
341 mapHisto[
"hGenResVSMuJPsi"]->Fill( genPair->second, genRes, -1 );
342 mapHisto[
"hGenResVsSelf"]->Fill( genRes, genRes, 1 );
391 for (std::map<std::string, Histograms*>::const_iterator
histo=
mapHisto.begin();
393 (*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)
Abs< T >::type abs(const T &t)
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.