StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtRobustPedMaker.cxx
1 
6 /***************************************************************************
7  *
8  * $Id: StFgtRobustPedMaker.cxx,v 1.3 2013/02/10 14:43:55 akio Exp $
9  * Author: S. Gliske, Jan 2012
10  *
11  ***************************************************************************
12  *
13  * Description: See header
14  *
15  ***************************************************************************
16  *
17  * $Log: StFgtRobustPedMaker.cxx,v $
18  * Revision 1.3 2013/02/10 14:43:55 akio
19  * slightly modified to gain better accuracy
20  *
21  * Revision 1.2 2012/01/31 16:47:47 wwitzke
22  * Changed for cosmic test stand change.
23  *
24  * Revision 1.1 2012/01/31 08:52:51 sgliske
25  * StFgtPedMaker moved to StFgtPool
26  *
27  * Revision 1.7 2012/01/30 10:42:22 sgliske
28  * strip containers now contain adc values for
29  * all time bins. Also fixed bug where setType modified the timebin
30  * rather than the type.
31  *
32  * Revision 1.6 2012/01/26 13:13:11 sgliske
33  * Updated to use StFgtConsts, which
34  * replaces StFgtEnums and StFgtGeomDefs
35  *
36  * Revision 1.5 2012/01/24 06:57:42 sgliske
37  * forgot to take out unused get geoId
38  *
39  * Revision 1.4 2012/01/24 06:56:42 sgliske
40  * directly use elec coord domian--no geoIds
41  *
42  * Revision 1.3 2012/01/18 18:53:01 sgliske
43  * minor bug fix
44  *
45  * Revision 1.2 2012/01/17 21:56:26 sgliske
46  * Short_t geoId -> Int_t geoId
47  *
48  * Revision 1.1 2012/01/17 20:08:49 sgliske
49  * creation
50  *
51  *
52  **************************************************************************/
53 
54 #include <string>
55 #include "StFgtRobustPedMaker.h"
56 #include "StRoot/StEvent/StFgtCollection.h"
57 #include "StRoot/StEvent/StFgtStrip.h"
58 #include "StRoot/StEvent/StEvent.h"
59 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
60 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
61 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
62 #include "StRoot/StFgtUtil/StFgtConsts.h"
63 
64 #define ONE_OVER_TWICE_SQRT_LOG_TWO 0.6005612
65 
66 // constructor
67 StFgtRobustPedMaker::StFgtRobustPedMaker( const Char_t* name ) :
68  StFgtPedMaker( name ), mNumBins(100) , mMaxAdc(1250), mNumSmooth(10), mInternalEventNum(0) {
69 
70  // set to all zeros
71  mHistVec.assign( mDataVec.size(), (TH1F*)0 );
72 };
73 
74 // make, i.e. compute histograms
75 // actual pedistals are computed in ::Finish()
77  Int_t ierr = kStOk;
78 
79  //cout << "StFgtRobustPedMaker::Make() internal event number " << mInternalEventNum++ << endl;
80 
81  StEvent* eventPtr = 0;
82  eventPtr = (StEvent*)GetInputDS("StEvent");
83 
84  if( !eventPtr ) {
85  LOG_ERROR << "Error getting pointer to StEvent from '" << ClassName() << "'" << endm;
86  ierr = kStErr;
87  };
88 
89  StFgtCollection* fgtCollectionPtr = 0;
90 
91  if( eventPtr ) {
92  fgtCollectionPtr=eventPtr->fgtCollection();
93  };
94 
95  if( !fgtCollectionPtr) {
96  LOG_ERROR << "Error getting pointer to StFgtCollection from '" << ClassName() << "'" << endm;
97  ierr = kStErr;
98  };
99 
100  if( !ierr ){
101  std::stringstream ss;
102  for( UInt_t discIdx=0; discIdx<fgtCollectionPtr->getNumDiscs(); ++discIdx ){
103  StFgtStripCollection *stripCollectionPtr = fgtCollectionPtr->getStripCollection( discIdx );
104  if( stripCollectionPtr ){
105  StSPtrVecFgtStrip& stripVec = stripCollectionPtr->getStripVec();
106  StSPtrVecFgtStripIterator stripIter;
107 
108  for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
109  for( Int_t timeBin = 0; timeBin < kFgtNumTimeBins; ++timeBin ){
110  Bool_t pass = ((mTimeBinMask==0 || ( (1<<timeBin) & mTimeBinMask)) && timeBin >= 0 && timeBin < kFgtNumTimeBins);
111  if( pass ){
112  Short_t adc = (*stripIter)->getAdc( timeBin );
113 
114  if( adc ){
115 
116  Int_t t = timeBin;
117  if(mTimeBinMask==0) t=0;
118 
119  Int_t rdo, arm, apv, channel;
120  (*stripIter)->getElecCoords( rdo, arm, apv, channel );
121  Int_t elecId = StFgtGeom::getElectIdFromElecCoord( rdo, arm, apv, channel );
122 
123  Int_t code = kFgtNumTimeBins * elecId + t;
124 
125  TH1F* hist = mHistVec[ code ];
126  if( !hist ){
127  ss.str("");
128  ss.clear();
129  ss << "hStripADC_" << code;
130  hist = new TH1F( ss.str().data(), "", mNumBins, 0, mMaxAdc );
131  mHistVec[ code ] = hist;
132  };
133 
134  hist->Fill( float(adc) );
135  };
136  };
137  };
138  };
139  };
140  };
141  };
142 
143  return ierr;
144 };
145 
146 // save as needed
148  Int_t ierr = kStOk;
149 
150  if( !mHasFinished ){
151  cout << "StFgtRobustPedMaker::Finish()" << endl;
152 
153  std::vector< TH1F* >::iterator mHistVecIter;
154 
155  //TF1 gaus( "gaus", "[0]*TMath::Gaus( x, [1], [2] )", 0, mMaxAdc );
156 
157  for( mHistVecIter = mHistVec.begin(); mHistVecIter != mHistVec.end(); ++mHistVecIter ){
158  // for easier-to-read code
159  TH1F *hist = *mHistVecIter;
160 
161  if( hist ){
162  // smooth for good measure
163  if( mNumSmooth ) hist->Smooth( mNumSmooth );
164 
165  // pedistal value is MPV
166  Int_t maxLoc = hist->GetMaximumBin();
167  Float_t halfMax = 0.5*hist->GetBinContent( maxLoc );
168  Float_t pedValue = hist->GetBinCenter( maxLoc );
169  Float_t mean = hist->GetMean();
170 
171  // estimate the half width at half max on both sides
172  Int_t binIdxR;
173  for( binIdxR = maxLoc + 1; binIdxR <= hist->GetNbinsX() && hist->GetBinContent( binIdxR ) > halfMax; ++binIdxR );
174  Float_t HWHMR = ( hist->GetBinCenter( binIdxR ) - pedValue );
175 
176  // estimate the sigma from the HWHM on the left
177  Int_t binIdxL;
178  for( binIdxL = maxLoc - 1; binIdxL > 0 && hist->GetBinContent( binIdxL ) > halfMax; --binIdxL );
179  Float_t HWHML = ( pedValue - hist->GetBinCenter( binIdxL ) );
180 
181  // estimate sigma
182  Float_t sigma = ( HWHML + HWHMR ) * ONE_OVER_TWICE_SQRT_LOG_TWO;
183  Float_t rms = hist->GetRMS();
184  Float_t sig3 = 3.0*rms;
185  if(sig3<100) sig3=100;
186 
187  // restrict to with three sigma
188  hist->GetXaxis()->SetRangeUser(mean-sig3, mean+sig3);
189 
190  // update mean and sigma
191  Float_t mean2 = hist->GetMean();
192  Float_t rms2 = hist->GetRMS();
193 
194  // estimate percentage in one sigma
195  Float_t fracClose = hist->Integral(hist->FindBin(mean2-rms2), hist->FindBin(mean2+rms2)) / hist->GetEntries();
196 
197  // save to map, note:
198  // sum == mean
199  // sumsq == st. dev. or RMS, etc
200 
201  Int_t code = std::distance( mHistVec.begin(), mHistVecIter );
202  pedData_t &data = mDataVec[ code ];
203  data.n = hist->GetEntries();
204  data.ped = mean2;
205  data.RMS = rms2;
206  data.fracClose = fracClose;
207 
208  //int eid=code/kFgtNumTimeBins;
209  //printf("Eleid=%5d Max=%6.2f Mean=%6.2f %6.2f %6.2f RMS=%6.2f %6.2f %6.2f f=%6.2f\n",
210  // eid,halfMax*2,pedValue,mean,mean2,sigma,rms,rms2,fracClose);
211 
212  };
213  };
214 
215  ierr = saveToFile();
216  };
217 
218  return ierr;
219 };
220 
221 ClassImp( StFgtRobustPedMaker );
Definition: Stypes.h:44
Definition: Stypes.h:41