00001 #include "CtbMatching.h"
00002
00003 #include "StMuLcp2TreeMaker.h"
00004
00005 #include "StCtbTriggerDetector.h"
00006 #include "StMuDSTMaker/COMMON/StMuEvent.h"
00007 #include "StarClassLibrary/StPhysicalHelixD.hh"
00008 #include "StarClassLibrary/StThreeVectorD.hh"
00009 #include "StMuDSTMaker/COMMON/StMuTrack.h"
00010 #include "TMath.h"
00011
00012
00013
00014 CtbMatching::CtbMatching() {
00015 ctbHits= new vector<ctbHit>();
00016
00017 etaToll=0.;
00018 phiToll=0;
00019
00020 }
00021
00022
00023 void CtbMatching::loadHits(StMuEvent* muEve) {
00024
00025 ctbHits->clear();
00026
00027 StCtbTriggerDetector* ctbDet = &(muEve->ctbTriggerDetector());
00028
00029 assert(ctbDet);
00030 float ctbSum = 0;
00031 for (UInt_t slat = 0; slat < ctbDet->numberOfSlats(); slat++) {
00032 for (UInt_t tray = 0; tray < ctbDet->numberOfTrays(); tray++) {
00033 ctbHit curHit;
00034 curHit.adc = ctbDet->mips(tray,slat,0);
00035 if(curHit.adc > 0){
00036 ctbSum += curHit.adc;
00037 ctb_get_slat_from_data(slat, tray, curHit.phi, curHit.eta);
00038 ctbHits->push_back(curHit);
00039
00040 }
00041 }
00042 }
00043
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 void CtbMatching::ctb_get_slat_from_data(int slat, int tray, double & ctbphi, double & ctbeta) {
00053
00054
00055 float phiZero1 = 72 ;
00056 float phiZero2 = 108 ;
00057 float deltaPhi = 6 ;
00058
00059
00060
00061 int iz ;
00062 double phi,eta ;
00063
00064 if ( tray < 60 ) {
00065 phi = phiZero1 - tray * deltaPhi ;
00066 iz = 0 ;
00067 } else {
00068 phi = phiZero2 + (tray-60) * deltaPhi ;
00069 iz = 1 ;
00070 }
00071
00072 if ( phi < 0. ) phi += 360 ;
00073 if ( phi > 360. ) phi -= 360 ;
00074
00075 ctbphi=phi;
00076 eta = (1-2*iz)*(1+2*slat)*0.25;
00077 ctbeta =(1-2*iz)*(1+2*slat)*0.25;
00078
00079
00080
00081 }
00082
00083
00084
00085
00086 unsigned int CtbMatching::match(const StMuTrack* rTrack) {
00087
00088
00089 bool shouldHit;
00090 double trackEtaInCTBFrame;
00091 double trackPhiInCTBFrame;
00092
00093
00094 const double Rctb=213.6;
00095
00096
00097
00098
00099
00100
00101 StPhysicalHelixD theHelix = rTrack->helix();
00102 pairD pathLength = theHelix.pathLength(Rctb);
00103
00104 if(pathLength.second < 0){
00105 cout << "pathLength is bad" << endl;
00106 return false;
00107 }
00108
00109 const StThreeVectorD &pos = theHelix.at(pathLength.second);
00110
00111 double phi = atan2(pos.y(),pos.x())*180/TMath::Pi();
00112 if(phi < 0) phi+= 360;
00113
00114 trackPhiInCTBFrame = phi;
00115
00116 double theta = atan2(pos.perp(),pos.z());
00117 double eta = -log(tan(theta/2.0));
00118 trackEtaInCTBFrame = eta;
00119
00120
00121 if(fabs(eta) < 1.+etaToll)
00122 shouldHit = true;
00123 else
00124 shouldHit = false;
00125
00126
00127 float deta,dphi;
00128 for(unsigned int i = 0; i < ctbHits->size() ; i++){
00129 ctbHit curHit = (*ctbHits)[i];
00130 deta = fabs(curHit.eta - eta);
00131 dphi = fabs(curHit.phi - phi);
00132 if(dphi>180) dphi=360.-dphi;
00133 if( dphi < (3.+phiToll) && deta < (.25+etaToll)){
00134 return static_cast<unsigned int>(curHit.adc);
00135 }
00136 }
00137 return 0;
00138 }
00139
00140 #if 0
00141 if(rTrack){
00142 globalTrackJG* glTrack = new globalTrackJG();
00143 bool shouldHitCTB = false;
00144 double etaInCTBFrame = -999;
00145 double phiInCTBFrame = -999;
00146
00147 glTrack->matchToCTB = EtaAndPhiToOrriginAtCTB(rTrack,ctbHits,shouldHitCTB,etaInCTBFrame,phiInCTBFrame);
00148 glTrack->shouldMatchToCTB = shouldHitCTB;
00149 glTrack->etaInCTBFrame = etaInCTBFrame;
00150 glTrack->phiInCTBFrame = phiInCTBFrame;
00151
00152
00153
00154 unsigned int matchToCTB = EtaAndPhiToOrriginAtCTB(rTrack,ctbHits,shouldHitCTB,etaInCTBFrame,phiInCTBFrame);
00155
00156
00157
00158
00159 #endif