StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StChargedPionMaker.cxx
1 // $Id: StChargedPionMaker.cxx,v 1.23 2013/10/09 14:43:39 stevens4 Exp $
2 
3 #include "StChargedPionMaker.h"
4 
5 //ROOT headers
6 #include "TFile.h"
7 #include "TTree.h"
8 #include "TClonesArray.h"
9 #include "TChain.h"
10 
11 //StarClassLibrary
12 #include "SystemOfUnits.h"
13 
14 //StMuDstMaker
15 #include "StMuDSTMaker/COMMON/StMuDst.h"
16 #include "StMuDSTMaker/COMMON/StMuEvent.h"
17 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
18 #include "StMuDSTMaker/COMMON/StMuDst.h"
19 #include "StMuDSTMaker/COMMON/StMuTrack.h"
20 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
21 
22 //logger
23 #include "StMessMgr.h"
24 
25 //my headers
26 #include "StChargedPionEvent.h"
27 #include "StChargedPionVertex.h"
28 #include "StChargedPionTrack.h"
29 #include "StChargedPionJet.h"
30 #include "StChargedPionJetParticle.h"
31 #include "StChargedPionMcEvent.h"
32 #include "StChargedPionHelpers.h"
33 #include "StChargedPionTypes.h"
34 
35 //StDetectorDbMaker
36 #include "StDetectorDbMaker/StDetectorDbTriggerID.h"
37 
38 //StJetMaker
39 #include "StSpinPool/StJetSkimEvent/StJetSkimEvent.h"
40 #include "StSpinPool/StJets/StJets.h"
41 #include "StSpinPool/StJets/StJet.h"
42 #include "StJetMaker/StJetMaker.h"
43 
44 //StSpinDbMaker
45 #include "StSpinPool/StSpinDbMaker/StSpinDbMaker.h"
46 
47 //StEmcTriggerMaker
48 #include "StEmcTriggerMaker/StEmcTriggerMaker.h"
49 
50 //StTriggerUtilities
51 #include "StTriggerUtilities/StTriggerSimuMaker.h"
52 #include "StTriggerUtilities/StTriggerSimuResult.h"
53 
54 //StMiniMcEvent
58 
59 #include "tables/St_g2t_event_Table.h"
60 #include "tables/St_particle_Table.h"
61 #include "tables/St_g2t_pythia_Table.h"
62 
63 //StMcEvent
64 #include "StMcEvent/StMcEvent.hh"
65 
66 ClassImp(StChargedPionMaker)
67 
68 StChargedPionMaker::StChargedPionMaker(const char *name, const char *outputfile) :
69  StMaker(name)
70 {
71  LOG_INFO << "calling constructor" << endm;
72 
73  mFile = new TFile(outputfile,"RECREATE");
74 
75  mBadTracks = new TH1D("badTracks","tracks failing quality cuts",4,0.5,4.5);
76 
77  time_t rawtime;
78  time(&rawtime);
79  char title[200];
80  sprintf(title, "created %s", ctime(&rawtime));
81  mTree = new TTree("tree",title);
82 
83  bool isMonteCarlo = GetMakerInheritsFrom("StEmcSimulatorMaker") ? true:false;
84  LOG_INFO << "Are we running on Monte Carlo? " << isMonteCarlo << endm;
85 
86  if(isMonteCarlo) {
87  mEvent = new StChargedPionMcEvent();
88  mTree->Branch("event", "StChargedPionMcEvent", &mEvent);
89  }
90  else {
91  mEvent = new StChargedPionEvent();
92  mTree->Branch("event", "StChargedPionEvent", &mEvent);
93  }
94 
95  Long64_t autosave = 1000000000; //1GB
96  mTree->SetAutoSave(autosave);
97  mTree->SetMaxTreeSize(autosave);
98 
99  mMuDstMk = NULL;
100  mSpDbMk = NULL;
101  mEmcTrgMk = NULL;
102  mJetMk = NULL;
103  mTrgSimuMk = NULL;
104 
105  mJetFile = NULL;
106  mJetTree = NULL;
107  mJets = new StJets();
108  mPyJets = new StJets();
109 
110  mMiniMcFile = NULL;
111  mMiniMcTree = NULL;
112  mMiniMcEvent = new StMiniMcEvent();
113 
114  mTriggers.clear();
115 
116  LOG_INFO << "finished constructor" << endm;
117 }
118 
119 StChargedPionMaker::~StChargedPionMaker() {
120  LOG_DEBUG << "calling destructor" << endm;
121 
122  if(mEvent) delete mEvent;
123 
124  if(mJetFile) mJetFile->Close();
125  delete mJets;
126  delete mPyJets;
127 
128  if(mMiniMcFile) mMiniMcFile->Close();
129  delete mMiniMcEvent;
130 
131  LOG_DEBUG << "finished destructor" << endm;
132 }
133 
134 void StChargedPionMaker::Clear(const char*) {
135  StChargedPionEvent *data = dynamic_cast<StChargedPionEvent*>(mEvent);
136  StChargedPionMcEvent *simu = dynamic_cast<StChargedPionMcEvent*>(mEvent);
137  if(data) data->Clear();
138  if(simu) simu->Clear();
139  StMaker::Clear();
140 }
141 
142 Int_t StChargedPionMaker::Init() {
143  mMuDstMk = dynamic_cast<StMuDstMaker*>(
144  GetMakerInheritsFrom("StMuDstMaker"));
145  mSpDbMk = dynamic_cast<StSpinDbMaker*>(
146  GetMakerInheritsFrom("StSpinDbMaker"));
147  mEmcTrgMk = dynamic_cast<StEmcTriggerMaker*>(
148  GetMakerInheritsFrom("StEmcTriggerMaker"));
149  mJetMk = dynamic_cast<StJetMaker*>(
150  GetMakerInheritsFrom("StJetMaker"));
151  mTrgSimuMk = dynamic_cast<StTriggerSimuMaker*>(
152  GetMakerInheritsFrom("StTriggerSimuMaker"));
153 
154  // do the setup for mPyJets here, since we only run on one file at a time
155  if( dynamic_cast<StChargedPionMcEvent*>(mEvent) ) {
156  if(mJetMk) {
157  mPyJets = mJetMk->getStJets("PythiaConeJets");
158  LOG_INFO << "loaded mPyJets at " << mPyJets << endm;
159  }
160  }
161 
162  this->Clear();
163 
164  LOG_INFO << "init OK" << endm;
165  return StMaker::Init();
166 }
167 
168 Int_t StChargedPionMaker::InitRun(int runnumber) {
169  if(mJetMk) {
170  LOG_INFO << "found StJetMaker in the chain" << endm;
171  if(StJets* stjets = mJetMk->getStJets("ConeJets")) {
172  mJets = stjets;
173  LOG_INFO << "found Jets in Run 5 branch " << mJets << endm;
174  }
175  else if(StJets* stjets = mJetMk->getStJets("ConeJets12")) {
176  mJets = stjets;
177  LOG_INFO << "found Jets in Run 6 branch " << mJets << endm;
178  }
179  else {
180  mJets = mJetMk->getStJets("ConeJets12_0.7");
181  LOG_INFO << "found ConeJets12_0.7 branch " << mJets << endm;
182  }
183  }
184  else {
185  LOG_INFO << "trying to get the jets off disk" << endm;
186  std::ostringstream os;
187  if(runnumber < 7000000) {
188  os << "/star/institutions/mit/common/run5/jets/jets_" << runnumber << ".tree.root";
189  }
190  else {
191  // best confirm this one with Murad first
192  os << "/star/institutions/mit/common/run6/jets/jets_" << runnumber << ".tree.root";
193  }
194 
195  if(mJetFile) mJetFile->Close();
196  mJetTree = NULL;
197  mJetFile = TFile::Open(os.str().c_str());
198  if(mJetFile) mJetTree = (TTree*) mJetFile->Get("jet");
199  if(mJetTree) {
200  if(runnumber < 7000000) {
201  mJetTree->SetBranchAddress("ConeJets", &mJets);
202  }
203  else {
204  mJetTree->SetBranchAddress("ConeJets12", &mJets);
205  }
206  mJetTree->BuildIndex("mRunId","mEventId");
207  }
208  }
209 
210  return StMaker::InitRun(runnumber);
211 }
212 
214 {
215  StChargedPionEvent *data = dynamic_cast<StChargedPionEvent*>(mEvent);
216  StChargedPionMcEvent *simu = dynamic_cast<StChargedPionMcEvent*>(mEvent);
217 
218  //have we changed files?
219  TString inputFile(mMuDstMk->chain()->GetFile()->GetName());
220  if(mCurrentFile != inputFile){
221  mCurrentFile = inputFile;
222  const char *baseName = strrchr(mCurrentFile.Data(), '/');
223  mEvent->setMuDstName( baseName );
224 
225  if(simu) {
226  TString minimcFile = inputFile.ReplaceAll("MuDst","minimc");
227  mMiniMcFile = TFile::Open(minimcFile);
228  if(mMiniMcFile) {
229  LOG_INFO << "opened minimc file at " << minimcFile << endm;
230  mMiniMcTree = dynamic_cast<TTree*> (mMiniMcFile->Get("StMiniMcTree"));
231  mMiniMcTree->BuildIndex("mEventId");
232  mMiniMcTree->SetBranchAddress("StMiniMcEvent", &mMiniMcEvent);
233  }
234  else {
235  LOG_WARN << "problem opening minimc at " << minimcFile << endm;
236  }
237  }
238  }
239 
240  if(data) {
241  StChargedPionHelpers::translateMuDst(data);
242 
243  // triggers, prescales
244  mTriggers.clear();
245  map<int,float> m = StDetectorDbTriggerID::instance()->getTotalPrescales();
246  for (map<int,float>::iterator it=m.begin(); it!=m.end(); ++it) {
247  int trigId = it->first;
248  data->setPrescale(trigId, it->second);
249 
250  if( StMuDst::event()->triggerIdCollection().nominal().isTrigger(trigId) ) {
251  data->addTrigger(trigId);
252  }
253 
254  mTriggers.push_back(trigId);
255  }
256 
257  makeTriggerSimu(data);
258 
259  //spin DB
260  int bx48 = StMuDst::event()->l0Trigger().bunchCrossingId();
261  data->setSpinBit( mSpDbMk->spin4usingBX48(bx48) );
262  data->setPolValid( mSpDbMk->isValid() );
263  data->setPolLong( mSpDbMk->isPolDirLong() );
264  data->setPolTrans( mSpDbMk->isPolDirTrans() );
265  data->setBxingMasked( mSpDbMk->isMaskedUsingBX48(bx48) );
266  data->setBxingOffset( mSpDbMk->offsetBX48minusBX7(bx48, data->bx7()) );
267  }
268 
269  if(simu) {
270  StChargedPionHelpers::translateMuDst(simu);
271 
272  makeTriggerSimu(simu);
273 
274  StMcEvent *mcEvent = static_cast<StMcEvent*>( GetDataSet("StMcEvent") );
275  simu->setProcessId( mcEvent->subProcessId() );
276 
277  TDataSet *Event = GetDataSet("geant");
278  TDataSetIter geantDstI(Event);
279 
280  St_g2t_pythia* PyPtr = (St_g2t_pythia *) geantDstI("g2t_pythia");
281  g2t_pythia_st *g2t_pythia = PyPtr->GetTable();
282  simu->setHardP( g2t_pythia->hard_p );
283  simu->setX1( g2t_pythia->bjor_1 );
284 
285  St_particle *particleTabPtr = (St_particle *) geantDstI("particle");
286  particle_st* particleTable = particleTabPtr->GetTable();
287 
288  simu->isr1().SetXYZT(
289  particleTable[2].phep[0],
290  particleTable[2].phep[1],
291  particleTable[2].phep[2],
292  particleTable[2].phep[3]
293  );
294 
295  simu->isr2().SetXYZT(
296  particleTable[3].phep[0],
297  particleTable[3].phep[1],
298  particleTable[3].phep[2],
299  particleTable[3].phep[3]
300  );
301 
302  simu->parton1().SetXYZT(
303  particleTable[4].phep[0],
304  particleTable[4].phep[1],
305  particleTable[4].phep[2],
306  particleTable[4].phep[3]
307  );
308 
309  simu->parton2().SetXYZT(
310  particleTable[5].phep[0],
311  particleTable[5].phep[1],
312  particleTable[5].phep[2],
313  particleTable[5].phep[3]
314  );
315 
316  simu->parton3().SetXYZT(
317  particleTable[6].phep[0],
318  particleTable[6].phep[1],
319  particleTable[6].phep[2],
320  particleTable[6].phep[3]
321  );
322 
323  simu->parton4().SetXYZT(
324  particleTable[7].phep[0],
325  particleTable[7].phep[1],
326  particleTable[7].phep[2],
327  particleTable[7].phep[3]
328  );
329 
330  simu->setFlavor(1, particleTable[4].idhep);
331  simu->setFlavor(2, particleTable[5].idhep);
332  simu->setFlavor(3, particleTable[6].idhep);
333  simu->setFlavor(4, particleTable[7].idhep);
334 
335  // save all final-state particles with E > 2.0 GeV
336  for(int i = 8; i < particleTabPtr->GetNRows(); ++i)
337  {
338  if(particleTable[i].isthep == 1 && particleTable[i].phep[3] > 2.0)
339  {
341  r.id = particleTable[i].idhep;
342  r.vec = StChargedPionLorentzVector(particleTable[i].phep[0],
343  particleTable[i].phep[1],
344  particleTable[i].phep[2],
345  particleTable[i].phep[3]);
346  simu->pythiaRecord().push_back(r);
347  }
348  }
349 
350  int bytesRead = mMiniMcTree->GetEntryWithIndex(simu->eventId());
351  if(bytesRead > 0) {
352  StChargedPionHelpers::translateMinimc(mMiniMcEvent, simu);
353  }
354 
355  // still need to set the the pythia jets
356  if(mJetMk) {
357  StChargedPionHelpers::translateJets(mPyJets, simu);
358  }
359  else if(mJetTree) {
360  int ok = mJetTree->GetEntryWithIndex(simu->runId(), simu->eventId());
361  if(ok > 0) StChargedPionHelpers::translateJets(mJets, simu);
362  }
363  }
364 
365  //and the jets
366  if(mJetMk) {
367  StChargedPionHelpers::translateJets(mJets, mEvent);
368  }
369  else if(mJetTree) {
370  int ok = mJetTree->GetEntryWithIndex(mEvent->runId(), mEvent->eventId());
371  if(ok > 0) StChargedPionHelpers::translateJets(mJets, mEvent);
372  }
373 
374  mTree->Fill();
375 
376  return StMaker::Make();
377 }
378 
380  mFile->cd();
381  mTree->Write();
382  mBadTracks->Write();
383  mFile->Close();
384  LOG_INFO << "finished OK"<<endm;
385  return StMaker::Finish();
386 }
387 
388 void StChargedPionMaker::makeTriggerSimu(StChargedPionBaseEv *ev) {
389  if(mTrgSimuMk) {
390  for (unsigned i=0; i<mTriggers.size(); ++i) {
391  int trigId = mTriggers[i];
392 
393  if( mTrgSimuMk->isTrigger(trigId) ) {
394  ev->addSimuTrigger(trigId);
395  }
396 
397  const StTriggerSimuResult result = mTrgSimuMk->detailedResult(trigId);
398  for(unsigned i=0; i<result.highTowerIds().size(); i++) {
399  int tid = result.highTowerIds().at(i);
400  ev->addHighTower(tid, result.highTowerAdc(tid));
401  }
402  for(unsigned i=0; i<result.triggerPatchIds().size(); i++) {
403  int tid = result.triggerPatchIds().at(i);
404  ev->addTriggerPatch(tid, result.triggerPatchAdc(tid));
405  }
406  for(unsigned i=0; i<result.jetPatchIds().size(); i++) {
407  int tid = result.jetPatchIds().at(i);
408  ev->addJetPatch(tid, result.jetPatchAdc(tid));
409  }
410  ev->setL2Result(result.l2Result(kJet), true);
411  }
412  }
413  else if(mEmcTrgMk) {
414  //minbias simu trigger
415  int Npmt=StMuDst::event()->bbcTriggerDetector().numberOfPMTs();
416  bool eastBBC(false), westBBC(false);
417  for (int pmt=0;pmt<Npmt;pmt++){
418  if(StMuDst::event()->bbcTriggerDetector().adc(pmt) > 5) {
419  if(pmt<16) eastBBC = true;
420  if(pmt>23 && pmt<40) westBBC = true;
421  }
422  }
423  if(eastBBC && westBBC) {
424  ev->addSimuTrigger(96011);
425  ev->addSimuTrigger(117011);
426  }
427 
428  for (unsigned i=0; i<mTriggers.size(); ++i) {
429  int trigId = mTriggers[i];
430 
431  if ( mEmcTrgMk->isTrigger(trigId) ) {
432  ev->addSimuTrigger(trigId);
433  }
434 
435  map<int,int> m( mEmcTrgMk->barrelTowersAboveThreshold(trigId) );
436  for(map<int,int>::const_iterator iter=m.begin(); iter!=m.end(); iter++) {
437  ev->addHighTower(iter->first, iter->second);
438  }
439 
440  m = mEmcTrgMk->barrelTriggerPatchesAboveThreshold(trigId);
441  for(map<int,int>::const_iterator iter=m.begin(); iter!=m.end(); iter++) {
442  ev->addTriggerPatch(iter->first, iter->second);
443  }
444 
445  m = mEmcTrgMk->barrelJetPatchesAboveThreshold(trigId);
446  for(map<int,int>::const_iterator iter=m.begin(); iter!=m.end(); iter++) {
447  ev->addJetPatch(iter->first, iter->second);
448  }
449  }
450  }
451 }
452 
453 /*****************************************************************************
454  * $Log: StChargedPionMaker.cxx,v $
455  * Revision 1.23 2013/10/09 14:43:39 stevens4
456  * Add const to char* in 2 lines to compile on 5.34.09 and SL6.4 on rplay18
457  *
458  * Revision 1.22 2010/04/25 16:07:57 pibero
459  * Modified StChargedPionMaker.cxx to use the safer StJetMaker::getStJets()
460  * instead of the outdated and no longer available StJetMaker::getJets().
461  *
462  * Revision 1.21 2010/04/25 15:18:49 pibero
463  * Temporary fix to keep AutoBuild happy. Permanent solution to be posted soon.
464  *
465  * Revision 1.20 2009/06/22 14:44:50 kocolosk
466  * support for new ConeJets12_0.7 branch name
467  *
468  * Revision 1.19 2009/04/02 18:25:42 kocolosk
469  * fixed paths to jet codes
470  *
471  * Revision 1.18 2008/12/29 15:58:30 kocolosk
472  * removed commented code and added Id and Log as needed
473  *
474  * Revision 1.17 2008/08/25 20:55:35 kocolosk
475  * get correct ConeJets/ConeJets12 branch w/o using runnumber
476  *
477  * Revision 1.16 2008/07/17 17:06:30 kocolosk
478  * big-bang integration StChargedPionMcEvent framework
479  *
480  *****************************************************************************/
map< Int_t, Float_t > getTotalPrescales()
bool isPolDirTrans()
true if all needed DB tables were found
Definition: StSpinDbMaker.h:54
bool isValid()
dump spinDb content for current time stamp
Definition: StSpinDbMaker.h:53
int jetPatchAdc(short jetPatchId) const
returns DSM ADC if above trigger threshold, otherwise -1
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
int highTowerAdc(short towerId) const
returns DSM ADC if above trigger threshold, otherwise -1
int spin4usingBX48(int bx48)
8bit spin information
Top level class for the MiniMcTree, containing event-wise information and the McTrack, and all TrackPair collections.
Definition: StJets.h:24
map< int, int > barrelTriggerPatchesAboveThreshold(int trigId)
map contains (key,value) = (patchId,ADC) of all TP above DSM threshold. map is empty if threshold = 0...
virtual Int_t Make()
Definition: StMaker.cxx:898
map< int, int > barrelJetPatchesAboveThreshold(int trigId)
map contains (key,value) = (patchId,ADC) of all JP above DSM threshold. map is empty if threshold = 0...
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
TChain * chain()
In read mode, returns pointer to the chain of .MuDst.root files that where selected.
Definition: StMuDstMaker.h:426
map< int, int > barrelTowersAboveThreshold(int trigId)
map contains (key,value) = (softId,ADC) of all towers above DSM threshold. map is empty if threshold ...
Definition: AgUStep.h:26
for simplicity, this contains both the rc and mc track information.
virtual Int_t Finish()
Definition: StMaker.cxx:776
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
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169
const unsigned int * l2Result(L2ResultType algo, int year=2006) const
returns address of specific L2 result struct – cast it yourself
int isTrigger(int trigId)
1==Yes,0==No,-1==Don&#39;t Know. Same convention holds for other methods where appropriate.
Persistent MC track class.
bool isPolDirLong()
Returns true if beams are transversely polarized, false otherwise.
Definition: StSpinDbMaker.h:55