analyse.cpp 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
void analyse()
{
	gSystem->Load("../libData.so");

	TFile *f = new TFile("../data/rawDataDSR4/NeuRad_test_07_1.root");
	TTree *tr = (TTree*)f->Get("rtree");

	const Int_t noBranches = 4;
	const Double_t cfRatio = 0.5;
	const Int_t cfTD = 5;

	TString bName;
	RawEvent *revent[noBranches];	// pointer to the array (of RawEvent class) in which raw data for each channel will be put
	for (Int_t j = 0; j<noBranches; j++) {
		revent[j] = new RawEvent();	//each raw event element is of class RawEvent()
		bName.Form("ch%d.", j);
		tr->SetBranchAddress(bName.Data(), &revent[j]);	//read the tree tr with raw data and fill array revent with raw data
	}

//	tr->SetMakeClass(1);

	TFile *fw = new TFile("../data/dataDSR4/analysis_07_1.root", "RECREATE");	//create .root file with somehow analyzed data
	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++) {
		wevent[j] = new AEvent();
		bName.Form("Ach%d.", j);
		wevent[j]->SetInputEvent(&revent[j]);	//takes raw event from RawEvent
		wevent[j]->SetCFratio(cfRatio);
		wevent[j]->SetCFtimeDelay(cfTD);
		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

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

	return;
}