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 "SummaryData/SpillData.h"
16 #include "Utilities/AssociationUtil.h"
18 
19 
20 #include <memory>
21 
28 
29 namespace SliceLID
30 {
31 
33 {
34 
35 public:
36  explicit FillSliceLID(const fhicl::ParameterSet &pset);
37 
38  FillSliceLID(FillSliceLID const &) = delete;
39  FillSliceLID(FillSliceLID &&) = delete;
40  FillSliceLID & operator = (FillSliceLID const &) = delete;
41  FillSliceLID & operator = (FillSliceLID &&) = delete;
42 
43  void produce(art::Event &evt) override;
44 
45  void reconfigure(const fhicl::ParameterSet &pset);
46 
47  void fillSliceLIDPreds(
48  art::Event &evt,
49  std::unique_ptr<std::vector<Prediction>> &sliceLIDPreds,
50  std::unique_ptr<art::Assns<Prediction, rb::Cluster>> &sliceLIDAssoc
51  );
52 
53 protected:
54 
55  bool getIsRHC(const art::Event &evt);
56  Model& selectModel(const art::Event &evt);
57 
59  Model &model,
60  const art::Event &evt,
61  const art::Handle<std::vector<rb::Cluster>> &slices_h,
62  size_t sliceIdx,
63  const std::vector<art::Ptr<rb::Vertex>> &elastics,
64  const std::vector<bool> &sliceIsMC
65  );
66 
67 private:
69 
72 
75 };
76 
77 
79  : modelFHC(util::EnvExpansion(pset.get<std::string>("modelFHC"))),
80  modelRHC(util::EnvExpansion(pset.get<std::string>("modelRHC")))
81 {
82  reconfigure(pset);
83 
84  produces<std::vector<Prediction>>();
85  produces<art::Assns<Prediction, rb::Cluster>>();
86 }
87 
89 {
90  beamLabel = pset.get<std::string>("beamLabel");
91  generatorLabel = pset.get<std::string>("generatorLabel");
92 
93  config.parse(pset);
94 }
95 
97 {
98  /* TODO: ask if this should be cached per file/run/job/etc ? */
100  if (! evt.isRealData()) {
101  evt.getByLabel(generatorLabel, spillPot);
102  }
103  else {
104  evt.getByLabel(beamLabel, spillPot);
105  }
106 
107  if (spillPot.failedToGet())
108  {
109  mf::LogError("FillSliceLID") <<
110  "Spill Data not found, aborting without horn current information";
111  abort();
112  }
113 
114  return spillPot->isRHC;
115 }
116 
118 {
119  bool isRHC = getIsRHC(evt);
120 
121  if (isRHC) {
122  return modelRHC;
123  }
124  else {
125  return modelFHC;
126  }
127 }
128 
130  Model &model,
131  const art::Event &evt,
132  const art::Handle<std::vector<rb::Cluster>> &slices_h,
133  size_t sliceIdx,
134  const std::vector<art::Ptr<rb::Vertex>> &elastics,
135  const std::vector<bool> &sliceIsMC
136 )
137 {
138  VarDictBuilder builder(evt, slices_h, sliceIdx, elastics, config);
139  VarDict varDict = builder.build();
140 
141  /* NOTE: this must be removed once geometry is fixed */
142  /* TODO: ask if backtracker->HasTruthInfo() is better to get isMC */
144  TrackLengthCorrection trkLenCorr(
145  sliceIsMC[sliceIdx], (geom->DetId() == novadaq::cnv::kFARDET)
146  );
147  trkLenCorr.shift(varDict);
148 
149  return model.predict(varDict);
150 }
151 
153  art::Event &evt,
154  std::unique_ptr<std::vector<Prediction>> &sliceLIDPreds,
155  std::unique_ptr<art::Assns<Prediction, rb::Cluster>> &sliceLIDAssoc
156 )
157 {
159  if (! evt.getByLabel(config.sliceLabel, slices_h))
160  {
161  mf::LogError("FillSliceLID")
162  << "Failed to get slice info" << std::endl;
163  return;
164  }
165 
166  art::FindManyP<rb::Vertex> elasticVxt_fmp(
167  slices_h, evt, config.elasticArmsLabel
168  );
169  if (! elasticVxt_fmp.isValid())
170  {
171  mf::LogError("FillSliceLID") << "No elastics found" << std::endl;
172  return;
173  }
174 
175  Model &model = selectModel(evt);
176  std::vector<bool> sliceIsMC = getSliceIsMC(*slices_h);
177 
178  for (size_t sliceIdx = 0; sliceIdx < slices_h->size(); ++sliceIdx)
179  {
180  const art::Ptr<rb::Cluster> slicePtr(slices_h, sliceIdx);
181 
182  if (slicePtr->IsNoise()) {
183  continue;
184  }
185 
186  auto elastics = elasticVxt_fmp.at(sliceIdx);
187 
189  model, evt, slices_h, sliceIdx, elastics, sliceIsMC
190  );
191 
192  sliceLIDPreds->emplace_back(std::move(pred));
194  *this, evt,
195  *(sliceLIDPreds.get()), slicePtr, *(sliceLIDAssoc.get())
196  );
197  }
198 }
199 
201 {
202  std::unique_ptr<std::vector<Prediction>> sliceLIDPreds(
203  new std::vector<Prediction>
204  );
205  std::unique_ptr<art::Assns<Prediction, rb::Cluster>> sliceLIDAssoc(
207  );
208 
209  fillSliceLIDPreds(evt, sliceLIDPreds, sliceLIDAssoc);
210 
211  evt.put(std::move(sliceLIDPreds));
212  evt.put(std::move(sliceLIDAssoc));
213 }
214 
216 
217 }
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
void shift(VarDict &varDict) const
Vertex location in position and time.
void produce(art::Event &evt) override
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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