18 #include <JANA/JApplication.h>
19 #include <JANA/JFactory.h>
63 JCalibration *jcalib = dapp->GetJCalibration(runnumber);
69 dgeom->GetTargetLength(dTargetLength);
73 dgeom->GetCDCEndplate(endplate_z,endplate_dz,endplate_rmin,endplate_rmax);
74 dgeom->GetCDCWires(cdcwires);
75 unsigned int numstraws[28]={42,42,54,54,66,66,80,80,93,93,106,106,123,123,
76 135,135,146,146,158,158,170,170,182,182,197,197,
80 vector< map<string, double> > tvals;
82 sag_phi_offset.clear();
83 unsigned int straw_count=0,ring_count=0;
84 if (jcalib->Get(
"CDC/sag_parameters", tvals)==
false){
85 vector<double>
temp,temp2;
86 for(
unsigned int i=0; i<tvals.size(); i++){
87 map<string, double> &row = tvals[i];
89 temp.push_back(row[
"offset"]);
90 temp2.push_back(row[
"phi"]);
93 if (straw_count==numstraws[ring_count]){
94 max_sag.push_back(temp);
95 sag_phi_offset.push_back(temp2);
104 typedef map<string,double>::iterator iter_double;
106 if (jcalib->Get(
"CDC/cdc_drift_table::NoBField", tvals)==
false){
107 for(
unsigned int i=0; i<tvals.size(); i++){
108 map<string, double> &row = tvals[i];
109 iter_double iter = row.find(
"t");
114 if (jcalib->Get(
"CDC/drift_parameters::NoBField", tvals)==
false){
115 map<string, double> &row = tvals[0];
139 if (jcalib->Get(
"CDC/cdc_drift_table", tvals)==
false){
140 for(
unsigned int i=0; i<tvals.size(); i++){
141 map<string, double> &row = tvals[i];
142 iter_double iter = row.find(
"t");
147 if (jcalib->Get(
"CDC/drift_parameters", tvals)==
false){
148 map<string, double> &row = tvals[0];
173 MAX_DRIFT_TIME = 1000.0;
176 vector<const DTrackCandidate*> locTrackCandidates;
177 eventLoop->Get(locTrackCandidates,
"StraightLine");
178 gPARMS->GetParameter(
"TRKFIT:PLANE_TO_SKIP", PLANE_TO_SKIP);
188 vector<const DTrackFitter *> fitters;
191 if(fitters.size()<1){
192 _DBG_<<
"Unable to get a DTrackFinder object!"<<endl;
193 return RESOURCE_UNAVAILABLE;
197 vector <const DCDCHit *> cdcHitVector;
198 loop->Get(cdcHitVector);
200 vector <const DChargedTrack *> chargedTrackVector;
201 loop->Get(chargedTrackVector);
203 unsigned int numstraws[28]={42,42,54,54,66,66,80,80,93,93,106,106,123,123,
204 135,135,146,146,158,158,170,170,182,182,197,197,
207 for (
unsigned int iTrack = 0; iTrack < chargedTrackVector.size(); iTrack++){
215 double t0 = thisTimeBasedTrack->
t0();
217 Fill1DHistogram(
"FDCProjectionResiduals",
"",
"Tracking FOM", thisTimeBasedTrack->FOM,
"TrackingFOM", 200, 0.0, 1.0);
218 if (thisTimeBasedTrack->FOM < 0.0027 || thisTimeBasedTrack->Ndof < 4)
continue;
221 vector<DTrackFitter::pull_t> pulls = thisTimeBasedTrack->pulls;
222 for (
size_t iPull = 0; iPull < pulls.size(); iPull++){
223 if ( pulls[iPull].fdc_hit !=
nullptr){
224 if (PLANE_TO_SKIP == 0 || PLANE_TO_SKIP == pulls[iPull].fdc_hit->wire->layer){
225 double DOCA = pulls[iPull].d;
226 double residual = pulls[iPull].resi;
227 double cathode_resi = pulls[iPull].resic;
228 double tdrift = pulls[iPull].tdrift;
229 Fill2DHistogram(
"FDCProjectionResiduals",
"FDCReco",
"Distance Vs Time",
231 "Distance Vs. Time; Time [ns]; Distance [cm]",
232 300, 0.0, 300., 100, 0.0, 0.5);
233 Fill2DHistogram(
"FDCProjectionResiduals",
"FDCReco",
"Residual Vs Time",
235 "Residual Vs. Time; Time [ns]; Residual [cm]",
236 200, 0.0, 200., 160, -0.2, 0.2);
237 Fill1DHistogram(
"FDCProjectionResiduals",
"FDCReco",
"Cathode Residuals",
238 cathode_resi,
"Cathode Residual; Residual [cm];", 160,-0.2, 0.2);
244 vector<DTrackFitter::Extrapolation_t>extrapolations=thisTimeBasedTrack->extrapolations.at(
SYS_CDC);
245 if (extrapolations.size()>0){
246 for (
auto ringPtr=cdcwires.begin(); ringPtr < cdcwires.end(); ringPtr++){
247 vector< DCDCWire * > wireByNumber = (*ringPtr);
248 for (
auto wirePtr = wireByNumber.begin(); wirePtr < wireByNumber.end(); wirePtr++)
253 DVector3 POCAOnTrack(0.0, 0.0, 0.0), POCAOnWire(0.0, 0.0, 0.0);
254 double zVertex = thisTimeBasedTrack->position().Z();
255 double distanceToBeamline = thisTimeBasedTrack->position().Perp();
256 double distanceToWire;
257 if (dIsNoFieldFlag) distanceToWire = GetDOCA(wire->
origin, wire->
udir, thisTimeBasedTrack->position(), thisTimeBasedTrack->momentum(), POCAOnTrack, POCAOnWire);
259 distanceToWire=fitter->
DistToWire(wire,extrapolations,
260 &POCAOnTrack,NULL,&POCAOnWire);
262 double zPOCA = POCAOnTrack.Z();
263 DVector3 LOCA = POCAOnTrack - POCAOnWire;
264 if(distanceToWire > 1.2 || distanceToBeamline > 1.0 || zPOCA < zVertex || POCAOnWire.Z() > endplate_z)
continue;
265 jout <<
" Dist = " << distanceToWire <<
" POCAOnTrack POCAOnWire Manual Distance = " << LOCA.Mag() << endl;
269 double delta = 0.0, dz = 0.0;
270 if(!Expect_Hit(thisTimeBasedTrack, wire, distanceToWire, delta, dz, fitter))
273 for (
auto cdcHit = cdcHitVector.begin(); cdcHit != cdcHitVector.end(); cdcHit++){
274 const DCDCHit *thisHit = (*cdcHit);
279 double tdrift = thisHit->
t - t0;
280 double measurement = CDCDriftDistance(delta, tdrift);
281 double signedResidual = measurement - (POCAOnTrack.Phi() - POCAOnWire.Phi())*POCAOnTrack.Perp();
282 double residual = measurement - distanceToWire;
286 sprintf(name,
"Ring %i Residual Vs. Straw Number", thisHit->
ring);
287 sprintf(title,
"Ring %i Residual Vs. Straw Number; Straw Number; Residual [cm]", thisHit->
ring);
289 thisHit->
straw, residual,
291 numstraws[thisHit->
ring-1], 0.5, numstraws[thisHit->
ring-1] + 0.5, 1000, -0.5, 0.5);
292 sprintf(name,
"Ring %i rPhi Residual Vs. phi", thisHit->
ring);
293 sprintf(title,
"Ring %i #Deltar#phi Vs. #phi; Straw Number; Residual [cm]", thisHit->
ring);
295 thisTimeBasedTrack->momentum().Phi(), signedResidual,
297 numstraws[thisHit->
ring-1], -3.14, 3.14, 1000, -0.5, 0.5);
298 if (thisHit->
ring == 1){
299 sprintf(name,
"Ring %i Straw %i Distance Vs. Time", thisHit->
ring, thisHit->
straw);
300 sprintf(title,
"Ring %i Straw %i Distance Vs. Time ; Time [ns]; Distance [cm]", thisHit->
ring, thisHit->
straw);
302 tdrift, distanceToWire,
304 500, -50.0, 1000, 120, 0.0, 1.2);
354 double sqrt_t=
sqrt(my_t);
355 double t3=my_t*my_t*my_t;
356 double delta_mag=fabs(delta);
357 f_delta=(a1+a2*delta_mag)*sqrt_t+(b1+b2*delta_mag)*my_t
358 +(c1+c2*delta_mag+c3*delta*delta)*t3;
359 f_0=a1*sqrt_t+b1*my_t+c1*t3;
363 double sqrt_t=
sqrt(my_t);
364 double delta_mag=fabs(delta);
374 double delta_sq=delta*delta;
375 f_delta= (a1+a2*delta_mag+a3*delta_sq)*sqrt_t
376 +(b1+b2*delta_mag+b3*delta_sq)*my_t;
377 f_0=a1*sqrt_t+b1*my_t;
389 unsigned int index=0;
392 double frac=(t-cdc_drift_table[
index])/dt;
393 double d_0=0.01*(double(index)+frac);
400 d=f_delta*(d_0/f_0*P+1.-P);
409 if (distanceToWire >= 1.2 )
415 if (extrapolations.size()==0)
return false;
422 double docaphi = DOCA.Phi();
423 dz = (pos - wire->
origin).Z();
426 int ring_index = wire->
ring - 1;
427 int straw_index = wire->
straw - 1;
428 delta = max_sag[ring_index][straw_index] * ( 1. - (dz*dz/5625.)) * TMath::Cos(docaphi + sag_phi_offset[ring_index][straw_index]);
430 return (distanceToWire < (0.78 + delta) && fabs(dz) < 65.0);
437 if (x==xx[0])
return 0;
438 else if (x==xx[n-1])
return n-2;
442 int ascnd=(xx[n-1]>=xx[0]);
445 if ( (x>=xx[jm])==ascnd)
455 Float_t a = trackMomentum.Dot(trackMomentum);
456 Float_t b = trackMomentum.Dot(wireDirection);
457 Float_t
c = wireDirection.Dot(wireDirection);
458 DVector3 w0 = trackPosition - wirePosition;
459 Float_t d = trackMomentum.Dot(w0);
460 Float_t
e = wireDirection.Dot(w0);
461 Float_t sc = ((b*e - c*d)/(a*c-b*b));
462 Float_t tc = ((a*e - b*d)/(a*c-b*b));
464 POCAOnTrack = trackPosition + sc * trackMomentum;
465 POCAOnWire = wirePosition + tc * wireDirection;
466 DVector3 LOCA = w0 + sc*trackMomentum - tc*wireDirection;
JEventProcessor_FDCProjectionResiduals()
The DTrackFitter class is a base class for different charged track fitting algorithms. It does not actually fit the track itself, but provides the interface and some common support features most algorthims will need to implement.
unsigned int Locate(vector< double > &xx, double x)
double short_drift_func[3][3]
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
sprintf(text,"Post KinFit Cut")
DMagneticFieldMap * GetBfield(unsigned int run_number=1)
const DTrackTimeBased * Get_TrackTimeBased(void) const
jerror_t init(void)
Called once at program start.
static char index(char c)
~JEventProcessor_FDCProjectionResiduals()
double long_drift_func[3][3]
vector< double > cdc_drift_table
DGeometry * GetDGeometry(unsigned int run_number)
bool Expect_Hit(const DTrackTimeBased *thisTimeBasedTrack, DCDCWire *wire, double distanceToWire, double &delta, double &dz, const DTrackFitter *fitter)
unsigned int Locate(vector< double > &xx, double x)
jerror_t fini(void)
Called after last event of last event source has been processed.
const DTrackFitter * fitter
double GetDOCA(DVector3, DVector3, DVector3, DVector3, DVector3 &, DVector3 &)
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
bool GetTargetZ(double &z_target) const
z-location of center of target
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
double CDCDriftDistance(double delta, double t)
double DistToWire(const DCoordinateSystem *wire, const vector< Extrapolation_t > &extrapolations, DVector3 *pos=NULL, DVector3 *mom=NULL, DVector3 *position_along_wire=NULL) const