const kvs::TransferFunction TransferFunctionEditor::transferFunction() const { // const kvs::Real32 min_value = m_initial_transfer_function.colorMap().minValue(); // const kvs::Real32 max_value = m_initial_transfer_function.colorMap().maxValue(); kvs::TransferFunction transfer_function( this->colorMap(), this->opacityMap() ); // transfer_function.setRange( min_value, max_value ); transfer_function.setRange( m_min_value, m_max_value ); return( transfer_function ); }
double MEM::transfer_function_smear(double* x, double* par){ TFType::TFType type = static_cast<TFType::TFType>( static_cast<int>(par[2]) ); if(type==TFType::bReco || type==TFType::qReco){ double yy[1] = {x[0]}; double xx[2] = {par[0], par[1]}; int out_of_range{0}; double cutoff {6.6}; int debug {0}; return transfer_function(yy, xx, type, out_of_range, cutoff, debug); } else if(type==TFType::MET){ double yy[2] = {x[0], x[1]}; double xx[2] = {par[0], par[1]}; int out_of_range{0}; double cutoff {6.6}; int debug {0}; return transfer_function(yy, xx, type, out_of_range, cutoff, debug); } else{ /* ... */ } return 1.0; }
transfer_function get_transfer_function( const options& op ) { std::string fn = op.require_as<std::string>("function"); if ( fn == "tanh" ) { ovec2d p = op.optional_as<ovec2d>("function_args", "1,1"); return transfer_function(functions::hyperbolic_tangent(p[0],p[1])); } else if ( fn == "linear" ) { ovector<real> p = op.optional_as<ovector<real>>("function_args", "1,0"); ZI_ASSERT(p.size()&&p.size()<3); if ( p.size() == 1 ) { return transfer_function(functions::linear(p[0])); } else if ( p.size() == 2 ) { return transfer_function(functions::linear(p[0], p[1])); } } else if ( fn == "rectify_linear" ) { return transfer_function(functions::rectify_linear()); } else if ( fn == "soft_sign" ) { return transfer_function(functions::soft_sign()); } else if ( fn == "logistics" ) { return transfer_function(functions::logistics()); } else if ( fn == "forward_logistics" ) { return transfer_function(functions::forward_logistics()); } throw std::logic_error(HERE() + "unknown function: " + fn); }
///////////////////////////////// // y := observables // type := decides the TF // alpha := CL (e.g. 0.95, 0.98, ...) // obj := optionally supply the particle, needed for external TF (obj==null -> internal TF) ///////////////////////////////// pair<double, double> MEM::get_support( double* y, const TFType::TFType& type, const double& alpha, const int& debug, MEM::Object* obj ){ if( type==TFType::TFType::MET ){ if( debug&DebugVerbosity::init_more) cout << "get_support" << y[0] << " " << y[1] << " " << alpha << " " << debug << " " << obj << endl; double alpha_n = TMath::Abs(alpha); int sign = alpha>0?1:0; // the MET px and py double Px = y[0]; double Py = y[1]; // return values double xLowPhi = -TMath::Pi(); double xHighPhi = +TMath::Pi(); double phiStep = 0.04; // phi of MET vector double Phi = Py>0?TMath::ACos(Px/sqrt(Px*Px+Py*Py)):2*TMath::Pi()-TMath::ACos(Px/sqrt(Px*Px+Py*Py)); if( debug&DebugVerbosity::init_more) cout << "MET phi at " << Phi << endl; // elements of the MET cov matrix double Vx = TF_MET_param[0]*TF_MET_param[0]; double Vy = TF_MET_param[1]*TF_MET_param[1]; double rho = TF_MET_param[2]; // chi2 cut to find the CL double chi2Cut = TMath::ChisquareQuantile(alpha_n ,2); // MET TF at zero double tfAtZero = Chi2Corr(Px,Py,sqrt(Vx),sqrt(Vy),rho); // nothing to do... if( tfAtZero <= chi2Cut ){ if( debug&DebugVerbosity::init_more) cout << "(0,0) is inside the 2-sigma CL => integrate over -TMath::Pi()/+TMath::Pi()" << endl; } // search for boundaries else{ if( debug&DebugVerbosity::init_more) cout << "(0,0) is outside the 2-sigma CL => find phi-window with interpolation..." << endl; for( int dir = 0; dir < 2 ; ++dir){ if(dir!=sign) continue; if( debug&DebugVerbosity::init_more) cout << "Doing scan along " << (dir?"+":"-") << " direction" << endl; bool stopPhiScan = false; for(std::size_t step = 0; step <= (std::size_t)(TMath::Pi()/phiStep) && !stopPhiScan; ++step){ double phi = Phi + double(2.*dir-1)*phiStep*step; //if(phi<0.) phi += 2*TMath::Pi(); //else if(phi>2*TMath::Pi()) phi -= 2*TMath::Pi(); if( debug&DebugVerbosity::init_more) cout << "\tScan phi=" << phi << endl; double sin = TMath::Sin(phi); double cos = TMath::Cos(phi); bool crossing = false; //bool exceeded = false; //bool alreadyInTheBox = PxMax*PxMin<=0. && PyMax*PyMin<=0.; double p_step = 2.; for(std::size_t stepP = 0; stepP<200 && !crossing && /*!exceeded && !crossing &&*/ !stopPhiScan; ++stepP){ double Px_P = stepP*p_step*cos; double Py_P = stepP*p_step*sin; //if( alreadyInTheBox && (Px_P>PxMax || Px_P<PxMin || Py_P>PyMax || Py_P<PyMin)){ //exceeded = true; //if( debug&DebugVerbosity::init_more) cout << "\tWas in box, and got out at P=" << stepP*p_step << endl; //continue; //} //else if( !alreadyInTheBox && (Px_P>PxMax || Px_P<PxMin || Py_P>PyMax || Py_P<PyMin)){ //if( debug&DebugVerbosity::init_more) cout << "\tWas not in the box, and I am still out at P=" << stepP*5 << endl; //continue; //} if( Chi2Corr(Px_P-Px, Py_P-Py, sqrt(Vx), sqrt(Vy), rho) < chi2Cut ) { crossing = true; if( debug&DebugVerbosity::init_more) cout << "\tWas not in the box, and found crossing at (" << Px_P << "," << Py_P << ")" << endl; } } // end loop over |P| if(!crossing){ if( debug&DebugVerbosity::init_more) cout << "\tNo crossing at " << phi << " => stop phi scan" << endl; if(dir==0) xLowPhi = phi+0.5*phiStep; if(dir==1) xHighPhi = phi-0.5*phiStep; stopPhiScan = true; } } } //xLowPhi = -TMath::ACos(TMath::Cos( Phi - xLowPhi )); //xHighPhi = +TMath::ACos(TMath::Cos( Phi - xHighPhi)); xLowPhi -= Phi; xHighPhi -= Phi; } return make_pair(xLowPhi,xHighPhi); } //TFType == MET // the reconstructed values double e_rec = y[0]; double eta_rec = y[1]; // start with reconstructed value double e_L{e_rec}; double e_H{e_rec}; // granularity double step_size{2.5}; double tot{1.}; int accept{0}; double cutoff{99.}; while( tot>(1-alpha)/2 && e_L>0. ){ tot = 0.; for(size_t i = 0; i < 500.; ++i){ double gen[2] = {e_L, eta_rec}; double rec[1] = {e_rec+i*step_size}; if (obj == nullptr) { tot += transfer_function(rec,gen,type,accept,cutoff,debug)*step_size; } else { // use external TF tot += transfer_function2(obj,gen,type,accept,cutoff,false,debug)*step_size; } if( tot>(1-alpha)/2 ) break; } e_L -= step_size; } if(e_L<0.) e_L=0.; tot = 1.; while( tot>(1-alpha)/2 ){ tot = 0.; for(size_t i = 0; i < 500.; ++i){ double gen[2] = {e_H, eta_rec}; double rec[1] = {e_rec-i*step_size}; if(rec[0]<0.) continue; if (obj == nullptr) { tot += transfer_function(rec,gen,type,accept,cutoff,debug)*step_size; } else { // use external TF tot += transfer_function2(obj,gen,type,accept,cutoff,false,debug)*step_size; } if( tot>(1-alpha)/2 ) break; } e_H += step_size; } #ifdef DEBUG_MODE if( debug&DebugVerbosity::init_more) cout << "MEM::get_support: E(reco) = " << e_rec << " ==> range at " << alpha << " CL is [" << e_L << ", " << e_H << "] (stepping every " << step_size << " GeV)" << endl; #endif e_L = TMath::Max(e_L, type==TFType::bReco ? MB : MQ); return make_pair(e_L, e_H); }