CMS 3D CMS Logo

HiMixingModule.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HiMixingModule
4 // Class: HiMixingModule
5 //
13 //
14 // Original Author: Yetkin Yilmaz
15 // Created: Tue Feb 17 17:32:06 EST 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 #include <iostream>
23 #include <memory>
24 #include <vector>
25 
26 // user include files
29 
32 
37 
45 
56 
57 #include <string>
58 
59 using namespace std;
60 
61 //
62 // class decleration
63 //
64 
65 namespace edm {
66 
67  class HiMixingModule;
68 
70  public:
71  explicit HiMixingWorkerBase() { ; }
72 
73  HiMixingWorkerBase(std::string& object, std::vector<InputTag>& tags, std::string& label)
74  : object_(object), tags_(tags), label_(label) {
75  ;
76  }
77  virtual ~HiMixingWorkerBase() { ; }
78  // virtual void put(edm::Event &e) = 0;
79  virtual void addSignals(edm::Event& e) = 0;
80 
82  std::vector<InputTag> tags_;
84  };
85 
86  template <class T>
88  public:
89  HiMixingWorker(std::string& object, std::vector<InputTag>& tags, std::string& label)
91  ;
92  }
93  ~HiMixingWorker() override { ; }
94  void addSignals(edm::Event& e) override {
95  std::vector<Handle<std::vector<T> > > handles;
96  bool get = true;
97  for (size_t itag = 0; itag < tags_.size(); ++itag) {
98  LogInfo("HiEmbedding") << "itag " << itag;
99  LogInfo("HiEmbedding") << "label " << tags_[itag].label();
100  LogInfo("HiEmbedding") << "instance " << tags_[itag].instance();
101  Handle<std::vector<T> > hand;
102  handles.push_back(hand);
103  get = get && e.getByLabel(tags_[itag], handles[itag]);
104  if (!get)
105  LogWarning("Product inconsistency")
106  << "One of the sub-events is missing the product with type " << object_ << ", instance "
107  << tags_[itag].instance() << " whereas the other one is fine.";
108  }
109 
110  if (get) {
111  std::unique_ptr<CrossingFrame<T> > crFrame(new CrossingFrame<T>());
112  crFrame->addSignals(handles[0].product(), e.id());
113  for (size_t itag = 1; itag < tags_.size(); ++itag) {
114  std::vector<T>* product = const_cast<std::vector<T>*>(handles[itag].product());
115  EncodedEventId id(0, itag);
116  for (auto& item : *product) {
117  item.setEventId(id);
118  }
119  crFrame->addPileups(*product);
120  }
121  e.put(std::move(crFrame), label_);
122  }
123  }
124  };
125 
126  template <>
128  std::vector<Handle<HepMCProduct> > handles;
129  bool get = true;
130  for (size_t itag = 0; itag < tags_.size(); ++itag) {
132  handles.push_back(hand);
133  get = get && e.getByLabel(tags_[itag], handles[itag]);
134  if (!get)
135  LogWarning("Product inconsistency")
136  << "One of the sub-events is missing the product with type " << object_ << ", instance "
137  << tags_[itag].instance() << " whereas the other one is fine.";
138  }
139 
140  if (get) {
141  std::unique_ptr<CrossingFrame<HepMCProduct> > crFrame(new CrossingFrame<HepMCProduct>());
142  crFrame->addSignals(handles[0].product(), e.id());
143  for (size_t itag = 1; itag < tags_.size(); ++itag) {
144  HepMCProduct* product = const_cast<HepMCProduct*>(handles[itag].product());
145  crFrame->addPileups(*product);
146  }
147  e.put(std::move(crFrame), label_);
148  }
149  }
150 
152  public:
153  explicit HiMixingModule(const edm::ParameterSet&);
154  ~HiMixingModule() override;
155 
156  private:
157  //virtual void beginJob() override {}
158  void produce(edm::Event&, const edm::EventSetup&) override;
159  //virtual void endJob() override {}
160  bool verifyRegistry(std::string object, std::string subdet, InputTag& tag, std::string& label);
161  // ----------member data ---------------------------
162 
163  std::vector<HiMixingWorkerBase*> workers_;
164  };
165 
166  //
167  // constants, enums and typedefs
168  //
169 
170  //
171  // static data member definitions
172  //
173 
174  //
175  // constructors and destructor
176  //
177  HiMixingModule::HiMixingModule(const edm::ParameterSet& pset) {
178  ParameterSet ps = pset.getParameter<ParameterSet>("mixObjects");
179  std::vector<std::string> names = ps.getParameterNames();
180  std::vector<std::string> simtags = pset.getParameter<std::vector<std::string> >("srcSIM");
181  std::vector<std::string> gentags = pset.getParameter<std::vector<std::string> >("srcGEN");
182 
183  if (simtags.size() != gentags.size())
184  LogError("MixingInput") << "Generator and Simulation input lists are not matching each other" << endl;
185 
186  for (std::vector<string>::iterator it = names.begin(); it != names.end(); ++it) {
187  ParameterSet pstag = ps.getParameter<ParameterSet>((*it));
188  if (!pstag.exists("type"))
189  continue; //to allow replacement by empty pset
190  std::string object = pstag.getParameter<std::string>("type");
191  std::vector<InputTag> tags = pstag.getParameter<std::vector<InputTag> >("input");
192 
193  std::string signal;
194  for (size_t itag = 0; itag < tags.size(); ++itag) {
195  InputTag tag = tags[itag];
196  std::vector<InputTag> inputs;
197 
198  for (size_t input = 0; input < simtags.size(); ++input) {
199  if (object == "HepMCProduct")
200  signal = gentags[input];
201  else
202  signal = simtags[input];
203  inputs.push_back(InputTag(signal, tag.instance()));
204  }
205 
206  std::string label = tag.label() + tag.instance();
207  // verifyRegistry(object,std::string(""),tag,label);
208  if (object == "HepMCProduct") {
209  workers_.push_back(new HiMixingWorker<HepMCProduct>(object, inputs, label));
210  produces<CrossingFrame<HepMCProduct> >(label);
211  consumes<HepMCProduct>(tag);
212  } else if (object == "SimTrack") {
213  workers_.push_back(new HiMixingWorker<SimTrack>(object, inputs, label));
214  produces<CrossingFrame<SimTrack> >(label);
215  consumes<std::vector<SimTrack> >(tag);
216  } else if (object == "SimVertex") {
217  workers_.push_back(new HiMixingWorker<SimVertex>(object, inputs, label));
218  produces<CrossingFrame<SimVertex> >(label);
219  consumes<std::vector<SimVertex> >(tag);
220  } else if (object == "PSimHit") {
221  workers_.push_back(new HiMixingWorker<PSimHit>(object, inputs, label));
222  produces<CrossingFrame<PSimHit> >(label);
223  consumes<std::vector<PSimHit> >(tag);
224  } else if (object == "PCaloHit") {
225  workers_.push_back(new HiMixingWorker<PCaloHit>(object, inputs, label));
226  produces<CrossingFrame<PCaloHit> >(label);
227  consumes<std::vector<PCaloHit> >(tag);
228  } else
229  LogInfo("Error") << "What the hell is this object?!";
230 
231  LogInfo("HiMixingModule") << "Will mix " << object << "s with InputTag= " << tag.encode() << ", label will be "
232  << label;
233  }
234  }
235 
236  produces<PileupMixingContent>();
237  }
238 
239  HiMixingModule::~HiMixingModule() {
240  // do anything here that needs to be done at desctruction time
241  // (e.g. close files, deallocate resources etc.)
242  }
243 
244  //
245  // member functions
246  //
247 
248  // ------------ method called to produce the data ------------
249  void HiMixingModule::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
250  using namespace edm;
251 
252  for (size_t i = 0; i < workers_.size(); ++i) {
253  (workers_[i])->addSignals(iEvent);
254  }
255 
256  std::unique_ptr<PileupMixingContent> PileupMixing_ = std::make_unique<PileupMixingContent>();
257  iEvent.put(std::move(PileupMixing_));
258  }
259 
260  bool HiMixingModule::verifyRegistry(std::string object, std::string subdet, InputTag& tag, std::string& label) {
261  // verify that the given product exists in the product registry
262  // and create the label to be given to the CrossingFrame
263 
265  // Loop over provenance of products in registry.
266  std::string lookfor;
267  if (object == "HepMCProduct")
268  lookfor = "edm::" + object; //exception for HepMCProduct
269  else if (object == "edm::HepMCProduct")
270  lookfor = object;
271  else
272  lookfor = "std::vector<" + object + ">";
273  bool found = false;
274  for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin();
275  it != reg->productList().end();
276  ++it) {
277  // See FWCore/Framework/interface/BranchDescription.h
278  // BranchDescription contains all the information for the product.
279  edm::BranchDescription desc = it->second;
280  if (desc.className() == lookfor && desc.moduleLabel() == tag.label() &&
281  desc.productInstanceName() == tag.instance()) {
282  label = desc.moduleLabel() + desc.productInstanceName();
283  found = true;
284  /*
285  wantedBranches_.push_back(desc.friendlyClassName() + '_' +
286  desc.moduleLabel() + '_' +
287  desc.productInstanceName());
288  */
289  break;
290  }
291  }
292  if (!found) {
293  LogWarning("MixingModule") << "!!!!!!!!!Could not find in registry requested object: " << object << " with "
294  << tag << ".\nWill NOT be considered for mixing!!!!!!!!!";
295  return false;
296  }
297 
298  return true;
299  }
300 
301  //define this as a plug-in
303 
304 } // namespace edm
ConstProductRegistry.h
Handle.h
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
edm::HiMixingModule
Definition: HiMixingModule.cc:151
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::HiMixingWorkerBase::HiMixingWorkerBase
HiMixingWorkerBase(std::string &object, std::vector< InputTag > &tags, std::string &label)
Definition: HiMixingModule.cc:73
CrossingFrame.h
PSimHitContainer.h
edm::ConstProductRegistry::productList
ProductList const & productList() const
Definition: ConstProductRegistry.h:44
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
Algorithms.h
EDProducer.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::HiMixingWorkerBase::tags_
std::vector< InputTag > tags_
Definition: HiMixingModule.cc:82
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::HiMixingWorker
Definition: HiMixingModule.cc:87
edm::HiMixingWorker::HiMixingWorker
HiMixingWorker(std::string &object, std::vector< InputTag > &tags, std::string &label)
Definition: HiMixingModule.cc:89
EncodedEventId
Definition: EncodedEventId.h:11
EDMException.h
CrossingFrame
Definition: CrossingFrame.h:38
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
Service.h
Provenance.h
ProductID.h
magneticfield::handles
std::vector< BaseVolumeHandle * > handles
Definition: BaseVolumeHandle.h:154
edm::HiMixingWorker::~HiMixingWorker
~HiMixingWorker() override
Definition: HiMixingModule.cc:93
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
BranchDescription.h
edm::ParameterSet
Definition: ParameterSet.h:47
edm::HiMixingWorkerBase::label_
std::string label_
Definition: HiMixingModule.cc:83
Event.h
edm::HiMixingWorkerBase
Definition: HiMixingModule.cc:69
edm::ParameterSet::getParameterNames
std::vector< std::string > getParameterNames() const
Definition: ParameterSet.cc:663
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
edm::stream::EDProducer
Definition: EDProducer.h:38
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
InputTag.h
edm::HiMixingModule::workers_
std::vector< HiMixingWorkerBase * > workers_
Definition: HiMixingModule.cc:163
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::HiMixingWorkerBase::HiMixingWorkerBase
HiMixingWorkerBase()
Definition: HiMixingModule.cc:71
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
HiMixingModule
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PCaloHitContainer.h
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
PileupMixingContent.h
edm::BranchDescription
Definition: BranchDescription.h:32
edm::HepMCProduct
Definition: HepMCProduct.h:18
ParameterSet.h
edm::HiMixingWorkerBase::object_
std::string object_
Definition: HiMixingModule.cc:81
edm::HiMixingWorker::addSignals
void addSignals(edm::Event &e) override
Definition: HiMixingModule.cc:94
HepMCProduct.h
edm::Event
Definition: Event.h:73
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
edm::HiMixingWorkerBase::~HiMixingWorkerBase
virtual ~HiMixingWorkerBase()
Definition: HiMixingModule.cc:77
label
const char * label
Definition: PFTauDecayModeTools.cc:11
SimVertexContainer.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37