Exemplo n.º 1
0
static double
cweakinv2(double slope, double shift, double vgst, double vds, double lambda, double beta, double vt, double mtr, double theta)
{
    double betam = beta / (1.0+theta*vgst);
    vgst += shift * (1 - scalef(0.5, vgst));
    double n = slope / 2.3 / 0.0256; /* Tsividis, p. 208 */
    double n1 = n + (1 - n) * scalef(0.7, vgst); /* n < n1 < 1 */
    double first = log(1 + exp(vgst / (2 * n1 * vt)));
    double second = log(1 + exp((vgst - vds * mtr * n1) / (2 * n1 * vt)));
    double cds =
        betam * n1 * 2 * vt * vt * (1 + scalef(1, vgst) * lambda * vds) *
        (first * first - second * second);
    return cds;
}
Exemplo n.º 2
0
void frame (float Vx, float Vy, float Vcx, float Vcy, float Wx, float Wy, float Wcx, float Wcy, mat &c){
	unit(c);
	mat R, t;
	///
	move(-Vcx, -Vcy, R);
	times(R, c, t);
	set(t,c);
	///
	scalef(Wx / Vx, Wy / Vy, R);
	times(R, c, t);
	set(t,c);
	///
	mirrorf( 1, 0, c);
	times(R, c, t);
	set(t,c);
	///
	move(Wcx, Wcy, R);
	times(R, c, t);
	set(t,c);
}
Exemplo n.º 3
0
int gfx_step(  uint32_t *fifo,  uint32_t jmp, int off )
{

	static bool init_particles = false;
	
	if( !init_particles )
	{
	    init_particles = true;
	    
	    for( size_t i = 0; i < INUMBER; ++i )
	    {
		dt[i] = ( rand() & 63 ) + 32;
		rnds[i][0] = 360.0f * i / (float)( INUMBER );//rnd( 0.0f, 360.0f );
		rnds[i][1] = rnd( -0.2f, +0.2f );
		rnds[i][2] = rnd( -0.8f, +0.3f );
		rnds[i][3] = rnd( 0.3f, 1.0f );
		
		
		insts[i].time 	= rand();
		insts[i].col[0] = rnd( 0.8f, 1.0f );
		insts[i].col[1] = rnd( 0.8f, 1.0f );
		insts[i].col[2] = rnd( 0.8f, 1.0f );
		insts[i].col[3] = 1.0f;				
	    }
	}
	
	
	for( size_t i = 0; i < INUMBER; ++i )
	{
	    insts[i].time += dt[i];
	    identity( insts[i].mat );
	
	    rotatef( 80.0f, 1.0f, 0.0f, 0.0f, insts[i].mat );
	    rotatef( off * 0.5f + rnds[i][0], 0.0f, 0.0f, 1.0f, insts[i].mat );
	    translatef( 1.6f, rnds[i][1], rnds[i][2], insts[i].mat );
	    scalef( rnds[i][3], insts[i].mat );
	    
	    float d = insts[i].mat[11];
	    
	    d = ( 1.0f - 0.6f * d );
	    insts[i].scale = rnds[i][3];
	    insts[i].col[0] = d;
	    insts[i].col[1] = 0.5f + d;
	    insts[i].col[2] = d;
	    
	    //translatef( 1.0f * sin( t * rnds[i][0] ), 1.0f * cos( t * rnds[i][0] ), 1.0f * sin( t * rnds[i][2] ), insts[i].mat );
	}
	
	
	
	clear_buffer_t clear;
	clear.clearR = clear.clearG = clear.clearB = clear.clearA = clear.clearD = 1;
	clear.rgba = 50 + ( 10 << 8 ) + ( 5 << 16 );
	clear.depth = 0xffff;

	static job_t job;
	
	static size_t curr = 0x0;

	job.pd.insts = (uint32_t)insts;
	job.pd.isize = INUMBER;
	job.pd.dynamic = (uint32_t)( dynamic ) + curr * 24;
	job.pd.fx = (uint32_t)fx.get_data();
	job.pd.atlas = (uint32_t)atlas.get_data();
	job.pd.asize = atlas.get_size();
	job.kick_job( );
	job.join();

	
	uint32_t *ptr = fifo;
	static float angle = 180.0f;
	ptr += setup_surfaces_with_offset( ptr, off % 3 );
	ptr += clear_buffers( &clear, ptr, Nv3D );
	
	ptr += set_mvp( ptr, angle );
	ptr += set_cnst( ptr );
	//ptr += troll_texture.set( ptr );
	//ptr += troll.set( ptr );
	
	//ptr += custom.set( ptr );
	ptr += particles.set( ptr );
	ptr += particle_texture.set( ptr );
	
	ptr += draw_primitives( 0, QUADS, curr, job.pd.quads * 4, ptr, Nv3D );
	
	curr += job.pd.quads * 4;// + 128;
	curr = ( curr + 16 ) & 2047;
	
	//printf( "%d \n", job.pd.quads );
	ptr += jump_to_address( ptr, jmp );
	return ptr - fifo;
}
Exemplo n.º 4
0
//Scale
void scalef(float s) {
    scalef(s, s, s);
}
Exemplo n.º 5
0
void buildAndFitModels(TDirectory *fout, RooWorkspace *wspace, RooRealVar &x, std::string proc="Zvv"){

   // Build and fit the model for the Zvv/Wlv background
   RooAbsPdf *pdfZvv 		   = wspace->pdf(doubleexp(wspace,x,Form("%s_control",proc.c_str())));
   RooAbsPdf *pdfZvv_mc 	   = wspace->pdf(doubleexp(wspace,x,Form("%s_control_mc",proc.c_str())));
   RooAbsPdf *pdfZvv_background_mc = wspace->pdf(doubleexp(wspace,x,Form("%s_control_bkg_mc",proc.c_str())));

   pdfZvv_mc->Print("v");
   // Fit control region MC
   std::cout << " Fit for control MC " << Form("%s_control_mc",proc.c_str())<< std::endl;
   RooFitResult *fit_res_control_mc  = pdfZvv_mc->fitTo(*(wspace->data(Form("%s_control_mc",proc.c_str()))),RooFit::Save(1),RooFit::SumW2Error(false));
   fout->cd(); fit_res_control_mc->SetName(Form("fitResult_%s_control_mc",proc.c_str())); fit_res_control_mc->Write();

   std::cout << " Fit for background MC " << Form("%s_control_bkg_mc",proc.c_str()) << std::endl;
   // Fit background MC and then fix it
   pdfZvv_background_mc->fitTo(*(wspace->data(Form("%s_control_bkg_mc",proc.c_str()))),RooFit::SumW2Error(true));
   freezeParameters(pdfZvv_background_mc->getParameters(RooArgSet(x)));
   
   // Now fit the Zvv Data 
   //RooRealVar frac_contamination_Zvv(Form("frac_contamination_%s",proc.c_str()),Form("frac_contamination_%s",proc.c_str()),0,1);
   double nbkgcont = wspace->data(Form("%s_control_bkg_mc",proc.c_str()))->sumEntries();
   double ncont    = wspace->data(Form("%s_control",proc.c_str()))->sumEntries()-nbkgcont;

   RooRealVar num_contamination_Zvv(Form("num_contamination_%s",proc.c_str()),Form("num_contamination_%s",proc.c_str()),nbkgcont,0,10E10);
   num_contamination_Zvv.setConstant();
   RooRealVar num_Zvv(Form("num_%s",proc.c_str()),Form("num_%s",proc.c_str()),ncont,0,10E10);
   num_Zvv.setConstant(true);// freeze the n_data now

   RooAddPdf modelZvv(Form("model_%s_control",proc.c_str()),Form("model_%s_control",proc.c_str()),RooArgList(*pdfZvv_background_mc,*pdfZvv),RooArgList(num_contamination_Zvv,num_Zvv));
   std::cout << " Fit for control Data " << Form("%s_control",proc.c_str()) << std::endl;
   RooFitResult *fit_res_control = modelZvv.fitTo(*(wspace->data(Form("%s_control",proc.c_str()))),RooFit::Save(1));
   fout->cd(); fit_res_control->SetName(Form("fitResult_%s_control",proc.c_str())); fit_res_control->Write();


   // Find the scale of ndata/nmc to normalize the yields
   double nmontecarlo = wspace->data(Form("%s_control_mc",proc.c_str()))->sumEntries();
   double ndata = num_Zvv.getVal();
   RooRealVar scalef(Form("scalef_%s",proc.c_str()),"scalef",ndata/nmontecarlo);
   // uncomment make this ONLY a shape correction!
   // scalef.setVal(1);
   scalef.setConstant(true);

   std::cout << proc.c_str() << " N Control Data == " << ndata       << std::endl;
   std::cout << proc.c_str() << " N Control MC   == " << nmontecarlo << std::endl;

   // Plot the fits
   TCanvas can_datafit(Form("%s_datafit",proc.c_str()),"Data Fit",800,600); 
   RooPlot *pl = x.frame();
   (wspace->data(Form("%s_control_bkg_mc",proc.c_str())))->plotOn(pl,RooFit::MarkerStyle(kOpenCircle));
   (wspace->data(Form("%s_control",proc.c_str())))->plotOn(pl);
   modelZvv.plotOn(pl);
   modelZvv.paramOn(pl);
   //pdfZvv_background_mc->plotOn(pl,RooFit::LineStyle(2));
   pl->Draw();
   fout->cd();can_datafit.Write();

   TCanvas can_mcfit(Form("%s_mcfit",proc.c_str()),"MC Fit",800,600); 
   RooPlot *plmc = x.frame();
   (wspace->data(Form("%s_control_mc",proc.c_str())))->plotOn(plmc,RooFit::MarkerColor(kBlack));
   pdfZvv_mc->plotOn(plmc,RooFit::LineStyle(1),RooFit::LineColor(2));
   pdfZvv_mc->paramOn(plmc);
   plmc->Draw();
   fout->cd();can_mcfit.Write();

   TCanvas can_mcdatafit(Form("%s_mcdatafit",proc.c_str()),"MC and Data Fits",800,600); 
   RooPlot *plmcdata = x.frame();
   pdfZvv_mc->plotOn(plmcdata,RooFit::LineColor(2),RooFit::Normalization(nmontecarlo));
   pdfZvv->plotOn(plmcdata,RooFit::Normalization(ndata));
   plmcdata->Draw();
   fout->cd();can_mcdatafit.Write();

   // Import the correction and the models 
   RooFormulaVar ratio(Form("ratio_%s",proc.c_str()),"@0*@1/@2",RooArgList(scalef,*pdfZvv,*pdfZvv_mc));
   wspace->import(ratio);
   wspace->import(num_Zvv);

   TCanvas can_ra(Form("%s_ratio",proc.c_str()),"MC Fit",800,600); 
   RooPlot *plra = x.frame();
   ratio.plotOn(plra,RooFit::LineStyle(1));
   plra->Draw();
   fout->cd();can_ra.Write();
}