17 #include "THaDetMap.h"
20 #include "THaCutList.h"
29 #include "THaApparatus.h"
41 const char* name,
const char* description,
42 THaApparatus* apparatus ) :
43 THaTrackingDetector(name,description,apparatus)
99 static const char*
const here =
"Setup";
101 THaApparatus *
app = GetApparatus();
104 fPrefix[0]=tolower(app->GetName()[0]);
107 cout <<
"No apparatus found" << endl;
114 string planenamelist;
118 {
"dc_tdc_time_per_channel",&
fNSperChan, kDouble},
120 {
"dc_plane_names",&planenamelist, kString},
121 {
"dc_version", &
fVersion, kInt, 0, optional},
136 cout <<
"Plane Name List: " << planenamelist << endl;
137 cout <<
"Drift Chambers: " <<
fNPlanes <<
" planes in " <<
fNChambers <<
" chambers" << endl;
139 vector<string> plane_names = Podd::vsplit(planenamelist);
142 cout <<
"ERROR: Number of planes " <<
fNPlanes <<
" doesn't agree with number of plane names " << plane_names.size() << endl;
147 fPlaneNames[i] =
new char[plane_names[i].length()+1];
151 char *desc =
new char[strlen(description)+100];
152 char *desc1=
new char[strlen(description)+100];
156 strcpy(desc, description);
157 strcat(desc,
" Plane ");
161 if( !newplane or newplane->IsZombie() ) {
162 Error( Here(here),
"Error creating Drift Chamber plane %s. Call expert.", name);
169 newplane->SetDebug(
fDebug);
176 sprintf(desc1,
"Ch%d",i+1);
181 cout <<
"Created Drift Chamber " << i+1 <<
", " << desc1 << endl;
190 THaTrackingDetector()
203 char EngineDID[] =
"xDC";
204 EngineDID[0] = toupper(GetApparatus()->
GetName()[0]);
206 static const char*
const here =
"Init()";
207 Error( Here(here),
"Error filling detectormap for %s.", EngineDID );
214 InitHitList(fDetMap,
"THcRawDCHit", fDetMap->GetTotNumChan()+1,
221 if( (status = THaTrackingDetector::Init( date )) )
222 return fStatus=status;
227 return fStatus=status;
236 return fStatus=status;
262 THaVar* vpresent = gHaVars->Find(
Form(
"%s.present",GetApparatus()->
GetName()));
266 return fStatus = kOK;
311 {
"dc_tdc_time_per_channel",&
fNSperChan, kDouble},
345 {
"dc_fix_lr", &
fFixLR, kInt},
379 DBRequest listOpt[]={
380 {
"dc_xpos",
fXPos, kDouble, (
UInt_t)fNPlanes, optional},
381 {
"dc_ypos",
fYPos, kDouble, (
UInt_t)fNPlanes, optional},
387 cout <<
"Plane counts:";
404 if( mode == kDefine && fIsSetup )
return kOK;
405 fIsSetup = ( mode == kDefine );
410 {
"stubtest",
"stub test",
"fStubTest" },
411 {
"nhit",
"Number of DC hits",
"fNhits" },
412 {
"tnhit",
"Number of good DC hits",
"fNthits" },
413 {
"trawhit",
"Number of true raw DC hits",
"fN_True_RawHits" },
414 {
"ntrack",
"Number of Tracks",
"fNDCTracks" },
415 {
"nsp",
"Number of Space Points",
"fNSp" },
416 {
"track_nsp",
"Number of spacepoints in track",
"fDCTracks.THcDCTrack.GetNSpacePoints()"},
417 {
"track_chisq",
"Chisq of track",
"fDCTracks.THcDCTrack.GetChisq()"},
418 {
"track_nhits",
"Number of hits in track",
"fDCTracks.THcDCTrack.GetNHits()"},
419 {
"track_sp1ID",
"CH 1 Spacepoint index",
"fDCTracks.THcDCTrack.GetSp1_ID()"},
420 {
"track_sp2ID",
"CH 2 Spacepoint index",
"fDCTracks.THcDCTrack.GetSp2_ID()"},
421 {
"track_hitpos",
"Position of each hit in track",
"fDCTracks.THcDCTrack.THcDCHit.GetPos()"},
422 {
"x",
"X at focal plane",
"fDCTracks.THcDCTrack.GetX()"},
423 {
"y",
"Y at focal plane",
"fDCTracks.THcDCTrack.GetY()"},
424 {
"xp",
"XP at focal plane",
"fDCTracks.THcDCTrack.GetXP()"},
425 {
"yp",
"YP at focal plane",
"fDCTracks.THcDCTrack.GetYP()"},
426 {
"x_fp",
"X at focal plane (golden track)",
"fX_fp_best"},
427 {
"y_fp",
"Y at focal plane( golden track)",
"fY_fp_best"},
428 {
"xp_fp",
"XP at focal plane (golden track)",
"fXp_fp_best"},
429 {
"yp_fp",
"YP at focal plane(golden track) ",
"fYp_fp_best"},
430 {
"chisq",
"chisq/dof (golden track) ",
"fChisq_best"},
431 {
"sp1_id",
" (golden track) ",
"fSp1_ID_best"},
432 {
"sp2_id",
" (golden track) ",
"fSp2_ID_best"},
433 {
"InsideDipoleExit",
" ",
"fInSideDipoleExit_best"},
434 {
"gtrack_nsp",
" Number of space points in golden track ",
"fNsp_best"},
435 {
"pos_best",
"Pos (golden track)",
"fPos_best"},
436 {
"dist_best",
"Dist (golden track)",
"fDist_best"},
437 {
"lr_best",
"LR sign (golden track)",
"fLR_best"},
438 {
"residual",
"Residuals",
"fResiduals"},
439 {
"residualExclPlane",
"Residuals",
"fResidualsExclPlane"},
440 {
"wireHitDid",
"Wire did have matched track hit",
"fWire_hit_did"},
441 {
"wireHitShould",
"Wire should have matched track hit",
"fWire_hit_should"},
444 return DefineVarsFromList( vars, mode );
459 for (vector<THcDriftChamberPlane*>::iterator ip =
fPlanes.begin();
460 ip !=
fPlanes.end(); ++ip)
delete *ip;
462 for (vector<THcDriftChamber*>::iterator ip =
fChambers.begin();
574 if(!gHaCuts->Result(
"Pedestal_event")) {
586 cout <<
" RAW_TOT_HITS = " <<
fNRawHits << endl;
587 cout <<
" Hit # " <<
"Plane " <<
" Wire " <<
" Raw TDC " << endl;
619 fPlanes[ip]->SubtractStartTime();
648 THaTrack* theTrack = NULL;
649 theTrack = AddTrack(tracks, 0.0, 0.0, 0.0, 0.0);
655 theTrack->SetFlag((
UInt_t) 0);
662 theTrack->SetTrkNum(itrack+1);
670 THaTrack* track =
static_cast<THaTrack*
>( tracks[it] );
680 track->SetTarget(0.0, ytar*100.0, xptar, yptar);
681 track->SetDp(delta*100.0);
682 Double_t ptemp = spectro->GetPcentral()*(1+track->GetDp()/100.0);
683 track->SetMomentum(ptemp);
685 spectro->TransportToLab(track->GetP(),track->GetTTheta(),track->GetTPhi(),pvect_temp);
686 track->SetPvect(pvect_temp);
736 Int_t wire_track_num=round(
fPlanes[plane]->CalcWireFromPos(track_pos));
737 if ( (wire_num-wire_track_num) ==0)
fWire_hit_did[plane]=wire_num;
741 Int_t wire_should = round(
fPlanes[ip]->CalcWireFromPos(track_pos));
749 printf(
"%s %2d %s %3d %s %3d \n",
" chamber = ",
fChambers[ich]->GetChamberNum(),
" number of hits = ",
fChambers[ich]->GetNHits(),
" number of spacepoints = ",
fChambers[ich]->GetNSpacePoints());
750 printf(
"%6s %-8s %-8s %6s %6s \n",
" ",
" ",
" ",
"Number",
"Number");
751 printf(
"%6s %-8s %-8s %6s %6s \n",
"Point",
"x",
"y",
" hits ",
"combos");
768 printf(
"%s %3d \n",
" Stub fit results Chamber = ",ich+1);
769 printf(
"%-5s %-18s %-18s %-18s %-18s\n",
"point",
"x_t",
"y_t",
"xp_t",
"yp_t");
770 printf(
"%-5s %-18s %-18s %-18s %-18s\n",
" ",
"[cm]",
"[cm]",
"[cm]",
"[cm]");
775 printf(
"%-5d % 15.10e % 15.10e % 15.10e % 15.10e \n",isp+1,spstubt[0],spstubt[1],spstubt[2],spstubt[3]);
785 std::vector<THcSpacePoint*> fSp;
793 fSp.push_back(static_cast<THcSpacePoint*>(spacepointarray->
At(isp)));
794 fSp[
fNSp]->fNChamber = nchamber;
795 fSp[
fNSp]->fNChamber_spnum = isp;
804 for(
Int_t isp2=ch1_nsp;isp2<ch1_nsp+ch2_nsp;isp2++) {
809 Double_t dposx = spstub1[0] - spstub2[0];
816 dposy = spstub1[1] - spstub2[1];
818 Double_t dposxp = spstub1[2] - spstub2[2];
819 Double_t dposyp = spstub1[3] - spstub2[3];
842 for(
Int_t isp2=ch1_nsp;isp2<ch1_nsp+ch2_nsp;isp2++) {
878 std::vector<THcSpacePoint*> fSp;
891 fSp.push_back(static_cast<THcSpacePoint*>(spacepointarray->
At(isp)));
892 fSp[
fNSp]->fNChamber = nchamber;
893 fSp[
fNSp]->fNChamber_spnum = isp;
895 if (ich==0 &&
fNSp>50)
break;
922 for(
Int_t isp2=isp1+1;isp2<
fNSp;isp2++) {
927 Double_t dposx = spstub1[0] - spstub2[0];
938 dposy = spstub1[1] - spstub2[1];
940 Double_t dposxp = spstub1[2] - spstub2[2];
941 Double_t dposyp = spstub1[3] - spstub2[3];
983 for(
Int_t itrack=0;itrack<sptracks;itrack++) {
984 Int_t track=stub_tracks[itrack];
1025 if (
fdebuglinkstubs) cout <<
"EPIC FAIL 2: Too many tracks found in THcDC::LinkStubs maxtracks = " <<
MAXTRACKS << endl;
1045 if (fSp[isp]->GetSetStubFlag()) {
1050 if (
fdebuglinkstubs) cout <<
"EPIC FAIL 3: Too many tracks found in THcDC::LinkStubs" << endl;
1059 cout <<
" Number of tracks from link stubs = " <<
fNDCTracks << endl;
1060 printf(
"%s %s \n",
"Track",
"Plane Wire ");
1063 printf(
"%-5d ",itrack+1);
1075 const Int_t raycoeffmap[]={4,5,2,3};
1080 for(
Int_t ihit=0;ihit < TrackHits;ihit++) {
1081 TT[irayp] += (coords[ihit]*
fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]])/
pow(wiresigma[ihit],2);
1087 AA[irayp][jrayp] = 0.0;
1089 AA[irayp][jrayp] = AA[jrayp][irayp];
1091 for(
Int_t ihit=0;ihit <TrackHits ;ihit++) {
1092 AA[irayp][jrayp] +=
fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1093 fPlaneCoeffs[planes[ihit]][raycoeffmap[jrayp]]/
pow(wiresigma[ihit],2);
1107 sumcoord +=
fPlaneCoeffs[iplane][raycoeffmap[ir]]*dray[ir];
1109 TrackCoord[iplane]=sumcoord;
1118 Int_t plusminus[MAXHITS];
1119 Int_t plusminusknown[MAXHITS];
1123 Int_t planes[TrackHits];
1126 for(
Int_t ihit=0;ihit<MAXHITS;ihit++) {
1127 plusminusknown[ihit]=0;
1129 Int_t nplusminus=1<<TrackHits;
1130 for(
Int_t pmloop=0;pmloop<nplusminus;pmloop++) {
1132 for(
Int_t ihit=0;ihit<TrackHits;ihit++) {
1133 if(plusminusknown[ihit]!=0) {
1134 plusminus[ihit] = plusminusknown[ihit];
1136 if(pmloop & iswhit) {
1137 plusminus[ihit] = 1;
1139 plusminus[ihit] = -1;
1144 for(
Int_t ihit=0;ihit<TrackHits;ihit++) {
1150 FitLineToTrack(TrackHits,coords,planes,wiresigma,TrackCoord,save_ray);
1152 for(
Int_t ihit=0;ihit < TrackHits;ihit++) {
1153 Double_t residual = coords[ihit] - TrackCoord[planes[ihit]];
1154 chi2 +=
pow(residual/wiresigma[ihit],2);
1156 if (chi2 < minchi2) {
1158 tr->
SetVector(save_ray[0], save_ray[1], 0.0, save_ray[2], save_ray[3]);
1159 for(
Int_t ihit=0;ihit < TrackHits;ihit++) {
1160 tr->
SetHitLR(ihit, plusminus[ihit]);
1161 tr->
SetCoord(planes[ihit], TrackCoord[planes[ihit]]);
1162 Double_t residual = coords[ihit] -TrackCoord[planes[ihit]] ;
1172 const Int_t raycoeffmap[]={4,5,2,3};
1173 for(
Int_t ihit=0;ihit<TrackHits;ihit++) {
1192 if (ihit != ipl_hit) {
1193 TT[irayp] += (coords[ihit]*
1202 AA[irayp][jrayp] = 0.0;
1204 AA[irayp][jrayp] = AA[jrayp][irayp];
1212 if (ihit != ipl_hit) {
1213 AA[irayp][jrayp] +=
fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1230 coord +=
fPlaneCoeffs[planes[ipl_hit]][raycoeffmap[ir]]*dray[ir];
1233 Double_t residual = coords[ipl_hit] - coord;
1250 const Int_t raycoeffmap[]={4,5,2,3};
1259 while (CheckResid) {
1260 Int_t MaxResidHitIndex = -1;
1271 coords[ihit] = hit->
GetPos()
1274 coords[ihit] = hit->
GetPos()
1280 coords[ihit] = hit->
GetPos()
1318 AA[irayp][jrayp] = 0.0;
1320 AA[irayp][jrayp] = AA[jrayp][irayp];
1327 AA[irayp][jrayp] +=
fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1346 coord +=
fPlaneCoeffs[iplane][raycoeffmap[ir]]*dray[ir];
1349 theDCTrack->
SetCoord(iplane,coord);
1360 if (abs(residual) > MaxResid) {
1361 MaxResidHitIndex =ihit;
1362 MaxResid = abs(residual);
1371 theDCTrack->
SetVector(dray[0], dray[1], 0.0, dray[2], dray[3]);
1375 for(
Int_t ipl_hit=0;ipl_hit < theDCTrack->
GetNHits();ipl_hit++) {
1388 if (ihit != ipl_hit) {
1389 TT[irayp] += (coords[ihit]*
1398 AA[irayp][jrayp] = 0.0;
1400 AA[irayp][jrayp] = AA[jrayp][irayp];
1408 if (ihit != ipl_hit) {
1409 AA[irayp][jrayp] +=
fPlaneCoeffs[planes[ihit]][raycoeffmap[irayp]]*
1426 coord +=
fPlaneCoeffs[planes[ipl_hit]][raycoeffmap[ir]]*dray[ir];
1429 Double_t residual = coords[ipl_hit] - coord;
1440 theDCTrack->
RemoveHit(MaxResidHitIndex);
1444 if (NLoops == NLoopsMax) CheckResid =
kFALSE;
1455 if(fNDCTracks == 2) {
1465 hit=theDCTrack2->
GetHit(ihit);
1471 theDCTrack1->
GetRay(ray1);
1472 theDCTrack2->
GetRay(ray2);
1537 printf(
"%5s %-14s %-14s %-14s %-14s %-10s %-10s \n",
"Track",
"x_t",
"y_t",
"xp_t",
"yp_t",
"chi2",
"DOF");
1538 printf(
"%5s %-14s %-14s %-14s %-14s %-10s %-10s \n",
" ",
"[cm]",
"[cm]",
"[rad]",
"[rad]",
" ",
" ");
1541 printf(
"%-5d %14.6e %14.6e %14.6e %14.6e %10.3e %3d \n", itr+1,theDCTrack->
GetX(),theDCTrack->
GetY(),theDCTrack->
GetXP(),theDCTrack->
GetYP(),theDCTrack->
GetChisq(),theDCTrack->
GetNFree());
1544 printf(
"%s %5d \n",
"Hit info for track number = ",itr+1);
1545 printf(
"%5s %-15s %-15s %-15s \n",
"Plane",
"WIRE_COORD",
"Fit postiion",
"Residual");
1553 coords_temp = hit->
GetPos()
1556 coords_temp = hit->
GetPos()
1561 coords_temp = hit->
GetPos()
1567 printf(
"%-5d %15.7e %15.7e %15.7e \n",plane+1,coords_temp,theDCTrack->
GetCoord(plane),theDCTrack->
GetResidual(plane));
1601 Double_t denom = ray[2]*fPlaneCoeffs[plane][6]
1602 + ray[3]*fPlaneCoeffs[plane][7]
1603 + fPlaneCoeffs[plane][8];
1607 DpsiFun = DpsiFun/denom;
Drift chamber wire hit info.
void SetResidual(Int_t ip, Double_t coord)
Int_t GetTimeRaw(UInt_t iHit=0) const
Gets raw TDC time. In channels.
std::string GetName(const std::string &scope_name)
virtual Int_t FillMap(THaDetMap *detmap, const char *detectorname)
Double_t * fPlaneTimeZero
void SetSp2_ID(Int_t isp2)
Double_t * fSpace_Point_Criterion
std::vector< THcDriftChamber * > fChambers
Double_t DpsiFun(Double_t ray[4], Int_t plane)
void MissReport(const char *name)
void SetSp1_ID(Int_t isp1)
Class for a a single Hall C horizontal drift chamber plane.
virtual void CalculateTargetQuantities(THaTrack *track, Double_t &gbeam_y, Double_t &xptar, Double_t &ytar, Double_t &yptar, Double_t &delta)
Transport focal plane track to target.
Double_t * fResidualsExclPlane
THcRawTdcHit & GetRawTdcHit()
void Setup(const char *name, const char *description)
virtual void RemoveHit(Int_t RemoveHitIndex)
THcSpacePoint * GetSpacePoint(Int_t i) const
Double_t GetChisq() const
UInt_t GetNHits() const
Gets the number of set hits.
TClonesArray * fRawHitList
Analyze a package of horizontal drift chambers.
virtual EStatus Init(const TDatime &run_time)
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual void AddSpacePoint(THcSpacePoint *sp)
Double_t GetSp1_ID() const
void GetRay(Double_t *ray) const
virtual Int_t CoarseTrack(TClonesArray &tracks)
double pow(double, double)
Double_t GetHitDist(Int_t ihit)
Double_t GetCoord(Int_t ip) const
Int_t GetHitLR(Int_t ihit)
Int_t fdebugprintdecodeddc
Double_t GetCoord() const
Int_t GetPlaneNum() const
void EfficiencyPerWire(Int_t golden_track_index)
Double_t * fWire_hit_should
void Error(const char *location, const char *msgfmt,...)
TMatrixT< Double_t > & Invert(Double_t *det=0)
Class representing a single hit DC.
void SetHMSStyleFlag(Int_t flag)
void SetChisq(Double_t chi2)
void InitHitList(THaDetMap *detmap, const char *hitclass, Int_t maxhits, Int_t tdcref_cut=0, Int_t adcref_cut=0)
Save the electronics module to detector mapping and initialize a hit array of hits of class hitclass...
void SetFocalPlaneBestTrack(Int_t golden_track_index)
void SetVector(Double_t x, Double_t y, Double_t z, Double_t xp, Double_t yp)
virtual void Delete(Option_t *option="")
void SetDoubleResidual(Int_t ip, Double_t coord)
Int_t GetNChamber(Int_t plane) const
char * Form(const char *fmt,...)
void CreateMissReportParms(const char *prefix)
Bool_t InsideDipoleExitWindow(Double_t x_fp, Double_t xp_fp, Double_t y_fp, Double_t yp_fp)
THcDCHit * GetHit(Int_t ihit)
virtual Int_t End(THaRunBase *run=0)
Bool_t fInSideDipoleExit_best
Class representing for drift chamber wire (or other device with a single multihit TDC channel per det...
virtual Int_t ReadDatabase(const TDatime &date)
R__EXTERN class THcDetectorMap * gHcDetectorMap
virtual Int_t ApplyCorrections(void)
static const UInt_t MAXTRACKS
Double_t GetResidualExclPlane(Int_t ip) const
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
Int_t fUseNewFindSpacePoints
Int_t fFixPropagationCorrection
void SetCoord(Int_t ip, Double_t coord)
THcDCHit * GetHit(Int_t i) const
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
Double_t GetWireSigma() const
void NewTrackFit(UInt_t TrackIndex)
Double_t GetSp2_ID() const
virtual Int_t Decode(const THaEvData &)
Int_t GetNSpacePoints() const
void FitLineToTrack(Int_t TrackHits, Double_t coords[], Int_t planes[], Double_t wiresigma[], Double_t TrackCoord[], Double_t save_ray[])
virtual Int_t FineTrack(TClonesArray &tracks)
void SetHitLR(Int_t ihit, Int_t lrtemp)
Subdetector class for a single drift chamber with several planes.
Double_t GetResidual(Int_t ip) const
R__EXTERN class THcParmList * gHcParms
TObject * At(Int_t idx) const
Double_t fTrackLargeResidCut
void SetResidualExclPlane(Int_t ip, Double_t coord)
std::vector< THcDriftChamberPlane * > fPlanes
void SetNFree(Int_t nfree)
virtual Int_t DecodeToHitList(const THaEvData &evdata, Bool_t suppress=kFALSE)
Populate the hitlist from the raw event data.
Class representing a track found from linking DC Space points.
A standard Hall C spectrometer apparatus.