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
gen::PhotosInterface Class Reference

#include <PhotosInterface.h>

Classes

struct  Scaling
 

Public Member Functions

HepMC::GenEvent * apply (HepMC::GenEvent *)
 
void avoidTauLeptonicDecays ()
 
void configureOnlyFor (int)
 
void init ()
 
bool isTauLeptonicDecay (HepMC::GenVertex *)
 
 PhotosInterface ()
 
 PhotosInterface (const edm::ParameterSet &)
 
const std::vector< std::string > & specialSettings ()
 
 ~PhotosInterface ()
 

Private Member Functions

void applyToBranch (HepMC::GenEvent *, int)
 
void applyToVertex (HepMC::GenEvent *, int)
 
void attachParticles (HepMC::GenEvent *, HepMC::GenVertex *, int)
 

Private Attributes

bool fAvoidTauLeptonicDecays
 
std::vector< int > fBarcodes
 
bool fIsInitialized
 
int fOnlyPDG
 
std::vector< int > fSecVtxStore
 
std::vector< std::string > fSpecialSettings
 

Detailed Description

Definition at line 20 of file PhotosInterface.h.

Constructor & Destructor Documentation

PhotosInterface::PhotosInterface ( )

Definition at line 43 of file PhotosInterface.cc.

References fAvoidTauLeptonicDecays, fIsInitialized, and fSpecialSettings.

44  : fOnlyPDG(-1)
45 {
46  fSpecialSettings.push_back("QED-brem-off:all");
48  fIsInitialized = false;
49 }
std::vector< std::string > fSpecialSettings
PhotosInterface::PhotosInterface ( const edm::ParameterSet )

Definition at line 51 of file PhotosInterface.cc.

References fIsInitialized, and fSpecialSettings.

52  : fOnlyPDG(-1)
53 {
54  fSpecialSettings.push_back("QED-brem-off:all");
55  fIsInitialized = false;
56 }
std::vector< std::string > fSpecialSettings
gen::PhotosInterface::~PhotosInterface ( )
inline

Definition at line 27 of file PhotosInterface.h.

27 {}

Member Function Documentation

HepMC::GenEvent * PhotosInterface::apply ( HepMC::GenEvent *  evt)

Definition at line 83 of file PhotosInterface.cc.

References funct::abs(), applyToBranch(), applyToVertex(), fAvoidTauLeptonicDecays, fIsInitialized, fOnlyPDG, fSecVtxStore, isTauLeptonicDecay(), and phoqed_.

Referenced by heavyIonTools.ConfigureHeavyIons::__call__(), editorTools.UserCodeTool::__call__(), HiCoreTools.RestrictInputToAOD::__call__(), coreTools.RunOnData::__call__(), trackTools.MakeAODTrackCandidates::__call__(), metTools.AddMETCollection::__call__(), heavyIonTools.ProductionDefaults::__call__(), editorTools.ChangeSource::__call__(), HiCoreTools.RemoveMCMatching::__call__(), jetTools.AddJetCollection::__call__(), cmsswVersionTools.PickRelValInputFiles::__call__(), coreTools.RemoveMCMatching::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), heavyIonTools.SelectionDefaults::__call__(), HiCoreTools.RemoveAllPATObjectsBut::__call__(), heavyIonTools.DisbaleMonteCarloDeps::__call__(), HiCoreTools.RemoveSpecificPATObjects::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), trackTools.MakeTrackCandidates::__call__(), tauTools.AddTauCollection::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), HiCoreTools.RemoveCleaning::__call__(), HiCoreTools.AddCleaning::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), jetTools.SwitchJetCollection::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), metUncertaintyTools.RunMEtUncertainties::__call__(), GenMuonRadiationAlgorithm::compFSR(), and gen::ExternalDecayDriver::decay().

