Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev russell #13

Merged
merged 4 commits into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions RJigsawTools/RJigsawCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,51 @@
#include "xAODMissingET/MissingET.h"

#include <unordered_map>
#include <iostream>

class RJigsawCalculator {

private :

public :


virtual ~RJigsawCalculator() = 0;


virtual EL::StatusCode initialize() = 0;
private :
enum ClearEventCalled {
NOTCALLED = 0,
CALLED = 1
};

ClearEventCalled m_clearEventCalled ;

public :
EL::StatusCode initialize(){m_clearEventCalled = CALLED;return doInitialize();}
//to be used per event
virtual EL::StatusCode clearEvent() = 0 ;
virtual EL::StatusCode calculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET & met
) = 0;
EL::StatusCode clearEvent(){m_clearEventCalled = CALLED;return doClearEvent();}
EL::StatusCode calculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET & met
){
if(m_clearEventCalled == NOTCALLED){
std::cout << "You didn't call clearEvent ! Exiting." << std::endl;
return EL::StatusCode::FAILURE;
}
m_clearEventCalled = NOTCALLED;
return doCalculate( RJVars,
particles,
met);
}

private :
//todo probably clean this up
virtual EL::StatusCode doInitialize(){std::cout << "you called the base calculator function! Exiting" << std::endl;return EL::StatusCode::FAILURE;};
virtual EL::StatusCode doClearEvent(){std::cout << "you called the base calculator function! Exiting" << std::endl;return EL::StatusCode::FAILURE;};
virtual EL::StatusCode doCalculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET& met
){std::cout << "you called the base calculator function! Exiting" << std::endl;return EL::StatusCode::FAILURE;};


public :
// this is needed to distribute the algorithm to the workers
ClassDef(RJigsawCalculator, 1);

Expand Down
20 changes: 8 additions & 12 deletions RJigsawTools/RJigsawCalculator_lvlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RJigsawCalculator_lvlv : public RJigsawCalculator {

public :
RJigsawCalculator_lvlv();
virtual ~RJigsawCalculator_lvlv ();
virtual ~RJigsawCalculator_lvlv ();

private :
RestFrames::LabGenFrame * LAB_G;
Expand Down Expand Up @@ -68,17 +68,13 @@ private :
double m_mL;
double m_mN;


public :

virtual EL::StatusCode initialize();

//to be used per event
virtual EL::StatusCode clearEvent();
virtual EL::StatusCode calculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET& met
);
private :
virtual EL::StatusCode doInitialize();
virtual EL::StatusCode doClearEvent();
virtual EL::StatusCode doCalculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET& met
);
// this is needed to distribute the algorithm to the workers
ClassDef(RJigsawCalculator_lvlv, 1);
};
Expand Down
15 changes: 7 additions & 8 deletions Root/RJigsawCalculator_lvlv.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ RJigsawCalculator_lvlv :: ~RJigsawCalculator_lvlv() {
delete ContraBoostJigsaw_R;
}

EL::StatusCode RJigsawCalculator_lvlv::clearEvent() {
EL::StatusCode RJigsawCalculator_lvlv::doClearEvent() {
if(! LAB_G->ClearEvent()){return EL::StatusCode::FAILURE;}
if(! LAB_R->ClearEvent()){return EL::StatusCode::FAILURE;}

return EL::StatusCode::SUCCESS;
}

EL::StatusCode RJigsawCalculator_lvlv::initialize() {
EL::StatusCode RJigsawCalculator_lvlv::doInitialize() {
using namespace RestFrames;

m_mH = 125.;
Expand Down Expand Up @@ -185,12 +185,11 @@ EL::StatusCode RJigsawCalculator_lvlv::initialize() {
return EL::StatusCode::SUCCESS;
}

EL::StatusCode RJigsawCalculator_lvlv::calculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET& met
){


EL::StatusCode RJigsawCalculator_lvlv::doCalculate(std::unordered_map<std::string, double>& RJVars,
xAOD::IParticleContainer& particles,
xAOD::MissingET& met
){
//todo check the initialization

// generate event
double PTH = m_mH*gRandom->Rndm();
Expand Down
2 changes: 1 addition & 1 deletion cmt/Makefile.RootCore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PACKAGE_BINFLAGS =
PACKAGE_LIBFLAGS =

# the list of packages we depend on:
PACKAGE_DEP = EventLoop Ext_RestFrames SUSYTools TauAnalysisTools CommonTools xAODMissingET
PACKAGE_DEP = EventLoop Ext_RestFrames SUSYTools TauAnalysisTools CommonTools xAODMissingET Asg_GoogleTest

# the list of packages we use if present, but that we can work without :
PACKAGE_TRYDEP =
Expand Down
55 changes: 55 additions & 0 deletions test/ut_rjigsawcalculator_lvlv_test.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//author : Russell Smith
//date : December 2015
//adapted from Code from Nils Krumnack

#include <RJigsawTools/RJigsawCalculator_lvlv.h>

#include <RootCoreUtils/Assert.h>
#include <TSystem.h>
#include <cstdlib>
#include <fstream>
#include <gtest/gtest.h>

#include <unordered_map>
#include <xAODMissingET/MissingET.h>
#include <xAODJet/JetContainer.h>

struct RJigsawCalculator_lvlv_Test : testing::Test
{
static const std::string root;

static void SetUpTestCase ()
{
// gSystem->MakeDirectory ((root + "").c_str());
// std::ofstream ((root + "/file.root_17").c_str());
// std::ofstream ((root + "/ignore").c_str());
// gSystem->MakeDirectory ((root + "/sample").c_str());
// std::ofstream ((root + "/sample/samplefile.root").c_str());
// gSystem->MakeDirectory ((root + "/deepsample").c_str());
// gSystem->MakeDirectory ((root + "/deepsample/subdir").c_str());
// std::ofstream ((root + "/deepsample/subdir/deepfile.root").c_str());
}
};
const std::string RJigsawCalculator_lvlv_Test::root = "test1";

TEST (RJigsawCalculator_lvlv_Test, clearEventTest)
{
RJigsawCalculator_lvlv calc;
calc.initialize();

std::unordered_map<std::string, double> mymap;
xAOD::JetContainer jets;
xAOD::MissingET met;


EXPECT_TRUE( calc.calculate(mymap, jets, met) == EL::StatusCode::SUCCESS ) ;//the first event is fine no matter what
EXPECT_TRUE( calc.clearEvent() == EL::StatusCode::SUCCESS );//clear event should work
EXPECT_TRUE( calc.calculate(mymap, jets, met) == EL::StatusCode::SUCCESS ) ;//after clearing everything works fine
EXPECT_TRUE( calc.calculate(mymap, jets, met) == EL::StatusCode::FAILURE ) ;//calling calculate twice fails!
}

int main (int argc, char **argv)
{
::testing::InitGoogleTest (&argc, argv);
return RUN_ALL_TESTS();
}