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 <vector>
31 #include <string>
32 #include <typeinfo>
33 #include "MixingWorkerBase.h"
34 
35 class SimTrack;
36 class SimVertex;
37 namespace edm
38 {
39  template <class T>
41  {
42  public:
43 
45  explicit MixingWorker() :
46  minBunch_(-5),
47  maxBunch_(3),
48  bunchSpace_(75),
49  subdet_(std::string(" ")),
50  label_(std::string(" ")),
51  labelCF_(std::string(" ")),
52  maxNbSources_(5),
54  {
55  tag_=InputTag();
57  }
58 
59  /*Normal constructor*/
60  MixingWorker(int minBunch,int maxBunch, int bunchSpace,
61  std::string subdet,std::string label,
62  std::string labelCF,int maxNbSources, InputTag& tag,
63  InputTag& tagCF, bool mixProdStep2):
65  minBunch_(minBunch),
66  maxBunch_(maxBunch),
67  bunchSpace_(bunchSpace),
68  subdet_(subdet),
69  label_(label),
70  labelCF_(labelCF),
71  maxNbSources_(maxNbSources),
72  tag_(tag),
73  tagSignal_(tagCF)
74  {
75  mixProdStep2_ = mixProdStep2;
76  }
77 
79  virtual ~MixingWorker() {;}
80 
81  public:
82 
83  virtual void reload(const edm::EventSetup & setup){
84  //get the required parameters from DB.
85  // watch the label/tag
87  setup.get<MixingRcd>().get(config);
88  minBunch_=config->minBunch();
89  maxBunch_=config->maxBunch();
90  bunchSpace_=config->bunchSpace();
91  }
92 
93  virtual bool checkSignal(const edm::Event &e){
94  bool got;
95  InputTag t;
96  edm::Handle<std::vector<T> > result_t;
97  if (mixProdStep2_){
98  got = e.getByLabel(tagSignal_,result_t);
100  }
101  else{
102  got = e.getByLabel(tag_,result_t);
103  t = InputTag(tag_.label(),tag_.instance());
104  }
105 
106  if (got)
107  LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name()
108  << " with InputTag= "<< t.encode();
109 
110  return got;
111  }
112 
113 
114  virtual void createnewEDProduct(){
116  }
117 
118  virtual void addSignals(const edm::Event &e){
119  if (mixProdStep2_){
120  edm::Handle<std::vector<T> > result_t;
121  bool got = e.getByLabel(tagSignal_,result_t);
122  if (got) {
123  LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tagSignal_;
124  crFrame_->addSignals(result_t.product(),e.id());
125  }
126  else LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tagSignal_;
127  }
128  else{
129  // Default version
130  edm::Handle<std::vector<T> > result_t;
131  bool got = e.getByLabel(tag_,result_t);
132  if (got) {
133  LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tag_;
134  crFrame_->addSignals(result_t.product(),e.id());
135  }
136  else LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
137 
138  }
139 
140  }
141 
142  virtual void addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
143 
144  virtual void setBcrOffset() {crFrame_->setBcrOffset();}
145  virtual void setSourceOffset(const unsigned int s) {crFrame_->setSourceOffset(s);}
146 
147  void setTof();
148 
149  virtual void put(edm::Event &e) {
150  std::auto_ptr<CrossingFrame<T> > pOut(crFrame_);
151  if (!mixProdStep2_){
152  e.put(pOut,label_);
153  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
154  }
155  else {
156  e.put(pOut,labelCF_);
157  LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<labelCF_;
158  }
159  }
160 
161 
162  // When using mixed secondary source
163  // Copy the data from the PCrossingFrame to the CrossingFrame
164  virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
165 
166  private:
170  std::string const subdet_;
171  std::string const label_;
172  std::string const labelCF_;
173  unsigned int const maxNbSources_;
177 
180  };
181 
182 //=============== template specializations ====================================================================================
183  template <class T>
184  void MixingWorker<T>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset)
185  {
186  if (!mixProdStep2_){
187  // default version
188  // valid for CaloHits
189  boost::shared_ptr<Wrapper<std::vector<T> > const> shPtr =
190  edm::getProductByTag<std::vector<T> >(ep, tag_);
191 
192  if (shPtr) {
193  LogDebug("MixingModule") <<shPtr->product()->size()<<" pileup objects added, eventNr "<<eventNr;
194  crFrame_->setPileupPtr(shPtr);
195  crFrame_->addPileups(bcr,const_cast< std::vector<T> * >(shPtr->product()),eventNr);
196  }
197 
198  }
199  else
200  {
201  boost::shared_ptr<Wrapper<PCrossingFrame<T> > const> shPtr = getProductByTag<PCrossingFrame<T> >(ep, tag_);
202 
203  if (shPtr){
204  crFrame_->setPileupPtr(shPtr);
205  secSourceCF_ = const_cast<PCrossingFrame<T> * >(shPtr->product());
206  LogDebug("MixingModule") << "Add PCrossingFrame<T> eventNr " << secSourceCF_->getEventID();
207 
208  copyPCrossingFrame(secSourceCF_);
209 
210  }
211  else
212  LogDebug("MixingModule") << "Could not get the PCrossingFrame<T>!";
213  }
214  }
215 
216 
217 template <>
218  void MixingWorker<PSimHit>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
219 
220 template <>
221  void MixingWorker<SimTrack>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
222 
223 template <>
224  void MixingWorker<SimVertex>::addPileups(const int bcr, const EventPrincipal& ep, unsigned int eventNr,int vertexoffset);
225 
226 template <>
227  void MixingWorker<HepMCProduct>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
228 
229 template <class T>
231 
232 template <class T>
234  {
235  crFrame_->setBunchRange(PCF->getBunchRange());
236  crFrame_->setBunchSpace(PCF->getBunchSpace());
237  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
238  crFrame_->setSubDet(PCF->getSubDet());
239  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
240  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
241  crFrame_->setPileups(PCF->getPileups());
242 
243  // For playback option
244  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
245  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
246  }
247 
248 }//edm
249 
250 #endif
#define LogDebug(id)
virtual void setBcrOffset()
Definition: MixingWorker.h:144
virtual void createnewEDProduct()
Definition: MixingWorker.h:114
virtual void addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr, int vertexoffset)
Definition: MixingWorker.h:184
int getBunchSpace() const
unsigned int getPileupFileNr() const
std::string const labelCF_
Definition: MixingWorker.h:172
virtual void addSignals(const edm::Event &e)
Definition: MixingWorker.h:118
std::string encode() const
Definition: InputTag.cc:72
edm::EventID getIdFirstPileup() const
virtual bool checkSignal(const edm::Event &e)
Definition: MixingWorker.h:93
virtual void copyPCrossingFrame(const PCrossingFrame< T > *PCF)
Definition: MixingWorker.h:233
virtual ~MixingWorker()
Definition: MixingWorker.h:79
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
CrossingFrame< T > * crFrame_
Definition: MixingWorker.h:178
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void put(edm::Event &e)
Definition: MixingWorker.h:149
std::string getSubDet() const
unsigned int getMaxNbSources() const
const T & get() const
Definition: EventSetup.h:55
std::pair< int, int > getBunchRange() const
T const * product() const
Definition: Handle.h:74
std::vector< unsigned int > getPileupOffsetsBcr() const
std::string const & label() const
Definition: InputTag.h:25
edm::EventID id() const
Definition: EventBase.h:56
PCrossingFrame< T > * secSourceCF_
Definition: MixingWorker.h:179
std::string const label_
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 mixProdStep2)
Definition: MixingWorker.h:60
std::vector< const T * > getPileups() const
virtual void reload(const edm::EventSetup &setup)
Definition: MixingWorker.h:83
long double T
std::string const subdet_
Definition: MixingWorker.h:170
std::string const & instance() const
Definition: InputTag.h:26
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual void setSourceOffset(const unsigned int s)
Definition: MixingWorker.h:145
unsigned int const maxNbSources_
Definition: MixingWorker.h:173
std::vector< std::vector< unsigned int > > getPileupOffsetsSource() const