00001
00002
00003
00004
00031 #include <Stiostream.h>
00032 #include <Stsstream.h>
00033
00034 #include "TList.h"
00035 #include "TMath.h"
00036 #include "TGeoVolume.h"
00037 #include "TGeoCone.h"
00038 #include "TGeoManager.h"
00039 #include "TGeoMedium.h"
00040 #include "TGeoMatrix.h"
00041 #include "THelix.h"
00042
00043 #include "StarClassLibrary/StPhysicalHelixD.hh"
00044 #include "StMuDSTMaker/COMMON/StMuTrack.h"
00045 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
00046
00047 #include "EEmcTower.h"
00048 #include "EEmcTTMatch.h"
00049 #include "EEmcTTMMaker.h"
00050 #include "EEmcTTDisplay.h"
00051
00052
00053 static const double cLight = 3e10*centimeter/second;
00054
00055
00056 static const int kSectorColors[] = {
00057 kBlack,
00058 kBlack,
00059 kGreen,
00060 kBlack,
00061 kBlack,
00062 kBlue ,
00063 kBlack,
00064 kBlack,
00065 kYellow,
00066 kBlack,
00067 kBlack,
00068 kRed ,
00069 kWhite,
00070 kWhite,
00071 };
00072
00073
00074 EEmcTTDisplay::EEmcTTDisplay(const char *name) : EEmcGeomSimple()
00075 {
00076 mEEmc=NULL;
00077
00078 mTrackHits=new TList;
00079 mTowerHits=new TList;
00080 mBField =0.5;
00081 mShowExtrapolatedTracks = false;
00082 initGeometry(name);
00083
00084 };
00085
00086 EEmcTTDisplay::~EEmcTTDisplay()
00087 {
00088 if(mEEmc) delete mEEmc;
00089 if(mTrackHits) delete mTrackHits;
00090 if(mTowerHits) delete mTowerHits;
00091 }
00092
00093
00094 void
00095 EEmcTTDisplay::initGeometry(const char *topName)
00096 {
00097 const double kDPhi = -15.0/180.0*M_PI;
00098 char rotName[256];
00099 if(mEEmc!=NULL) return;
00100
00101 double eta1 = mEtaBin[0];
00102 double eta2 = mEtaBin[mNumEta];
00103
00104 double rmin1 = mZ1/TMath::SinH(eta1);
00105 double rmax1 = mZ1/TMath::SinH(eta2);
00106
00107 double rmin2 = mZ2/TMath::SinH(eta1);
00108 double rmax2 = mZ2/TMath::SinH(eta2);
00109
00110 double dz = TMath::Abs(mZ2-mZ1)/2.0;
00111
00112 int numSSec = mNumSec*mNumSSec;
00113
00114 TGeoMedium *medVac = new TGeoMedium ("Vacuum",1, new TGeoMaterial("Vacuum") );
00115 TGeoCone *econe = new TGeoCone(dz,rmin1,rmax1,rmin2,rmax2);
00116 mEEmc = new TGeoVolume(topName,econe,medVac);
00117 mEEmc->SetLineColor(kWhite);
00118 TGeoConeSeg *geosector = new TGeoConeSeg(dz,rmin1,rmax1,rmin2,rmax2,0.0,360.0/mNumSec);
00119 TGeoConeSeg *geosubsec = new TGeoConeSeg(dz,rmin1,rmax1,rmin2,rmax2,0.0,360.0/numSSec);
00120 for(unsigned s=0;s<mNumSec;s++) {
00121 double phi = getPhiMean(s)+kDPhi;
00122 sprintf(rotName,"RotSec%02d",s+1);
00123 TGeoRotation *rots = new TGeoRotation(rotName,phi/M_PI*180.0,0.0,0.0);
00124 TGeoVolume *sector = new TGeoVolume(volumeName(s),geosector,medVac);
00125 sector->SetVisibility(kTRUE);
00126 sector->SetLineColor (kSectorColors[s]);
00127 mEEmc->AddNode(sector,1,rots);
00128
00129 for(unsigned ss=0;ss<mNumSSec;ss++) {
00130 double phi = getPhiMean(0,ss)-getPhiMean(0,mNumSSec-1);
00131 sprintf(rotName,"Rot%02dT%1c",s+1,ss+'A');
00132 TGeoRotation *rotss = new TGeoRotation(rotName,phi/M_PI*180.0,0.0,0.0);
00133 TGeoVolume *subsector = new TGeoVolume(volumeName(s,ss),geosubsec,medVac);
00134 subsector->SetVisibility(kFALSE);
00135 sector->AddNode(subsector,1,rotss);
00136
00137 for(unsigned e=0;e<mNumEta;e++) {
00138 eta1 = mEtaBin[e];
00139 eta2 = mEtaBin[e+1];
00140 rmin1 = mZ1/TMath::SinH(eta1);
00141 rmax1 = mZ1/TMath::SinH(eta2);
00142 rmin2 = mZ2/TMath::SinH(eta1);
00143 rmax2 = mZ2/TMath::SinH(eta2);
00144
00145 TGeoConeSeg *geotile = new TGeoConeSeg(dz,rmin1,rmax1,rmin2,rmax2,0.0,360.0/numSSec);
00146 TGeoVolume *tile = new TGeoVolume(volumeName(s,ss,e),geotile,medVac);
00147 tile->SetVisibility(kFALSE);
00148 subsector->AddNode(tile,1);
00149 }
00150 }
00151 }
00152 }
00153
00154
00155 void
00156 EEmcTTDisplay::Draw(const Option_t* option)
00157 {
00158 TIter nextTower(mTowerHits);
00159 TIter nextTrack(mTrackHits);
00160 TGeoNode *gnode;
00161 TGeoVolume *vol;
00162 THelix *helix;
00163
00164 while( (gnode=(TGeoNode *)nextTower())!=NULL ) {
00165 vol=gnode->GetVolume();
00166 vol->SetLineColor(kRed);
00167 vol->SetVisibility(kTRUE);
00168 }
00169 while( (helix=(THelix *)nextTrack())!=NULL ) {
00170 helix->Draw();
00171 }
00172 }
00173
00174
00175 void
00176 EEmcTTDisplay::Clear(const Option_t* option)
00177 {
00178 TIter nextTower(mTowerHits);
00179 TGeoNode *gnode;
00180 while( (gnode=(TGeoNode *)nextTower())!=NULL ) {
00181
00182 gnode->GetVolume()->SetLineColor(kBlack);
00183 gnode->GetVolume()->SetVisibility(kFALSE);
00184 }
00185
00186 mTrackHits->Delete();
00187 mTowerHits->Clear();
00188 }
00189
00190
00191
00192
00193 Bool_t
00194 EEmcTTDisplay::AddTower(const char *vname)
00195 {
00196 const int kSecLen=2;
00197 const int kSubLen=4;
00198 const int kEtaLen=6;
00199 TGeoNode *node;
00200 TIter sector(mEEmc->GetNodes());
00201 while( (node=(TGeoNode *)sector())!=NULL ) {
00202 if(strncmp(vname,node->GetVolume()->GetName(),kSecLen)!=0) continue;
00203 TIter subsector(node->GetVolume()->GetNodes());
00204 while( (node=(TGeoNode *)subsector())!=NULL ) {
00205 if(strncmp(vname,node->GetVolume()->GetName(),kSubLen)!=0) continue;
00206 TIter tile(node->GetVolume()->GetNodes());
00207 while( (node=(TGeoNode *)tile())!=NULL ) {
00208 if(strncmp(vname,node->GetVolume()->GetName(),kEtaLen)!=0) continue;
00209
00210 mTowerHits->Add(node);
00211 return kTRUE;
00212 }
00213 }
00214 }
00215 return kFALSE;
00216 }
00217
00218 Bool_t
00219 EEmcTTDisplay::AddTower(const EEmcTower& tower)
00220 {
00221 return AddTower(volumeName(tower.Sec(),tower.SubSec(),tower.Eta()));
00222 }
00223
00224
00225 Bool_t
00226 EEmcTTDisplay::AddTrack(Double_t x, Double_t y, Double_t z,
00227 Double_t px, Double_t py, Double_t pz,
00228 Double_t qB, Double_t zMin, Double_t zMax)
00229 {
00230 THelix *helix = new THelix(x,y,z,px,py,pz,cLight*qB);
00231
00232 if(zMin<=0.0) zMin=z;
00233 if(zMax<=0.0) zMax=mZ2;
00234
00235 helix->SetRange(zMin,zMax);
00236 helix->SetLineColor(102);
00237 helix->SetLineWidth(2);
00238
00239 if(mShowExtrapolatedTracks) {
00240 THelix *helixExt = new THelix(x,y,z,px,py,pz,cLight*qB);
00241 helixExt->SetRange(z ,mZ2);
00242 helixExt->SetLineColor(20);
00243 helixExt->SetLineWidth(1);
00244 mTrackHits->Add(helixExt);
00245 }
00246 mTrackHits->Add(helix);
00247 return kTRUE;
00248 }
00249
00250 Bool_t
00251 EEmcTTDisplay::AddTrack(const StMuTrack& track)
00252 {
00253 StPhysicalHelixD h = track.helix();
00254 StThreeVectorD o = h.origin();
00255 StThreeVectorD p = h.momentum(mBField*tesla);
00256 double q = h.charge(mBField*tesla);
00257 double zMin= track.firstPoint().z();
00258 double zMax= track.lastPoint().z();
00259 return AddTrack(o.x(),o.y(),o.z(),
00260 p.x(),p.y(),p.z(),
00261 q*mBField*tesla,zMin,zMax);
00262 }
00263
00264
00265 Bool_t
00266 EEmcTTDisplay::AddMatch(EEmcTTMatch& tmatch)
00267 {
00268 EEmcTower *tower =tmatch.Tower();
00269 StMuTrack *track =NULL;
00270 if(!AddTower(*tower)) return kFALSE;
00271 TIter nextTrack(tmatch.Tracks());
00272 while((track=(StMuTrack *)nextTrack())) AddTrack(*track);
00273 return kTRUE;
00274 }
00275
00276
00277 void
00278 EEmcTTDisplay::Out(ostream &out, EEmcTTMatch &tmatch)
00279 {
00280 EEmcTower *tower =tmatch.Tower();
00281 StMuTrack *track =NULL;
00282 out << *tower;
00283 TIter nextTrack(tmatch.Tracks());
00284 while((track=(StMuTrack *)nextTrack()))
00285 out << *track;
00286 }
00287
00288 void
00289 EEmcTTDisplay::Out(TString &out, EEmcTTMatch &tmatch)
00290 {
00291 const int bufLen=1024;
00292 static char buff[bufLen];
00293
00294
00295 EEmcTower *tower =tmatch.Tower();
00296 StMuTrack *track =NULL;
00297 TIter nextTrack(tmatch.Tracks());
00298 while((track=(StMuTrack *)nextTrack())) {
00299 sprintf(buff,"ADC(%s)=%4.1f pT=%.2f GeV/c\n",volumeName(*tower),tower->ADC(),track->pt());
00300 out.Append(buff);
00301 }
00302 }
00303
00304
00305
00306
00307
00308
00309
00310 char *
00311 EEmcTTDisplay::volumeName (int sec, int sub, int eta)
00312 {
00313 const int vnameLen=1024;
00314 static char vname[vnameLen];
00315 int kCase=0x00;
00316
00317 memset(vname,0x00,vnameLen);
00318 if( 0<=sec && sec<int(mNumSec ) ) kCase |=0x4; else kCase &=0x3;
00319 if( 0<=sub && sub<int(mNumSSec) ) kCase |=0x2; else kCase &=0x5;
00320 if( 0<=eta && eta<int(mNumEta ) ) kCase |=0x1; else kCase &=0x6;
00321
00322 switch(kCase) {
00323 case 0x07: sprintf(vname,"%02dT%1c%02d",sec+1,sub+'A',eta+1); break;
00324 case 0x06: sprintf(vname,"%02dT%1c" ,sec+1,sub+'A'); break;
00325 case 0x04: sprintf(vname,"%02d" ,sec+1) ; break;
00326 default: break;
00327 }
00328 return vname;
00329 }
00330
00331 char *
00332 EEmcTTDisplay::volumeName(const EEmcTower& tower)
00333 {
00334 return volumeName(tower.Sec(),tower.SubSec(),tower.Eta());
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385