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

 BPFPIdMaker (fhicl::ParameterSet const &pset)
 
 ~BPFPIdMaker ()
 
void produce (art::Event &evt)
 
void reconfigure (const fhicl::ParameterSet &pset)
 
void beginRun (art::Run &run)
 
void resetVars ()
 
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 Attributes

const art::ProductToken< std::vector< rb::Cluster > > fSlicerToken
 
std::string fProngLabel
 label for module that made the prongs More...
 
std::string fProngInstance
 instance label for the prongs to be used More...
 
std::string fTrackLabel
 label for module that made the tracks More...
 
std::string fLibPath
 location of all BPF library files listed below More...
 
std::string fHistoFile
 name of dE/dx log-likelihood histogram file More...
 
std::string fMuonPIDMethod
 name of the TMVA method for the muon PID, fileName = "tmva_"+method+".xml" More...
 
std::string fPionPIDMethod
 name of the TMVA method for the pion PID, fileName = "tmva_"+method+".xml" More...
 
std::string fProtonPIDMethod
 name of the TMVA method for the proton PID, fileName = "tmva_"+method+".xml" More...
 
double fdxTOL
 lower limit for dx values to be used in dE/dx calculation More...
 
bool fPIdAsMuon
 Create a Muon PID. More...
 
bool fPIdAsPion
 Create a Pion PID. More...
 
bool fPIdAsProton
 Create a Proton PID. More...
 
std::vector< intfPartList
 List of particle types (by pdg code) to be used for PID creation. More...
 
TH2F * fdEdxVSbg [2][2]
 histo of computed dE/dx for cell hits (vs. beta*gamma) More...
 
bpfit::dEdxCalculator fdEdxCalc
 helper class for computing dEdx values More...
 
bool fBookedKNNs
 Have we yet booked the kNNs? More...
 
TMVA::Reader * fMuonPID
 TMVA reader object for the muon PID. More...
 
TMVA::Reader * fPionPID
 TMVA reader object for the pion PID – jpdavies NOT implemented yet. More...
 
TMVA::Reader * fProtonPID
 TMVA reader object for the proton PID – jpdavies NOT implemented yet. More...
 
std::map< int, TMVA::Reader * > fPartListPID
 Map of particle pdg codes to TMVA reader object for that PID. More...
 
std::map< int, std::stringfPartListPIDMethod
 Map of particle pdg codes to TMVA method for that PID. More...
 
float fLength
 track length More...
 
float fChi2T
 total chi^2 More...
 
float fdEdxLL
 dEdx LL value More...
 
float fHitRatio
 ratio of track hits to prong hits (used as a track/shower discriminator) More...
 

Detailed Description

Definition at line 58 of file BPFPIdMaker_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

bpfit::BPFPIdMaker::BPFPIdMaker ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 118 of file BPFPIdMaker_module.cc.

References fBookedKNNs, and reconfigure().

118  :
119  fSlicerToken(consumes<std::vector<rb::Cluster>>(pset.get<std::string>("SlicerLabel"))),
120  fdEdxCalc()
121  {
122 
123 
124  produces< std::vector<BPFPId> >();
125  produces< art::Assns<BPFPId, rb::Track> >();
126 
127  this->reconfigure(pset);
128 
129  fBookedKNNs = false;
130  }
bpfit::dEdxCalculator fdEdxCalc
helper class for computing dEdx values
const art::ProductToken< std::vector< rb::Cluster > > fSlicerToken
void reconfigure(const fhicl::ParameterSet &pset)
bool fBookedKNNs
Have we yet booked the kNNs?
ProductToken< T > consumes(InputTag const &)
enum BeamMode string
bpfit::BPFPIdMaker::~BPFPIdMaker ( )

Definition at line 133 of file BPFPIdMaker_module.cc.

134  {
135  //======================================================================
136  // Clean up any memory allocated by your module... ...if you dare...
137  //======================================================================
138  }

Member Function Documentation

void bpfit::BPFPIdMaker::beginRun ( art::Run run)
virtual

Reimplemented from art::EDProducer.

Definition at line 185 of file BPFPIdMaker_module.cc.

