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 45 of file PhotosInterface.cc.

References fAvoidTauLeptonicDecays, fIsInitialized, and fSpecialSettings.

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

Definition at line 53 of file PhotosInterface.cc.

References fIsInitialized, and fSpecialSettings.

54  : fOnlyPDG(-1)
55 {
56  fSpecialSettings.push_back("QED-brem-off:all");
57  fIsInitialized = false;
58 }
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 85 of file PhotosInterface.cc.

References 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__(), jetTools.AddJetCollection::__call__(), HiCoreTools.RemoveMCMatching::__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__(), tauTools.AddTauCollection::__call__(), trackTools.MakeTrackCandidates::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), HiCoreTools.RemoveCleaning::__call__(), HiCoreTools.AddCleaning::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.AddJetID::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.SetTagInfos::__call__(), metUncertaintyTools.RunMEtUncertainties::__call__(), and gen::ExternalDecayDriver::decay().

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

References applyToVertex(), and fSecVtxStore.

Referenced by apply().

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

Definition at line 186 of file PhotosInterface.cc.

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

Referenced by apply(), and applyToBranch().

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

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

Referenced by applyToVertex().

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

References fOnlyPDG, and fSpecialSettings.

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

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

Definition at line 73 of file PhotosInterface.cc.

References fIsInitialized, and phoini_().

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

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

Definition at line 453 of file PhotosInterface.cc.

References abs.

Referenced by apply(), and applyToVertex().

454 {
455 
456  if ( abs((*(vtx->particles_in_const_begin()))->pdg_id()) != 15 ) return false;
457 
458  for ( HepMC::GenVertex::particle_iterator pitr=vtx->particles_begin(HepMC::children);
459  pitr != vtx->particles_end(HepMC::children); ++pitr)
460  {
461  if ( abs((*pitr)->pdg_id()) == 11 || abs((*pitr)->pdg_id()) == 13 )
462  {
463  return true;
464  }
465  }
466 
467  return false;
468 
469 }
#define abs(x)
Definition: mlp_lapack.h:159
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().