StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGammaScheduleMaker.cxx
1 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
2 #include "StEmcSimulatorMaker/StEmcSimulatorMaker.h"
3 #include "St_db_Maker/St_db_Maker.h"
4 
5 #include "TList.h"
6 #include "TTree.h"
7 
8 #include "StGammaScheduleMaker.h"
9 
10 ClassImp(StGammaScheduleMaker);
11 
13 // Constructor //
15 StGammaScheduleMaker::StGammaScheduleMaker(const char *name): StMaker(name)
16 {}
17 
19 // Add a timestamp //
21 void StGammaScheduleMaker::addTimestamp(int date, int time, double weight)
22 {
23 
24  stamp currentStamp;
25  currentStamp.date = date;
26  currentStamp.time = time;
27  currentStamp.weight = weight;
28 
29  mStamps.push_back(currentStamp);
30 
31 }
32 
34 // Sneak the maker right before the //
35 // slow simulator in the chain //
37 void StGammaScheduleMaker::rearrange()
38 {
39 
40  StMaker *simulator = GetMakerInheritsFrom("StEmcSimulatorMaker");
41  if(!simulator)
42  {
43  LOG_WARN << "rearrange() - No StEmcSimulatorMaker found in the chain!" << endm;
44  return;
45  }
46 
47  TList *makerList = this->GetParentChain()->GetMakeList();
48 
49  makerList->Remove(dynamic_cast<StMaker*>(this));
50  makerList->AddBefore(simulator, dynamic_cast<StMaker*>(this));
51 
52 }
53 
55 // Maker Init //
57 Int_t StGammaScheduleMaker::Init()
58 {
59 
60  // Fetch the total number of events in the MuDst
61  StMuDstMaker *muDstMaker = dynamic_cast<StMuDstMaker*>(GetMakerInheritsFrom("StMuDstMaker"));
62  if(!muDstMaker)
63  {
64  LOG_WARN << "Init() - No StMuDstMaker found in the chain!" << endm;
65  return kStWarn;
66  }
67 
68  mTotalEvents = muDstMaker->tree()->GetEntries();
69  mCurrentEvent = 0;
70  mStampIndex = 0;
71 
72  if(mStamps.size())
73  {
74 
75  LOG_INFO << "Init() - Distributing status tables across " << mTotalEvents << " events" << endm;
76 
77  // Calculate integrated weight to ensure proper normalization
78  double totalWeight = 0;
79 
80  vector<stamp>::iterator it;
81 
82  for(it = mStamps.begin(); it != mStamps.end(); ++it)
83  {
84  totalWeight += (*it).weight;
85  }
86 
87  // Calculate the events at which the status tables will switch
88  double usedEvents = 0;
89  for(it = mStamps.begin(); it != mStamps.end(); ++it)
90  {
91  double newEvents = ((*it).weight / totalWeight) * mTotalEvents;
92  (*it).event = usedEvents;
93  usedEvents += newEvents;
94  }
95 
96  LOG_INFO << "Init() - Using the timestamps" << endm;
97  LOG_INFO << "Init() - \tDate\t\tTime\tWeight\tInitial Event" << endm;
98  for(it = mStamps.begin(); it != mStamps.end(); ++it)
99  {
100  LOG_INFO << "Init() - \t" << it->date << "\t" << it->time << "\t" << it->weight << "\t" << it->event << endm;
101  }
102 
103  }
104  else
105  {
106  LOG_INFO << "Init() - Using the default timestamp" << endm;
107  }
108 
109  return StMaker::Init();
110 
111 }
112 
113 
115 // Maker Make //
118 {
119 
120  // Grab a pointer to the database
121  St_db_Maker *database = dynamic_cast<St_db_Maker*>(GetMakerInheritsFrom("St_db_Maker"));
122  if(!database)
123  {
124  LOG_WARN << "Make() - No St_db_Maker found in the chain!" << endm;
125  return kStWarn;
126  }
127 
128  // Loop over timestamps
129  vector<stamp>::iterator it;
130 
131  for(it = mStamps.begin(); it != mStamps.end(); ++it)
132  {
133 
134  // Reset the database date and time to align with
135  // the new time stamp if necessary
136  double diff = mCurrentEvent - it->event;
137  if(!mCurrentEvent) diff = 0.5;
138 
139  if(diff > 0 && diff < 1)
140  {
141  LOG_INFO << "Make() - Setting time stamp to Date = " << it->date << ", Time = " << it->time
142  << " (Index " << mStampIndex + 1 << ") at event " << mCurrentEvent + 1 << endm;
143  database->SetDateTime(it->date, it->time);
144  ++mStampIndex;
145  break;
146  }
147 
148  }
149 
150  ++mCurrentEvent;
151 
152  return kStOk;
153 
154 }
TTree * tree()
Returns pointer to the current TTree, the top level io structure that holds the event, track, v0, etc. information in branches of that tree.
Definition: StMuDstMaker.h:427
Definition: Stypes.h:42
Definition: Stypes.h:41