Skip to content

Commit f4c9c7c

Browse files
committed
working version
1 parent 81fea66 commit f4c9c7c

3 files changed

Lines changed: 130 additions & 93 deletions

File tree

outTree.C

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#define outTree_cxx
22
#include "outTree.h"
33
#include <TH2.h>
4-
#include "TH1F.h"
54
#include <TStyle.h>
65
#include <TCanvas.h>
76
#include <iostream>
7+
#include "TH1F.h"
8+
#include <math.h>
9+
810
void outTree::Loop()
911
{
1012
// In a ROOT session, you can do:
@@ -30,47 +32,49 @@ void outTree::Loop()
3032
// METHOD2: replace line
3133
// fChain->GetEntry(jentry); //read all branches
3234
//by b_branchname->GetEntry(ientry); //read only this branch
33-
if (fChain == 0) return;
35+
TH1F* h = new TH1F("h", "muon spectrum", 1000, .0, 18.5);
36+
TH1F* h1 = new TH1F("h1", "Pulse Output1", 2499, -2.68000004411e-08, 2.31600001399e-08);
37+
TH1F* h2 = new TH1F("h2", "Pulse Output2", 2499, -2.68000004411e-08, 2.31600001399e-08);
38+
TH1F* h3 = new TH1F("h3", "Pulse Output3", 2499, -2.68000004411e-08, 2.31600001399e-08);
39+
float min2 = 1.0;
40+
std::cout.precision(16);
41+
3442

35-
TH1F* h = new TH1F("h", "muon spectrum", 1000, .0, .5);
36-
TH1F* h1 = new TH1F("h1", "Pulse Output1", 2499, -2.68000004411e-08, 2.31600001399e-08);
37-
TH1F* h2 = new TH1F("h2", "Pulse Output2", 2499, -2.68000004411e-08, 2.31600001399e-08);
38-
TH1F* h3 = new TH1F("h3", "Pulse Output3", 2499, -2.68000004411e-08, 2.31600001399e-08);
39-
float min2 = 1.0;
40-
41-
Long64_t nentries = fChain->GetEntriesFast();
43+
if (fChain == 0) return;
4244

45+
Long64_t nentries = fChain->GetEntriesFast();
4346
Long64_t nbytes = 0, nb = 0;
44-
for (Long64_t jentry=0; jentry<nentries;jentry++) {
47+
for (Long64_t jentry = 1; jentry < nentries; jentry++) {
4548
Long64_t ientry = LoadTree(jentry);
4649
if (ientry < 0) break;
4750
nb = fChain->GetEntry(jentry); nbytes += nb;
4851
// if (Cut(ientry) < 0) continue;
49-
//std::cout << "entry: " << jentry << std::endl;
52+
if(jentry < 2000){
53+
//std::cout << "entry: " << jentry << std::endl;
54+
//std::cout << "vector size: " << Time->size() << " Time: " << Time->at(0) << " " << Time->at(1) << " " << Time->at(2) << " " << Time->at(Time->size()-1) << std::endl;
55+
}
5056

51-
float min = 1.0;
52-
min2 = 1.0;
53-
int size = Time->size();
54-
//std::cout << "vector size: " << Amp->size() << " Time: " << Time->at(0) << " " << Time->at(1) << " " << Time->at(2) << " " << Time->at(size-1) << std::endl;
55-
//std::cout << "time stamp: " << ptime << std::endl;
56-
for(int j = 0; j < Amp->size(); j++){
57-
if(jentry = 1)h1->Fill(Time->at(j),Amp->at(j));
58-
if(jentry = 109)h2->Fill(Time->at(j),Amp->at(j));
59-
if(jentry = 267)h3->Fill(Time->at(j),Amp->at(j));
60-
if(Amp->at(j) < min2){
61-
min2 = Amp->at(j);
57+
int ctr = 0;
58+
for (std::vector<float>::iterator it = Time->begin() ; it != Time->end(); ++it){
59+
//if(ctr == 0 || ctr == Time->size() -1)std::cout << ' ' << *it << std::endl;
60+
ctr++;
61+
}
62+
int ctr1 = 0;
63+
min2 = 1.0;
64+
for (std::vector<float>::iterator it1 = Amp->begin() ; it1 != Amp->end(); ++it1){
65+
//if(ctr1 == 0 || ctr1 == Amp->size() -1)std::cout << ' ' << *it1 << std::endl;
66+
ctr1++;
67+
if(*it1 < min2){
68+
min2 = *it1;
69+
}
6270
}
63-
}
64-
65-
h->Fill(TMath::Abs(min2));
71+
72+
h->Fill(fabs(min2));
73+
if(min2 < 1.0)std::cout << "min2: " << min2 << std::endl;
74+
6675
}
67-
68-
h1->Draw();
69-
TFile* f1 = new TFile("test.root","RECREATE");
76+
77+
TFile* fout = new TFile("file_out.root", "recreate");
7078
h->Write();
71-
h1->Write();
72-
h2->Write();
73-
h3->Write();
74-
f1->Close();
75-
79+
fout->Close();
7680
}

outTree.h

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//////////////////////////////////////////////////////////
22
// This class has been automatically generated on
3-
// Fri Aug 9 14:57:01 2013 by ROOT version 5.34/09
3+
// Fri Aug 9 16:03:44 2013 by ROOT version 5.34/09
44
// from TTree outTree/outTree
5-
// found on file: /media/data/cmorgoth/scope_data/NoCrystalData/NoCrystalData.root
5+
// found on file: /media/data/cmorgoth/scope_data/data_Scope_Total.root
66
//////////////////////////////////////////////////////////
77

88
#ifndef outTree_h
@@ -48,17 +48,17 @@ public :
4848
#ifdef outTree_cxx
4949
outTree::outTree(TTree *tree) : fChain(0)
5050
{
51-
// if parameter tree is not specified (or zero), connect the file
52-
// used to generate this class and read the Tree.
53-
if (tree == 0) {
54-
TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("/media/data/cmorgoth/scope_data/NoCrystalData/NoCrystalData.root");
55-
if (!f || !f->IsOpen()) {
56-
f = new TFile("/media/data/cmorgoth/scope_data/NoCrystalData/NoCrystalData.root");
57-
}
58-
f->GetObject("outTree",tree);
59-
60-
}
61-
Init(tree);
51+
// if parameter tree is not specified (or zero), connect the file
52+
// used to generate this class and read the Tree.
53+
if (tree == 0) {
54+
TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("/media/data/cmorgoth/scope_data/data_Scope_Total.root");
55+
if (!f || !f->IsOpen()) {
56+
f = new TFile("/media/data/cmorgoth/scope_data/data_Scope_Total.root");
57+
}
58+
f->GetObject("outTree",tree);
59+
60+
}
61+
Init(tree);
6262
}
6363

6464
outTree::~outTree()
@@ -69,46 +69,46 @@ outTree::~outTree()
6969

7070
Int_t outTree::GetEntry(Long64_t entry)
7171
{
72-
// Read contents of entry.
73-
if (!fChain) return 0;
74-
return fChain->GetEntry(entry);
72+
// Read contents of entry.
73+
if (!fChain) return 0;
74+
return fChain->GetEntry(entry);
7575
}
7676
Long64_t outTree::LoadTree(Long64_t entry)
7777
{
78-
// Set the environment to read one entry
79-
if (!fChain) return -5;
80-
Long64_t centry = fChain->LoadTree(entry);
81-
if (centry < 0) return centry;
82-
if (fChain->GetTreeNumber() != fCurrent) {
83-
fCurrent = fChain->GetTreeNumber();
84-
Notify();
85-
}
86-
return centry;
78+
// Set the environment to read one entry
79+
if (!fChain) return -5;
80+
Long64_t centry = fChain->LoadTree(entry);
81+
if (centry < 0) return centry;
82+
if (fChain->GetTreeNumber() != fCurrent) {
83+
fCurrent = fChain->GetTreeNumber();
84+
Notify();
85+
}
86+
return centry;
8787
}
8888

8989
void outTree::Init(TTree *tree)
9090
{
91-
// The Init() function is called when the selector needs to initialize
92-
// a new tree or chain. Typically here the branch addresses and branch
93-
// pointers of the tree will be set.
94-
// It is normally not necessary to make changes to the generated
95-
// code, but the routine can be extended by the user if needed.
96-
// Init() will be called many times when running on PROOF
97-
// (once per file to be processed).
98-
99-
// Set object pointer
100-
Amp = 0;
101-
Time = 0;
102-
// Set branch addresses and branch pointers
103-
if (!tree) return;
104-
fChain = tree;
105-
fCurrent = -1;
106-
fChain->SetMakeClass(1);
107-
108-
fChain->SetBranchAddress("ptime", &ptime, &b_ptime);
109-
fChain->SetBranchAddress("Amp", &Amp, &b_Amp);
110-
fChain->SetBranchAddress("Time", &Time, &b_Time);
111-
Notify();
91+
// The Init() function is called when the selector needs to initialize
92+
// a new tree or chain. Typically here the branch addresses and branch
93+
// pointers of the tree will be set.
94+
// It is normally not necessary to make changes to the generated
95+
// code, but the routine can be extended by the user if needed.
96+
// Init() will be called many times when running on PROOF
97+
// (once per file to be processed).
98+
99+
// Set object pointer
100+
Amp = 0;
101+
Time = 0;
102+
// Set branch addresses and branch pointers
103+
if (!tree) return;
104+
fChain = tree;
105+
fCurrent = -1;
106+
fChain->SetMakeClass(1);
107+
108+
fChain->SetBranchAddress("ptime", &ptime, &b_ptime);
109+
fChain->SetBranchAddress("Amp", &Amp, &b_Amp);
110+
fChain->SetBranchAddress("Time", &Time, &b_Time);
111+
Notify();
112112
}
113113

114114
Bool_t outTree::Notify()
@@ -119,21 +119,21 @@ Bool_t outTree::Notify()
119119
// to the generated code, but the routine can be extended by the
120120
// user if needed. The return value is currently not used.
121121

122-
return kTRUE;
122+
return kTRUE;
123123
}
124124

125125
void outTree::Show(Long64_t entry)
126126
{
127127
// Print contents of entry.
128128
// If entry is not specified, print current entry
129-
if (!fChain) return;
130-
fChain->Show(entry);
129+
if (!fChain) return;
130+
fChain->Show(entry);
131131
}
132132
Int_t outTree::Cut(Long64_t entry)
133133
{
134-
// This function may be called from Loop.
135-
// returns 1 if entry is accepted.
136-
// returns -1 otherwise.
134+
// This function may be called from Loop.
135+
// returns 1 if entry is accepted.
136+
// returns -1 otherwise.
137137
return 1;
138138
}
139139
#endif // #ifdef outTree_cxx

spectrum.cc

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
{
1+
#include <iostream>
2+
#include <vector>
3+
#include "TMath.h"
4+
#include "TFile.h"
5+
#include "TH1F.h"
6+
#include "TTree.h"
7+
#include "TROOT.h"
8+
#include "TBranch.h"
9+
#include "TSystem.h"
10+
11+
12+
//#ifdef __MAKECINT__
13+
//#pragma link C++ class vector<float>+;
14+
//#endif
15+
16+
int main(){
217
gROOT->Reset();
18+
std::cout << "here it breaks -1" << std::endl;
19+
gROOT->ProcessLine("#include <vector>");
20+
std::cout << "here it breaks -2" << std::endl;
321

422
TFile* f = new TFile("/media/data/cmorgoth/scope_data/NoCrystalData/NoCrystalData.root");
523
TTree* tree = (TTree*)f->Get("outTree");
624

725
std::cout.precision(12);
26+
827
double ptime;
9-
std::vector<float> *Amp;
10-
std::vector<float> *Time;
28+
std::vector<float> *Amp;
29+
std::vector<float> *Time;
30+
TBranch *BTime = 0;
31+
TBranch *BAmp = 0;
32+
33+
//tree->SetBranchAddress("ptime", &ptime);
34+
//tree->SetBranchAddress("Amp", &Amp, &BAmp);
35+
//tree->SetBranchAddress("Time", &Time, &BTime);
1136

1237
tree->SetBranchAddress("ptime", &ptime);
1338
tree->SetBranchAddress("Amp", &Amp);
@@ -18,13 +43,18 @@
1843
TH1F* h2 = new TH1F("h2", "Pulse Output2", 2499, -2.68000004411e-08, 2.31600001399e-08);
1944
TH1F* h3 = new TH1F("h3", "Pulse Output3", 2499, -2.68000004411e-08, 2.31600001399e-08);
2045
float min2 = 1.0;
21-
for(int i = 0; i < tree->GetEntries(); i++){
46+
47+
48+
for(int i = 0; i < 10/*tree->GetEntries()*/; i++){
2249
tree->GetEntry(i);
50+
//BTime->GetEntry(i);
51+
//BAmp->GetEntry(i);
52+
std::cout << "here it breaks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
2353
float min = 1.0;
2454
min2 = 1.0;
25-
int size = Time->size();
26-
std::cout << "vector size: " << Amp->size() << " Time: " << Time->at(0) << " " << Time->at(1) << " " << Time->at(2) << " " << Time->at(size-1) << std::endl;
27-
std::cout << " Time: " << Time->at(0)-Time->at(1) << " " << Time->at(1)-Time->at(2) << " " << Time->at(2)-Time->at(3) << " " << Time->at(size-1) << std::endl;
55+
//int size = Time->size();
56+
//std::cout << "vector size: " << Amp->size() << " Time: " << Time->at(0) << " " << Time->at(1) << " " << Time->at(2) << " " << Time->at(size-1) << std::endl;
57+
//std::cout << " Time: " << Time->at(0)-Time->at(1) << " " << Time->at(1)-Time->at(2) << " " << Time->at(2)-Time->at(3) << " " << Time->at(size-1) << std::endl;
2858
//std::cout << "time stamp: " << ptime << std::endl;
2959
for(int j = 0; j < Amp->size(); j++){
3060
if(i = 1)h1->Fill(Time->at(j),Amp->at(j));
@@ -36,10 +66,11 @@
3666
}
3767

3868
h->Fill(TMath::Abs(min2));
39-
if(min2 != 1.0)std::cout << "Min: " << min2 << std::endl;
69+
//if(min2 != 1.0)std::cout << "Min: " << min2 << std::endl;
4070

4171
}
4272

73+
4374
h1->Draw();
4475
TFile* f1 = new TFile("test.root","RECREATE");
4576
h->Write();
@@ -48,4 +79,6 @@
4879
h3->Write();
4980
f1->Close();
5081
f->Close();
82+
83+
return 0;
5184
}

0 commit comments

Comments
 (0)