StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEpdHitMaker.cxx
1 #include <stdlib.h>
2 
17 #include "StEpdHitMaker.h"
18 #include "StMaker.h"
19 #include "StEventTypes.h"
20 #include "StEvent/StTriggerData.h"
21 #include "StEpdHit.h"
22 #include <TSystem.h>
23 #include "StEvent/StEpdCollection.h"
24 #include "StEpdDbMaker/StEpdDbMaker.h"
25 
26 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
27 
28 #include <iostream>
29 #include <fstream>
30 #include <sstream>
31 #include <string>
32 
33 ClassImp(StEpdHitMaker)
34 
35 
36 //----------------------------------------------
38  mEventCounter(0), mTriggerEventCounter(0), mEpdCollection(0), mTriggerData(0), mEpdDbMaker(0), mStEvent(0) {
39  LOG_DEBUG << "StEpdHitMaker::ctor" << endm;
40 }
41 
42 //----------------------------------------------
44  return kStOK;
45 }
46 
47 //----------------------------------------------
49  mEventCounter++ ;
50  mTriggerEventCounter++;
51  if( mReadMuDst ){
52  StMuDst* mudst = (StMuDst*)GetInputDS("MuDst");
53  if(!mudst){LOG_ERROR<<"StEpdHitMaker::GetEpdCollection found no StMuDst"<<endm; return 0; }
54  TClonesArray* epdhits = mudst->epdHits();
55  if( epdhits!=0 && epdhits->GetEntriesFast()!=0 ){ return kStOk; } //If processing MuDsts and non-zero hits exist in MuDst then stop and just use those hits otherwise fill StEvent
56  }
57 
58  mTriggerData = this->GetTriggerData();
59  if (!mTriggerData){
60  LOG_ERROR << "StEpdHitMaker::Make - no TriggerData object" << endm;
61  return kStErr;
62  }
63  mEpdDbMaker = this->GetEpdDbMaker();
64  if (!mEpdDbMaker){
65  LOG_ERROR << "StEpdHitMaker::Make - no EpdDbMaker object" << endm;
66  return kStErr;
67  }
68  mEpdCollection = this->GetEpdCollection();
69  if (!mEpdCollection){
70  LOG_ERROR << "StEpdHitMaker::Make - no EpdCollection object" << endm;
71  return kStErr;
72  }
73  FillStEpdData();
74  return kStOK;
75 }
76 
77 
78 //------------------------------------------------
80  // StEpdDbMaker* dbMaker = (StEpdDbMaker*)GetDataSet("epdDb"); // no, this doesn't work!!
81  StEpdDbMaker* dbMaker = (StEpdDbMaker*)GetMaker("epdDb");
82  if (!dbMaker) LOG_WARN << "No StEpdDbMaker found by StEpdHitMaker::GetEpdDbMaker" << endm;
83  return dbMaker;
84 }
85 
86 //----------------------------------------------
88  return kStOK;
89 }
90 
91 //----------------------------------------------
93  const StTriggerData* trg=0;
94  if( mReadMuDst ){
95  StMuDst* mudst = (StMuDst*)GetInputDS("MuDst");
96  if( mudst==0 ){ LOG_ERROR << "StEpdHitMaker::GetTriggerData - !StMuDst" << endm; return 0; }
97  StMuEvent* muevent = mudst->event();
98  if( muevent==0 ){ LOG_ERROR <<"StEpdHitMaker::GetTriggerData - !StMuEvent" <<endm; return 0; }
99  else{ trg = muevent->triggerData(); }
100  }
101  else{
102  mStEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent")); // this is how the StBtofHitMaker does it.
103  if (mStEvent){
104  trg = mStEvent->triggerData();
105  }
106  else {LOG_WARN << "No StEvent found by StEpdHitMaker::GetTriggerData" << endm;}
107  }
108  return trg;
109 }
110 
111 //----------------------------------------------
112 // this is patterned after the StBTofHitMaker
114  StEpdCollection* epdCollection = 0;
115  //This will get executed if no epdhits from mudsts. This way it will still generate the epd collection
116  mStEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent")); // this is how the StBtofHitMaker does it.
117  if (mStEvent){
118  epdCollection = mStEvent->epdCollection();
120  if (!epdCollection){
121  LOG_INFO << "StEpdHitMaker::GetEpdCollection - making new StEpdCollection and giving it to StEvent" << endm;
122  epdCollection = new StEpdCollection();
123  mStEvent->setEpdCollection(epdCollection);
124  }
125  else {
126  LOG_INFO << "StEpdHitMaker::GetEpdCollection - StEvent already has a StEpdCollection - not making a new one" << endm;
127  }
128  }
129  else{ LOG_WARN << "No StEvent found by StEpdHitMaker::GetEpdCollection" << endm; }
130  return epdCollection;
131 }
132 
133 void StEpdHitMaker::FillStEpdData(){
134 
135  const StTriggerData* trg=mTriggerData;
136 
137  // This is for BBC. We can do this if we ever have a StBbc class.
138  // for (Int_t ew=0; ew<2; ew++){
139  // for (Int_t pmt=0; pmt<24; pmt++){
140  // mStEpdData.BBCadc[ew][pmt] = trg->bbcADC(eastwest(ew),pmt+1,0);
141  // mStEpdData.BBCtac[ew][pmt] = trg->bbcTDC(eastwest(ew),pmt+1,0);
142  // mStEpdData.BBCtdc[ew][pmt] = trg->bbcTDC5bit(eastwest(ew),pmt+1);
143  // }
144  // }
145 
146  int PrePost=0; // this probably will henceforth always be zero, but keep it
147 
148  // ofstream EpdOfs;
149  // EpdOfs.open("FromStEpdHitMaker.txt");
150  // ofstream EpdOfs2;
151  // EpdOfs.open("FromStEpdHitMaker2.txt");
152 
153 
154  int nHitsAdded=0;
155  for (short ew=0; ew<2; ew++){ // EastWest (ew) = 0,1 for east,west
156  for (short PP=1; PP<13; PP++){ // note position (PP) goes from 1..12
157  for (short TT=1; TT<32; TT++){ // note tile number (TT) goes from 1..31
158 
159  short crateAdc = mEpdDbMaker->GetCrateAdc(ew,PP,TT);
160 
161  short EWforHit=(ew==0)?-1:+1;
162 
163  //---------------------------------------------------
164  // This below is for debugging only...
165  // cout << "StEpdHitMaker::FillStEpdData() -- this is what I get from StEpdDbMaker...\n";
166  // cout << "EW\tPP\tTT\tcrateAdc\t\boardAdc\tchannelAdc\tcrateTac\tboardTac\tchannelTac\n";
167  // cout << ew << "\t" << PP << "\t" << TT << "\t"
168  // << mEpdDbMaker->GetCrateAdc(ew,PP,TT) << "\t"
169  // << mEpdDbMaker->GetBoardAdc(ew,PP,TT) << "\t"
170  // << mEpdDbMaker->GetChannelAdc(ew,PP,TT) << "\t"
171  // << mEpdDbMaker->GetCrateTac(ew,PP,TT) << "\t"
172  // << mEpdDbMaker->GetBoardTac(ew,PP,TT) << "\t"
173  // << mEpdDbMaker->GetChannelTac(ew,PP,TT) << "\n";
174  //---------------------------------------------------
175 
176 
177  // EpdOfs << ew << "\t" << PP << "\t" << TT << "\t"
178  // << mEpdDbMaker->GetCrateAdc(ew,PP,TT) << "\t"
179  // << mEpdDbMaker->GetBoardAdc(ew,PP,TT) << "\t"
180  // << mEpdDbMaker->GetChannelAdc(ew,PP,TT) << "\t"
181  // << mEpdDbMaker->GetCrateTac(ew,PP,TT) << "\t"
182  // << mEpdDbMaker->GetBoardTac(ew,PP,TT) << "\t"
183  // << mEpdDbMaker->GetChannelTac(ew,PP,TT) << "\n";
184 
185 
186 
187  if (crateAdc>0){ // only create a StEpdHit object if database says it is in the data
188 
189  short boardAdc = mEpdDbMaker->GetBoardAdc(ew,PP,TT);
190  short channelAdc = mEpdDbMaker->GetChannelAdc(ew,PP,TT);
191  int ADC = trg->epdADC(crateAdc,boardAdc,channelAdc,PrePost);
192 
193  if (ADC>0){ // we are zero-suppressing at QT level, so don't just write a bunch of zeros into the data
194  int TDC = trg->epdTDC(crateAdc,boardAdc,channelAdc,PrePost);
195 
196  // bool isGood = kTRUE; // until it is in the database
197  bool isGood = true; // until it is in the database
198 
199  bool HasTac = (mEpdDbMaker->GetChannelTac(ew,PP,TT)>=0);
200  int TAC;
201  if (HasTac){
202  TAC = trg->epdADC(mEpdDbMaker->GetCrateTac(ew,PP,TT), // relying on conversion from int to short
203  mEpdDbMaker->GetBoardTac(ew,PP,TT),
204  mEpdDbMaker->GetChannelTac(ew,PP,TT),
205  PrePost);}
206  else{TAC = 0;}
207 
208  // finally.... CALIBRATED data....
209  double gain = mEpdDbMaker->GetMip(ew,PP,TT);
210  if (gain<=0.0) gain = 1.0; // not yet calibrated. Give it a gain of unity
211 
212  float nMIP = (ADC + mEpdDbMaker->GetOffset(ew,PP,TT)) / mEpdDbMaker->GetMip(ew,PP,TT);
213 
214  int truthId=0; // this is for simulation
215 
216 
217  // EpdOfs2 << ew << "\t" << PP << "\t" << TT << "\t"
218  // << mEpdDbMaker->GetCrateAdc(ew,PP,TT) << "\t"
219  // << mEpdDbMaker->GetBoardAdc(ew,PP,TT) << "\t"
220  // << mEpdDbMaker->GetChannelAdc(ew,PP,TT) << "\t"
221  // << mEpdDbMaker->GetCrateTac(ew,PP,TT) << "\t"
222  // << mEpdDbMaker->GetBoardTac(ew,PP,TT) << "\t"
223  // << mEpdDbMaker->GetChannelTac(ew,PP,TT) << "\t"
224  // << ADC << "\t" << nMIP << endl;
225 
226  StEpdHit* hit = new StEpdHit(PP,TT,EWforHit,ADC,TAC,TDC,HasTac,nMIP,isGood,truthId);
227  mEpdCollection->addHit(hit);
228  nHitsAdded++;
229  }
230  }
231  }
232  }
233  }
234 
235  // EpdOfs.close();
236  // EpdOfs2.close();
237 
238  LOG_INFO << "StEpdHitMaker::FillStEpdData - added " << nHitsAdded << " to StEpdHitCollection" << endm;
239 }
240 
StEpdDbMaker * GetEpdDbMaker()
Returns a pointer to the StEpdDbMaker.
virtual int Init()
Init does nothing right now.
Definition: T.h:18
StEpdCollection * GetEpdCollection()
Returns the collection of StEpdHits in the event.
static TClonesArray * epdHits()
returns pointer to the EpdHitCollection
Definition: StMuDst.h:297
virtual int Finish()
Finish does nothing right now.
virtual int Make()
const StTriggerData * GetTriggerData()
Returns a pointer to the StTriggerData object.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Stores information for tiles in STAR Event Plane Detector.
Definition: StEpdHit.h:43
Definition: Stypes.h:40
Definition: Stypes.h:44
Definition: Stypes.h:41