ROOT logo
#ifndef _MultiWF
#define _MultiWF

//                                                                      //
// MultiWF                                                              //
//                                                                      //
// Managing Multi waveform                                              //
//                                                                      //

#include "TObject.h"
#include "TH1.h"
#include "TMath.h"
#include "TArray.h"
#include "TArrayI.h"
#include "TArrayF.h"
#include "TGraph.h"
#include <stdio.h>
#include <stdlib.h>
#include "TClonesArray.h"
#include "TPaveText.h"
#include "TText.h"
#include "Elec.h"
#include "TF1.h"
#include "MeasureWF.h"
//#define HeaderSize 44

Double_t langaufun(Double_t *, Double_t *);

class  MultiWF : public TObject {

  FILE	 	 *in;	 	//Stream
  Int_t          HeaderSize;    //Size of the header
  Int_t          Events;        //Number of Events
  Int_t 	 Points;	//Number of points per event
  Float_t 	 t0;		//Starting point
  Float_t	 deltat;       	//distance between two points
  Int_t          NumU;
  Int_t          NumUAver;
  Int_t          NumCh;
  TArrayF 	 Date;		//Date of the Measurement (or simulation)
  TArrayF        Voltage;      //Array of Voltages  
  TArrayF	 Current; 	//Array of Currents
  TArrayF	 Temperature;	//Array of Temperatures
  Char_t         Comment[2000]; //Comment
  Int_t          SelPlot;       //Select plot
  void swoo(char *,char *);
  void swooip(float *, int);
  Int_t i2a(Char_t *,Float_t,Int_t=1);

  Float_t        **Ebuf;        //Event Buffer
  TH1F        **hisa;        //histogram array
  Float_t Weight;
  TPaveText *pt;
  Int_t cevent;
  TH1F *chis;
  Float_t cm_mint;
  Float_t cm_maxt;
  Int_t CCmode;
  // horizontal correction 
  Int_t TimeC;
  Float_t TimeThr; 
  // end of horizontal correction
  Float_t cmode; //select exclusion =1 (cut region) =0 (except region)
  Float_t *Cmode;
  Int_t cmcut;  
  Float_t cmcut_low;
  Float_t cmcut_hi;
  // Filtering variables
  Bool_t FOnOff;
  Float_t Fxlow;
  Float_t Fxhi; 
  Float_t Fylow; 
  Float_t Fyhi;
  Float_t FIntPass;
  Float_t FIntPassHi;
  Float_t Fmaxhi;
  Float_t Fmaxlo;
  Int_t Fmode;


MultiWF(Char_t *,Float_t=-1111.,Int_t=0);
Int_t CheckSize();
void GetNextEvent();
 void DrawNextEvent();
Int_t GetPoints() {return(Points);};
Float_t Gett0() {return(t0);};
Float_t GetDeltat() {return(deltat);};
Int_t GetEvents() {return(Events);};
 Float_t GetU(int ind=0) {return(Voltage[ind]); }
 Int_t GetNU() {return (NumU);} 
 Float_t GetT(int ind=0) {return(Temperature[ind]); }
 Float_t GetI(int ind=0) {return(Current[ind]); }

void Sett0(Float_t x) {t0=x; delete chis; chis=new TH1F("Event View","Event View",Points,t0*1e9,(t0+Points*deltat)*1e9);};
void CommonMode();
Float_t Integral(Float_t=-1111,Float_t=-1111);
void EShaping(Elec *,TH1F *,Int_t=1);
void SetNewFile(char *);
void Rewind(Int_t=0); // {rewind(i;for(int i=0;i<};
TH1F *Average(Int_t , Int_t);
 TH1F *AverPlot(Int_t, Int_t=0, Int_t=-1,Int_t=-1,Int_t=-1);
 void Persistance(Int_t, Int_t, Int_t = -1111);
 MeasureWF *AverTime(Int_t,Int_t);

TH1F *Add(Int_t=0, Int_t end=0);
void Info();
 void SelectPlot(Int_t=0);
 void PlotEvent(Int_t);
inline TH1F *operator()(Int_t index) { Rewind(index); return chis;};

TH1F *Time(Float_t=1,Float_t=0, Float_t=-1111,Int_t =1,Float_t=0);
 TH1F *Specter(Float_t=0, Float_t=-1111,Float_t=1,Int_t=100,Float_t=-0.5,Float_t=5,Int_t=-1,Int_t=-1);
 TH1F *PHSpecter(Float_t=10, Int_t=180,Float_t=0,Float_t=6,Float_t=-1e6,Float_t=-1e6,Int_t mode=0,Int_t=-1,Int_t=-1);
 TH1F *CMHisto();
TH1F *WaveHisto(Float_t, Int_t ,Float_t ,Float_t,Int_t=-1,Int_t=-1 );
void FitShape(Int_t, Float_t );
inline void SetPoints(Int_t x) {Points=x;};
 MeasureWF *GetWF();
 Bool_t Filter();
 void SetNumAver(Int_t x) {NumUAver=x;}; 
void WF(Int_t,Int_t,Int_t,Float_t=-5,Float_t=30,Int_t=0);
void Legend(TH1F *, Int_t, Int_t,Int_t=1);

 void CorrectTime(Int_t , Float_t );
// void PHSpecterMulti(Int_t, Int