95 #define BXOPE std::cout<<\
96 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"<<std::endl<<\
98 #define BXTXT(text) std::cout<<\
99 "F "<<std::setw(40)<< text <<" F"<<std::endl
100 #define BX1I(name,numb,text) std::cout<<\
101 "F "<<std::setw(10)<<name<<" = "<<std::setw(10)<<numb<<" = " <<std::setw(50)<<text<<" F"<<std::endl
102 #define BX1F(name,numb,text) std::cout<<"F "<<std::setw(10)<<name<<\
103 " = "<<std::setw(15)<<std::setprecision(8)<<numb<<" = "<<std::setw(40)<<text<<" F"<<std::endl
104 #define BX2F(name,numb,err,text) std::cout<<"F "<<std::setw(10)<<name<<\
105 " = "<<std::setw(15)<<std::setprecision(8)<<numb<<" +- "<<std::setw(15)<<std::setprecision(8)<<err<< \
106 " = "<<std::setw(25)<<text<<" F"<<std::endl
107 #define BXCLO std::cout<<\
109 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"<<std::endl
112 static const Double_t gHigh= 1.0e150;
113 static const Double_t gVlow=-1.0e150;
115 #define SW2 setprecision(7) << std::setw(12)
118 class FoamIntegrandFunction :
public TFoamIntegrand {
122 typedef Double_t (*FunctionPtr)(Int_t, Double_t*);
124 FoamIntegrandFunction(FunctionPtr func) : fFunc(func) {}
126 virtual ~FoamIntegrandFunction() {}
129 Double_t Density (Int_t nDim, Double_t * x) {
130 return fFunc(nDim,x);
144 fDim(0), fNCells(0), fRNmax(0),
145 fOptDrive(0), fChat(0), fOptRej(0),
146 fNBin(0), fNSampl(0), fEvPerBin(0),
147 fMaskDiv(0), fInhiDiv(0), fOptPRD(0), fXdivPRD(0),
148 fNoAct(0), fLastCe(0), fCells(0),
149 fMCMonit(0), fMaxWtRej(0), fCellsAct(0), fPrimAcu(0),
150 fHistEdg(0), fHistDbg(0), fHistWt(0),
151 fMCvect(0), fMCwt(0), fRvec(0),
152 fRho(0), fMethodCall(0), fPseRan(0),
153 fNCalls(0), fNEffev(0),
154 fSumWt(0), fSumWt2(0),
155 fSumOve(0), fNevGen(0),
156 fWtMax(0), fWtMin(0),
157 fPrime(0), fMCresult(0), fMCerror(0),
164 TFoam::TFoam(
const Char_t* Name) :
165 fDim(0), fNCells(0), fRNmax(0),
166 fOptDrive(0), fChat(0), fOptRej(0),
167 fNBin(0), fNSampl(0), fEvPerBin(0),
168 fMaskDiv(0), fInhiDiv(0), fOptPRD(0), fXdivPRD(0),
169 fNoAct(0), fLastCe(0), fCells(0),
170 fMCMonit(0), fMaxWtRej(0), fCellsAct(0), fPrimAcu(0),
171 fHistEdg(0), fHistDbg(0), fHistWt(0),
172 fMCvect(0), fMCwt(0), fRvec(0),
173 fRho(0), fMethodCall(0), fPseRan(0),
174 fNCalls(0), fNEffev(0),
175 fSumWt(0), fSumWt2(0),
176 fSumOve(0), fNevGen(0),
177 fWtMax(0), fWtMin(0),
178 fPrime(0), fMCresult(0), fMCerror(0),
181 if(strlen(Name) >129) {
182 Error(
"TFoam",
"Name too long %s \n",Name);
185 fDate=
" Release date: 2005.04.10";
233 for(i=0; i<fNCells; i++)
delete fCells[i];
236 if (fCellsAct)
delete fCellsAct ;
237 if (fRvec)
delete [] fRvec;
238 if (fAlpha)
delete [] fAlpha;
239 if (fMCvect)
delete [] fMCvect;
240 if (fPrimAcu)
delete [] fPrimAcu;
241 if (fMaskDiv)
delete [] fMaskDiv;
242 if (fInhiDiv)
delete [] fInhiDiv;
245 for(i=0; i<fDim; i++)
delete fXdivPRD[i];
248 if (fMCMonit)
delete fMCMonit;
249 if (fHistWt)
delete fHistWt;
261 if (fRho && dynamic_cast<FoamIntegrandFunction*>(fRho) )
delete fRho;
268 TFoam::TFoam(
const TFoam &From): TObject(From)
270 Error(
"TFoam",
"COPY CONSTRUCTOR NOT IMPLEMENTED \n");
308 void TFoam::Initialize(TRandom *PseRan, TFoamIntegrand *fun )
322 void TFoam::Initialize()
324 Bool_t addStatus = TH1::AddDirectoryStatus();
325 TH1::AddDirectory(kFALSE);
330 BXTXT(
"****************************************");
331 BXTXT(
"****** TFoam::Initialize ******");
332 BXTXT(
"****************************************");
334 BX1F(
" Version",fVersion, fDate);
335 BX1I(
" kDim",fDim,
" Dimension of the hyper-cubical space ");
336 BX1I(
" nCells",fNCells,
" Requested number of Cells (half of them active) ");
337 BX1I(
" nSampl",fNSampl,
" No of MC events in exploration of a cell ");
338 BX1I(
" nBin",fNBin,
" No of bins in histograms, MC exploration of cell ");
339 BX1I(
" EvPerBin",fEvPerBin,
" Maximum No effective_events/bin, MC exploration ");
340 BX1I(
" OptDrive",fOptDrive,
" Type of Driver =1,2 for Sigma,WtMax ");
341 BX1I(
" OptRej",fOptRej,
" MC rejection on/off for OptRej=0,1 ");
342 BX1F(
" MaxWtRej",fMaxWtRej,
" Maximum wt in rejection for wt=1 evts");
346 if(fPseRan==0) Error(
"Initialize",
"Random number generator not set \n");
347 if(fRho==0 && fMethodCall==0 ) Error(
"Initialize",
"Distribution function not set \n");
348 if(fDim==0) Error(
"Initialize",
"Zero dimension not allowed \n");
355 fRvec =
new Double_t[fRNmax];
356 if(fRvec==0) Error(
"Initialize",
"Cannot initialize buffer fRvec \n");
359 fAlpha =
new Double_t[fDim];
360 if(fAlpha==0) Error(
"Initialize",
"Cannot initialize buffer fAlpha \n" );
362 fMCvect =
new Double_t[fDim];
363 if(fMCvect==0) Error(
"Initialize",
"Cannot initialize buffer fMCvect \n" );
367 fInhiDiv =
new Int_t[fDim];
368 for(i=0; i<fDim; i++) fInhiDiv[i]=0;
372 fMaskDiv =
new Int_t[fDim];
373 for(i=0; i<fDim; i++) fMaskDiv[i]=1;
377 fXdivPRD =
new TFoamVect*[fDim];
378 for(i=0; i<fDim; i++) fXdivPRD[i]=0;
381 fHistWt =
new TH1D(
"HistWt",
"Histogram of MC weight",100,0.0, 1.5*fMaxWtRej);
382 fHistEdg =
new TObjArray(fDim);
386 hname=fName+TString(
"_HistEdge_");
388 htitle=TString(
"Edge Histogram No. ");
391 (*fHistEdg)[i] =
new TH1D(hname.Data(),htitle.Data(),fNBin,0.0, 1.0);
392 ((TH1D*)(*fHistEdg)[i])->Sumw2();
395 fHistDbg =
new TObjArray(fDim);
397 hname=fName+TString(
"_HistDebug_");
399 htitle=TString(
"Debug Histogram ");
401 (*fHistDbg)[i] =
new TH1D(hname.Data(),htitle.Data(),fNBin,0.0, 1.0);
423 fMCresult=fCells[0]->GetIntg();
424 fMCresult=fCells[0]->GetIntg();
425 fMCerror =fCells[0]->GetIntg();
426 fMCMonit =
new TFoamMaxwt(5.0,1000);
429 Double_t driver = fCells[0]->GetDriv();
431 BXTXT(
"*** TFoam::Initialize FINISHED!!! ***");
432 BX1I(
" nCalls",fNCalls,
"Total number of function calls ");
433 BX1F(
" XPrime",fPrime,
"Primary total integral ");
434 BX1F(
" XDiver",driver,
"Driver total integral ");
435 BX1F(
" mcResult",fMCresult,
"Estimate of the true MC Integral ");
438 if(fChat==2) PrintCells();
439 TH1::AddDirectory(addStatus);
446 void TFoam::InitCells()
452 for(i=0; i<fNCells; i++)
delete fCells[i];
456 fCells =
new TFoamCell*[fNCells];
457 for(i=0;i<fNCells;i++){
458 fCells[i]=
new TFoamCell(fDim);
459 fCells[i]->SetSerial(i);
461 if(fCells==0) Error(
"InitCells",
"Cannot initialize CELLS \n" );
469 for(Long_t iCell=0; iCell<=fLastCe; iCell++){
470 Explore( fCells[iCell] );
478 Int_t TFoam::CellFill(Int_t Status, TFoamCell *parent)
481 if (fLastCe==fNCells){
482 Error(
"CellFill",
"Too many cells\n");
485 if (Status==1) fNoAct++;
487 cell = fCells[fLastCe];
489 cell->Fill(Status, parent, 0, 0);
493 Double_t xInt2,xDri2;
495 xInt2 = 0.5*parent->GetIntg();
496 xDri2 = 0.5*parent->GetDriv();
497 cell->SetIntg(xInt2);
498 cell->SetDriv(xDri2);
521 void TFoam::Explore(TFoamCell *cell)
523 Double_t wt, dx, xBest=0, yBest=0;
524 Double_t intOld, driOld;
530 Double_t ceSum[5], xproj;
532 TFoamVect cellSize(fDim);
533 TFoamVect cellPosi(fDim);
535 cell->GetHcub(cellPosi,cellSize);
539 Double_t *xRand =
new Double_t[fDim];
544 dx = cell->GetVolume();
545 intOld = cell->GetIntg();
546 driOld = cell->GetDriv();
558 for(i=0;i<fDim;i++) ((TH1D *)(*fHistEdg)[i])->Reset();
563 for(iev=0;iev<fNSampl;iev++){
567 for(j=0; j<fDim; j++)
568 xRand[j]= cellPosi[j] +fAlpha[j]*(cellSize[j]);
575 for(k=0; k<fDim; k++) {
577 ((TH1D *)(*fHistEdg)[nProj])->Fill(xproj,wt);
586 if (ceSum[3]>wt) ceSum[3]=wt;
587 if (ceSum[4]<wt) ceSum[4]=wt;
589 nevEff = ceSum[1] == 0. ? 0. : ceSum[0]*ceSum[0]/ceSum[1];
590 if( nevEff >= fNBin*fEvPerBin)
break;
594 for(k=0; k<fDim;k++){
596 if( fInhiDiv[k]==1) fMaskDiv[k] =0;
600 Double_t rmin,rmax,rdiv;
602 for(k=0; k<fDim; k++) {
604 rmax= cellPosi[k] +cellSize[k];
605 if( fXdivPRD[k] != 0) {
606 Int_t n= (fXdivPRD[k])->GetDim();
608 rdiv=(*fXdivPRD[k])[j];
610 if( (rmin +1e-99 <rdiv) && (rdiv< rmax -1e-99)) {
612 xBest= (rdiv-cellPosi[k])/cellSize[k] ;
622 fNEffev += (Long_t)nevEff;
624 Double_t intTrue = ceSum[0]/(nevMC+0.000001);
630 if(kBest == -1) Varedu(ceSum,kBest,xBest,yBest);
632 intDriv =sqrt(ceSum[1]/nevMC) -intTrue;
633 intPrim =sqrt(ceSum[1]/nevMC);
636 if(kBest == -1) Carver(kBest,xBest,yBest);
637 intDriv =ceSum[4] -intTrue;
641 Error(
"Explore",
"Wrong fOptDrive = \n" );
648 cell->SetBest(kBest);
649 cell->SetXdiv(xBest);
650 cell->SetIntg(intTrue);
651 cell->SetDriv(intDriv);
652 cell->SetPrim(intPrim);
654 Double_t parIntg, parDriv;
655 for(parent = cell->GetPare(); parent!=0; parent = parent->GetPare()){
656 parIntg = parent->GetIntg();
657 parDriv = parent->GetDriv();
658 parent->SetIntg( parIntg +intTrue -intOld );
659 parent->SetDriv( parDriv +intDriv -driOld );
673 void TFoam::Varedu(Double_t ceSum[5], Int_t &kBest, Double_t &xBest, Double_t &yBest)
675 Double_t nent = ceSum[2];
676 Double_t swAll = ceSum[0];
677 Double_t sswAll = ceSum[1];
678 Double_t ssw = sqrt(sswAll)/sqrt(nent);
680 Double_t swIn,swOut,sswIn,sswOut,xLo,xUp;
684 Double_t maxGain=0.0;
686 for(Int_t kProj=0; kProj<fDim; kProj++) {
687 if( fMaskDiv[kProj]) {
689 Double_t sigmIn =0.0; Double_t sigmOut =0.0;
690 Double_t sswtBest = gHigh;
692 Double_t xMin=0.0; Double_t xMax=0.0;
694 for(Int_t jLo=1; jLo<=fNBin; jLo++) {
695 Double_t aswIn=0; Double_t asswIn=0;
696 for(Int_t jUp=jLo; jUp<=fNBin;jUp++) {
697 aswIn += ((TH1D *)(*fHistEdg)[kProj])->GetBinContent(jUp);
698 asswIn += Sqr(((TH1D *)(*fHistEdg)[kProj])->GetBinError( jUp));
702 swOut = (swAll-aswIn)/nent;
703 sswIn = sqrt(asswIn) /sqrt(nent*(xUp-xLo)) *(xUp-xLo);
704 sswOut= sqrt(sswAll-asswIn)/sqrt(nent*(1.0-xUp+xLo)) *(1.0-xUp+xLo);
705 if( (sswIn+sswOut) < sswtBest) {
706 sswtBest = sswIn+sswOut;
708 sigmIn = sswIn -swIn;
709 sigmOut = sswOut-swOut;
715 Int_t iLo = (Int_t) (fNBin*xMin);
716 Int_t iUp = (Int_t) (fNBin*xMax);
721 for(Int_t iBin=1;iBin<=fNBin;iBin++) {
722 if( ((iBin-0.5)/fNBin > xMin) && ((iBin-0.5)/fNBin < xMax) ){
723 ((TH1D *)(*fHistDbg)[kProj])->SetBinContent(iBin,sigmIn/(xMax-xMin));
725 ((TH1D *)(*fHistDbg)[kProj])->SetBinContent(iBin,sigmOut/(1-xMax+xMin));
733 if(iLo == 0) xBest=yBest;
734 if(iUp == fNBin) yBest=xBest;
740 if( (kBest >= fDim) || (kBest<0) ) Error(
"Varedu",
"Something wrong with kBest - kBest = %d dim = %d\n",kBest,fDim);
750 void TFoam::Carver(Int_t &kBest, Double_t &xBest, Double_t &yBest)
753 Double_t carve,carvTot,carvMax,carvOne,binMax,binTot;
754 Int_t jLow,jUp,iLow,iUp;
759 Double_t *bins =
new Double_t[fNBin];
760 if(bins==0) Error(
"Carver",
"Cannot initialize buffer Bins \n" );
767 for(kProj=0; kProj<fDim; kProj++)
768 if( fMaskDiv[kProj] ) {
773 for(iBin=0; iBin<fNBin;iBin++){
774 bins[iBin]= ((TH1D *)(*fHistEdg)[kProj])->GetBinContent(iBin+1);
775 binMax = TMath::Max( binMax, bins[iBin]);
783 for(iBin=0;iBin<fNBin;iBin++){
784 carvTot = carvTot + (binMax-bins[iBin]);
792 Double_t yLevel = gVlow;
793 for(iBin=0; iBin<fNBin;iBin++) {
797 for(j=iBin; j>-1; j-- ) {
798 if(theBin< bins[j])
break;
805 for(j=iBin; j<fNBin; j++) {
806 if(theBin< bins[j])
break;
812 carve = (iUp-iLow+1)*(binMax-theBin);
813 if( carve > carvOne) {
820 if( carvTot > carvMax) {
825 xBest = ((Double_t)(jLow))/fNBin;
826 yBest = ((Double_t)(jUp+1))/fNBin;
827 if(jLow == 0 ) xBest = yBest;
828 if(jUp == fNBin-1) yBest = xBest;
835 for(iBin=0; iBin<fNBin; iBin++)
836 ((TH1D *)(*fHistDbg)[kProj])->SetBinContent(iBin+1,binMax);
837 for(iBin=jLow; iBin<jUp+1; iBin++)
838 ((TH1D *)(*fHistDbg)[kProj])->SetBinContent(iBin+1,yLevel);
840 if( (kBest >= fDim) || (kBest<0) ) Error(
"Carver",
"Something wrong with kBest - kBest = %d dim = %d\n",kBest,fDim);
848 void TFoam::MakeAlpha()
854 fPseRan->RndmArray(fDim,fRvec);
855 for(k=0; k<fDim; k++) fAlpha[k] = fRvec[k];
868 while ( (fLastCe+2) < fNCells ) {
870 if( (iCell<0) || (iCell>fLastCe) ) {
871 Error(
"Grow",
"Wrong iCell \n");
874 newCell = fCells[iCell];
878 if(fLastCe>=10000) kEcho=100;
879 if( (fLastCe%kEcho)==0) {
882 std::cout<<fDim<<std::flush;
884 std::cout<<
"."<<std::flush;
885 if( (fLastCe%(100*kEcho))==0) std::cout<<
"|"<<fLastCe<<std::endl<<std::flush;
889 if( Divide( newCell )==0)
break;
892 std::cout<<std::endl<<std::flush;
901 Long_t TFoam::PeekMax()
905 Double_t drivMax, driv;
908 for(i=0; i<=fLastCe; i++) {
909 if( fCells[i]->GetStat() == 1 ) {
910 driv = TMath::Abs( fCells[i]->GetDriv());
920 std::cout <<
"STOP in TFoam::PeekMax: not found iCell=" << iCell << std::endl;
935 Int_t TFoam::Divide(TFoamCell *cell)
939 if(fLastCe+1 >= fNCells) Error(
"Divide",
"Buffer limit is reached, fLastCe=fnBuf \n");
944 kBest = cell->GetBest();
945 if( kBest<0 || kBest>=fDim ) Error(
"Divide",
"Wrong kBest \n");
951 Int_t d1 = CellFill(1, cell);
952 Int_t d2 = CellFill(1, cell);
953 cell->SetDau0((fCells[d1]));
954 cell->SetDau1((fCells[d2]));
955 Explore( (fCells[d1]) );
956 Explore( (fCells[d2]) );
968 void TFoam::MakeActiveList()
973 if(fPrimAcu != 0)
delete [] fPrimAcu;
974 if(fCellsAct != 0)
delete fCellsAct;
977 fCellsAct =
new TRefArray();
983 for(iCell=0; iCell<=fLastCe; iCell++) {
984 if (fCells[iCell]->GetStat()==1) {
985 fPrime += fCells[iCell]->GetPrim();
986 fCellsAct->Add(fCells[iCell]);
991 if(fNoAct != n) Error(
"MakeActiveList",
"Wrong fNoAct \n" );
992 if(fPrime == 0.) Error(
"MakeActiveList",
"Integrand function is zero \n" );
994 fPrimAcu =
new Double_t[fNoAct];
995 if( fCellsAct==0 || fPrimAcu==0 ) Error(
"MakeActiveList",
"Cant allocate fCellsAct or fPrimAcu \n");
998 for(iCell=0; iCell<fNoAct; iCell++) {
999 sum = sum + ( (TFoamCell *) (fCellsAct->At(iCell)) )->GetPrim()/fPrime;
1000 fPrimAcu[iCell]=sum;
1012 void TFoam::ResetPseRan(TRandom *PseRan)
1015 Info(
"ResetPseRan",
"Resetting random number generator \n");
1024 void TFoam::SetRho(TFoamIntegrand *fun)
1029 Error(
"SetRho",
"Bad function \n" );
1035 void TFoam::SetRhoInt(Double_t (*fun)(Int_t, Double_t *) )
1040 if (fRho && dynamic_cast<FoamIntegrandFunction*>(fRho) )
delete fRho;
1041 fRho=
new FoamIntegrandFunction(fun);
1043 Error(
"SetRho",
"Bad function \n" );
1055 void TFoam::ResetRho(TFoamIntegrand *fun)
1058 Info(
"ResetRho",
"!!! Resetting distribution function !!!\n");
1068 Double_t TFoam::Eval(Double_t *xRand)
1074 paramArr[0]=(Long_t)fDim;
1075 paramArr[1]=(Long_t)xRand;
1076 fMethodCall->SetParamPtrs(paramArr);
1077 fMethodCall->Execute(result);
1079 result=fRho->Density(fDim,xRand);
1090 void TFoam::GenerCel2(TFoamCell *&pCell)
1093 Double_t fhit, flo, fhi;
1096 random=fPseRan->Rndm();
1097 lo = 0; hi =fNoAct-1;
1098 flo = fPrimAcu[lo]; fhi=fPrimAcu[hi];
1100 hit = lo + (Int_t)( (hi-lo)*(random-flo)/(fhi-flo)+0.5);
1114 if (fPrimAcu[lo]>random)
1115 pCell = (TFoamCell *) fCellsAct->At(lo);
1117 pCell = (TFoamCell *) fCellsAct->At(hi);
1128 void TFoam::MakeEvent(
void)
1131 Double_t wt,dx,mcwt;
1140 TFoamVect cellPosi(fDim); TFoamVect cellSize(fDim);
1141 rCell->GetHcub(cellPosi,cellSize);
1142 for(j=0; j<fDim; j++)
1143 fMCvect[j]= cellPosi[j] +fAlpha[j]*cellSize[j];
1144 dx = rCell->GetVolume();
1147 wt=dx*Eval(fMCvect);
1149 mcwt = wt / rCell->GetPrim();
1154 fSumWt2 += mcwt*mcwt;
1156 fWtMax = TMath::Max(fWtMax, mcwt);
1157 fWtMin = TMath::Min(fWtMin, mcwt);
1158 fMCMonit->Fill(mcwt);
1159 fHistWt->Fill(mcwt,1.0);
1163 random=fPseRan->Rndm();
1164 if( fMaxWtRej*random > fMCwt)
goto ee0;
1165 if( fMCwt<fMaxWtRej ) {
1168 fMCwt = fMCwt/fMaxWtRej;
1169 fSumOve += fMCwt-fMaxWtRej;
1178 void TFoam::GetMCvect(Double_t *MCvect)
1180 for ( Int_t k=0 ; k<fDim ; k++) *(MCvect +k) = fMCvect[k];
1186 Double_t TFoam::GetMCwt(
void)
1193 void TFoam::GetMCwt(Double_t &mcwt)
1201 Double_t TFoam::MCgenerate(Double_t *MCvect)
1213 void TFoam::GetIntegMC(Double_t &mcResult, Double_t &mcError)
1219 mcResult = fPrime*fSumWt/fNevGen;
1220 mCerelat = sqrt( fSumWt2/(fSumWt*fSumWt) - 1/fNevGen);
1222 mcError = mcResult *mCerelat;
1232 void TFoam::GetIntNorm(Double_t& IntNorm, Double_t& Errel )
1235 Double_t intMC,errMC;
1236 GetIntegMC(intMC,errMC);
1249 void TFoam::GetWtParams(Double_t eps, Double_t &aveWt, Double_t &wtMax, Double_t &sigma)
1251 Double_t mCeff, wtLim;
1252 fMCMonit->GetMCeff(eps, mCeff, wtLim);
1254 aveWt = fSumWt/fNevGen;
1255 sigma = sqrt( fSumWt2/fNevGen -aveWt*aveWt );
1262 void TFoam::Finalize(Double_t& IntNorm, Double_t& Errel)
1264 GetIntNorm(IntNorm,Errel);
1265 Double_t mcResult,mcError;
1266 GetIntegMC(mcResult,mcError);
1267 Double_t mCerelat= mcError/mcResult;
1270 Double_t eps = 0.0005;
1271 Double_t mCeff, mcEf2, wtMax, aveWt, sigma;
1272 GetWtParams(eps, aveWt, wtMax, sigma);
1274 if(wtMax>0.0) mCeff=aveWt/wtMax;
1275 mcEf2 = sigma/aveWt;
1276 Double_t driver = fCells[0]->GetDriv();
1279 BXTXT(
"****************************************");
1280 BXTXT(
"****** TFoam::Finalize ******");
1281 BXTXT(
"****************************************");
1282 BX1I(
" NevGen",fNevGen,
"Number of generated events in the MC generation ");
1283 BX1I(
" nCalls",fNCalls,
"Total number of function calls ");
1284 BXTXT(
"----------------------------------------");
1285 BX1F(
" AveWt",aveWt,
"Average MC weight ");
1286 BX1F(
" WtMin",fWtMin,
"Minimum MC weight (absolute) ");
1287 BX1F(
" WtMax",fWtMax,
"Maximum MC weight (absolute) ");
1288 BXTXT(
"----------------------------------------");
1289 BX1F(
" XPrime",fPrime,
"Primary total integral, R_prime ");
1290 BX1F(
" XDiver",driver,
"Driver total integral, R_loss ");
1291 BXTXT(
"----------------------------------------");
1292 BX2F(
" IntMC", mcResult, mcError,
"Result of the MC Integral");
1293 BX1F(
" mCerelat", mCerelat,
"Relative error of the MC integral ");
1294 BX1F(
" <w>/WtMax",mCeff,
"MC efficiency, acceptance rate");
1295 BX1F(
" Sigma/<w>",mcEf2,
"MC efficiency, variance/ave_wt");
1296 BX1F(
" WtMax",wtMax,
"WtMax(esp= 0.0005) ");
1297 BX1F(
" Sigma",sigma,
"variance of MC weight ");
1299 Double_t avOve=fSumOve/fSumWt;
1300 BX1F(
"<OveW>/<W>",avOve,
"Contrib. of events wt>MaxWtRej");
1314 void TFoam::SetInhiDiv(Int_t iDim, Int_t InhiDiv)
1318 if(fDim==0) Error(
"TFoam",
"SetInhiDiv: fDim=0 \n");
1320 fInhiDiv =
new Int_t[ fDim ];
1321 for(Int_t i=0; i<fDim; i++) fInhiDiv[i]=0;
1324 if( ( 0<=iDim) && (iDim<fDim)) {
1325 fInhiDiv[iDim] = InhiDiv;
1327 Error(
"SetInhiDiv:",
"Wrong iDim \n");
1344 void TFoam::SetXdivPRD(Int_t iDim, Int_t len, Double_t xDiv[])
1348 if(fDim<=0) Error(
"SetXdivPRD",
"fDim=0 \n");
1349 if( len<1 ) Error(
"SetXdivPRD",
"len<1 \n");
1352 fXdivPRD =
new TFoamVect*[fDim];
1353 for(i=0; i<fDim; i++) fXdivPRD[i]=0;
1356 if( ( 0<=iDim) && (iDim<fDim)) {
1358 if( fXdivPRD[iDim] != 0)
1359 Error(
"SetXdivPRD",
"Second allocation of XdivPRD not allowed \n");
1360 fXdivPRD[iDim] =
new TFoamVect(len);
1361 for(i=0; i<len; i++) {
1362 (*fXdivPRD[iDim])[i]=xDiv[i];
1365 Error(
"SetXdivPRD",
"Wrong iDim \n");
1368 std::cout<<
" SetXdivPRD, idim= "<<iDim<<
" len= "<<len<<
" "<<std::endl;
1369 for(i=0; i<len; i++) {
1370 if (iDim < fDim) std::cout<< (*fXdivPRD[iDim])[i] <<
" ";
1372 std::cout<<std::endl;
1373 for(i=0; i<len; i++) std::cout<< xDiv[i] <<
" ";
1374 std::cout<<std::endl;
1384 void TFoam::CheckAll(Int_t level)
1386 Int_t errors, warnings;
1390 errors = 0; warnings = 0;
1391 if (level==1) std::cout <<
"///////////////////////////// FOAM_Checks /////////////////////////////////" << std::endl;
1392 for(iCell=1; iCell<=fLastCe; iCell++) {
1393 cell = fCells[iCell];
1395 if( ((cell->GetDau0()==0) && (cell->GetDau1()!=0) ) ||
1396 ((cell->GetDau1()==0) && (cell->GetDau0()!=0) ) ) {
1398 if (level==1) Error(
"CheckAll",
"ERROR: Cell's no %ld has only one daughter \n",iCell);
1400 if( (cell->GetDau0()==0) && (cell->GetDau1()==0) && (cell->GetStat()==0) ) {
1402 if (level==1) Error(
"CheckAll",
"ERROR: Cell's no %ld has no daughter and is inactive \n",iCell);
1404 if( (cell->GetDau0()!=0) && (cell->GetDau1()!=0) && (cell->GetStat()==1) ) {
1406 if (level==1) Error(
"CheckAll",
"ERROR: Cell's no %ld has two daughters and is active \n",iCell);
1410 if( (cell->GetPare())!=fCells[0] ) {
1411 if ( (cell != cell->GetPare()->GetDau0()) && (cell != cell->GetPare()->GetDau1()) ) {
1413 if (level==1) Error(
"CheckAll",
"ERROR: Cell's no %ld parent not pointing to this cell\n ",iCell);
1418 if(cell->GetDau0()!=0) {
1419 if(cell != (cell->GetDau0())->GetPare()) {
1421 if (level==1) Error(
"CheckAll",
"ERROR: Cell's no %ld daughter 0 not pointing to this cell \n",iCell);
1424 if(cell->GetDau1()!=0) {
1425 if(cell != (cell->GetDau1())->GetPare()) {
1427 if (level==1) Error(
"CheckAll",
"ERROR: Cell's no %ld daughter 1 not pointing to this cell \n",iCell);
1433 for(iCell=0; iCell<=fLastCe; iCell++) {
1434 cell = fCells[iCell];
1435 if( (cell->GetStat()==1) && (cell->GetDriv()==0) ) {
1437 if(level==1) Warning(
"CheckAll",
"Warning: Cell no. %ld is active but empty \n", iCell);
1442 Info(
"CheckAll",
"Check has found %d errors and %d warnings \n",errors, warnings);
1445 Info(
"CheckAll",
"Check - found total %d errors \n",errors);
1452 void TFoam::PrintCells(
void)
1456 for(iCell=0; iCell<=fLastCe; iCell++) {
1457 std::cout<<
"Cell["<<iCell<<
"]={ ";
1459 std::cout<<std::endl;
1460 fCells[iCell]->Print(
"1");
1461 std::cout<<
"}"<<std::endl;
1469 void TFoam::RootPlot2dim(Char_t *filename)
1471 std::ofstream outfile(filename, std::ios::out);
1472 Double_t x1,y1,x2,y2,x,y;
1475 Double_t lpag =1-2*offs;
1476 outfile<<
"{" << std::endl;
1477 outfile<<
"cMap = new TCanvas(\"Map1\",\" Cell Map \",600,600);"<<std::endl;
1479 outfile<<
"TBox*a=new TBox();"<<std::endl;
1480 outfile<<
"a->SetFillStyle(0);"<<std::endl;
1481 outfile<<
"a->SetLineWidth(4);"<<std::endl;
1482 outfile<<
"a->SetLineColor(2);"<<std::endl;
1483 outfile<<
"a->DrawBox("<<offs<<
","<<offs<<
","<<(offs+lpag)<<
","<<(offs+lpag)<<
");"<<std::endl;
1485 outfile<<
"TText*t=new TText();"<<std::endl;
1486 outfile<<
"t->SetTextColor(4);"<<std::endl;
1488 outfile<<
"t->SetTextSize(0.025);"<<std::endl;
1489 else if(fLastCe<251)
1490 outfile<<
"t->SetTextSize(0.015);"<<std::endl;
1492 outfile<<
"t->SetTextSize(0.008);"<<std::endl;
1494 outfile<<
"TBox*b=new TBox();"<<std::endl;
1495 outfile <<
"b->SetFillStyle(0);"<<std::endl;
1497 if(fDim==2 && fLastCe<=2000) {
1498 TFoamVect cellPosi(fDim); TFoamVect cellSize(fDim);
1499 outfile <<
"// =========== Rectangular cells ==========="<< std::endl;
1500 for(iCell=1; iCell<=fLastCe; iCell++) {
1501 if( fCells[iCell]->GetStat() == 1) {
1502 fCells[iCell]->GetHcub(cellPosi,cellSize);
1503 x1 = offs+lpag*( cellPosi[0]); y1 = offs+lpag*( cellPosi[1]);
1504 x2 = offs+lpag*(cellPosi[0]+cellSize[0]); y2 = offs+lpag*(cellPosi[1]+cellSize[1]);
1507 outfile<<
"b->DrawBox("<<x1<<
","<<y1<<
","<<x2<<
","<<y2<<
");"<<std::endl;
1510 x = offs+lpag*(cellPosi[0]+0.5*cellSize[0]); y = offs+lpag*(cellPosi[1]+0.5*cellSize[1]);
1511 outfile<<
"t->DrawText("<<x<<
","<<y<<
","<<
"\""<<iCell<<
"\""<<
");"<<std::endl;
1515 outfile<<
"// ============== End Rectangles ==========="<< std::endl;
1519 outfile <<
"}" << std::endl;
1523 void TFoam::LinkCells()
1527 Info(
"LinkCells",
"VOID function for backward compatibility \n");