CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
ParticleReplacerClass Class Reference

#include <ParticleReplacerClass.h>

Inheritance diagram for ParticleReplacerClass:
ParticleReplacerBase

Classes

struct  MinVisPtCut
 

Public Member Functions

virtual void beginRun (const edm::Run &iRun, const edm::EventSetup &iSetup)
 
virtual void endJob ()
 
 ParticleReplacerClass (const edm::ParameterSet &, bool)
 
virtual std::auto_ptr
< HepMC::GenEvent > 
produce (const reco::MuonCollection &muons, const reco::Vertex *pvtx=0, const HepMC::GenEvent *genEvt=0)
 
 ~ParticleReplacerClass ()
 
- Public Member Functions inherited from ParticleReplacerBase
virtual void beginJob ()
 
virtual void endRun ()
 
 ParticleReplacerBase (const edm::ParameterSet &iConfig)
 
virtual ~ParticleReplacerBase ()
 

Private Member Functions

void cleanEvent (HepMC::GenEvent *evt, HepMC::GenVertex *vtx)
 
HepMC::GenEvent * processEventWithPythia (HepMC::GenEvent *evt)
 
HepMC::GenEvent * processEventWithTauola (HepMC::GenEvent *evt)
 
void repairBarcodes (HepMC::GenEvent *evt)
 
bool testEvent (HepMC::GenEvent *evt)
 
void transformMuMu2TauNu (reco::Particle *muon1, reco::Particle *muon2)
 transform a muon pair into tau nu (as coming from a W boson) More...
 
void transformMuMu2TauTau (reco::Particle *muon1, reco::Particle *muon2)
 transform a muon pair into a tau pair More...
 

Private Attributes

int attempts
 
std::string generatorMode_
 
int maxNumberOfAttempts_
 
std::vector< std::vector
< MinVisPtCut > > 
minVisPtCuts_
 
int motherParticleID_
 
bool noInitialisation_
 
TTree * outTree
 
bool printEvent_
 
double targetParticleMass_
 
int targetParticlePdgID_
 
gen::TauolaInterfacetauola_
 
unsigned int transformationMode_
 
bool useExternalGenerators_
 
bool useTauola_
 
bool useTauolaPolarization_
 

Additional Inherited Members

- Public Attributes inherited from ParticleReplacerBase
unsigned int passed
 
unsigned int tried
 
- Protected Attributes inherited from ParticleReplacerBase
const double tauMass
 

Detailed Description

Definition at line 56 of file ParticleReplacerClass.h.

Constructor & Destructor Documentation

ParticleReplacerClass::ParticleReplacerClass ( const edm::ParameterSet pset,
bool  verbose 
)
explicit

Definition at line 23 of file ParticleReplacerClass.cc.

References attempts, GOODCOLL_filter_cfg::cut, hpstanc_transforms::cuts, decayRandomEngine, ParticleReplacerClass::MinVisPtCut::ELEC, edm::hlt::Exception, generatorMode_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), ParticleReplacerClass::MinVisPtCut::HAD, ParticleReplacerClass::MinVisPtCut::index_, minVisPtCuts_, motherParticleID_, ParticleReplacerClass::MinVisPtCut::MU, noInitialisation_, NULL, outTree, pos, ParticleReplacerClass::MinVisPtCut::pt_, gen::TauolaInterface::setPSet(), AlCaHLTBitMon_QueryRunRegistry::string, ParticleReplacerClass::MinVisPtCut::TAU, tauola_, transformationMode_, and ParticleReplacerClass::MinVisPtCut::type_.

