CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MixEvtVtxGenerator.cc
Go to the documentation of this file.
1 #ifndef HI_MixEvtVtxGenerator_H
2 #define HI_MixEvtVtxGenerator_H
3 /*
4 */
7 
15 
19 
22 
23 #include "TMatrixD.h"
24 
25 using namespace edm;
26 using namespace std;
27 
28 
29 namespace HepMC {
30  class FourVector ;
31 }
32 
33 
35 {
36  public:
37 
38  // ctor & dtor
39  explicit MixEvtVtxGenerator( const edm::ParameterSet& );
40  virtual ~MixEvtVtxGenerator();
41 
42  virtual void produce( edm::Event&, const edm::EventSetup& ) override;
43 
44  virtual HepMC::FourVector* getVertex(edm::Event&);
45  virtual HepMC::FourVector* getRecVertex(edm::Event&);
46 
47  protected:
48 
49  HepMC::FourVector* fVertex ;
50  TMatrixD *boost_;
51 
52  private :
53 
57 
59  std::vector<double> vtxOffset;
60  bool useCF_;
61 
62 };
63 
65  : fVertex(0), boost_(0),
66  signalLabel(pset.getParameter<edm::InputTag>("signalLabel")),
67  hiLabel(pset.getParameter<edm::InputTag>("heavyIonLabel")),
68  useRecVertex(pset.exists("useRecVertex")?pset.getParameter<bool>("useRecVertex"):false)
69 
70 {
71  produces<bool>("matchedVertex");
72  vtxOffset.resize(3);
73  if(pset.exists("vtxOffset")) vtxOffset=pset.getParameter< std::vector<double> >("vtxOffset");
74 
75  if(useRecVertex) useCF_ = 0;
76  else{
77  useCF_ = pset.getUntrackedParameter<bool>("useCF",false);
78  cfLabel = pset.getUntrackedParameter<edm::InputTag>("mixLabel",edm::InputTag("mixGen","generator"));
79  }
80 }
81 
83 {
84  delete fVertex ;
85  if (boost_ != 0 ) delete boost_;
86  // no need since now it's done in HepMCProduct
87  // delete fEvt ;
88 }
89 
90 HepMC::FourVector* MixEvtVtxGenerator::getVertex( Event& evt){
91 
92  HepMC::GenVertex* genvtx = 0;
93  const HepMC::GenEvent* inev = 0;
94 
95  //cout<<" use CF "<<useCF_<<endl;
96 
97  if(useCF_){
99  evt.getByLabel(cfLabel,cf);
101  if(mix.size() < 2){
102  cout<<"Less than 2 sub-events, mixing seems to have failed!"<<endl;
103  }
104  const HepMCProduct& bkg = mix.getObject(1);
105  if(!(bkg.isVtxGenApplied())){
106  cout<<"Input does not have smeared vertex!"<<endl;
107  }else{
108  inev = bkg.GetEvent();
109  }
110  }else{
111  //cout<<" hiLabel "<<hiLabel<<endl;
113  evt.getByLabel(hiLabel,input);
114  inev = input->GetEvent();
115  }
116 
117  genvtx = inev->signal_process_vertex();
118  if(!genvtx){
119  //cout<<"No Signal Process Vertex!"<<endl;
120  HepMC::GenEvent::particle_const_iterator pt=inev->particles_begin();
121  HepMC::GenEvent::particle_const_iterator ptend=inev->particles_end();
122  while(!genvtx || ( genvtx->particles_in_size() == 1 && pt != ptend ) ){
123  //if(!genvtx) cout<<"No Gen Vertex!"<<endl;
124  if(pt == ptend) cout<<"End reached, No Gen Vertex!"<<endl;
125  genvtx = (*pt)->production_vertex();
126  ++pt;
127  }
128  }
129  double aX,aY,aZ,aT;
130 
131  aX = genvtx->position().x();
132  aY = genvtx->position().y();
133  aZ = genvtx->position().z();
134  aT = genvtx->position().t();
135 
136  if(!fVertex){
137  fVertex = new HepMC::FourVector();
138  //cout<<" creating new vertex "<<endl;
139  }
140  //cout<<" setting vertex "<<" aX "<<aX<<" aY "<<aY<<" aZ "<<aZ<<" aT "<<aT<<endl;
141  fVertex->set(aX,aY,aZ,aT);
142 
143 
144  return fVertex;
145 
146 }
147 
148 
149 HepMC::FourVector* MixEvtVtxGenerator::getRecVertex( Event& evt){
150 
152  evt.getByLabel(hiLabel,input);
153 
154  double aX,aY,aZ;
155 
156  aX = input->begin()->position().x() + vtxOffset[0];
157  aY = input->begin()->position().y() + vtxOffset[1];
158  aZ = input->begin()->position().z() + vtxOffset[2];
159 
160  /*
161  std::cout << "reco::Vertex = " << input->begin()->position().x()
162  << ", " << input->begin()->position().y()
163  << ", " << input->begin()->position().z()
164  << std::endl;
165 
166  std::cout << "offset = " << vtxOffset[0]
167  << ", " << vtxOffset[1]
168  << ", " << vtxOffset[2]
169  << std::endl;
170 
171  std::cout << "embedded GEN vertex = " << aX
172  << ", " << aY << ", " << aZ << std::endl;
173 
174  */
175  if(!fVertex) fVertex = new HepMC::FourVector();
176  fVertex->set(10.0*aX,10.0*aY,10.0*aZ,0.0); // HepMC positions in mm (RECO in cm)
177 
178  return fVertex;
179 
180 }
181 
183 {
184 
185 
186  Handle<HepMCProduct> HepMCEvt ;
187 
188  evt.getByLabel( signalLabel, HepMCEvt ) ;
189 
190  // generate new vertex & apply the shift
191  //
192 
193  HepMCEvt->applyVtxGen( useRecVertex ? getRecVertex(evt) : getVertex(evt) ) ;
194 
195  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
196  // HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
197 
198  // OK, create a (pseudo)product and put in into edm::Event
199  //
200  auto_ptr<bool> NewProduct(new bool(true)) ;
201  evt.put( NewProduct ,"matchedVertex") ;
202 
203  return ;
204 
205 }
206 
208 
209 #endif
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual HepMC::FourVector * getRecVertex(edm::Event &)
std::vector< double > vtxOffset
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
MixEvtVtxGenerator(const edm::ParameterSet &)
virtual void produce(edm::Event &, const edm::EventSetup &) override
virtual HepMC::FourVector * getVertex(edm::Event &)
static std::string const input
Definition: EdmProvDump.cc:44
edm::InputTag signalLabel
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:35
HepMC::FourVector * fVertex
bool isVtxGenApplied() const
Definition: HepMCProduct.h:37
T const * product() const
Definition: Handle.h:81
return(e1-e2)*(e1-e2)+dp *dp
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false