Creation of a set of demo frame files

#include <time.h>
#ifndef __CINT__
#include "FrameL.h"
#include "VManagerFrameL.h"
#include "TCanvas.h"
#include "TRandom.h"
#include "VFrUtil.h"
#include "TF2.h"
#endif

void create_testfr()
{
//
// Macro for producing a few demonstration frame files containing
// five adc data. The data produced are simple gaussian noise on which
// are superimposed some simple functions.
// For example, there is, in each MYGO_ADC3 adc data, near the begining
// of the frame, a spike which is just a damped sine wave.
// This is not very likely to happen in each frame in reality but...
// it's only demonstration...
//
// The global pattern in time for frames in the files is the following
//
//      File 1   Frame1     begins at time = 600000000.097 = init time
//               Frame2      follows
//                 .            .
//                 .            .
//                 .            .
//               FrameN         .
//      File 2   Frame1         .
//               Frame2         .
//                 .            .
//                 .            .
//                 .            .
//               FrameN         .
//      File 3   Frame1         .
//               Frame2         .
//                 .            .
//                 .            .
//                 .            .
//               FrameN         .
//      ------------------------------
//                            no data, skip NFRAMES * 100
//      ------------------------------
//      File 4   Frame1     begins at time = init time + length of frame*15 + NFRAMES*100
//               Frame2      follows
//      ------------------------------
//                            no data, skip NFRAMES * 40
//      ------------------------------
//      File 5   Frame1
//               Frame2
//      File 4   Frame3
//                 .
//                 .
//                 .
//               FrameN
//      File 5   Frame3
//                 .
//                 .
//                 .
//               FrameN
//  followed by other files where the frames are in sequence
//  Note the intentional mixing of frames to allow testing
//
//  Four triggers are defined to allow thorough testing of selections
//  There is also a file containing only SMS data that is generated
//
//  A text file is generated as well, containing ascii values with a format :
//      Time1 valueA1 valueB1 valueC1
//      Time2 valueA2 valueB2 valueC2
//      Time3 valueA3 valueB3 valueC3
//  etc...

// Open a new window (canvas) and divide it
  TCanvas* c1 = new TCanvas("c1","c1",1);
  c1->Divide(2,2);

// Init some variables
    
  char fname[100];
  char selvar[100];
  double imadata[100*100];

  int NFRAMES        = 9;      // number of frames to be written per file
  int RUN            = 1000;   // run number
  int NDATA          = 50000;  // number of data points
  int NFILES         = 5;      // number of files

  double dt     = 1.e-4;
  double sttime = 600000000.;
  double globsttime = sttime;  // global start time, is constant
  
//
//-------------------------------------------------
// Creates NFILES files containing some ADC data
//-------------------------------------------------
//
  
// function and start parameters for the image;
  TF2* f2 = new TF2("f2","xygaus + xygaus(5) + xylandau(10)",0,100,0,100);
  double imaparams[15] = {130,30,15,40,20, 150,70,10,70,10, 3600,80,2,30,10};

  for (int jFile=1;jFile<=NFILES;jFile++)
  {
  // shift Files 4 and 5 for testing
     if (jFile==4) sttime += NFRAMES*100;
     if (jFile==5) sttime -= NFRAMES*5;
  
     sprintf(fname,"demo%d.F",int(sttime));

     // open a new frames file
     FrFile* oFile = FrFileONew(fname,3);

// loop over NFRAMES

     for (int iFrame=0; iFrame<NFRAMES; iFrame++) {
        
// create a new frame
        FrameH* frame = FrameHNew("MYGO");
        frame->run = RUN+jFile;
        frame->frame = iFrame+1;
        frame->GTimeS = int(sttime);
        frame->GTimeN = 97000000;     // arbitrary nanosec
        frame->dt = 5.;

// create new adc's
        FrAdcData* adc  = FrAdcDataNew(frame,"MYGO_APD",1/dt,NDATA,16);
        FrAdcData* adc1 = FrAdcDataNew(frame,"MYGO_ADC1",1/dt,NDATA,16);
        FrAdcData* adc2 = FrAdcDataNew(frame,"MYGO_ADC2",1/dt,NDATA,16);
        FrAdcData* seis = FrAdcDataNew(frame,"MYGO_Seis",1/(4*dt),NDATA/4,16);
        FrAdcData* adc3 = FrAdcDataNew(frame,"MYGO_ADC3",1/dt,NDATA,16);

// get pointer to data
        short* data  = adc->data->dataS;
        short* data1 = adc1->data->dataS;
        short* data2 = adc2->data->dataS;
        short* datas = seis->data->dataS;
        short* data3 = adc3->data->dataS;

// set data values
        
        float signalampli = (jFile)*10 + iFrame*3;
        for (int i=0; i<NDATA; i++) {
           data[i] = (short)(500*sin(i*2*3.1415926/1000.));
           data1[i] = (short)(gRandom->Gaus(543,250));
           if (i>1546) {data1[i] = data1[i] + (2500*exp(-(i-1546.)/100.)*sin((i-1546.)/4.));}
           if (i>20000) {data1[i] = data1[i] + (signalampli*200*exp(-(i-20000.)/300.)*sin((i-20000.)/4.));}
           data2[i] = (short)(gRandom->Gaus(1023,250));
//        Add two simple chirp signals to ADC2 (to play with time-frequency)
           if (sttime<globsttime+6) {
              double timecur = sttime+dt*i-globsttime;
              data2[i] = data2[i]+(500*sin(timecur*1000*6.28+2000*timecur*timecur));
              data2[i] = data2[i]+(1500/(0.2*timecur+1)*(int(timecur*pow(timecur+2,2)*750)/2.==int(int(timecur*pow(timecur+2,2)*750)/2.)));
           }
           data3[i] = (short)(gRandom->Gaus(0,250)*(5+sin(i/100.)));
        }
        for (int i=0; i<NDATA/4; i++) {
           datas[i] = (short)(gRandom->Gaus(0,25));
           if (i>370 && i<407) {datas[i] = datas[i] + (250*sin((i-370.)/4.));}
        }
        
// Builds an image
        if (long(sttime/20)*20==sttime) {
           FrAdcData* adci = FrAdcDataNew(frame,"MYGO_IMAGE",1/dt,100*100,16);
           FrVectFree(adci->data);  // Free the created empty vector
           f2->SetParameters(imaparams);
           imaparams[1] = 30+(iFrame+NFRAMES*jFile)*40./(NFRAMES*NFILES);
           imaparams[8] = 70-(iFrame+NFRAMES*jFile)*30./(NFRAMES*NFILES);
           for (int ix=0;ix<100;ix++) {
              for (int iy=0;iy<100;iy++) {
                 imadata[iy+ix*100] = f2->Eval((double)ix, (double)iy) + gRandom->Gaus(10,3);
              }
           }
           adci->data = VVectNew2D("MYGO_IMAGE",100,100,1,1,
                                   sttime,imadata,FR_VECT_8R,"X","Y","I");
        }
               
// Build some triggers
        FrEvent* trig1 = FrEventNew(frame,"Trig1","","inp1=0 inp2=3.1415",
                                 sttime+0.156,2,3,signalampli, gRandom->Gaus(100,50),
                                 "deltam=-1.45 deltap=1.32 va1=45.678",(FrVect*)0,0);
        if (long(sttime/10)*10==sttime) {
           FrEvent* trig2 = FrEventNew(frame,"Trig2","","inp1=1 inp2=6.28",
                                 sttime+2.0843,2.2,1.5,signalampli/10, -gRandom->Gaus(100,50),
                                 "deltam=-0.86 deltap=0.32 va1=90.123",(FrVect*)0,0);
        }
        if (signalampli>30) {
           float deltam = signalampli/10;
           float deltap = (float)(sttime-600000000.097);
           float va2 = iFrame;
           sprintf(selvar,"deltam=%f deltap=%f va2=%f",deltam,deltap,iFrame);
           FrEvent* trig3 = FrEventNew(frame,"Trig3","","inp1=2 inp2=9.0234",
                                 sttime+2.0843,0,0,signalampli/100, -gRandom->Gaus(-100,50),
                                 selvar,(FrVect*)0,0);
        }
        if (long(sttime/20)*20==sttime) {
           FrEvent* trigimage = FrEventNew(frame,"TrigImage","","inp1=1 inp2=6.28",
                                 sttime+2.0843,1,1.5,signalampli/10, -gRandom->Gaus(100,50),
                                 "deltam=-0.86 deltap=0.32 va1=90.123",(FrVect*)0,0);
        }

// write this frame to the frame file
        FrameWrite(frame,oFile);
        printf("Written frame %d in file %s, beginning time %12.3fn",iFrame+1,fname,sttime);
        
// Display some contents of the frames
        c1->cd(1);
        gVM->Draw(frame,"adc.MYGO_ADC1");
        c1->cd(2);
        gVM->Draw(frame,"adc.MYGO_Seis");
        c1->cd(3);
        gVM->Draw(frame,"adc.MYGO_ADC2");
        if (long(sttime/20)*20==sttime) {
           c1->cd(4);
           gVM->Draw(frame,"adc.MYGO_IMAGE","colz");
        }
        gPad->Update();

// Release frame resources
        FrameFree(frame);
        
// Update the time
        sttime += dt*NDATA;
        if (jFile==4 && iFrame==1) sttime += NFRAMES*40;
        if (jFile==5 && iFrame==1) sttime += (NFRAMES-2)*5;
     }
  
// release the file resources
     FrFileOEnd(oFile);
  }

//
//-------------------------------------------------
// Now create a file with sms data in it
//-------------------------------------------------
//

   int NSMSFRAMES = 1000;
   sttime = 600000000.;  // Reset start time
   double sttime0 = sttime;
   char smsvar[1000];
   char smsname[10] = "MYGOSMS";
   char smstime[20];

   printf("nCreation of frame files containing slow monitoring datan");
   
// open a new frames file
   FrFile* oFile = FrFileONew("SMSdemo.F",3);

// Build frames containing only sms data
   int toggle = 1;
   for (int iFrame=0; iFrame<NSMSFRAMES; iFrame++) {
    
//   create a new frame
      FrameH* frame = FrameHNew("MYGO");
      frame->run = RUN+5+1;
      frame->frame = iFrame+1;
      frame->GTimeS = int(sttime);
      frame->GTimeN = 97000000;     // arbitrary nanosec
      frame->dt = 5.;

//   Prepare SMS data into a string
      
      if ((long((sttime-sttime0)/500)*500-sttime+sttime0) == 0) {
         sttime0 = sttime;
         toggle = - toggle;
      }
      double var1 = toggle*100*(1-exp((sttime0-sttime)/100)) + (1-toggle)/2*100 + gRandom->Gaus(0,10);
      int var2 = (sttime-sttime0)/10 + gRandom->Gaus(0,10);
      
      sprintf(smsvar," VF1 %f VI2 %d",var1,var2);
      
//  create new SMS's
      FrSerData* smsdat  = FrSerDataNew(frame,smsname,(unsigned long)(sttime),smsvar, 5);
     
// write this frame to the frame file
      FrameWrite(frame,oFile);
     
// Update the time
      sttime += 5;
   }
  
// release the file resources
   FrFileOEnd(oFile);
   
//
//---------------------------------------------------------------------
// Builds a very simple ascii test file containing data in a format :
// Time1 valueA1 valueB1 valueC1
// Time2 valueA2 valueB2 valueC2
// Time3 valueA3 valueB3 valueC3
// etc...
//---------------------------------------------------------------------
//

   printf("nCreation of a text file containing a numerical tablen");
   
   int i,nsteps;
   FILE* asciifile;
   
   double starttime = 600000000.34;
   double endtime = 600001024.34;
   double step = 1;
   
   asciifile = fopen("demovalues.txt","a");
   
   nsteps = (int)((endtime - starttime)/step);
   for (i=0;i<nsteps;i++) {
      double value1 = gRandom->Rndm(1)*24+12;
      double value2 = gRandom->Gaus(0,100)+1000*sin((double)i/1386.*3.1415926);
      double value3 = gRandom->Gaus(543,250);
      if (i>434) {value3 = value3 + (2500*exp(-(i-434.)/100.)*sin((i-434.)/4.));}
      
      double time = step*i+starttime;
      
      fprintf(asciifile,"%20f %f %f %fn",time, value1, value2, value3);
   }
   
   fclose(asciifile);

}



- ROOT page - VEGA page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to , or contact with any questions or problems regarding ROOT or VEGA.