Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
xnue::XnuePID Class Reference
Inheritance diagram for xnue::XnuePID:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 XnuePID (fhicl::ParameterSet const &pset)
 
virtual ~XnuePID ()
 
void beginJob ()
 
void produce (art::Event &evt)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Protected Attributes

std::string fXnueWeightFile
 Xnue weight file name. More...
 
std::string fSliceLabel
 Label for slices. More...
 
std::string fProngLabel
 Label for prong. More...
 
std::string fInstLabel3D
 Instance label for 3d prongs. More...
 
std::string fInstLabel2D
 Instance label for 2d prongs. More...
 
std::string fVertexLabel
 Label for vertex. More...
 
std::vector< Float_t > fInputVarsXnue
 Vector of the variables that are input for TMVA. More...
 
TMVA::Reader * fbdtXnue
 Reader for Xnue15. More...
 
std::string fbdtXnueMethodName
 

Private Member Functions

rb::RecoHit MakeRecoHit (art::Ptr< rb::CellHit > const &chit, float const &w)
 
bool bookVariables (const std::string &weight_file, TMVA::Reader &xnue, std::string &method_name)
 Book xnue reader. More...
 
std::vector< std::stringgetVarNamesFromXML (const std::string weights_file_name) const
 Method to get Variable names from XML. More...
 
std::string getMethodNameFromXML (const std::string weights_file_name, const bool get_full_name=true) const
 Get TMVA method name from XML. More...
 

Detailed Description

Definition at line 54 of file XnuePID_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

xnue::XnuePID::XnuePID ( fhicl::ParameterSet const &  pset)
explicit

Reserve the number of variables to be something big

Expand fcl input path to BDTs

Add BDT path to the files

Definition at line 94 of file XnuePID_module.cc.

References util::EnvExpansion(), fInputVarsXnue, fInstLabel2D, fInstLabel3D, fProngLabel, fSliceLabel, fVertexLabel, fXnueWeightFile, fhicl::ParameterSet::get(), and string.

94  :
95  fbdtXnue (new TMVA::Reader())
96  {
97  /// Reserve the number of variables to be something big
98  fInputVarsXnue.reserve(10000);
99 
100  fXnueWeightFile = util::EnvExpansion(pset.get< std::string >("XnueWeightFile") );
101  fSliceLabel = pset.get< std::string >("SliceLabel");
102  fProngLabel = pset.get< std::string >("ProngLabel");
103  fInstLabel3D = pset.get< std::string >("InstLabel3D");
104  fInstLabel2D = pset.get< std::string >("InstLabel2D");
105  fVertexLabel = pset.get< std::string >("VertexLabel");
106 
107  /// Expand fcl input path to BDTs
108  //std::string bdtpath = util::EnvExpansion(bdt);
109  /// Add BDT path to the files
110  //fXnueWeightFile = bdtpath + fXnueWeightFile;
111 
112 
113  produces< std::vector<xnue::Xnue> >();
114  produces< art::Assns<xnue::Xnue,rb::Cluster> >();
115 
116  }
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
std::vector< Float_t > fInputVarsXnue
Vector of the variables that are input for TMVA.
std::string fProngLabel
Label for prong.
TMVA::Reader * fbdtXnue
Reader for Xnue15.
std::string fInstLabel3D
Instance label for 3d prongs.
std::string fXnueWeightFile
Xnue weight file name.
std::string fInstLabel2D
Instance label for 2d prongs.
std::string fVertexLabel
Label for vertex.
std::string fSliceLabel
Label for slices.
enum BeamMode string
xnue::XnuePID::~XnuePID ( )
virtual

Definition at line 119 of file XnuePID_module.cc.

References fbdtXnue.

120  {
121  if(fbdtXnue) delete fbdtXnue;
122  }
TMVA::Reader * fbdtXnue
Reader for Xnue15.

Member Function Documentation

