Skip to content

Commit

Permalink
fixing CS subtracftion
Browse files Browse the repository at this point in the history
  • Loading branch information
mverwe committed Mar 6, 2020
1 parent cee31d0 commit e442a6c
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pythia8
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/soft/pythia8235
/Users/mverweij/soft/pythia8235
41 changes: 32 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ FFLAGS = -Wall -O2
CXXFLAGS += -std=c++11
LDFLAGS += -std=c++11

FJCONFIG = /soft/fastjet-3.3.2/../fastjet332-install/bin/fastjet-config
FJLOC = /soft/fastjet-3.3.2/../fastjet332-install
FJCONFIG = /Users/mverweij/soft/fastjet332-install/bin/fastjet-config
FJLOC = /Users/mverweij/soft/fastjet332-install

INCLUDE += `$(FJCONFIG) --cxxflags`
LIBRARIES += -L$(FJLOC)/lib -lRecursiveTools `$(FJCONFIG) --libs --plugins` -lfastjetcontribfragile

PYTHIA8LOCATION = /soft/pythia8235
PYTHIA8LOCATION = /Users/mverweij/soft/pythia8235
INCLUDE += -I$(PYTHIA8LOCATION)/include
LIBRARIES += -L$(PYTHIA8LOCATION)/lib -lpythia8
LIBRARIES += -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -lm
LIBRARIES += -L/usr/local/Cellar/gsl/2.5/lib -lgsl -lgslcblas

INCLUDE += -I/usr/include
INCLUDE += -I/usr/local/Cellar/gsl/2.5/include


INCLUDE += `root-config --cflags`
Expand All @@ -33,16 +33,19 @@ COMMONSRC =
F77SRC =
COMMONOBJ =

PROGSRC = runConversionQPYTHIA.cc runCreatePythiaEvents.cc runCreatePythiaEventsPartonLevel.cc runCreateThermalEvents.cc runCSVariations.cc runFromFile.cc runJetPerformance.cc runJetProfile.cc runJetProfileJewelSub.cc runJewelSub.cc runSDGenVarious.cc runSDGenVariousJewelSub.cc runSharedLayerSubtraction.cc runSimpleJetAnalysis.cc runtest.cc
PROGOBJ = runConversionQPYTHIA.o runCreatePythiaEvents.o runCreatePythiaEventsPartonLevel.o runCreateThermalEvents.o runCSVariations.o runFromFile.o runJetPerformance.o runJetProfile.o runJetProfileJewelSub.o runJewelSub.o runSDGenVarious.o runSDGenVariousJewelSub.o runSharedLayerSubtraction.o runSimpleJetAnalysis.o runtest.o
PROGSRC = runConstituentSubtraction.cc runConversionQPYTHIA.cc runCreatePythiaEvents.cc runCreatePythiaEventsPartonLevel.cc runCreateThermalEvents.cc runCSVariations.cc runFromFile.cc runHybridJetAnalysis.cc runJetPerformance.cc runJetProfile.cc runJetProfileJewelSub.cc runJewelSub.cc runSDGenVarious.cc runSDGenVariousJewelSub.cc runSharedLayerSubtraction.cc runSimpleJetAnalysis.cc runtest.cc
PROGOBJ = runConstituentSubtraction.o runConversionQPYTHIA.o runCreatePythiaEvents.o runCreatePythiaEventsPartonLevel.o runCreateThermalEvents.o runCSVariations.o runFromFile.o runHybridJetAnalysis.o runJetPerformance.o runJetProfile.o runJetProfileJewelSub.o runJewelSub.o runSDGenVarious.o runSDGenVariousJewelSub.o runSharedLayerSubtraction.o runSimpleJetAnalysis.o runtest.o

INCLUDE +=
LIBRARIES += -LPU14 -lPU14 -lz