23  :
25  generatorMode_(pset.getParameter<std::string>("generatorMode")),
28  outTree(0),
29  maxNumberOfAttempts_(pset.getUntrackedParameter<int>("maxNumberOfAttempts", 1000))
30 {
31  tauola_->setPSet(pset.getParameter< edm::ParameterSet>("TauolaOptions"));
32 // using namespace reco;
33  using namespace edm;
34  using namespace std;
35 
36  //HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
37  //HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
38 
39  // transformationMode =
40  // 0 - no transformation
41  // 1 - mumu -> tautau
42  transformationMode_ = pset.getUntrackedParameter<int>("transformationMode",1);
43  switch (transformationMode_)
44  {
45  case 0:
46  {
47  LogInfo("Replacer") << "won't do any transformation with the given mumu";
48  break;
49  }
50  case 1:
51  {
52  LogInfo("Replacer") << "will transform mumu into tautau";
53  break;
54  }
55  case 2:
56  {
57  LogInfo("Replacer") << "will transform mumu into taunu (as coming from a W boson)";
58  break;
59  }
60  case 3:
61  {
62  LogInfo("Replacer") << "Will transform mu-nu into tau-nu. No mass correction will be made.";
63  break;
64  }
65  default:
66  {
67  throw cms::Exception("ParticleReplacerClass") << "Unknown transformation mode!\n";
68  break;
69  }
70 
71  }
72 
73  // If one wants to use two instances of this module in one
74  // configuration file, there might occur some segmentation
75  // faults due to the second initialisation of Tauola. This
76  // can be prevented by setting noInitialisation to false.
77  // Caution: This option is not tested!
78  noInitialisation_ = pset.getUntrackedParameter<bool>("noInitialisation",false);
79 
80  motherParticleID_ = pset.getUntrackedParameter<int>("motherParticleID",23);
81 
82  // requires the visible decay products of a tau to have a sum transverse momentum
83  std::string minVisibleTransverseMomentumLine = pset.getUntrackedParameter<std::string>("minVisibleTransverseMomentum","");
84 
85  // fallback for backwards compatibility: If it's a single number then use this as a threshold for both particles
86  const char* startptr = minVisibleTransverseMomentumLine.c_str();
87  char* endptr;
88  double d = strtod(startptr, &endptr);
89  if(*endptr == '\0' && endptr != startptr)
90  {
91  MinVisPtCut cuts[2];
92  cuts[0].type_ = cuts[1].type_ = MinVisPtCut::TAU;
93  cuts[0].pt_ = cuts[1].pt_ = d;
94  cuts[0].index_ = 0; cuts[1].index_ = 1;
95  minVisPtCuts_.push_back(std::vector<MinVisPtCut>(cuts, cuts+2));
96  }
97  else
98  {
99  // string has new format: parse the minvistransversemomentum string
100  for(std::string::size_type prev = 0, pos = 0; prev < minVisibleTransverseMomentumLine.length(); prev = pos + 1)
101  {
102  pos = minVisibleTransverseMomentumLine.find(';', prev);
103  if(pos == std::string::npos) pos = minVisibleTransverseMomentumLine.length();
104 
105  std::string sub = minVisibleTransverseMomentumLine.substr(prev, pos - prev);
106  std::vector<MinVisPtCut> cuts;
107  const char* sub_c = sub.c_str();
108  while(*sub_c != '\0')
109  {
110  const char* sep = std::strchr(sub_c, '_');
111  if(sep == NULL) throw cms::Exception("Configuration") << "Minimum transverse parameter string must contain an underscore to separate type from pt threshold" << std::endl;
112  std::string type(sub_c, sep);
113 
114  MinVisPtCut cut;
115  if(type == "elec1") { cut.type_ = MinVisPtCut::ELEC; cut.index_ = 0; }
116  else if(type == "mu1") { cut.type_ = MinVisPtCut::MU; cut.index_ = 0; }
117  else if(type == "had1") { cut.type_ = MinVisPtCut::HAD; cut.index_ = 0; }
118  else if(type == "tau1") { cut.type_ = MinVisPtCut::TAU; cut.index_ = 0; }
119  else if(type == "elec2") { cut.type_ = MinVisPtCut::ELEC; cut.index_ = 1; }
120  else if(type == "mu2") { cut.type_ = MinVisPtCut::MU; cut.index_ = 1; }
121  else if(type == "had2") { cut.type_ = MinVisPtCut::HAD; cut.index_ = 1; }
122  else if(type == "tau2") { cut.type_ = MinVisPtCut::TAU; cut.index_ = 1; }
123  else throw cms::Exception("Configuration") << "'" << type << "' is not a valid type. Allowed values are elec1,mu1,had1,tau1,elec2,mu2,had2,tau2" << std::endl;
124 
125  char* endptr;
126  cut.pt_ = strtod(sep + 1, &endptr);
127  if(endptr == sep + 1) throw cms::Exception("Configuration") << "No pt threshold given" << std::endl;
128 
129  cuts.push_back(cut);
130  sub_c = endptr;
131  }
132  minVisPtCuts_.push_back(cuts);
133  }
134  }
135 
136  edm::Service<TFileService> fileService_;
137  if(fileService_.isAvailable()) {
138  outTree = fileService_->make<TTree>( "event_generation","This tree stores information about the event generation");
139  outTree->Branch("attempts",&attempts,"attempts/I");
140  }
141 
143  if(!rng.isAvailable()) {
144  throw cms::Exception("Configuration")
145  << "The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
146  "which appears to be absent. Please add that service to your configuration\n"
147  "or remove the modules that require it." << std::endl;
148  }
149  // this is a global variable defined in GeneratorInterface/ExternalDecays/src/ExternalDecayDriver.cc
150  decayRandomEngine = &rng->getEngine();
151 
152  edm::LogInfo("Replacer") << "generatorMode = "<< generatorMode_<< "\n";
153 
154  return;
155 }
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
gen::TauolaInterface * tauola_
void setPSet(const edm::ParameterSet &)
#define NULL
Definition: scimark2.h:8
uint16_t size_type
ParticleReplacerBase(const edm::ParameterSet &iConfig)
static TauolaInterface * getInstance()
CLHEP::HepRandomEngine * decayRandomEngine
std::vector< std::vector< MinVisPtCut > > minVisPtCuts_
ParticleReplacerClass::~ParticleReplacerClass ( )

Definition at line 157 of file ParticleReplacerClass.cc.

158 {
159  // do anything here that needs to be done at desctruction time
160  // (e.g. close files, deallocate resources etc.)
161 }

Member Function Documentation

void ParticleReplacerClass::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Reimplemented from ParticleReplacerBase.

Definition at line 448 of file ParticleReplacerClass.cc.

References gen::TauolaInterface::init(), and tauola_.

449 {
450  tauola_->init(iSetup);
451 }
gen::TauolaInterface * tauola_
void init(const edm::EventSetup &)
void ParticleReplacerClass::cleanEvent ( HepMC::GenEvent *  evt,
HepMC::GenVertex *  vtx 
)
private

Definition at line 547 of file ParticleReplacerClass.cc.

References L1Trigger_dataformats::reco, and repairBarcodes().

Referenced by produce().

