void confidence_intervals_SMLE(double A, double B, int N, int n, int **freq, int npoints, int K, int NumIt, double grid[], double **F, double data[], int delta[], double **Fsmooth, double **lowbound, double **upbound, double ***f3) { int iter,i,k,below,above; double *f4,h; h= B*pow(N,-1.0/5); f4 = new double[NumIt]; below=(int)(0.025*NumIt-1); above=(int)(0.975*NumIt-1); for (i=1;i<npoints;i++) { for (k=1;k<=K;k++) { for (iter=0;iter<NumIt;iter++) f4[iter]=f3[iter][k][i-1]; qsort(f4,NumIt,sizeof(double),compare); lowbound[k][i]= Fsmooth[k][10*i]-f4[above]*sqrt(varF(N,n,freq,k,K,F,delta,A,B,data,h,grid[10*i])); upbound[k][i]= Fsmooth[k][10*i]-f4[below]*sqrt(varF(N,n,freq,k,K,F,delta,A,B,data,h,grid[10*i])); //lowbound[k][i]= Fsmooth[k][10*i]-f4[above]; //upbound[k][i]= Fsmooth[k][10*i]-f4[below]; if (i>1) { lowbound[k][i]=fmax(lowbound[k][i],lowbound[k][i-1]); upbound[k][i]=fmax(upbound[k][i],upbound[k][i-1]); } } } ofstream file_("CI_SMLE.txt"); if (file_.is_open()) { for (i=1;i<npoints;i++) { file_ << setprecision(10) << setw(20) << grid[10*i]; for (k=1;k<K+1;k++) file_ << setprecision(10) << setw(20) << fmax(0,lowbound[k][i]) << setprecision(10) << setw(20) << fmax(0,upbound[k][i]); file_ << "\n"; } file_.close(); } delete[] f4; }
expectation() : BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_INITIALIZE, _) BOOST_PP_COMMA_IF(MOCK_NUM_ARGS) i_( boost::make_shared< unlimited >() ) , file_( "unknown location" ) , line_( 0 ) {} expectation( const char* file, int line ) : BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_INITIALIZE, _) BOOST_PP_COMMA_IF(MOCK_NUM_ARGS) i_( boost::make_shared< unlimited >() ) , file_( file ) , line_( line ) {} ~expectation() { for( sequences_cit it = sequences_.begin(); it != sequences_.end(); ++it ) (*it)->remove( this ); } expectation& once() { i_ = boost::make_shared< detail::once >(); return *this; } expectation& never() { i_ = boost::make_shared< detail::never >(); return *this; } expectation& exactly( std::size_t count ) { i_ = boost::make_shared< detail::exactly >( count ); return *this; }
void memory_mapped_file::open(const wchar_t* file_name, uint64_t offset, size_t request_size) { file_handle file_(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL); uint64_t file_size = file_.get_size(); uint64_t map_size = offset + request_size; if (map_size < offset) { throw windows_exception("requested region exceeds the available address space", ERROR_INVALID_PARAMETER); } if (offset > file_size) { if(0 == request_size) { throw windows_exception("region out of range", ERROR_INVALID_PARAMETER); } } else if(0 == request_size) { #ifdef _WIN64 request_size = file_size - offset; #else uint64_t request_size2 = file_size - offset; if (request_size2 > static_cast<uint64_t>(0xFFFFFFFF)) { throw windows_exception("region size too large", ERROR_NOT_ENOUGH_MEMORY); } request_size = static_cast<size_t>(request_size2); #endif map_size = offset + request_size; } if (0 == request_size) { memory_ = nullptr; cb_ = 0; return ; } file_mapping_handle map_(file_, NULL, PAGE_READONLY, map_size, NULL); memory_ = map_.create_view(FILE_MAP_READ, offset, request_size); cb_ = request_size; }
string extension() { //file string result=file_(); //split array<string> parts=result.split("."); //no extension if(parts.count()==1) result.clear(); else result=parts.back(); return result; }
void confidence_intervals_hazard(int npoints, int K, int NumIt, double grid[], double **hazard, double **lowbound, double **upbound, double ***f3) { int iter,i,k,below,above; double *f4; f4 = new double[NumIt]; below=(int)(0.025*NumIt-1); above=(int)(0.975*NumIt-1); for (i=1;i<npoints;i++) { for (k=1;k<=K;k++) { for (iter=0;iter<NumIt;iter++) f4[iter]=f3[iter][k][i-1]; qsort(f4,NumIt,sizeof(double),compare); lowbound[k][i]= hazard[k][10*i]-f4[above]; upbound[k][i]= hazard[k][10*i]-f4[below]; } } ofstream file_("CI_hazard.txt"); if (file_.is_open()) { for (i=1;i<npoints;i++) { file_ << setprecision(10) << setw(20) << grid[10*i]; for (k=1;k<K+1;k++) file_ << setprecision(10) << setw(20) << fmax(0,lowbound[k][i]) << setprecision(10) << setw(20) << fmax(0,upbound[k][i]); file_ << "\n"; } file_.close(); } delete[] f4; }
string name() { //file string result=file_(); //split array<string> parts=result.split("."); //drop extension parts.drop(); //join string buffer=parts.join("."); if(!buffer.is_empty()) result=buffer; return result; }
void GlobalExceptionHandler::terminate() throw() { // add cerr to the log stream // and write all available information on // the exception to the log stream (potentially with an assigned file!) // and cerr std::cout << std::endl; std::cout << "---------------------------------------------------" << std::endl; std::cout << "FATAL: uncaught exception!" << std::endl; std::cout << "---------------------------------------------------" << std::endl; if ((line_() != -1) && (name_() != "unknown")) { std::cout << "last entry in the exception handler: " << std::endl; std::cout << "exception of type " << name_().c_str() << " occured in line " << line_() << ", function " << function_() << " of " << file_().c_str() << std::endl; std::cout << "error message: " << what_().c_str() << std::endl; } std::cout << "---------------------------------------------------" << std::endl; #ifndef OPENMS_WINDOWSPLATFORM // if the environment variable declared in OPENMS_CORE_DUMP_ENVNAME // is set, provoke a core dump (this is helpful to get a stack traceback) if (getenv(OPENMS_CORE_DUMP_ENVNAME) != 0) { #ifdef OPENMS_HAS_KILL std::cout << "dumping core file.... (to avoid this, unset " << OPENMS_CORE_DUMP_ENVNAME << " in your environment)" << std::endl; // provoke a core dump kill(getpid(), SIGSEGV); #endif } #endif // otherwise exit as default terminate() would: abort(); }
TCanvas* example_plot( int iPeriod, int iPos ) { // if( iPos==0 ) relPosX = 0.12; int W = 800; int H = 600; // // Simple example of macro: plot with CMS name and lumi text // (this script does not pretend to work in all configurations) // iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV) + 4*(0/1 13 TeV) // For instance: // iPeriod = 3 means: 7 TeV + 8 TeV // iPeriod = 7 means: 7 TeV + 8 TeV + 13 TeV // Initiated by: Gautier Hamel de Monchenault (Saclay) // Updated by: Dinko Ferencek (Rutgers) // int H_ref = 600; int W_ref = 800; // references for T, B, L, R float T = 0.08*H_ref; float B = 0.12*H_ref; float L = 0.12*W_ref; float R = 0.04*W_ref; TString canvName = "FigExample_"; canvName += W; canvName += "-"; canvName += H; canvName += "_"; canvName += iPeriod; if( writeExtraText ) canvName += "-prelim"; if( iPos%10==0 ) canvName += "-out"; else if( iPos%10==1 ) canvName += "-left"; else if( iPos%10==2 ) canvName += "-center"; else if( iPos%10==3 ) canvName += "-right"; TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H); canv->SetFillColor(0); canv->SetBorderMode(0); canv->SetFrameFillStyle(0); canv->SetFrameBorderMode(0); canv->SetLeftMargin( L/W ); canv->SetRightMargin( R/W ); canv->SetTopMargin( T/H ); canv->SetBottomMargin( B/H ); canv->SetTickx(0); canv->SetTicky(0); TH1* h = new TH1F("h","h",40,70,110); h->GetXaxis()->SetNdivisions(6,5,0); h->GetXaxis()->SetTitle("m_{e^{+}e^{-}} (GeV)"); h->GetYaxis()->SetNdivisions(6,5,0); h->GetYaxis()->SetTitleOffset(1); h->GetYaxis()->SetTitle("Events / 0.5 GeV"); h->SetMaximum( 260 ); if( iPos==1 ) h->SetMaximum( 300 ); h->Draw(); int histLineColor = kOrange+7; int histFillColor = kOrange-2; float markerSize = 1.0; { TLatex latex; int n_ = 2; float x1_l = 0.92; float y1_l = 0.60; float dx_l = 0.30; float dy_l = 0.18; float x0_l = x1_l-dx_l; float y0_l = y1_l-dy_l; TPad* legend = new TPad("legend_0","legend_0",x0_l,y0_l,x1_l, y1_l ); // legend->SetFillColor( kGray ); legend->Draw(); legend->cd(); float ar_l = dy_l/dx_l; float x_l[1]; float ex_l[1]; float y_l[1]; float ey_l[1]; // float gap_ = 0.09/ar_l; float gap_ = 1./(n_+1); float bwx_ = 0.12; float bwy_ = gap_/1.5; x_l[0] = 1.2*bwx_; // y_l[0] = 1-(1-0.10)/ar_l; y_l[0] = 1-gap_; ex_l[0] = 0; ey_l[0] = 0.04/ar_l; TGraph* gr_l = new TGraphErrors(1, x_l, y_l, ex_l, ey_l ); gStyle->SetEndErrorSize(0); gr_l->SetMarkerSize(0.9); gr_l->Draw("0P"); latex.SetTextFont(42); latex.SetTextAngle(0); latex.SetTextColor(kBlack); latex.SetTextSize(0.25); latex.SetTextAlign(12); TLine line_; TBox box_; float xx_ = x_l[0]; float yy_ = y_l[0]; latex.DrawLatex(xx_+1.*bwx_,yy_,"Data"); yy_ -= gap_; box_.SetLineStyle( kSolid ); box_.SetLineWidth( 1 ); // box_.SetLineColor( kBlack ); box_.SetLineColor( histLineColor ); box_.SetFillColor( histFillColor ); box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 ); box_.SetFillStyle(0); box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 ); latex.DrawLatex(xx_+1.*bwx_,yy_,"Z #rightarrow e^{+}e^{-} (MC)"); canv->cd(); } { // Observed data TFile file_("histo.root","READ"); TH1F *data = static_cast<TH1F*>(file_.Get("data")->Clone()); data->SetDirectory(0); data->SetMarkerStyle(20); data->SetMarkerSize(markerSize); TH1F *MC = static_cast<TH1F*>(file_.Get("MC")->Clone()); MC->SetDirectory(0); MC->SetLineColor(histLineColor); MC->SetFillColor(histFillColor); MC->Draw("histsame"); data->Draw("esamex0"); file_.Close(); } // writing the lumi information and the CMS "logo" CMS_lumi( canv, iPeriod, iPos ); canv->Update(); canv->RedrawAxis(); canv->GetFrame()->Draw(); canv->Print(canvName+".pdf",".pdf"); canv->Print(canvName+".png",".png"); return canv; }
vector<double> GMLReader::ReadGMLLinearRings(string filePath){ //std::ifstream file_("building.gml"); // ifstream file_("test.txt"); //or ("test.txt", std::ifstream::in); ifstream file_(filePath.c_str()); std::string line; vector<string> GroundSurface; vector<string> LinearRing; vector<double> LinearRingCoords; // Create vector to hold our coords //to find the position of the text int pos = 0; int foundStartPos=0; int foundEndPos=0; if (file_.is_open()){ while(getline(file_,line)){ GroundSurface.push_back(line); if(line.find("<bldg:GroundSurface")!= std::string::npos){ foundStartPos=pos++; // cout<<"line "<<foundStartPos<<":"<<line<<endl; } else if(line.find("</bldg:GroundSurface>")!= std::string::npos){ foundEndPos=pos; } else{ pos++; } } file_.close(); } else { std::cout<<"The file is NOT open!"; } // for(int i=foundStartPos;i<foundEndPos;i++){ //// cout<<"new file :"<<i<<LinearRing[i]<<endl; // if(GroundSurface[i].find("<gml:LinearRing")){ // if(GroundSurface[i].find("<gml:posList srsDimension=\"3\">") != std::string::npos){ // LinearRing.push_back(GroundSurface[i]); // // string buf; // Have a buffer string // stringstream ss(GroundSurface[i]); // Insert the string into a stream // // std::string delimiter1 = "srsDimension=\"3\">"; // std::string delimiter2 = "</gml:posList>"; // // SplitAndConvert conv; // // while (ss >> buf) // { // if (buf=="<gml:posList"){ //// cout<<"Ignoring the first index"<<endl; // //do nothing // } // else if (buf.find(delimiter1)!= std::string::npos){ // buf=conv.SplitStartTagAndCoord(buf,delimiter1); // LinearRingCoords.push_back(conv.StringToCoord(buf)); //// cout<<"---------the dilimiter1 is found--------------"<<endl; // } // // else if (buf.find(delimiter2)!= std::string::npos){ // buf=conv.SplitEndTagAndCoord(buf,delimiter2); // LinearRingCoords.push_back(conv.StringToCoord(buf)); //// cout<<"xxxxxxxxxxxxxxxxx the dilimiter2 is found xxxxxxxxxxxx"<<endl; // } // else { //// double coords = conv.StringToCoord(buf); // LinearRingCoords.push_back(conv.StringToCoord(buf)); //// cout<<"LinearRingCoords :"<< buf<<endl; // } // } // } // } // } // // for(unsigned int i=0;i<LinearRing.size();i++){ // cout<<"Linear Rings"<<i<<": "<<LinearRing[i]<<endl; // } return LinearRingCoords; }
void main_comp(double *A1, double *B1, int N, int n, int K, int ngrid, double data[], double data1[], int delta[], int **freq, double *grid, double **F, double **Fsmooth, double **hazard, const char *appdir) { int i,j,k,**ind,iterations,n_Iterations=1000; int *njumps; double phi,**fdens; double step,**p,**jumploc; double A,B,c,h; SampleTime *obs; delta[0]=0; data[0]=data1[0]=0; obs = new SampleTime[N]; for (i=0; i<N; i++) { obs[i].t = data[i+1]; obs[i].delta = delta[i+1]; } qsort(obs,N,sizeof(SampleTime),CompareTime); for (i=0; i<N; i++) { data[i+1]= obs[i].t ; delta[i+1] = obs[i].delta; } ind = new int *[K+2]; for (i=0;i<K+2;i++) ind[i]= new int[N+1]; for (k=1;k<=K+1;k++) F[k][0]=0; njumps = new int[K+2]; fdens= new double *[K+2]; p= new double *[K+2]; jumploc= new double *[K+2]; for (i=0;i<K+2;i++) { fdens[i]= new double[ngrid+1]; p[i]= new double[n+1]; jumploc[i]= new double[n+1]; } ICM(N,n,freq,K,ind,F,n_Iterations,&phi,&iterations); ofstream file2_("MLE.txt"); if (file2_.is_open()) { for (i=1;i<=n;i++) { if (F[K+1][i]>F[K+1][i-1]) { file2_ << setprecision(11) << setw(20) << data1[i]; for (k=1;k<=K+1;k++) file2_ << setprecision(11) << setw(20) << F[k][i]; file2_ << "\n"; } } file2_.close(); } for (k=1;k<=K+1;k++) { j=0; for (i=1;i<=n;i++) { if (F[k][i]>F[k][i-1]) { p[k][j]=F[k][i]-F[k][i-1]; jumploc[k][j]=data1[i]; j++; } } njumps[k]=j; } A=min(N,data); B=max(N,data); *A1=A; *B1=B; step=(B-A)/ngrid; c=B; for (i=0;i<=ngrid;i++) grid[i]=A+i*step; h = fmin(c*pow(N,-1.0/7),9.9); for (i=0;i<=ngrid;i++) { for (k=1;k<K+1;k++) fdens[k][i]=dens_estimate(A,B,k,njumps,jumploc,p,h,grid[i]); } h = B*pow(N,-1.0/5); for (i=0;i<=ngrid;i++) { for (k=1;k<=K;k++) Fsmooth[k][i]=bdf(A,B,k,njumps,jumploc,p,h,grid[i]); } for (i=0;i<=ngrid;i++) { for (k=1;k<=K;k++) hazard[k][i]=fdens[k][i]/(1-Fsmooth[k][i]); } ofstream file_("SMLE.txt"); if (file_.is_open()) { for (i=1;i<=ngrid;i++) { file_ << setprecision(10) << setw(20) << grid[i]; for (k=1;k<K+1;k++) file_ << setprecision(10) << setw(20) << Fsmooth[k][i]; file_ << "\n"; } file_.close(); } ofstream file1_("data.txt"); if (file1_.is_open()) { for (i=1;i<=N;i++) { file1_ << setprecision(11) << setw(20) << data[i]; file1_ << setw(10) << delta[i]; file1_ << "\n"; } file1_.close(); } ofstream file3_("hazard.txt"); if (file3_.is_open()) { for (i=1;i<=ngrid;i++) { file3_ << setprecision(10) << setw(20) << grid[i]; for (k=1;k<K+1;k++) file3_ << setprecision(10) << setw(20) << hazard[k][i]; file3_ << "\n"; } file3_.close(); } // free memory for (i = 0; i < K+2; i++) delete[] ind[i], delete[] p[i], delete[] jumploc[i], delete[] fdens[i]; delete[] ind, delete[] p, delete[] jumploc, delete[] njumps, delete[] fdens; delete[] obs; }
int main() { bool do_ratio = true; bool do_logy = true; TH1::AddDirectory(0); ModTDRStyle(); TString canvName = "FigExample"; TCanvas* canv = new TCanvas(canvName, canvName); canv->cd(); std::vector<TPad*> pads = do_ratio ? TwoPadSplit(0.29, 0.00, 0.00) : OnePad(); pads[0]->SetLogy(do_logy); // Source histograms TFile file_("histo.root", "READ"); TH1F* data = reinterpret_cast<TH1F*>(file_.Get("data")->Clone()); TH1F* MC = reinterpret_cast<TH1F*>(file_.Get("MC")->Clone()); file_.Close(); // Source binning MC->Rebin(2); data->Rebin(2); // Derived histograms TH1F* err = reinterpret_cast<TH1F*>(MC->Clone()); // Axis histogram std::vector<TH1*> h = CreateAxisHists(2, data, 70, 119.9); h[0]->Draw("axis"); if (do_ratio) { pads[1]->cd(); h[1]->Draw("axis"); SetupTwoPadSplitAsRatio(pads, "Obs/Exp", true, 0.65, 1.35); StandardAxes(h[1]->GetXaxis(), h[0]->GetYaxis(), "m_{e^{+}e^{-}}", "GeV"); } else { h[0]->GetXaxis()->SetTitleOffset(1.0); StandardAxes(h[0]->GetXaxis(), h[0]->GetYaxis(), "m_{e^{+}e^{-}}", "GeV"); } pads[0]->cd(); // Can draw main axis now int new_idx = CreateTransparentColor(12, 0.2); err->SetFillColor(new_idx); err->SetMarkerSize(0); MC->SetFillColor(kAzure + 1); MC->Draw("histsame"); err->Draw("e2same"); data->Draw("esamex0"); TH1F *ratio = reinterpret_cast<TH1F*>(MakeRatioHist(data, MC, true, false)); TH1F *ratio_err = reinterpret_cast<TH1F*>(MakeRatioHist(err, err, true, false)); if (pads[0]->GetLogy()) h[0]->SetMinimum(0.09); FixTopRange(pads[0], GetPadYMax(pads[0]), 0.15); DrawCMSLogo(pads[0], "CMS", "Preliminary", 11, 0.045, 0.035, 1.2); DrawTitle(pads[0], "19.7 fb^{-1} (8 TeV) + 4.9 fb^{-1} (7 TeV)", 3); DrawTitle(pads[0], "Z#rightarrowee", 1); if (do_ratio) { pads[1]->cd(); h[1]->Draw("axis"); ratio_err->Draw("e2same"); ratio->Draw("esamex0"); } pads[0]->cd(); // pos = 1, 2, 3 TLegend *legend = PositionedLegend(0.25, 0.18, 3, 0.03); legend->SetTextFont(42); FixBoxPadding(pads[0], legend, 0.05); legend->AddEntry(data, "Observed", "pe"); legend->AddEntry(MC, "Background", "f"); legend->AddEntry(err, "Uncertainty", "f"); legend->Draw(); canv->Update(); pads[0]->RedrawAxis(); pads[0]->GetFrame()->Draw(); if (do_ratio) { pads[1]->cd(); pads[1]->RedrawAxis(); pads[1]->GetFrame()->Draw(); } canv->Print(".pdf"); canv->Print(".png"); return 0; }
void memory_mapped_file::open(const wchar_t* file_name, uint64_t offset, size_t request_size) { file_handle file_(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL); open(file_.get(), offset, request_size); }