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