FillSliceLID_module.cc
Go to the documentation of this file.
10 
11 #include "Geometry/Geometry.h"
12 #include "NovaDAQConventions/DAQConventions.h"
13 #include "RecoBase/Cluster.h"
14 #include "RecoBase/Vertex.h"
15 #include "RecoBase/FilterList.h"
16 #include "SummaryData/SpillData.h"
17 #include "Utilities/AssociationUtil.h"
19 
20 
21 #include <memory>
22 
29 
30 namespace SliceLID
31 {
32 
34 {
35 
36 public:
37  explicit FillSliceLID(const fhicl::ParameterSet &pset);
38 
39  FillSliceLID(FillSliceLID const &) = delete;
40  FillSliceLID(FillSliceLID &&) = delete;
41  FillSliceLID & operator = (FillSliceLID const &) = delete;
42  FillSliceLID & operator = (FillSliceLID &&) = delete;
43 
44  void produce(art::Event &evt) override;
45 
46  void reconfigure(const fhicl::ParameterSet &pset);
47 
48  void fillSliceLIDPreds(
49  art::Event &evt,
50  std::unique_ptr<std::vector<Prediction>> &sliceLIDPreds,
51  std::unique_ptr<art::Assns<Prediction, rb::Cluster>> &sliceLIDAssoc
52  );
53 
54 protected:
55 
56  bool getIsRHC(const art::Event &evt);
57  Model& selectModel(const art::Event &evt);
58 
60  Model &model,
61  const art::Event &evt,
62  const art::Handle<std::vector<rb::Cluster>> &slices_h,
63  size_t sliceIdx,
64  const std::vector<art::Ptr<rb::Vertex>> &elastics,
65  const std::vector<bool> &sliceIsMC
66  );
67 
68 private:
70 
73 
76 
78  std::vector<std::string> fPreselectionLabels;
79 
81 };
82 
83 
85  : modelFHC(util::EnvExpansion(pset.get<std::string>("modelFHC"))),
86  modelRHC(util::EnvExpansion(pset.get<std::string>("modelRHC"))),
87  fObeyPreselection (pset.get<bool> ("ObeyPreselection" )),
88  fPreselectionLabels(pset.get<std::vector<std::string>> ("PreselectionLabels")),
89  useOppositeHornCurrentNetwork(pset.get<bool>("useOppositeHornCurrentNetwork"))
90 {
91  reconfigure(pset);
92 
93  produces<std::vector<Prediction>>();
94  produces<art::Assns<Prediction, rb::Cluster>>();
95 }
96 
98 {
99  beamLabel = pset.get<std::string>("beamLabel");
100  generatorLabel = pset.get<std::string>("generatorLabel");
101 
102  config.parse(pset);
103 }
104 
106 {
107  /* TODO: ask if this should be cached per file/run/job/etc ? */
109  if (! evt.isRealData()) {
110  evt.getByLabel(generatorLabel, spillPot);
111  }
112  else {
113  evt.getByLabel(beamLabel, spillPot);
114  }
115 
116  if (spillPot.failedToGet())
117  {
118  mf::LogError("FillSliceLID") <<
119  "Spill Data not found, aborting without horn current information";
120  abort();
121  }
122 
123  if(useOppositeHornCurrentNetwork) return !spillPot->isRHC;
124 
125  // NB - the logic here will cause 0HC to use the FHC network
126  return spillPot->isRHC;
127 }
128 
130 {
131  bool isRHC = getIsRHC(evt);
132 
133  if (isRHC) {
134  return modelRHC;
135  }
136  else {
137  return modelFHC;
138  }
139 }
140 
142  Model &model,
143  const art::Event &evt,
144  const art::Handle<std::vector<rb::Cluster>> &slices_h,
145  size_t sliceIdx,
146  const std::vector<art::Ptr<rb::Vertex>> &elastics,
147  const std::vector<bool> &sliceIsMC
148 )
149 {
150  VarDictBuilder builder(evt, slices_h, sliceIdx, elastics, config);
151  VarDict varDict = builder.build();
152 
153  /* NOTE: this must be removed once geometry is fixed */
154  /* TODO: ask if backtracker->HasTruthInfo() is better to get isMC */
156  TrackLengthCorrection trkLenCorr(
157  sliceIsMC[sliceIdx], (geom->DetId() == novadaq::cnv::kFARDET)
158  );
159  trkLenCorr.shift(varDict);
160 
161  return model.predict(varDict);
162 }
163 
165  art::Event &evt,
166  std::unique_ptr<std::vector<Prediction>> &sliceLIDPreds,
167  std::unique_ptr<art::Assns<Prediction, rb::Cluster>> &sliceLIDAssoc
168 )
169 {
171  if (! evt.getByLabel(config.sliceLabel, slices_h))
172  {
173  mf::LogError("FillSliceLID")
174  << "Failed to get slice info" << std::endl;
175  return;
176  }
177 
178  art::FindManyP<rb::Vertex> elasticVxt_fmp(
179  slices_h, evt, config.elasticArmsLabel
180  );
181  if (! elasticVxt_fmp.isValid())
182  {
183  mf::LogError("FillSliceLID") << "No elastics found" << std::endl;
184  return;
185  }
186 
187  Model &model = selectModel(evt);
188  std::vector<bool> sliceIsMC = getSliceIsMC(*slices_h);
189 
190  for (size_t sliceIdx = 0; sliceIdx < slices_h->size(); ++sliceIdx)
191  {
192  const art::Ptr<rb::Cluster> slicePtr(slices_h, sliceIdx);
193 
194  if (slicePtr->IsNoise()) {
195  continue;
196  }
197  if(fObeyPreselection && rb::IsFiltered(evt, slices_h, sliceIdx, fPreselectionLabels)) continue;
198 
199  auto elastics = elasticVxt_fmp.at(sliceIdx);
200 
202  model, evt, slices_h, sliceIdx, elastics, sliceIsMC
203  );
204 
205  sliceLIDPreds->emplace_back(std::move(pred));
207  *this, evt,
208  *(sliceLIDPreds.get()), slicePtr, *(sliceLIDAssoc.get())
209  );
210  }
211 }
212 
214 {
215  std::unique_ptr<std::vector<Prediction>> sliceLIDPreds(
216  new std::vector<Prediction>
217  );
218  std::unique_ptr<art::Assns<Prediction, rb::Cluster>> sliceLIDAssoc(
220  );
221 
222  fillSliceLIDPreds(evt, sliceLIDPreds, sliceLIDAssoc);
223 
224  evt.put(std::move(sliceLIDPreds));
225  evt.put(std::move(sliceLIDAssoc));
226 }
227 
229 
230 }
bool isRHC
is the beam in antineutrino mode, aka RHC
Definition: SpillData.h:28
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.
Filter events based on their run/event numbers.
Prediction predict(const VarDict &varDict)
Definition: Model.cxx:23
FillSliceLID & operator=(FillSliceLID const &)=delete
void reconfigure(const fhicl::ParameterSet &pset)
std::string EnvExpansion(const std::string &inString)
Function to expand environment variables.
Definition: EnvExpand.cxx:8
Model & selectModel(const art::Event &evt)
Definition: config.py:1
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool isRealData() const
Definition: Event.h:83
DEFINE_ART_MODULE(TestTMapFile)
Prediction predict(Model &model, const art::Event &evt, const art::Handle< std::vector< rb::Cluster >> &slices_h, size_t sliceIdx, const std::vector< art::Ptr< rb::Vertex >> &elastics, const std::vector< bool > &sliceIsMC)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Far Detector at Ash River, MN.
T get(std::string const &key) const
Definition: ParameterSet.h:231
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
int evt
void shift(VarDict &varDict) const
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
Vertex location in position and time.
void produce(art::Event &evt) override
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void geom(int which=0)
Definition: geom.C:163
Definition: VarDict.h:7
void fillSliceLIDPreds(art::Event &evt, std::unique_ptr< std::vector< Prediction >> &sliceLIDPreds, std::unique_ptr< art::Assns< Prediction, rb::Cluster >> &sliceLIDAssoc)
bool getIsRHC(const art::Event &evt)
std::vector< bool > getSliceIsMC(const std::vector< rb::Cluster > &slices)
Definition: utils.cxx:6
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
const XML_Char XML_Content * model
Definition: expat.h:151
FillSliceLID(const fhicl::ParameterSet &pset)
Definition: fwd.h:28
Encapsulate the geometry of one entire detector (near, far, ndos)
bool failedToGet() const
Definition: Handle.h:196
std::vector< std::string > fPreselectionLabels
enum BeamMode string