43typedef vector<THaVDC::THaMatrixElement>
MEvec_t;
67 fSpacing(0.33), fCentralDist(0.),
68 fNumIter(1), fErrorCutoff(1e9), fCoordType(kRotatingTransport),
69 fTimeCorrectionModule(nullptr)
73 Error(
Here(
"THaVDC()"),
"Failed to create subdetectors." );
113 map<string,MEdef_t>& matrix_map,
121 const char*
const here =
"THaVDC::ParseMatrixElements";
123 istringstream ist(MEstring);
125 bool findnext =
true, findpowers =
true;
126 Int_t powers_left = 0;
127 auto cur = matrix_map.end();
129 while( ist >> word ) {
131 assert( cur != matrix_map.end() );
132 bool havenext = isalpha(word[0]);
134 assert( powers_left > 0 );
135 if( havenext || word.find_first_not_of(
"0123456789") != string::npos ||
136 atoi(word.c_str()) > 9 ) {
137 Error( Here(
here,prefix),
"Bad exponent = %s for matrix element \"%s\". "
138 "Must be integer between 0 and 9. Fix database.",
139 word.c_str(),
w.c_str() );
142 ME.
pw.push_back( atoi(word.c_str()) );
143 if( --powers_left == 0 ) {
145 if( cur->second.isfp ) {
147 if( ME.
pw[0] != 0 || ME.
pw[1] != 0 || ME.
pw[2] != 0 ) {
148 Error( Here(
here,prefix),
"Bad coefficients of focal plane matrix "
149 "element %s = %d %d %d. Fix database.",
150 w.c_str(), ME.
pw[0], ME.
pw[1], ME.
pw[2] );
158 MEvec_t* mat = cur->second.elems;
161 for(
auto it = mat->begin();
162 it != mat->end() && !(match = it->match(ME)); ++it ) {}
164 Warning( Here(
here,prefix),
"Duplicate definition of matrix element %s. "
165 "Using first definition.", cur->first.c_str() );
177 ME.
poly.push_back( atof(word.c_str()) );
178 if( ME.
poly.back() != 0.0 ) {
180 ME.
order =
static_cast<int>(ME.
poly.size());
184 if( havenext || ist.eof() ) {
185 if( ME.
poly.empty() ) {
187 Error( Here(
here,prefix),
"Could not read in Matrix Element %s%d%d%d!",
188 w.c_str(), ME.
pw[0], ME.
pw[1], ME.
pw[2]);
192 MEvec_t* mat = cur->second.elems;
195 if( cur->second.isfp ) {
198 Warning( Here(
here,prefix),
"Duplicate definition of focal plane "
199 "matrix element %s. Using first definition.",
213 cur = matrix_map.find(word);
214 if( cur == matrix_map.end() ) {
221 findnext =
false; findpowers =
true;
222 powers_left = cur->second.npow;
235 const char*
const here =
"ReadDatabase";
260 map<string,MEdef_t> matrix_map;
280 string MEstring, TCmodule;
281 DBRequest request1[] = {
282 {
"matrixelem", &MEstring, kString },
283 {
"time_cor", &TCmodule, kString, 0,
true },
291 if( MEstring.empty() ) {
292 Error(
Here(
here),
"No matrix elements defined. Set \"maxtrixelem\" in database." );
307 Error(
Here(
here),
"Missing FP matrix element t000. Fix database." );
311 Error(
Here(
here),
"Missing FP matrix element y000. Fix database." );
315 Error(
Here(
here),
"Missing FP matrix element p000. Fix database." );
325 if( !TCmodule.empty() ) {
327 (
FindModule(TCmodule.c_str(),
"Podd::TimeCorrectionModule",
false));
330 "Event-by-event time offsets will NOT be used!\nCheck \"time_cor\" database key",
349 Int_t disable_tracking = 0, disable_finetrack = 0, only_fastest_hit = 1;
350 Int_t do_tdc_hardcut = 1, do_tdc_softcut = 0, ignore_negdrift = 0;
356 DBRequest request[] = {
359 {
"coord_type", &coord_type, kString, 0,
true },
360 {
"disable_tracking", &disable_tracking,
kInt, 0,
true },
361 {
"disable_finetrack", &disable_finetrack,
kInt, 0,
true },
362 {
"only_fastest_hit", &only_fastest_hit,
kInt, 0,
true },
363 {
"do_tdc_hardcut", &do_tdc_hardcut,
kInt, 0,
true },
364 {
"do_tdc_softcut", &do_tdc_softcut,
kInt, 0,
true },
365 {
"ignore_negdrift", &ignore_negdrift,
kInt, 0,
true },
367 {
"MCdata", &mc_data,
kInt, 0,
true },
383 SetBit( kMCdata, mc_data );
388 if( !coord_type.empty() ) {
394 Error(
Here(
here),
"Invalid coordinate type coord_type = %s. "
395 "Must be \"Transport\" or \"RotatingTransport\". Fix database.",
396 coord_type.c_str() );
407 Error(
Here(
here),
"Illegal parameter max_matcherr = 0.0. Must be > 0. "
416 Error(
Here(
here),
"Illegal parameter num_iter = %d. Must be <= 10. "
423 Info(
Here(
here),
"VDC flags fastest/hardcut/softcut/noneg/mcdata/"
428 Info(
Here(
here),
"VDC flags fastest/hardcut/softcut/noneg/"
465 {
"time_cor",
"Trigger time offset (s)",
"GetTimeCorrectionUnchecked()" },
483 cout <<
"-----------------------------------------------\n";
484 cout <<
"ConstructTracks: ";
488 cout <<
"coarse tracking";
490 cout <<
"fine tracking";
503 cout <<
"nUpper/nLower = " << nUpper <<
" " << nLower << endl;
509 if( (nUpper == 0) xor (nLower == 0) ) {
514 cout <<
"missing cluster " << nLower <<
" " << nUpper << endl;
520 for(
int i = 0; i < nLower; i++ ) {
524 for(
int j = 0; j < nUpper; j++ ) {
539 auto* thePair =
new( (*fLUpairs)[nPairs++] )
559 int n_exist = 0, n_mod = 0;
565 n_exist =
tracks->GetLast()+1;
573 cout << nPairs <<
" pairs.\n";
582 for(
int i = 0; i < nPairs; i++ ) {
589 cout <<
"Pair " << i <<
": ";
590 thePair->Print(
"NOHEAD");
595 if( thePair->HasUsedCluster() ) {
598 cout <<
" ... skipped (cluster already used)." << endl;
604 cout <<
" ... good." << endl;
610 assert( lowerPoint && upperPoint );
623 thePair->Print(
"TRACKP");
637 for( ; t < n_exist; t++ ) {
641 if( theTrack && theTrack->
GetCreator() ==
this &&
642 *thisID == *theTrack->
GetID() ) {
659 cout <<
"Track " << t <<
" modified.\n";
666 cout <<
"Track " <<
tracks->GetLast()+1 <<
" added.\n";
673 assert(
tracks->IndexOf(theTrack) >= 0 );
675 thePair->Associate( theTrack );
676 if( theStage ==
kFine )
689 chi2_t chi2 = thePair->CalcChi2();
690 theTrack->
SetChi2( chi2.first, chi2.second - 4 );
695 Int_t nhits = chi2.second;
696 cout <<
" chi2/ndof = " << chisq <<
"/" << nhits-4;
698 cout <<
" = " << chisq/(nhits-4);
707 cout << nTracks <<
" good tracks.\n";
711 if(
tracks && n_exist > n_mod ) {
713 for(
int i = 0; i <
tracks->GetLast()+1; i++ ) {
716 if( (theTrack->GetCreator() ==
this) &&
717 ((theTrack->GetFlag() &
kStageMask) != theStage ) ) {
719 for(
int j = 0; j < nPairs; j++ ) {
722 if( thePair->GetTrack() == theTrack ) {
723 thePair->Associate(
nullptr);
732 cout <<
"Track " << i <<
" deleted.\n";
749 for(
int i = 0; i <
tracks->GetLast()+1; i++ ) {
752 theTrack->SetIndex(i);
778 cout <<
"=========================================\n";
779 cout <<
"Event: " <<
fEvNum << endl;
839 for(
Int_t t = 0; t < n_exist; t++ ) {
876 x = x0.X() - x0.Z()*theta;
877 y = x0.Y() - x0.Z()*phi;
904 Double_t cos_rho_loc = 1.0/
sqrt(1.0+tan_rho_loc*tan_rho_loc);
907 (1.0-track->
GetDTheta()*tan_rho_loc) / cos_rho_loc;
912 track->
Set(
x,
y, theta, phi);
913 track->
SetR(r_x, r_y, r_theta, r_phi);
921 const Int_t kNUM_PRECOMP_POW = 10;
926 x_fp = track->
GetX();
927 y_fp = track->
GetY();
931 x_fp = track->
GetRX();
932 y_fp = track->
GetRY();
938 Double_t powers[kNUM_PRECOMP_POW][5];
939 for(
int i=0; i<kNUM_PRECOMP_POW; i++) {
940 powers[i][0] =
pow(x_fp, i);
941 powers[i][1] =
pow(th_fp, i);
942 powers[i][2] =
pow(y_fp, i);
943 powers[i][3] =
pow(ph_fp, i);
965 Double_t p = app->GetPcentral() * (1.0+dp);
979 app->TransportToLab(
p, theta, phi, track->
GetPvect() );
990 for(
auto& ME : matrix ) {
993 for(
int i = ME.order - 1; i >= 1; i-- )
994 ME.v =
x * (ME.v + ME.poly[i]);
1007 for(
const auto& ME : matrix )
1010 auto np = ME.pw.size();
1011 for(
size_t i = 0; i <
np; ++i )
1012 v *= powers[ME.pw[i]][i + 1];
1030 for(
const auto& ME : matrix )
1032 retval += ME.v * powers[ME.pw[0]][0]
1033 * powers[ME.pw[1]][1]
1034 * powers[ME.pw[2]][2]
1035 * powers[ME.pw[3]][3];
1049 if( (
s1 ==
nullptr) || (s2 ==
nullptr) )
1059 for(
Int_t t = 0; t < n_exist; t++ ) {
1063 Double_t s1_dist = 0.0, vdc_dist = 0.0;
1064 s1->CalcPathLen(track, s1_dist);
1070 Double_t dist = (track->GetX() < 0) ? s1_dist + vdc_dist
1071 : s1_dist - vdc_dist;
1077 Int_t n_clust = track->GetNclusters();
1078 for(
Int_t i = 0; i < n_clust; i++ ) {
1079 auto* the_point =
static_cast<THaVDCPoint*
>( track->GetCluster(i) );
1084 the_point->GetVCluster()->SetTimeCorrection(tdelta);
1102 for(
Int_t t = 0; t < n_exist; t++ ) {
1109 if( !s2->CalcInterceptCoords(track,
x2,
y2) ||
1110 !s2->IsInActiveArea(
x2,
y2) ) {
1113 track->SetFlag( track->GetFlag() |
kBadTrack );
1128 const vector<THaMatrixElement>& matrix )
1132 cout << header << endl;
1133 for(
const auto& ME : matrix ) {
1134 for(
int pw : ME.pw) {
1135 cout <<
" " << setw(2) << pw;
1137 for(
int j = 0; j < ME.order; j++ ) {
1138 cout <<
" " << setprecision(4) << ME.poly[j];
1173 const char*
const here =
"ReadGeometry";
1177 vector<double>
size;
1178 DBRequest request[] = {
1179 {
"size", &
size, kDoubleV, 0,
true,
1180 0,
"\"size\" (detector size [m])" },
1187 if( !
size.empty() ) {
1188 if(
size.size() != 3 ) {
1190 "detector size. Must be exactly 3. Fix database.",
1191 static_cast<unsigned int>(
size.size()) );
1195 Error(
Here(
here),
"Illegal zero detector dimension. Fix database." );
1199 Warning(
Here(
here),
"Illegal negative value for detector dimension. "
1200 "Taking absolute. Check database." );
1232 return make_pair(0.0,
false);
UInt_t fEvNum
Index of currently open file.
size_t size(const MatrixT &matrix)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
vector< THaVDC::THaMatrixElement > MEvec_t
static Int_t ParseMatrixElements(const string &MEstring, map< string, MEdef_t > &matrix_map, const char *prefix)
static const char *const here
MEdef_t(Int_t npw, MEvec_t *elemp, Bool_t is_fp=false, Int_t fp_idx=0)
Double_t TimeOffset() const
void Clear(Option_t *option="") override
void Sort(Int_t upto=kMaxInt) override
virtual void Print(Option_t *option, const char *wildcard, Int_t recurse=1) const
virtual void SetDebug(Int_t level)
static Int_t LoadDB(FILE *file, const TDatime &date, const DBRequest *request, const char *prefix, Int_t search=0, const char *here="THaAnalysisObject::LoadDB")
static Int_t DefineVarsFromList(const void *list, EType type, EMode mode, const char *def_prefix, const TObject *obj, const char *prefix, const char *here, const char *comment_subst="")
virtual const char * Here(const char *) const
THaAnalysisObject * FindModule(const char *name, const char *classname, bool do_error=true)
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual FILE * OpenFile(const TDatime &date)
virtual THaDetector * GetDetector(const char *name)
virtual void DefineAxes(Double_t rotation_angle)
TVector3 DetToTrackCoord(const TVector3 &point) const
THaApparatus * GetApparatus() const
Bool_t CalcPathLen(THaTrack *track, Double_t &t)
THaTrackingDetector * GetCreator() const
void Set(Double_t x, Double_t y, Double_t theta, Double_t phi)
Double_t GetDTheta() const
Double_t GetRTheta() const
Int_t AddCluster(THaCluster *c)
Double_t GetTheta() const
void SetR(Double_t x, Double_t y, Double_t theta, Double_t phi)
void SetMomentum(Double_t p)
THaTrackID * GetID() const
void SetFlag(UInt_t flag)
void SetTarget(Double_t x, Double_t y, Double_t theta, Double_t phi)
void SetD(Double_t x, Double_t y, Double_t theta, Double_t phi)
void SetPathLen(Double_t pathl)
void SetChi2(Double_t chi2, Int_t ndof)
virtual THaTrack * AddTrack(TClonesArray &tracks, Double_t x, Double_t y, Double_t theta, Double_t phi, THaTrackID *ID=nullptr)
THaVDCPlane * GetUPlane() const
virtual void Clear(Option_t *opt="")
virtual Int_t CoarseTrack()
THaVDCPoint * GetPoint(Int_t i) const
virtual void SetDebug(Int_t level)
virtual Int_t FineTrack()
virtual Int_t Decode(const THaEvData &evData)
virtual EStatus Init(const TDatime &date)
void SetTimeCorrection(Double_t dt)
static Double_t CalcError(THaVDCPoint *lowerPoint, THaVDCPoint *upperPoint, Double_t spacing)
Double_t GetTheta() const
THaVDCCluster * GetUCluster() const
void SetPartner(THaVDCPoint *partner)
THaVDCPoint * GetPartner() const
std::vector< double > poly
std::vector< THaMatrixElement > fTMatrixElems
static Double_t CalcTarget2FPLen(const std::vector< THaMatrixElement > &matrix, const Double_t powers[][5])
std::vector< THaMatrixElement > fFPMatrixElems
virtual Int_t ConstructTracks(TClonesArray *tracks=nullptr, Int_t flag=0)
virtual void SetDebug(Int_t level)
void CalcTargetCoords(THaTrack *the_track)
virtual Int_t FineTrack(TClonesArray &tracks)
std::vector< THaMatrixElement > fPTAMatrixElems
Double_t GetTimeCorrectionUnchecked() const
virtual Int_t DefineVariables(EMode mode=kDefine)
std::vector< THaMatrixElement > fLMatrixElems
virtual Int_t ReadDatabase(const TDatime &date)
std::vector< THaMatrixElement > fDMatrixElems
virtual Int_t Decode(const THaEvData &)
virtual Int_t ReadGeometry(FILE *file, const TDatime &date, Bool_t required=false)
void CorrectTimeOfFlight(TClonesArray &tracks)
std::pair< Double_t, bool > GetTimeCorrection() const
std::vector< THaMatrixElement > fYMatrixElems
static void CalcMatrix(double x, std::vector< THaMatrixElement > &matrix)
std::vector< THaMatrixElement > fPMatrixElems
static void PrintME(const std::string &header, const std::vector< THaMatrixElement > &matrix)
static Double_t CalcTargetVar(const std::vector< THaMatrixElement > &matrix, const double powers[][5])
virtual void Clear(Option_t *opt="")
std::vector< THaMatrixElement > fYTAMatrixElems
void Print(const Option_t *opt="") const
THaVDC(const char *name, const char *description="", THaApparatus *a=nullptr)
Podd::TimeCorrectionModule * fTimeCorrectionModule
void FindBadTracks(TClonesArray &tracks)
void CalcFocalPlaneCoords(THaTrack *track)
virtual Int_t CoarseTrack(TClonesArray &tracks)
virtual Int_t FindVertices(TClonesArray &tracks)
void Print(Option_t *option="") const override
void Clear(Option_t *option="") override
TObject * At(Int_t idx) const override
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void SetXYZ(Double_t x, Double_t y, Double_t z)
RVec< PromoteTypes< T0, T1 > > pow(const RVec< T0 > &v, const T1 &y)
double dist(AxisAngle const &r1, AxisAngle const &r2)
Expr< UnaryOp< Sqrt< T >, Expr< A, T, D, D2, R >, T >, T, D, D2, R > sqrt(const Expr< A, T, D, D2, R > &rhs)
int CmpNoCase(const string &r, const string &s)
constexpr Double_t Sqrt2()
constexpr Double_t PiOver4()
std::pair< Double_t, Int_t > chi2_t