Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MergeCollections::MergeCollections Class Reference
Inheritance diagram for MergeCollections::MergeCollections:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 MergeCollections (fhicl::ParameterSet const &pset)
 
virtual ~MergeCollections ()
 
void produce (art::Event &evt)
 
std::string workerType () const
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< TconsumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< TmayConsumeView (InputTag const &tag)
 

Protected Member Functions

ConsumesCollector & consumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Protected Attributes

std::string fFirstGenCollection
 
std::string fFirstG4Collection
 Label on the main collection. More...
 
std::string fSecondCollection
 Label on the main collection. More...
 
int fIsFirstCollectionCosmic
 Label on the main collection. More...
 

Detailed Description

Definition at line 35 of file MergeCollections_module.cc.

Member Typedef Documentation

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 25 of file Producer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 18 of file EDProducer.h.

Constructor & Destructor Documentation

MergeCollections::MergeCollections::MergeCollections ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 56 of file MergeCollections_module.cc.

56  :
57  EDProducer(pset),
58  fFirstGenCollection (pset.get< std::string >("FirstGenCollection")),
59  fFirstG4Collection (pset.get< std::string >("FirstG4Collection")),
60  fSecondCollection (pset.get< std::string >("SecondCollection")),
61  fIsFirstCollectionCosmic (pset.get< int >("IsFirstCollectionCosmic"))
62 
63  { produces< std::vector<simb::MCTruth> >();
64  produces< std::vector<simb::MCFlux> >();
65  produces< std::vector<sim::FLSHitList > >();
66  produces< std::vector<sim::Particle> >();
67  produces< std::vector<simb::GTruth> >();
68  produces< art::Assns<simb::MCTruth, simb::MCFlux> >();
69  produces< art::Assns<simb::MCTruth, simb::GTruth> >();
70  produces< art::Assns<sim::Particle, simb::MCTruth> >();
71 
72 
73  }
std::string fFirstG4Collection
Label on the main collection.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
int fIsFirstCollectionCosmic
Label on the main collection.
std::string fSecondCollection
Label on the main collection.
enum BeamMode string
MergeCollections::MergeCollections::~MergeCollections ( )
virtual

Definition at line 76 of file MergeCollections_module.cc.

77  {
78  }

Member Function Documentation

template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 55 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::consumes(), T, and getGoodRuns4SAM::tag.

