10 #include <trackbase_historic/SvtxVertexMap_v1.h>
17 #include <g4jets/JetMap.h>
19 #include <calobase/RawTowerGeomContainer.h>
20 #include <calobase/RawTowerContainer.h>
21 #include <calobase/RawTowerGeom.h>
22 #include <calobase/RawTowerv1.h>
24 #include <g4vertex/GlobalVertexMap.h>
25 #include <g4vertex/GlobalVertex.h>
35 #include <TLorentzVector.h>
56 _jetcolname(
"AntiKt_Tower_r05")
70 vector< float > vdummy;
134 _t_event =
new TTree(
"event",
"a Tree with global event information and tau candidates");
142 _t_event->Branch( (iter->first).c_str(),
159 _ntp_tower =
new TNtuple(
"ntp_tower",
"towers from all all tau candidates",
160 "ievent:jet_id:evtgen_pid:evtgen_etotal:evtgen_eta:evtgen_phi:evtgen_decay_prong:evtgen_decay_hcharged:evtgen_decay_lcharged:jet_eta:jet_phi:jet_etotal:tower_calo_id:tower_eta:tower_phi:tower_delta_r:tower_e");
166 _ntp_track =
new TNtuple(
"ntp_track",
"tracks from all all tau candidates",
167 "ievent:jet_id:evtgen_pid:evtgen_etotal:evtgen_eta:evtgen_phi:evtgen_decay_prong:evtgen_decay_hcharged:evtgen_decay_lcharged:jet_eta:jet_phi:jet_etotal:track_quality:track_eta:track_phi:track_delta_r:track_p");
195 findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
198 cout<<
PHWHERE <<
"SvtxTrackMap node not found on node tree"
205 findNode::getClass<SvtxVertexMap>(topNode,
"SvtxVertexMap");
208 cout<<
PHWHERE <<
"SvtxVertexMap node not found on node tree"
215 PHHepMCGenEventMap *genevtmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
217 cerr <<
PHWHERE <<
" ERROR: Can't find PHHepMCGenEventMap" << endl;
225 vector< RawTowerDefs::CalorimeterId > v_caloids;
234 for (
unsigned i = 0;
i < v_caloids.size();
i++ )
237 string towers_name =
"TOWER_CALIB_";
240 RawTowerContainer *towers = findNode::getClass<RawTowerContainer>(topNode,towers_name);
242 cerr <<
PHWHERE <<
" ERROR: Can't find " << towers_name << endl;
247 string towergeom_name =
"TOWERGEOM_";
252 cerr <<
PHWHERE <<
" ERROR: Can't find " << towergeom_name << endl;
257 map_calotower.insert( make_pair( v_caloids.at(
i ), make_pair( towers, geom ) ) );
263 iter != recojets->
end();
278 tauCandidateMap.insert( make_pair( (iter->second)->get_e(),
tc ) );
315 int med_i = v.size()/2;
316 vector<float> temp_v;
317 for(
int i=0;(unsigned)
i<v.size();
i++)
318 if (v[
i] > (v[med_i] - v[med_i]*0.2) && v[
i] < (v[med_i] + v[med_i]*0.2)) temp_v.push_back(v[
i]);
320 for(
int j=0;(unsigned)
j<temp_v.size();
j++) sum = sum + temp_v[
j];
322 return sum/temp_v.size();
335 int pdg_electron = 11;
338 HepMC::GenParticle* particle_electron = NULL;
343 HepMC::GenEvent *theEvent = genevt->
getEvent();
346 for ( HepMC::GenEvent::particle_iterator
p = theEvent->particles_begin();
347 p != theEvent->particles_end(); ++
p ) {
349 if((*p)->pdg_id() == pdg_electron && (*p)->status() == 1) particle_electron = (*
p);
354 HepMC::GenParticle* particle_lq = truth.
FindParticle( pdg_lq );
361 HepMC::GenParticle* particle_tau = NULL;
369 HepMC::GenParticle* particle_quark = NULL;
370 for (
int pdg_quark = 1; pdg_quark < 7; pdg_quark++ )
376 pdg_parton = pdg_quark;
384 pdg_parton = -pdg_quark;
393 particle_tau->momentum().eta(),
394 particle_tau->momentum().phi() );
403 cout <<
"ERROR: Try to set PidCandidate::evtgen_pid for PidCandidate with evtgen_pid != 0" << endl;
414 if ( particle_tau->end_vertex() )
417 uint tau_decay_prong = 0;
418 uint tau_decay_hcharged = 0;
419 uint tau_decay_lcharged = 0;
422 truth.
FindDecayParticles( particle_tau, tau_decay_prong, tau_decay_hcharged, tau_decay_lcharged );
437 particle_quark->momentum().eta(),
438 particle_quark->momentum().phi() );
446 cout <<
"ERROR: Try to set PidCandidate::evtgen_pid for PidCandidate with evtgen_pid != 0" << endl;
457 if( particle_electron )
461 particle_electron->momentum().eta(),
462 particle_electron->momentum().phi() );
470 cout <<
"ERROR: Try to set PidCandidate::evtgen_pid for PidCandidate with evtgen_pid != 0" << endl;
491 for (type_map_tcan::iterator iter = tauCandidateMap.begin();
492 iter != tauCandidateMap.end();
498 float jet_mtrans = sqrt( pow( jetx->
get_mass(), 2 ) +
499 pow( jetx->
get_pt(), 2 ) );
502 unsigned int jet_ncomp_above_0p1 = 0;
503 unsigned int jet_ncomp_above_1 = 0;
504 unsigned int jet_ncomp_above_10 = 0;
510 switch ( jcompiter->first )
530 float e_component = 0;
531 if ( map_calotower->find( calo_id ) != map_calotower->end() )
532 e_component = ( ( ( map_calotower->find( calo_id ) )->second ).first )->getTower( jcompiter->second )->get_energy();
535 if ( e_component > 0.1 )
536 jet_ncomp_above_0p1++;
537 if ( e_component > 1 )
539 if ( e_component > 10 )
540 jet_ncomp_above_10++;
568 float delta_R_cutoff_r1 = 0.1;
569 float delta_R_cutoff_r2 = 0.2;
570 float delta_R_cutoff_r3 = 0.3;
571 float delta_R_cutoff_r4 = 0.4;
572 float delta_R_cutoff_r5 = 0.5;
581 for (type_map_tcan::iterator iter = tauCandidateMap.begin();
582 iter != tauCandidateMap.end();
608 float emcal_radius = 0;
610 float emcal_rms_esum = 0;
613 for (type_map_cdata::iterator iter_calo = map_towers->begin();
614 iter_calo != map_towers->end();
622 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
629 if ( tower_energy < tower_emin )
633 RawTowerGeom * tower_geom = ((iter_calo->second).second)->get_tower_geometry(tower -> get_key());
634 float tower_eta = tower_geom->
get_eta();
635 float tower_phi = tower_geom->
get_phi();
645 float delta_R =
CalculateDeltaR( tower_eta , tower_phi, jet_eta, jet_phi );
650 float tower_data[17] = {(float)
_ievent,
662 (float) (iter_calo->first),
673 if ( delta_R <= delta_R_cutoff_r1 )
677 emcal_er1 += tower_energy;
679 if ( delta_R <= delta_R_cutoff_r2 )
683 emcal_er2 += tower_energy;
685 if ( delta_R <= delta_R_cutoff_r3 )
689 emcal_er3 += tower_energy;
691 if ( delta_R <= delta_R_cutoff_r4 )
695 emcal_er4 += tower_energy;
697 if ( delta_R <= delta_R_cutoff_r5 )
701 emcal_er5 += tower_energy;
704 if ( delta_R <= delta_R_cutoff_r5 )
706 rms += tower_energy*delta_R*delta_R;
707 rms_esum += tower_energy;
709 radius += tower_energy*delta_R;
713 emcal_rms += tower_energy*delta_R*delta_R;
714 emcal_rms_esum += tower_energy;
715 emcal_radius += tower_energy*delta_R;
733 if ( emcal_rms_esum > 0 )
735 emcal_radius /= emcal_rms_esum;
736 emcal_rms /= emcal_rms_esum;
737 emcal_rms = sqrt( emcal_rms );
746 for(
int r_i = 1; r_i<n_steps+1; r_i++){
747 float e_tower_sum = 0;
750 for (type_map_cdata::iterator iter_calo = map_towers->begin();
751 iter_calo != map_towers->end();
758 if (e_tower_sum >= 0.9*jet_e)
break;
760 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
766 if ( tower_energy < tower_emin )
769 RawTowerGeom * tower_geom = ((iter_calo->second).second)->get_tower_geometry(tower -> get_key());
770 float tower_eta = tower_geom->
get_eta();
771 float tower_phi = tower_geom->
get_phi();
773 float delta_R =
CalculateDeltaR( tower_eta , tower_phi, jet_eta, jet_phi );
775 if(delta_R < r_i*delta_R_cutoff_r5/n_steps) {
776 e_tower_sum = e_tower_sum + tower_energy;
777 r90 = r_i*delta_R_cutoff_r5/n_steps;
781 if (e_tower_sum >= 0.9*jet_e)
break;
816 for (type_map_tcan::iterator iter = tauCandidateMap.begin();
817 iter != tauCandidateMap.end();
820 uint tracks_count_r02 = 0;
821 int tracks_chargesum_r02 = 0;
822 float tracks_rmax_r02 = 0;
824 uint tracks_count_r04 = 0;
825 int tracks_chargesum_r04 = 0;
826 float tracks_rmax_r04 = 0;
828 uint tracks_count_R = 0;
829 int tracks_chargesum_R = 0;
830 float tracks_rmax_R = 0;
832 vector<float> tracks_vertex;
833 vector<float> temp_vertex;
848 track_itr != trackmap->
end(); track_itr++) {
853 float track_eta = track->
get_eta();
854 float track_phi = track->
get_phi();
858 float delta_R =
CalculateDeltaR( track_eta, track_phi, jet_eta, jet_phi );
871 if(delta_R < 0.5 && trutheval->is_primary(g4particle)) tracks_vertex.push_back(sqrt(pow(gvx,2)+pow(gvy,2)+pow(gvz,2)));
876 float track_data[17] = {(float)
_ievent,
892 (
float) track->
get_p()
902 tracks_chargesum_r02 += track_charge;
904 if ( delta_R > tracks_rmax_r02 )
905 tracks_rmax_r02 = delta_R;
911 tracks_chargesum_r04 += track_charge;
913 if ( delta_R > tracks_rmax_r04 )
914 tracks_rmax_r04 = delta_R;
917 if ( delta_R < R_max )
920 tracks_chargesum_R += track_charge;
922 if ( delta_R > tracks_rmax_R )
923 tracks_rmax_R = delta_R;
928 std::sort(tracks_vertex.begin(),tracks_vertex.end());
931 float avg =
Average(tracks_vertex);
955 for (type_map_tcan::iterator iter = tauCandidateMap.begin();
956 iter != tauCandidateMap.end();
967 (iter_prop->second).push_back( (iter->second)->get_property_float( (iter_prop->first) ) );
971 (iter_prop->second).push_back( (iter->second)->get_property_int( (iter_prop->first) ) );
975 (iter_prop->second).push_back( (iter->second)->get_property_uint( (iter_prop->first) ) );
994 float eta_ref_local = eta_ref;
995 float phi_ref_local = phi_ref;
999 if( phi_ref_local > TMath::Pi() ) phi_ref_local = phi_ref_local - 2*TMath::Pi();
1002 float min_delta_R = 100;
1003 type_map_tcan::iterator min_delta_R_iter = candidates->end();
1005 for (type_map_tcan::iterator iter = candidates->begin();
1006 iter != candidates->end();
1012 float delta_R =
CalculateDeltaR( eta, phi, eta_ref_local, phi_ref_local );
1014 if ( delta_R < min_delta_R )
1016 min_delta_R_iter = iter; ;
1017 min_delta_R = delta_R;
1022 if ( min_delta_R_iter != candidates->end() && min_delta_R < 0.5 )
1023 best_candidate = min_delta_R_iter->second;
1025 return best_candidate;
1035 if( ( phi1 < -0.9*TMath::Pi()) && ( phi2 > 0.9*TMath::Pi() ) ) phi2 = phi2 - 2*TMath::Pi();
1036 if( ( phi1 > 0.9*TMath::Pi()) && ( phi2 < -0.9*TMath::Pi() ) ) phi1 = phi1 - 2*TMath::Pi();
1038 float delta_R = sqrt( pow( eta2 - eta1, 2 ) + pow( phi2 - phi1, 2 ) );
1055 float Et_miss_phi = 0;
1063 for (type_map_cdata::iterator iter_calo = map_towers->begin();
1064 iter_calo != map_towers->end();
1073 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
1080 if ( tower_energy < tower_emin )
1084 RawTowerGeom * tower_geom = ((iter_calo->second).second)->get_tower_geometry(tower -> get_key());
1085 float tower_eta = tower_geom->
get_eta();
1086 float tower_phi = tower_geom->
get_phi();
1096 float tower_energy_t = tower_energy / cosh( tower_eta );
1099 Ex_sum += tower_energy_t * cos( tower_phi );
1100 Ey_sum += tower_energy_t * sin( tower_phi );
1105 Et_miss = sqrt( Ex_sum * Ex_sum + Ey_sum * Ey_sum );
1106 Et_miss_phi = atan2( Ey_sum , Ex_sum );
1110 for (type_map_tcan::iterator iter = tauCandidateMap.begin();
1111 iter != tauCandidateMap.end();
1115 the_tau = iter->second;
1158 (iter->second) = NAN;
1166 (iter->second).clear();