Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:18

0001 // ----------------------------------------------------------------------------
0002 // 'SMakeTrackQATuple.cc'
0003 // Derek Anderson
0004 // 03.10.2024
0005 //
0006 // SCorrelatorQAMaker plugin to produce QA tuples
0007 // for tracks.
0008 // ----------------------------------------------------------------------------
0009 
0010 #define SCORRELATORQAMAKER_SMAKETRACKQATUPLE_CC
0011 
0012 // plugin definition
0013 #include "SMakeTrackQATuple.h"
0014 
0015 // make common namespaces implicit
0016 using namespace std;
0017 using namespace findNode;
0018 
0019 
0020 
0021 namespace SColdQcdCorrelatorAnalysis {
0022 
0023   // SMakeTrackQATuple public methods ------------------------------------------
0024 
0025   int SMakeTrackQATuple::Init(PHCompositeNode* topNode) {
0026 
0027     InitOutput();
0028     InitTuple();
0029     return Fun4AllReturnCodes::EVENT_OK;
0030 
0031   }  // end 'Init(PHCompositeNode*)'
0032 
0033 
0034 
0035   int SMakeTrackQATuple::process_event(PHCompositeNode* topNode) {
0036 
0037     DoTrackLoop(topNode);
0038     return Fun4AllReturnCodes::EVENT_OK;
0039 
0040   }  // end 'process_event(PHCompositeNode* topNode)'
0041 
0042 
0043 
0044   int SMakeTrackQATuple::End(PHCompositeNode* topNode) {
0045 
0046     SaveOutput();
0047     CloseOutput();
0048     return Fun4AllReturnCodes::EVENT_OK;
0049 
0050   }  // end 'End(PHCompositeNode*)'
0051 
0052 
0053 
0054   // SMakeTrackQATuple internal methods -----------------------------------------
0055 
0056   void SMakeTrackQATuple::InitTuple() {
0057 
0058     if (m_isDebugOn && (m_verbosity > 2)) {
0059       cout << "SColdQcdCorrelatorAnalysis::SMakeTrackQATuple::InitTuple(): initializing output tuple." << endl;
0060     }
0061 
0062     // create leaf lists for event and track info
0063     vector<string> vecRecLeaves = Types::RecoInfo::GetListOfMembers();
0064     vector<string> vecGenLeaves = Types::GenInfo::GetListOfMembers();
0065     vector<string> vecTrkLeaves = Types::TrkInfo::GetListOfMembers();
0066 
0067     // combine leaf lists
0068     vector<string> vecOutLeaves;
0069     Interfaces::CombineLeafLists(vecRecLeaves, vecOutLeaves);
0070     Interfaces::CombineLeafLists(vecGenLeaves, vecOutLeaves);
0071     Interfaces::CombineLeafLists(vecTrkLeaves, vecOutLeaves);
0072 
0073     // compress leaves into a color-separated list
0074     string argOutLeaves = Interfaces::FlattenLeafList(vecOutLeaves);
0075 
0076     // create tuple and return
0077     m_ntTrackQA = new TNtuple("ntTrackQA", "Track QA", argOutLeaves.data());
0078     m_vecTrackLeaves.reserve(vecOutLeaves.size());
0079     return;
0080 
0081   }  // end 'InitTuple()'
0082 
0083 
0084 
0085   void SMakeTrackQATuple::SaveOutput() {
0086 
0087     if (m_isDebugOn && (m_verbosity > 2)) {
0088       cout << "SColdQcdCorrelatorAnalysis::SMakeTrackQATuple::SaveOutput(): saving output." << endl;
0089     }
0090 
0091     m_outDir    -> cd();
0092     m_ntTrackQA -> Write();
0093     return;
0094 
0095   }  // end 'SaveOutput()'
0096 
0097 
0098 
0099   void SMakeTrackQATuple::DoTrackLoop(PHCompositeNode* topNode) {
0100 
0101     if (m_isDebugOn && (m_verbosity > 2)) {
0102       cout << "SColdQcdCorrelatorAnalysis::SMakeTrackQATuple::DoTrackLoop(PHCompositeNode*): looping over tracks." << endl;
0103     }
0104 
0105     // grab event info
0106     //   - FIXME add in subevent selection
0107     Types::RecoInfo recInfo(topNode);
0108     Types::GenInfo  genInfo(topNode, m_config.isEmbed, {2});
0109 
0110     // loop over tracks
0111     SvtxTrack*    track   = NULL;
0112     SvtxTrackMap* mapTrks = Interfaces::GetTrackMap(topNode);
0113     for (
0114       SvtxTrackMap::Iter itTrk = mapTrks -> begin();
0115       itTrk != mapTrks -> end();
0116       ++itTrk
0117     ) {
0118 
0119       // grab track and skip if bad
0120       track = itTrk -> second;
0121       if (!track) continue;
0122 
0123       const bool isGoodTrack = IsGoodTrack(track, topNode);
0124       if (!isGoodTrack) continue;
0125 
0126       // grab track info
0127       Types::TrkInfo trkInfo(track, topNode);
0128 
0129       // set tuple leaves
0130       m_vecTrackLeaves[0]  = (float) recInfo.GetNTrks();
0131       m_vecTrackLeaves[1]  = (float) recInfo.GetPSumTrks();
0132       m_vecTrackLeaves[2]  = (float) recInfo.GetESumEMCal();
0133       m_vecTrackLeaves[3]  = (float) recInfo.GetESumIHCal();
0134       m_vecTrackLeaves[4]  = (float) recInfo.GetESumOHCal();
0135       m_vecTrackLeaves[5]  = (float) recInfo.GetVX();
0136       m_vecTrackLeaves[6]  = (float) recInfo.GetVY();
0137       m_vecTrackLeaves[7]  = (float) recInfo.GetVZ();
0138       m_vecTrackLeaves[8]  = (float) genInfo.GetNChrgPar();
0139       m_vecTrackLeaves[9]  = (float) genInfo.GetNNeuPar();
0140       m_vecTrackLeaves[10] = (float) genInfo.GetIsEmbed();
0141       m_vecTrackLeaves[11] = (float) genInfo.GetESumChrg();
0142       m_vecTrackLeaves[12] = (float) genInfo.GetESumNeu();
0143       m_vecTrackLeaves[13] = (float) genInfo.GetPartons().first.GetPID();
0144       m_vecTrackLeaves[14] = (float) genInfo.GetPartons().first.GetStatus();
0145       m_vecTrackLeaves[15] = (float) genInfo.GetPartons().first.GetBarcode();
0146       m_vecTrackLeaves[16] = (float) genInfo.GetPartons().first.GetEmbedID();
0147       m_vecTrackLeaves[17] = (float) genInfo.GetPartons().first.GetCharge();
0148       m_vecTrackLeaves[18] = (float) genInfo.GetPartons().first.GetMass();
0149       m_vecTrackLeaves[19] = (float) genInfo.GetPartons().first.GetEta();
0150       m_vecTrackLeaves[20] = (float) genInfo.GetPartons().first.GetPhi();
0151       m_vecTrackLeaves[21] = (float) genInfo.GetPartons().first.GetEne();
0152       m_vecTrackLeaves[22] = (float) genInfo.GetPartons().first.GetPX();
0153       m_vecTrackLeaves[23] = (float) genInfo.GetPartons().first.GetPY();
0154       m_vecTrackLeaves[24] = (float) genInfo.GetPartons().first.GetPZ();
0155       m_vecTrackLeaves[25] = (float) genInfo.GetPartons().first.GetPT();
0156       m_vecTrackLeaves[26] = (float) genInfo.GetPartons().first.GetVX();
0157       m_vecTrackLeaves[27] = (float) genInfo.GetPartons().first.GetVY();
0158       m_vecTrackLeaves[28] = (float) genInfo.GetPartons().first.GetVZ();
0159       m_vecTrackLeaves[29] = (float) genInfo.GetPartons().second.GetPID();
0160       m_vecTrackLeaves[30] = (float) genInfo.GetPartons().second.GetStatus();
0161       m_vecTrackLeaves[31] = (float) genInfo.GetPartons().second.GetBarcode();
0162       m_vecTrackLeaves[32] = (float) genInfo.GetPartons().second.GetEmbedID();
0163       m_vecTrackLeaves[33] = (float) genInfo.GetPartons().second.GetCharge();
0164       m_vecTrackLeaves[34] = (float) genInfo.GetPartons().second.GetMass();
0165       m_vecTrackLeaves[35] = (float) genInfo.GetPartons().second.GetEta();
0166       m_vecTrackLeaves[36] = (float) genInfo.GetPartons().second.GetPhi();
0167       m_vecTrackLeaves[37] = (float) genInfo.GetPartons().second.GetEne();
0168       m_vecTrackLeaves[38] = (float) genInfo.GetPartons().second.GetPX();
0169       m_vecTrackLeaves[39] = (float) genInfo.GetPartons().second.GetPY();
0170       m_vecTrackLeaves[40] = (float) genInfo.GetPartons().second.GetPZ();
0171       m_vecTrackLeaves[41] = (float) genInfo.GetPartons().second.GetPT();
0172       m_vecTrackLeaves[42] = (float) genInfo.GetPartons().second.GetVX();
0173       m_vecTrackLeaves[43] = (float) genInfo.GetPartons().second.GetVY();
0174       m_vecTrackLeaves[44] = (float) genInfo.GetPartons().second.GetVZ();
0175       m_vecTrackLeaves[45] = (float) trkInfo.GetID();
0176       m_vecTrackLeaves[46] = (float) trkInfo.GetNMvtxLayer();
0177       m_vecTrackLeaves[47] = (float) trkInfo.GetNInttLayer();
0178       m_vecTrackLeaves[48] = (float) trkInfo.GetNTpcLayer();
0179       m_vecTrackLeaves[49] = (float) trkInfo.GetNMvtxClust();
0180       m_vecTrackLeaves[50] = (float) trkInfo.GetNInttClust();
0181       m_vecTrackLeaves[51] = (float) trkInfo.GetNTpcClust();
0182       m_vecTrackLeaves[52] = (float) trkInfo.GetEta();
0183       m_vecTrackLeaves[53] = (float) trkInfo.GetPhi();
0184       m_vecTrackLeaves[54] = (float) trkInfo.GetPX();
0185       m_vecTrackLeaves[55] = (float) trkInfo.GetPY();
0186       m_vecTrackLeaves[56] = (float) trkInfo.GetPZ();
0187       m_vecTrackLeaves[57] = (float) trkInfo.GetPT();
0188       m_vecTrackLeaves[58] = (float) trkInfo.GetEne();
0189       m_vecTrackLeaves[59] = (float) trkInfo.GetDcaXY();
0190       m_vecTrackLeaves[60] = (float) trkInfo.GetDcaZ();
0191       m_vecTrackLeaves[61] = (float) trkInfo.GetPtErr();
0192       m_vecTrackLeaves[62] = (float) trkInfo.GetQuality();
0193       m_vecTrackLeaves[63] = (float) trkInfo.GetVX();
0194       m_vecTrackLeaves[64] = (float) trkInfo.GetVY();
0195       m_vecTrackLeaves[65] = (float) trkInfo.GetVZ();
0196 
0197       // fill track tuple
0198       m_ntTrackQA -> Fill(m_vecTrackLeaves.data());
0199 
0200     }  // end track loop
0201     return;
0202 
0203   }  // end 'DoTrackLoop(PHCompositeNode*)'
0204 
0205 
0206 
0207   bool SMakeTrackQATuple::IsGoodTrack(SvtxTrack* track, PHCompositeNode* topNode) {
0208 
0209     // print debug statement
0210     if (m_isDebugOn && (m_verbosity > 4)) {
0211       cout << "SMakeTrackQATuple::IsGoodTrack(SvtxTrack*, PHCompositeNode*) Checking if track is good..." << endl;
0212     }
0213 
0214     // grab track info
0215     Types::TrkInfo info(track, topNode);
0216 
0217     // if needed, check if dca is in pt-dependent range
0218     bool isInDcaSigma = true;
0219     if (m_config.doDcaSigCut) {
0220       isInDcaSigma = info.IsInSigmaDcaCut(m_config.nSigCut, m_config.ptFitMax, m_config.fSigDca);
0221     }
0222 
0223     // if needed, check if track is from primary vertex
0224     const bool isFromPrimVtx = m_config.useOnlyPrimVtx ? Tools::IsFromPrimaryVtx(track, topNode) : true;
0225 
0226     // check if seed is good & track is in acceptance
0227     const bool isSeedGood = Tools::IsGoodTrackSeed(track, m_config.requireSiSeed);
0228     const bool isInAccept = info.IsInAcceptance(m_config.trkAccept);
0229 
0230     // return overall goodness of track
0231     return (isFromPrimVtx && isInDcaSigma && isSeedGood && isInAccept);
0232 
0233   }  // end 'IsGoodTrack(SvtxTrack* track, PHCompositeNode* topNode)'
0234 
0235 }  // end SColdQcdCorrelatorAnalysis namespace
0236 
0237 // end -----------------------------------------------------------------------