NumuCCpiSkimmer.cxx
Go to the documentation of this file.
1 //
2 // NumuCCpiSkimmer.cxx
3 //
4 // Created by Paul Sail on 10/07/16.
5 //
6 
10 
11 #include "CosRej/CosRejObj.h"
12 #include "Preselection/Veto.h"
13 #include "ReMId/ReMId.h"
14 #include "QEEventFinder/QePId.h"
16 #include "NumuEnergy/NumuE.h"
17 #include "RecoBase/Prong.h"
18 #include "RecoBase/Shower.h"
19 #include "RecoBase/Vertex.h"
20 #include "Utilities/AssociationUtil.h"
21 
24 
28 
29 //------------------------------------------------------------------------------
32 {
33  this->reconfigure(p);
34 
35  return;
36 }
37 
38 //------------------------------------------------------------------------------
40  art::EDProducer const& prod)
41 {
42  // get the CellHits made in the previous module
44  e.getByLabel(fInputTag, cellHits);
45 
46  if(cellHits.failedToGet() ){
47  LOG_VERBATIM("NumuSkimmer")
48  << "There are no numu CellHits for this event, don't try to skim anything.";
49  return;
50  }
51 
52  // if we are in this module, then this event has interesting slices.
53  // to facilitate making copies of the rb::XXX objects we want, make
54  // a map of the cell unique id values to the art::Ptr of the copy
55  // from the previous module
56  skim::SkimmingUtils su(cellHits, fInstanceLabel);
57 
58  // get the slices out of the event
59  auto sliceHandle = e.getValidHandle< art::PtrVector<rb::Cluster> >(fInputTag);
60  art::PtrVector<rb::Cluster> slices = *sliceHandle;
61 
62  LOG_DEBUG("NumuCCpiSkimmer") << "there are " << slices.size() << " slices in this event";
63  //std::cout << "Inside NumuCCpiSkimmer on behalf of numuccpi skim" << std::endl;
64  // now we are sure we have all the data products we need, declare the items to store in the event
65  // As long as we do a drop on output we will keep all the necessary provanence information on how
66  // each item was created. The information is left in the configuration DB intact, and we know what
67  // modules created which input data product by the module label configurations for this module.
68  std::unique_ptr< std::vector<rb::Energy> > energyOut (new std::vector<rb::Energy> );
69  std::unique_ptr< std::vector<rb::Cluster> > sliceOut (new std::vector<rb::Cluster> );
70  //std::unique_ptr< std::vector<rb::Shower> > showerOut (new std::vector<rb::Shower> );
71  //std::unique_ptr< std::vector<rb::Vertex> > vertexOut (new std::vector<rb::Vertex> );
72  std::unique_ptr< std::vector<rb::Track> > trackOut (new std::vector<rb::Track> );
73  std::unique_ptr< std::vector<cosrej::CosRejObj> > cosRejOut (new std::vector<cosrej::CosRejObj> );
74  std::unique_ptr< std::vector<numusand::NumuSandObj> > sandOut (new std::vector<numusand::NumuSandObj> );
75  std::unique_ptr< std::vector<presel::Veto> > vetoOut (new std::vector<presel::Veto> );
76  std::unique_ptr< std::vector<qeef::QePId> > qepidOut (new std::vector<qeef::QePId> );
77  std::unique_ptr< std::vector<remid::ReMId> > remidOut (new std::vector<remid::ReMId> );
78  std::unique_ptr< std::vector<numue::NumuE> > numuEOut (new std::vector<numue::NumuE> );
79  //std::unique_ptr< std::vector<me::MichelECluster> > michelEOut(new std::vector<me::MichelECluster> );
80  //std::unique_ptr< art::Assns<rb::Cluster, rb::Shower> > slcShwAssn(new art::Assns<rb::Cluster, rb::Shower> );
81  //std::unique_ptr< art::Assns<rb::Cluster, rb::Vertex> > slcVtxAssn(new art::Assns<rb::Cluster, rb::Vertex> );
82  std::unique_ptr< art::Assns<rb::Cluster, rb::Track> > slcTrkAssn(new art::Assns<rb::Cluster, rb::Track> );
83  std::unique_ptr< art::Assns<rb::Cluster, cosrej::CosRejObj> > slcCROAssn(new art::Assns<rb::Cluster, cosrej::CosRejObj> );
84  std::unique_ptr< art::Assns<rb::Cluster, numusand::NumuSandObj> > slcNSOAssn(new art::Assns<rb::Cluster, numusand::NumuSandObj>);
85  std::unique_ptr< art::Assns<rb::Cluster, presel::Veto> > slcVetAssn(new art::Assns<rb::Cluster, presel::Veto> );
86  std::unique_ptr< art::Assns<rb::Cluster, qeef::QePId> > slcQEPAssn(new art::Assns<rb::Cluster, qeef::QePId> );
87  std::unique_ptr< art::Assns<rb::Cluster, numue::NumuE> > slcNMEAssn(new art::Assns<rb::Cluster, numue::NumuE> );
88  //std::unique_ptr< art::Assns<rb::Cluster, me::MichelECluster> > slcMECAssn(new art::Assns<rb::Cluster, me::MichelECluster> );
89  //std::unique_ptr< art::Assns<rb::Track, me::MichelECluster> > trkMECAssn(new art::Assns<rb::Track, me::MichelECluster> );
90  std::unique_ptr< art::Assns<rb::Track, remid::ReMId> > trkREMAssn(new art::Assns<rb::Track, remid::ReMId> );
91  std::unique_ptr< art::Assns<rb::Track, rb::Energy> > trkEngAssn(new art::Assns<rb::Track, rb::Energy> );
92  std::unique_ptr< art::Assns<rb::Cluster, simb::MCTruth> > slcTruAssn(new art::Assns<rb::Cluster, simb::MCTruth> );
93  std::unique_ptr< art::Assns<rb::Cluster, simb::MCFlux> > slcFlxAssn(new art::Assns<rb::Cluster, simb::MCFlux> );
94  std::unique_ptr< art::Assns<rb::Cluster, fxwgt::FluxWeights> > slcFlxWgtAssn(new art::Assns<rb::Cluster, fxwgt::FluxWeights> );
95  std::unique_ptr< art::Assns<rb::Cluster, simb::GTruth> > slcGTruAssn(new art::Assns<rb::Cluster, simb::GTruth> );
96 
97  // get the FindMany for the slices to shower association.
98  art::FindManyP<rb::Shower> fms (slices, e, fShowerLabel );
99  art::FindManyP<rb::Vertex> fmvx(slices, e, fVertexLabel );
103  art::FindManyP<presel::Veto> fmv (slices, e, fVetoLabel );
104  art::FindManyP<qeef::QePId> fmqe(slices, e, fQePIdLabel );
105  art::FindManyP<numue::NumuE> fme (slices, e, fNumuELabel );
106 
107  //std::cout << "slices.size() in NumuCCpiSkimmer : " << slices.size() << std::endl;
108  for(size_t s = 0; s < slices.size(); ++s){
109 
110  //std::cout << "loop over available slices and fill new file." << std::endl;
111  // vector of art::Ptrs for the FindManyP calls
112  std::vector< art::Ptr<rb::Track> > tracks;
113  std::vector< art::Ptr<cosrej::CosRejObj> > cosrejs;
114  std::vector< art::Ptr<numusand::NumuSandObj> > sands;
115  std::vector< art::Ptr<presel::Veto> > vetos;
116  std::vector< art::Ptr<qeef::QePId> > qepids;
117  std::vector< art::Ptr<numue::NumuE> > numues;
118 
119  fmt .get(s, tracks);
120  fmcr.get(s, cosrejs);
121  fmns.get(s, sands);
122  fmv .get(s, vetos);
123  fmqe.get(s, qepids);
124  fme .get(s, numues);
125 
126  // create the new copies of the desired data products
127  su.CopySlice(slices[s], *sliceOut, s);
128  su.CopyTracks(prod, e, tracks, *trackOut, *sliceOut, *slcTrkAssn);
129  su.CopyProductAndSliceAssn(prod, e, cosrejs, *cosRejOut, *sliceOut, *slcCROAssn);
130  su.CopyProductAndSliceAssn(prod, e, sands, *sandOut, *sliceOut, *slcNSOAssn);
131  su.CopyProductAndSliceAssn(prod, e, vetos, *vetoOut, *sliceOut, *slcVetAssn);
132  su.CopyProductAndSliceAssn(prod, e, qepids, *qepidOut, *sliceOut, *slcQEPAssn);
133  su.CopyProductAndSliceAssn(prod, e, numues, *numuEOut, *sliceOut, *slcNMEAssn);
134  //this->CopyMichelEClusters(e, prod, tracks, *michelEOut, *sliceOut, *trackOut, *slcMECAssn, *trkMECAssn);
135  this->CopyTrackAssn(e, prod, tracks, *remidOut, *trackOut, *trkREMAssn, fReMIdLabel);
136  this->CopyTrackAssn(e, prod, tracks, *energyOut, *trackOut, *trkEngAssn, fEnergyLabel);
137 
138  // apparently we can't count on a vertex object being present in the
139  // reconstruction. As no cuts depend on them, just remove them for now
140 // std::vector< art::Ptr<rb::Vertex> > vertices;
141 // fmvx.get(s, vertices);
142 // su.CopyVertex(prod, e, vertices[0], *vertexOut, *sliceOut, *slcVtxAssn);
143 
144 
145  // finally check to see if this is MC, and if so make the association to MCTruth
146  if( !e.isRealData() )
147  su.SliceMCTruthAssociation(prod,
148  e,
149  s,
150  *sliceOut,
151  *slcTruAssn,
152  *slcFlxAssn,
153  *slcFlxWgtAssn,
154  *slcGTruAssn,
157 
158  } // end loop over the slices
159 
160  e.put(std::move(sliceOut), fInstanceLabel);
161  e.put(std::move(energyOut), fInstanceLabel);
162  //e.put(std::move(showerOut), fInstanceLabel);
163  //e.put(std::move(vertexOut), fInstanceLabel);
164  e.put(std::move(trackOut), fInstanceLabel);
165  e.put(std::move(cosRejOut), fInstanceLabel);
166  e.put(std::move(sandOut), fInstanceLabel);
167  e.put(std::move(vetoOut), fInstanceLabel);
168  e.put(std::move(qepidOut), fInstanceLabel);
169  e.put(std::move(remidOut), fInstanceLabel);
170  e.put(std::move(numuEOut), fInstanceLabel);
171  //e.put(std::move(michelEOut));
172  e.put(std::move(slcTrkAssn), fInstanceLabel);
173  //e.put(std::move(slcShwAssn), fInstanceLabel);
174  //e.put(std::move(slcVtxAssn), fInstanceLabel);
175  e.put(std::move(slcCROAssn), fInstanceLabel);
176  e.put(std::move(slcNSOAssn), fInstanceLabel);
177  e.put(std::move(slcVetAssn), fInstanceLabel);
178  e.put(std::move(slcQEPAssn), fInstanceLabel);
179  e.put(std::move(slcNMEAssn), fInstanceLabel);
180  //e.put(std::move(slcMECAssn));
181  //e.put(std::move(trkMECAssn));
182  e.put(std::move(trkREMAssn), fInstanceLabel);
183  e.put(std::move(trkEngAssn), fInstanceLabel);
184  e.put(std::move(slcTruAssn), fInstanceLabel);
185  e.put(std::move(slcFlxAssn), fInstanceLabel);
186  e.put(std::move(slcFlxWgtAssn), fInstanceLabel);
187 
188 
189  return;
190 
191 }
192 
193 //------------------------------------------------------------------------------
194 //void skim::NumuCCpiSkimmer::CopyMichelEClusters(art::Event &e,
195 // art::EDProducer const& prod,
196 // std::vector<art::Ptr<rb::Track> > const& trackIn,
197 // std::vector<me::MichelECluster> & michelEOut,
198 // std::vector<rb::Cluster> & sliceOut,
199 // std::vector<rb::Track> & trackOut,
200 // art::Assns<rb::Cluster, me::MichelECluster> & slcMECAssn,
201 // art::Assns<rb::Track, me::MichelECluster> & trkMECAssn)
202 //{
203 // // this method requires the trackOut collection to have already been filled. All
204 // // tracks from the slice are assumed to be copied into the skimmed slice and in the
205 // // same order as the tracks from the original slice (ie trackIn)
206 // if( trackOut.size() != trackIn.size() )
207 // throw cet::exception("NumuCCpiSkimmer") << "The output collection of tracks has "
208 // << trackOut.size() << " tracks, the input collection has"
209 // << trackIn.size() << " something is wrong.";
210 //
211 // // do a FindMany for the track to MichelECluster connection. Copy the found MichelECluster
212 // // into the output vector, then make the associations
213 // // apparently there can be a many to one or many to many association between
214 // // MichelEClusters and Tracks...so just pass through what was already decided
215 // art::FindMany<me::MichelECluster> fmme(trackIn, e, fMichelELabel);
216 //
217 // for(size_t t = 0; t < trackIn.size(); ++t){
218 // std::vector<const me::MichelECluster*> mevec;
219 // fmme.get(t, mevec);
220 //
221 // for(auto mec : mevec ){
222 // michelEOut.push_back( *mec );
223 // // set the parent track based on the current track being output
224 // art::ProductID tid = prod.getProductID< std::vector<rb::Track> >(e);
225 // art::Ptr<rb::Track> tptr(tid, t, e.productGetter(tid));
226 // michelEOut.back().SetParentTrack(tptr);
227 // util::CreateAssn(prod, e, trackOut, michelEOut, trkMECAssn, michelEOut.size()-1, michelEOut.size(), t);
228 // util::CreateAssn(prod, e, sliceOut, michelEOut, slcMECAssn, michelEOut.size()-1, michelEOut.size());
229 // }
230 // }
231 //
232 // return;
233 //}
234 
235 //------------------------------------------------------------------------------
237  art::EDProducer const& prod,
238  std::vector<art::Ptr<rb::Track> > const& trackIn,
239  std::vector<T> & tOut,
240  std::vector<rb::Track> & trackOut,
241  art::Assns<rb::Track, T> & trkTAssn,
242  std::string const& modLabel)
243 {
244  // this method requires the trackOut collection to have already been filled. All
245  // tracks from the slice are assumed to be copied into the skimmed slice and in the
246  // same order as the tracks from the original slice (ie trackIn)
247  // trackOut could be larger than track in, if we are in the ND so only look at the
248  // last trackIn.size() entries in trackOut
249 
250  // do a FindOne for the track to T connection. Copy the found T
251  // into the output vector, then make the associations
252  art::FindOne<T> fot(trackIn, e, modLabel);
253  for(size_t ti = 0; ti < trackIn.size(); ++ti){
254  cet::maybe_ref<T const> t(fot.at(ti));
255  if( t.isValid() ){
256  tOut.push_back( t.ref() );
257  util::CreateAssn(prod,
258  e,
259  trackOut,
260  tOut,
261  trkTAssn,
262  tOut.size()-1,
263  tOut.size(),
264  trackOut.size() - trackIn.size() + ti,
267  }
268  }
269 
270  return;
271 }
272 
273 
274 
275 //------------------------------------------------------------------------------
277 {
278  fVertexLabel = p.get<std::string>("VertexLabel", "elasticarmshs" );
279  fShowerLabel = p.get<std::string>("ShowerLabel", "recluster" );
280  fTrackLabel = p.get<std::string>("TrackLabel", "kalmantrackmerge" );
281  fCosRejLabel = p.get<std::string>("CosRejLabel", "cosrej" );
282  fNumuSandLabel = p.get<std::string>("NumuSandLabel", "numusand" );
283  fVetoLabel = p.get<std::string>("VetoLabel", "veto" );
284  fQePIdLabel = p.get<std::string>("QePIdLabel", "qepid" );
285  fReMIdLabel = p.get<std::string>("ReMIdLabel", "remid" );
286  fMichelELabel = p.get<std::string>("MichelELabel", "michelekalmantrack");
287  fNumuELabel = p.get<std::string>("NumuELabel", "numue" );
288  fEnergyLabel = p.get<std::string>("EnergyLabel", "numue" );
289  fCAFLabel = p.get<std::string>("CAFLabel", "cafmaker" );
290  fGeneratorLabel = p.get<std::string>("GeneratorLabel", "generator" );
291  fFluxWeightLabel = p.get<std::string>("FluxWeightLabel", "ppfxcorrection" );
292 
293  return;
294 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
size_type size() const
Definition: Assns.h:440
std::string fVetoLabel
label of module creating vetos
std::string fTrackLabel
label of module creating 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.
const char * p
Definition: xmltok.h:285
bool SliceMCTruthAssociation(art::EDProducer const &prod, art::Event &e, size_t const &slcIdx, std::vector< rb::Cluster > &sliceOut, art::Assns< rb::Cluster, simb::MCTruth > &slcTruAssn, art::Assns< rb::Cluster, simb::MCFlux > &slcFlxAssn, art::Assns< rb::Cluster, fxwgt::FluxWeights > &slcFlxWgtAssn, art::Assns< rb::Cluster, simb::GTruth > &slcGTruAssn, std::string const &generatorLabel, std::string const &fluxWeightLabel)
void Skim(art::Event &e, art::EDProducer const &prod)
std::string fEnergyLabel
label of module creating energy objects
bool CopyProductAndSliceAssn(art::EDProducer const &prod, art::Event &e, std::vector< art::Ptr< T > > const &objIn, std::vector< T > &objOut, std::vector< rb::Cluster > &sliceOut, art::Assns< rb::Cluster, T > &slcCROAssn)
bool isRealData() const
Definition: Event.h:83
void reconfigure(fhicl::ParameterSet const &p)
std::string fNumuSandLabel
label of module creating NumuSand
bool CopySlice(art::Ptr< rb::Cluster > const &sliceIn, std::vector< rb::Cluster > &sliceOut, size_t &sliceNum)
art::InputTag fInputTag
combination of the above two strings
Definition: BaseSkimmer.h:45
Module to create a summary of total POT seen in a job.
Definition: Evaluator.h:27
std::string fNumuELabel
label of module creating NumuEs
object containing MC flux information
std::string fMichelELabel
label of module creating MichelEClusters
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
const XML_Char * s
Definition: expat.h:262
NumuCCpiSkimmer(fhicl::ParameterSet const &p)
std::string fFluxWeightLabel
label of module creating MC events
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::string fCosRejLabel
label of module creating CosRej
std::string fCAFLabel
label of module creating StandardRecords
std::string fShowerLabel
label of module creating showers
Vertex location in position and time.
T prod(const std::vector< T > &v)
Definition: prod.hpp:17
size_type size() const
Definition: PtrVector.h:308
std::string fReMIdLabel
label of module creating ReMIds
std::string fVertexLabel
label of module creating vertex
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string fGeneratorLabel
label of module creating MC events
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void CopyTrackAssn(art::Event &e, art::EDProducer const &prod, std::vector< art::Ptr< rb::Track > > const &trackIn, std::vector< T > &tOut, std::vector< rb::Track > &trackOut, art::Assns< rb::Track, T > &trkTAssn, std::string const &modLabel)
std::string fQePIdLabel
label of module creating QePIds
std::string fInstanceLabel
instance label for products created by this skimmer
Definition: BaseSkimmer.h:44
bool CopyTracks(art::EDProducer const &prod, art::Event &e, std::vector< art::Ptr< rb::Track > > const &trackIn, std::vector< rb::Track > &trackOut, std::vector< rb::Cluster > &sliceOut, art::Assns< rb::Cluster, rb::Track > &slcTrkAssn, std::string const &slcInstance="", std::string const &trkInstance="")
size_type get(size_type i, reference item, data_reference data) const
Definition: FindManyP.h:469
#define LOG_VERBATIM(category)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Float_t e
Definition: plot.C:35
bool failedToGet() const
Definition: Handle.h:196