BmnRoot
Loading...
Searching...
No Matches
BmnHistToF.cxx
Go to the documentation of this file.
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/*
8 * File: BmnHistToF.cxx
9 * Author: ilnur
10 *
11 * Created on November 27, 2016, 4:24 PM
12 */
13
14#include "BmnHistToF.h"
15
16#include "BmnRawDataDecoder.h"
17
18BmnHistToF::BmnHistToF(TString title, TString path)
19 : BmnHist()
20{
21 fTitle = title;
22 fName = title + "_cl";
23 fSelectedPlane = -1;
24 fSelectedStrip = -1;
25 fSelectedSide = -1;
26 TString name;
27 name = fTitle + "_Leading_Time";
28 histLeadingTime = new TH1D(name, name, 500, 0, 2500);
29 histLeadingTime->GetXaxis()->SetTitle("Time, ns");
30 histLeadingTime->GetYaxis()->SetTitle("Activations count");
31 name = fTitle + "_Leading_Time_Specific";
32 histLeadingTimeSpecific = new TH1D(name, name, 500, 0, 2500);
33 histLeadingTimeSpecific->GetXaxis()->SetTitle("Time, ns");
34 histLeadingTimeSpecific->GetYaxis()->SetTitle("Activations count");
35 name = fTitle + "_Amplitude";
36 histAmp = new TH1D(name, name, 4096, 0, 96);
37 histAmp->GetXaxis()->SetTitle("Amplitude, ns");
38 histAmp->GetYaxis()->SetTitle("Activations count");
39 TGaxis* ay = (TGaxis*)histAmp->GetYaxis();
40 ay->SetMaxDigits(2);
41 name = fTitle + "_Amplitude_Specific";
42 histAmpSpecific = new TH1D(name, name, 4096, 0, 96);
43 histAmpSpecific->GetXaxis()->SetTitle("Amplitude, ns");
44 histAmpSpecific->GetYaxis()->SetTitle("Activations count");
45 name = fTitle + "_Strip";
46 histStrip = new TH1I(name, name, TOF400_STRIP_COUNT, 0, TOF400_STRIP_COUNT);
47 histStrip->GetXaxis()->SetTitle("Strip #");
48 histStrip->GetYaxis()->SetTitle("Activations count");
49 histAmp->GetYaxis()->SetNoExponent(kFALSE);
50 name = fTitle + "_StripSimult";
51 histStripSimult = new TH1I(name, name, TOF400_STRIP_COUNT, 0, TOF400_STRIP_COUNT);
52 histStripSimult->GetXaxis()->SetTitle("Strip count");
53 histStripSimult->GetYaxis()->SetTitle("Activations count");
54 name = fTitle + "_State";
55 histState = new TH2F(name, name, TOF400_STRIP_COUNT, 0, TOF400_STRIP_COUNT, 2, 0, 2);
56 histState->GetXaxis()->SetTitle("Strip #");
57 histState->GetYaxis()->SetTitle("Side");
58 name = fTitle + "_State2D";
59 histStrip2d =
61 histStrip2d->GetXaxis()->SetTitle("Strip #");
62 histStrip2d->GetYaxis()->SetTitle("Plane #");
63
64 histSimultaneous.SetDirectory(0);
65 histL->SetDirectory(0);
66 histR->SetDirectory(0);
67 fServer = NULL;
68 frecoTree = NULL;
69 Events = NULL;
70 name = fTitle + "Canvas2d";
71 can2d = new TCanvas(name, name, PAD_WIDTH * 2, PAD_HEIGHT * 1);
72 can2d->Divide(2, 1);
73 can2dPads.resize(2 * 1);
74 for (Int_t iPad = 0; iPad < 2 * 1; iPad++) {
75 PadInfo* p = new PadInfo();
76 can2dPads[iPad] = p;
77 p->opt = "colz nostat";
78 }
79 can2dPads[0]->current = histStrip2d;
80 can2dPads[1]->current = histState;
81 name = fTitle + "CanvasTimes";
82 canTimes = new TCanvas(name, name, PAD_WIDTH * TOF_ROWS, PAD_HEIGHT * TOF_COLS);
83 canTimes->Divide(TOF_ROWS, TOF_COLS);
84 canTimesPads.resize(TOF_ROWS * TOF_COLS);
85 for (Int_t iPad = 0; iPad < TOF_ROWS * TOF_COLS; iPad++) {
86 PadInfo* p = new PadInfo();
87 canTimesPads[iPad] = p;
88 canTimes->GetPad(iPad + 1)->SetGrid();
89 }
90 canTimesPads[0]->current = histLeadingTime;
91 canTimesPads[1]->current = histAmp;
92 canTimesPads[2]->current = histLeadingTimeSpecific;
93 canTimesPads[3]->current = histAmpSpecific;
94 canTimesPads[4]->current = histStrip;
95 canTimesPads[5]->current = histStripSimult;
96 for (size_t iPad = 0; iPad < canTimesPads.size(); iPad++)
97 if (canTimesPads[iPad]->current) {
98 Names.push_back(canTimesPads[iPad]->current->GetName());
99 BmnHist::SetHistStyleTH1(canTimesPads[iPad]->current);
100 }
101 for (size_t iPad = 0; iPad < can2dPads.size(); iPad++)
102 if (can2dPads[iPad]->current) {
103 // Names.push_back(canTimesPads[iPad]->current->GetName());
104 BmnHist::SetHistStyleTH1(can2dPads[iPad]->current);
105 }
106}
107
109{
110 delete histL;
111 delete histR;
112 delete Events;
113 delete canTimes;
114 delete can2d;
115 if (fDir)
116 return;
117 for (auto pad : canTimesPads)
118 delete pad;
119 for (auto pad : can2dPads)
120 delete pad;
121}
122
124{
125 TClonesArray* digits = fDigiArrays->tof400;
126 if (!digits)
127 return;
128 histL->Reset();
129 histR->Reset();
130 histSimultaneous.Reset();
131 Events->Clear();
132 for (Int_t digIndex = 0; digIndex < digits->GetEntriesFast(); digIndex++) {
133 BmnTof1Digit* td = (BmnTof1Digit*)digits->At(digIndex);
134 Int_t strip = td->GetStrip();
135 if ((strip == 0) || (strip == (TOF400_STRIP_COUNT - 1))) // noisy
136 continue;
137 histLeadingTime->Fill(td->GetTime());
138 histAmp->Fill(td->GetAmplitude());
139 histStrip->Fill(strip);
140 histStrip2d->Fill(strip, td->GetPlane(), 1);
141 if ((td->GetPlane() == fSelectedPlane)) {
142 histState->Reset();
143 histState->Fill(td->GetStrip(), td->GetSide(), td->GetAmplitude());
144 }
145 if (td->GetSide() == 0)
146 histL->Fill(strip);
147 else
148 histR->Fill(strip);
149 if (((td->GetPlane() == fSelectedPlane) || (fSelectedPlane < 0))
150 && ((td->GetStrip() == fSelectedStrip) || (fSelectedStrip < 0))
151 && ((td->GetSide() == fSelectedSide) || (fSelectedSide < 0)))
152 {
153 histAmpSpecific->Fill(td->GetAmplitude());
154 histLeadingTimeSpecific->Fill(td->GetTime());
155 }
156
157 // new ((*Events)[Events->GetEntriesFast()])
158 // BmnTof1Digit(td->GetPlane(), td->GetStrip(), td->GetSide(), td->GetTime(),
159 // td->GetAmplitude());
160 // frecoTree->Fill();
161 }
162 // histSimultaneous = (*histL) * (*histR);
163 Int_t s;
164 histStripSimult->ResetStats();
165 for (Int_t binIndex = 1; binIndex < TOF400_STRIP_COUNT; binIndex++) {
166 s = ((histL->GetBinContent(binIndex) * histR->GetBinContent(binIndex)) != 0) ? 1 : 0;
167 if (s)
168 histStripSimult->AddBinContent(s);
169 }
170 // if (fEventsBranch != NULL)
171 // fEventsBranch->Fill();
172}
173
174void BmnHistToF::Register(THttpServer* serv)
175{
176 fServer = serv;
177 fServer->Register("/", this);
178 TString path = "/" + fTitle + "/";
179 fServer->Register(path, canTimes);
180 fServer->Register(path, can2d);
181
182 TString cmd = "/" + fName + "/->SetRefRun(%arg1%)";
183 TString cmdTitle = path + "SetRefRun";
184 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(), "button;");
185 fServer->Restrict(cmdTitle.Data(), "visible=shift");
186 fServer->Restrict(cmdTitle.Data(), "allow=shift");
187 fServer->Restrict(cmdTitle.Data(), "deny=guest");
188 cmdTitle = path + "ChangeSelection";
189 fServer->RegisterCommand(cmdTitle, TString("/") + fName.Data() + "/->SetSelection(%arg1%,%arg2%,%arg3%)",
190 "button;");
191 fServer->Restrict(cmdTitle, "visible=shift");
192 fServer->Restrict(cmdTitle, "allow=shift");
193 fServer->Restrict(cmdTitle.Data(), "deny=guest");
194 cmdTitle = path + TString("Reset");
195 fServer->RegisterCommand(cmdTitle, TString("/") + fName.Data() + "/->Reset()", "button;");
196 fServer->Restrict(cmdTitle.Data(), "visible=shift");
197 fServer->Restrict(cmdTitle.Data(), "allow=shift");
198 // fServer->Restrict(cmdTitle.Data(), "deny=guest");
199}
200
201void BmnHistToF::SetDir(TFile* outFile, TTree* recoTree)
202{
203 frecoTree = recoTree;
204 fDir = NULL;
205 if (outFile != NULL)
206 fDir = outFile->mkdir(fTitle + "_hists");
207 histLeadingTime->SetDirectory(fDir);
208 histLeadingTimeSpecific->SetDirectory(fDir);
209 histAmp->SetDirectory(fDir);
210 histAmpSpecific->SetDirectory(fDir);
211 histStrip->SetDirectory(fDir);
212 histStripSimult->SetDirectory(fDir);
213 histState->SetDirectory(fDir);
214 if (Events != NULL)
215 delete Events;
216 Events = new TClonesArray("BmnTof1Digit");
217 if (frecoTree != NULL)
218 frecoTree->Branch(fTitle.Data(), &Events);
219}
220
221void BmnHistToF::SetSelection(Int_t Plane, Int_t Strip, Int_t Side)
222{
223 SetPlane(Plane);
224 SetStrip(Strip);
225 SetSide(Side);
226 TString command;
227 if (fSelectedPlane >= 0)
228 command = Form("%s.fPlane == %d", fTitle.Data(), fSelectedPlane);
229 if (fSelectedStrip >= 0) {
230 if (command.Length() > 0)
231 command = command + " && ";
232 command = command + Form("%s.fStrip == %d", fTitle.Data(), fSelectedStrip);
233 }
234 if (fSelectedSide >= 0) {
235 if (command.Length() > 0)
236 command = command + " && ";
237 command = command + Form("%s.fSide == %d", fTitle.Data(), fSelectedSide);
238 }
239 histAmpSpecific->Reset();
240 histLeadingTimeSpecific->Reset();
241 histAmpSpecific->SetTitle("Amplitude For: " + command);
242 histLeadingTimeSpecific->SetTitle("Leading Time For: " + command);
243 if (frecoTree != NULL) {
244 histAmpSpecific->SetTitle("Amplitude For: " + command);
245 TString direction = "fAmplitude>>" + TString(histAmpSpecific->GetName());
246 // TCanvas *c1 = new TCanvas("c1");
247 frecoTree->Draw(direction.Data(), command.Data(), "goff");
248 histLeadingTimeSpecific->SetTitle("Leading Time For: " + command);
249 direction = "fTime>>" + TString(histLeadingTimeSpecific->GetName());
250 // TDirectory *d = gDirectory->GetDirectory();
251 // TDirectory()
252 frecoTree->Draw(direction.Data(), command.Data(), "goff");
253 // delete c1;
254 }
255}
256
258{
259 for (auto& h : canTimesPads) {
260 h->current->Reset();
261 }
262 for (auto& h : can2dPads) {
263 h->current->Reset();
264 }
265}
266
268{
269 BmnHist::DrawRef(canTimes, &canTimesPads);
270 BmnHist::DrawRef(can2d, &can2dPads);
271}
272
274{
275 if (refID != id) {
276 TString FileName = Form("bmn_run%04d_hist.root", id);
277 printf("SetRefRun: %s\n", FileName.Data());
278 refRunName = FileName;
279 refID = id;
280 BmnHist::LoadRefRun(refID, refPath + FileName, fTitle, canTimesPads, Names);
281 DrawBoth();
282 }
283 return kBMNSUCCESS;
284}
285
287{
288 for (auto& pad : canTimesPads) {
289 if (pad->ref)
290 delete pad->ref;
291 pad->ref = NULL;
292 }
293 refID = 0;
294}
#define PAD_WIDTH
Definition BmnAdcQA.cxx:3
#define PAD_HEIGHT
Definition BmnAdcQA.cxx:4
BmnStatus
Definition BmnEnums.h:24
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnStatus SetRefRun(Int_t id)
BmnHistToF(TString title, TString path="")
void SetStrip(Int_t v)
Definition BmnHistToF.h:59
void FillFromDigi(DigiArrays *fDigiArrays)
void SetPlane(Int_t v)
Definition BmnHistToF.h:57
void SetSide(Int_t v)
Definition BmnHistToF.h:58
void Register(THttpServer *serv)
void ClearRefRun()
virtual ~BmnHistToF()
void DrawBoth()
void SetDir(TFile *outFile=NULL, TTree *recoTree=NULL)
void SetSelection(Int_t Plane, Int_t Strip, Int_t Side)
TTree * frecoTree
Definition BmnHist.h:88
Int_t refID
Definition BmnHist.h:92
TString refPath
Definition BmnHist.h:90
TDirectory * fDir
Definition BmnHist.h:89
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
Definition BmnHist.cxx:15
static void SetHistStyleTH1(TH1 *h)
Definition BmnHist.cxx:195
TString refRunName
Definition BmnHist.h:91
static BmnStatus LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector< PadInfo * > canPads, vector< TString > Names)
Definition BmnHist.cxx:100
THttpServer * fServer
Definition BmnHist.h:87
Short_t GetPlane() const
Short_t GetSide() const
Short_t GetStrip() const
Float_t GetTime() const
Float_t GetAmplitude() const
TClonesArray * tof400
Definition DigiArrays.h:129
Storage for pad content and it's options.
Definition PadInfo.h:20
string opt
Definition PadInfo.h:88
#define TOF_ROWS
Definition BmnHistToF.h:39
#define TOF400_PLANE_COUNT
Definition BmnHistToF.h:36
#define TOF_COLS
Definition BmnHistToF.h:38
#define TOF400_STRIP_COUNT
Definition BmnHistToF.h:37