60 #include "StLorentzVectorF.hh"
61 #include <TProcessID.h>
64 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
65 #include "StMuDSTMaker/COMMON/StMuDst.h"
66 #include "StMuDSTMaker/COMMON/StMuEvent.h"
68 #include "StMessMgr.h"
71 #include "StFmsCluster.h"
72 #include "StFmsCollection.h"
74 #include "StFmsPoint.h"
75 #include "StRunInfo.h"
76 #include "StFmsDbMaker/StFmsDbMaker.h"
82 #include "StFmsUtil/StFmsConstant.h"
100 LOG_DEBUG <<
"StFmsPointMaker initializing run" << endm;
101 mFmsDbMaker =
static_cast<StFmsDbMaker*
>(GetMaker(
"fmsDb"));
103 LOG_ERROR <<
"StFmsPointMaker initializing failed due to no StFmsDbMaker" << endm;
113 return StMaker::InitRun(runNumber);
123 LOG_DEBUG <<
"StFmsPointMaker making" << endm;
124 if(mReadMuDst)
return readMuDst();
128 muDst = (
StMuDst*)GetInputDS(
"MuDst");
131 unsigned short bbcTimeBin = muDst->
event()->bbcTriggerDetector().onlineTimeDifference();
132 if (bbcTimeBin!=0) vertexz = 633.544 - 0.158*bbcTimeBin;
136 mObjectCount = TProcessID::GetObjectCount();
137 if (!populateTowerLists()) {
151 TProcessID::SetObjectCount(mObjectCount);
159 fms =
event->fmsCollection();
162 LOG_ERROR <<
"StFmsPointMaker did not find "
163 <<
"an StFmsCollection in StEvent" << endm;
168 int StFmsPointMaker::clusterEvent() {
169 if (!mFmsCollection) {
172 for (
auto i = mTowers.begin(); i != mTowers.end(); ++i) {
178 clusterDetector(&i->second, i->first);
180 mFmsCollection->setMergeSmallToLarge(mMergeSmallToLarge);
181 mFmsCollection->setGlobalRefit(mGlobalRefit);
182 mFmsCollection->setTry1PhotonFit(mTry1PhotonFitWhen2PhotonFitFailed);
183 mFmsCollection->setNewClusterCategorization(mCategorizationAlgo);
184 mFmsCollection->setScaleShowerShape(1);
185 mFmsCollection->setScaleShowerShape(mScaleShowerShapeLarge,mScaleShowerShapeSmall);
186 mFmsCollection->sortPointsByEnergy();
187 LOG_INFO << Form(
"Found %d Clusters and %d Points",mFmsCollection->numberOfClusters(),mFmsCollection->numberOfPoints()) << endm;
192 int StFmsPointMaker::clusterDetector(TowerList* towers,
const int detectorId) {
195 mTry1PhotonFitWhen2PhotonFitFailed,mCategorizationAlgo,
196 mScaleShowerShapeLarge,mScaleShowerShapeSmall,
197 mShowerShapeWithAngle,vertexz);
199 if (!clustering.cluster(towers)) {
204 auto& clusters = clustering.clusters();
205 for (
auto cluster = clusters.begin(); cluster != clusters.end(); ++cluster) {
206 processTowerCluster(cluster->get(), detectorId);
208 LOG_DEBUG << Form(
"Found %d clusters for det=%d",clusters.size(),detectorId)<<endm;
237 bool StFmsPointMaker::processTowerCluster(
239 const int detectorId) {
244 if (!(cluster->x() > 0. && cluster->y() > 0.)) {
245 LOG_INFO <<
"Found cluster x or y is zero, not processing this cluster" << endm;
249 float x=cluster->x();
250 float y=cluster->y();
251 if(mMergeSmallToLarge>0){
252 if(x<8.0 && y>9.0 && y<25.0){
254 cluster->setX(x*1.5);
255 cluster->setY((y-9.0)*1.5);
258 cluster->setDetectorId(det);
261 cluster->setId(200*(det-kFmsNorthLargeDetId) + mFmsCollection->numberOfPoints());
265 if( mShowerShapeWithAngle>0 ) xyz.setZ (735.45);
267 cluster->setFourMomentum(mFmsDbMaker->
getLorentzVector(xyz,cluster->energy()));
270 for (UInt_t np = 0; np < towerCluster->
photons().size(); np++) {
273 point->setId(200*(det-kFmsNorthLargeDetId) + mFmsCollection->numberOfPoints());
274 point->setParentClusterId(cluster->id());
275 point->setNParentClusterPhotons(towerCluster->
photons().size());
276 point->setCluster(cluster);
279 mFmsCollection->points().push_back(point);
280 cluster->points().push_back(point);
283 auto& towers = towerCluster->
towers();
284 for (
auto i = towers.begin(); i != towers.end(); ++i) {
285 if ((*i)->hit()->adc() >= 1) {
286 cluster->hits().push_back((*i)->hit());
291 mFmsCollection->addCluster(towerCluster->
release());
301 float lwx=mFmsDbMaker->
getXWidth(kFmsNorthLargeDetId);
302 float lwy=mFmsDbMaker->
getYWidth(kFmsNorthLargeDetId);
303 float wx=mFmsDbMaker->
getXWidth(kFmsNorthSmallDetId);
304 float wy=mFmsDbMaker->
getYWidth(kFmsNorthSmallDetId);
305 if(mMergeSmallToLarge>0){
306 if(x<8.0*lwx && y>9.0*lwy && y<25.0*lwy){
308 y = (y/lwy - 9.0)*1.5*wy;
312 point->setEnergy(photon.
energy);
313 point->setDetectorId(det);
321 if( mShowerShapeWithAngle>0) xyz.setZ(735.45);
327 bool StFmsPointMaker::populateTowerLists() {
328 mFmsCollection = getFmsCollection();
329 if (!mFmsCollection) {
330 LOG_ERROR <<
"mFmsCollection is null" << endm;
333 auto& hits = mFmsCollection->hits();
334 LOG_DEBUG <<
"Found nhits = " << hits.size() << endm;
335 float sumE[5]={0.0,0.0,0.0,0.0,0.0};
337 for (
auto i = hits.begin(); i != hits.end(); ++i) {
339 int detector = hit->detectorId();
340 const int row = mFmsDbMaker->
getRowNumber(detector, hit->channel());
342 if (!isValidChannel(detector, row, column)) {
345 if(mMergeSmallToLarge>0){
346 if(detector==kFmsNorthSmallDetId) detector=kFmsNorthLargeDetId;
347 if(detector==kFmsSouthSmallDetId) detector=kFmsSouthLargeDetId;
349 if (hit->adc() > 0) {
350 sumE[0]+=hit->energy();
351 sumE[detector-kFmsNorthLargeDetId+1]+=hit->energy();
355 auto low = mTowers.lower_bound(detector);
356 if (low == mTowers.end() || mTowers.key_comp()(detector, low->first)) {
357 mTowers.insert(TowerMap::value_type(detector, TowerList()));
361 if (tower.initialize(mFmsDbMaker)) {
362 mTowers[detector].push_back(tower);
367 LOG_INFO << Form(
"NHit=%d NValidHit=%d Esum=%f (%f %f %f %f) Max=%f",hits.size(),n,sumE[0],sumE[1],sumE[2],sumE[3],sumE[4],mMaxEnergySum) << endm;
368 if(sumE[0]<=0.0 || sumE[0]>mMaxEnergySum) {
369 LOG_INFO << Form(
"Energy sum=%f exceed MaxEnergySum=%f (LED tail?) or below zero. Skipping!",sumE[0],mMaxEnergySum)<< endm;
377 bool StFmsPointMaker::isValidChannel(
int detector,
int row,
int column) {
380 if (row < ROW_LOW_LIMIT || column < COL_LOW_LIMIT) {
388 if (fabs(row - CEN_ROW_LRG) < CEN_ROW_WIDTH_LRG && column < CEN_UPPER_COL_LRG) {
392 if (fabs(CORNER_ROW - row) + column > CORNER_LOW_COL) {
399 if (fabs(row - CEN_ROW_SML) < CEN_ROW_WIDTH_SML && column < CEN_UPPER_COL_SML) {
411 const int nRows = mFmsDbMaker->
nRow(detector);
412 if (nRows < 0 || row > nRows) {
415 const int nColumns = mFmsDbMaker->
nColumn(detector);
416 if (nColumns < 0 || column > nColumns) {
422 Int_t StFmsPointMaker::readMuDst(){
424 if(!event){LOG_INFO<<
"StFmsPointMaker::readMuDst found no StEvent"<<endm;
return kStErr;}
426 if(!fmscol){LOG_INFO<<
"StFmsPointMaker::readMuDst found no FmsCollection"<<endm;
return kStErr;}
427 for (
unsigned i(0); i < fmscol->numberOfClusters(); ++i) {
435 for (
unsigned i(0); i < fmscol->numberOfPoints(); ++i) {
444 fmscol->sortPointsByET();
Declaration of StFmsPointMaker, the FMS cluster/photon maker.
Float_t getXWidth(Int_t detectorId)
get the offset of the detector
virtual void Clear(Option_t *option="")
User defined functions.
StThreeVectorF getStarXYZfromColumnRow(Int_t detectorId, Float_t column, Float_t row)
get the STAR frame coordinates from column/row
Int_t InitRun(Int_t runNumber)
Declaration of StFmsTower, a simple FMS tower wrapper.
double x
Fitted (relative) x-position.
StLorentzVectorF getLorentzVector(const StThreeVectorF &xyz, Float_t energy)
get the STAR frame pseudo rapidity from the vertex from local X/Y [cm]
Int_t largeSmall(Int_t detectorId)
north or south side
Int_t getRowNumber(Int_t detectorId, Int_t ch)
maximum number of channels
Int_t nRow(Int_t detectorId)
type of the detector
StThreeVectorF getStarXYZ(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the Y width of the cell
Int_t getColumnNumber(Int_t detectorId, Int_t ch)
get the row number for the channel
double energy
Fitted energy.
Declaration of StFmsTowerCluster, a cluster of FMS towers.
Declaration of StFmsEventClusterer, manager class for clustering.
Float_t getYWidth(Int_t detectorId)
get the X width of the cell
double y
Fitted (relative) y-position.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
StFmsPointMaker(const char *name="StFmsPointMaker")
void Clear(Option_t *option="")
Declaration of StFmsFittedPhoton, a photon fitted to an FMS cluster.
Int_t nColumn(Int_t detectorId)
number of rows