File indexing completed on 2025-12-15 10:30:42
0001 #ifndef ATOOLS_Phys_Blob_H
0002 #define ATOOLS_Phys_Blob_H
0003
0004 #include <string>
0005 #include <vector>
0006 #include <map>
0007
0008 #include "ATOOLS/Math/Poincare.H"
0009 #include "ATOOLS/Phys/Particle.H"
0010 #include "ATOOLS/Org/STL_Tools.H"
0011
0012 namespace ATOOLS {
0013
0014 class Blob_Data_Base {
0015 private:
0016 static long int s_number;
0017 public:
0018 template <class Type> Type &Get();
0019 template <class Type> void Set(const Type &data);
0020 Blob_Data_Base();
0021 Blob_Data_Base(const Blob_Data_Base &base);
0022 virtual ~Blob_Data_Base();
0023 virtual std::ostream & operator>>(std::ostream &) const =0;
0024 virtual Blob_Data_Base* ClonePtr() { return NULL; }
0025 };
0026
0027 template <class Type> class Blob_Data : public Blob_Data_Base {
0028 Type m_data;
0029 public:
0030 Blob_Data(const Type & d);
0031 Type &Get() { return m_data; }
0032 void Set(const Type & d) { m_data=d; }
0033 std::ostream & operator>>(std::ostream &) const;
0034 virtual Blob_Data_Base* ClonePtr() { return new Blob_Data(m_data); }
0035 ~Blob_Data();
0036 };
0037
0038 std::ostream& operator<<(std::ostream&,const Blob_Data_Base &);
0039
0040 typedef std::map<std::string,Blob_Data_Base *> String_BlobDataBase_Map;
0041
0042 struct blob_status {
0043 enum code {
0044 inactive = 0,
0045 needs_signal = 1,
0046 needs_showers = 2,
0047 needs_harddecays = 4,
0048 needs_beams = 8,
0049 needs_softUE = 16,
0050 needs_reconnections = 32,
0051 needs_hadronization = 64,
0052 needs_hadrondecays = 128,
0053 needs_extraQED = 256,
0054 needs_minBias = 512,
0055 needs_beamRescatter = 1024,
0056 needs_smearing = 16384,
0057 internal_flag = 32768,
0058 needs_yfs = 65536,
0059 fully_active = 131072
0060 };
0061 };
0062
0063 inline blob_status::code operator|(const blob_status::code& c1,const blob_status::code& c2)
0064 { return (blob_status::code)((int)c1|(int)c2); }
0065 inline blob_status::code operator&(const blob_status::code& c1,const blob_status::code& c2)
0066 { return (blob_status::code)((int)c1&(int)c2); }
0067
0068 struct btp {
0069 enum code {
0070 Signal_Process = 1,
0071 Hard_Decay = 2,
0072 Hard_Collision = 4,
0073 Soft_Collision = 8,
0074 Shower = 16,
0075 QED_Radiation = 32,
0076 Beam = 256,
0077 Bunch = 512,
0078 Fragmentation = 1024,
0079 Cluster_Formation = 2048,
0080 Cluster_Decay = 4096,
0081 Hadron_Decay = 8192,
0082 Hadron_Mixing = 16384,
0083 Hadron_To_Parton = 32768,
0084 Elastic_Collision = 65536,
0085 Soft_Diffractive_Collision = 131072,
0086 Quasi_Elastic_Collision = 262144,
0087 YFS_Initial = 524288,
0088 Unspecified = 1048576
0089 };
0090 };
0091
0092 inline btp::code operator|(const btp::code& c1,const btp::code& c2)
0093 { return (btp::code)((int)c1|(int)c2); }
0094 inline btp::code operator&(const btp::code& c1,const btp::code& c2)
0095 { return (btp::code)((int)c1&(int)c2); }
0096
0097 std::ostream& operator<<(std::ostream&,const btp::code);
0098
0099 class Blob {
0100 friend std::ostream& operator<<( std::ostream&, const Blob &);
0101 private:
0102 static long unsigned int s_currentnumber;
0103 Vec4D m_position;
0104 int m_id;
0105 blob_status::code m_status;
0106 int m_beam;
0107 bool m_hasboost;
0108 btp::code m_type;
0109 std::string m_typespec;
0110 String_BlobDataBase_Map m_datacontainer;
0111 Particle_Vector m_inparticles, m_outparticles;
0112 Vec4D m_cms_vec;
0113 Poincare m_cms_boost;
0114 static int s_totalnumber;
0115 bool IsConnectedTo(const btp::code &type,
0116 std::set<const Blob*> &checked) const;
0117 public:
0118 Blob(const Vec4D _pos = Vec4D(0.,0.,0.,0.), const int _id=-1);
0119 Blob(const Blob *,const bool);
0120 ~Blob();
0121 void AddToInParticles(Particle *);
0122 void AddToOutParticles(Particle *);
0123 Particle_Vector GetOutParticles() { return m_outparticles; }
0124 Particle_Vector GetInParticles() { return m_inparticles; }
0125 Particle_Vector * OutParticles() { return &m_outparticles; }
0126 Particle_Vector * InParticles() { return &m_inparticles; }
0127 Particle * OutParticle(int);
0128 Particle * InParticle(int);
0129 Particle * GetParticle(int);
0130 const Particle *ConstOutParticle(const size_t i) const;
0131 const Particle *ConstInParticle(const size_t i) const;
0132 Particle * RemoveInParticle(int,bool = true);
0133 Particle * RemoveInParticle(Particle *,bool = true);
0134 Particle * RemoveOutParticle(int,bool = true);
0135 Particle * RemoveOutParticle(Particle *,bool = true);
0136 void RemoveInParticles(const int = 1);
0137 void RemoveOutParticles(const int = 1);
0138 void DeleteInParticles(const int = -1);
0139 void DeleteOutParticles(const int = -1);
0140 void DeleteInParticle(Particle *);
0141 void DeleteOutParticle(Particle *);
0142 void RemoveOwnedParticles(const bool = true);
0143 void DeleteOwnedParticles();
0144
0145 void Boost(const Poincare& boost);
0146 void BoostInCMS();
0147 void BoostInLab();
0148
0149 void SetVecs();
0150 void SetPosition(Vec4D pos) { m_position = pos; }
0151 void SetCMS(Vec4D _cms) { m_cms_vec = _cms; }
0152 void SetCMS();
0153 void SetId(const int _id=0);
0154 static void ResetCounter() { s_totalnumber = 0; }
0155 static int Counter() { return s_totalnumber; }
0156 inline static void Reset(const int number=0) { s_currentnumber = number; }
0157 inline bool Has(blob_status::code status) { return (int(status&m_status)>0); }
0158 bool IsConnectedTo(const btp::code &type) const;
0159 Blob * UpstreamBlob() const;
0160 Blob * DownstreamBlob() const;
0161 void SetStatus(blob_status::code status=blob_status::inactive) {
0162 m_status = status;
0163 }
0164 void UnsetStatus(blob_status::code status=blob_status::inactive) {
0165 m_status = blob_status::code(int(m_status) & int(~status));
0166 }
0167 void AddStatus(blob_status::code status=blob_status::inactive) {
0168 m_status = m_status | status;
0169 }
0170 void SetType(btp::code _type) { m_type = _type; }
0171 void SetTypeSpec(std::string _type) { m_typespec = _type; }
0172 void SetBeam(int _beam) { m_beam = _beam; }
0173 Blob_Data_Base * operator[](const std::string name)
0174 {
0175 String_BlobDataBase_Map::const_iterator cit=m_datacontainer.find(name);
0176 if (cit==m_datacontainer.end()) return 0;
0177 return cit->second;
0178 }
0179 const String_BlobDataBase_Map & GetData() const {return m_datacontainer;}
0180
0181 void AddData(const std::string name, Blob_Data_Base * data);
0182 void ClearAllData();
0183
0184 int Id() const { return m_id; }
0185 int Status() const { return m_status; }
0186 int Beam() const { return m_beam; }
0187 int NInP() const { return m_inparticles.size(); }
0188 int NOutP() const { return m_outparticles.size(); }
0189
0190 Vec4D CheckMomentumConservation() const;
0191 double CheckChargeConservation() const;
0192 std::string ShortProcessName();
0193 bool MomentumConserved();
0194 bool CheckColour(const bool & transient=false);
0195 const Vec4D& Position() const { return m_position; }
0196 const Vec4D& CMS() const { return m_cms_vec; }
0197 const btp::code& Type() const { return m_type; }
0198 std::string const TypeSpec() const { return m_typespec; }
0199 void SwapInParticles(const size_t i,const size_t j);
0200 void SwapOutParticles(const size_t i,const size_t j);
0201 };
0202
0203
0204 typedef std::vector<ATOOLS::Blob *> Blob_Vector;
0205 typedef std::map<int,ATOOLS::Blob *> Int_Blob_Map;
0206 typedef std::map<ATOOLS::Particle *,ATOOLS::Blob *> Particle_Blob_Map;
0207
0208
0209
0210 template <class Type>
0211 Blob_Data<Type>::Blob_Data(const Type & d) : m_data(d) {}
0212
0213
0214 template <class Type>
0215 std::ostream & Blob_Data<Type>::operator>>(std::ostream & s) const
0216 {
0217 s<<m_data;
0218 return s;
0219 }
0220
0221 template <class Type>
0222 Type &Blob_Data_Base::Get()
0223 {
0224 return ((Blob_Data<Type>*)this)->Get();
0225 }
0226
0227 template <class Type>
0228 void Blob_Data_Base::Set(const Type &data)
0229 {
0230 return ((Blob_Data<Type>*)this)->Set(data);
0231 }
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288 }
0289
0290 #endif
0291
0292
0293
0294