analyse.cpp 3.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <fstream>

#include "TString.h"
#include "TFile.h"
#include "TError.h"
#include "TTree.h"
#include <stdio.h>
#include <stdlib.h>

#include "../dataClasses/RawEvent.h"
#include "../dataClasses/AEvent.h"

int main(int argc, char* argv[])
14
{
15 16 17

	//to be extracted from the source as parameters
	const Int_t noBranches = 4;
18 19
	const Double_t cfRatio = 0.3;
	const Double_t cfTD = 1.5; //in ns
20 21
	Double_t noiseMin = 5;
	Double_t noiseMax = 25;
22
	Int_t nump = 5;		//number of points for smoothing
23 24 25



26
	if ( (argc < 3) || (argc > 5) ) {
27
		// Tell the user how to run the program
28
		std::cerr << "Usage: " << argv[0] << " [list with input files] [outputfile] [smoothParameter (1 - smoothed, 0 - not)] [number of points in one event (1000 or 1024)]" << std::endl;
29 30 31 32 33
		/* "Usage messages" are a conventional way of telling the user
		 * how to run a program if they enter the command incorrectly.
		 */
		return 1;
	}
34

35 36
	TString infiles = argv[1];
	TString ofile = argv[2];
37 38 39 40
	TString smooth = argv[3];
	TString Asize = argv[4];
	Int_t kEventSize,intSmoth;
	Bool_t smoothPar = kFALSE;
41 42 43

	if(argc==3) {
		kEventSize = 1024;
44 45
		noiseMin = 10.;
		noiseMax = 100.;
46 47
		Info("convertRawToAnalyzed", "Event size was set to %d", kEventSize);
	}
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

	if(argc>3) {
		intSmoth = smooth.Atoi();
		if((intSmoth!=1) && (intSmoth!=0)) {
			std::cerr<< argv[3] << " smoothpar should be 1 or 0 " << std::endl;
			return 1;
		}
		if( intSmoth == 1 ) {
			smoothPar = kTRUE;
			Info("convertRawToAnalyzed", "we gona SMOOTH");
		}
		else {Info("convertRawToAnalyzed", "we NOT gonna SMOOTH");}
	}

	if(argc==5) {
63
		kEventSize = Asize.Atoi();
64 65
		if((kEventSize!=1000) && ((kEventSize!=1024))) {
			std::cerr<< argv[0] << " the size of Events should be 1000 or 1024 " << std::endl;
66 67 68
			return 1;
		} 
	}
69

70
	TFile *f = new TFile(infiles.Data());
71 72
	if (/*f == 0 || */f->IsZombie()) {
		Error("convertRawToAnalyzed", "Input file was not opened. Program will be terminated");
73
		return 1;
74
	}
75 76 77
	TTree *tr = (TTree*)f->Get("rtree");

	TString bName;
78
	RawEvent *revent[noBranches];
79
	for (Int_t j = 0; j<noBranches; j++) {
80
		revent[j] = new RawEvent(kEventSize);	//each Aevent element is of class AEvent()
81
		bName.Form("ch%d.", j);
82
		tr->SetBranchAddress(bName.Data(), &revent[j]);
83 84
	}

85
	TFile *fw = new TFile(ofile.Data(), "RECREATE");	//create .root file with somehow analyzed data
86 87 88 89
	TTree *tw = new TTree("atree", "title of drs4 analysis tree");	//create analysis tree atree in it

	AEvent *wevent[noBranches];	// pointer to the array (of AEvent class) in which analyzed data for each channel will be put
	for (Int_t j = 0; j<noBranches; j++) {
90
		wevent[j] = new AEvent(kEventSize);
91 92 93 94
		bName.Form("Ach%d.", j);
		wevent[j]->SetInputEvent(&revent[j]);	//takes raw event from RawEvent
		wevent[j]->SetCFratio(cfRatio);
		wevent[j]->SetCFtimeDelay(cfTD);
95
		wevent[j]->SetNoiseRange(noiseMin, noiseMax);
96
		wevent[j]->SetSmoothPoints(nump);
97 98 99 100 101 102 103
		tw->Bronch(bName.Data(), "AEvent", &wevent[j]);	// create branches in atree to hold analyzed data
	}
//----event loop in tr input tree
	Long64_t nentries = tr->GetEntries();

	for(Long64_t i = 0; i < nentries; i++) {
		tr->GetEntry(i);
104
		//cout<<" Event "<<i<<endl;
105 106
		for (Int_t j = 0; j<noBranches; j++) {
			wevent[j]->Reset();
107
			wevent[j]->ProcessEvent(smoothPar);	//here all the analysis is going on so far
108 109
		}

110
		if ( !(i%100) ) { printf("Found event #%lld\n", i); }
111 112 113 114
		tw->Fill();
	}

//----end of event loop
115
	printf("%lld events are processed\n", nentries);
116 117 118 119

	tw->Write();
	fw->Close();

120
	return 0;
121
}