void ViolinClassification::normalize(vector<float> &data) { float maximum = absmax(data, 0, SAMPLESIZE); for (int i=0; i<SAMPLESIZE; i++){ data[i] /= maximum; data[i] *= 0.99; } }
inline void normalize(const Iterator& first, const Iterator& last){ // first pass to find range absmax const auto max = absmax(first,last); // detect range of zeros and empty range if(max == 0) return; // normalization factor const auto factor = 1.0 / max; // second pass to normalize the range by this factor using T = typename Iterator::value_type; std::for_each(first, last, [&](T& v){v*=factor;}); }
//************************************************************* void arrangeCanvas(TCanvas *canv,TH1F* meanplots[100],TH1F* widthplots[100],Int_t nFiles, TString LegLabels[10], bool onlyBias){ //************************************************************* TPaveText *ali = new TPaveText(0.18,0.87,0.50,0.93,"NDC"); ali->SetFillColor(10); ali->SetTextColor(1); ali->SetTextFont(42); ali->SetMargin(0.); ali->SetLineColor(10); ali->SetShadowColor(10); // pt->SetTextAlign(11); TText *alitext = ali->AddText("Alignment: PCL"); //"Preliminary 2015 - 0T collision data"); alitext->SetTextSize(0.04); TLegend *lego = new TLegend(0.18,0.80,0.78,0.92); lego-> SetNColumns(2); //TLegend *lego = new TLegend(0.18,0.77,0.50,0.86); lego->SetFillColor(10); lego->SetTextSize(0.04); lego->SetTextFont(42); lego->SetFillColor(10); lego->SetLineColor(10); lego->SetShadowColor(10); TPaveText *pt = NULL; TPaveText *pt2 = NULL; TPaveText *pt3 = NULL; if(!onlyBias){ pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC"); } else { pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC"); } pt->SetFillColor(10); pt->SetTextColor(1); pt->SetTextFont(61); // pt->SetTextAlign(11); TText *text1 = pt->AddText("CMS"); //"Preliminary 2015 - 0T collision data"); text1->SetTextSize(0.05); float extraOverCmsTextSize = 0.76; if(!onlyBias){ pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC"); } else { pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC"); } pt2->SetFillColor(10); pt2->SetTextColor(1); pt2->SetTextFont(52); pt2->SetTextAlign(22); TText *text2 = pt2->AddText("work in progress"); text2->SetTextSize(0.05*extraOverCmsTextSize); if(!onlyBias){ pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC"); } else { pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC"); } pt3->SetFillColor(10); pt3->SetTextColor(1); pt3->SetTextFont(42); // pt2->SetTextAlign(11); TText *text3 = pt3->AddText("3.8T collision data 2015"); text3->SetTextSize(0.05*extraOverCmsTextSize); canv->SetFillColor(10); if(!onlyBias) { canv->Divide(2,1); canv->cd(1)->SetBottomMargin(0.12); canv->cd(1)->SetLeftMargin(0.17); canv->cd(1)->SetRightMargin(0.02); canv->cd(1)->SetTopMargin(0.06); canv->cd(2)->SetBottomMargin(0.12); canv->cd(2)->SetLeftMargin(0.17); canv->cd(2)->SetRightMargin(0.02); canv->cd(2)->SetTopMargin(0.06); canv->cd(1); } else { canv->cd()->SetBottomMargin(0.14); canv->cd()->SetLeftMargin(0.17); canv->cd()->SetRightMargin(0.02); canv->cd()->SetTopMargin(0.06); canv->cd(); } Double_t absmin(999.); Double_t absmax(-999.); for(Int_t i=0; i<nFiles; i++){ if(meanplots[i]->GetMaximum()>absmax) absmax = meanplots[i]->GetMaximum(); if(meanplots[i]->GetMinimum()<absmin) absmin = meanplots[i]->GetMinimum(); } Double_t safeDelta=(absmax-absmin)/2.; Double_t theExtreme=std::max(absmax,TMath::Abs(absmin)); for(Int_t i=0; i<nFiles; i++){ TString myTitle = meanplots[i]->GetName(); float axmin = -999; float axmax = 999.; int ndiv = 510; if(myTitle.Contains("eta")){ axmin = -2.5; axmax = 2.5; ndiv = 505; } else if (myTitle.Contains("phi")){ axmin = -TMath::Pi(); axmax = TMath::Pi(); ndiv = 510; } else { std::cout<<"unrecongnized variable"; } meanplots[i]->GetXaxis()->SetLabelOffset(999); meanplots[i]->GetXaxis()->SetTickLength(0); // Redraw the new axis gPad->Update(); TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),gPad->GetUymin(), gPad->GetUxmax(),gPad->GetUymin(), axmin, axmax, //meanplots[i]->GetXaxis()->GetXmin(), //meanplots[i]->GetXaxis()->GetXmax(), ndiv,"SDH"); TGaxis *newaxisup = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(), gPad->GetUxmax(),gPad->GetUymax(), axmin, axmax, //meanplots[i]->GetXaxis()->GetXmin(), //meanplots[i]->GetXaxis()->GetXmax(), ndiv,"-SDH"); newaxis->SetLabelOffset(0.02); newaxis->SetLabelFont(42); newaxis->SetLabelSize(.05); newaxis->Draw(); newaxisup->SetLabelOffset(-0.02); newaxisup->SetLabelFont(42); newaxisup->SetLabelSize(0); newaxisup->Draw(); if(i==0){ //meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta/2.,absmax+safeDelta); std::cout<<"name is: "<< meanplots[i]->GetName() << " absmin:" <<absmin<<" absmax: "<<absmax<<" safeDelta: "<<safeDelta<<std::endl; TString theTitle = meanplots[i]->GetName(); if( theTitle.Contains("Norm")){ meanplots[i]->GetYaxis()->SetRangeUser(std::min(-0.48,absmin-safeDelta),std::max(0.48,absmax+safeDelta)); } else { if(!onlyBias){ meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta,absmax+safeDelta); } else { meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme-(TMath::Abs(absmin)/10.),theExtreme+(TMath::Abs(absmax/10.))); } //meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme,theExtreme); } meanplots[i]->Draw("e1"); if(onlyBias){ Int_t nbins = meanplots[i]->GetNbinsX(); Double_t lowedge = meanplots[i]->GetBinLowEdge(1); Double_t highedge = meanplots[i]->GetBinLowEdge(nbins+1); TH1F* hzero = DrawZero(meanplots[i],nbins,lowedge,highedge); hzero->Draw("PLsame"); } } else meanplots[i]->Draw("e1sames"); lego->AddEntry(meanplots[i],LegLabels[i]); } //ali->Draw(); lego->Draw(); pt->Draw("same"); pt2->Draw("same"); pt3->Draw("same"); if(!onlyBias){ canv->cd(2); Double_t absmax2(-999.); for(Int_t i=0; i<nFiles; i++){ if(widthplots[i]->GetMaximum()>absmax2) absmax2 = widthplots[i]->GetMaximum(); } Double_t safeDelta2=absmax2/3.; for(Int_t i=0; i<nFiles; i++){ TString myTitle = widthplots[i]->GetName(); float axmin = -999; float axmax = 999.; int ndiv = 510; if(myTitle.Contains("eta")){ axmin = -2.5; axmax = 2.5; ndiv = 505; } else if (myTitle.Contains("phi")){ axmin = -TMath::Pi(); axmax = TMath::Pi(); ndiv = 510; } else { std::cout<<"unrecongnized variable"; } widthplots[i]->GetXaxis()->SetLabelOffset(999); widthplots[i]->GetXaxis()->SetTickLength(0); // Redraw the new axis gPad->Update(); TGaxis *newaxis2 = new TGaxis(gPad->GetUxmin(),gPad->GetUymin(), gPad->GetUxmax(),gPad->GetUymin(), axmin, axmax, //widthplots[i]->GetXaxis()->GetXmin(), //widthplots[i]->GetXaxis()->GetXmax(), ndiv,"SDH"); newaxis2->SetLabelOffset(0.02); newaxis2->SetLabelFont(42); newaxis2->SetLabelSize(.05); newaxis2->Draw(); TGaxis *newaxis2up = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(), gPad->GetUxmax(),gPad->GetUymax(), axmin, axmax, //widthplots[i]->GetXaxis()->GetXmin(), //widthplots[i]->GetXaxis()->GetXmax(), ndiv,"-SDH"); newaxis2up->SetLabelOffset(-0.02); newaxis2up->SetLabelFont(42); newaxis2up->SetLabelSize(0.); newaxis2up->Draw(); if(i==0) widthplots[i]->Draw("e1"); else widthplots[i]->Draw("e1sames"); widthplots[i]->SetMinimum(0.5); widthplots[i]->SetMaximum(absmax2+safeDelta2); } lego->Draw(); pt->Draw("same"); pt2->Draw("same"); pt3->Draw("same"); } }
int main() { wave_object obj; wt_object wt; double *inp,*out,*diff; int N, i,J; FILE *ifp; double temp[1200]; char *name = "db4"; obj = wave_init(name);// Initialize the wavelet ifp = fopen(FILE_SIGNAL, "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = 256; inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } J = 3; wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option setWTConv(wt, "direct"); dwt(wt, inp);// Perform DWT //DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients for (i = 0; i < wt->outlength; ++i) { // printf("%g ",wt->output[i]); } idwt(wt, out);// Perform IDWT (if needed) // Test Reconstruction for (i = 0; i < wt->siglength; ++i) { diff[i] = out[i] - inp[i]; } printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value. wt_summary(wt);// Prints the full summary. wave_free(obj); wt_free(wt); free(inp); free(out); free(diff); return 0; }
int main() { wave_object obj; wt_object wt; double *inp, *out, *diff; int N, i, J; FILE *ifp; double temp[1200]; char *name = "db4"; obj = wave_init(name); wave_summary(obj); ifp = fopen("signal.txt", "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = 177; fclose(ifp); inp = (double*)malloc(sizeof(double)* N); out = (double*)malloc(sizeof(double)* N); diff = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } J = 2; wt = wt_init(obj, "modwt", N, J);// Initialize the wavelet transform object modwt(wt, inp);// Perform MODWT //MODWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients for (i = 0; i < wt->outlength; ++i) { printf("%g ",wt->output[i]); } imodwt(wt, out);// Perform ISWT (if needed) // Test Reconstruction for (i = 0; i < wt->siglength; ++i) { diff[i] = out[i] - inp[i]; } printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value. wt_summary(wt);// Prints the full summary. wave_free(obj); wt_free(wt); free(inp); free(out); free(diff); return 0; }
Vec2f Map::isHitPlayerToBlock(Object player, CONDITION player_condition){ p.po = player.pos; p.si = player.size; Vec2f sinking = Vec2f::Zero(); Vec2f a; if (player_condition == CONDITION::WHITE){ for (int y = 0; y < static_cast<int>(map_chip.size()); y++) { for (int x = 0; x < static_cast<int>(map_chip[y].size()); x++) { //当たり判定をするブロックの条件 if (map_chip[y][x]->getCondition() == CONDITION::STRIPE || map_chip[y][x]->getCondition() == CONDITION::BLACK){ a = collsion(player, map_chip[y][x]->getObject(), //上のブロックに当たり判定がなかったらの条件式 /*map_chip[y - (1 * y != 0)][x]->getCondition() != CONDITION::WHITE*/ !(map_chip[y - (1 * y != 0)][x]->getCondition() == CONDITION::STRIPE || map_chip[y - (1 * y != 0)][x]->getCondition() == CONDITION::BLACK), //下のブロックの当たり判定がなかったらの条件式 !(map_chip[y + (1 * y != (map_chip.size() - 1))][x]->getCondition() == CONDITION::STRIPE || map_chip[y + (1 * y != (map_chip.size() - 1))][x]->getCondition() == CONDITION::BLACK)); if (a.y() > 0) map_chip[y][x]->setFallFlag(1); sinking.x() = absmax(sinking.x(), a.x()); sinking.y() = absmax(sinking.y(), a.y()); } } } } if (player_condition == CONDITION::BLACK){ for (int y = 0; y < static_cast<int>(map_chip.size()); y++) { for (int x = 0; x < static_cast<int>(map_chip[y].size()); x++) { //当たり判定をするブロックの条件 if (map_chip[y][x]->getCondition() == CONDITION::STRIPE || map_chip[y][x]->getCondition() == CONDITION::WHITE){ a = collsion(player, map_chip[y][x]->getObject(), //上のブロックに当たり判定がなかったらの条件式 //map_chip[y - (1 * y != 0)][x]->getCondition() != CONDITION::BLACK !(map_chip[y - (1 * y != 0)][x]->getCondition() == CONDITION::STRIPE || map_chip[y - (1 * y != 0)][x]->getCondition() == CONDITION::WHITE) , //下のブロックの当たり判定がなかったらの条件式 !(map_chip[y + (1 * y != (map_chip.size() - 1))][x]->getCondition() == CONDITION::STRIPE || map_chip[y + (1 * y != (map_chip.size() - 1))][x]->getCondition() == CONDITION::WHITE)); if (a.y() > 0){ map_chip[y][x]->setFallFlag(1); //a += map_chip[y][x]->getVectol() * map_chip[y][x]->getFallFlag()*map_chip[y][x]->getMoveFlag(); } sinking.x() = absmax(sinking.x(), a.x()); sinking.y() = absmax(sinking.y(), a.y()); } } } } return sinking; }