Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
muonid::MuonIDProd Class Reference
Inheritance diagram for muonid::MuonIDProd:
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

 MuonIDProd (fhicl::ParameterSet const &pset)
 
virtual ~MuonIDProd ()
 
void produce (art::Event &evt)
 
void beginJob () override
 
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
 

Private Member Functions

void Init ()
 

Private Attributes

std::string fWeightFile
 BDT Weights from training. More...
 
std::string fBDTLabel
 Title of BDT in weight training file. More...
 
std::string fTrackLabel
 Where to find reconstructed tracks. More...
 
std::string fTrackInfoLabel
 TrackInfoObj label. More...
 
std::string fRemidLabel
 Where to find the remid. More...
 
bool trainfileloaded
 
TMVA::Reader * fReader
 
float dedxllh
 
float scatllh
 
float avgdedxlast10cm
 
float avgdedxlast40cm
 Objects for BDT calculation to use. More...
 

Detailed Description

Definition at line 40 of file MuonIDProd_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

muonid::MuonIDProd::MuonIDProd ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 67 of file MuonIDProd_module.cc.

References fBDTLabel, fRemidLabel, fTrackInfoLabel, fTrackLabel, fWeightFile, fhicl::ParameterSet::get(), and string.

67  :
68  trainfileloaded(false),
69  fReader(NULL),
70  dedxllh(-999),
71  scatllh(-999),
72  avgdedxlast10cm(-999),
73  avgdedxlast40cm(-999)
74  {
75  fWeightFile = pset.get<std::string>("WeightFile");
76  fBDTLabel = pset.get<std::string>("BDTLabel");
77  fTrackLabel = pset.get<std::string>("TrackLabel");
78  fTrackInfoLabel = pset.get<std::string>("TrackInfoLabel");
79  fRemidLabel = pset.get<std::string>("RemidLabel");
80 
81  produces < std::vector < muonid::MuonID > > ();
82  produces < art::Assns < muonid::MuonID, rb::Track > > ();
83  }
std::string fTrackInfoLabel
TrackInfoObj label.
std::string fTrackLabel
Where to find reconstructed tracks.
TMVA::Reader * fReader
std::string fWeightFile
BDT Weights from training.
float avgdedxlast40cm
Objects for BDT calculation to use.
std::string fRemidLabel
Where to find the remid.
std::string fBDTLabel
Title of BDT in weight training file.
enum BeamMode string
muonid::MuonIDProd::~MuonIDProd ( )
virtual

Definition at line 87 of file MuonIDProd_module.cc.

References fReader.

87  {
88  if (fReader) { delete fReader; }
89  }
TMVA::Reader * fReader

Member Function Documentation

void muonid::MuonIDProd::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 180 of file MuonIDProd_module.cc.

References DEFINE_ART_MODULE(), and Init().

180  {
181  Init();
182  }
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
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  }
void muonid::MuonIDProd::Init ( )
private

Definition at line 93 of file MuonIDProd_module.cc.

References avgdedxlast10cm, avgdedxlast40cm, dedxllh, allTimeWatchdog::endl, util::EnvExpansion(), cet::file_exists(), fReader, fWeightFile, scatllh, string, and trainfileloaded.

Referenced by beginJob(), and produce().

94  {
95  // Book Method
96  if (!trainfileloaded) {
97  // Locate weight file
98  std::string xmlFileName = util::EnvExpansion("$SRT_PRIVATE_CONTEXT/") + fWeightFile;
99  mf::LogDebug("MuonID") << "Checking in SRT PRIVATE for " << xmlFileName << std::endl;
100  if (!cet::file_exists(xmlFileName)){
101  xmlFileName = util::EnvExpansion("$SRT_PUBLIC_CONTEXT/") + fWeightFile;
102  mf::LogDebug("MuonID") << "Checking in SRT PUBLIC for " << xmlFileName << std::endl;
103  if (!cet::file_exists(xmlFileName))
104  throw cet::exception("MuonIDProd") << "MuonID Train file " << fWeightFile << " not found" << std::endl;
105  }
106 
107  // Set up the TMVA::Reader to read in MVA weight file
108  fReader = new TMVA::Reader();
109 
110  // Add the pid variables
111  fReader->AddVariable("DedxLL", &dedxllh);
112  fReader->AddVariable("ScatLL", &scatllh);
113  fReader->AddVariable("Avededxlast10cm", &avgdedxlast10cm);
114  fReader->AddVariable("Avededxlast40cm", &avgdedxlast40cm);
115 
116  // Book the MVA
117  fReader->BookMVA("BDTG", xmlFileName);
118  trainfileloaded = true;
119  }
120  }
TMVA::Reader * fReader
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
std::string fWeightFile
BDT Weights from training.
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
float avgdedxlast40cm
Objects for BDT calculation to use.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
bool file_exists(std::string const &qualified_filename)
enum BeamMode string
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 muonid::MuonIDProd::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 124 of file MuonIDProd_module.cc.

References trackinfo::TrackInfoObj::AvedEdxTrackLast10cm(), trackinfo::TrackInfoObj::AvedEdxTrackLast40cm(), avgdedxlast10cm, avgdedxlast40cm, util::CreateAssn(), dedxllh, remid::ReMId::DedxSeparation(), allTimeWatchdog::endl, fBDTLabel, check_time_usage::float, fReader, fRemidLabel, fTrackInfoLabel, fTrackLabel, art::DataViewImpl::getByLabel(), Init(), std::min(), art::Event::put(), scatllh, remid::ReMId::ScatSeparation(), rb::PID::SetVal(), and track.