84 {
85 
86  if ( !fIsInitialized ) return evt; // conv.read_next_event();
87 
88  // loop over HepMC::GenEvent, find vertices
89 
90  // for ( int ip=0; ip<evt->particles_size(); ip++ )
91  for ( int ip=0; ip<4000; ip++ ) // 4000 is the max size of the array
92  {
93  phoqed_.qedrad[ip]=true;
94  }
95 
96  //
97  // now do actual job
98  //
99 
100  for ( int iv=1; iv<=evt->vertices_size(); iv++ )
101  {
102 
103  bool legalVtx = false;
104 
105  fSecVtxStore.clear();
106 
107  HepMC::GenVertex* vtx = evt->barcode_to_vertex( -iv ) ;
108 
109  if ( vtx->particles_in_size() != 1 ) continue; // more complex than we need
110  if ( vtx->particles_out_size() <= 1 ) continue; // no outcoming particles
111 
112  if ( (*(vtx->particles_in_const_begin()))->pdg_id() == 111 ) continue; // pi0 decay vtx - no point to try
113 
114  if ( fOnlyPDG != 1 && (*(vtx->particles_in_const_begin()))->pdg_id() != fOnlyPDG )
115  {
116  continue;
117  }
118  else
119  {
120  // requested for specific PDG ID only, typically tau (15)
121  //
122  // first check if a brem vertex, where outcoming are the same pdg id and a photon
123  //
124  bool same = false;
125  for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
126  pitr != vtx->particles_end(HepMC::children); ++pitr)
127  {
128  if ( (*pitr)->pdg_id() == fOnlyPDG )
129  {
130  same = true;
131  break;
132  }
133  }
134  if ( same ) continue;
135 
136  // OK, we get here if incoming fOnlyPDG and something else outcoming
137  // call it for the whole branch starting at vtx barcode iv, and go on
138  // NOTE: theoretically, it has a danger of double counting in vertices
139  // down the decay branch originating from fOnlyPDG, but in practice
140  // it's unlikely that down the branchg there'll be more fOnlyPDG's
141 
142  // cross-check printout
143  // vtx->print();
144 
145  // overprotection...
146  //
147  if ( fOnlyPDG == 15 && fAvoidTauLeptonicDecays && isTauLeptonicDecay( vtx ) ) continue;
148 
149  applyToBranch( evt, -iv );
150  continue;
151  }
152 
153  // configured for all types of particles
154  //
155  for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
156  pitr != vtx->particles_end(HepMC::children); ++pitr)
157  {
158 
159  // quark or gluon out of this vertex - no good !
160  if ( abs((*pitr)->pdg_id()) >=1 && abs((*pitr)->pdg_id()) <=8 ) break;
161  if ( abs((*pitr)->pdg_id()) == 21 ) break;
162 
163  if ( (*pitr)->status() == 1 || (*pitr)->end_vertex() )
164  {
165  // OK, legal already !
166  legalVtx = true;
167  break;
168  }
169  }
170 
171  if ( !legalVtx ) continue;
172 
173  applyToVertex( evt, -iv );
174 
175  } // end of master loop
176 
177  // restore event number in HEPEVT (safety measure, somehow needed by Hw6)
178  HepMC::HEPEVT_Wrapper::set_event_number( evt->event_number() );
179 
180  return evt;
181 
182 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void applyToBranch(HepMC::GenEvent *, int)
struct @360 phoqed_
std::vector< int > fSecVtxStore
void applyToVertex(HepMC::GenEvent *, int)
bool isTauLeptonicDecay(HepMC::GenVertex *)
void PhotosInterface::applyToBranch ( HepMC::GenEvent *  evt,
int  vtxbcode 
)
private

Definition at line 276 of file PhotosInterface.cc.

References applyToVertex(), and fSecVtxStore.

Referenced by apply().

277 {
278 
279 
280  fSecVtxStore.clear();
281 
282  // 1st level vertex
283  //
284  applyToVertex( evt, vtxbcode );
285 
286  // now look down the branch for more vertices, if any
287  //
288  // Note: fSecVtxStore gets filled up in applyToVertex, if necessary
289  //
290  unsigned int vcounter = 0;
291 
292  while ( vcounter < fSecVtxStore.size() )
293  {
294  applyToVertex( evt, fSecVtxStore[vcounter] );
295  vcounter++;
296  }
297 
298  fSecVtxStore.clear();
299 
300  return;
301 
302 }
std::vector< int > fSecVtxStore
void applyToVertex(HepMC::GenEvent *, int)
void PhotosInterface::applyToVertex ( HepMC::GenEvent *  evt,
int  vtxbcode 
)
private

Definition at line 184 of file PhotosInterface.cc.

References attachParticles(), fAvoidTauLeptonicDecays, fBarcodes, fSecVtxStore, getHLTprescales::index, isTauLeptonicDecay(), and photos_().

Referenced by apply(), and applyToBranch().

