AIDA GELINA BRIKEN nToF CRIB ISOLDE CIRCE nTOFCapture DESPEC DTAS EDI_PSA 179Ta CARME StellarModelling DCF K40
  AIDA  ELOG logo
Fields marked with * are required
Entry time:Fri Jan 30 15:27:35 2015
Author*:
Subject*:

Encoding:
        
Attachment 1:
Make smaller Original size Make larger   Rotate left Rotate right   Delete attachment    R61part_ts_dist_adc_hit.png  Original size: 1314x809
R61part_ts_dist_adc_hit.png
Attachment 2:
Make smaller Original size Make larger   Rotate left Rotate right   Delete attachment    R61part_rates.png  Original size: 1439x821
R61part_rates.png
Attachment 3:
Make smaller Original size Make larger   Rotate left Rotate right   Delete attachment    R61part_t1_hits_ts_adc.png  Original size: 1372x721
R61part_t1_hits_ts_adc.png
Attachment 4:
Make smaller Original size Make larger   Rotate left Rotate right   Delete attachment    R61part_t1_hits_ts_adc_zoom.png  Original size: 1372x721
R61part_t1_hits_ts_adc_zoom.png
Attachment 5:
Make smaller Original size Make larger   Rotate left Rotate right   Delete attachment    R61part_t1_hits_ts_info.png  Original size: 1285x641
R61part_t1_hits_ts_info.png
Attachment 6:
Make smaller Original size Make larger   Rotate left Rotate right   Delete attachment    R61part_ts_info_fee.png  Original size: 1100x595
R61part_ts_info_fee.png
Attachment 7: loopAIDAsort.cpp   
/*********/
//#include <bitset>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <ctime>

#include <TFile.h>
#include <TTree.h>
#include <TH1I.h>
#include <TH2I.h>
#include <TGraph.h>
#include <TCanvas.h>

//#include "Common.h"


//using namespace std;
/*********/


