StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerStudyMaker.cxx
1 //StMuDstMaker
2 #include "StMuDSTMaker/COMMON/StMuDst.h"
3 #include "StMuDSTMaker/COMMON/StMuEvent.h"
4 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
5 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
6 #include "StMuDSTMaker/COMMON/StMuEmcUtil.h"
7 #include "StMuDSTMaker/COMMON/StMuTrack.h"
8 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
9 
10 #include "StEvent/StTriggerId.h"
11 #include "StEvent/StEvent.h"
12 #include "StEventTypes.h"
13 
14 #include "StDetectorDbMaker/StDetectorDbTriggerID.h"
15 #include "StEvent/StL0Trigger.h"
16 
17 #include "StDaqLib/TRG/trgStructures2005.h"
18 
19 //StEmc
20 #include "StEmcUtil/database/StBemcTables.h"
21 #include "StEmcUtil/database/StEmcDecoder.h"
22 #include "StEmcUtil/geometry/StEmcGeom.h"
23 #include "StEmcUtil/projection/StEmcPosition.h"
24 #include "StEmcADCtoEMaker/StBemcData.h"
25 #include "StEmcADCtoEMaker/StEmcADCtoEMaker.h"
26 #include "StEmcRawMaker/StBemcRaw.h"
27 #include "StEmcRawMaker/defines.h"
28 #include "StEmcRawMaker/StBemcTables.h"
29 #include "StEmcTriggerMaker/StEmcTriggerMaker.h"
30 
31 //logger
32 #include "StMessMgr.h"
33 
34 
35 #include "StTriggerStudyMaker.h"
36 #include "StDetectorDbMaker/StDetectorDbBeamInfo.h"
37 #include "StSpinPool/StTriggerFilterMaker/StTriggerFilterMaker.h"
38 #include "StTriggerStudyEvent.h"
39 #include "StEnumerations.h"
40 #include "StTriggerUtilities/StTriggerSimuMaker.h"
41 #include "StTriggerUtilities/StTriggerSimuResult.h"
42 #include "TTree.h"
43 #include "TFile.h"
44 
45 ClassImp(StTriggerStudyMaker)
46 
47 StTriggerStudyMaker::StTriggerStudyMaker(const char* filename, const char* name):StMaker(name),nTriggers(12)
48 {
49  mName = filename;
50  runNumber = 0;
51  muDstMaker = NULL;
52  mTriggerSimuMaker = NULL;
53  mTree = NULL;
54  mFile = NULL;
55  mTSEvent = NULL;
56 }
57 //_____________________________________________________________________________
58 Int_t StTriggerStudyMaker::Init()
59 {
60  int trigarray[12] = {117001,137221,137222,137822,117300,137571,137575,137585,137586,137611,137501,137622};
61  for(int i = 0; i < nTriggers; i++){
62  triggers[i] = trigarray[i];
63  trigmap[triggers[i]] = i;
64  }
65 
66  mFile = new TFile(mName,"RECREATE");
67  mTSEvent = new StTriggerStudyEvent();
68  mTree = new TTree("trigStudyTree","Trigger Study Tree");
69  mTree->Branch("event_branch","StTriggerStudyEvent",&mTSEvent);
70  mTree->SetAutoSave(1000000000);
71 
72  muDstMaker = dynamic_cast<StMuDstMaker*>(GetMaker("MuDst"));
73  assert(muDstMaker);
74  mADCtoEMaker = dynamic_cast<StEmcADCtoEMaker*>(GetMaker("Eread")); assert(mADCtoEMaker);
75  mTriggerSimuMaker = dynamic_cast<StTriggerSimuMaker*>(GetMaker("StarTrigSimu"));
76 
77  mDecoder = new StEmcDecoder();
78  mEmcGeom = StEmcGeom::instance("bemc");
79  mBemcTables = mADCtoEMaker->getBemcData()->getTables();
80 
81  zvertall = new TH1F("zvertall","Z Vertex Distribution",280,-139.5,140.5);
82  bbctall = new TH1F("bbctall","BBC Time Bins",18,-1.5,16.5);
83  jp1et = new TH1F("jp1et","JP1 Et Distribution",70,17.9,31.9);
84  jp2et = new TH1F("jp2et","JP2 Et Distribution",70,17.9,31.9);
85  jp1et0 = new TH1F("jp1et0","JP1 Et Distribution",70,3.9,17.9);
86  jp0et0 = new TH1F("jp0et0","JP0 Et Distribution",70,3.9,17.9);
87  for(int i = 0; i < nTriggers; i++){
88  trigmap[triggers[i]] = i;
89  char namez[100];
90  sprintf(namez,"zvert%i",triggers[i]);
91  zverttrig[i] = new TH1F(namez,"Z Vertex Distribution",280,-139.5,140.5);
92  char nameb[100];
93  sprintf(nameb,"bbct%i",triggers[i]);
94  bbcttrig[i] = new TH1F(nameb,"BBC Time Bins",18,-1.5,16.5);
95  }
96 
97  return StMaker::Init();
98 }
99 //_____________________________________________________________________________
100 Int_t StTriggerStudyMaker::InitRun(int run)
101 {
102  if(runNumber != 0){
103  LOG_ERROR<<"Attempting to change run: check file list"<<endm;
104  return kStErr;
105  }
106  LOG_INFO<<"Now starting Run#"<<run<<endm;
107  runNumber = run;
108  return kStOk;
109 
110 }
111 //_____________________________________________________________________________
113  mFile->cd();
114  mTree->Write();
115  zvertall->Write();
116  bbctall->Write();
117  jp1et->Write();
118  jp2et->Write();
119  jp1et0->Write();
120  jp0et0->Write();
121  for(int i = 0; i < nTriggers; i++){
122  zverttrig[i]->Write();
123  bbcttrig[i]->Write();
124  }
125  mFile->Close();
126  return StMaker::Finish();
127 }
128 //_____________________________________________________________________________
130  fillTree();
131  mTSEvent->Clear();
132  return kStOK;
133 }
134 //_____________________________________________________________________________
135 void StTriggerStudyMaker::fillTree()
136 {
137  StDetectorDbTriggerID* dbtrig = StDetectorDbTriggerID::instance();
138  StMuDst* mudst = muDstMaker->muDst();assert(mudst);
139  StMuEvent* muevent = mudst->event();assert(muevent);
140 
141  int bbctimebin = muevent->bbcTriggerDetector().onlineTimeDifference();
142  mTSEvent->setBbcTimeBin(bbctimebin);
143  bbctall->Fill(bbctimebin/32);
144 
145  float vertmag = TMath::Abs(muevent->primaryVertexPosition().mag());
146  float vertz = muevent->primaryVertexPosition().z();
147  if(vertmag > 1e-7)mTSEvent->setVertexPosition(muevent->primaryVertexPosition());
148  if(vertmag > 1e-7)zvertall->Fill(vertz);
149 
150  int isjp1 = 0;
151  int isjp0 = 0;
152  int isjp2 = 0;
153  float jpEt[12] = {0,0,0,0,0,0,0,0,0};
154  float maxjpEt = -1;
155  mEmcCollection = mudst->emcCollection();
156  StDetectorId detectorid = static_cast<StDetectorId>(kBarrelEmcTowerId);
157  StEmcDetector* detector=mEmcCollection->detector(detectorid);
158  if(detector){
159  for(int m=1;m<=120;m++){
160  StEmcModule* module = detector->module(m);
161  if(module){
162  StSPtrVecEmcRawHit& rawHit=module->hits();
163  for(unsigned int k=0;k<rawHit.size();k++){
164  if(rawHit[k]){
165  int module = rawHit[k]->module();
166  int eta = rawHit[k]->eta();
167  int submodule = abs(rawHit[k]->sub());
168  int ADC = rawHit[k]->adc();
169  int hitid;
170  int stat = mEmcGeom->getId(module,eta,submodule,hitid);
171  int status;
172  mBemcTables->getStatus(BTOW,hitid,status);
173  float pedestal,rms;
174  mBemcTables->getPedestal(BTOW,hitid,0,pedestal,rms);
175  if(stat==0&&status==1&&((float)ADC-pedestal) > 2*rms){
176  //mTSEvent->addTowerADC(hitid,(float)ADC-pedestal);
177  float theta;
178  mEmcGeom->getTheta(hitid,theta);
179  float calib = mBemcTables->calib(BTOW,hitid);
180  float energy = calib * (float)(ADC-pedestal);
181  float et = energy*sin(theta);
182  if(et > 0.2){
183  int jpID;
184  mDecoder->GetJetPatchFromTowerId(hitid,jpID);
185  jpEt[jpID]+=et;
186  }
187  }
188  }
189  }
190  }
191  else { LOG_WARN<<"couldn't find StEmcModule "<<m<<" for detector "<<BTOW<<endm;}
192  }
193  }
194 
195  const StTriggerId& trigs = muevent->triggerIdCollection().nominal();
196  vector<unsigned int>triggers = trigs.triggerIds();
197  vector<unsigned int>prescales;
198  vector<unsigned int>simutriggers;
199 
200  mTSEvent->setTriggers(triggers);
201 
202  for(unsigned int i = 0; i < triggers.size(); i++){
203  unsigned int prs = (unsigned int)dbtrig->getTotalPrescaleByTrgId(triggers[i]);
204  prescales.push_back(prs);
205 
206  if(triggers[i] == 137222)isjp1 = 1;
207  if(triggers[i] == 137501)isjp0 = 1;
208  if(triggers[i] == 137585)isjp2 = 1;
209  map<int,int>::iterator iter = trigmap.find(triggers[i]);
210  if(iter!=trigmap.end()){
211  int tr = iter->second;
212  if(vertmag > 1e-7)zverttrig[tr]->Fill(vertz);
213  bbcttrig[tr]->Fill(bbctimebin/32);
214  }
215  if(mTriggerSimuMaker && mTriggerSimuMaker->isTrigger(triggers[i])){
216  simutriggers.push_back(triggers[i]);
217  StTriggerSimuResult trigsimuresult = mTriggerSimuMaker->detailedResult(triggers[i]);
218  vector<short> towers = trigsimuresult.highTowerIds();
219  for(unsigned int j = 0; j < towers.size(); j++){
220  int dsm = trigsimuresult.highTowerAdc(towers[j]);
221  //if(dsm > 0)mTSEvent->addTowerDSM(towers[j],dsm);
222  }
223  vector<short> jpatches = trigsimuresult.jetPatchIds();
224  for(unsigned int j = 0; j < jpatches.size(); j++){
225  int dsm = trigsimuresult.jetPatchAdc(jpatches[j]);
226  if(dsm > 0)mTSEvent->addJPatchDSM(jpatches[j],dsm);
227  }
228  vector<short> tpatches = trigsimuresult.triggerPatchIds();
229  for(unsigned int j = 0; j < tpatches.size(); j++){
230  int dsm = trigsimuresult.triggerPatchAdc(tpatches[j]);
231  if(dsm > 0)mTSEvent->addTPatchDSM(tpatches[j],dsm);
232  }
233  }
234  }
235  vector<float> jpetvec;
236  for(int k = 0; k < 12; k++){
237  if(jpEt[k] > maxjpEt)maxjpEt = jpEt[k];
238  jpetvec.push_back(jpEt[k]);
239  }
240  if(isjp1) jp1et->Fill(maxjpEt);
241  if(isjp1 && isjp2)jp2et->Fill(maxjpEt);
242  if(isjp0) jp0et0->Fill(maxjpEt);
243  if(isjp0 && isjp1)jp1et0->Fill(maxjpEt);
244 
245  mTSEvent->setJPEt(jpetvec);
246  mTSEvent->setPrescales(prescales);
247  mTSEvent->setSimuTriggers(simutriggers);
248 
249  mTree->Fill();
250 }
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
int GetJetPatchFromTowerId(int softId, int &jetPatch) const
Get jet patch that contains software Id.
StMuDst * muDst()
Definition: StMuDstMaker.h:425
int jetPatchAdc(short jetPatchId) const
returns DSM ADC if above trigger threshold, otherwise -1
StBemcData * getBemcData()
Return the StBemcData pointer.
int highTowerAdc(short towerId) const
returns DSM ADC if above trigger threshold, otherwise -1
StBemcTables * getTables()
Return the StBemcTable pointer.
Definition: StBemcRaw.h:207
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
Accessor to the database for trigger id information.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776
static StEmcCollection * emcCollection()
returns pointer to current StEmcCollection
Definition: StMuDst.h:405
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
Float_t getTotalPrescaleByTrgId(Int_t trgId)
const StTriggerSimuResult & detailedResult(int trigId)
returns object containing detailed information about simulation of given trigger
int triggerPatchAdc(short patchId) const
returns DSM ADC if above trigger threshold, otherwise -1
Definition: Stypes.h:44
Definition: Stypes.h:41