Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:18

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DDEve/HitActors.h>
0016 #include <DD4hep/Objects.h>
0017 #include <DD4hep/DD4hepUnits.h>
0018 
0019 // ROOT include files
0020 #include <TH2.h>
0021 #include <TVector3.h>
0022 #include <TEveBoxSet.h>
0023 #include <TEvePointSet.h>
0024 #include <TEveCompound.h>
0025 
0026 using namespace dd4hep;
0027 
0028 #ifdef DD4HEP_USE_GEANT4_UNITS
0029 #define MM_2_CM        1.0
0030 #define MEV_TO_GEV  1000.0
0031 #else
0032 #define MM_2_CM        0.1
0033 #define MEV_TO_GEV     1.0
0034 #endif
0035 
0036 /// Action callback of this functor: 
0037 void EtaPhiHistogramActor::operator()(const DDEveHit& hit)   {
0038   const Position pos(hit.x/MM_2_CM,hit.y/MM_2_CM,hit.z/MM_2_CM);
0039   histogram->Fill(pos.Eta(),pos.Phi(),hit.deposit);
0040 }
0041 
0042 /// Standard initializing constructor
0043 PointsetCreator::PointsetCreator(const std::string& collection, size_t length) 
0044 {
0045   pointset = new TEvePointSet(collection.c_str(),length);
0046   pointset->SetMarkerSize(0.2);
0047 }
0048 
0049 /// Standard initializing constructor
0050 PointsetCreator::PointsetCreator(const std::string& collection, size_t length, const DisplayConfiguration::Config& cfg) 
0051 {
0052   pointset = new TEvePointSet(collection.c_str(),length);
0053   pointset->SetMarkerSize(cfg.data.hits.size);
0054   pointset->SetMarkerStyle(cfg.data.hits.type);
0055   //pointset->SetMarkerAlpha(cfg.data.hits.alpha);
0056   pointset->SetMainColor(cfg.data.hits.color);
0057   threshold = cfg.data.hits.threshold * MEV_TO_GEV;
0058 }
0059 /// Return eve element
0060 TEveElement* PointsetCreator::element() const   {
0061   return pointset;
0062 }
0063 
0064 /// Standard destructor
0065 PointsetCreator::~PointsetCreator()   {
0066   if ( pointset )  {
0067     pointset->SetTitle(Form("Hit collection:\n"
0068                             "Container%s\n"
0069                             "with %d hits\n"
0070                             "total deposit:%.3f GeV",
0071                             pointset->GetName(), count, deposit));
0072   }
0073 }
0074 
0075 /// Action callback of this functor: 
0076 void PointsetCreator::operator()(const DDEveHit& hit)   {
0077   if ( hit.deposit > threshold )   {
0078     deposit += hit.deposit;
0079     pointset->SetPoint(count++, hit.x*MM_2_CM, hit.y*MM_2_CM, hit.z*MM_2_CM);
0080   }
0081 }
0082 
0083 /// Standard initializing constructor
0084 BoxsetCreator::BoxsetCreator(const std::string& collection, size_t /*length */, const DisplayConfiguration::Config& cfg)
0085 {
0086   emax   = cfg.data.hits.emax;
0087   towerH = cfg.data.hits.towerH;
0088   boxset = new TEveBoxSet(collection.c_str());
0089   boxset->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);
0090   boxset->SetMainTransparency(0);
0091   boxset->SetMainColor(cfg.data.hits.color);
0092   boxset->SetRenderMode(TEveBoxSet::kRM_Fill);
0093   boxset->CSCApplyMainColorToAllChildren();
0094   boxset->CSCApplyMainTransparencyToAllChildren();
0095 }
0096 
0097 /// Standard initializing constructor
0098 BoxsetCreator::BoxsetCreator(const std::string& collection, size_t /*length */)
0099 {
0100   boxset = new TEveBoxSet(collection.c_str());
0101   boxset->SetMainTransparency(0);
0102   boxset->Reset(TEveBoxSet::kBT_FreeBox, kFALSE, 64);
0103   boxset->CSCApplyMainColorToAllChildren();
0104   boxset->CSCApplyMainTransparencyToAllChildren();
0105 }
0106 
0107 /// Standard destructor
0108 BoxsetCreator::~BoxsetCreator()  {
0109   if ( boxset )  {
0110     boxset->SetTitle(Form("Hit collection:\n"
0111                           "Container%s\n"
0112                           "with %d hits\n"
0113                           "total deposit:%.3f GeV",
0114                           boxset->GetName(), count, deposit));
0115   }
0116 }
0117 
0118 /// Return eve element
0119 TEveElement* BoxsetCreator::element() const   {
0120   return boxset;
0121 }
0122 
0123 /// Action callback of this functor: 
0124 void BoxsetCreator::operator()(const DDEveHit& hit)   {
0125   double ene = hit.deposit*MEV_2_GEV <= emax ? hit.deposit*MEV_2_GEV : emax;
0126   TVector3 scale(ene/towerH,ene/towerH,ene/towerH);
0127   std::cout << "Hit:" << ene << " deposit:" << hit.deposit << " "
0128             << " emax:" << emax << " towerH:" << towerH << std::endl;
0129   TVector3 p(hit.x*MM_2_CM, hit.y*MM_2_CM, hit.z*MM_2_CM);
0130   double phi = p.Phi();
0131   float s1X = -0.5*(scale(0)*std::sin(phi)+scale(2)*std::cos(phi));
0132   float s1Y =  0.5*(scale(0)*std::cos(phi)-scale(2)*std::sin(phi));
0133   float s2X = -0.5*(scale(0)*std::sin(phi)-scale(2)*std::cos(phi));
0134   float s2Y =  0.5*(scale(0)*std::cos(phi)+scale(2)*std::sin(phi));
0135   float s1Z =  scale(1)/2.0;
0136   float s2Z = s1Z;
0137   float coords[24]= { float(p.X()+s1X), float(p.Y()+s1Y), float(p.Z()-s1Z),
0138                       float(p.X()+s1X), float(p.Y()+s1Y), float(p.Z()+s1Z),
0139                       float(p.X()-s2X), float(p.Y()-s2Y), float(p.Z()+s2Z),
0140                       float(p.X()-s2X), float(p.Y()-s2Y), float(p.Z()-s2Z),
0141                       float(p.X()+s2X), float(p.Y()+s2Y), float(p.Z()-s2Z),
0142                       float(p.X()+s2X), float(p.Y()+s2Y), float(p.Z()+s2Z),
0143                       float(p.X()-s1X), float(p.Y()-s1Y), float(p.Z()+s1Z),
0144                       float(p.X()-s1X), float(p.Y()-s1Y), float(p.Z()-s1Z) };
0145   ++count;
0146   deposit += hit.deposit*MEV_2_GEV;
0147   boxset->AddBox(coords);
0148   boxset->DigitColor(boxset->GetMainColor());
0149 }
0150 
0151 /// Action callback of this functor: 
0152 void TowersetCreator::operator()(const DDEveHit& hit)   {
0153   double ene = hit.deposit*MEV_2_GEV <= emax ? hit.deposit*MEV_2_GEV : emax;
0154   TVector3 scale(1,1,ene/towerH);
0155   TVector3 p(hit.x*MM_2_CM, hit.y*MM_2_CM, hit.z*MM_2_CM);
0156   double phi = p.Phi();
0157   float s1X = -0.5*(scale(0)*std::sin(phi)+scale(2)*std::cos(phi));
0158   float s1Y =  0.5*(scale(0)*std::cos(phi)-scale(2)*std::sin(phi));
0159   float s2X = -0.5*(scale(0)*std::sin(phi)-scale(2)*std::cos(phi));
0160   float s2Y =  0.5*(scale(0)*std::cos(phi)+scale(2)*std::sin(phi));
0161   float s1Z =  scale(1)/2.0;
0162   float s2Z = s1Z;
0163   p = TVector3(hit.x*MM_2_CM-s1X, hit.y*MM_2_CM-s1Y, hit.z*MM_2_CM-s1Z);
0164   float coords[24]= { float(p.X()+s1X), float(p.Y()+s1Y), float(p.Z()-s1Z),
0165                       float(p.X()+s1X), float(p.Y()+s1Y), float(p.Z()+s1Z),
0166                       float(p.X()-s2X), float(p.Y()-s2Y), float(p.Z()+s2Z),
0167                       float(p.X()-s2X), float(p.Y()-s2Y), float(p.Z()-s2Z),
0168                       float(p.X()+s2X), float(p.Y()+s2Y), float(p.Z()-s2Z),
0169                       float(p.X()+s2X), float(p.Y()+s2Y), float(p.Z()+s2Z),
0170                       float(p.X()-s1X), float(p.Y()-s1Y), float(p.Z()+s1Z),
0171                       float(p.X()-s1X), float(p.Y()-s1Y), float(p.Z()-s1Z) };
0172   ++count;
0173   deposit += hit.deposit*MEV_2_GEV;
0174   boxset->AddBox(coords);
0175   boxset->DigitColor(boxset->GetMainColor());
0176 }