185 {
186 
187  HepMC::GenVertex* vtx = evt->barcode_to_vertex( vtxbcode );
188 
189  if ( fAvoidTauLeptonicDecays && isTauLeptonicDecay( vtx ) ) return;
190 
191  // cross-check printout
192  //
193  // vtx->print();
194 
195  // first, flush out HEPEVT & tmp barcode storage
196  //
197  HepMC::HEPEVT_Wrapper::zero_everything();
198  fBarcodes.clear();
199 
200  // add incoming particle
201  //
202  int index = 1;
203  HepMC::HEPEVT_Wrapper::set_id( index, (*(vtx->particles_in_const_begin()))->pdg_id() );
204  HepMC::FourVector vec4;
205  vec4 = (*(vtx->particles_in_const_begin()))->momentum();
206  HepMC::HEPEVT_Wrapper::set_momentum( index, vec4.x(), vec4.y(), vec4.z(), vec4.e() );
207  HepMC::HEPEVT_Wrapper::set_mass( index, (*(vtx->particles_in_const_begin()))->generated_mass() );
208  HepMC::HEPEVT_Wrapper::set_position( index, vtx->position().x(), vtx->position().y(),
209  vtx->position().z(), vtx->position().t() );
210  HepMC::HEPEVT_Wrapper::set_status( index, (*(vtx->particles_in_const_begin()))->status() );
211  HepMC::HEPEVT_Wrapper::set_parents( index, 0, 0 );
212  fBarcodes.push_back( (*(vtx->particles_in_const_begin()))->barcode() );
213 
214  // add outcoming particles (decay products)
215  //
216  int lastDau = 1;
217  for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
218  pitr != vtx->particles_end(HepMC::children); ++pitr)
219  {
220 
221  if ( (*pitr)->status() == 1 || (*pitr)->end_vertex() )
222  {
223  index++;
224  vec4 = (*pitr)->momentum();
225  HepMC::HEPEVT_Wrapper::set_id( index, (*pitr)->pdg_id() );
226  HepMC::HEPEVT_Wrapper::set_momentum( index, vec4.x(), vec4.y(), vec4.z(), vec4.e() );
227  HepMC::HEPEVT_Wrapper::set_mass( index, (*pitr)->generated_mass() );
228  vec4 = (*pitr)->production_vertex()->position();
229  HepMC::HEPEVT_Wrapper::set_position( index, vec4.x(), vec4.y(), vec4.z(), vec4.t() );
230  HepMC::HEPEVT_Wrapper::set_status( index, (*pitr)->status() );
231  HepMC::HEPEVT_Wrapper::set_parents( index, 1, 1 );
232  fBarcodes.push_back( (*pitr)->barcode() );
233  lastDau++;
234  }
235  if ( (*pitr)->end_vertex() )
236  {
237  fSecVtxStore.push_back( (*pitr)->end_vertex()->barcode() );
238  }
239  }
240 
241  // store, further to set NHEP in HEPEVT
242  //
243  int nentries = index;
244 
245  // reset master pointer to mother
246  index = 1;
247  HepMC::HEPEVT_Wrapper::set_children ( index, 2, lastDau ); // FIXME: need to check
248  // if last daughter>=2 !!!
249 
250  // finally, set number of entries (NHEP) in HEPEVT
251  //
252  HepMC::HEPEVT_Wrapper::set_number_entries( nentries );
253 
254  // cross-check printout HEPEVT
255  // HepMC::HEPEVT_Wrapper::print_hepevt();
256 
257  // OK, 1-level vertex is formed - now, call PHOTOS
258  //
259  photos_( index ) ;
260 
261  // another cross-check printout HEPEVT - after photos
262  // HepMC::HEPEVT_Wrapper::print_hepevt();
263 
264 
265  // now check if something has been generated
266  // and make all adjustments to underlying vtx/parts
267  //
268  attachParticles( evt, vtx, nentries );
269 
270  // ugh, done with this vertex !
271 
272  return;
273 
274 }
void attachParticles(HepMC::GenEvent *, HepMC::GenVertex *, int)
void photos_(int &)
std::vector< int > fBarcodes
std::vector< vec3 > vec4
Definition: HCALResponse.h:18
std::vector< int > fSecVtxStore
bool isTauLeptonicDecay(HepMC::GenVertex *)
void PhotosInterface::attachParticles ( HepMC::GenEvent *  evt,
HepMC::GenVertex *  vtx,
int  nentries 
)
private

Definition at line 304 of file PhotosInterface.cc.

References alignCSCRings::e, fBarcodes, configurableAnalysis::GenParticle, m, and ntuplemaker::status.

Referenced by applyToVertex().