References om::cerr, allTimeWatchdog::endl, util::EnvExpansion(), fBookedKNNs, fChi2T, fdEdxLL, fdEdxVSbg, fHistoFile, fHitRatio, cet::file_exists(), fLength, fLibPath, fMuonPID, fMuonPIDMethod, fPIdAsMuon, fPIdAsPion, fPIdAsProton, fPionPID, fPionPIDMethod, fProtonPID, fProtonPIDMethod, infile, and string.

186  {
187 
188  // Interpret the env variable LibPath
190 
191  //
192  // Read in the log-likelihood histos from the input file
193  //
194  std::cerr << "BPFPIdMaker: Opening dEdX file \"" << (libpath+fHistoFile) << "\"" << std::endl;
195  if(!cet::file_exists(libpath+fHistoFile)){
196  throw cet::exception("BPFPIdMaker")
197  << "dEdX file \"" << (libpath+fHistoFile) << "\" can't be found. Got the correct bpf UPS version?" << std::endl;
198  }
199 
200 
201  TFile infile((libpath+fHistoFile).c_str());
202 
203  fdEdxVSbg[0][0] = (TH2F*)infile.FindObjectAny("fdEdxVSbg_W0_X0");
204  fdEdxVSbg[0][1] = (TH2F*)infile.FindObjectAny("fdEdxVSbg_W0_X1");
205  fdEdxVSbg[1][0] = (TH2F*)infile.FindObjectAny("fdEdxVSbg_W1_X0");
206  fdEdxVSbg[1][1] = (TH2F*)infile.FindObjectAny("fdEdxVSbg_W1_X1");
207 
208  if(fdEdxVSbg[0][0] == 0 || fdEdxVSbg[0][1] == 0 || fdEdxVSbg[1][0] == 0 || fdEdxVSbg[1][1] == 0){
209  std::cerr << "BPFPIdMaker: ERROR: Failed to find dEdX Histograms" << std::endl;
210  }
211 
212  std::cerr << "BPFPIdMaker: Closing dEdX file" << std::endl;
213 
214  infile.Close();
215 
216 
217  if(!fBookedKNNs) {
218  //
219  // Set up the TMVA reader for the muon PID.
220  //
221  if(fPIdAsMuon){
222  fMuonPID->AddVariable("length",&fLength);
223  fMuonPID->AddVariable("chi2T",&fChi2T);
224  fMuonPID->AddVariable("dEdxLL",&fdEdxLL);
225  fMuonPID->AddVariable("hitRatio",&fHitRatio);
226  std::string xmlFileName = libpath+"tmva_"+fMuonPIDMethod+".xml";
227  std::cerr << "BPFPIdMaker: Booking MuonPID MVA of type \"" << fMuonPIDMethod << "\" with weights file File \"" << xmlFileName << "\"" << std::endl;
228  if(!cet::file_exists(xmlFileName)){
229  throw cet::exception("BPFPIdMaker")
230  << "TMVA weight file \"" << (xmlFileName) << "\" can't be found. Got the correct bpf UPS version?" << std::endl;
231  }
232 
233  fMuonPID->BookMVA(fMuonPIDMethod + " Method",xmlFileName);
234  }
235  if(fPIdAsPion){
236  fPionPID->AddVariable("length",&fLength);
237  fPionPID->AddVariable("chi2T",&fChi2T);
238  fPionPID->AddVariable("dEdxLL",&fdEdxLL);
239  std::string xmlFileName = libpath+"tmva_"+fPionPIDMethod+".xml";
240  std::cerr << "BPFPIdMaker: Booking PionPID MVA of type \"" << fPionPIDMethod << "\" with weights file File \"" << xmlFileName << "\"" << std::endl;
241  if(!cet::file_exists(xmlFileName)){
242  throw cet::exception("BPFPIdMaker")
243  << "TMVA weight file \"" << (xmlFileName) << "\" can't be found. Got the correct bpf UPS version?" << std::endl;
244  }
245  fPionPID->BookMVA(fPionPIDMethod + " Method",xmlFileName);
246  }
247  if(fPIdAsProton){
248  fProtonPID->AddVariable("length",&fLength);
249  fProtonPID->AddVariable("chi2T",&fChi2T);
250  fProtonPID->AddVariable("dEdxLL",&fdEdxLL);
251  fProtonPID->AddVariable("hitRatio",&fHitRatio);
252  std::string xmlFileName = libpath+"tmva_"+fProtonPIDMethod+".xml";
253  std::cerr << "BPFPIdMaker: Booking ProtonPID MVA of type \"" << fProtonPIDMethod << "\" with weights file File \"" << xmlFileName << "\"" << std::endl;
254  if(!cet::file_exists(xmlFileName)){
255  throw cet::exception("BPFPIdMaker")
256  << "TMVA weight file \"" << (xmlFileName) << "\" can't be found. Got the correct bpf UPS version?" << std::endl;
257  }
258  fProtonPID->BookMVA(fProtonPIDMethod + " Method",xmlFileName);
259  }
260 
261  fBookedKNNs = true;
262  }
263 
264  }
float fdEdxLL
dEdx LL value
std::string fMuonPIDMethod
name of the TMVA method for the muon PID, fileName = "tmva_"+method+".xml"
std::string fProtonPIDMethod
name of the TMVA method for the proton PID, fileName = "tmva_"+method+".xml"
TMVA::Reader * fProtonPID
TMVA reader object for the proton PID – jpdavies NOT implemented yet.
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
OStream cerr
Definition: OStream.cxx:7
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
bool fPIdAsProton
Create a Proton PID.
bool fBookedKNNs
Have we yet booked the kNNs?
float fChi2T
total chi^2
TMVA::Reader * fPionPID
TMVA reader object for the pion PID – jpdavies NOT implemented yet.
std::string fHistoFile
name of dE/dx log-likelihood histogram file
TMVA::Reader * fMuonPID
TMVA reader object for the muon PID.
string infile
float fLength
track length
std::string fLibPath
location of all BPF library files listed below
bool fPIdAsMuon
Create a Muon PID.
float fHitRatio
ratio of track hits to prong hits (used as a track/shower discriminator)
bool fPIdAsPion
Create a Pion PID.
bool file_exists(std::string const &qualified_filename)
std::string fPionPIDMethod
name of the TMVA method for the pion PID, fileName = "tmva_"+method+".xml"
TH2F * fdEdxVSbg[2][2]
histo of computed dE/dx for cell hits (vs. beta*gamma)
enum BeamMode string
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  }
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 bpfit::BPFPIdMaker::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 279 of file BPFPIdMaker_module.cc.

