Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
mschrode committed Jun 22, 2021
0 parents commit 2577ed4
Show file tree
Hide file tree
Showing 17 changed files with 896 additions and 0 deletions.
10 changes: 10 additions & 0 deletions BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<use name="root" />
<use name="boost" />
<use name="UHH2/common" />
<use name="UHH2/core" />
<use name="PhysicsTools/TensorFlow"/>
<use name="tensorflow-cc"/>
<use name="tensorflow"/>
<use name="protobuf"/>
<use name="Eigen"/>
<use name="RecoBTag/TensorFlow"/>
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
LIBRARY := SUHH2Delphes2UHH2Converter
LHAPDFINC=$(shell scram tool tag lhapdf INCLUDE)
LHAPDFLIB=$(shell scram tool tag LHAPDF LIBDIR)
TFLOWLIB= $(shell scram tool tag tensorflow LIBDIR)
TFLOWINC= $(shell scram tool tag tensorflow INCLUDE)
PBUFLIB= $(shell scram tool tag protobuf LIBDIR)
PBUFINC= $(shell scram tool tag protobuf INCLUDE)
EigenINC= $(shell scram tool tag Eigen INCLUDE)
USERCXXFLAGS := -I${LHAPDFINC} -I/cvmfs/cms.cern.ch/${SCRAM_ARCH}/cms/cmssw/${CMSSW_VERSION}/src -I${TFLOWINC} -I${PBUFINC} -I${EigenINC}
USERLDFLAGS := -lSUHH2core -lSUHH2common -lGenVector -lSUHH2JetMETObjects -L${LHAPDFLIB} -lLHAPDF -L/cvmfs/cms.cern.ch/${SCRAM_ARCH}/cms/cmssw/${CMSSW_VERSION}/lib/${SCRAM_ARCH} -lPhysicsToolsTensorFlow -L${TFLOWLIB} -ltensorflow_framework -L${PBUFLIB}
# enable par creation; this is necessary for all packages containing AnalysisModules
# to be loaded from by AnalysisModuleRunner.
PAR := 1
TEST := test
include ../Makefile.common
53 changes: 53 additions & 0 deletions config/Delphes2UHH2Converter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE JobConfiguration PUBLIC "" "JobConfig.dtd">

<!-- OutputLevel controls which messages are printed; set to VERBOSE or DEBUG for more verbosity, to WARNING or ERROR for less -->
<JobConfiguration JobName="ExampleCycleJob" OutputLevel="INFO">
<Library Name="libSUHH2Delphes2UHH2Converter"/>
<Package Name="SUHH2Delphes2UHH2Converter.par" />

<Cycle Name="uhh2::AnalysisModuleRunner" OutputDirectory="./" PostFix="" TargetLumi="1" >

<!-- Verion attribute must have year in it, same as used in ntuple config, e.g. 2018, 2016v3, etc -->

<InputData Lumi="1" NEventsMax="10" Type="MC" Version="Example_2018" Cacheable="False">
<In FileName="Delphes2UHH2Converter/Delphes2UHH2ConverterTree.root" Lumi="0.0"/>
<InputTree Name="UHH2TreeFromDelphes" />
</InputData>

<!--
<InputData Lumi="1" NEventsMax="10" Type="MC" Version="Example_2018" Cacheable="False">
<In FileName="test_input/Ntuple_UHH2_TTZ.root" Lumi="0.0"/>
<InputTree Name="AnalysisTree" />
</InputData>
-->

<UserConfig>

<Item Name="PrimaryVertexCollection" Value="offlineSlimmedPrimaryVertices" />
<Item Name="ElectronCollection" Value="slimmedElectronsUSER" />
<Item Name="MuonCollection" Value="slimmedMuonsUSER" />
<Item Name="JetCollection" Value="jetsAk4CHS" />
<Item Name="GenJetCollection" Value="slimmedGenJets" />
<Item Name="METName" Value="slimmedMETs" />


<!-- the class name of the AnalysisModule subclasses to run: -->
<Item Name="AnalysisModule" Value="Delphes2UHH2ConverterModule" />

<!-- tell AnalysisModuleRunner NOT to use the MC event weight from SFrame; rather let
MCLumiWeight (called via CommonModules) calculate the MC event weight. The MC
event weight assigned by MCLumiWeight is InputData.Lumi / Cycle.TargetLumi. -->
<Item Name="use_sframe_weight" Value="false" />

<!-- configuration for MCPileupReweight (run as part of CommonModules): -->
<Item Name="pileup_directory" Value="common/data/2018/MyMCPileupHistogram.root" />
<Item Name="pileup_directory_data" Value="common/data/2018/MyDataPileupHistogram2018.root" />

