3 #include "StEEmcPool/StEEmcA2EMaker/StEEmcA2EMaker.h"
4 #include "StEEmcPool/StEEmcClusterMaker/StEEmcGenericClusterMaker.h"
6 #include "SystemOfUnits.h"
7 #include "StEmcUtil/geometry/StEmcGeom.h"
8 #include "StEmcUtil/projection/StEmcPosition.h"
10 #include "StBarrelEmcCluster.h"
11 #include "StBarrelEmcClusterMaker.h"
12 #include "StGammaFitter.h"
13 #include "StGammaEvent.h"
14 #include "StGammaEventMaker.h"
15 #include "StGammaRawMaker.h"
17 #include "StGammaCandidateMaker.h"
24 StGammaCandidateMaker::StGammaCandidateMaker(
const char *name):
StMaker(name)
30 mStrictBemcStatus =
true;
44 StGammaCandidateMaker::~StGammaCandidateMaker()
50 Int_t StGammaCandidateMaker::Init()
52 return StMaker::Init();
69 if(mUseBemc) MakeBarrel();
70 if(mUseEemc) MakeEndcap();
86 TVector3 d = cluster.
momentum().Unit();
88 d.SetMag( kEEmcZSMD / d.CosTheta() );
100 Int_t StGammaCandidateMaker::MakeBarrel()
105 if(!mGammaEventMaker)
107 LOG_WARN <<
"MakeBarrel() - No StGammaEventMaker found!" << endm;
114 LOG_WARN <<
"MakeBarrel() - No StGammaEvent found!" << endm;
121 LOG_WARN <<
"MakeBarrel() - No StGammaRawMaker found!" << endm;
126 if(!mBemcClusterMaker)
128 LOG_WARN <<
"MakeBarrel() - No StBarrelEmcClusterMaker found!" << endm;
133 StEmcGeom* geom = StEmcGeom::instance(
"bemc");
141 for(
unsigned int i = 0; i < mBemcClusterMaker->clusters().size(); ++i)
147 if(cluster->momentum().Pt() < mMinimumEt)
continue;
150 if(cluster->seed()->fail)
continue;
154 if(mStrictBemcStatus)
159 for(
int deta = -1; deta <= 1; ++deta)
161 for(
int dphi = -1; dphi <= 1; ++dphi)
165 if(tower->fail) fail =
true;
176 candidate->SetTowerClusterId(i);
177 candidate->SetId(nextId());
178 candidate->SetDetectorId(StGammaCandidate::kBEmc);
179 candidate->SetEnergy(cluster->energy());
180 candidate->SetPosition(cluster->position());
181 candidate->SetMomentum(cluster->momentum());
185 candidate->SetSeedEnergy(seed->energy);
186 candidate->SetTowerId(seed->id);
191 for(
int deta = -1; deta <= 1; ++deta)
194 for(
int dphi = -1; dphi <= 1; ++dphi)
201 if(tower->fail)
continue;
204 candidate->addMyTower(tower);
205 tower->candidates.Add(candidate);
208 if(
StGammaTower *preshower = mGammaRawMaker->tower(tower->id, kBEmcPres))
210 candidate->addMyPreshower1(preshower);
211 preshower->candidates.Add(candidate);
212 energy += preshower->energy;
216 for(
int k = 0; k < mGammaEvent->numberOfTracks(); ++k)
223 if(position != TVector3(0, 0, 0))
227 if(geom->getId(position.Phi(), position.Eta(), id) == 0 &&
id == static_cast<int>(tower->id))
229 candidate->addMyTrack(track);
245 candidate->SetBPrsEnergy(energy);
248 for (
int k = 0; k < mGammaEvent->numberOfTracks(); ++k)
254 float deta = cluster->momentum().Eta() - track->
eta();
255 float dphi = cluster->momentum().Phi() - track->
phi();
256 dphi = TVector2::Phi_mpi_pi(dphi);
257 float r = hypot(deta, dphi);
261 candidate->addTrack(track);
274 if(tower && tower->layer == kBEmcTower)
277 float deta = cluster->momentum().Eta() - tower->eta;
278 float dphi = cluster->momentum().Phi() - tower->phi;
279 dphi = TVector2::Phi_mpi_pi(dphi);
280 float r = hypot(deta, dphi);
284 candidate->addTower(tower);
285 if(!tower->candidates.FindObject(candidate)) tower->candidates.Add(candidate);
288 for(
int t = 0; t < mGammaEvent->numberOfTracks(); ++t)
295 if(position != TVector3(0, 0, 0))
299 if(geom->getId(position.Phi(), position.Eta(), id) == 0 &&
id == static_cast<int>(tower->id))
301 if(!tower->tracks.FindObject(track)) tower->tracks.Add(track);
319 if(preshower && preshower->layer == kBEmcPres)
322 float deta = cluster->momentum().Eta() - preshower->eta;
323 float dphi = cluster->momentum().Phi() - preshower->phi;
324 dphi = TVector2::Phi_mpi_pi(dphi);
325 float r = hypot(deta, dphi);
329 candidate->addPreshower1(preshower);
330 if(!preshower->candidates.FindObject(candidate)) preshower->candidates.Add(candidate);
338 float smdEtaEnergy = 0;
339 float smdPhiEnergy = 0;
346 smdEtaGeom->getId(cluster->position().Phi(), cluster->position().Eta(), centralId);
350 for(
int dPhiStrip = -1; dPhiStrip <= 1; ++dPhiStrip)
353 for(
int dEtaStrip = -20; dEtaStrip <= 20; ++dEtaStrip)
356 int id = emcPosition.
getNextId(3, centralId, dEtaStrip, dPhiStrip);
357 if(
id == 0)
continue;
359 smdEtaGeom->
getBin(
id, module, eta, sub);
363 smdEtaGeom->getXYZ(
id, x, y, z);
364 TVector3 vEta(x, y, z);
366 float deta = cluster->position().Eta() - vEta.Eta();
367 float dphi = cluster->position().Phi() - vEta.Phi();
368 dphi = TVector2::Phi_mpi_pi(dphi);
369 float r = hypot(deta, dphi);
376 if(
StGammaStrip* strip = mGammaRawMaker->strip(sector, kBEmcSmdEta,
id))
379 candidate->addSmdEta(strip);
380 strip->candidates.Add(candidate);
381 smdEtaEnergy += strip->energy;
390 smdEtaGeom->getEta(
id, eta);
395 strip->sector = module;
396 strip->plane = kBEmcSmdEta;
400 strip->position = 230.705 * sinh(eta);
402 double offset = fabs(eta) < 0.5 ? 0.73 : 0.94;
404 strip->left = strip->position - offset;
405 strip->right = strip->position + offset;
407 mGammaRawMaker->AddEtaStrip(strip);
409 candidate->addSmdEta(strip);
410 strip->candidates.Add(candidate);
421 smdPhiGeom->getId(cluster->position().Phi(), cluster->position().Eta(), centralId);
423 for(
int dEtaStrip = -1; dEtaStrip <= 1; ++dEtaStrip)
426 for(
int dPhiStrip = -20; dPhiStrip <= 20; ++dPhiStrip)
429 int id = emcPosition.
getNextId(4, centralId, dEtaStrip, dPhiStrip);
430 if(
id == 0)
continue;
432 smdEtaGeom->
getBin(
id, module, eta, sub);
436 smdPhiGeom->getXYZ(
id, x, y, z);
437 TVector3 vPhi(x, y, z);
439 float deta = cluster->position().Eta() - vPhi.Eta();
440 float dphi = cluster->position().Phi() - vPhi.Phi();
441 dphi = TVector2::Phi_mpi_pi(dphi);
442 float r = hypot(deta, dphi);
449 if(
StGammaStrip* strip = mGammaRawMaker->strip(sector, kBEmcSmdPhi,
id))
452 candidate->addSmdPhi(strip);
453 strip->candidates.Add(candidate);
454 smdPhiEnergy += strip->energy;
463 smdPhiGeom->getPhi(
id, phi);
468 strip->sector = module;
469 strip->plane = kBEmcSmdPhi;
473 strip->position = phi;
475 double offset = 0.00293;
477 strip->left = phi - offset;
478 strip->right = phi + offset;
480 mGammaRawMaker->AddPhiStrip(strip);
482 candidate->addSmdPhi(strip);
483 strip->candidates.Add(candidate);
493 candidate->SetSmdEtaEnergy(smdEtaEnergy);
494 candidate->SetSmdPhiEnergy(smdPhiEnergy);
505 Int_t StGammaCandidateMaker::MakeEndcap()
510 if(!mGammaEventMaker)
512 LOG_WARN <<
"MakeEndcap() - No StGammaEventMaker found!" << endm;
519 LOG_WARN <<
"MakeEndcap() - No StGammaEvent found!" << endm;
526 LOG_WARN <<
"MakeEndcap() - No StGammaRawMaker found!" << endm;
533 LOG_DEBUG <<
"MakeEndcap() - No StEEmcGenericClusterMaker found!" << endm;
540 LOG_DEBUG <<
"MakeEndcap() - No StEEmcA2EMaker found!" << endm;
546 for(Int_t sector = 0; sector < kEEmcNumSectors; sector++)
550 StEEmcClusterVec_t clusters = mEEclusters->
clusters(sector, 0);
551 for(UInt_t i = 0; i < clusters.size(); i++)
556 TVector3 position = getEEmcClusterPosition(cluster);
557 if(position == TVector3(0,0,0)) position = cluster.
position();
558 TVector3 pcluster = position - mGammaEvent->
vertex();
559 pcluster.SetMag(cluster.
energy());
562 Float_t ET = pcluster.Perp();
563 if(ET < mMinimumEt)
continue;
568 mCandidate->SetId( nextId() );
569 mCandidate->SetTowerClusterId( cluster.key() );
570 mCandidate->SetDetectorId( StGammaCandidate::kEEmc );
573 mCandidate->SetMomentum( pcluster );
574 mCandidate->SetPosition( cluster.
position() );
575 mCandidate->SetEnergy( cluster.
energy() );
579 mCandidate->SetSeedEnergy( seed.
energy() );
580 mCandidate->SetTowerId( seed.
index() );
595 Int_t index = tower.
index();
610 StGammaTower *gtower = mGammaRawMaker->tower(index, kEEmcTower);
611 StGammaTower *gpre1 = mGammaRawMaker->tower(index, kEEmcPre1);
612 StGammaTower *gpre2 = mGammaRawMaker->tower(index, kEEmcPre2);
613 StGammaTower *gpost = mGammaRawMaker->tower(index, kEEmcPost);
619 mCandidate->addMyTower(gtower);
620 gtower->candidates.Add(mCandidate);
624 if(gpre1 && !pre1.
fail() && pre1.
energy() > 0.0)
626 mCandidate->addMyPreshower1(gpre1);
627 gpre1->candidates.Add(mCandidate);
631 if(gpre2 && !pre2.
fail() && pre2.
energy() > 0.0)
633 mCandidate->addMyPreshower2(gpre2);
634 gpre2->candidates.Add(mCandidate);
638 if(gpost && !post.
fail() && post.
energy() > 0.0)
640 mCandidate->addMyPostshower(gpost);
641 gpost->candidates.Add(mCandidate);
649 for(
int k = 0; k < mGammaEvent->numberOfTracks(); ++k)
655 if (!track || track->
pz() < 0)
continue;
661 if(position != TVector3(0, 0, 0))
666 int sector, subsector, etabin;
668 if (geom.
getTower(position, sector, subsector, etabin))
671 bool match = gtower->sector() == sector;
672 match &= gtower->
subsector() == subsector;
673 match &= gtower->etabin() == etabin;
677 mCandidate->addMyTrack(track);
694 mCandidate->SetPre1Energy(epre1);
695 mCandidate->SetPre2Energy(epre2);
696 mCandidate->SetPostEnergy(epost);
702 Float_t candidateEta = pcluster.Eta();
703 Float_t candidatePhi = pcluster.Phi();
706 for(Int_t i = 0; i < mGammaEvent->numberOfTracks(); i++)
710 if (!track)
continue;
712 Float_t trackEta = track->
eta();
713 Float_t trackPhi = track->
phi();
714 Float_t dEta = trackEta - candidateEta;
715 Float_t dPhi = TVector2::Phi_mpi_pi(trackPhi - candidatePhi);
717 Float_t r = TMath::Sqrt(dPhi * dPhi + dEta * dEta);
721 mCandidate->addTrack(track);
734 Float_t towerEta = tower->eta;
735 Float_t towerPhi = tower->phi;
736 Float_t dEta = towerEta - candidateEta;
737 Float_t dPhi = TVector2::Phi_mpi_pi(towerPhi - candidatePhi);
739 Float_t r = TMath::Sqrt(dPhi * dPhi + dEta * dEta);
743 mCandidate->addTower(tower);
744 if(!tower->candidates.FindObject(mCandidate)) tower->candidates.Add(mCandidate);
756 Float_t towerEta = tower->eta;
757 Float_t towerPhi = tower->phi;
758 Float_t dEta = towerEta - candidateEta;
759 Float_t dPhi = TVector2::Phi_mpi_pi(towerPhi - candidatePhi);
761 Float_t r = TMath::Sqrt(dPhi * dPhi + dEta * dEta);
765 mCandidate->addPreshower1(tower);
766 if(!tower->candidates.FindObject(mCandidate)) tower->candidates.Add(mCandidate);
778 Float_t towerEta = tower->eta;
779 Float_t towerPhi = tower->phi;
780 Float_t dEta = towerEta - candidateEta;
781 Float_t dPhi = TVector2::Phi_mpi_pi(towerPhi - candidatePhi);
783 Float_t r = TMath::Sqrt(dPhi * dPhi + dEta * dEta);
787 mCandidate->addPreshower2(tower);
788 if(!tower->candidates.FindObject(mCandidate)) tower->candidates.Add(mCandidate);
798 if (!tower)
continue;
800 Float_t towerEta = tower->eta;
801 Float_t towerPhi = tower->phi;
802 Float_t dEta = towerEta - candidateEta;
803 Float_t dPhi = TVector2::Phi_mpi_pi(towerPhi - candidatePhi);
805 Float_t r = TMath::Sqrt(dPhi * dPhi + dEta * dEta);
809 mCandidate->addPostshower(tower);
810 if(!tower->candidates.FindObject(mCandidate)) tower->candidates.Add(mCandidate);
818 Float_t umin[kEEmcNumSectors], vmin[kEEmcNumSectors];
819 Float_t umax[kEEmcNumSectors], vmax[kEEmcNumSectors];
820 Float_t umid[kEEmcNumSectors], vmid[kEEmcNumSectors];
821 Int_t ntow[kEEmcNumSectors];
824 for(Int_t ii = 0; ii < 12; ii++)
844 umid[ tower.
sector() ]+=0.5+(Float_t)U;
845 vmid[ tower.
sector() ]+=0.5+(Float_t)V;
850 for(Int_t isec = 0; isec < 12; isec++)
855 umid[isec] /= ntow[isec];
856 vmid[isec] /= ntow[isec];
857 umin[isec] = TMath::Max(umid[isec] - mEsmdRange * 2.0, 0. );
858 vmin[isec] = TMath::Max(vmid[isec] - mEsmdRange * 2.0, 0. );
859 umax[isec] = TMath::Min(umid[isec] + mEsmdRange * 2.0, 287. );
860 vmax[isec] = TMath::Min(vmid[isec] + mEsmdRange * 2.0, 287. );
866 for(Int_t isec = 0; isec < 12; isec++)
869 if(!ntow[isec])
continue;
872 for(Int_t i = (Int_t)umin[isec]; i < (Int_t)umax[isec]; i++)
875 StGammaStrip *strip = mGammaRawMaker->strip(isec, 0, i);
879 mCandidate->addSmdu(strip);
880 strip->candidates.Add(mCandidate);
886 for(Int_t i = (Int_t)vmin[isec]; i < (Int_t)vmax[isec]; i++)
893 mCandidate->addSmdv(strip);
894 strip->candidates.Add(mCandidate);
902 float smduEnergy = 0;
904 for(
int i = 0; i < mCandidate->numberOfSmdu(); ++i)
907 smduEnergy += strip->energy;
910 mCandidate->SetSmduEnergy(smduEnergy);
913 float smdvEnergy = 0;
914 for (
int i = 0; i < mCandidate->numberOfSmdv(); ++i)
917 smdvEnergy += strip->energy;
920 mCandidate->SetSmdvEnergy(smdvEnergy);
931 if (candidate->detectorId() == StGammaCandidate::kEEmc)
936 if(ustatus == 0) candidate->SetSmdFit(ufit,0);
938 if(vstatus == 0) candidate->SetSmdFit(vfit,1);
950 TVector3 StGammaCandidateMaker::getEEmcClusterPosition(
const StEEmcCluster& cluster)
957 LOG_WARN <<
"MakeEndcap() - No StGammaRawMaker found!" << endm;
958 return TVector3(-999,-999,-999);
965 int sector = seed.
sector();
967 int etabin = seed.
etabin();
968 int xmin[2], xmax[2];
970 EEmcSmdMap::instance()->getRangeU(sector, subsector, etabin, xmin[0], xmax[0]);
971 EEmcSmdMap::instance()->getRangeV(sector, subsector, etabin, xmin[1], xmax[1]);
975 for(
int plane = 0; plane < 2; ++plane)
978 for(
int i = xmin[plane]; i <= xmax[plane]; ++i)
981 StGammaStrip* strip = mGammaRawMaker->strip(sector, plane, i);
984 if(!maxStrips[plane] || strip->energy > maxStrips[plane]->energy)
986 maxStrips[plane] = strip;
996 if(maxStrips[0] && maxStrips[1])
999 TVector3 position = EEmcSmdGeom::instance()->
getIntersection(sector, maxStrips[0]->index, maxStrips[1]->index);
1002 bool success = position.z() != -999;
1004 success &= sector == sec;
1005 success &= subsector == sub;
1006 success &= etabin == eta;
1008 if(success)
return position;
1013 return TVector3(0, 0, 0);
1021 Int_t StGammaCandidateMaker::Compress()
1025 if(mCompressLevel == 0)
return kStOk;
1029 if(!mGammaEventMaker)
1031 LOG_WARN <<
"Compress() - No StGammaEventMaker found!" << endm;
1038 LOG_WARN <<
"Compress() - No StGammaEvent found!" << endm;
1042 Compress<StGammaStrip>(mGammaEvent->mStrips);
1045 if(mCompressLevel == 1)
return kStOk;
1048 Compress<StGammaTrack>(mGammaEvent->mTracks);
1049 Compress<StGammaTower>(mGammaEvent->mTowers);
1050 Compress<StGammaTower>(mGammaEvent->mPreshower1);
1051 Compress<StGammaTower>(mGammaEvent->mPreshower2);
1052 Compress<StGammaTower>(mGammaEvent->mPostshower);
1055 if(mCompressLevel == 2)
return kStOk;
1057 LOG_WARN << Form(
"Unknown compression level (%d)", mCompressLevel) << endm;
1069 void StGammaCandidateMaker::Compress(TClonesArray* clones)
1072 while (T* x = (T*)next())
if (x->candidates.IsEmpty()) clones->Remove(x);
TVector3 momentum() const
StEEmcTower & tower(Int_t t)
Get the specified tower within the cluster.
Float_t getZ1() const
gets lower Z edge of EEMC (preshower)
EEmc ADC –> energy maker.
static EEmcGeomSimple & Instance()
returns a reference to a static instance of EEmcGeomSimple
void Clear(Option_t *opts="")
User defined functions.
StGammaTower * tower(Int_t i) const
Return ith track.
StGammaTower * preshower1(Int_t i) const
Return ith tower.
Int_t numberOfPostshower() const
Return number of pre2.
TVector3 position() const
Int_t getNextId(Int_t det, Int_t m, Int_t e, Int_t s, Int_t nEta, Int_t nPhi) const
Return neighbor id (works for all detectors 1=bemc, 2=bprs, 3=bsmde, 4=bsmdp)
Int_t numberOfPreshower1() const
Return number of towers.
Int_t numberOfCandidates() const
Return number of strips.
StEEmcClusterVec_t & clusters(Int_t sec, Int_t layer)
Return a vector of tower clusters.
static StGammaFitter * instance()
Access to single instance of this singleton class.
Int_t etabin() const
Returns the etabin of this tower, pre- or postshower element.
void fail(unsigned f)
Set a fail bit for this element.
TVector3 & vertex()
Returns muDst file from which event originated.
Int_t subsector() const
Returns subsector of this tower, pre- or postshower element.
StGammaCandidate * newCandidate()
Add a new SMD strip.
Base class for representing tower, preshower and postshower elements.
StGammaStrip * newStrip()
Add a new postshower element.
Int_t sector() const
Returns sector of this tower, pre- or postshower element.
int fit(StGammaCandidate *candidate, StGammaFitterResult *fits, Int_t plane=0)
Fit transverse SMD profile to predetermined peak in u- and v-plane.
StGammaTrack * track(Int_t i) const
Return number of candidates.
Int_t numberOfTowers() const
Get the number of towers in cluster.
Float_t phi() const
eta at vertex
Float_t energy() const
Get energy of this cluster.
TVector3 getIntersection(Int_t iSec, Int_t iUStrip, Int_t iVStrip, const TVector3 &vertex) const
TRefArray candidates
Returns (0,0,0) if failed.
A base class for describing clusters of EEMC towers.
Int_t numberOfPreshower2() const
Return number of pre1.
StEEmcTower & tower(Int_t index, Int_t layer=0)
StGammaTower * preshower2(Int_t i) const
Return ith pre1.
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Float_t pz() const
pt at vertex
TVector3 positionAtRadius(Double_t radius) const
Returns outer helix (last measured point)
bool getTower(const TVector3 &r, int &sec, int &sub, int &etabin, Float_t &dphi, Float_t &deta) const
TVector3 positionAtZ(Double_t z) const
Returns (0,0,0) if failed.
StGammaTower * postshower(Int_t i) const
Return ith pre2.
void energy(Float_t e)
Set the energy (adc-ped+0.5)/gain for this element.
Int_t numberOfTowers() const
Return number of tracks.
StGammaCandidate * candidate(Int_t i) const
Return ith strip.
Float_t eta() const
pz at vertex