20 #include <g4jets/JetMap.h>
22 #include <calobase/RawTowerGeomContainer.h>
23 #include <calobase/RawTowerContainer.h>
24 #include <calobase/RawTowerGeom.h>
25 #include <calobase/RawTowerv1.h>
26 #include <calobase/RawTowerDefs.h>
28 #include <calobase/RawClusterContainer.h>
29 #include <calobase/RawCluster.h>
31 #include <g4vertex/GlobalVertexMap.h>
32 #include <g4vertex/GlobalVertex.h>
40 #include <TLorentzVector.h>
45 #include <TDatabasePDG.h>
54 _do_process_geant4_cluster(
false),
55 _do_process_truth(
false),
59 _tree_event_cluster(nullptr),
60 _tree_event_truth(nullptr),
61 _beam_electron_ptotal(10),
62 _beam_hadron_ptotal(250),
79 vector< float > vdummy;
168 _tree_event_cluster =
new TTree(
"event_cluster",
"a Tree with global event information and EM candidates");
192 _tree_event_truth->SetTitle(
"a Tree with global event information and truth particle candidates");
269 vector< string > v_ecals;
270 v_ecals.push_back(
"EEMC");
271 v_ecals.push_back(
"CEMC");
272 v_ecals.push_back(
"FEMC");
273 for (
unsigned idx = 0;
idx < v_ecals.size();
idx++ )
277 string clusternodename =
"CLUSTER_" + v_ecals.at(
idx );
282 cerr <<
PHWHERE <<
" ERROR: Can't find node " << clusternodename << endl;
286 cerr <<
PHWHERE <<
" ERROR: Can't find node SvtxTrackMap" << endl;
290 for (
unsigned int k = 0;
k < clusterList->
size(); ++
k)
294 float e_cluster_threshold = 0.3;
295 if ( cluster->
get_energy() < e_cluster_threshold )
317 int embedding_id = 1;
321 std::cout <<
PHWHERE <<
"WARNING: Node PHHepMCGenEventMap missing subevent with embedding ID "<< embedding_id;
322 std::cout <<
". Print PHHepMCGenEventMap:";
327 HepMC::GenEvent* theEvent = genevt->
getEvent();
331 std::cout <<
PHWHERE <<
"WARNING: Missing requested GenEvent!" << endl;
342 for (HepMC::GenEvent::particle_const_iterator
p = theEvent->particles_begin();
343 p != theEvent->particles_end(); ++
p)
345 TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle( (*p)->pdg_id() );
350 charge = pdg_p->Charge() / 3;
354 if ( (*p)->status() != 1 )
360 float mom_eta = -1 * log ( tan( (*p)->momentum().theta() / 2.0 ) );
371 if ( particle_scattered_l &&
372 (*
p) == particle_scattered_l )
393 float eta = -1 * log( tan( theta / 2.0 ) );
422 float best_track_dr = NAN;
429 float theta = 2.0 * atan( exp( -1 * best_track->
get_eta() ) );
448 float e3x3_femc = NAN;
449 float e3x3_fhcal = NAN;
450 float e3x3_eemc = NAN;
453 state_itr != best_track->
end_states(); state_itr++) {
497 float gpt = sqrt(gpx * gpx + gpy * gpy);
498 float gptotal = sqrt(gpx * gpx + gpy * gpy + gpz * gpz);
507 gtheta = atan2( gpt, gpz );
508 geta = -1 * log( tan( gtheta / 2.0 ) );
511 gphi = atan2(gpy, gpx);
514 TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle( primary->
get_pid() );
519 gcharge = pdg_p->Charge() / 3;
532 bool fill_in_truth =
false;
545 double posv[3] = {0.,0.,0.};
546 posv[0] = the_state->
get_x();
547 posv[1] = the_state->
get_y();
548 posv[2] = the_state->
get_z();
550 float track2cluster_theta = atan(sqrt(posv[0]*posv[0]+
551 posv[1]*posv[1]) / posv[2]);
552 float track2cluster_eta = -log(abs(tan(track2cluster_theta/2)));
553 if(tan(track2cluster_theta/2)<0)
554 track2cluster_eta*=-1;
555 float track2cluster_phi = atan(posv[1]/posv[0]);
556 float track2cluster_x = posv[0];
557 float track2cluster_y = posv[1];
558 float track2cluster_z = posv[2];
561 float track2cluster_p = 0;
605 else if(fill_in_truth)
635 if ( abs( primary->
get_pid() ) == 11 )
638 if ( abs( primary->
get_pid() ) == 211 )
641 if ( abs( primary->
get_pid() ) == 321 )
644 if ( abs( primary->
get_pid() ) == 2212 )
691 float Et_miss_phi = 0;
699 vector < string > calo_names;
700 calo_names.push_back(
"CEMC" );
701 calo_names.push_back(
"HCALIN" );
702 calo_names.push_back(
"HCALOUT" );
703 calo_names.push_back(
"FEMC" );
704 calo_names.push_back(
"FHCAL" );
705 calo_names.push_back(
"EEMC" );
707 for (
unsigned i = 0;
i < calo_names.size();
i++ )
710 string towernodename =
"TOWER_CALIB_" + calo_names.at(
i );
714 std::cout <<
PHWHERE <<
": Could not find node " << towernodename.c_str() << std::endl;
718 string towergeomnodename =
"TOWERGEOM_" + calo_names.at(
i );
722 cout <<
PHWHERE <<
": Could not find node " << towergeomnodename.c_str() << endl;
731 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
738 if ( tower_energy < tower_emin )
743 float tower_eta = tower_geom->
get_eta();
744 float tower_phi = tower_geom->
get_phi();
754 float tower_energy_t = tower_energy / cosh( tower_eta );
757 Ex_sum += tower_energy_t * cos( tower_phi );
758 Ey_sum += tower_energy_t * sin( tower_phi );
763 Et_miss = sqrt( Ex_sum * Ex_sum + Ey_sum * Ey_sum );
764 Et_miss_phi = atan( Ey_sum / Ex_sum );
780 for (type_map_tcan::iterator iter = electronCandidateMap.begin();
781 iter != electronCandidateMap.end();
792 (iter_prop->second).push_back( (iter->second)->get_property_float( (iter_prop->first) ) );
796 (iter_prop->second).push_back( (iter->second)->get_property_int( (iter_prop->first) ) );
800 (iter_prop->second).push_back( (iter->second)->get_property_uint( (iter_prop->first) ) );
819 return best_candidate;
829 if( ( phi1 < -0.9*TMath::Pi()) && ( phi2 > 0.9*TMath::Pi() ) ) phi2 = phi2 - 2*TMath::Pi();
830 if( ( phi1 > 0.9*TMath::Pi()) && ( phi2 < -0.9*TMath::Pi() ) ) phi1 = phi1 - 2*TMath::Pi();
832 float delta_R = sqrt( pow( eta2 - eta1, 2 ) + pow( phi2 - phi1, 2 ) );
841 for (type_map_tcan::iterator iter = em_candidates.begin();
842 iter != em_candidates.end();
853 float e1_theta = NAN;
855 if ( mode ==
"cluster" )
860 else if ( mode ==
"truth" )
867 cout <<
"WARNING: Unknown mode " << mode <<
" selected." << endl;
875 float e1_theta_rel = M_PI - e1_theta;
878 float dis_s = 4.0 * e0_E * p0_E;
880 float dis_Q2 = 2.0 * e0_E * e1_E * ( 1 - cos( e1_theta_rel ) );
883 float dis_y = 1.0 - ( e1_E / e0_E ) + ( dis_Q2 / ( 4.0 * e0_E * e0_E ) );
888 float dis_x = dis_Q2 / ( dis_s * dis_y );
891 float dis_W = sqrt( dis_W2 );
908 std::cout <<
PHWHERE <<
" WARNING: Can't find requested PHHepMCGenEventMap" << endl;
913 int embedding_id = 1;
917 std::cout <<
PHWHERE <<
"WARNING: Node PHHepMCGenEventMap missing subevent with embedding ID "<< embedding_id;
918 std::cout <<
". Print PHHepMCGenEventMap:";
923 HepMC::GenEvent* theEvent = genevt->
getEvent();
927 std::cout <<
PHWHERE <<
"WARNING: Missing requested GenEvent!" << endl;
931 int true_process_id = theEvent->signal_process_id();
940 if ( theEvent->pdf_info() )
943 ev_x = theEvent->pdf_info()->x2();
944 ev_Q2 = theEvent->pdf_info()->scalePDF();
945 ev_y = ev_Q2 / ( ev_x * ev_s );
967 (iter->second) = NAN;
975 (iter->second).clear();