Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TPCPedestalCalibration.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TPCPedestalCalibration.cc
2 
5 #include <phool/PHIODataNode.h> // for PHIODataNode
6 #include <phool/PHNodeIterator.h> // for PHNodeIterator
7 #include <phool/PHObject.h> // for PHObject
8 #include <phool/recoConsts.h>
9 #include <phool/getClass.h>
10 #include <phool/phool.h>
11 
12 #include <Event/Event.h>
13 #include <Event/EventTypes.h>
14 #include <Event/packet.h>
15 
16 #include <TMath.h>
17 #include <TFile.h>
18 #include <TTree.h>
19 
20 #include <memory>
21 #include <cassert>
22 #include <iostream>
23 
24 /*************************************************************/
25 /* TPC Pedestal Calibration */
26 /* Thomas Marshall,Aditya Dash */
27 /* rosstom@ucla.edu,aditya55@physics.ucla.edu */
28 /*************************************************************/
29 
31  :SubsysReco("TPCPedestalCalibration")
32  , m_fname(name)
33  , m_writeToCDB(false)
34 {
35  // reserve memory for max ADC samples
36  m_adcSamples.resize(1024, 0);
37 
38  for(int fee_no=0;fee_no<26;fee_no++)
39  {
40  for(int channel_no=0;channel_no<256;channel_no++)
41  {
42  m_aveADCFeeChannel[fee_no][channel_no]=0.0;
43  m_stdADCFeeChannel[fee_no][channel_no]=0.0;
44  m_countsADCFeeChannel[fee_no][channel_no]=0.0;
45  m_aliveArrayFeeChannel[fee_no][channel_no]=1;
46  }
47  }
48 
49 }
50 
52 {
53  m_cdbttree = new CDBTTree(m_fname);
54 
56 }
57 
58 //____________________________________________________________________________..
60 {
61  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
62  if (_event == nullptr)
63  {
64  std::cout << "TPCRawDataTree::Process_Event - Event not found" << std::endl;
65  return -1;
66  }
67  if (_event->getEvtType() >= 8)
68  {
70  }
71 
72  for (int packet : m_packets)
73  {
74  if (Verbosity())
75  {
76  std::cout << __PRETTY_FUNCTION__ << " : decoding packet " << packet << std::endl;
77  }
78 
79  m_packet = packet;
80 
81  std::unique_ptr<Packet> p (_event->getPacket(m_packet));
82  if (!p)
83  {
84  if (Verbosity())
85  {
86  std::cout << __PRETTY_FUNCTION__ << " : missing packet " << packet << std::endl;
87  }
88 
89  continue;
90  }
91 
92  m_nWaveormInFrame = p->iValue(0, "NR_WF");
93 
94  for (int wf = 0; wf < m_nWaveormInFrame; wf++)
95  {
96  if (m_firstBCO == true)
97  {
98  m_BCO = p->iValue(wf, "BCO");
99  m_firstBCO = false;
100  }
101 
102  m_nSamples = p->iValue(wf, "SAMPLES");
103  m_fee = p->iValue(wf, "FEE");
104  m_Channel = p->iValue(wf, "CHANNEL");
105 
106  if(m_nSamples==0)
107  {
109  continue;
110  }
111 
112  assert(m_nSamples < (int) m_adcSamples.size()); // no need for movements in memory allocation
113  for (int s = 0; s < m_nSamples; s++)
114  {
115  m_adcSamples[s] = p->iValue(wf, s);
116  }
117 
118  bool dead = false;
119  for(int adc_sam_no=0;adc_sam_no<m_nSamples;adc_sam_no++)
120  {
121  if (m_adcSamples[adc_sam_no] == 0 || TMath::IsNaN(float(m_adcSamples[adc_sam_no])))
122  {
124  }
125  }
126  if (dead) {continue;}
127 
128  for(int adc_sam_no=0;adc_sam_no<m_nSamples;adc_sam_no++){
130  m_stdADCFeeChannel[m_fee][m_Channel]+=pow(m_adcSamples[adc_sam_no],2);
132  }
133  }
134  } // for (int packet : m_packets)
135 
137 }
138 
140 {
141  std::cout << "TPCPedestalCalibration::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
142 
143  for(int fee_no=0;fee_no<26;fee_no++)
144  {
145  for(int channel_no=0;channel_no<256;channel_no++)
146  {
147  if(m_countsADCFeeChannel[fee_no][channel_no] != 0.0)
148  {
149  float temp1 = m_aveADCFeeChannel[fee_no][channel_no]/m_countsADCFeeChannel[fee_no][channel_no];
150  float temp2 = m_stdADCFeeChannel[fee_no][channel_no]/m_countsADCFeeChannel[fee_no][channel_no];
151  m_aveADCFeeChannel[fee_no][channel_no] = temp1;
152  m_stdADCFeeChannel[fee_no][channel_no] = temp2;
153  }
154  else
155  {
156  m_aveADCFeeChannel[fee_no][channel_no] = 0.0;
157  m_stdADCFeeChannel[fee_no][channel_no] = 0.0;
158  m_aliveArrayFeeChannel[fee_no][channel_no]=0;
159  }
160 
161  if(m_aveADCFeeChannel[fee_no][channel_no] > 200 || m_aveADCFeeChannel[fee_no][channel_no] < 10)
162  {
163  m_aliveArrayFeeChannel[fee_no][channel_no]=0;
164  }
165 
166  m_pedMean=m_aveADCFeeChannel[fee_no][channel_no];
167  m_pedStd=sqrt(m_stdADCFeeChannel[fee_no][channel_no] - pow(m_aveADCFeeChannel[fee_no][channel_no],2));
168  m_isAlive=m_aliveArrayFeeChannel[fee_no][channel_no];
169  m_chan=channel_no;
170  m_outFEE=fee_no;
171  m_module=mod_arr[fee_no];
172  m_slot=slot_arr[fee_no];
173 
174  m_cdbttree->SetIntValue(fee_no*256 + channel_no,"isAlive",m_isAlive);
175  m_cdbttree->SetFloatValue(fee_no*256 + channel_no,"pedMean",m_pedMean);
176  m_cdbttree->SetFloatValue(fee_no*256 + channel_no,"pedStd",m_pedStd);
177  m_cdbttree->SetIntValue(fee_no*256 + channel_no,"sector",m_sector);
178  m_cdbttree->SetIntValue(fee_no*256 + channel_no,"fee",m_outFEE);
179  m_cdbttree->SetIntValue(fee_no*256 + channel_no,"channel",m_chan);
180  m_cdbttree->SetIntValue(fee_no*256 + channel_no,"module",m_module);
181  m_cdbttree->SetIntValue(fee_no*256 + channel_no,"slot",m_slot);
182  }
183  }
184 
186 }
187 
189 {
191 
192  CDBUtils *cdbInsert = new CDBUtils(rc->get_StringFlag("CDB_GLOBALTAG"));
193  cdbInsert->createPayloadType("TPCPedestalCalibration");
194  cdbInsert->insertPayload("TPCPedestalCalibration",m_fname,m_BCO); // uses first BCO value from first waveform
195 
196  return;
197 }
198 
199 //____________________________________________________________________________..
201 {
202  m_cdbttree->Commit();
203  if (Verbosity())
204  {
205  m_cdbttree->Print();
206  }
208  delete m_cdbttree;
209 
210  if (m_writeToCDB)
211  {
212  std::cout << "Inserting file " << m_fname << " in CDB under username " << m_username << std::endl;
213  CDBInsert();
214  }
215 
217 }