data analysis scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

989 lines
32 KiB

//////////////////////////////////////////////////////////
// This class has been automatically generated on
// Tue Sep 12 15:40:57 2017 by ROOT version 5.34/32
// from TTree t/t
// found on file: ../../HIT_26-11-2016/with_timestamp/pin/PiN_run1.root
//////////////////////////////////////////////////////////
#ifndef analyse2_h
#define analyse2_h
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TTree.h>
#include <stdio.h>
#include <TH2D.h>
#include <TH1D.h>
#include <TProfile.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TMath.h>
#include <vector>
#include <utility>
#include <TString.h>
#include <TDirectory.h>
#include <TString.h>
#include <TVectorD.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <cmath>
#include <TPaveStats.h>
#include <TText.h>
#include <TStyle.h>
#include <TObjArray.h>
#include <TLegend.h>
#include <TFitResult.h>
#include <gsl/gsl_statistics.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_fft_complex.h>
using namespace std;
// Header file for the classes stored in the TTree if any.
// Fixed size dimensions of array or collections stored in the TTree if any.
class analyse2 {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
TTree *data;
TTree *newdata;
// Declaration of leaf types
Double_t time;
Double_t event_id;
Double_t sync_out;
Double_t sync_in;
Double_t data_ok;
Double_t led_voltage;
Double_t current;
Double_t ch00;
Double_t ch01;
Double_t ch02;
Double_t ch03;
Double_t ch04;
Double_t ch05;
Double_t ch06;
Double_t ch07;
Double_t ch08;
Double_t ch09;
Double_t ch10;
Double_t ch11;
Double_t ch12;
Double_t ch13;
Double_t ch14;
Double_t ch15;
Double_t ch16;
Double_t ch17;
Double_t ch18;
Double_t ch19;
Double_t ch20;
Double_t ch21;
Double_t ch22;
Double_t ch23;
Double_t ch24;
Double_t ch25;
Double_t ch26;
Double_t ch27;
Double_t ch28;
Double_t ch29;
Double_t ch30;
Double_t ch31;
Double_t ch32;
Double_t ch33;
Double_t ch34;
Double_t ch35;
Double_t ch36;
Double_t ch37;
Double_t ch38;
Double_t ch39;
Double_t ch40;
Double_t ch41;
Double_t ch42;
Double_t ch43;
Double_t ch44;
Double_t ch45;
Double_t ch46;
Double_t ch47;
Double_t ch48;
Double_t ch49;
Double_t ch50;
Double_t ch51;
Double_t ch52;
Double_t ch53;
Double_t ch54;
Double_t ch55;
Double_t ch56;
Double_t ch57;
Double_t ch58;
Double_t ch59;
Double_t ch60;
Double_t ch61;
Double_t ch62;
Double_t ch63;
Double_t ch64;
Double_t ch65;
Double_t ch66;
Double_t ch67;
Double_t ch68;
Double_t ch69;
Double_t ch70;
Double_t ch71;
Double_t ch72;
Double_t ch73;
Double_t ch74;
Double_t ch75;
Double_t ch76;
Double_t ch77;
Double_t ch78;
Double_t ch79;
Double_t ch80;
Double_t ch81;
Double_t ch82;
Double_t ch83;
Double_t ch84;
Double_t ch85;
Double_t ch86;
Double_t ch87;
Double_t ch88;
Double_t ch89;
Double_t ch90;
Double_t ch91;
Double_t ch92;
Double_t ch93;
Double_t ch94;
Double_t ch95;
Double_t ch96;
Double_t ch97;
Double_t ch98;
Double_t ch99;
Double_t ch100;
Double_t ch101;
Double_t ch102;
Double_t ch103;
Double_t ch104;
Double_t ch105;
Double_t ch106;
Double_t ch107;
Double_t ch108;
Double_t ch109;
Double_t ch110;
Double_t ch111;
Double_t ch112;
Double_t ch113;
Double_t ch114;
Double_t ch115;
Double_t ch116;
Double_t ch117;
Double_t ch118;
Double_t ch119;
Double_t ch120;
Double_t ch121;
Double_t ch122;
Double_t ch123;
Double_t ch124;
Double_t ch125;
Double_t ch126;
Double_t ch127;
Double_t ic1;
Double_t ic2;
Double_t mw1_focusx;
Double_t mw1_focusy;
Double_t mw2_focusx;
Double_t mw2_focusy;
Double_t mw1_posx;
Double_t mw1_posy;
Double_t mw2_posx;
Double_t mw2_posy;
// List of branches
TBranch *b_time; //!
TBranch *b_event_id; //!
TBranch *b_sync_out; //!
TBranch *b_sync_in; //!
TBranch *b_data_ok; //!
TBranch *b_led_voltage; //!
TBranch *b_current; //!
TBranch *b_ch00; //!
TBranch *b_ch01; //!
TBranch *b_ch02; //!
TBranch *b_ch03; //!
TBranch *b_ch04; //!
TBranch *b_ch05; //!
TBranch *b_ch06; //!
TBranch *b_ch07; //!
TBranch *b_ch08; //!
TBranch *b_ch09; //!
TBranch *b_ch10; //!
TBranch *b_ch11; //!
TBranch *b_ch12; //!
TBranch *b_ch13; //!
TBranch *b_ch14; //!
TBranch *b_ch15; //!
TBranch *b_ch16; //!
TBranch *b_ch17; //!
TBranch *b_ch18; //!
TBranch *b_ch19; //!
TBranch *b_ch20; //!
TBranch *b_ch21; //!
TBranch *b_ch22; //!
TBranch *b_ch23; //!
TBranch *b_ch24; //!
TBranch *b_ch25; //!
TBranch *b_ch26; //!
TBranch *b_ch27; //!
TBranch *b_ch28; //!
TBranch *b_ch29; //!
TBranch *b_ch30; //!
TBranch *b_ch31; //!
TBranch *b_ch32; //!
TBranch *b_ch33; //!
TBranch *b_ch34; //!
TBranch *b_ch35; //!
TBranch *b_ch36; //!
TBranch *b_ch37; //!
TBranch *b_ch38; //!
TBranch *b_ch39; //!
TBranch *b_ch40; //!
TBranch *b_ch41; //!
TBranch *b_ch42; //!
TBranch *b_ch43; //!
TBranch *b_ch44; //!
TBranch *b_ch45; //!
TBranch *b_ch46; //!
TBranch *b_ch47; //!
TBranch *b_ch48; //!
TBranch *b_ch49; //!
TBranch *b_ch50; //!
TBranch *b_ch51; //!
TBranch *b_ch52; //!
TBranch *b_ch53; //!
TBranch *b_ch54; //!
TBranch *b_ch55; //!
TBranch *b_ch56; //!
TBranch *b_ch57; //!
TBranch *b_ch58; //!
TBranch *b_ch59; //!
TBranch *b_ch60; //!
TBranch *b_ch61; //!
TBranch *b_ch62; //!
TBranch *b_ch63; //!
TBranch *b_ch64; //!
TBranch *b_ch65; //!
TBranch *b_ch66; //!
TBranch *b_ch67; //!
TBranch *b_ch68; //!
TBranch *b_ch69; //!
TBranch *b_ch70; //!
TBranch *b_ch71; //!
TBranch *b_ch72; //!
TBranch *b_ch73; //!
TBranch *b_ch74; //!
TBranch *b_ch75; //!
TBranch *b_ch76; //!
TBranch *b_ch77; //!
TBranch *b_ch78; //!
TBranch *b_ch79; //!
TBranch *b_ch80; //!
TBranch *b_ch81; //!
TBranch *b_ch82; //!
TBranch *b_ch83; //!
TBranch *b_ch84; //!
TBranch *b_ch85; //!
TBranch *b_ch86; //!
TBranch *b_ch87; //!
TBranch *b_ch88; //!
TBranch *b_ch89; //!
TBranch *b_ch90; //!
TBranch *b_ch91; //!
TBranch *b_ch92; //!
TBranch *b_ch93; //!
TBranch *b_ch94; //!
TBranch *b_ch95; //!
TBranch *b_ch96; //!
TBranch *b_ch97; //!
TBranch *b_ch98; //!
TBranch *b_ch99; //!
TBranch *b_ch100; //!
TBranch *b_ch101; //!
TBranch *b_ch102; //!
TBranch *b_ch103; //!
TBranch *b_ch104; //!
TBranch *b_ch105; //!
TBranch *b_ch106; //!
TBranch *b_ch107; //!
TBranch *b_ch108; //!
TBranch *b_ch109; //!
TBranch *b_ch110; //!
TBranch *b_ch111; //!
TBranch *b_ch112; //!
TBranch *b_ch113; //!
TBranch *b_ch114; //!
TBranch *b_ch115; //!
TBranch *b_ch116; //!
TBranch *b_ch117; //!
TBranch *b_ch118; //!
TBranch *b_ch119; //!
TBranch *b_ch120; //!
TBranch *b_ch121; //!
TBranch *b_ch122; //!
TBranch *b_ch123; //!
TBranch *b_ch124; //!
TBranch *b_ch125; //!
TBranch *b_ch126; //!
TBranch *b_ch127; //!
TBranch *b_ic1; //!
TBranch *b_ic2; //!
TBranch *b_mw1_focusx; //!
TBranch *b_mw1_focusy; //!
TBranch *b_mw2_focusx; //!
TBranch *b_mw2_focusy; //!
TBranch *b_mw1_posx; //!
TBranch *b_mw1_posy; //!
TBranch *b_mw2_posx; //!
TBranch *b_mw2_posy; //!
char *file;
TFile *fileIn;
TFile *fileOut;
TObjArray objectArray;
TBranch *b_channels[128];
TBranch *b_baseline[128];
double channels[128];
double channelamp_smooth[128];
double baseline[128];
double channellist[128];
double errorx[128];
double errory[128];
TBranch *b_beamNumX_1;
TBranch *b_beamPosX_1;
TBranch *b_beamFocusX_1;
TBranch *b_beamSignal_1;
TBranch *b_beamSidebandNoise_1;
TBranch *b_beamSkewX_1;
TBranch *b_beamKurtX_1;
TBranch *b_beamPosX_fit;
TBranch *b_beamFocusX_fit;
TBranch *b_beamChi2_fit;
TBranch *b_beamPeakX_fit;
TBranch *b_beamPosX_fit2;
TBranch *b_beamFocusX_fit2;
TBranch *b_beamChi2_fit2;
TBranch *b_beamPeakX_fit2;
TBranch *b_ic1_1; //!
TBranch *b_ic2_1; //!
TBranch *b_mw1_focusx_1; //!
TBranch *b_mw1_focusy_1; //!
TBranch *b_mw2_focusx_1; //!
TBranch *b_mw2_focusy_1; //!
TBranch *b_mw1_posx_1; //!
TBranch *b_mw1_posy_1; //!
TBranch *b_mw2_posx_1; //!
TBranch *b_mw2_posy_1; //!
TBranch *b_baseline_integral;
TBranch *b_time_1; //!
TBranch *b_eventid_1; //!
TBranch *b_rollingavg; //!
TBranch *b_beamon; //!
double time_1;
double ic1_1;
double ic2_1;
double mw1_focusx_1;
double mw2_focusx_1;
double mw2_posx_1;
double mw1_posx_1;
double mw1_focusy_1;
double mw2_focusy_1;
double mw2_posy_1;
double mw1_posy_1;
double beamNumX_1;
double beamPosX_1;
double beamFocusX_1;
double beamSignal_1;
double beamSidebandNoise_1;
double beamSkewX_1;
double beamKurtX_1;
double baseline_integral;
double chargeintegral;
double timeintegral;
double eventid_1;
double rollingavg;
int beamon;
double beamPosX_fit;
double beamFocusX_fit;
double beamChi2_fit;
double beamPeakX_fit;
double beamPosX_fit2;
double beamFocusX_fit2;
double beamChi2_fit2;
double beamPeakX_fit2;
analyse2(TTree *tree=0);
virtual ~analyse2();
virtual Int_t Cut(Long64_t entry);
virtual Int_t GetEntry(Long64_t entry);
virtual Long64_t LoadTree(Long64_t entry);
virtual void Init(TTree *tree);
virtual void Loop();
virtual Bool_t Notify();
virtual void Show(Long64_t entry = -1);
double channelWidth;
void Initialize(const char *dirname, const char *filename, int baselineEvents = 1000, int prelimEvents = 10000, double beamLevel = 0.1, bool firstFibermat = true, double readOutFrequency = 1000., int integrationTime = 100);
void Baseline(bool useFirstEvents, int nBaselineEvents, int StartEvent, bool run50hz);
void Save();
void Close();
double * FFTsmoothing(double arr[]);
// double RollingAverage(const int length, double newdata);
TH2D * th2d_mw1_beamPosX;
TH2D * th2d_ic1_beamSignal;
TH1D * th1d_beamSignal_ic1ratio;
TH2D * th2d_beamSignal_channel;
TH2D * th2d_bkg_channel;
TH1D * th1d_baseline;
TH1D * th1d_baselinesub;
TH1D * th1d_chbaseline;
TH1D * th1d_chbaselinesub;
TH2D * th2d_fitdiff_channel;
TH2D * th2d_fit2diff_channel;
TH2D * th2d_AmpFFT_channel;
TH2D * th2d_PhaseFFT_channel;
TFitResultPtr bkgfitResult;
Double_t bkgfitPar0[130];
Double_t bkgfitPar1[130];
Double_t bkgfitPar2[130];
Double_t bkgfitPar3[130];
Double_t bkgfitPar4[130];
};
#endif
#ifdef analyse2_cxx
analyse2::analyse2(TTree *tree) : fChain(0)
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
if (tree == 0) {
cerr << "no TTree found." << endl;
}
Init(tree);
}
analyse2::~analyse2()
{
if (!fChain) return;
delete fChain->GetCurrentFile();
}
Int_t analyse2::GetEntry(Long64_t entry)
{
// Read contents of entry.
if (!fChain) return 0;
return fChain->GetEntry(entry);
}
Long64_t analyse2::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
if (!fChain) return -5;
Long64_t centry = fChain->LoadTree(entry);
if (centry < 0) return centry;
if (fChain->GetTreeNumber() != fCurrent) {
fCurrent = fChain->GetTreeNumber();
Notify();
}
return centry;
}
void analyse2::Init(TTree *tree)
{
// The Init() function is called when the selector needs to initialize
// a new tree or chain. Typically here the branch addresses and branch
// pointers of the tree will be set.
// It is normally not necessary to make changes to the generated
// code, but the routine can be extended by the user if needed.
// Init() will be called many times when running on PROOF
// (once per file to be processed).
// Set branch addresses and branch pointers
if (!tree) return;
fChain = tree;
fCurrent = -1;
fChain->SetMakeClass(1);
fChain->SetBranchAddress("time", &time, &b_time);
fChain->SetBranchAddress("event_id", &event_id, &b_event_id);
fChain->SetBranchAddress("sync_out", &sync_out, &b_sync_out);
fChain->SetBranchAddress("sync_in", &sync_in, &b_sync_in);
fChain->SetBranchAddress("data_ok", &data_ok, &b_data_ok);
fChain->SetBranchAddress("led_voltage", &led_voltage, &b_led_voltage);
fChain->SetBranchAddress("current", &current, &b_current);
fChain->SetBranchAddress("ch00", &ch00, &b_ch00);
fChain->SetBranchAddress("ch01", &ch01, &b_ch01);
fChain->SetBranchAddress("ch02", &ch02, &b_ch02);
fChain->SetBranchAddress("ch03", &ch03, &b_ch03);
fChain->SetBranchAddress("ch04", &ch04, &b_ch04);
fChain->SetBranchAddress("ch05", &ch05, &b_ch05);
fChain->SetBranchAddress("ch06", &ch06, &b_ch06);
fChain->SetBranchAddress("ch07", &ch07, &b_ch07);
fChain->SetBranchAddress("ch08", &ch08, &b_ch08);
fChain->SetBranchAddress("ch09", &ch09, &b_ch09);
fChain->SetBranchAddress("ch10", &ch10, &b_ch10);
fChain->SetBranchAddress("ch11", &ch11, &b_ch11);
fChain->SetBranchAddress("ch12", &ch12, &b_ch12);
fChain->SetBranchAddress("ch13", &ch13, &b_ch13);
fChain->SetBranchAddress("ch14", &ch14, &b_ch14);
fChain->SetBranchAddress("ch15", &ch15, &b_ch15);
fChain->SetBranchAddress("ch16", &ch16, &b_ch16);
fChain->SetBranchAddress("ch17", &ch17, &b_ch17);
fChain->SetBranchAddress("ch18", &ch18, &b_ch18);
fChain->SetBranchAddress("ch19", &ch19, &b_ch19);
fChain->SetBranchAddress("ch20", &ch20, &b_ch20);
fChain->SetBranchAddress("ch21", &ch21, &b_ch21);
fChain->SetBranchAddress("ch22", &ch22, &b_ch22);
fChain->SetBranchAddress("ch23", &ch23, &b_ch23);
fChain->SetBranchAddress("ch24", &ch24, &b_ch24);
fChain->SetBranchAddress("ch25", &ch25, &b_ch25);
fChain->SetBranchAddress("ch26", &ch26, &b_ch26);
fChain->SetBranchAddress("ch27", &ch27, &b_ch27);
fChain->SetBranchAddress("ch28", &ch28, &b_ch28);
fChain->SetBranchAddress("ch29", &ch29, &b_ch29);
fChain->SetBranchAddress("ch30", &ch30, &b_ch30);
fChain->SetBranchAddress("ch31", &ch31, &b_ch31);
fChain->SetBranchAddress("ch32", &ch32, &b_ch32);
fChain->SetBranchAddress("ch33", &ch33, &b_ch33);
fChain->SetBranchAddress("ch34", &ch34, &b_ch34);
fChain->SetBranchAddress("ch35", &ch35, &b_ch35);
fChain->SetBranchAddress("ch36", &ch36, &b_ch36);
fChain->SetBranchAddress("ch37", &ch37, &b_ch37);
fChain->SetBranchAddress("ch38", &ch38, &b_ch38);
fChain->SetBranchAddress("ch39", &ch39, &b_ch39);
fChain->SetBranchAddress("ch40", &ch40, &b_ch40);
fChain->SetBranchAddress("ch41", &ch41, &b_ch41);
fChain->SetBranchAddress("ch42", &ch42, &b_ch42);
fChain->SetBranchAddress("ch43", &ch43, &b_ch43);
fChain->SetBranchAddress("ch44", &ch44, &b_ch44);
fChain->SetBranchAddress("ch45", &ch45, &b_ch45);
fChain->SetBranchAddress("ch46", &ch46, &b_ch46);
fChain->SetBranchAddress("ch47", &ch47, &b_ch47);
fChain->SetBranchAddress("ch48", &ch48, &b_ch48);
fChain->SetBranchAddress("ch49", &ch49, &b_ch49);
fChain->SetBranchAddress("ch50", &ch50, &b_ch50);
fChain->SetBranchAddress("ch51", &ch51, &b_ch51);
fChain->SetBranchAddress("ch52", &ch52, &b_ch52);
fChain->SetBranchAddress("ch53", &ch53, &b_ch53);
fChain->SetBranchAddress("ch54", &ch54, &b_ch54);
fChain->SetBranchAddress("ch55", &ch55, &b_ch55);
fChain->SetBranchAddress("ch56", &ch56, &b_ch56);
fChain->SetBranchAddress("ch57", &ch57, &b_ch57);
fChain->SetBranchAddress("ch58", &ch58, &b_ch58);
fChain->SetBranchAddress("ch59", &ch59, &b_ch59);
fChain->SetBranchAddress("ch60", &ch60, &b_ch60);
fChain->SetBranchAddress("ch61", &ch61, &b_ch61);
fChain->SetBranchAddress("ch62", &ch62, &b_ch62);
fChain->SetBranchAddress("ch63", &ch63, &b_ch63);
fChain->SetBranchAddress("ch64", &ch64, &b_ch64);
fChain->SetBranchAddress("ch65", &ch65, &b_ch65);
fChain->SetBranchAddress("ch66", &ch66, &b_ch66);
fChain->SetBranchAddress("ch67", &ch67, &b_ch67);
fChain->SetBranchAddress("ch68", &ch68, &b_ch68);
fChain->SetBranchAddress("ch69", &ch69, &b_ch69);
fChain->SetBranchAddress("ch70", &ch70, &b_ch70);
fChain->SetBranchAddress("ch71", &ch71, &b_ch71);
fChain->SetBranchAddress("ch72", &ch72, &b_ch72);
fChain->SetBranchAddress("ch73", &ch73, &b_ch73);
fChain->SetBranchAddress("ch74", &ch74, &b_ch74);
fChain->SetBranchAddress("ch75", &ch75, &b_ch75);
fChain->SetBranchAddress("ch76", &ch76, &b_ch76);
fChain->SetBranchAddress("ch77", &ch77, &b_ch77);
fChain->SetBranchAddress("ch78", &ch78, &b_ch78);
fChain->SetBranchAddress("ch79", &ch79, &b_ch79);
fChain->SetBranchAddress("ch80", &ch80, &b_ch80);
fChain->SetBranchAddress("ch81", &ch81, &b_ch81);
fChain->SetBranchAddress("ch82", &ch82, &b_ch82);
fChain->SetBranchAddress("ch83", &ch83, &b_ch83);
fChain->SetBranchAddress("ch84", &ch84, &b_ch84);
fChain->SetBranchAddress("ch85", &ch85, &b_ch85);
fChain->SetBranchAddress("ch86", &ch86, &b_ch86);
fChain->SetBranchAddress("ch87", &ch87, &b_ch87);
fChain->SetBranchAddress("ch88", &ch88, &b_ch88);
fChain->SetBranchAddress("ch89", &ch89, &b_ch89);
fChain->SetBranchAddress("ch90", &ch90, &b_ch90);
fChain->SetBranchAddress("ch91", &ch91, &b_ch91);
fChain->SetBranchAddress("ch92", &ch92, &b_ch92);
fChain->SetBranchAddress("ch93", &ch93, &b_ch93);
fChain->SetBranchAddress("ch94", &ch94, &b_ch94);
fChain->SetBranchAddress("ch95", &ch95, &b_ch95);
fChain->SetBranchAddress("ch96", &ch96, &b_ch96);
fChain->SetBranchAddress("ch97", &ch97, &b_ch97);
fChain->SetBranchAddress("ch98", &ch98, &b_ch98);
fChain->SetBranchAddress("ch99", &ch99, &b_ch99);
fChain->SetBranchAddress("ch100", &ch100, &b_ch100);
fChain->SetBranchAddress("ch101", &ch101, &b_ch101);
fChain->SetBranchAddress("ch102", &ch102, &b_ch102);
fChain->SetBranchAddress("ch103", &ch103, &b_ch103);
fChain->SetBranchAddress("ch104", &ch104, &b_ch104);
fChain->SetBranchAddress("ch105", &ch105, &b_ch105);
fChain->SetBranchAddress("ch106", &ch106, &b_ch106);
fChain->SetBranchAddress("ch107", &ch107, &b_ch107);
fChain->SetBranchAddress("ch108", &ch108, &b_ch108);
fChain->SetBranchAddress("ch109", &ch109, &b_ch109);
fChain->SetBranchAddress("ch110", &ch110, &b_ch110);
fChain->SetBranchAddress("ch111", &ch111, &b_ch111);
fChain->SetBranchAddress("ch112", &ch112, &b_ch112);
fChain->SetBranchAddress("ch113", &ch113, &b_ch113);
fChain->SetBranchAddress("ch114", &ch114, &b_ch114);
fChain->SetBranchAddress("ch115", &ch115, &b_ch115);
fChain->SetBranchAddress("ch116", &ch116, &b_ch116);
fChain->SetBranchAddress("ch117", &ch117, &b_ch117);
fChain->SetBranchAddress("ch118", &ch118, &b_ch118);
fChain->SetBranchAddress("ch119", &ch119, &b_ch119);
fChain->SetBranchAddress("ch120", &ch120, &b_ch120);
fChain->SetBranchAddress("ch121", &ch121, &b_ch121);
fChain->SetBranchAddress("ch122", &ch122, &b_ch122);
fChain->SetBranchAddress("ch123", &ch123, &b_ch123);
fChain->SetBranchAddress("ch124", &ch124, &b_ch124);
fChain->SetBranchAddress("ch125", &ch125, &b_ch125);
fChain->SetBranchAddress("ch126", &ch126, &b_ch126);
fChain->SetBranchAddress("ch127", &ch127, &b_ch127);
fChain->SetBranchAddress("ic1", &ic1, &b_ic1);
fChain->SetBranchAddress("ic2", &ic2, &b_ic2);
fChain->SetBranchAddress("mw1_focusx", &mw1_focusx, &b_mw1_focusx);
fChain->SetBranchAddress("mw1_focusy", &mw1_focusy, &b_mw1_focusy);
fChain->SetBranchAddress("mw2_focusx", &mw2_focusx, &b_mw2_focusx);
fChain->SetBranchAddress("mw2_focusy", &mw2_focusy, &b_mw2_focusy);
fChain->SetBranchAddress("mw1_posx", &mw1_posx, &b_mw1_posx);
fChain->SetBranchAddress("mw1_posy", &mw1_posy, &b_mw1_posy);
fChain->SetBranchAddress("mw2_posx", &mw2_posx, &b_mw2_posx);
fChain->SetBranchAddress("mw2_posy", &mw2_posy, &b_mw2_posy);
// v->ResizeTo(10);
Notify();
}
Bool_t analyse2::Notify()
{
// The Notify() function is called when a new file is opened. This
// can be either for a new TTree in a TChain or when when a new TTree
// is started when using PROOF. It is normally not necessary to make changes
// to the generated code, but the routine can be extended by the
// user if needed. The return value is currently not used.
return kTRUE;
}
void analyse2::Show(Long64_t entry)
{
// Print contents of entry.
// If entry is not specified, print current entry
if (!fChain) return;
fChain->Show(entry);
}
Int_t analyse2::Cut(Long64_t entry)
{
// This function may be called from Loop.
// returns 1 if entry is accepted.
// returns -1 otherwise.
return 1;
}
void analyse2::Initialize(const char *dirname, const char *filename, int baselineEvents, int prelimEvents, double beamLevel, bool firstFibermat, double readOutFrequency, int integrationTime)
{
TString fn = TString(filename);
TString dn = TString(dirname);
channelWidth = 0.8;
TString inName = dn + "pin/" + fn;
fileIn = new TFile(inName, "READ");
fileIn->GetObject("t", fChain);
fChain->Print();
Init(fChain);
TString outname = filename;
outname.Insert(0, "SAVE_");
outname.Insert(0, dirname);
fileOut = new TFile(outname.Data(), "RECREATE");
newdata = new TTree("newdata", "newdata");
for (int n = 0; n < 128; n++)
{
baseline[n] = 0.;
channellist[n] = double(n);
errorx[n] = 0.0;
errory[n] = 7.0;
char bname[20];
sprintf(bname, "ch%02d", n);
b_channels[n] = fChain->GetBranch(bname);
b_channels[n]->SetAddress(&channels[n]);
}
b_eventid_1 = newdata->Branch("eventid_1", &eventid_1);
b_beamNumX_1 = newdata->Branch("beamNumX_1", &beamNumX_1);
b_beamPosX_1 = newdata->Branch("beamPosX_1", &beamPosX_1);
b_beamFocusX_1 = newdata->Branch("beamFocusX_1", &beamFocusX_1);
b_beamSignal_1 = newdata->Branch("beamSignal_1", &beamSignal_1);
b_beamSidebandNoise_1 = newdata->Branch("beamSidebandNoise_1", &beamSidebandNoise_1);
b_beamSkewX_1 = newdata->Branch("beamSkewX_1", &beamSkewX_1);
b_beamKurtX_1 = newdata->Branch("beamKurtX_1", &beamKurtX_1);
b_beamPosX_fit = newdata->Branch("beamPosX_fit", &beamPosX_fit);
b_beamFocusX_fit = newdata->Branch("beamFocusX_fit", &beamFocusX_fit);
b_beamChi2_fit = newdata->Branch("beamChi2_fit", &beamChi2_fit);
b_beamPeakX_fit = newdata->Branch("beamPeakX_fit", &beamPeakX_fit);
b_beamPosX_fit2 = newdata->Branch("beamPosX_fit2", &beamPosX_fit2);
b_beamFocusX_fit2 = newdata->Branch("beamFocusX_fit2", &beamFocusX_fit2);
b_beamChi2_fit2 = newdata->Branch("beamChi2_fit2", &beamChi2_fit2);
b_beamPeakX_fit2 = newdata->Branch("beamPeakX_fit2", &beamPeakX_fit2);
b_ic1_1 = newdata->Branch("ic1_1", &ic1_1);
b_ic2_1 = newdata->Branch("ic2_1", &ic2_1);
b_mw1_focusx_1 = newdata->Branch("mw1_focusx_1", &mw1_focusx_1);
b_mw1_posx_1 = newdata->Branch("mw1_posx_1", &mw1_posx_1);
b_mw2_focusx_1 = newdata->Branch("mw2_focusx_1", &mw2_focusx_1);
b_mw2_posx_1 = newdata->Branch("mw2_posx_1", &mw2_posx_1);
b_mw1_focusy_1 = newdata->Branch("mw1_focusy_1", &mw1_focusy_1);
b_mw1_posy_1 = newdata->Branch("mw1_posy_1", &mw1_posy_1);
b_mw2_focusy_1 = newdata->Branch("mw2_focusy_1", &mw2_focusy_1);
b_mw2_posy_1 = newdata->Branch("mw2_posy_1", &mw2_posy_1);
b_rollingavg = newdata->Branch("rollingavg", &rollingavg);
b_beamon = newdata->Branch("beamon", &beamon);
b_time_1 = newdata->Branch("time_1", &time_1);
//histograms;
th2d_mw1_beamPosX = new TH2D("th2d_mw1_beamPosX","th2d_mw1_beamPosX",1000,0,64,1000,0,60);
th2d_ic1_beamSignal = new TH2D("th2d_ic1_beamSignal","th2d_ic1_beamSignal",500,0,500,500,0,100000);
th1d_beamSignal_ic1ratio = new TH1D("th1d_beamSignal_ic1ratio","th1d_beamSignal_ic1ratio",500,0,500.);
th2d_beamSignal_channel = new TH2D("th2d_beamSignal_channel","th2d_beamSignal_channel",129,-0.5,128.5,5100,-1000,10000);
th2d_fitdiff_channel = new TH2D("th2d_fitdiff_channel","th2d_fitdiff_channel",129,-0.5,128.5,510,-1000,1000);
th2d_fit2diff_channel = new TH2D("th2d_fit2diff_channel","th2d_fit2diff_channel",129,-0.5,128.5,510,-1000,1000);
th2d_bkg_channel = new TH2D("th2d_bkg_channel","th2d_bkg_channel",65,-0.5,64.5,500,-500,500);
th1d_baseline = new TH1D("th1d_baseline","th1d_baseline",500,-1500,1500.);
th1d_baselinesub = new TH1D("th1d_baselinesub","th1d_baselinesub",500,-1500,1500.);
th1d_chbaseline = new TH1D("th1d_chbaseline","th1d_chbaseline",2100,-100,1000.);
th1d_chbaselinesub = new TH1D("th1d_chbaselinesub","th1d_chbaselinesub",200,-100,100.);
}
void analyse2::Baseline(bool useFirstEvents, const int nBaselineEvents, int startevent, bool run50hz)
{
Long64_t nevents = fChain->GetEntriesFast();
baseline_integral = 0.;
// use the first/last nBaselineEvents events to calculate the average/baseline
cout << "Start background subtraction event:" << startevent << endl;
const int numbaseline = 1800;
Double_t channelamp[numbaseline];
Double_t basetime[numbaseline] = {0.};
TGraph * g1;
TF1 * fitfunc = new TF1("fitfunc","[0]+[1]*TMath::Cos(x*[2]*(2*3.14159)+[3])");
fitfunc->SetParameters( 0.0, 10.0, 0.05, 0.0 );
fitfunc->FixParameter(2,0.05);
fChain->GetEvent(1);
Double_t basetimeoffsetzero = time;
fChain->GetEvent(startevent+numbaseline);
Double_t basetimeoffset = time-basetimeoffsetzero;
fChain->GetEvent(startevent);
Double_t basetimeoffsetstart = time-basetimeoffsetzero;
Int_t counter = 0;
char bname[20];
for (int ch = 0; ch < 128; ch++)
{
baseline[ch] =0.;
}
if (!useFirstEvents)
{ // last
for (int i = nevents- numbaseline; i < nevents; i++)
{
fChain->GetEvent(i);
for (int ch = 0; ch < 128; ch++)
{
if (channels[ch]>-100) baseline[ch] += channels[ch] / double(numbaseline);
if (channels[ch]>-100) baseline_integral +=baseline[ch];
th1d_chbaseline->Fill(channels[ch]);
}
}
// cout << "baseline int: " << baseline_integral << endl;
}
else
{
for (int i = startevent ; i <= startevent+ numbaseline; i++)
{
fChain->GetEvent(i);
for (int ch = 0; ch < 128; ch++)
{
if (channels[ch]>-100) baseline[ch] += channels[ch] / double(numbaseline);
if (channels[ch]>-100) baseline_integral +=baseline[ch];
th1d_chbaseline->Fill(channels[ch]);
}
// cout << "baseline int: " << baseline_integral << endl;
}
}
if (run50hz){
///fit a 50Hz background noise to each channel
for (int ch = 0; ch < 128; ch++)
{
counter = 0;
for (int i = startevent ; i < startevent+numbaseline; i++)
{
fChain->GetEvent(i);
// for (int ch = 0; ch < 64; ch++)
//{
channelamp[counter]= channels[ch]- baseline[ch];
//}
basetime[counter] = time-basetimeoffsetzero;
counter++;
}
g1 = new TGraph(numbaseline,basetime,channelamp);
///////finished here. 1) need to fit the baseline to a Cosine function 2) return 3 parameters per channel. 50 Hz is fixed.
bkgfitResult = g1->Fit(fitfunc,"QSR","",basetimeoffsetstart,basetimeoffset );
bkgfitPar0[ch] = bkgfitResult->Parameter(0);
bkgfitPar1[ch] = bkgfitResult->Parameter(1);
bkgfitPar2[ch] = bkgfitResult->Parameter(2);
bkgfitPar3[ch] = bkgfitResult->Parameter(3);
sprintf(bname, "bkg_ch%02d_graph", ch);
g1->SetTitle(bname);
g1->SetName(bname);
//fitResult->Print("V");
// bkgfitResult->Write();
g1->Write();
} //end for (int ch = ...
for (int ch = 0; ch < 128; ch++)
{
counter = 0;
fitfunc->SetParameters( bkgfitPar0[ch], bkgfitPar1[ch], bkgfitPar2[ch], bkgfitPar3[ch]);
for (Long64_t i = startevent ; i <startevent+ numbaseline; i++)
{
fChain->GetEvent(i);
channelamp[counter] = channels[ch]- baseline[ch]- fitfunc->Eval(time-basetimeoffsetzero);
th1d_chbaselinesub->Fill(channelamp[counter]);
counter++;
th2d_bkg_channel->Fill(ch,channelamp[counter]);
}
}
Double_t channelampsum[numbaseline] = {0.};
counter = 0;
///fit a 50Hz background noise to the sum of all channels
for (Long64_t i = startevent ; i <startevent+ numbaseline; i++)
{
fChain->GetEvent(i);
channelampsum[counter]=0.;
for (int ch = 0; ch < 128; ch++){
if (channels[ch]>-100 && baseline[ch]>-100) channelampsum[counter] += channels[ch] - baseline[ch]; //integrate the signal
}
basetime[counter] = (time-basetimeoffsetzero);
counter++;
}
TGraph * g2 = new TGraph(counter,basetime,channelampsum);
TF1 * fitfunc2 = new TF1("fitfunc2","[0]+[1]*TMath::Cos(x*[2]*(2*3.14159)+[3])");
fitfunc2->SetParameters( 5120.0, 450.0, 0.05, 0.0 );
// fitfunc2->SetParLimits(1,0.,1000.);
fitfunc2->FixParameter(2,0.05);
TFitResultPtr sumbkgfitResult = g2->Fit(fitfunc2,"QRS","", basetimeoffsetstart, basetimeoffset);
g2->SetName("commonmodenoise"); g2->SetTitle("commonmodenoise");
// g2->Write();
sumbkgfitResult->Write();
// fitfunc2->Write();
bkgfitPar0[128] = fitfunc2->GetParameter(0);
bkgfitPar1[128] = fitfunc2->GetParameter(1);
bkgfitPar2[128] = fitfunc2->GetParameter(2);
bkgfitPar3[128] = fitfunc2->GetParameter(3);
counter=0;
for (Long64_t i = startevent ; i <startevent+ numbaseline; i++)
{
fChain->GetEvent(i);
channelampsum[counter] -= fitfunc2->Eval(time-basetimeoffsetzero);
th1d_baselinesub->Fill(channelampsum[counter]);
counter++;
}
th1d_baseline->Write();
th1d_baselinesub->Write();
th1d_chbaseline->Write();
th1d_chbaselinesub->Write();
TGraph * g3 = new TGraph(counter,basetime,channelampsum);
g3->SetName("commonmodenoisesub"); g2->SetTitle("commonmodenoisesub");
g3->Write();
}
}
void analyse2::Save()
{
//fileIn->Close();
//fileOut->cd();
newdata->AutoSave();
}
void analyse2::Close()
{
fileIn->Close();
fileOut->Close();
if(fChain) delete fChain->GetCurrentFile();
}
#endif // #ifdef analyse2_cxx