コード例 #1
0
ファイル: LMert.cpp プロジェクト: Libardo1/ucam-smt
void MertEnvelope::SweepLine() {
  SortLines();
  int j = 0;
  for (std::vector<MertLine>::size_type i = 0; i < lines.size(); i++) {
    MertLine l = lines[i];
    l.x = -std::numeric_limits<double>::infinity();
    if (0 < j) {
      if (lines[j - 1].m == l.m) {
        if (l.y <= lines[j - 1].y)
          continue;
        --j;
      }
      while (0 < j) {
        l.x = (l.y - lines[j - 1].y) / (lines[j - 1].m - l.m);
        if (lines[j - 1].x < l.x)
          break;
        --j;
      }
      if (0 == j)
        l.x = -std::numeric_limits<double>::infinity();
      lines[j++] = l;
    } else {
      lines[j++] = l;
    }
  }
  lines.resize (j);
}
コード例 #2
0
void SortFile(FULL_CHAR *infile, FULL_CHAR *outfile)
{
    LINE *lines;
    int lines_len;
    FILE *in_fp, *out_fp;
    debug2(DEX, D, "SortFile(%s, %s)", infile, outfile);

    /* open input file */
    in_fp = fopen( (char *) infile, READ_BINARY);
    if( in_fp == (FILE *) NULL )
        Error(45, 5, "cannot open index file %s for reading",
              FATAL, no_fpos, outfile);

    /* open output file */
    out_fp = fopen( (char *) outfile, WRITE_BINARY);
    if( out_fp == (FILE *) NULL )
        Error(45, 6, "cannot open index file %s for writing",
              FATAL, no_fpos, outfile);

    /* read lines, sort them, and write them out again sorted */
    lines = ReadLines(in_fp, infile, (FULL_CHAR *) NULL, &lines_len);
    SortLines(lines, lines_len);
    fclose(in_fp);
    WriteLines(out_fp, lines, lines_len);
    fclose(out_fp);
}
コード例 #3
0
ファイル: KVZALineFinder.cpp プロジェクト: pwigg/kaliveda
//________________________________________________________________
void KVZALineFinder::FindALine(Int_t zz, Int_t width)
{
    fLinearHisto->SetAxisRange(zz-0.5,zz+0.5,"Y");

    KVIDLine* line = (KVIDLine*)fGrid->GetIdentifier(zz,2*zz+1); // A=2*zz+1 : dummy, A is ignored in this case
    if(!line)
    {
        int i=1;
        while(!(line = (KVIDLine*)fGrid->GetIdentifier(zz+i,2*zz+1))) i++;
    }
    if(!line) return;

    Double_t lX, lY;
    line->GetStartPoint(lX,lY);
    Int_t xbmin = 0;//fLinearHisto->GetYaxis()->FindBin(lX);
    line->GetEndPoint(lX,lY);
    Int_t xbmax = fLinearHisto->GetXaxis()->FindBin(lX);
    
    // create lines
    TList Lines;
    KVSpiderLine* tmp = 0;

    fLinearHisto->SetAxisRange(fLinearHisto->GetXaxis()->GetBinCenter(50),lX,"X");//fLinearHisto->GetXaxis()->GetXmax(),"X");
    TH1* tmph = fLinearHisto->ProjectionX(Form("tmph%d",zz));
    Int_t startBin = (Int_t)(tmph->GetMaximumBin()*0.95);
    delete tmph;

    TH1* projey = 0;
    if(startBin)
    {
        projey = fLinearHisto->ProjectionY("ProjectionAfterLin",startBin-width*3,startBin+width*3);
        int nfound = fSpectrum.Search(projey,0.05,"goff",0.0001);
        Info("FindALine","%d peack found...",nfound);
#if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
        Double_t* xpeaks = fSpectrum.GetPositionX();
        Double_t* ypeaks = fSpectrum.GetPositionY();
#else
        Float_t* xpeaks = fSpectrum.GetPositionX();
        Float_t* ypeaks = fSpectrum.GetPositionY();
#endif
        for(int p=0;p<nfound;p++)
        {
            if(p>8) break;
            if(ypeaks[p]<10) continue;
            Double_t xline = fLinearHisto->GetXaxis()->GetBinCenter(startBin);
            Double_t yline = xpeaks[p];
            KVSpiderLine* tmp = 0;
            TIter next(&Lines);
            while((tmp=(KVSpiderLine*)next()))
            {
                Info("FindALine","line found but I don't know why...");
                if(TMath::Abs(tmp->GetY()-yline)<0.05) continue;
            }
            tmp = new KVSpiderLine(zz,-1);
            Lines.AddLast(tmp);
            tmp->AddPoint(xline,yline);
            fPoints->SetPoint(fNPoints,xline,yline);
            fNPoints++;
        }
        if(projey) delete projey;
    }
    else Error("FindALine","not starting bin indicated...");
    SortLines(&Lines);

    Int_t nLines = Lines.GetSize();
    tmp = 0;
    for(int xx=startBin-width; xx>xbmin; xx-=width)
    {
        projey = fLinearHisto->ProjectionY("ProjectionAfterLin",xx-width/2,xx+width/2);
        int nfound = fSpectrum.Search(projey,0.05,"goff",0.02);
#if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
        Double_t* xpeaks = fSpectrum.GetPositionX();
        Double_t* ypeaks = fSpectrum.GetPositionY();
#else
        Float_t* xpeaks = fSpectrum.GetPositionX();
        Float_t* ypeaks = fSpectrum.GetPositionY();
#endif
        for(int p=0;p<nfound;p++)
        {
            if(p>=nLines+1) continue;
            if(ypeaks[p]<5) continue;
            Double_t xline = fLinearHisto->GetXaxis()->GetBinCenter(xx);
            Double_t yline = xpeaks[p];
            KVSpiderLine* tmp = 0;
            TIter next(&Lines);
            while((tmp=(KVSpiderLine*)next()))
            {
                if((TMath::Abs(tmp->GetY()-yline)<0.05)) break;
            }
            if(tmp)
            {
                if((TMath::Abs(tmp->GetX()-xline)<10*width)) tmp->AddPoint(xline,yline);
            }
        }
        if(projey) delete projey;
    }

    TIter nextli(&Lines);
    while((tmp=(KVSpiderLine*)nextli()))tmp->Sort(true);

    tmp = 0;
    for(int xx=startBin+width; xx<=xbmax-width/2; xx+=width)
    {
        projey = fLinearHisto->ProjectionY("ProjectionAfterLin",xx-width/2,xx+width/2);
        int nfound = fSpectrum.Search(projey,0.05,"goff",0.02);
#if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01)
        Double_t* xpeaks = fSpectrum.GetPositionX();
        Double_t* ypeaks = fSpectrum.GetPositionY();
#else
        Float_t* xpeaks = fSpectrum.GetPositionX();
        Float_t* ypeaks = fSpectrum.GetPositionY();
#endif
        for(int p=0;p<nfound;p++)
        {
            if(p>=nLines+1) continue;
            if(ypeaks[p]<5) continue;
            Double_t xline = fLinearHisto->GetXaxis()->GetBinCenter(xx);
            Double_t yline = xpeaks[p];
            KVSpiderLine* tmp = 0;
            TIter next(&Lines);
            while((tmp=(KVSpiderLine*)next()))
            {
                if(TMath::Abs(tmp->GetY()-yline)<0.05) break;
            }
            if(tmp)
            {
                if((TMath::Abs(tmp->GetX()-xline)<10*width)) tmp->AddPoint(xline,yline);
            }
        }
        if(projey) delete projey;
    }

    fLines->AddAll(&Lines);
}