Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BbcCheck.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BbcCheck.cc
1 #include "BbcCheck.h"
2 
3 #include <phool/phool.h>
4 #include <phool/getClass.h>
5 #include <phool/recoConsts.h>
8 
9 #include <mbd/MbdDefs.h>
10 #include <mbd/MbdOut.h>
11 #include <mbd/MbdPmtContainer.h>
12 #include <mbd/MbdPmtHit.h>
13 #include <mbd/MbdGeom.h>
14 
15 #include <calobase/TowerInfoContainer.h>
16 #include <calobase/TowerInfo.h>
19 
20 #include <TFile.h>
21 #include <TTree.h>
22 #include <TH1F.h>
23 #include <TH2F.h>
24 #include <TGraphErrors.h>
25 #include <TF1.h>
26 #include <TCanvas.h>
27 #include <TString.h>
28 #include <TLorentzVector.h>
29 //#include <TMath.h>
30 #include <TSystem.h>
31 
32 #include <iostream>
33 #include <cmath>
34 #include <cstdio>
35 
36 using namespace std;
37 using namespace MbdDefs;
38 
39 /*
40 const Double_t index_refract = 1.4585;
41 const Double_t v_ckov = 1.0/index_refract; // velocity threshold for CKOV
42 const Double_t C = 29.9792458; // cm/ns
43 */
44 
45 //____________________________________
46 BbcCheck::BbcCheck(const string &name) : SubsysReco(name),
47  _tree( 0 ),
48  f_evt( 0 ),
49  _tres( 0.05 ),
50  _savefname( "bbcstudy.root" ),
51  _savefile( 0 )
52 {
53 
54 }
55 
56 //___________________________________
58 {
59  cout << PHWHERE << " Saving to file " << _savefname << endl;
60  //PHTFileServer::get().open( _outfile, "RECREATE");
61  _savefile = new TFile( _savefname.c_str(), "RECREATE" );
62 
63  _tree = new TTree("t","BbcCheck");
64  _tree->Branch("run",&f_run,"run/I");
65  _tree->Branch("ch",&f_ch,"ch/I");
66  _tree->Branch("qmean",&f_qmean,"qmean/F");
67  _tree->Branch("qmerr",&f_qmerr,"qmerr/F");
68 
69  TString name, title;
70  for (int ipmt=0; ipmt<128; ipmt++)
71  {
72  name = "h_bbcq"; name += ipmt;
73  title = "bbc charge, ch "; title += ipmt;
74  h_bbcq[ipmt] = new TH1F(name,title,1200,0,60);
75 
76  // TGraph to track mean of bbcq distribution
77  name = "g_bbcq"; name += ipmt;
78  title = "mbdq, ch "; title += ipmt;
79  g_bbcq[ipmt] = new TGraphErrors();
80  g_bbcq[ipmt]->SetName(name);
81  g_bbcq[ipmt]->SetTitle(name);
82 
83  /*
84  name = "h_tdiff_ch"; name += ipmt;
85  title = "tdiff, ch "; title += ipmt;
86  h_tdiff_ch[ipmt] = new TH1F(name,title,600,-3,3);
87  */
88  }
89 
90  for (int iarm=0; iarm<2; iarm++)
91  {
92  name = "h_bbcqtot"; name += iarm;
93  title = "bbc charge, arm "; title += iarm;
94  h_bbcqtot[iarm] = new TH1F(name,title,1400,0,1400); // npe for 1 mip = 120, and up to 30 mips are possible
95 
96  //
97  name = "hevt_bbct"; name += iarm;
98  title = "bbc times, arm "; title += iarm;
99  hevt_bbct[iarm] = new TH1F(name,title,200,7.5,11.5);
100  hevt_bbct[iarm]->SetLineColor(4);
101  }
102  h_bbcqsum = new TH1F("h_bbcqsum","MBD/BBC north + south charge sum",3000,0.,3000.);
103  h2_bbcqsum = new TH2F("h2_bbcqsum","north BBCQ vs South BBCQ",1400,0.,1400.,1400,0.,1400.);
104 
105  h_zdce = new TH1F("h_zdce","ZDC Energy",820,-50,4050);
106  h_zdctimecut = new TH1F("h_zdctimecut", "zdctimecut", 50, -17.5 , 32.5);
107 
108  h_emcale = new TH1F("h_emcale","Emcal Energy",3000,-100,2900);
109  h_emcaltimecut = new TH1F("h_emcaltimecut", "emcaltimecut", 50, -17.5 , 32.5);
110 
111  h_ohcale = new TH1F("h_ohcale","OHCAL Energy",1000,-100,900);
112  h_ohcaltimecut = new TH1F("h_ohcaltimecut", "ohcaltimecut", 50, -17.5 , 32.5);
113 
114  h_ihcale = new TH1F("h_ihcale","IHCAL Energy",1000,-100,900);
115  h_ihcaltimecut = new TH1F("h_ihcaltimecut", "ihcaltimecut", 50, -17.5 , 32.5);
116 
117  h_bz = new TH1F("h_bz","MBD z-vertex",1200,-300,300);
118 
119  gaussian = new TF1("gaussian","gaus",0,20);
120  gaussian->FixParameter(2,0.05); // set sigma to 50 ps
121 
122  c_bbct = new TCanvas("c_bbct","BBC Times",1200,800);
123  c_bbct->Divide(1,2);
124 
125  return 0;
126 }
127 
128 //___________________________________
130 {
132  f_run = rc->get_IntFlag("RUNNUMBER");
133 
134  GetNodes(topNode);
135 
136  return 0;
137 }
138 
139 //__________________________________
140 //Call user instructions for every event
142 {
143  nprocessed++;
144 
145  //f_evt = _evtheader->get_EvtSequence();
146  //if(f_evt%1==0) cout << PHWHERE << "Event " << f_evt << "\t" << ", nprocessed = " << nprocessed << endl;
147 
148  // Initialize Variables
149  f_bbcn[0] = 0;
150  f_bbcn[1] = 0;
151  f_bbcq[0] = 0.;
152  f_bbcq[1] = 0.;
153  f_bbct[0] = -9999.;
154  f_bbct[1] = -9999.;
155  f_bbcte[0] = -9999.;
156  f_bbcte[1] = -9999.;
157  f_bbcz = NAN;
158  f_bbct0 = NAN;
159  hevt_bbct[0]->Reset();
160  hevt_bbct[1]->Reset();
161 
162  // Get Truth Centrality Info
163  //f_bimp = _evtheader->get_ImpactParameter();
164  //f_ncoll = _evtheader->get_ncoll();
165  //f_npart = _evtheader->get_npart();
166 
167  /*
168  if ( f_evt<20 )
169  {
170  cout << "******** " << f_evt << " **************" << endl;
171  }
172  */
173 
174 
175  CheckDST(topNode);
176 
177  return 0;
178 }
179 
180 //___________________________________
182 {
183  // Get the DST objects
184 
185  //_evtheader = findNode::getClass<EventHeaderv1>(topNode, "EventHeader");
186  //if (!_evtheader && f_evt<10) cout << PHWHERE << " EventHeader node not found on node tree" << endl;
187 
188  // BbcOut
189  _bbcout = findNode::getClass<MbdOut>(topNode, "MbdOut");
190  if(!_bbcout && f_evt<4) cout << PHWHERE << " MbdOut node not found on node tree" << endl;
191 
192  // BbcPmt Info
193  _bbcpmts = findNode::getClass<MbdPmtContainer>(topNode, "MbdPmtContainer");
194  if(!_bbcpmts && f_evt<4) cout << PHWHERE << " MbdPmtContainer node not found on node tree" << endl;
195 
196 }
197 
198 //______________________________________
200 {
201  _savefile->cd();
202 
203  Double_t nevents = h_bbcqsum->Integral();
204  Double_t norm = 1.0/nevents;
205  h_bbcqsum->Scale( norm );
206  h2_bbcqsum->Scale( norm );
207 
208  h_bbcqtot[0]->Scale( norm );
209  h_bbcqtot[1]->Scale( norm );
210 
211  for (int ipmt=0; ipmt<BBC_N_PMT; ipmt++)
212  {
213  h_bbcq[ipmt]->Scale( norm );
214 
215  // Fill info on q distribution
216  f_ch = ipmt;
217  f_qmean = h_bbcq[ipmt]->GetMean();
218  f_qmerr = h_bbcq[ipmt]->GetMeanError();
219  _tree->Fill();
220  cout << f_run << "\t" << f_ch << "\t" << f_qmean << "\t" << f_qmerr << endl;
221 
222  g_bbcq[ipmt]->SetPoint(0,f_run,f_qmean);
223  g_bbcq[ipmt]->SetPointError(0,0,f_qmerr);
224  g_bbcq[ipmt]->Write();
225  }
226 
227  cout << "Nevents processed integral " << nprocessed << "\t" << nevents << "\t" << nevents/nprocessed << endl;
228  _savefile->Write();
229  _savefile->Close();
230 
231  return 0;
232 }
233 
235 {
236  Float_t bqs = _bbcout->get_q(0);
237  Float_t bqn = _bbcout->get_q(1);
238  Float_t bz = _bbcout->get_zvtx();
239 
240  h_bz->Fill( bz );
241 
242  // Check the GlobalVertex
243  GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
244  if ( vertexmap && !vertexmap->empty() )
245  {
246  GlobalVertex *vtx = vertexmap->begin()->second;
247  if ( vtx )
248  {
249  float vtx_z = vtx->get_z();
250  if ( vtx_z != bz )
251  {
252  cout << "ERROR, vertices do not match " << vtx_z << "\t" << bz << endl;
253  }
254  }
255  }
256  else
257  {
258  static int counter = 0;
259  if ( counter < 4 ) cout << "GlobalVertexMap not found or is empty" << endl;
260  counter++;
261  }
262 
263  if ( fabs(bz)>60. ) return;
264  if ( bqn<10 && bqs>150 ) return;
265 
266  //Float_t r = (4.4049/4.05882);
267  Float_t r = 1.0;
268 
269  h_bbcqsum->Fill( (bqn+bqs)*r );
270  h_bbcqtot[0]->Fill( bqs*r );
271  h_bbcqtot[1]->Fill( bqn*r );
272  h2_bbcqsum->Fill( bqn*r, bqs*r );
273 
274  // Fill info from each PMT
275  for (int ipmt=0; ipmt<_bbcpmts->get_npmt(); ipmt++)
276  {
277  Float_t q = _bbcpmts->get_pmt(ipmt)->get_q();
278  Float_t t = _bbcpmts->get_pmt(ipmt)->get_time();
279  //Float_t phi = mbdgeom->get_phi(ipmt); // get phi angle
280 
281  if ( fabs(t) < 25. )
282  {
283  h_bbcq[ipmt]->Fill( q*r );
284  }
285 
286  //cout << ipmt << ":\t" << q << "\t" << t << endl;
287  }
288 
289  // Analyze other subsystems
290  process_zdc( topNode );
291  process_emcal( topNode );
292  process_ohcal( topNode );
293  process_ihcal( topNode );
294 }
295 
297 {
298  int getmaxtime, tcut = -1;
299 
300  for(int bin = 1; bin < h->GetNbinsX()+1; bin++)
301  {
302  double c = h->GetBinContent(bin);
303  double max = h->GetMaximum();
304  int bincenter = h->GetBinCenter(bin);
305  if(max == c)
306  {
307  getmaxtime = bincenter;
308  if(getmaxtime != -1) tcut = getmaxtime;
309  }
310  }
311 
312  return tcut;
313 
314 }
315 
317 {
318  TowerInfoContainer* zdctowers = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_ZDC");
319  if (zdctowers)
320  {
321  int max_zdc_t = Getpeaktime( h_zdctimecut );
322  int range = 1;
323  double zdc_etot = 0.;
324 
325  int size = zdctowers->size(); //online towers should be the same!
326  for (int ich = 0; ich < size; ich++)
327  {
328  TowerInfo* zdctower = zdctowers->get_tower_at_channel(ich);
329  float zdce = zdctower->get_energy();
330  int zdct = zdctowers->get_tower_at_channel(ich)->get_time();
331  h_zdctimecut->Fill( zdct );
332 
333  if (ich == 0 || ich == 2 || ich == 4 || ich == 8 || ich == 10 || ich == 12)
334  {
335  if( zdct > (max_zdc_t - range) && zdct < (max_zdc_t + range))
336  {
337  zdc_etot += zdce;
338  }
339  }
340  }
341 
342  h_zdce->Fill( zdc_etot);
343  }
344 }
345 
346 
348 {
349  TowerInfoContainer* towers = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC");
350  if (towers)
351  {
352  int max_emcal_t = Getpeaktime( h_emcaltimecut );
353  int range = 1;
354  double etot = 0.;
355 
356  int size = towers->size(); //online towers should be the same!
357  for (int channel = 0; channel < size;channel++)
358  {
360  float energy = tower->get_energy();
361  int t = towers->get_tower_at_channel(channel)->get_time();
362  h_emcaltimecut->Fill(t);
363 
364  if( abs(t - max_emcal_t) < range )
365  {
366  etot += energy;
367  }
368  }
369 
370  h_emcale->Fill(etot);
371  }
372 }
373 
375 {
376  TowerInfoContainer* towers = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
377  if (towers)
378  {
379  int max_hcal_t = Getpeaktime( h_ohcaltimecut );
380  int range = 1;
381  double etot = 0.;
382 
383  int size = towers->size(); //online towers should be the same!
384  for (int channel = 0; channel < size;channel++)
385  {
387  float energy = tower->get_energy();
388  int t = towers->get_tower_at_channel(channel)->get_time();
389  h_ohcaltimecut->Fill(t);
390 
391  if( abs(t - max_hcal_t) < range )
392  {
393  etot += energy;
394  }
395  }
396 
397  h_ohcale->Fill(etot);
398  }
399 }
400 
402 {
403  TowerInfoContainer* towers = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
404  if (towers)
405  {
406  int max_hcal_t = Getpeaktime( h_ihcaltimecut );
407  int range = 1;
408  double etot = 0.;
409 
410  int size = towers->size(); //online towers should be the same!
411  for (int channel = 0; channel < size;channel++)
412  {
414  float energy = tower->get_energy();
415  int t = towers->get_tower_at_channel(channel)->get_time();
416  h_ihcaltimecut->Fill(t);
417 
418  if( abs(t - max_hcal_t) < range )
419  {
420  etot += energy;
421  }
422  }
423 
424  h_ihcale->Fill(etot);
425  }
426 }
427