548 {
549  using namespace HepMC;
550  using namespace std;
551  using namespace edm;
552  using namespace reco;
553 
554  stack<HepMC::GenParticle *> deleteParticle;
555 
556  stack<GenVertex *> deleteVertex;
557  stack<GenVertex *> queueVertex;
558 
559  if (vtx->particles_out_size()>0)
560  {
561  for (GenVertex::particles_out_const_iterator it=vtx->particles_out_const_begin();it!=vtx->particles_out_const_end();it++)
562  {
563  deleteParticle.push(*it);
564  if ((*it)->end_vertex())
565  queueVertex.push((*it)->end_vertex());
566  }
567  }
568 
569  while (!queueVertex.empty())
570  {
571  GenVertex * temp_vtx=queueVertex.top();
572  if (temp_vtx->particles_out_size()>0)
573  {
574  for (GenVertex::particles_out_const_iterator it=temp_vtx->particles_out_const_begin();it!=temp_vtx->particles_out_const_end();it++)
575  {
576  if ((*it)->end_vertex())
577  queueVertex.push((*it)->end_vertex());
578  }
579  delete temp_vtx;
580  }
581  deleteVertex.push(queueVertex.top());
582  queueVertex.pop();
583  }
584 
585  while (!deleteVertex.empty())
586  {
587  evt->remove_vertex(deleteVertex.top());
588  deleteVertex.pop();
589  }
590 
591  while (!deleteParticle.empty())
592  {
593  delete vtx->remove_particle(deleteParticle.top());
594  deleteParticle.pop();
595  }
596 
597  while (!deleteVertex.empty())
598  deleteVertex.pop();
599  while (!queueVertex.empty())
600  queueVertex.pop();
601 
602  repairBarcodes(evt);
603 }
void repairBarcodes(HepMC::GenEvent *evt)
void ParticleReplacerClass::endJob ( void  )
virtual

Reimplemented from ParticleReplacerBase.

Definition at line 455 of file ParticleReplacerClass.cc.

References gen::TauolaInterface::statistics(), and tauola_.

456 {
457  tauola_->statistics();
458 }
gen::TauolaInterface * tauola_
HepMC::GenEvent* ParticleReplacerClass::processEventWithPythia ( HepMC::GenEvent *  evt)
private
HepMC::GenEvent* ParticleReplacerClass::processEventWithTauola ( HepMC::GenEvent *  evt)
private
std::auto_ptr< HepMC::GenEvent > ParticleReplacerClass::produce ( const reco::MuonCollection muons,
const reco::Vertex pvtx = 0,
const HepMC::GenEvent *  genEvt = 0 
)
virtual

2) transform the muons to the desired particles

3) prepare the event

3) process the event

Implements ParticleReplacerBase.

Definition at line 164 of file ParticleReplacerClass.cc.

References abs, attempts, reco::LeafCandidate::charge(), cleanEvent(), conv, gather_cfg::cout, gen::TauolaInterface::decay(), edm::hlt::Exception, generatorMode_, configurableAnalysis::GenParticle, i, prof2calltree::l, maxNumberOfAttempts_, motherParticleID_, outTree, AlCaHLTBitMon_ParallelJobs::p, reco::LeafCandidate::p4(), ParticleReplacerBase::passed, reco::LeafCandidate::pdgId(), printEvent_, reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), repairBarcodes(), run_regression::ret, reco::Particle::setStatus(), mathSSE::sqrt(), targetParticleMass_, targetParticlePdgID_, tauola_, testEvent(), transformationMode_, transformMuMu2TauNu(), transformMuMu2TauTau(), ParticleReplacerBase::tried, funct::true, and reco::LeafCandidate::vertex().

