Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloCalibEmc_Pi0.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloCalibEmc_Pi0.cc
1 #include "CaloCalibEmc_Pi0.h"
2 
3 #include <calobase/RawCluster.h>
4 #include <calobase/RawClusterContainer.h>
5 #include <calobase/RawClusterUtility.h>
6 #include <calobase/RawTower.h>
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerDefs.h>
9 #include <calobase/RawTowerGeomContainer.h>
10 #include <calobase/TowerInfoContainer.h>
11 
14 
16 #include <fun4all/SubsysReco.h>
17 
18 #include <phool/getClass.h>
19 #include <phool/phool.h>
20 
21 #include <TF1.h>
22 #include <TFile.h>
23 #include <TGraphErrors.h>
24 #include <TH1.h>
25 #include <TH2.h>
26 #include <TH3.h>
27 #include <TLorentzVector.h>
28 #include <TNtuple.h>
29 #include <TStyle.h>
30 #include <TSystem.h>
31 #include <TTree.h>
32 
33 #include <CLHEP/Vector/ThreeVector.h> // for Hep3Vector
34 
35 #include <algorithm> // for max, max_element
36 #include <cmath> // for abs
37 #include <iostream>
38 #include <map> // for _Rb_tree_const_iterator
39 #include <string> // for string
40 #include <utility> // for pair
41 #include <vector> // for vector
42 
43 //____________________________________________________________________________..
45  : SubsysReco(name)
46  , m_Filename(filename)
47  , m_cent_nclus_cut(350)
48 {
49  eta_hist.fill(nullptr);
50  // the 2d filling took a bit of googling but it works:
51  std::for_each(cemc_hist_eta_phi.begin(), cemc_hist_eta_phi.end(), [](auto &row)
52  { row.fill(nullptr); });
53 }
54 
55 //____________________________________________________________________________..
57 {
58  std::cout << "LiteCaloEval::Init(PHCompositeNode *topNode) Initializing" << std::endl;
59 
60  m_ievent = 0;
61 
62  cal_output = new TFile(m_Filename.c_str(), "RECREATE");
63 
64  pairInvMassTotal = new TH1F("pairInvMassTotal", "Pair Mass Histo", 130, 0.0, 1.3);
65  mass_eta = new TH2F("mass_eta", "2d Pair Mass Histo", 70, 0.0, 0.7, 400, -1.5, 1.5);
66  mass_eta_phi = new TH3F("mass_eta_phi", "3d Pair Mass Histo", 70, 0.0, 0.7, 150, -1.5, 1.5, 256, -3.142, 3.142);
67  h_totalClusters = new TH1F("h_totalClusters", "Histogram of total number of clusters", 600, 0, 600);
68  pt1_ptpi0_alpha = new TH3F("pt1_ptpi0_alpha", "Photon1 pT, pi0 pT, alpha", 40, 0., 4., 40, 0., 4., 10, 0., 1.);
69  fitp1_eta_phi2d = new TH2F("fitp1_eta_phi2d", "fit p1 eta phi", 16, 0, 16, 16, 0, 16);
70 
71  // temporarily don't need these till Run2 and they take up a lot of space
72  // // histo to record every tower by tower locations
73  // for (int i = 0; i < 96; i++) // eta rows
74  // {
75  // for (int j = 0; j < 258; j++) // phi columns
76  // {
77  // std::string hist_name = std::string("emc_ieta") + std::tostring(i)
78  // + std::string("_phi") + std::to_string(j);
79 
80  // cemc_hist_eta_phi[i][j] = new TH1F(hist_name.c_str()(), "Hist_ieta_phi_", 70, 0.0, 0.7);
81  // }
82  // }
83 
84  // histo to record each eta locations (with all phis included in each)
85  for (int i = 0; i < 96; i++)
86  {
87  gStyle->SetOptFit(1);
89 
90  eta_hist.at(i) = new TH1F(b.c_str(), "eta and all phi's", 130, 0.0, 1.3);
91  }
92 
93  if (topNode != nullptr)
94  {
95  // TTree declare
96  _eventTree = new TTree("_eventTree", "An event level info Tree");
97  // TTree branches
98  _eventTree->Branch("_eventNumber", &_eventNumber, "_eventNumber/I");
99  _eventTree->Branch("_nClusters", &_nClusters, "_nClusters/I");
100  //_eventTree->Branch("_nTowers", &_nTowers, "_nTowers[_nClusters]/I");
101  _eventTree->Branch("_clusterIDs", _clusterIDs, "_clusterIDs[_nClusters]/I");
102  _eventTree->Branch("_clusterEnergies", _clusterEnergies, "_clusterEnergies[_nClusters]/F");
103  _eventTree->Branch("_clusterPts", _clusterPts, "_clusterPts[_nClusters]/F");
104  _eventTree->Branch("_clusterEtas", _clusterEtas, "_clusterEtas[_nClusters]/F");
105  _eventTree->Branch("_clusterPhis", _clusterPhis, "_clusterPhis[_nClusters]/F");
106  _eventTree->Branch("_maxTowerEtas", _maxTowerEtas, "_maxTowerEtas[_nClusters]/I");
107  _eventTree->Branch("_maxTowerPhis", _maxTowerPhis, "_maxTowerPhis[_nClusters]/I");
108  }
109 
111 }
112 
113 //____________________________________________________________________________..
115 {
116  if (m_ievent % 50 == 0)
117  // if (true)
118  {
119  std::cout << std::endl;
120  std::cout << "Beginning of the event " << m_ievent << std::endl;
121  std::cout << "====================================" << std::endl;
122  }
123 
125 
126  std::string clusnodename = "CLUSTER_CEMC";
127  if (m_UseTowerInfo && !_inputnodename.empty())
128  {
129  // clusnodename = "CLUSTERINFO_CEMC";
130  // clusnodename = "CLUSTERINFO2_CEMC";
131  clusnodename = _inputnodename;
132  }
133 
134  // create a cluster object
135  RawClusterContainer *recal_clusters = findNode::getClass<RawClusterContainer>(topNode, clusnodename);
136 
137  if (!recal_clusters)
138  {
139  std::cout << PHWHERE << "EMCal cluster node is missing, can't collect EMCal clusters" << std::endl;
140  }
141 
142  // create a tower object
143  std::string towernode = "TOWER_CALIB_" + _caloname;
144  RawTowerContainer *_towers = findNode::getClass<RawTowerContainer>(topNode, towernode);
145  if (!_towers && m_UseTowerInfo < 1)
146  {
147  std::cout << PHWHERE << " ERROR: Can't find " << towernode << std::endl;
148  }
149 
150  // create a tower geometry object
151  std::string towergeomnode = "TOWERGEOM_" + _caloname;
152  RawTowerGeomContainer *towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, towergeomnode);
153  if (!towergeom && m_UseTowerInfo < 1)
154  {
155  std::cout << PHWHERE << ": Could not find node " << towergeomnode << std::endl;
157  }
158 
159  // if using towerinfo
160  // create a tower object
161  // towernode = "TOWERINFO_CALIB_" + _caloname;
162  towernode = "TOWERS_Calib_" + _caloname;
163  if (!_inputtownodename.empty())
164  {
165  towernode = _inputtownodename;
166  }
167 
168  TowerInfoContainer *_towerinfos = findNode::getClass<TowerInfoContainer>(topNode, towernode);
169  if (!_towerinfos && m_UseTowerInfo > 0)
170  {
171  std::cout << PHWHERE << " ERROR: Can't find " << towernode << std::endl;
172  }
173 
174  if (m_ievent < 3)
175  {
176  std::cout << "using these nodes for cluster/tower: " << clusnodename << " " << towernode << std::endl;
177  }
178 
179  // Get Vertex
180  float vx = 0;
181  float vy = 0;
182  float vz = 0;
183  GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
184  if (vertexmap)
185  {
186  if (!vertexmap->empty())
187  {
188  GlobalVertex *vtx = (vertexmap->begin()->second);
189  vx = vtx->get_x();
190  vy = vtx->get_y();
191  vz = vtx->get_z();
192  }
193  }
195 
196  // std::cout << "vtx " << vx << " " << vy << std::endl;
197  // CLHEP::Hep3Vector vertex(vtx->get_x(), vtx->get_y(), vtx->get_z());
198  CLHEP::Hep3Vector vertex(vx, vy, vz);
199 
200  // ------------------------------
201 
202  // loop over the clusters
203  RawClusterContainer::ConstRange t_rbegin_end = recal_clusters->getClusters();
205 
206  RawCluster *savCs[10000]; // savingClusters that has 1 GeV or more
207  int iCs = 0;
208  int inCs = 0;
209 
210  // saving the clusters
211  for (t_rclusiter = t_rbegin_end.first; t_rclusiter != t_rbegin_end.second; ++t_rclusiter)
212  {
213  RawCluster *t_recalcluster = t_rclusiter->second;
214 
215  float cluse = t_recalcluster->get_ecore();
216  // std::cout << "clus " << cluse << std::endl;
217 
218  if (cluse > 0.5)
219  {
220  inCs++;
221  }
222 
223  if (cluse > 0.6 && t_recalcluster->get_chi2() < 4)
224  {
225  savCs[iCs++] = t_recalcluster;
226  }
227  }
228 
229  _nClusters = iCs;
230 
232  {
234  }
235 
236  // looping on the saved clusters savCs[]
237  // outer loop (we want to do pair of the loops)
238  for (int jCs = 0; jCs < iCs; jCs++)
239  {
240  CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*savCs[jCs], vertex);
241 
242  // CLHEP::Hep3Vector E_vec_cluster(PxCluster, PyCluster, ...);
243 
244  _clusterIDs[jCs] = savCs[jCs]->get_id();
245 
246  // vector to hold all the towers etas, phis, and energy in this cluster
247  std::vector<int> toweretas;
248  std::vector<int> towerphis;
249  std::vector<float> towerenergies;
250 
251  // loop over the towers from the outer loop cluster
252  // and find the max tower location and save the
253  // histogram on that max tower location with this
254  // invariant mass
255 
256  RawCluster::TowerConstRange towers = savCs[jCs]->get_towers();
258 
259  int towerieta = -1;
260  int toweriphi = -1;
261 
262  for (toweriter = towers.first; toweriter != towers.second; ++toweriter)
263  {
264  if (m_UseTowerInfo < 1)
265  {
266  RawTower *tower = _towers->getTower(toweriter->first);
267  towerieta = tower->get_bineta();
268  toweriphi = tower->get_binphi();
269  }
270  else
271  {
272  // this probably works for case above as well but to be checked...
273  // (ie probably no need for RawTower pointer or the if statement)
274  toweriphi = RawTowerDefs::decode_index2(toweriter->first); // index2 is phi in CYL
275  towerieta = RawTowerDefs::decode_index1(toweriter->first); // index1 is eta in CYL
276  }
277 
278  double towerenergy = toweriter->second;
279 
280  // put the eta, phi, energy into corresponding vectors
281  toweretas.push_back(towerieta);
282  towerphis.push_back(toweriphi);
283  towerenergies.push_back(towerenergy);
284  }
285 
286  // cout << endl;
287  // cout << "Cluster energy: " << tt_clus_energy << endl;
288  // cout << "Total number of towers (getNTowers()): " << savCs[jCs]->getNTowers() << endl;
289  // cout << "Total number of towers size(toweretas): " << toweretas.size() << endl;
290  // float maxTowerEnergy = *max_element(towerenergies.begin(), towerenergies.end());
291  // cout << "The maxTowerEnergy: " << maxTowerEnergy << endl;
292 
293  int maxTowerIndex = max_element(towerenergies.begin(), towerenergies.end()) - towerenergies.begin();
294  maxTowerEta = toweretas[maxTowerIndex];
295  maxTowerPhi = towerphis[maxTowerIndex];
296 
297  _maxTowerEtas[jCs] = maxTowerEta;
298  _maxTowerPhis[jCs] = maxTowerPhi;
299 
300  float tt_clus_energy = E_vec_cluster.mag();
301  float tt_clus_eta = E_vec_cluster.pseudoRapidity();
302  float tt_clus_pt = E_vec_cluster.perp();
303  float tt_clus_phi = E_vec_cluster.getPhi();
304 
305  // if (tt_clus_energy > 0.029)
306  // {
307 
308  // if (m_UseTowerInfo < 1)
309  // std::cout << "rawtJF clus " << jCs << " " << tt_clus_energy << " phi: "
310  // << tt_clus_phi << " eta: " << tt_clus_eta << " ieta "
311  // << maxTowerEta << " iphi " << maxTowerPhi
312  // << " towsize " << towerenergies.size() << std::endl;
313  // else
314  // std::cout << "infoJF clus " << jCs << " " << tt_clus_energy << " phi: "
315  // << tt_clus_phi << " eta: " << tt_clus_eta << " ieta "
316  // << maxTowerEta << " iphi " << maxTowerPhi
317  // << " towsize " << towerenergies.size() << std::endl;
318 
319  // }
320 
321  _clusterEnergies[jCs] = tt_clus_energy;
322  _clusterPts[jCs] = tt_clus_pt;
323  _clusterEtas[jCs] = tt_clus_eta;
324  _clusterPhis[jCs] = tt_clus_phi;
325 
326  if (tt_clus_pt > 0.9 && iCs > 400000) // while we are using the ntuples we don't need the
327  // rest of this fn --but this will likely change soon.
328  {
329  // another loop to go into the saved cluster
330  for (int kCs = 0; kCs < iCs; kCs++)
331  {
332  if (jCs == kCs)
333  {
334  continue;
335  }
336 
337  CLHEP::Hep3Vector E_vec_cluster2 = RawClusterUtility::GetECoreVec(*savCs[kCs], vertex);
338 
339  float tt2_clus_energy = E_vec_cluster2.mag();
340  if (tt2_clus_energy > 0.6) // again this will be greater than 1.0, but lets keep
341  {
342  // lets do alpha cut here: this is needed tho
343  alphaCut = std::abs(tt_clus_energy - tt2_clus_energy) / (tt_clus_energy + tt_clus_energy);
344  if (alphaCut <= 0.5)
345  {
346  float tt2_clus_eta = E_vec_cluster2.pseudoRapidity();
347  float tt2_clus_pt = E_vec_cluster2.perp();
348  float tt2_clus_phi = E_vec_cluster2.getPhi();
349 
350  TLorentzVector pho1, pho2, pi0lv;
351 
352  pho1.SetPtEtaPhiE(tt_clus_pt, tt_clus_eta, tt_clus_phi, tt_clus_energy);
353  pho2.SetPtEtaPhiE(tt2_clus_pt, tt2_clus_eta, tt2_clus_phi, tt2_clus_energy);
354 
355  if (pho1.DeltaR(pho2) > 0.8)
356  {
357  continue;
358  }
359  // if (pho1.Eta()/pho2.Eta() < 0) continue;
360 
361  pi0lv = pho1 + pho2;
362  float pairInvMass = pi0lv.M();
363 
364  pt1_ptpi0_alpha->Fill(tt_clus_pt, fabs(pi0lv.Pt()), alphaCut);
365 
366  // if (tt_clus_energy > 1.3 && tt2_clus_energy > 1.0 && fabs(pi0lv.Pt()) > 1.8)
367  if (fabs(pi0lv.Pt()) > 1.0)
368  {
369  pairInvMassTotal->Fill(pairInvMass);
370  mass_eta->Fill(pairInvMass, tt_clus_eta);
371  // mass_eta_phi->Fill(pairInvMass, tt_clus_eta, tt_clus_phi);
372 
373  // fill the tower by tower histograms with invariant mass
374  cemc_hist_eta_phi.at(maxTowerEta).at(maxTowerPhi)->Fill(pairInvMass);
375  eta_hist.at(maxTowerEta)->Fill(pairInvMass);
376  }
377  }
378  }
379  }
380  }
381  }
382  _eventTree->Fill();
383 
384  // m_ievent++;
385 
386  // pause few seconds
387  // std::chrono::seconds dura(2);
388  // std::this_thread::sleep_for(dura);
389  // std::std::cout << "Waited 2 sec\n";
390 
392 }
393 
394 //____________________________________________________________________________..
396 {
397  if (topNode == nullptr && f_temp)
398  {
399  cal_output->Close();
400  f_temp->Close();
401  delete f_temp;
402  delete cal_output;
404  }
405 
406  cal_output->cd();
407  // _eventTree->Write();
408  cal_output->Write();
409  cal_output->Close();
410  delete cal_output;
411 
413 }
414 
415 //______________________________________________________________________________..
416 void CaloCalibEmc_Pi0::Loop(int nevts, const std::string &filename, TTree *intree, const std::string &incorrFile)
417 {
418  // KINEMATIC CUTS ON PI0's ARE LISTED BELOW IN ONE SECTION OF COMMENTS
419  //
420  // search for "CUTS FOLLOW HERE"
421  //
422  // they are centrality dependent (centrality = nclusters > minpt) so they can only
423  // defined after loading up this values from the ntuples
424  // so they can't be moved here
425  //
426 
427  // std::arrays have their indices backward, this is the old float myaggcorr[96][260];
428  std::array<std::array<float, 260>, 96> myaggcorr{};
429  std::for_each(myaggcorr.begin(), myaggcorr.end(), [](auto &row)
430  { row.fill(1.); });
431 
432  std::cout << "running w/ corr file? : " << incorrFile << std::endl;
433 
434  if (!incorrFile.empty())
435  {
436  TFile *infileNt = new TFile(incorrFile.c_str());
437  std::cout << "loaded incorrFile " << infileNt << std::endl;
438 
439  float myieta;
440  float myiphi;
441  float mycorr;
442  float myaggcv;
443 
444  TNtuple *innt_corrVals = (TNtuple *) infileNt->Get("nt_corrVals");
445 
446  innt_corrVals->SetBranchAddress("tower_eta", &myieta);
447  innt_corrVals->SetBranchAddress("tower_phi", &myiphi);
448  innt_corrVals->SetBranchAddress("corr_val", &mycorr);
449  innt_corrVals->SetBranchAddress("agg_cv", &myaggcv);
450 
451  int ntCorrs = innt_corrVals->GetEntries();
452 
453  for (int ij = 0; ij < ntCorrs; ij++)
454  {
455  innt_corrVals->GetEntry(ij);
456  int ci = (int) myieta;
457  int cj = (int) myiphi;
458  myaggcorr.at(ci).at(cj) = myaggcv;
459  if (ij > ntCorrs - 2 || ij == ntCorrs / 2)
460  {
461  std::cout << "loaded corrs eta,phi,aggcv " << myieta
462  << " " << myiphi << " " << myaggcv << std::endl;
463  }
464  }
465 
466  infileNt->Close();
467  delete infileNt;
468  }
469 
470  std::cout << "in loop" << std::endl;
471 
472  TTree *t1 = intree;
473  if (!intree)
474  {
475  TFile *f = new TFile(filename.c_str());
476  t1 = (TTree *) f->Get("_eventTree");
477  }
478 
479  // Set Branches
480  // t1->SetBranchAddress("_eventNumber", &_eventNumber);
481  t1->SetBranchAddress("_nClusters", &_nClusters);
482  // t1->SetBranchAddress("_clusterIDs", _clusterIDs);
483  t1->SetBranchAddress("_clusterEnergies", _clusterEnergies);
484  t1->SetBranchAddress("_clusterPts", _clusterPts);
485  t1->SetBranchAddress("_clusterEtas", _clusterEtas);
486  t1->SetBranchAddress("_clusterPhis", _clusterPhis);
487  t1->SetBranchAddress("_maxTowerEtas", _maxTowerEtas);
488  t1->SetBranchAddress("_maxTowerPhis", _maxTowerPhis);
489 
490  // pre-loop to save all the clusters LorentzVector
491 
492  TLorentzVector *savClusLV[10000];
493 
494  // int nEntries = (int) t1->GetEntriesFast();
495  int nEntries = (int) t1->GetEntries();
496  int nevts2 = nevts;
497 
498  if (nevts < 0 || nEntries < nevts)
499  {
500  nevts2 = nEntries;
501  }
502 
503  // keeping track of discarded clusters for v7
504  int discarded_clusters = 0;
505 
506  for (int i = 0; i < nevts2; i++)
507  {
508  // load the ith instance of the TTree
509  t1->GetEntry(i);
510 
511  if ((i % 10 == 0 && i < 200) || (i % 100 == 0 && i < 1000) || (i % 1000 == 0 && i < 37003) || i % 10000 == 0)
512  {
513  std::cout << "evt no " << i << std::endl;
514  }
515  // calibration correction will be applied here
516 
517  int nClusters = _nClusters;
518 
519  // see below this is like centrality cut, but currently need central events
520  // as well as peripheral to maximize statistical power
521  if (nClusters > 1000)
522  {
523  discarded_clusters += 1;
524  continue;
525  }
526 
527  float pt1cut = 0, pt2cut = 0;
528 
529  for (int j = 0; j < nClusters; j++)
530  {
531  // float px, py, pz;
532  float pt, eta, phi, E, aggcv;
533  pt = _clusterPts[j];
534  eta = _clusterEtas[j];
535  phi = _clusterPhis[j];
536  E = _clusterEnergies[j];
537  // px = pt * cos(phi);
538  // py = pt * sin(phi);
539  // pz = pt * sinh(eta);
540  // pt *= myaggcorr[
541  aggcv = myaggcorr.at(_maxTowerEtas[j]).at(_maxTowerPhis[j]);
542 
543  // std::cout << "aggcv applied: " << aggcv << std::endl;
544 
545  // eta slice shifts test
546  // int ket = _maxTowerEtas[j]/4;
547  // int jket = ket %4;
548  // if ((ket/4)%2==1)
549  // jket = 4-ket%4;
550  // int pjj = _maxTowerEtas[j]%4 - 1;
551  // aggcv *= 0.86+jket*0.11 + 0.02*pjj;
552 
553  pt *= aggcv;
554  E *= aggcv;
555 
556  savClusLV[j] = new TLorentzVector();
557  savClusLV[j]->SetPtEtaPhiE(pt, eta, phi, E);
558  }
559 
560  TLorentzVector *pho1, *pho2;
561  int iCs = nClusters;
562  for (int jCs = 0; jCs < iCs; jCs++)
563  {
564  pho1 = savClusLV[jCs];
567  // *********************************
568  //
569  // CUTS FOLLOW HERE (e.g. pt cuts)
570  //
571  //*************************************
573 
574  // centrality dependent pt cuts designed to keep
575  // statistical cluster count contribution (& sig/bkg)
576  // constant with all centrality
577  // in order to maximize statistical power i.e. using all events
578  // in the calibration not just peripheral events.
579  // this is neccessary for the summer 23 data because
580  // the event rate was small and the total statistics per
581  // stable calibration period (typically a daq run-length) is small
582 
583  float modCutFactor = 1.0;
584 
585  if (iCs < 30)
586  {
587  // pt1cut = 1.65*modCutFactor;
588  // pt2cut = 0.8*modCutFactor;
589 
590  pt1cut = 1.3 * modCutFactor;
591  pt2cut = 0.7 * modCutFactor;
592  }
593  else
594  {
595  // pt1cut = 1.65*modCutFactor + 1.4*(iCs-29)/200.0*modCutFactor;
596  // pt2cut = 0.8*modCutFactor + 1.4*(iCs-29)/200.0*modCutFactor;
597 
598  pt1cut = 1.3 * modCutFactor + 1.4 * (iCs - 29) / 200.0 * modCutFactor;
599  pt2cut = 0.7 * modCutFactor + 1.4 * (iCs - 29) / 200.0 * modCutFactor;
600  }
601 
602  float pi0ptcut = 1.22 * (pt1cut + pt2cut);
603 
604  // energy asymmetry alpha cut
605  float alphacutval = 0.6;
606 
607  float deltaRconecut = 1.1; // 2-gamma opening angle(dR) cut
608  // value relevant for background extent in mass
609  // not in peak area.
610 
613  // END CUTS
616 
617  if (fabs(pho1->Pt()) < pt1cut)
618  {
619  continue;
620  }
621 
622  // another loop to go into the saved cluster
623  for (int kCs = 0; kCs < iCs; kCs++)
624  {
625  if (jCs == kCs)
626  {
627  continue;
628  }
629 
630  pho2 = savClusLV[kCs];
631 
632  if (fabs(pho2->Pt()) < pt2cut)
633  {
634  continue;
635  }
636 
637  alphaCut = fabs((pho1->E() - pho2->E()) / (pho1->E() + pho2->E()));
638 
639  if (alphaCut > alphacutval)
640  {
641  continue;
642  }
643 
644  TLorentzVector pi0lv;
645 
646  if (pho1->DeltaR(*pho2) > deltaRconecut)
647  {
648  continue;
649  }
650 
651  pi0lv = *pho1 + *pho2;
652  if (fabs(pi0lv.Pt()) > pi0ptcut)
653  {
654  float pairInvMass = pi0lv.M();
655 
656  // fill the tower by tower histograms with invariant mass
657  // cemc_hist_eta_phi[_maxTowerEtas[jCs]][_maxTowerPhis[jCs]]->Fill(pairInvMass);
658  // not useful in summer 23 data
659  eta_hist.at(_maxTowerEtas[jCs])->Fill(pairInvMass);
660  pt1_ptpi0_alpha->Fill(pho1->Pt(), pi0lv.Pt(), alphaCut);
661  pairInvMassTotal->Fill(pairInvMass);
662  mass_eta->Fill(pairInvMass, _clusterEtas[jCs]);
663  mass_eta_phi->Fill(pairInvMass, _clusterEtas[jCs], _clusterPhis[jCs]);
664  }
665  }
666  }
667  }
668  std::cout << "total number of events: " << nEntries << std::endl;
669  std::cout << "total number of events discarded: " << discarded_clusters << std::endl;
670 }
671 
672 //__________oo00oo__________oo00oo_________________
673 // This one is for etaslices
674 void CaloCalibEmc_Pi0::Loop_for_eta_slices(int nevts, const std::string &filename, TTree *intree, const std::string &incorrFile)
675 {
676  // std::arrays have their indices backward, this is the old float myaggcorr[96][260];
677  std::array<std::array<float, 260>, 96> myaggcorr{};
678  std::for_each(myaggcorr.begin(), myaggcorr.end(), [](auto &row)
679  { row.fill(1.); });
680 
681  std::cout << "running w/ corr file? : " << incorrFile << std::endl;
682 
683  if (!incorrFile.empty())
684  {
685  TFile *infileNt = new TFile(incorrFile.c_str());
686  std::cout << "loaded incorrFile " << infileNt << std::endl;
687 
688  float myieta;
689  float myiphi;
690  float mycorr;
691  float myaggcv;
692 
693  TNtuple *innt_corrVals = (TNtuple *) infileNt->Get("nt_corrVals");
694 
695  innt_corrVals->SetBranchAddress("tower_eta", &myieta);
696  innt_corrVals->SetBranchAddress("tower_phi", &myiphi);
697  innt_corrVals->SetBranchAddress("corr_val", &mycorr);
698  innt_corrVals->SetBranchAddress("agg_cv", &myaggcv);
699 
700  int ntCorrs = innt_corrVals->GetEntries();
701 
702  for (int ij = 0; ij < ntCorrs; ij++)
703  {
704  innt_corrVals->GetEntry(ij);
705  int ci = (int) myieta;
706  int cj = (int) myiphi;
707  myaggcorr.at(ci).at(cj) = myaggcv;
708  if (ij > ntCorrs - 2)
709  {
710  std::cout << "loaded corrs eta,phi,aggcv " << myieta
711  << " " << myiphi << " " << myaggcv << std::endl;
712  }
713  }
714 
715  infileNt->Close();
716  delete infileNt;
717  }
718 
719  std::cout << "in loop" << std::endl;
720 
721  TTree *t1 = intree;
722  if (!intree)
723  {
724  TFile *f = new TFile(filename.c_str());
725  t1 = (TTree *) f->Get("_eventTree");
726  }
727 
728  // Set Branches
729  // t1->SetBranchAddress("_eventNumber", &_eventNumber);
730  t1->SetBranchAddress("_nClusters", &_nClusters);
731  // t1->SetBranchAddress("_clusterIDs", _clusterIDs);
732  t1->SetBranchAddress("_clusterEnergies", _clusterEnergies);
733  t1->SetBranchAddress("_clusterPts", _clusterPts);
734  t1->SetBranchAddress("_clusterEtas", _clusterEtas);
735  t1->SetBranchAddress("_clusterPhis", _clusterPhis);
736  t1->SetBranchAddress("_maxTowerEtas", _maxTowerEtas);
737  t1->SetBranchAddress("_maxTowerPhis", _maxTowerPhis);
738 
739  // pre-loop to save all the clusters LorentzVector
740 
741  std::array<TLorentzVector *, 10000> savClusLV{};
742 
743  // int nEntries = (int) t1->GetEntriesFast();
744  int nEntries = (int) t1->GetEntries();
745  int nevts2 = nevts;
746 
747  if (nevts < 0 || nEntries < nevts)
748  {
749  nevts2 = nEntries;
750  }
751 
752  for (int i = 0; i < nevts2; i++)
753  {
754  // load the ith instance of the TTree
755  t1->GetEntry(i);
756 
757  if ((i % 10 == 0 && i < 200) || (i % 100 == 0 && i < 1000) || (i % 1000 == 0 && i < 37003) || i % 10000 == 0)
758  {
759  std::cout << "evt no " << i << std::endl;
760  }
761  // calibration correction will be applied here
762 
763  int nClusters = _nClusters;
764 
765  if (nClusters > 60)
766  {
767  continue;
768  }
769 
770  for (int j = 0; j < nClusters; j++)
771  {
772  // float px, py, pz;
773  float pt, eta, phi, E, aggcv;
774  pt = _clusterPts[j];
775  eta = _clusterEtas[j];
776  phi = _clusterPhis[j];
777  E = _clusterEnergies[j];
778  aggcv = myaggcorr.at(_maxTowerEtas[j]).at(_maxTowerPhis[j]);
779 
780  pt *= aggcv;
781  E *= aggcv;
782 
783  savClusLV.at(j) = new TLorentzVector();
784  savClusLV.at(j)->SetPtEtaPhiE(pt, eta, phi, E);
785  }
786 
787  TLorentzVector *pho1, *pho2;
788  int iCs = nClusters;
789  for (int jCs = 0; jCs < iCs; jCs++)
790  {
791  pho1 = savClusLV.at(jCs);
792 
793  if (fabs(pho1->Pt()) < 1.0)
794  {
795  continue;
796  }
797 
798  // another loop to go into the saved cluster
799  for (int kCs = 0; kCs < iCs; kCs++)
800  {
801  if (jCs == kCs)
802  {
803  continue;
804  }
805 
806  pho2 = savClusLV.at(kCs);
807 
808  if (fabs(pho2->Pt()) < 0.6)
809  {
810  continue;
811  }
812 
813  TLorentzVector pi0lv;
814  if (pho1->DeltaR(*pho2) > 0.45)
815  {
816  continue;
817  }
818  pi0lv = *pho1 + *pho2;
819  float pairInvMass = pi0lv.M();
820  if (pi0lv.Pt() < 1.0)
821  {
822  continue;
823  }
824 
825  /*
826  if (_maxTowerEtas[jCs]==50 && ((pi0lv.M()>=0.015 && pi0lv.M()<=0.095) || (pi0lv.M()>=0.175 && pi0lv.M()<=0.255)))
827  {
828  e1_hist_wo_alpha->Fill(pho1->E());
829  e2_hist_wo_alpha->Fill(pho2->E());
830  }
831  */
832 
833  alphaCut = fabs((pho1->E() - pho2->E()) / (pho1->E() + pho2->E()));
834  if (alphaCut > 0.50)
835  {
836  continue; // 0.50 to begin with
837  }
838 
839  /*
840  if (_maxTowerEtas[jCs]==50 && ((pi0lv.M()>=0.015 && pi0lv.M()<=0.095) || (pi0lv.M()>=0.175 && pi0lv.M()<=0.255)))
841  {
842  e1_hist_w_alpha->Fill(pho1->E());
843  e2_hist_w_alpha->Fill(pho2->E());
844  }
845  */
846 
847  // fill the tower by tower histograms with invariant mass
848  // we don't need to fill tower-by-tower level when we do for eta slices
849  // although filling here just so we don't have to change codes in other places
850  cemc_hist_eta_phi.at(_maxTowerEtas[jCs]).at(_maxTowerPhis[jCs])->Fill(pairInvMass);
851  eta_hist.at(_maxTowerEtas[jCs])->Fill(pairInvMass);
852  // pt1_ptpi0_alpha->Fill(pho1->Pt(), pi0lv.Pt(), alphaCut);
853  }
854  }
855  }
856 }
857 
858 // _______________________________________________________________..
860 {
861  std::cout << " Inside Fit_Histos_Eta_Phi." << std::endl;
862 
863  // std::arrays have their indices backward, this is the old float myaggcorr[96][256];
864  std::array<std::array<float, 256>, 96> myaggcorr{};
865  std::for_each(myaggcorr.begin(), myaggcorr.end(), [](auto &row)
866  { row.fill(1.); });
867 
868  if (!incorrFile.empty())
869  {
870  TFile *infileNt = new TFile(incorrFile.c_str());
871 
872  float myieta;
873  float myiphi;
874  float mycorr;
875  float myaggcv;
876 
877  TNtuple *innt_corrVals = (TNtuple *) infileNt->Get("nt_corrVals");
878 
879  innt_corrVals->SetBranchAddress("tower_eta", &myieta);
880  innt_corrVals->SetBranchAddress("tower_phi", &myiphi);
881  innt_corrVals->SetBranchAddress("corr_val", &mycorr);
882  innt_corrVals->SetBranchAddress("agg_cv", &myaggcv);
883 
884  int ntCorrs = innt_corrVals->GetEntries();
885 
886  for (int ij = 0; ij < ntCorrs; ij++)
887  {
888  innt_corrVals->GetEntry(ij);
889  int ci = (int) myieta;
890  int cj = (int) myiphi;
891  myaggcorr.at(ci).at(cj) = myaggcv;
892  if (ij > ntCorrs - 2)
893  {
894  std::cout << "loaded corrs eta,phi,aggcv " << myieta
895  << " " << myiphi << " " << myaggcv << std::endl;
896  }
897  }
898 
899  infileNt->Close();
900  delete infileNt;
901  }
902 
903  cal_output->cd();
904 
905  TF1 *f1[25000];
906  TF1 *f2[25000];
907  TF1 *total[25000];
908  TF1 *fit_fn[25000];
909  int kj = 0;
910 
911  // arrays to hold the fit results (cemc)
912  fitp1_eta_phi2d = new TH2F("fitp1_eta_phi2d", "fit p1 eta phi", 96, 0, 96, 256, 0, 256);
913 
914  double cemc_par1_values[96][256] = {{0.0}}; // mising braces Werror w/o double braces
915  // double cemc_par0_values[96][256] = {0.0};
916  // double cemc_par0_errors[96][256] = {0.0};
917  double cemc_par1_errors[96][256] = {{0.0}};
918  // double cemc_par2_values[96][256] = {0.0};
919  // double cemc_par2_errors[96][256] = {0.0};
920 
921  // create Ntuple object of the fit result from the data
922  TNtuple *nt_corrVals = new TNtuple("nt_corrVals", "Ntuple of the corrections", "tower_eta:tower_phi:corr_val:agg_cv");
923 
924  for (int ieta = 0; ieta < 96; ieta++) // eta loop
925  {
926  for (int iphi = 0; iphi < 256; iphi++)
927  {
928  // for(int ithirds=0; ithirds<3; ithirds++)
929  //{
930  // for (int ieta=0+ithirds*32; ieta<(ithirds*32+16); ieta++)
931  // {
932  // for (int iphi=0; iphi<16; iphi++)
933  // {
934  // }
935  // }
936  // }
937  // find max bin around peak
938  float pkloc = 0.0;
939  float bsavloc = 0.0;
940  for (int kfi = 1; kfi < 20; kfi++) // old kfi<25
941  {
942  float locbv = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinContent(kfi);
943  if (locbv > bsavloc)
944  {
945  pkloc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinCenter(kfi);
946  bsavloc = locbv;
947  }
948  }
949 
950  f1[kj] = new TF1("f1", "gaus", 0.06, 0.20); //"gaus",pkloc-0.03,pkloc+0.03
951  f2[kj] = new TF1("f2", "pol2", 0.01, 0.4);
952 
953  cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(f1[kj], "", "", pkloc - 0.04, pkloc + 0.04);
954  float fpkloc2 = f1[kj]->GetParameter(1);
955 
956  TGraphErrors *grtemp = new TGraphErrors();
957  std::string bkgNm = std::string("grBkgEta_phi_") + std::to_string(ieta) + std::string("_") + std::to_string(iphi);
958 
959  std::cout << " getting " << bkgNm << " mean was " << fpkloc2
960  << " " << pkloc << std::endl;
961 
962  grtemp->SetName(bkgNm.c_str());
963  int ingr = 0;
964  for (int gj = 1; gj < cemc_hist_eta_phi.at(ieta).at(iphi)->GetNbinsX() + 1; gj++)
965  {
966  float binc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinCenter(gj);
967  float cntc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinContent(gj);
968  if ((binc > 0.06 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.22 * fpkloc2 / 0.145 && binc < 0.35 * fpkloc2 / 0.145))
969  {
970  grtemp->SetPoint(ingr, binc, cntc);
971  grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
972  }
973  }
974 
975  grtemp->Fit(f2[kj]);
976 
977  total[kj] = new TF1("total", "gaus(0)+pol2(3)", 0.06, 0.25); // 0.3*fpkloc2/0.145
978 
979  double par[6];
980 
981  f1[kj]->GetParameters(&par[0]);
982  f2[kj]->GetParameters(&par[3]);
983 
984  total[kj]->SetParameters(par);
985  total[kj]->SetParLimits(2, 0.01, 0.027);
986 
987  cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(total[kj], "R");
988  fit_fn[kj] = cemc_hist_eta_phi.at(ieta).at(iphi)->GetFunction("total");
989 
990  grtemp->Write();
991 
992  if (fit_fn[kj])
993  {
994  // cemc_hist_eta_phi.at(ieta).at(iphi) = i;
995  cemc_par1_values[ieta][iphi] = fit_fn[kj]->GetParameter(1);
996 
997  // if (!(cemc_par1_values[ieta][iphi]>0.0))
998  // {
999  // cemc_par1_values[ieta][iphi] = 0.5;
1000  // }
1001  // cemc_par0_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(0);
1002  cemc_par1_errors[ieta][iphi] = fit_fn[kj]->GetParError(1);
1003  // cemc_par2_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(2);
1004  // cemc_par2_errors[ieta][iphi] = cemc_eta_phi_result->GetParError(2);
1005  }
1006  else
1007  {
1008  std::cout << "Warning::Fit Failed for eta bin : " << ieta << iphi << std::endl;
1009  cemc_par1_values[ieta][iphi] = -999.0;
1010  cemc_par1_errors[ieta][iphi] = -999.0;
1011  }
1012 
1013  nt_corrVals->Fill(ieta, iphi, 0.135 / cemc_par1_values[ieta][iphi], 0.135 / cemc_par1_values[ieta][iphi] * myaggcorr.at(ieta).at(iphi));
1014  //}
1015 
1016  // cemc_p1_eta_phi->Fill(cemc_par1_values[ieta][iphi],ieta,iphi);
1017 
1018  // fitp0_eta_phi2d->SetBinContent(ieta+1,iphi+1,cemc_par0_values[ieta][iphi]);
1019  fitp1_eta_phi2d->SetBinContent(ieta + 1, iphi + 1, cemc_par1_values[ieta][iphi]);
1020  fitp1_eta_phi2d->SetBinError(ieta + 1, iphi + 1, cemc_par1_errors[ieta][iphi]);
1021 
1022  kj++;
1023  }
1024  }
1025 
1026  // nt_corrVals->Fill(ieta,259,0.135/cemc_par1_values[ieta][iphi],0.135/cemc_par1_values[ieta][iphi]*myaggcorr[ieta][259]);
1027 
1028  /*
1029  TGraphErrors g1(96, eta_value, eta_par1_value, 0, eta_par1_error);
1030  g1.SetTitle("pi0 mean eta; eta; p1");
1031  g1.SetMarkerStyle(20);
1032  g1.SetMarkerColor(2);
1033  g1.Draw("P");
1034  g1.SetName("eta_p1");
1035  g1.Write();
1036 
1037  TGraphErrors g2(96, eta_value, eta_par2_value, 0, eta_par2_error);
1038  g2.SetTitle("pi0 sigma eta; eta; p2");
1039  g2.Draw("AP");
1040  g2.SetName("eta_p2");
1041  g2.Write();
1042 
1043  */
1044 
1045  fitp1_eta_phi2d->Write();
1046  std::cout << " finished fit_histos_eta_phi. " << std::endl;
1047 }
1048 
1049 // _______________________________________________________________..
1051 {
1052  std::cout << " Inside Fit_Histos_Eta_Phi." << std::endl;
1053  // std::arrays have their indices backward, this is the old float myaggcorr[96][256];
1054  std::array<std::array<float, 256>, 96> myaggcorr{};
1055  std::for_each(myaggcorr.begin(), myaggcorr.end(), [](auto &row)
1056  { row.fill(1.); });
1057 
1058  if (!incorrFile.empty())
1059  {
1060  TFile *infileNt = new TFile(incorrFile.c_str());
1061 
1062  float myieta;
1063  float myiphi;
1064  float mycorr;
1065  float myaggcv;
1066 
1067  TNtuple *innt_corrVals = (TNtuple *) infileNt->Get("nt_corrVals");
1068 
1069  innt_corrVals->SetBranchAddress("tower_eta", &myieta);
1070  innt_corrVals->SetBranchAddress("tower_phi", &myiphi);
1071  innt_corrVals->SetBranchAddress("corr_val", &mycorr);
1072  innt_corrVals->SetBranchAddress("agg_cv", &myaggcv);
1073 
1074  int ntCorrs = innt_corrVals->GetEntries();
1075 
1076  for (int ij = 0; ij < ntCorrs; ij++)
1077  {
1078  innt_corrVals->GetEntry(ij);
1079  int ci = (int) myieta;
1080  int cj = (int) myiphi;
1081  myaggcorr.at(ci).at(cj) = myaggcv;
1082  if (ij > ntCorrs - 2)
1083  {
1084  std::cout << "loaded corrs eta,phi,aggcv " << myieta
1085  << " " << myiphi << " " << myaggcv << std::endl;
1086  }
1087  }
1088 
1089  infileNt->Close();
1090  delete infileNt;
1091  }
1092 
1093  cal_output->cd();
1094 
1095  TF1 *f1[25000];
1096  TF1 *f2[25000];
1097  TF1 *total[25000];
1098  TF1 *fit_fn[25000];
1099  int kj = 0;
1100 
1101  // arrays to hold the fit results (cemc)
1102  fitp1_eta_phi2d = new TH2F("fitp1_eta_phi2d", "fit p1 eta phi", 96, 0, 96, 256, 0, 256);
1103 
1104  double cemc_par1_values[96][256] = {{0.0}}; // mising braces Werror w/o double braces
1105  // double cemc_par0_values[96][256] = {0.0};
1106  // double cemc_par0_errors[96][256] = {0.0};
1107  double cemc_par1_errors[96][256] = {{0.0}};
1108  // double cemc_par2_values[96][256] = {0.0};
1109  // double cemc_par2_errors[96][256] = {0.0};
1110 
1111  // create Ntuple object of the fit result from the data
1112  TNtuple *nt_corrVals = new TNtuple("nt_corrVals", "Ntuple of the corrections", "tower_eta:tower_phi:corr_val:agg_cv");
1113 
1114  for (int ieta = 0; ieta < 96; ieta++) // eta loop
1115  {
1116  for (int iphi = 0; iphi < 256; iphi++)
1117  {
1118  if (ieta > 15 || iphi > 15)
1119  {
1120  continue;
1121  }
1122 
1123  // for(int ithirds=0; ithirds<3; ithirds++)
1124  //{
1125  // for (int ieta=0+ithirds*32; ieta<(ithirds*32+16); ieta++)
1126  // {
1127  // for (int iphi=0; iphi<16; iphi++)
1128  // {
1129  // }
1130  // }
1131  // }
1132  // find max bin around peak
1133  float pkloc = 0.0;
1134  float bsavloc = 0.0;
1135  for (int kfi = 1; kfi < 20; kfi++) // old kfi<25
1136  {
1137  float locbv = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinContent(kfi);
1138  if (locbv > bsavloc)
1139  {
1140  pkloc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinCenter(kfi);
1141  bsavloc = locbv;
1142  }
1143  }
1144 
1145  f1[kj] = new TF1("f1", "gaus", 0.06, 0.20); //"gaus",pkloc-0.03,pkloc+0.03
1146  f2[kj] = new TF1("f2", "pol2", 0.01, 0.4);
1147 
1148  cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(f1[kj], "", "", pkloc - 0.04, pkloc + 0.04);
1149  float fpkloc2 = f1[kj]->GetParameter(1);
1150 
1151  TGraphErrors *grtemp = new TGraphErrors();
1152  std::string bkgNm = std::string("grBkgEta_phi_") + std::to_string(ieta) + std::string("_") + std::to_string(iphi);
1153 
1154  std::cout << " getting " << bkgNm << " mean was " << fpkloc2
1155  << " " << pkloc << std::endl;
1156 
1157  grtemp->SetName(bkgNm.c_str());
1158  int ingr = 0;
1159  for (int gj = 1; gj < cemc_hist_eta_phi.at(ieta).at(iphi)->GetNbinsX() + 1; gj++)
1160  {
1161  float binc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinCenter(gj);
1162  float cntc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinContent(gj);
1163  if ((binc > 0.06 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.22 * fpkloc2 / 0.145 && binc < 0.35 * fpkloc2 / 0.145))
1164  {
1165  grtemp->SetPoint(ingr, binc, cntc);
1166  grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
1167  }
1168  }
1169 
1170  grtemp->Fit(f2[kj]);
1171 
1172  total[kj] = new TF1("total", "gaus(0)+pol2(3)", 0.06, 0.25); // 0.3*fpkloc2/0.145
1173 
1174  double par[6];
1175 
1176  f1[kj]->GetParameters(&par[0]);
1177  f2[kj]->GetParameters(&par[3]);
1178 
1179  total[kj]->SetParameters(par);
1180  total[kj]->SetParLimits(2, 0.01, 0.027);
1181 
1182  cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(total[kj], "R");
1183  fit_fn[kj] = cemc_hist_eta_phi.at(ieta).at(iphi)->GetFunction("total");
1184 
1185  grtemp->Write();
1186 
1187  if (fit_fn[kj])
1188  {
1189  // cemc_hist_eta_phi.at(ieta).at(iphi) = i;
1190  cemc_par1_values[ieta][iphi] = fit_fn[kj]->GetParameter(1);
1191 
1192  // if (!(cemc_par1_values[ieta][iphi]>0.0))
1193  // {
1194  // cemc_par1_values[ieta][iphi] = 0.5;
1195  // }
1196  // cemc_par0_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(0);
1197  cemc_par1_errors[ieta][iphi] = fit_fn[kj]->GetParError(1);
1198  // cemc_par2_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(2);
1199  // cemc_par2_errors[ieta][iphi] = cemc_eta_phi_result->GetParError(2);
1200  }
1201  else
1202  {
1203  std::cout << "Warning::Fit Failed for eta bin : " << ieta << iphi << std::endl;
1204  }
1205 
1206  for (int ipatt_eta = 0; ipatt_eta < 6; ipatt_eta++)
1207  {
1208  for (int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1209  {
1210  // if ((ipatt_eta>0) || (ipatt_phi>0))
1211  //{
1212  nt_corrVals->Fill(ieta + ipatt_eta * 16, iphi + ipatt_phi * 16, 0.135 / cemc_par1_values[ieta][iphi], 0.135 / cemc_par1_values[ieta][iphi] * myaggcorr.at(ieta).at(iphi));
1213  //}
1214  }
1215  }
1216 
1217  // nt_corrVals->Fill(ieta,259,0.135/cemc_par1_values[ieta][iphi],0.135/cemc_par1_values[ieta][iphi]*myaggcorr[ieta][259]);
1218 
1219  // cemc_p1_eta_phi->Fill(cemc_par1_values[ieta][iphi],ieta,iphi);
1220 
1221  // fitp0_eta_phi2d->SetBinContent(ieta+1,iphi+1,cemc_par0_values[ieta][iphi]);
1222  fitp1_eta_phi2d->SetBinContent(ieta + 1, iphi + 1, cemc_par1_values[ieta][iphi]);
1223  fitp1_eta_phi2d->SetBinError(ieta + 1, iphi + 1, cemc_par1_errors[ieta][iphi]);
1224 
1225  kj++;
1226  }
1227  }
1228 
1229  /*
1230  TGraphErrors g1(96, eta_value, eta_par1_value, 0, eta_par1_error);
1231  g1.SetTitle("pi0 mean eta; eta; p1");
1232  g1.SetMarkerStyle(20);
1233  g1.SetMarkerColor(2);
1234  g1.Draw("P");
1235  g1.SetName("eta_p1");
1236  g1.Write();
1237 
1238  TGraphErrors g2(96, eta_value, eta_par2_value, 0, eta_par2_error);
1239  g2.SetTitle("pi0 sigma eta; eta; p2");
1240  g2.Draw("AP");
1241  g2.SetName("eta_p2");
1242  g2.Write();
1243 
1244  */
1245 
1246  fitp1_eta_phi2d->Write();
1247  std::cout << " finished fit_histos_eta_phi. " << std::endl;
1248 }
1249 
1250 // _______________________________________________________________..
1252 {
1253  std::cout << " Inside Fit_Histos_Eta_Phi." << std::endl;
1254 
1255  // std::arrays have their indices backward, this is the old float myaggcorr[96][256];
1256  std::array<std::array<float, 256>, 96> myaggcorr{};
1257  std::for_each(myaggcorr.begin(), myaggcorr.end(), [](auto &row)
1258  { row.fill(1.); });
1259 
1260  if (!incorrFile.empty())
1261  {
1262  TFile *infileNt = new TFile(incorrFile.c_str());
1263 
1264  float myieta;
1265  float myiphi;
1266  float mycorr;
1267  float myaggcv;
1268 
1269  TNtuple *innt_corrVals = (TNtuple *) infileNt->Get("nt_corrVals");
1270 
1271  innt_corrVals->SetBranchAddress("tower_eta", &myieta);
1272  innt_corrVals->SetBranchAddress("tower_phi", &myiphi);
1273  innt_corrVals->SetBranchAddress("corr_val", &mycorr);
1274  innt_corrVals->SetBranchAddress("agg_cv", &myaggcv);
1275 
1276  int ntCorrs = innt_corrVals->GetEntries();
1277 
1278  for (int ij = 0; ij < ntCorrs; ij++)
1279  {
1280  innt_corrVals->GetEntry(ij);
1281  int ci = (int) myieta;
1282  int cj = (int) myiphi;
1283  myaggcorr.at(ci).at(cj) = myaggcv;
1284  if (ij > ntCorrs - 2)
1285  {
1286  std::cout << "loaded corrs eta,phi,aggcv " << myieta
1287  << " " << myiphi << " " << myaggcv << std::endl;
1288  }
1289  }
1290 
1291  infileNt->Close();
1292  delete infileNt;
1293  }
1294 
1295  cal_output->cd();
1296 
1297  TF1 *f1[25000];
1298  TF1 *f2[25000];
1299  TF1 *total[25000];
1300  int kj = 0;
1301 
1302  // arrays to hold the fit results (cemc)
1303  TF1 *cemc_eta_phi_result = nullptr;
1304  fitp1_eta_phi2d = new TH2F("fitp1_eta_phi2d", "fit p1 eta phi", 96, 0, 96, 256, 0, 256);
1305  double cemc_par1_values[96][256] = {{0.0}};
1306  // double cemc_par0_values[96][256] = {0.0};
1307  // double cemc_par0_errors[96][256] = {0.0};
1308  double cemc_par1_errors[96][256] = {{0.0}};
1309  // double cemc_par2_values[96][256] = {0.0};
1310  // double cemc_par2_errors[96][256] = {0.0};
1311 
1312  // create Ntuple object of the fit result from the data
1313  TNtuple *nt_corrVals = new TNtuple("nt_corrVals", "Ntuple of the corrections", "tower_eta:tower_phi:corr_val:agg_cv");
1314 
1315  for (int ithirds = 0; ithirds < 3; ithirds++)
1316  {
1317  for (int ieta = 0 + ithirds * 32; ieta < (ithirds * 32 + 16); ieta++)
1318  {
1319  for (int iphi = 0; iphi < 16; iphi++)
1320  {
1321  float pkloc = 0.0;
1322  float bsavloc = 0.0;
1323  for (int kfi = 1; kfi < 25; kfi++) // assuming pi0 peak within 25 bins and no other peak within
1324  {
1325  float locbv = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinContent(kfi);
1326  if (locbv > bsavloc)
1327  {
1328  pkloc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinCenter(kfi);
1329  bsavloc = locbv;
1330  }
1331  }
1332 
1333  f1[kj] = new TF1("f1", "gaus", pkloc - 0.03, pkloc + 0.03);
1334  f2[kj] = new TF1("f2", "pol2", 0.01, 0.4);
1335 
1336  cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(f1[kj], "", "", pkloc - 0.04, pkloc + 0.04);
1337  float fpkloc2 = f1[kj]->GetParameter(1);
1338 
1339  TGraphErrors *grtemp = new TGraphErrors();
1340  std::string bkgNm = std::string("grBkgEta_phi_") + std::to_string(ieta) + std::string("_") + std::to_string(iphi);
1341 
1342  std::cout << " getting " << bkgNm << " mean was " << fpkloc2
1343  << " " << pkloc << std::endl;
1344 
1345  grtemp->SetName(bkgNm.c_str());
1346  int ingr = 0;
1347  for (int gj = 1; gj < cemc_hist_eta_phi.at(ieta).at(iphi)->GetNbinsX() + 1; gj++)
1348  {
1349  float binc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinCenter(gj);
1350  float cntc = cemc_hist_eta_phi.at(ieta).at(iphi)->GetBinContent(gj);
1351  if ((binc > 0.06 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.22 * fpkloc2 / 0.145 && binc < 0.35 * fpkloc2 / 0.145))
1352  {
1353  grtemp->SetPoint(ingr, binc, cntc);
1354  grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
1355  }
1356  }
1357 
1358  grtemp->Fit(f2[kj]);
1359 
1360  total[kj] = new TF1("total", "gaus(0)+pol2(3)", 0.06, 0.3 * fpkloc2 / 0.145);
1361 
1362  double par[6];
1363 
1364  f1[kj]->GetParameters(&par[0]);
1365  f2[kj]->GetParameters(&par[3]);
1366 
1367  total[kj]->SetParameters(par);
1368  total[kj]->SetParLimits(2, 0.01, 0.027);
1369  cemc_hist_eta_phi.at(ieta).at(iphi)->Fit(total[kj], "R");
1370  cemc_eta_phi_result = cemc_hist_eta_phi.at(ieta).at(iphi)->GetFunction("total");
1371  kj++;
1372 
1373  grtemp->Write();
1374 
1375  if (cemc_eta_phi_result)
1376  {
1377  // cemc_hist_eta_phi.at(ieta).at(iphi) = i;
1378  cemc_par1_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(1);
1379 
1380  // if (!(cemc_par1_values[ieta][iphi]>0.0))
1381  // {
1382  // cemc_par1_values[ieta][iphi] = 0.5;
1383  // }
1384  // cemc_par0_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(0);
1385  cemc_par1_errors[ieta][iphi] = cemc_eta_phi_result->GetParError(1);
1386  // cemc_par2_values[ieta][iphi] = cemc_eta_phi_result->GetParameter(2);
1387  // cemc_par2_errors[ieta][iphi] = cemc_eta_phi_result->GetParError(2);
1388  }
1389  else
1390  {
1391  std::cout << "Warning::Fit Failed for eta bin : " << ieta << iphi << std::endl;
1392  }
1393 
1394  for (int ipatt_eta = 0; ipatt_eta < 2; ipatt_eta++)
1395  {
1396  for (int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1397  {
1398  // if ((ipatt_eta>0) || (ipatt_phi>0))
1399  //{
1400  nt_corrVals->Fill(ieta + ipatt_eta * 16, iphi + ipatt_phi * 16, 0.135 / cemc_par1_values[ieta][iphi], 0.135 / cemc_par1_values[ieta][iphi] * myaggcorr.at(ieta).at(iphi));
1401  //}
1402  }
1403  }
1404 
1405  // nt_corrVals->Fill(ieta,259,0.135/cemc_par1_values[ieta][iphi],0.135/cemc_par1_values[ieta][iphi]*myaggcorr[ieta][259]);
1406 
1407  // cemc_p1_eta_phi->Fill(cemc_par1_values[ieta][iphi],ieta,iphi);
1408 
1409  // fitp0_eta_phi2d->SetBinContent(ieta+1,iphi+1,cemc_par0_values[ieta][iphi]);
1410  fitp1_eta_phi2d->SetBinContent(ieta + 1, iphi + 1, cemc_par1_values[ieta][iphi]);
1411  fitp1_eta_phi2d->SetBinError(ieta + 1, iphi + 1, cemc_par1_errors[ieta][iphi]);
1412  }
1413  }
1414  }
1415  std::cout << " finished fit_histos_eta_phi. " << std::endl;
1416 }
1417 
1418 // _______________________________________________________________..
1420 {
1421  // std::arrays have their indices backward, this is the old float myaggcorr[96][260];
1422  std::array<std::array<float, 260>, 96> myaggcorr{};
1423  std::for_each(myaggcorr.begin(), myaggcorr.end(), [](auto &row)
1424  { row.fill(1.); });
1425 
1426  if (!incorrFile.empty())
1427  {
1428  TFile *infileNt = new TFile(incorrFile.c_str());
1429 
1430  float myieta;
1431  float myiphi;
1432  float mycorr;
1433  float myaggcv;
1434 
1435  TNtuple *innt_corrVals = (TNtuple *) infileNt->Get("nt_corrVals");
1436 
1437  innt_corrVals->SetBranchAddress("tower_eta", &myieta);
1438  innt_corrVals->SetBranchAddress("tower_phi", &myiphi);
1439  innt_corrVals->SetBranchAddress("corr_val", &mycorr);
1440  innt_corrVals->SetBranchAddress("agg_cv", &myaggcv);
1441 
1442  int ntCorrs = innt_corrVals->GetEntries();
1443 
1444  for (int ij = 0; ij < ntCorrs; ij++)
1445  {
1446  innt_corrVals->GetEntry(ij);
1447  int ci = (int) myieta;
1448  int cj = (int) myiphi;
1449  myaggcorr.at(ci).at(cj) = myaggcv;
1450  if (ij > ntCorrs - 2)
1451  {
1452  std::cout << "loaded corrs eta,phi,aggcv " << myieta
1453  << " " << myiphi << " " << myaggcv << std::endl;
1454  }
1455  }
1456 
1457  infileNt->Close();
1458  delete infileNt;
1459  }
1460 
1461  cal_output->cd();
1462 
1463  TF1 *f1[96];
1464  TF1 *f2[96];
1465  TF1 *total[96];
1466  TF1 *fit_fn[96];
1467  int kj = 0;
1468 
1469  // arrays to hold parameters and its error
1470  double eta_value[96];
1471  double eta_par1_value[96] = {0.0};
1472  double eta_par1_error[96] = {0.0};
1473  double eta_par2_value[96] = {0.0};
1474  double eta_par2_error[96] = {0.0};
1475  // double eta_[96] = {0.0};
1476 
1477  // create Ntuple object from your calculated data
1478  TNtuple *nt_corrVals = new TNtuple("nt_corrVals", "Ntuple of the corrections", "tower_eta:tower_phi:corr_val:agg_cv");
1479 
1480  float avgmean = 0.170;
1481 
1482  int okHist[96] = {0};
1483 
1484  for (int i = 0; i < 96; i++)
1485  {
1486  if (eta_hist.at(i) == nullptr)
1487  {
1488  continue;
1489  }
1490  else if (eta_hist.at(i)->GetEntries() == 0)
1491  {
1492  continue;
1493  }
1494 
1495  okHist[i] = 1;
1496 
1497  // find max bin around peak
1498  float pkloc = 0.0;
1499  float bsavloc = 0.0;
1500 
1501  for (int kfi = 1; kfi < 30; kfi++)
1502  {
1503  float locbv = eta_hist.at(i)->GetBinContent(kfi);
1504  if (locbv > bsavloc)
1505  {
1506  pkloc = eta_hist.at(i)->GetBinCenter(kfi);
1507  bsavloc = locbv;
1508  }
1509  }
1510 
1511  f1[kj] = new TF1("f1", "gaus", 0.06, 0.20); // pkloc-0.03, pkloc+0.03);
1512  f2[kj] = new TF1("f2", "pol2", 0.005, 0.5);
1513 
1514  if (pkloc < 0.110 || pkloc > 0.2)
1515  {
1516  pkloc = 0.170;
1517  }
1518 
1519  eta_hist.at(i)->Fit(f1[kj], "", "", pkloc - 0.04, pkloc + 0.04);
1520  float fpkloc2 = f1[kj]->GetParameter(1);
1521 
1522  if (fpkloc2 < 0.110 || fpkloc2 > 0.2)
1523  {
1524  fpkloc2 = 0.170;
1525  }
1526 
1527  TGraphErrors *grtemp = new TGraphErrors();
1528  std::string bkgNm = std::string("grBkgEta_") + std::to_string(i);
1529 
1530  std::cout << " getting " << bkgNm << " mean was "
1531  << fpkloc2 << " " << pkloc << std::endl;
1532  grtemp->SetName(bkgNm.c_str());
1533  int ingr = 0;
1534  int firstnonzbin = -1;
1535  for (int gj = 1; gj < eta_hist.at(i)->GetNbinsX() + 1; gj++)
1536  {
1537  float binc = eta_hist.at(i)->GetBinCenter(gj);
1538  float cntc = eta_hist.at(i)->GetBinContent(gj);
1539  if (
1540  ((binc > 0.03 * fpkloc2 / 0.145 && binc < 0.09 * fpkloc2 / 0.145) || (binc > 0.265 * fpkloc2 / 0.145 && binc < 0.31 * fpkloc2 / 0.145)) && (cntc > 0 || firstnonzbin > 0))
1541  {
1542  grtemp->SetPoint(ingr, binc, cntc);
1543  grtemp->SetPointError(ingr++, 0.001, sqrt(cntc));
1544  }
1545  if (cntc && firstnonzbin < 0)
1546  {
1547  firstnonzbin = gj;
1548  }
1549  }
1550 
1551  grtemp->Fit(f2[kj]);
1552 
1553  total[kj] = new TF1("total", "gaus(0)+pol2(3)", 0.03 * fpkloc2 / 0.145, 0.31 * fpkloc2 / 0.145); // 0.3*fpkloc2/0.145);
1554 
1555  double par[6];
1556 
1557  f1[kj]->GetParameters(&par[0]);
1558  f2[kj]->GetParameters(&par[3]);
1559 
1560  total[kj]->SetParameters(par);
1561  total[kj]->SetParLimits(2, 0.015, 0.037);
1562  // total[kj]->SetParLimits(0,0.01*eta_hist.at(i)->Integral(0,40),eta_hist.at(i)->Integral(0,40));
1563  total[kj]->SetParLimits(0, 5.0, eta_hist.at(i)->Integral(0, 40));
1564  total[kj]->SetParLimits(1, 0.08, 0.22);
1565  // total[kj]->SetParLimits(3,0.01,0.027);
1566  // total[kj]->SetParLimits(3,0.01,0.027);
1567 
1568  eta_hist.at(i)->Fit(total[kj], "R");
1569 
1570  fit_fn[kj] = eta_hist.at(i)->GetFunction("total");
1571 
1572  grtemp->Write();
1573 
1574  if (fit_fn[kj])
1575  {
1576  eta_value[i] = i;
1577  eta_par1_value[i] = fit_fn[kj]->GetParameter(1);
1578  if (!(eta_par1_value[i] > 0))
1579  {
1580  eta_par1_value[i] = 0.5;
1581  }
1582  eta_par1_error[i] = fit_fn[kj]->GetParError(1);
1583  eta_par2_value[i] = fit_fn[kj]->GetParameter(2);
1584  eta_par2_error[i] = fit_fn[kj]->GetParError(2);
1585  }
1586  else
1587  {
1588  std::cout << "WarninG :: Fit Failed for eta bin : " << i << std::endl;
1589  }
1590 
1591  avgmean += eta_par1_value[i];
1592 
1593  kj++;
1594  }
1595 
1596  avgmean /= kj + 1;
1597  int kj2 = 0;
1598 
1599  for (int iijk = 0; iijk < 96; iijk++)
1600  {
1601  if (okHist[iijk] == 0)
1602  {
1603  continue;
1604  }
1605 
1606  float locavg = 0.01;
1607  if (kj2 < 6 && iijk < 88)
1608  {
1609  locavg = (eta_par1_value[iijk + 3] + eta_par1_value[iijk + 4] + eta_par1_value[iijk + 5] + eta_par1_value[iijk + 6] + eta_par1_value[iijk + 7]) / 5.0;
1610  if (fabs(locavg - avgmean) > 0.2 * avgmean)
1611  {
1612  locavg = avgmean;
1613  }
1614  }
1615  else if (iijk > 90)
1616  {
1617  locavg = (eta_par1_value[iijk - 3] + eta_par1_value[iijk - 4] + eta_par1_value[iijk - 5] + eta_par1_value[iijk - 6] + eta_par1_value[iijk - 7]) / 5.0;
1618  if (fabs(locavg - avgmean) > 0.2 * avgmean)
1619  {
1620  locavg = avgmean;
1621  }
1622  }
1623  else
1624  {
1625  locavg = (eta_par1_value[iijk - 3] + eta_par1_value[iijk - 2] + eta_par1_value[iijk - 1] + eta_par1_value[iijk + 1] + eta_par1_value[iijk + 2] + eta_par1_value[iijk + 3]) / 6.0;
1626  if (fabs(locavg - avgmean) > 0.2 * avgmean)
1627  {
1628  locavg = avgmean;
1629  }
1630  }
1631 
1632  float thisfitp1 = 0;
1633  if (fit_fn[kj2])
1634  {
1635  thisfitp1 = fit_fn[kj2]->GetParameter(1);
1636  if (fabs(thisfitp1 - locavg) > 0.12 * locavg)
1637  {
1638  std::cout << "redoing fit for eta" << iijk << " " << fit_fn[kj2] << std::endl;
1639  fit_fn[kj2]->SetParameter(1, locavg);
1640  fit_fn[kj2]->FixParameter(1, locavg);
1641  eta_hist.at(iijk)->Fit(fit_fn[kj2]);
1642  fit_fn[kj2]->SetParLimits(1, locavg - 0.011, locavg + 0.011);
1643  eta_hist.at(iijk)->Fit(fit_fn[kj2]);
1644  }
1645  // if (iijk > 63 && iijk < 72)
1646  // {
1647  // std::cout << "redoing fit for eta" << iijk << " " << fit_fn[kj2] << std::endl;
1648  // fit_fn[kj2]->SetParameter(1,0.26);
1649  // fit_fn[kj2]->FixParameter(1,0.26);
1650  // eta_hist.at(iijk)->Fit(fit_fn[kj2]);
1651  // // fit_fn[kj2]->SetParLimits(1,locavg - 0.011, locavg + 0.011);
1652  // //eta_hist.at(iijk)->Fit(fit_fn[kj2]);
1653 
1654  // }
1655 
1656  eta_value[iijk] = iijk;
1657  eta_par1_value[iijk] = fit_fn[kj2]->GetParameter(1);
1658  if (!(eta_par1_value[iijk] > 0))
1659  {
1660  eta_par1_value[iijk] = 0.5;
1661  }
1662  eta_par1_error[iijk] = fit_fn[kj2]->GetParError(1);
1663  eta_par2_value[iijk] = fit_fn[kj2]->GetParameter(2);
1664  eta_par2_error[iijk] = fit_fn[kj2]->GetParError(2);
1665  }
1666  else
1667  {
1668  std::cout << "WarninG :: Fit Failed for eta bin : " << iijk << std::endl;
1669  }
1670 
1671  for (int jj = 0; jj < 256; jj++)
1672  {
1673  nt_corrVals->Fill(iijk, jj, _setMassVal / eta_par1_value[iijk], _setMassVal / eta_par1_value[iijk] * myaggcorr.at(iijk).at(jj));
1674  }
1675 
1676  // nt_corrVals->Fill(i,259,0.135/eta_par1_value[i],0.135/eta_par1_value[i]*myaggcorr[i][259]);
1677 
1678  kj2++;
1679 
1680  } // iijk
1681 
1682  TGraphErrors *g1 = new TGraphErrors(96, eta_value, eta_par1_value, nullptr, eta_par1_error);
1683  g1->SetTitle("pi0 mean eta; eta; p1");
1684  g1->SetMarkerStyle(20);
1685  g1->SetMarkerColor(2);
1686  g1->SetName("eta_p1");
1687 
1688  TGraphErrors *g2 = new TGraphErrors(96, eta_value, eta_par2_value, nullptr, eta_par2_error);
1689  g2->SetTitle("pi0 sigma eta; eta; p2");
1690  g2->SetName("eta_p2");
1691 
1692  cal_output->WriteTObject(g1);
1693  cal_output->WriteTObject(g2);
1694 
1695  std::cout << " finished fit_histos_eta_slice" << std::endl;
1696 }
1697 
1698 //_________________________________________________________________________..
1700 {
1701  std::string ts = "cp -rp " + infile + std::string(" ") + outfile;
1702  gSystem->Exec(ts.c_str());
1703 
1704  cal_output = new TFile(outfile.c_str(), "UPDATE");
1705  // load the file from the fun4all 1st run
1706 
1707  for (int i = 0; i < 96; i++)
1708  {
1709  // getting eta towers
1710  std::string b = std::string("eta_") + std::to_string(i);
1711  TH1F *heta_temp = (TH1F *) cal_output->Get(b.c_str());
1712  eta_hist.at(i) = heta_temp;
1713 
1714  std::cout << "got " << b << std::endl;
1715 
1716  // getting eta_phi towers
1717  for (int j = 0; j < 256; j++)
1718  {
1719  std::string hist_name = std::string("emc_ieta") + std::to_string(i) + std::string("_phi") + std::to_string(j);
1720  TH1F *h_eta_phi_temp = (TH1F *) cal_output->Get(hist_name.c_str());
1721  cemc_hist_eta_phi.at(i).at(j) = h_eta_phi_temp;
1722  }
1723  }
1724  std::cout << "finished Loading histos" << std::endl;
1725 }
1726 
1727 // _______________________________________________________________________________..
1729 {
1730  for (int ithirds = 0; ithirds < 3; ithirds++)
1731  {
1732  for (int ieta = 0 + ithirds * 32; ieta < (ithirds * 32 + 16); ieta++)
1733  {
1734  for (int iphi = 0; iphi < 16; iphi++)
1735  {
1736  for (int ipatt_eta = 0; ipatt_eta < 2; ipatt_eta++)
1737  {
1738  for (int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1739  {
1740  if ((ipatt_eta > 0) || (ipatt_phi > 0))
1741  {
1742  cemc_hist_eta_phi.at(ieta).at(iphi)->Add(cemc_hist_eta_phi.at(ieta + ipatt_eta * 16).at(iphi + ipatt_phi * 16));
1743  }
1744  }
1745  }
1746  }
1747  }
1748  }
1749 }
1750 
1751 // ________________________________________________________________________________..
1753 {
1754  std::cout << " Inside Add_96()." << std::endl;
1755  for (int ieta = 0; ieta < 16; ieta++)
1756  {
1757  for (int iphi = 0; iphi < 16; iphi++)
1758  {
1759  for (int ipatt_eta = 0; ipatt_eta < 6; ipatt_eta++)
1760  {
1761  for (int ipatt_phi = 0; ipatt_phi < 16; ipatt_phi++)
1762  {
1763  if ((ipatt_eta > 0) || (ipatt_phi > 0))
1764  {
1765  cemc_hist_eta_phi.at(ieta).at(iphi)->Add(cemc_hist_eta_phi.at(ieta + ipatt_eta * 16).at(iphi + ipatt_phi * 16));
1766  }
1767  }
1768  }
1769  }
1770  }
1771  std::cout << " Finished Add_96(). " << std::endl;
1772 }