void xnue::XnuePID::beginJob ( )
virtual

Need to set Weight file

Need to set Weight file

Reimplemented from art::EDProducer.

Definition at line 125 of file XnuePID_module.cc.

References bookVariables(), fbdtXnue, fbdtXnueMethodName, and fXnueWeightFile.

126  {
127 
129 
130  /// Need to set Weight file
131  fbdtXnueMethodName = "XnuePID ";
133 
134  /// Need to set Weight file
135  //fbdtXnue12MethodName = "Xnue12 ";
136  //bookVariables(fXnue12WeightFile, *fbdtXnue12, fbdtXnue12MethodName);
137  }
bool bookVariables(const std::string &weight_file, TMVA::Reader &xnue, std::string &method_name)
Book xnue reader.
TMVA::Reader * fbdtXnue
Reader for Xnue15.
std::string fXnueWeightFile
Xnue weight file name.
std::string fbdtXnueMethodName
bool xnue::XnuePID::bookVariables ( const std::string weight_file,
TMVA::Reader &  xnue,
std::string method_name 
)
private

Book xnue reader.

Get all variable names from the weight XML

Number of variables

Add variables to TMVA

Extract method name and add it to the current name

Book TMVA

Definition at line 471 of file XnuePID_module.cc.

References fInputVarsXnue, getMethodNameFromXML(), getVarNamesFromXML(), MECModelEnuComparisons::i, and nvars.

Referenced by beginJob().

472  {
473  /// Get all variable names from the weight XML
474  const std::vector<std::string> varnames_from_xml = getVarNamesFromXML(weight_file);
475 
476  /// Number of variables
477  const unsigned int nvars = varnames_from_xml.size();
478 
479  /// Add variables to TMVA
480  for(unsigned int i=0; i<nvars; ++i){
481  xnue.AddVariable(varnames_from_xml[i], &fInputVarsXnue[i]);
482 
483  }// end of adding variables to TMVA
484 
485  /// Extract method name and add it to the current name
486  method_name += getMethodNameFromXML(weight_file);
487 
488  /// Book TMVA
489  xnue.BookMVA(method_name, weight_file);
490 
491  return true;
492  }// end of XnuePID::bookVariables(TMVA::Reader& xnue)
std::vector< Float_t > fInputVarsXnue
Vector of the variables that are input for TMVA.
const int nvars
std::string getMethodNameFromXML(const std::string weights_file_name, const bool get_full_name=true) const
Get TMVA method name from XML.
Definition: FillPIDs.h:16
std::vector< std::string > getVarNamesFromXML(const std::string weights_file_name) const
Method to get Variable names from XML.
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
std::string xnue::XnuePID::getMethodNameFromXML ( const std::string  weights_file_name,
const bool  get_full_name = true 
) const
private

Get TMVA method name from XML.

System command to read out variables

d

< stream from system

Perform a system call of cmd with the output stream going to data

Replace stuff

If getting a full name, return now Full name is, for instance, "BDT::BDTG" Short name would be "BDTG"

Getting the short name from the full name

Tokenize the string, with a separator ";"

If the size is non-zero, add the string to the vector of arguments

Definition at line 497 of file XnuePID_module.cc.

References run_hadd::cmd, MAX_BUFFER, gen_hdf5record::names, cet::replace_all(), sep, runNovaSAM::stream, string, confusionMatrixTree::t, parsePQSLOutput::tokens, and make_true_q0q3_plots::weights_file_name.

Referenced by bookVariables().

