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_=InputTag();
56  }
57 
58  /*Normal constructor*/
59  MixingWorker(int minBunch,int maxBunch, int bunchSpace,
61  std::string labelCF,int maxNbSources, InputTag& tag,
62  InputTag& tagCF):
64  minBunch_(minBunch),
65  maxBunch_(maxBunch),
66  bunchSpace_(bunchSpace),
67  subdet_(subdet),
68  label_(label),
69  labelCF_(labelCF),
70  maxNbSources_(maxNbSources),
71  tag_(tag),
72  tagSignal_(tagCF)
73  {
74  }
75 
77  virtual ~MixingWorker() {;}
78 
79  public:
80 
81  virtual void reload(const edm::EventSetup & setup){
82  //get the required parameters from DB.
83  // watch the label/tag
85  setup.get<MixingRcd>().get(config);
86  minBunch_=config->minBunch();
87  maxBunch_=config->maxBunch();
88  bunchSpace_=config->bunchSpace();
89  }
90 
91  virtual bool checkSignal(const edm::Event &e){
92  bool got;
93  InputTag t;
94  edm::Handle<std::vector<T> > result_t;
95  got = e.getByLabel(tag_,result_t);
96  t = InputTag(tag_.label(),tag_.instance());
97 
98  if (got)
99  LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name()
100  << " with InputTag= "<< t.encode();
101 
102  return got;
103  }
104 
105 
106  virtual void createnewEDProduct(){
108  }
109 
110  virtual void addSignals(const edm::Event &e){
111  edm::Handle<std::vector<T> > result_t;
112  bool got = e.getByLabel(tag_,result_t);
113  if (got) {
114  LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tag_;
115  crFrame_->addSignals(result_t.product(),e.id());
116  } else {
117  LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
118  }
119  }
120 
121  virtual void addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr);
122 
123  virtual void setBcrOffset() {crFrame_->setBcrOffset();}
124  virtual void setSourceOffset(const unsigned int s) {crFrame_->setSourceOffset(s);}
125 
126  void setTof();
127 
128  virtual void put(edm::Event &e) {
129  std::auto_ptr<CrossingFrame<T> > pOut(crFrame_);
130  e.put(pOut,label_);
131  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
132  }
133 
134 
135  // When using mixed secondary source
136  // Copy the data from the PCrossingFrame to the CrossingFrame
137  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
138 
139  private:
146  unsigned int const maxNbSources_;
149 
152  };
153 
154  template <typename T>
155  void MixingWorker<T>::addPileups(const EventPrincipal &ep, ModuleCallingContext const* mcc, unsigned int eventNr) {
156  std::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_, mcc);
157  if (shPtr) {
158  LogDebug("MixingModule") << shPtr->product()->size() << " pileup objects added, eventNr " << eventNr;
159  crFrame_->setPileupPtr(shPtr);
160  crFrame_->addPileups(*shPtr->product());
161  }
162  }
163 //=============== template specializations ====================================================================================
164 
165 template <>
166  void MixingWorker<HepMCProduct>::addPileups(const EventPrincipal &ep, ModuleCallingContext const*, unsigned int eventNr);
167 
168 template <class T>
170 
171 template <class T>
173  {
174  crFrame_->setBunchRange(PCF->getBunchRange());
175  crFrame_->setBunchSpace(PCF->getBunchSpace());
176  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
177  crFrame_->setSubDet(PCF->getSubDet());
178  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
179  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
180  crFrame_->setPileups(PCF->getPileups());
181 
182  // For playback option
183  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
184  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
185  }
186 
187 }//edm
188 
189 #endif
#define LogDebug(id)
virtual void setBcrOffset()
Definition: MixingWorker.h:123
virtual void createnewEDProduct()
Definition: MixingWorker.h:106
int getBunchSpace() const
unsigned int getPileupFileNr() const
std::string const labelCF_
Definition: MixingWorker.h:145
virtual void addSignals(const edm::Event &e)
Definition: MixingWorker.h:110
std::string encode() const
Definition: InputTag.cc:164
edm::EventID getIdFirstPileup() const
virtual bool checkSignal(const edm::Event &e)
Definition: MixingWorker.h:91
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:172
virtual ~MixingWorker()
Definition: MixingWorker.h:77
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
CrossingFrame< T > * crFrame_
Definition: MixingWorker.h:150
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
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:59
virtual void put(edm::Event &e)
Definition: MixingWorker.h:128
std::string getSubDet() const
T const * product() const
Definition: Handle.h:81
unsigned int getMaxNbSources() const
const T & get() const
Definition: EventSetup.h:55
std::pair< int, int > getBunchRange() const
std::vector< unsigned int > getPileupOffsetsBcr() const
std::string const & label() const
Definition: InputTag.h:42
edm::EventID id() const
Definition: EventBase.h:56
PCrossingFrame< T > * secSourceCF_
Definition: MixingWorker.h:151
std::string const label_
Definition: MixingWorker.h:144
virtual void addPileups(const EventPrincipal &ep, ModuleCallingContext const *, unsigned int eventNr)
Definition: MixingWorker.h:155
std::vector< const T * > getPileups() const
virtual void reload(const edm::EventSetup &setup)
Definition: MixingWorker.h:81
long double T
std::string const subdet_
Definition: MixingWorker.h:143
std::string const & instance() const
Definition: InputTag.h:43
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual void setSourceOffset(const unsigned int s)
Definition: MixingWorker.h:124
unsigned int const maxNbSources_
Definition: MixingWorker.h:146
std::vector< std::vector< unsigned int > > getPileupOffsetsSource() const