Example #1
0
void METAnalyser::analyse(const EventPtr event) {
	histMan_->setCurrentHistogramFolder(histogramFolder_);
	weight_ = event->weight() * prescale_ * scale_;

	for (unsigned index = 0; index < METAlgorithm::NUMBER_OF_METALGORITHMS; ++index) {
		std::string prefix = METAlgorithm::prefixes.at(index);
		METAlgorithm::value metType = (METAlgorithm::value) index;
		if (!MET::isAvailableInNTupleVersion(Globals::NTupleVersion, index))
			continue;
		bool isMCOnlyMET = MET::isMCOnlyMETType(index);

		if (isMCOnlyMET && event->isRealData()) //these METs are MC only (Jet resolution systematics)
			continue;
		const METPointer met(event->MET(metType));
		histMan_->setCurrentHistogramFolder(histogramFolder_ + "/" + prefix);
		histMan_->H1D_BJetBinned("MET")->Fill(met->et(), weight_);
		if (index != METAlgorithm::GenMET && !event->isRealData()) {
			histMan_->H2D_BJetBinned("RecoMET_vs_GenMET")->Fill(event->GenMET()->et(), met->et(), weight_);
		}
		//do not fill other histograms for met systematics
		if ((index > METAlgorithm::patType1p2CorrectedPFMet) && (index != METAlgorithm::recoMetPFlow))
			continue;
		histMan_->H1D_BJetBinned("MET_phi")->Fill(met->phi(), weight_);
		histMan_->H1D_BJetBinned("METsignificance")->Fill(met->significance(), weight_);
		histMan_->H2D_BJetBinned("METsignificance_vs_MET")->Fill(met->et(), met->significance(), weight_);
	}

}
Example #2
0
void METAnalyser::analyseTransverseMass(const EventPtr event, const ParticlePointer particle) {
	histMan_->setCurrentHistogramFolder(histogramFolder_);
	weight_ = event->weight() * prescale_ * scale_;

	for (unsigned index = 0; index < METAlgorithm::NUMBER_OF_METALGORITHMS; ++index) {
		std::string prefix = METAlgorithm::prefixes.at(index);
		METAlgorithm::value metType = (METAlgorithm::value) index;
		if (!MET::isAvailableInNTupleVersion(Globals::NTupleVersion, index))
			continue;
		if (MET::isMCOnlyMETType(index) && event->isRealData())
			continue; //skip MC only METs for real data

		const METPointer met(event->MET(metType));
		histMan_->setCurrentHistogramFolder(histogramFolder_ + "/" + prefix);

		//do not fill histograms for met systematics
		if (index > METAlgorithm::patType1p2CorrectedPFMet)
			continue;

		double MT = Event::MT(particle, met);
		double angle = met->angle(particle);
		double delPhi = met->deltaPhi(particle);
		histMan_->H1D_BJetBinned("Transverse_Mass")->Fill(MT, weight_);
		histMan_->H1D_BJetBinned("Angle_lepton_MET")->Fill(angle, weight_);
		histMan_->H1D_BJetBinned("DeltaPhi_lepton_MET")->Fill(delPhi, weight_);
		if (met->et() < 20)
			histMan_->H1D_BJetBinned("Transverse_Mass_MET20")->Fill(MT, weight_);
	}
}
Example #3
0
void METAnalyser::analyse_ST(const EventPtr event, const ParticlePointer particle, const JetCollection jets) {
	histMan_->setCurrentHistogramFolder(histogramFolder_);
	weight_ = event->weight() * prescale_ * scale_;
	for (unsigned index = 0; index < METAlgorithm::NUMBER_OF_METALGORITHMS; ++index) {
		std::string prefix = METAlgorithm::prefixes.at(index);
		METAlgorithm::value metType = (METAlgorithm::value) index;
		if (!MET::isAvailableInNTupleVersion(Globals::NTupleVersion, index))
			continue;
		bool isMCOnlyMET = MET::isMCOnlyMETType(index);

		if (isMCOnlyMET && event->isRealData()) //these METs are MC only (Jet resolution systematics)
			continue;

		const METPointer met(event->MET(metType));

		float ST = Event::ST(jets, particle, met);
		float WPT = Event::WPT(particle, met);
		float MT = Event::MT(particle, met);

		histMan_->setCurrentHistogramFolder(histogramFolder_ + "/" + prefix);
		histMan_->H1D("ST")->Fill(ST, weight_);
		histMan_->H1D("WPT")->Fill(WPT, weight_);
		histMan_->H1D("MT")->Fill(MT, weight_);

		treeMan_->setCurrentFolder(histogramFolder_);
		treeMan_->Fill("ST",ST);
		treeMan_->Fill("WPT",WPT);
		treeMan_->Fill("MT",MT);

		histMan_->H2D("HT_vs_MET_plus_leptonPt")->Fill(particle->pt() + met->et(), Event::HT(jets), weight_);
	}
}
Example #4
0
bool TopPairEMuReferenceSelection::passesMetCut(const EventPtr event) const {

	const METPointer met(event->MET());

	return met->pt() > 40;

}
void TTbar_plus_X_analyser::fillCommonTreesNoBSelection(const EventPtr event,  const unsigned int selectionCriteria, std::string folder ) {
	SelectionCriteria::selection selection = SelectionCriteria::selection(selectionCriteria);

	// Jets
	const JetCollection jets(event->CleanedJets());
	// B Jets
	const JetCollection bJets(event->CleanedBJets());
	// Lepton
	const LeptonPointer signalLepton = event->getSignalLepton( selection );
	// MET
	const METPointer MET_original(event->MET((METAlgorithm::value) 0));


	treeMan_->setCurrentFolder(folder);
	treeMan_->Fill("EventWeight", event->weight());
	treeMan_->Fill("PUWeight", event->PileUpWeight());
	treeMan_->Fill("PUWeight_up", event->PileUpWeight(1));
	treeMan_->Fill("PUWeight_down", event->PileUpWeight(-1));

	treeMan_->Fill("M3",Event::M3(jets));

	if ( Event::NJets(bJets) > 0 ) {
		treeMan_->Fill("M_bl",Event::M_bl(bJets, signalLepton));
		treeMan_->Fill("angle_bl",Event::angle_bl(bJets, signalLepton));
	}

	treeMan_->Fill("HT",Event::HT(jets));
	treeMan_->Fill("MET",MET_original->et());
	treeMan_->Fill("MET_phi",MET_original->phi());
	treeMan_->Fill("ST",Event::ST(jets, signalLepton, MET_original));
	treeMan_->Fill("WPT",Event::WPT(signalLepton, MET_original));
	treeMan_->Fill("MT",Event::MT(signalLepton, MET_original));

	treeMan_->Fill("NJets",Event::NJets(jets));
	treeMan_->Fill("NBJets",Event::NJets(bJets));
	treeMan_->Fill("NVertices",	event->Vertices().size());

	treeMan_->Fill("BJetWeight",event->BJetWeight());
	treeMan_->Fill("BJetEfficiencyCorrectionWeight",event->BJetEfficiencyCorrectionWeight());
	treeMan_->Fill("BJetAlternativeWeight",event->BJetAlternativeWeight());

	treeMan_->Fill("BJetUpWeight",event->BJetUpWeight());
	treeMan_->Fill("BJetDownWeight",event->BJetDownWeight());
	treeMan_->Fill("LightJetUpWeight",event->LightJetUpWeight());
	treeMan_->Fill("LightJetDownWeight",event->LightJetDownWeight());

	if (selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsReference)){
		treeMan_->Fill("lepton_isolation", signalLepton->PFRelIso03DeltaBeta());
	}
	else if (selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsReference)){
		treeMan_->Fill("lepton_isolation", signalLepton->PFRelIso04DeltaBeta());
	}

	for (unsigned int index = 0; index < jets.size(); ++index) {
		treeMan_->Fill("jet_csv", jets.at(index)->getBTagDiscriminator(BtagAlgorithm::CombinedSecondaryVertexV2) );
	}	
	fillLeptonEfficiencyCorrectionBranches( event, selectionCriteria, signalLepton );	
}
void TTbar_plus_X_analyser::fillCommonTrees(const EventPtr event, const unsigned int selectionCriteria, std::string folder ) {
	SelectionCriteria::selection selection = SelectionCriteria::selection(selectionCriteria);

	// Jets
	const JetCollection jets(event->CleanedJets());
	// B Jets
	unsigned int numberOfBjets = event->getNBJets( selection );

	const JetCollection bJets(event->CleanedBJets());
	// Lepton
	const LeptonPointer signalLepton = event->getSignalLepton( selection );

	// MET
	const METPointer MET_original(event->MET((METAlgorithm::value) 0));

	treeMan_->setCurrentFolder(folder);
	treeMan_->Fill("EventWeight", event->weight());
	treeMan_->Fill("PUWeight", event->PileUpWeight());
	treeMan_->Fill("PUWeight_up", event->PileUpWeight(1));
	treeMan_->Fill("PUWeight_down", event->PileUpWeight(-1));
	treeMan_->Fill("lepton_eta",signalLepton->eta());
	treeMan_->Fill("lepton_pt",signalLepton->pt());
	treeMan_->Fill("lepton_charge",signalLepton->charge());

	if (selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsReference) ||
		selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsQCDNonIsolated) ||
		selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsQCDConversion)){
		treeMan_->Fill("lepton_isolation", signalLepton->PFRelIsoWithEA());

		treeMan_->Fill("lepton_hltECALisolation", signalLepton->hltECALIso());
		treeMan_->Fill("lepton_hltHCALisolation", signalLepton->hltHCALIso());
		treeMan_->Fill("lepton_hltTrackerisolation", signalLepton->hltTrackerIso());
		if ( signalLepton->pt() > 0 ) {
			treeMan_->Fill("lepton_hltTrackerisolation_overPt", signalLepton->hltTrackerIso() / signalLepton->pt() );
		}
	}
	else if (selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsReference) ||
			 selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsQCDNonIsolated1p5to3) ||
			 selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsQCDNonIsolated3toInf)){
		treeMan_->Fill("lepton_isolation", signalLepton->PFRelIso04DeltaBeta());
	}
	treeMan_->Fill("M3",Event::M3(jets));
	if ( numberOfBjets > 0 ) {
		treeMan_->Fill("M_bl",Event::M_bl(bJets, signalLepton));
		treeMan_->Fill("angle_bl",Event::angle_bl(bJets, signalLepton));

// 		if ( numberOfBjets >= 2 ) {
// 			unsigned int highestCSVJetIndex = 0;
// 			unsigned int secondHighestCSVJetIndex = 0;
// 			Event::getTopTwoCSVJets( bJets, highestCSVJetIndex, secondHighestCSVJetIndex );
// 			JetPointer highestCSVJet(bJets.at(highestCSVJetIndex));
// 			JetPointer secondHighestCSVJet(bJets.at(secondHighestCSVJetIndex));
// 			treeMan_->Fill("deltaPhi_bb", fabs( Event::deltaPhi_bb(highestCSVJet, secondHighestCSVJet) ) ) ;
// 			treeMan_->Fill("deltaEta_bb", fabs( Event::deltaEta_bb(highestCSVJet, secondHighestCSVJet) ) ) ;
// 			treeMan_->Fill("angle_bb", Event::angle_bb(highestCSVJet, secondHighestCSVJet));
// 		}
	}
	for (unsigned int index = 0; index < jets.size(); ++index) {
		treeMan_->Fill("jet_pt", jets.at(index)->pt() );
		treeMan_->Fill("jet_eta", jets.at(index)->eta() );
		treeMan_->Fill("jet_csv", jets.at(index)->getBTagDiscriminator(BtagAlgorithm::CombinedSecondaryVertexV2) );
	}	
	treeMan_->Fill("HT",Event::HT(jets));
	treeMan_->Fill("MET",MET_original->et());
	treeMan_->Fill("MET_phi",MET_original->phi());
	treeMan_->Fill("ST",Event::ST(jets, signalLepton, MET_original));
	treeMan_->Fill("WPT",Event::WPT(signalLepton, MET_original));
	treeMan_->Fill("MT",Event::MT(signalLepton, MET_original));

	treeMan_->Fill("NJets",Event::NJets(jets));
	treeMan_->Fill("NBJets",Event::NJets(bJets));
	treeMan_->Fill("NVertices",	event->Vertices().size());

	treeMan_->Fill("BJetWeight",event->BJetWeight());
	treeMan_->Fill("BJetEfficiencyCorrectionWeight",event->BJetEfficiencyCorrectionWeight());
	treeMan_->Fill("BJetAlternativeWeight",event->BJetAlternativeWeight());

	treeMan_->Fill("BJetUpWeight",event->BJetUpWeight());
	treeMan_->Fill("BJetDownWeight",event->BJetDownWeight());
	treeMan_->Fill("LightJetUpWeight",event->LightJetUpWeight());
	treeMan_->Fill("LightJetDownWeight",event->LightJetDownWeight());

	treeMan_->Fill("tau1", event->getTau1());
	treeMan_->Fill("tau2", event->getTau2());
	treeMan_->Fill("tau3", event->getTau3());
	treeMan_->Fill("tau4", event->getTau4());
	treeMan_->Fill("tau5", event->getTau5());
	treeMan_->Fill("tau6", event->getTau6());

	// MET Uncertainties		
	for ( unsigned int unc_i = 0; unc_i < MET_original->getAllMETUncertainties().size(); ++unc_i ) {		
		METPointer METForUnc_i = MET_original->getMETForUncertainty( unc_i );		
		treeMan_->Fill("MET_METUncertainties",METForUnc_i->et());		
		treeMan_->Fill("ST_METUncertainties",Event::ST(jets, signalLepton, METForUnc_i));		
		treeMan_->Fill("WPT_METUncertainties",Event::WPT(signalLepton, METForUnc_i));		
	}

	double topPtWeight = 1.;

	if ( ( event->isSemiLeptonicElectron() || event->isSemiLeptonicMuon() ) ) {

	const TTGenInfoPointer ttGen( event->TTGenInfo() );
	const ParticlePointer leptonicTop = ttGen->getLeptonicTop();
	const ParticlePointer hadronicTop = ttGen->getHadronicTop();

		if ( leptonicTop != 0 && hadronicTop != 0 ) {
			// Store info on leptonic top
			treeMan_->Fill("lepTopPt_parton", leptonicTop->pt() );
			treeMan_->Fill("hadTopPt_parton", hadronicTop->pt() );
			topPtWeight = exp( 0.0615 - 0.0005 * leptonicTop->pt() ) * exp( 0.0615 - 0.0005 * hadronicTop->pt() );

		}

	}

	treeMan_->Fill("topPtWeight",topPtWeight);

	fillLeptonEfficiencyCorrectionBranches( event, selectionCriteria, signalLepton );

	wAnalyser_->analyseHadronicW( event, jets, bJets, folder );
}
Example #7
0
void TTbar_plus_X_analyser::fillCommonTrees(const EventPtr event, const unsigned int selectionCriteria, std::string folder ) {
	SelectionCriteria::selection selection = SelectionCriteria::selection(selectionCriteria);

	// Jets
	const JetCollection jets(event->CleanedJets());
	// B Jets
	unsigned int numberOfBjets = event->getNBJets( selection );

	const JetCollection bJets(event->CleanedBJets());
	// Lepton
	const LeptonPointer signalLepton = event->getSignalLepton( selection );

	// MET
	const METPointer MET_original(event->MET((METAlgorithm::value) 0));

	treeMan_->setCurrentFolder(folder);
	treeMan_->Fill("EventWeight", event->weight());
	treeMan_->Fill("PUWeight", event->PileUpWeight());
	treeMan_->Fill("PUWeight_up", event->PileUpWeight(1));
	treeMan_->Fill("PUWeight_down", event->PileUpWeight(-1));
	treeMan_->Fill("lepton_eta",signalLepton->eta());
	treeMan_->Fill("lepton_pt",signalLepton->pt());
	treeMan_->Fill("lepton_charge",signalLepton->charge());
	if (selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsReference) ||
		selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsQCDNonIsolated) ||
		selection == SelectionCriteria::selection(SelectionCriteria::ElectronPlusJetsQCDConversion)){
		treeMan_->Fill("lepton_isolation", signalLepton->PFRelIsoWithEA());
	}
	else if (selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsReference) ||
			 selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsQCDNonIsolated1p5to3) ||
			 selection == SelectionCriteria::selection(SelectionCriteria::MuonPlusJetsQCDNonIsolated3toInf)){
		treeMan_->Fill("lepton_isolation", signalLepton->PFRelIso04DeltaBeta());
	}
	treeMan_->Fill("M3",Event::M3(jets));
	if ( numberOfBjets > 0 ) {
		treeMan_->Fill("M_bl",Event::M_bl(bJets, signalLepton));
		treeMan_->Fill("angle_bl",Event::angle_bl(bJets, signalLepton));
	}
	for (unsigned int index = 0; index < jets.size(); ++index) {
		treeMan_->Fill("jet_pt", jets.at(index)->pt() );
		treeMan_->Fill("jet_eta", jets.at(index)->eta() );
	}	
	treeMan_->Fill("HT",Event::HT(jets));
	treeMan_->Fill("MET",MET_original->et());
	treeMan_->Fill("ST",Event::ST(jets, signalLepton, MET_original));
	treeMan_->Fill("WPT",Event::WPT(signalLepton, MET_original));
	treeMan_->Fill("MT",Event::MT(signalLepton, MET_original));

	treeMan_->Fill("NJets",Event::NJets(jets));
	treeMan_->Fill("NBJets",Event::NJets(bJets));
	treeMan_->Fill("NVertices",	event->Vertices().size());

	treeMan_->Fill("BJetWeight",event->BJetWeight());
	treeMan_->Fill("BJetUpWeight",event->BJetUpWeight());
	treeMan_->Fill("BJetDownWeight",event->BJetDownWeight());
	treeMan_->Fill("LightJetUpWeight",event->LightJetUpWeight());
	treeMan_->Fill("LightJetDownWeight",event->LightJetDownWeight());

	// MET Uncertainties		
	for ( unsigned int unc_i = 0; unc_i < MET_original->getAllMETUncertainties().size(); ++unc_i ) {		
		METPointer METForUnc_i = MET_original->getMETForUncertainty( unc_i );		
		treeMan_->Fill("MET_METUncertainties",METForUnc_i->et());		
		treeMan_->Fill("ST_METUncertainties",Event::ST(jets, signalLepton, METForUnc_i));		
		treeMan_->Fill("WPT_METUncertainties",Event::WPT(signalLepton, METForUnc_i));		
	}

	fillLeptonEfficiencyCorrectionBranches( event, selectionCriteria, signalLepton );	
}
void PseudoTopAnalyser::analyse(const EventPtr event) {
	weight_ = event->weight();

	treeMan_->setCurrentFolder(histogramFolder_);

	// Store gen selection criteria
	treeMan_->Fill("isSemiLeptonicElectron", event->isSemiLeptonicElectron());
	treeMan_->Fill("isSemiLeptonicMuon", event->isSemiLeptonicMuon());


	const PseudoTopParticlesPointer pseudoTopParticles = event->PseudoTopParticles();
	const MCParticleCollection pseudoTops = pseudoTopParticles->getPseudoTops();
	const MCParticlePointer pseudoLeptonicW = pseudoTopParticles->getPseudoLeptonicW();
	const MCParticlePointer pseudoLepton = pseudoTopParticles->getPseudoLepton();
	const ParticleCollection allPseudoLeptons = pseudoTopParticles->getAllPseudoLeptons();
	const MCParticleCollection pseudoBs = pseudoTopParticles->getPseudoBs();
	const ParticlePointer pseudoMET = pseudoTopParticles->getPseudoMET();
	const ParticlePointer pseudoNeutrino = pseudoTopParticles->getPseudoNeutrino();
	const JetCollection pseudoJets = pseudoTopParticles->getPseudoJets();

	ParticleCollection pseudoTopsForTTbar;

	// // Only consider events with two pseudo tops
	// if ( pseudoTops.size() != 2 ) return;

	// // Also only consider events that are semi leptonic at the pseudo top level
	// if ( !pseudoTopParticles->isSemiLeptonic() ) return;

	// Check if event passes event selection (at pseudo top level)
	if ( passesEventSelection( pseudoLepton, pseudoNeutrino, pseudoJets, pseudoBs, allPseudoLeptons, pseudoMET ) ) {
		treeMan_->Fill("passesGenEventSelection",1);
	}
	else {
		treeMan_->Fill("passesGenEventSelection",0);
	}

	//
	// TOP VARIABLES
	// Top reco at particle level performed
	//

	// Store info on top
	for ( unsigned int ptIndex = 0; ptIndex < pseudoTops.size(); ++ ptIndex ) {
		// cout << "Getting pseudo top number : " << ptIndex << endl;
		const ParticlePointer pseudoTop = pseudoTops[ptIndex];
		pseudoTopsForTTbar.push_back( pseudoTop );
		treeMan_->Fill("pseudoTop_pT", pseudoTop->pt() );
		treeMan_->Fill("pseudoTop_y", pseudoTop->rapidity() );
	}

	if( pseudoTopsForTTbar.size() == 2 ) {
		// Store info on ttbar
		ParticlePointer pseudoTTbar( new Particle( *pseudoTopsForTTbar[0] + *pseudoTopsForTTbar[1] ) );
		treeMan_->Fill("pseudoTTbar_pT", pseudoTTbar->pt() );
		treeMan_->Fill("pseudoTTbar_y", pseudoTTbar->rapidity() );
		treeMan_->Fill("pseudoTTbar_m", pseudoTTbar->mass() );
	}


	// Store info on Bs
	if ( pseudoBs.size() == 2 ) {
		unsigned int leadingPsuedoBIndex = 0;
		if ( pseudoBs[1]->pt() > pseudoBs[0]->pt() ) {
			leadingPsuedoBIndex = 1;
		}
		unsigned int subleadingPsuedoBIndex = ( leadingPsuedoBIndex == 0 ) ? 1 : 0;
		treeMan_->Fill("pseudoB_pT", pseudoBs[leadingPsuedoBIndex]->pt() );
		treeMan_->Fill("pseudoB_eta", pseudoBs[leadingPsuedoBIndex]->eta() );
		treeMan_->Fill("pseudoB_pT", pseudoBs[subleadingPsuedoBIndex]->pt() );
		treeMan_->Fill("pseudoB_eta", pseudoBs[subleadingPsuedoBIndex]->eta() );
		// for ( unsigned int pbIndex = 0; pbIndex < pseudoBs.size(); ++pbIndex ) {
		// 	treeMan_->Fill("pseudoB_pT", pseudoBs[pbIndex]->pt() );
		// 	treeMan_->Fill("pseudoB_eta", pseudoBs[pbIndex]->eta() );
		// }
	}


	//
	// GLOBAL VARIABLES
	// No top reco at particle level
	//

	if ( allPseudoLeptons.size() > 0 ) {
		// Store info on lepton
		treeMan_->Fill("pseudoLepton_pT", allPseudoLeptons[0]->pt() );
		treeMan_->Fill("pseudoLepton_eta", allPseudoLeptons[0]->eta() );		
	}

	// Store pseudo MET
	if ( pseudoMET != 0 ) {
		treeMan_->Fill("pseudoMET", pseudoMET->et() );
		METAlgorithm::value metType = (METAlgorithm::value) 0;
		const METPointer met(event->MET(metType));
		if ( pseudoMET->et() <= 0 && met->et() > 0 ) {
		}
		treeMan_->Fill("pseudoMET_mass", pseudoMET->mass() );
	}


	// Store pseudo HT
	treeMan_->Fill("pseudoHT", event->HT( pseudoJets ) );

	// Store pseudo ST
	if ( allPseudoLeptons.size() > 0 ) {
		treeMan_->Fill("pseudoST", event->ST( pseudoJets, allPseudoLeptons[0], METPointer( new MET( pseudoMET->px(), pseudoMET->py() )) ) );
	}

	// Store pseudo MT and WPT
	// These are from the W reconstructed from the pseudo particles
	// i.e. use the neutrino assocaited with the W rather than the more "global" MET
	if ( pseudoLeptonicW != 0 ) {
		treeMan_->Fill("pseudoWPT_reco", pseudoLeptonicW->pt() );
	}

	if ( pseudoMET != 0 && allPseudoLeptons.size() > 0 ) {
		double WPT = event->WPT( allPseudoLeptons[0], METPointer( new MET( pseudoMET->px(), pseudoMET->py() ))  );
		treeMan_->Fill("pseudoWPT", WPT );

		double MT = event->MT( allPseudoLeptons[0], METPointer( new MET( pseudoMET->px(), pseudoMET->py() )) );
		treeMan_->Fill("pseudoMT", MT );
	}

}
BAT::TtbarHypothesis HitFitAnalyser::analyseAndReturn(const EventPtr event, const JetCollection jets, const JetCollection bjets, const LeptonPointer selectedLepton ) {
	weight_ = event->weight() * prescale_ * scale_;
	treeMan_->setCurrentFolder(histogramFolder_);
	treeMan_->Fill("EventWeight", weight_ );

	// const JetCollection jets(event->getCleanedJets( SelectionCriteria::ElectronPlusJetsReference ));
	// const JetCollection bJets(event->getCleanedBJets( SelectionCriteria::ElectronPlusJetsReference ));
	// const LeptonPointer selectedLepton = event->getSignalLepton( SelectionCriteria::ElectronPlusJetsReference );

	string metPrefix = METAlgorithm::names.at(0);
	const METPointer met(event->MET((METAlgorithm::value) 0));

	// Get cleaned jets that aren't b tagged
	JetCollection leadingLightJets;
	JetCollection leadingBJets;
	unsigned int maxNJet = std::min(5, int(jets.size()));
	for ( unsigned int jetIndex=0; jetIndex < maxNJet; ++jetIndex ) {
		bool isBJet = false;
		JetPointer thisJet = jets[jetIndex];
		for ( unsigned int bJetIndex=0; bJetIndex < bjets.size(); ++bJetIndex ) {
			JetPointer thisBJet = bjets[bJetIndex];
			if ( thisJet == thisBJet ) {
				isBJet = true;
				break;
			}
		}
		if ( !isBJet ) leadingLightJets.push_back( thisJet );
		else leadingBJets.push_back( thisJet );
	}

	//set MC matching flag
	if (event->getDataType() == DataType::TTJets_amcatnloFXFX)
		do_MC_matching = true;
	else
		do_MC_matching = false;

	//prepare the jets collection
	// Copy jets into an array
	JetCollection jetCopy;
	for (JetCollection::const_iterator j = leadingLightJets.begin(); j != leadingLightJets.end(); ++j) {
		jetCopy.push_back(*j);
	}

	JetCollection bJetCopy;
	for (JetCollection::const_iterator j = leadingBJets.begin(); j != leadingBJets.end(); ++j) {
		bJetCopy.push_back(*j);
	}

	std::sort(jetCopy.begin(), jetCopy.end(), jetPtComp);
	std::sort(bJetCopy.begin(), bJetCopy.end(), jetPtComp);

	jetsForFitting.clear();
	unsigned numJetsToFit = jetCopy.size();

	if (jetCopy.size() >= 2) {
		if (numJetsToFit > 5)
			numJetsToFit = 5;
		jetsForFitting.insert(jetsForFitting.begin(), jetCopy.begin(), jetCopy.begin() + numJetsToFit);
	}

	bJetsForFitting.clear();
	numJetsToFit = bJetCopy.size();
	if (bJetCopy.size() >= 2) {
		if (numJetsToFit > 5)
			numJetsToFit = 5;
		bJetsForFitting.insert(bJetsForFitting.begin(), bJetCopy.begin(), bJetCopy.begin() + numJetsToFit);
	}

	BatHitFit hhFitter(electronTranslator_, muonTranslator_, jetTranslator_, metTranslator_, hitfitDefault_,
			hitfitLepWMass_, hitfitHadWMass_, hitfitTopMass_);

	// Clear the internal state
	hhFitter.clear();

	// Add lepton into hitfit
	if ( isElectronChannel_ ) {
		const ElectronPointer signalElectron(boost::static_pointer_cast<Electron>(selectedLepton));
		//TODO: fix the fitter to accept lepton class OR particle!!
		hhFitter.AddLepton(*signalElectron);		
	}
	else {
		const MuonPointer signalMuon(boost::static_pointer_cast<Muon>(selectedLepton));
		//TODO: fix the fitter to accept lepton class OR particle!!
		hhFitter.AddLepton(*signalMuon);
	}


	// Add jets into HitFit
	// Also check if jets matched to ttbar partons are in the jets passed to the fit
	bool quarkInCollection = false, quarkBarInCollection = false, lebBInCollection = false, hadBInCollection = false;
	for (size_t jet = 0; jet != jetsForFitting.size(); ++jet) {
		hhFitter.AddJet(*jetsForFitting.at(jet));
		// cout << "Adding light jet with csv : " << jetsForFitting.at(jet)->getBTagDiscriminator(BAT::BtagAlgorithm::value::CombinedSecondaryVertexV2) << endl;
		if ( jetsForFitting.at(jet)->ttbar_decay_parton() ) {
			int partonPdg = jetsForFitting.at(jet)->ttbar_decay_parton();
			if ( partonPdg == 3 ) quarkInCollection = true;
			else if ( partonPdg == 4 ) quarkBarInCollection = true;
			else if ( partonPdg == 5 ) lebBInCollection = true;
			else if ( partonPdg == 6 ) hadBInCollection = true;
		}
	}
	for (size_t jet = 0; jet != bJetsForFitting.size(); ++jet) {
		hhFitter.AddBJet(*bJetsForFitting.at(jet));
		// cout << "Adding b jet with csv : " << bJetsForFitting.at(jet)->getBTagDiscriminator(BAT::BtagAlgorithm::value::CombinedSecondaryVertexV2) << endl;
		if ( bJetsForFitting.at(jet)->ttbar_decay_parton() ) {
			int partonPdg = bJetsForFitting.at(jet)->ttbar_decay_parton();
			if ( partonPdg == 3 ) quarkInCollection = true;
			else if ( partonPdg == 4 ) quarkBarInCollection = true;
			else if ( partonPdg == 5 ) lebBInCollection = true;
			else if ( partonPdg == 6 ) hadBInCollection = true;
		}

	}

	// Check if jets matched to ttbar partons are in the jets passed to the fit
	if (do_MC_matching) {
		if ( quarkInCollection && quarkBarInCollection && lebBInCollection && hadBInCollection  ) {
			allTTBarJetsPassedToFit_ = true;
		}
		int lastTTBarJetPosition = positionOfLastTTBarJet( jets );
		if ( lastTTBarJetPosition != -1 ) {
			allTTBarJetsPassSelection_ = true;
			treeMan_->Fill("PositionOfLastTTbarJet", lastTTBarJetPosition + 1 );
		}
		else treeMan_->Fill("PositionOfLastTTbarJet", lastTTBarJetPosition );
	}

	// Add missing transverse energy into HitFit
	hhFitter.SetMet(*met);

	// Container for input of all jet permutation of the event
	std::vector<hitfit::Lepjets_Event> hitfitEventsInput;

	// Container for results of the fit for all jet permutation of the event
	std::vector<hitfit::Fit_Result> hitfitResult;
	//
	// R U N   H I T F I T
	//
	// Run the kinematic fit and get how many permutations is possible
	// in the fit

	size_t nHitFit = hhFitter.FitAllPermutation();

//   // Get the number of jets
	// nHitFitJet      = hhFitter.GetEvent().njets();

	// Get the input events for all permutations
	hitfitEventsInput = hhFitter.GetUnfittedEvent();

	// Get the fit results for all permutations
	hitfitResult = hhFitter.GetFitAllPermutation();

	double bestChi2 = 999.;
	unsigned bestX2pos = nHitFit + 1;

//   // Loop over all permutations and extract the information
	for (size_t fit = 0; fit != nHitFit; ++fit) {

		// Get the event after the fit
		hitfit::Fit_Result fitResult = hitfitResult[fit];

		if (hitfitResult[fit].chisq() > 0.0) {
			treeMan_->Fill("FitChiSquaredAllSolutions",fitResult.chisq());
		}
		// Is this the permutation with smallest chi2?
		if (fitResult.chisq() > 0.0 && fitResult.chisq() < bestChi2) {
			bestChi2 = fitResult.chisq();
			bestX2pos = fit;
		}

	}

	//
	// END PART WHICH EXTRACTS INFORMATION FROM HITFIT
	//

	if (bestX2pos < nHitFit + 1) {
		treeMan_->Fill("FitChiSquaredBestSolutions",hitfitResult[bestX2pos].chisq());
		treeMan_->Fill("FitChiSquaredProbabilityBestSolutions",TMath::Prob(hitfitResult[bestX2pos].chisq(),1));

		//pass hitfit event into BAT format
		lepton_charge = selectedLepton->charge();
		BAT::TtbarHypothesis newHyp = BatEvent(hitfitResult[bestX2pos].ev(), event, "SolutionCategory");

		treeMan_->Fill("FittedLeptonicTopPtBestSolution", newHyp.leptonicTop->pt());
		treeMan_->Fill("FittedHadronicTopPtBestSolution", newHyp.hadronicTop->pt());
		treeMan_->Fill("FittedLeptonicTopRapidityBestSolution", newHyp.leptonicTop->rapidity());
		treeMan_->Fill("FittedHadronicTopRapidityBestSolution", newHyp.hadronicTop->rapidity());
		treeMan_->Fill("FittedTTbarMassBestSolution", newHyp.resonance->mass());
		treeMan_->Fill("FittedTTbarPtBestSolution", newHyp.resonance->pt());
		treeMan_->Fill("FittedTTbarRapidityBestSolution", newHyp.resonance->rapidity());

		// Get the event before the fit
		hitfit::Lepjets_Event unfittedEvent = hitfitEventsInput[bestX2pos];

		// Now need to perform second kinematic fit
		hitfit::Fit_Result secondFitResult = performSecondKinematicFit( unfittedEvent, event);
		BAT::TtbarHypothesis newHyp_afterSecondFit = BatEvent(secondFitResult.ev(), event, "SolutionCategory_second");

		treeMan_->Fill("FitChiSquaredBestSolutions_second",secondFitResult.chisq());
		treeMan_->Fill("FitChiSquaredProbabilityBestSolutions_second",TMath::Prob(secondFitResult.chisq(),2));

		treeMan_->Fill("FittedLeptonicTopPtBestSolution_second", newHyp_afterSecondFit.leptonicTop->pt());
		treeMan_->Fill("FittedHadronicTopPtBestSolution_second", newHyp_afterSecondFit.hadronicTop->pt());
		treeMan_->Fill("FittedLeptonicTopRapidityBestSolution_second", newHyp_afterSecondFit.leptonicTop->rapidity());
		treeMan_->Fill("FittedHadronicTopRapidityBestSolution_second", newHyp_afterSecondFit.hadronicTop->rapidity());
		treeMan_->Fill("FittedTTbarMassBestSolution_second", newHyp_afterSecondFit.resonance->mass());
		treeMan_->Fill("FittedTTbarPtBestSolution_second", newHyp_afterSecondFit.resonance->pt());
		treeMan_->Fill("FittedTTbarRapidityBestSolution_second", newHyp_afterSecondFit.resonance->rapidity());

		return newHyp_afterSecondFit;

	} else {
		// cout << "No HitFit solution found for this event" << endl;
		treeMan_->Fill("SolutionCategory", 0 );
		treeMan_->Fill("SolutionCategory_second", 0);
	}

	return BAT::TtbarHypothesis();

}
Example #10
0
void UnfoldingRecoAnalyser::analyse(const EventPtr event) {
	weight_ = event->weight();

	treeMan_->setCurrentFolder(histogramFolder_);

	treeMan_->Fill("EventWeight", event->weight());

	double centralLHEWeight = event->centralLHEWeight();
	for ( unsigned int unc_i = 0; unc_i < event->generatorSystematicWeights().size(); ++unc_i ) {
		double weight = event->generatorSystematicWeights().at( unc_i ) / centralLHEWeight;
		int weightID = event->generatorSystematicWeightsID().at( unc_i );

		// cout << to_string(unc_i) << " " << weightID << " " << weight/centralLHEWeight << endl;
		// string uncString = to_string(unc_i);
		if ( weightID >= 1001 && weightID <= 1009 ) {
			treeMan_->Fill( "muFmuRWeight_" + to_string(weightID-1001), weight);
		}
		else if ( weightID >= 2001 && weightID <= 2100 ) {
			treeMan_->Fill( "pdfWeight_" + to_string(weightID-2001), weight);
		}
		else if ( weightID == 2101 || weightID == 2102 ) {
			treeMan_->Fill( "alphaSWeight_" + to_string(weightID-2101), weight);
		}

	}

	treeMan_->setCurrentFolder(histogramFolder_);

	int selectionCriteria = -1;

	if ( event->PassesElectronTriggerAndSelection() ) selectionCriteria = SelectionCriteria::ElectronPlusJetsReference;
	else if ( event->PassesMuonTriggerAndSelection() ) selectionCriteria = SelectionCriteria::MuonPlusJetsReference;


	if ( event->PassesElectronTriggerAndSelection() && event->PassesMuonTriggerAndSelection() ) {
		cout << "-------------> This should not happen <-------------" << endl;
	}
	// Store selection flags first
	treeMan_->Fill("passSelection",selectionCriteria);

	if ( !( event->PassesMuonTriggerAndSelection() || event->PassesElectronTriggerAndSelection() )) return;

	const JetCollection jets(event->CleanedJets());
	const JetCollection bjets(event->CleanedBJets());
	const LeptonPointer signalLepton = event->getSignalLepton( selectionCriteria );
	METAlgorithm::value metType = (METAlgorithm::value) 0;
	const METPointer met(event->MET(metType));

	treeMan_->Fill("MET",met->et());
	treeMan_->Fill("HT",Event::HT(jets));
	treeMan_->Fill("ST",Event::ST(jets,signalLepton,met));
	treeMan_->Fill("WPT",Event::WPT(signalLepton,met));
	treeMan_->Fill("MT",Event::MT(signalLepton,met));

	treeMan_->Fill("leptonPt", signalLepton->pt() );
	treeMan_->Fill("leptonEta", signalLepton->eta() );
	treeMan_->Fill("leptonCharge", signalLepton->charge() );

	// Get lepton scale factor
	if ( event->PassesMuonTriggerAndSelection() ) {
		const MuonPointer signalMuon(boost::static_pointer_cast<Muon>(signalLepton));
		double efficiencyCorrection = signalMuon->getEfficiencyCorrection( 0 );
		treeMan_->Fill("LeptonEfficiencyCorrection", efficiencyCorrection);
		treeMan_->Fill("LeptonEfficiencyCorrectionUp", signalMuon->getEfficiencyCorrection( 1 ));
		treeMan_->Fill("LeptonEfficiencyCorrectionDown", signalMuon->getEfficiencyCorrection( -1 ));
	}
	else if ( event->PassesElectronTriggerAndSelection() ) {
		const ElectronPointer signalElectron(boost::static_pointer_cast<Electron>(signalLepton));
		double efficiencyCorrection = signalElectron->getEfficiencyCorrection( 0 );	
		treeMan_->Fill("LeptonEfficiencyCorrection", efficiencyCorrection);
		treeMan_->Fill("LeptonEfficiencyCorrectionUp", signalElectron->getEfficiencyCorrection( 1 ));
		treeMan_->Fill("LeptonEfficiencyCorrectionDown", signalElectron->getEfficiencyCorrection( -1 ));
	}

	treeMan_->Fill("PUWeight", event->PileUpWeight() );
	treeMan_->Fill("PUWeight_up", event->PileUpWeight(1) );
	treeMan_->Fill("PUWeight_down", event->PileUpWeight(-1) );
	treeMan_->Fill("BJetWeight",event->BJetWeight());
	treeMan_->Fill("LightJetUpWeight",event->LightJetUpWeight());
	treeMan_->Fill("LightJetDownWeight",event->LightJetDownWeight());
	treeMan_->Fill("BJetUpWeight",event->BJetUpWeight());
	treeMan_->Fill("BJetDownWeight",event->BJetDownWeight());

	// MET Uncertainties
	for ( unsigned int unc_i = 0; unc_i < met->getAllMETUncertainties().size(); ++unc_i ) {
		METPointer METForUnc_i = met->getMETForUncertainty( unc_i );
		treeMan_->Fill("MET_METUncertainties",METForUnc_i->et());
		treeMan_->Fill("ST_METUncertainties",Event::ST(jets, signalLepton, METForUnc_i));
		treeMan_->Fill("WPT_METUncertainties",Event::WPT(signalLepton, METForUnc_i));
	}

	for (unsigned int index = 0; index < bjets.size(); ++index) {
		treeMan_->Fill("bPt", bjets.at(index)->pt() );
		treeMan_->Fill("bEta", bjets.at(index)->eta() );
	}

	for (unsigned int index = 0; index < jets.size(); ++index) {
		treeMan_->Fill("jetPt", jets.at(index)->pt() );
		treeMan_->Fill("jetEta", jets.at(index)->eta() );
		treeMan_->Fill("jetParton", jets.at(index)->ttbar_decay_parton() );
	}

	BAT::TtbarHypothesis topHypothesis = event->ttbarHypothesis();
	if ( topHypothesis.isValid() && topHypothesis.isPhysical() ) {
		treeMan_->Fill("lepTopPt",topHypothesis.leptonicTop->pt());
		treeMan_->Fill("hadTopPt",topHypothesis.hadronicTop->pt());
		treeMan_->Fill("lepTopRap",topHypothesis.leptonicTop->rapidity());
		treeMan_->Fill("hadTopRap",topHypothesis.hadronicTop->rapidity());
		treeMan_->Fill("ttbarPt",topHypothesis.resonance->pt());
		treeMan_->Fill("ttbarM",topHypothesis.resonance->mass());
		treeMan_->Fill("ttbarRap",topHypothesis.resonance->rapidity());
	}

	unsigned int numberOfJets(event->NJets(jets));
	unsigned int numberOfBJets(event->NJets(bjets));
	treeMan_->Fill("NJets", numberOfJets );
	treeMan_->Fill("NBJets", numberOfBJets );
}
Example #11
0
void MCAnalyser::analyse(const EventPtr event) {

	histMan_->setCurrentHistogramFolder("MCStudy");
	MCParticlePointer top, antitop, b_from_top, b_from_antitop, W_plus, W_minus, electron, neutrino, quark_from_W,
			antiquark_from_W;
	JetCollection genJets = event->GenJets();
	JetPointer topBjet, antitopBjet, jet1fromW, jet2fromW;
	bool ejets_event = false;
	bool leptonic_Wplus_found = false, leptonic_Wminus_found = false;
	bool hadronic_Wplus_found = false, hadronic_Wminus_found = false;
//	bool fully_hadronic_event = false, fully_leptonic_event = false;
	bool non_electron_leptonic_channel = false;
	int index = 0;
	int top_index = -100, antitop_index = -100, W_plus_index = -100, W_minus_index = -100;//, electron_index = -100,
//			neutrino_index = -100, b_from_top_index = -100, b_from_antitop_index = -100, quark_from_W_index = -100,
//			antiquark_from_W_index = -100;

	//TODO: change from iterator to index: std::vectors have constant time for index = no gain using iterators
	// MC ttbar reconstruction
	for (MCParticleCollection::const_iterator mc_particle = event->GenParticles().begin();
			mc_particle != event->GenParticles().end(); ++mc_particle, ++index) {

		if ((*mc_particle)->status() != 3)
			continue;
		//top quark
		if ((*mc_particle)->pdgId() == 6) {
			top = *mc_particle;
			top_index = index;
			continue;
		}

		//anti-top quark
		if ((*mc_particle)->pdgId() == -6) {
			antitop = *mc_particle;
			antitop_index = index;
			continue;
		}

		//W+/W- bosons
		if (((*mc_particle)->pdgId() == 24) && ((*mc_particle)->motherIndex() == top_index)) {
			W_plus = *mc_particle;
			W_plus_index = index;
			continue;
		}

		if (((*mc_particle)->pdgId() == -24) && ((*mc_particle)->motherIndex() == antitop_index)) {
			W_minus = *mc_particle;
			W_minus_index = index;
			continue;
		}

		//b-quarks
		if (((*mc_particle)->pdgId() == 5) && ((*mc_particle)->motherIndex() == top_index)) {
			b_from_top = *mc_particle;
//			b_from_top_index = index;
			continue;
		}
		if (((*mc_particle)->pdgId() == -5) && ((*mc_particle)->motherIndex() == antitop_index)) {
			b_from_antitop = *mc_particle;
//			b_from_antitop_index = index;
			continue;
		}

		//W+ decay products
		if ((*mc_particle)->motherIndex() == W_plus_index) {
			if ((*mc_particle)->pdgId() == -11) {
				electron = *mc_particle;
//				electron_index = index;
				leptonic_Wplus_found = true;
			}

			else if ((*mc_particle)->pdgId() == 12) {
				neutrino = *mc_particle;
//				neutrino_index = index;
				leptonic_Wplus_found = true;
			}

			else if ((*mc_particle)->isLepton()) {
				non_electron_leptonic_channel = true;
				leptonic_Wplus_found = true;
			}

			else if ((*mc_particle)->isQuark() && ((*mc_particle)->pdgId() > 0)) {
				quark_from_W = *mc_particle;
//				quark_from_W_index = index;
				hadronic_Wplus_found = true;
			}

			else if ((*mc_particle)->isQuark() && ((*mc_particle)->pdgId() < 0)) {
				antiquark_from_W = *mc_particle;
//				antiquark_from_W_index = index;
				hadronic_Wplus_found = true;
			}

			else {
				cout << "Something went wrong: W+ has unusual decay products." << endl;
			}

		}

		//W- decay products
		if ((*mc_particle)->motherIndex() == W_minus_index) {
			if ((*mc_particle)->pdgId() == 11) {
				electron = *mc_particle;
//				electron_index = index;
				leptonic_Wminus_found = true;
			}

			else if ((*mc_particle)->pdgId() == -12) {
				neutrino = *mc_particle;
//				neutrino_index = index;
				leptonic_Wminus_found = true;
			}

			else if ((*mc_particle)->isLepton()) {
				leptonic_Wminus_found = true;
				non_electron_leptonic_channel = true;
			}

			else if ((*mc_particle)->isQuark() && ((*mc_particle)->pdgId() > 0)) {
				quark_from_W = *mc_particle;
//				quark_from_W_index = index;
				hadronic_Wminus_found = true;
			}

			else if ((*mc_particle)->isQuark() && ((*mc_particle)->pdgId() < 0)) {
				antiquark_from_W = *mc_particle;
//				antiquark_from_W_index = index;
				hadronic_Wminus_found = true;
			}

			else {
				cout << "Something went wrong: W- has unusual decay products." << endl;
			}
		}
	}

	//classify the event
	if (((leptonic_Wplus_found) || (leptonic_Wminus_found)) && ((hadronic_Wplus_found) || (hadronic_Wminus_found))
			&& (!non_electron_leptonic_channel)) {
		ejets_event = true;
		mcEvent.decayChannel = Decay::electronPlusJets;
	}
	if (((leptonic_Wplus_found) || (leptonic_Wminus_found)) && (!hadronic_Wplus_found) && (!hadronic_Wminus_found)) {
//		fully_leptonic_event = true;
		mcEvent.decayChannel = Decay::fullyLeptonic;
	}
	if (((hadronic_Wplus_found) || (hadronic_Wminus_found)) && (!leptonic_Wplus_found) && (!leptonic_Wminus_found)) {
//		fully_hadronic_event = true;
		mcEvent.decayChannel = Decay::fullyHadronic;
	}

	if (ejets_event) {
		//matching genJets and partons
		if (genJets.size() > 0) {
			int closestJetQuarkFromWIndex = quark_from_W->getClosestJetIndex(genJets);
			float minDR_quarkW = quark_from_W->deltaR(genJets.at(closestJetQuarkFromWIndex));
			jet1fromW = genJets.at(closestJetQuarkFromWIndex);

			int closestJetAntiQuarkFromWIndex = antiquark_from_W->getClosestJetIndex(genJets);
			float minDR_antiquarkW = antiquark_from_W->deltaR(genJets.at(closestJetAntiQuarkFromWIndex));
			jet2fromW = genJets.at(closestJetAntiQuarkFromWIndex);

			int closestJetBfromTopIndex = b_from_top->getClosestJetIndex(genJets);
			float minDR_BfromTop = b_from_top->deltaR(genJets.at(closestJetBfromTopIndex));
			topBjet = genJets.at(closestJetBfromTopIndex);

			int closestJetBfromAntiTopIndex = b_from_antitop->getClosestJetIndex(genJets);
			float minDR_BfromAntiTop = b_from_antitop->deltaR(genJets.at(closestJetBfromAntiTopIndex));
			antitopBjet = genJets.at(closestJetBfromAntiTopIndex);

			//delta R between genJets and partons histograms
			histMan_->H1D("deltaRjet1")->Fill(minDR_quarkW);
			histMan_->H1D("deltaRjet2")->Fill(minDR_antiquarkW);
			histMan_->H1D("deltaRjet3")->Fill(minDR_BfromTop);
			histMan_->H1D("deltaRjet4")->Fill(minDR_BfromAntiTop);

			histMan_->H1D("deltaRjet_sum")->Fill(minDR_quarkW);
			histMan_->H1D("deltaRjet_sum")->Fill(minDR_antiquarkW);
			histMan_->H1D("deltaRjet_sum")->Fill(minDR_BfromTop);
			histMan_->H1D("deltaRjet_sum")->Fill(minDR_BfromAntiTop);
		}

		if (leptonic_Wplus_found) {
			mcEvent.leptonicTop = (ParticlePointer) top;
			mcEvent.hadronicTop = (ParticlePointer) antitop;
			mcEvent.leptonicW = (ParticlePointer) W_plus;
			mcEvent.hadronicW = (ParticlePointer) W_minus;
			mcEvent.leptonicBjet = topBjet;
			mcEvent.hadronicBJet = antitopBjet;
			mcEvent.jet1FromW = jet1fromW;
			mcEvent.jet2FromW = jet2fromW;
			mcEvent.neutrinoFromW = (ParticlePointer) neutrino;
			ElectronPointer e(new Electron(electron->energy(), electron->px(), electron->py(), electron->pz()));
			mcEvent.leptonFromW = e;
		} else if (hadronic_Wplus_found) {
			mcEvent.leptonicTop = (ParticlePointer) antitop;
			mcEvent.hadronicTop = (ParticlePointer) top;
			mcEvent.leptonicW = (ParticlePointer) W_minus;
			mcEvent.hadronicW = (ParticlePointer) W_plus;
			mcEvent.leptonicBjet = antitopBjet;
			mcEvent.hadronicBJet = topBjet;
			mcEvent.jet1FromW = jet1fromW;
			mcEvent.jet2FromW = jet2fromW;
			mcEvent.neutrinoFromW = (ParticlePointer) neutrino;
			ElectronPointer e(new Electron(electron->energy(), electron->px(), electron->py(), electron->pz()));
			mcEvent.leptonFromW = e;
		} else
			cout << "ERROR: no hadronic or leptonic W's in semileptonic event (nonsense).\n";

		//comparing deltaR between genJets from W and closest partons
		histMan_->H2D("deltaR_genJets_partons")->Fill(mcEvent.jet1FromW->deltaR(mcEvent.jet2FromW),
				quark_from_W->deltaR(antiquark_from_W));

		//invariant mass histograms
		histMan_->H1D("W_inv_mass_from_truth_partons")->Fill(quark_from_W->invariantMass(antiquark_from_W));
		histMan_->H1D("W_inv_mass_from_genJets")->Fill(mcEvent.jet1FromW->invariantMass(mcEvent.jet2FromW));
		histMan_->H1D("top_leptonic_inv_mass_from_truth")->Fill(mcEvent.leptonicW->invariantMass(mcEvent.leptonicBjet));
		histMan_->H1D("top_hadronic_inv_mass_from_truth")->Fill(mcEvent.hadronicW->invariantMass(mcEvent.hadronicBJet));

		histMan_->H1D("m3_mc")->Fill(mcEvent.M3());

		// comparing truth and reco objects
		if (topEplusJetsRefSelection_->passesFullSelectionExceptLastTwoSteps(event)) {
			const JetCollection jets = topEplusJetsRefSelection_->cleanedJets(event);
			LeptonPointer selectedElectron = topEplusJetsRefSelection_->signalLepton(event);
			METPointer met = event->MET();

			histMan_->H1D("m3_diff")->Fill(fabs(mcEvent.M3() - TtbarHypothesis::M3(jets)));

			boost::scoped_ptr<ChiSquaredBasedTopPairReconstruction> chi2Reco(
					new ChiSquaredBasedTopPairReconstruction(selectedElectron, met, jets));
			if (!chi2Reco->meetsInitialCriteria()) { //reports details on failure and skips event
				cout << chi2Reco->getDetailsOnFailure();
				return;
			}
			TtbarHypothesisPointer bestTopHypothesis = chi2Reco->getBestSolution();

			double deltaRElectron = mcEvent.leptonFromW->deltaR(bestTopHypothesis->leptonFromW);
			double deltaRLeptonicBjet = mcEvent.leptonicBjet->deltaR(bestTopHypothesis->leptonicBjet);
			double deltaRHadronicBjet = mcEvent.hadronicBJet->deltaR(bestTopHypothesis->hadronicBJet);
			double deltaRjet11fromW = mcEvent.jet1FromW->deltaR(bestTopHypothesis->jet1FromW);
			double deltaRjet12fromW = mcEvent.jet1FromW->deltaR(bestTopHypothesis->jet2FromW);
			double deltaRjet21fromW = mcEvent.jet2FromW->deltaR(bestTopHypothesis->jet1FromW);
			double deltaRjet22fromW = mcEvent.jet2FromW->deltaR(bestTopHypothesis->jet2FromW);

			double deltaRjet1fromW = 0;
			double deltaRjet2fromW = 0;

			if (deltaRjet11fromW < deltaRjet12fromW)
				deltaRjet1fromW = deltaRjet11fromW;
			else
				deltaRjet1fromW = deltaRjet12fromW;
			if (deltaRjet21fromW < deltaRjet22fromW)
				deltaRjet2fromW = deltaRjet21fromW;
			else
				deltaRjet2fromW = deltaRjet22fromW;

			double deltaEtaNeutrino = mcEvent.neutrinoFromW->deltaEta(bestTopHypothesis->neutrinoFromW);
			double deltaPhiNeutrino = mcEvent.neutrinoFromW->deltaPhi(bestTopHypothesis->neutrinoFromW);
			histMan_->H1D("deltaEtaNeutrino")->Fill(deltaEtaNeutrino);
			histMan_->H1D("deltaPhiNeutrino")->Fill(deltaPhiNeutrino);

			histMan_->H1D("deltaRElectron")->Fill(deltaRElectron);
			histMan_->H1D("deltaRLeptonicBjet")->Fill(deltaRLeptonicBjet);
			histMan_->H1D("deltaRHadronicBjet")->Fill(deltaRHadronicBjet);
			histMan_->H1D("deltaRjet1fromW")->Fill(deltaRjet1fromW);
			histMan_->H1D("deltaRjet2fromW")->Fill(deltaRjet2fromW);
			histMan_->H1D("deltaRsum")->Fill(
					deltaRElectron + deltaRLeptonicBjet + deltaRHadronicBjet + deltaRjet1fromW + deltaRjet2fromW);

		}
	}
}