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

Avoid frtree to be written in plots.root + other updates for standalone workflow (samples and only initialStep for BH, STD and CE builds) #328

Merged
merged 13 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
137 changes: 127 additions & 10 deletions mkFit/buildtestMPlex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,53 @@ namespace
// runBuildTestPlexDumbCMSSW
//==============================================================================

void runBuildingTestPlexDumbCMSSW(Event& ev, const EventOfHits &eoh, MkBuilder& builder)
void runBuildingTestPlexDumbCMSSW(Event& ev, const EventOfHits &eoh, MkBuilder& builder, int n)
{
MkJob job( { Config::TrkInfo, Config::ItrInfo[0], eoh } );

builder.begin_event(&job, &ev, __func__);
const IterationConfig &itconf = Config::ItrInfo[0];

if (Config::sim_val_for_cmssw) {
builder.root_val_dumb_cmssw();
if (n<1) // if no multi-iter, only consider initialStep (to minimize time and size)
{
TrackVec seeds1;
unsigned int algorithms[]={ 4 }; //only initialStep

for (auto &s : ev.seedTracks_)
{
//keep seeds form the first iteration for processing
if ( std::find(algorithms, algorithms+1, s.algoint())!=algorithms+1 ) seeds1.push_back(s);
}
ev.seedTracks_.swap(seeds1);
ev.relabel_bad_seedtracks();
}

// To disable hit-masks, pass nullptr in place of &mask_ifc to MkJob ctor
// and optionally comment out ev.fill_hitmask_bool_vectors() call.

if (n<1){
IterationMaskIfc mask_ifc;
ev.fill_hitmask_bool_vectors(itconf.m_track_algorithm, mask_ifc.m_mask_vector);

MkJob job( { Config::TrkInfo, itconf, eoh, &mask_ifc } );

builder.begin_event(&job, &ev, __func__);

if (Config::sim_val_for_cmssw) {
builder.root_val_dumb_cmssw();
}

builder.end_event();
}
else{
MkJob job( { Config::TrkInfo, itconf, eoh, nullptr } );

builder.begin_event(&job, &ev, __func__);

if (Config::sim_val_for_cmssw) {
builder.root_val_dumb_cmssw();
}

builder.end_event();
}

builder.end_event();
}

//==============================================================================
Expand All @@ -136,7 +172,34 @@ void runBuildingTestPlexDumbCMSSW(Event& ev, const EventOfHits &eoh, MkBuilder&

double runBuildingTestPlexBestHit(Event& ev, const EventOfHits &eoh, MkBuilder& builder)
{
MkJob job( { Config::TrkInfo, Config::ItrInfo[0], eoh } );

const IterationConfig &itconf = Config::ItrInfo[0];

const bool validation_on = (Config::sim_val || Config::quality_val);

if (validation_on)
{
TrackVec seeds1;

unsigned int algorithms[]={ 4 }; //only initialStep

for (auto &s : ev.seedTracks_)
{
//keep seeds form the first iteration for processing
if ( std::find(algorithms, algorithms+1, s.algoint())!=algorithms+1 ) seeds1.push_back(s);
}
ev.seedTracks_.swap(seeds1);//necessary for the validation - PrepareSeeds
ev.relabel_bad_seedtracks();//necessary for the validation - PrepareSeeds
}

IterationMaskIfc mask_ifc;

// To disable hit-masks, pass nullptr in place of &mask_ifc to MkJob ctor
// and optionally comment out ev.fill_hitmask_bool_vectors() call.

ev.fill_hitmask_bool_vectors(itconf.m_track_algorithm, mask_ifc.m_mask_vector);

MkJob job( { Config::TrkInfo, itconf, eoh, &mask_ifc } );

builder.begin_event(&job, &ev, __func__);

Expand Down Expand Up @@ -200,7 +263,34 @@ double runBuildingTestPlexBestHit(Event& ev, const EventOfHits &eoh, MkBuilder&

double runBuildingTestPlexStandard(Event& ev, const EventOfHits &eoh, MkBuilder& builder)
{
MkJob job( { Config::TrkInfo, Config::ItrInfo[0], eoh } );

const IterationConfig &itconf = Config::ItrInfo[0];

const bool validation_on = (Config::sim_val || Config::quality_val);

if (validation_on)
{
TrackVec seeds1;

unsigned int algorithms[]={ 4 }; //only initialStep

for (auto &s : ev.seedTracks_)
{
//keep seeds form the first iteration for processing
if ( std::find(algorithms, algorithms+1, s.algoint())!=algorithms+1 ) seeds1.push_back(s);
}
ev.seedTracks_.swap(seeds1);//necessary for the validation - PrepareSeeds
ev.relabel_bad_seedtracks();//necessary for the validation - PrepareSeeds
}

IterationMaskIfc mask_ifc;

// To disable hit-masks, pass nullptr in place of &mask_ifc to MkJob ctor
// and optionally comment out ev.fill_hitmask_bool_vectors() call.

ev.fill_hitmask_bool_vectors(itconf.m_track_algorithm, mask_ifc.m_mask_vector);

MkJob job( { Config::TrkInfo, itconf, eoh, &mask_ifc } );

builder.begin_event(&job, &ev, __func__);

Expand Down Expand Up @@ -263,7 +353,34 @@ double runBuildingTestPlexStandard(Event& ev, const EventOfHits &eoh, MkBuilder&

double runBuildingTestPlexCloneEngine(Event& ev, const EventOfHits &eoh, MkBuilder& builder)
{
MkJob job( { Config::TrkInfo, Config::ItrInfo[0], eoh } );

const IterationConfig &itconf = Config::ItrInfo[0];

const bool validation_on = (Config::sim_val || Config::quality_val);

if (validation_on)
{
TrackVec seeds1;

unsigned int algorithms[]={ 4 }; //only initialStep

for (auto &s : ev.seedTracks_)
{
//keep seeds form the first iteration for processing
if ( std::find(algorithms, algorithms+1, s.algoint())!=algorithms+1 ) seeds1.push_back(s);
}
ev.seedTracks_.swap(seeds1);//necessary for the validation - PrepareSeeds
ev.relabel_bad_seedtracks();//necessary for the validation - PrepareSeeds
}

IterationMaskIfc mask_ifc;

// To disable hit-masks, pass nullptr in place of &mask_ifc to MkJob ctor
// and optionally comment out ev.fill_hitmask_bool_vectors() call.

ev.fill_hitmask_bool_vectors(itconf.m_track_algorithm, mask_ifc.m_mask_vector);

MkJob job( { Config::TrkInfo, itconf, eoh, &mask_ifc } );

builder.begin_event(&job, &ev, __func__);

Expand Down
3 changes: 2 additions & 1 deletion mkFit/buildtestMPlex.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace mkfit {
class IterationConfig;
class MkBuilder;

void runBuildingTestPlexDumbCMSSW (Event& ev, const EventOfHits &eoh, MkBuilder& builder);
void runBuildingTestPlexDumbCMSSW (Event& ev, const EventOfHits &eoh, MkBuilder& builder, int n);

double runBuildingTestPlexBestHit (Event& ev, const EventOfHits &eoh, MkBuilder& builder);
double runBuildingTestPlexStandard (Event& ev, const EventOfHits &eoh, MkBuilder& builder);
double runBuildingTestPlexCloneEngine(Event& ev, const EventOfHits &eoh, MkBuilder& builder);
Expand Down
2 changes: 1 addition & 1 deletion mkFit/mkFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void test_standard()
t_cur[3] = (g_run_build_all || g_run_build_ce) ? runBuildingTestPlexCloneEngine(ev, eoh, mkb) : 0;
if(g_run_build_all || g_run_build_mimi) t_cur_iter = runBtpCe_MultiIter(ev, eoh, mkb, Config::nItersCMSSW);
t_cur[4] = (g_run_build_all || g_run_build_mimi)? t_cur_iter[Config::nItersCMSSW] : 0 ;
if (g_run_build_all || g_run_build_cmssw) runBuildingTestPlexDumbCMSSW(ev, eoh, mkb);
if (g_run_build_all || g_run_build_cmssw) runBuildingTestPlexDumbCMSSW(ev, eoh, mkb, Config::nItersCMSSW);
t_cur[2] = (g_run_build_all || g_run_build_std) ? runBuildingTestPlexStandard(ev, eoh, mkb) : 0;
if (g_run_build_ce){
ncands_thisthread = mkb.total_cands();
Expand Down
53 changes: 17 additions & 36 deletions plotting/PlotValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
// h at the start == a different string version

PlotValidation::PlotValidation(const TString & inName, const TString & outName, const Bool_t cmsswComp, const int algo,
const Bool_t mvInput, const Bool_t saveAs, const TString & outType)
const Bool_t mvInput, const Bool_t rmSuffix, const Bool_t saveAs, const TString & outType)
: fInName(inName), fOutName(outName), fCmsswComp(cmsswComp), fAlgo(algo),
fMvInput(mvInput), fSaveAs(saveAs), fOutType(outType)
fMvInput(mvInput), fRmSuffix(rmSuffix), fSaveAs(saveAs), fOutType(outType)
{
// Setup
PlotValidation::SetupStyle();
if (fAlgo>0) fOutName=fOutName+"_iter"+algo;
if (fAlgo>0 && !fRmSuffix) fOutName=fOutName+"_iter"+algo;
PlotValidation::MakeOutDir(fOutName);
PlotValidation::SetupBins();
PlotValidation::SetupCommonVars();
Expand All @@ -47,13 +47,18 @@ PlotValidation::PlotValidation(const TString & inName, const TString & outName,
std::cerr << "File: " << fInName.Data() << " does not exist!!! Exiting..." << std::endl;
exit(1);
}

gROOT->cd();
efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree"));
frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree"));
if(algo>0) frtree=frtree->CopyTree(Form("algorithm==%i",algo));
// make output root file
fOutRoot = new TFile(fOutName+"/plots.root", "RECREATE");
}

PlotValidation::~PlotValidation()
{
delete efftree;
delete frtree;
delete fInRoot;
delete fOutRoot; // will delete all pointers to subdirectory
}
Expand All @@ -76,12 +81,6 @@ void PlotValidation::Validation(int algo)
// Loop over efficiency tree: produce efficiency, inefficiency per region of tracker, and duplicate rate
void PlotValidation::PlotEffTree(int algo)
{
//////////////
// Get tree //
//////////////

auto efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree"));

////////////////////////////////////////////
// Declare strings for branches and plots //
////////////////////////////////////////////
Expand Down Expand Up @@ -276,15 +275,14 @@ void PlotValidation::PlotEffTree(int algo)
{
const auto refmask_trk = refmask_trks [j];
const auto duplmask_trk = duplmask_trks[j];
const auto itermask_trk = itermask_trks[j];
const auto iterduplmask_trk = iterduplmask_trks[j];

const auto effIteration = algo>0?((itermask_trk>>algo)&1):1;
const auto oneIteration = algo>0?((iterduplmask_trk>>algo)&1):1;
const auto ineffIteration = algo>0?(((itermask_trk>>algo)&1) == 0):(refmask_trk == 0);
const auto seedalgo_flag = (algoseed_trk>0 && algo>0)?((algoseed_trk>>algo)&1):1;
//if (algoseed_trk>0) std::cout << algoseed_trk << " "<<algo <<" "<< seedalgo_flag<<" "<<effIteration<< std::endl;
//effIteration=effIteration&&seedalgo_flag;
const auto itermask_trk = itermask_trks[j];
const auto iterduplmask_trk = iterduplmask_trks[j];

const auto effIteration = algo>0?((itermask_trk>>algo)&1):1;
const auto oneIteration = algo>0?((iterduplmask_trk>>algo)&1):1;
const auto ineffIteration = algo>0?(((itermask_trk>>algo)&1) == 0):(refmask_trk == 0);
const auto seedalgo_flag = (algoseed_trk>0 && algo>0)?((algoseed_trk>>algo)&1):1;

// plot key base
const TString basekey = Form("%i_%i_%i",i,j,k);

Expand Down Expand Up @@ -356,20 +354,11 @@ void PlotValidation::PlotEffTree(int algo)
} // end loop over tracks
} // end loop over variables

// delete efficiency tree
delete efftree;
}

// loop over fake rate tree, producing fake rate, nHits/track, score, and kinematic diffs to cmssw
void PlotValidation::PlotFRTree(int algo)
{
//////////////
// Get tree //
//////////////

auto frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree"));
if(algo>0) frtree=frtree->CopyTree(Form("algorithm==%i",algo));

////////////////////////////////////////////
// Declare strings for branches and plots //
////////////////////////////////////////////
Expand Down Expand Up @@ -781,18 +770,13 @@ void PlotValidation::PlotFRTree(int algo)
} // end loop over pt cuts
} // end loop over tracks

// delete fake rate tree
delete frtree;
}

void PlotValidation::PrintTotals(int algo)
{
///////////////////////////////////////////////
// Get number of events and number of tracks //
///////////////////////////////////////////////
auto efftree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswefftree":"efftree"));
auto frtree = (TTree*)fInRoot->Get((fCmsswComp?"cmsswfrtree":"frtree"));
if(algo>0) frtree=frtree->CopyTree(Form("algorithm==%i",algo));

Int_t Nevents = 0;
Int_t evtID = 0; TBranch * b_evtID = 0; efftree->SetBranchAddress("evtID",&evtID,&b_evtID);
Expand All @@ -808,9 +792,6 @@ void PlotValidation::PrintTotals(int algo)
const Int_t NtracksReco = frtree->GetEntries();
const Float_t ntkspevReco = Float_t(NtracksReco) / Float_t(Nevents);

delete frtree;
delete efftree;

////////////////////////////////////////////////////////////////////////////////////////////////////////
// Print out totals of nHits, frac of Hits shared, track score, eff, FR, DR rate of seeds, build, fit //
// --> numer/denom plots for phi, know it will be in the bounds. //
Expand Down
7 changes: 5 additions & 2 deletions plotting/PlotValidation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PlotValidation
{
public:
PlotValidation(const TString & inName, const TString & outName, const Bool_t cmsswComp,const int algo,
const Bool_t mvInput, const Bool_t saveAs, const TString & outType);
const Bool_t mvInput, const Bool_t rmSuffix, const Bool_t saveAs, const TString & outType);
~PlotValidation();

// setup functions
Expand Down Expand Up @@ -84,14 +84,17 @@ private:
const TString fInName;
const Bool_t fCmsswComp;
const Bool_t fMvInput;
const Bool_t fRmSuffix;
const Bool_t fSaveAs;
const TString fOutType;

const int fAlgo;

// main input
TFile * fInRoot;

TTree * efftree;
TTree * frtree;

// binning for rate plots
DblVec fPtBins;
DblVec fEtaBins;
Expand Down
4 changes: 2 additions & 2 deletions plotting/runValidation.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "plotting/PlotValidation.cpp+"

void runValidation(const TString & test = "", const Bool_t cmsswComp = false, const int algo = 0, const Bool_t mvInput = true,
void runValidation(const TString & test = "", const Bool_t cmsswComp = false, const int algo = 0, const Bool_t mvInput = true, const Bool_t rmSuffix = true,
const Bool_t saveAs = false, const TString & image = "pdf")
{
// PlotValidation arguments
Expand All @@ -11,6 +11,6 @@ void runValidation(const TString & test = "", const Bool_t cmsswComp = false, co
// Third Bool is saving the image files
// Last argument is output type of plots

PlotValidation Val(Form("valtree%s.root",test.Data()),Form("validation%s",test.Data()),cmsswComp,algo,mvInput,saveAs,image);
PlotValidation Val(Form("valtree%s.root",test.Data()),Form("validation%s",test.Data()),cmsswComp,algo,mvInput,rmSuffix,saveAs,image);
Val.Validation(algo);
}
Loading