References a, bpfit::dEdxCalculator::computeDEDX(), util::CreateAssn(), dE, DEFINE_ART_MODULE(), geo::GeometryBase::DetId(), dx, e, fChi2T, fdEdxCalc, fdEdxLL, fdEdxVSbg, fdxTOL, fHitRatio, fLength, check_time_usage::float, fPartList, fPartListPID, fPartListPIDMethod, fProngInstance, fProngLabel, fSlicerToken, fTrackLabel, geom(), art::DataViewImpl::getByToken(), bpfit::dEdxCalculator::getResults(), MECModelEnuComparisons::i, novadaq::cnv::kNEARDET, test_ParserArtEvents::log, min(), BlessedPlots::pid, art::PtrVector< T >::push_back(), art::Event::put(), resetVars(), bpfit::BPFPId::SetChi2T(), bpfit::BPFPId::SetdEdXLL(), bpfit::BPFPId::SetHitRatio(), bpfit::BPFPId::SetLength(), rb::PID::SetPdg(), rb::PID::SetVal(), string, w, W, and submit_syst::x.

280  {
281 
282  // Get the slices and put them into a more convenient container.
284  evt.getByToken(fSlicerToken, slhandle);
286  for(unsigned int i=0; i < slhandle->size(); ++i) {
287  slices.push_back(art::Ptr<rb::Cluster>(slhandle,i));
288  }
289 
290  // Create the FindMany object for getting prongs.
292 
293  // Make the required service handles...
296 
297  // Make the containers for the BPFPId objects and their associations
298  std::unique_ptr< std::vector<BPFPId> >
299  PIds(new std::vector<BPFPId>);
300  std::unique_ptr< art::Assns<BPFPId,rb::Track> > PIdTrackAssns(new art::Assns<BPFPId,rb::Track>);
301 
302 
303  // loop over all slices and get the fuzzyk 3D prongs
304  for(unsigned int islice = 0; islice < slhandle->size(); ++islice) {
305 
306  // As usual, skip the noise slice...
307  if((*slhandle)[islice].IsNoise()) continue;
308 
309  // NOTE: Currently, the fundamental object of analysis is the slice.
310  // If in the future we change things so that the fundamental object
311  // of analysis becomes the vertex, then we will have to get prongs
312  // associated with the vertex instead.
313 
314  // Reset all variables.
315  this->resetVars();
316 
317  // get the 3D prongs associated with this slice
318  std::vector< art::Ptr< rb::Prong > > prongs;
319  if(prongFMP.isValid()) prongs = prongFMP.at(islice);
320 
321  // create the FindMany object for getting tracks
322  art::FindManyP<rb::Track> trackFMP(prongs, evt, fTrackLabel);
323 
324  //////////
325  //
326  // Step 1: Determine which prong is the most muon-like.
327  //
328  //////////
329 
330  // loop over all prongs and get the tracks
331  for(unsigned int iprong = 0; iprong < prongs.size(); ++iprong) {
332 
333  // get the tracks associated with this prong
334  std::vector< art::Ptr< rb::Track > > tracks;
335  if(trackFMP.isValid()) tracks = trackFMP.at(iprong);
336 
337  // create the FindMany object for getting FitSum objects
338  art::FindManyP<rb::FitSum> fitsumFMP(tracks, evt, fTrackLabel);
339 
340  // Loop over all tracks...
341  for(unsigned int itrack = 0; itrack < tracks.size(); ++itrack) {
342 
343  // get the FitSum object associated with this track
344  std::vector< art::Ptr< rb::FitSum > > fitsums;
345  if(fitsumFMP.isValid()) fitsums = fitsumFMP.at(itrack);
346 
347  // There can be only one!!!
348  // (something went really wrong with BPF if there's not one and
349  // only one of these per track.)
350  if(fitsums.size() != 1) abort();
351 
352 
353  float LLtemp = 0.0;
354 
355  // fill in chi2 and NDOF values
356  float tempH = 0.0;
357  float tempA = 0.0;
358  float tempN = 0.0;
359  tempH = fitsums[0]->Chi2(0)+fitsums[0]->Chi2(1); // chi2 from the hits
360  tempA = fitsums[0]->Chi2(2)+fitsums[0]->Chi2(3); // chi2 from the angles
361  tempN = fitsums[0]->Ndof(0)+fitsums[0]->Ndof(1)-4; // NDOF (NOTE: currently 4 is NOT subtracted from NDOF when the fitsum object is made by BPF)
362 
363  if(tempN <= 0) continue;
364 
365  // Keep track of the relevant info...
366  fChi2T = tempH/tempN + tempA/tempN;
367  fLength = tracks[itrack]->TotalLength();
368 
369  //
370  // Calculate dE/dx for each cell the track passes through using
371  // the helper class.
372  //
373  fdEdxCalc.computeDEDX(tracks[itrack],fitsums[0]->PDG());
374 
375  std::vector<double> dE;
376  std::vector<double> dx;
377  std::vector<double> W;
378  std::vector<double> BG;
379  std::vector<double> s; // this is a throw away variable...
380 
381  fdEdxCalc.getResults(dE,dx,W,BG,s,fdxTOL);
382 
383  //
384  // Compute the de/dx likelihood values for all cells.
385  //
386  for(unsigned int a = 0; a < dE.size(); ++a) {
387 
388  unsigned int w = 0;
389  unsigned int x = 0;
390 
391  if(W[a] > 0.0) w = 1;
392  if(dx[a] > 8.0) x = 1;
393 
394  // For the NearDet, we will just the "close to the readout end" FarDet histos.
395  if(geom->DetId() == novadaq::cnv::kNEARDET) w = 1;
396 
397  double content = fdEdxVSbg[w][x]->GetBinContent(fdEdxVSbg[w][x]->FindBin(log(BG[a]),dE[a]/dx[a]));
398  // We can't take the log of zero, so put a minimum on it.
399  if(content < 1.0e-9) content = 1.0e-9;
400  LLtemp += log(content);
401 
402  }
403 
404  if(dE.size() > 0) {
405  // Keep track of the relevant info...
406  fdEdxLL = LLtemp/(float)dE.size();
407  // NOTE: For this ratio, the number of hits on the track is taken to be the
408  // number of hits for which a value of dE/dx was successfully calculated.
409  fHitRatio = (float)dE.size()/(float)prongs[iprong]->NCell();
410  }
411  // end computing dE/dx LL info...
412 
413  BPFPId this_bpfpid;
414  this_bpfpid.SetPdg(fitsums[0]->PDG());
415  this_bpfpid.SetLength(fLength);
416  this_bpfpid.SetChi2T(fChi2T);
417  this_bpfpid.SetdEdXLL(fdEdxLL);
418  this_bpfpid.SetHitRatio(fHitRatio);
419 
420  // For now, this energy estimator only uses information from the muon track fit.
421  // jpdavies - correction - we will build in the ability to carry out the pion and proton PIDs as well
422  int this_pdg = std::numeric_limits<int>::min();
423  for(size_t part_index=0; part_index<fPartList.size();part_index++){
424  if(fitsums[0]->PDG() == fPartList.at(part_index)) this_pdg = fitsums[0]->PDG();
425  }
426  if(this_pdg==std::numeric_limits<int>::min()){
427  this_bpfpid.SetVal(-5);
428  PIds->push_back(this_bpfpid);
429  util::CreateAssn(*this,evt,*(PIds.get()),tracks[itrack],*(PIdTrackAssns.get()));
430  continue;
431  }
432 
433 
434  // Set the variables for the track with the best muonPID
435  if(fLength > 0.0 && fdEdxLL > -1.0e9 && fChi2T < 1.0e9) {
436  // Get the PID value...
437  TMVA::Reader* this_pid_reader = fPartListPID.at(fitsums[0]->PDG());
438  std::string this_pid_method = fPartListPIDMethod.at(fitsums[0]->PDG()) + " Method";
439  float pid = this_pid_reader->EvaluateMVA(this_pid_method);
440  this_bpfpid.SetVal(pid);
441  }
442 
443  //FIXME - jpdavies - I think this is how to create the PIDs and Associations between PIDs and tracks
444  // (again I think that is the association that we want!)
445  PIds->push_back(this_bpfpid);
446  util::CreateAssn(*this,evt,*(PIds.get()),tracks[itrack],*(PIdTrackAssns.get()));
447 
448  } // end loop over tracks (itrack)
449 
450  } // end loop over prongs (iprong)
451 
452  } // end loop over slhandle (islice)
453 
454  evt.put(std::move(PIds));
455  evt.put(std::move(PIdTrackAssns));
456 
457  }
std::map< int, TMVA::Reader * > fPartListPID
Map of particle pdg codes to TMVA reader object for that PID.
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.
float fdEdxLL
dEdx LL value
std::vector< int > fPartList
List of particle types (by pdg code) to be used for PID creation.
bpfit::dEdxCalculator fdEdxCalc
helper class for computing dEdx values
void computeDEDX(art::Ptr< rb::Track > &track, int pdg=13)
Compute dE/dx for all cells along this track and the fitsum object that went with it...
const art::ProductToken< std::vector< rb::Cluster > > fSlicerToken
std::map< int, std::string > fPartListPIDMethod
Map of particle pdg codes to TMVA method for that PID.
double dE
float fChi2T
total chi^2
std::string fTrackLabel
label for module that made the tracks
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
const XML_Char * s
Definition: expat.h:262
double dx[NP][NC]
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
float fLength
track length
const double a
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
std::string fProngLabel
label for module that made the prongs
double fdxTOL
lower limit for dx values to be used in dE/dx calculation
Near Detector in the NuMI cavern.
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
float fHitRatio
ratio of track hits to prong hits (used as a track/shower discriminator)
std::string fProngInstance
instance label for the prongs to be used
void geom(int which=0)
Definition: geom.C:163
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
Float_t e
Definition: plot.C:35
TH2F * fdEdxVSbg[2][2]
histo of computed dE/dx for cell hits (vs. beta*gamma)
Float_t w
Definition: plot.C:20
#define W(x)
void getResults(std::vector< double > &dEtemp, std::vector< double > &dxtemp, std::vector< double > &Wtemp, std::vector< double > &bgtemp, std::vector< double > &stemp, double dxTol)
Return the results of the dE/dx calculation.
enum BeamMode string
void bpfit::BPFPIdMaker::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 141 of file BPFPIdMaker_module.cc.