165 {
166  using namespace edm;
167  using namespace std;
168  using namespace HepMC;
169 
170  if(pvtx != 0)
171  throw cms::Exception("Configuration") << "ParticleReplacerClass does NOT support using primary vertex as the origin for taus" << std::endl;
172 
173  HepMC::GenEvent * evt=0;
174 
175  GenVertex * zvtx = new GenVertex();
176 
177  reco::GenParticle * part1=0;
178  reco::GenParticle * part2=0;
179 
181  std::vector<reco::Particle> particles;
182  switch (transformationMode_)
183  {
184  case 0: // mumu->mumu
185  {
186  if (muons.size()!=2)
187  {
188  LogError("Replacer") << "the decay mode Z->mumu requires exactly two muons, aborting processing";
189  return std::auto_ptr<HepMC::GenEvent>(0);
190  }
191 
192  targetParticleMass_ = 0.105658369;
194 
195  reco::Muon muon1 = muons.at(0);
196  reco::Muon muon2 = muons.at(1);
197  reco::Particle tau1(muon1.charge(), muon1.p4(), muon1.vertex(), muon1.pdgId(), 0, true);
198  reco::Particle tau2(muon2.charge(), muon2.p4(), muon2.vertex(), muon2.pdgId(), 0, true);
199  particles.push_back(tau1);
200  particles.push_back(tau2);
201  break;
202  }
203  case 1: // mumu->tautau
204  {
205  if (muons.size()!=2)
206  {
207  LogError("Replacer") << "the decay mode Z->tautau requires exactly two muons, aborting processing";
208  return std::auto_ptr<HepMC::GenEvent>(0);
209  }
210 
211  targetParticleMass_ = 1.77690;
213 
214  reco::Muon muon1 = muons.at(0);
215  reco::Muon muon2 = muons.at(1);
216  reco::Particle tau1(muon1.charge(), muon1.p4(), muon1.vertex(), muon1.pdgId(), 0, true);
217  reco::Particle tau2(muon2.charge(), muon2.p4(), muon2.vertex(), muon2.pdgId(), 0, true);
218  transformMuMu2TauTau(&tau1, &tau2);
219  particles.push_back(tau1);
220  particles.push_back(tau2);
221  break;
222  }
223  case 2: // mumu->taunu (W boson)
224  {
225  if (muons.size()!=2)
226  {
227  LogError("Replacer") << "the decay mode Z->tautau requires exactly two muons, aborting processing";
228  return std::auto_ptr<HepMC::GenEvent>(0);
229  }
230 
231  targetParticleMass_ = 1.77690;
233 
234  reco::Muon muon1 = muons.at(0);
235  reco::Muon muon2 = muons.at(1);
236  reco::Particle tau1(muon1.charge(), muon1.p4(), muon1.vertex(), muon1.pdgId(), 0, true);
237  reco::Particle tau2(muon2.charge(), muon2.p4(), muon2.vertex(), muon2.pdgId(), 0, true);
238  transformMuMu2TauNu(&tau1, &tau2);
239  particles.push_back(tau1);
240  particles.push_back(tau2);
241  break;
242  }
243  case 3: // mu-nu->tau-nu
244  {
245  if (muons.size()!=2)
246  {
247  LogError("Replacer") << "transformation mode mu-nu ->tau-nu - wrong input";
248  return std::auto_ptr<HepMC::GenEvent>(0);
249  }
250 
251  targetParticleMass_ = 1.77690;
253  int targetParticlePdgIDNu_ = 16;
254 
255  reco::Muon muon1 = muons.at(0);
256  reco::Muon::LorentzVector l(muon1.px(), muon1.py(), muon1.pz(),
257  sqrt(
258  muon1.px()*muon1.px()+
259  muon1.py()*muon1.py()+
260  muon1.pz()*muon1.pz()+targetParticleMass_*targetParticleMass_));
261 
262  reco::Particle tau1(muon1.charge(), l, muon1.vertex(), targetParticlePdgID_*std::abs(muon1.pdgId())/muon1.pdgId()
263  , 0, true
264  );
265  tau1.setStatus(1);
266  particles.push_back(tau1);
267 
268  reco::Muon nu = muons.at(1);
269  reco::Particle nutau( 0, nu.p4(), nu.vertex(), -targetParticlePdgIDNu_*std::abs(muon1.pdgId())/muon1.pdgId(), 0, true);
270  nutau.setStatus(1);
271  particles.push_back(nutau);
272 
273  break;
274  }
275 
276  }
277 
278  if (particles.size()==0)
279  {
280  LogError("Replacer") << "the creation of the new particles failed somehow";
281  return std::auto_ptr<HepMC::GenEvent>(0);
282  }
283  else
284  {
285  LogInfo("Replacer") << particles.size() << " particles found, continue processing";
286  }
287 
289  if (genEvt)
290  {
291 
292  evt = new HepMC::GenEvent(*genEvt);
293 
294  for ( GenEvent::vertex_iterator p = evt->vertices_begin(); p != evt->vertices_end(); p++ )
295  {
296  GenVertex * vtx=(*p);
297 
298  if ( vtx->particles_out_size()<=0 || vtx->particles_in_size()<=0)
299  continue;
300 
301  bool temp_muon1=false,temp_muon2=false,temp_z=false;
302  for (GenVertex::particles_out_const_iterator it = vtx->particles_out_const_begin(); it!=vtx->particles_out_const_end(); it++)
303  {
304  if ((*it)->pdg_id()==13) temp_muon1=true;
305  if ((*it)->pdg_id()==-13) temp_muon2=true;
306  if ((*it)->pdg_id()==23) temp_z=true;
307  }
308 
309  int mother_pdg=(*vtx->particles_in_const_begin())->pdg_id();
310 
311  if ((vtx->particles_out_size()==2 && vtx->particles_in_size()>0
312  && mother_pdg == 23
313  && temp_muon1
314  && temp_muon2)
315  || (vtx->particles_out_size()>2 && vtx->particles_in_size()>0
316  && mother_pdg == 23
317  && temp_muon1 && temp_muon2 && temp_z ))
318  {
319  zvtx=*p;
320  }
321  }
322 
323  cleanEvent(evt, zvtx);
324 
325  // prevent a decay of existing particles
326  // this is due to a bug in the PythiaInterface that should be fixed in newer versions
327  for (GenEvent::particle_iterator it=evt->particles_begin();it!=evt->particles_end();it++)
328  (*it)->set_status(0);
329 
330  for (std::vector<reco::Particle>::const_iterator it=particles.begin();it!=particles.end();it++)
331  {
332  zvtx->add_particle_out(new HepMC::GenParticle((FourVector)it->p4(), it->pdgId(), 1, Flow(), Polarization(0,0)));
333  }
334  }
335  // new product with tau decays
336  else
337  {
338  reco::Particle::LorentzVector mother_particle_p4;
339  for (std::vector<reco::Particle>::const_iterator it=particles.begin();it!=particles.end();it++)
340  mother_particle_p4+=it->p4();
341 
342  reco::Particle::Point production_point = particles.begin()->vertex();
343 
344  GenVertex* startVtx = new GenVertex(FourVector(production_point.x()*10,production_point.y()*10,production_point.z()*10,0));
345  startVtx->add_particle_in( new GenParticle( FourVector(0,0,7000,7000), 2212, 3 ) );
346  startVtx->add_particle_in( new GenParticle( FourVector(0,0,-7000,7000), 2212, 3 ) );
347 
348  GenVertex * decayvtx = new GenVertex(FourVector(production_point.x()*10,production_point.y()*10,production_point.z()*10,0));
349  HepMC::GenParticle * mother_particle = new HepMC::GenParticle((FourVector)mother_particle_p4, motherParticleID_, (generatorMode_=="Pythia" ? 3 : 2), Flow(), Polarization(0,0));
350  if (transformationMode_ == 3) {
351  //std::cout << "Overriding mother particle id\n" << std::endl;
352  int muPDG = particles.begin()->pdgId();
353  int id = -24*muPDG/std::abs(muPDG);
354  mother_particle->set_pdg_id(id);
355  }
356 
357  startVtx->add_particle_out(mother_particle);
358  decayvtx->add_particle_in(mother_particle);
359  evt = new HepMC::GenEvent();
360  for (std::vector<reco::Particle>::const_iterator it=particles.begin();it!=particles.end();it++)
361  {
362  //std::cout << "XXX" << it->p4().pt() << " " << it->pdgId() << std::endl;
363  decayvtx->add_particle_out(new HepMC::GenParticle((FourVector)it->p4(), it->pdgId(), 1, Flow(), Polarization(0,0)));
364  }
365 
366  evt->add_vertex(startVtx);
367  evt->add_vertex(decayvtx);
368  }
369  repairBarcodes(evt);
370 
371  HepMC::GenEvent * retevt = 0;
372  HepMC::GenEvent * tempevt = 0;
373 
375  int nr_of_trials=0;
376 
377  unsigned int cntVisPt_all = 0;
378  unsigned int cntVisPt_pass = 0;
379 
380  HepMC::IO_HEPEVT conv;
381  for (int i = 0; i<maxNumberOfAttempts_; i++)
382  {
383  ++cntVisPt_all;
384  if (generatorMode_ == "Pythia") // Pythia
385  {
386  LogError("Replacer") << "Pythia is currently not supported!";
387  return std::auto_ptr<HepMC::GenEvent>(evt);
388  }
389 
390  if (generatorMode_ == "Tauola") // TAUOLA
391  {
392  conv.write_event(evt);
393  tempevt=tauola_->decay(evt);
394  }
395 
396  if (testEvent(tempevt))
397  {
398  if (retevt==0) {
399  retevt=tempevt;
400  } else {
401  delete tempevt;
402  }
403  ++cntVisPt_pass;
404  } else {
405  delete tempevt;
406  }
407  }
408 
409  tried = cntVisPt_all;
410  passed = cntVisPt_pass;
411 
412  std::cout << /*minVisibleTransverseMomentum_ <<*/ " " << cntVisPt_pass << "\t" << cntVisPt_all << "\n";
413  if (!retevt)
414  {
415  LogError("Replacer") << "failed to create an event which satisfies the minimum visible transverse momentum cuts ";
416  attempts=-1;
417  if(outTree) outTree->Fill();
418  return std::auto_ptr<HepMC::GenEvent>(0);
419  }
420  attempts=nr_of_trials;
421  if(outTree) outTree->Fill();
422 
423  // recover the status codes
424  if (genEvt)
425  {
426  for (GenEvent::particle_iterator it=retevt->particles_begin();it!=retevt->particles_end();it++)
427  {
428  if ((*it)->end_vertex())
429  (*it)->set_status(2);
430  else
431  (*it)->set_status(1);
432  }
433  }
434 
435  std::auto_ptr<HepMC::GenEvent> ret(retevt);
436 
437  if (printEvent_)
438  retevt->print(std::cout);
439 
440  delete part1;
441  delete part2;
442  delete zvtx;
443  delete evt;
444  return ret;
445 }
int i
Definition: DBlmapReader.cc:9
void repairBarcodes(HepMC::GenEvent *evt)
gen::TauolaInterface * tauola_
HepMC::GenEvent * decay(HepMC::GenEvent *)
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
static HepMC::IO_HEPEVT conv
virtual const Point & vertex() const
vertex position (overwritten by PF...)
virtual int pdgId() const GCC11_FINAL
PDG identifier.
bool testEvent(HepMC::GenEvent *evt)
#define abs(x)
Definition: mlp_lapack.h:159
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
T sqrt(T t)
Definition: SSEVec.h:48
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
math::XYZPoint Point
point in the space
Definition: Particle.h:29
virtual int charge() const GCC11_FINAL
electric charge
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
void cleanEvent(HepMC::GenEvent *evt, HepMC::GenVertex *vtx)
void transformMuMu2TauNu(reco::Particle *muon1, reco::Particle *muon2)
transform a muon pair into tau nu (as coming from a W boson)
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19
void transformMuMu2TauTau(reco::Particle *muon1, reco::Particle *muon2)
transform a muon pair into a tau pair
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
void setStatus(int status)
set status word
Definition: Particle.h:156
void ParticleReplacerClass::repairBarcodes ( HepMC::GenEvent *  evt)
private

