CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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),
54  tag_(),
55  tagSignal_(),
56  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):
68  minBunch_(minBunch),
69  maxBunch_(maxBunch),
70  bunchSpace_(bunchSpace),
71  subdet_(subdet),
72  label_(label),
73  labelCF_(labelCF),
74  maxNbSources_(maxNbSources),
75  tag_(tag),
76  tagSignal_(tagCF),
77  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),
97  tag_(tag),
98  tagSignal_(tagCF),
99  allTags_(tags),
100  crFrame_(nullptr),
102  {
103  }
104 
106  virtual ~MixingWorker() {;}
107 
108  public:
109 
110  virtual void reload(const edm::EventSetup & setup){
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  virtual bool checkSignal(const edm::Event &e){
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  virtual void createnewEDProduct(){
137  }
138 
139  virtual void addSignals(const edm::Event &e){
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  virtual void addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr);
151 
152  virtual void setBcrOffset() {crFrame_->setBcrOffset();}
153  virtual void setSourceOffset(const unsigned int s) {crFrame_->setSourceOffset(s);}
154 
155  void setTof();
156 
157  virtual void put(edm::Event &e) {
158  std::auto_ptr<CrossingFrame<T> > pOut(crFrame_);
159  e.put(pOut,label_);
160  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
161  }
162 
163  // When using mixed secondary source
164  // Copy the data from the PCrossingFrame to the CrossingFrame
165  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
166 
167  private:
174  unsigned int const maxNbSources_;
177  std::vector<InputTag> allTags_; // for HepMCProduct
178 
181  };
182 
183  template <typename T>
184  void MixingWorker<T>::addPileups(const EventPrincipal &ep, ModuleCallingContext const* mcc, unsigned int eventNr) {
185  std::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_, mcc);
186  if (shPtr) {
187  LogDebug("MixingModule") << shPtr->product()->size() << " pileup objects added, eventNr " << eventNr;
188  crFrame_->setPileupPtr(shPtr);
189  crFrame_->addPileups(*shPtr->product());
190  }
191  }
192 //=============== template specializations ====================================================================================
193 
194 template <>
195  void MixingWorker<HepMCProduct>::addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr);
196 
197 template <class T>
199 
200 template <class T>
202  {
203  crFrame_->setBunchRange(PCF->getBunchRange());
204  crFrame_->setBunchSpace(PCF->getBunchSpace());
205  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
206  crFrame_->setSubDet(PCF->getSubDet());
207  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
208  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
209  crFrame_->setPileups(PCF->getPileups());
210 
211  // For playback option
212  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
213  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
214  }
215 
216 }//edm
217 
218 #endif
#define LogDebug(id)
virtual void setBcrOffset()
Definition: MixingWorker.h:152
virtual void createnewEDProduct()
Definition: MixingWorker.h:135
int getBunchSpace() const
unsigned int getPileupFileNr() const
std::string const labelCF_
Definition: MixingWorker.h:173
#define nullptr
virtual void addSignals(const edm::Event &e)
Definition: MixingWorker.h:139
std::string encode() const
Definition: InputTag.cc:164
edm::EventID getIdFirstPileup() const
virtual bool checkSignal(const edm::Event &e)
Definition: MixingWorker.h:120
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:201
virtual ~MixingWorker()
Definition: MixingWorker.h:106
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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
CrossingFrame< T > * crFrame_
Definition: MixingWorker.h:179
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
MixingWorker(int minBunch, int maxBunch, int bunchSpace, std::string subdet, std::string label, std::string labelCF, int maxNbSources, InputTag &tag, InputTag &tagCF)
Definition: MixingWorker.h:63
tuple tags
Definition: o2o.py:248
virtual void put(edm::Event &e)
Definition: MixingWorker.h:157
std::vector< InputTag > allTags_
Definition: MixingWorker.h:177
std::string getSubDet() const
T const * product() const
Definition: Handle.h:81
unsigned int getMaxNbSources() const
const T & get() const
Definition: EventSetup.h:56
std::pair< int, int > getBunchRange() const
std::vector< unsigned int > getPileupOffsetsBcr() const
std::string const & label() const
Definition: InputTag.h:36
edm::EventID id() const
Definition: EventBase.h:59
PCrossingFrame< T > * secSourceCF_
Definition: MixingWorker.h:180
std::string const label_
Definition: MixingWorker.h:172
virtual void addPileups(const EventPrincipal &ep, ModuleCallingContext const *, unsigned int eventNr)
Definition: MixingWorker.h:184
std::vector< const T * > getPileups() const
virtual void reload(const edm::EventSetup &setup)
Definition: MixingWorker.h:110
long double T
std::string const subdet_
Definition: MixingWorker.h:171
std::string const & instance() const
Definition: InputTag.h:37
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual void setSourceOffset(const unsigned int s)
Definition: MixingWorker.h:153
unsigned int const maxNbSources_
Definition: MixingWorker.h:174
std::vector< std::vector< unsigned int > > getPileupOffsetsSource() const