StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CtbMatching.cxx
1 #include "CtbMatching.h"
2 
3 #include "StMuLcp2TreeMaker.h"
4 
5 #include "StCtbTriggerDetector.h"
6 #include "StMuDSTMaker/COMMON/StMuEvent.h"
7 #include "StarClassLibrary/StPhysicalHelixD.hh"
8 #include "StarClassLibrary/StThreeVectorD.hh"
9 #include "StMuDSTMaker/COMMON/StMuTrack.h"
10 #include "TMath.h"
11 
12 //________________________________________________
13 //________________________________________________
14 CtbMatching::CtbMatching() {
15  ctbHits= new vector<ctbHit>();
16  // define matching tolerance
17  etaToll=0.; // was 0.1
18  phiToll=0; // (deg) was 1
19 
20 }
21 //________________________________________________
22 //________________________________________________
23 void CtbMatching::loadHits(StMuEvent* muEve) {
24 
25  ctbHits->clear();
26 
27  StCtbTriggerDetector* ctbDet = &(muEve->ctbTriggerDetector());
28 
29  assert(ctbDet);
30  float ctbSum = 0;
31  for (UInt_t slat = 0; slat < ctbDet->numberOfSlats(); slat++) {
32  for (UInt_t tray = 0; tray < ctbDet->numberOfTrays(); tray++) {
33  ctbHit curHit;
34  curHit.adc = ctbDet->mips(tray,slat,0);
35  if(curHit.adc > 0){
36  ctbSum += curHit.adc;
37  ctb_get_slat_from_data(slat, tray, curHit.phi, curHit.eta);
38  ctbHits->push_back(curHit);
39  // printf("CTB Hit ADC=%f sum=%f\n",curHit.adc, ctbSum);
40  }
41  }
42  }
43  //printf("nCtbHit=%d, CtbSum=%f\n", ctbHits->size(),ctbSum);
44 }
45 
46 
47 
48 //StCtbTriggerDetector& ctbDet=muEve->ctbTriggerDetector();
49 
50 //________________________________________________
51 //________________________________________________
52 void CtbMatching::ctb_get_slat_from_data(int slat, int tray, double & ctbphi, double & ctbeta) {
53  // Function copied verbatum from St_dst_Maker/CtbResponce. We may want to clean this up.
54 
55  float phiZero1 = 72 ; // magic lines from Pablo & Herb
56  float phiZero2 = 108 ;
57  float deltaPhi = 6 ;
58  // tray=0,1
59  // slat=0,...,119
60 
61  int iz ;
62  double phi;
63 
64  if ( tray < 60 ) {
65  phi = phiZero1 - tray * deltaPhi ;
66  iz = 0 ;
67  } else {
68  phi = phiZero2 + (tray-60) * deltaPhi ;
69  iz = 1 ;
70  }
71 
72  if ( phi < 0. ) phi += 360 ;
73  if ( phi > 360. ) phi -= 360 ;
74 
75  ctbphi=phi;
76  //double eta = (1-2*iz)*(1+2*slat)*0.25;
77  ctbeta =(1-2*iz)*(1+2*slat)*0.25;
78 
79  //printf("CTB hit: slat=%d, tray=%d, phiDeg=%f/deg, eta=%f\n",slat,tray,ctbphi,ctbeta);
80 
81 }
82 
83 
84 //________________________________________________
85 //________________________________________________
86 unsigned int CtbMatching::match(const StMuTrack* rTrack) {
87 
88  // the code
89  const double Rctb=213.6; // (cm) radius of the CTB
90 
91  /*
92  if(rTrack->geometry()->momentum().perp() < .20)
93  return false;
94  */
95 
96  StPhysicalHelixD theHelix = rTrack->helix();
97  pairD pathLength = theHelix.pathLength(Rctb);
98 
99  if(pathLength.second < 0){
100  cout << "pathLength is bad" << endl;
101  return false;
102  }
103 
104  const StThreeVectorD &pos = theHelix.at(pathLength.second);
105 
106  double phi = atan2(pos.y(),pos.x())*180/TMath::Pi();
107  if(phi < 0) phi+= 360;
108 
109  double theta = atan2(pos.perp(),pos.z());
110  double eta = -log(tan(theta/2.0));
111 
112  // if |eta| < 1 then track should have hit the CTB.
113 
114  // Loop over CTB Hits To see if a match
115  float deta,dphi;
116  for(unsigned int i = 0; i < ctbHits->size() ; i++){
117  ctbHit curHit = (*ctbHits)[i];
118  deta = fabs(curHit.eta - eta);
119  dphi = fabs(curHit.phi - phi);
120  if(dphi>180) dphi=360.-dphi;
121  if( dphi < (3.+phiToll) && deta < (.25+etaToll)){
122  return static_cast<unsigned int>(curHit.adc);
123  }
124  }
125  return 0;
126 }
127 
128 #if 0
129 if(rTrack){
130  globalTrackJG* glTrack = new globalTrackJG();
131  bool shouldHitCTB = false;
132  double etaInCTBFrame = -999;
133  double phiInCTBFrame = -999;
134 
135  glTrack->matchToCTB = EtaAndPhiToOrriginAtCTB(rTrack,ctbHits,shouldHitCTB,etaInCTBFrame,phiInCTBFrame);
136  glTrack->shouldMatchToCTB = shouldHitCTB;
137  glTrack->etaInCTBFrame = etaInCTBFrame;
138  glTrack->phiInCTBFrame = phiInCTBFrame;
139 
140 
141 
142  unsigned int matchToCTB = EtaAndPhiToOrriginAtCTB(rTrack,ctbHits,shouldHitCTB,etaInCTBFrame,phiInCTBFrame);
143  // rTrack is StTrack/StMuTrack
144  // ctbHits is above vector
145  // shouldHitCTB will be a boolean if track is withing
146  // etaInCTBFrame, phiInCTBFrame is the phi/eta of where the track hits the CTB with the origin at 0,0,
147 #endif
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
StPhysicalHelixD helix() const
Returns inner helix (first measured point)
Definition: StMuTrack.cxx:407