Definition at line 605 of file ParticleReplacerClass.cc.

Referenced by cleanEvent(), and produce().

606 {
607  using namespace HepMC;
608 
609  // repair the barcodes
610  int max_barc=0;
611  for (GenEvent::vertex_iterator it=evt->vertices_begin(), next;it!=evt->vertices_end();it=next)
612  {
613  next=it;++next;
614  while (!(*it)->suggest_barcode(-1*(++max_barc)))
615  ;
616  }
617 
618  max_barc=0;
619  for (GenEvent::particle_iterator it=evt->particles_begin(), next;it!=evt->particles_end();it=next)
620  {
621  next=it;++next;
622  while (!(*it)->suggest_barcode(++max_barc))
623  ;
624  }
625 }
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19
bool ParticleReplacerClass::testEvent ( HepMC::GenEvent *  evt)
private

Definition at line 460 of file ParticleReplacerClass.cc.

References abs, runEdmFileComparison::collection, ParticleReplacerClass::MinVisPtCut::ELEC, prof2calltree::front, configurableAnalysis::GenParticle, ParticleReplacerClass::MinVisPtCut::HAD, minVisPtCuts_, ParticleReplacerClass::MinVisPtCut::MU, benchmark_cfg::pdgId, python.multivaluedict::sort(), lumiQTWidget::t, and ParticleReplacerClass::MinVisPtCut::TAU.

