StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtPedReader.cxx
1 
6 /***************************************************************************
7  *
8  * $Id: StFgtPedReader.cxx,v 1.1 2012/01/31 08:52:51 sgliske Exp $
9  * Author: S. Gliske, Sept 2011
10  *
11  ***************************************************************************
12  *
13  * Description: see header.
14  *
15  ***************************************************************************
16  *
17  * $Log: StFgtPedReader.cxx,v $
18  * Revision 1.1 2012/01/31 08:52:51 sgliske
19  * StFgtPedMaker moved to StFgtPool
20  *
21  * Revision 1.4 2012/01/27 13:24:50 sgliske
22  * updated to correspond with new PedMakers
23  * Now keyed by elecId
24  *
25  * Revision 1.3 2012/01/26 13:13:11 sgliske
26  * Updated to use StFgtConsts, which
27  * replaces StFgtEnums and StFgtGeomDefs
28  *
29  * Revision 1.2 2011/09/24 02:14:09 sgliske
30  * updated FGT cosmic QA
31  *
32  * Revision 1.1 2011/09/22 21:21:08 sgliske
33  * first working version
34  *
35  *
36  **************************************************************************/
37 
38 #include <string>
39 #include <iostream>
40 #include <fstream>
41 #include <Rtypes.h>
42 #include "StFgtPedReader.h"
43 #include "StRoot/StFgtUtil/StFgtConsts.h"
44 
45 // constructor
46 inline StFgtPedReader::StFgtPedReader( const Char_t* filename ) :
47  mTimeBinMask( 0x10 ), mFilename( filename ) {
48 
49  // set to all zeros
50  mPedVec.resize( kFgtNumTimeBins * kFgtNumElecIds );
51 };
52 
53 // initialize
54 Int_t StFgtPedReader::Init(){
55  Int_t ierr = 0;
56 
57  std::ifstream fin( mFilename.data() );
58 
59  if( !fin ){
60  std::cerr << "Error opening file '" << mFilename << "'" << std::endl;
61  ierr = 1;
62  };
63 
64  if( !ierr ){
65  Int_t timebin, geoId;
66  Float_t ped, stdev;
67 
68  while( !fin.eof() && !ierr ){
69  fin >> geoId >> timebin >> ped >> stdev;
70 
71  if( 1<<timebin & mTimeBinMask )
72  mPedVec[ key_t( geoId, timebin ) ] = ped_t( ped, stdev );
73  };
74  };
75 
76  return ierr;
77 };
78 
79 // accessor: input is geoId and timebin, output is ped and
80 // st. dev. (err)
81 void StFgtPedReader::getPed( Int_t geoId, Int_t timebin, Float_t& ped, Float_t& err ) const {
82  const ped_t& pedpair = mPedVec[ key_t( geoId, timebin ) ];
83  ped = pedpair.ped;
84  err = pedpair.err;
85 };
86 
87 ClassImp( StFgtPedReader );