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

Several items: fixed crop, new cc-inclusive and cosmic filter, tree_index accessor for ProcessDriver #36

Merged
merged 7 commits into from
May 29, 2016
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
20 changes: 13 additions & 7 deletions app/APICaffe/SimpleFiller.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,20 @@ namespace larcv {
int coldiff = std::max(0,(int)(image_v.front().meta().cols()-_crop_cols));
int rowdiff = std::max(0,(int)(image_v.front().meta().rows()-_crop_rows));

if ( coldiff>0 ) {
std::uniform_int_distribution<> irand_col(0,coldiff);
col_offset = irand_col(gen);
}
if ( _randomize_crop ) {
if ( coldiff>0 ) {
std::uniform_int_distribution<> irand_col(0,coldiff);
col_offset = irand_col(gen);
}

if ( rowdiff>0 ) {
std::uniform_int_distribution<> irand_row(0,rowdiff);
row_offset = irand_row(gen);
if ( rowdiff>0 ) {
std::uniform_int_distribution<> irand_row(0,rowdiff);
row_offset = irand_row(gen);
}
}
else {
if ( coldiff>0 ) col_offset = (int)coldiff/2;
if ( rowdiff>0 ) row_offset = (int)rowdiff/2;
}
//LARCV_DEBUG() << "Cropping. col offset=" << col_offset << " row offset=" << row_offset << std::endl;
img_rows = image_v.front().meta().rows();
Expand Down
22 changes: 11 additions & 11 deletions app/APICaffe/ThreadDatumFiller.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,25 @@ namespace larcv {
}
else if(entry >= _driver.io().get_n_entries()) entry -= _driver.io().get_n_entries();

LARCV_INFO() << "Processing entry: " << entry << std::endl;
LARCV_INFO() << "Processing entry: " << entry << " (tree index=" << _driver.get_tree_index( entry ) << ")" << std::endl;

last_entry = entry;
bool good_status = _driver.process_entry(entry,true);
if(_enable_filter && !good_status) {
LARCV_INFO() << "Filter enabled: bad event found" << std::endl;
continue;
}

_batch_entries[valid_ctr] = entry;
++valid_ctr;
LARCV_INFO() << "Processed good event: valid entry counter = " << valid_ctr << std::endl;
}
_num_processed += valid_ctr;
_filler->batch_end();
_thread_running = false;
_batch_entries[valid_ctr] = _driver.get_tree_index( entry );
++valid_ctr;
LARCV_INFO() << "Processed good event: valid entry counter = " << valid_ctr << std::endl;
}
_num_processed += valid_ctr;
_filler->batch_end();
_thread_running = false;
_optional_next_index = kINVALID_SIZE;
LARCV_DEBUG() << " end" << std::endl;
return true;
LARCV_DEBUG() << " end" << std::endl;
return true;
}
}