//ts_0 in usec
void LoopTree(string inFile, int downscale=1, long long n_last= -1, int ts_0=-1, bool b_print=false, bool b_quit_ts=false){



  struct struct_entry_sort{
    long long tm_stp; //reconstructed timestamp (MSB+LSB)
    long long info; //MBS info data (external timestamp), anything else(?)
    int mod_id;
    int ch_id;
    int type; // QQQ: 0= 20 MeV or 1 GeV (decays), 1= 20 GeV (checked pulser data only in type 0)
              // type>=10: type = info_code+10 (i.e., PAUSE, RESUME, SYNC100, etc...)
    int adc_data;
    bool sync_flag; // check SYNC100 pulses received for this module
    bool pause_flag; // check Pause signals followed by proper Resume signal: true= SYNC100 paused...
  };



  //***** histograms! many...
  //

  //delta ts: any->any [100]
  //          adc->adc [100]
  //          adc(feei)->adc(feej) [1]
  //          adc(sidei)->adc(sidej) [1]
  //          !adc->!adc [1]
  //1,2,3,5,10,15,20,50,100
  TH1D *Hdts_any[10];
  Hdts_any[0]= new TH1D("Hdts_any0","#Delta ts_{(i+1,i)} !ANY DATA;ts_{i+1} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[1]= new TH1D("Hdts_any1","#Delta ts_{(i+2,i)} !ANY DATA;ts_{i+2} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[2]= new TH1D("Hdts_any2","#Delta ts_{(i+3,i)} !ANY DATA;ts_{i+3} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[3]= new TH1D("Hdts_any3","#Delta ts_{(i+5,i)} !ANY DATA;ts_{i+5} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[4]= new TH1D("Hdts_any4","#Delta ts_{(i+10,i)} !ANY DATA;ts_{i+10} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[5]= new TH1D("Hdts_any5","#Delta ts_{(i+15,i)} !ANY DATA;ts_{i+15} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[6]= new TH1D("Hdts_any6","#Delta ts_{(i+20,i)} !ANY DATA;ts_{i+20} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[7]= new TH1D("Hdts_any7","#Delta ts_{(i+50,i)} !ANY DATA;ts_{i+50} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_any[8]= new TH1D("Hdts_any8","#Delta ts_{(i+100,i)} !ANY DATA;ts_{i+100} - ts_{i} [usec]",4400,-20,200); //200 us full scale

  TH1D *Hdts_adc[10];
  Hdts_adc[0]= new TH1D("Hdts_adc0","#Delta ts_{(i+1,i)} !ADC(low) DATA;ts_{i+1} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[1]= new TH1D("Hdts_adc1","#Delta ts_{(i+2,i)} !ADC(low) DATA;ts_{i+2} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[2]= new TH1D("Hdts_adc2","#Delta ts_{(i+3,i)} !ADC(low) DATA;ts_{i+3} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[3]= new TH1D("Hdts_adc3","#Delta ts_{(i+5,i)} !ADC(low) DATA;ts_{i+5} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[4]= new TH1D("Hdts_adc4","#Delta ts_{(i+10,i)} !ADC(low) DATA;ts_{i+10} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[5]= new TH1D("Hdts_adc5","#Delta ts_{(i+15,i)} !ADC(low) DATA;ts_{i+15} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[6]= new TH1D("Hdts_adc6","#Delta ts_{(i+20,i)} !ADC(low) DATA;ts_{i+20} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[7]= new TH1D("Hdts_adc7","#Delta ts_{(i+50,i)} !ADC(low) DATA;ts_{i+50} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_adc[8]= new TH1D("Hdts_adc8","#Delta ts_{(i+100,i)} !ADC(low) DATA;ts_{i+100} - ts_{i} [usec]",4400,-20,200); //200 us full scale

  TH1D *Hdts_fee[1];
  Hdts_fee[0]= new TH1D("Hdts_fee0","#Delta ts_{(i+1,i)} !ADC(low), diff. FEE;ts_{i+1} - ts_{i} [usec]",4400,-20,200); //200 us full scale

  TH1D *Hdts_side[2];
  Hdts_side[0]= new TH1D("Hdts_side0","#Delta ts_{(i+1,i)} !ADC(low), side0->1;ts_{i+1} - ts_{i} [usec]",4400,-20,200); //200 us full scale
  Hdts_side[1]= new TH1D("Hdts_side1","#Delta ts_{(i+1,i)} !ADC(low), side1->0;ts_{i+1} - ts_{i} [usec]",4400,-20,200); //200 us full scale

  TH1D *Hdts_info[1];
  Hdts_info[0]= new TH1D("Hdts_info0","#Delta ts_{(i+1,i)} !info DATA;ts_{i+1} - ts_{i} [usec]",4400,-20,200); //200 us full scale
 
  TH1D *Hdts_ooo[1];
  Hdts_ooo[0]= new TH1D("Hdts_ooo0","#Delta ts_{(i+1,i)} !out-of-order!;ts_{i+1} - ts_{i} [usec]",15000,-3e6,0); //500 us full scale
 

  TH1D * Hts[2];
  Hts[0]= new TH1D("Hts0","Time-stamp;ts [usec]",2000,0,27e5);
  Hts[1]= new TH1D("Hts1","Time-stamp;ts [usec]",2000,91e9,97e9);



  //Rate hitograms
  TH1D * HrateFEE_ts[4];
  TH1D * HrateFEE_ch[4];
  TH1D * HrateADChigh_ts[1];
  TH1D * HrateInfo_ts[1];
  
  TH1I * HhitsADC[5];
  TH1I * HhitsInfo[4];
    
  TH2I * HtsFEE[3];
  TH2I * HtsInfo[1];
  TH2D * HtsCh[4];


  TH2I * HInfoFEE[4];

  double max_bin;
  if(n_last>0) max_bin= n_last;
  else max_bin= 1.e7;
  TH2I * HtsEvent[2];
  //HtsEvent[0]= new TH2I("HtsEvent0","Time-stamp vs entry;entry #;ts [usec]",200,0,max_bin,1000,0,27e5);
  HtsEvent[1]= new TH2I("HtsEvent1","Time-stamp vs entry;entry #;ts [usec]",500,0,max_bin,500,92e9,97e9);
  //sEvent[1]= new TH2I("HtsEvent1","Time-stamp vs entry;entry #;ts [usec]",500,0,max_bin,500,92.4e9,92.44e9);



  // variables for distribution of time-stamp differences
  double dts;
  double ts100_any[101];
  double ts100_adc[101];
  //  long long tsinide01;
  //  long long ts_side10;
  // long long ts_fee; 
  double ts_info= -1;
  int index_adc=0;
  int index_any=0;
  int index_prev;
  int last_side, this_side;
  int last_fee, this_fee;

  int step_back[9]={1,2,3,5,10,15,20,50,100};
  int steps;

  double ts;

  for(int i=0;i<101;i++){
    ts100_any[i]= -1;
    ts100_adc[i]= -1;
  }


  int Nooo=0;

  int info_code_prev, mod_id_prev, type_prev;


  //logfile
  ofstream logfile("outputLoop_R61_5.txt");

  time_t t_start; //, t_stop;

  TFile* input_file; 
  input_file = new TFile(inFile.data(),"read");
 
  if (input_file != 0){
    input_file->ls();

    TTree * input_tree;
    input_tree= (TTree*) input_file->Get("AIDA_sort");

    if(input_tree !=0) input_tree->Print();
    else {
      cout << "\n WARNING@ could not assign AIDA_sort Tree...." << endl;
      exit(0);
    }


    //tree from Converter step will data in a struct_entry_midas structure
    struct_entry_sort entry_1;

    input_tree->SetMakeClass(1);
    input_tree->SetBranchAddress("entry_sort",&entry_1,0);
    input_tree->SetBranchStatus("entry_sort",1);

    //number of data points in TTree
    long long n_entries;
    n_entries = input_tree->GetEntries();

    cout << "\nNumber of entries in input tree= " << n_entries << ", in file " << inFile << endl;
    logfile << "\nNumber of entries in input tree= " << n_entries << ", in file " << inFile << endl;
  


    //get run time... properly...
    long long time_first, time_last;

    time_first= 0;
    for(long long i=0; i<=100000; i++){
      input_tree->GetEntry(i);
      if(entry_1.sync_flag){
	time_first= entry_1.tm_stp;
	i=100000+1;
      }
    }
    if(time_first<=0){
      cout << "\n\n**** WARNING: Couldn't find Synchronized data in first 100K entries of file! ****\n" << endl;
      time_first=0;
    }
    input_tree->GetEntry(n_entries-1);
    time_last= entry_1.tm_stp;

    cout << "\n----------------------------------------------------------------------------"
    	 << "\n  Inititial time stamp= " <<time_first;
    cout << "\n  Lenght of run= "<<time_last-time_first <<" tm-stp= "<<(time_last-time_first)/1.e8 <<" sec"<<endl;




    //Define histograms that need to know run lenght....
    double ts_low, ts_up; //in usc
    double ts_sec;
    //    int ts_0;
    //in msec units!
    if(ts_0<0) ts_0 = time_first/100000; // 10x ns -> ms
    
    cout << " .... using ts_0= " << ts_0;

    //and this in usec units!
    ts_low= ts_0*1000.;
    ts_up= ts_low+20.e6;

    cout << "msec, ts_low= " << ts_low << " usec, ts_up= " << ts_up << " usec" << endl<<endl;

    int fee_index;
    bool b_ts_window;

    //Rate histograms

    int ts_0_sec= int(1.*time_first/1e8);
    //2 hrs, 10sec/bin
    HrateFEE_ts[0]= new TH1D("HrateFEE_ts0","Rate - ADClow(nnaida11);time-stamp [s];rate [1/s]",360,ts_0_sec,ts_0_sec+3600);
    HrateFEE_ts[1]= new TH1D("HrateFEE_ts1","Rate - ADClow(nnaida12);time-stamp [s];rate [1/s]",360,ts_0_sec,ts_0_sec+3600);
    HrateFEE_ts[2]= new TH1D("HrateFEE_ts2","Rate - ADClow(nnaida13);time-stamp [s];rate [1/s]",360,ts_0_sec,ts_0_sec+3600);
    HrateFEE_ts[3]= new TH1D("HrateFEE_ts3","Rate - ADClow(nnaida14);time-stamp [s];rate [1/s]",360,ts_0_sec,ts_0_sec+3600);

    HrateFEE_ch[0]= new TH1D("HrateFEE_ch0","Rate - ADClow(nnaida11);ch; rate [1/s];time-stamp [s]",64,0,64);
    HrateFEE_ch[1]= new TH1D("HrateFEE_ch1","Rate - ADClow(nnaida12);ch; rate [1/s];time-stamp [s]",64,0,64);
    HrateFEE_ch[2]= new TH1D("HrateFEE_ch2","Rate - ADClow(nnaida13);ch; rate [1/s];time-stamp [s]",64,0,64);
    HrateFEE_ch[3]= new TH1D("HrateFEE_ch3","Rate - ADClow(nnaida14);ch; rate [1/s];time-stamp [s]",64,0,64);

    HrateADChigh_ts[0]= new TH1D("HrateADChigh_ts0","Rate - ADChigh(any FEE);time-stamp [s];rate [1/s]",360,ts_0_sec,ts_0_sec+3600);
    HrateInfo_ts[0]= new TH1D("HrateInfo_ts0","Rate - Info Types;time-stamp [s];rate [1/s]",360,ts_0_sec,ts_0_sec+3600);

    //Info types for different FEEs (sum and vs time)
    HInfoFEE[0]= new TH2I("HInfoFEE0","Info Code vs FEE;Info Type;nnaida",16,0,16,4,11,15);
    HInfoFEE[1]= new TH2I("HInfoFEE1","Time-stamp vs FEE(Pause/Resume);time-stamp [s];nnaida",240,ts_0_sec,ts_0_sec+3600,4,11,15);
    HInfoFEE[2]= new TH2I("HInfoFEE2","Time-stamp vs FEE(SYNC100);time-stamp [s];nnaida",240,ts_0_sec,ts_0_sec+3600,4,11,15);
    HInfoFEE[3]= new TH2I("HInfoFEE3","Time-stamp vs FEE(Disc.);time-stamp [s];nnaida",240,ts_0_sec,ts_0_sec+3600,4,11,15);


    //hist vs time
    
    HhitsADC[0]= new TH1I("HhitsADC0","Rate [1/ms] - ADClow(nnaida11);time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsADC[1]= new TH1I("HhitsADC1","Rate [1/ms] - ADClow(nnaida12);time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsADC[2]= new TH1I("HhitsADC2","Rate [1/ms] - ADClow(nnaida13);time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsADC[3]= new TH1I("HhitsADC3","Rate [1/ms] - ADClow(nnaida14);time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsADC[4]= new TH1I("HhitsADC4","Rate [1/ms] - ADChigh;time-stamp [ms]",20000,ts_0,ts_0+20000);
    
    HhitsInfo[0]= new TH1I("HhitsInfo0","Rate [1/ms] - PAUSE/RESUME;time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsInfo[1]= new TH1I("HhitsInfo1","Rate [1/ms] - RESUME TS;time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsInfo[2]= new TH1I("HhitsInfo2","Rate [1/ms] - SYNC100;time-stamp [ms]",20000,ts_0,ts_0+20000);
    HhitsInfo[3]= new TH1I("HhitsInfo3","Rate [1/ms] - Discr. Data;time-stamp [ms]",20000,ts_0,ts_0+20000);


    HtsFEE[0]= new TH2I("HtsFEE0","Time-stamp vs FEE(ADClow);ts [ms];nnaida",1000,ts_0,ts_0+20000,4,11,15);
    HtsFEE[1]= new TH2I("HtsFEE1","Time-stamp vs FEE(SYNC100);ts [ms];nnaida",1000,ts_0,ts_0+20000,4,11,15);
    HtsFEE[2]= new TH2I("HtsFEE2","Time-stamp vs FEE(Pause/Res.);ts [ms];nnaida",1000,ts_0,ts_0+20000,8,11,15);

    //  HtsFEE[0]= new TH2I("HtsFEE0","Time-stamp vs FEE\# (ADClow);ts [msec];nnaida\# ",2000,ts_0,ts_0+20000,4,10.5,14.5);
    
    HtsInfo[0]= new TH2I("HtsInfo0","Time-stamp vs InfoCode;ts [ms];Info Type",1000,ts_0,ts_0+20000,16,0,16);
    
 
    HtsCh[0]= new TH2D("HtsCh0","Time-stamp vs Ch. (nnaida11);ts [ms];ch",5000,ts_0,ts_0+5000,64,0,64);
    HtsCh[1]= new TH2D("HtsCh1","Time-stamp vs Ch. (nnaida12);ts [ms];ch",5000,ts_0,ts_0+5000,64,0,64);
    HtsCh[2]= new TH2D("HtsCh2","Time-stamp vs Ch. (nnaida13);ts [ms];ch",5000,ts_0,ts_0+5000,64,0,64);
    HtsCh[3]= new TH2D("HtsCh3","Time-stamp vs Ch. (nnaida14);ts [ms];ch",5000,ts_0,ts_0+5000,64,0,64);




    t_start= time(0); //lets count how long it takes to loop through tree

    
    //now looping only over first 99 events, or up to n_entries, whatever is less
    if(n_last<1 || n_last>n_entries) n_last= n_entries;
   
    //  input_tree->GetEntry(0);

    for(long long i=0; i<n_last; i=i+downscale){
      //
      //  do stuff...
      //

      //    entry_0.tm_stp= entry_1.tm_stp;
      //    entry_0.type= entry_1.type;
      //    entry_0.info= entry_1.info;
... 343 more lines ...
Attachment 8:   
Drop attachments here...
ELOG V3.1.4-unknown