MINT2
BaseGenerator.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:59 GMT
3 #include "Mint/BaseGenerator.h"
5 
6 #include <ctime>
7 #include <iostream>
8 
9 using namespace std;
10 using namespace MINT;
11 
13  : _unWeighted(true)
14  , _evtList(0)
15  , _noPrintout(false)
16  , _rnd(rnd)
17  , _mums_p(0)
18  , _mums_cosTheta(0)
19  , _mums_phi(0)
20 {
21 
22 }
25  , _unWeighted(other._unWeighted)
26  , _evtList(other._evtList)
27  , _noPrintout(other._noPrintout)
28  , _rnd(other._rnd)
29  , _mums_p(other._mums_p)
30  , _mums_cosTheta(other._mums_cosTheta)
31  , _mums_phi(other._mums_phi)
32 {
33 }
34 
36  , counted_ptr<IReturnReal> cosTheta
38  ){
39  _mums_p = p;
40  _mums_cosTheta = cosTheta;
41  _mums_phi = phi;
42 }
45 }
46 
48  return (0 != _mums_p);
49 }
50 
53  double p, cT, phi;
54  if(0 != _mums_p) p = _mums_p->RealVal();
55  else p=0;
56  if(0 != _mums_cosTheta) cT = _mums_cosTheta->RealVal();
57  else cT = _rnd->Rndm()*2.0 - 1.0;
58  if(0 != _mums_phi) phi = _mums_phi->RealVal();
59  else phi = _rnd->Rndm()*2.0*pi;
60 
61  double sT2 = 1.0 - cT*cT;
62  double sT;
63  if(sT2 < 0) sT=0;
64  else sT = sqrt(sT2);
65 
66  TVector3 v(p*cos(phi)*sT, p*sin(phi)*sT, p*cT);
67 
68  return v;
69  }else{
70  TVector3 v(0,0,0);
71  return v;
72  }
73 }
74 
75 void BaseGenerator::setSaveEvents(const std::string& fname
76  , const std::string& opt){
77  _evtList =
79 }
81  _evtList =
83 }
84 
86  bool dbThis=false;
87  if(dbThis) cout << "BaseGenerator::FillEventList (dr) called" << endl;
88  time_t t0 = time(0);
89  for(int i=0; i < NEvents; i++){
90  if(!_noPrintout){
91  int printEvery = 10000;
92  //if(i < 1000) printEvery=100;
93  bool printout = ( i%printEvery == 0 || i < 1);
94  if(dbThis || printout){
95  cout << "BaseGenerator::FillEventList (disk resident)" << endl;
96  cout << " about to make event number " << i << endl;
97  cout << " current list size " << evtList.size() << endl;
98  double dt = difftime(time(0), t0);
99  cout << " this took " << dt << "s" << endl;
100  if(dt > 0) cout << " or " << evtList.size()/dt << "evt/s" << endl;
101  }
102  }
104  DalitzEvent evt(evtPtr.get());
105  evtList.Add(evt);
106  if(dbThis){
107  cout << "BaseGenerator::FillEventList (disk resident)" <<endl;
108  cout << "After adding this event to the event list:\n " << evt << endl;
109  cout << ".... the last event in the list is:\n "
110  << evtList.getEvent(evtList.size()-1) << endl;
111  cout << "are they the same?" << endl;
112  }
113  }
114 }
115 
116 void BaseGenerator::FillEventList(DalitzEventList& evtList, int NEvents){
117  bool dbThis=false;
118  if(dbThis) cout << "BaseGenerator::FillEventList (mr) called" << endl;
119 
120  time_t t0 = time(0);
121  for(int i=0; i < NEvents; i++){
122  if(!_noPrintout){
123  int printEvery = 10000;
124  //if(i < 1000) printEvery=100;
125  bool printout = ( i%printEvery == 0 || i < 1);
126  if(dbThis || printout){
127  cout << "BaseGenerator::FillEventList (memory resident)" << endl;
128  cout << " about to make event number " << i << endl;
129  cout << " current list size " << evtList.size() << endl;
130  double dt = difftime(time(0), t0);
131  cout << " this took " << dt << "s" << endl;
132  if(dt > 0) cout << " or " << evtList.size()/dt << "evt/s" << endl;
133  }
134  }
135  // counted_ptr<IDalitzEvent> evt = newEvent();
136  if(dbThis) cout << " got new event, now adding it" << endl;
137  // evtList.Add(counted_ptr<DalitzEvent>(new DalitzEvent(evt.get()))); // this is a bit silly - will fix later
139  DalitzEvent evt(evtPtr.get());
140  evtList.Add(evt);
141  if(dbThis){
142  cout << "BaseGenerator::FillEventList (memory resident)" <<endl;
143  cout << "After adding this event to the event list:\n " << evt << endl;
144  cout << ".... the last event in the list is:\n "
145  << evtList[evtList.size()-1] << endl;
146  cout << "are they the same?" << endl;
147  }
148 
149  }
150 }
151 
153  if(0 == _rnd) _rnd = gRandom;
154  _rnd->SetSeed(time(0)*3);
155  return true;
156 }
158 
159 }
virtual bool Add(const EVENT_TYPE &evt)
Definition: EventList.h:63
MINT::counted_ptr< MINT::IReturnReal > _mums_p
Definition: BaseGenerator.h:39
MINT::counted_ptr< DiskResidentEventList > _evtList
Definition: BaseGenerator.h:31
virtual bool ensureFreshEvents()
virtual ~BaseGenerator()
MINT::counted_ptr< MINT::IReturnReal > _mums_cosTheta
Definition: BaseGenerator.h:40
TRandom * _rnd
Definition: BaseGenerator.h:37
static const double pi
void setSaveEvents(const std::string &fname="GeneratorEvents.root", const std::string &opt="RECREATE")
virtual bool Add(const DalitzEvent &evt)
bool mothers3MomentumIsSet() const
void dontSaveEvents()
void setMothers3Momentum(MINT::counted_ptr< MINT::IReturnReal > p, MINT::counted_ptr< MINT::IReturnReal > cosTheta=(MINT::counted_ptr< MINT::IReturnReal >) 0, MINT::counted_ptr< MINT::IReturnReal > phi=(MINT::counted_ptr< MINT::IReturnReal >) 0)
virtual unsigned int size() const
MINT::counted_ptr< MINT::IReturnReal > _mums_phi
Definition: BaseGenerator.h:41
void unsetMothers3Momentum()
BaseGenerator(TRandom *rnd=gRandom)
virtual double RealVal()=0
virtual unsigned int size() const
Definition: EventList.h:59
TVector3 mothers3Momentum() const
DalitzEvent getEvent(unsigned int i) const
void FillEventList(DalitzEventList &evtList, int NEvents)
virtual MINT::counted_ptr< IDalitzEvent > newEvent()=0
X * get() const
Definition: counted_ptr.h:123