References fdxTOL, fHistoFile, fLibPath, fMuonPID, fMuonPIDMethod, fPartList, fPartListPID, fPartListPIDMethod, fPIdAsMuon, fPIdAsPion, fPIdAsProton, fPionPID, fPionPIDMethod, fProngInstance, fProngLabel, fProtonPID, fProtonPIDMethod, fTrackLabel, fhicl::ParameterSet::get(), and string.

Referenced by BPFPIdMaker().

142  {
143  fProngLabel = pset.get<std::string> ("ProngLabel");
144  fProngInstance = pset.get<std::string> ("ProngInstance");
145  fTrackLabel = pset.get<std::string> ("TrackLabel");
146  fLibPath = pset.get<std::string> ("LibPath");
147  fHistoFile = pset.get<std::string> ("HistoFile");
148  fMuonPIDMethod = pset.get<std::string> ("MuonPIDMethod");
149  fPionPIDMethod = pset.get<std::string> ("PionPIDMethod");
150  fProtonPIDMethod = pset.get<std::string> ("ProtonPIDMethod");
151  fdxTOL = pset.get<double> ("dxTOL");
152 
153  fPIdAsMuon = pset.get<bool> ("PIdAsMuon");
154  fPIdAsPion = pset.get<bool> ("PIdAsPion");
155  fPIdAsProton = pset.get<bool> ("PIdAsProton");
156 
157  fPartList.clear();
158  fPartListPID.clear();
159  fPartListPIDMethod.clear();
160 
161  if(fPIdAsMuon){
162  fPartList.push_back(13);
163  fMuonPID = new TMVA::Reader();
164  fPartListPID.insert(std::pair<int, TMVA::Reader*>(13,fMuonPID));
165  fPartListPIDMethod.insert(std::pair<int, std::string>(13, fMuonPIDMethod));
166  }
167  if(fPIdAsPion){
168  fPartList.push_back(211);
169  fPionPID = new TMVA::Reader();
170  fPartListPID.insert(std::pair<int, TMVA::Reader*>(211,fPionPID));
171  fPartListPIDMethod.insert(std::pair<int, std::string>(211, fPionPIDMethod));
172  }
173  if(fPIdAsProton){
174  fPartList.push_back(2212);
175  fProtonPID = new TMVA::Reader();
176  fPartListPID.insert(std::pair<int, TMVA::Reader*>(2212,fProtonPID));
177  fPartListPIDMethod.insert(std::pair<int, std::string>(2212, fProtonPIDMethod));
178  }
179 
180 
181 
182  }
std::map< int, TMVA::Reader * > fPartListPID
Map of particle pdg codes to TMVA reader object for that PID.
std::vector< int > fPartList
List of particle types (by pdg code) to be used for PID creation.
std::string fMuonPIDMethod
name of the TMVA method for the muon PID, fileName = "tmva_"+method+".xml"
std::string fProtonPIDMethod
name of the TMVA method for the proton PID, fileName = "tmva_"+method+".xml"
TMVA::Reader * fProtonPID
TMVA reader object for the proton PID – jpdavies NOT implemented yet.
bool fPIdAsProton
Create a Proton PID.
std::map< int, std::string > fPartListPIDMethod
Map of particle pdg codes to TMVA method for that PID.
std::string fTrackLabel
label for module that made the tracks
TMVA::Reader * fPionPID
TMVA reader object for the pion PID – jpdavies NOT implemented yet.
std::string fHistoFile
name of dE/dx log-likelihood histogram file
TMVA::Reader * fMuonPID
TMVA reader object for the muon PID.
std::string fLibPath
location of all BPF library files listed below
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::string fProngLabel
label for module that made the prongs
double fdxTOL
lower limit for dx values to be used in dE/dx calculation
bool fPIdAsMuon
Create a Muon PID.
std::string fProngInstance
instance label for the prongs to be used
bool fPIdAsPion
Create a Pion PID.
std::string fPionPIDMethod
name of the TMVA method for the pion PID, fileName = "tmva_"+method+".xml"
enum BeamMode string
void bpfit::BPFPIdMaker::resetVars ( )

