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

 MergeGenCollections (fhicl::ParameterSet const &pset)
 
virtual ~MergeGenCollections ()
 
void produce (art::Event &evt)
 
void endSubRun (art::SubRun &sr)
 
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
 

Protected Attributes

std::string fFirstCollection
 
std::string fSecondCollection
 MCTruth label for main collection. More...
 
bool fFirstColIsMCNu
 Process label for the second collection. More...
 
bool fSecondColIsMCNu
 
bool fMergeDk2Nu
 
int fSecondaryModeOffset
 Merge Dk2Nu/NuChoice objects? More...
 

Detailed Description

Definition at line 38 of file MergeGenCollections_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

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

Definition at line 60 of file MergeGenCollections_module.cc.

References om::cerr, and allTimeWatchdog::endl.

60  :
61  fFirstCollection (pset.get< std::string >("FirstGenCollection","")),
62  fSecondCollection (pset.get< std::string >("SecondCollection","")),
63  fFirstColIsMCNu (!pset.get< bool >("IsFirstCollectionCosmic")),
64  fSecondColIsMCNu (!pset.get< bool >("IsSecondCollectionCosmic")),
65  fMergeDk2Nu (pset.get< bool >("MergeDk2Nu")),
66  fSecondaryModeOffset (pset.get< int >("SecondaryModeOffset",0))
67  {
68  if(fFirstCollection=="" && fSecondCollection==""){
69  std::cerr << "MergeGenCollections: "
70  << "Neither collection is specified to merge from. Abort."
71  << std::endl;
72  std::abort();
73  }
75  std::cerr << "MergeGenCollections: "
76  << "No MC Collections to merge. Abort."
77  << std::endl;
78  std::abort();
79  }
80 
81  produces< sumdata::POTSum, art::InSubRun >();
82  produces< sumdata::SpillData >();
83  produces< std::vector<simb::MCTruth> >();
84  produces< std::vector<simb::MCFlux> >();
85  produces< std::vector<simb::GTruth> >();
86  produces< std::vector<bsim::Dk2Nu> >();
87  produces< std::vector<bsim::NuChoice> >();
88  produces< art::Assns<simb::MCTruth, simb::MCFlux> >();
89  produces< art::Assns<simb::MCTruth, simb::GTruth> >();
90  }
int fSecondaryModeOffset
Merge Dk2Nu/NuChoice objects?
OStream cerr
Definition: OStream.cxx:7
std::string fSecondCollection
MCTruth label for main collection.
bool fFirstColIsMCNu
Process label for the second collection.
enum BeamMode string
MergeGenCollections::MergeGenCollections::~MergeGenCollections ( )
virtual

Definition at line 93 of file MergeGenCollections_module.cc.

94  {
95  }

Member Function Documentation

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
void MergeGenCollections::MergeGenCollections::endSubRun ( art::SubRun sr)
virtual

Reimplemented from art::EDProducer.

Definition at line 242 of file MergeGenCollections_module.cc.

References DEFINE_ART_MODULE(), art::DataViewImpl::getByLabel(), art::Handle< T >::isValid(), pots, and art::SubRun::put().

243  {
244  std::unique_ptr< sumdata::POTSum > potcol(new sumdata::POTSum);
245 
246  if(fFirstColIsMCNu) {
248  sr.getByLabel(fFirstCollection, pots);
249 
250  if(pots.isValid()) *potcol = *pots;
251  }
252  else if(fSecondColIsMCNu) {
253  mf::LogWarning("MergeGenCollections")
254  << "Ignoring second-collection POTSum, using only first";
255  }
256  sr.put(std::move(potcol));
257  }
int pots
bool fFirstColIsMCNu
Process label for the second collection.
bool isValid() const
Definition: Handle.h:189
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
ProductID put(std::unique_ptr< PROD > &&)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
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 MergeGenCollections::MergeGenCollections::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 98 of file MergeGenCollections_module.cc.

References simb::MCTruth::Add(), simb::MCNeutrino::CCNC(), util::CreateAssn(), dk2nu, flux, art::DataViewImpl::getByLabel(), simb::MCTruth::GetNeutrino(), simb::MCTruth::GetParticle(), simb::MCNeutrino::HitNuc(), simb::MCNeutrino::HitQuark(), MECModelEnuComparisons::i, simb::MCNeutrino::InteractionType(), art::Handle< T >::isValid(), simb::MCNeutrino::Mode(), simb::MCTruth::NParticles(), simb::MCTruth::Origin(), art::Event::put(), simb::MCNeutrino::QSqr(), simb::MCTruth::SetNeutrino(), simb::MCTruth::SetOrigin(), art::DataViewImpl::size(), gen_flatrecord::size, caf_analysis::spill, simb::MCNeutrino::Target(), simb::MCNeutrino::W(), simb::MCNeutrino::X(), and simb::MCNeutrino::Y().

