SignalFormNEW.cpp

рисовальный макрос - Ivan Muzalevsky, 12/21/2017 12:45 PM

Download (5.75 KB)

 
1
#include "TH1F.h"
2

    
3
void SignalFormNEW(        const char *foldername = "report",        const char *ext = ".gif")
4
{
5
        //gSystem->Load("../libData.so");
6
        using std::cout;
7
        using std::endl;
8

    
9
        TFile *f = new TFile("/home/muzalevsky/work/dataER/simNeuRad/analyze_4000_0_test.root");
10
        //TFile fr("../data/dataTektronix/GSItests/1000V_trigg40mv/30_60_10_50_GSI.root");
11
        TTree *tr = (TTree*)f->Get("cbmsim");
12

    
13
        const Int_t noBranches = 2;
14
        Double_t ZeroTime[4],mh[4],RisTime[4],decayT[4];
15
        Int_t iZero[4],PosZero[4],deltaT[4],Eh[4],Bh[4]; 
16
        TString bName;
17
        ERNeuRadAEvent *aevent[noBranches];        // pointer to the array (of RawEvent class) in which raw data for each channel will be put
18
        for (Int_t j = 0; j<noBranches; j++) {
19
                aevent[j] = new ERNeuRadAEvent(1000);        //each raw event element is of class RawEvent()
20
                bName.Form("Ach%d.", j+1);
21
                tr->SetBranchAddress(bName.Data(), &aevent[j]);        //read the tree tr with raw data and fill array revent with raw data
22
                //cout << tr->SetBranchAddress(bName.Data(), &aevent[j]) << endl;        //read the tree tr with raw data and fill array revent with raw data
23
        }
24

    
25
        TString hname,Chname;
26
                TH1F *hist[2];
27
                for (Int_t i = 0; i < 2; i++) {
28
                        hname.Form("hist%d",i);
29
                        Chname.Form("Integral form of the signal SIM");
30
                        hist[i] = new TH1F(hname.Data(), Chname.Data(), 1000, 0, 100);
31
                }
32

    
33
                TF1 *fit1 = new TF1("fit1","-[0]*exp(-x*[1])");
34
                        //fit1->SetRange(-15,-5);
35
                        fit1->SetParName(1,"tD");
36

    
37
                        Long64_t nEntries = tr->GetEntries();
38

    
39
                        //loop over events
40
                        for (Int_t j = 0; j < nEntries; j++) {
41
                        //{ Int_t j=0;
42
                                //cout<<"found event number "<<j<<endl;
43
                                tr->GetEntry(j);
44
                                for(Int_t k=0;k<2;k++) { // loop for channels
45
                                        ZeroTime[k] = aevent[k]->GetfLED(); // get LEDtime for channel №k
46
                                        //ZeroTime[k] = aevent[k]->GetfCFD(); // get LEDtime for channel №k
47
                                        iZero[k] = ZeroTime[k]*10;
48
                                        if(j==0) { PosZero[k] = iZero[k]; }
49
                                        deltaT[k] = iZero[k] - PosZero[k];
50
                                }
51

    
52
                                        for(Int_t i = 0; i<1000; i++){
53
                                                if( ((i+deltaT[0])>-1) && ((i+deltaT[0])<1000))        hist[0]->AddBinContent(i,aevent[0]->GetOnefAmpPos(i+deltaT[0]));
54
                                                if( ((i+deltaT[1])>-1) && ((i+deltaT[1])<1000))        hist[1]->AddBinContent(i,aevent[1]->GetOnefAmpPos(i+deltaT[1]));
55
                                        }
56
                        }
57

    
58
                TCanvas *c1 = new TCanvas("c1","testSIM",10,10,1000,600);
59
                        //c1->Divide(2,2);
60
                        Int_t i=0;
61
                        //for(Int_t i=0;i<2;i++)
62
                        {
63
                                //c1->cd(i+1);file8000_20.root 
64

    
65
                                hist[i]->GetYaxis()->SetTitle("Signal [V]");
66
                                hist[i]->GetYaxis()->CenterTitle();
67

    
68
                                hist[i]->GetXaxis()->SetTitle("Time [ns]");
69
                                hist[i]->GetXaxis()->CenterTitle();
70

    
71
                                hist[i]->GetXaxis()->SetRangeUser(0, 30);
72

    
73
                                hist[i]->Draw();
74
                                c1->Update();
75
                        }
76

    
77

    
78

    
79

    
80
        TFile *f1 = new TFile("/home/muzalevsky/work/dataER/analyzeEXP.root");
81
        //TFile fr("../data/dataTektronix/GSItests/1000V_trigg40mv/30_60_10_50_GSI.root");
82
        TTree *tr1 = (TTree*)f1->Get("cbmsim");
83

    
84
        ERNeuRadAEvent *aevent1[noBranches];        // pointer to the array (of RawEvent class) in which raw data for each channel will be put
85
        for (Int_t j = 0; j<noBranches; j++) {
86
                aevent1[j] = new ERNeuRadAEvent(1024);        //each raw event element is of class RawEvent()
87
                bName.Form("Ach%d.", j+1);
88
                tr1->SetBranchAddress(bName.Data(), &aevent[j]);        //read the tree tr with raw data and fill array revent with raw data
89
        }
90

    
91
                TH1F *hist1[2];
92
                for (Int_t i = 0; i < 2; i++) {
93
                        hname.Form("hist1%d",i);
94
                        Chname.Form("Integral form of the signal EXP");
95
                        hist1[i] = new TH1F(hname.Data(), Chname.Data(), 1024, 0, 100);
96
                }
97
                nEntries = tr1->GetEntries();
98

    
99
                        //loop over events
100
                        for (Int_t j = 0; j < nEntries; j++) {
101
                                //cout<<"found event number "<<j<<endl;
102
                                tr1->GetEntry(j);
103
                                for(Int_t k=0;k<2;k++) { // loop for channels
104
                                        ZeroTime[k] = aevent1[k]->GetfLED(); // get fCFD for channel №k
105
                                        //ZeroTime[k] = aevent1[k]->GetfCFD();
106
                                        iZero[k] = ZeroTime[k]*10;
107
                                        if(j==0) { PosZero[k] = iZero[k]; }
108
                                        deltaT[k] = iZero[k] - PosZero[k];
109
                                }
110

    
111
                                        for(Int_t i = 0; i<1024; i++){
112
                                                if( ((i+deltaT[0])>-1) && ((i+deltaT[0])<1024))        hist1[0]->AddBinContent(i, aevent[0]->GetOnefAmpPos(i+deltaT[0]));
113
                                                if( ((i+deltaT[1])>-1) && ((i+deltaT[1])<1024))        hist1[1]->AddBinContent(i, aevent[1]->GetOnefAmpPos(i+deltaT[1]));
114
                                        }
115
                        }
116

    
117
//------------------------------------------- finding Nbins of max summAMP 
118
                        Double_t max1,max2;
119
                        Int_t n1,n2;
120
                        for(Int_t i=0;i<1000;i++){
121
                                if(hist[0]->GetBinContent(i) > max1) {
122
                                        max1 = hist[0]->GetBinContent(i);
123
                                        n1 = i;
124
                                }
125

    
126
                                if(hist1[0]->GetBinContent(i) > max2) {
127
                                        max2 = hist1[0]->GetBinContent(i);
128
                                        n2 = i;
129
                                }
130
                        }
131
                        cout << n1 << " " << n2 << endl;
132
//------------------------------------------- 
133
                        TH1F *h1 = new TH1F("h1","summEXPhist",1000,0,100);
134
                        TH1F *h2 = new TH1F("h2","summSIMhist",1000,0,100);
135

    
136

    
137
                        for(Int_t i =0; i<1000;i++) {
138
                                if(i > (n2-n1)) {
139
                                        h1->SetBinContent( i - (n2-n1), (max1/max2)*hist1[0]->GetBinContent(i));
140
                                }
141
                                else {h1->SetBinContent(i, 0);}
142
                        }
143

    
144
                /*        for(Int_i = 0;i<1000;i++) {
145
                                if(i<(500 + n1)) {
146
                                        h1->SetBinContent( i + (500-n1), (max1/max2)*hist1[0]->GetBinContent(i) );
147
                                }
148
                                else {h1->SetBinContent(i, 0);}
149

150
                                if(i>(n2 - 500)) {
151
                                        h2->SetBinContent( i - (n2-500), hist[0]->GetBinContent(i) );
152
                                }
153
                                else {h2->SetBinContent(i, 0);}
154
                        }*/
155

    
156
                        //h1->Draw();
157
                        //h2->Draw("SAME");
158
                                h1->GetYaxis()->SetTitle("Signal [V]");
159
                                h1->GetYaxis()->CenterTitle();
160

    
161
                                h1->GetXaxis()->SetTitle("Time [ns]");
162
                                h1->GetXaxis()->CenterTitle();
163
                                h1->SetLineColor(kRed);
164
                                h1->Draw("SAME");
165

    
166

    
167
                //TCanvas *c2 = new TCanvas("c2","testEXP",10,10,1000,600);
168
                //i=0;
169
                        //for(Int_t i=0;i<2;i++)
170
                                //c1->cd(i+1);
171
                        /*        hist1[i]->GetYaxis()->SetTitle("Signal [V]");
172
                                hist1[i]->GetYaxis()->CenterTitle();
173

174
                                hist1[i]->GetXaxis()->SetTitle("Time [ns]");
175
                                hist1[i]->GetXaxis()->CenterTitle();
176
                                hist1[i]->SetLineColor(kRed);
177
                                hist1[i]->Draw();
178
*/
179
                                //c2->Update();
180
                        //}
181

    
182

    
183
}