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 {
40  template <class T>
42  {
43  public:
44 
46  explicit MixingWorker() :
47  minBunch_(-5),
48  maxBunch_(3),
49  bunchSpace_(75),
50  subdet_(std::string(" ")),
51  label_(std::string(" ")),
52  labelCF_(std::string(" ")),
53  maxNbSources_(5),
55  tag_(),
56  tagSignal_(),
57  allTags_(),
59  {
60  }
61 
62  /*Normal constructor*/
63  MixingWorker(int minBunch,int maxBunch, int bunchSpace,
65  std::string labelCF,int maxNbSources, InputTag& tag,
66  InputTag& tagCF, bool makePCrossingFrame=false):
68  minBunch_(minBunch),
69  maxBunch_(maxBunch),
70  bunchSpace_(bunchSpace),
71  subdet_(subdet),
72  label_(label),
73  labelCF_(labelCF),
74  maxNbSources_(maxNbSources),
75  makePCrossingFrame_(makePCrossingFrame),
76  tag_(tag),
77  tagSignal_(tagCF),
78  allTags_(),
80  {
81  }
82 
83  /*constructor for HepMCproduct case*/
84  MixingWorker(int minBunch,int maxBunch, int bunchSpace,
86  std::string labelCF,int maxNbSources, InputTag& tag,
87  InputTag& tagCF,
88  std::vector<InputTag> const& tags) :
90  minBunch_(minBunch),
91  maxBunch_(maxBunch),
92  bunchSpace_(bunchSpace),
93  subdet_(subdet),
94  label_(label),
95  labelCF_(labelCF),
96  maxNbSources_(maxNbSources),
98  tag_(tag),
99  tagSignal_(tagCF),
100  allTags_(tags),
102  {
103  }
104 
106  ~MixingWorker() override {;}
107 
108  public:
109 
110  void reload(const edm::EventSetup & setup) override{
111  //get the required parameters from DB.
112  // watch the label/tag
114  setup.get<MixingRcd>().get(config);
115  minBunch_=config->minBunch();
116  maxBunch_=config->maxBunch();
117  bunchSpace_=config->bunchSpace();
118  }
119 
120  bool checkSignal(const edm::Event &e) override{
121  bool got;
122  InputTag t;
123  edm::Handle<std::vector<T> > result_t;
124  got = e.getByLabel(tag_,result_t);
125  t = InputTag(tag_.label(),tag_.instance());
126 
127  if (got)
128  LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name()
129  << " with InputTag= "<< t.encode();
130 
131  return got;
132  }
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 "<<typeid(T).name()<<" with "<<tag_;
144  crFrame_->addSignals(result_t.product(),e.id());
145  } else {
146  LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
147  }
148  }
149 
150  void addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr) override;
151 
152  void setBcrOffset() override {crFrame_->setBcrOffset();}
153  void setSourceOffset(const unsigned int s) override {crFrame_->setSourceOffset(s);}
154 
155  void setTof() override;
156 
157  void put(edm::Event &e) override {
158  if(makePCrossingFrame_) {
159  e.put(std::make_unique<PCrossingFrame<T> >(*crFrame_), label_);
160  }
162  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
163  }
164 
165  // When using mixed secondary source
166  // Copy the data from the PCrossingFrame to the CrossingFrame
167  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
168 
169  private:
176  unsigned int const maxNbSources_;
180  std::vector<InputTag> allTags_; // for HepMCProduct
181 
182  std::unique_ptr<CrossingFrame<T> > crFrame_;
183  };
184 
185  template <typename T>
186  void MixingWorker<T>::addPileups(const EventPrincipal &ep, ModuleCallingContext const* mcc, unsigned int eventNr) {
187  std::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_, mcc);
188  if (shPtr) {
189  LogDebug("MixingModule") << shPtr->product()->size() << " pileup objects added, eventNr " << eventNr;
190  crFrame_->setPileupPtr(shPtr);
191  crFrame_->addPileups(*shPtr->product());
192  }
193  }
194 //=============== template specializations ====================================================================================
195 
196 template <>
197  void MixingWorker<HepMCProduct>::addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr);
198 
199 template <class T>
201 
202 template <class T>
204  {
205  crFrame_->setBunchRange(PCF->getBunchRange());
206  crFrame_->setBunchSpace(PCF->getBunchSpace());
207  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
208  crFrame_->setSubDet(PCF->getSubDet());
209  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
210  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
211  crFrame_->setPileups(PCF->getPileups());
212 
213  // For playback option
214  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
215  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
216  }
217 
218 }//edm
219 
220 #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:125
std::unique_ptr< CrossingFrame< T > > crFrame_
Definition: MixingWorker.h:182
const int & bunchSpace() const
bool const makePCrossingFrame_
Definition: MixingWorker.h:177
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:63
#define nullptr
void setTof() override
Definition: MixingWorker.h:200
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
int getBunchSpace() const
unsigned int getPileupFileNr() const
std::string const labelCF_
Definition: MixingWorker.h:175
std::vector< const T * > getPileups() const
std::string encode() const
Definition: InputTag.cc:159
bool checkSignal(const edm::Event &e) override
Definition: MixingWorker.h:120
void setSourceOffset(const unsigned int s) override
Definition: MixingWorker.h:153
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:157
void addPileups(const EventPrincipal &ep, ModuleCallingContext const *, unsigned int eventNr) override
Definition: MixingWorker.h:186
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:203
~MixingWorker() override
Definition: MixingWorker.h:106
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:84
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
std::vector< InputTag > allTags_
Definition: MixingWorker.h:180
std::string getSubDet() const
T const * product() const
Definition: Handle.h:74
unsigned int getMaxNbSources() const
std::pair< int, int > getBunchRange() const
void setBcrOffset() override
Definition: MixingWorker.h:152
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:174
T get() const
Definition: EventSetup.h:71
void reload(const edm::EventSetup &setup) override
Definition: MixingWorker.h:110
const int & minBunch() const
long double T
std::string const subdet_
Definition: MixingWorker.h:173
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:176