diff --git a/src/THcDC.cxx b/src/THcDC.cxx index e79868cd26090cc462a36fdb37b40d3942064365..0df2ec32db03a991c357bd55bd0511a6a021c574 100644 --- a/src/THcDC.cxx +++ b/src/THcDC.cxx @@ -41,12 +41,36 @@ THcDC::THcDC( // fTrackProj = new TClonesArray( "THaTrackProj", 5 ); fNPlanes = 0; // No planes until we make them + fXCenter = NULL; + fYCenter = NULL; + fMinHits = NULL; + fMaxHits = NULL; + fMinCombos = NULL; + fSpace_Point_Criterion2 = NULL; + + fTdcWinMin = NULL; + fTdcWinMax = NULL; + fCentralTime = NULL; + fNWires = NULL; + fNChamber = NULL; + fWireOrder = NULL; + fDriftTimeSign = NULL; + + fZPos = NULL; + fAlphaAngle = NULL; + fBetaAngle = NULL; + fGammaAngle = NULL; + fPitch = NULL; + fCentralWire = NULL; + fPlaneTimeZero = NULL; + fSigma = NULL; } //_____________________________________________________________________________ void THcDC::Setup(const char* name, const char* description) { + static const char* const here = "Setup"; char prefix[2]; char parname[100]; @@ -87,23 +111,32 @@ void THcDC::Setup(const char* name, const char* description) } char *desc = new char[strlen(description)+100]; - fPlanes = new THcDriftChamberPlane* [fNPlanes]; + fPlanes.clear(); for(Int_t i=0;i<fNPlanes;i++) { strcpy(desc, description); strcat(desc, " Plane "); strcat(desc, fPlaneNames[i]); - fPlanes[i] = new THcDriftChamberPlane(fPlaneNames[i], desc, i+1, this); + THcDriftChamberPlane* newplane = new THcDriftChamberPlane(fPlaneNames[i], desc, i+1, this); + if( !newplane or newplane->IsZombie() ) { + Error( Here(here), "Error creating Drift Chamber plane %s. Call expert.", name); + MakeZombie(); + return; + } + fPlanes.push_back(newplane); + newplane->SetDebug(fDebug); cout << "Created Drift Chamber Plane " << fPlaneNames[i] << ", " << desc << endl; } - fChambers = new THcDriftChamber* [fNChambers]; + + fChambers.clear(); for(Int_t i=0;i<fNChambers;i++) { sprintf(desc,"%s Chamber %d",description, i+1); // Should construct a better chamber name - fChambers[i] = new THcDriftChamber(desc, desc, i+1, this); + THcDriftChamber* newchamber = new THcDriftChamber(desc, desc, i+1, this); + fChambers.push_back(newchamber); cout << "Created Drift Chamber " << i+1 << ", " << desc << endl; @@ -200,29 +233,29 @@ Int_t THcDC::ReadDatabase( const TDatime& date ) prefix[1]='\0'; - fXCenter = new Double_t [fNChambers]; - fYCenter = new Double_t [fNChambers]; - fMinHits = new Int_t [fNChambers]; - fMaxHits = new Int_t [fNChambers]; - fMinCombos = new Int_t [fNChambers]; - fSpace_Point_Criterion2 = new Double_t [fNChambers]; - - fTdcWinMin = new Int_t [fNPlanes]; - fTdcWinMax = new Int_t [fNPlanes]; - fCentralTime = new Int_t [fNPlanes]; - fNWires = new Int_t [fNPlanes]; - fNChamber = new Int_t [fNPlanes]; // Which chamber is this plane - fWireOrder = new Int_t [fNPlanes]; // Wire readout order - fDriftTimeSign = new Int_t [fNPlanes]; - - fZPos = new Double_t [fNPlanes]; - fAlphaAngle = new Double_t [fNPlanes]; - fBetaAngle = new Double_t [fNPlanes]; - fGammaAngle = new Double_t [fNPlanes]; - fPitch = new Double_t [fNPlanes]; - fCentralWire = new Double_t [fNPlanes]; - fPlaneTimeZero = new Double_t [fNPlanes]; - fSigma = new Double_t [fNPlanes]; + delete [] fXCenter; fXCenter = new Double_t [fNChambers]; + delete [] fYCenter; fYCenter = new Double_t [fNChambers]; + delete [] fMinHits; fMinHits = new Int_t [fNChambers]; + delete [] fMaxHits; fMaxHits = new Int_t [fNChambers]; + delete [] fMinCombos; fMinCombos = new Int_t [fNChambers]; + delete [] fSpace_Point_Criterion2; fSpace_Point_Criterion2 = new Double_t [fNChambers]; + + delete [] fTdcWinMin; fTdcWinMin = new Int_t [fNPlanes]; + delete [] fTdcWinMax; fTdcWinMax = new Int_t [fNPlanes]; + delete [] fCentralTime; fCentralTime = new Int_t [fNPlanes]; + delete [] fNWires; fNWires = new Int_t [fNPlanes]; + delete [] fNChamber; fNChamber = new Int_t [fNPlanes]; // Which chamber is this plane + delete [] fWireOrder; fWireOrder = new Int_t [fNPlanes]; // Wire readout order + delete [] fDriftTimeSign; fDriftTimeSign = new Int_t [fNPlanes]; + + delete [] fZPos; fZPos = new Double_t [fNPlanes]; + delete [] fAlphaAngle; fAlphaAngle = new Double_t [fNPlanes]; + delete [] fBetaAngle; fBetaAngle = new Double_t [fNPlanes]; + delete [] fGammaAngle; fGammaAngle = new Double_t [fNPlanes]; + delete [] fPitch; fPitch = new Double_t [fNPlanes]; + delete [] fCentralWire; fCentralWire = new Double_t [fNPlanes]; + delete [] fPlaneTimeZero; fPlaneTimeZero = new Double_t [fNPlanes]; + delete [] fSigma; fSigma = new Double_t [fNPlanes]; DBRequest list[]={ {"dc_tdc_time_per_channel",&fNSperChan, kDouble}, @@ -293,6 +326,14 @@ THcDC::~THcDC() RemoveVariables(); if( fIsInit ) DeleteArrays(); + + // Delete the plane objects + for (vector<THcDriftChamberPlane*>::iterator ip = fPlanes.begin(); + ip != fPlanes.end(); ip++) delete *ip; + // Delete the chamber objects + for (vector<THcDriftChamber*>::iterator ip = fChambers.begin(); + ip != fChambers.end(); ip++) delete *ip; + if (fTrackProj) { fTrackProj->Clear(); delete fTrackProj; fTrackProj = 0; @@ -304,35 +345,30 @@ void THcDC::DeleteArrays() { // Delete member arrays. Used by destructor. - delete [] fNWires; fNWires = NULL; - // delete [] fSpacing; fSpacing = NULL; - // delete [] fCenter; fCenter = NULL; // This 2D. What is correct way to delete? - - // delete [] fRA_c; fRA_c = NULL; - // delete [] fRA_p; fRA_p = NULL; - // delete [] fRA; fRA = NULL; - // delete [] fLA_c; fLA_c = NULL; - // delete [] fLA_p; fLA_p = NULL; - // delete [] fLA; fLA = NULL; - // delete [] fRT_c; fRT_c = NULL; - // delete [] fRT; fRT = NULL; - // delete [] fLT_c; fLT_c = NULL; - // delete [] fLT; fLT = NULL; - - // delete [] fRGain; fRGain = NULL; - // delete [] fLGain; fLGain = NULL; - // delete [] fRPed; fRPed = NULL; - // delete [] fLPed; fLPed = NULL; - // delete [] fROff; fROff = NULL; - // delete [] fLOff; fLOff = NULL; - // delete [] fTWalkPar; fTWalkPar = NULL; - // delete [] fTrigOff; fTrigOff = NULL; - - // delete [] fHitPad; fHitPad = NULL; - // delete [] fTime; fTime = NULL; - // delete [] fdTime; fdTime = NULL; - // delete [] fYt; fYt = NULL; - // delete [] fYa; fYa = NULL; + delete [] fXCenter; fXCenter = NULL; + delete [] fYCenter; fYCenter = NULL; + delete [] fMinHits; fMinHits = NULL; + delete [] fMaxHits; fMaxHits = NULL; + delete [] fMinCombos; fMinCombos = NULL; + delete [] fSpace_Point_Criterion2; fSpace_Point_Criterion2 = NULL; + + delete [] fTdcWinMin; fTdcWinMin = NULL; + delete [] fTdcWinMax; fTdcWinMax = NULL; + delete [] fCentralTime; fCentralTime = NULL; + delete [] fNWires; fNWires = NULL; + delete [] fNChamber; fNChamber = NULL; + delete [] fWireOrder; fWireOrder = NULL; + delete [] fDriftTimeSign; fDriftTimeSign = NULL; + + delete [] fZPos; fZPos = NULL; + delete [] fAlphaAngle; fAlphaAngle = NULL; + delete [] fBetaAngle; fBetaAngle = NULL; + delete [] fGammaAngle; fGammaAngle = NULL; + delete [] fPitch; fPitch = NULL; + delete [] fCentralWire; fCentralWire = NULL; + delete [] fPlaneTimeZero; fPlaneTimeZero = NULL; + delete [] fSigma; fSigma = NULL; + } //_____________________________________________________________________________ diff --git a/src/THcDC.h b/src/THcDC.h index 809441a64e92285ed243ffeb429299b4c8832b0e..e0b7b4d6b140d7faa490c8c013fb38c84ea8900e 100644 --- a/src/THcDC.h +++ b/src/THcDC.h @@ -113,8 +113,8 @@ protected: Double_t* fPlaneTimeZero; Double_t* fSigma; - THcDriftChamberPlane** fPlanes; // List of plane objects - THcDriftChamber** fChambers; // List of chamber objects + std::vector<THcDriftChamberPlane*> fPlanes; // List of plane objects + std::vector<THcDriftChamber*> fChambers; // List of chamber objects TClonesArray* fTrackProj; // projection of track onto scintillator plane // and estimated match to TOF paddle diff --git a/src/THcDriftChamber.cxx b/src/THcDriftChamber.cxx index 4c3e622d1b66cb1ee9701cd7d9d8dec347ab69a8..dfd388c219780d7c33917a2bdebd2f0129167da0 100644 --- a/src/THcDriftChamber.cxx +++ b/src/THcDriftChamber.cxx @@ -69,6 +69,7 @@ THcDriftChamber::THcDriftChamber( ) : THaSubDetector() { // Constructor + fPlanes.clear(); } //_____________________________________________________________________________ @@ -97,7 +98,7 @@ void THcDriftChamber::AddPlane(THcDriftChamberPlane *plane) { cout << "Added plane " << plane->GetPlaneNum() << " to chamber " << fChamberNum << " " << fNPlanes << " " << YPlaneInd << " " << YPlanePInd << endl; plane->SetPlaneIndex(fNPlanes); - fPlanes[fNPlanes] = plane; + fPlanes.push_back(plane); // HMS Specific // Hard code Y plane numbers. Should be able to get from wire angle if(fChamberNum == 1) { @@ -109,7 +110,7 @@ void THcDriftChamber::AddPlane(THcDriftChamberPlane *plane) } // HMS Specific - // Check if this is a Y Plae + // Check if this is a Y Plane if(plane->GetPlaneNum() == YPlaneNum) { YPlaneInd = fNPlanes; } else if (plane->GetPlaneNum() == YPlanePNum) { @@ -232,11 +233,14 @@ void THcDriftChamber::ProcessHits( void) { // Make a list of hits for whole chamber fNhits = 0; + fHits.clear(); + fHits.reserve(10); for(Int_t ip=0;ip<fNPlanes;ip++) { TClonesArray* hitsarray = fPlanes[ip]->GetHits(); for(Int_t ihit=0;ihit<fPlanes[ip]->GetNHits();ihit++) { - fHits[fNhits++] = static_cast<THcDCHit*>(hitsarray->At(ihit)); + fHits.push_back(static_cast<THcDCHit*>(hitsarray->At(ihit))); + fNhits++; } } // cout << "ThcDriftChamber::ProcessHits() " << fNhits << " hits" << endl; @@ -373,9 +377,9 @@ Int_t THcDriftChamber::FindEasySpacePoint(Int_t yplane_hitind,Int_t yplanep_hiti fSpacePoints[0].y = yt; fSpacePoints[0].nhits = fNhits; fSpacePoints[0].ncombos = 0; // No combos + fSpacePoints[0].hits.resize(fNhits); for(Int_t ihit=0;ihit<fNhits;ihit++) { - THcDCHit* thishit = fHits[ihit]; - fSpacePoints[0].hits[ihit] = thishit; + fSpacePoints[0].hits[ihit] = fHits[ihit]; } } return(easy_space_point); @@ -485,7 +489,8 @@ Int_t THcDriftChamber::FindHardSpacePoints() // Add the unique combo hits to the space point for(Int_t icm=0;icm<4;icm++) { if(iflag[icm]==0) { - fSpacePoints[ispace].hits[fSpacePoints[ispace].nhits++] = hits[icm]; + fSpacePoints[ispace].hits.push_back(hits[icm]); + fSpacePoints[ispace].nhits++; } } fSpacePoints[ispace].ncombos++; @@ -499,15 +504,18 @@ Int_t THcDriftChamber::FindHardSpacePoints() if(add_flag) { fSpacePoints[fNSpacePoints].nhits=2; fSpacePoints[fNSpacePoints].ncombos=1; + fSpacePoints[fNSpacePoints].hits.resize(fSpacePoints[fNSpacePoints].nhits); fSpacePoints[fNSpacePoints].hits[0]=hits[0]; fSpacePoints[fNSpacePoints].hits[1]=hits[1]; fSpacePoints[fNSpacePoints].x = xt; fSpacePoints[fNSpacePoints].y = yt; if(hits[0] != hits[2] && hits[1] != hits[2]) { - fSpacePoints[fNSpacePoints].hits[fSpacePoints[fNSpacePoints].nhits++] = hits[2]; + fSpacePoints[fNSpacePoints].hits.push_back(hits[2]); + fSpacePoints[fNSpacePoints].nhits++; } if(hits[0] != hits[3] && hits[1] != hits[3]) { - fSpacePoints[fNSpacePoints].hits[fSpacePoints[fNSpacePoints].nhits++] = hits[3]; + fSpacePoints[fNSpacePoints].hits.push_back(hits[3]); + fSpacePoints[fNSpacePoints].nhits++; } fNSpacePoints++; } @@ -517,15 +525,18 @@ Int_t THcDriftChamber::FindHardSpacePoints() // to avoid fSpacePoints[fNSpacePoints].nhits=2; fSpacePoints[fNSpacePoints].ncombos=1; - fSpacePoints[fNSpacePoints].hits[0]=hits[0]; - fSpacePoints[fNSpacePoints].hits[1]=hits[1]; + fSpacePoints[fNSpacePoints].hits.resize(fSpacePoints[fNSpacePoints].nhits); + fSpacePoints[fNSpacePoints].hits[0] = hits[0]; + fSpacePoints[fNSpacePoints].hits[1] = hits[1]; fSpacePoints[fNSpacePoints].x = xt; fSpacePoints[fNSpacePoints].y = yt; if(hits[0] != hits[2] && hits[1] != hits[2]) { - fSpacePoints[fNSpacePoints].hits[fSpacePoints[fNSpacePoints].nhits++] = hits[2]; + fSpacePoints[fNSpacePoints].hits.push_back(hits[2]); + fSpacePoints[fNSpacePoints].nhits++; } if(hits[0] != hits[3] && hits[1] != hits[3]) { - fSpacePoints[fNSpacePoints].hits[fSpacePoints[fNSpacePoints].nhits++] = hits[3]; + fSpacePoints[fNSpacePoints].hits.push_back(hits[3]); + fSpacePoints[fNSpacePoints].nhits++; } fNSpacePoints++; }//End check on 0 space points @@ -668,14 +679,16 @@ Int_t THcDriftChamber::SpacePointMultiWire() fSpacePoints[newsp_num].y = fSpacePoints[isp].y; fSpacePoints[newsp_num].nhits = nplanes_hit; fSpacePoints[newsp_num].ncombos = fSpacePoints[isp].ncombos; - fSpacePoints[newsp_num].hits[0] = hits_plane[maxplane[0]][n1]; - fSpacePoints[newsp_num].hits[1] = hits_plane[maxplane[1]][n2]; - fSpacePoints[newsp_num].hits[2] = hits_plane[maxplane[2]][n3]; - fSpacePoints[newsp_num].hits[3] = hits_plane[maxplane[3]][0]; - if(nhitsperplane[maxplane[4]] == 1) - fSpacePoints[newsp_num].hits[4] = hits_plane[maxplane[4]][0]; - if(nhitsperplane[maxplane[5]] == 1) - fSpacePoints[newsp_num].hits[5] = hits_plane[maxplane[5]][0]; + fSpacePoints[newsp_num].hits.resize(0); + fSpacePoints[newsp_num].hits.push_back(hits_plane[maxplane[0]][n1]); + fSpacePoints[newsp_num].hits.push_back(hits_plane[maxplane[1]][n2]); + fSpacePoints[newsp_num].hits.push_back(hits_plane[maxplane[2]][n3]); + fSpacePoints[newsp_num].hits.push_back(hits_plane[maxplane[3]][0]); + if(nhitsperplane[maxplane[4]] == 1) { + fSpacePoints[newsp_num].hits.push_back(hits_plane[maxplane[4]][0]); + if(nhitsperplane[maxplane[5]] == 1) + fSpacePoints[newsp_num].hits.push_back(hits_plane[maxplane[5]][0]); + } } } } @@ -1010,7 +1023,7 @@ void THcDriftChamber::LeftRight() } // if(fAA3Inv.find(bitpat) != fAAInv.end()) { // Valid hit combination //_____________________________________________________________________________ -Double_t THcDriftChamber::FindStub(Int_t nhits, THcDCHit** hits, +Double_t THcDriftChamber::FindStub(Int_t nhits, const std::vector<THcDCHit*>& hits, Int_t* plane_list, UInt_t bitpat, Int_t* plusminus, Double_t* stub) { diff --git a/src/THcDriftChamber.h b/src/THcDriftChamber.h index db307dd06bfab3b204bf482e8c3820351d03da0b..e6d61df5d6be217884121b613e7b2417ae5847dc 100644 --- a/src/THcDriftChamber.h +++ b/src/THcDriftChamber.h @@ -13,6 +13,7 @@ #include "TMatrixDSym.h" #include <map> +#include <vector> #define MAX_SPACE_POINTS 50 #define MAX_HITS_PER_POINT 20 @@ -85,7 +86,8 @@ protected: Double_t* fPsi0; Double_t** fStubCoefs; - THcDriftChamberPlane* fPlanes[20]; // List of plane objects + std::vector<THcDriftChamberPlane*> fPlanes; + // THcDriftChamberPlane* fPlanes[20]; // List of plane objects TClonesArray* fTrackProj; // projection of track onto scintillator plane // and estimated match to TOF paddle @@ -103,17 +105,19 @@ protected: void SelectSpacePoints(void); UInt_t Count1Bits(UInt_t x); void LeftRight(void); - Double_t FindStub(Int_t nhits, THcDCHit** hits, Int_t* plane_list, - UInt_t bitpat, Int_t* plusminus, Double_t* stub); + Double_t FindStub(Int_t nhits, const std::vector<THcDCHit*>& hits, + Int_t* plane_list, UInt_t bitpat, + Int_t* plusminus, Double_t* stub); - THcDCHit* fHits[10000]; /* All hits for this chamber */ + std::vector<THcDCHit*> fHits; /* All hits for this chamber */ // A simple structure until we figure out what we are doing. struct SpacePoint { Double_t x; Double_t y; Int_t nhits; Int_t ncombos; - THcDCHit* hits[MAX_HITS_PER_POINT]; + // THcDCHit* hits[MAX_HITS_PER_POINT]; + std::vector<THcDCHit*> hits; Double_t stub[4]; }; SpacePoint fSpacePoints[MAX_SPACE_POINTS];