11 #include "TVirtualFitter.h" 13 #include "TTreePlayer.h" 14 #include "TTreeFormula.h" 15 #include "TTreeFormulaManager.h" 16 #include "TSelectorDraw.h" 21 extern void Yields(Int_t &, Double_t *, Double_t &f, Double_t *
x, Int_t iflag);
497 while ((h = (TH1D*)next()))
498 b->Add(h,h->GetName());
504 while ((h = (TH1D*)next()))
505 b->Add(h,h->GetName());
510 while ((h = (TH1D*)next()))
511 b->Add(h,h->GetName());
516 while ((h = (TH1D*)next()))
517 b->Add(h,h->GetName());
546 Error(
"MakeSPlot",
"Initial numbers of events in species have not been set");
549 Int_t i, j, ispecies;
551 TString opt = option;
553 opt.ReplaceAll(
"VV",
"W");
557 if (TVirtualFitter::GetFitter()){
558 Int_t strdiff=strcmp(TVirtualFitter::GetFitter()->IsA()->GetName(), s);
560 delete TVirtualFitter::GetFitter();
564 TVirtualFitter *minuit = TVirtualFitter::Fitter(0, 2);
569 for (Int_t iplot=-1; iplot<
fNy; iplot++){
571 for (ispecies=0; ispecies<
fNSpecies; ispecies++){
573 for (j=0; j<
fNy; j++){
581 Double_t arglist[10];
583 if (opt.Contains(
"Q")||opt.Contains(
"V")){
586 if (opt.Contains(
"W"))
588 minuit->ExecuteCommand(
"SET PRINT", arglist, 1);
590 minuit->SetObjectFit(&
fPdfTot);
591 for (ispecies=0; ispecies<
fNSpecies; ispecies++)
594 minuit->ExecuteCommand(
"MIGRAD", arglist, 0);
595 for (ispecies=0; ispecies<
fNSpecies; ispecies++){
597 if (!opt.Contains(
"Q"))
598 printf(
"estimated #of events in species %d = %f\n", ispecies,
fNumbersOfEvents[ispecies]);
600 if (!opt.Contains(
"Q"))
602 Double_t *covmat = minuit->GetCovarianceMatrix();
605 if (opt.Contains(
"W")){
606 Double_t *sumweight =
new Double_t[
fNSpecies];
610 sumweight[i]+=
fSWeights(j, (iplot+1)*fNSpecies + i);
611 printf(
"checking sum of weights[%d]=%f\n", i, sumweight[i]);
624 Int_t i, ispecies, k;
625 Double_t numerator, denominator;
628 for (ispecies=0; ispecies<
fNSpecies; ispecies++)
630 for (ispecies=0; ispecies<
fNSpecies; ispecies++){
633 numerator+=covmat[ispecies*fNSpecies+k]*
fPdfTot(i, k);
634 fSWeights(i, (i_excl+1)*fNSpecies + ispecies)=numerator/denominator;
670 if (((TH1D*)
fXvarHists.First())->GetNbinsX()!=nbins)
678 for (i=0; i<
fNx; i++){
679 snprintf(name,
sizeof(name),
"x%d", i);
680 TH1D *h =
new TH1D(name, name, nbins,
fMinmax(0, i),
fMinmax(1, i));
682 h->Fill(
fXvar(j, i));
698 else if (((TH1D*)
fXvarHists.First())->GetNbinsX()!=nbins)
713 else if (((TH1D*)
fXvarHists.First())->GetNbinsX()!=nbins)
727 if (((TH1D*)
fYvarHists.First())->GetNbinsX()!=nbins)
735 for (i=0; i<
fNy; i++){
736 snprintf(name,
sizeof(name),
"y%d", i);
739 h->Fill(
fYvar(j, i));
753 else if (((TH1D*)
fYvarHists.First())->GetNbinsX()!=nbins)
767 else if (((TH1D*)
fYvarHists.First())->GetNbinsX()!=nbins)
777 Int_t i, j, ispecies;
780 if (((TH1D*)
fYpdfHists.First())->GetNbinsX()!=nbins)
787 for (ispecies=0; ispecies<
fNSpecies; ispecies++){
788 for (i=0; i<
fNy; i++){
789 snprintf(name,
sizeof(name),
"pdf_species%d_y%d", ispecies, i);
791 TH1D *h =
new TH1D(name, name, nbins,
fMinmax(0,
fNx+fNy+ispecies*fNy+i),
fMinmax(1,
fNx+fNy+ispecies*fNy+i));
793 h->Fill(
fYpdf(j, ispecies*fNy+i));
836 Error(
"GetSWeightsHists",
"SWeights were not computed");
850 for (Int_t ivar=0; ivar<
fNx; ivar++){
851 for (Int_t ispecies=0; ispecies<
fNSpecies; ispecies++){
852 snprintf(name,30,
"x%d_species%d", ivar, ispecies);
853 TH1D *h =
new TH1D(name, name, nbins,
fMinmax(0, ivar),
fMinmax(1, ivar));
855 for (Int_t ievent=0; ievent<
fNevents; ievent++)
862 for (Int_t iexcl=0; iexcl<
fNy; iexcl++){
863 for(Int_t ispecies=0; ispecies<
fNSpecies; ispecies++){
864 snprintf(name,30,
"y%d_species%d", iexcl, ispecies);
865 TH1D *h =
new TH1D(name, name, nbins,
fMinmax(0, fNx+iexcl),
fMinmax(1, fNx+iexcl));
867 for (Int_t ievent=0; ievent<
fNevents; ievent++)
868 h->Fill(
fYvar(ievent, iexcl),
fSWeights(ievent, fNSpecies*(iexcl+1)+ispecies));
899 void TSPlot::RefillHist(Int_t type, Int_t nvar, Int_t nbins, Double_t min, Double_t max, Int_t nspecies)
901 if (type<1 || type>5){
902 Error(
"RefillHist",
"type must lie between 1 and 5");
911 snprintf(name,20,
"x%d",nvar);
912 TH1D *h =
new TH1D(name, name, nbins, min, max);
914 h->Fill(
fXvar(j, nvar));
920 snprintf(name,20,
"y%d", nvar);
921 TH1D *h =
new TH1D(name, name, nbins, min, max);
923 h->Fill(
fYvar(j, nvar));
929 snprintf(name,20,
"pdf_species%d_y%d", nspecies, nvar);
930 TH1D *h=
new TH1D(name, name, nbins, min, max);
932 h->Fill(
fYpdf(j, nspecies*
fNy+nvar));
938 snprintf(name,20,
"x%d_species%d", nvar, nspecies);
939 TH1D *h =
new TH1D(name, name, nbins, min, max);
941 for (Int_t ievent=0; ievent<
fNevents; ievent++)
948 snprintf(name,20,
"y%d_species%d", nvar, nspecies);
949 TH1D *h =
new TH1D(name, name, nbins, min, max);
951 for (Int_t ievent=0; ievent<
fNevents; ievent++)
1003 std::vector<TString> cnames;
1004 TList *formulaList =
new TList();
1005 TSelectorDraw *selector = (TSelectorDraw*)(((TTreePlayer*)
fTree->GetPlayer())->GetSelector());
1007 Long64_t entry, entryNumber;
1010 TObjArray *leaves =
fTree->GetListOfLeaves();
1014 fVarexp =
new TString(varexp);
1018 nch = varexp ? strlen(varexp) : 0;
1022 TTreeFormula *select = 0;
1023 if (selection && strlen(selection)) {
1024 select =
new TTreeFormula(
"Selection",selection,
fTree);
1025 if (!select)
return;
1026 if (!select->GetNdim()) {
delete select;
return; }
1027 formulaList->Add(select);
1033 for (i=0;i<ncols;i++) {
1034 cnames.push_back( leaves->At(i)->GetName() );
1038 ncols = selector->SplitNames(varexp,cnames);
1040 var =
new TTreeFormula* [ncols];
1041 Double_t *xvars =
new Double_t[ncols];
1044 for (i=0; i<ncols; i++){
1050 for (i=0;i<ncols;i++) {
1051 var[i] =
new TTreeFormula(
"Var1",cnames[i].Data(),
fTree);
1052 formulaList->Add(var[i]);
1056 TTreeFormulaManager *manager=0;
1057 if (formulaList->LastIndex()>=0) {
1058 manager =
new TTreeFormulaManager;
1059 for(i=0;i<=formulaList->LastIndex();i++) {
1060 manager->Add((TTreeFormula*)formulaList->At(i));
1067 Long64_t selectedrows=0;
1068 for (entry=firstentry;entry<firstentry+
fNevents;entry++) {
1069 entryNumber =
fTree->GetEntryNumber(entry);
1070 if (entryNumber < 0)
break;
1071 Long64_t localEntry =
fTree->LoadTree(entryNumber);
1072 if (localEntry < 0)
break;
1073 if (tnumber !=
fTree->GetTreeNumber()) {
1074 tnumber =
fTree->GetTreeNumber();
1075 if (manager) manager->UpdateFormulaLeaves();
1078 if (manager && manager->GetMultiplicity()) {
1079 ndata = manager->GetNdata();
1082 for(Int_t inst=0;inst<ndata;inst++) {
1083 Bool_t loaded = kFALSE;
1085 if (select->EvalInstance(inst) == 0) {
1090 if (inst==0) loaded = kTRUE;
1094 for (i=0;i<ncols;i++) {
1095 var[i]->EvalInstance(0);
1100 for (i=0;i<ncols;i++) {
1101 xvars[i] = var[i]->EvalInstance(inst);
1109 for (i=0; i<
fNx; i++){
1110 fXvar(selectedrows, i) = xvars[i];
1116 for (i=0; i<
fNy; i++){
1117 fYvar(selectedrows, i) = xvars[i+
fNx];
1124 fYpdf(selectedrows, j*fNy + i)=xvars[j*fNy + i+fNx+
fNy];
1125 if (
fYpdf(selectedrows, j*fNy+i) <
fMinmax(0, j*fNy+i+fNx+fNy))
1126 fMinmax(0, j*fNy+i+fNx+fNy) =
fYpdf(selectedrows, j*fNy+i);
1127 if (
fYpdf(selectedrows, j*fNy+i) >
fMinmax(1, j*fNy+i+fNx+fNy))
1128 fMinmax(1, j*fNy+i+fNx+fNy) =
fYpdf(selectedrows, j*fNy+i);
1134 fNevents=selectedrows;
1151 void Yields(Int_t &, Double_t *, Double_t &f, Double_t *
x, Int_t )
1156 TVirtualFitter *fitter = TVirtualFitter::GetFitter();
1161 for (i=0; i<nev; i++){
1163 for (ispecies=0; ispecies<nes; ispecies++)
1164 lik+=x[ispecies]*(*pdftot)(i, ispecies);
1170 for (i=0; i<nes; i++)
void SPlots(Double_t *covmat, Int_t i_excl)
Computes the sWeights from the covariance matrix.
TH1D * GetYpdfHist(Int_t iyvar, Int_t ispecies)
Returns the histogram of the pdf of variable #iyvar for species #ispecies, binning nbins If histogram...
void Yields(Int_t &, Double_t *, Double_t &f, Double_t *x, Int_t iflag)
FCN-function for Minuit.
void SetInitialNumbersOfSpecies(Int_t *numbers)
Set the initial number of events of each species - used as initial estimates in minuit.
void MakeSPlot(Option_t *option="v")
Calculates the sWeights The option controls the print level "Q" - no print out "V" - prints the estim...
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Int_t GetNoElements() const
void FillYvarHists(Int_t nbins=100)
Fill the histograms of y variables.
virtual ~TSPlot()
destructor
void FillYpdfHists(Int_t nbins=100)
Fills the histograms of pdf-s of y variables with binning nbins.
TObjArray * GetYpdfHists()
Returns the array of histograms of pdf's of y variables with binning nbins If histograms have not alr...
void RefillHist(Int_t type, Int_t var, Int_t nbins, Double_t min, Double_t max, Int_t nspecies=-1)
The Fill...Hist() methods fill the histograms with the real limits on the variables This method allow...
void GetSWeights(TMatrixD &weights)
Returns the matrix of sweights.
void SetTree(TTree *tree)
Set the input Tree.
TObjArray * GetYvarHists()
Returns the array of histograms of y variables.
* x
Deprecated and error prone model selection interface.
TH1D * GetYvarHist(Int_t iyvar)
Returns the histogram of variable iyvar.If histograms have not already been filled, they are filled with default binning 100.
TSPlot()
default constructor (used by I/O only)
void Browse(TBrowser *b)
To browse the histograms.
Double_t * fNumbersOfEvents
void SetTreeSelection(const char *varexp="", const char *selection="", Long64_t firstentry=0)
Specifies the variables from the tree to be used for splot.
void FillXvarHists(Int_t nbins=100)
Fills the histograms of x variables (not weighted) with nbins.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
TObjArray * GetXvarHists()
Returns the array of histograms of x variables (not weighted) If histograms have not already been fil...
TH1D * GetXvarHist(Int_t ixvar)
Returns the histogram of variable #ixvar If histograms have not already been filled, they are filled with default binning 100.
void FillSWeightsHists(Int_t nbins=50)
The order of histograms in the array: x0_species0, x0_species1,..., x1_species0, x1_species1,..., y0_species0, y0_species1,...
TObjArray * GetSWeightsHists()
Returns an array of all histograms of variables, weighted with sWeights If histograms have not been a...
TH1D * GetSWeightsHist(Int_t ixvar, Int_t ispecies, Int_t iyexcl=-1)
Returns the histogram of a variable, weithed with sWeights If histograms have not been already filled...