Expand Down
7 changes: 5 additions & 2 deletions app/CalibADC/calcPeakADC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace larcv {

void calcPeakADC::configure(const PSet& cfg)
{
fImageProducer = cfg.get<std::string>("ImageProducerName");
fThreshold = cfg.get<float>("PeakThreshold");
fDeadtime = cfg.get<float>("Deadtime");
fNewCols = cfg.get<int>("NewCols",-1);
Expand All @@ -31,8 +32,10 @@ namespace larcv {
bool calcPeakADC::process(IOManager& mgr)
{

auto event_images = (larcv::EventImage2D*)mgr.get_data( larcv::kProductImage2D, "tpc" );
auto event_images = (larcv::EventImage2D*)mgr.get_data( larcv::kProductImage2D, fImageProducer );
for ( auto const& img_src : event_images->Image2DArray() ) {
//for ( int p=0; p<=8; p+=4 ) { // hack for 12 channel data
auto const& img_src = event_images->Image2DArray().at(p);
larcv::Image2D img( img_src );
if ( fNewCols>0 || fNewRows>0 )
img.compress( fNewRows, fNewCols ); //504, 864
Expand All @@ -42,7 +45,7 @@ namespace larcv {

for (int w=0; w<wfms; w++) {
bool inpeak = false;
int pmax = -1;
float pmax = -1;
int peakcenter = -1;
std::vector<int> peakcenters;

Expand Down
2 changes: 2 additions & 0 deletions app/CalibADC/calcPeakADC.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Processor/ProcessBase.h"
#include "Processor/ProcessFactory.h"

#include <string>
#include "TTree.h"
#include "TFile.h"

Expand Down Expand Up @@ -50,6 +51,7 @@ namespace larcv {
float fDeadtime;
int fNewCols;
int fNewRows;
std::string fImageProducer;

// ana output
TTree* ttree;
Expand Down
5 changes: 3 additions & 2 deletions app/CalibADC/calibadc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ProcessDriver: {

Verbosity: 0
EnableFilter: false
RandomAccess: false
RandomAccess: true
ProcessType: ["calcPeakADC"]
ProcessName: ["calcPeakADC"]
AnaFile: "ana.root"
Expand All @@ -21,7 +21,8 @@ ProcessDriver: {

ProcessList: {
calcPeakADC: {
PeakThreshold: 30.0
ImageProducerName: "tpc_12ch"
PeakThreshold: 5
Deadtime: 20
NewCols: -1
NewRows: -1
Expand Down
129 changes: 129 additions & 0 deletions app/Filter/CCIncFilter.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#ifndef __CCINCFILTER_CXX__
#define __CCINCFILTER_CXX__

#include "CCIncFilter.h"
#include "DataFormat/EventROI.h"
namespace larcv {

static CCIncFilterProcessFactory __global_CCIncFilterProcessFactory__;

CCIncFilter::CCIncFilter(const std::string name)
: ProcessBase(name)
{}

void CCIncFilter::configure(const PSet& cfg)
{
_roi_producer = cfg.get<std::string>("ROIProducer");
_shower_min_energy = cfg.get<double>("ShowerMinEnergyMeV");
_track_min_energy = cfg.get<double>("TrackMinEnergyMeV");
_proton_min_energy = cfg.get<double>("ProtonMinEnergyMeV");
_fiducial_cut_cm = cfg.get<double>("FiducialCutCM");
if ( _fiducial_cut_cm<0 )
_fiducial_cut_cm = 0.0;
}

void CCIncFilter::initialize()
{}

bool CCIncFilter::process(IOManager& mgr)
{

// get the event roi
auto ev_roi = (EventROI*)(mgr.get_data(kProductROI,_roi_producer));

// track the number of particles that satisfy our conditions


// goal: looking for "clean" CC-inclusive events
// Event must have
// (1) muon present
// (2) proton or shower with minium energy deposition
// (3) vertex in fiducial volume

bool has_muon = false;
bool has_proton = false;
bool has_shower = false;
bool fv_vertex = false;
bool has_mc = false;

for(auto const& roi : ev_roi->ROIArray()) {


if ( roi.Type()==larcv::kROIBNB ) {
// BNB ROI
double x = roi.X();
double y = roi.Y();
double z = roi.Z();
LARCV_INFO() << "Vertex: " << x << ", " << y << ", " << z << std::endl;
if ( (x>(0+_fiducial_cut_cm) && x<(250-_fiducial_cut_cm) )
&& (y!=0 && y>(-117+_fiducial_cut_cm) && y<(117-_fiducial_cut_cm))
&& ( z>(0+_fiducial_cut_cm) && z<(1025-_fiducial_cut_cm) ) ) {
fv_vertex = true;
}
}

// not an MC particle ROI
if(roi.MCSTIndex() == kINVALID_USHORT) continue;

// shower ROI
if( roi.PdgCode() == 11 || roi.PdgCode() == -11 || roi.PdgCode() == 22 || roi.PdgCode() == 111 ) {
if ( roi.EnergyDeposit() < _shower_min_energy ) {
LARCV_INFO() << "Ignoring Shower (PdgCode=" << roi.PdgCode() << ") with energy " << roi.EnergyDeposit() << std::endl;
continue;
}
else {
has_shower = true;
LARCV_INFO() << "Accepting Shower (PdgCode=" << roi.PdgCode() << ") with energy " << roi.EnergyDeposit() << std::endl;
}
}
// proton ROI
else if(roi.PdgCode() == 2212) {
if ( roi.EnergyDeposit() < _proton_min_energy) {
LARCV_INFO() << "Ignoring Proton with energy " << roi.EnergyDeposit() << std::endl;
continue;
}
else {
has_proton = true;
LARCV_INFO() << "Accepting Proton with energy " << roi.EnergyDeposit() << std::endl;
}
}
else if ( roi.PdgCode()==13 || roi.PdgCode()==-13 ) {
if ( roi.EnergyDeposit()<_track_min_energy ) {
LARCV_INFO() << "Ignoring muon with energy " << roi.EnergyDeposit() << std::endl;
continue;
}
else {
has_muon = true;
LARCV_INFO() << "Accepting muon with energy " << roi.EnergyDeposit() << std::endl;
}
}
// use track for moun replacement? // covers proton, muon, pion
// else if(roi.Shape() == kShapeTrack && roi.EnergyDeposit() < _track_min_energy) {

// LARCV_INFO() << "Ignoring TRACK (PdgCode=" << roi.PdgCode() << ") with energy " << roi.EnergyDeposit() << std::endl;
// continue;

// }

//LARCV_INFO() << "Counting particle (PdgCode=" << roi.PdgCode() << ") with energy " << roi.EnergyDeposit() << std::endl;

//++part_ctr;

}

bool keep = (has_muon && (has_proton || has_shower) && fv_vertex );
if ( keep ) {
LARCV_INFO() << "Keeping Event" << std::endl;
}
else {
LARCV_INFO() << "Reject Event (mu=" << has_muon << ", proton=" << has_proton << ", shower=" << has_shower << ", vtx=" << fv_vertex << ")" << std::endl;
}

return keep;
}

void CCIncFilter::finalize()
{}

}
#endif
71 changes: 71 additions & 0 deletions app/Filter/CCIncFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* \file CCIncFilter.h
*
* \ingroup Package_Name
*
* \brief Class def header for a class CCIncFilter
*
* @author drinkingkazu
*/

/** \addtogroup Package_Name

@{*/
#ifndef __MCSINGLEPARTICLEFILTER_H__
#define __MCSINGLEPARTICLEFILTER_H__

#include "Processor/ProcessBase.h"
#include "Processor/ProcessFactory.h"
namespace larcv {

/**
\class ProcessBase
User defined class CCIncFilter ... these comments are used to generate
doxygen documentation!
*/
class CCIncFilter : public ProcessBase {

public:

/// Default constructor
CCIncFilter(const std::string name="CCIncFilter");

/// Default destructor
~CCIncFilter(){}

void configure(const PSet&);

void initialize();

bool process(IOManager& mgr);

void finalize();

private:

std::string _roi_producer;
double _shower_min_energy;
double _track_min_energy;
double _proton_min_energy;
double _fiducial_cut_cm;
};

/**
\class larcv::CCIncFilterFactory
\brief A concrete factory class for larcv::CCIncFilter
*/
class CCIncFilterProcessFactory : public ProcessFactoryBase {
public:
/// ctor
CCIncFilterProcessFactory() { ProcessFactory::get().add_factory("CCIncFilter",this); }
/// dtor
~CCIncFilterProcessFactory() {}
/// creation method
ProcessBase* create(const std::string instance_name) { return new CCIncFilter(instance_name); }
};

}

#endif
/** @} */ // end of doxygen group

50 changes: 50 additions & 0 deletions app/Filter/CosmicFilter.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef __COSMICFILTER_CXX__
#define __COSMICFILTER_CXX__

#include "CosmicFilter.h"
#include "DataFormat/EventROI.h"
#include "TRandom3.h"

namespace larcv {

static CosmicFilterProcessFactory __global_CosmicFilterProcessFactory__;

CosmicFilter::CosmicFilter(const std::string name)
: ProcessBase(name)
{}

void CosmicFilter::configure(const PSet& cfg)
{
_roi_producer = cfg.get<std::string>("ROIProducer");
_thinning_factor = cfg.get<double>("ThinningFactor", -1.0);
_rand = new TRandom3(123456);
}

void CosmicFilter::initialize()
{}

bool CosmicFilter::process(IOManager& mgr)
{
if(!_roi_producer.empty()) {
auto ev_roi = (EventROI*)(mgr.get_data(kProductROI,_roi_producer));
bool cosmic_only = true;
for(auto const& roi : ev_roi->ROIArray()) {
if(roi.Type()!=larcv::kROICosmic) {
cosmic_only = false;
}
}
if ( _thinning_factor>0 && _thinning_factor<=1.0 ) {
if ( cosmic_only && _rand->Uniform()<_thinning_factor ) return true;
}
else {
if (cosmic_only) return true;
}
}
return false;
}

void CosmicFilter::finalize()
{}

}
#endif
Loading