500  {
501 
502  /// System command to read out variables
503  std::string cmd = "cat " + weights_file_name;
504  cmd += "| grep \"<MethodSetup\"";
505 
506  /// d
507  std::string data; ///< stream from system
508 
509  /// Perform a system call of cmd with the output stream going to data
510  {
511  FILE *stream;
512  char buffer[MAX_BUFFER];
513 
514  stream = popen(cmd.c_str(), "r");
515 
516  while ( fgets(buffer, MAX_BUFFER, stream) != NULL ){
517  data.append(buffer);
518  }
519  pclose(stream);
520  }// end of the system call
521 
522  /// Replace stuff
523  boost::replace_all(data, "<MethodSetup Method=", "");
524  boost::replace_all(data, ">" , "");
525  boost::replace_all(data, "\"" , "");
526  boost::replace_all(data, " " , "");
527  boost::replace_all(data, "\n" , "");
528 
529  /// If getting a full name, return now
530  /// Full name is, for instance, "BDT::BDTG"
531  /// Short name would be "BDTG"
532  if(get_full_name) return data;
533 
534 
535  /// Getting the short name from the full name
536 
537  std::vector<std::string> names;
538 
539  /// Tokenize the string, with a separator ";"
540  const boost::char_separator<char> sep(":");
541  boost::tokenizer< boost::char_separator<char> > tokens(data, sep);
542  BOOST_FOREACH (const std::string& t, tokens) {
543 
544  /// If the size is non-zero, add the string to the vector of arguments
545  if(t.size() > 0)
546  names.push_back(t);
547  }// end of loop over tokens
548 
549  std::string out_string;
550 
551  if(names.size() > 0)
552  out_string = names[names.size() - 1];
553 
554  return out_string;
555  }
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
const XML_Char const XML_Char * data
Definition: expat.h:268
bool replace_all(std::string &in, std::string const &from, std::string const &to)
Replace all occurrences of from in string with to.
string cmd
Definition: run_hadd.py:52
const char sep
#define MAX_BUFFER
for std::out
enum BeamMode string
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
std::vector< std::string > xnue::XnuePID::getVarNamesFromXML ( const std::string  weights_file_name) const
private

Method to get Variable names from XML.

System command to read out variables

d

< stream from system

Perform a system call of cmd with the output stream going to data

Replace stuff

After the replacement the string of variables have variables separated by ";"

Output vector of variables in the XML file

Tokenize the string, with a separator ";"

If the size is non-zero, add the string to the vector of arguments

Definition at line 559 of file XnuePID_module.cc.

References run_hadd::cmd, DEFINE_ART_MODULE(), ConvertToSnowGlobesInput::file_name, MAX_BUFFER, cet::replace_all(), sep, runNovaSAM::stream, string, confusionMatrixTree::t, parsePQSLOutput::tokens, and vars.

Referenced by bookVariables().

560  {
561  /// System command to read out variables
562  std::string cmd = "cat " + file_name;
563  cmd += "| grep \"Variable VarIndex=\" | awk \'{print $3}\'";
564 
565  /// d
566  std::string data; ///< stream from system
567 
568  /// Perform a system call of cmd with the output stream going to data
569  {
570  FILE *stream;
571  char buffer[MAX_BUFFER];
572 
573  stream = popen(cmd.c_str(), "r");
574 
575  while ( fgets(buffer, MAX_BUFFER, stream) != NULL ){
576  data.append(buffer);
577  }
578  pclose(stream);
579  }// end of the system call
580 
581  /// Replace stuff
582  boost::replace_all(data, "Expression=", ";");
583  boost::replace_all(data, "\"" , "");
584  boost::replace_all(data, "\n" , "");
585  boost::replace_all(data, "," , "");
586  boost::replace_all(data, " " , "");
587  /// After the replacement the string of variables have variables separated by ";"
588 
589  /// Output vector of variables in the XML file
590  std::vector<std::string> vars;
591 
592  /// Tokenize the string, with a separator ";"
593  const boost::char_separator<char> sep(";");
594  boost::tokenizer< boost::char_separator<char> > tokens(data, sep);
595  BOOST_FOREACH (const std::string& t, tokens) {
596 
597  /// If the size is non-zero, add the string to the vector of arguments
598  if(t.size() > 0)
599  vars.push_back(t);
600  }// end of loop over tokens
601 
602  return vars;
603  }
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
const XML_Char const XML_Char * data
Definition: expat.h:268
bool replace_all(std::string &in, std::string const &from, std::string const &to)
Replace all occurrences of from in string with to.
string cmd
Definition: run_hadd.py:52
const std::map< std::pair< std::string, std::string >, Variable > vars
const char sep
#define MAX_BUFFER
for std::out
enum BeamMode string
rb::RecoHit xnue::XnuePID::MakeRecoHit ( art::Ptr< rb::CellHit > const &  chit,
float const &  w 
)
private

