hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ClusterHistos.cxx
Go to the documentation of this file.
1#include "ClusterHistos.h"
2#include <math.h>
3#include "TCanvas.h"
4
5ClusterHistos::ClusterHistos(const std::string& inputName):HistoManager(inputName) {
6 m_name = inputName;
7 mmapper_ = new ModuleMapper(2016);
8}
9
11
12 std::cout<<"Cleaning ClusterHistos"<<std::endl;
13
14 //TODO understand why this crashes
15 /*
16 if (mmapper_) {
17 delete mmapper_;
18 mmapper_=nullptr;
19 }
20 */
21
22 cluSizeMap.clear();
23 chargeMap.clear();
24 chargeCorrectedMap.clear();
25 cluPositionMap.clear();
26 for (std::map<std::string, TGraphErrors*>::iterator it = baselineGraphs.begin();
27 it!=baselineGraphs.end(); ++it) {
28 if (it->second) {
29 delete (it->second);
30 it->second = nullptr;
31 }
32 }
33 baselineGraphs.clear();
34}
35
36
38
39 //TODO improve this naming scheme
40 std::string h_name = "";
41
42 //Cluster position
43 histos1d[m_name+"_gz"] = plot1D(m_name+"_gz","Global Z [mm]",20000,-1000,2000);
44
46
47 for (unsigned int ihm = 0; ihm<half_module_names.size(); ihm++) {
48 h_name = m_name+"_"+half_module_names[ihm]+"_charge";
49 histos1d[h_name] = plot1D(h_name,"charge",100,0,10000);
50 h_name = m_name+"_"+half_module_names[ihm]+"_cluSize";
51 histos1d[h_name] = plot1D(h_name,"cluSize",10,0,10);
52 cluSizeMap[h_name] = 0.;
53 chargeMap[h_name] = 0.;
54 chargeCorrectedMap[h_name] = 0.;
55 cluPositionMap[h_name] = 0.;
56 }//half module plots
57}
58
60 std::string h_name = "";
61 int nbins = 1000;
62 float pitch = 0.055;
63 float startY = 0.700;
64
65 histos2d[m_name+"_charge_L0T_vs_gy"] = plot2D(m_name+"_charge_L0T_vs_gy",
66 "Global Y [mm]",nbins,startY,(nbins+1)*pitch,
67 "edep",100,0,1e-5);
68
69
70 histos2d[m_name+"_charge_L0T_vs_gx"] = plot2D(m_name+"_charge_L0T_vs_gx",
71 "Global X [mm] ",80,-20,20,
72 "edep",100,0,1e-5);
73
74
75 histos2d[m_name+"_charge_L0B_vs_gy"] = plot2D(m_name+"_charge_L0B_vs_gy",
76 "Global Y [mm]",nbins,startY,(nbins+1)*pitch,
77 "edep",100,0,1e-5);
78
79
80 histos2d[m_name+"_charge_L0B_vs_gx"] = plot2D(m_name+"_charge_L0B_vs_gx",
81 "Global X [mm] ",80,-20,20,
82 "edep",100,0,1e-5);
83
84
85 // location of the hits
86
87 histos2d[m_name+"_gy_L0T_vs_gx"] = plot2D(m_name+"_gy_L0T_vs_gx",
88 "Global X [mm] ",400,-20,20,
89 "Global Y [mm]",200,0,5);
90
91
92
93 histos2d[m_name+"_gy_L0B_vs_gx"] = plot2D(m_name+"_gy_L0B_vs_gx",
94 "Global X [mm] ",400,-20,20,
95 "Global Y [mm]",200,0,5);
96
97
98
99
100
101 //bin size must be multiple of 20 adc counts
102
103 for (unsigned int ihm = 0; ihm<half_module_names.size(); ihm++) {
104
105 h_name = m_name+"_"+half_module_names[ihm]+"_charge_vs_stripPos";
106 histos2d[h_name] = plot2D(h_name,
107 "Strip Position",640,0,640,
108 "charge",100,0,10000);
109
110 h_name = m_name+"_"+half_module_names[ihm]+"_charge_vs_globRad";
111
112 histos2d[h_name] = plot2D(h_name,
113 "#sqrt{x^{2} + y^{2}}",600,0,150,
114 "charge",100,0,10000);
115
116 //Charge with baseline substracted
117 h_name = m_name+"_"+half_module_names[ihm]+"_charge_corrected_vs_stripPos";
118 histos2d[h_name] = plot2D(h_name,
119 "Strip Position",640,0,640,
120 "corrected charge",100,0,10000);
121
122 //sample 0 vs Strip
123 h_name = m_name+"_"+half_module_names[ihm]+"_sample0_vs_stripPos";
124 histos2d[h_name] = plot2D(h_name,
125 "Strip Position",640,0,640,
126 "sample0",200,-2000,2000);
127
128 h_name = m_name+"_"+half_module_names[ihm]+"_sample1_vs_stripPos";
129 histos2d[h_name] = plot2D(h_name,
130 "Strip Position",640,0,640,
131 "sample1",200,-2000,2000);
132
133
134 //adc[0] (Sample 0) vs Amplitude
135 h_name = m_name+"_"+half_module_names[ihm]+"_sample0_vs_Amp";
136 histos2d[h_name] = plot2D(h_name,
137 "Amp", 100,0,10000,
138 "Sample0",200,-2000,2000);
139
140
141 //adc[1] (Sample 1) vs Amplitude
142 h_name = m_name+"_"+half_module_names[ihm]+"_sample1_vs_Amp";
143 histos2d[h_name] = plot2D(h_name,
144 "Amp", 100,0,10000,
145 "Sample1",200,-2000,2000);
146
147
148 h_name = m_name+"_"+half_module_names[ihm]+"_stripPos_vs_gy";
149 histos2d[h_name] = plot2D(h_name,
150 "Global Y [mm]", nbins, startY, (nbins+1)* pitch,
151 "strip Pos", 640,0,640);
152
153 }
154}
155
156bool ClusterHistos::LoadOfflineBaselines(const std::string& baselineFits) {
157
158 TFile *inFile = new TFile((baselineFits).c_str(), "READ");
159
160 if (!inFile)
161 return false;
162
163 TIter next(inFile->GetListOfKeys());
164 TKey *key;
165 while ((key = (TKey*)next())) {
166 std::string classname = key->GetClassName();
167 if (classname.find("TDirectoryFile") != -1){
168 TDirectoryFile* tdir = (TDirectoryFile*) inFile->Get(key->GetName());
169 TGraphErrors* gr = (TGraphErrors*) tdir->Get(((std::string)(key->GetName())+"_baseline_0").c_str());
170 std::string grname = gr->GetName();
171 std::cout << "Loading baselines from graph " << grname << std::endl;
172 grname = grname.substr(0,grname.find("_baseline_0"));
173 baselineGraphs[grname] = gr;
174 std::cout << grname << std::endl;
175 }
176 }
177
178 inFile->Close();
179 delete inFile;
180 inFile = nullptr;
181
182 return true;
183}
184
185bool ClusterHistos::LoadBaselineHistos(const std::string& baselinesIn) {
186
187 //TFile *baselinesFile = new TFile((baselineFits_+"/hpssvt_"+baselineRun+"_baselineFits.root").c_str());
188 TFile *baselinesFile = new TFile((baselinesIn).c_str());
189
190 if (!baselinesFile)
191 return false;
192
194 TDirectory* dir = baselinesFile->GetDirectory("baseline");
195
196 TList* keyList = dir->GetListOfKeys();
197 TIter next(keyList);
198 TKey* key;
199
200 //I assume that there are only TGraphErrors
201 //TObject* obj;
202
203 while ( (key = (TKey*)next())) {
204 //obj = key->ReadObj();
205 //if (strcmp(obj->IsA()->GetName(),"TGraphErrors") != 0 )
206 //continue;
207
208
209 //x values go from 0 to 512 (513 points) for L0-1. Last point is 0
210 //x values go from 0 to 639 (640 points) for other layers
211 std::string graph_key = key->GetName();
212 graph_key = graph_key.substr(graph_key.find("F"),4);
213 baselineGraphs[graph_key] = (TGraphErrors*) (dir->Get(key->GetName()));
214 }
215
216 //for (std::map<std::string,TGraphErrors*>::iterator it = baselineGraphs.begin(); it!=baselineGraphs.end(); ++it)
217 //std::cout<<it->first<<" " <<it->second->GetN()<<std::endl;
218 //
219 //for (int point = 0 ; point < baselineGraphs["F5H1"]->GetN();point++) {
220 //Double_t x=-999;
221 //Double_t y=-999;
222 //baselineGraphs["F5H1"]->GetPoint(point,x,y);
223 //std::cout<<point<<" x "<<x<<" y "<<y<<std::endl;
224 //}
225
226 baselinesFile->Close();
227 delete baselinesFile;
228 baselinesFile = nullptr;
229
230 return true;
231}
232
233
234
235
236
238
239 TRefArray rawhits_ = hit->getRawHits();
240 //int iv = -1; // 0 top, 1 bottom
241 //int it = -1; // 0 axial, 1 stereo
242 //int ily = -1; // 0-6
243
244 //TODO do this better
245
246 //std::cout<<"Size:" <<rawhits_->GetEntries()<<std::endl;
247
248 std::string swTag = "";
249
250 for (unsigned int irh = 0; irh < rawhits_.GetEntries(); ++irh) {
251
252 RawSvtHit * rawhit = static_cast<RawSvtHit*>(rawhits_.At(irh));
253 //rawhit layers go from 1 to 14. Example: RawHit->Layer1 is layer0 axial on top and layer0 stereo in bottom.
254
255 swTag = "ly"+std::to_string(rawhit->getLayer())+"_m"+std::to_string(rawhit->getModule());
256
257 std::string key = mmapper_->getStringFromSw(swTag);
258 //std::cout<<"----"<<std::endl;
259 //std::cout<<"From Mapper "<<mmapper_->getStringFromSw(swTag)<<std::endl;
260 //std::cout<<"----"<<std::endl;
261
262 //2D cluster charge
263 chargeMap [m_name+"_"+key+"_charge"] += rawhit->getAmp(0);
264
265 double baseline = -999;
266 double strip = -999;
267
268 /*
269 //2D cluster corrected charge
270 if (baselineGraphs[mmapper_->getHwFromString(key)])
271 baselineGraphs[mmapper_->getHwFromString(key)]->GetPoint(rawhit->getStrip(),strip,baseline);
272 */
273
274 float sample0 = baseline - rawhit->getADCs()[0];
275 float sample1 = baseline - rawhit->getADCs()[1];
276
277 chargeCorrectedMap[m_name+"_"+key+"_charge"] += (rawhit->getAmp(0) + sample0);
278
279 histos2d[m_name+"_"+key+"_sample0_vs_Amp"]->Fill(rawhit->getAmp(0),sample0,weight);
280 histos2d[m_name+"_"+key+"_sample1_vs_Amp"]->Fill(rawhit->getAmp(0),sample1,weight);
281
282 histos2d[m_name+"_"+key+"_sample0_vs_stripPos"]->Fill(rawhit->getStrip(),-sample0,weight);
283 histos2d[m_name+"_"+key+"_sample1_vs_stripPos"]->Fill(rawhit->getStrip(),-sample1,weight);
284
285
286 //2D cluster size1
287 cluSizeMap [m_name+"_"+key+"_cluSize"] ++;
288
289 //2D Weighted position numerator
290 cluPositionMap[m_name+"_"+key+"_charge"] += rawhit->getAmp(0)*rawhit->getStrip();
291 //std::cout<<"rawhit->getStrip()::"<<rawhit->getStrip()<<std::endl;
292 }
293
294 //TODO make this more efficient: useless to loop all over the possibilities
295
296 for (std::map<std::string, int>::iterator it = cluSizeMap.begin(); it!=cluSizeMap.end(); ++it ) {
297 if (it->second != 0) {
298 //std::cout<<"Filling..."<<it->first<<" "<<histos1d[it->first]<<std::endl;
299 histos1d[it->first]->Fill(it->second,weight);
300 cluSizeMap[it->first]= 0;
301 }
302 }// fills the maps
303
304 //TODO make this more efficient: useless to loop all over the possibilities
305 for (std::map<std::string, double>::iterator it = chargeMap.begin(); it!=chargeMap.end(); ++it ) {
306 //TODO make it better
307 //Avoid comparing to 0.0 and check if there is a charge deposit on this
308 if (it->second > 1e-6) {
309
310
311 std::string plotID = (it->first).substr(0,(it->first).find("_charge"));
312
313 //it->second holds the charge
314 //it->first = charge histogram name.
315 double charge = it->second;
316 histos1d[it->first]->Fill(charge,weight);
317 double weighted_pos = cluPositionMap[it->first] / (charge);
318 double chargeCorrected = chargeCorrectedMap[it->first];
319 //std::cout<<"weighted pos "<<weighted_pos<<std::endl;
320 histos2d[it->first+"_vs_stripPos"]->Fill(weighted_pos,charge,weight);
321
322 // Fill the baseline corrected charge
323 histos2d[it->first+"_corrected_vs_stripPos"]->Fill(weighted_pos,chargeCorrected,weight);
324
325 //Fill local vs global
326
327 histos2d[plotID+"_stripPos_vs_gy"]->Fill(fabs(hit->getGlobalY()),weighted_pos,weight);
328
329 double globRad = sqrt(hit->getGlobalX() * hit->getGlobalX() + hit->getGlobalY()+hit->getGlobalY());
330 histos2d[it->first+"_vs_globRad"]->Fill(globRad,charge,weight);
331
332
333 chargeMap[it->first] = 0.0;
334 chargeCorrectedMap[it->first] = 0.0;
335 cluPositionMap[it->first] = 0.0;
336
337 }
338 }
339 histos1d[m_name+"_gz"]->Fill(hit->getGlobalZ(),weight);
340 //1D
341 //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight);
342 //2D
343 if (hit->getGlobalZ() < 50 && hit->getGlobalZ() > 40) {
344 histos2d[m_name+"_gy_L0T_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight);
345 histos2d[m_name+"_charge_L0T_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight);
346 histos2d[m_name+"_charge_L0T_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight);
347
348 }
349
350 if (hit->getGlobalZ() < 60 && hit->getGlobalZ() > 55) {
351 histos2d[m_name+"_gy_L0B_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight);
352 histos2d[m_name+"_charge_L0B_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight);
353 histos2d[m_name+"_charge_L0B_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight);
354 }
355}
std::map< std::string, double > cluPositionMap
bool LoadBaselineHistos(const std::string &baselineRun)
Load baseline histograms.
ClusterHistos(const std::string &inputName)
Constructor.
std::vector< std::string > half_module_names
std::map< std::string, double > chargeCorrectedMap
virtual void Define1DHistos()
description
void FillHistograms(TrackerHit *hit, float weight=1.)
description
std::map< std::string, int > cluSizeMap
virtual void Define2DHistos()
description
bool LoadOfflineBaselines(const std::string &baselineFits)
Load offline baseline.
std::map< std::string, double > chargeMap
ModuleMapper * mmapper_
std::map< std::string, TGraphErrors * > baselineGraphs
description
std::map< std::string, TH2F * > histos2d
description
TH2F * plot2D(std::string name, std::string xtitle, int nbinsX, float xmin, float xmax, std::string ytitle, int nbinsY, float ymin, float ymax)
description
std::map< std::string, TH1F * > histos1d
description
TH1F * plot1D(const std::string &name, const std::string &xtitle, int nbinsX, float xmin, float xmax)
description
std::string m_name
description
std::string getStringFromSw(const std::string &key)
Get the String From Sw.
void getStrings(std::vector< std::string > &strings)
Get list of string modules.
int getStrip()
int getLayer()
Definition RawSvtHit.cxx:88
double getAmp(int fitI)
Definition RawSvtHit.h:101
int * getADCs()
Definition RawSvtHit.cxx:76
int getModule()
Definition RawSvtHit.cxx:92
double getGlobalY() const
Definition TrackerHit.h:53
double getCharge() const
Definition TrackerHit.h:93
double getGlobalZ() const
Definition TrackerHit.h:56
TRefArray getRawHits() const
Definition TrackerHit.h:36
double getGlobalX() const
Definition TrackerHit.h:50