Definition at line 267 of file BPFPIdMaker_module.cc.

References fChi2T, fdEdxLL, fHitRatio, and fLength.

Referenced by produce().

268  {
269  //
270  // PID variables:
271  //
272  fLength = -5.0;
273  fChi2T = 1.0e9;
274  fdEdxLL = -1.0e9;
275  fHitRatio = -5.0;
276  }
float fdEdxLL
dEdx LL value
float fChi2T
total chi^2
float fLength
track length
float fHitRatio
ratio of track hits to prong hits (used as a track/shower discriminator)
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

bool bpfit::BPFPIdMaker::fBookedKNNs
private

Have we yet booked the kNNs?

Definition at line 91 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and BPFPIdMaker().

float bpfit::BPFPIdMaker::fChi2T
private

total chi^2

Definition at line 106 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), produce(), and resetVars().

bpfit::dEdxCalculator bpfit::BPFPIdMaker::fdEdxCalc
private

helper class for computing dEdx values

Definition at line 88 of file BPFPIdMaker_module.cc.

Referenced by produce().

float bpfit::BPFPIdMaker::fdEdxLL
private

dEdx LL value

Definition at line 107 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), produce(), and resetVars().

TH2F* bpfit::BPFPIdMaker::fdEdxVSbg[2][2]
private

