Пример #1
0
Bool_t THSEventsFit::InitialiseFit(){
  if(GetDataSet()->numEntries()<2) {cout<<" THSEventsFit::InitialiseFit() less than 2 entries in dataset!"<<endl; return kFALSE;}
  RooAbsPdf* pdf=0;
  Long64_t PdfN[GetPDFs().getSize()];
  Long64_t TotalN=0;
  for(Int_t ip=0;ip<GetPDFs().getSize();ip++){
    pdf=(RooAbsPdf*)&(GetPDFs()[ip]);
    THSEventsPDF* mpdf=0;
    cout<<" THSEventsFit::InitialiseFit(); PDFs "<<pdf->GetName()<<endl;
    if(mpdf=dynamic_cast<THSEventsPDF*>(pdf)){//Only applies to THSEventsPDF
      if(!(mpdf->GetHistPdf())){
  	cout<<"Start smeared model "<<gDirectory->GetName()<<endl;
	PdfN[ip]=mpdf->AddSmearedModel(0,GetAuxVars());
	cout<<"Stop smeared model "<<gDirectory->GetName()<<endl;
	TotalN+=PdfN[ip];
	if(PdfN[ip]<10) {
	  cout<<" THSEventsFit::InitialiseFit() no events found for "<<GetName()<<" MODEL: "<<pdf->GetName()<<" probably no events kinmatically allowed in this bin" <<endl;
	  GetPDFsp()->remove(GetPDFs()[ip]);
	  GetYieldsp()->remove(*(GetWorkSpace()->var(fYld+pdf->GetName())));
	  GetWorkSpace()->removeSet("Yields");
	  GetWorkSpace()->removeSet("PDFs");
	  GetWorkSpace()->defineSet("Yields",GetYields());
	  GetWorkSpace()->defineSet("PDFs",GetPDFs());	
	}
      }
    }
  }
  for(Int_t ip=0;ip<GetPDFs().getSize();ip++){
    if(PdfN[ip]/TotalN<fAccFrac){
      //  cout<<" THSEventsFit::InitialiseFit()  "<<GetName()<<" MODEL: "<<GetPDFs()[ip]->GetName()<<" N events below acceptance fraction so not considered significant enough background " <<PdfN[ip] <<" out of "<<TotalN<<endl;
      GetPDFsp()->remove(GetPDFs()[ip]);
      GetYieldsp()->remove(*(GetWorkSpace()->var(fYld+pdf->GetName())));
      GetWorkSpace()->removeSet("Yields");
      GetWorkSpace()->removeSet("PDFs");
      GetWorkSpace()->defineSet("Yields",GetYields());
      GetWorkSpace()->defineSet("PDFs",GetPDFs());	
      
    }
    
  }
  if(GetPDFs().getSize()) TotalPDF();
  else {
    cout<<" THSEventsFit::InitialiseFit() no model found for "<<GetName()<<" probably no events kinmatically allowed in this bin" <<endl;
    return kFALSE;
  }
  return kTRUE;
  
}
Пример #2
0
void __fastcall TMDIChild::actEditSourceExecute(TObject *Sender)
{
    if(SourceEditFrm->EditSource(GetWorkSpace(), m_WorkSpace->GetClassManager(), gBasicSrc, false))
    {
        m_SourceLoader.LoadFromStringList(SourceEditFrm->memSrcFile->Lines, m_WorkSpace->GetClassManager());
        m_ParseTree->BindClass(NULL);
        RefreshAllClassView();
        SetModify();
    }
}
Пример #3
0
void CQDM_Edit::DrawSectionPlane(bool FastMode)//draw a slice plane to reference where we're cutting
{
	Vec3D<> WS = GetWorkSpace();
	Vec3D<> v1, v2, v12, v21, ArrDir;
	CColor CutColor = CColor(0.3, 0.3, 0.5, 1.0);
	double PadOut = WS.Length()/10.0;
	double Plane;
	switch (CurSecAxis){
	case ZAXIS:
//		DrawSecZ(CurSecLayer, LAYERMAX, CurSecFromNeg, GetCurSel());
		Plane = GetXYZ(0, 0, CurSecLayer).z;
		v1 = Vec3D<>(-PadOut, -PadOut, Plane);
		v2 = Vec3D<>(WS.x+PadOut, WS.y+PadOut, Plane);
		v12 = Vec3D<>(v1.x, v2.y, v1.z);
		v21 = Vec3D<>(v2.x, v1.y, v1.z);
		ArrDir = Vec3D<>(0,0, CurSecFromNeg?-PadOut:PadOut);
	break;
	case YAXIS:
//		DrawSecY(CurSecLayer, LAYERMAX, CurSecFromNeg, GetCurSel());
		Plane = GetXYZ(0, CurSecLayer, 0).y;
		v1 = Vec3D<>(-PadOut, Plane, -PadOut);
		v2 = Vec3D<>(WS.x+PadOut, Plane, WS.z+PadOut);
		v12 = Vec3D<>(v1.x, v1.y, v2.z);
		v21 = Vec3D<>(v2.x, v1.y, v1.z);
		ArrDir = Vec3D<>(0,CurSecFromNeg?-PadOut:PadOut, 0);
	break;
	case XAXIS:
//		DrawSecX(CurSecLayer, LAYERMAX, CurSecFromNeg, GetCurSel());
		Plane = GetXYZ(CurSecLayer, 0, 0).x;
		v1 = Vec3D<>(Plane, -PadOut, -PadOut);
		v2 = Vec3D<>(Plane, WS.y+PadOut, WS.z+PadOut);
		v12 = Vec3D<>(v1.x, v1.y, v2.z);
		v21 = Vec3D<>(v1.x, v2.y, v1.z);
		ArrDir = Vec3D<>(CurSecFromNeg?-PadOut:PadOut,0,0);
	break;
	}


	CGL_Utils::DrawRectangle(v1, v2, !FastMode, 0, CColor(CutColor.r, CutColor.g, CutColor.b, 0.3));
	CGL_Utils::DrawArrow(v1, ArrDir, CutColor);
	CGL_Utils::DrawArrow(v2, ArrDir, CutColor);
	CGL_Utils::DrawArrow(v12, ArrDir, CutColor);
	CGL_Utils::DrawArrow(v21, ArrDir, CutColor);
}
Пример #4
0
THSRooFit*  THSRooFit::CreateSubFit(TNamed cut){//cut.fName=cut selectionl fcut.fTitle=name
  cout<<"CreateSubFit "<<cut.GetName()<<endl;
  //create a fit object for a subset of data either by setting cut
  //or by fTree->SetEntryList prior to calling this function 
  //It will be deleted by this object
  THSRooFit* RFa=new THSRooFit();
  fRooFits->Add(RFa);
  RFa->SetName(cut.GetName());
 if(fBinnedFit)RFa->SetBinnedFit();
  RFa->SetSingleSpecies(fSingleSp);
  RFa->SetOutDir(fOutDir);
  // RFa->SetSPlotRange(fSRange[0],fSRange[1]);
  RFa->SetInWeights(fInWeights);
  RFa->SetWeightName(fWeightName);
  RFa->LoadWorkSpace(GetWorkSpace());
  //speed up copy by turning off redundant branches
  // RFa->SetBranchStatus("*",0);
  //need iterator over fVariables and getName 
  RFa->LoadDataSet(GetTree()->CopyTree(cut.GetTitle()));//will use any EntryList
  RFa->SetDataWeight();//if defined weights use them for this dataset
  return RFa;
}
Пример #5
0
int CQDM_Edit::V2DFindVoxelUnder(Vec3D<> Coord) //returns the index of a voxel under the coordinates
{
	//Could be rewritten better!!
	Vec3D<> Bounds = GetWorkSpace();
	
	switch(CurSecAxis){ //put the "undefined" coordinate from 2d projection to something reasonable...
		case ZAXIS: Coord.z = GetXYZ(0,0,CurSecLayer).z; break;
		case YAXIS: Coord.y = GetXYZ(0,CurSecLayer,0).y; break;
		case XAXIS: Coord.x = GetXYZ(CurSecLayer,0,0).x; break;
	}

	if (Coord.x<0.0 || Coord.x > Bounds.x || Coord.y<0.0 || Coord.y > Bounds.y || Coord.z<0.0 || Coord.z > Bounds.z) return -1; //do easy check to see if we're even within the area

	int tX, tY, tZ, tInd;
	Vec3D<> tVec;
	Vec3D<> BB = Vec3D<>(Lattice.GetXDimAdj(), Lattice.GetYDimAdj(), Lattice.GetZDimAdj())*GetLatticeDim()/2;
	tX = Coord.x/Bounds.x*GetVXDim(); //approximate...
	tY = Coord.y/Bounds.y*GetVYDim();
	tZ = Coord.z/Bounds.z*GetVZDim();
	
	//estimates
	for (int i=-1; i<=1; i++){ //for +/- 1 in each direction..
		for (int j=-1; j<=1; j++){
			switch(CurSecAxis){
				case ZAXIS: tInd = GetIndex(tX+i, tY+j, CurSecLayer); break;
				case YAXIS: tInd = GetIndex(tX+i, CurSecLayer, tZ+j); break;
				case XAXIS: tInd = GetIndex(CurSecLayer, tY+i, tZ+j); break;
			}
			tVec = GetXYZ(tInd);
			if ((CurSecAxis == XAXIS || (Coord.x > tVec.x-BB.x && Coord.x < tVec.x+BB.x)) && 
				(CurSecAxis == YAXIS || (Coord.y > tVec.y-BB.y && Coord.y < tVec.y+BB.y)) &&
				(CurSecAxis == ZAXIS || (Coord.z > tVec.z-BB.z && Coord.z < tVec.z+BB.z))) 
				return tInd;
		}
	}
	return -1;
}
Пример #6
0
void THSEventsFit::RunWeights(Int_t Nbins){
  if(!fDataBins) {cout<<"Error : Need to define at least 1 bin for this class e.g. RF->LoadBinVars(\"Eg\",1,3,4);"<<endl; exit(0);}
  DefineSets();
  MakeBins();
  cout<<"THSEventsFit::RunWithBins(); number of bins "<<fDataBins->GetN()<<endl;
  TDirectory *saveDir=gDirectory;
  THSBins* savedBins=new THSBins("HSDataBins",fOutDir+"DataEntries.root");
  fTree->SetBranchStatus("*",0);
  for(Int_t i=0;i<fVariables.getSize();i++){//only copy variable branches for speed
    fTree->SetBranchStatus(fVariables[i].GetName(),1);
  }
  //but always need ID branch
  if(fTree->GetBranch(fIDBranchName)){
   fTree->SetBranchStatus(fIDBranchName,1);
  }
 
  for(Int_t i=0;i<fDataBins->GetN();i++){
    Long64_t PdfN[GetPDFs().getSize()];
    for(Int_t ipdf=0;ipdf<GetPDFs().getSize();ipdf++)  PdfN[ipdf]=0;
    Long64_t TotalN=0;
    THSsPlot* rf=static_cast<THSsPlot*>(CreateSubFitBins(savedBins->GetBinnedTree(fTree,i),kFALSE));
    //iterate over models and set their entry lists id THSEventsPdf
    RooAbsPdf* pdf=0;
    for(Int_t ip=0;ip<rf->GetPDFs().getSize();ip++){
      pdf=(RooAbsPdf*)&(rf->GetPDFs()[ip]);
      THSEventsPDF* mpdf=0;
      cout<<"THSEventsFit::RunWithBins(); PDFs "<<pdf->GetName()<<endl;
      if(mpdf=dynamic_cast<THSEventsPDF*>(pdf)){//Only applies to THSEventsPDF
	THSBins* savedMCBins=new THSBins("MCModelBins",fOutDir+TString("Bins")+mpdf->GetName()+".root");
  	mpdf->SetTree(savedMCBins->GetBinnedTree(dynamic_cast<THSEventsPDF*>(fPDFs.find(mpdf->GetName()))->GetTree(),i));
	delete savedMCBins;
       	PdfN[ip]=mpdf->AddSmearedModel(0,rf->GetAuxVars());
	cout<<"CHCK "<<PdfN[ip]<<" "<<TotalN<<endl;
	TotalN+=PdfN[ip];
	cout<<"CHCK "<<PdfN[ip]<<" "<<TotalN<<endl;
	if(PdfN[ip]<10) {
	  cout<<"THSEventsFitfrom::RunWithBins() no events found for "<<fDataBins->GetBinName(i)<<" MODEL: "<<pdf->GetName()<<" probably no events kinmatically allowed in this bin" <<endl;
	  rf->GetPDFsp()->remove(rf->GetPDFs()[ip]);
	  rf->GetYieldsp()->remove(*(rf->GetWorkSpace()->var(fYld+pdf->GetName())));
	  rf->GetWorkSpace()->removeSet("Yields");
	  rf->GetWorkSpace()->removeSet("PDFs");
	  rf->GetWorkSpace()->defineSet("Yields",rf->GetYields());
	  rf->GetWorkSpace()->defineSet("PDFs",rf->GetPDFs());
	}
      }
    }
    for(Int_t ip=0;ip<GetPDFs().getSize();ip++){
 	pdf=(RooAbsPdf*)&(rf->GetPDFs()[ip]);
	THSEventsPDF* mpdf=0;
 	if(mpdf=dynamic_cast<THSEventsPDF*>(pdf)){
	  if(Double_t(PdfN[ip])/TotalN<fAccFrac){
	    cout<<" THSEventsFit::InitialiseFit()  "<<GetName()<<" MODEL: "<<GetPDFs()[ip].GetName()<<" N events below acceptance fraction so not considered significant enough background " <<PdfN[ip] <<" out of "<<TotalN<<" "<<fAccFrac<<endl;
	    GetPDFsp()->remove(GetPDFs()[ip]);
	    GetYieldsp()->remove(*(GetWorkSpace()->var(fYld+pdf->GetName())));
	    GetWorkSpace()->removeSet("Yields");
	    GetWorkSpace()->removeSet("PDFs");
	    GetWorkSpace()->defineSet("Yields",GetYields());
	    GetWorkSpace()->defineSet("PDFs",GetPDFs());	

	  }
	}
    }
    if(rf->GetPDFs().getSize()) rf->TotalPDF();
    else {
      cout<<"THSEventsFit::RunWithBins() no model found for "<<fDataBins->GetBinName(i)<<" probably no events kinmatically allowed in this bin" <<endl;
      rf->RemoveDataSet();//save memory
      delete rf;
      continue;
    }
    cout<<fData->numEntries()<<endl;
    if(rf->GetDataSet()->numEntries()<2) {delete rf;continue;}
    rf->FitMany(Nbins);
    rf->sPlot();
    rf->SavePlots("");//save plots for each bin fit
    if(rf->GetWeights()){
      rf->GetWeights()->PrintWeight();
      AddWeightMap(rf->GetWeights());
      rf->GetWeights()->Save();
    }
    rf->RemoveDataSet();//save memory
    delete rf;
  }
  //tfile->Close();
   delete savedBins;
   //delete tfile;
  fTree->SetBranchStatus("*",1);
  cout<<"THSRooFit::RunWithBins() Done all Fits "<<endl;
  // AddSubWeights();
  if(fWeights)GetWeights()->PrintWeight();
  if(fWeights) GetWeights()->SortWeights();
}
Пример #7
0
void THSEventsFit::PrepareForFarm(){
  if(!fDataBins) {cout<<"Error : Need to define at least 1 bin for this class e.g. RF->LoadBinVars(\"Eg\",1,3,4);"<<endl; exit(0);}
  DefineSets();
  MakeBins();
  cout<<" THSEventsFit::PrepareForFarm(); number of bins "<<fDataBins->GetN()<<endl;
  TDirectory *saveDir=gDirectory;
  THSBins* savedBins=new THSBins("HSDataBins",fOutDir+"DataEntries.root");
  fTree->SetBranchStatus("*",0);
  for(Int_t i=0;i<fVariables.getSize();i++){//only copy variable branches for speed
    fTree->SetBranchStatus(fVariables[i].GetName(),1);
  }
  //but always need ID branch
  if(fTree->GetBranch(fIDBranchName)){
   fTree->SetBranchStatus(fIDBranchName,1);
  }
   for(Int_t i=0;i<fDataBins->GetN();i++){
     Long64_t PdfN[GetPDFs().getSize()];
     Long64_t TotalN=0;

    THSRooFit* rf=CreateSubFitBins(savedBins->GetBinnedTree(fTree,i),kFALSE);
    cout<<"THSEventsFit::PrepareForFarm() made data for "<<fDataBins->GetBinName(i)<<" with entries =" <<rf->GetDataSet()->numEntries()<<endl;
     //iterate over models and set their entry lists id THSEventsPdf
    RooAbsPdf* pdf=0;
    for(Int_t ip=0;ip<rf->GetPDFs().getSize();ip++){
      pdf=(RooAbsPdf*)&(rf->GetPDFs()[ip]);
      THSEventsPDF* mpdf=0;
      cout<<" THSEventsFit::PrepareForFarm(); PDFs "<<pdf->GetName()<<endl;
      if(mpdf=dynamic_cast<THSEventsPDF*>(pdf)){//Only applies to THSEventsPDF

	THSBins* savedMCBins=new THSBins("MCModelBins",fOutDir+TString("Bins")+mpdf->GetName()+".root");
	//Get tree for this bin
  	mpdf->SetTree(savedMCBins->GetBinnedTree(dynamic_cast<THSEventsPDF*>(fPDFs.find(mpdf->GetName()))->GetTree(),i));
      	PdfN[ip]=mpdf->AddSmearedModel(0,rf->GetAuxVars());
	TotalN+=PdfN[ip];
	
	if(PdfN[ip]<10) {
	  cout<<" THSEventsFit::InitialiseFit() no events found for "<<rf->GetName()<<" MODEL: "<<pdf->GetName()<<" probably no events kinmatically allowed in this bin" <<endl;
	  rf->GetPDFsp()->remove(rf->GetPDFs()[ip]);
	  rf->GetYieldsp()->remove(*(rf->GetWorkSpace()->var(fYld+pdf->GetName())));
	  rf->GetWorkSpace()->removeSet("Yields");
	  rf->GetWorkSpace()->removeSet("PDFs");
	  rf->GetWorkSpace()->defineSet("Yields",rf->GetYields());
	  rf->GetWorkSpace()->defineSet("PDFs",rf->GetPDFs());	
	}
	delete savedMCBins;
      }
    }
   for(Int_t ip=0;ip<GetPDFs().getSize();ip++){
 	pdf=(RooAbsPdf*)&(rf->GetPDFs()[ip]);
	THSEventsPDF* mpdf=0;
 	if(mpdf=dynamic_cast<THSEventsPDF*>(pdf)){
	  if(Double_t(PdfN[ip])/TotalN<fAccFrac){
	    cout<<" THSEventsFit::InitialiseFit()  "<<GetName()<<" MODEL: "<<GetPDFs()[ip].GetName()<<" N events below acceptance fraction so not considered significant enough background " <<PdfN[ip] <<" out of "<<TotalN<<" "<<fAccFrac<<endl;
	    GetPDFsp()->remove(GetPDFs()[ip]);
	    GetYieldsp()->remove(*(GetWorkSpace()->var(fYld+pdf->GetName())));
	    GetWorkSpace()->removeSet("Yields");
	    GetWorkSpace()->removeSet("PDFs");
	    GetWorkSpace()->defineSet("Yields",GetYields());
	    GetWorkSpace()->defineSet("PDFs",GetPDFs());	
	    
	  }
	}
    }
  
    //also need to import custom PDF class
   rf->GetWorkSpace()->Print();
   //rf->GetWorkSpace()->importClassCode(THSEventsPDF::Class(),kTRUE);
    rf->GetWorkSpace()->writeToFile(fOutDir+TString("Farm")+fDataBins->GetBinName(i)+".root");
    // cout <<" THSEventsFit::PrepareForFarm() Saved Workspace with "<<rf->GetDataSet()->numEntries()<<" for bin "<<fDataBins->GetBinName(i)<<endl;
    rf->RemoveDataSet();//save memory
    delete rf;
  }
  delete savedBins;

  cout<<"THSRooFit::PrepareForFarm() Done all files "<<endl;
 }
Пример #8
0
void __fastcall TMDIChild::actOutputSourceExecute(TObject *Sender)
{
    SourceEditFrm->EditSource(GetWorkSpace(), m_WorkSpace->GetClassManager(), gBasicSrc, false);
}