StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StJetHistMaker.cxx
1 //root
2 #include "TFile.h"
3 #include "TTree.h"
4 #include "TH3.h"
5 #include "TNtuple.h"
6 
7 //std
8 #include <vector>
9 #include <map>
10 #include <algorithm>
11 #include <cmath>
12 using namespace std;
13 
14 //St_base
15 #include "StChain.h"
16 #include "StDetectorDbMaker/StDetectorDbTriggerID.h"
17 
18 //StEvent
19 #include "StEvent.h"
20 #include "StEnumerations.h"
21 #include "StEventTypes.h"
22 
23 //SCL
24 #include "StPhysicalHelixD.hh"
25 
26 //vertex constraint
27 #include "tables/St_vertexSeed_Table.h"
28 
29 //STAR
30 #include "TFile.h"
31 #include "StChain.h"
32 #include "SystemOfUnits.h"
33 
34 //StMuDstMaker
35 #include "StMuDSTMaker/COMMON/StMuDst.h"
36 #include "StMuDSTMaker/COMMON/StMuTrack.h"
37 #include "StMuDSTMaker/COMMON/StMuEvent.h"
38 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
39 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
40 #include "StMuDSTMaker/COMMON/StMuDst.h"
41 #include "StMuDSTMaker/COMMON/StMuEmcUtil.h"
42 
43 //StEvent
44 #include "StEventTypes.h"
45 
46 //StEmc
47 #include "StEmcClusterCollection.h"
48 #include "StEmcPoint.h"
49 #include "StEmcUtil/geometry/StEmcGeom.h"
50 #include "StEmcUtil/others/emcDetectorName.h"
51 #include "StEmcADCtoEMaker/StBemcData.h"
52 #include "StEmcADCtoEMaker/StEmcADCtoEMaker.h"
53 #include "StEmcRawMaker/defines.h"
54 #include "StEmcRawMaker/StBemcRaw.h"
55 #include "StEmcRawMaker/StBemcTables.h"
56 #include "StEmcRawMaker/StEmcRawMaker.h"
57 #include "StEmcRawMaker/defines.h"
58 
59 //Endcap
60 #include "StEEmcUtil/database/StEEmcDb.h"
61 #include "StEEmcUtil/database/EEmcDbItem.h"
62 #include "StEEmcUtil/database/cstructs/eemcConstDB.hh"
63 #include "StEEmcUtil/EEfeeRaw/EEname2Index.h"
64 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
65 
66 
67 //local
68 #include "StJetHistMaker.h"
69 
70 ClassImp(StJetHistMaker)
71 
72 //StJetHistMaker::StJetHistMaker(const Char_t *name, StMuDstMaker* uDstMaker, StEmcADCtoEMaker* adc2e, StEmcSimulatorMaker* sim, const char *outputName)
73 //: StMaker(name), muDstMaker(uDstMaker), mEmcSim(sim), mOutName(outputName), mAdc2E(adc2e), mTables(new StBemcTables())
74  StJetHistMaker::StJetHistMaker(StMuDstMaker* uDstMaker, const char *outputName)
75  : StMaker("StJetHistMaker"), muDstMaker(uDstMaker), mOutName(outputName), mTables(new StBemcTables())
76 {
77  mudst=0;
78 }
79 
80 Int_t StJetHistMaker::InitRun(Int_t runId)
81 {
82  cout <<"Welcome to StJetHistMaker::InitRun()"<<endl;
83  mTables->loadTables((StMaker*)this);
84 
85  /*
86  cout <<"id\tadc\teta\tphi\tpedestal\trms\tgain\tstatus"<<endl;
87  cout <<"--\t---\t---\t---\t--------\t---\t----\t------\n"<<endl;
88 
89  for (int id=1; id<24; ++id) {
90  float pedestal, rms;
91  int CAP=0; //this arument matters only for SMD
92  mTables->getPedestal(BTOW, id, CAP, pedestal, rms);
93 
94  //get eta/phi
95  float eta, phi;
96  //geom->getEtaPhi(id,eta,phi);
97 
98  //get gain
99  float gain = -1;
100  mTables->getCalib(BTOW,id,1,gain);
101 
102  cout <<id<<"\t"<<"-"<<"\t"<<"-"<<"\t"<<"-"<<"\t"<<pedestal<<"\t"<<rms<<"\t"<<gain<<"\t"<<"-"<<endl;
103 
104  }
105 
106  abort();
107  */
108 
109  return kStOk;
110 
111 }
112 
113 Int_t StJetHistMaker::Init()
114 {
115  cout << "StJetHistMaker: output file: " << mOutName << endl;
116 
117  //open output file
118  mOutfile = new TFile(mOutName,"RECREATE");
119 
120  //for mb
121  mbVertexZvsNp = new TH2F("mbVertexZvsNp","Z_{vertex} vs N_{good-primary} (mb)", 101, -0.5, 100.5, 400, -200., 200.);
122  mbTrackKin = new TH3F("mbTrackKin","Eta vs Phi vs Pt (mb)", 200, 0., 10., 100, -3.14159, 3.14159, 100, -1.5, 1.5);
123  mbNfitVsEta = new TH2F("mbNfitVsEta","Eta vs N_{fit} (mb)", 56, -0.5, 55.5, 100, -1.5, 1.5);
124 
125  //for ht1
126  ht1VertexZvsNp = new TH2F("ht1VertexZvsNp","Z_{vertex} vs N_{good-primary} (ht1)", 101, -0.5, 100.5, 400, -200., 200.);
127  ht1TrackKin = new TH3F("ht1TrackKin","Eta vs Phi vs Pt (ht1)", 200, 0., 10., 100, -3.14159, 3.14159, 100, -1.5, 1.5);
128  ht1NfitVsEta = new TH2F("ht1NfitVsEta","Eta vs N_{fit} (ht1)", 56, -0.5, 55.5, 100, -1.5, 1.5);
129 
130  //for other (e.g., pythia)
131  otherVertexZvsNp = new TH2F("otherVertexZvsNp","Z_{vertex} vs N_{good-primary} (other)", 101, -0.5, 100.5, 400, -200., 200.);
132  otherTrackKin = new TH3F("otherTrackKin","Eta vs Phi vs Pt (other)", 200, 0., 10., 100, -3.14159, 3.14159, 100, -1.5, 1.5);
133  otherNfitVsEta = new TH2F("otherNfitVsEta","Eta vs N_{fit} (other)", 56, -0.5, 55.5, 100, -1.5, 1.5);
134 
135  //EMC MIP hist:
136  mipHistVsEta = new TH2F("mipHistVsEta","ADC_{MIP} distribution vs Tower Eta",20, 0., 1., 200, 0, 200);
137  mipEvsEta = new TH2F("mipEvsEta","E_{MIP} distribution vs Tower Eta",20, 0., 1., 200, 0, 2);
138  towerEvsId = new TH2F("towerEvsId","E_{Tower} vs ID",2401, -0.5, 2400.5, 100, 0., 10.);
139  towerAdcvsId = new TH2F("towerAdcvsId","ADC_{Tower} vs ID", 2401, -0.5, 2400.5, 100, 0., 500.);
140 
141 
142  return StMaker::Init();
143 }
144 
145 void StJetHistMaker::fillBarrelHits()
146 {
147  cout <<"void StJetHistMaker::fillBarrelHits()"<<endl;
148 
149  //assert(mEmcSim);
150 
151  StEmcGeom* geom = StEmcGeom::instance("bemc"); // for towers
152  assert(geom);
153 
154  //Get status tables.
155  assert(mTables);
156 
157  //Now loop on emc data
158  StEvent* event = dynamic_cast<StEvent*>( GetInputDS("StEvent") );
159  assert(event);
160  StEmcCollection* emc = event->emcCollection();
161  assert(emc);
162 
163  // now it is like StEvent, getting energies for towers
164  StEmcDetector* detector = emc->detector(kBarrelEmcTowerId);
165  assert(detector);
166 
167  //cout <<"id\tadc\teta\tphi\tpedestal\trms\tgain\tstatus"<<endl;
168  //cout <<"--\t---\t---\t---\t--------\t---\t----\t------\n"<<endl;
169 
170  //check peds, gain, status, etc...
171  for(int m = 1; m<=120;m++) { //loop on modules...
172  StEmcModule* module = detector->module(m);
173  assert(module);
174 
175  StSPtrVecEmcRawHit& rawHits = module->hits();
176 
177  for(UInt_t k=0;k<rawHits.size();k++) { //loop on hits in modules
178  StEmcRawHit* tempRawHit = rawHits[k];
179 
180  //Get eta, phi
181  int m = tempRawHit->module();
182  int e = tempRawHit->eta();
183  int s = abs(tempRawHit->sub());
184  int id, status;
185  //int adc = tempRawHit->adc(); //not pedestal subtracted!
186  geom->getId(m,e,s,id); // to get the software id
187 
188  //now check the status: (//BTOW defined in StEmcRawMaker/defines.h
189  mTables->getStatus(BTOW, id, status);
190 
191  //Get ped, rms
192  float pedestal, rms;
193  int CAP=0; //this arument matters only for SMD
194  mTables->getPedestal(BTOW, id, CAP, pedestal, rms);
195 
196  //get eta/phi
197  float eta, phi;
198  geom->getEtaPhi(id,eta,phi);
199 
200  //get gain
201  float gain = -1;
202  mTables->getCalib(BTOW,id,1,gain);
203 
204  if (gain!=0. && status==1);
205 
206 
207  //cout <<id<<"\t"<<adc<<"\t"<<eta<<"\t"<<phi<<"\t"<<pedestal<<"\t"<<rms<<"\t"<<gain<<"\t"<<status<<endl;
208 
209  }
210  }
211 }
212 
214 {
215  cout <<" Start StJetHistMaker :: "<< GetName() <<endl;
216  gMessMgr->SwitchOff("I");
217  gMessMgr->SwitchOff("E");
218  gMessMgr->SwitchOff("W");
219  gMessMgr->SwitchOff("Q");
220 
221  //fillBarrelHits();
222 
223  mudst = muDstMaker->muDst();
224  StMuEvent* muEvent = mudst->event();
225 
226  //Event quantities: http://www.star.bnl.gov/cgi-bin/cvsweb.cgi/StRoot/StMuDSTMaker/COMMON/
228  /*
229  int nprimary = mudst->numberOfPrimaryTracks();
230  int runId = muEvent->runId();
231  int eventId = muEvent->eventNumber();
232  int day = runId/1000 - 5000;
233  StRunInfo& runInfo = muEvent->runInfo();
234 
235  assert(runInfo.beamFillNumber(blue)==runInfo.beamFillNumber(yellow));
236  float fill = runInfo.beamFillNumber(blue);
237  */
238 
239  StMuTriggerIdCollection tic = muEvent -> triggerIdCollection();
240  StTriggerId l1trig = tic.l1();
241 
242  int startriggers[3] = {45010, 45201, 45202}; //mb, bht1-slow, bht2-slow
243  int trigs[3] = {0,0,0};
244  int prescales[3] = {0,0,0};
245 
246  //see if we satisfy various triggers
247  for (int i=0; i<3; ++i) {
248  if (l1trig.isTrigger(startriggers[i])) {
249  trigs[i] = 1;
250  }
251  }
252 
253  //get trigger prescales:
254  StDetectorDbTriggerID& v = *(StDetectorDbTriggerID::instance());
255  for(unsigned int i = 0; i < v.getL0NumRows(); i++){ //loop on table
256 
257  for (int j=0; j<3; ++j) { //loop on triggers
258 
259  if (v.getL0OfflineTrgId(i) == startriggers[j]) { //ok, it's one of our triggers
260  prescales[j] = v.getPsL0(i);
261  }
262  }
263  }
264 
265  if (vertex.z()!=0. && fabs(vertex.z())<50 ) {
266 
267  int nprim = 0;
268  int nTracks = mudst->primaryTracks()->GetLast()+1;
269 
270  for(int i = 0; i < nTracks; i++) {
271  StMuTrack* track = mudst->primaryTracks(i);
272  assert(track);
273 
274  if ( track->flag()>0
275  && track->topologyMap().trackFtpcEast()==false
276  && track->topologyMap().trackFtpcWest()==false
277  && track->pt()>0.2
278  && track->nHitsFit()>30
279  && fabs(track->eta())<0.5
280  ) {
281 
282 
283  StThreeVectorF mom = track->momentum();
284  //if (fabs(track->eta())<0.5 && track->nHitsFit>30)
285  ++nprim;
286 
287  //ok, we have a vertex, and a good primary track.
288  if (trigs[0] == 1) { //we have a mb event
289  mbTrackKin->Fill( mom.perp(), mom.phi(), mom.pseudoRapidity() );
290  mbNfitVsEta->Fill(track->nHitsFit(), mom.pseudoRapidity());
291  }
292  if (trigs[1] == 1) {//we have a ht1-slow event
293  ht1TrackKin->Fill( mom.perp(), mom.phi(), mom.pseudoRapidity() );
294  ht1NfitVsEta->Fill(track->nHitsFit(), mom.pseudoRapidity());
295  }
296  if (trigs[0]==0 && trigs[1]==0 && trigs[2]==0) {//ok, "other"
297  otherTrackKin->Fill( mom.perp(), mom.phi(), mom.pseudoRapidity() );
298  otherNfitVsEta->Fill(track->nHitsFit(), mom.pseudoRapidity());
299  }
300 
301  }
302  }
303 
304  if (trigs[0] == 1) { //we have a mb event
305  mbVertexZvsNp->Fill(nprim, vertex.z());
306  }
307  if (trigs[1] == 1) {//we have a ht1-slow event
308  ht1VertexZvsNp->Fill(nprim, vertex.z());
309  }
310  if (trigs[0]==0 && trigs[1]==0 && trigs[2]==0) {//ok, "other"
311  otherVertexZvsNp->Fill(nprim, vertex.z());
312  }
313  }
314 
315  return kStOk;
316 }
317 
318 void StJetHistMaker::FinishFile(void)
319 {
320  //close file
321  mOutfile->Write();
322  mOutfile->Close();
323  delete mOutfile;
324 }
325 
327 {
328  FinishFile();
329  StMaker::Finish();
330  return kStOK;
331 }
332 
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
StMuDst * muDst()
Definition: StMuDstMaker.h:425
Double_t pt() const
Returns pT at point of dca to primary vertex.
Definition: StMuTrack.h:256
virtual Int_t Make()
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
Accessor to the database for trigger id information.
short flag() const
Returns flag, (see StEvent manual for type information)
Definition: StMuTrack.h:230
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:260
Definition: Stypes.h:40
virtual Int_t Finish()
virtual Int_t Finish()
Definition: StMaker.cxx:776
Collection of trigger ids as stored in MuDst.
StTrackTopologyMap topologyMap() const
Returns topology map.
Definition: StMuTrack.h:254
Definition: Stypes.h:41