histo of computed dE/dx for cell hits (vs. beta*gamma)

Definition at line 87 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and produce().

double bpfit::BPFPIdMaker::fdxTOL
private

lower limit for dx values to be used in dE/dx calculation

Definition at line 79 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().

std::string bpfit::BPFPIdMaker::fHistoFile
private

name of dE/dx log-likelihood histogram file

Definition at line 74 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

float bpfit::BPFPIdMaker::fHitRatio
private

ratio of track hits to prong hits (used as a track/shower discriminator)

Definition at line 108 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), produce(), and resetVars().

float bpfit::BPFPIdMaker::fLength
private

track length

Definition at line 105 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), produce(), and resetVars().

std::string bpfit::BPFPIdMaker::fLibPath
private

location of all BPF library files listed below

Definition at line 73 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

TMVA::Reader* bpfit::BPFPIdMaker::fMuonPID
private

TMVA reader object for the muon PID.

Definition at line 93 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

std::string bpfit::BPFPIdMaker::fMuonPIDMethod
private

name of the TMVA method for the muon PID, fileName = "tmva_"+method+".xml"

Definition at line 76 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

std::vector<int> bpfit::BPFPIdMaker::fPartList
private

List of particle types (by pdg code) to be used for PID creation.

Definition at line 85 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().

