StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPxlSimMaker.cxx
1 /*
2  **********************************************************
3  * $Log: StPxlSimMaker.cxx,v $
4  * Revision 1.13 2017/10/19 19:38:17 jeromel
5  * Merging PXL201709UPD back to MAIN
6  *
7  * Revision 1.12.6.1 2017/09/11 20:15:14 dongx
8  * Pxl slow simulator added
9  *
10  * Revision 1.12 2016/04/14 23:10:19 smirnovd
11  * Cosmetic changes
12  *
13  * * Make sure we call functions from std library as it was probably intended
14  *
15  * * Removed unnecessary #included dependency
16  * - Nothing in the code seems to come from the stdio.h header
17  *
18  * * End log messages with endm to flush the internal buffer
19  *
20  * Revision 1.11 2016/04/13 19:15:02 mstftsm
21  * The choice of geometry should be mutually exclusive
22  *
23  * streamline inlined methods and define them outside the header
24  *
25  * Use one flag to control geometry source
26  *
27  * Use fundamental C++ types; this is not a persistent class
28  *
29  * Fix a logic bug
30  *
31  * fix bug: missing inline keyword
32  *
33  * The choice of geometry source shoule be mutually exclusive
34  *
35  * Revision 1.10 2015/03/13 18:45:01 perev
36  * Roll back
37  *
38  * Revision 1.8 2014/07/17 01:47:43 mstftsm
39  * Fix a bug in creating a new StPxlHitCollection.
40  * Random seed is set to default.
41  * DB geometry is set to default.
42  *
43  * Revision 1.7 2014/07/10 18:52:09 mstftsm
44  * Check if StPxlHitCollection exists in StEvent and add simulated hits to it. Otherwise, create a new collection.
45  *
46  * Revision 1.6 2014/07/03 19:46:37 mstftsm
47  * Revereted the changes made for the pileup adder. That does not belong to the master branch.
48  *
49  * Revision 1.4 2014/06/25 19:21:57 mstftsm
50  * pxl DB DataSet has been change to pxl_db. Name changed in this code.
51  *
52  * Revision 1.3 2014/03/13 17:00:19 mstftsm
53  * StPxlSimMaker has a method to switch on random seed for StRandom generatos in simulators. Default is not a random seed.
54  *
55  * Revision 1.1 2013/05/12 21:43:33 jeromel
56  * Initial revision, code peer review closed 2013/05/06
57  *
58  * Revision 1.4 2013/05/03 15:08:19 mstftsm
59  *
60  */
61 
62 #include "StPxlSimMaker.h"
63 #include "StPxlFastSim.h"
64 #include "StPxlDigmapsSim.h"
65 #include "StPxlISim.h"
66 #include "StMcEvent/StMcPxlHitCollection.hh"
67 #include "StEvent/StPxlHitCollection.h"
68 #include "StPxlRawHitMaker/StPxlRawHit.h"
69 #include "StPxlRawHitMaker/StPxlRawHitCollection.h"
70 
71 #include "Stiostream.h"
72 #include "StHit.h"
73 #include "StEventTypes.h"
74 #include "StEvent.h"
75 #include "StMcEvent.hh"
76 #include "StMcEventTypes.hh"
77 
78 #include "TGeoManager.h"
79 #include "TGeoMatrix.h"
80 
81 #include "TObjectSet.h"
82 
83 ClassImp(StPxlSimMaker)
84 
85 using namespace std;
86 
87 StPxlSimMaker::StPxlSimMaker(const Char_t* name) : StMaker(name) , mPxlSimulator(0), mUseFastSim(false), mUseDIGMAPSSim(false) , mUseDbGeom(true), mUseRandomSeed(true)
88 {
89 }
90 //____________________________________________________________
92 {
93  delete mPxlSimulator;
94 }
95 //____________________________________________________________
97 {
98  LOG_INFO << "StPxlSimMaker::Init()" << endm;
99 
100  mUseDIGMAPSSim = IAttr("useDIGMAPSSim");
101 
102  if(mUseDIGMAPSSim)
103  {
104  mPxlSimulator = new StPxlDigmapsSim();
105  LOG_INFO << "StPxlSimMaker: using StPxlDigmapsSim " << endm;
106  }
107  else
108  {
109  mUseFastSim = true;
110  mPxlSimulator = new StPxlFastSim("pxlFastSim",mUseRandomSeed);
111  LOG_INFO << "StPxlSimMaker: using StPxlFastSim " << endm;
112  }
113 
114  return kStOk;
115 }
116 
117 //____________________________________________________________
118 Int_t StPxlSimMaker::InitRun(Int_t RunNo)
119 {
120  LOG_INFO << "StPxlSimMaker::InitRun" << endm;
121 
122  TDataSet *hitErrSet = GetDataBase("Calibrations/tracker/PixelHitError");
123  if (!hitErrSet)
124  {
125  LOG_ERROR << "StPxlSimMaker - E - could not Get Calibrations/tracker." << endm;
126  return kStErr;
127  }
128 
129  TObjectSet *pxlDbDataSet = 0;
130  if(mUseDbGeom)
131  {
132  pxlDbDataSet = (TObjectSet*)GetDataSet("pxl_db");
133  if (!pxlDbDataSet)
134  {
135  LOG_ERROR << "StPxlSimMaker - E - pxlDb is not available" << endm;
136  return kStErr;
137  }
138  }
139 
140  return mPxlSimulator->initRun(*hitErrSet, pxlDbDataSet, RunNo);
141 }
142 //____________________________________________________________
143 
145 {
146  LOG_INFO << "StPxlSimMaker::Make()" << endm;
147 
148  // Get the input data structures from StEvent and StMcEvent
149  StEvent* rcEvent = (StEvent*) GetInputDS("StEvent");
150  if (! rcEvent)
151  {
152  LOG_INFO << "No StEvent on input" << endm;
153  return kStWarn;
154  }
155 
156  StMcEvent* mcEvent = (StMcEvent *) GetInputDS("StMcEvent");
157  if (! mcEvent)
158  {
159  LOG_INFO << "No StMcEvent on input" << endm;
160  return kStWarn;
161  }
162 
163  //Get MC Pxl hit collection. This contains all PXL hits.
164  StMcPxlHitCollection* mcPxlHitCol = mcEvent->pxlHitCollection();
165  if (!mcPxlHitCol)
166  {
167  LOG_INFO << "StPxlSimMaker no PXL hits in this StMcEvent!" << endm;
168  return kStOk;
169  }
170 
171  if (!mUseDbGeom && !gGeoManager) GetDataBase("VmcGeometry");
172  if (!mUseDbGeom && !gGeoManager)
173  {
174  LOG_ERROR << " StPxlSimMaker - E - gGeoManager is not available." << endm;
175  return kStErr;
176  }
177 
178  // call the requested simulator
179  if (mUseFastSim)
180  {
181  StPxlHitCollection *pxlHitCol = rcEvent->pxlHitCollection();
182 
183  bool newCollection = false;
184  if (!pxlHitCol)
185  {
186  LOG_INFO << "No existing StPxlHiCollection. Creating a new one..." <<endm;
187  pxlHitCol = new StPxlHitCollection();
188  newCollection = true;
189  }
190 
191  mPxlSimulator->addPxlHits(*mcPxlHitCol, *pxlHitCol);
192 
193  if(newCollection) rcEvent->setPxlHitCollection(pxlHitCol);
194  LOG_DEBUG << " size of hit collection : " << pxlHitCol->numberOfHits() << endm;
195  }
196  else //if (mUseDIGMAPSSim)
197  {
198  StPxlRawHitCollection* pxlRawHitCol = 0;
199 
200  TObjectSet* pxlRawHitDataSet = (TObjectSet*)GetDataSet("pxlRawHit");
201 
202  if (!pxlRawHitDataSet)
203  {
204  LOG_INFO << " pxlRawHit does NOT exist! Create a new one! " << endm;
205 // pxlRawHitDataSet = new TObjectSet("pxlRawHit");
206 // m_DataSet = pxlRawHitDataSet;
207  pxlRawHitCol = new StPxlRawHitCollection();
208  ToWhiteBoard("pxlRawHit", pxlRawHitCol);
209 // pxlRawHitDataSet->AddObject(pxlRawHitCol);
210  }
211  else
212  {
213  LOG_INFO << " pxlRawHit exists! Append raw hits to this collection! " << endm;
214  pxlRawHitCol= (StPxlRawHitCollection*)pxlRawHitDataSet->GetObject();
215  }
216 
217  if(!pxlRawHitCol)
218  {
219  LOG_ERROR << "Make() - no pxlRawHitCollection."<<endm;
220  return kStErr;
221  }
222  mPxlSimulator->addPxlRawHits(*mcPxlHitCol,*pxlRawHitCol);
223 
224  LOG_INFO << " Finishing DIGMAPS simulator. Number of PxlRawHits = " << pxlRawHitCol->numberOfRawHits() << endm;
225  }
226 
227 
228  return kStOK;
229 }
230 /*
231  **********************************************************
232  * $Log: StPxlSimMaker.cxx,v $
233  * Revision 1.13 2017/10/19 19:38:17 jeromel
234  * Merging PXL201709UPD back to MAIN
235  *
236  * Revision 1.12.6.1 2017/09/11 20:15:14 dongx
237  * Pxl slow simulator added
238  *
239  * Revision 1.12 2016/04/14 23:10:19 smirnovd
240  * Cosmetic changes
241  *
242  * * Make sure we call functions from std library as it was probably intended
243  *
244  * * Removed unnecessary #included dependency
245  * - Nothing in the code seems to come from the stdio.h header
246  *
247  * * End log messages with endm to flush the internal buffer
248  *
249  * Revision 1.11 2016/04/13 19:15:02 mstftsm
250  * The choice of geometry should be mutually exclusive
251  *
252  * streamline inlined methods and define them outside the header
253  *
254  * Use one flag to control geometry source
255  *
256  * Use fundamental C++ types; this is not a persistent class
257  *
258  * Fix a logic bug
259  *
260  * fix bug: missing inline keyword
261  *
262  * The choice of geometry source shoule be mutually exclusive
263  *
264  * Revision 1.10 2015/03/13 18:45:01 perev
265  * Roll back
266  *
267  * Revision 1.8 2014/07/17 01:47:43 mstftsm
268  * Fix a bug in creating a new StPxlHitCollection.
269  * Random seed is set to default.
270  * DB geometry is set to default.
271  *
272  * Revision 1.7 2014/07/10 18:52:09 mstftsm
273  * Check if StPxlHitCollection exists in StEvent and add simulated hits to it. Otherwise, create a new collection.
274  *
275  * Revision 1.6 2014/07/03 19:46:37 mstftsm
276  * Revereted the changes made for the pileup adder. That does not belong to the master branch.
277  *
278  * Revision 1.4 2014/06/25 19:21:57 mstftsm
279  * pxl DB DataSet has been change to pxl_db. Name changed in this code.
280  *
281  * Revision 1.3 2014/03/13 17:00:19 mstftsm
282  * StPxlSimMaker has a method to switch on random seed for StRandom generatos in simulators. Default is not a random seed.
283  *
284  * Revision 1.1 2013/05/12 21:43:33 jeromel
285  * Initial revision, code peer review closed 2013/05/06
286  *
287  * Revision 1.4 2013/05/03 15:08:19 mstftsm
288  *
289  */
290 
virtual Int_t addPxlHits(const StMcPxlHitCollection &in, StPxlHitCollection &out)
this function is to be implemented by algorithms which create PXL hits points.
Definition: StPxlISim.h:30
virtual Int_t Make()
calls the StPxlISim methods.
virtual ~StPxlSimMaker()
StEvent will own any hits created by this maker, and is responsible for cleanup.
maker for all PXL simulators
Definition: StPxlSimMaker.h:73
virtual Int_t addPxlRawHits(const StMcPxlHitCollection &in, StPxlRawHitCollection &out)
this function is to be implemented by algorithms which create raw PXL hits
Definition: StPxlISim.h:33
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t InitRun(Int_t)
gets the DB and initializes StPxlISim for this run.
STAR wrapper for DIGMAPS package.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56
Definition: Stypes.h:44
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169
Definition: Stypes.h:41
virtual Int_t Init()
checks if other simulators have been requested and initializes StPxlISim accordingly.
Int_t numberOfRawHits(Int_t sector, Int_t ladder, Int_t sensor)
number of raw hits in a sensor
Class to simulate PXL hits from Monte Carlo.
Definition: StPxlFastSim.h:56