Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:31

0001 // ----------------------------------------------------------------------------
0002 /*! \file    JetQADefs.h
0003  *  \authors Derek Anderson
0004  *  \date    06.24.2024
0005  *
0006  *  A namespace to hold definitions of various
0007  *  enums, helper methods, etc. relevant to
0008  *  all jet QA modules.
0009  */
0010 // ----------------------------------------------------------------------------
0011 
0012 #ifndef JETQADEFS_H
0013 #define JETQADEFS_H
0014 
0015 #include <calotrigger/TriggerAnalyzer.h>
0016 
0017 #include <phool/phool.h>
0018 
0019 #include <algorithm>
0020 #include <iostream>
0021 #include <map>
0022 #include <string>
0023 #include <vector>
0024 
0025 // ----------------------------------------------------------------------------
0026 //! Namespace to hold misc. definitions for the Jet QA
0027 // ----------------------------------------------------------------------------
0028 namespace JetQADefs
0029 {
0030 
0031   // enums -------------------------------------------------------------------
0032 
0033   // -------------------------------------------------------------------------
0034   //! Trigger flags
0035   // -------------------------------------------------------------------------
0036   /*! Enumerates possible triggers for easy reference in QA modules
0037    *  and Fun4all macros. Note that these numbers ARE NOT necessarily 
0038    *  matched to the trigger bit numbers
0039    */
0040   enum GL1
0041   {
0042     Clock           = 0,  /*!< Clock */
0043     ZDCS            = 1,  /*!< ZDC South */
0044     ZDCN            = 2,  /*!< ZDC North */
0045     ZDCNS           = 3,  /*!< ZDC Coincidence */
0046     HCalSingle      = 4,  /*!< HCAL Singles */
0047     HCalCoin        = 5,  /*!< HCAL Coincidence */
0048     MBDS            = 8,  /*!< MBD S >= 1 */
0049     MBDN            = 9,  /*!< MBD N >= 1 */
0050     MBDNS1          = 10, /*!< MBD N&S >= 1 */
0051     MBDNS2          = 11, /*!< MBD N&S >= 2 */
0052     MBDNSVtx10      = 12, /*!< MBD N&S >= 1, vtx < 10 cm */
0053     MBDNSVtx30      = 13, /*!< MBD N&S >= 1, vtx < 30 cm */
0054     MBDNSVtx60      = 14, /*!< MBD N&S >= 1, vtx < 60 cm */
0055     MBDNSHCalSingle = 15, /*!< HCAL Singles + MBD NS >= 1 */
0056     MBDNSJet1       = 16, /*!< Jet 6 GeV + MBD NS >= 1 */
0057     MBDNSJet2       = 17, /*!< Jet 8 GeV + MBD NS >= 1 */
0058     MBDNSJet3       = 18, /*!< Jet 10 GeV + MBD NS >= 1 */
0059     MBDNSJet4       = 19, /*!< Jet 12 GeV + MBD NS >= 1 */
0060     Jet1            = 20, /*!< Jet 6 GeV (no MBD coincidence) */
0061     Jet2            = 21, /*!< Jet 8 GeV (no MBD coincidence) */
0062     Jet3            = 22, /*!< Jet 10 GeV (no MBD coincidence) */
0063     Jet4            = 23, /*!< Jet 12 GeV (no MBD coincidence) */
0064     MBDNSPhoton1    = 24, /*!< Photon 2 GeV+ MBD NS >= 1 */
0065     MBDNSPhoton2    = 25, /*!< Photon 3 GeV + MBD NS >= 1 */
0066     MBDNSPhoton3    = 26, /*!< Photon 4 GeV + MBD NS >= 1 */
0067     MBDNSPhoton4    = 27, /*!< Photon 5 GeV + MBD NS >= 1 */
0068     Photon1         = 28, /*!< Photon 2 GeV (no MBD coincidence) */
0069     Photon2         = 29, /*!< Photon 3 GeV (no MBD coincidence) */
0070     Photon3         = 30, /*!< Photon 4 GeV (no MBD coincidence) */
0071     Photon4         = 31, /*!< Photon 5 GeV (no MBD coincidence) */
0072     MBDNS2Vtx10     = 32, /*!< MBD N&S >= 2, vtx < 10 cm */
0073     MBDNS2Vtx30     = 33, /*!< MBD N&S >= 2, vtx < 30 cm */
0074     MBDNS2Vtx60     = 34, /*!< MBD N&S >= 2, vtx < 60 cm */
0075     MBDNS2Vtx150    = 35, /*!< MBD N&S >= 2, vtx < 150 cm */
0076     MBDNS2Photon6Vtx10  = 36, /*!< Photon 6 GeV + MBD NS >= 2, vtx < 10 cm */
0077     MBDNS2Photon8Vtx10  = 37, /*!< Photon 8 GeV + MBD NS >= 2, vtx < 10 cm */
0078     MBDNS2Photon10Vtx10 = 38, /*!< Photon 10 GeV + MBD NS >= 2, vtx < 10 cm */
0079     MBDNS2Photon12Vtx10 = 39, /*!< Photon 12 GeV + MBD NS >= 2, vtx < 10 cm */
0080     MBDNS2Photon6Vtx150 = 40, /*!< Photon 6 GeV + MBD NS >= 2, vtx < 150 cm */
0081     MBDNS2Photon8Vtx150 = 41, /*!< Photon 8 GeV + MBD NS >= 2, vtx < 150 cm */
0082     MBDNS2Photon10Vtx150 = 42, /*!< Photon 10 GeV + MBD NS >= 2, vtx < 150 cm */
0083     MBDNS2Photon12Vtx150 = 43, /*!< Photon 12 GeV + MBD NS >= 2, vtx < 150 cm */
0084     Inclusive = 44  /*!< inclusive (i.e. NO trigger selection) */
0085   };
0086 
0087   // constants ----------------------------------------------------------------
0088 
0089   // --------------------------------------------------------------------------
0090   //! Map of trigger flag onto name
0091   // --------------------------------------------------------------------------
0092   /*! This helper method provides a map from the triggers
0093    *  enumerated by `JetQADefs::GL1` to their official
0094    *  names. Used by `JetQADefs::DidTriggerFire` to
0095    *  identify if a trigger fired.
0096    */
0097   inline std::map<uint32_t, std::string> MapTriggerFlagToName()
0098   {
0099     static const std::map<uint32_t, std::string> mapFlagToName = 
0100     {
0101       {Clock           , "Clock"},
0102       {ZDCS            , "ZDC South"},
0103       {ZDCN            , "ZDC North"},
0104       {ZDCNS           , "ZDC Coincidence"},
0105       {HCalSingle      , "HCAL Singles"},
0106       {HCalCoin        , "HCAL Coincidence"},
0107       {MBDS            , "MBD S >= 1"},
0108       {MBDN            , "MBD N >= 1"},
0109       {MBDNS1          , "MBD N&S >= 1"},
0110       {MBDNS2          , "MBD N&S >= 2"},
0111       {MBDNSVtx10      , "MBD N&S >= 1, vtx < 10 cm"},
0112       {MBDNSVtx30      , "MBD N&S >= 1, vtx < 30 cm"},
0113       {MBDNSVtx60      , "MBD N&S >= 1, vtx < 60 cm"},
0114       {MBDNS2Vtx10     , "MBD N&S >= 2, vtx < 10 cm"},
0115       {MBDNS2Vtx30     , "MBD N&S >= 2, vtx < 30 cm"},
0116       {MBDNS2Vtx60     , "MBD N&S >= 2, vtx < 60 cm"},
0117       {MBDNS2Vtx150    , "MBD N&S >= 2, vtx < 150 cm"},
0118       {MBDNSHCalSingle , "HCAL Singles + MBD NS >= 1"},
0119       {MBDNSJet1       , "Jet 6 GeV + MBD NS >= 1"},
0120       {MBDNSJet2       , "Jet 8 GeV + MBD NS >= 1"},
0121       {MBDNSJet3       , "Jet 10 GeV + MBD NS >= 1"},
0122       {MBDNSJet4       , "Jet 12 GeV + MBD NS >= 1"},
0123       {Jet1            , "Jet 6 GeV"},
0124       {Jet2            , "Jet 8 GeV"},
0125       {Jet3            , "Jet 10 GeV"},
0126       {Jet4            , "Jet 12 GeV"},
0127       {MBDNSPhoton1    , "Photon 2 GeV+ MBD NS >= 1"},
0128       {MBDNSPhoton2    , "Photon 3 GeV + MBD NS >= 1"},
0129       {MBDNSPhoton3    , "Photon 4 GeV + MBD NS >= 1"},
0130       {MBDNSPhoton4    , "Photon 5 GeV + MBD NS >= 1"},
0131       {MBDNS2Photon6Vtx10   , "Photon 6 GeV + MBD NS >= 2, vtx < 10 cm"},
0132       {MBDNS2Photon8Vtx10   , "Photon 8 GeV + MBD NS >= 2, vtx < 10 cm"},
0133       {MBDNS2Photon10Vtx10  , "Photon 10 GeV + MBD NS >= 2, vtx < 10 cm"},
0134       {MBDNS2Photon12Vtx10  , "Photon 12 GeV + MBD NS >= 2, vtx < 10 cm"},
0135       {MBDNS2Photon6Vtx150   , "Photon 6 GeV + MBD NS >= 2, vtx < 150 cm"},
0136       {MBDNS2Photon8Vtx150   , "Photon 8 GeV + MBD NS >= 2, vtx < 150 cm"},
0137       {MBDNS2Photon10Vtx150  , "Photon 10 GeV + MBD NS >= 2, vtx < 150 cm"},
0138       {MBDNS2Photon12Vtx150  , "Photon 12 GeV + MBD NS >= 2, vtx < 150 cm"},
0139       {Photon1         , "Photon 2 GeV"},
0140       {Photon2         , "Photon 3 GeV"},
0141       {Photon3         , "Photon 4 GeV"},
0142       {Photon4         , "Photon 5 GeV"},
0143       {Inclusive       , "Inclusive"}
0144     };
0145     return mapFlagToName;
0146   }
0147 
0148   // methods ------------------------------------------------------------------
0149 
0150   // --------------------------------------------------------------------------
0151   //! Check if a particular trigger fired
0152   // --------------------------------------------------------------------------
0153   /*! Helper method to check if a particular trigger based on
0154    *  it's flag (see `JetQADefs::MapTriggerFlagToName()`).
0155    *  Returns value of `TriggerAnalyzer::didTriggerFire(
0156    *  std::string)`.
0157    *
0158    *  If unknown trigger flag is provided, method will
0159    *  cause Fun4All to abort.
0160    */ 
0161   inline bool DidTriggerFire(const uint32_t trg, TriggerAnalyzer* analyzer)
0162   {
0163 
0164     if (MapTriggerFlagToName().count(trg) == 0)
0165     {
0166       std::cerr << PHWHERE << ": PANIC: unknown trigger flag (" << trg << ") provided! Aborting" << std::endl;
0167       exit(1);
0168     }
0169     return analyzer->didTriggerFire( MapTriggerFlagToName()[trg] );
0170 
0171   }  // end 'DidTriggerFire(uint32_t, TriggerAnalyzer*)'
0172 
0173   // ==========================================================================
0174   //! Make a single QA-compliant histogram name
0175   // ==========================================================================
0176   /*! This helper method takes in a base name (e.g. some variable you want
0177    *  to histogram like "JetEne") and produces a histogram name compliant
0178    *  w/ the rest of the jet QA.
0179    *
0180    *  The format should always be:
0181    *      h_<module name>_<trigger tag>_<jet tag>_<base name> + <tag>
0182    */
0183   inline std::string MakeQAHistName(
0184     const std::string& base,
0185     const std::string& module,
0186     const std::string& tag = "")
0187   {
0188 
0189     // set name to base
0190     std::string name = base;
0191 
0192     // inject module names, tags, etc.
0193     name.insert(0, "h_" + module + "_");
0194     if (!tag.empty())
0195     {
0196       name.append("_" + tag);
0197     }
0198     std::transform(
0199       name.begin(),
0200       name.end(),
0201       name.begin(),
0202       ::tolower
0203     );
0204     return name;
0205 
0206   }  // end 'MakeQAHistName(std::string& x 3)'
0207 
0208   // ==========================================================================
0209   //! Make multiple QA-compliant histogram names
0210   // ==========================================================================
0211   /*! This helper method takes in a list of base names (e.g.
0212    *  some variable you want to histogram like "JetEne") and
0213    *  produces a list of histogram names compliant w/ the
0214    *  rest of the jet QA.
0215    *
0216    *  The format should always be:
0217    *    h_<module name>_<trigger tag>_<jet tag>_<base name> + <tag>
0218    */
0219   inline std::vector<std::string> MakeQAHistNames(
0220       const std::vector<std::string>& bases,
0221       const std::string& module,
0222       const std::string& tag = "")
0223   {
0224     // copy base names to list of hist names
0225     std::vector<std::string> names = bases;
0226 
0227     // inject module names, tags, etc.
0228     for (auto& name : names)
0229     {
0230       name.insert(0, "h_" + module + "_");
0231       if (!tag.empty())
0232       {
0233         name.append("_" + tag);
0234       }
0235       std::transform(
0236           name.begin(),
0237           name.end(),
0238           name.begin(),
0239           ::tolower);
0240     }
0241     return names;
0242 
0243   }  // end 'MakeQAHistNames(std::vector<std::string>&, std::string& x 2)'
0244 
0245 }  // namespace JetQADefs
0246 
0247 #endif
0248 
0249 // end ------------------------------------------------------------------------