// $Id$ // // File: DCDCTrackHit_factory.cc // Created: Mon Oct 16 10:20:07 EDT 2006 // Creator: davidl (on Darwin swire-b241.jlab.org 8.7.0 powerpc) // #include #include using namespace std; #include "DCDCTrackHit_factory.h" #include "DCDCHit.h" #include #include #include DCDCTrackHit_factory::~DCDCTrackHit_factory(){ if (cdcwires.size()){ for (unsigned int i=0;iSetDefaultParameter("CDC:MATCH_TRUTH_HITS",MATCH_TRUTH_HITS,"Match truth hits to CDC hits (DEF=false)"); return NOERROR; } //------------------ // brun //------------------ jerror_t DCDCTrackHit_factory::brun(JEventLoop *loop, int runnumber) { // Get pointer to DGeometry object DApplication* dapp=dynamic_cast(eventLoop->GetJApplication()); dgeom = dapp->GetDGeometry(runnumber); // Get the CDC wire table from the XML //jout<< "Getting map of cdc wires from the XML" <GetCDCWires(cdcwires); // Fill array with the number of straws for each layer for (unsigned int i=0;iGetJCalibration((loop->GetJEvent()).GetRunNumber()); map cdc_drift_parms; jcalib->Get("CDC/cdc_drift_parms", cdc_drift_parms); CDC_DRIFT_BSCALE_PAR1 = cdc_drift_parms["bscale_par1"]; CDC_DRIFT_BSCALE_PAR2 = cdc_drift_parms["bscale_par2"]; typedef map::iterator iter_double; vector< map > tvals; if (jcalib->Get("CDC/cdc_drift_table", tvals)==false){ for(unsigned int i=0; i &row = tvals[i]; iter_double iter = row.find("t"); cdc_drift_table.push_back(1000.*iter->second); } } if(cdc_drift_table.empty()){ jerr << endl; jerr << " No values found for \"CDC/cdc_drift_table\"!" < cdchits; loop->Get(cdchits); if (cdchits.size()==0) return NOERROR; // If this is simulated data then we want to match up the truth hit // with this "real" hit. Ideally, this would be done at the // DCDCHit object level, but the organization of the data in HDDM // makes that difficult. Here we have the full wire definition so // we make the connection here. vector mctrackhits; if (MATCH_TRUTH_HITS)loop->Get(mctrackhits); for(unsigned int i=0; iring>CDC_MAX_RINGS || cdchit->ring<1 || cdchit->straw>Nstraws[cdchit->ring-1] || cdchit->straw<1){ cerr<<__FILE__<<":"<<__LINE__<<" Ring or straw out of range! ring=" <ring<<" (should be 1-"<ring-1]<<")"<wire = cdcwires[cdchit->ring-1][cdchit->straw-1]; hit->is_stereo=((cdchit->ring>4&&cdchit->ring<13) ||(cdchit->ring>16&&cdchit->ring<25)) ?true:false; hit->tdrift = cdchit->t; double w_eff=29.5e-9; double gas_gain=1e5; double electron_charge=1.6022e-4; /* fC */ hit->dE=cdchit->q*w_eff/(gas_gain*electron_charge); // Calculate drift distance assuming no tof to wire for now. // The tracking package will replace this once an estimate // of the tof to the wire is known. This algorithm was copied // from the method DTrackFitterKalmanSIMD::ComputeCDCDrift // so that a distance could be used for drawing the CDC // drift times in hdview2, even when track fitting isn't done. double B = 2.0; // just assume 2T B-field everywhere double dtc =(CDC_DRIFT_BSCALE_PAR1 + CDC_DRIFT_BSCALE_PAR2 * B)* hit->tdrift; double tcorr = hit->tdrift - dtc; unsigned int index=0; if(tcorr < cdc_drift_table_min){ index = 0; }else if (tcorr >= cdc_drift_table_max){ index = cdc_drift_table.size()-1; }else{ index=locate(cdc_drift_table,tcorr); } double dt=cdc_drift_table[index+1]-cdc_drift_table[index]; double frac=(tcorr-cdc_drift_table[index])/dt; hit->dist = 0.01*(double(index)+frac); // the actual drift distance is calculated later, use a placeholder value here hit->AddAssociatedObject(cdchit); if (MATCH_TRUTH_HITS==true&&mctrackhits.size()>0){ // Estimate for drift distance, ignoring flight time double d=0.; if (cdchit->t>0) d=0.0279*sqrt(cdchit->t); // Try matching truth hit with this "real" hit. const DMCTrackHit *mctrackhit = DTrackHitSelectorTHROWN::GetMCTrackHit(hit->wire,d, mctrackhits); if(mctrackhit)hit->AddAssociatedObject(mctrackhit); } _data.push_back(hit); } return NOERROR; } //------------------ // locate // Locate a position in vector xx given x // (this copied from DTrackFitterKalmanSIMD.cc) //------------------ unsigned int DCDCTrackHit_factory::locate(vector&xx,double x){ int ju,jm,jl; int ascnd; int n=xx.size(); jl=-1; ju=n; ascnd=(xx[n-1]>=xx[0]); while(ju-jl>1){ jm=(ju+jl)>>1; if ( (x>=xx[jm])==ascnd) jl=jm; else ju=jm; } if (x==xx[0]) return 0; else if (x==xx[n-1]) return n-2; return jl; }