README of FACT svntools/rootmacros

	on the ISDC cluster, I used /opt/root5.18.x86_64/bin/root for testing.

fbsl.C		ROOT Macro computing the baseline for each pixel
	the function is declared as:
	int fbsl( 
  	const char *datafilename    = "path-to-datafile.fits.gz",
	  const char *drsfilename = "path-to-calibfile.drs.fits.gz",
	  const char *TextOutFileName = "./appendfile.txt",
	  const char *RootOutFileName = "./datafile.root",
	  int firstevent      = 0,
	  int nevents       = -1, 
	  int firstpixel    = 0,
	  int npixel        = -1,
	  bool produceGraphic = false
	)

	the baseline and its rms is calculated for each pixel based on the data,
	given in the datafile.
	the results are appended to a textfile
	and the histograms ,which were used for caluculation, as well as some
overviews are stored in a root file.
	the 4 ints: firstevent, nevents, firstpixel, npixel can be used to calculate
only for a subset
	the last bool can be set to true, which will open 2 Canvases with overview
histograms.

	for automatic production of baseline analysis one can call this macro like
this:
e.g.
	root -l -q fbsl.C++'("/data00/fact-construction/raw/2011/10/26/20111026_036.fits.gz", "/data00/fact-construction/raw/2011/10/26/20111026_031.drs.fits.gz", "./fbsl.txt", "./20111026_036.root")'


-----------------------------------------------------------------------------------------------
fpeak_cfd.C		ROOT macro creating an amplitude spektrum for each pixel

int fpeak(
  char *datafilename    = "data/20111016_013.fits.gz",
  const char *drsfilename = "../../20111016_011.drs.fits.gz",
  const char *OutRootFileName = "../analysis/fpeak_cdf.Coutput.root",
  int firstevent      = 0,
  int nevents       = -1,
  int firstpixel      = 0,
  int npixel        = -1,
  bool spikeDebug = false,
  int avg1    = 14,
  int avg2    = 8,
  int verbosityLevel = 1, // different verbosity levels can be implemented here
  bool ProduceGraphic = true
 )

the peaks are search, using the constant fraction discriminator, implemented
as a FIR filter, which outputs a waveform, which rising edge zero crossings
show the position of a peak.

the two integers 'avg1' and 'avg2' are still present for debugging... 
two sliding average filters are beeing used, and these are the HALFwidths of
these filters.

The amplitude spektra are produced as a TH2F with the pixels on its x-Axis.
For further analysy the ROOT macro gainfit.C may be used...


-----------------------------------------------------------------------------------------------

gainfit.C ROOT macro for analysing the amplitude spektra of fpeak_cfd.C

this is far from beeing any good, but have a look yourself.

call it like this:
gainfit("rootfilename.root", "textoutfilename.txt" , false);

its short ... so I'd rather not explain it here.
I guess one can try for many other fit functions, and play with Parameter
bounds, but I had no time yet.
Thomas Krähenbühl once send me a mail containing a lot of ideas, and I guess
in gainanalysis.C there is a lot more ... 
these scripts should maybe be joined soon ...somehow.
D.Neise 20111104


-----------------------------------------------------------------------------------------------
flightpulser.C ROOT macro for plotting the amplitudes of the external lightpulser 

call it e.g. like this 
root
flightpulser.C+'("data/20111029_017.fits.gz","data/20111029_013.drs.fits.gz","../analysis/20111029_017-013_fpeak_cfd.root",
0, 100, 0,-1)'

to look at the amplitudes of all camera pixel for 100 events.
you get a color coded TH2F so you can look at the amplitude distribution
yourself.

this macro is based on fpeak_cdf.C pretty much.
I basically use the same steps, but in the end I just fill the absolute
maximum into the TH2F.

The macro is pretty slow (about 1.5 min for 100 full camera events) so I
switched off the sliding averages...

but it didn't help much...

I am still not sure how to improve the speed of these macros.....


-----------------------------------------------------------------------------------------------
tpeak.C ROOT macros to produce overlays of data around a found peak in a given
window.

int tpeak(
  char *datafilename    = "data/20111016_013.fits.gz",
  const char *drsfilename = "../../20111016_011.drs.fits.gz",
  const char *OutRootFileName = "../analysis/fpeak_cdf.Coutput.root",
  int firstevent      = 0,
  int nevents       = -1,
  int firstpixel      = 0,
  int npixel        = -1,
  bool spikeDebug = false,
  int avg1    = 14,
  int avg2    = 8,
  int OverlayWindowLeft = 50,
  int OverlayWindowRight = 150,
  int verbosityLevel = 1, // different verbosity levels can be implemented
here
  bool ProduceGraphic = true
  )

call it like this, if you want to overlay a certain number of peaks for a
single channel
tpeak("data/20111029_017.fits.gz","data/20111029_013.drs.fits.gz","test.root",0,1000,333,1,true,0,0,50,150,1,true)

set the first bool 'spikeDebug' to false in order to overlay quicker ... every
50th event the canvas is updated.
depending on what kind of peaks you like to detect the sliding average filters
should be set to e.g. 14,8 for singles in a quiet G-APD pedestal run
or 0,0 if you want to see just every thing that might be a signal...

the window size 50,150 means .. 50 slices to the left of the maximum and 150
to the right.

there is a bit of cleaning included in the file, maybe you want to switch it
off, then just search for the calls of these methods... 
 removeMaximaBelow( *zXings, 3.0);
 removeRegionWithMaxOnEdge( *zXings, 2);
 removeRegionOnFallingEdge( *zXings, 100);

and comment them out or play with the settings.

they are defined in zerosearch.C, which is maybe a bad choice...



