diff --git a/src/THcDC.cxx b/src/THcDC.cxx index b7c17f39a4813c364f01292f2d9ab668e1e33039..5a295b8066be1dcec0a7abbd0e59e824b33c262b 100644 --- a/src/THcDC.cxx +++ b/src/THcDC.cxx @@ -299,14 +299,14 @@ Int_t THcDC::ReadDatabase( const TDatime& date ) {0} }; gHcParms->LoadParmValues((DBRequest*)&list,prefix); - + fDebugDC=0; if(fNTracksMaxFP <= 0) fNTracksMaxFP = 10; // if(fNTracksMaxFP > HNRACKS_MAX) fNTracksMaxFP = NHTRACKS_MAX; - cout << "Plane counts:"; + if (fDebugDC) cout << "Plane counts:"; for(Int_t i=0;i<fNPlanes;i++) { - cout << " " << fNWires[i]; + if (fDebugDC) cout << " " << fNWires[i]; } - cout << endl; + if (fDebugDC) cout << endl; fIsInit = true; @@ -405,7 +405,8 @@ Int_t THcDC::Decode( const THaEvData& evdata ) { ClearEvent(); - + Int_t num_event = evdata.GetEvNum(); + if (fDebugDC) cout << " event num = " << num_event << endl; // Get the Hall C style hitlist (fRawHitList) for this event fNhits = THcHitList::DecodeToHitList(evdata); @@ -423,14 +424,14 @@ Int_t THcDC::Decode( const THaEvData& evdata ) // fRawHitList is TClones array of THcRawDCHit objects for(Int_t ihit = 0; ihit < fNRawHits ; ihit++) { THcRawDCHit* hit = (THcRawDCHit *) fRawHitList->At(ihit); - // cout << ihit << " : " << hit->fPlane << ":" << hit->fCounter << " : " + // if (fDebugDC) cout << ihit << " : " << hit->fPlane << ":" << hit->fCounter << " : " // << endl; for(Int_t imhit = 0; imhit < hit->fNHits; imhit++) { - // cout << " " << imhit << " " << hit->fTDC[imhit] + // if (fDebugDC) cout << " " << imhit << " " << hit->fTDC[imhit] // << endl; } } - // cout << endl; + // if (fDebugDC) cout << endl; #endif return fNhits; @@ -453,7 +454,6 @@ Int_t THcDC::CoarseTrack( TClonesArray& /* tracks */ ) // // static const Double_t sqrt2 = TMath::Sqrt(2.); for(Int_t i=0;i<fNChambers;i++) { - fChambers[i]->FindSpacePoints(); fChambers[i]->CorrectHitTimes(); fChambers[i]->LeftRight(); @@ -501,12 +501,13 @@ void THcDC::LinkStubs() fSp.clear(); fSp.reserve(10); // Make a vector of pointers to the SpacePoints - cout << "Linking " << fChambers[0]->GetNSpacePoints() + if (fDebugDC) cout << "Linking " << fChambers[0]->GetNSpacePoints() << " and " << fChambers[1]->GetNSpacePoints() << " stubs" << endl; for(Int_t ich=0;ich<fNChambers;ich++) { Int_t nchamber=fChambers[ich]->GetChamberNum(); TClonesArray* spacepointarray = fChambers[ich]->GetSpacePointsP(); for(Int_t isp=0;isp<fChambers[ich]->GetNSpacePoints();isp++) { + if (fDebugDC) cout << " Chamber = " << nchamber << " number of space pts = " << fNSp << endl; fSp.push_back(static_cast<THcSpacePoint*>(spacepointarray->At(isp))); fSp[fNSp]->fNChamber = nchamber; fNSp++; @@ -518,7 +519,7 @@ void THcDC::LinkStubs() Double_t stubminxp = 999999; Double_t stubminyp = 999999; Int_t stub_tracks[MAXTRACKS]; - + if (fDebugDC) cout << " single stub , fsnp" << fSingleStub << fNSp << endl; if(!fSingleStub) { for(Int_t isp1=0;isp1<fNSp-1;isp1++) { Int_t sptracks=0; @@ -559,6 +560,7 @@ void THcDC::LinkStubs() && (TMath::Abs(dposxp) < fXptTrCriterion) && (TMath::Abs(dposyp) < fYptTrCriterion)) { if(newtrack) { + if (fDebugDC) cout << " new track" << endl; assert(sptracks==0); //stubtest=1; Used in h_track_tests.f // Make a new track if there are not to many @@ -576,12 +578,13 @@ void THcDC::LinkStubs() // (But could replace a SP?) ntracks_fp++; } else { - cout << "EPIC FAIL 1: Too many tracks found in THcDC::LinkStubs" << endl; + if (fDebugDC) cout << "EPIC FAIL 1: Too many tracks found in THcDC::LinkStubs" << endl; ntracks_fp=0; // Do something here to fail this event return; } } else { + if (fDebugDC) cout << " check if another space point in same chamber" << endl; // Check if there is another space point in the same chamber for(Int_t itrack=0;itrack<sptracks;itrack++) { Int_t track=stub_tracks[itrack]; @@ -616,7 +619,7 @@ void THcDC::LinkStubs() } // End check for dup on copy } // End copy of track } else { - cout << "EPIC FAIL 2: Too many tracks found in THcDC::LinkStubs" << endl; + if (fDebugDC) cout << "EPIC FAIL 2: Too many tracks found in THcDC::LinkStubs" << endl; ntracks_fp=0; // Do something here to fail this event return; // Max # of allowed tracks @@ -637,7 +640,7 @@ void THcDC::LinkStubs() fTrackSP[ntracks_fp].spID[0]=isp; ntracks_fp++; } else { - cout << "EPIC FAIL 3: Too many tracks found in THcDC::LinkStubs" << endl; + if (fDebugDC) cout << "EPIC FAIL 3: Too many tracks found in THcDC::LinkStubs" << endl; ntracks_fp=0; // Do something here to fail this event return; // Max # of allowed tracks @@ -657,7 +660,7 @@ void THcDC::LinkStubs() } /// /// - cout << "Found " << ntracks_fp << " tracks"<<endl; + if (fDebugDC) cout << "Found " << ntracks_fp << " tracks"<<endl; } // Primary track fitting routine @@ -736,6 +739,7 @@ void THcDC::TrackFit() hdc_track_coord[iplane] += fPlaneCoeffs[iplane][raycoeffmap[ir]]*dray[ir]; } } + if (fDebugDC) { cout << "Residuals:" << endl; for(Int_t ihit=0;ihit < fTrackSP[itrack].fNHits;ihit++) { THcDCHit* hit=fTrackSP[itrack].fHits[ihit]; @@ -744,7 +748,7 @@ void THcDC::TrackFit() cout << " " << plane << ": " << residual << endl; chi2 += pow(residual/fSigma[plane],2); } - + } } } diff --git a/src/THcDC.h b/src/THcDC.h index b324a08c55b3419d3fe092c066f88d2cb89eb88e..1c60ed60a21a51db3d23a798c59b9b3a7b7dfb3d 100644 --- a/src/THcDC.h +++ b/src/THcDC.h @@ -74,7 +74,7 @@ public: THcDC(); // for ROOT I/O protected: - + Int_t fDebugDC; // Calibration // Per-event data diff --git a/src/THcDriftChamber.cxx b/src/THcDriftChamber.cxx index 97c32bce370b3a66675144bfbb65e62ef2f5d5fd..4ac8419201926ed35f461822b3dd9bb49b89fc65 100644 --- a/src/THcDriftChamber.cxx +++ b/src/THcDriftChamber.cxx @@ -57,9 +57,9 @@ void THcDriftChamber::Setup(const char* name, const char* description) THaApparatus *app = GetApparatus(); if(app) { - cout << app->GetName() << endl; + if (fDebugDriftCh) cout << app->GetName() << endl; } else { - cout << "No apparatus found" << endl; + if (fDebugDriftCh) cout << "No apparatus found" << endl; } prefix[0]=tolower(app->GetName()[0]); @@ -78,7 +78,7 @@ THcDriftChamber::THcDriftChamber( ) : //_____________________________________________________________________________ Int_t THcDriftChamber::Decode( const THaEvData& evdata ) { - cout << "THcDriftChamber::Decode called" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::Decode called" << endl; return 0; } @@ -99,7 +99,7 @@ THaAnalysisObject::EStatus THcDriftChamber::Init( const TDatime& date ) void THcDriftChamber::AddPlane(THcDriftChamberPlane *plane) { - cout << "Added plane " << plane->GetPlaneNum() << " to chamber " << fChamberNum << " " << fNPlanes << " " << YPlaneInd << " " << YPlanePInd << endl; + if (fDebugDriftCh) cout << "Added plane " << plane->GetPlaneNum() << " to chamber " << fChamberNum << " " << fNPlanes << " " << YPlaneInd << " " << YPlanePInd << endl; plane->SetPlaneIndex(fNPlanes); fPlanes.push_back(plane); // HMS Specific @@ -127,7 +127,7 @@ void THcDriftChamber::AddPlane(THcDriftChamberPlane *plane) Int_t THcDriftChamber::ReadDatabase( const TDatime& date ) { - cout << "THcDriftChamber::ReadDatabase()" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::ReadDatabase()" << endl; char prefix[2]; prefix[0]=tolower(GetApparatus()->GetName()[0]); prefix[1]='\0'; @@ -147,11 +147,11 @@ Int_t THcDriftChamber::ReadDatabase( const TDatime& date ) fMaxHits = fParent->GetMaxHits(fChamberNum); fMinCombos = fParent->GetMinCombos(fChamberNum); - cout << "Chamber " << fChamberNum << " Min/Max: " << fMinHits << "/" << fMaxHits << endl; + if (fDebugDriftCh) cout << "Chamber " << fChamberNum << " Min/Max: " << fMinHits << "/" << fMaxHits << endl; fSpacePointCriterion = fParent->GetSpacePointCriterion(fChamberNum); fSpacePointCriterion2 = fSpacePointCriterion*fSpacePointCriterion; - cout << " cham = " << fChamberNum << " Set yplane num " << YPlaneNum << " "<< YPlanePNum << endl; + if (fDebugDriftCh) cout << " cham = " << fChamberNum << " Set yplane num " << YPlaneNum << " "<< YPlanePNum << endl; // Generate the HAA3INV matrix for all the acceptable combinations // of hit planes. Try to make it as generic as possible // pindex=0 -> Plane 1 missing, pindex5 -> plane 6 missing. Won't @@ -196,7 +196,7 @@ Int_t THcDriftChamber::ReadDatabase( const TDatime& date ) } Int_t bitpat = allplanes & ~(1<<ipm1) & ~(1<<ipm2); // Should check that it is invertable - // cout << bitpat << " Determinant: " << AA3->Determinant() << endl; + // if (fDebugDriftCh) cout << bitpat << " Determinant: " << AA3->Determinant() << endl; AA3->Invert(); fAA3Inv[bitpat] = AA3; } @@ -205,7 +205,7 @@ Int_t THcDriftChamber::ReadDatabase( const TDatime& date ) #if 0 for(map<int,TMatrixD*>::iterator pm=fHaa3map.begin(); pm != fHaa3map.end(); pm++) { - cout << setbase(8) << pm->first << endl; + if (fDebugDriftCh) cout << setbase(8) << pm->first << endl; fAA3Inv[pm->first]->Print(); } #endif @@ -221,7 +221,7 @@ Int_t THcDriftChamber::DefineVariables( EMode mode ) if( mode == kDefine && fIsSetup ) return kOK; fIsSetup = ( mode == kDefine ); - + fDebugDriftCh=0; // Register variables in global list // RVarDef vars[] = { @@ -246,7 +246,7 @@ void THcDriftChamber::ProcessHits( void) fNhits++; } } - // cout << "ThcDriftChamber::ProcessHits() " << fNhits << " hits" << endl; + // if (fDebugDriftCh) cout << "ThcDriftChamber::ProcessHits() " << fNhits << " hits" << endl; } @@ -263,6 +263,7 @@ Int_t THcDriftChamber::FindSpacePoints( void ) fNSpacePoints=0; fEasySpacePoint = 0; + if (fDebugDriftCh) cout << " starting build up array of hits" << endl; // Should really build up array of hits if(fNhits >= fMinHits && fNhits < fMaxHits) { /* Has this list of hits already been cut the way it should have at this point? */ @@ -271,14 +272,14 @@ Int_t THcDriftChamber::FindSpacePoints( void ) Int_t ip=thishit->GetPlaneNum(); // This is the absolute plane mumber if(ip==YPlaneNum) yplane_hitind = ihit; if(ip==YPlanePNum) yplanep_hitind = ihit; - // cout << " hit = " << ihit << " " << ip <<" " << thishit->GetWireNum()<<" " << thishit->GetPos()<< " " << thishit->GetPlaneNum()<< endl; + if (fDebugDriftCh) cout << " hit = " << ihit << " " << ip <<" " << thishit->GetWireNum() << " " << thishit->GetRawTime()<<" " << thishit->GetPos()<< " " << endl; } // fPlanes is the array of planes for this chamber. - // cout << fPlanes[YPlaneInd]->GetNHits() << " " + // if (fDebugDriftCh) cout << fPlanes[YPlaneInd]->GetNHits() << " " // << fPlanes[YPlanePInd]->GetNHits() << " " << endl; - // cout << " Yplane ind " << YPlaneInd << " " << YPlanePInd << endl; + // if (fDebugDriftCh) cout << " Yplane ind " << YPlaneInd << " " << YPlanePInd << endl; if (fPlanes[YPlaneInd]->GetNHits() == 1 && fPlanes[YPlanePInd]->GetNHits() == 1) { - // cout <<" Yplane info :" << fHits[yplane_hitind]->GetWireNum() << " " + // if (fDebugDriftCh) cout <<" Yplane info :" << fHits[yplane_hitind]->GetWireNum() << " " // << fHits[yplane_hitind]->GetPos() << " " // << fHits[yplanep_hitind]->GetWireNum() << " " // << fHits[yplanep_hitind]->GetPos() << " " @@ -288,33 +289,36 @@ Int_t THcDriftChamber::FindSpacePoints( void ) && TMath::Abs(fHits[yplane_hitind]->GetPos() - fHits[yplanep_hitind]->GetPos()) < fSpacePointCriterion && fNhits <= 6) { // An easy case, probably one hit per plane - // cout << " call FindEasySpacePoint" << endl; fEasySpacePoint = FindEasySpacePoint(yplane_hitind, yplanep_hitind); + if (fDebugDriftCh) cout << " call FindEasySpacePoint" << " # of space points = " << fNSpacePoints << endl; } if(!fEasySpacePoint) { // It's not easy - // cout << " call FindHardSpacePoints" << endl; - // cout << " nhits = " << fNhits << " " << fPlanes[YPlaneInd]->GetNHits() << " " << fPlanes[YPlanePInd]->GetNHits() << endl; + if (fDebugDriftCh) cout << " call FindHardSpacePoints" << endl; + if (fDebugDriftCh) cout << " nhits = " << fNhits << " " << fPlanes[YPlaneInd]->GetNHits() << " " << fPlanes[YPlanePInd]->GetNHits() << endl; FindHardSpacePoints(); + if (fDebugDriftCh) cout << " call FindHardSpacePoint" << " # of space points = " << fNSpacePoints << endl; } // We have our space points for this chamber - // cout << fNSpacePoints << " Space Points found" << endl; + if (fDebugDriftCh) cout << fNSpacePoints << " Space Points found" << endl; if(fNSpacePoints > 0) { if(fRemove_Sppt_If_One_YPlane == 1) { // The routine is specific to HMS Int_t ndest=DestroyPoorSpacePoints(); - // cout << ndest << " Poor space points destroyed" << endl; + if (fDebugDriftCh) cout << ndest << " Poor space points destroyed" << " # of space points = " << fNSpacePoints << endl; // Loop over space points and remove those with less than 4 planes // hit and missing hits in Y,Y' planes } - // if(fNSpacePoints == 0) cout << "DestroyPoorSpacePoints() killed SP" << endl; + // if(fNSpacePoints == 0) if (fDebugDriftCh) cout << "DestroyPoorSpacePoints() killed SP" << endl; Int_t nadded=SpacePointMultiWire(); - if (nadded) cout << nadded << " Space Points added with SpacePointMultiWire()" << endl; + if (nadded) if (fDebugDriftCh) cout << nadded << " Space Points added with SpacePointMultiWire()" << endl; ChooseSingleHit(); + if (fDebugDriftCh) cout << " After choose single hit " << " # of space points = " << fNSpacePoints << endl; SelectSpacePoints(); - // if(fNSpacePoints == 0) cout << "SelectSpacePoints() killed SP" << endl; + if (fDebugDriftCh) cout << " After select space point " << " # of space points = " << fNSpacePoints << endl; + // if(fNSpacePoints == 0) if (fDebugDriftCh) cout << "SelectSpacePoints() killed SP" << endl; } - // cout << fNSpacePoints << " Space Points remain" << endl; + // if (fDebugDriftCh) cout << fNSpacePoints << " Space Points remain" << endl; // Add these space points to the total list of space points for the // the DC package. Do this in THcDC.cxx. #if 0 @@ -343,7 +347,7 @@ Int_t THcDriftChamber::FindEasySpacePoint(Int_t yplane_hitind,Int_t yplanep_hiti // a space point. Int_t easy_space_point=0; - // cout << "Doing Find Easy Space Point" << endl; + // if (fDebugDriftCh) cout << "Doing Find Easy Space Point" << endl; Double_t yt = (fHits[yplane_hitind]->GetPos() + fHits[yplanep_hitind]->GetPos())/2.0; Double_t xt = 0.0; Int_t num_xhits = 0; @@ -353,7 +357,7 @@ Int_t THcDriftChamber::FindEasySpacePoint(Int_t yplane_hitind,Int_t yplanep_hiti THcDCHit* thishit = fHits[ihit]; if(ihit!=yplane_hitind && ihit!=yplanep_hitind) { // x-like hit // ysp and xsp are from h_generate_geometry - // cout << ihit << " " << thishit->GetPos() << " " << yt << " " << thishit->GetWirePlane()->GetYsp() << " " << thishit->GetWirePlane()->GetXsp() << endl; + if (fDebugDriftCh) cout << ihit << " " << thishit->GetPos() << " " << yt << " " << thishit->GetWirePlane()->GetYsp() << " " << thishit->GetWirePlane()->GetXsp() << endl; x_pos[ihit] = (thishit->GetPos() -yt*thishit->GetWirePlane()->GetYsp()) /thishit->GetWirePlane()->GetXsp(); @@ -365,19 +369,19 @@ Int_t THcDriftChamber::FindEasySpacePoint(Int_t yplane_hitind,Int_t yplanep_hiti } Double_t max_dist = TMath::Sqrt(fSpacePointCriterion/2.); xt = (num_xhits>0?xt/num_xhits:0.0); - // cout << " mean x = "<< xt << " max dist = " << max_dist << endl; + if (fDebugDriftCh) cout << " mean x = "<< xt << " max dist = " << max_dist << endl; easy_space_point = 1; // Assume we have an easy space point // Rule it out if x points don't cluster well enough for(Int_t ihit=0;ihit<fNhits;ihit++) { - // cout << "Hit " << ihit << " " << x_pos[ihit] << " " << TMath::Abs(xt-x_pos[ihit]) << endl; + if (fDebugDriftCh) cout << "Hit " << ihit+1 << " " << x_pos[ihit] << " " << TMath::Abs(xt-x_pos[ihit]) << endl; if(ihit!=yplane_hitind && ihit!=yplanep_hitind) { // x-like hit if(TMath::Abs(xt-x_pos[ihit]) >= max_dist) { easy_space_point=0; break;} } } if(easy_space_point) { // Register the space point - // cout << "Easy Space Point " << xt << " " << yt << endl; THcSpacePoint* sp = (THcSpacePoint*)fSpacePoints->ConstructedAt(fNSpacePoints++); + if (fDebugDriftCh) cout << "Easy Space Point " << xt << " " << yt << " Space point # =" << fNSpacePoints << endl; sp->Clear(); sp->SetXY(xt, yt); for(Int_t ihit=0;ihit<fNhits;ihit++) { @@ -443,6 +447,7 @@ Int_t THcDriftChamber::FindHardSpacePoints() } } // Loop over all valid combinations and build space points + if (fDebugDriftCh) cout << "looking for hard Space Point combos = " << ncombos << "# of sp pts = " << fNSpacePoints<< endl; for(Int_t icombo=0;icombo<ncombos;icombo++) { THcDCHit* hits[4]; hits[0]=combos[icombo].pair1->hit1; @@ -495,6 +500,7 @@ Int_t THcDriftChamber::FindHardSpacePoints() } } sp->IncCombos(); + //cout << " number of combos = " << sp->GetCombos() << endl; // Terminate loop since this combo can only belong to one space point break; } @@ -503,6 +509,7 @@ Int_t THcDriftChamber::FindHardSpacePoints() // Create a new space point if more than 2*space_point_criteria if(fNSpacePoints < MAX_SPACE_POINTS) { if(add_flag) { + if (fDebugDriftCh) cout << " add glag = " << add_flag << " space pts = " << fNSpacePoints << endl ; THcSpacePoint* sp = (THcSpacePoint*)fSpacePoints->ConstructedAt(fNSpacePoints++); sp->Clear(); sp->SetXY(xt, yt); @@ -532,8 +539,10 @@ Int_t THcDriftChamber::FindHardSpacePoints() if(hits[0] != hits[3] && hits[1] != hits[3]) { sp->AddHit(hits[3]); } + if (fDebugDriftCh) cout << "1st hard Space Point " << xt << " " << yt << " Space point # =" << fNSpacePoints << endl; }//End check on 0 space points }//End loop over combos + if (fDebugDriftCh) cout << " finished findspacept # of sp pts = " << fNSpacePoints << endl; return(fNSpacePoints); } @@ -572,7 +581,7 @@ Int_t THcDriftChamber::DestroyPoorSpacePoints() && nhitsperplane[YPlanePInd] > 0) { spacepointsgood[ngood++] = isp; // Build list of good points } else { - // cout << "Missing Y-hit!!"; + // if (fDebugDriftCh) cout << "Missing Y-hit!!"; } } @@ -584,7 +593,18 @@ Int_t THcDriftChamber::DestroyPoorSpacePoints() if(osp > isp) { // Does this work, or do we have to copy each member? // If it doesn't we should overload the = operator - (*fSpacePoints)[isp] = (*fSpacePoints)[osp]; + //(*fSpacePoints)[isp] = (*fSpacePoints)[osp]; + THcSpacePoint* spi = (THcSpacePoint*)(*fSpacePoints)[isp]; + THcSpacePoint* spo = (THcSpacePoint*)(*fSpacePoints)[osp]; + spi->Clear(); + Double_t xt,yt; + xt=spo->GetX(); + yt=spo->GetY(); + spi->SetXY(xt, yt); + for(Int_t ihit=0;ihit<spo->GetNHits();ihit++) { + THcDCHit* hit = spo->GetHit(ihit); + spi->AddHit(hit); + } } } return nremoved; @@ -611,15 +631,21 @@ Int_t THcDriftChamber::SpacePointMultiWire() Int_t nplanes_single; Int_t nsp_tot=fNSpacePoints; + Int_t nsp_totl=fNSpacePoints; + if (fDebugDriftCh) cout << "Start Multiwire # of sp pts = " << nsp_totl << endl; - for(Int_t isp=0;isp<fNSpacePoints;isp++) { + for(Int_t isp=0;isp<nsp_totl;isp++) { Int_t nplanes_hit = 0; // Number of planes with hits Int_t nplanes_mult = 0; // Number of planes with multiple hits Int_t nsp_new = 1; Int_t newsp_num=0; + if (fDebugDriftCh) cout << "Looping thru space pts at # = " << isp << " total = " << fNSpacePoints << endl; for(Int_t ip=0;ip<fNPlanes;ip++) { nhitsperplane[ip] = 0; + for(Int_t ih=0;ih<MAX_HITS_PER_POINT;ih++) { + hits_plane[ip][ih] = 0; + } } // Sort Space Points hits by plane THcSpacePoint* sp = (THcSpacePoint*)(*fSpacePoints)[isp]; @@ -629,23 +655,25 @@ Int_t THcDriftChamber::SpacePointMultiWire() // hash(hit) = ihit; Int_t ip = hit->GetPlaneIndex(); hits_plane[ip][nhitsperplane[ip]++] = hit; + //if (fDebugDriftCh) cout << " hit = " << ihit+1 << " plane index = " << ip << " nhitsperplane = " << nhitsperplane[ip] << endl; } for(Int_t ip=0;ip<fNPlanes;ip++) { if(nhitsperplane[ip] > 0) { nplanes_hit++; nsp_new *= nhitsperplane[ip]; if(nhitsperplane[ip] > 1) nplanes_mult++; + //if (fDebugDriftCh) cout << "Found plane with multi hits plane =" << ip+1 << " nplane_hit = "<< nplanes_hit << " nsp_new = " <<nsp_new << " nplane_mult = "<< nplanes_mult << endl; } } --nsp_new; nsp_check=nsp_tot + nsp_new; nplanes_single = nplanes_hit - nplanes_mult; - + if (fDebugDriftCh) cout << " # of new space points = " << nsp_new << " total now = " << nsp_tot<< endl; // Check if cloning conditions are met Int_t ntot = 0; if(nplanes_hit >= 4 && nplanes_mult < 4 && nplanes_mult >0 && nsp_check < 20) { - + if (fDebugDriftCh) cout << " Cloning space point " << endl; // Order planes by decreasing # of hits Int_t maxplane[fNPlanes]; @@ -662,24 +690,50 @@ Int_t THcDriftChamber::SpacePointMultiWire() } } } - + if (fDebugDriftCh) cout << " Max plane and hits " << maxplane[0] << " " << nhitsperplane[maxplane[0]]<< " " << maxplane[1] << " " << nhitsperplane[maxplane[1]]<< " "<< maxplane[2] << " " << nhitsperplane[maxplane[2]]<< endl; // First fill clones with 1 hit each from the 3 planes with the most hits for(Int_t n1=0;n1<nhitsperplane[maxplane[0]];n1++) { for(Int_t n2=0;n2<nhitsperplane[maxplane[1]];n2++) { for(Int_t n3=0;n3<nhitsperplane[maxplane[2]];n3++) { ntot++; - newsp_num = nsp_tot + ntot - 2; // ntot will be 2 for first new - THcSpacePoint* newsp; + newsp_num = fNSpacePoints; // + if (fDebugDriftCh) cout << " new space pt num = " << newsp_num << " " << fNSpacePoints << endl; + //THcSpacePoint* newsp; if(n1==0 && n2==0 && n3==0) { - newsp_num = isp; // Copy over original SP - newsp = sp; + newsp_num = isp; // Copy over the original SP + THcSpacePoint* newsp = (THcSpacePoint*)fSpacePoints->ConstructedAt(newsp_num);//= (THcSpacePoint*)(*fSpacePoints)[newsp_num]; + if (fDebugDriftCh) cout << " Copy over original SP " << endl; + // newsp = sp; + Int_t combos_save=sp->GetCombos(); newsp->Clear(); // Clear doesn't clear X, Y + if (fDebugDriftCh) cout << " original sp #hits combos X y " << sp->GetCombos() << sp->GetNHits() << sp->GetX() << " " << sp->GetY() << endl; + newsp->SetXY(sp->GetX(), sp->GetY()); + newsp->SetCombos(combos_save); + newsp->AddHit(hits_plane[maxplane[0]][n1]); + newsp->AddHit(hits_plane[maxplane[1]][n2]); + newsp->AddHit(hits_plane[maxplane[2]][n3]); + newsp->AddHit(hits_plane[maxplane[3]][0]); + if(nhitsperplane[maxplane[4]] == 1) { + newsp->AddHit(hits_plane[maxplane[4]][0]); + if(nhitsperplane[maxplane[5]] == 1) + newsp->AddHit(hits_plane[maxplane[5]][0]); + } + if (fDebugDriftCh) { + THcSpacePoint* spt = (THcSpacePoint*)fSpacePoints->ConstructedAt(newsp_num);//(THcSpacePoint*)(*fSpacePoints)[isp]; + cout << " new space pt num = " <<newsp_num << " " << spt->GetNHits() << endl; + for(Int_t ihit=0;ihit<spt->GetNHits();ihit++) { + THcDCHit* hit = spt->GetHit(ihit); + cout << " hit = " << ihit+1 << " " << hit->GetDist() << endl; + } + } // fDebugDriftCh } else { - THcSpacePoint* newsp = (THcSpacePoint*)fSpacePoints->ConstructedAt(fNSpacePoints++); + if (fDebugDriftCh) cout << " setting other sp " << "# space pts now = " << fNSpacePoints << endl; + THcSpacePoint* newsp = (THcSpacePoint*)fSpacePoints->ConstructedAt(newsp_num); + fNSpacePoints++; + Int_t combos_save=sp->GetCombos(); newsp->Clear(); newsp->SetXY(sp->GetX(), sp->GetY()); - } - newsp->SetCombos(sp->GetCombos()); + newsp->SetCombos(combos_save); newsp->AddHit(hits_plane[maxplane[0]][n1]); newsp->AddHit(hits_plane[maxplane[1]][n2]); newsp->AddHit(hits_plane[maxplane[2]][n3]); @@ -689,6 +743,15 @@ Int_t THcDriftChamber::SpacePointMultiWire() if(nhitsperplane[maxplane[5]] == 1) newsp->AddHit(hits_plane[maxplane[5]][0]); } + if (fDebugDriftCh) { + THcSpacePoint* spt = (THcSpacePoint*)fSpacePoints->ConstructedAt(newsp_num); + cout << " new space pt num = " << fNSpacePoints << " " << spt->GetNHits() << endl; + for(Int_t ihit=0;ihit<spt->GetNHits();ihit++) { + THcDCHit* hit = spt->GetHit(ihit); + cout << " hit = " << ihit+1 << " " << hit->GetDist() << endl; + } + } // fDebugDriftCh + } } } } @@ -713,16 +776,17 @@ Int_t THcDriftChamber::SpacePointMultiWire() #endif nsp_tot += (ntot-1); } else { - ntot=1; + ntot=1; // space point not to be cloned } } - assert (nsp_tot > 0); + assert (nsp_tot > 0); // program terminates if nsp_tot <=0 Int_t nadded=0; if(nsp_tot <= 20) { nadded = nsp_tot - fNSpacePoints; - fNSpacePoints = nsp_tot; + // fNSpacePoints = nsp_tot; } - + if (fDebugDriftCh) cout << " Added space pts " << nadded << " total space pts = " << fNSpacePoints << endl; + // In Fortran, fill in zeros. return(nadded); } @@ -757,19 +821,25 @@ void THcDriftChamber::ChooseSingleHit() } else { goodhit[ihit2] = 0; } + if (fDebugDriftCh) cout << " Rejecting hit " << ihit1 << " " << tdrift1 << " " << ihit2 << " " << tdrift2 << endl; } } } // Gather the remaining hits Int_t finalnum = 0; for(Int_t ihit=0;ihit<startnum;ihit++) { + THcDCHit* hit = sp->GetHit(ihit); + if (fDebugDriftCh) cout << " good hit = "<< ihit << " " << goodhit[ihit] << " time = " << hit->GetTime() << endl; if(goodhit[ihit] > 0) { // Keep this hit if (ihit > finalnum) { // Move hit sp->ReplaceHit(finalnum++, sp->GetHit(ihit)); - } + } else { + finalnum++ ; + } } } sp->SetNHits(finalnum); + if (fDebugDriftCh) cout << " choose single hit start # of hits = " << startnum << " final # = " <<finalnum << endl; } } //_____________________________________________________________________________ @@ -784,17 +854,39 @@ void THcDriftChamber::SelectSpacePoints() for(Int_t isp=0;isp<fNSpacePoints;isp++) { // Include fEasySpacePoint because ncombos not filled in THcSpacePoint* sp = (THcSpacePoint*)(*fSpacePoints)[isp]; + if (fDebugDriftCh) cout << " looping sp points " << sp->GetCombos() << " " << fMinCombos << " " << fEasySpacePoint << " " << sp->GetNHits() << " " << fMinHits << endl; if(sp->GetCombos() >= fMinCombos || fEasySpacePoint) { if(sp->GetNHits() >= fMinHits) { - if(isp > sp_count) - (*fSpacePoints)[sp_count] = (*fSpacePoints)[isp]; + if (fDebugDriftCh) cout << " select space pt = " << isp << endl; + if(isp > sp_count) { + // (*fSpacePoints)[sp_count] = (*fSpacePoints)[isp]; + THcSpacePoint* sp1 = (THcSpacePoint*)(*fSpacePoints)[sp_count]; + sp1->Clear(); + Double_t xt,yt; + xt=sp->GetX(); + yt=sp->GetY(); + sp1->SetXY(xt, yt); + sp1->SetCombos(sp->GetCombos()); + for(Int_t ihit=0;ihit<sp->GetNHits();ihit++) { + THcDCHit* hit = sp->GetHit(ihit); + sp1->AddHit(hit); + } + } sp_count++; } } } - // if(sp_count < fNSpacePoints) - // cout << "Reduced from " << fNSpacePoints << " to " << sp_count << " space points" << endl; + if(sp_count < fNSpacePoints) if (fDebugDriftCh) cout << "Reduced from " << fNSpacePoints << " to " << sp_count << " space points" << endl; fNSpacePoints = sp_count; + for(Int_t isp=0;isp<fNSpacePoints;isp++) { + THcSpacePoint* sp = (THcSpacePoint*)(*fSpacePoints)[isp]; + if (fDebugDriftCh) cout << " sp pt = " << isp+1 << " # of hits = " << sp->GetNHits() << endl; + for(Int_t ihit=0;ihit<sp->GetNHits();ihit++) { + THcDCHit* hit = sp->GetHit(ihit); + THcDriftChamberPlane* plane=hit->GetWirePlane(); + if (fDebugDriftCh) cout << ihit+1 << "selecting " << plane->GetPlaneNum() << " " << plane->GetChamberNum() << " " << hit->GetTime() << " " << hit->GetDist() << " " << plane->GetCentralTime() << " " << plane->GetDriftTimeSign() << endl; + } + } } void THcDriftChamber::CorrectHitTimes() @@ -808,6 +900,7 @@ void THcDriftChamber::CorrectHitTimes() // SOS u and v planes. They have 1 card each on the side, but the overall // time offset per card will cancel much of the error caused by this. The // alternative is to check by card, rather than by plane and this is harder. + //if (fDebugDriftCh) cout << "In correcthittimes fNSpacePoints = " << fNSpacePoints << endl; for(Int_t isp=0;isp<fNSpacePoints;isp++) { THcSpacePoint* sp = (THcSpacePoint*)(*fSpacePoints)[isp]; Double_t x = sp->GetX(); @@ -822,16 +915,17 @@ void THcDriftChamber::CorrectHitTimes() y*plane->GetReadoutCorr()/fWireVelocity : x*plane->GetReadoutCorr()/fWireVelocity; - // cout << "Correcting hit " << hit << " " << plane->GetPlaneNum() << " " << isp << "/" << ihit << " " << x << "," << y << endl; + // if (fDebugDriftCh) cout << "Correcting hit " << hit << " " << plane->GetPlaneNum() << " " << isp << "/" << ihit << " " << x << "," << y << endl; // Fortran ENGINE does not do this check, so hits can get "corrected" // multiple times if they belong to multiple space points. // To reproduce the precise ENGINE behavior, remove this if condition. - if(! hit->GetCorrectedStatus()) { + //if(! hit->GetCorrectedStatus()) { hit->SetTime(hit->GetTime() - plane->GetCentralTime() + plane->GetDriftTimeSign()*time_corr); hit->ConvertTimeToDist(); + //if (fDebugDriftCh) cout << ihit+1 << " " << plane->GetPlaneNum() << " " << plane->GetChamberNum() << " " << hit->GetTime() << " " << hit->GetDist() << " " << plane->GetCentralTime() << " " << plane->GetDriftTimeSign() << " " << time_corr << endl; hit->SetCorrectedStatus(1); - } + //} } } } @@ -870,9 +964,9 @@ void THcDriftChamber::LeftRight() Double_t tmp_stub[4]; if(nhits < 0) { - cout << "THcDriftChamber::LeftRight() nhits < 0" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight() nhits < 0" << endl; } else if (nhits==0) { - cout << "THcDriftChamber::LeftRight() nhits = 0" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight() nhits = 0" << endl; } for(Int_t ihit=0;ihit < nhits;ihit++) { THcDCHit* hit = sp->GetHit(ihit); @@ -888,23 +982,26 @@ void THcDriftChamber::LeftRight() } Int_t smallAngOK = (hasy1>=0) && (hasy2>=0); if(fSmallAngleApprox !=0 && smallAngOK) { // to small Angle L/R for Y,Y' planes - if(sp->GetHit(hasy1)->GetPos() <= - sp->GetHit(hasy2)->GetPos()) { + if(sp->GetHit(hasy2)->GetPos() <= + sp->GetHit(hasy1)->GetPos()) { plusminusknown[hasy1] = -1; plusminusknown[hasy2] = 1; } else { plusminusknown[hasy1] = 1; plusminusknown[hasy2] = -1; } + if (fDebugDriftCh) cout << " Small angle approx = " << smallAngOK << " " << plusminusknown[hasy1] << endl; + if (fDebugDriftCh) cout << "pm = " << plusminusknown[hasy2] << " " << hasy1 << " " << hasy2 << endl; + if (fDebugDriftCh) cout << " Plane index " << YPlaneInd << " " << YPlanePInd << endl; } if(nhits < 2) { - cout << "THcDriftChamber::LeftRight: numhits-2 < 0" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight: numhits-2 < 0" << endl; } else if (nhits == 2) { - cout << "THcDriftChamber::LeftRight: numhits-2 = 0" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight: numhits-2 = 0" << endl; } Int_t nplaneshit = Count1Bits(bitpat); Int_t nplusminus = 1<<(nhits-2); - + if (fDebugDriftCh) cout << " num of pm = " << nplusminus << " num of hits =" << nhits << endl; // Use bit value of integer word to set + or - // Loop over all combinations of left right. for(Int_t pmloop=0;pmloop<nplusminus;pmloop++) { @@ -927,7 +1024,6 @@ void THcDriftChamber::LeftRight() plane_list, bitpat, plusminus, stub); //if(debugging) - //cout << "pmloop=" << pmloop << " Chi2=" << chi2 << endl; // Take best chi2 IF x' of the stub agrees with x' as expected from x. // Sometimes an incorrect x' gives a good chi2 for the stub, even though it is // not the correct left/right combination for the real track. @@ -935,7 +1031,7 @@ void THcDriftChamber::LeftRight() // THIS ASSUMES STANDARD HMS TUNE!!!!, for which x' is approx. x/875. if(chi2 < minchi2) { if(stub[2]*fTanBeta[plane_list[0]]==-1.0) { - cout << "THcDriftChamber::LeftRight() Error 3" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight() Error 3" << endl; } Double_t xp_fit=stub[2]-fTanBeta[plane_list[0]] /(1+stub[2]*fTanBeta[plane_list[0]]); @@ -964,10 +1060,10 @@ void THcDriftChamber::LeftRight() Double_t chi2 = FindStub(nhits, sp->GetHitVectorP(), plane_list, bitpat, plusminus, stub); //if(debugging) - //cout << "pmloop=" << pmloop << " Chi2=" << chi2 << endl; + //if (fDebugDriftCh) cout << "pmloop=" << pmloop << " Chi2=" << chi2 << endl; // Isn't this a bad idea, doing == with reals if(stub[2]*fTanBeta[plane_list[0]] == -1.0) { - cout << "THcDriftChamber::LeftRight() Error 3" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight() Error 3" << endl; } Double_t xp_fit=stub[2]-fTanBeta[plane_list[0]] /(1+stub[2]*fTanBeta[plane_list[0]]); @@ -983,7 +1079,7 @@ void THcDriftChamber::LeftRight() } } } else { - cout << "Insufficient planes hit in THcDriftChamber::LeftRight()" << bitpat <<endl; + if (fDebugDriftCh) cout << "Insufficient planes hit in THcDriftChamber::LeftRight()" << bitpat <<endl; } } // End loop of pm combinations @@ -1009,12 +1105,12 @@ void THcDriftChamber::LeftRight() // (I think this rotates in case chambers not perpendicular to central ray) Int_t pindex=plane_list[0]; if(spstub[2] - fTanBeta[pindex] == -1.0) { - cout << "THcDriftChamber::LeftRight(): stub3 error" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight(): stub3 error" << endl; } stub[2] = (spstub[2] - fTanBeta[pindex]) / (1.0 + spstub[2]*fTanBeta[pindex]); if(spstub[2]*fSinBeta[pindex] == -fCosBeta[pindex]) { - cout << "THcDriftChamber::LeftRight(): stub4 error" << endl; + if (fDebugDriftCh) cout << "THcDriftChamber::LeftRight(): stub4 error" << endl; } stub[3] = spstub[3] / (spstub[2]*fSinBeta[pindex]+fCosBeta[pindex]); @@ -1025,7 +1121,8 @@ void THcDriftChamber::LeftRight() for(Int_t i=0;i<4;i++) { spstub[i] = stub[i]; } - } + if (fDebugDriftCh) cout << " Left/Right space pt " << isp+1 << " " << stub[0]<< " " << stub[1] << " " << stub[2]<< " " << stub[3] << endl; + } // Option to print stubs } // if(fAA3Inv.find(bitpat) != fAAInv.end()) { // Valid hit combination @@ -1042,7 +1139,7 @@ Double_t THcDriftChamber::FindStub(Int_t nhits, const std::vector<THcDCHit*>* hi // This isn't right. dpos only goes up to 2. for(Int_t ihit=0;ihit<nhits; ihit++) { - dpos[ihit] = (*hits)[ihit]->GetPos() + plusminus[ihit]*(*hits)[ihit]->GetdDist() + dpos[ihit] = (*hits)[ihit]->GetPos() + plusminus[ihit]*(*hits)[ihit]->GetDist() - fPsi0[plane_list[ihit]]; for(Int_t index=0;index<3;index++) { TT[index]+= dpos[ihit]*fStubCoefs[plane_list[ihit]][index] @@ -1050,13 +1147,13 @@ Double_t THcDriftChamber::FindStub(Int_t nhits, const std::vector<THcDCHit*>* hi } } // fAA3Inv[bitpat]->Print(); - // cout << TT[0] << " " << TT[1] << " " << TT[2] << endl; + // if (fDebugDriftCh) cout << TT[0] << " " << TT[1] << " " << TT[2] << endl; // TT->Print(); //dstub = *(fAA3Inv[bitpat]) * TT; TT *= *fAA3Inv[bitpat]; - // cout << TT[0] << " " << TT[1] << " " << TT[2] << endl; - // cout << dstub[0] << " " << dstub[1] << " " << dstub[2] << endl; + // if (fDebugDriftCh) cout << TT[0] << " " << TT[1] << " " << TT[2] << endl; + // if (fDebugDriftCh) cout << dstub[0] << " " << dstub[1] << " " << dstub[2] << endl; // Calculate Chi2. Remember one power of sigma is in fStubCoefs stub[0] = TT[0]; @@ -1079,7 +1176,7 @@ THcDriftChamber::~THcDriftChamber() { // Destructor. Remove variables from global list. - cout << fChamberNum << ": delete fSpacePoints: " << hex << fSpacePoints << endl; + if (fDebugDriftCh) cout << fChamberNum << ": delete fSpacePoints: " << hex << fSpacePoints << endl; delete fSpacePoints; // Should delete the matrices diff --git a/src/THcDriftChamber.h b/src/THcDriftChamber.h index 43c2dd3e2517fb81fa2354490354d19dccdac971..c6f57c24fb86e878edb8c24d11b21737833913ef 100644 --- a/src/THcDriftChamber.h +++ b/src/THcDriftChamber.h @@ -49,11 +49,11 @@ public: const TClonesArray* GetTrackHits() const { return fTrackProj; } TClonesArray* GetSpacePointsP() const { return(fSpacePoints);} Int_t GetChamberNum() const { return fChamberNum;} - // friend class THaScCalib; THcDriftChamber(); // for ROOT I/O // Why do we need this? protected: + Int_t fDebugDriftCh; // Calibration