39 #include "StFmsFpsMaker.h"
41 #include "StMessMgr.h"
44 #include "StFmsDbMaker/StFmsDbMaker.h"
46 #include "StEventTypes.h"
47 #include "StEvent/StEvent.h"
48 #include "StEvent/StFmsCollection.h"
49 #include "StEvent/StFmsHit.h"
50 #include "StEvent/StFmsPoint.h"
51 #include "StEvent/StFmsPointPair.h"
52 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
56 StFmsFpsMaker::StFmsFpsMaker(
const Char_t* name):
StMaker(name) {}
58 StFmsFpsMaker::~StFmsFpsMaker(){}
60 Int_t StFmsFpsMaker::Init(){
61 mFmsDbMaker=
static_cast<StFmsDbMaker*
>(GetMaker(
"fmsDb"));
63 LOG_ERROR <<
"StFmsFpsMaker::InitRun Failed to get StFmsDbMaker" << endm;
71 if(!event) {LOG_ERROR <<
"StFmsFpsMaker::Make did not find StEvent"<<endm;
return kStErr;}
72 mFmsColl =
event->fmsCollection();
73 if(!mFmsColl) {LOG_ERROR <<
"StFmsFpsMaker::Make did not find StEvent->FmsCollection"<<endm;
return kStErr;}
74 if(mReadMuDST) readMuDST();
75 mFmsColl->fillFpsSlat();
77 mFmsColl->fillFpsAssociation();
79 mFmsColl->fillFmsPointPair();
85 void StFmsFpsMaker::corrFmsFps(){
86 const unsigned int npoint=mFmsColl->numberOfPoints();
87 StSPtrVecFmsPoint& points = mFmsColl->points();
90 for(
unsigned int i=0; i<npoint; i++) {
91 const float x=points[i]->XYZ().x();
92 const float y=points[i]->XYZ().y();
93 const float z=points[i]->XYZ().z();
95 points[i]->resetFps();
97 for(
unsigned int l=1; l<=kFpsNLayer; l++){
100 for(
unsigned int q=1; q<=kFpsNQuad; q++){
101 for(
unsigned int s=1; s<=kFpsNSlat; s++) {
102 const int slatid = mFmsDbMaker->fpsSlatId(q,l,s);
103 if(slatid<0)
continue;
104 float xyz[3],width[3];
105 mFmsDbMaker->fpsPosition(slatid,xyz,width);
106 const float projx=project(x,z,xyz[2],mMeanVertexZ);
107 const float projy=project(y,z,xyz[2],mMeanVertexZ);
108 const float d = distance(projx,projy,xyz[0],xyz[1],width[0],width[1]);
109 if(d<mMaxDistanceToAssociate){
110 float mip=mFmsColl->fps(slatid)->mip();
111 const unsigned short status=mFmsDbMaker->fpsStatus(slatid);
112 if(status != 0) mip=-9.0;
113 LOG_DEBUG << Form(
"%3d proj=%5.1f %5.1f slatid=%4d Q%1dL%1dS%02d d=%4.1f n=%d\n",
114 i,projx,projy,slatid,q,l,s,d,nFpsFound) << endm;
115 points[i]->setFps(l,mip,slatid,d);
121 LOG_DEBUG << Form(
"%3d proj=%5.1f %5.1f E=%5.1f L%1d not found!!!\n",i,x,y,points[i]->energy(),l) << endm;
122 }
else if(nFpsFound>kFpsNCandidate){
123 LOG_WARN << Form(
"found %d FPS slats assosicated with FmsPoint, which is more than %d!!!",nFpsFound,kFpsNCandidate) <<endm;
130 void StFmsFpsMaker::pid(
int opt){
131 const unsigned int npoint=mFmsColl->numberOfPoints();
132 StSPtrVecFmsPoint& points = mFmsColl->points();
134 for(
unsigned int i=0; i<npoint; i++) {
135 int pid=StFmsPoint::kFpsPidNoFps;
137 if(opt==0 || opt==2){
138 i1=int(points[i]->fpsMip(1,0) + 0.5);
139 i2=int(points[i]->fpsMip(2,0) + 0.5);
140 i3=int(points[i]->fpsMip(3,0) + 0.5);
142 i1=int(points[i]->fpsMip(1,kFpsNCandidate+2)+0.5);
143 i2=int(points[i]->fpsMip(2,kFpsNCandidate+2)+0.5);
144 i3=int(points[i]->fpsMip(3,kFpsNCandidate+2)+0.5);
147 if(i1<=0) i1=int(points[i]->fpsMip(1,1) + 0.5);
148 if(i2<=0) i2=int(points[i]->fpsMip(2,1) + 0.5);
149 if(i3<=0) i3=int(points[i]->fpsMip(3,1) + 0.5);
151 if(i1<-5 || i2<-5 || i3<-5) {
152 pid=StFmsPoint::kFpsPidBad;
153 }
else if(i1<0 || i2<0 || i3<0) {
154 pid=StFmsPoint::kFpsPidNoFps;
157 if (i1==0 && i2==0 && i3==0) pid=StFmsPoint::kFpsPidGamma1;
159 else if(i1>=1 && i2==0 && i3==0) pid=StFmsPoint::kFpsPidGamma3;
160 else if(i1==0 && i2>=1 && i3==0) pid=StFmsPoint::kFpsPidGamma4;
161 else if(i1==0 && i2==0 && i3>=1) pid=StFmsPoint::kFpsPidGamma2;
163 else if(i1>=1 && i2>=1 && i3==0) pid=StFmsPoint::kFpsPidUnknown;
164 else if(i1>=1 && i2==0 && i3>=1) pid=StFmsPoint::kFpsPidGamma5;
165 else if(i1==0 && i2>=1 && i3>=1) pid=StFmsPoint::kFpsPidGamma6;
167 else if(i1>=1 && i2>=1 && i3<=4) pid=StFmsPoint::kFpsPidMip;
168 else if(i1==1 && i2==1 && i3>=5) pid=StFmsPoint::kFpsPidElectron1;
169 else if(i1==1 && i2>=2 && i3>=5) pid=StFmsPoint::kFpsPidElectron2;
170 else if(i1>=2 && i2==1 && i3>=5) pid=StFmsPoint::kFpsPidElectron3;
171 else if(i1>=2 && i2>=2 && i3>=5) pid=StFmsPoint::kFpsPidGamma7;
172 else LOG_WARN << Form(
"Leaking selection : %1d %1d %1d\n",i1,i2,i3)<<endm;
174 points[i]->setFpsPid(pid);
178 void StFmsFpsMaker::isolationCone(){
179 const unsigned int nPointPairs = mFmsColl->numberOfPointPairs();
180 const unsigned int nHits = mFmsColl->numberOfHits();
181 for(
unsigned int i=0; i<nPointPairs; i++){
184 float sum[StFmsPointPair::kFmsPointMaxCone];
185 memset(sum,0,
sizeof(sum));
186 for(
unsigned int h=0; h<nHits; h++){
188 if(hit->detectorId()>=kFmsNorthLargeDetId && hit->detectorId()<=kFmsSouthSmallDetId){
190 float angle=v1.angle(v2);
191 for(
unsigned int c=0; c<StFmsPointPair::kFmsPointMaxCone; c++){
192 if(angle < pair->coneRadius(c)){
193 sum[c]+=hit->energy();
198 for(
unsigned int c=0; c<StFmsPointPair::kFmsPointMaxCone; c++) pair->setConeEnergy(c,sum[c]);
203 void StFmsFpsMaker::readMuDST(){
204 const unsigned int nh=mFmsColl->numberOfHits();
205 StSPtrVecFmsHit& hits = mFmsColl->hits();
207 for(
unsigned int j=0; j<nh; j++){
208 if(hits[j]->detectorId()==kFpsDetId) nfpshit++;
211 if(!mudst){ LOG_INFO<<
"StFmsFpsMaker::readMuDST found no Mudst"<<endm;
return;}
214 if(!muFmsColl){ LOG_INFO<<
"StFmsFpsMaker::readMuDST found no StMuFmsCollection in MuDST"<<endm;
return;}
216 const unsigned int nhits = muFmsColl->numberOfHits();
217 for(
unsigned int i=0; i<nhits; i++){
219 if(h->detectorId()==15) h->setDetectorId(kFpsDetId);
220 if(h->detectorId()==kFpsDetId) {
222 const int ch=h->channel();
223 const float gain=mFmsDbMaker->fpsGain(ch);
224 const float nmip=h->adc()/gain;
225 LOG_DEBUG << Form(
"ch=%3d adc=%4d gain=%6.2f nmip=%6.2f\n",ch,h->adc(),gain,nmip)<<endm;
227 for(
unsigned int j=0; j<nh; j++){
228 if(hits[j]->detectorId()==kFpsDetId && hits[j]->channel()==ch){
229 if(h->adc()!= hits[j]->adc()) {
230 LOG_ERROR <<
"StFmsFpsMaker::readMuDst Found inconsistent FPS hit" <<endm;
235 LOG_DEBUG<<
"StFmsFpsMaker::readMuDST found matching hits in StEvent->StFmsCollection, updating energy with new DB value "<<endm;
236 hits[j]->setEnergy(nmip);
244 h->qtCrate(),h->qtSlot(),h->qtChannel(),
245 h->adc(), h->tdc(), nmip);
246 mFmsColl->addHit(hit);
247 LOG_DEBUG<<
"StFmsFpsMaker::readMuDST did not find matching hits in StEvent->StFmsCollection. Creating and adding"<<endm;
252 LOG_INFO<<
"StFmsFpsMaker::readMuDST Found "<<nhits<<
" FMS hits in MuDst, updated "<<nfps<<
" FPS hits"<<endm;
255 Float_t StFmsFpsMaker::project(
float x,
float z,
float zp,
float vz){
256 if(z==vz)
return 0.0;
257 return x/(z-vz)*(zp-vz);
262 Float_t StFmsFpsMaker::distance(
float x,
float y,
float x0,
float y0,
float xw,
float yw){
265 float dx1=xx-xw/2.0, adx1=fabs(dx1);
266 float dx2=xx+xw/2.0, adx2=fabs(dx2);
267 float dy1=yy-yw/2.0, ady1=fabs(dy1);
268 float dy2=yy+yw/2.0, ady2=fabs(dy2);
269 float adx=(adx1<adx2) ? adx1 : adx2;
270 float ady=(ady1<ady2) ? ady1 : ady2;
271 float ad =(adx <ady ) ? adx : ady ;
274 if(oix<0.0 && oiy<0.0)
return -ad;
275 if(oix<0.0 && oiy>0.0)
return ady;
276 if(oix>0.0 && oiy<0.0)
return adx;
277 return sqrt( pow(fabs(xx)-xw/2.0,2.0) + pow(fabs(yy)-yw/2.0,2.0) );
static StMuFmsCollection * muFmsCollection()
returns pointer to current StMuFmsCollection
StThreeVectorF getStarXYZ(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the Y width of the cell