Referenced by produce().

461 {
462  using namespace HepMC;
463  using namespace edm;
464 
465  if (minVisPtCuts_.empty()) //ibleTransverseMomentum_<=0)
466  return true;
467 
468  std::vector<double> mus;
469  std::vector<double> elecs;
470  std::vector<double> hads;
471  std::vector<double> taus;
472 
473  for (GenEvent::particle_iterator it=evt->particles_begin();it!=evt->particles_end();it++)
474  {
475  if (abs((*it)->pdg_id())==15 && (*it)->end_vertex())
476  {
477  FourVector vis_mom();
478  math::PtEtaPhiMLorentzVector visible_momentum;
479  std::queue<const GenParticle *> decaying_particles;
480  decaying_particles.push(*it);
481  int t=0;
482  enum { ELEC, MU, HAD } type = HAD;
483  while(!decaying_particles.empty() && (++t < 30))
484  {
485  const GenParticle * front = decaying_particles.front();
486  decaying_particles.pop();
487 
488  if (!front->end_vertex())
489  {
490  int pdgId=abs(front->pdg_id());
491  if (pdgId>10 && pdgId!=12 && pdgId!=14 && pdgId!=16)
492  visible_momentum+=(math::PtEtaPhiMLorentzVector)front->momentum();
493 
494  if(pdgId == 11) type = ELEC;
495  if(pdgId == 13) type = MU;
496  }
497  else
498  {
499  GenVertex * temp_vert = front->end_vertex();
500  for (GenVertex::particles_out_const_iterator it2=temp_vert->particles_out_const_begin();it2!=temp_vert->particles_out_const_end();it2++)
501  decaying_particles.push((*it2));
502  }
503  }
504 
505  double vis_pt = visible_momentum.pt();
506  taus.push_back(vis_pt);
507  if(type == MU) mus.push_back(vis_pt);
508  if(type == ELEC) elecs.push_back(vis_pt);
509  if(type == HAD) hads.push_back(vis_pt);
510  }
511  }
512 
513  std::sort(taus.begin(), taus.end(), std::greater<double>());
514  std::sort(elecs.begin(), elecs.end(), std::greater<double>());
515  std::sort(mus.begin(), mus.end(), std::greater<double>());
516  std::sort(hads.begin(), hads.end(), std::greater<double>());
517 
518  for(std::vector<std::vector<MinVisPtCut> >::const_iterator iter = minVisPtCuts_.begin(); iter != minVisPtCuts_.end(); ++iter)
519  {
520  std::vector<MinVisPtCut>::const_iterator iter2;
521  for(iter2 = iter->begin(); iter2 != iter->end(); ++iter2)
522  {
523  std::vector<double>* collection;
524  switch(iter2->type_)
525  {
526  case MinVisPtCut::ELEC: collection = &elecs; break;
527  case MinVisPtCut::MU: collection = &mus; break;
528  case MinVisPtCut::HAD: collection = &hads; break;
529  case MinVisPtCut::TAU: collection = &taus; break;
530  default: assert(false); break;
531  }
532 
533  // subcut fail
534  if(iter2->index_ >= collection->size() || (*collection)[iter2->index_] < iter2->pt_)
535  break;
536  }
537 
538  // no subcut failed: This cut passed
539  if(iter2 == iter->end())
540  return true;
541  }
542 
543  LogInfo("Replacer") << "refusing the event as the sum of the visible transverse momenta is too small\n";
544  return false;
545 }
type
Definition: HCALResponse.h:21
#define abs(x)
Definition: mlp_lapack.h:159
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:26
virtual Vector momentum() const GCC11_FINAL
spatial momentum vector
virtual float pt() const GCC11_FINAL
transverse momentum
std::vector< std::vector< MinVisPtCut > > minVisPtCuts_
void ParticleReplacerClass::transformMuMu2TauNu ( reco::Particle muon1,
reco::Particle muon2 
)
private

transform a muon pair into tau nu (as coming from a W boson)

Definition at line 686 of file ParticleReplacerClass.cc.

References abs, gather_cfg::cout, reco::Particle::p4(), reco::Particle::pdgId(), L1Trigger_dataformats::reco, reco::Particle::setP4(), reco::Particle::setPdgId(), reco::Particle::setStatus(), mathSSE::sqrt(), and targetParticleMass_.

