BmnRoot
Loading...
Searching...
No Matches
hodo_profile.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <vector>
4#include <TFile.h>
5#include <TNtuple.h>
6#include <TGraph.h>
7#include <TF1.h>
8#include <TTree.h>
9#include <TCanvas.h>
10#include <TH1F.h>
11#include "TCutG.h"
12#include <algorithm>
13#include <fstream>
14#include <iostream>
15#include <map>
16#include <numeric>
17#include <stdio.h>
18//#include "utils.h"
19#include "TString.h"
20#include "TH1D.h"
21#include "TMultiGraph.h"
22#include "TStyle.h"
23#include "TH2.h"
24//#include "BmnHodoDigi.h"
25#include "TClonesArray.h"
26
27#include "../common/utilites.h"
28
29#define kNstrips 16
30#define kNsides 2
31#define kNgains 2
32
33int make_flat_index(uint32_t StripId, uint32_t StripSide, uint32_t Gain){
34 uint32_t address = BmnHodoAddress::GetAddress(0, StripId, StripSide, Gain);
35 return BmnHodoAddress::GetFlatIndex(address);
36}
37
38void hodo_profile(TString converted_root_file, TString result_file_name, int max_entries)
39{
40 TObjArray *canvas_array = new TObjArray;
41 canvas_array->SetName ("Canvas");
42 TObjArray *result_array = new TObjArray;
43 result_array->SetName("Histo");
44
45 int variantes = BmnHodoAddress::GetMaxFlatIndex();
46 TH2F* profile_hist = new TH2F("profile", "profile", 18,0,18, 100,0,50);
47 profile_hist->SetTitle("Hodoscope profile; Strip # ; Z^{2} ");
48 profile_hist->SetStats(0);
49
50 TFile *_file0 = TFile::Open(converted_root_file, "READONLY");
51 TTree *tree = (TTree *)_file0->Get("bmndata");
52
53 BmnEventHeader* eventHeader = nullptr;
54 tree->SetBranchAddress("BmnEventHeader.", &eventHeader);
55
56 TClonesArray *DigiArray = nullptr; //leave nullptr!!!
57 tree->SetBranchAddress("HodoDigi", &DigiArray);
58
59 TClonesArray *ScWallDigiArray = nullptr; //leave nullptr!!!
60 tree->SetBranchAddress("ScWallDigi", &ScWallDigiArray);
61
62 double ScWallCtrEnergy = 0.;
63 int counter = 0;
64 int n_events = (max_entries>0 && tree->GetEntries()>max_entries)? max_entries : tree->GetEntries();
65 cout << n_events << endl;
66 for (int ev = 0; ev < n_events; ev++)
67 {
68 tree->GetEntry(ev);
69 if (ev%10000 == 0) cout << "Event: " << ev << endl;
70
71 auto TrigPattern = eventHeader->GetInputSignalsAR();
72 auto BT = !(TrigPattern ^ (1 << 7));
73 auto ArmAnd = !(TrigPattern ^ (1 << 2));
74 auto ArmOr = !(TrigPattern ^ (1 << 3));
75 if(!ArmOr) continue;
76
77 ScWallCtrEnergy = 0.;
78 for (int i = 0; i < ScWallDigiArray->GetEntriesFast(); i++)
79 {
80 BmnScWallDigi *ThisDigi = (BmnScWallDigi *)ScWallDigiArray->At(i);
81
82 //##################################
83 //SELECTION
84 if(ThisDigi->fFitR2 > 0.5) continue;
85 auto cell_id = ThisDigi->GetCellId();
86 if(cell_id != 17 && cell_id != 18 && cell_id != 27 && cell_id != 28 ) continue; // MF = 1650
87 ScWallCtrEnergy += ThisDigi->GetSignal();
88
89 }
90 //if(ScWallCtrEnergy < 40) continue;
91
92 float responses[kNstrips+1][kNsides];
93 memset(responses, 0, sizeof(responses[0][0]) * (kNstrips+1) * kNsides);
94 for (int i = 0; i < DigiArray->GetEntriesFast(); i++)
95 {
96 BmnHodoDigi *ThisDigi = (BmnHodoDigi *)DigiArray->At(i);
97
98 //##################################
99 //SELECTION
100 //if(ThisDigi->GetStripId() == 9) continue;
101 if(ThisDigi->fFitR2 > 0.4) continue;
102 if(ThisDigi->fTimeMax > 28 || ThisDigi->fTimeMax < 25) continue;
103 //##################################
104
105 auto strip = ThisDigi->GetStripId();
106 auto side = ThisDigi->GetStripSide();
107 auto gain = ThisDigi->GetGain();
108 auto idx = make_flat_index(strip,side,gain);
109
110 if(gain != 1) continue;
111 responses[strip][side] = ThisDigi->GetSignal();
112 }
113
114 for (int i = 1; i <= kNstrips; i++)
115 if(responses[i][0] * responses[i][1] > 0.001)
116 profile_hist->Fill(i, (responses[i][0] + responses[i][1]));
117 }
118
119 TCanvas* prof = new TCanvas("c_prof","c_prof",800,800);
120 canvas_array->Add(prof);
121 result_array->Add(profile_hist);
122 profile_hist->Draw("colz");
123
124 for (int i = 1; i <= kNstrips; i++){
125 TCanvas *canv_ptr = new TCanvas();
126 canvas_array->Add(canv_ptr);
127 auto hist_ptr = profile_hist->ProjectionY(Form("projection_strip%i", i), i, i+1);
128 hist_ptr->SetTitle(Form("strip%i; Z^{2}; Counts", i));
129 result_array->Add(hist_ptr);
130 hist_ptr->Draw();
131 }
132
133 TFile *result_file = new TFile((result_file_name + ".root").Data(), "RECREATE");
134 TIter nx_iter((TCollection*)(result_array));
135 TObject* obj_ptr;
136 while ( (obj_ptr=(TObjArray*)nx_iter()) )
137 {
138 if(obj_ptr == nullptr) continue;
139 printf("Writing %s object\n", obj_ptr->GetName());
140 obj_ptr->Write();
141 }
142 printf("file %s was written\n", (result_file_name + ".root").Data());
143 result_file->Close();
144 delete result_file;
145
146 for (Int_t i = 0; i < canvas_array->GetLast (); i++)
147 ((TCanvas*) canvas_array->At(i))->SaveAs ((result_file_name + ".pdf(").Data ());
148 ((TCanvas*) canvas_array->At (canvas_array->GetLast ()))->SaveAs ((result_file_name + ".pdf)").Data ());
149 printf("file %s was written\n", (result_file_name + ".pdf").Data());
150
151}
void memset(T *dest, T i, size_t num)
uses binary expansion of copied volume for speed up
Definition L1Grid.h:25
int i
Definition P4_F32vec4.h:22
double GetSignal() const
float fFitR2
Energy deposition from fit of waveform [adc counts].
int fTimeMax
Energy deposition from waveform [adc counts].
UInt_t GetInputSignalsAR()
static uint32_t GetAddress(uint32_t StripId, uint32_t StripSide, uint32_t Gain)
Return address from system ID, StripId, StripSide, Gain.
Data class for BmnHodo digital signal processing.
Definition BmnHodoDigi.h:25
uint32_t GetGain() const
Gain.
Definition BmnHodoDigi.h:70
uint32_t GetStripSide() const
Strip Side.
Definition BmnHodoDigi.h:65
uint32_t GetStripId() const
Class for experimental data at digi level.
uint32_t GetCellId() const
#define kNstrips
void hodo_profile(TString converted_root_file, TString result_file_name, int max_entries)
#define kNsides
int make_flat_index(uint32_t StripId, uint32_t StripSide, uint32_t Gain)