StFms  0.0.0
FMS software in the STAR framework
StFmsHitMaker.cxx
Go to the documentation of this file.
1 // ROOT
2 #include "TFile.h"
3 #include "TH1.h"
4 #include "TH2.h"
5 #include "TTree.h"
6 
7 
8 #include "StMessMgr.h"
9 #include "StEventTypes.h"
10 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
11 
13 #include "StFmsCollection.h"
14 #include "StFmsHit.h"
15 #include "StFmsHitMaker.h"
16 #include "StTriggerData2009.h"
17 
18 // PSU-FMS package
20 
21 #include <iostream>
22 #include <fstream>
23 #include <stdlib.h>
24 using namespace std;
25 
27 
28 StFmsHitMaker::StFmsHitMaker(const char* name) : StMaker(name){
29  mFmsDbMaker = NULL;
30  mFmsCollection = NULL;
31  mMuFmsColl = NULL;
32  LOG_INFO << "StFmsHitMaker initializing...."<<endm;
33  LOG_DEBUG << "StFmsHitMaker::constructor." << endm;
34 }
35 
37 
38  LOG_INFO << "StFmsHitMaker::destructor." << endm;
39 }
40 
41 void StFmsHitMaker::Clear(Option_t* option){
42  LOG_DEBUG << "StFmsHitMaker::Clear()" << endm;
43  StMaker::Clear(option);
44 }
45 
47 
48  LOG_INFO<<"StFmsHitMaker::Init() "<<endm;
49 
50  return StMaker::Init();
51 
52 }
53 
54 int StFmsHitMaker::InitRun(Int_t runNumber) {
55 
56  LOG_INFO << "StFmsHitMaker::InitRun --run# changed to " << runNumber << endm;
58  mCurrentRunNumber = runNumber; //called by maker's method :InitRun(run); when the run# changes
59 
60  return kStOK;
61 }
62 
65 
66  LOG_DEBUG<<"StFmsHitMaker::Make start"<<endm;
67  int flag = 0;
68  StTriggerData* triggerData = 0;
69 
70  //first try to get StTriggerData from StTriggerDataMaker (works for proudction) and create StFmsCollection
71  TObjectSet *os = (TObjectSet*)GetDataSet("StTriggerData");
72  if (os) {
73  triggerData = (StTriggerData*)os->GetObject();
74  if(triggerData){
75  flag=1;
76  // mFmsCollection = new StFmsCollection();
77  LOG_DEBUG<<"StFmsHitMaker::Make Found StTriggerData from StTriggerDataMaker"<<endm;
78  }
79  }
80 
81  //2nd try to get StTriggerData from StEvent
82  //but once FMS data is killed in StEvent, this will not work and all you see is empty data
83  StEvent* stEvent = (StEvent*) GetInputDS("StEvent");
84  //StEvent* stEvent = (StEvent*) GetInputDS("StEvent");
85  if(flag==0){
86  if(stEvent){
87  triggerData = stEvent->triggerData();
88  if(triggerData) {
89  flag=2;
90  LOG_DEBUG<<"StFmsHitMaker::Make Found StTriggerData from StEvent"<<endm;
91  }
92  else{
93  mFmsCollection = stEvent->fmsCollection();
94  if(mFmsCollection){
95  flag=3;
96  LOG_DEBUG<<"StFmsHitMaker::Make Found StFmsCollection from StEvent"<<endm;
97  }
98  }
99  } //found StEvent
100  }
101  LOG_DEBUG<<"before checking MuDst, flag is: "<<flag<<endl;
102 
103  //3rd try to get StTriggerData from StMuEvent, works for produced data (.MuDst.root) --Yuxi
104  StMuDst* muDst = (StMuDst*)GetInputDS("MuDst");
105  if(flag==0){
106  if(muDst){
107  mCurrentRunNumber = muDst->event()->runNumber();
108  triggerData = (StTriggerData*)StMuDst::event()->triggerData();
109  if(triggerData){
110  flag = 4; //Yuxi
111  LOG_INFO<<"StFmsHitMaker::Make Found StFmsTriggerData in MuDst"<<endm;
112  }
113  else LOG_ERROR << "Finally, no StFmsTriggerData in MuDst " <<endm;
114  }
115  }
116 
117 
118  LOG_DEBUG<<"after checking MuDst, flag is: "<<flag<<endm;
119  //after this step triggerData is pointing to StTriggerData block of StEvent
120 
121  if(flag>0){
123  //create StFmsHit and add it to StFmsCollection
124  for(unsigned short crt=1; crt<=4; crt++){
125  for(unsigned short slot=1; slot<=16; slot++){
126  for(unsigned short ch=0; ch<32; ch++){
127  unsigned short adc=0;
128  unsigned short tdc=0;
129  if(flag<=4){ //wont work when flag=3
130  adc=triggerData->fmsADC(crt,slot-1,ch);
131  tdc=triggerData->fmsTDC(crt,slot-1,ch);
132  }
133 
134  if(adc>0 || tdc>0){
135  // LOG_INFO<<"adc of crt "<<crt<<", slot "<<slot<<", channel "<<ch<<" is: "<<adc<<endm;
136  // LOG_INFO<<"tdc=====================================================is: "<<tdc<<endm;
137  StFmsHit* hit = new StFmsHit();
138  if(!hit){
139  LOG_ERROR <<"Failed to create FMS hit, skip this hit."<<endm;
140  continue;
141  }
142  hit->setDetectorId(0);
143  hit->setChannel(0);
144  hit->setQtCrate(crt);
145  hit->setQtSlot(slot);
146  hit->setQtChannel(ch);
147  hit->setAdc(adc);
148  hit->setTdc(tdc);
149  hit->setEnergy(0.0);
150  mFmsCollection->addHit(hit);
151  if(GetDebug()>0) hit->print();
152  }
153  }
154  }
155  }
156 
157 
159  if(flag>0){
160  for(unsigned int i=0; i<mFmsCollection->numberOfHits(); i++){
161  int d,c;
162  StFmsHit* fmsHit = (mFmsCollection->hits())[i];
163  int crt =fmsHit->qtCrate();
164  int slot =fmsHit->qtSlot();
165  int ch =fmsHit->qtChannel();
166  float adc =fmsHit->adc();
167  mFmsDbMaker->getReverseMap(crt,slot,ch,&d,&c);
168  float e=0.0;
169  if(d>0 || c>0){
170  float g1=mFmsDbMaker->getGain(d,c);
171  float g2=mFmsDbMaker->getGainCorrection(d,c);
172  e =adc*g1*g2;
173  }
174  fmsHit->setDetectorId(d);
175  fmsHit->setChannel(c);
176  fmsHit->setEnergy(e);
177  if(GetDebug()>0) fmsHit->print();
178  }
179  }
180 
181  LOG_INFO<<"StFmsHitMaker::Make got "<<mFmsCollection->numberOfHits()<<" hits in StFmsCollection"<<endm;
182 
183 
184 
185 
186  }//flag, received fms data from mudst, triggerdata, etc.
187 
188 /*
189  //flag = 0; //yuxi debug
190  if(flag==0) { //read hits created during production
191  if(muDst){
192  mMuFmsColl = StMuDst::muFmsCollection();
193  if(mMuFmsColl){
194  int nhits = mMuFmsColl->numberOfHits();
195  LOG_DEBUG<<"StFmsHitMaker::Make Found "<<nhits<<" hits in MuDst"<<endm;
196  cout<<"StFmsHitMaker::Make Found "<<nhits<<" hits in MuDst"<<endl;
197  for(int i=0; i<nhits; i++){
198  StMuFmsHit* mHit = mMuFmsColl->getHit(i);
199  if(mHit && GetDebug()>0) mHit->print();
200  mHit->print();
201  }
202  flag=5;
203  }
204  }
205  }
206 */
207  if(stEvent) {
208  //Adding StFmsCollection to StEvent
209  LOG_DEBUG<<"StFmsHitMaker::Make Adding StFmsCollection as FMSCOLLECTION"<<endm;
210  stEvent->setFmsCollection(mFmsCollection);
211  }
212 
213  return kStOk;
214 }
215 
217 
218  LOG_INFO << "StFmsHitMaker::Finish() " << endm;
219  return kStOk;
220 }
Int_t InitRun(Int_t runNumber)
void getReverseMap(Int_t qtCrate, Int_t qtSlot, Int_t qtChannel, Int_t *detectorId, Int_t *ch)
StFmsDbMaker * gStFmsDbMaker
StMuFmsCollection * mMuFmsColl
FMS data structure for StEvent.
Definition: StFmsHitMaker.h:46
unsigned int numberOfHits() const
Declaration of StFmsClusterFitter, shower-shape fitting routine.
Float_t getGainCorrection(Int_t detectorId, Int_t ch)
get the gain for the channel
void Clear(Option_t *option="")
void addHit(StFmsHit *)
StFmsHitMaker.
Definition: StFmsHitMaker.h:27
Float_t getGain(Int_t detectorId, Int_t ch)
StSPtrVecFmsHit & hits()
Int_t mCurrentRunNumber
FMS data structure for StMuEvent.
Definition: StFmsHitMaker.h:48
StFmsDbMaker * mFmsDbMaker
Definition: StFmsHitMaker.h:44
ClassImp(StFmsHitMaker)
StFmsCollection * mFmsCollection
DB maker provides FMS geometry and calibration data.
Definition: StFmsHitMaker.h:45
StFmsHitMaker(const char *name="StFmsHitMaker")