305 {
306 
307  if ( HepMC::HEPEVT_Wrapper::number_entries() > nentries )
308  {
309  // yes, need all corrections and adjustments -
310  // figure out how many photons and what particles in
311  // the decay branch have changes;
312  // also, follow up each one and correct accordingly;
313  // at the same time, add photon(s) to the GenVertex
314  //
315 
316  // vtx->print();
317 
318  int largestBarcode = -1;
319  int Nbcodes = fBarcodes.size();
320 
321  for ( int ip=1; ip<Nbcodes; ip++ )
322  {
323 
324  int bcode = fBarcodes[ip];
325  HepMC::GenParticle* prt = evt->barcode_to_particle( bcode );
326  if ( bcode > largestBarcode ) largestBarcode = bcode;
327  double px = HepMC::HEPEVT_Wrapper::px(ip+1);
328  double py = HepMC::HEPEVT_Wrapper::py(ip+1);
329  double pz = HepMC::HEPEVT_Wrapper::pz(ip+1);
330  double e = HepMC::HEPEVT_Wrapper::e(ip+1);
331  double m = HepMC::HEPEVT_Wrapper::m(ip+1);
332 
333  if ( prt->end_vertex() )
334  {
335 
336  HepMC::GenVertex* endVtx = prt->end_vertex();
337 
338  std::vector<int> secVtxStorage;
339  secVtxStorage.clear();
340 
341  secVtxStorage.push_back( endVtx->barcode() );
342 
343  HepMC::FourVector mom4 = prt->momentum();
344 
345  // now rescale all descendants
346  double bet1[3], bet2[3], gam1, gam2, pb;
347  double mass = mom4.m();
348  bet1[0] = -(mom4.px()/mass);
349  bet1[1] = -(mom4.py()/mass);
350  bet1[2] = -(mom4.pz()/mass);
351  bet2[0] = px/m;
352  bet2[1] = py/m;
353  bet2[2] = pz/m;
354  gam1 = mom4.e()/mass;
355  gam2 = e/m;
356 
357  unsigned int vcounter = 0;
358 
359  while ( vcounter < secVtxStorage.size() )
360  {
361 
362  HepMC::GenVertex* theVtx = evt->barcode_to_vertex( secVtxStorage[vcounter] );
363 
364  for ( HepMC::GenVertex::particle_iterator pitr=theVtx->particles_begin(HepMC::children);
365  pitr != theVtx->particles_end(HepMC::children); ++pitr)
366  {
367 
368  if ( (*pitr)->end_vertex() )
369  {
370  secVtxStorage.push_back( (*pitr)->end_vertex()->barcode() );
371  }
372 
373  if ( theVtx->particles_out_size() == 1 && (*pitr)->pdg_id() == prt->pdg_id() )
374  {
375  // carbon copy
376  (*pitr)->set_momentum( HepMC::FourVector(px,py,pz,e) );
377  continue;
378  }
379 
380  HepMC::FourVector dmom4 = (*pitr)->momentum();
381 
382  // Boost vector to parent rest frame...
383  pb = bet1[0]*dmom4.px() + bet1[1]*dmom4.py() + bet1[2]*dmom4.pz();
384  double dpx = dmom4.px() + bet1[0] * (dmom4.e() + pb/(gam1+1.) );
385  double dpy = dmom4.py() + bet1[1] * (dmom4.e() + pb/(gam1+1.) );
386  double dpz = dmom4.pz() + bet1[2] * (dmom4.e() + pb/(gam1+1.) );
387  double de = gam1*dmom4.e() + pb;
388  // ...and boost back to modified parent frame
389  pb = bet2[0]*dpx + bet2[1]*dpy + bet2[2]*dpz;
390  dpx += bet2[0] * ( de + pb/(gam2+1.) );
391  dpy += bet2[1] * ( de + pb/(gam2+1.) );
392  dpz += bet2[2] * ( de + pb/(gam2+1.) );
393  de *= gam2;
394  de += pb;
395 
396  (*pitr)->set_momentum( HepMC::FourVector(dpx,dpy,dpz,de) );
397 
398  }
399  vcounter++;
400  }
401 
402  secVtxStorage.clear();
403  }
404 
405  prt->set_momentum( HepMC::FourVector(px,py,pz,e) );
406 
407  } // ok, all affected particles update, but the photon(s) still not inserted
408 
409  int newlyGen = HepMC::HEPEVT_Wrapper::number_entries() - nentries;
410 
411  if ( largestBarcode < evt->particles_size() )
412  {
413  // need to adjust barcodes down from the affected vertex/particles
414  // such that we "free up" barcodes for newly generated photons
415  // in the middle of the event record
416  //
417  for ( int ipp=evt->particles_size(); ipp>largestBarcode; ipp-- )
418  {
419  (evt->barcode_to_particle(ipp))->suggest_barcode( ipp+newlyGen );
420  }
421  }
422 
423  // now attach new generated photons to the vertex
424  //
425  for ( int ipnw=1; ipnw<=newlyGen; ipnw++ )
426  {
427  int nbcode = largestBarcode+ipnw;
428  int pdg_id = HepMC::HEPEVT_Wrapper::id( nentries+ipnw );
429  int status = HepMC::HEPEVT_Wrapper::status( nentries+ipnw );
430  double px = HepMC::HEPEVT_Wrapper::px( nentries+ipnw );
431  double py = HepMC::HEPEVT_Wrapper::py( nentries+ipnw );
432  double pz = HepMC::HEPEVT_Wrapper::pz( nentries+ipnw );
433  double e = HepMC::HEPEVT_Wrapper::e( nentries+ipnw );
434  double m = HepMC::HEPEVT_Wrapper::m( nentries+ipnw );
435 
436  HepMC::GenParticle* NewPart = new HepMC::GenParticle( HepMC::FourVector(px,py,pz,e),
437  pdg_id, status);
438  NewPart->set_generated_mass( m );
439  NewPart->suggest_barcode( nbcode );
440  vtx->add_particle_out( NewPart ) ;
441  }
442 
443  //vtx->print();
444  //std::cout << " leaving attachParticles() " << std::endl;
445 
446  } // end of global if-statement
447 
448  return;
449 }
std::vector< int > fBarcodes
tuple status
Definition: ntuplemaker.py:245
void gen::PhotosInterface::avoidTauLeptonicDecays ( )
inline

