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