Skip to content

Commit

Permalink
Merge pull request #177 from alspellm/ana_dev_pr_20230726
Browse files Browse the repository at this point in the history
Merger of 3 different development branches into one PR
  • Loading branch information
cbravo135 authored Sep 20, 2023
2 parents 1125397 + fc75cc8 commit 2b7824e
Show file tree
Hide file tree
Showing 53 changed files with 9,628 additions and 422 deletions.
412 changes: 412 additions & 0 deletions analysis/data/beamspot_positions_2016.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions analysis/include/BaseSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class BaseSelector {
*/
void clearSelector() { passSelection = true; }

protected:
typedef std::map<std::string, std::pair<double, int>>::iterator cut_it; //!< description
std::map<std::string,std::pair<double, int>> cuts; //!< description
bool debug_{false}; //!< description

private:
json _h_selections; //!< description
Expand All @@ -151,16 +155,13 @@ class BaseSelector {
//string: cutname
//double: cutvalue
//int : cut id (for cut flow book-keeping)
std::map<std::string,std::pair<double, int>> cuts; //!< description
std::map<std::string,std::string> labels; //!< description

bool debug_{false}; //!< description
int ncuts_{0}; //!< description
std::shared_ptr<TH1F> h_cf_; //!< description

bool passSelection{false}; //!< description

typedef std::map<std::string, std::pair<double, int>>::iterator cut_it; //!< description

};

#endif
101 changes: 101 additions & 0 deletions analysis/include/IterativeCutSelector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#ifndef ITERATIVECUTSELECTOR_H
#define ITERATIVECUTSELECTOR_H

#include <string>
#include <iostream>
#include <map>
#include <memory>
#include "BaseSelector.h"

#include "TH1F.h"
#include "json.hpp"

// for convenience
using json = nlohmann::json;

/**
* @brief brief description
*
* more details
*/
class IterativeCutSelector : public BaseSelector {

public:

IterativeCutSelector();

IterativeCutSelector(const std::string& inputName);

IterativeCutSelector(const std::string& inputName, const std::string& cfgFile);

virtual ~IterativeCutSelector();

/**
* @brief get cut variable from name
*
* @param cutname
*/
std::string getCutVar(std::string cutname);

/**
* @brief is cut of type 'greater than'
*
* @param cutname
* @return true
* @return false
*/
bool isCutGreaterThan(std::string cutname);

/**
* @brief set cut value
*
* @param cutname
* @param value
*/
void setCutValue(std::string cutname, double value);

/**
* @brief does value pass cut
*
* @param cutname
* @param val
* @return true
* @return false
*/
bool passCutGTorLT(std::string cutname, double val);

/**
* @brief prints cuts and values
*
*/
void printCuts();

/**
* @brief get cut ID
* @param cutname
* @return cut ID
*
*/
int getCutID(std::string cutname){return cuts[cutname].second;};

/**
* @brief remove cuts that aren't specified in the list of cut
* variables
* @param cut_variables_list
*
*/
void filterCuts(std::vector<std::string> cut_variable_list);

/**
* @brief get pointer to the base class cuts
*
*/
std::map<std::string, std::pair<double,int>>* getPointerToCuts(){ return &cuts; }


private:
//When this variable value is encountered, do not apply cut to event
double skipCutVarValue_ = -9876543210.0; //Must match definition in MutableTTree
};

#endif
118 changes: 118 additions & 0 deletions analysis/include/MutableTTree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#ifndef MUTABLE_TTREE_H
#define MUTABLE_TTREE_H

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <TTree.h>
#include <TFile.h>
#include <TBranch.h>
#include <functional>

/**
* @brief Reads flat TTree and allows user to create new variables in the TTree
*/
class MutableTTree {

public:

MutableTTree(TFile* infile, std::string tree_name);

/**
* @brief return number of entries in tree
*/
int GetEntries(){return tree_->GetEntries();}

/**
* @brief get tree entry
* @param entry
*/
void GetEntry(int entry){tree_->GetEntry(entry);}

/**
* @brief Fill ttree with new variables included
*/
void Fill();

/**
* @brief Apply any corrections to specified variable
* @param variable
* @param correction/shift
*/
void shiftVariable(std::string variable, double shift);

/**
* @brief Get the value of a flat tuple variable
* @param branch_name
* @return value
*/
double getValue(std::string branch_name);

/**
* @brief Print TTree Event
*/
void printEvent();

/**
* @brief Set branch value
* @param branch_name
* @param value
*/
void setBranchValue(std::string branch_name, double value){*tuple_[branch_name] = value;}

/**
* @brief Add new branch to ttree
* @param branch
*/
void addNewBranch(std::string branch);

/**
* @brief Set the mass window within which to read the input ttree
* @param lowMass
* @param highMass
*/
void defineMassWindow(double lowMass, double highMass);

/**
* @brief Get list of all variables defined in ttree
*/
std::vector<std::string> getAllVariables();

/**
* @brief Check if a variable exists in the ttree
* @param variable
* @return true
* @return false
*/
bool variableExists(std::string variable);

~MutableTTree();

protected:
TTree* tree_{nullptr}; //!< flat ttree
TTree* newtree_{nullptr}; //!< temporary ttree used to create and fill new branches
std::map<std::string,double*> tuple_; //!< holds all variables and values
std::map<std::string,TBranch*> new_branches; //!< list of new branches added to ttree
std::map<std::string, double*> new_variables_;//!< list of new variables
std::map<std::string,std::function<double()>> functions_;//!< functions that calculate new variables
std::map<std::string,std::function<double()>> variable_shifts_;//!< variable corrections

private:
/**
* @brief read in the initial flat TTree
* @param tree
* @param tuple_map
*/
void initializeFlatTuple(TTree* tree, std::map<std::string, double*> &tuple_map);

/**
* @brief copy the TTree
*/
void copyTTree();

double lowMass_{-999.9};//!< mass window low
double highMass_{-999.9};//!< mass window high
};

#endif // __MUTABLE_TTREE_H
75 changes: 75 additions & 0 deletions analysis/include/SimpAnaTTree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef SIMP_ANA_TTREE_H
#define SIMP_ANA_TTREE_H

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <TTree.h>
#include <TFile.h>
#include <TBranch.h>

#include "MutableTTree.h"

/**
*@brief Read in flat TTree and create new cut variables for SIMP analysis
*/
class SimpAnaTTree : public MutableTTree {

public:

SimpAnaTTree(TFile* infile, std::string tree_name) : MutableTTree(infile,tree_name){};
~SimpAnaTTree();

/**
*@brief New Variables
*/
/*
void addVariable_unc_vtx_zalpha(double y_intercept, double slope, double alpha_z);
void addVariable_unc_vtx_zbravo();
void addVariable_unc_vtx_zbravoAlpha(double slope);
void addVariable_unc_vtx_zbravosum();
void addVariable_unc_vtx_zbravosumAlpha(double slope);
void addVariable_unc_vtx_ZalphaTop(double slope);
void addVariable_unc_vtx_ZalphaBot(double slope);
void addVariable_unc_vtx_ZalphaTopBot(double top_slope, double bot_slope);
void addVariable_unc_vtx_ZbravoAlphaTop(double slope);
void addVariable_unc_vtx_ZbravoAlphaBot(double slope);
void addVariable_unc_vtx_ZalphaBotEle(double slope);
void addVariable_unc_vtx_ZalphaTopEle(double slope);
void addVariable_unc_vtx_ZalphaTopPos(double slope);
void addVariable_unc_vtx_ZalphaBotPos(double slope);
*/

void addVariable_unc_vtx_ele_zalpha(double slope);
void addVariable_unc_vtx_pos_zalpha(double slope);
void addVariable_unc_vtx_zalpha_max(double slope);
void addVariable_unc_vtx_zalpha_min(double slope);

void addVariable_unc_vtx_ele_iso_z0err();
void addVariable_unc_vtx_pos_iso_z0err();
void addVariable_unc_vtx_ele_z0_z0err();
void addVariable_unc_vtx_pos_z0_z0err();
void addVariable_unc_vtx_ele_isolation_cut();
void addVariable_unc_vtx_pos_isolation_cut();

void addVariable_unc_vtx_ele_z0tanlambda();
void addVariable_unc_vtx_pos_z0tanlambda();
void addVariable_unc_vtx_ele_z0tanlambda_right(double slope);
void addVariable_unc_vtx_pos_z0tanlambda_right(double slope);
void addVariable_unc_vtx_ele_z0tanlambda_left(double slope);
void addVariable_unc_vtx_pos_z0tanlambda_left(double slope);

void addVariable_unc_vtx_abs_delta_z0tanlambda();

//misc
bool impactParameterCut2016Canonical(double mass);
bool testImpactParameterCut();

private:
double skipCutVarValue_ = -9876543210.0;//<! if cut variable is not defined for an event, assign this value
};

#endif // __SIMP_ANA_TTREE_H
Loading

0 comments on commit 2b7824e

Please sign in to comment.