124  {
125  Init();
126 
127  std::unique_ptr<std::vector<muonid::MuonID>> pidcol(new std::vector <muonid::MuonID>);
128  std::unique_ptr<art::Assns<muonid::MuonID, rb::Track>> assncol(new art::Assns <muonid::MuonID, rb::Track>);
129 
130  // Load the tracks
132  evt.getByLabel(fTrackLabel, tracklist);
133 
134  // Load the remid and info
135  art::FindOneP<remid::ReMId> remidTracks(tracklist, evt, fRemidLabel);
136  art::FindOneP<trackinfo::TrackInfoObj> infoTracks(tracklist, evt, fTrackInfoLabel);
137 
138  for(unsigned int itrack = 0; itrack < tracklist->size(); ++itrack)
139  {
140  // MuonID Object to fill
141  MuonID muid(13, -999); // Default to PDG 13 (muon), -999 (value)
142 
143  // Track Ptr for Assns
144  const art::Ptr<rb::Track> track(tracklist, itrack);
145 
146  // Load remid and track info
147  const art::Ptr<remid::ReMId> trackremid = remidTracks.at(itrack);
148  const art::Ptr<trackinfo::TrackInfoObj> trackinfoobj = infoTracks.at(itrack);
149 
150  // Fill and evaluate the BDT
151  dedxllh = trackremid->DedxSeparation();
152  scatllh = trackremid->ScatSeparation();
153  avgdedxlast10cm = std::min(trackinfoobj->AvedEdxTrackLast10cm(), float(30.));
154  avgdedxlast40cm = std::min(trackinfoobj->AvedEdxTrackLast40cm(), float(30.));
155 
156  // Skip calculation if remid failed, or unphysical values
157  if(avgdedxlast10cm < 0 || avgdedxlast40cm < 0)
158  mf::LogDebug("Skipping MuonIDProd") << "Skipping muonid calculation due to invalid remid or unphysical values" << std::endl;
159  else
160  {
161  float muonidval = fReader->EvaluateMVA(fBDTLabel);
162  if(muonidval > -1.0 && muonidval < 1.0){
163  muid.SetVal(muonidval);
164  }
165  else
166  mf::LogWarning("Invalid MuonID") << "Invalid MuonID calculated (outside valid range)" <<
167  "\n\nMuonID = " << muonidval << std::endl;
168  }
169 
170  pidcol->push_back(muid);
171  util::CreateAssn(*this, evt, *(pidcol.get()), track, *(assncol.get()));
172 
173  } // end of loop over slice
174 
175  evt.put(std::move(pidcol));
176  evt.put(std::move(assncol));
177  }
std::string fTrackInfoLabel
TrackInfoObj label.
std::string fTrackLabel
Where to find reconstructed tracks.
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.
TMVA::Reader * fReader
double ScatSeparation() const
Return the scattering separation variable used as an input to the kNN that determines the pid value...
Definition: ReMId.cxx:206
Definition: event.h:19
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
float AvedEdxTrackLast40cm() const
Definition: TrackInfoObj.h:32
float avgdedxlast40cm
Objects for BDT calculation to use.
float MuonID(const caf::SRProxy *sr)
Definition: MuonID.cxx:51
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string fRemidLabel
Where to find the remid.
T min(const caf::Proxy< T > &a, T b)
Float_t track
Definition: plot.C:35
double DedxSeparation() const
Return the dE/dx separation variable used as an input to the kNN that determines the pid value...
Definition: ReMId.cxx:199
std::string fBDTLabel
Title of BDT in weight training file.
float AvedEdxTrackLast10cm() const
Definition: TrackInfoObj.h:29
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

float muonid::MuonIDProd::avgdedxlast10cm
private

Definition at line 62 of file MuonIDProd_module.cc.

Referenced by Init(), and produce().

float muonid::MuonIDProd::avgdedxlast40cm
private

Objects for BDT calculation to use.

Definition at line 62 of file MuonIDProd_module.cc.

Referenced by Init(), and produce().

float muonid::MuonIDProd::dedxllh
private

Definition at line 62 of file MuonIDProd_module.cc.

Referenced by Init(), and produce().

std::string muonid::MuonIDProd::fBDTLabel
private

Title of BDT in weight training file.

Definition at line 55 of file MuonIDProd_module.cc.

Referenced by MuonIDProd(), and produce().

TMVA::Reader* muonid::MuonIDProd::fReader
private

Definition at line 61 of file MuonIDProd_module.cc.

Referenced by Init(), produce(), and ~MuonIDProd().

std::string muonid::MuonIDProd::fRemidLabel
private

Where to find the remid.

Definition at line 58 of file MuonIDProd_module.cc.

Referenced by MuonIDProd(), and produce().

std::string muonid::MuonIDProd::fTrackInfoLabel
private

TrackInfoObj label.

Definition at line 57 of file MuonIDProd_module.cc.

Referenced by MuonIDProd(), and produce().

std::string muonid::MuonIDProd::fTrackLabel
private

Where to find reconstructed tracks.

Definition at line 56 of file MuonIDProd_module.cc.

Referenced by MuonIDProd(), and produce().

std::string muonid::MuonIDProd::fWeightFile
private

BDT Weights from training.

Definition at line 54 of file MuonIDProd_module.cc.

Referenced by Init(), and MuonIDProd().

float muonid::MuonIDProd::scatllh
private

Definition at line 62 of file MuonIDProd_module.cc.

Referenced by Init(), and produce().

bool muonid::MuonIDProd::trainfileloaded
private

Definition at line 60 of file MuonIDProd_module.cc.

Referenced by Init().


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