56  {
57  return collector_.consumes<T, BT>(tag);
58  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
ProductToken< T > consumes(InputTag const &)
double T
Definition: Xdiff_gwt.C:5
ConsumesCollector& art::ModuleBase::consumesCollector ( )
protectedinherited
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 69 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::consumesMany(), and T.

70  {
71  collector_.consumesMany<T, BT>();
72  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
double T
Definition: Xdiff_gwt.C:5
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 62 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::consumesView(), T, and getGoodRuns4SAM::tag.

63  {
64  return collector_.consumesView<T, BT>(tag);
65  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
ViewToken< Element > consumesView(InputTag const &)
double T
Definition: Xdiff_gwt.C:5
void art::detail::Producer::doBeginJob ( )
inherited
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited
void art::detail::Producer::doEndJob ( )
inherited
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited
bool art::detail::Producer::doEvent ( EventPrincipal ep,
ModuleContext const &  mc,
std::atomic< std::size_t > &  counts_run,
std::atomic< std::size_t > &  counts_passed,
std::atomic< std::size_t > &  counts_failed 
)
inherited
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited
std::array<std::vector<ProductInfo>, NumBranchTypes> const& art::ModuleBase::getConsumables ( ) const
inherited
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 76 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::mayConsume(), T, and getGoodRuns4SAM::tag.

77  {
78  return collector_.mayConsume<T, BT>(tag);
79  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:50
double T
Definition: Xdiff_gwt.C:5
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 90 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::mayConsumeMany(), and T.

91  {
93  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
double T
Definition: Xdiff_gwt.C:5
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 83 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::mayConsumeView(), T, and getGoodRuns4SAM::tag.

84  {
85  return collector_.mayConsumeView<T, BT>(tag);
86  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
ViewToken< Element > mayConsumeView(InputTag const &)
double T
Definition: Xdiff_gwt.C:5
ModuleDescription const& art::ModuleBase::moduleDescription ( ) const
inherited
void MergeCollections::MergeCollections::produce ( art::Event evt)
virtual

Current event number

Loop over neutrino interactions

Second collection

Offset ids for FLSHits

End of the FLS offset

Implements art::EDProducer.

Definition at line 81 of file MergeCollections_module.cc.

References sim::FLSHit::Clear(), om::cout, util::CreateAssn(), d, simb::MCParticle::Daughter(), DEFINE_ART_MODULE(), allTimeWatchdog::endl, sim::FLSHitList::fHits, flux, art::DataViewImpl::getByLabel(), simb::MCParticle::Gvt(), simb::MCParticle::Gvx(), simb::MCParticle::Gvy(), simb::MCParticle::Gvz(), hits(), MECModelEnuComparisons::i, calib::j, simb::MCParticle::Mass(), simb::MCParticle::Momentum(), simb::MCParticle::Mother(), simb::MCParticle::NumberDaughters(), simb::MCParticle::NumberTrajectoryPoints(), ana::Offset(), part, simb::MCParticle::PdgCode(), simb::MCParticle::Polarization(), simb::MCParticle::Position(), simb::MCParticle::Process(), art::DataViewImpl::put(), simb::MCParticle::Rescatter(), simb::MCParticle::SetGvtx(), sim::FLSHit::SetTrackId(), gen_hdf5record::size, simb::MCParticle::StatusCode(), confusionMatrixTree::t, simb::MCParticle::TrackId(), and simb::MCParticle::Weight().

82  {
83 
84 
85  std::unique_ptr< std::vector<simb::MCTruth> > truthcol (new std::vector<simb::MCTruth>);
86  std::unique_ptr< std::vector<simb::MCFlux> > fluxcol (new std::vector<simb::MCFlux >);
87  std::unique_ptr< std::vector<simb::GTruth> > gtruthcol(new std::vector<simb::GTruth>);
88  std::unique_ptr< art::Assns<simb::MCTruth, simb::MCFlux> > assns (new art::Assns<simb::MCTruth, simb::MCFlux>);
89  std::unique_ptr< art::Assns<simb::MCTruth, simb::GTruth> > gassns(new art::Assns<simb::MCTruth, simb::GTruth>);
90  std::unique_ptr< art::Assns<sim::Particle, simb::MCTruth> > passns(new art::Assns<sim::Particle, simb::MCTruth>);
91 
92 
93  // Define the FLSHitList and Particle vectors.
94  std::unique_ptr<std::vector<sim::FLSHitList> > flshlcol(new std::vector<sim::FLSHitList> );
95  std::unique_ptr<std::vector<sim::Particle> > pcol (new std::vector<sim::Particle> );
96 
97 
98  /// Current event number
99 // fCurrentEvent = evt.id().event();
100 
101  // Pull the MC generator information out of the event
103  evt.getByLabel(fFirstGenCollection, mclist);
104 
107 
109  evt.getByLabel(fFirstGenCollection, fllist);
110  evt.getByLabel(fFirstGenCollection, glist);
111 
112  }
113 
115  evt.getByLabel(fFirstG4Collection, flslist);
116 
117 
119  evt.getByLabel(fFirstG4Collection, partlist);
120 
121 
122  int IdOffset=0;
123 
124  for(unsigned int i = 0; i < partlist->size(); ++i){
125 
126  sim::Particle part ((*partlist)[i]);
127  IdOffset=part.TrackId();
128  // std::cout << " Primary Collection ID " << IdOffset << std::endl;
129  pcol->push_back(part);
130 
131  }
132 
133 
134  /// Loop over neutrino interactions
135 
136  // std::cout << " primary mc list size " << mclist->size() << std::endl;
137 
138  for(unsigned int i = 0; i < mclist->size(); ++i){
139 
140  simb::MCTruth truth ((*mclist)[i]);
141  truthcol->push_back(truth);
142 
144  simb::MCFlux flux ((*fllist)[i]);
145  fluxcol ->push_back(flux);
146 
147  simb::GTruth gtruth ((*glist)[i]);
148  gtruthcol->push_back(gtruth);
149 
150  util::CreateAssn(evt, *truthcol, *fluxcol, *assns, fluxcol ->size()-1, fluxcol ->size());
151  util::CreateAssn(evt, *truthcol, *gtruthcol, *gassns, gtruthcol->size()-1, gtruthcol->size());
152 
153  }
154 
155  // IdOffset=truth.NParticles();
156 
157  // std::cout<<"First collection:"<< flslist->size() << std::endl;
158 
159  if(i<flslist->size()){
160  sim::FLSHitList mcfls ((*flslist)[i]);
161  flshlcol->push_back(mcfls);
162  }
163  }
164 
165  ///Second collection
166  // std::cout<<"Id Offset = "<<IdOffset<<std::endl;
167 
169  evt.getByLabel(fSecondCollection, mc2list);
170 
172  evt.getByLabel(fSecondCollection, g2list);
173 
175  evt.getByLabel(fSecondCollection, fl2list);
176 
178  evt.getByLabel(fSecondCollection, fls2list);
179 
180 
182  evt.getByLabel(fSecondCollection, part2list);
183 
184  int LastPartId;
185  int *Offset = new int[1000];
186  int *OffsetParticles = new int[1000];
187  int OffsetIndex;
188 
189  LastPartId=0;
190  for(int i=0;i<10;i++){
191  Offset[i]=0;
192  OffsetParticles[i]=0;
193  }
194  Offset[0]=IdOffset;
195  OffsetParticles[0]=partlist->size();
196  OffsetIndex=1;
197 
198  for(unsigned int i = 0; i < part2list->size(); ++i){
199 
200  OffsetParticles[OffsetIndex]++;
201 
202  sim::Particle part ((*part2list)[i]);
203  // std::cout<<"partID="<<part.TrackId()<<std::endl;
204  if(LastPartId > part.TrackId() ){
205  Offset[OffsetIndex]= Offset[OffsetIndex-1] + LastPartId;
206  OffsetIndex++ ;
207 
208  // std::cout<<"osfet for i="<<i<<" is "<<Offset[OffsetIndex-1]<<std::endl;
209  // std::cin.get();
210  }
211 
212  LastPartId=part.TrackId();
213 
214  int partmother =0;
215  if (part.Mother()!=0)partmother = part.Mother() + Offset[OffsetIndex-1];
216 
217  sim::Particle gpart(part.TrackId()+ Offset[OffsetIndex-1],
218  part.PdgCode(),
219  part.Process(),
220  partmother,
221  part.Mass(),
222  part.StatusCode());
223  // std::cout <<part.TrackId()<< "\t" << gpart.TrackId()<<"\t"<< Offset[OffsetIndex-1] << " mother " << part.Mother() << " mother offset " << partmother << std::endl;//std::cin.get();
224 
225  gpart.SetGvtx(part.Gvx(), part.Gvy(),part.Gvz(),part.Gvt());
226  gpart.SetPolarization(part.Polarization());
227  gpart.SetWeight(part.Weight());
228  gpart.SetRescatter(part.Rescatter());
229  for(int d=0; d<part.NumberDaughters(); d++){
230  gpart.AddDaughter(part.Daughter(d)+ Offset[OffsetIndex-1]);
231  }
232  for(unsigned int t=0; t<part.NumberTrajectoryPoints(); t++){
233  //std::cout<<part.Vx(t)<<"\t"<<part.EndX()<<std::endl;
234  gpart.AddTrajectoryPoint(part.Position(t),part.Momentum(t));
235  }
236  pcol->push_back(gpart);
237  // std::cout<< "mc particle " << part.TrackId() << " " << Offset[OffsetIndex-1] << std::endl;
238  }
239 
240  std::cout<<"mc1 size="<<mclist->size()<<std::endl;
241  std::cout<<"mc2 size="<<mc2list->size()<<std::endl;
242 
243  for(unsigned int i = 0; i < mc2list->size(); ++i){
244 
245  simb::MCTruth truth ((*mc2list)[i]);
246  simb::MCFlux flux ((*fl2list)[i]);
247  simb::GTruth gtruth ((*g2list) [i]);
248 
249  simb::MCTruth tmc(truth);
250 
251 
252  /// Offset ids for FLSHits
253 
254  // std::cout<<"size="<<fls2list->size()<< " mclist " << i << std::endl;
255  if(i<fls2list->size()){
256 
257  sim::FLSHitList mcfls ((*fls2list)[i]);
258  sim::FLSHitList tmcfls;
259  sim::FLSHit fHit;
260 
261  const std::vector<sim::FLSHit>& hits = mcfls.fHits;
262  for (unsigned int j=0; j<hits.size(); ++j)
263  {
264  fHit.Clear();
265  fHit=hits[j];
266  fHit.SetTrackId(hits[j].GetTrackID() + Offset[i]);
267  tmcfls.fHits.push_back(fHit);
268 
269  // std::cout << " fls ID " << hits[j].GetTrackID() << " " << Offset[i] << " " << hits[j].GetTrackID()+Offset[i] << std::endl;
270  }
271  flshlcol->push_back(tmcfls);
272 
273  }
274  /// End of the FLS offset
275 
276  truthcol->push_back(tmc);
277  gtruthcol->push_back(gtruth);
278  fluxcol ->push_back(flux);
279 
280  util::CreateAssn(evt, *truthcol, *fluxcol, *assns, fluxcol->size()-1, fluxcol->size());
281  util::CreateAssn(evt, *truthcol, *gtruthcol, *gassns, gtruthcol->size()-1, gtruthcol->size());
282 
283 
284  // std::cout<<"end of i mcsize"<<std::endl;
285 
286 
287  }
288 
289  // Define the FLSHitList and Particle vectors.
290 
291 
292  std::unique_ptr< std::vector<simb::MCTruth> > temptruelist (new std::vector<simb::MCTruth>);
293  std::unique_ptr< std::vector<sim::Particle> > temppartlist (new std::vector<sim::Particle>);
294 
295  bool NewMCList = false;
296  int MCListIndex = -1;
297  for(unsigned int j = 0; j < pcol->size(); ++j){
298  sim::Particle part ((*pcol)[j]);
299  if(part.Mother()!=0 )NewMCList=false;
300  if(part.Mother()==0 && ! NewMCList){
301  MCListIndex++;
302  // std::cout << " pushing truthcol index " << MCListIndex << " onto temptrue " << std::endl;
303 
304  simb::MCTruth truth ((*truthcol)[MCListIndex]);
305  temptruelist->push_back(truth);
306  NewMCList=true;
307  }
308  // std::cout << j << " " << temptruelist->size()-1 << std::endl;
309 
310  temppartlist->push_back(part);
311  util::CreateAssn(evt, *temppartlist, *temptruelist, *passns, temptruelist->size()-1,temptruelist->size());
312 
313 
314  }
315 
316 
317  // put the collections in the event
318  evt.put(std::move(temptruelist));
319  evt.put(std::move(fluxcol));
320  evt.put(std::move(gtruthcol));
321  evt.put(std::move(assns));
322  evt.put(std::move(gassns));
323  evt.put(std::move(flshlcol));
324  evt.put(std::move(temppartlist));
325  evt.put(std::move(passns));
326  // int dum;
327  // std::cin >> dum;
328 
329  delete [] Offset ;
330  delete [] OffsetParticles;
331 
332  }
void SetTrackId(const int trackid)
Definition: FLSHit.h:101
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.
std::vector< sim::FLSHit > fHits
Definition: FLSHitList.h:21
std::string fFirstG4Collection
Label on the main collection.
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
int fIsFirstCollectionCosmic
Label on the main collection.
Loaders::FluxType flux
TString part[npart]
Definition: Style.C:32
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
void hits()
Definition: readHits.C:15
Float_t d
Definition: plot.C:236
const double j
Definition: BetheBloch.cxx:29
std::string fSecondCollection
Label on the main collection.
OStream cout
Definition: OStream.cxx:6
size_t Offset(bool allow_default)
Value passed to –offset, or 0 if not specified.
Definition: Utilities.cxx:395
void SetGvtx(double *v)
Definition: MCParticle.cxx:120
A vector of FLSHit from single neutrino interaction.
Definition: FLSHitList.h:13
void Clear()
Clear the FLS hit.
Definition: FLSHit.cxx:39
Event generator information.
Definition: MCTruth.h:32
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  )
inherited
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited
std::string art::EDProducer::workerType ( ) const
inherited

Member Data Documentation

std::string MergeCollections::MergeCollections::fFirstG4Collection
protected

Label on the main collection.

Definition at line 47 of file MergeCollections_module.cc.

std::string MergeCollections::MergeCollections::fFirstGenCollection
protected

Definition at line 46 of file MergeCollections_module.cc.

int MergeCollections::MergeCollections::fIsFirstCollectionCosmic
protected

Label on the main collection.

Definition at line 49 of file MergeCollections_module.cc.

std::string MergeCollections::MergeCollections::fSecondCollection
protected

Label on the main collection.

Definition at line 48 of file MergeCollections_module.cc.


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