all: runConversionQPYTHIA runCreatePythiaEvents runCreatePythiaEventsPartonLevel runCreateThermalEvents runCSVariations runFromFile runJetPerformance runJetProfile runJetProfileJewelSub runJewelSub runSDGenVarious runSDGenVariousJewelSub runSharedLayerSubtraction runSimpleJetAnalysis runtest
all: runConstituentSubtraction runConversionQPYTHIA runCreatePythiaEvents runCreatePythiaEventsPartonLevel runCreateThermalEvents runCSVariations runFromFile runHybridJetAnalysis runJetPerformance runJetProfile runJetProfileJewelSub runJewelSub runSDGenVarious runSDGenVariousJewelSub runSharedLayerSubtraction runSimpleJetAnalysis runtest


runConstituentSubtraction: runConstituentSubtraction.o $(COMMONOBJ)
$(CXX) $(LDFLAGS) -o $@ $@.o $(COMMONOBJ) $(LIBRARIES)

runConversionQPYTHIA: runConversionQPYTHIA.o $(COMMONOBJ)
$(CXX) $(LDFLAGS) -o $@ $@.o $(COMMONOBJ) $(LIBRARIES)

Expand All @@ -61,6 +64,9 @@ runCSVariations: runCSVariations.o $(COMMONOBJ)
runFromFile: runFromFile.o $(COMMONOBJ)
$(CXX) $(LDFLAGS) -o $@ $@.o $(COMMONOBJ) $(LIBRARIES)

runHybridJetAnalysis: runHybridJetAnalysis.o $(COMMONOBJ)
$(CXX) $(LDFLAGS) -o $@ $@.o $(COMMONOBJ) $(LIBRARIES)

runJetPerformance: runJetPerformance.o $(COMMONOBJ)
$(CXX) $(LDFLAGS) -o $@ $@.o $(COMMONOBJ) $(LIBRARIES)

Expand Down Expand Up @@ -96,7 +102,7 @@ clean:
rm -vf $(COMMONOBJ) $(PROGOBJ)

realclean: clean
rm -vf runConversionQPYTHIA runCreatePythiaEvents runCreatePythiaEventsPartonLevel runCreateThermalEvents runCSVariations runFromFile runJetPerformance runJetProfile runJetProfileJewelSub runJewelSub runSDGenVarious runSDGenVariousJewelSub runSharedLayerSubtraction runSimpleJetAnalysis runtest
rm -vf runConstituentSubtraction runConversionQPYTHIA runCreatePythiaEvents runCreatePythiaEventsPartonLevel runCreateThermalEvents runCSVariations runFromFile runHybridJetAnalysis runJetPerformance runJetProfile runJetProfileJewelSub runJewelSub runSDGenVarious runSDGenVariousJewelSub runSharedLayerSubtraction runSimpleJetAnalysis runtest

.cc.o: $<
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
Expand All @@ -114,6 +120,15 @@ depend:
makedepend $(LCLINCLUDE) -Y -- -- $(COMMONSRC) $(PROGSRC)
# DO NOT DELETE

