StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsBsQaMaker.cxx
1 #include "StFmsBsQaMaker.h"
2 ClassImp(StFmsBsQaMaker);
3 
4 #include "StEnumerations.h"
5 #include "StEventTypes.h"
6 #include "StEvent/StEvent.h"
7 #include "StEvent/StFmsCollection.h"
8 #include "StEvent/StFmsHit.h"
9 #include "StEvent/StFmsPoint.h"
10 #include "StEvent/StFmsPointPair.h"
11 #include "StEvent/StTriggerData.h"
12 #include "StEvent/StTriggerId.h"
13 #include "StFmsDbMaker/StFmsDbMaker.h"
14 #include "StMessMgr.h"
15 #include "StMuDSTMaker/COMMON/StMuEvent.h"
16 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
17 #include "Stypes.h"
18 
19 #include <TFile.h>
20 #include <TH1F.h>
21 #include <TH2F.h>
22 #include <TString.h>
23 
24 #include <iostream>
25 #include <fstream>
26 #include <map>
27 using namespace std;
28 
29 //=================================================================
30 StFmsBsQaMaker::StFmsBsQaMaker(const char* name) : StMaker(name) {}
31 
32 //==========================
33 Int_t StFmsBsQaMaker::Init()
34 {
35  mFmsDbMk = static_cast<StFmsDbMaker*>(GetMaker("fmsDb"));
36  if (!mFmsDbMk) { LOG_ERROR <<"StFmsBsQaMaker::InitRun - !StFmsDbMaker" <<endl; return kStFatal; }
37 
38  return kStOk;
39 }//Init
40 
41 //======================================
42 Int_t StFmsBsQaMaker::InitRun(int runNo)
43 {
44  Info("InitRun", "Start run %d...", runNo);
45 
46  mFile = new TFile(mOutputName, "RECREATE");
47  mFile->SetCompressionLevel(9);
48  mFile->cd();
49 
50  //-------------------------------------------
51 
52  /*
53  //Get map of each FMS cell's x/y position for mapping
54  ofstream out;
55  out.open("fmsCellMap.txt");
56  for (int a=0; a<nDet; a++)
57  {
58  const int detId = a+8;
59  const int maxCh = mFmsDbMk->maxChannel(detId);
60  for (int b=0; b<maxCh; b++)
61  {
62  const int ch = b+1;
63  const float gain = mFmsDbMk->getGain(detId, ch);
64  StThreeVectorF XYZ = mFmsDbMk->getStarXYZ(detId, ch);
65  out <<Form("%2i %3i %i %6.2f %6.2f", detId, ch, gain>0?true:false, XYZ.x(), XYZ.y()) <<endl;
66  }//b, ch
67  }//, detId
68  out.close();
69  */
70 
71  //-------------------------------------------
72 
73  //Get list of "valid" FMS channels
74  for (int a=0; a<nDet; a++)
75  {
76  int index = 0;
77  const int detId = a+8;
78  const int maxCh = mFmsDbMk->maxChannel(detId);
79  for (int b=0; b<maxCh; b++)
80  {
81  const int ch = b+1;
82  const float gain = mFmsDbMk->getGain(detId, ch);
83  if (gain <= 0.) continue;
84 
85  //cout <<Form("detId = %2i ch = %3i index = %3i", detId, ch, index) <<endl;
86  nToCh[a].insert(std::pair<int, int>(index, ch));
87  chToN[a].insert(std::pair<int, int>(ch, index));
88  index++;
89  }//b, ch (all, including invalid ones)
90  }//a, detId
91 
92  //-------------------------------------------
93 
94  //Histograms: ADC
95  for (int a=0; a<nDet; a++)
96  {
97  const int nCh = (a<2)?nChLg:nChSm;
98  mH2_adc[a] = new TH2F(Form("Adc_d%i",a+8), Form("detId = %i;ch;ADC",a+8), nCh,0.5,nCh+0.5, 5000,0,5000);
99  mH2_adc[a]->Sumw2();
100  }
101 
102  //-------------------------------------------
103 
104  //Histograms: bit shift, DB
105  for (int a=0; a<nDet; a++)
106  {
107  const int nCh = (a<2)?nChLg:nChSm;
108  mH2_bs_DB[a] = new TH2F(Form("BitShift_DB_d%i", a+8), "", nCh,0.5,nCh+0.5, nBit,0.5,nBit+0.5);
109  mH2_bs_DB[a]->SetTitle(Form("DB, detId = %i;ch;bit", a+8));
110 
111  for (unsigned int x=0; x<nToCh[a].size(); x++) //Loop over only valid FMS channels
112  for (int y=0; y<nBit; y++)
113  {
114  const int ch = nToCh[a][x];
115  const int bs = mFmsDbMk->getBitShiftGain(a+8, ch);
116 
117  //BS = +5: filled y bins will be 1, 2, 3, 4, and 5
118  //BS = -5: filled y bins will be 12, 11, 10, 9, and 8
119  if ((bs>0 && y<bs) || (bs<0 && y>=(bs+nBit))) mH2_bs_DB[a]->SetBinContent(ch, y+1, 1);
120  }
121  }//a, detId
122 
123  //-------------------------------------------
124 
125  //Histograms: BS, data
126  for (int a=0; a<nDet; a++)
127  {
128  const int nCh = (a<2)?nChLg:nChSm;
129  mH2_bs_data[a] = new TH2F(Form("BitShift_data_d%i", a+8), "", nCh,0.5,nCh+0.5, nBit,0.5,nBit+0.5);
130  mH2_bs_data[a]->SetTitle(Form("Data, detId = %i;ch;bit", a+8));
131 
132  //Set all "valid" channels' content to 1
133  for (unsigned int x=0; x<nToCh[a].size(); x++)
134  for (int y=0; y<nBit; y++)
135  {
136  const int ch = nToCh[a][x];
137  mH2_bs_data[a]->SetBinContent(ch, y+1, 1);
138  }
139  }//a, detId
140 
141  //-------------------------------------------
142 
143  //Histograms: chMap
144  for (int a=0; a<nDet; a++)
145  {
146  const int nCh = (a<2)?nChLg:nChSm;
147  mH2_chMap[a] = new TH2F(Form("ChMap_d%i", a+8), "", nCh,0.5,nCh+0.5, 1,0,1);
148  mH2_chMap[a]->SetTitle(Form("Map of valid channels, detId = %i;ch", a+8));
149 
150  for (unsigned int x=0; x<nToCh[a].size(); x++)
151  {
152  const int ch = nToCh[a][x];
153  mH2_chMap[a]->SetBinContent(ch, 1, 1);
154  }
155  }//a, detId
156 
157  return kStOk;
158 }//InitRun
159 
160 //==========================
162 {
163  mEvent++;
164  if (mEvent%1000 == 0) cout <<Form("%5i processed...", mEvent) <<endl;
165 
166  StEvent* event = (StEvent*)GetInputDS("StEvent");
167  if (!event) { LOG_ERROR <<"StFmsOfflineQaMakerNew::Make - !StEvent" <<endl; return kStErr; }
168  else mFmsColl = (StFmsCollection*) event->fmsCollection();
169 
170  StSPtrVecFmsHit& hits = mFmsColl->hits();
171  const int nHits = mFmsColl->numberOfHits();
172  for (int a=0; a<nHits; a++)
173  {
174  const int adc = hits[a]->adc();
175  const int ch = hits[a]->channel();
176  const int det = hits[a]->detectorId();
177  if (det<8 || det>11) continue;
178 
179  //Fill ADCs (for future crosscheck)
180  mH2_adc[det-8]->Fill(ch, adc);
181 
182  //Iteration for binary bits
183  for (int b=0; b<nBit; b++) { if (adc & (1 << b)) mH2_bs_data[det-8]->SetBinContent(ch, b+1, 0); }
184  }//Hit
185 
186  return kStOk;
187 }//Make
188 
189 //============================
191 {
192  mFile->Write();
193  mFile->Close();
194  return kStOK;
195 }//Finish
virtual Int_t Make()
virtual Int_t Finish()
Short_t getBitShiftGain(Int_t detectorId, Int_t ch) const
get the gain correction for the channel
UShort_t maxChannel(Int_t detectorId) const
number of column
Definition: Stypes.h:40
Definition: Stypes.h:44
Definition: Stypes.h:41