13 #include <calobase/RawTowerGeomContainer.h>
14 #include <calobase/RawTowerContainer.h>
15 #include <calobase/RawTower.h>
16 #include <calobase/RawClusterContainer.h>
17 #include <calobase/RawCluster.h>
18 #include <calobase/RawClusterUtility.h>
20 #include <phgenfit/Fitter.h>
22 #include <phgeom/PHGeomUtility.h>
24 #include <phfield/PHFieldUtility.h>
32 #include <GenFit/AbsTrackRep.h>
33 #include <GenFit/MeasuredStateOnPlane.h>
34 #include <GenFit/RKTrackRep.h>
38 #include <TDatabasePDG.h>
39 #include <TMatrixDSymfwd.h>
40 #include <TMatrixTSym.h>
41 #include <TMatrixTUtils.h>
42 #include <TParticlePDG.h>
62 #define LogDebug(exp) std::cout<<"DEBUG: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<std::endl
63 #define LogError(exp) std::cout<<"ERROR: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<std::endl
64 #define LogWarning(exp) std::cout<<"WARNING: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<std::endl
73 _pid_guess(pid_guess),
94 string nodename =
"TOWERGEOM_" +
_cal_names[i];
96 topNode, nodename.c_str());
104 tgeo_manager->Export(
"Geo_extract.root");
110 "RKTrackRep",
false);
122 <<
"================== PHGenFitTrackProjection::InitRun() ====================="
126 cout <<
" " <<
_cal_names[i] <<
" projection radius: "
130 cout <<
" projections still curl after the mag field" << endl;
132 <<
" projections start from the vertex momentum vector (M.S. effects could be large)"
134 cout <<
" projections don't correct for the slat HCAL geometry" << endl;
136 <<
"==========================================================================="
145 cout <<
"PHGenFitTrackProjection::process_event -- entered" << endl;
152 SvtxTrackMap* _g4tracks = findNode::getClass<SvtxTrackMap>(topNode,
155 cerr <<
PHWHERE <<
" ERROR: Can't find SvtxTrackMap." << endl;
165 cout <<
"Projecting tracks into: " <<
_cal_names[i] << endl;
168 string towergeonodename =
"TOWERGEOM_" +
_cal_names[i];
172 cerr <<
PHWHERE <<
" ERROR: Can't find node " << towergeonodename
178 string towernodename =
"TOWER_CALIB_" +
_cal_names[i];
180 topNode, towernodename.c_str());
183 cerr <<
PHWHERE <<
" ERROR: Can't find node " << towernodename
189 string clusternodename =
"CLUSTER_" +
_cal_names[i];
195 std::string nodeName =
"CLUSTER_POS_COR_" +
_cal_names[i];
196 clusterList = findNode::getClass<RawClusterContainer>( topNode, nodeName.c_str());
199 std::cout <<
"Grabbing CEMC position recalib clusters"
204 cerr <<
PHWHERE <<
" ERROR: Can't find node " << clusternodename
211 iter != _g4tracks->
end(); ++iter) {
216 <<
": track->get_charge(): "<<track->
get_charge()
225 cout <<
"projecting track id " << track->
get_id() << endl;
228 cout <<
" track pt = " << track->
get_pt() << endl;
231 std::vector<double>
point;
232 point.assign(3, -9999.);
243 auto pdg = unique_ptr<TDatabasePDG> (TDatabasePDG::Instance());
246 if(reco_charge*gues_charge<0)
_pid_guess *= -1;
250 <<
": guess charge: " << gues_charge
251 <<
": reco charge: " << reco_charge
257 auto rep = unique_ptr<genfit::AbsTrackRep> (
new genfit::RKTrackRep(
_pid_guess));
259 unique_ptr<genfit::MeasuredStateOnPlane> msop80 =
nullptr;
269 for (
int k = 0;
k < 6; ++
k) {
270 for (
int j = 0; j < 6; ++j) {
275 msop80 = unique_ptr<genfit::MeasuredStateOnPlane> (
new genfit::MeasuredStateOnPlane(rep.get()));
277 msop80->setPosMomCov(
pos,
mom, cov);
282 double x = msop80->getPos().X();
283 double y = msop80->getPos().Y();
284 double z = msop80->getPos().Z();
287 double pz = msop80->getMom().Z();
288 genfit::FieldManager *field_mgr = genfit::FieldManager::getInstance();
289 double Bx=0, By=0,
Bz=0;
290 field_mgr->getFieldVal(x,y,z,Bx,By,
Bz);
293 <<
": { " << msop80->getPos().Perp() <<
", " << msop80->getPos().Phi() <<
", " << msop80->getPos().Eta() <<
"} @ "
295 <<
"{ " << msop80->getMom().Perp() <<
", " << msop80->getMom().Phi() <<
", " << pz <<
"} "
301 rep->extrapolateToCylinder(*msop80,
_cal_radii[i], TVector3(0,0,0), TVector3(0,0,1));
310 cout<<__LINE__<<endl;
312 double x = msop80->getPos().X();
313 double y = msop80->getPos().Y();
314 double z = msop80->getPos().Z();
317 double pz = msop80->getMom().Z();
318 genfit::FieldManager *field_mgr = genfit::FieldManager::getInstance();
319 double Bx=0, By=0,
Bz=0;
320 field_mgr->getFieldVal(x,y,z,Bx,By,
Bz);
323 <<
": { " << msop80->getPos().Perp() <<
", " << msop80->getPos().Phi() <<
", " << msop80->getPos().Eta() <<
"} @ "
325 <<
"{ " << msop80->getMom().Perp() <<
", " << msop80->getMom().Phi() <<
", " << pz <<
"} "
330 point[0] = msop80->getPos().X();
331 point[1] = msop80->getPos().Y();
332 point[2] = msop80->getPos().Z();
344 if (std::isnan(point[0]))
346 if (std::isnan(point[1]))
348 if (std::isnan(point[2]))
355 double phi = atan2(y, x);
356 double eta = asinh(z / sqrt(x * x + y * y));
359 cout <<
" initial track phi = " << track->
get_phi();
360 cout <<
", eta = " << track->
get_eta() << endl;
361 cout <<
" calorimeter phi = " << phi <<
", eta = " << eta
368 if (fabs(eta) >= 1.0)
375 double energy_3x3 = 0.0;
376 double energy_5x5 = 0.0;
377 for (
int iphi = binphi - 2; iphi <= binphi + 2; ++iphi) {
378 for (
int ieta = bineta - 2; ieta <= bineta + 2; ++ieta) {
399 if (
abs(iphi - binphi) <= 1 and
abs(ieta - bineta) <= 1)
403 cout <<
" tower " << ieta <<
" " << wrapphi
415 double min_index = -9999;
416 double min_dphi = NAN;
417 double min_deta = NAN;
420 double min_cluster_phi = NAN;
429 double dphi = atan2(sin(phi - cluster->
get_phi()),
430 cos(phi - cluster->
get_phi()));
431 double deta = eta - cluster_eta;
432 double r = sqrt(pow(dphi, 2) + pow(deta, 2));
435 min_index = iterator.first;
441 min_cluster_phi = cluster->
get_phi();
446 if (min_index != -9999) {
455 <<
": min_cluster_phi: "<<min_cluster_phi
460 cout <<
" nearest cluster dphi = " << min_dphi <<
" deta = "
461 << min_deta <<
" e = " << min_e << endl;
469 cout <<
"PHGenFitTrackProjection::process_event -- exited" << endl;