runConstituentSubtraction.o: include/ProgressBar.h PU14/EventMixer.hh
runConstituentSubtraction.o: PU14/CmdLine.hh PU14/EventSource.hh
runConstituentSubtraction.o: PU14/CmdLine.hh PU14/PU14.hh
runConstituentSubtraction.o: PU14/HepPID/ParticleIDMethods.hh
runConstituentSubtraction.o: include/extraInfo.hh include/jetCollection.hh
runConstituentSubtraction.o: include/softDropGroomer.hh PU14/PU14.hh
runConstituentSubtraction.o: include/jetCollection.hh include/jewelMatcher.hh
runConstituentSubtraction.o: include/treeWriter.hh include/jetMatcher.hh
runConstituentSubtraction.o: include/Angularity.hh include/csSubtractor.hh
runConversionQPYTHIA.o: include/ProgressBar.h include/pythiaEvent.hh
runConversionQPYTHIA.o: include/extraInfo.hh include/extraInfo.hh
runConversionQPYTHIA.o: PU14/CmdLine.hh
Expand Down Expand Up @@ -144,6 +159,14 @@ runFromFile.o: include/softDropGroomer.hh include/jetCollection.hh
runFromFile.o: include/jewelMatcher.hh include/treeWriter.hh
runFromFile.o: include/jetMatcher.hh include/randomCones.hh
runFromFile.o: include/Angularity.hh include/jewelMatcher.hh
runHybridJetAnalysis.o: include/ProgressBar.h PU14/EventMixer.hh
runHybridJetAnalysis.o: PU14/CmdLine.hh PU14/EventSource.hh PU14/CmdLine.hh
runHybridJetAnalysis.o: PU14/PU14.hh PU14/HepPID/ParticleIDMethods.hh
runHybridJetAnalysis.o: include/extraInfo.hh include/jetCollection.hh
runHybridJetAnalysis.o: include/softDropGroomer.hh PU14/PU14.hh
runHybridJetAnalysis.o: include/jetCollection.hh include/jewelMatcher.hh
runHybridJetAnalysis.o: include/treeWriter.hh include/jetMatcher.hh
runHybridJetAnalysis.o: include/Angularity.hh
runJetPerformance.o: include/ProgressBar.h PU14/EventMixer.hh PU14/CmdLine.hh
runJetPerformance.o: PU14/EventSource.hh PU14/CmdLine.hh PU14/PU14.hh
runJetPerformance.o: PU14/HepPID/ParticleIDMethods.hh
Expand Down
11 changes: 7 additions & 4 deletions include/csSubtractor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class csSubtractor {
std::vector<std::vector<fastjet::PseudoJet>> getHard() const { return Hard; }
std::vector<std::vector<fastjet::PseudoJet>> getSoft() const { return Soft; }

std::vector<fastjet::PseudoJet> getUnsubtractedJets() const { return fjJetInputs_;}

std::vector<fastjet::PseudoJet> doSubtraction() {

Hard.clear();
Expand All @@ -81,19 +83,20 @@ class csSubtractor {
// return std::vector<fastjet::PseudoJet>();
//}

fastjet::GhostedAreaSpec ghost_spec(ghostRapMax_, 1, ghostArea_);


std::vector<fastjet::PseudoJet> jets = fjJetInputs_;
//if(jets.size()==0) {

// do the clustering with ghosts and get the jets
//----------------------------------------------------------
fastjet::JetDefinition jet_def(antikt_algorithm, jetRParam_);
fastjet::GhostedAreaSpec ghost_spec(ghostRapMax_, 1, ghostArea_);
fastjet::AreaDefinition area_def = fastjet::AreaDefinition(fastjet::active_area_explicit_ghosts,ghost_spec);

fastjet::JetDefinition jet_def(antikt_algorithm, jetRParam_);

fastjet::ClusterSequenceArea cs(fjInputs_, jet_def, area_def);
fastjet::Selector jet_selector = SelectorAbsRapMax(jetRapMax_);
jets = fastjet::sorted_by_pt(jet_selector(cs.inclusive_jets()));
// fjJetInputs_ = jets;
//}

// create what we need for the background estimation
Expand Down
208 changes: 208 additions & 0 deletions runConstituentSubtraction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#include <iostream>
#include <chrono>

#include "TFile.h"
#include "TTree.h"

#include "fastjet/PseudoJet.hh"
#include "fastjet/ClusterSequenceArea.hh"

#include "include/ProgressBar.h"

#include "PU14/EventMixer.hh"
#include "PU14/CmdLine.hh"
#include "PU14/PU14.hh"

#include "include/extraInfo.hh"
#include "include/jetCollection.hh"
#include "include/softDropGroomer.hh"
#include "include/treeWriter.hh"
#include "include/jetMatcher.hh"
#include "include/Angularity.hh"
#include "include/csSubtractor.hh"

using namespace std;
using namespace fastjet;

// ./runConstituentSubtraction -hard samples/PythiaEventsTune14PtHat120.pu14 -pileup samples/ThermalEventsMult7000PtAv1.20_1.pu14 -nev 10

int main (int argc, char ** argv) {

auto start_time = chrono::steady_clock::now();

CmdLine cmdline(argc,argv);
// inputs read from command line
int nEvent = cmdline.value<int>("-nev",1); // first argument: command line option; second argument: default value
//bool verbose = cmdline.present("-verbose");

cout << "will run on " << nEvent << " events" << endl;

// Uncomment to silence fastjet banner
ClusterSequence::set_fastjet_banner_stream(NULL);

//to write info to root tree
treeWriter trw("jetTree");

//Jet definition
double R = 0.4;
double ghostRapMax = 6.0;
double ghost_area = 0.005;
int active_area_repeats = 1;
GhostedAreaSpec ghost_spec(ghostRapMax, active_area_repeats, ghost_area);
AreaDefinition area_def = AreaDefinition(active_area,ghost_spec);
JetDefinition jet_def(antikt_algorithm, R);

double jetRapMax = 3.0;
Selector jet_selector = SelectorAbsRapMax(jetRapMax);

Angularity width(1.,1.,R);
Angularity pTD(0.,2.,R);

ProgressBar Bar(cout, nEvent);
Bar.SetStyle(-1);

EventMixer mixer(&cmdline); //the mixing machinery from PU14 workshop

// loop over events
int iev = 0;
unsigned int entryDiv = (nEvent > 200) ? nEvent / 200 : 1;
while ( mixer.next_event() && iev < nEvent )
{
// increment event number
iev++;

Bar.Update(iev);
Bar.PrintWithMod(entryDiv);

vector<PseudoJet> particlesMergedAll = mixer.particles();

vector<double> eventWeight;
eventWeight.push_back(mixer.hard_weight());
eventWeight.push_back(mixer.pu_weight());

// extract hard partons that initiated the jets
fastjet::Selector parton_selector = SelectorVertexNumber(-1);
vector<PseudoJet> partons = parton_selector(particlesMergedAll);

// select final state particles from hard event only
//vector<PseudoJet> particlesBkg, particlesSig;
//SelectorIsHard().sift(particlesMerged, particlesSig, particlesBkg); // this sifts the full event into two vectors of PseudoJet, one for the hard event, one for the underlying event

fastjet::Selector sig_selector = SelectorVertexNumber(0);
vector<PseudoJet> particlesSig = sig_selector(particlesMergedAll);

fastjet::Selector bkg_selector = SelectorVertexNumber(1);
vector<PseudoJet> particlesBkg = bkg_selector(particlesMergedAll);

vector<PseudoJet> particlesMerged = particlesBkg;
particlesMerged.insert( particlesMerged.end(), particlesSig.begin(), particlesSig.end() );

std::cout << "#merged: " << particlesMerged.size() << " signal: " << particlesSig.size() << " bkg: " << particlesBkg.size() << std::endl;

//---------------------------------------------------------------------------
// jet clustering of signal jets
//---------------------------------------------------------------------------

fastjet::ClusterSequenceArea csSig(particlesSig, jet_def, area_def);
jetCollection jetCollectionSig(sorted_by_pt(jet_selector(csSig.inclusive_jets(10.))));

//calculate some angularities
vector<double> widthSig; widthSig.reserve(jetCollectionSig.getJet().size());
vector<double> pTDSig; pTDSig.reserve(jetCollectionSig.getJet().size());
for(PseudoJet jet : jetCollectionSig.getJet()) {
widthSig.push_back(width.result(jet));
pTDSig.push_back(pTD.result(jet));
}
jetCollectionSig.addVector("widthSig", widthSig);
jetCollectionSig.addVector("pTDSig", pTDSig);


//---------------------------------------------------------------------------
// jet clustering of signal+background jets
//---------------------------------------------------------------------------

fastjet::ClusterSequenceArea csRaw(particlesMerged, jet_def, area_def);
jetCollection jetCollectionRaw(sorted_by_pt(jet_selector(csRaw.inclusive_jets(10.))));


//---------------------------------------------------------------------------
// background subtraction
//---------------------------------------------------------------------------

//run jet-by-jet constituent subtraction on mixed (hard+UE) event
csSubtractor csSub(R, 0., -1, 0.005,ghostRapMax,jetRapMax);
csSub.setInputParticles(particlesMerged);
jetCollection jetCollectionCS(csSub.doSubtraction());

//Background densities used by constituent subtraction
std::vector<double> rho;
std::vector<double> rhom;
rho.push_back(csSub.getRho());
rhom.push_back(csSub.getRhoM());

//match CS jets to signal jets
jetMatcher jmCS(R);
jmCS.setBaseJets(jetCollectionCS);
jmCS.setTagJets(jetCollectionSig);
jmCS.matchJets();

jmCS.reorderedToTag(jetCollectionCS);

//match Raw(=unsubtracted) jets to signal jets
jetMatcher jmRaw(R);
jmRaw.setBaseJets(jetCollectionRaw);
jmRaw.setTagJets(jetCollectionSig);
jmRaw.matchJets();

jmRaw.reorderedToTag(jetCollectionRaw);

//---------------------------------------------------------------------------
// Groom the jets
//---------------------------------------------------------------------------

//SoftDrop grooming classic for signal jets (zcut=0.1, beta=0)
softDropGroomer sdgSigBeta00Z01(0.1, 0.0, R);
jetCollection jetCollectionSigSDBeta00Z01(sdgSigBeta00Z01.doGrooming(jetCollectionSig));
jetCollectionSigSDBeta00Z01.addVector("zgSigSDBeta00Z01", sdgSigBeta00Z01.getZgs());
jetCollectionSigSDBeta00Z01.addVector("ndropSigSDBeta00Z01", sdgSigBeta00Z01.getNDroppedSubjets());
jetCollectionSigSDBeta00Z01.addVector("dr12SigSDBeta00Z01", sdgSigBeta00Z01.getDR12());


//---------------------------------------------------------------------------
// write tree
//---------------------------------------------------------------------------

//Give variable we want to write out to treeWriter.
//Only vectors of the types 'jetCollection', and 'double', 'int', 'PseudoJet' are supported

trw.addCollection("eventWeight", eventWeight);
trw.addCollection("csRho", rho);
trw.addCollection("csRhom", rhom);

trw.addPartonCollection("partons", partons);

trw.addCollection("sigJet", jetCollectionSig);
trw.addCollection("sigJetSDBeta00Z01", jetCollectionSigSDBeta00Z01);

trw.addCollection("csJet", jetCollectionCS);
trw.addCollection("rawJet", jetCollectionRaw);

trw.fillTree();

}//event loop

Bar.Update(nEvent);
Bar.Print();
Bar.PrintLine();

TTree *trOut = trw.getTree();

TFile *fout = new TFile(cmdline.value<string>("-output", "JetToyHIResultConstituentSubtraction.root").c_str(), "RECREATE");
trOut->Write();
fout->Write();
fout->Close();

double time_in_seconds = chrono::duration_cast<chrono::milliseconds>
(chrono::steady_clock::now() - start_time).count() / 1000.0;
cout << "runFromFile: " << time_in_seconds << endl;
}
2 changes: 2 additions & 0 deletions runCreateThermalEvents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using namespace std;
using namespace fastjet;

// ./runCreateThermalEvents -nev 100 -ncent 0 -jobId 0

int main (int argc, char ** argv)
{
// Uncomment to silence fastjet banner
Expand Down

0 comments on commit e442a6c

Please sign in to comment.