Finding peaks from the tree branch with corresponding bin

I have a tree with defined leaflist defined.

 struct data_t {
    Int_t Event;
    Int_t QuartzChn;
    Int_t TrRightChn;
    Int_t TrLeftChn;
    Int_t LYSOChn;
    Int_t t1;
    Int_t t2;
    Int_t OR;
  data_t data;

  TFile *f = new TFile(Form("run_%d.root",run),"RECREATE");
  TTree *dataTree = new TTree("dataTree","Detector Event Data");

  FILE *fp1 = NULL;
  FILE *fp2 = NULL;
  FILE *fp3 = NULL;
  FILE *fp4 = NULL;
  FILE *fp5 = NULL;

  fp1 = fopen(Form("ch00/run_%d_ch00.dat",run),"r"); //Quartz
  fp2 = fopen(Form("ch02/run_%d_ch02.dat",run),"r"); //Trigger right
  fp3 = fopen(Form("ch04/run_%d_ch04.dat",run),"r"); //Trigger left
  fp4 = fopen(Form("ch06/run_%d_ch06.dat",run),"r"); //LYSO
  fp5 = fopen(Form("ch08/run_%d_ch08.dat",run),"r"); //Signal OR

  char tmp[20]; 
  fscanf(fp1,"%s",tmp); cout << tmp << endl;
  fscanf(fp2,"%s",tmp); cout << tmp << endl;
  fscanf(fp3,"%s",tmp); cout << tmp << endl;
  fscanf(fp4,"%s",tmp); cout << tmp << endl;
  fscanf(fp5,"%s",tmp); cout << tmp << endl;

  Int_t ret;


    ret = fscanf(fp1,"%d %d %d %d",&data.Event, &data.t1, &data.t2, &data.QuartzChn); if(ret == EOF) break;
    ret = fscanf(fp2,"%d %d %d %d",&data.Event, &data.t1, &data.t2, &data.TrRightChn); if(ret == EOF) break;
    ret = fscanf(fp3,"%d %d %d %d",&data.Event, &data.t1, &data.t2, &data.TrLeftChn); if(ret == EOF) break;
    ret = fscanf(fp4,"%d %d %d %d",&data.Event, &data.t1, &data.t2, &data.LYSOChn); if(ret == EOF) break;    
    ret = fscanf(fp5,"%d %d %d %d",&data.Event, &data.t1, &data.t2, &data.OR); if(ret == EOF) break;    




I can view the resulting root file with the Tbrowser with desired histogram.
now from here, I would like to find the two right most peaks from LYSOChn and apply the range between two peaks to QuartzChn histogram.
I plan to do this by finding the list of bins with maximum counts, choose the two right most bins and applying the range to LYSOChn.
Would there be any built in function that would find the bin? Or if I have to loop through the leaves, how could I loop through the items in each leaf?
Thank you for taking your time.
Let me know if there is something unclear.

Hi @hansoullee,
From the root TBrowser if you right click on the histogram, there is the method ShowPeaks(), in this way
you can visualize the peak directly on the TBrowser.

Otherwise try to look a the TSpectrum class, especially the TSpectrum::Search method to found the peaks.
Then to get back the position and the number of peaks there are the methods TSpectrum::GetNPeaks and TSpectrum::GetPositionX


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.