Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TemplateCreation.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TemplateCreation.cc
1 
2 #include "TemplateCreation.h"
3 
5 #include <fun4all/SubsysReco.h> // for SubsysReco
7 
8 
9 #include <Event/Event.h>
10 #include <Event/packet.h>
11 
12 #include <phool/PHCompositeNode.h>
13 #include <phool/PHIODataNode.h> // for PHIODataNode
14 #include <phool/PHNode.h> // for PHNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/getClass.h>
18 
19 #include <TProfile.h>
20 #include <TMath.h>
21 #include <TF1.h>
22 #include <TH2.h>
23 
24 #include <phool/PHCompositeNode.h>
25 
26 
27 
28 
29 
30 
31 
32 double TemplateCreation::rising_shape(double *val, double *par){
33  double ped = par[0];
34  double N_lan = par[1];
35  double peak = par[2];
36  double width = par[3];
37  double x = val[0];
38  double result = ped + N_lan*TMath::Landau(x, peak, width);
39  return result;
40 }
41 
42 //____________________________________________________________________________..
44  SubsysReco(name)
45  , s_outfilename("testout.root")
46  , nsamples(31)
47  , m_packet_low(21351)
48  , m_packet_high(21352)
49  , m_nchannels(192)
50  , target_hm(5)
51 {
52 }
53 
54 //____________________________________________________________________________..
56 {
57 }
58 
59 //____________________________________________________________________________..
61 {
62  PHTFileServer::get().open(s_outfilename, "RECREATE");
63  hp_all_particle_fine = new TProfile("hp_all_particle_fine","", nsamples*binscale, -0.5, nsamples - .5);
64  h2_all_particle_fine = new TH2D("h2_all_particle_fine","", nsamples*binscale, -0.5, nsamples - .5, 100, -0.1, 0.5);
66 }
67 
68 //____________________________________________________________________________..
70 {
72 }
73 
74 //____________________________________________________________________________..
76 {
77  TH1F *h_waveform = new TH1F("h_waveform","", nsamples, -0.5, nsamples - 0.5);
78  TF1 *f_rising_func = new TF1("f_rising_func",this,&TemplateCreation::rising_shape, 0, 31, 4,"TemplateCreation","rising_shape");
79 
80  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
81  if (_event == nullptr)
82  {
83  std::cout << "CaloUnpackPRDF::Process_Event - Event not found" << std::endl;
84  return -1;
85  }
86  if (_event->getEvtType() >= 8)
87  {
89  }
90  for (int pid = m_packet_low; pid <= m_packet_high; pid++)
91  {
92  Packet *packet = _event->getPacket(pid);
93  if (packet)
94  {
95  int nchannels = packet->iValue(0, "CHANNELS");
96  if (nchannels > m_nchannels) // packet is corrupted and reports too many channels
97  {
99  }
100  for (int channel = 0; channel < nchannels; channel++)
101  {
102  float hm = 0;
103  float sum = 0;
104  int maxbin = 0;
105  float shift = 0;
106 
107  std::vector<float> waveform;
108  waveform.reserve(nsamples);
109  for (int samp = 0; samp < nsamples; samp++)
110  {
111  h_waveform->SetBinContent(samp + 1, packet->iValue(samp, channel));
112  }
113 
114  maxbin = h_waveform->GetMaximumBin();
115  if (maxbin > 12){continue;} //Selection region really only needed for test beam data
116  if (maxbin <= 5) {continue;}
117  if (h_waveform->GetMaximum() < 2000){continue;}
118 
119  float pedestal = 1500;
120  if (maxbin > 5)
121  {
122  pedestal = 0.5 * (h_waveform->GetBinContent(maxbin - 6) + h_waveform->GetBinContent(maxbin - 5));
123  }
124 
125  for (int j = 1; j <= nsamples; j++)
126  {
127  if (h_waveform->GetBinContent(j) - pedestal > 0)
128  {
129  sum += h_waveform->GetBinContent(j) - pedestal;
130  }
131  }
132  for (int j = 0; j <= nsamples; j++)
133  {
134  if (((h_waveform->GetBinContent(j+1)) - pedestal) > 0)
135  {
136  h_waveform->SetBinContent(j + 1, ((h_waveform->GetBinContent(j+1)) - pedestal)/sum);
137  }
138  else
139  {
140  h_waveform->SetBinContent(j + 1,0);
141  }
142  }
143 
144  if (h_waveform->GetBinContent(h_waveform->GetMaximumBin()) > 0.33){continue;}
145 
146  bool pileup = false;
147  for (int k = maxbin+1; k <= nsamples;k++)
148  {
149  if ( h_waveform->GetBinContent(k) > 1.05 * h_waveform->GetBinContent(k-1))
150  {
151  pileup = true;
152  }
153  }
154  if (pileup){continue;}
155 
156  f_rising_func->SetParameters(0, 0.1, static_cast<double>(h_waveform->GetBinCenter(maxbin)), 1);//, p3, p4, p5);
157  f_rising_func->FixParameter(0, 0);
158  f_rising_func->SetParLimits(2,static_cast<double>(h_waveform->GetBinCenter(maxbin - 1)), static_cast<double>(h_waveform->GetBinCenter(maxbin + 1)));
159  f_rising_func->SetParLimits(3, 0.5, 3);
160  f_rising_func->SetRange(static_cast<float>(h_waveform->GetBinCenter(maxbin-3)), static_cast<float>(h_waveform->GetBinCenter(maxbin+1)));
161  h_waveform->Fit("f_rising_func","NRQ");
162  hm = f_rising_func->GetParameter(2) - 1.5*f_rising_func->GetParameter(3);
163  shift = target_hm - hm;
164 
165  bool skipwaveform = false;
166  for (int i = h_waveform->GetMaximumBin() + 5; i < nsamples ;i++)
167  {
168  if (h_waveform->GetMaximum() < binscale*h_waveform->GetBinContent(i))
169  {
170  skipwaveform = true;
171  continue;
172  }
173  }
174  if (skipwaveform){continue;}
175  for (int j = 0; j < nsamples; j++)
176  {
177  hp_all_particle_fine->Fill(j + shift, h_waveform->GetBinContent(j+1));
178  h2_all_particle_fine->Fill(j + shift, h_waveform->GetBinContent(j+1));
179  }
180  }
181  }
182  }
183 
184 
185  delete h_waveform;
186 
188 }
189 
190 //____________________________________________________________________________..
192 {
194 }
195 
196 //____________________________________________________________________________..
198 {
200 }
201 
202 //____________________________________________________________________________..
204 {
205  hp_all_particle_fine->Scale(1/hp_all_particle_fine->GetMaximum());
206 
207 
208 
209  for (int i = 0 ; i < hp_all_particle_fine->GetNbinsX();i++)
210  {
211  if ( hp_all_particle_fine->GetBinContent(i+1) < 0.001)
212  {
213  hp_all_particle_fine->SetBinContent(i+1,0);
214  }
215  }
216 
217 
218 
220  hp_all_particle_fine->SetName("h_template");
221  hp_all_particle_fine->Write();
222  h2_all_particle_fine->Write();
223 
224 
226 }
227 
228 //____________________________________________________________________________..
230 {
232 }
233