示例#1
0
//this can be done shorter if you introduce a function which passes the btagWeight
std::vector<double> BjetWeights(const JetCollection& jets, unsigned int numberOfBtags, int btagSystematicFactor,
		int lightJetSystematicFactor) {
	boost::scoped_ptr < BTagWeight > btagWeight(new BTagWeight(btagSystematicFactor, lightJetSystematicFactor));
	//get b-jets
	const JetCollection bjets(btagWeight->getBJets(jets));
	//get c-jets
	const JetCollection cjets(btagWeight->getCJets(jets));
	//get udsg jets
	const JetCollection udsgjets(btagWeight->getUDSGJets(jets));

	//get mean scale factors
	double SF_b = btagWeight->getAverageBScaleFactor(bjets);
	double SF_c = btagWeight->getAverageCScaleFactor(cjets);
	double SF_udsg = btagWeight->getAverageUDSGScaleFactor(udsgjets);
	//get mean efficiencies
	double mean_bJetEfficiency = btagWeight->getAverageBEfficiency();
	double mean_cJetEfficiency = btagWeight->getAverageCEfficiency();
	double mean_udsgJetEfficiency = btagWeight->getAverageUDSGEfficiency(udsgjets);

	std::vector<double> event_weights;
	for (unsigned int nTag = 0; nTag <= numberOfBtags; ++nTag) { // >= 4 is our last b-tag bin!
		btagWeight->setNumberOfBtags(nTag, 20);
		double event_weight = btagWeight->weight(bjets.size(), cjets.size(), udsgjets.size(), mean_bJetEfficiency,
				mean_cJetEfficiency, mean_udsgJetEfficiency, SF_b, SF_c, SF_udsg, numberOfBtags);
		event_weights.push_back(event_weight);
	}
	//all weights are inclusive. To get the weight for exclusive N b-tags ones has to subtract:
	for (unsigned int nTag = 0; nTag < numberOfBtags; ++nTag) {
		// w(N b-tags) = w(>= N) - w(>= N+1)
		event_weights.at(nTag) = event_weights.at(nTag) - event_weights.at(nTag + 1);
		//last weight, >= numberOfBjets jets, stays inclusive
	}
	return event_weights;
}
void JetAnalyser::analyse(const EventPtr event) {

    histMan_->setCurrentHistogramFolder(histogramFolder_);
    weight_ = event->weight() * prescale_ * scale_;
    const JetCollection jets = event->Jets();
    unsigned int numberOfBJets(0);

    for (unsigned int index = 0; index < jets.size(); ++index) {

        const JetPointer jet(jets.at(index));
        histMan_->H1D_BJetBinned("all_jet_pT")->Fill(jet->pt(), weight_);
        histMan_->H1D_BJetBinned("all_jet_phi")->Fill(jet->phi(), weight_);
        histMan_->H1D_BJetBinned("all_jet_eta")->Fill(jet->eta(), weight_);
        if (jet->isBJet(BtagAlgorithm::CombinedSecondaryVertex, BtagAlgorithm::MEDIUM))
            ++numberOfBJets;

        if (index < 7) {
            stringstream temp;
            temp << "jet" << (index + 1);
            string nthJet = temp.str();
            histMan_->H1D_BJetBinned(nthJet + "_pT")->Fill(jet->pt(), weight_);
            histMan_->H1D_BJetBinned(nthJet + "_phi")->Fill(jet->phi(), weight_);
            histMan_->H1D_BJetBinned(nthJet + "_eta")->Fill(jet->eta(), weight_);
        }

    }

    histMan_->H1D_BJetBinned("N_Jets")->Fill(jets.size(), weight_);
    histMan_->H1D("N_BJets")->Fill(numberOfBJets, weight_);
}
void TTbarDiLeptonAnalyser::eESignalAnalysis(const EventPtr event) {

	if (topEERefSelection_->passesSelectionUpToStep(event, TTbarEEReferenceSelection::MetCut)) {

			const JetCollection jets(topEERefSelection_->cleanedJets(event));
			const JetCollection bJets(topEERefSelection_->cleanedBJets(event));
			unsigned int numberOfBjets(bJets.size());
			vector<double> bjetWeights;
			if (event->isRealData()) {
				for (unsigned int index = 0; index <= numberOfBjets; ++index) {
					if (index == numberOfBjets)
						bjetWeights.push_back(1.);
					else
						bjetWeights.push_back(0);
				}
			} else
				bjetWeights = BjetWeights(jets, numberOfBjets);
			histMan_->setCurrentJetBin(jets.size());
			histMan_->setCurrentBJetBin(numberOfBjets);

			//this is for HT in the MET analyser but needs changing
			const LeptonPointer signalLepton = topEERefSelection_->signalLepton(event);
			const ElectronPointer signalElectron(boost::static_pointer_cast<Electron>(signalLepton));
			const PhotonCollection photons = topEERefSelection_->signalPhotons(event);

			//get dilepton collection
			const ElectronCollection electrons = topEERefSelection_->signalElectrons(event);
			const MuonCollection muons = topEERefSelection_->signalMuons(event);

			for (unsigned int weightIndex = 0; weightIndex < bjetWeights.size(); ++weightIndex) {

				double bjetWeight = bjetWeights.at(weightIndex);
				histMan_->setCurrentBJetBin(weightIndex);
				histMan_->setCurrentHistogramFolder(histogramFolder_ + "/EE/Ref selection");
				//MET
				metAnalyserEERefSelection_->setScale(bjetWeight);
				metAnalyserEERefSelection_->analyse(event, signalLepton);

				//jets
				jetAnalyserEERefSelection_->setScale(bjetWeight);
				jetAnalyserEERefSelection_->analyse(event);

				//DiElectron
				diElectronAnalyserEERefSelection_->setScale(bjetWeight);
			    diElectronAnalyserEERefSelection_->analyse(event, electrons);

			    //photons
			    photonAnalyserEERefSelection_->setScale(bjetWeight);
			    photonAnalyserEERefSelection_->analyse(event, photons, jets, electrons, muons);

			}
	}
}
示例#4
0
文件: MET.cpp 项目: dhidas/UserCode
void MET::adjForUnc(const JetCollection &jets)
{
	if (Jet::correctDirection == JetCorrDirection::NONE ||
		jets.size() <= 0)
		return;
	FourVector new4vec = getFourVector();
	for (unsigned int index = 0; index < jets.size(); ++index)
		new4vec += jets.at(index)->DiffVec;
	new4vec.SetPz(0.0);  // Make sure no longitudinal component
	new4vec.SetE(new4vec.Pt()); // Make sure it stays massless
	setFourVector(new4vec);
}
extern void printJets(const JetCollection jets) {
	for (unsigned short index = 0; index < jets.size(); ++index) {
		const JetPointer jet = jets.at(index);
		cout << "Jet " << index + 1 << endl;
		printJet(jet);
	}
}
bool PseudoTopAnalyser::passesEventSelection( const MCParticlePointer pseudoLepton, const ParticlePointer pseudoNeutrino, const JetCollection pseudoJets, const MCParticleCollection pseudoBs, const ParticleCollection allPseudoLeptons, const ParticlePointer pseudoMET ) {

	// Event selection taken from here : https://twiki.cern.ch/twiki/bin/view/LHCPhysics/ParticleLevelTopDefinitions
	unsigned int numberGoodLeptons = 0;
	unsigned int numberVetoLeptons = 0;
	ParticlePointer leadingLepton;
	for ( unsigned int leptonIndex = 0; leptonIndex < allPseudoLeptons.size(); ++ leptonIndex ) {
		const ParticlePointer lepton = allPseudoLeptons.at(leptonIndex);

		// Check if this is a good signal type lepton
		if ( lepton->pt() > minLeptonPt_ && fabs(lepton->eta()) < maxLeptonAbsEta_ ) {
			++numberGoodLeptons;
			if ( leadingLepton == 0 ) leadingLepton = lepton;
		}
		
		// Check if this is a veto lepton
		if ( lepton->pt() > minVetoLeptonPt_ && fabs(lepton->eta()) < maxVetoLeptonAbsEta_ ) {
			++numberVetoLeptons;
		}
	}

	// Neutrino pt sum
	bool passesNeutrinoSumPt = false;
	if ( pseudoMET != 0 ) {
		if ( pseudoMET->pt() > minNeutrinoSumPt_ ) passesNeutrinoSumPt = true;
	}

	// W MT
	bool passesWMT = false;
	if ( leadingLepton != 0 && pseudoMET != 0 ) {
		double genMT = sqrt( 2 * leadingLepton->pt() * pseudoMET->pt() * ( 1 - cos(leadingLepton->phi() - pseudoMET->phi() ) ) );
		if (genMT > minWMt_) passesWMT = true;
	}


	// Jets
	unsigned int numberGoodJets = 0;
	unsigned int numberGoodBJets = 0;

	for ( unsigned int jetIndex = 0; jetIndex < pseudoJets.size(); ++ jetIndex ) {
		const JetPointer jet = pseudoJets.at(jetIndex);

		// Check if this is a good jet
		if ( jet->pt() > minJetPt_ && fabs(jet->eta()) < maxJetAbsEta_ ) {
			++numberGoodJets;

			// Check if this is also a good b jet
			if ( fabs( jet->partonFlavour() ) == 5 ) {
				++numberGoodBJets;
			}
		}
	}
	
	if ( numberGoodLeptons == 1 && numberVetoLeptons <= 1 && passesNeutrinoSumPt && passesWMT && numberGoodJets >= minNJets_ && numberGoodBJets >= minNBJets_ ) {
		return true;
	}
	else return false;

}
示例#7
0
JetCollection BTagWeight::getBJets(const JetCollection jets) const {
	JetCollection bjets;
	for (unsigned int index = 0; index < jets.size(); ++index) {
		if (abs(jets.at(index)->partonFlavour()) == 5) //b-quark
			bjets.push_back(jets.at(index));
	}
	return bjets;
}
示例#8
0
JetCollection BTagWeight::getCJets(const JetCollection& jets) const {
	JetCollection cjets;
	for (unsigned int index = 0; index < jets.size(); ++index) {
		if (abs(jets.at(index).partonFlavour()) == 4) //c-quark
			cjets.push_back(jets.at(index));
	}
	return cjets;
}
示例#9
0
JetCollection BTagWeight::getUDSGJets(const JetCollection& jets) const {
	JetCollection udsgjets;
	for (unsigned int index = 0; index < jets.size(); ++index) {
		if (abs(jets.at(index).partonFlavour()) != 4 && abs(jets.at(index).partonFlavour()) != 5) //not a c- or b-quark
			udsgjets.push_back(jets.at(index));
	}
	return udsgjets;
}
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 );	
}
bool TopPairEplusJetsRefAsymJetsSelection::passesAsymmetricJetCuts(const EventPtr event) const {
	const JetCollection goodElectronCleanedJets = cleanedJets(event);
	if (goodElectronCleanedJets.size() < 3) // good jets have a cut of 30 GeV!
		return false;
	JetPointer leadingJet = goodElectronCleanedJets.front();
	JetPointer secondLeadingJet = goodElectronCleanedJets.at(1);
	JetPointer thirdLeadingJet = goodElectronCleanedJets.at(2);
	return leadingJet->pt() > 70 && secondLeadingJet->pt() > 50 && thirdLeadingJet->pt() > 50;
}
示例#12
0
double Event::HT(const JetCollection jets) {
	double ht(0);
	//Take ALL the jets!
	for (unsigned int index = 0; index < jets.size(); ++index) {
		if(jets.at(index)->pt() > 20)
			ht += jets.at(index)->pt();
	}
	return ht;
}
示例#13
0
JetCollection Event::GetBJetCollection(const JetCollection& jets, BtagAlgorithm::value btagAlgorithm,
		BtagAlgorithm::workingPoint WP) const {
	JetCollection bjets;
	for (unsigned int index = 0; index < jets.size(); ++index) {
		const JetPointer jet = jets.at(index);
		if (jet->isBJet(btagAlgorithm, WP))
			bjets.push_back(jet);
	}

	return bjets;
}
示例#14
0
double TtbarHypothesis::M3(const JetCollection jets) {
	double m3(0), max_pt(0);
	if (jets.size() >= 3) {
		for (unsigned int index1 = 0; index1 < jets.size() - 2; ++index1) {
			for (unsigned int index2 = index1 + 1; index2 < jets.size() - 1; ++index2) {
				for (unsigned int index3 = index2 + 1; index3 < jets.size(); ++index3) {
					FourVector m3Vector(
							jets.at(index1)->getFourVector() + jets.at(index2)->getFourVector()
									+ jets.at(index3)->getFourVector());
					double currentPt = m3Vector.Pt();
					if (currentPt > max_pt) {
						max_pt = currentPt;
						m3 = m3Vector.M();
					}
				}
			}
		}
	}

	return m3;
}
示例#15
0
unsigned short Electron::getClosestJetIndex(const JetCollection& jets) const {
	unsigned short idOfClosest = 999;
	double closestDR = 999.;
	for (unsigned short index = 0; index < jets.size(); ++index) {
		double DR = deltaR(jets.at(index));
		if (DR < closestDR) {
			closestDR = DR;
			idOfClosest = index;
		}
	}
	return idOfClosest;
}
示例#16
0
double BTagWeight::getAverageUDSGScaleFactor(const JetCollection& jets) const {
	std::vector<double> scaleFactors;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		const Jet jet(jets.at(index));
		scaleFactors.push_back(getUDSGScaleFactor(jet));
	}
	double sumOfScaleFactors = std::accumulate(scaleFactors.begin(), scaleFactors.end(), 0.0);
	if (scaleFactors.size() == 0)
		return 1.;
	else
		return sumOfScaleFactors / scaleFactors.size();
}
double BTagWeight::weight ( const JetCollection& jets, int BTagSystematic, std::string MCSampleTag) const {
	float bTaggedMCJet = 1.0;
	float nonBTaggedMCJet = 1.0;
	float bTaggedDataJet = 1.0;
	float nonBTaggedDataJet = 1.0;

	float err1 = 0.0;
	float err2 = 0.0;
	float err3 = 0.0;
	float err4 = 0.0;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		// Info on this jet
		const pat::Jet& jet (jets.at(index));
		const unsigned int partonFlavour = abs( jet.partonFlavour() );
		const bool isBTagged = jet.bDiscriminator("combinedSecondaryVertexBJetTags") >= 0.679;

		// Get scale factor for this jet
		std::vector<double> sfAndError = getScaleFactor( partonFlavour, jet, MCSampleTag );
		const double sf = sfAndError.at(0);
		const double sfError = sfAndError.at(1);

		// Get efficiency for this jet
		const double eff = getEfficiency( partonFlavour, jet, MCSampleTag );
		if ( isBTagged ) {
			bTaggedMCJet *= eff;
			bTaggedDataJet *= eff*sf;
			if(partonFlavour==5 || partonFlavour ==4) err1 += sfError/sf; ///correlated for b/c
			else err3 += sfError/sf; //correlated for light
		} else {
			nonBTaggedMCJet *= ( 1 - eff );
			nonBTaggedDataJet *= ( 1 - eff*sf );
			if(partonFlavour==5 || partonFlavour ==4 ) err2 += (-eff*sfError)/(1-eff*sf); /// /correlated for b/c
			else err4 += (-eff*sfError)/(1-eff*sf); ////correlated for light
		}
	}

	double bTagWeight = (nonBTaggedDataJet * bTaggedDataJet) / (nonBTaggedMCJet * bTaggedMCJet);
	double error_BTagWeight = sqrt(pow(err1 + err2, 2) + pow(err3 + err4, 2)) * bTagWeight; ///un-correlated for b/c and light


	if (BTagSystematic == +1) {
		return bTagWeight + error_BTagWeight;
	} else if (BTagSystematic == -1) {
		return bTagWeight - error_BTagWeight;
	} else if (BTagSystematic == 0) {
		return bTagWeight;
	}
	return 0.;
}
示例#18
0
double BTagWeight::getAverageBScaleFactor(const JetCollection& jets, std::string MCSampleTag, double uncertaintyFactor) const {
	std::vector<double> scaleFactors;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		const Jet jet(jets.at(index));
		scaleFactors.push_back(getBScaleFactor(jet, MCSampleTag, uncertaintyFactor));
	}
	double sumOfScaleFactors = std::accumulate(scaleFactors.begin(), scaleFactors.end(), 0.0);
	if (scaleFactors.size() == 0) {
		return 1.;
	} else {
		return sumOfScaleFactors / scaleFactors.size();
	}
}
bool HLTriggerQCDAnalyser::passesTriggerAnalysisSelection(const EventPtr event) const {
	const ElectronCollection electrons(event->Electrons());
	const JetCollection jets(event->Jets());
	if (electrons.size() == 0 || jets.size() < 3)
		return false;

	unsigned int nElectrons(0);
	for (unsigned int index = 0; index < electrons.size(); ++index) {
		const ElectronPointer electron(electrons.at(index));
		if (fabs(electron->eta()) < 2.5 && electron->pt() > 20)
			++nElectrons;
		//if more than 2 electrons passing the selection of > 20GeV, reject event
	}
	const ElectronPointer mostEnergeticElectron(electrons.front());
	//clean jets against electron
	JetCollection cleanedJets;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		const JetPointer jet(jets.at(index));
		if (!jet->isWithinDeltaR(0.3, mostEnergeticElectron))
			cleanedJets.push_back(jet);
	}

	unsigned int nCleanedJetsAbove30GeV(0), nCleanedJetsAbove45GeV(0);
	for (unsigned int index = 0; index < cleanedJets.size(); ++index) {
		const JetPointer jet(cleanedJets.at(index));
		if (jet->pt() > 45.)
			++nCleanedJetsAbove45GeV;
		if (jet->pt() > 30.)
			++nCleanedJetsAbove30GeV;
	}

	return nElectrons == 1
			&& (nCleanedJetsAbove45GeV >= 3
					|| (nCleanedJetsAbove45GeV >= 2 && nCleanedJetsAbove30GeV >= 3 && event->runnumber() >= 194270));
}
示例#20
0
void Analysis::analyse() {
	cout << "detected samples:" << endl;
	for (unsigned int sample = 0; sample < DataType::NUMBER_OF_DATA_TYPES; ++sample) {
		if (eventReader->getSeenDatatypes()[sample])
			cout << DataType::names[sample] << endl;
	}

	createHistograms();


	while (eventReader->hasNextEvent()) {

		initiateEvent();
		printNumberOfProccessedEventsEvery(Globals::printEveryXEvents);
		inspectEvents();
		const JetCollection jets(currentEvent->Jets());
		unsigned int numberOfJets(jets.size());
		unsigned int numberOfBJets(0);
		for (unsigned int index = 0; index < numberOfJets; ++index) {
			const JetPointer jet(currentEvent->Jets().at(index));
			if (jet->isBJet(BtagAlgorithm::CombinedSecondaryVertexV2, BtagAlgorithm::MEDIUM))
				++numberOfBJets;
		}
		histMan->setCurrentBJetBin(numberOfBJets);
		histMan->setCurrentJetBin(numberOfJets);

		vector<double> bjetWeights;
		if (currentEvent->isRealData()) {
			for (unsigned int index = 0; index <= numberOfBJets; ++index) {
				if (index == numberOfBJets)
					bjetWeights.push_back(1.);
				else
					bjetWeights.push_back(0);
			}
		} else
			bjetWeights = BjetWeights(jets, numberOfBJets);

		ttbar_plus_X_analyser_->analyse(currentEvent);
		if ( ( currentEvent->getDataType() == DataType::TTJets_amcatnloFXFX || currentEvent->getDataType() == DataType::TTJets_madgraphMLM ) && Globals::treePrefix_ == "" ) {
			pseudoTopAnalyser_->analyse(currentEvent);
			unfoldingRecoAnalyser_->analyse(currentEvent);
			partonAnalyser_->analyse(currentEvent);
			// likelihoodInputAnalyser_->analyse(currentEvent);
		}
		treeMan->FillTrees();
	}
}
const JetCollection TopPairMuPlusJetsReferenceSelection2011::cleanedJets(const EventPtr event) const {
	const JetCollection jets(event->Jets());
	JetCollection cleanedJets;

	if (!hasExactlyOneIsolatedLepton(event)) //if no signal lepton is found, can't clean jets, return them all!
		return jets;

	const LeptonPointer lepton(signalLepton(event));

	for (unsigned int index = 0; index < jets.size(); ++index) {
		const JetPointer jet(jets.at(index));
		if (!jet->isWithinDeltaR(0.3, lepton))
			cleanedJets.push_back(jet);
	}

	return cleanedJets;
}
int HitFitAnalyser::positionOfLastTTBarJet(const JetCollection jets) {
	// Loop over jets and find position of last jet that comes from ttbar decay
	bool foundHadB = false;
	bool foundLepB = false;
	bool foundQ = false;
	bool foundQBar = false;
	for ( unsigned int jetIndex=0; jetIndex < jets.size(); ++jetIndex ) {
		JetPointer jet = jets[jetIndex];

		if ( jet->ttbar_decay_parton() == 3 ) foundQ = true;
		else if ( jet->ttbar_decay_parton() == 4 ) foundQBar = true;
		else if ( jet->ttbar_decay_parton() == 5 ) foundLepB = true;
		else if ( jet->ttbar_decay_parton() == 6 ) foundHadB = true;

		if ( foundQ && foundQBar && foundLepB && foundHadB ) return jetIndex;
	}
	return -1;

}
void BTagEff::analyse(const EventPtr event) {

	histMan_->setCurrentHistogramFolder(histogramFolder_);
	treeMan_->setCurrentFolder(histogramFolder_);
	int NJets = 0;
	const JetCollection allJets = event->Jets();

	for (unsigned int jetIndex = 0; jetIndex < allJets.size(); ++jetIndex) {
		const JetPointer jet(allJets.at(jetIndex));

		bool isLoose = false;
		bool isMedium = false;
		bool isTight = false;

		double jetPt = jet->pt();
		double jetEta = jet->eta();

		if (jetPt < 25 || abs(jetEta) > 2.4) continue;
		// double jetCSV = jet->getBTagDiscriminator(BtagAlgorithm::CombinedSecondaryVertexV2, BtagAlgorithm::MEDIUM);
		double jetCSV = jet->getBTagDiscriminator(BAT::BtagAlgorithm::value::CombinedSecondaryVertexV2);

		// https://twiki.cern.ch/twiki/bin/viewauth/CMS/BtagRecommendation74X50ns
		if (jetCSV > 0.605) isLoose = true;
		if (jetCSV > 0.890) isMedium = true;
		if (jetCSV > 0.970) isTight = true;

		unsigned int partonFlavour = abs(jet->partonFlavour());
		// const bool isBTagged = jet->isBJet(BtagAlgorithm::CombinedSecondaryVertexV2, BtagAlgorithm::MEDIUM);
		// cout << jet->isBJet(BtagAlgorithm::CombinedSecondaryVertexV2, BtagAlgorithm::MEDIUM) << endl;
		
		treeMan_->Fill("pt", jetPt);
		treeMan_->Fill("eta", jetEta);
		treeMan_->Fill("CSV", jetCSV);
		treeMan_->Fill("partonFlavour", partonFlavour);
		treeMan_->Fill("isLoose", isLoose);
		treeMan_->Fill("isMedium", isMedium);
		treeMan_->Fill("isTight", isTight);
		++NJets;
	}


	treeMan_->Fill("NJets", NJets);
}
示例#24
0
void Analysis::analyse() {
	createHistograms();
	cout << "detected samples:" << endl;
	for (unsigned int sample = 0; sample < DataType::NUMBER_OF_DATA_TYPES; ++sample) {
		if (eventReader->getSeenDatatypes()[sample])
			cout << DataType::names[sample] << endl;
	}
	while (eventReader->hasNextEvent()) {
		initiateEvent();
		printNumberOfProccessedEventsEvery(Globals::printEveryXEvents);
		inspectEvents();
		const JetCollection jets(currentEvent->Jets());
		unsigned int numberOfJets(jets.size());
		unsigned int numberOfBJets(0);
		for (unsigned int index = 0; index < numberOfJets; ++index) {
			const JetPointer jet(currentEvent->Jets().at(index));
			if (jet->isBJet(BtagAlgorithm::CombinedSecondaryVertex, BtagAlgorithm::MEDIUM))
				++numberOfBJets;
		}
		histMan->setCurrentBJetBin(numberOfBJets);
		histMan->setCurrentJetBin(numberOfJets);

		vector<double> bjetWeights;
		if (currentEvent->isRealData()) {
			for (unsigned int index = 0; index <= numberOfBJets; ++index) {
				if (index == numberOfBJets)
					bjetWeights.push_back(1.);
				else
					bjetWeights.push_back(0);
			}
		} else
			bjetWeights = BjetWeights(jets, numberOfBJets);

		eventcountAnalyser->analyse(currentEvent);
//		mttbarAnalyser->analyse(currentEvent);
		ttbar_plus_X_analyser_->analyse(currentEvent);
		diffVariablesAnalyser->analyse(currentEvent);
//		binningAnalyser->analyse(currentEvent);
	}
}
示例#25
0
const JetCollection TopPairEMuReferenceSelection::cleanedJets(const EventPtr event) const {
	const JetCollection jets(event->Jets());
	JetCollection cleanedJets;

	//if no signal lepton is found, can't clean jets, return them all!
	if (!passesDiLeptonSelection(event))
		return jets;

	const PhotonCollection photons(signalPhotons(event));
	const ElectronCollection electrons(signalElectrons(event));
	const MuonCollection muons(signalMuons(event));


	double minDR = 999999999.;
	double minDR_pho = 999999999.;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		const JetPointer jet(jets.at(index));
		for (unsigned int lep = 0; lep < electrons.size(); lep++){
			const LeptonPointer lepton(electrons.at(lep));
			if(jet->deltaR(lepton) < minDR)
				minDR = jet->deltaR(lepton);
		}
		for (unsigned int lep = 0; lep < muons.size(); lep++){
			const LeptonPointer lepton(muons.at(lep));
			if(jet->deltaR(lepton) < minDR)
				minDR = jet->deltaR(lepton);
		}
		for (unsigned int pho = 0; pho < photons.size(); pho++){
					const PhotonPointer photon(photons.at(pho));
					if(jet->deltaR(photon) < minDR_pho)
						minDR_pho = jet->deltaR(photon);
		}

		if (minDR > 0.5 && minDR_pho > 0.3 && isGoodJet(jet))
			cleanedJets.push_back(jet);
	}
	
	return cleanedJets;
}
示例#26
0
double BTagWeight::getAverageUDSGEfficiency(const JetCollection& jets) const {
	std::vector<double> efficiencies;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		const Jet jet(jets.at(index));
		double efficiency(0);
		//these numbers are for CSVM only
		double pt = getSmearedJetPtScale(jet, 0)*jet.pt();
		if (pt < 20) {
			continue;
		} else if (pt > 800) {
			efficiency = getMeanUDSGEfficiency(800.);
		} else {
			efficiency = getMeanUDSGEfficiency(pt);
		}
		efficiencies.push_back(efficiency);
	}
	double sumOfEfficiencies = std::accumulate(efficiencies.begin(), efficiencies.end(), 0.0);
	if (efficiencies.size() == 0)
		return 1.;
	else
		return sumOfEfficiencies / efficiencies.size();
}
示例#27
0
void BTagEff::analyse(const EventPtr event) {

	treeMan_->setCurrentFolder(histogramFolder_);
	int NJets = 0;
	int NBJets = 0; // How many medium b jets
	const JetCollection cleanedJets = event->CleanedJets();

	int selectionCriteria = -1;
	if ( event->PassesElectronTriggerAndSelectionNoB() ) selectionCriteria = SelectionCriteria::ElectronPlusJetsReference;
	else if ( event->PassesMuonTriggerAndSelectionNoB() ) selectionCriteria = SelectionCriteria::MuonPlusJetsReference;
	const LeptonPointer signalLepton = event->getSignalLepton( selectionCriteria );

	// unsigned int nParton = 0;
	for (unsigned int jetIndex = 0; jetIndex < cleanedJets.size(); ++jetIndex) {
		const JetPointer jet(cleanedJets.at(jetIndex));

		bool isLoose = false;
		bool isMedium = false;
		bool isTight = false;

		double jetPt = jet->pt();
		double jetEta = jet->eta();

		if (jetPt < 25 || fabs(jetEta) > 2.4) continue;

		double jetCSV = jet->getBTagDiscriminator(BAT::BtagAlgorithm::value::CombinedSecondaryVertexV2);

		// https://twiki.cern.ch/twiki/bin/viewauth/CMS/BtagRecommendation76X
		if (jetCSV > 0.460) {
			isLoose = true;
		}
		if (jetCSV > 0.800) {
			isMedium = true;
			++NBJets;
		}
		if (jetCSV > 0.935) {
			isTight = true;
		}

		unsigned int partonFlavour = abs(jet->partonFlavour());
		unsigned int hadronFlavour = abs(jet->hadronFlavour());

		treeMan_->Fill("pt", jetPt);
		treeMan_->Fill("eta", jetEta);
		treeMan_->Fill("CSV", jetCSV);
		treeMan_->Fill("partonFlavour", partonFlavour);
		treeMan_->Fill("hadronFlavour", hadronFlavour);
		treeMan_->Fill("isLoose", isLoose);
		treeMan_->Fill("isMedium", isMedium);
		treeMan_->Fill("isTight", isTight);
		++NJets;
	}

	treeMan_->Fill("NJets", NJets);
	treeMan_->Fill("NBJets", NBJets);
	treeMan_->Fill("EventWeight", event->weight());
	treeMan_->Fill("PUWeight", event->PileUpWeight());

	if ( selectionCriteria == SelectionCriteria::ElectronPlusJetsReference ) {
		double electronEfficiencyCorrection = 1;
		if ( !event->isRealData() ) {
			const ElectronPointer signalElectron(boost::static_pointer_cast<Electron>(signalLepton));
			electronEfficiencyCorrection = signalElectron->getEfficiencyCorrection( 0 );
		}
		treeMan_->Fill("ElectronEfficiencyCorrection",electronEfficiencyCorrection);
	}
	else if ( selectionCriteria == SelectionCriteria::MuonPlusJetsReference ) {
		double muonEfficiencyCorrection = 1;
		if ( !event->isRealData() ) {
			const MuonPointer signalMuon(boost::static_pointer_cast<Muon>(signalLepton));
			muonEfficiencyCorrection = signalMuon->getEfficiencyCorrection( 0 );
		}
		treeMan_->Fill("MuonEfficiencyCorrection",muonEfficiencyCorrection);
	}
}
示例#28
0
double BTagWeight::weight(const JetCollection jets, const int systematic) const {
	float bTaggedMCJet = 1.0;
	float nonBTaggedMCJet = 1.0;
	float bTaggedDataJet = 1.0;
	float nonBTaggedDataJet = 1.0;

	for (unsigned int index = 0; index < jets.size(); ++index) {
		// Info on this jet
		const JetPointer jet(jets.at(index));

		double jetPt = jet->pt();
		if ( jetPt < 25 ) continue;

		// If the pt of the jet is outside the pt range of the SFs,
		// use the pt at the upper/lower edge and double the uncertainty.
		bool ptOutOfRange = false;
		if ( jetPt <= 30 || jet->pt() >= 670 ) {
			ptOutOfRange = true;
		}

		const unsigned int partonFlavour = abs( jet->partonFlavour() );
		const bool isBTagged = jet->isBJet();

		// Get scale factor for this jet
		const double sf = jet->getBTagSF( 0 );
		double sf_up = jet->getBTagSF( 1 );
		double sf_down = jet->getBTagSF( -1 );

		if ( ptOutOfRange ) {
			sf_up = sf + 2 * ( sf_up - sf );
			sf_down = sf - 2 * ( sf - sf_down );

			if ( sf_up < 0 ) sf_up = 0;
			if ( sf_down < 0 ) sf_down = 0;
		}

		// Get efficiency for this jet
		const double eff = getEfficiency( partonFlavour, jet );
		double sfToUse = sf;
		if ( systematic == 1 ) {
			sfToUse = sf_up;
		}
		else if ( systematic == -1 ) {
			sfToUse = sf_down;
		}

		if ( isBTagged ) {
			bTaggedMCJet *= eff;
			if ( eff*sfToUse > 1 ) {
				bTaggedDataJet *= 1;
			}
			else if ( eff*sfToUse < 0 ) {
				bTaggedDataJet *= 0;
			}
			else {
				bTaggedDataJet *= eff*sfToUse;
			}
		}
		else {
			nonBTaggedMCJet *= ( 1 - eff );

			if ( eff*sfToUse > 1 ) {
				nonBTaggedDataJet *= 0;
			}
			else if ( eff*sfToUse < 0 ) {
				nonBTaggedDataJet *= 1;
			}
			else {
				bTaggedDataJet *= ( 1 - eff*sfToUse );
			}
		}
		// if ( nonBTaggedMCJet < 0 || nonBTaggedDataJet < 0 ) {
		// 	cout << nonBTaggedMCJet << " " << nonBTaggedDataJet << endl;
		// 	cout << eff << " " << sfToUse << endl;
		// }
	}

	double bTagWeight = (nonBTaggedDataJet * bTaggedDataJet) / (nonBTaggedMCJet * bTaggedMCJet);

	return bTagWeight;
}
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 );
}
示例#30
0
bool TopPairEMuReferenceSelection::isGoodPhoton(const PhotonPointer photon, const EventPtr event) const {
	
	bool passesEtAndEta = photon->et() > 25 && fabs(photon->eta()) < 1.4442 && !photon->isInCrack();
	bool passesSafeElectronVeto = photon->ConversionSafeElectronVeto();
	bool passesHOverE = photon->SingleTowerHoE() < 0.05; // same for EE and EB
	
//	bool passesShowerShape = false;
//	bool passesPFChargedIso = false;
	bool passesPFNeutralIso = false;
	bool passesPFPhotonIso = false;
	bool passesphoSCChIso = false;
//	bool passesphoSCNuIso = false;
//	bool passesphoSCPhIso = false;
	
	if (photon->isInBarrelRegion()) {
//		passesShowerShape = photon->sigmaIEtaIEta() < 0.012;
//		passesPFChargedIso = photon->RhoCorrectedPFChargedHadronIso(event->rho()) < 2.6;
		passesPFNeutralIso = photon->RhoCorrectedPFNeutralHadronIso(event->rho()) < 7.5 + 0.04 * photon->pt(); //3.5
		passesPFPhotonIso = photon->RhoCorrectedPFPhotonIso(event->rho()) < 5 + 0.005 * photon->pt(); //1.3
		passesphoSCChIso = photon->RhoCorrectedSCChIso(event->rho()) < 5;
//		passesphoSCNuIso = photon->RhoCorrectedSCNuIso(event->rho()) < 3.5 + 0.04 * photon->pt();
//		passesphoSCPhIso = photon->RhoCorrectedSCPhIso(event->rho()) < 1.3 + 0.005 * photon->pt();
	} else if (photon->isInEndCapRegion()) {
//		passesShowerShape = photon->sigmaIEtaIEta() < 0.034;
//		passesPFChargedIso = photon->RhoCorrectedPFChargedHadronIso(event->rho()) < 2.3;
		passesPFNeutralIso = photon->RhoCorrectedPFNeutralHadronIso(event->rho()) < 2.9 + 0.04 * photon->pt();
		passesPFPhotonIso = photon->RhoCorrectedPFPhotonIso(event->rho()) < 1.5 + 0.005 * photon->pt();
		passesphoSCChIso = photon->RhoCorrectedSCChIso(event->rho()) < 2.3;
//		passesphoSCNuIso = photon->RhoCorrectedSCNuIso(event->rho()) < 2.9 + 0.04 * photon->pt();
//		passesphoSCPhIso = photon->RhoCorrectedSCPhIso(event->rho()) < 1.5 + 0.005 * photon->pt();
	}
	
	const ElectronCollection electrons(goodElectrons(event));
	const MuonCollection muons(goodMuons(event));
	const JetCollection jets(event->Jets());;

	   bool passesDeltaRgammaMuons = false;

	 	for (unsigned int index = 0; index < muons.size(); ++index) {
	 			const MuonPointer muon(muons.at(index));
	 			passesDeltaRgammaMuons = photon->deltaR(muon) > 0.3;
				
				if(photon->deltaR(muon) < 0.3)
				break;
	 	}

	 	bool passesDeltaRgammaElectrons = false;

	 	 	for (unsigned int index = 0; index < electrons.size(); ++index) {
	 	 		const ElectronPointer electron(electrons.at(index));
	 	 		passesDeltaRgammaElectrons = photon->deltaR(electron) > 0.3;
					
				if(photon->deltaR(electron) < 0.3)
				break;	
	  	}
		
	bool passesDeltaRgammaJets = false;
	
	for (unsigned int index = 0; index < jets.size(); ++index) { 
			const JetPointer jet(jets.at(index));
			passesDeltaRgammaJets = photon->deltaR(jet) > 0.3;
	}	
		
	bool passesDeltaRjetsElectrons = false;

	 for (unsigned int index = 0; index < electrons.size(); ++index) {
	 		const ElectronPointer electron(electrons.at(index));
			for(unsigned int jindex = 0; jindex<jets.size(); ++jindex){
				const JetPointer jet(jets[jindex]);
	 			passesDeltaRjetsElectrons = electron->deltaR(jet) > 0.3;
			}	

	}

	bool passesDeltaRjetsMuons = false;

	 for (unsigned int index = 0; index < muons.size(); ++index) {
	 		const MuonPointer muon(muons.at(index));
			for(unsigned int jindex = 0; jindex<jets.size(); ++jindex){
				const JetPointer jet(jets[jindex]);
	 			passesDeltaRjetsMuons = muon->deltaR(jet) > 0.3;
			}	

	}

	return passesEtAndEta && passesSafeElectronVeto && passesHOverE /*&& passesShowerShape*/  && passesPFNeutralIso && passesPFPhotonIso && passesphoSCChIso && passesDeltaRgammaElectrons && 
	passesDeltaRgammaMuons && passesDeltaRgammaJets && passesDeltaRjetsMuons && passesDeltaRjetsElectrons; 
}