std::map<int, TMVA::Reader*> bpfit::BPFPIdMaker::fPartListPID
private

Map of particle pdg codes to TMVA reader object for that PID.

Definition at line 97 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().

std::map<int, std::string> bpfit::BPFPIdMaker::fPartListPIDMethod
private

Map of particle pdg codes to TMVA method for that PID.

Definition at line 98 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().

bool bpfit::BPFPIdMaker::fPIdAsMuon
private

Create a Muon PID.

Definition at line 81 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

bool bpfit::BPFPIdMaker::fPIdAsPion
private

Create a Pion PID.

Definition at line 82 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

bool bpfit::BPFPIdMaker::fPIdAsProton
private

Create a Proton PID.

Definition at line 83 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

TMVA::Reader* bpfit::BPFPIdMaker::fPionPID
private

TMVA reader object for the pion PID – jpdavies NOT implemented yet.

Definition at line 94 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

std::string bpfit::BPFPIdMaker::fPionPIDMethod
private

name of the TMVA method for the pion PID, fileName = "tmva_"+method+".xml"

Definition at line 77 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

std::string bpfit::BPFPIdMaker::fProngInstance
private

instance label for the prongs to be used

Definition at line 71 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().

std::string bpfit::BPFPIdMaker::fProngLabel
private

label for module that made the prongs

Definition at line 70 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().

TMVA::Reader* bpfit::BPFPIdMaker::fProtonPID
private

TMVA reader object for the proton PID – jpdavies NOT implemented yet.

Definition at line 95 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

std::string bpfit::BPFPIdMaker::fProtonPIDMethod
private

name of the TMVA method for the proton PID, fileName = "tmva_"+method+".xml"

Definition at line 78 of file BPFPIdMaker_module.cc.

Referenced by beginRun(), and reconfigure().

const art::ProductToken<std::vector<rb::Cluster> > bpfit::BPFPIdMaker::fSlicerToken
private

Definition at line 69 of file BPFPIdMaker_module.cc.

Referenced by produce().

std::string bpfit::BPFPIdMaker::fTrackLabel
private

label for module that made the tracks

Definition at line 72 of file BPFPIdMaker_module.cc.

Referenced by produce(), and reconfigure().


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