99  {
100  std::unique_ptr< sumdata::SpillData > spillcol (new sumdata::SpillData);
101  std::unique_ptr< std::vector<simb::MCTruth> > truthcol (new std::vector<simb::MCTruth >);
102  std::unique_ptr< std::vector<simb::MCFlux> > fluxcol (new std::vector<simb::MCFlux >);
103  std::unique_ptr< std::vector<simb::GTruth> > gtruthcol(new std::vector<simb::GTruth >);
104  std::unique_ptr< std::vector<bsim::Dk2Nu> > dk2nucol (new std::vector<bsim::Dk2Nu >);
105  std::unique_ptr< std::vector<bsim::NuChoice> > nuccol (new std::vector<bsim::NuChoice>);
106 
107  std::unique_ptr< art::Assns<simb::MCTruth, simb::MCFlux> > assns (new art::Assns<simb::MCTruth, simb::MCFlux>);
108  std::unique_ptr< art::Assns<simb::MCTruth, simb::GTruth> > gassns(new art::Assns<simb::MCTruth, simb::GTruth>);
109 
110 
111 
112  //// First Collection
113  //
114  if(fFirstCollection!=""){ // Dont look for MC if not there
115 
116  // Pull SpillData from the first collection only
118  evt.getByLabel(fFirstCollection, spill);
119  if(spill.isValid()) *spillcol = *spill;
120 
121  // MCTruth from generator -- not necessarily neutrino MC
123  evt.getByLabel(fFirstCollection, mclist);
124 
129  if(fFirstColIsMCNu) {
130  evt.getByLabel(fFirstCollection, fllist);
131  evt.getByLabel(fFirstCollection, glist);
132  if(fMergeDk2Nu){
133  evt.getByLabel(fFirstCollection, dklist);
134  evt.getByLabel(fFirstCollection, nulist);
135  }
136  }
137 
138  // Loop over MCTruths and associate to Flux/GTruth
139  for(unsigned int i = 0; i < mclist->size(); ++i){
140  simb::MCTruth truth ((*mclist)[i]);
141  truthcol->push_back(truth);
142 
143  if(fFirstColIsMCNu){
144  if(i < fllist->size() && i < glist->size()){
145  simb::MCFlux flux ((*fllist)[i]);
146  simb::GTruth gtruth ((*glist)[i]);
147  fluxcol ->push_back(flux);
148  gtruthcol->push_back(gtruth);
149 
150  util::CreateAssn(*this, evt, *truthcol, *fluxcol, *assns, fluxcol ->size()-1, fluxcol ->size());
151  util::CreateAssn(*this, evt, *truthcol, *gtruthcol, *gassns, gtruthcol->size()-1, gtruthcol->size());
152  }
153  if(i < dklist->size() && i < nulist->size()){
154  bsim::Dk2Nu dk2nu ((*dklist)[i]);
155  dk2nucol->push_back(dk2nu);
156  bsim::NuChoice nuc ((*nulist)[i]);
157  nuccol ->push_back(nuc);
158  }
159  } // end fFirstColIsMCNu
160  } // end loop over MCTruths
161  } // If FirstCollection specified
162 
163 
164 
165  //// Second Collection
166  //
167  if(fSecondCollection!=""){ // dont use label if not there
169  evt.getByLabel(fSecondCollection, mc2list);
170 
175  if(fSecondColIsMCNu) {
176  evt.getByLabel(fSecondCollection, g2list);
177  evt.getByLabel(fSecondCollection, fl2list);
178  evt.getByLabel(fSecondCollection, dk2list);
179  evt.getByLabel(fSecondCollection, nu2list);
180  }
181 
182  for(unsigned int i = 0; i < mc2list->size(); ++i){
183  simb::MCTruth tru2 ((*mc2list)[i]);
184 
186  // Make new truth so MCNeutrino mode can be
187  // offset and used to flag overlaid MCTruth
188  simb::MCNeutrino nu2 = tru2.GetNeutrino();
189  simb::MCTruth truth;
190  truth.SetOrigin(tru2.Origin());
191  for( int p=0; p<tru2.NParticles(); p++ ){
192  simb::MCParticle mcp2 = tru2.GetParticle(p);
193  truth.Add(mcp2);
194  }
195  // set nu must be after MCParticle list is made
196  truth.SetNeutrino( nu2.CCNC(),
197  nu2.Mode() + fSecondaryModeOffset,
198  nu2.InteractionType(),
199  nu2.Target(), nu2.HitNuc(),
200  nu2.HitQuark(), nu2.W(),
201  nu2.X(), nu2.Y(),nu2.QSqr() );
202  truthcol->push_back(truth);
203 
204  } else {
205  // don't bother if no offset
206  truthcol->push_back(tru2);
207  }
208 
209 
210  if(fSecondColIsMCNu) {
211  if(i < fl2list->size() && i < g2list->size()){
212  simb::MCFlux flux ((*fl2list)[i]);
213  simb::GTruth gtruth ((*g2list) [i]);
214  gtruthcol->push_back(gtruth);
215  fluxcol->push_back(flux);
216 
217  util::CreateAssn(*this, evt, *truthcol, *fluxcol, *assns, fluxcol ->size()-1, fluxcol ->size());
218  util::CreateAssn(*this, evt, *truthcol, *gtruthcol, *gassns, gtruthcol->size()-1, gtruthcol->size());
219  }
220  if(i < dk2list->size() && i < nu2list->size()){
221  bsim::Dk2Nu dk2nu ((*dk2list)[i]);
222  dk2nucol->push_back(dk2nu);
223  bsim::NuChoice nuc ((*nu2list)[i]);
224  nuccol ->push_back(nuc);
225  }
226  } // end fSecondColIsMCNu
227  } // end loop over MCTruths
228  } // If SecondCollection specified
229 
230  // put the collections in the event
231  evt.put(std::move(spillcol));
232  evt.put(std::move(truthcol));
233  evt.put(std::move(fluxcol));
234  evt.put(std::move(gtruthcol));
235  evt.put(std::move(dk2nucol));
236  evt.put(std::move(nuccol));
237  evt.put(std::move(assns));
238  evt.put(std::move(gassns));
239  }
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.
int CCNC() const
Definition: MCNeutrino.h:148
double QSqr() const
Definition: MCNeutrino.h:157
int HitQuark() const
Definition: MCNeutrino.h:153
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:80
int fSecondaryModeOffset
Merge Dk2Nu/NuChoice objects?
const char * p
Definition: xmltok.h:285
int HitNuc() const
Definition: MCNeutrino.h:152
std::string fSecondCollection
MCTruth label for main collection.
bool fFirstColIsMCNu
Process label for the second collection.
void SetNeutrino(int CCNC, int mode, int interactionType, int target, int nucleon, int quark, double w, double x, double y, double qsqr)
Definition: MCTruth.cxx:30
bsim::Dk2Nu * dk2nu
void Add(simb::MCParticle &part)
Definition: MCTruth.h:79
Loaders::FluxType flux
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:189
int InteractionType() const
Definition: MCNeutrino.h:150
double W() const
Definition: MCNeutrino.h:154
double Y() const
Definition: MCNeutrino.h:156
double X() const
Definition: MCNeutrino.h:155
int Target() const
Definition: MCNeutrino.h:151
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Event generator information.
Definition: MCTruth.h:32
Event generator information.
Definition: MCNeutrino.h:18
int Mode() const
Definition: MCNeutrino.h:149
size_t size() const
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 MergeGenCollections::MergeGenCollections::fFirstColIsMCNu
protected

Process label for the second collection.

Definition at line 52 of file MergeGenCollections_module.cc.

std::string MergeGenCollections::MergeGenCollections::fFirstCollection
protected

Definition at line 50 of file MergeGenCollections_module.cc.

bool MergeGenCollections::MergeGenCollections::fMergeDk2Nu
protected

Definition at line 54 of file MergeGenCollections_module.cc.

int MergeGenCollections::MergeGenCollections::fSecondaryModeOffset
protected

Merge Dk2Nu/NuChoice objects?

Definition at line 55 of file MergeGenCollections_module.cc.

bool MergeGenCollections::MergeGenCollections::fSecondColIsMCNu
protected

Definition at line 53 of file MergeGenCollections_module.cc.

std::string MergeGenCollections::MergeGenCollections::fSecondCollection
protected

MCTruth label for main collection.

Definition at line 51 of file MergeGenCollections_module.cc.


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