Referenced by produce().

687 {
688  using namespace edm;
689  using namespace reco;
690  using namespace std;
691 
692  reco::Particle::LorentzVector muon1_momentum = part1->p4();
693  reco::Particle::LorentzVector muon2_momentum = part2->p4();
694  reco::Particle::LorentzVector z_momentum = muon1_momentum + muon2_momentum;
695 
696  ROOT::Math::Boost booster(z_momentum.BoostToCM());
697  ROOT::Math::Boost invbooster(booster.Inverse());
698 
699  reco::Particle::LorentzVector Zb = booster(z_momentum);
700 
701  const double breitWignerWidth_Z = 2.4952;
702  const double breitWignerWidth_W = 2.141;
703  const double knownMass_W = 80.398;
704  const double knownMass_Z = 91.1876;
705 
706  double Wb_mass = ( Zb.mass() - knownMass_Z ) * ( breitWignerWidth_W / breitWignerWidth_Z ) + knownMass_W;
707  std::cout << "Wb_mass: " << Wb_mass << "\n";
708 
709  reco::Particle::LorentzVector muon1b = booster(muon1_momentum);
710  reco::Particle::LorentzVector muon2b = booster(muon2_momentum);
711 
712  double tau_mass2 = targetParticleMass_*targetParticleMass_;
713 
714  double muonxb_mom2 = muon1b.x()*muon1b.x() + muon1b.y()*muon1b.y() + muon1b.z() * muon1b.z();
715  double tauxb_mom2 = 0.25 * Zb.t() * Zb.t() - tau_mass2;
716 
717  float scaling1 = sqrt(tauxb_mom2 / muonxb_mom2) * Wb_mass/Zb.mass();
718  float scaling2 = scaling1;
719 
720  float tauEnergy= Zb.t() / 2.;
721 
722  if (tauEnergy*tauEnergy<tau_mass2)
723  return;
724 
725  reco::Particle::LorentzVector tau1b_mom = reco::Particle::LorentzVector(scaling1*muon1b.x(),scaling1*muon1b.y(),scaling1*muon1b.z(),tauEnergy* Wb_mass/Zb.mass());
726  reco::Particle::LorentzVector tau2b_mom = reco::Particle::LorentzVector(scaling2*muon2b.x(),scaling2*muon2b.y(),scaling2*muon2b.z(),tauEnergy* Wb_mass/Zb.mass());
727 
728  std::cout << "muon1b_momentum: " << muon1b << "\n";
729  std::cout << "muon2b_momentum: " << muon2b << "\n";
730 
731  std::cout << "tau1b_momentum: " << tau1b_mom << "\n";
732  std::cout << "tau2b_momentum: " << tau2b_mom << "\n";
733 
734  std::cout << "zb_momentum: " << Zb << "\n";
735  std::cout << "wb_momentum: " << (tau1b_mom+tau2b_mom) << "\n";
736 
737  // some checks
738  // the following test guarantees a deviation
739  // of less than 0.1% for phi and theta for the
740  // original muons and the placed taus
741  // (in the centre-of-mass system of the z boson)
742  assert((muon1b.phi()-tau1b_mom.phi())/muon1b.phi()<0.001);
743  assert((muon2b.phi()-tau2b_mom.phi())/muon2b.phi()<0.001);
744  assert((muon1b.theta()-tau1b_mom.theta())/muon1b.theta()<0.001);
745  assert((muon2b.theta()-tau2b_mom.theta())/muon2b.theta()<0.001);
746 
747  reco::Particle::LorentzVector tau1_mom = (invbooster(tau1b_mom));
748  reco::Particle::LorentzVector tau2_mom = (invbooster(tau2b_mom));
749 
750  // some additional checks
751  // the following tests guarantee a deviation of less
752  // than 0.1% for the following values of the original
753  // muons and the placed taus
754  // invariant mass
755  // transverse momentum
756  //assert(((muon1_momentum+muon1_momentum).mass()-(tau1_mom+tau2_mom).mass())/(muon1_momentum+muon1_momentum).mass()<0.001);
757  //assert(((muon1_momentum+muon2_momentum).pt()-(tau1_mom+tau2_mom).pt())/(muon1_momentum+muon1_momentum).pt()<0.001);
758 
759  part1->setP4(tau1_mom);
760  part2->setP4(tau2_mom);
761 
762  part1->setPdgId(15*part1->pdgId()/abs(part1->pdgId()));
763  part2->setPdgId(16*part2->pdgId()/abs(part2->pdgId()));
764 
765  part1->setStatus(1);
766  part2->setStatus(1);
767 
768  return;
769 }
#define abs(x)
Definition: mlp_lapack.h:159
T sqrt(T t)
Definition: SSEVec.h:48
tuple cout
Definition: gather_cfg.py:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
void ParticleReplacerClass::transformMuMu2TauTau ( reco::Particle muon1,
reco::Particle muon2 
)
private

transform a muon pair into a tau pair

Definition at line 628 of file ParticleReplacerClass.cc.

References abs, reco::Particle::p4(), reco::Particle::pdgId(), L1Trigger_dataformats::reco, reco::Particle::setP4(), reco::Particle::setPdgId(), reco::Particle::setStatus(), mathSSE::sqrt(), targetParticleMass_, and targetParticlePdgID_.

Referenced by produce().

