StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtDaq2RootMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtDaq2RootMaker.cxx,v 1.3 2012/03/05 20:35:46 sgliske Exp $
4  * Author: S. Gliske, Jan 2012
5  *
6  ***************************************************************************
7  *
8  * Description: see header.
9  *
10  ***************************************************************************
11  *
12  * $Log: StFgtDaq2RootMaker.cxx,v $
13  * Revision 1.3 2012/03/05 20:35:46 sgliske
14  * update to export DAQ data as well
15  *
16  * Revision 1.2 2012/01/30 10:42:23 sgliske
17  * strip containers now contain adc values for
18  * all time bins. Also fixed bug where setType modified the timebin
19  * rather than the type.
20  *
21  * Revision 1.1 2012/01/28 09:29:26 sgliske
22  * creation
23  *
24  *
25  **************************************************************************/
26 
27 #include "StFgtDaq2RootMaker.h"
28 #include <TFile.h>
29 #include <TTree.h>
30 
31 #include "StRoot/StEvent/StEvent.h"
32 #include "StRoot/StEvent/StFgtCollection.h"
33 #include "StRoot/StEvent/StFgtStrip.h"
34 
35 // constructors
36 StFgtDaq2RootMaker::StFgtDaq2RootMaker( const Char_t* name,
37  const Char_t* outputfile )
38  : StMaker( name ),
39  mFileName( outputfile ),
40  mTFile(0),
41  mTTree(0) { /* */ };
42 
43 // deconstructor
44 StFgtDaq2RootMaker::~StFgtDaq2RootMaker(){
45 // if( mTFile ){
46 // mTFile->Close();
47 // delete mTFile;
48 // };
49 };
50 
51 Int_t StFgtDaq2RootMaker::Init(){
52  Int_t ierr = kStOk;
53 
54  // set the output
55  LOG_INFO << "Opening file '" << mFileName << "' for output" << endm;
56  mTFile = new TFile( mFileName.data(), "RECREATE", "raw fgt data from the cosmic test stand" );
57  if( !mTFile->IsOpen() ){
58  LOG_FATAL << "error opening file '" << mFileName << "'" << endm;
59  ierr = kStFatal;
60  };
61 
62  if( !ierr ){
63  mTTree = new TTree ( "fgtTree", "raw fgt data from the cosmic test stand" );
64  mTTree->Branch( "branch", &mData, "data[26880]/I" );
65  };
66 
67  return ierr;
68 };
69 
70 void StFgtDaq2RootMaker::Clear(const Option_t* opts ){
71  for( Int_t quad = 0; quad < kNumQuad; ++quad )
72  for( Int_t apv = 0; apv < kNumApv; ++apv )
73  for( Int_t chan = 0; chan < kNumApv; ++chan )
74  for( Int_t tb = 0; tb < kNumApv; ++tb )
75  mData.quad[quad].apv[apv].chan[chan].tb[tb] = 0;
76 };
77 
78 
80  Int_t ierr = kStOk;
81 
82  StEvent* eventPtr = 0;
83  eventPtr = (StEvent*)GetInputDS("StEvent");
84 
85  if( !eventPtr ) {
86  LOG_ERROR << "Error getting pointer to StEvent from '" << ClassName() << "'" << endm;
87  ierr = kStErr;
88  };
89 
90  StFgtCollection* fgtCollectionPtr = 0;
91 
92  if( eventPtr ) {
93  fgtCollectionPtr=eventPtr->fgtCollection();
94  };
95 
96  if( !fgtCollectionPtr) {
97  LOG_ERROR << "Error getting pointer to StFgtCollection from '" << ClassName() << "'" << endm;
98  ierr = kStErr;
99  };
100 
101  if( !ierr ){
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 tb = 0; tb < kFgtNumTimeBins; ++tb ){
110  Short_t adc = (*stripIter)->getAdc(tb);
111 
112  Int_t rdo, arm, apv, chan, quad;
113  (*stripIter)->getElecCoords( rdo, arm, apv, chan );
114 
115  // Note: for cosmic data, discs are in the order
116  // expected (top to bottom on the rack)) for DAQ
117  // data, the discs correspond to
118  // 0: 1A.L, 1D.S
119  // 1: 2A.L, 2B.S
120  // 2: 2B.L, 2A.S
121 
122  if( rdo == 1 && arm == 0 && apv < 10 )
123  quad = 0;
124  else if( arm == 1 && apv < 10 )
125  quad = 1;
126  else if( rdo == 1 && arm == 1 && apv > 10 )
127  quad = 2;
128  apv %= 12;
129 
130 
131  mData.quad[quad].apv[apv].chan[chan].tb[tb] = adc;
132  };
133  };
134  };
135  };
136  };
137 
138  mTTree->Fill();
139 
140  return ierr;
141 };
142 
144  mTFile->Write();
145  mTFile->Close();
146 
147  return kStOk;
148 };
149 
150 ClassImp(StFgtDaq2RootMaker);
Definition: Stypes.h:44
Definition: Stypes.h:41