Definition at line 33 of file PhotosInterface.h.

References fAvoidTauLeptonicDecays.

Referenced by gen::ExternalDecayDriver::ExternalDecayDriver().

33 { fAvoidTauLeptonicDecays=true; return; }
void PhotosInterface::configureOnlyFor ( int  ipdg)

Definition at line 58 of file PhotosInterface.cc.

References fOnlyPDG, and fSpecialSettings.

Referenced by gen::ExternalDecayDriver::ExternalDecayDriver().

59 {
60 
61  fOnlyPDG = ipdg;
62 // std::ostringstream command;
63 // command << "QED-brem-off:" << fOnlyPDG ;
64  fSpecialSettings.clear();
65 // fSpecialSettings.push_back( command.str() );
66 
67  return;
68 
69 }
std::vector< std::string > fSpecialSettings
void PhotosInterface::init ( void  )

Definition at line 71 of file PhotosInterface.cc.

References fIsInitialized, and phoini_().

Referenced by GenMuonRadiationAlgorithm::compFSR(), and gen::ExternalDecayDriver::init().

72 {
73 
74  if ( fIsInitialized ) return; // do init only once
75 
76  phoini_();
77 
78  fIsInitialized = true;
79 
80  return;
81 }
void phoini_(void)
bool PhotosInterface::isTauLeptonicDecay ( HepMC::GenVertex *  vtx)

Definition at line 451 of file PhotosInterface.cc.

References funct::abs().

Referenced by apply(), and applyToVertex().

452 {
453 
454  if ( abs((*(vtx->particles_in_const_begin()))->pdg_id()) != 15 ) return false;
455 
456  for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
457  pitr != vtx->particles_end(HepMC::children); ++pitr)
458  {
459  if ( abs((*pitr)->pdg_id()) == 11 || abs((*pitr)->pdg_id()) == 13 )
460  {
461  return true;
462  }
463  }
464 
465  return false;
466 
467 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector<std::string>& gen::PhotosInterface::specialSettings ( )
inline

Definition at line 30 of file PhotosInterface.h.

References fSpecialSettings.

Referenced by gen::ExternalDecayDriver::init().

30 { return fSpecialSettings; }
std::vector< std::string > fSpecialSettings

Member Data Documentation

bool gen::PhotosInterface::fAvoidTauLeptonicDecays
private

Definition at line 47 of file PhotosInterface.h.

Referenced by apply(), applyToVertex(), avoidTauLeptonicDecays(), and PhotosInterface().

std::vector<int> gen::PhotosInterface::fBarcodes
private

Definition at line 48 of file PhotosInterface.h.

Referenced by applyToVertex(), and attachParticles().

bool gen::PhotosInterface::fIsInitialized
private

Definition at line 50 of file PhotosInterface.h.

Referenced by apply(), init(), and PhotosInterface().

int gen::PhotosInterface::fOnlyPDG
private

Definition at line 45 of file PhotosInterface.h.

Referenced by apply(), and configureOnlyFor().

std::vector<int> gen::PhotosInterface::fSecVtxStore
private

Definition at line 49 of file PhotosInterface.h.

Referenced by apply(), applyToBranch(), and applyToVertex().

std::vector<std::string> gen::PhotosInterface::fSpecialSettings
private

Definition at line 46 of file PhotosInterface.h.

Referenced by configureOnlyFor(), PhotosInterface(), and specialSettings().