Definition at line 140 of file XnuePID_module.cc.

References calib::Calibrator::MakeRecoHit().

142  {
144  rb::RecoHit rhit(cal->MakeRecoHit(*chit, w));
145 
146  return rhit;
147  }
rb::RecoHit MakeRecoHit(rb::CellHit const &cellhit, double w)
Calibrated quantities relying on position in the orthogonal view. To generate a rb::CellHit from a rb...
Definition: RecoHit.h:19
Float_t w
Definition: plot.C:20
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void xnue::XnuePID::produce ( art::Event evt)
virtual

Slice for the PID

Implements art::EDProducer.

Definition at line 150 of file XnuePID_module.cc.

References util::CreateAssn(), stan::math::fabs(), fbdtXnue, fbdtXnueMethodName, fInputVarsXnue, fInstLabel2D, fInstLabel3D, check_time_usage::float, fProngLabel, fSliceLabel, fVertexLabel, art::DataViewImpl::getByLabel(), rb::RecoHit::GeV(), MECModelEnuComparisons::i, ip, rb::RecoHit::IsCalibrated(), rb::IsFiltered(), rb::Cluster::IsNoise(), calib::j, geo::kXorY, nplanes, nprongs, BlessedPlots::pid, rb::CellHit::Plane(), art::Event::put(), xnue::Xnue::SetEfrac10p(), xnue::Xnue::SetEfrac2sig(), xnue::Xnue::SetEfracp2(), xnue::Xnue::SetEfracp3(), xnue::Xnue::SetEfracp4(), xnue::Xnue::SetEmaxfrac6p(), xnue::Xnue::SetP1Energy(), xnue::Xnue::SetP1Fmip(), xnue::Xnue::SetP2Fmip(), rb::PID::SetPdg(), rb::PID::SetVal(), rb::RecoHit::X(), and rb::RecoHit::Y().

