CMS 3D CMS Logo

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