Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:15

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 /**
0004  * @file FullJetFinder.cc
0005  *
0006  * @brief module for producing a TTree with full jets (tracks + calos) studies
0007  *        Based on JetValidation macro and HF group macros
0008  *
0009  * @ingroup FullJetFinder
0010  *
0011  * @author Jakub Kvapil
0012  * Contact: jakub.kvapil@cern.ch
0013  *
0014  */
0015 #ifndef FULLJETFINDER_H
0016 #define FULLJETFINDER_H
0017 
0018 #include <fun4all/SubsysReco.h>
0019 #include <jetbase/Jetv1.h>
0020 #include <globalvertex/GlobalVertex.h>
0021 #pragma GCC diagnostic push
0022 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
0023 #include <HepMC/GenEvent.h>
0024 #include <HepMC/GenVertex.h>
0025 #pragma GCC diagnostic pop
0026 #include <particleflowreco/ParticleFlowElementv1.h>
0027 #include <trackbase_historic/SvtxTrack.h>
0028 
0029 #include <string>
0030 #include <TH1.h>
0031 #include <vector>
0032 
0033 class PHCompositeNode;
0034 class TTree;
0035 
0036 class FullJetFinder : public SubsysReco {
0037   public:
0038 
0039 enum TYPE {
0040   FULLJET,
0041   CHARGEJET,
0042   CALOJET
0043 }; 
0044 
0045   //note max 10 inputs allowed
0046   FullJetFinder(    const std::string &outputfilename = "myjetanalysis.root", FullJetFinder::TYPE jet_type = FullJetFinder::TYPE::FULLJET);
0047 
0048   ~FullJetFinder() override;
0049 
0050   /** Called during initialization.
0051       Typically this is where you can book histograms, and e.g.
0052       register them to Fun4AllServer (so they can be output to file
0053       using Fun4AllServer::dumpHistos() method).
0054    */
0055   int Init(PHCompositeNode *topNode) override;
0056 
0057   /** Called for first event when run number is known.
0058       Typically this is where you may want to fetch data from
0059       database, because you know the run number. A place
0060       to book histograms which have to know the run number.
0061    */
0062   int InitRun(PHCompositeNode *topNode) override;
0063 
0064   /** Called for each event.
0065       This is where you do the real work.
0066    */
0067   int process_event(PHCompositeNode *topNode) override;
0068 
0069   /// Clean up internals after each event.
0070   int ResetEvent(PHCompositeNode *topNode) override;
0071 
0072   /// Called at the end of each run.
0073   int EndRun(const int runnumber) override;
0074 
0075   /// Called at the end of all processing.
0076   int End(PHCompositeNode *topNode) override;
0077 
0078   /// Reset
0079   int Reset(PHCompositeNode * /*topNode*/) override;
0080 
0081   void Print(const std::string &what = "ALL") const override;
0082 
0083   void GetDistanceFromVertex(SvtxTrack *m_dst_track, GlobalVertex *m_dst_vertex,float &val_xy, float &err_xy, float &val_3d, float &chi2_3d);
0084 
0085   void add_input(const std::string &recojetname = "AntiKt_Tower_r04", const std::string &truthjetname = "AntiKt_Truth_r04", const std::string &outputtreename = "AntiKt_r04"){
0086       m_recoJetName.push_back(recojetname);
0087       m_truthJetName.push_back(truthjetname);
0088       m_TreeNameCollection.push_back(outputtreename);
0089       m_inputs += 1;
0090       jetR.push_back(std::stof(recojetname.substr(recojetname.find("r0") + 2))/10);
0091       std::cout<<"pushing name "<<recojetname<<" "<<truthjetname<<" "<<outputtreename<<" jet R"<<std::stof(recojetname.substr(recojetname.find("r0") + 2))/10<<" total inputs "<<m_inputs<<std::endl;
0092     }
0093 
0094   void doFiducialAcceptance(bool doF){doFiducial = doF;}
0095 
0096   void setPtRangeReco(double low, double high){m_ptRangeReco.first = low; m_ptRangeReco.second = high;}
0097   void setPtRangeTruth(double low, double high){m_ptRangeTruth.first = low; m_ptRangeTruth.second = high;}
0098   void doTruth(int flag){m_doTruthJets = flag; }
0099 
0100   class CutSelection: public PHObject{
0101     public:
0102       float jetptmin;
0103       float jetptmax;
0104   };
0105 
0106   struct neConstituent{
0107     ParticleFlowElement::PFLOWTYPE pflowtype;
0108     float e;
0109     float eta;
0110     float phi;
0111   } ;
0112 
0113   struct chConstituent{
0114     ParticleFlowElement::PFLOWTYPE pflowtype;
0115     int vtx_id;
0116     float e;
0117     float eta;
0118     float phi;
0119     float pt;
0120     int charge;
0121     float DCA_xy;
0122     float DCA_xy_unc;
0123     float sDCA_xy;
0124     float DCA3d;
0125     float sDCA3d;
0126     int n_mvtx;
0127     int n_intt;
0128     int n_tpc;
0129     float chisq;
0130     int ndf;
0131   } ;
0132 
0133   //! reconstructed jets
0134   class RecoJets{
0135     public:
0136       int id;
0137       float area;
0138       int num_Constituents;
0139       int num_ChConstituents;
0140       float px;
0141       float py;
0142       float pz;
0143       float pt;
0144       float eta;
0145       float phi;
0146       float m;
0147       float e;
0148       std::vector<neConstituent> neConstituents;
0149       std::vector<chConstituent> chConstituents;
0150 
0151     using List = std::vector<RecoJets>;
0152   };
0153 
0154    struct quark{
0155     int vtx_barcode;
0156     int pdgid;
0157     float px;
0158     float py;
0159     float pz;
0160     float e;
0161   } ;
0162 
0163   //! truth jets
0164   class TruthJets{
0165     public:
0166       int id;
0167       float area;
0168       int num_Constituents;
0169       int num_ChConstituents;
0170       float px;
0171       float py;
0172       float pz;
0173       float pt;
0174       float eta;
0175       float phi;
0176       float m;
0177       float e;
0178       std::vector<int> constituents_PDG_ID;
0179       std::vector<quark> constituents_origin_quark;
0180 
0181     using List = std::vector<TruthJets>;
0182   };
0183 
0184    class PrimaryVertex{
0185     public:
0186       float id;
0187       float x;
0188       float y;
0189       float z;
0190       float x_unc;
0191       float y_unc;
0192       float z_unc;
0193       float chisq;
0194       int ndf;
0195       GlobalVertex::VTXTYPE vtxtype;
0196       using List = PrimaryVertex;
0197   };
0198 
0199   class Container: public PHObject
0200   {
0201     public:
0202     void Reset();
0203     PrimaryVertex::List primaryVertex;
0204     int reco_jet_n;
0205     int truth_jet_n;
0206     int centrality;
0207     float impactparam;
0208     RecoJets::List recojets;
0209     TruthJets::List truthjets;
0210    
0211     ClassDef(Container,1)
0212   };
0213 
0214  private:
0215   int m_inputs = 0;
0216   std::vector<std::string> m_TreeNameCollection;
0217   std::vector<std::string> m_recoJetName;
0218   std::vector<std::string> m_truthJetName;
0219   std::string m_outputFileName;
0220   std::pair<double, double> m_etaRange;
0221   std::pair<double, double> m_ptRangeReco;
0222   std::pair<double, double> m_ptRangeTruth;
0223   int m_doTruthJets;
0224 
0225   bool doFiducial = false;
0226 
0227   //! Output Tree variables
0228   TTree *m_T[10];
0229   std::vector<float>jetR;
0230   TH1I *m_stat;
0231   FullJetFinder::TYPE m_jet_type;
0232 
0233   //! main branch
0234   Container* m_container[10];
0235 
0236   TH1D *m_chi2ndf[10];
0237   TH1I *m_mvtxcl[10];
0238   TH1I *m_inttcl[10];
0239   TH1I *m_mtpccl[10];
0240 };
0241 
0242 #endif // FULLJETFINDER_H