151  {
152 
154 
155  typedef std::unique_ptr<std::vector<xnue::Xnue> > Xnues_t;
156  typedef std::unique_ptr<art::Assns<xnue::Xnue,rb::Cluster> > XnueAssn_t;
157  Xnues_t pidcol (new std::vector<xnue::Xnue>);
158  XnueAssn_t assncol(new art::Assns<xnue::Xnue,rb::Cluster>);
159 
160  float BDT = -1.0;//set the BDT output to -1
161 
163  evt.getByLabel(fSliceLabel, slices);
164 
165  const art::FindManyP<rb::Vertex> fmVertex (slices, evt, fVertexLabel);
166 
167  //loop over all slices
168  for(unsigned int sliceIdx = 0; sliceIdx < slices->size(); ++sliceIdx){
169 
170  if(rb::IsFiltered(evt, slices, sliceIdx)) continue;
171  const rb::Cluster& slice = (*slices)[sliceIdx];
172 
173  if(slice.IsNoise()) continue;
174 
175  //reco vertex
176  //only continue if this get by label succeeded
177  if (fmVertex.isValid()){
178  std::vector<art::Ptr<rb::Vertex>> vert = fmVertex.at(sliceIdx);
179  if (vert.size() != 1) continue;
180 
182  std::vector<art::Ptr<FUZZYKVERTEXOUTPUT>> prongs = fmProng3D.at(0);
183 
184  std::vector<art::Ptr<FUZZYKVERTEXOUTPUT>> SelectedProng;
185  //check if instance label is defined to handle sorting of prongs
186  if ((fInstLabel3D != "")&&(fInstLabel2D != "")){
187  SelectedProng = fmProng3D.at(0);
188  }
189  else{
190  for( unsigned int ip=0; ip<prongs.size(); ++ip ){
191  art::Ptr<FUZZYKVERTEXOUTPUT> current_prong = prongs[ip];
192  if(current_prong->IsNoise() ) continue;
193  if(current_prong->View() == geo::kXorY)//3D prongs
194  SelectedProng.push_back(current_prong);
195  }
196  }
197 
198  ///////////////////////////////
199  // variables
200  ///////////////////////////////
201  float prong1_energy=0.;
202  float prong1_fmip=0.;
203  float prong2_fmip=0.;
204  float prong1_Efrac_6maxplanes=0.;
205  float prong1_Efrac_plane2=0.;
206  float prong1_Efrac_plane3=0.;
207  float prong1_Efrac_plane4=0.;
208  float prong1_Efrac_10planes=0.;
209  float prong1_Efrac_2sigma=0.;
210 
211  ////////////////////////////////
212  //select most-energetic shower
213  //select sub-most-energetic shower
214  ////////////////////////////////
215  int nprongs=SelectedProng.size();
216 
217  if( nprongs>0 ){
218  //prong-level info
219  std::vector<float> pEnergy;
220  std::vector<float> pFmip;
221  std::vector<int> pNplanes;
222  pEnergy.clear();
223  pFmip.clear();
224  pNplanes.clear();
225 
226  //cell-level info
227  std::vector<unsigned int> pCellIndex;
228  std::vector<float> pCellX;
229  std::vector<float> pCellY;
230  std::vector<float> pCellE;
231  std::vector<int> pCellPlane;
232  pCellIndex.clear();
233  pCellX.clear();
234  pCellY.clear();
235  pCellE.clear();
236  pCellPlane.clear();
237 
238  for( int ip=0; ip<nprongs; ++ip ){
239 
240  float Eprong=0.;
241  int ntotal=0;
242  int nmip=0;
243  const art::Ptr<FUZZYKVERTEXOUTPUT> current_prong = SelectedProng[ip];
244  for( unsigned int icell=0; icell<current_prong->NCell(); ++icell){
245  const art::Ptr<rb::CellHit>& chit = current_prong->Cell(icell);
246  const rb::RecoHit rhit = current_prong->RecoHit(icell);
247 
248  if( !rhit.IsCalibrated() ) continue;
249 
250  pCellX.push_back(rhit.X());
251  pCellY.push_back(rhit.Y());
252  pCellE.push_back(rhit.GeV());
253  pCellIndex.push_back(ip);
254  pCellPlane.push_back(chit->Plane());
255 
256  Eprong += rhit.GeV();
257  ++ntotal;
258  //if( rhit.PECorr()>100. && rhit.PECorr()<240. ) ++nmip;
259  if( rhit.GeV()>0.0067 && rhit.GeV()<0.0161 ) ++nmip;
260  }//loop prong associated cells
261  //save each prong energy
262  pEnergy.push_back(Eprong);
263  //save total planes
264  pNplanes.push_back(current_prong->ExtentPlane());
265  //calculate and save fraction of mip for each prong
266  float fmip=0.;
267  if( ntotal>0 ) fmip = (float)nmip/ntotal;
268  pFmip.push_back(fmip);
269 
270  }//loop prongs
271  //find index for most-energetic prong
272  unsigned int Index1=-1;
273  float p1Emax=-1.;
274  for( int i=0; i<nprongs; ++i ){
275  if( pEnergy[i]>p1Emax ){
276  p1Emax = pEnergy[i];
277  Index1=i;
278  }
279  }//loop all prongs' energy
280  prong1_energy = pEnergy[Index1];
281  prong1_fmip = pFmip[Index1];
282 
283  //save leading-prong associated cell info
284  std::vector<float> p1cellX;
285  std::vector<float> p1cellY;
286  std::vector<float> p1cellE;
287  std::vector<int> p1cellPlane;
288  for(unsigned int ic=0; ic<pCellE.size(); ++ic ){
289  if( pCellIndex[ic] != Index1 ) continue;
290  p1cellX.push_back(pCellX[ic]);
291  p1cellY.push_back(pCellY[ic]);
292  p1cellE.push_back(pCellE[ic]);
293  p1cellPlane.push_back(pCellPlane[ic]);
294  }//loop all cells
295 
296  int minplane=9999;
297  for(unsigned int ic=0; ic<p1cellE.size(); ++ic ){
298  if( minplane>p1cellPlane[ic] ){
299  minplane=p1cellPlane[ic];
300  }
301  }//lopp leading-prong cells
302 
303  int Nplanes_p1=pNplanes[Index1];
304  if( prong1_energy>0. ){
305  //energy in each plane
306  std::vector<float> p1PlaneEnergy;
307  p1PlaneEnergy.clear();
308  //energy in transverse road
309  double totalE_road=0.;
310 
311  for( int ip=0; ip<Nplanes_p1; ++ip ){
312  double eplane=0.;
313 
314  double cellX=0.;//energetic cell X in each plane
315  double cellY=0.;//energetic cell Y in each plane
316  double Ecell=0.;
317  double EXcell=0.;
318  double EYcell=0.;
319  std::vector<double> Xxview;
320  std::vector<double> Exview;
321  std::vector<double> Yyview;
322  std::vector<double> Eyview;
323  Xxview.clear();
324  Exview.clear();
325  Yyview.clear();
326  Eyview.clear();
327 
328  for(unsigned int ic=0; ic<p1cellE.size(); ++ic ){
329  int Dplane=p1cellPlane[ic]-minplane;
330  if( Dplane==ip ){
331  eplane += p1cellE[ic];
332 
333  Ecell += p1cellE[ic];
334  EXcell += p1cellE[ic]*p1cellX[ic];
335  EYcell += p1cellE[ic]*p1cellY[ic];
336 
337  if( p1cellPlane[ic]%2 != 0 ){
338  Xxview.push_back(p1cellX[ic]);
339  Exview.push_back(p1cellE[ic]);
340  }//in X view
341  else {
342  Yyview.push_back(p1cellY[ic]);
343  Eyview.push_back(p1cellE[ic]);
344  }//in Y view
345  }//in the plane
346  }//loop leading-prong associated cells
347  p1PlaneEnergy.push_back(eplane);
348 
349  if( Ecell>0.0 ){
350  cellX = EXcell/Ecell;
351  cellY = EYcell/Ecell;
352  }
353  int Nxviews=Xxview.size();
354  int Nyviews=Yyview.size();
355  if( Nxviews>0 ){
356  for( int ixv=0; ixv<Nxviews; ++ixv ){
357  if( fabs(Xxview[ixv]-cellX) < 2.*2. ) totalE_road+=Exview[ixv];
358  }
359  }//in X view
360  if( Nyviews>0 ){
361  for( int iyv=0; iyv<Nyviews; ++iyv ){
362  if( fabs(Yyview[iyv]-cellY) < 2.*2. ) totalE_road+=Eyview[iyv];
363  }
364  }//in Y view
365 
366  }//loop planes
367 
368  double efrac_6plane=-1.;
369  double p1_Eplane[20]={0.};//energy deposit upto 20 planes
370  int nplanes=p1PlaneEnergy.size();
371  for( int ip=0; ip<nplanes; ++ip ){
372  for( int j=0; j<20; ++j ){
373  if( ip<=j ) p1_Eplane[j]+=p1PlaneEnergy[ip];
374  }
375  if( ip<nplanes-6 ){
376  double e_frac6=(p1PlaneEnergy[ip]+p1PlaneEnergy[ip+1]+p1PlaneEnergy[ip+2]+p1PlaneEnergy[ip+3]+p1PlaneEnergy[ip+4]+p1PlaneEnergy[ip+5])/pEnergy[Index1];
377  if( efrac_6plane<e_frac6 ) efrac_6plane=e_frac6;
378  }
379  else if( nplanes<=6 ) efrac_6plane=1.;
380 
381  }//end loop for p1PlaneEnergy
382 
383  double efrac_Eplane[20]={0.};
384  for( int ip=0; ip<20; ++ip ){
385  efrac_Eplane[ip] = p1_Eplane[ip]/pEnergy[Index1];
386  }
387 
388  double efrac_plane2=0.;
389  double efrac_plane3=0.;
390  double efrac_plane4=0.;
391 
392  if( p1PlaneEnergy.size()>1 && pEnergy[Index1]>0. )
393  efrac_plane2=p1PlaneEnergy[1]/pEnergy[Index1];
394  if( p1PlaneEnergy.size()>2 && pEnergy[Index1]>0. )
395  efrac_plane3=p1PlaneEnergy[2]/pEnergy[Index1];
396  if( p1PlaneEnergy.size()>3 && pEnergy[Index1]>0. )
397  efrac_plane4=p1PlaneEnergy[3]/pEnergy[Index1];
398 
399  prong1_Efrac_6maxplanes=efrac_6plane;
400  prong1_Efrac_10planes=efrac_Eplane[9];
401  prong1_Efrac_plane2 = efrac_plane2;
402  prong1_Efrac_plane3 = efrac_plane3;
403  prong1_Efrac_plane4 = efrac_plane4;
404 
405  prong1_Efrac_2sigma = totalE_road/pEnergy[Index1];
406 
407  }//prong energy is above 0
408 
409  //find index for sub-leading prong
410  if( nprongs>1 ){
411  unsigned int Index2=-1;
412  float p2Emax=-1;
413  for(unsigned int i=0; i<pEnergy.size(); ++i ){
414  if( i == Index1 ) continue;//exclude leading prong
415  if( pEnergy[i]>p2Emax ){
416  p2Emax = pEnergy[i];
417  Index2=i;
418  }
419  }//loop all prongs' energy
420  prong2_fmip=pFmip[Index2];
421 
422  }//haveing more than 1 prongs
423 
424  }//having 3D prongs
425 
426  fInputVarsXnue[0] = (Float_t)prong2_fmip;
427  fInputVarsXnue[1] = (Float_t)prong1_Efrac_6maxplanes;
428  fInputVarsXnue[2] = (Float_t)prong1_Efrac_plane2;
429  fInputVarsXnue[3] = (Float_t)prong1_Efrac_plane3;
430  fInputVarsXnue[4] = (Float_t)prong1_Efrac_plane4;
431  fInputVarsXnue[5] = (Float_t)prong1_Efrac_10planes;
432  fInputVarsXnue[6] = (Float_t)prong1_Efrac_2sigma;
433 
434 
435  BDT = fbdtXnue->EvaluateMVA(fbdtXnueMethodName);
436 
437 
438  /// Slice for the PID
439  const art::Ptr<rb::Cluster> bestSlice(slices,sliceIdx);
440 
441  Xnue pid;
442  pid.SetVal (BDT);
443  pid.SetPdg (12);
444  pid.SetP2Fmip (fInputVarsXnue[0]);
445  pid.SetEmaxfrac6p (fInputVarsXnue[1]);
446  pid.SetEfracp2 (fInputVarsXnue[2]);
447  pid.SetEfracp3 (fInputVarsXnue[3]);
448  pid.SetEfracp4 (fInputVarsXnue[4]);
449  pid.SetEfrac10p (fInputVarsXnue[5]);
450  pid.SetEfrac2sig (fInputVarsXnue[6]);
451 
452  pid.SetP1Fmip (prong1_fmip);
453  pid.SetP1Energy (prong1_energy);
454 
455  pidcol->push_back(pid);
456 
457 
458  util::CreateAssn(*this,evt,*(pidcol.get()),bestSlice,*(assncol.get()));
459 
460 
461  }//check Assn between Vertex and Slice exists
462  }//has reco slicer
463 
464  evt.put(std::move(pidcol));
465  evt.put(std::move(assncol));
466 
467  }// end of produce
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
int nprongs
TH1F * Xnue
Definition: Xsec_final.C:59
X or Y views.
Definition: PlaneGeo.h:30
unsigned short Plane() const
Definition: CellHit.h:39
A collection of associated CellHits.
Definition: Cluster.h:47
std::vector< Float_t > fInputVarsXnue
Vector of the variables that are input for TMVA.
TString ip
Definition: loadincs.C:5
Calibrated quantities relying on position in the orthogonal view. To generate a rb::CellHit from a rb...
Definition: RecoHit.h:19
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::string fProngLabel
Label for prong.
TMVA::Reader * fbdtXnue
Reader for Xnue15.
bool IsCalibrated() const
You MUST check here before accessing PECorr, MIP or GeV.
Definition: RecoHit.cxx:35
bool IsFiltered(const art::Event &evt, art::Ptr< T > x, const std::vector< std::string > &labels)
Is this Ptr marked "filtered out"?
Definition: FilterList.h:96
const double j
Definition: BetheBloch.cxx:29
std::string fInstLabel3D
Instance label for 3d prongs.
int nplanes
Definition: geom.C:145
std::string fInstLabel2D
Instance label for 2d prongs.
std::string fVertexLabel
Label for vertex.
float GeV() const
Definition: RecoHit.cxx:69
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
float X() const
Definition: RecoHit.h:36
float Y() const
Definition: RecoHit.h:37
std::string fSliceLabel
Label for slices.
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
Definition: fwd.h:28
std::string fbdtXnueMethodName
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

