StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcCalibrationMaker.cxx
1 #include "StEmcCalibrationMaker.h"
2 
3 #include <math.h>
4 
5 #include <TFile.h>
6 
7 #include "StEventTypes.h"
8 #include "StEvent.h"
9 #include "Stiostream.h"
10 #include "Stsstream.h"
11 #include "StEmcUtil/geometry/StEmcGeom.h"
12 #include "StEmcUtil/filters/StEmcFilter.h"
13 #include "StEmcUtil/projection/StEmcPosition.h"
14 #include "StarClassLibrary/StThreeVectorF.hh"
15 #include "StarClassLibrary/StElectron.hh"
16 #include "tables/St_emcStatus_Table.h"
17 #include "PhysicalConstants.h"
18 #include "tables/St_emcPed_Table.h"
19 #include "tables/St_smdPed_Table.h"
20 #include "tables/St_emcStatus_Table.h"
21 #include "tables/St_smdStatus_Table.h"
22 #include "StEmcADCtoEMaker/StBemcData.h"
23 #include "StDbLib/StDbManager.hh"
24 #include "StDbLib/StDbTable.h"
25 #include "StDbLib/StDbConfigNode.hh"
26 #include "StDaqLib/EMC/StEmcDecoder.h"
27 
28 #define CAP1 124
29 #define CAP2 125
30 
31 ClassImp(StEmcCalibrationMaker)
32 
33 //_____________________________________________________________________________
35 {
36  this->Clear();
37  TString n[MAXBEMC]={"bemc","bprs","bsmde","bsmdp"};
38  for(int i=0;i<MAXBEMC;i++) mGeom[i] = StEmcGeom::instance(n[i].Data());
39  mPosition = new StEmcPosition();
40  mNChannel[0] = 4800;
41  mNChannel[1] = 4800;
42  mNChannel[2] = 18000;
43  mNChannel[3] = 18000;
44 }
45 //_____________________________________________________________________________
46 StEmcCalibrationMaker::~StEmcCalibrationMaker()
47 {
48 }
49 //_____________________________________________________________________________
50 Int_t StEmcCalibrationMaker::Init()
51 {
52  return StMaker::Init();
53 }
54 //_____________________________________________________________________________
55 void StEmcCalibrationMaker::zeroAll()
56 {
57  mStEvent = NULL;
58  mEmcCol = NULL;
59  mField = 0;
60  mL3Tracks = false;
61  mVx = mVy = mVz = 0;
62  mNTracks = 0;
63  for(int i=0;i<MAXTRACK;i++)
64  {
65  mTrack[i] = NULL;
66  mTrackP[i] = mTrackPt[i] = mTrackTower[i] = mTrackNPoints[i] = mTrackTowerExit[i] =0;
67  }
68  for(int i=0;i<MAXBEMC;i++) for(int j=0;j<mNChannel[i];j++)
69  {
70  mADC[i][j] = mADCPedSub[i][j] = 0;
71  mCap[i][j] = mNTracksTower[j] = 0;
72  mPedRms[i][j] = mPed[i][j] = 0;
73  if(i==0) mIsIsolatedTower[j] = true;
74  mHasDetector[i] = false;
75  }
76  mZDCSum = 0;
77  mCTBSum = 0;
78 }
79 //_____________________________________________________________________________
81 {
82  zeroAll();
83  mStEvent = (StEvent*)GetInputDS("StEvent");
84  if(!mStEvent) return kStOk;
85  mEmcCol=(StEmcCollection*)mStEvent->emcCollection();
86  if(!mEmcCol) return kStOk;
87 
88  StPrimaryVertex *v = mStEvent->primaryVertex();
89  if(v)
90  {
91  StThreeVectorF position = v->position();
92  mVx-=position.x(); mVy=position.y(); mVz=position.z();
93  }
94 
95  mIsTriggerOk = true;
96 
97  //need to set BField ////////////////
98  StEventSummary *evtSummary = mStEvent->summary();
99  if (evtSummary) mField = evtSummary->magneticField()/10;
100 
101  fillEmcArrays();
102  fillTrackArrays();
103 
104  return kStOK;
105 }
106 //_____________________________________________________________________________
108 {
109  return StMaker::Finish();
110 }
111 //_____________________________________________________________________________
112 void StEmcCalibrationMaker::fillEmcArrays()
113 {
114  TString n[MAXBEMC]={"bemc","bprs","bsmde","bsmdp"};
115 
116  for(int i = 0;i<MAXBEMC;i++)
117  {
118  mHasDetector[i] = false;
119  TString calibDb="Calibrations/emc/y3";
120  calibDb+=n[i];
121  TDataSet *emcDb=GetInputDB(calibDb.Data());
122  TString table=n[i];
123  table+="Ped";
124  if(i<2 && emcDb) // tower and preShower
125  {
126  St_emcPed *ped = (St_emcPed*)emcDb->Find(table.Data());
127  emcPed_st *pedst=NULL;
128  if(ped) pedst=ped->GetTable();
129  if(pedst) for(int j=0;j<mNChannel[i];j++)
130  {
131  mPed[i][j] = (float)pedst[0].AdcPedestal[j]/100.;
132  mPedRms[i][j] = (float)pedst[0].AdcPedestalRMS[j]/100.;
133  //cout <<"Pedestal "<<i<<" id = "<<j+1<<" Ped = "<<mPed[i][j]<<" rms = "<<mPedRms[i][j]<<endl;
134  }
135  }
136  else if(i>=2 && emcDb)
137  {
138  St_smdPed *ped = (St_smdPed*)emcDb->Find(table.Data());
139  smdPed_st *pedst=NULL;
140  if(ped) pedst=ped->GetTable();
141  if(pedst) for(int j=0;j<mNChannel[i];j++) // uses only capacitor index 0
142  {
143  mPed[i][j] = (float)pedst[0].AdcPedestal[j][0]/100.;
144  mPedRms[i][j] = (float)pedst[0].AdcPedestalRMS[j][0]/100.;
145  //cout <<"Pedestal "<<i<<" id = "<<j+1<<" Ped = "<<mPed[i][j]<<" rms = "<<mPedRms[i][j]<<endl;
146  }
147  }
148 
149  StDetectorId id = static_cast<StDetectorId>(i+kBarrelEmcTowerId);
150  StEmcDetector* detector=mEmcCol->detector(id);
151  if(detector) for(int m=1;m<=120;m++)
152  {
153  StEmcModule* module = detector->module(m);
154  if(module)
155  {
156  StSPtrVecEmcRawHit& rawHit=module->hits();
157  for(unsigned int k=0;k<rawHit.size();k++) if(rawHit[k])
158  {
159  mHasDetector[i] = true;
160  int did;
161  int mod=rawHit[k]->module();
162  int e=rawHit[k]->eta();
163  int s=abs(rawHit[k]->sub());
164  int ADC = rawHit[k]->adc();
165  int stat = mGeom[i]->getId(mod,e,s,did);
166  if(stat ==0)
167  {
168  mADC[i][did-1] = ADC;
169  mADCPedSub[i][did-1] = (short)(ADC - mPed[i][did-1]);
170  mCap[i][did-1] = (char) rawHit[k]->calibrationType();
171  if(mCap[i][did-1]>127) mCap[i][did-1]-=128;
172  if(mPed[i][did-1]==0 || mPedRms[i][did-1]==0) mADCPedSub[i][did-1] = 0;
173  if(i>=2)
174  {
175  if(mCap[i][did-1]==CAP1 || mCap[i][did-1]==CAP1) //uses only capacitor 0 data
176  {
177  mADCPedSub[i][did-1] = 0;
178  mADC[i][did-1] = 0;
179  }
180  }
181  }
182  }
183  }
184  }
185  }
186 }
187 //_____________________________________________________________________________
188 void StEmcCalibrationMaker::fillTrackArrays()
189 {
190  StSPtrVecTrackNode& tracks=mStEvent->trackNodes();
191  mNTracks = tracks.size();
192  mL3Tracks = false;
193  if(mNTracks<=0)
194  {
195  if(mStEvent->l3Trigger())
196  {
197  tracks =mStEvent->l3Trigger()->trackNodes();
198  mNTracks = tracks.size();
199  mL3Tracks = true;
200  }
201  }
202  if(mNTracks > 0)
203  {
204  for(int t=0;t<mNTracks;t++)
205  {
206  StTrack *track = tracks[t]->track(0);
207  if(track)
208  {
209  if(track->geometry())
210  {
211  mTrackPt[t] = track->geometry()->momentum().perp();
212  mTrackP[t] = track->geometry()->momentum().mag();
213  mTrackNPoints[t] = track->fitTraits().numberOfFitPoints();
214  StThreeVectorD momentum,position;
215  bool tok = mPosition->trackOnEmc(&position,&momentum,(StTrack*)track,(Double_t)mField,(Double_t)mGeom[0]->Radius());
216  if(tok)
217  {
218  int m,e,s,id=0;
219  float eta=position.pseudoRapidity();
220  float phi=position.phi();
221  int stat = mGeom[0]->getBin(phi,eta,m,e,s);
222  stat = mGeom[0]->getId(m,e,s,id);
223  if(stat==0)
224  {
225  mTrackTower[t] = id;
226  mNTracksTower[id-1]++;
227  StThreeVectorD momentum1,position1;
228  bool tok1 = mPosition->trackOnEmc(&position1,&momentum1,(StTrack*)track,(Double_t)mField,(Double_t)mGeom[0]->Radius()+30.0);
229  if(tok1)
230  {
231  int id2=0;
232  eta=position1.pseudoRapidity();
233  phi=position1.phi();
234  stat = mGeom[0]->getBin(phi,eta,m,e,s);
235  stat = mGeom[0]->getId(m,e,s,id2);
236  if(stat==0)
237  {
238  mTrackTowerExit[t] = id2;
239  if(id2!=id) mNTracksTower[id2-1]++;
240  }
241  }
242  }
243  }
244  }
245  }
246  }
247  }
248 
249  for(int i=0;i<mNChannel[0];i++)
250  {
251  int id = i+1;
252  mIsIsolatedTower[id-1] = true;
253  for(int j=-1;j<=1;j++) for(int k=-1;k<=1;k++)
254  {
255  int id2 = mPosition->getNextTowerId(id,j,k);
256  if(id2!=id) if(id2>=1 && id2<=4800) if(mNTracksTower[id2-1]>0) { mIsIsolatedTower[id-1] = false; break; }
257  }
258  }
259 }
260 void StEmcCalibrationMaker::makeStatus(bool t, bool p, bool se, bool sp)
261 {
262  // for the towers
264  int towers[4800];
265  for(int i =0;i<4800;i++) towers[i] = 1; // include all towers
266 
267  int crates[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
268  1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}; // exclude some crates
269 
271  // for the PSD
272  int psd[4800];
273  for(int i =0;i<4800;i++) psd[i] = 1; // include all PSD towers
274  for(int i =2400;i<4800;i++) psd[i] = 0; // include all PSD towers
275 
277  // for the SMD-eta
278  int smde[18000];
279  for(int i =0;i<18000;i++) smde[i] = 1; // include all SMD-eta towers
280 
281  int smdeMod[120];
282  for(int i =0;i<120;i++) smdeMod[i] = 1; // include all SMD-eta modules
283  for(int i =60;i<120;i++) smdeMod[i] = 0; // include all SMD-eta modules
284 
286  // for the SMD-phi
287  int smdp[18000];
288  for(int i =0;i<18000;i++) smdp[i] = 1; // include all SMD-phi towers
289 
290  int smdpMod[120];
291  for(int i =0;i<120;i++) smdpMod[i] = 1; // include all SMD-phi modules
292  for(int i =60;i<120;i++) smdpMod[i] = 0; // include all SMD-eta modules
293 
295  StEmcDecoder *dec = new StEmcDecoder(20300101,0);
296 
297  const char *timestamp = "2004-01-01 00:00:00";
298 
300  StDbConfigNode* node=mgr->initConfig(dbCalibrations,dbEmc);
301 
302  // for the towers
303 
304  if(t)
305  {
306  St_emcStatus *mBemc = new St_emcStatus("emcStatus",1);
307  emcStatus_st *bemc=mBemc->GetTable();
308 
309  for(int i=0;i<4800;i++)
310  {
311  bemc[0].Status[i] = towers[i];
312  int daq;
313  dec->GetDaqIdFromTowerId(i+1,daq);
314  int crate, pos;
315  dec->GetTowerCrateFromDaqId(daq,crate,pos);
316  bemc[0].Status[i] = crates[crate-1];
317  }
318 
319  StDbTable* tab1=node->addDbTable("bemcStatus");
320  tab1->SetTable((char*)bemc,1);
321  mgr->setStoreTime(timestamp);
322  mgr->storeDbTable(tab1);
323  }
324 
325  // for the PSD
326 
327  if(p)
328  {
329  St_emcStatus *mPSD = new St_emcStatus("emcStatus",1);
330  emcStatus_st *psdt = mPSD->GetTable();
331 
332  for(int i=0;i<4800;i++)
333  {
334  psdt[0].Status[i] = psd[i];
335  }
336 
337  StDbTable* tab2=node->addDbTable("bprsStatus");
338  tab2->SetTable((char*)psdt,1);
339  mgr->setStoreTime(timestamp);
340  mgr->storeDbTable(tab2);
341  }
342 
343  // for the SMD-eta
344 
345  if(se)
346  {
347  St_smdStatus *mSMDE = new St_smdStatus("smdStatus",1);
348  smdStatus_st *smdet = mSMDE->GetTable();
349  StEmcGeom *geo3 = StEmcGeom::instance("bsmde");
350 
351  for(int i=0;i<18000;i++)
352  {
353  smdet[0].Status[i] = smde[i];
354  int m,e,s;
355  geo3->getBin(i+1,m,e,s);
356  smdet[0].Status[i] = smdeMod[m-1];
357  }
358 
359  StDbTable* tab3=node->addDbTable("bsmdeStatus");
360  tab3->SetTable((char*)smdet,1);
361  mgr->setStoreTime(timestamp);
362  mgr->storeDbTable(tab3);
363  }
364 
365  // for the SMD-phi
366  if(sp)
367  {
368  St_smdStatus *mSMDP = new St_smdStatus("smdStatus",1);
369  smdStatus_st *smdpt = mSMDP->GetTable();
370  StEmcGeom *geo4 = StEmcGeom::instance("bsmdp");
371 
372  for(int i=0;i<18000;i++)
373  {
374  smdpt[0].Status[i] = smdp[i];
375  int m,e,s;
376  geo4->getBin(i+1,m,e,s);
377  smdpt[0].Status[i] = smdpMod[m-1];
378  }
379 
380  StDbTable* tab4=node->addDbTable("bsmdpStatus");
381  tab4->SetTable((char*)smdpt,1);
382  mgr->setStoreTime(timestamp);
383  mgr->storeDbTable(tab4);
384  }
385 
386  delete dec;
387  dec = 0;
388 
389 }
Bool_t trackOnEmc(StThreeVectorD *position, StThreeVectorD *momentum, const StTrack *const track, Double_t magField, Double_t emcRadius=225.405) const
Track projection utility.
int GetTowerCrateFromDaqId(int RDO, int &crate, int &sequence) const
Get crate number from Daq Id for towers.
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
Int_t getNextTowerId(Float_t eta, Float_t phi, Int_t nTowersdEta, Int_t nTowersdPhi) const
Return neighbor tower id&#39;s.
Definition: Stypes.h:40
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
virtual Int_t Finish()
Definition: StMaker.cxx:776
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.
Definition: Stypes.h:41
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362