<!--
<Item Name="readTrigger" Value="false" />
-->

</UserConfig>
</Cycle>
</JobConfiguration>
109 changes: 109 additions & 0 deletions config/JobConfig.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- ======================================================================= -->
<!-- @Project: SFrame - ROOT-based analysis framework for ATLAS -->
<!-- @Package: User -->
<!-- -->
<!-- @author Stefan Ask <[email protected]> - Manchester -->
<!-- @author David Berge <[email protected]> - CERN -->
<!-- @author Johannes Haller <[email protected]> - Hamburg -->
<!-- @author A. Krasznahorkay <[email protected]> - CERN/Debrecen -->
<!-- -->
<!-- This is the dtd that can be used to configure an SFrame job -->
<!-- -->
<!-- ======================================================================= -->

<!ELEMENT JobConfiguration ((PyLibrary|Library|Package)*,Cycle+) >
<!ATTLIST JobConfiguration
JobName CDATA #REQUIRED
OutputLevel CDATA "INFO"
>

<!ELEMENT PyLibrary EMPTY>
<!ATTLIST PyLibrary
Name CDATA #REQUIRED
>

<!ELEMENT Library EMPTY>
<!ATTLIST Library
Name CDATA #REQUIRED
>

<!ELEMENT Package EMPTY>
<!ATTLIST Package
Name CDATA #REQUIRED
>

<!ELEMENT Cycle (InputData+,UserConfig?)>
<!ATTLIST Cycle
Name CDATA #REQUIRED
TargetLumi CDATA #REQUIRED
OutputDirectory CDATA "./"
PostFix CDATA ""
RunMode (LOCAL|PROOF) "LOCAL"
ProofServer CDATA ""
ProofWorkDir CDATA ""
ProofNodes CDATA "-1"
UseTreeCache (True|False|1|0) "False"
TreeCacheSize CDATA "30000000"
TreeCacheLearnEntries CDATA "100"
ProcessOnlyLocal (True|False|1|0) "False"
>

<!ELEMENT InputData ((GeneratorCut|DataSet|In|InputTree|OutputTree|
MetadataInputTree|MetadataOutputTree)*) >
<!ATTLIST InputData
Type CDATA #REQUIRED
Version CDATA #REQUIRED
Lumi CDATA "0.0"
NEventsMax CDATA "-1"
NEventsSkip CDATA "0"
Cacheable (True|False) "False"
SkipValid (True|False) "False"
>

<!ELEMENT GeneratorCut EMPTY>
<!ATTLIST GeneratorCut
Tree CDATA #REQUIRED
Formula CDATA #REQUIRED
>

<!ELEMENT DataSet EMPTY>
<!ATTLIST DataSet
Name CDATA #REQUIRED
Lumi CDATA #REQUIRED
>

<!ELEMENT In EMPTY>
<!ATTLIST In
FileName CDATA #REQUIRED
Lumi CDATA #REQUIRED
>

<!ELEMENT OutputTree EMPTY>
<!ATTLIST OutputTree
Name CDATA #REQUIRED
>

<!ELEMENT InputTree EMPTY>
<!ATTLIST InputTree
Name CDATA #REQUIRED
>

<!ELEMENT MetadataInputTree EMPTY>
<!ATTLIST MetadataInputTree
Name CDATA #REQUIRED
>

<!ELEMENT MetadataOutputTree EMPTY>
<!ATTLIST MetadataOutputTree
Name CDATA #REQUIRED
>

<!ELEMENT UserConfig (Item*)>

<!ELEMENT Item EMPTY>
<!ATTLIST Item
Name CDATA #REQUIRED
Value CDATA #REQUIRED
>
Binary file added data/Example_DelphesTree.root
Binary file not shown.
23 changes: 23 additions & 0 deletions include/Delphes2UHH2ConverterHists.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "UHH2/core/include/Hists.h"

namespace uhh2examples {

/** \brief Example class for booking and filling histograms
*
* NOTE: This class uses the 'hist' method to retrieve histograms.
* This requires a string lookup and is therefore slow if you have
* many histograms. Therefore, it is recommended to use histogram
* pointers as member data instead, like in 'common/include/ElectronHists.h'.
*/
class Delphes2UHH2ConverterHists: public uhh2::Hists {
public:
// use the same constructor arguments as Hists for forwarding:
Delphes2UHH2ConverterHists(uhh2::Context & ctx, const std::string & dirname);

virtual void fill(const uhh2::Event & ev) override;
virtual ~Delphes2UHH2ConverterHists();
};

}
22 changes: 22 additions & 0 deletions include/Delphes2UHH2ConverterSelections.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "UHH2/core/include/fwd.h"
#include "UHH2/core/include/Selection.h"

