35 #include "StHiMicroMaker.h"
40 #include "StHighptPool/StHiMicroEvent/StHiMicroEvent.h"
43 #include "StIOMaker/StIOMaker.h"
44 #include "StThreeVectorF.hh"
45 #include "StThreeVectorD.hh"
46 #include "StEventTypes.h"
47 #include "StMessMgr.h"
48 #include "SystemOfUnits.h"
49 #include "StTpcDedxPidAlgorithm.h"
50 #include "StuProbabilityPidAlgorithm.h"
51 #include "StPhysicalHelixD.hh"
52 #include "StuRefMult.hh"
53 #define PR(x) cout << "##### StHiMicroMaker: " << (#x) << " = " << (x) << endl;
58 return p1->position().perp()<p2->position().perp();
65 StHiMicroMaker::StHiMicroMaker(
const Char_t *makerName)
66 :
StMaker(makerName), mNEvent(0), mNAcceptedEvent(0),
68 mVertexZCut(200), mHitLoop(0)
75 StHiMicroMaker::~StHiMicroMaker()
84 Int_t StHiMicroMaker::InitRun(
int runID) {
85 if (mDebug) gMessMgr->Info() <<
"StHiMicroMaker: InitRun()" << endm;
90 if(mIOMaker) mInFileName = strrchr(mIOMaker->GetFile(),
'/')+1;
92 if(mDebug) cout <<
"##Creating StHiMicroEvent..." << endl;
95 Int_t stat = openFile();
97 return stat + StMaker::Init();
103 StHiMicroMaker::Init()
106 cout <<
"###StHiMicroMaker::Init():\n";
108 const char* set = (mDebug) ?
"ON" :
"OFF";
109 cout <<
"\tDebug is " << set << endl;
113 if(mSaveAllEvents) { cout <<
"\t<I> Saving event info for events without a primary vertex!!" << endl; }
115 return StMaker::Init();
136 cout <<
"###StHiMicroMaker::Finish()\n";
137 cout <<
"\tTotal " << mNEvent <<
" events." << endl;
138 cout <<
"\tProcessed " << mNAcceptedEvent <<
" events." << endl;
139 cout <<
"\tTracks : " << mNAcceptedTrack << endl << endl;
158 if(mIOMaker) curFileName = strrchr(mIOMaker->GetFile(),
'/')+1;
159 if(mInFileName!=curFileName){
161 cout <<
"##New file found : " << curFileName << endl;
162 cout <<
"##Replacing " << mInFileName << endl;
165 mInFileName = curFileName;
173 event = (
StEvent *) GetInputDS(
"StEvent");
175 if (!event)
return kStOK;
210 mHiMicroEvent->Clear();
216 StHiMicroMaker::fillEvent(
StEvent* stEvent)
221 if (stEvent->primaryVertex()) {
222 mHiMicroEvent->SetVertexZ(stEvent->primaryVertex()->position().z());
223 mHiMicroEvent->SetVertexX(stEvent->primaryVertex()->position().x());
224 mHiMicroEvent->SetVertexY(stEvent->primaryVertex()->position().y());
225 mHiMicroEvent->SetOriginMult(stEvent->primaryVertex()->numberOfDaughters());
227 mHiMicroEvent->SetVertexZ(999.);
228 mHiMicroEvent->SetVertexX(999.);
229 mHiMicroEvent->SetVertexY(999.);
230 mHiMicroEvent->SetOriginMult(0);
234 if(stEvent->runInfo()){
235 mHiMicroEvent->SetCenterOfMassEnergy(stEvent->runInfo()->centerOfMassEnergy());
236 mHiMicroEvent->SetMagneticField(stEvent->runInfo()->magneticField());
237 mHiMicroEvent->SetBeamMassNumberEast(stEvent->runInfo()->beamMassNumber(east));
238 mHiMicroEvent->SetBeamMassNumberWest(stEvent->runInfo()->beamMassNumber(west));
241 gMessMgr->Info() <<
"StHiMicroMaker: no Run Info, reverting to year 1 settings "
243 mHiMicroEvent->SetCenterOfMassEnergy(130);
244 mHiMicroEvent->SetMagneticField(4.98);
245 mHiMicroEvent->SetBeamMassNumberEast(197);
246 mHiMicroEvent->SetBeamMassNumberWest(197);
249 mHiMicroEvent->SetNUncorrectedNegativePrimaries(uncorrectedNumberOfNegativePrimaries(*stEvent));
250 mHiMicroEvent->SetNUncorrectedPrimaries(uncorrectedNumberOfPrimaries(*stEvent));
254 mHiMicroEvent->SetCentMult(mHiMicroEvent->NUncorrectedPrimaries());
255 mHiMicroEvent->SetCentrality(mHiMicroEvent->NUncorrectedPrimaries());
257 mHiMicroEvent->SetRunId((Int_t) stEvent->runId());
258 mHiMicroEvent->SetEventId((Int_t) stEvent->id());
264 StSPtrVecTrackNode& theNodes = stEvent->trackNodes();
265 long allcnt = 0;
long goodcnt = 0;
long goodFlagcnt = 0;
266 long goodAcnt = 0;
long goodBcnt = 0;
long goodCcnt = 0;
267 long goodDcnt = 0;
long goodEcnt = 0;
269 for (
unsigned int i=0; i<theNodes.size(); i++) {
270 allcnt += theNodes[i]->entries(global);
271 track = theNodes[i]->track(global);
273 if (goodGlobal(track)) goodcnt++;
274 if (goodGlobalA(track)) goodAcnt++;
275 if (goodGlobalB(track)) goodBcnt++;
276 if (goodGlobalC(track)) goodCcnt++;
277 if (goodGlobalD(track)) goodDcnt++;
278 if (goodGlobalE(track)) goodEcnt++;
279 if (goodGlobalFlag(track)) goodFlagcnt++;
281 mHiMicroEvent->SetNAllGlobals(allcnt);
282 mHiMicroEvent->SetNGoodGlobals(goodcnt);
283 mHiMicroEvent->SetNFlagGlobals(goodFlagcnt);
284 mHiMicroEvent->SetNGoodGlobalsA(goodAcnt);
285 mHiMicroEvent->SetNGoodGlobalsB(goodBcnt);
286 mHiMicroEvent->SetNGoodGlobalsC(goodCcnt);
287 mHiMicroEvent->SetNGoodGlobalsD(goodDcnt);
288 mHiMicroEvent->SetNGoodGlobalsE(goodEcnt);
293 mHiMicroEvent->SetL0TriggerWord(pTrigger->triggerWord());
297 mHiMicroEvent->SetL3UnbiasedTrigger(pL3Trigger->l3EventSummary()->unbiasedTrigger());
298 mHiMicroEvent->SetL3RichTrigger(
false);
301 const StPtrVecL3AlgorithmInfo& algoInfo = pL3Trigger->l3EventSummary()->algorithmsAcceptingEvent();
302 for (UInt_t i = 0; i < algoInfo.size(); i++) {
303 if(algoInfo[i]->
id() == 4) mHiMicroEvent->SetL3RichTrigger(
true);
309 Float_t ctb = -1., zdce = -1, zdcw = -1, zdcVertexZ = 999.;
312 = stEvent->triggerDetectorCollection();
317 for (UInt_t slat=0; slat<CTB.numberOfSlats(); slat++) {
318 for (UInt_t tray=0; tray<CTB.numberOfTrays();tray++) {
319 ctb += CTB.mips(tray,slat,0);
323 zdce = ZDC.adcSum(east);
324 zdcw = ZDC.adcSum(west);
325 zdcVertexZ = ZDC.vertexZ();
328 mHiMicroEvent->SetCTB(ctb);
329 mHiMicroEvent->SetZDCe(zdce);
330 mHiMicroEvent->SetZDCw(zdcw);
331 mHiMicroEvent->SetZDCVertexZ(zdcVertexZ);
333 cout <<
"###StHiMicroMaker::fillEvent" << endl;
334 cout <<
"\tvertex z : " << mHiMicroEvent->VertexZ() << endl;
335 cout <<
"\tZDC vertex z : " << mHiMicroEvent->ZDCVertexZ() << endl;
336 cout <<
"\tmultiplicity : " << mHiMicroEvent->OriginMult() << endl;
337 cout <<
"\tuncorrected h- : " << mHiMicroEvent->NUncorrectedNegativePrimaries() << endl;
338 cout <<
"\tuncorrected Nch : " << mHiMicroEvent->NUncorrectedPrimaries() << endl;
339 cout <<
"\tNch centrality : " << mHiMicroEvent->Centrality() << endl;
344 StHiMicroMaker::fillTracks(
StEvent* stEvent)
350 Int_t nGoodTrackEta(0);
371 StSPtrVecPrimaryTrack& prTracks = stEvent->primaryVertex(0)->daughters();
373 for(UInt_t i=0; i<prTracks.size(); i++){
376 cout <<
"No primary?" << endl;
383 dynamic_cast<StGlobalTrack*
>(prTracks[i]->node()->track(global));
385 cout <<
"Error! no global information?" << endl;
392 if(acceptCentrality(prTrack)) nGoodTrackEta++;
397 if(!accept(glTrack) && !accept(prTrack))
continue;
401 cout <<
"Accepted track" << endl;
402 dump(prTrack,glTrack);
408 const StPtrVecHit& hhits = glTrack->detectorInfo()->hits(kTpcId);
409 Float_t firstZ(0),lastZ(0);
410 Short_t innerPadList(0);
411 Int_t firstPadrow(0), lastPadrow(0), outerPadList(0);
412 UInt_t firstSector(0), lastSector(0);
413 Double_t crossAngle(999);
415 vector<StTpcHit*> vec;
418 for(UInt_t i=0; i<hhits.size(); i++){
424 sort(vec.begin(),vec.end(),sortCmp);
426 firstZ=vec[0]->position().z(); lastZ=vec[vec.size()-1]->position().z();
427 firstPadrow=vec[0]->padrow(); lastPadrow=vec[vec.size()-1]->padrow();
435 for (UInt_t i=0; i < vec.size(); i++) {
437 Int_t val = vec[i]->padrow();
440 inner = inner | SET_ON;
442 SET_ON = (1 << (val-14));
443 outer = outer | SET_ON;
445 innerPadList=inner; outerPadList=outer;
447 firstSector=vec[0]->sector(); lastSector=vec[vec.size()-1]->sector();
452 cout <<
"\tno hits" << endl;
467 hiMicroTrack->SetCurvPr(prTrack->geometry()->curvature());
468 hiMicroTrack->SetCurvGl(glTrack->geometry()->curvature());
469 hiMicroTrack->SetPtPr(prMom.perp());
470 hiMicroTrack->SetEtaPr(prMom.pseudoRapidity());
471 hiMicroTrack->SetPhiPr(prMom.phi());
472 hiMicroTrack->SetDipAnglePr(prTrack->geometry()->dipAngle());
474 hiMicroTrack->SetPtGl(glMom.perp());
475 hiMicroTrack->SetEtaGl(glMom.pseudoRapidity());
476 hiMicroTrack->SetPhiGl(glMom.phi());
477 hiMicroTrack->SetDipAngleGl(glTrack->geometry()->dipAngle());
482 Float_t dcaXYGl = computeXY(stEvent->primaryVertex()->position(),
485 Float_t dcaXYPr = computeXY(stEvent->primaryVertex()->position(),
488 hiMicroTrack->SetDcaGl(glHelix.
distance(stEvent->primaryVertex(0)->position()));
489 hiMicroTrack->SetDcaPr(prHelix.
distance(stEvent->primaryVertex(0)->position()));
491 hiMicroTrack->SetDcaXYGl(dcaXYGl);
492 hiMicroTrack->SetDcaXYPr(dcaXYPr);
494 hiMicroTrack->SetDcaZGl(dcaz(glHelix,
495 stEvent->primaryVertex()->position(),glTrack));
497 hiMicroTrack->SetChi2(prTrack->fitTraits().chi2());
503 StPtrVecTrackPidTraits traits = prTrack->pidTraits(kTpcId);
505 for (UInt_t i = 0; i < traits.size(); i++) {
507 if (pid && pid->method() == kTruncatedMeanId)
break;
510 hiMicroTrack->SetDedx((pid) ? pid->mean() : 0);
511 hiMicroTrack->SetDedxPts((pid) ? pid->numberOfPoints() : 0);
513 hiMicroTrack->SetFitPts(glTrack->fitTraits().numberOfFitPoints(kTpcId));
514 hiMicroTrack->SetAllPts(glTrack->detectorInfo()->numberOfPoints(kTpcId));
515 hiMicroTrack->SetMaxPossPts(glTrack->numberOfPossiblePoints());
516 hiMicroTrack->SetFlag(glTrack->flag());
517 hiMicroTrack->SetCharge(glTrack->geometry()->charge());
519 hiMicroTrack->SetFirstZ(firstZ);
520 hiMicroTrack->SetLastZ(lastZ);
521 hiMicroTrack->SetFirstPadrow(firstPadrow);
522 hiMicroTrack->SetInnerPadList(innerPadList);
523 hiMicroTrack->SetOuterPadList(outerPadList);
524 hiMicroTrack->SetLastPadrow(lastPadrow);
525 hiMicroTrack->SetFirstSector(firstSector);
526 hiMicroTrack->SetLastSector(lastSector);
528 hiMicroTrack->SetCrossingAngle(crossAngle);
534 mHiMicroEvent->AddTrack(hiMicroTrack);
539 if (!mHitLoop)
continue;
541 const StPtrVecHit& hits = prTrack->detectorInfo()->hits(kTpcId);
542 for(UInt_t iHit=0 ; iHit<hits.size(); iHit++){
545 cout <<
"Not a tpc hit?" << endl;
548 if (!hit->usedInFit())
continue;
552 hiMicroHit->SetPtPr(hiMicroTrack->PtPr());
553 hiMicroHit->SetPtGl(hiMicroTrack->PtGl());
554 hiMicroHit->SetEta(hiMicroTrack->EtaPr());
555 hiMicroHit->SetPhi(hiMicroTrack->PhiPr());
556 hiMicroHit->SetFitPts(hiMicroTrack->FitPts());
557 hiMicroHit->SetSDcaGl(hiMicroTrack->DcaGl());
558 hiMicroHit->SetDipAngle(hiMicroTrack->DipAnglePr());
559 hiMicroHit->SetExitZ(hiMicroTrack->LastZ());
560 hiMicroHit->SetCharge(hiMicroTrack->Charge());
564 hiMicroHit->SetR(hit->position().perp());
565 hiMicroHit->SetZ(hit->position().z());
566 hiMicroHit->SetPadRow( (Int_t) hit->padrow());
567 hiMicroHit->SetSector( (Int_t) hit->sector());
571 Double_t sGl = glHelix.
pathLength(hit->position());
572 Double_t sPr = prHelix.
pathLength(hit->position());
577 hiMicroHit->SetZResGl(hit->position().z() - glHitPos.z());
578 hiMicroHit->SetZResPr(hit->position().z() - prHitPos.z());
580 Float_t resXYGl = computeXY(hit->position(),glTrack);
581 Float_t resXYPr = computeXY(hit->position(),prTrack);
582 hiMicroHit->SetXYResGl(resXYGl);
583 hiMicroHit->SetXYResPr(resXYPr);
588 mHiMicroEvent->AddHit(hiMicroHit);
593 if(hiMicroTrack)
delete hiMicroTrack;
594 cout <<
"\t hi pt tracks : " << nHi << endl;
595 mNAcceptedTrack += nHi;
597 return nGoodTrackEta;
605 << glTrack->geometry()->momentum().perp()
607 << glTrack->geometry()->momentum().pseudoRapidity()
609 << glTrack->fitTraits().numberOfFitPoints(kTpcId)
611 << glTrack->detectorInfo()->numberOfPoints(kTpcId)<<endl
612 <<
"\t\t ptPr=" <<prTrack->geometry()->momentum().perp()
614 << glTrack->geometry()->momentum().pseudoRapidity() <<endl;
619 StHiMicroMaker::openFile()
621 cout <<
"###StHiMicroMaker::openFile()" << endl;
626 TString outFileName(mInFileName);
633 strcpy(cTemp,outFileName.Data());
635 cout <<
"We think the filename is " << outFileName.Data() << endl;
637 if(strstr(cTemp,
"dst.root")) replace=
".dst.root";
638 else if(strstr(cTemp,
"event.root")) replace=
".event.root";
639 else { cout <<
"unknown extension " << endl; exit(1); }
643 cout << replace << endl;
645 outFileName.ReplaceAll(replace.Data(),
".himicro.root");
647 cout << outFileName << endl;
649 outFileName.Prepend(mOutDir +
"/");
652 mDSTFile =
new TFile(outFileName.Data(),
"RECREATE");
656 <<
"Cannot create = " << outFileName << endm;
660 cout <<
"\toutfile = " << outFileName << endl;
666 cout <<
"##Creating the top level tree..." << endl;
667 mDSTTree =
new TTree(
"StHiMicroTree",
"StHiMicroTree");
670 <<
"Cannot create mDSTTree" << endm;
673 if(mDebug)cout <<
"##...done" << endl;
677 mDSTTree->SetAutoSave(10000000);
681 mDSTTree->Branch(
"StHiMicroEvent",
"StHiMicroEvent",
682 &mHiMicroEvent, bufSZ,1);
688 StHiMicroMaker::closeFile()
690 cout <<
"###StHiMicroMaker::closeFile()" << endl;
692 cout <<
"##Writing " << mInFileName << endl;
694 if(mDSTFile && mDSTFile->IsOpen()){
699 cout <<
"##...done\n";
714 double xCenter = track->geometry()->helix().
xcenter();
715 double yCenter = track->geometry()->helix().
ycenter();
716 double radius = 1.0/track->geometry()->helix().curvature();
719 = TMath::Sqrt( (pos.x()-xCenter) * (pos.x()-xCenter) +
720 (pos.y()-yCenter) * (pos.y()-yCenter));
722 return (Float_t) radius - dPosCenter;
733 double z0 = helix.
origin().z();
734 double phi = atan2(point.y()-helix.
ycenter(),
737 double dphi = h*(phi-helix.
phase());
740 dphi = (fabs(dphi) < M_PI ) ? dphi :
741 ((dphi<0) ? 2*M_PI + dphi : 2*M_PI - dphi);
743 double arclength= (1./helix.curvature()) * dphi;
745 double dcaZ = (point.z() - (z0 + arclength*tan(helix.dipAngle())));
779 double dcaZ = (dis1.mag() < dis2.mag()) ? dis1.z() : dis2.z();
780 if(::isnan(dcaZ))
return 999;
789 bool StHiMicroMaker::accept(
StEvent* stEvent)
792 return (stEvent->primaryVertex());
798 bool StHiMicroMaker::accept(
StTrack* track)
801 return (track && track->flag() > 0 &&
802 track->geometry()->momentum().perp()>=1.5);
807 bool StHiMicroMaker::acceptCentrality(
StTrack *track)
809 return (track && track->flag() > 0 && track->fitTraits().numberOfFitPoints(kTpcId) >= 10 &&
810 fabs(track->geometry()->momentum().pseudoRapidity())<.5);
818 bool StHiMicroMaker::goodGlobal(
StTrack *track)
820 return (track && track->flag() > 0 && track->geometry()->charge() != 0 &&
821 track->fitTraits().numberOfFitPoints(kTpcId) >= 25);
825 bool StHiMicroMaker::goodGlobalA(
StTrack *track)
827 return (track && track->flag() > 0 && track->geometry()->charge() != 0 &&
828 track->fitTraits().numberOfFitPoints(kTpcId) >= 10);
832 bool StHiMicroMaker::goodGlobalB(
StTrack *track)
834 return (track && track->flag() > 0 && track->geometry()->charge() != 0 &&
835 track->fitTraits().numberOfFitPoints(kTpcId) >= 15);
839 bool StHiMicroMaker::goodGlobalC(
StTrack *track)
841 return (track && track->flag() > 0 && track->geometry()->charge() != 0 &&
842 track->fitTraits().numberOfFitPoints(kTpcId) >= 20);
846 bool StHiMicroMaker::goodGlobalD(
StTrack *track)
848 return (track && track->flag() > 0 && track->geometry()->charge() != 0 &&
849 track->fitTraits().numberOfFitPoints(kTpcId) >= 30);
853 bool StHiMicroMaker::goodGlobalE(
StTrack *track)
855 return (track && track->geometry()->charge() != 0 &&
856 track->fitTraits().numberOfFitPoints(kTpcId) >= 25);
860 bool StHiMicroMaker::goodGlobalFlag(
StTrack *track)
862 return (track && track->flag() > 0 );
int h() const
y-center of circle in xy-plane
virtual void Clear(Option_t *option="")
User defined functions.
double distance(const StThreeVector< double > &p, bool scanPeriods=true) const
minimal distance between point and helix
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
double ycenter() const
x-center of circle in xy-plane
const StThreeVector< double > & origin() const
-sign(q*B);
double xcenter() const
aziumth in xy-plane measured from ring center
double phase() const
1/R in xy-plane
void Clear(Option_t *option="")
User defined functions.