3 #include <phfield/PHFieldConfig_v3.h>
4 #include <phfield/PHFieldUtility.h>
5 #include <phgeom/PHGeomUtility.h>
17 #include <GenFit/FieldManager.h>
18 #include <GenFit/MaterialEffects.h>
19 #include <GenFit/TGeoMaterialInterface.h>
20 #include <ktracker/SRecEvent.h>
21 #include <ktracker/GFTrack.h>
22 #include <TGeoManager.h>
29 static bool inited =
false;
31 static double Z_TARGET;
33 static double Z_UPSTREAM;
37 static double SIGX_BEAM;
38 static double SIGY_BEAM;
41 void initGlobalVariables()
51 std::cout<<
"Z_UPSTREAM :" <<Z_UPSTREAM<<std::endl;
52 std::cout<<
"Z_DUMP :" <<Z_DUMP<<std::endl;
53 std::cout<<
"Z_TARGET :" <<Z_TARGET<<std::endl;
65 legacyContainer_in(false),
66 legacyContainer_out(false),
67 enableSingleRetracking(false),
81 initGlobalVariables();
82 std::cout<<
"global variables set"<<std::endl;
87 initGlobalVariables();
112 std::vector<int> trackIDs1;
113 std::vector<int> trackIDs2;
115 if(
Verbosity() > 10) std::cout <<
"SQVertexing_v2::process_event(): nTracks = " << nTracks << std::endl;
116 for(
int i = 0; i < nTracks; ++i)
127 if(
Verbosity() > 10) std::cout <<
" N of trackIDs1 & trackIDs1 = " << trackIDs1.size() <<
" & " << trackIDs2.size() << std::endl;
129 for(std::size_t i = 0; i < trackIDs1.size(); ++i)
131 for(std::size_t j =
charge1 ==
charge2 ? i+1 : 0; j < trackIDs2.size(); ++j)
134 if(trackIDs1[i] == trackIDs2[j])
continue;
144 recDimuon.set_track_id_neg(trackIDs2[j]);
166 recEvent = findNode::getClass<SRecEvent>(topNode,
"SRecEvent");
169 std::cerr <<
Name() <<
": failed finding SRecEvent node, abort." << std::endl;
175 recTrackVec = findNode::getClass<SQTrackVector>(topNode,
"SQRecTrackVector");
178 std::cerr <<
Name() <<
": failed finding SQRecTrackVector node, abort." << std::endl;
194 std::cerr <<
Name() <<
": cannot locate DST node, abort." << std::endl;
199 TString dimuonVecName = TString::Format(
"SQRecDimuonVector_%s%s", (
charge1 == 1 ?
"P" :
"M"), (
charge2 == 1 ?
"P" :
"M"));
213 if(
Verbosity() > 20) std::cout <<
"SQVertexing_v2::refitTrkToVtx(): z = " << z <<
", pos = (" << pos->X() <<
", " << pos->Y() <<
", " << pos->Z() <<
"), mom = (" << mom->X() <<
", " << mom->Y() <<
", " << mom->Z() <<
")" << std::endl;
216 double z_offset_prev = 1.E9;
217 double z_offset_curr = 0.;
219 const int n_iter_max = 100;
221 while(fabs(z_offset_curr - z_offset_prev) > 0.1)
226 z_offset_prev = z_offset_curr;
230 if(
Verbosity() > 20) std::cout <<
" i_iter = " << n_iter <<
": p = " << mom->Mag() <<
", dz = " << z_offset_curr <<
" - " << z_offset_prev <<
" = " << z_offset_curr - z_offset_prev << std::endl;
231 if (++n_iter == n_iter_max) {
232 std::cout <<
"!WARNING! SQVertexing_v2::refitTrkToVtx(): Give up the iteration." << std::endl;
236 if(
Verbosity() > 10) std::cout <<
" n_iter = " << n_iter << std::endl;
253 else if(p > 120.) p = 120.;
255 return 301.84 - 1.27137*p + 0.0218294*p*p - 0.000170711*p*p*p + 4.94683e-07*p*p*p*p - 271.;
301 if(
Verbosity() > 10) std::cout <<
" SQVertexing_v2::processOneDimuon(): " << std::endl;
319 dimuon.
vtx.SetXYZ(0., 0., z_vtx);
358 double stepsize[3] = {25., 5., 1.};
361 double chi2_min = 1.E9;
362 for(
int i = 0; i < 3; ++i)
364 double z_start, z_end;
372 z_start = z_min + stepsize[i-1];
373 z_end = z_min - stepsize[i-1];
375 for(
double z = z_start; z > z_end; z = z - stepsize[i])
379 double chi2 = chi2_1 > 0 && chi2_2 > 0 ? chi2_1 + chi2_2 : 1.E9;
393 std::cout<<
"setting up the B field and storing in 'gfiled'"<<std::endl;
398 catch(
const std::exception& e)
400 std::cout <<
"SQVertexing::InitGeom - Caught an exception " << std::endl;
411 std::cout <<
"SQVertexing_v2::InitField - creating new GenFit field map" << std::endl;
414 genfit::FieldManager::getInstance()->init(
gfield);
415 genfit::MaterialEffects::getInstance()->init(
new genfit::TGeoMaterialInterface());
419 std::cout <<
"SQVertexing_v2::InitGeom - reading existing GenFit field map" << std::endl;
428 std::cout <<
"SQVertexing_v2::InitGeom - create geom from " <<
geom_file_name << std::endl;
431 else {std::cout <<
"geometry import failed" << std::endl;}
435 std::cout <<
"SQVertexing_v2::InitGeom - rely on existing TGeo geometry" << std::endl;
virtual const std::string Name() const
Returns the name of this module.
virtual int Verbosity() const
Gets the verbosity of this module.
PHBoolean addNode(PHNode *)
PHFieldConfig_v3 implements field configuration information for input a field map file.
static PHField * BuildFieldMap(const PHFieldConfig *field_config, const int verbosity=0)
Build or build field map with a configuration object.
transient DST object for field storage and access
virtual double get_DoubleFlag(const std::string &name) const
virtual const std::string get_CharFlag(const std::string &flag) const
PHNode * findFirst(const std::string &, const std::string &)
virtual void push_back(const SQDimuon *dim)=0
void setOffset(double offset=0.)
double swimToVertex(double z, TVector3 *pos=nullptr, TVector3 *mom=nullptr, TMatrixDSym *cov=nullptr)
virtual const SQTrack * at(const size_t id) const =0
virtual size_t size() const =0
bool processOneMuon(SRecTrack *track)
SQGenFit::GFField * gfield
double findDimuonZVertex(SRecDimuon &dimuon, SQGenFit::GFTrack &track1, SQGenFit::GFTrack &track2)
double refitTrkToVtx(SQGenFit::GFTrack &track, double z, TVector3 *pos=nullptr, TVector3 *mom=nullptr)
double calcZsclp(double p)
SQVertexing_v2(const std::string &name="SQVertexing_v2", int sign1=1, int sign2=-1)
double swimTrackToVertex(SQGenFit::GFTrack &track, double z, TVector3 *pos=nullptr, TVector3 *mom=nullptr)
std::string geom_file_name
int GetNodes(PHCompositeNode *topNode)
int Init(PHCompositeNode *topNode)
bool processOneDimuon(SRecTrack *track1, SRecTrack *track2, SRecDimuon &dimuon)
int process_event(PHCompositeNode *topNode)
int End(PHCompositeNode *topNode)
Called at the end of all processing.
int InitRun(PHCompositeNode *topNode)
SQTrackVector * recTrackVec
bool enableSingleRetracking
int MakeNodes(PHCompositeNode *topNode)
SQDimuonVector * recDimuonVec
TVector3 vtx
3-vector vertex position
TLorentzVector p_neg_target
virtual void set_track_id_pos(const int a)
Double_t chisq_target
Chisq of three test position.
TLorentzVector p_pos_target
Track momentum projections at different location.
Double_t chisq_kf
Vertex fit chisqs.
TLorentzVector p_pos
4-momentum of the muon tracks after vertex fit
TVector3 proj_target_pos
Track projections at different location.
TLorentzVector p_pos_dump
TLorentzVector p_neg_dump
void insertDimuon(SRecDimuon dimuon)
Insert dimuon.
Int_t getNTracks()
Get tracks.
void clearDimuons()
Clear the dimuon list.
SRecTrack & getTrack(Int_t i)
Int_t getCharge() const
Gets.
Double_t getChisqTarget()
void setChisqDump(Double_t chisq)
void setChisqTarget(Double_t chisq)
Double_t getChisqUpstream()
void setChisqUpstream(Double_t chisq)
Bool_t isKalmanFitted()
Fit status.
void swimToVertex(TVector3 *pos=nullptr, TVector3 *mom=nullptr, bool hyptest=true)
Simple swim to vertex.
TVector3 getDumpPos()
Get mom/pos at a given location.
void setVertexFast(TVector3 mom, TVector3 pos)
Plain setting, no KF-related stuff.
void setChisqVertex(Double_t chisq)
static recoConsts * instance()