Skip to content
Snippets Groups Projects
Commit 7842c916 authored by Cesar Jesus-Valls's avatar Cesar Jesus-Valls
Browse files

working code for ASCII -> TTree of Classes -> Read TTree in template

parent 1c6f6cbb
Branches
No related tags found
No related merge requests found
......@@ -71,8 +71,10 @@ void dataConverter() {
if(x.size() == 4){
cout << "new event: " << x[2] << endl;
if(stoi(x[2])>1){
Event->SetSignals(chSigMap);
Event->SetSignals(chSigMap);
cout << Event->GetSignals().size() << endl;
dataOut->Fill(); // store the previous event
chSigMap.clear();
//Event->ResetEvent();
}
jumpToNextLine = true;
......
......@@ -12,73 +12,71 @@
#include "../../tools/global_header.hh"
// //____DEFINE_GLOBAL_SCOPE_VARIABLES____: this needs to be declared before global_tools!
// bool batch = false;
// int maxEvents = std::numeric_limits<int>::max();;
// int maxSelEvents = std::numeric_limits<int>::max();;
// int selEvents = 0;
// float start_time = clock();
// TString fileOut = "~/Desktop/templateAna_Out.root";
// TString fileIn = "../../data/204_56_188/Reconstructed_SFGD_MC.root";
// TFile* FileInput;
// TFile* FileOutput;
// TTree* dataOut;
// TTree* data;
// ND280SFGDEvent* inputEvent;
// ND280SFGDEvent* recoEvent;
// TBranch* recoBranch;
// TBranch* inputBranch;
// int nEvents;
// Event* unpackEvent;
// #include "../src/tools/global_tools.cc"
// #include "../src/tools/reconstruction_methods.hh"
void templateAna() {
// TTree* output = new TTree();
// output->SetBranch("treeofevents", Event);
cout << "work in progres..." << endl;
/// ------------START--------------
// ReadFile();
// TH1F * h_baseline = new TH1F("h_baseline", "h_baseline", 10,0,10);
// for(ievt=0; ievt<nevts; i++){
// data->GetEntry(ievt);
#include "../../tools/global_header.hh"
float start_time = clock();
bool batch = true;
TString fileIn = "events.root";
TString fileOut = "output_ana.root";
TFile* FileOutput ; TFile* FileInput;
TTree* dataOut ; TTree* dataIn;
#include "../../tools/global_tools.cc"
void templateAna() {
/// ------------IGNORE THIS PART OF THE CODE --------------
FileOutput = new TFile(fileOut.Data(),"RECREATE");
if(!FileOutput) {cout << "no output file! exit." << endl; exit(1);}
dataOut = new TTree("Events","Events");
ToFEvent* anaEvent = new ToFEvent();
TBranch* anaBranch = dataOut->Branch("anaEvent", "anaEvent", anaEvent);
anaBranch->Reset();
anaBranch->SetAddress(&anaEvent);
FileInput = new TFile(fileIn.Data(),"update");
if(!FileInput) {cout << "no input file! exit." << endl; exit(1);}
dataIn = (TTree*) FileInput->Get("Events");
int nEvents = dataIn->GetEntries();
TBranch* inputBranch = dataIn->GetBranch("Event");
ToFEvent* dataEvent = new ToFEvent();
inputBranch->SetAddress(&dataEvent);
// std::vector<ToFSignal*> signals = Event->GetToFSignals();
// for(auto s:singals){
// h_baseline->Fill(s->GetBaseline());
// }
// }
cout << "--- Starting Analysis Template ---" << endl;
cout << "input filename: " << fileIn.Data() << endl;
cout << "output filename: " << fileOut.Data() << endl;
/// ---------------------------------------------------------
// TCanvas *c = new TCanvas("c");
// c->cd();
// h_baseline->Draw("HIST");
// c->Update();
/// ------------DECLARE OBJECTS TO STORE RESULTS-------------
/// ------------START YOUR ANALYSIS--------------
for(int ievt=0; ievt<nEvents; ievt++){
dataIn->GetEntry(ievt);
//________ANALYSIS_OF_EVT_STARTS_____//
//
// ---> Write here your analysis.
//
//________ANALYSIS_OF_EVT_ENDS________//
cout << "====== EVENT " << ievt << "======" << endl;
map<int, ToFSignal*> signals = dataEvent->GetSignals();
for (const auto& kv : signals) {
std::cout << "--- CH " << kv.first << " ---" << endl;
TH1F* h_waveform = new TH1F("h_waveform","", 1024,0,1023);
for(int w(0); w<1024; w++){
if (w>10) h_waveform->SetBinContent(w,kv.second->Waveform[w]);
else h_waveform->SetBinContent(w,0); // prevent first bins with strange values to be shown.
//if(w<10) cout << w << ", " << kv.second->Waveform[w] << endl;
}
TCanvas* c = new TCanvas("c");
c->cd();
h_waveform->Draw("HIST");
c->Update();
c->WaitPrimitive();
delete h_waveform; delete c;
}
}
writeOutput();
handleEndOfExecution();
}
No preview for this file type
No preview for this file type
......@@ -10,22 +10,17 @@ using namespace ROOT::Math;
class ToFSignal : public TObject {
private:
//------------------
Double_t Baseline; // baseline
public:
// baseline substracted:
Double_t Baseline; // baseline
Double_t Waveform [1024]; // Waveform
Double_t AmpMax; // Maximum value for the amplitude
Double_t Integral; // Integral for the Waveform
//------------------
public:
ToFSignal(std::vector<std::string> x){
for(int i=0;i<1024;i++) Waveform[i] = std::stof(x[i]);
std::cout << "example wvf: " << Waveform[378] << std::endl;
};
ToFSignal(){
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment