void DiElectronAnalyser::analyse(const EventPtr event, const ElectronCollection electrons) {
	histMan_->setCurrentHistogramFolder(histogramFolder_);

	weight_ = event->weight() * prescale_ * scale_;
	if (electrons.size() == 2) {
		ElectronPointer leadingElectron = electrons.front();
		ElectronPointer secondElectron = electrons.at(1);
		//both
		histMan_->H1D_BJetBinned("diLepton_Mass")->Fill(leadingElectron->invariantMass(secondElectron), weight_);
		histMan_->H1D_BJetBinned("diLepton_DeltaR")->Fill(leadingElectron->deltaR(secondElectron), weight_);
		//lead
		histMan_->H1D_BJetBinned("LeadLepton_Pt")->Fill(leadingElectron->pt(), weight_);
		histMan_->H1D_BJetBinned("LeadLepton_Eta")->Fill(leadingElectron->eta(), weight_);
		histMan_->H1D_BJetBinned("LeadLepton_AbsEta")->Fill(abs(leadingElectron->eta()), weight_);
		histMan_->H1D_BJetBinned("LeadLepton_Phi")->Fill(leadingElectron->phi(), weight_);
		histMan_->H1D_BJetBinned("LeadLepton_RelIso")->Fill(leadingElectron->pfRelativeIsolationRhoCorrected(), weight_);
		histMan_->H1D_BJetBinned("LeadLepton_HadOverEM")->Fill(leadingElectron->HadOverEm(), weight_);
		histMan_->H1D_BJetBinned("LeadLepton_dB")->Fill(leadingElectron->d0_wrtBeamSpot(), weight_);
		//second
		histMan_->H1D_BJetBinned("SecondLepton_Pt")->Fill(secondElectron->pt(), weight_);
		histMan_->H1D_BJetBinned("SecondLepton_Eta")->Fill(secondElectron->eta(), weight_);
		histMan_->H1D_BJetBinned("SecondLepton_AbsEta")->Fill(abs(secondElectron->eta()), weight_);
		histMan_->H1D_BJetBinned("SecondLepton_Phi")->Fill(secondElectron->phi(), weight_);
		histMan_->H1D_BJetBinned("SecondLepton_RelIso")->Fill(secondElectron->pfRelativeIsolationRhoCorrected(), weight_);
		histMan_->H1D_BJetBinned("SecondLepton_HadOverEM")->Fill(secondElectron->HadOverEm(), weight_);
		histMan_->H1D_BJetBinned("SecondLepton_dB")->Fill(secondElectron->d0_wrtBeamSpot(), weight_);

	}
}
bool QCDBCToESelection::isGoodElectron(const ElectronPointer electron) const {
	bool passesEtAndEta = electron->et() > 30 && fabs(electron->eta()) < 2.5 && !electron->isInCrack();
	bool passesD0 = fabs(electron->d0()) > 0.02; //cm, inverted cut for non-prompt electrons
	bool passesHOverE = electron->HadOverEm() < 0.05; // same for EE and EB
	bool passesID(electron->passesElectronID(ElectronID::MVAIDTrigger));
	return passesEtAndEta && passesD0 && passesHOverE && passesID;
}
void ElectronAnalyser::analyse(const EventPtr event) {
	histMan_->setCurrentHistogramFolder(histogramFolder_);
	weight_ = event->weight() * prescale_ * scale_;
	const ElectronCollection electrons = event->Electrons();

	if (singleElectronOnly_)
		return;
	histMan_->H1D("Number_Of_Electrons")->Fill(electrons.size(), weight_);
	for (unsigned int index = 0; index < electrons.size(); ++index) {
		const ElectronPointer electron(electrons.at(index));

		histMan_->H1D("All_Electron_Pt")->Fill(electron->pt(), weight_);
		histMan_->H1D("All_Electron_Eta")->Fill(electron->eta(), weight_);
		histMan_->H1D("All_Electron_AbsEta")->Fill(fabs(electron->eta()), weight_);
		histMan_->H1D("All_Electron_Phi")->Fill(electron->phi(), weight_);
		histMan_->H1D("All_Electron_pfIsolation_03_deltaBeta")->Fill(electron->PFRelIso03DeltaBeta(), weight_);

		histMan_->H1D("All_Electron_sigma_ietaieta")->Fill(electron->sigmaIEtaIEta(), weight_);
		histMan_->H1D("All_Electron_dPhi_in")->Fill(electron->dPhiIn(), weight_);
		histMan_->H1D("All_Electron_dEta_in")->Fill(electron->dEtaIn(), weight_);
		histMan_->H1D("All_Electron_HadOverEM")->Fill(electron->HadOverEm(), weight_);
		histMan_->H1D("All_Electron_mvaTrigV0")->Fill(electron->mvaTrigV0(), weight_);
		histMan_->H1D("All_Electron_mvaNonTrigV0")->Fill(electron->mvaNonTrigV0(), weight_);
		histMan_->H1D("All_Electron_dB")->Fill(electron->d0(), weight_);
	}
}
bool TopPairMuPlusJetsReferenceSelection2011::isGoodElectron(const ElectronPointer electron) const {
	bool passesEtAndEta = electron->et() > 30 && fabs(electron->eta()) < 2.5 && !electron->isInCrack();
	bool passesD0 = fabs(electron->d0()) < 0.02; //cm
	bool passesHOverE = electron->HadOverEm() < 0.05; // same for EE and EB
	bool passesID(electron->passesElectronID(ElectronID::MVAIDTrigger));
	return passesEtAndEta && passesD0 &&
//			passesDistanceToPV &&
			passesHOverE && passesID;
}
void ElectronAnalyser::analyseElectron(const ElectronPointer electron, double weight) {
	histMan_->setCurrentHistogramFolder(histogramFolder_);
	weight_ = weight * prescale_ * scale_;

	if (!singleElectronOnly_)
		return;

	histMan_->H1D("electron_eta")->Fill(electron->eta(), weight_);
	histMan_->H1D("electron_AbsEta")->Fill(fabs(electron->eta()), weight_);
	histMan_->H1D("electron_pfIsolation_03_deltaBeta")->Fill(electron->PFRelIso03DeltaBeta(), weight_);

	if (!ttbarPlusMETAnalysisSetup_) {
		histMan_->H1D("electron_pT")->Fill(electron->pt(), weight_);
		histMan_->H1D("electron_phi")->Fill(electron->phi(), weight_);

		histMan_->H1D("electron_sigma_ietaieta")->Fill(electron->sigmaIEtaIEta(), weight_);
		histMan_->H1D("electron_dPhi_in")->Fill(electron->dPhiIn(), weight_);
		histMan_->H1D("electron_dEta_in")->Fill(electron->dEtaIn(), weight_);
		histMan_->H1D("electron_HadOverEM")->Fill(electron->HadOverEm(), weight_);
		histMan_->H1D("electron_mvaTrigV0")->Fill(electron->mvaTrigV0(), weight_);
		histMan_->H1D("electron_mvaNonTrigV0")->Fill(electron->mvaNonTrigV0(), weight_);
		histMan_->H1D("electron_dB")->Fill(electron->d0(), weight_);
	}

	treeMan_->setCurrentFolder(histogramFolder_);
	treeMan_->Fill("EventWeight", weight_ );

	treeMan_->Fill("pt", electron->pt() );
	treeMan_->Fill("eta", electron->eta() );	
	treeMan_->Fill("etaSC", electron->superClusterEta() );
	treeMan_->Fill("relIso_03_deltaBeta", electron->PFRelIso03DeltaBeta() );

	double efficiencyCorrection = electron->getEfficiencyCorrection( 0 );	
	treeMan_->Fill("ElectronEfficiencyCorrection", efficiencyCorrection);

}
extern void printElectron(const ElectronPointer electron) {
	printParticle(electron);
	cout << "Electron Information" << endl;
	cout << setw(30) << "isTight" 					<< setw(30) << "isNonIso" 							<< setw(30) << "isConv" 								<< endl;
	cout << setw(30) << electron->isTightElectron() << setw(30) << electron->isTightNonIsoElectron() << setw(30) << electron->isTightConversionElectron() << endl;

	cout << setw(30) << "sigma_{ieta ieta}" 		<< setw(30) << "|Delta phi_{in}|" 		<< setw(30) << "|Delta eta_{in}|" 		<< setw(30) << "HadOverEm" 				<< endl;
	cout << setw(30) << electron->sigmaIEtaIEta() 	<< setw(30) << fabs(electron->dPhiIn()) << setw(30) << fabs(electron->dEtaIn()) << setw(30) << electron->HadOverEm() 	<< endl;

	cout << setw(30) << "Isolation" 					<< setw(30) << "superClusterEta" 			<< endl;
	cout << setw(30) << electron->PFRelIso03DeltaBeta() << setw(30) << electron->superClusterEta() 	<< endl;
}