analyse.cpp 2.71 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 18 19 20 21 22 23 24 25

	//to be extracted from the source as parameters
	const Int_t noBranches = 4;
	const Double_t cfRatio = 0.5;
	const Int_t cfTD = 5;
	Double_t noiseMin = 5;
	Double_t noiseMax = 25;




26
	if ( (argc < 3) || (argc > 4) ) {
27
		// Tell the user how to run the program
28
		std::cerr << "Usage: " << argv[0] << " [list with input files] [outputfile] [number of points in one event (1000)]" << 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 41
	TString Asize = argv[3];
	Int_t kEventSize;

	if(argc==3) {
		kEventSize = 1024;
42 43
		noiseMin = 10.;
		noiseMax = 100.;
44 45 46 47 48 49 50 51 52
		Info("convertRawToAnalyzed", "Event size was set to %d", kEventSize);
	}
	if(argc==4) {
		kEventSize = Asize.Atoi();
		if(kEventSize!=1000) {
			std::cerr<< argv[0] << " the size of Events should be 1000 in this case " << std::endl;
			return 1;
		} 
	}
53

54
	TFile *f = new TFile(infiles.Data());
55 56 57
	TTree *tr = (TTree*)f->Get("rtree");

	TString bName;
58
	RawEvent *revent[noBranches];
59
	for (Int_t j = 0; j<noBranches; j++) {
60
		revent[j] = new RawEvent(kEventSize);	//each Aevent element is of class AEvent()
61
		bName.Form("ch%d.", j);
62
		tr->SetBranchAddress(bName.Data(), &revent[j]);
63 64
	}

65

66

67
	TFile *fw = new TFile(ofile.Data(), "RECREATE");	//create .root file with somehow analyzed data
68 69 70 71
	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++) {
72
		wevent[j] = new AEvent(kEventSize);
73 74 75 76
		bName.Form("Ach%d.", j);
		wevent[j]->SetInputEvent(&revent[j]);	//takes raw event from RawEvent
		wevent[j]->SetCFratio(cfRatio);
		wevent[j]->SetCFtimeDelay(cfTD);
77
		wevent[j]->SetNoiseRange(noiseMin, noiseMax);
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
		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);
		if ( !(tr->GetEntry(i)%100) ) {
			printf("Found event #%d\n", tr->GetEntry(i));
		}

		for (Int_t j = 0; j<noBranches; j++) {
			wevent[j]->Reset();
			wevent[j]->ProcessEvent();	//here all the analysis is going on so far
		}

		tw->Fill();
	}

//----end of event loop
98
	printf("%lld events are processed\n", nentries);
99 100 101 102

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

103
	return 1;
104
}