CMS 3D CMS Logo

MixingWorker.h
Go to the documentation of this file.
1 #ifndef MixingWorker_h
2 #define MixingWorker_h
3 
19 
24 
29 
30 #include <memory>
31 #include <vector>
32 #include <string>
33 #include <typeinfo>
34 #include "MixingWorkerBase.h"
35 
36 class SimTrack;
37 class SimVertex;
38 namespace edm {
39  template <class T>
40  class MixingWorker : public MixingWorkerBase {
41  public:
43  explicit MixingWorker()
44  : minBunch_(-5),
45  maxBunch_(3),
46  bunchSpace_(75),
47  subdet_(std::string(" ")),
48  label_(std::string(" ")),
49  labelCF_(std::string(" ")),
50  maxNbSources_(5),
52  tag_(),
53  tagSignal_(),
54  allTags_(),
55  crFrame_(nullptr) {}
56 
57  /*Normal constructor*/
59  int maxBunch,
60  int bunchSpace,
61  std::string subdet,
63  std::string labelCF,
64  int maxNbSources,
65  InputTag &tag,
66  InputTag &tagCF,
67  bool makePCrossingFrame = false)
68  : MixingWorkerBase(),
69  minBunch_(minBunch),
70  maxBunch_(maxBunch),
71  bunchSpace_(bunchSpace),
72  subdet_(subdet),
73  label_(label),
74  labelCF_(labelCF),
75  maxNbSources_(maxNbSources),
76  makePCrossingFrame_(makePCrossingFrame),
77  tag_(tag),
78  tagSignal_(tagCF),
79  allTags_(),
80  crFrame_(nullptr) {}
81 
82  /*constructor for HepMCproduct case*/
84  int maxBunch,
85  int bunchSpace,
86  std::string subdet,
88  std::string labelCF,
89  int maxNbSources,
90  InputTag &tag,
91  InputTag &tagCF,
92  std::vector<InputTag> const &tags)
93  : MixingWorkerBase(),
94  minBunch_(minBunch),
95  maxBunch_(maxBunch),
96  bunchSpace_(bunchSpace),
97  subdet_(subdet),
98  label_(label),
99  labelCF_(labelCF),
100  maxNbSources_(maxNbSources),
102  tag_(tag),
103  tagSignal_(tagCF),
104  allTags_(tags),
105  crFrame_(nullptr) {}
106 
108  ~MixingWorker() override { ; }
109 
110  public:
111  void reload(const edm::EventSetup &setup) override {
112  //get the required parameters from DB.
113  // watch the label/tag
115  setup.get<MixingRcd>().get(config);
116  minBunch_ = config->minBunch();
117  maxBunch_ = config->maxBunch();
118  bunchSpace_ = config->bunchSpace();
119  }
120 
121  bool checkSignal(const edm::Event &e) override {
122  bool got;
123  InputTag t;
124  edm::Handle<std::vector<T> > result_t;
125  got = e.getByLabel(tag_, result_t);
126  t = InputTag(tag_.label(), tag_.instance());
127 
128  if (got)
129  LogInfo("MixingModule") << " Will create a CrossingFrame for " << typeid(T).name()
130  << " with InputTag= " << t.encode();
131 
132  return got;
133  }
134 
135  void createnewEDProduct() override {
136  crFrame_ = std::make_unique<CrossingFrame<T> >(minBunch_, maxBunch_, bunchSpace_, subdet_, maxNbSources_);
137  }
138 
139  void addSignals(const edm::Event &e) override {
140  edm::Handle<std::vector<T> > result_t;
141  bool got = e.getByLabel(tag_, result_t);
142  if (got) {
143  LogDebug("MixingModule") << " adding " << result_t.product()->size() << " signal objects for "
144  << typeid(T).name() << " with " << tag_;
145  crFrame_->addSignals(result_t.product(), e.id());
146  } else {
147  LogInfo("MixingModule") << "!!!!!!! Did not get any signal data for " << typeid(T).name() << ", with " << tag_;
148  }
149  }
150 
151  void addPileups(const EventPrincipal &ep, ModuleCallingContext const *, unsigned int eventNr) override;
152 
153  void setBcrOffset() override { crFrame_->setBcrOffset(); }
154  void setSourceOffset(const unsigned int s) override { crFrame_->setSourceOffset(s); }
155 
156  void setTof() override;
157 
158  void put(edm::Event &e) override {
159  if (makePCrossingFrame_) {
160  e.put(std::make_unique<PCrossingFrame<T> >(*crFrame_), label_);
161  }
163  LogDebug("MixingModule") << " CF was put for type " << typeid(T).name() << " with " << label_;
164  }
165 
166  // When using mixed secondary source
167  // Copy the data from the PCrossingFrame to the CrossingFrame
168  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
169 
170  private:
177  unsigned int const maxNbSources_;
181  std::vector<InputTag> allTags_; // for HepMCProduct
182 
183  std::unique_ptr<CrossingFrame<T> > crFrame_;
184  };
185 
186  template <typename T>
187  void MixingWorker<T>::addPileups(const EventPrincipal &ep, ModuleCallingContext const *mcc, unsigned int eventNr) {
188  std::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_, mcc);
189  if (shPtr) {
190  LogDebug("MixingModule") << shPtr->product()->size() << " pileup objects added, eventNr " << eventNr;
191  crFrame_->setPileupPtr(shPtr);
192  crFrame_->addPileups(*shPtr->product());
193  }
194  }
195  //=============== template specializations ====================================================================================
196 
197  template <>
199  ModuleCallingContext const *,
200  unsigned int eventNr);
201 
202  template <class T>
204  ;
205  }
206 
207  template <class T>
209  crFrame_->setBunchRange(PCF->getBunchRange());
210  crFrame_->setBunchSpace(PCF->getBunchSpace());
211  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
212  crFrame_->setSubDet(PCF->getSubDet());
213  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
214  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
215  crFrame_->setPileups(PCF->getPileups());
216 
217  // For playback option
218  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
219  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
220  }
221 
222 } // namespace edm
223 
224 #endif
#define LogDebug(id)
const std::vector< std::vector< unsigned int > > & getPileupOffsetsSource() const
void addSignals(const edm::Event &e) override
Definition: MixingWorker.h:139
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::unique_ptr< CrossingFrame< T > > crFrame_
Definition: MixingWorker.h:183
const int & bunchSpace() const
bool const makePCrossingFrame_
Definition: MixingWorker.h:178
MixingWorker(int minBunch, int maxBunch, int bunchSpace, std::string subdet, std::string label, std::string labelCF, int maxNbSources, InputTag &tag, InputTag &tagCF, bool makePCrossingFrame=false)
Definition: MixingWorker.h:58
#define nullptr
void setTof() override
Definition: MixingWorker.h:203
int getBunchSpace() const
unsigned int getPileupFileNr() const
std::string const labelCF_
Definition: MixingWorker.h:176
std::vector< const T * > getPileups() const
std::string encode() const
Definition: InputTag.cc:159
bool checkSignal(const edm::Event &e) override
Definition: MixingWorker.h:121
void setSourceOffset(const unsigned int s) override
Definition: MixingWorker.h:154
const int & maxBunch() const
config
Definition: looper.py:291
edm::EventID getIdFirstPileup() const
char const * label
void put(edm::Event &e) override
Definition: MixingWorker.h:158
void addPileups(const EventPrincipal &ep, ModuleCallingContext const *, unsigned int eventNr) override
Definition: MixingWorker.h:187
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:208
~MixingWorker() override
Definition: MixingWorker.h:108
MixingWorker(int minBunch, int maxBunch, int bunchSpace, std::string subdet, std::string label, std::string labelCF, int maxNbSources, InputTag &tag, InputTag &tagCF, std::vector< InputTag > const &tags)
Definition: MixingWorker.h:83
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
std::vector< InputTag > allTags_
Definition: MixingWorker.h:181
std::string getSubDet() const
T const * product() const
Definition: Handle.h:69
unsigned int getMaxNbSources() const
std::pair< int, int > getBunchRange() const
void setBcrOffset() override
Definition: MixingWorker.h:153
std::string const & label() const
Definition: InputTag.h:36
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
std::string const label_
Definition: MixingWorker.h:175
T get() const
Definition: EventSetup.h:73
void reload(const edm::EventSetup &setup) override
Definition: MixingWorker.h:111
const int & minBunch() const
long double T
std::string const subdet_
Definition: MixingWorker.h:174
void createnewEDProduct() override
Definition: MixingWorker.h:135
std::string const & instance() const
Definition: InputTag.h:37
const std::vector< unsigned int > & getPileupOffsetsBcr() const
def move(src, dest)
Definition: eostools.py:511
unsigned int const maxNbSources_
Definition: MixingWorker.h:177