13 #include <sys/types.h> 46 if((
string)HistoOption == (
string)
"fast") setFast();
47 if((
string)HistoOption == (
string)
"slow") setSlow();
60 , HistoOption(
"FitAmpPairList::HistoOption", (std::string)
"default")
67 , _Nevents(other._Nevents)
69 , _sumsq(other._sumsq)
70 , _psSum(other._psSum)
71 , _psSumSq(other._psSumSq)
73 , _cov(other._cov, this)
74 , _efficiency(other._efficiency)
75 , HistoOption(
"FitAmpPairList::HistoOption", (std::string)
"default")
86 if(0 == a1 || 0 == a2){
87 cout <<
"Error in FitAmpPairList::addAmps: " << a1 <<
", " << a2 << endl;
99 if(0 == evtPtr)
return;
105 static unsigned int nZeroPs=0;
112 cout <<
"WARNING in FitAmpPairList::addToHistograms" 113 <<
" " << ++nZeroPs <<
" th" 114 <<
" event with phase space = " << ps << endl;
119 for(
unsigned int i=0; i< this->
size(); i++){
123 if(dbThis) cout <<
"FitAmpPairList::addEvent(): adding event" << endl;
144 for(
unsigned int i=0; i< this->
size(); i++){
159 if(this->
size() != otherList.
size())
return false;
160 for(
unsigned int i=0; i < this->
size(); i++){
161 if(this->
at(i).
name() != otherList[i].name())
return false;
166 if(0 != otherListPtr){
167 return add(*otherListPtr);
172 if(0 != otherListPtr){
173 return add(*otherListPtr);
179 cout <<
"ERROR in FitAmpPairList::add " 180 <<
"trying to add incompatible lists" 193 for(
unsigned int i=0; i< this->
size(); i++){
194 this->
at(i) += otherList[i];
202 return append(*otherListPtr);
205 return append(*otherListPtr);
210 for(
unsigned int i=0; i< otherList.
size(); i++){
236 for(
unsigned int i=0; i< this->
size(); i++){
243 std::complex<double> sum = 0;
245 for(
unsigned int i=0; i< this->
size(); i++){
246 if((this->
at(i).fitAmp1().getTag() == tag1) && ( this->
at(i).
fitAmp2().
getTag() == tag2)){
247 sum += conj(this->
at(i).complexVal());
249 else if((this->
at(i).fitAmp1().getTag() == tag2) && ( this->
at(i).fitAmp2().getTag() == tag1)){
258 for(
unsigned int i=0; i< this->
size(); i++){
270 std::complex<double> sum = 0;
271 for(
unsigned int i=0; i< this->
size(); i++){
274 if(this->
at(i).fitAmp1().theBareDecay().getVal() > this->
at(i).fitAmp2().theBareDecay().getVal() ) val = conj(val);
283 std::complex<double> sum = 0;
284 for(
unsigned int i=0; i< this->
size(); i++){
293 for (
unsigned int i=0; i<mps->
size(); i++) {
296 if(i+1 >= grad.size()){
297 cout <<
"WARNING in FitAmpPairList::Gradient:" 298 <<
" have to increase size of grad to avoid memory issues" << endl;
302 grad.at(i)=0; grad.at(i+1)=0;
305 if(name_i.find(
"_Re")!=std::string::npos){
310 name_i.replace(name_i.find(
"_Re"),3,
"");
311 complex<double> sum(0);
312 for(
unsigned int j=0; j< this->
size(); j++){
313 if(!
A_is_in_B(name_i,this->
at(j).name()))
continue;
315 double singleAmpCorrection= 1.;
318 if(
A_is_in_B(name_i,this->
at(j).fitAmp1().name())){
319 sum += singleAmpCorrection* this->
at(j).
valNoFitPars()* conj(this->
at(j).fitAmp2().AmpPhase());
322 sum += singleAmpCorrection* conj( this->
at(j).valNoFitPars()* this->
at(j).fitAmp1().AmpPhase() );
326 grad.at(i)= sum.real();
327 grad.at(i+1)= -sum.imag();
359 std::cout <<
"FitAmpPairList::Gradient() called. Sorry, I don't know how to calculate the derivative with respect to the fit parameter " << mps->
getParPtr(i)->
name() <<
" ! Please implement me or set useAnalytic Gradient to 0 in your options file. I'll crash now. " << std::endl;
367 , std::vector<double>& grad){
369 for (
unsigned int i=0; i<mps->
size(); i++) {
372 grad[i]=0; grad[i+1]=0;
374 if(name_i.find(
"_Re")!=std::string::npos){
376 name_i.replace(name_i.find(
"_Re"),3,
"");
377 for(
unsigned int j=0; j< this->
size(); j++){
378 if(!
A_is_in_B(name_i,this->
at(j).name()))
continue;
382 if(i+1 >= grad.size()){
383 cout <<
"WARNING in FitAmpPairList::GradientForLasso:" 384 <<
" have to increase size of grad to avoid memory issues" << endl;
399 std::cout <<
"Sorry, I don't know how to calculate the derivative with respect to the fit parameter " << mps->
getParPtr(i)->
name() <<
" ! Please implement me or set useAnalytic Gradient to 0 in your options file. I'll crash now. " << std::endl;
408 for(
unsigned int i=0; i< this->
size(); i++){
416 for(
unsigned int i=0; i< this->
size(); i++){
424 for(
unsigned int i=0; i< this->
size(); i++){
432 for(
unsigned int i=0; i< this->
size(); i++){
441 for(
unsigned int i=0; i< this->
size(); i++){
443 if(this->
at(i).
integral()/norm > threshold)n++ ;
458 static int printouts=0;
459 static bool printedWarning=
false;
463 if(dbThis && printouts < 100){
465 cout <<
"FitAmpPairList::variance() with " 475 if(dbThis) cout <<
"returning OLD variance " << var << endl;
479 if(dbThis) cout <<
"returning new variance " << var << endl;
482 if(! printedWarning){
483 cout <<
"WARNING in FitAmpPairList::variance()" 484 <<
" ignoring correlations because _cov is invalid." 485 <<
" (I'll print this only once)" 495 for(
unsigned int i=0; i < this->
size(); i++){
509 double mean =
_sum/dN;
510 double meansq =
_sumsq/dN;
511 double v = (meansq - mean*mean)/dN;
520 cout <<
"FitAmpPairList::oldVariance() " 525 <<
" v " << v << endl;
531 if(0 == evtPtr)
return 0;
545 for(
unsigned int i=0; i< this->
size(); i++){
552 for(
unsigned int i=0; i< this->
size(); i++){
561 for(
unsigned int i=0; i< this->
size(); i++){
568 cout <<
"FitAmpPairList::saveEachAmpsHistograms: " 569 <<
"saving " << title <<
" as " << name << endl;
577 std::vector<DalitzHistoSet> HistoSet;
580 for(
unsigned int i=0; i< this->
size(); i++){
588 cout <<
"FitAmpPairList::saveEachAmpsHistograms: " 589 <<
"saving " << title <<
" as " << name << endl;
591 HistoSet.push_back(hs);
599 for(
unsigned int i=0; i< this->
size(); i++){
612 for(
unsigned int i=0; i< this->
size(); i++){
617 std::string title = this->
at(i).
name();
619 cout <<
"FitAmpPairList::saveEachAmpsHistograms: " 620 <<
"saving " << title <<
" as " << name << endl;
628 std::vector<DalitzHistoSet> HistoSet;
631 for(
unsigned int i=0; i< this->
size(); i++){
637 std::string title = this->
at(i).
name();
639 cout <<
"FitAmpPairList::saveEachAmpsHistograms: " 640 <<
"saving " << title <<
" as " << name << endl;
642 HistoSet.push_back(hs);
655 if(dbThis) cout <<
"FitAmpPairList::doFinalStats() called" << endl;
662 if(this->
empty())
return 0;
667 cout <<
"\n============================================" 668 <<
"============================================" 669 <<
"\n Amplitude Fractions";
674 cout <<
"ERROR in FitAmpPairList::makeAndStoreFractions()" 676 <<
" won't do fractions." 681 for(
unsigned int i=0; i < this->
size(); i++){
684 if(this->
at(i).isSingleAmp()){
692 if(this->
at(i).isSingleAmp()){
700 cout <<
"filled FitFractionLists" << endl;
704 cout <<
"=================================================" 705 <<
"\n=================================================" 707 <<
"\n ^^^^^^^^^^" << endl;
709 cout <<
"=================================================" 710 <<
"\n=================================================" 711 <<
"\n Interference terms (sorted by size)" 712 <<
"\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
713 cout << interferenceFractionsSorted << endl;
714 cout <<
"=================================================" 715 <<
"\n=================================================" << endl;
717 cout <<
"\n\n\t X-check: total sum of all terms" 718 <<
" (amplitude fractions + interference terms): " 727 ,
const std::string& fnameROOT
735 if(this->
empty())
return 0;
739 cout <<
"ERROR in FitAmpPairList::makeAndStoreFractions" 740 <<
"\n Minuit parameter set and fit parameters incompatible" 743 cout <<
"getting minuitCov" << endl;
745 cout <<
"got minuitCov" << endl;
749 cout <<
"got fcov" << endl;
753 bool printFitErrors = (fcov != 0 && fcov->
isValid());
755 cout <<
"\n============================================" 756 <<
"============================================" 757 <<
"\n Amplitude Fractions";
758 if(0 != fcov) cout <<
" +/- fit error ";
759 cout <<
" +/- integration error " 763 cout <<
"ERROR in FitAmpPairList::makeAndStoreFractions()" 765 <<
" won't do fractions." 770 for(
unsigned int i=0; i < this->
size(); i++){
773 if(this->
at(i).isSingleAmp()){
776 name = this->
at(i).
name();
786 if(this->
at(i).isSingleAmp()){
794 if(dbThis)cout <<
"filled FitFractionLists" << endl;
803 if(dbThis) cout <<
"... now including errors" << endl;
804 if(dbThis)cout <<
" sorting" << endl;
806 if(dbThis)cout <<
"sorted" << endl;
808 cout <<
"=================================================" 809 <<
"\n=================================================" 811 <<
"\n ^^^^^^^^^^" << endl;
813 cout <<
"=================================================" 814 <<
"\n=================================================" 815 <<
"\n Interference terms (sorted by size)" 816 <<
"\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
818 cout <<
"=================================================" 819 <<
"\n=================================================" << endl;
821 cout <<
"\n\n\t X-check: total sum of all terms" 822 <<
" (amplitude fractions + interference terms): " 826 ofstream os(fname.c_str(),std::ofstream::trunc);
834 os <<
"\\begin{tabular}{l r}" <<
"\n";
835 os <<
"\\hline" <<
"\n";
836 os <<
"\\hline" <<
"\n";
837 os <<
"Decay channel & Fraction [$\\%$] \\\\" <<
"\n";
838 os <<
"\\hline" <<
"\n";
840 for(
unsigned int i=0; i < this->
size(); i++){
848 name.ReplaceAll(
"->",
" \\to ");
849 name.ReplaceAll(
"Bs0",
"B_s");
850 name.ReplaceAll(
"Ds",
"D_s");
851 name.ReplaceAll(
"pi",
"\\pi");
852 name.ReplaceAll(
"rho",
"\\rho");
853 name.ReplaceAll(
"sigma10",
"\\sigma");
854 name.ReplaceAll(
"GS",
"");
855 name.ReplaceAll(
"SBW",
"");
856 name.ReplaceAll(
"RhoOmega",
"");
857 name.ReplaceAll(
"GLass",
"");
858 name.ReplaceAll(
"Lass",
"");
859 name.ReplaceAll(
"Bugg",
"");
860 name.ReplaceAll(
"Flatte",
"");
861 name.ReplaceAll(
"+",
"^+");
862 name.ReplaceAll(
"-",
"^-");
863 name.ReplaceAll(
"*",
"^*");
864 name.ReplaceAll(
")0",
")^0");
865 name.ReplaceAll(
",",
" \\, ");
866 name.ReplaceAll(
"NonResS0( \\to D_s^- \\, \\pi^+)",
"( D_s^- \\, \\pi^+)_{S}");
867 name.ReplaceAll(
"NonResV0( \\to D_s^- \\, \\pi^+)",
"( D_s^- \\, \\pi^+)_{P}");
868 name.ReplaceAll(
"NonResS0( \\to D_s^- \\, K^+)",
"( D_s^- \\, K^+)_{S}");
869 name.ReplaceAll(
"NonResV0( \\to D_s^- \\, K^+)",
"( D_s^- \\, K^+)_{P}");
871 os << std::fixed << std::setprecision(2) <<
"$" << name <<
"$ & " << frac * 100. <<
" $\\pm$ " << frac_err * 100. <<
" \\\\" <<
"\n";
873 os <<
" \\hline" <<
"\n";
875 os <<
"\\hline" <<
"\n";
876 os <<
"\\hline" <<
"\n";
877 os <<
"\\end{tabular}" <<
"\n";
880 TFile* paraFile =
new TFile((fnameROOT).c_str(),
"RECREATE");
881 TTree* tree =
new TTree(
"fractions",
"fractions");
883 for(
unsigned int i=0; i < this->
size(); i++){
886 if(this->
at(i).isSingleAmp())name = TString(this->
at(i).fitAmp1().name());
887 else name = TString(this->
at(i).name());
890 name.ReplaceAll(
"A(",
"");
891 name.ReplaceAll(
"fit",
"");
892 name.ReplaceAll(
"[",
"_");
893 name.ReplaceAll(
"]",
"_");
894 name.ReplaceAll(
"(",
"_");
895 name.ReplaceAll(
")",
"_");
896 name.ReplaceAll(
"->",
"_");
897 name.ReplaceAll(
"+",
"p");
898 name.ReplaceAll(
"-",
"m");
899 name.ReplaceAll(
"*",
"s");
900 name.ReplaceAll(
",",
"");
901 name.ReplaceAll(
"GS",
"");
902 name.ReplaceAll(
"GLass",
"");
903 name.ReplaceAll(
"Lass",
"");
904 name.ReplaceAll(
"RhoOmega",
"");
905 name.ReplaceAll(
"Bugg",
"");
906 name.ReplaceAll(
"Flatte",
"");
910 if(!this->
at(i).isSingleAmp()) name =
"int_" + name;
911 TBranch* Bra_val = tree->Branch( ((
string)name).c_str(), &val, ((
string)(name+
"/D")).c_str());
912 if(0 != Bra_val) Bra_val->Fill();
916 TBranch* Bra_val = tree->Branch(
"Sum", &val,
"Sum/D");
917 if(0 != Bra_val) Bra_val->Fill();
919 if(0 != tree) tree->Fill();
1068 bool ErrorProportionalToSqrtTarget =
true;
1071 cout <<
"ERROR in FitAmpPairList::getFractionChi2()" 1073 <<
" won't do fractions. Returning " << 9999.0e30
1078 double canonicalError=0.001;
1082 for(
unsigned int i=0; i < this->
size(); i++){
1090 double dfs=(frac - target_f)/canonicalError;
1091 if(ErrorProportionalToSqrtTarget && target_f > 0) dfs /= sqrt(0.01*target_f);
1100 return "FitAmpPairList";
1105 ofstream os((asSubdirOf +
"/"+
dirName() +
"values.txt").c_str());
1107 os <<
"sum " << setprecision(20) <<
_sum << endl;
1108 os <<
"sumsq " << setprecision(20) <<
_sumsq << endl;
1109 os <<
"psSum " << setprecision(20) <<
_psSum << endl;
1110 os <<
"psSumSq " << setprecision(20) <<
_psSumSq << endl;
1113 for(
unsigned int i=0; i < this->
size(); i++){
1119 cout <<
"WARNING IN FitAmpPairList::save(" << asSubdirOf
1120 <<
"): invalid _cov" << endl;
1129 cout <<
"FitAmpPairList::retrieve: reading from " 1130 << asSubdirOf << endl;
1134 if(stat(asSubdirOf.c_str(), &buf) != 0){
1135 if(verbose) cout <<
"FitAmpPairList::retrieve: " << asSubdirOf
1136 <<
" does not exist" << endl;
1140 ifstream is((asSubdirOf +
"/"+
dirName() +
"values.txt").c_str());
1143 is >> dummy >>
_sum;
1148 for(
unsigned int i=0; i < this->
size(); i++){
1179 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO
1180 | S_ISUID | S_ISGID;
1184 int zeroForSuccess = 0;
1185 zeroForSuccess |= mkdir( (asSubdirOf ).c_str(), mode );
1186 zeroForSuccess |= mkdir( (asSubdirOf +
"/" +
dirName() ).c_str(), mode );
1187 return (0 == zeroForSuccess);
1191 os <<
"FitAmpPairList with " << this->
size() <<
" FitAmpPairs:";
1192 for(
unsigned int i=0; i < this->
size(); i++){
1193 os <<
"\n\t" << i <<
") " << this->
at(i);
1198 for(
unsigned int i=0; i < this->
size(); i++){
1204 for(
unsigned int i=0; i < this->
size(); i++){
1209 for(
unsigned int i=0; i < this->
size(); i++){
1214 for(
unsigned int i=0; i < this->
size(); i++){
1219 for(
unsigned int i=0; i < this->
size(); i++){
1226 for(
unsigned int i=0; i < this->
size(); i++){
1232 for(
unsigned int i=0; i < this->
size(); i++){
1243 returnVal.
add(other);
std::complex< double > AmpPhase() const
TMatrixTSym< double > covMatrixFull()
void setSumFitError(double sfe)
bool acceptEvents() const
virtual double getFractionChi2() const
void startReIntegration()
virtual FitParameter & p1()=0
virtual bool append(const FitAmpPairList &otherListPtr)
FitFractionList _singleAmpFractions
const MinuitParameterSet * parSet() const
void push_back(const FitAmpPair &c)
FitAmpPairList & operator+=(const FitAmpPairList &other)
void startForcedReIntegration()
virtual double phaseSpace() const =0
std::complex< double > ComplexIntegralForTags(int tag1, int tag2) const
void setSumIntegError(double sie)
virtual int iFixInit() const =0
std::complex< double > complexVal() const
bool add(const FitAmpPair &other)
virtual void addAmps(FitAmplitude *a1, FitAmplitude *a2)
double getFractionSumError()
DalitzHistoSet histoSet() const
IMinuitParameter * getParPtr(unsigned int i)
virtual void reAddEvent(IDalitzEvent &evt, double weight=1)
double getFractionSumError()
virtual double RealVal(EVENT_TYPE &evt)=0
std::vector< DalitzHistoSet > GetEachAmpsHistograms()
virtual void GradientForLasso(MINT::MinuitParameterSet *mps, std::vector< double > &grad)
unsigned int size() const
bool retrieve(const std::string &asSubdirOf=".")
std::ostream & operator<<(std::ostream &os, const FitAmpPairList &fap)
void saveEachAmpsHistograms(const std::string &prefix) const
DecayTree theBareDecay() const
virtual const std::string & name() const =0
FitAmpPairCovariance _cov
double getInterferenceFracSumError()
const ValueType & getVal() const
virtual void doFinalStats(MINT::Minimiser *min=0)
DalitzHistoSet histoSetRe() const
virtual double oldVariance() const
virtual double variance() const
MINT::FitComplex & FitAmpPhase()
std::vector< DalitzHistoSet > GetInterferenceHistograms()
double integralForMatchingPatterns(bool match, int pattern_sign) const
double getIntegralVariance()
bool A_is_in_B(const std::string &a, const std::string &b)
double getFraction() const
bool isCompatibleWith(const FitAmpPairList &other) const
bool hasMatchingPattern() const
FitAmpPairList operator+(const FitAmpPairList &other) const
DalitzHistoSet histoSetIm() const
void add(const FitFraction &f)
std::complex< double > ComplexSumForMatchingPatterns(bool match) const
virtual bool add(const FitAmpPairList &otherList)
void setEfficiency(MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > eff)
double phaseSpaceIntegral() const
void setFraction(double fr)
MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > _efficiency
bool needToReIntegrate() const
FitAmpPair & at(unsigned int i)
virtual double integral() const
void setTitle(const std::string &title)
virtual bool hidden() const =0
virtual double sumOfVariances() const
bool makeDirectory(const std::string &asSubdirOf=".") const
int numberOfFitFractionsLargerThanThreshold(double threshold)
virtual std::complex< double > ComplexSum() const
virtual bool makeAndStoreFractions(MINT::Minimiser *mini=0)
double sumOfFitFractions()
virtual bool save(const std::string &asSubdirOf=".") const
bool needToReIntegrate() const
const FitFraction & sum() const
MINT::counted_ptr< IIntegrationCalculator > clone_IIntegrationCalculator() const
virtual void Gradient(MINT::MinuitParameterSet *mps, std::vector< double > &grad)
bool retrieve(const std::string &fromDirectory=".")
unsigned int size() const
std::string anythingToString(const T &anything)
virtual const MinuitParameterSet * parSet() const
virtual DalitzHistoSet un_normalised_histoSetIm() const
void startReIntegration()
double efficiency(IDalitzEvent *evtPtr)
void saveInterferenceHistograms(const std::string &prefix) const
double getFractionError(int i)
void sortByMagnitudeDecending()
double getFractionError(int i)
DalitzHistoSet interferenceHistoSet() const
virtual int numEvents() const
virtual void addEvent(IDalitzEvent *evtPtr, double weight=1)
std::string dirName() const
double sumOfSqrtFitFractions()
virtual DalitzHistoSet histoSet() const
virtual DalitzHistoSet un_normalised_histoSetRe() const
bool save(const std::string &filename="DalitzHistos.root") const
bool addLastEventFromList()
double absSumOfSqrtInterferenceFractions()
std::complex< double > valNoFitPars() const
virtual bool retrieve(const std::string &asSubdirOf=".")
FitFractionList _interferenceFractions
double absSumOfInterferenceFractions()
const std::string & name() const
virtual void print(std::ostream &os=std::cout) const
bool save(const std::string &asSubdirOf=".") const
double reAdd(IDalitzEvent &evt, double weight=1, double efficiency=1)
bool save(const std::string &asSubdirOf=".") const