14 #include "TObjString.h" 46 bool success = fromNtuple(ntp);
48 cout <<
"ERROR in DalitzEventList::DalitzEventList(TNtupleD* ntp)" 49 <<
"\n > problem creating myself from ntuple" 62 cout <<
"DalitzEventList::generatePhaseSpaceEvents " 63 <<
" about to generate " << NumEvents
64 <<
" events to phase space" << endl;
65 time_t tstart = time(0);
66 int reportN = NumEvents/10;
67 if(reportN > 10000) reportN = 10000;
68 for(
int i=0; i< NumEvents; i++){
69 if( i < 5 || (!(i%reportN))){
70 cout <<
"DalitzEventList::generatePhaseSpaceEvents " 71 <<
" generating " << i+1 <<
"th event." 72 <<
" with " << pat <<
" and " << rnd << endl;
76 double delT = difftime(time(0), tstart);
77 cout <<
" This took " << delT <<
" s";
79 cout <<
" this is " << NumEvents/delT <<
" evts/s" 80 <<
" or " << (NumEvents/delT) * 60<<
" evts/min";
88 ,
const std::string& name
94 if(this->
empty())
return (TH1D*)0;
97 double mi = ((*this)[0]).sijMin(sijIndices)/units;
98 double ma = ((*this)[0]).sijMax(sijIndices)/units;
106 TH1D* histo =
new TH1D(name.c_str(), name.c_str(), nbins, mi, ma);
108 for(
unsigned int i = 0; i < this->
size(); i++){
111 if(0 != weightFunction) w = weightFunction->
RealVal(evt);
112 double x= evt.sij(sijIndices)/units;
113 if(opt ==
'm') x = sqrt(x);
120 ,
const std::vector<int> sijIndicesY
121 ,
const std::string& name
127 if(this->
empty())
return (TH2D*)0;
131 double miX = ((*this)[0]).sijMin(sijIndicesX)/units;
132 double maX = ((*this)[0]).sijMax(sijIndicesX)/units;
133 double miY = ((*this)[0]).sijMin(sijIndicesY)/units;
134 double maY = ((*this)[0]).sijMax(sijIndicesY)/units;
141 miX -= (maX - miX)*eps;
142 maX += (maX - miX)*eps;
143 miY -= (maY - miY)*eps;
144 maY += (maY - miY)*eps;
146 TH2D* histo =
new TH2D(name.c_str()
150 for(
unsigned int i = 0; i < this->
size(); i++){
153 if(0 != weightFunction) w = weightFunction->
RealVal(evt);
154 double x= evt.sij(sijIndicesX)/units;
155 double y= evt.sij(sijIndicesY)/units;
160 histo->Fill(x, y, w);
169 std::string ntp_str=
"";
170 int nd = ((*this)[0]).eventPattern().size()-1;
171 if(nd < 3)
return (TNtupleD*)0;
175 for(namedVMap::const_iterator it = sijList.begin();
176 it != sijList.end(); it++){
177 std::string entry_name =
"s" + it->first +
":";
178 ntp_str += entry_name;
181 for(namedVMap::const_iterator it = sijList.begin();
182 it != sijList.end(); it++){
183 std::string entry_name =
"m" + it->first +
":";
184 ntp_str += entry_name;
187 ntp_str +=
"weight:";
191 std::string ntp_id =
className() +
"_sij";
192 std::string name = name_prefix +
"_sij";
193 TNtupleD* ntp =
new TNtupleD(ntp_id.c_str()
197 Double_t* array =
new Double_t[arraySize];
199 for(
unsigned int i = 0; i < this->
size(); i++){
201 for(namedVMap::const_iterator it = sijList.begin();
202 it != sijList.end(); it++){
203 array[arrayIndex]=((*this)[i]).sij(it->second)/units;
206 for(namedVMap::const_iterator it = sijList.begin();
207 it != sijList.end(); it++){
208 std::string entry_name =
"m" + it->first;
209 double sijtemp = ((*this)[i]).sij(it->second)/units;
211 array[arrayIndex]=sqrt(sijtemp);
213 array[arrayIndex] = -9999.;
218 array[arrayIndex] = evt.getWeight();
221 if(0 != weightFunction) fcn = weightFunction->
RealVal(evt);
222 array[arrayIndex] = fcn;
238 if(this->
empty())
return ps;
240 int nd = ((*this)[0]).eventPattern().
size()-1;
241 if(nd < 3)
return ps;
245 for(namedVMap::const_iterator it = sijList.begin();
246 it != sijList.end(); it++){
247 std::string name = name_prefix +
"_s" + it->first;
249 TH1D* newPlots =
makePlot(it->second
255 if(0 != newPlots) ps.
push_back(newPlots);
257 name = name_prefix +
"_m" + it->first;
258 TH1D* newPlotm =
makePlot(it->second
264 if(0 != newPlotm) ps.
push_back(newPlotm);
265 namedVMap::const_iterator jt = it;
267 for(; jt != sijList.end(); jt++){
268 std::string name2D = name_prefix + jt->first +
"_vs_" + it->first;
270 TH2D* newPlot2D =
makePlot2D(it->second, jt->second, name2D
271 , weightFunction, nbins2D, units
274 if(0 != newPlot2D) ps.
push_back(newPlot2D);
277 TNtupleD* newPlotNtp =
makePlotNtp(name_prefix, weightFunction, units);
296 if(this->
empty())
return (TNtupleD*) 0;
297 std::string varNameString= ((this->
begin()))->makeNtupleVarnames();
298 TNtupleD* ntp =
new TNtupleD(
className().c_str()
300 , varNameString.c_str());
302 ntp->SetDirectory(0);
304 unsigned int arraySize = ((this->
begin()))->ntupleVarArraySize();
305 vector<Double_t> array(arraySize);
308 for(vector<DalitzEvent>::const_iterator it = this->
begin();
309 it != this->
end(); it++){
311 bool success = (it)->fillNtupleVarArray(array);
313 cout <<
"ERROR in DalitzEventList::makeNtuple" 314 <<
", call to DalitzEvent::fillNtupleVarArray" 315 <<
" returned failure" 318 ntp->Fill(&(array[0]));
337 ,
const std::string& ntpName
340 cout <<
"WARNING in DalitzEventList::saveAsNtuple!" 341 <<
"\n\tyou are trying to save me to the file: " 343 <<
"\n\tbut I have only " << this->
size()
345 <<
" I won't create the file." 349 TFile* f= TFile::Open(fname.c_str(),
"RECREATE");
352 if(0 != ntp) ntp->Write();
361 if(dbThis) cout <<
"about to read ntuple with ptr " << ntp << endl;
362 if(0==ntp)
return false;
363 if(ntp->GetEntries() <=0)
return false;
364 if(dbThis) cout <<
" number of entries: " << ntp->GetEntries() << endl;
367 for(Long64_t i=0; i< ntp->GetEntries(); i++){
369 cout <<
"DalitzEventList::fromNtuple " 370 <<
" getting " << i <<
" th entry" << endl;
373 if(dbThis) cout <<
" got it" << endl;
377 if(dbThis) cout <<
" made event" << endl;
379 cout <<
"ERROR in DalitzEventList::fromNtuple" 380 <<
", call to DalitzEvent::fromNtuple returned false!" 385 if(dbThis) cout <<
" added event" << endl;
387 if(dbThis) cout <<
"DalitzEventList::fromNtuple worked!" << endl;
393 if(dbThis) cout <<
"about to read ntuple with ptr " << ntp << endl;
394 if(0==ntp)
return false;
395 if(ntp->GetEntries() <=0)
return false;
396 if(dbThis) cout <<
" number of entries: " << ntp->GetEntries() << endl;
400 for(Long64_t i=0; i< ntp->GetEntries(); i++){
402 cout <<
"DalitzEventList::fromNtuple " 403 <<
" getting " << i <<
" th entry" << endl;
405 double rand = Rand.Rndm();
409 if(dbThis) cout <<
" got it" << endl;
413 if(dbThis) cout <<
" made event" << endl;
415 cout <<
"ERROR in DalitzEventList::fromNtuple" 416 <<
", call to DalitzEvent::fromNtuple returned false!" 421 if(dbThis) cout <<
" added event" << endl;
424 if(dbThis) cout <<
"DalitzEventList::fromNtuple worked!" << endl;
429 TFile* f(
new TFile(fname.c_str()));
431 cout <<
"ERROR in DalitzEventList::fromNtupleFile" 432 <<
"\n > Can't open file with filename = " 433 <<
"\n > " << fname << endl;
440 cout <<
"ERROR in DalitzEventList::fromNtupleFile" 441 <<
"\n > Can't get ntuple for filename = " 442 <<
"\n > " << fname << endl;
451 for(
unsigned int i=0; i< this->
size(); i++){
459 for(
unsigned int i=0; i< this->
size(); i++){
468 if(0 == w)
return hs;
469 for(
unsigned int i=0; i< this->
size(); i++){
478 if(0 == w)
return hs;
479 for(
unsigned int i=0; i< this->
size(); i++){
virtual bool Add(const DalitzEvent &evt)
bool fromFile(const std::string &fname="DalitzEvents.root")
virtual ~DalitzEventList()
TNtupleD * makeNtuple() const
std::vector< DalitzEvent >::iterator end()
void push_back(const T &c)
DalitzHistoSet weighedReWeightedHistoSet(MINT::IReturnRealForEvent< IDalitzEvent > *w)
bool save(const std::string &fname="DalitzEvents.root") const
TH2D * makePlot2D(const std::vector< int > sijIndicesX, const std::vector< int > sijIndicesY, const std::string &name, MINT::IReturnRealForEvent< IDalitzEvent > *weightFunction=0, int nbins=10, double units=GeV *GeV, char opt='s')
bool fromTree(TTree *tree)
virtual double RealVal(EVENT_TYPE &evt)=0
DalitzHistoSet reWeightedHistoSet(MINT::IReturnRealForEvent< IDalitzEvent > *w)
bool fromNtupleFile(const std::string &fname="DalitzEvents.root")
static const std::string _className
DalitzHistoSet weightedHistoSet() const
TNtupleD * makePlotNtp(const std::string &name_prefix="DalitzPlotNtp", MINT::IReturnRealForEvent< IDalitzEvent > *weightFunction=0, double units=GeV *GeV)
bool makePlots(const std::string &filename) const
bool fromNtuple(TTree *ntp)
virtual double getWeight() const
PlotSet makeAllPlots(const std::string &name_prefix, MINT::IReturnRealForEvent< IDalitzEvent > *weightFunction=0, int nbins1D=100, int nbins2D=10, double units=GeV *GeV)
DalitzEvent & at(unsigned int i)
std::vector< DalitzEvent >::iterator begin()
void addEvent(const IDalitzEvent &evt, double weight=1)
unsigned int size() const
virtual unsigned int size() const
const std::string & className() const
DalitzHistoSet histoSet() const
bool saveAsNtuple(const std::string &fname="DalitzEvents.root") const
int generatePhaseSpaceEvents(int NumEvents, const DalitzEventPattern &pat, TRandom *rnd=0)
TH1D * makePlot(const std::vector< int > sij, const std::string &name, MINT::IReturnRealForEvent< IDalitzEvent > *weightFunction=0, int nbins=100, double units=GeV *GeV, char opt='s')
bool save(const std::string &filename="DalitzHistos.root") const