lape
  LAPE e-log  ELOG logo
Message ID: 42     Entry time: Tue Mar 20 20:21:34 2012
Author: kazu 
Type: Other 
Category: General 
Subject: analise calibraçao 

 criei um algoritmo para fazer o alinhamento temporal dos sinais e também fitar a melhor função seno.

coloco alguns gráficos para corroborar a afirmação acima.

coloco também a macro. Falta ainda saber qual é o tamanho na escala de tempo.  a função ajustada é

Amp * sen(2*pi*freq*t +delta) + offset

na escala, t = 1 == 8192 TDC. dados de Amp = 400mV

Kazu. 

 

Attachment 1: AlignedSine2D.png  10 kB  | Hide | Hide all
AlignedSine2D.png
Attachment 2: AlignedSine2DZoom.png  13 kB  | Hide | Hide all
AlignedSine2DZoom.png
Attachment 3: AlignedSine2DZoom2.png  12 kB  | Hide | Hide all
AlignedSine2DZoom2.png
Attachment 4: AlignedSineProfile.png  19 kB  | Hide | Hide all
AlignedSineProfile.png
Attachment 5: AlignedSineProfileZoom.png  17 kB  | Hide | Hide all
AlignedSineProfileZoom.png
Attachment 6: readLines.C  4 kB  | Hide | Hide all
readLines(){
  ifstream inputFile("Sen_400mV.dat");
  string line;
  gStyle->SetOptStat(111111);
  gStyle->SetOptFit(111111);
  int  voltages[8292]={0}; 
  TH2F *hSineData = new TH2F("hSineData","hSineData; time; ADC Counts", 8192,-0.5*(1./8192), 1-0.5*(1./8192), 256, -127.5, 128.5);
  TProfile *hSineProf = new TProfile("hSineProf","hSineProf; time; ADC Counts", 8192,-0.5*(1./8192), 1-0.5*(1./8192), "s"); 
  TH1F *hAmp = new TH1F("hAmp","hAmp; ADC Counts",  256, -127.5, 128.5);
  TH1F *hX= new TH1F("hX","hX; time; ADC Counts",   8192, -0.5, 8191.5);
  //TH1F *hXClean= new TH1F("hXClean","hXClean; time; ADC Counts",   8192, -0.5, 8191.5);
  TH1F *hXClean= new TH1F("hXClean","hXClean; time (us); ADC Counts",   8192, -0.5*(1./8192), 1-0.5*(1./8192));
  int myline=0;
  
  TF1 *fSineWave = new TF1("fSineWave","[0]*sin([1]*2*3.14159265358979312e+00*x+[2])+[3]", 0, 8192);
  fSineWave->SetParNames("Amplitude", "Frequency", "phase","offset");
  fSineWave->SetParameters(100,2./8192.,0,50); 
  fSineWave->SetParLimits(1,0,1000000); 
  fSineWave->SetParLimits(0,0,1000000); 
  fSineWave->SetNpx(1000*1000*1000); 
  TCanvas *c1= new TCanvas();
  //fSineWave->Draw();
  TCanvas *c2= new TCanvas();
  // 8192 = 1 ns;  1 bin = 1us/8192;
  TH1F *hAmplitudes = new TH1F ("hAmplitudes", "Amplitudes; ADC Counts; Entries", 10000, 0, 200);
  TH1F *hFrequencies = new TH1F ("hFrequencies", "Frequencies; ; Entries", 10000, 0, 20);

  if (inputFile.is_open()) { 
    while (getline(inputFile,line)) {
      myline++;
      //if (myline > 1) break;
      cout << "line = " << myline << endl;
      stringstream strline; 
      strline << line;
      int firstZero = -10000;
      int firstMax = -10000;
      int max =-100000;
      int min = 100000;
      for(int column =0; column < 8192; column++ ){
        strline >> voltages[column];
        if (voltages[column] > max) max = column; 
        if (voltages[column] < min) min = column; 
        if(abs(voltages[column] - voltages[column+1]) <10) continue;
        if(abs(voltages[column] - voltages[column+2]) <10) continue;
          hX->SetBinContent(column+1, voltages[column]);
       // hX->SetBinError(column+1, 1.0/sqrt(12));
       // if (voltages[column] ==0  && firstZero <0) firstZero = column; 
       // hAmp->Fill(voltages[column]);
      }
      double voltagePeakToPeak = hX->GetMaximum()-hX->GetMinimum() ;
      cout << "voltagePeakToPeak " <<  voltagePeakToPeak << endl;
      int middleWay = (int)(voltagePeakToPeak/2); 
      for(int column =0; column < 8188; column++ ){
        if (abs(voltages[column] - middleWay) < 3  && firstZero <0 &&  (voltages[column+3] > voltages[column] ) ) firstZero = column;
      } 
     if (firstZero < 0) {
       cout << "fuck" << endl; 
       continue;
     } 
     // hX->DrawCopy();
     // hX->Fit(fSineWave);
      c1->Update();
      //for(int column =max; column >= 0; column-- ){
      for(int column =0; column < 8189; column++ ){
        //hSineData->Fill(column, voltages[column]);
        if(abs(voltages[column] - voltages[column+1]) > 10) break;
        if(abs(voltages[column] - voltages[column+2]) > 10) break;
        
        hXClean->SetBinContent(column+1, voltages[column]);
        hXClean->SetBinError(column+1, 1.0/sqrt(12));
        /*
        hSineData->Fill(column-=firstZero, voltages[column]);
        hAmp->Fill(voltages[column]);
        hSineProf->Fill(column, voltages[column]);
        */
      }
      for(int column =firstZero; column < 8189; column++ ){
        if(abs(voltages[column] - voltages[column+1]) > 10) break;
        if(abs(voltages[column] - voltages[column+2]) > 10) break;
        hSineProf->Fill((column-firstZero)/8192., voltages[column]);
        hSineData->Fill((column-firstZero)/8192., voltages[column]);
      }
      hXClean->Fit(fSineWave, "0Q");
      //hXClean->Draw("ep");
      double amplitude = fSineWave->GetParameter(0);
      double frequency = fSineWave->GetParameter(1);
      hAmplitudes->Fill(amplitude);
      hFrequencies->Fill(frequency);
      hSineProf->Fit(fSineWave);
      c2->Update();
      cout << "overall Amp " << fSineWave->GetParameter(0) << "overall Freq " << fSineWave->GetParameter(1) << endl;
      hSineData->Draw("box");
      c2->Update();
    }
  }
  //hSineData->Draw();
  inputFile.close();
}



/*
{
  ifstream xInFile(inFilename.c_str());
  if(!xInFile){
    return;
  }

  char acLine[SIZE_MAX_LINE + 1];

  while(xInFile){
    xInFile.getline(acLine, SIZE_MAX_LINE);
    if(xInFile){
      m_sStream.append(acLine); //Appending read line to string
    }
  }

  xInFile.close();

}
*/
ELOG V2.9.2-2455