629 {
630  using namespace edm;
631  using namespace reco;
632  using namespace std;
633 
634  reco::Particle::LorentzVector muon1_momentum = muon1->p4();
635  reco::Particle::LorentzVector muon2_momentum = muon2->p4();
636  reco::Particle::LorentzVector z_momentum = muon1_momentum + muon2_momentum;
637 
638  ROOT::Math::Boost booster(z_momentum.BoostToCM());
639  ROOT::Math::Boost invbooster(booster.Inverse());
640 
641  reco::Particle::LorentzVector Zb = booster(z_momentum);
642 
643  reco::Particle::LorentzVector muon1b = booster(muon1_momentum);
644  reco::Particle::LorentzVector muon2b = booster(muon2_momentum);
645 
646  double tau_mass2 = targetParticleMass_*targetParticleMass_;
647 
648  double muonxb_mom2 = muon1b.x()*muon1b.x() + muon1b.y()*muon1b.y() + muon1b.z() * muon1b.z();
649  double tauxb_mom2 = 0.25 * Zb.t() * Zb.t() - tau_mass2;
650 
651  float scaling1 = sqrt(tauxb_mom2 / muonxb_mom2);
652  float scaling2 = scaling1;
653 
654  float tauEnergy= Zb.t() / 2.;
655 
656  if (tauEnergy*tauEnergy<tau_mass2)
657  return;
658 
659  reco::Particle::LorentzVector tau1b_mom = reco::Particle::LorentzVector(scaling1*muon1b.x(),scaling1*muon1b.y(),scaling1*muon1b.z(),tauEnergy);
660  reco::Particle::LorentzVector tau2b_mom = reco::Particle::LorentzVector(scaling2*muon2b.x(),scaling2*muon2b.y(),scaling2*muon2b.z(),tauEnergy);
661 
662  reco::Particle::LorentzVector tau1_mom = (invbooster(tau1b_mom));
663  reco::Particle::LorentzVector tau2_mom = (invbooster(tau2b_mom));
664 
665  // some additional checks
666  // the following tests guarantee a deviation of less
667  // than 0.1% for the following values of the original
668  // muons and the placed taus
669  // invariant mass
670  // transverse momentum
671  assert(std::abs((muon1_momentum+muon2_momentum).mass()-(tau1_mom+tau2_mom).mass())/(muon1_momentum+muon2_momentum).mass()<0.001);
672  assert(std::abs((muon1_momentum+muon2_momentum).pt()-(tau1_mom+tau2_mom).pt())/(muon1_momentum+muon2_momentum).pt()<0.001);
673 
674  muon1->setP4(tau1_mom);
675  muon2->setP4(tau2_mom);
676 
677  muon1->setPdgId(targetParticlePdgID_*muon1->pdgId()/abs(muon1->pdgId()));
678  muon2->setPdgId(targetParticlePdgID_*muon2->pdgId()/abs(muon2->pdgId()));
679 
680  muon1->setStatus(1);
681  muon2->setStatus(1);
682 
683  return;
684 }
void setP4(const LorentzVector &p4)
set 4-momentum
Definition: Particle.h:105
#define abs(x)
Definition: mlp_lapack.h:159
const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: Particle.h:64
int pdgId() const
PDG identifier.
Definition: Particle.h:150
T sqrt(T t)
Definition: SSEVec.h:48
void setPdgId(int pdgId)
Definition: Particle.h:152
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
void setStatus(int status)
set status word
Definition: Particle.h:156

Member Data Documentation

int ParticleReplacerClass::attempts
private

Definition at line 103 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass(), and produce().

std::string ParticleReplacerClass::generatorMode_
private

Definition at line 78 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass(), and produce().

int ParticleReplacerClass::maxNumberOfAttempts_
private

Definition at line 104 of file ParticleReplacerClass.h.

Referenced by produce().

std::vector<std::vector<MinVisPtCut> > ParticleReplacerClass::minVisPtCuts_
private

Definition at line 96 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass(), and testEvent().

int ParticleReplacerClass::motherParticleID_
private

Definition at line 86 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass(), and produce().

bool ParticleReplacerClass::noInitialisation_
private

Definition at line 79 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass().

TTree* ParticleReplacerClass::outTree
private

Definition at line 102 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass(), and produce().

bool ParticleReplacerClass::printEvent_
private

Definition at line 93 of file ParticleReplacerClass.h.

Referenced by produce().

double ParticleReplacerClass::targetParticleMass_
private

Definition at line 99 of file ParticleReplacerClass.h.

Referenced by produce(), transformMuMu2TauNu(), and transformMuMu2TauTau().

int ParticleReplacerClass::targetParticlePdgID_
private

Definition at line 100 of file ParticleReplacerClass.h.

Referenced by produce(), and transformMuMu2TauTau().

gen::TauolaInterface* ParticleReplacerClass::tauola_
private

Definition at line 91 of file ParticleReplacerClass.h.

Referenced by beginRun(), endJob(), ParticleReplacerClass(), and produce().

unsigned int ParticleReplacerClass::transformationMode_
private

Definition at line 84 of file ParticleReplacerClass.h.

Referenced by ParticleReplacerClass(), and produce().

bool ParticleReplacerClass::useExternalGenerators_
private

Definition at line 87 of file ParticleReplacerClass.h.

bool ParticleReplacerClass::useTauola_
private

Definition at line 88 of file ParticleReplacerClass.h.

bool ParticleReplacerClass::useTauolaPolarization_
private

Definition at line 89 of file ParticleReplacerClass.h.