TMVA::Reader* xnue::XnuePID::fbdtXnue
protected

Reader for Xnue15.

Definition at line 88 of file XnuePID_module.cc.

Referenced by beginJob(), produce(), and ~XnuePID().

std::string xnue::XnuePID::fbdtXnueMethodName
protected

Definition at line 89 of file XnuePID_module.cc.

Referenced by beginJob(), and produce().

std::vector<Float_t> xnue::XnuePID::fInputVarsXnue
protected

Vector of the variables that are input for TMVA.

Definition at line 86 of file XnuePID_module.cc.

Referenced by bookVariables(), produce(), and XnuePID().

std::string xnue::XnuePID::fInstLabel2D
protected

Instance label for 2d prongs.

Definition at line 83 of file XnuePID_module.cc.

Referenced by produce(), and XnuePID().

std::string xnue::XnuePID::fInstLabel3D
protected

Instance label for 3d prongs.

Definition at line 82 of file XnuePID_module.cc.

Referenced by produce(), and XnuePID().

std::string xnue::XnuePID::fProngLabel
protected

Label for prong.

Definition at line 81 of file XnuePID_module.cc.

Referenced by produce(), and XnuePID().

std::string xnue::XnuePID::fSliceLabel
protected

Label for slices.

Definition at line 80 of file XnuePID_module.cc.

Referenced by produce(), and XnuePID().

std::string xnue::XnuePID::fVertexLabel
protected

Label for vertex.

Definition at line 84 of file XnuePID_module.cc.

Referenced by produce(), and XnuePID().

std::string xnue::XnuePID::fXnueWeightFile
protected

Xnue weight file name.

Definition at line 79 of file XnuePID_module.cc.

Referenced by beginJob(), and XnuePID().


The documentation for this class was generated from the following file: