20 #include "StEventTypes.h"
22 #include "StThreeVectorF.hh"
23 #include "StMeasuredPoint.h"
24 #include "StDedxPidTraits.h"
25 #include "StTrackPidTraits.h"
26 #include "StarClassLibrary/StParticleTypes.hh"
27 #include "StarClassLibrary/StParticleDefinition.hh"
28 #include "StMuDSTMaker/COMMON/StMuUtilities.h"
29 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
31 #include "StTrackGeometry.h"
32 #include "StParticleTypes.hh"
33 #include "StTpcDedxPidAlgorithm.h"
35 #include "StAssociationMaker/StTrackPairInfo.hh"
36 #include "StEventUtilities/StuRefMult.hh"
37 #include "PhysicalConstants.h"
38 #include "StPhysicalHelixD.hh"
41 #include "StMemoryInfo.hh"
42 #include "StMessMgr.h"
44 #include "tables/St_pvpdStrobeDef_Table.h"
45 #include "tables/St_g2t_vertex_Table.h"
46 #include "tables/St_vertexSeed_Table.h"
48 #include "StTofUtil/tofPathLength.hh"
49 #include "StTofUtil/StTofrGeometry.h"
50 #include "StTofUtil/StTofrDaqMap.h"
51 #include "StTofUtil/StTofCellCollection.h"
52 #include "StTofUtil/StTofHitCollection.h"
53 #include "StTofrNtupleMaker.h"
60 mTupleFileName=outname;
62 doPrintMemoryInfo = kFALSE;
63 doPrintCpuInfo = kFALSE;
84 Int_t StTofrNtupleMaker::InitRun(
int runnumber) {
86 if(mInitGeomFromOther) {
87 TDataSet *geom = GetDataSet(
"tofrGeometry");
90 mTofrGeom =
new StTofrGeometry(
"tofrGeoNtuple",
"tofGeo in NtupleMaker");
91 if(!mTofrGeom->IsInitDone()) {
92 gMessMgr->Info(
"TofrGemetry initialization..." ,
"OS");
94 mTofrGeom->Init(starHall);
98 gMessMgr->Info(
" -- retrieving run parameters from Calibrations_tof",
"OS");
99 TDataSet *mDbDataSet = GetDataBase(
"Calibrations/tof/pvpdStrobeDef");
101 gMessMgr->Error(
"unable to get TOF run parameters",
"OS");
104 St_pvpdStrobeDef* pvpdStrobeDef =
static_cast<St_pvpdStrobeDef*
>(mDbDataSet->
Find(
"pvpdStrobeDef"));
106 gMessMgr->Error(
"unable to find TOF run param table",
"OS");
107 assert(pvpdStrobeDef);
109 pvpdStrobeDef_st *strobeDef =
static_cast<pvpdStrobeDef_st*
>(pvpdStrobeDef->GetArray());
110 int numRows = pvpdStrobeDef->GetNRows();
111 if (mNPVPD != numRows) gMessMgr->Warning(
"#tubes inconsistency in dbase");
112 for (
int i=0;i<mNPVPD;i++){
113 int ii = strobeDef[i].id - 1;
114 mStrobeTdcMin[ii] = strobeDef[i].strobeTdcMin;
115 mStrobeTdcMax[ii] = strobeDef[i].strobeTdcMax;
117 LOG_INFO <<
"tube " << strobeDef[i].id <<
" min:"<< strobeDef[i].strobeTdcMin
118 <<
" max:"<< strobeDef[i].strobeTdcMax<< endm;
142 LOG_INFO<<
" beamline is set by hand "<<endl;
144 LOG_INFO <<
"BeamLine Constraint: " << endm;
145 LOG_INFO <<
"x(z) = " << x0 <<
" + " << dxdz <<
" * z" << endm;
146 LOG_INFO <<
"y(z) = " << y0 <<
" + " << dydz <<
" * z" << endm;
153 double pt = 88889999;
154 double nxy=::sqrt(dxdz*dxdz + dydz*dydz);
156 LOG_WARN <<
"StppLMVVertexFinder:: Beam line must be tilted!" << endm;
173 Int_t StTofrNtupleMaker::FinishRun(
int runnumber)
175 if(!mInitGeomFromOther) {
176 if(mTofrGeom)
delete mTofrGeom;
188 if (!(mTupleFileName==
"")){
191 LOG_INFO <<
"StTofrNtupleMaker::Finish() ntuple file "
192 << mTupleFileName <<
" closed." << endm;
199 LOG_INFO <<
"StTofrNtupleMaker -- statistics" << endm;
200 LOG_INFO <<
" accepted events : " << mAcceptedEvents << endm;
201 LOG_INFO <<
" pVPD entries : " << mPvpdEntries << endm;
202 LOG_INFO <<
" Tofr entries/events : " << mTofrEntries <<
"/" << mTofrEvents << endm;
210 LOG_INFO <<
"StTofrNtupleMaker -- welcome" << endm;
218 !event->tofCollection() ||
220 !
event->tofCollection()->rawdataPresent()){
221 LOG_INFO <<
"StTofrNtupleMaker -- nothing to do ... bye-bye"<< endm;
227 if (doPrintCpuInfo) timer.start();
228 if (doPrintMemoryInfo) StMemoryInfo::instance()->snapshot();
231 mYear2= (
event->runId()<4000000);
232 mYear3= (
event->runId()>4000000&&
event->runId()<5000000);
233 mYear4= (
event->runId()>5000000);
240 cout<<
"runId: "<<
event->runId()<<
" runnumber"<<
event->id()<<endl;
249 unsigned int triggerWord = 0;
250 if (pTrigger) triggerWord = pTrigger->triggerWord();
253 mCellData.run =
event->runId();
254 mCellData.evt =
event->id();
255 mCellData.trgword = triggerWord;
256 mCellData.vertexX = xvtx;
257 mCellData.vertexY = yvtx;
258 mCellData.vertexZ = zvtx;
261 LOG_INFO <<
" vertexZ: "<<mCellData.vertexZ<<endm;
267 if (event->tofCollection()->cellsPresent()){
270 int entriesThisEvent(0);
273 for(
int i=0;i<19;i++){
274 mCellData.pvpdLeadingEdgeTimeEast[i] = 0;
275 mCellData.pvpdTotEast[i] = 0;
276 mCellData.pvpdLeadingEdgeTimeWest[i] = 0;
277 mCellData.pvpdTotWest[i] = 0;
281 StSPtrVecTofCell& cellTofVec = theTof->tofCells();
283 float tdcsumeast = 0., tdcsumwest = 0.;
284 unsigned int vpdEast=0, vpdWest=0, nVpdEast=0, nVpdWest=0;
285 for (
size_t i = 0; i < cellTofVec.size(); i++) {
287 int trayId = thisCell->trayIndex();
288 if(Debug()) LOG_INFO <<
" tray ID: "<< trayId<<endm;
290 int tubeId = thisCell->cellIndex()-1;
291 vpdEast += 1<<tubeId;
294 mCellData.pvpdLeadingEdgeTimeEast[tubeId] = thisCell->leadingEdgeTime();
295 mCellData.pvpdTotEast[tubeId] = thisCell->tot();
296 cout<<
" tray/tube "<< trayId<<
"/"<<tubeId<<
" letime/tot "<< thisCell->leadingEdgeTime()<<
"/"<< thisCell->tot()<<endl;
297 tdcsumeast += thisCell->leadingEdgeTime();
299 }
else if(trayId==121){
300 int tubeId = thisCell->cellIndex()-1;
301 vpdWest += 1<<tubeId;
303 mCellData.pvpdLeadingEdgeTimeWest[tubeId] = thisCell->leadingEdgeTime();
304 mCellData.pvpdTotWest[tubeId] = thisCell->tot();
306 tdcsumwest += thisCell->leadingEdgeTime();
308 }
else if(trayId<=120&&trayId>=0){
310 mCellData.tray[ntofhits] = trayId;
311 mCellData.module[ntofhits] = thisCell->moduleIndex();
312 mCellData.cell[ntofhits] = thisCell->cellIndex();
313 mCellData.daq[ntofhits] = thisCell->daqIndex();
314 mCellData.leadingEdgeTime[ntofhits] = thisCell->leadingEdgeTime();
316 mCellData.tot[ntofhits] = thisCell->tot();
322 if(Debug()) LOG_INFO <<
" trayID/moduleID/cellID/leadingEdgeTime/tot"<< trayId <<
"/"<< mCellData.module[ntofhits]<<
"/"<< mCellData.cell[ntofhits] <<
"/" << mCellData.leadingEdgeTime[ntofhits] <<
"/"<< mCellData.tot[ntofhits]<<
"/"<<endm;
325 StTofrGeomSensor* sensor = mTofrGeom->GetGeomSensor(thisCell->moduleIndex(), thisCell->trayIndex());
326 double local[3], globalp[3];
327 globalp[0] = globalHit.x();
328 globalp[1] = globalHit.y();
329 globalp[2] = globalHit.z();
330 sensor->Master2Local(&globalp[0], &local[0]);
332 float ycenter = (thisCell->cellIndex()-1)*3.45-8.625;
335 cout<<
"zHit local = "<<local[2]<<
" "<< thisCell->zHit()<<endl;
336 mCellData.xlocal[ntofhits] = (Float_t) localHit.x();
337 mCellData.ylocal[ntofhits] = (Float_t) localHit.y();
338 mCellData.zlocal[ntofhits] = (Float_t) localHit.z();
339 mCellData.deltay[ntofhits] = local[1] - ycenter;
342 LOG_INFO <<
" global:("<<globalp[0]<<
", "<<globalp[1]<<
", "<<globalp[2]<<
")"
343 <<
"\n \t local:("<<localHit.x()<<
", "<<localHit.y()<<
", "<<localHit.z()<<
")"<<endm;
347 StTrack *thisTrack = thisCell->associatedTrack();
353 float dedx(0.), cherang(0), dedxerror(0);
354 int dedx_np(0), cherang_nph(0);
355 StSPtrVecTrackPidTraits& traits = thisTrack->pidTraits();
356 for (
unsigned int it=0;it<traits.size();it++){
357 if (traits[it]->detector() == kTpcId){
359 if (pid && pid->method() ==kTruncatedMeanId){
360 dedx = pid->mean()*1e6;
361 dedx_np = pid->numberOfPoints();
362 dedxerror = pid->errorOnMean()*1e6;
364 }
else if (traits[it]->detector() == kRichId){
368 if (pidinfo && pidinfo->getCherenkovPhotons()>2){
369 cherang = pidinfo->getCherenkovAngle();
370 cherang_nph = pidinfo->getCherenkovPhotons();
379 float mNSigmaElectron(0.);
380 float mNSigmaPion(0.);
381 float mNSigmaKaon(0.);
382 float mNSigmaProton(0.);
385 static StElectron* Electron = StElectron::instance();
386 static StPionPlus* Pion = StPionPlus::instance();
387 static StKaonPlus* Kaon = StKaonPlus::instance();
388 static StProton* Proton = StProton::instance();
392 mNSigmaElectron = fabsMin(PidAlgorithm.numberOfSigma(Electron), __SIGMA_SCALE__);
393 mNSigmaPion = pack2Int( fabsMin(PidAlgorithm.numberOfSigma(Pion),__SIGMA_SCALE__), __SIGMA_SCALE__ );
394 mNSigmaKaon = pack2Int( fabsMin(PidAlgorithm.numberOfSigma(Kaon),__SIGMA_SCALE__), __SIGMA_SCALE__ );
395 mNSigmaProton = pack2Int( fabsMin(PidAlgorithm.numberOfSigma(Proton),__SIGMA_SCALE__), __SIGMA_SCALE__ );
398 double pathLength = -999.;
402 pathLength = tofPathLength(&tofPos, &thisCell->position(), theTrackGeometry->helix().curvature());
403 if(Debug()) LOG_INFO <<
"dca(x,y,z) = (" << dcatof.x() <<
", " << dcatof.y()
404 <<
", " << dcatof.z() <<
"), tof pathLength = " << pathLength<<endm;
405 mCellData.trackId[ntofhits] = (Int_t)thisTrack->key();
406 mCellData.charge[ntofhits] = theTrackGeometry->charge();
407 if(thisTrack->detectorInfo()) {
408 mCellData.nHits[ntofhits] = thisTrack->detectorInfo()->numberOfPoints(kTpcId);
410 mCellData.nHits[ntofhits] = 0;
412 mCellData.nHitsFit[ntofhits] = thisTrack->fitTraits().numberOfFitPoints(kTpcId);
413 mCellData.dcaX[ntofhits] = dcatof.x();
414 mCellData.dcaY[ntofhits] = dcatof.y();
415 mCellData.dcaZ[ntofhits] = tofPos.z();
417 mCellData.length[ntofhits] = (float)fabs(pathLength);
418 mCellData.p[ntofhits] = momentum.mag();
419 mCellData.pt[ntofhits] = momentum.perp();
420 mCellData.px[ntofhits] = momentum.x();
421 mCellData.py[ntofhits] = momentum.y();
422 mCellData.pz[ntofhits] = momentum.z();
423 mCellData.eta[ntofhits] = momentum.pseudoRapidity();
424 mCellData.dedx[ntofhits] = dedx;
425 mCellData.dedxError[ntofhits] = dedxerror;
426 mCellData.nHitsDedx[ntofhits] = dedx_np;
427 mCellData.cherenkovAngle[ntofhits] = cherang;
428 mCellData.cherenkovPhotons[ntofhits] = cherang_nph;
429 mCellData.nSigE[ntofhits] = mNSigmaElectron;
430 mCellData.nSigPi[ntofhits] = mNSigmaPion;
431 mCellData.nSigK[ntofhits] = mNSigmaKaon;
432 mCellData.nSigP[ntofhits] = mNSigmaProton;
435 mCellData.tofcorr[ntofhits] = -999.;
436 mCellData.beta[ntofhits] = -999.;
437 StSPtrVecTofHit& hitTofVec = theTof->tofHits();
438 for(
size_t ih=0;ih<hitTofVec.size();ih++) {
441 if(aHit->trayIndex() == thisCell->trayIndex() &&
442 aHit->moduleIndex() == thisCell->moduleIndex() &&
443 aHit->cellIndex() == thisCell->cellIndex()) {
444 mCellData.tofcorr[ntofhits] = aHit->timeOfFlight();
445 mCellData.beta[ntofhits] = aHit->beta();
453 mCellData.vpdEast = vpdEast;
454 mCellData.vpdWest = vpdWest;
455 mCellData.numberOfVpdEast = nVpdEast;
456 mCellData.numberOfVpdWest = nVpdWest;
457 mCellData.tDiff = theTof->tdiff();
458 mCellData.nTofHits = ntofhits;
461 mTofrEntries = ntofhits;
462 entriesThisEvent = ntofhits;
465 LOG_INFO <<
" #vpd East: "<<mCellData.numberOfVpdEast
466 <<
"\n \t #vpd West: "<<mCellData.numberOfVpdWest<<endm;
468 LOG_INFO <<
" Tofr update: " << entriesThisEvent <<
" entries" <<endm;
473 if (doPrintMemoryInfo) {
474 StMemoryInfo::instance()->snapshot();
475 StMemoryInfo::instance()->print();
477 if (doPrintCpuInfo) {
479 LOG_INFO <<
"CPU time for StEventMaker::Make(): "
480 << timer.elapsedTime() <<
" sec\n" << endm;
483 LOG_INFO <<
"StTofrNtupleMaker -- bye-bye" << endm;
491 mTupleFile =
new TFile(mTupleFileName.c_str(),
"RECREATE");
492 LOG_INFO <<
"StTofrNtupleMaker::bookNtuples() file "
493 << mTupleFileName <<
" opened" << endm;
496 mPvpdTuple =
new TTree(
"pvpd",
"tofr timing");
497 mPvpdTuple->SetAutoSave(1000);
498 mPvpdTuple->Branch(
"run",&mCellData.run,
"run/I");
499 mPvpdTuple->Branch(
"evt",&mCellData.evt,
"evt/I");
500 mPvpdTuple->Branch(
"trgword",&mCellData.trgword,
"trgword/I");
501 mPvpdTuple->Branch(
"vertexX",&mCellData.vertexX,
"vertexX/F");
502 mPvpdTuple->Branch(
"vertexY",&mCellData.vertexY,
"vertexY/F");
503 mPvpdTuple->Branch(
"vertexZ",&mCellData.vertexZ,
"vertexZ/F");
504 mPvpdTuple->Branch(
"vpdEast",&mCellData.vpdEast,
"vpdEast/I");
505 mPvpdTuple->Branch(
"vpdWest",&mCellData.vpdWest,
"vpdWest/I");
506 mPvpdTuple->Branch(
"numberOfVpdEast",&mCellData.numberOfVpdEast,
"numberOfVpdEast/I");
507 mPvpdTuple->Branch(
"numberOfVpdWest",&mCellData.numberOfVpdWest,
"numberOfVpdWest/I");
508 mPvpdTuple->Branch(
"tDiff",&mCellData.tDiff,
"tDiff/F");
509 mPvpdTuple->Branch(
"pvpdLeadingEdgeTimeEast",&mCellData.pvpdLeadingEdgeTimeEast,
"pvpdLeadingEdgeTimeEast[19]/D");
510 mPvpdTuple->Branch(
"pvpdLeadingEdgeTimeWest",&mCellData.pvpdLeadingEdgeTimeWest,
"pvpdLeadingEdgeTimeWest[19]/D");
511 mPvpdTuple->Branch(
"pvpdTotEast",&mCellData.pvpdTotEast,
"pvpdTotEast[19]/D");
512 mPvpdTuple->Branch(
"pvpdTotWest",&mCellData.pvpdTotWest,
"pvpdTotWest[19]/D");
515 mCellTuple =
new TTree(
"tofr",
"Tofr cell data");
516 mCellTuple->SetAutoSave(1000);
517 mCellTuple->Branch(
"run",&mCellData.run,
"run/I");
518 mCellTuple->Branch(
"evt",&mCellData.evt,
"evt/I");
519 mCellTuple->Branch(
"trgword",&mCellData.trgword,
"trgword/I");
520 mCellTuple->Branch(
"vertexX",&mCellData.vertexX,
"vertexX/F");
521 mCellTuple->Branch(
"vertexY",&mCellData.vertexY,
"vertexY/F");
522 mCellTuple->Branch(
"vertexZ",&mCellData.vertexZ,
"vertexZ/F");
523 mCellTuple->Branch(
"vpdEast",&mCellData.vpdEast,
"vpdEast/I");
524 mCellTuple->Branch(
"vpdWest",&mCellData.vpdWest,
"vpdWest/I");
525 mCellTuple->Branch(
"numberOfVpdEast",&mCellData.numberOfVpdEast,
"numberOfVpdEast/I");
526 mCellTuple->Branch(
"numberOfVpdWest",&mCellData.numberOfVpdWest,
"numberOfVpdWest/I");
527 mCellTuple->Branch(
"tDiff",&mCellData.tDiff,
"tDiff/F");
528 mCellTuple->Branch(
"pvpdLeadingEdgeTimeEast",&mCellData.pvpdLeadingEdgeTimeEast,
"pvpdLeadingEdgeTimeEast[19]/D");
529 mCellTuple->Branch(
"pvpdLeadingEdgeTimeWest",&mCellData.pvpdLeadingEdgeTimeWest,
"pvpdLeadingEdgeTimeWest[19]/D");
530 mCellTuple->Branch(
"pvpdTotEast",&mCellData.pvpdTotEast,
"pvpdTotEast[19]/D");
531 mCellTuple->Branch(
"pvpdTotWest",&mCellData.pvpdTotWest,
"pvpdTotWest[19]/D");
532 mCellTuple->Branch(
"nTofHits",&mCellData.nTofHits,
"nTofHits/I");
533 mCellTuple->Branch(
"tray",&mCellData.tray,
"tray[nTofHits]/I");
534 mCellTuple->Branch(
"module",&mCellData.module,
"module[nTofHits]/I");
535 mCellTuple->Branch(
"cell",&mCellData.cell,
"cell[nTofHits]/I");
536 mCellTuple->Branch(
"daq",&mCellData.daq,
"daq[nTofHits]/I");
537 mCellTuple->Branch(
"leadingEdgeTime",&mCellData.leadingEdgeTime,
"leadingEdgeTime[nTofHits]/D");
538 mCellTuple->Branch(
"tot",&mCellData.tot,
"tot[nTofHits]/D");
540 mCellTuple->Branch(
"xlocal",&mCellData.xlocal,
"xlocal[nTofHits]/F");
541 mCellTuple->Branch(
"ylocal",&mCellData.ylocal,
"ylocal[nTofHits]/F");
542 mCellTuple->Branch(
"zlocal",&mCellData.zlocal,
"zlocal[nTofHits]/F");
543 mCellTuple->Branch(
"deltay",&mCellData.deltay,
"deltay[nTofHits]/F");
544 mCellTuple->Branch(
"trackId",&mCellData.trackId,
"trackId[nTofHits]/I");
545 mCellTuple->Branch(
"charge",&mCellData.charge,
"charge[nTofHits]/I");
546 mCellTuple->Branch(
"p",&mCellData.p,
"p[nTofHits]/F");
547 mCellTuple->Branch(
"pt",&mCellData.pt,
"pt[nTofHits]/F");
548 mCellTuple->Branch(
"px",&mCellData.px,
"px[nTofHits]/F");
549 mCellTuple->Branch(
"py",&mCellData.py,
"py[nTofHits]/F");
550 mCellTuple->Branch(
"pz",&mCellData.pz,
"pz[nTofHits]/F");
551 mCellTuple->Branch(
"eta",&mCellData.eta,
"eta[nTofHits]/F");
552 mCellTuple->Branch(
"dcaX",&mCellData.dcaX,
"dcaX[nTofHits]/F");
553 mCellTuple->Branch(
"dcaY",&mCellData.dcaY,
"dcaY[nTofHits]/F");
554 mCellTuple->Branch(
"dcaZ",&mCellData.dcaZ,
"dcaZ[nTofHits]/F");
555 mCellTuple->Branch(
"length",&mCellData.length,
"length[nTofHits]/F");
556 mCellTuple->Branch(
"nHits",&mCellData.nHits,
"nHits[nTofHits]/I");
557 mCellTuple->Branch(
"nHitsFit",&mCellData.nHitsFit,
"nHitsFit[nTofHits]/I");
558 mCellTuple->Branch(
"nHitsDedx",&mCellData.nHitsDedx,
"nHitsDedx[nTofHits]/I");
559 mCellTuple->Branch(
"dedx",&mCellData.dedx,
"dedx[nTofHits]/F");
560 mCellTuple->Branch(
"dedxError",&mCellData.dedxError,
"dedxError[nTofHits]/F");
561 mCellTuple->Branch(
"cherenkovAngle",&mCellData.cherenkovAngle,
"cherenkovAngle[nTofHits]/F");
562 mCellTuple->Branch(
"cherenkovPhotons",&mCellData.cherenkovPhotons,
"cherenkovPhotons[nTofHits]/I");
563 mCellTuple->Branch(
"nSigE",&mCellData.nSigE,
"nSigE[nTofHits]/F");
564 mCellTuple->Branch(
"nSigPi",&mCellData.nSigPi,
"nSigPi[nTofHits]/F");
565 mCellTuple->Branch(
"nSigK",&mCellData.nSigK,
"nSigK[nTofHits]/F");
566 mCellTuple->Branch(
"nSigP",&mCellData.nSigP,
"nSigP[nTofHits]/F");
567 mCellTuple->Branch(
"tofcorr",&mCellData.tofcorr,
"tofcorr[nTofHits]/F");
568 mCellTuple->Branch(
"beta",&mCellData.beta,
"beta[nTofHits]/F");
StTofrNtupleMaker(const Char_t *name, const Char_t *outname)
constructor sets default parameters
Int_t Finish()
write and close the ntuple file
pair< double, double > pathLengths(const StHelix &, double minStepSize=10 *micrometer, double minRange=10 *centimeter) const
path lengths at dca between two helices
Int_t Make()
get tofr slat, pvpd rawdata and global data from StEvent and store in flat TTrees (ntuples) ...
Int_t Init()
initialize ntuple and daqmap, and reset counters
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
~StTofrNtupleMaker()
default empty destructor
void bookNtuples()
create and initialize ntuple and TTrees
virtual TDataSet * Find(const char *path) const