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 
121  virtual void addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
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 specializations ====================================================================================
155 
156 template <>
157  void MixingWorker<PCaloHit>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
158 
159 template <>
160  void MixingWorker<PSimHit>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
161 
162 template <>
163  void MixingWorker<SimTrack>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
164 
165 template <>
166  void MixingWorker<SimVertex>::addPileups(const int bcr, const EventPrincipal& ep, unsigned int eventNr,int vertexoffset);
167 
168 template <>
169  void MixingWorker<HepMCProduct>::addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr,int vertexoffset);
170 
171 template <class T>
173 
174 template <class T>
176  {
177  crFrame_->setBunchRange(PCF->getBunchRange());
178  crFrame_->setBunchSpace(PCF->getBunchSpace());
179  crFrame_->setMaxNbSources(PCF->getMaxNbSources());
180  crFrame_->setSubDet(PCF->getSubDet());
181  crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
182  crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
183  crFrame_->setPileups(PCF->getPileups());
184 
185  // For playback option
186  crFrame_->setPileupFileNr(PCF->getPileupFileNr());
187  crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
188  }
189 
190 }//edm
191 
192 #endif
#define LogDebug(id)
virtual void setBcrOffset()
Definition: MixingWorker.h:123
virtual void addPileups(const int bcr, const EventPrincipal &ep, unsigned int eventNr, int vertexoffset)
virtual void createnewEDProduct()
Definition: MixingWorker.h:105
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: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:175
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:150
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:128
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:151
std::string const label_
Definition: MixingWorker.h:144
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: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