32 #include "StVpdSimMaker.h"
33 #include "StBTofUtil/StVpdSimConfig.h"
36 #include "SystemOfUnits.h"
37 #include "PhysicalConstants.h"
38 #include "phys_constants.h"
45 #include "tables/St_g2t_vpd_hit_Table.h"
48 #include "RanluxEngine.h"
49 #include "RandGauss.h"
51 #include "StMcEvent/StMcVertex.hh"
52 #include "StEvent/StPrimaryVertex.h"
53 #include "StMcEvent/StMcBTofHit.hh"
54 #include "StEventTypes.h"
55 #include "StEvent/StBTofCollection.h"
56 #include "StChain/StChainOpt.h"
67 mMcBTofHitCollection = 0;
69 mUseFileParameters=kFALSE;
97 return StMaker::Init();
112 int StVpdSimMaker::InitRun(
int runnumber)
114 LOG_DEBUG <<
"StVpdSimMaker::InitRun -- reading configuration file --" << endm;
120 LOG_DEBUG <<
"Vpd Simulation Parameters loaded from file." << endm;
124 LOG_DEBUG <<
"Vpd Simulation Parameters loaded from database." << endm;
131 int StVpdSimMaker::FinishRun(
int runnumber)
154 double tubeTimeWest = 0;
155 double tubeTimeEast = 0;
156 std::vector<VpdSingleHit> hitsWest;
157 std::vector<VpdSingleHit> hitsEast;
159 std::vector<int> tubeCountsWest(19);
160 std::vector<int> tubeCountsEast(19);
168 LOG_WARN <<
" No GEANT data loaded. Exit! " << endm;
171 LOG_INFO <<
" Found GEANT data -- loading Vpd hits... " << endm;
175 LOG_ERROR <<
"No StMcEvent! Bailing out ..." << endm;
177 else if (
mMcEvent->primaryVertex() != NULL){
180 LOG_DEBUG <<
"The simulated vZ is: " << mVz << endm;
183 LOG_WARN <<
"No primary vertex in McEvent! Bailing out ..." << endm;
188 St_g2t_vpd_hit* g2t_vpd_hits = 0;
189 g2t_vpd_hits =
dynamic_cast<St_g2t_vpd_hit*
>(
mGeantData->
Find(
"g2t_vpd_hit"));
191 LOG_WARN <<
" No Vpd hits in GEANT" << endm;
194 int nVpdHits = g2t_vpd_hits->GetNRows();
195 LOG_DEBUG <<
" Found Vpd hits: " << nVpdHits << endm;
196 g2t_vpd_hit_st* vpd_hit = g2t_vpd_hits->begin();
200 LOG_WARN <<
" No Vpd hit!" << endm;
204 for(
int i=0; i<nVpdHits; i++, vpd_hit++) {
205 int vId = vpd_hit->volume_id;
206 int iTray = vId/1000 + 120;
207 int tubeIndex = (vId % 100)-1;
209 if ( (tubeIndex<0) || (tubeIndex>18) ) {
210 LOG_WARN <<
"Invalid Vpd Tube Id!" << endm;
219 if ((iTray == 121) && (
mSimParams[tubeIndex].tubeStatusFlag == 1)) {
220 singleHit.
tof =
mSimConfig->getVpdDistance()*1e9/C_C_LIGHT - mVz*1e9/C_C_LIGHT;
222 tubeCountsWest[singleHit.
tubeId - 1] += 1;
223 hitsWest.push_back(singleHit);
227 else if ((iTray == 122) && (
mSimParams[tubeIndex+19].tubeStatusFlag) == 1) {
228 singleHit.
tof =
mSimConfig->getVpdDistance()*1e9/C_C_LIGHT + mVz*1e9/C_C_LIGHT;
230 tubeCountsEast[singleHit.
tubeId - 1] += 1;
231 hitsEast.push_back(singleHit);
239 for(
unsigned int i = 0; i < tubeCountsWest.size(); i++ ){
243 for(
unsigned int i = 0; i < tubeCountsEast.size(); i++ ){
249 if(hitsWest.size() > 0) {
256 if(hitsEast.size() > 0) {
268 mTStart = ((tubeTimeEast+tubeTimeWest)-(nEast-nWest)*(mVz)/(C_C_LIGHT*1.e9))/(nEast+nWest) -
mSimConfig->getVpdDistance()/(C_C_LIGHT*1.e-9);
269 LOG_DEBUG <<
"The vpdVz is: " <<
mVpdVertex <<
" cm" << endm;
270 LOG_DEBUG <<
"The tStart is " <<
mTStart <<
" ns" << endm;
294 TRandom3& randengine = *((TRandom3 *)gRandom);
296 singleHit.
tray = vId/1000 + 120;
297 singleHit.
tubeId = vId%100;
299 if (singleHit.
tray == 122) {
300 randNum = randengine.Gaus(0,
mSimParams[singleHit.
tubeId-1+19].singleTubeRes);
306 singleHit.
tof += randNum/1000;
307 singleHit.
t0 = vpd_hit->tof*1./nanosecond;
309 singleHit.
de = vpd_hit->de;
310 singleHit.
pathL = -9999;
323 std::vector<double> timesVec;
329 for(
int i = 0; i < (int)tubeCounts.size(); i++) {
331 double lowTime = 1.e+9;
333 if (tubeCounts[i] >=
mSimConfig->getThreshold()) {
334 if (
mBookHisto) { TubeHits->Fill( i + 1, 1 ); }
335 for(
int j = 0; j < (int)singleHitsVec.size(); j++) {
336 if ((i == singleHitsVec[j].tubeId-1) and (singleHitsVec[j].
tof > 1.e-4)) {
337 if (singleHitsVec[j].
tof < lowTime) {
338 lowTime = singleHitsVec[j].tof;
347 StMcBTofHit *mcHit =
new StMcBTofHit(singleHitsVec[dex].tray,0,singleHitsVec[dex].tubeId,singleHitsVec[dex].de,singleHitsVec[dex].pathL,singleHitsVec[dex].t0,singleHitsVec[dex].
tof,singleHitsVec[dex].q);
352 timesVec.push_back(singleHitsVec[dex].tof);
357 if (timesVec.size() != 0) {
358 mNHits = timesVec.size();
379 LOG_DEBUG <<
" No hit stored in mMcBTofHitCollection." << endm;
381 if(mcVpdHit->sameCell(*tempHit)) {
382 LOG_WARN <<
" Multiple hits passed to same cell. Exit! " << endm;
387 LOG_DEBUG <<
" Storing mcVpdHit to Collection." << endm;
399 LOG_DEBUG <<
"Filling McEvent and Event"<<endm;
404 LOG_ERROR <<
"No StMcEvent! Bailing out ..." << endm;
408 LOG_INFO <<
" ... StMcVpdHitCollection stored in StMcEvent" << endm;
413 LOG_ERROR <<
"No StEvent! Bailing out ..." << endm;
416 LOG_DEBUG <<
"mEvent = " <<
mEvent << endm;
419 if (
mMcEvent->primaryVertex() != NULL){
424 LOG_DEBUG <<
" mVx, mVy, vZ: "
427 << mVz <<
" " << endm;
434 LOG_INFO <<
"Creating new StBTofCollection" << endm;
442 if(!aMcVpdHit)
continue;
448 float mcTof = aMcVpdHit->
tof();
450 aVpdHit.setHardwarePosition(kBTofId);
451 aVpdHit.setTray((
int)aMcVpdHit->tray());
452 aVpdHit.setModule((
unsigned char)aMcVpdHit->module());
453 aVpdHit.setCell((
int)aMcVpdHit->cell());
454 aVpdHit.setLeadingEdgeTime((
double)mcTof);
455 aVpdHit.setTrailingEdgeTime((
double)mcTof);
456 aVpdHit.setAssociatedTrack(NULL);
457 aVpdHit.setIdTruth(aMcVpdHit->parentTrackId(), 1);
463 aVpdRawHit.setTray((
int)aMcVpdHit->tray());
464 aVpdRawHit.setChannel(6*(aMcVpdHit->module() - 1) + (
int)aMcVpdHit->cell());
465 aVpdRawHit.setFlag(1);
473 LOG_INFO <<
"... StBTofCollection Stored in StEvent! " << endm;
485 string StVpdSimMaker::pullHistFileName() {
487 string extension =
".VpdSim.root";
489 if (GetChainOpt()->GetFileOut() != NULL) {
490 TString outFile = GetChainOpt()->GetFileOut();
509 AddHist(
mNRawHitsWest =
new TH1F(
"mNRawHitsWest_tubeId",
"mNRawHitsWest vs. tubeId; Tube Number; # of Hits", 21, 0, 21) );
510 AddHist(
mNRawHitsEast =
new TH1F(
"mNRawHitsEast_tubeId",
"mNRawHitsEast vs. tubeId; Tube Number; # of Hits",21, 0, 21) );
512 AddHist(
mTubeHitsWest =
new TH1F(
"mTubeHitsWest_tubeId",
"mTubeHitsWest vs. tubeId (Threshold Cut); Tube Number; # of Hits", 21, 0, 21) );
513 AddHist(
mTubeHitsEast =
new TH1F(
"mTubeHitsEast_tubeId",
"mTubeHitsEast vs. tubeId (Threshold Cut); Tube Number; # of Hits",21, 0, 21) );
515 AddHist(
mNHitsWest =
new TH1F(
"mNHitsWest",
"# Tubes Hit per Event West; # Tubes; Counts", 21, 0, 21) );
516 AddHist(
mNHitsEast =
new TH1F(
"mNHitsEast",
"# Tubes Hit per Event East; # Tubes; Counts",21, 0, 21) );
518 AddHist(
mLeTimeWest =
new TH1F(
"mLeTimeWest",
"Leading Edge Times West (No Cuts); LE (ns); Counts", 300, 0, 30) );
519 AddHist(
mLeTimeEast =
new TH1F(
"mLeTimeEast",
"Leading Edge Times East (No Cuts); LE (ns); Counts", 300, 0, 30) );
520 AddHist(
mTStartHist =
new TH1F(
"mTStart",
"mTStart; Time (ns); Counts", 300, -30, 30) );
522 AddHist(
mLeTubeHitsWest =
new TH2F(
"mLeTubeHitsWest",
" mTubeHitsWest & LE Times (No Cuts); LE (ns); # of Hits; Counts", 300, 0, 30, 25, 0, 25) );
523 AddHist(
mLeTubeHitsEast =
new TH2F(
"mLeTubeHitsEast",
"mTubeHitsEast & LE Times (No Cuts); LE (ns); # of Hits; Counts", 300, 0, 30, 25, 0, 25) );
525 AddHist(
mZVertexHist =
new TH1F(
"mZVertexHist",
"True Vertices; Position (cm); Counts", 300, -50, 50) );
526 AddHist(
mVpdVertexHist =
new TH1F(
"mVpdVertexHist",
"Calculated Vpd Vertices; Position (cm); Counts", 300, -50, 50) );
527 AddHist(
mVpdResHist =
new TH1F(
"mVpdResHist",
"True - Vpd Vertex Position; TruePos - CalcPos (cm); Counts", 300, -15, 15) );
529 AddHist(
mResVsNumHits =
new TH3F(
"mResVsNumHits",
"mResVsNumHits; numTubesWest; numTubesEast; vZ-vpdVz", 21, 0, 21, 21, 0, 21, 300, -10, 10) );
StMcBTofHitCollection * mMcBTofHitCollection
The Mc hit collection.
string mHistoFileName
histogram file name
int tubeId
The tube id of a given Vpd, with values [1,19].
double mTStart
Start time for an event.
TH1F * mZVertexHist
Histogram of the provided Mc Vertices for all events.
StBTofCollection * mVpdCollection
The StBTofCollection of StBTofHit's (in this case, vpd hits)
std::map< int, StVpdSimConfig::SingleTubeParams > mSimParams
Map of the calibration parameters to be applied.
bool mUseFileParameters
Default is kFALSE.
double t0
Time offset (currently unused)
TH1F * mVpdResHist
Histogram of the difference between Mc and calculated vertices.
StVpdSimConfig * mSimConfig
The calibration parameters for Vpd.
VpdSingleHit contains the parameters that describe a vpd hit.
int vpdResponse(VpdSingleHit &Hit, g2t_vpd_hit_st *vpd_hit, int vId)
Extracts relevant parameters from a Vpd hit.
TH3F * mResVsNumHits
Histogram fo the difference between Mc and calculated vertices vs. number of hits.
int tray
The vpd tray (121==West, 122==East)
int fillEvent()
Fill StEvent from the McBTofCollection.
StMcEvent * mMcEvent
The McEvent info.
float mVpdVertex
The calculated vertex as seen by the Vpd.
TH1F * mNRawHitsWest
Number of hits on each west Vpd tube before threshold cuts.
TH1F * mLeTimeEast
Leading edge times (currently equal to Time of Flight) for east Vpd.
TH1F * mTubeHitsWest
Number of hits on each west Vpd tube after threshold cuts.
TH1F * mTStartHist
mTStart times (in ns)
bool mBookHisto
Default is kFALSE.
double q
Charge (currently set to 0 for Vpd hits)
double mTubeTAvgWest
Corrected event time for the west Vpd.
int storeMcVpdHit(StMcBTofHit *mcVpdHit)
Builds the McBTofCollection, insures no duplicate hits.
TH2F * mLeTubeHitsEast
Leading edge times and Number of tubes hit across events for East Vpd.
double mSumTubeTime
Tracks the time measured by each Vpd tube and sums them.
TH2F * mLeTubeHitsWest
Leading edge times and Number of tubes hit across events for West Vpd.
double mTubeTAvgEast
Corrected event time for the east Vpd.
int bookHistograms()
Creat the QA histograms.
double thresholdCut(std::vector< VpdSingleHit > Hits, std::vector< int > Tube_Counts, TH1F *TubeHits, TH1F *NHits)
Determines average time information from East and West Vpd, cuts zero-velocity particles.
double mTubeTAvg
Average time lapse seen by the east or west Vpd.
TH1F * mNHitsEast
Number of tubes hit across events for east Vpd.
StEvent * mEvent
The StEvent info.
TH1F * mNRawHitsEast
Number of hits on each east Vpd tube before threshold cuts.
TH1F * mTubeHitsEast
Number of hits on each east Vpd tube after threshold cuts.
TH1F * mLeTimeWest
Leading edge times (currently equal to Time of Flight) for west Vpd.
St_DataSet * mGeantData
Geant data passed into the StVpdSimMaker.
TH1F * mNHitsWest
Number of tubes hit across events for west Vpd.
double de
Energy deposition in GeV.
virtual float tof() const
time of flight geant
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
void loadVpdSimParams(const int date=20160913, const int time=175725, const char *Default_time="2016-09-13 17:57:25")
Loads Vpd Sim Params from database.
TH1F * mVpdVertexHist
Histogram of the calculated Vpd vertices for all events.
double tof
Time of flight given in ns.
virtual TDataSet * Find(const char *path) const
double pathL
Path length in cm (currently set to -9999)