namespace uhh2examples {

/* Select events with at least two jets in which the leading two jets have deltaphi > 2.7 and the third jet pt is
* below 20% of the average of the leading two jets, where the minimum deltaphi and
* maximum third jet pt fraction can be changed in the constructor.
* The jets are assumed to be sorted in pt.
*/
class DijetSelection: public uhh2::Selection {
public:
DijetSelection(float dphi_min = 2.7f, float third_frac_max = 0.2f);
virtual bool passes(const uhh2::Event & event) override;
private:
float dphi_min, third_frac_max;
};


}
59 changes: 59 additions & 0 deletions include/InputTreeProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <iostream>
#include <vector>

#include "TChain.h"
#include "TString.h"

#include "UHH2/Delphes2UHH2Converter/include/Reader.h"



class InputTreeProcessor {
public:
InputTreeProcessor(const TString& file_name, const TString& tree_name);

void add_reader(Reader* reader) {
reader->set_chain(m_chain);
m_readers.push_back(reader);
}

bool operator()(int n_max_evts = -1) {
return load_next_event(n_max_evts);
}
bool load_next_event(int n_max_evts = -1);


private:
TChain* m_chain;
long m_entry;
std::vector<Reader*> m_readers;
};


InputTreeProcessor::InputTreeProcessor(const TString& file_name, const TString& tree_name)
: m_entry(-1) {
std::cout << "Setting up TChain '" << tree_name << "' from '" << file_name << "'" << std::endl;
m_chain = new TChain(tree_name);
m_chain->Add(file_name);
}


bool InputTreeProcessor::load_next_event(int n_max_evts) {
m_entry++;
if( m_entry == n_max_evts ) {
return false;
}
if( m_entry % 2 == 0 ) {
std::cout << "Processing event " << m_entry << std::endl;
}
if( m_chain->GetEntry(m_entry) ) {
for(auto& reader: m_readers) {
reader->read();
}
return true;
} else {
return false;
}
}
77 changes: 77 additions & 0 deletions include/JetReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#pragma once

#include <vector>

#include "UHH2/core/include/Jet.h"
#include "UHH2/Delphes2UHH2Converter/include/Reader.h"


class JetReader : public Reader {
public:
JetReader(std::vector<Jet> &jets);

void read();

protected:
void init();

private:
std::vector<Jet>& m_jets;

std::vector<float> *m_jet_pt;
std::vector<float> *m_jet_eta;
std::vector<float> *m_jet_phi;
std::vector<float> *m_jet_mass;
std::vector<int> *m_jet_btag;
std::vector<int> *m_jet_flavor;
};

JetReader::JetReader(std::vector<Jet> &jets)
: m_jets(jets) {
m_jet_pt = 0;
m_jet_eta = 0;
m_jet_phi = 0;
m_jet_mass = 0;
m_jet_btag = 0;
m_jet_flavor = 0;
}

void JetReader::init() {
m_chain->SetBranchAddress("jet_pt",&m_jet_pt);
m_chain->SetBranchAddress("jet_eta",&m_jet_eta);
m_chain->SetBranchAddress("jet_phi",&m_jet_phi);
m_chain->SetBranchAddress("jet_mass",&m_jet_mass);
m_chain->SetBranchAddress("jet_btag",&m_jet_btag);
m_chain->SetBranchAddress("jet_flavor",&m_jet_flavor);
}

void JetReader::read() {
m_jets.clear();

for(size_t i = 0; i < m_jet_pt->size(); ++i) {
Jet jet;

// Kinematic properties, well defined
jet.set_pt( m_jet_pt->at(i) );
jet.set_eta( m_jet_eta->at(i) );
jet.set_phi( m_jet_phi->at(i) );

// b-tagging: in Delphes tree, we have 0 or 1 (which tagger?)
// Put some sensible translation:
if( m_jet_btag->at(i) == 1 ) {
jet.set_btag_DeepFlavour_probb( 1. );
jet.set_btag_DeepCSV_probb( 1. );
} else {
jet.set_btag_DeepFlavour_probb( 0. );
jet.set_btag_DeepCSV_probb( 0. );
}

// Need to check which flavour definition is used in Delphes
jet.set_pdgId( m_jet_flavor->at(i) );
jet.set_partonFlavour( m_jet_flavor->at(i) );
jet.set_hadronFlavour( m_jet_flavor->at(i) );

// Store Jet object in collection written to output file
m_jets.push_back(jet);
}
}
Loading

0 comments on commit 2577ed4

Please sign in to comment.