/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Simulation/BOOST/MucSim/MucSim-00-01-03/src/BesMucDigit.cc

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------//
00002 //      BOOST --- BESIII Object_Oriented Simulation Tool                     //
00003 //---------------------------------------------------------------------------//
00004 //Description:
00005 //Author:  Youzy      Peking University      mail: youzy@hep.pku.cn
00006 //Created:  Dec, 2003
00007 //Modified:
00008 //Comment:
00009 //---------------------------------------------------------------------------//
00010 
00011 //
00012 // $Id: BesMucDigit
00013 
00014 #include "BesMucDigit.hh"
00015 #include "G4ios.hh"
00016 #include "G4Box.hh"
00017 #include "G4VSolid.hh"
00018 #include "strstream"
00019 class G4VSolid;
00020 
00021 BesMucDigit::BesMucDigit() 
00022 {
00023 }
00024 
00025 BesMucDigit::~BesMucDigit() 
00026 {
00027 }
00028 
00029 void BesMucDigit::SetHit(BesMucHit* hit)
00030 {
00031   m_pHit = hit;
00032   
00033   G4int part = m_pHit->GetPart();
00034   G4int seg  = m_pHit->GetSeg();
00035   G4int gap  = m_pHit->GetGap();
00036   m_Pos = m_pHit->GetPosLocal().x();
00037   if ( (part == 1 && gap%2 != 0) || (part != 1 && gap%2 == 0) ) {
00038     m_Pos = m_pHit->GetPosLocal().y();
00039   }
00040 
00041   if(part == 1 && seg == 2 &&gap%2 != 0) m_Pos2 = m_pHit->GetPosLocal().x();
00042 
00043   G4VPhysicalVolume* pvGasChamber = m_pHit->GetVolume();
00044   if(m_pHit->GetTrackID()!=-1){
00045     m_lvGap     = pvGasChamber->GetMotherLogical();  //after update gdml, mother of gaschamber change to be aluminumbox, but i still use the name m_lvGap
00046   m_lvGapName = m_lvGap->GetName();
00047 
00048   //G4cout<<"in digit----"<<m_lvGapName<<"  "<<m_lvGap->GetDaughter(1)->GetLogicalVolume()->GetName()<<G4endl;
00049   }
00050 }
00051 
00052 G4VPhysicalVolume* 
00053 BesMucDigit::GetNearestStrip() 
00054 {
00055   m_pvStripDigit = GetStrip( GetNearestStripNo() );
00056   if(!m_pvStripDigit) {
00057     G4cerr << "Nearest Strip is not found." << G4endl;
00058   }
00059 
00060   return m_pvStripDigit;
00061 }
00062 
00063 G4int BesMucDigit::GetNearestStripNo() 
00064 {
00065  if(m_pHit->GetTrackID()!=-1){
00066   G4float posStrip0 = GetStripPos( GetStrip(0) );
00067   G4float posStrip1 = GetStripPos( GetStrip(1) );
00068   G4float width = posStrip1 - posStrip0;
00069   //G4cout << "posStrip0 " << posStrip0 << " posStrip1 " << posStrip1 << G4endl;
00070 
00071   G4int iGuessStrip = G4int( (m_Pos - posStrip0)/width + 0.5 );
00072   // confine iGuessStrip to an extend before check IsNearest.
00073   if(iGuessStrip < 0) {
00074     iGuessStrip = 0;
00075   } 
00076   else if(iGuessStrip >= 112) {
00077     iGuessStrip = 112;
00078   }
00079   //G4cout << "m_pos=" << m_Pos << "firstly, I guess: " << iGuessStrip << G4endl;
00080   
00081   G4int step = IsNearest(iGuessStrip);
00082   while(step != 0) {
00083     //G4cout << "guess " << iGuessStrip << " wrong , iGuess " << step << G4endl;
00084     iGuessStrip += step;
00085     step = IsNearest(iGuessStrip);
00086   }
00087   //G4cout << " guess " << iGuessStrip << " right " << G4endl;
00088 
00089   //deal with barrel segment 2 gap%2!=0
00090   G4int part = m_pHit->GetPart();
00091   G4int seg  = m_pHit->GetSeg();
00092   G4int gap  = m_pHit->GetGap();
00093   //G4cout<<" in Digit   iGuessStrip = "<< iGuessStrip <<G4endl;
00094   if(part == 1 && seg == 2 &&gap%2 != 0 && iGuessStrip > 79 ){
00095     if(iGuessStrip > 79 && iGuessStrip <= 95 && m_Pos2 < 0) iGuessStrip += 16 ;
00096     if(iGuessStrip > 95 && iGuessStrip <= 111 && m_Pos2 > 0) iGuessStrip -= 16 ;
00097     //G4cout<<" in barrel segment 2 and gap%2!=0, and strip > 79  strip="<< iGuessStrip<<" posx="<<m_Pos2<<" "<<" posy="<<m_Pos<<G4endl;
00098   }
00099 
00100   return iGuessStrip;
00101  }
00102  else return m_pHit->GetStrip();
00103 }
00104 
00105 G4VPhysicalVolume* 
00106 BesMucDigit::GetStrip(G4int i)
00107 {
00108   // If no strip get, return 0.
00109   // If i > daughtersNo, there will be run error.
00110   G4LogicalVolume *lvStripPlane = m_lvGap->GetDaughter(0)->GetLogicalVolume();
00111   G4int daughtersNo = lvStripPlane->GetNoDaughters();
00112   
00113   if(i >= 0 && i < daughtersNo) {
00114     G4VPhysicalVolume*  pvStrip = lvStripPlane->GetDaughter(i);
00115     G4String strStrip = pvStrip->GetLogicalVolume()->GetName();
00116     //G4cout << "length " << strStrip.length() << G4endl;
00117     //if(strStrip.length() == 30) { //use name length to determine whether it is a strip
00118 
00119     if (strStrip.find("s") == 10) { //"Strip" at 23 of "logicalMucPart1Seg0Gap0Strip111" 
00120       //"s" at 10 of lMucP0S0G0s001
00121       return pvStrip;
00122     }
00123     //return pvStrip;
00124   }
00125   
00126   return 0;
00127 }
00128 
00129 G4float BesMucDigit::GetStripPos(G4VPhysicalVolume* pvStrip)
00130 {
00131   G4float pos = 1.0e38;
00132   if (!pvStrip) return pos;
00133   
00134   G4int part = m_pHit->GetPart();
00135   G4int gap  = m_pHit->GetGap();
00136 
00137   pos = pvStrip->GetObjectTranslation().x();
00138   if ( (part == 1 && gap%2 != 0) || (part != 1 && gap%2 == 0) ) {
00139     pos = pvStrip->GetObjectTranslation().y();
00140   }
00141 
00142   G4String striptype= pvStrip->GetLogicalVolume()->GetSolid()->GetEntityType();
00143 //  G4String striplenght= pvStrip->GetLogicalVolume()->GetName();
00144   G4Box *temp;
00145   temp=(G4Box *)pvStrip->GetLogicalVolume()->GetSolid();
00146   G4double length=temp->GetXHalfLength();
00147 //  std::ostream length;
00148 //  pvStrip->GetLogicalVolume()->GetSolid()->StreamInfo( length);
00149 
00150   G4float  box1,box2,box3;
00151 //  length>>box1>>box2>>box3;
00152   //G4cout<<length<<" "<<striptype<<"         in GetStripPos   "<<pvStrip->GetObjectTranslation().x()<<" "<<pvStrip->GetObjectTranslation().y()<<" "<<pvStrip->GetObjectTranslation().z()<<G4endl;
00153   return pos; 
00154 } 
00155 
00156 
00157 
00158 G4int BesMucDigit::IsNearest(G4int i)
00159 {
00160   G4float posMax = 1.0e38;
00161   G4float posLeftStrip;
00162   G4float posRightStrip;
00163   G4float posCurrentStrip;
00164 
00165   G4VPhysicalVolume* pvLeftStrip    = GetStrip(i-1);
00166   G4VPhysicalVolume* pvRightStrip   = GetStrip(i+1);
00167   G4VPhysicalVolume* pvCurrentStrip = GetStrip(i);
00168 
00169   if(i < 0) {
00170     return i;
00171   }
00172   else if(i == 0) {
00173     posLeftStrip    = -1.0*posMax;
00174     posRightStrip   = GetStripPos( pvRightStrip );
00175   }
00176   else if(!pvCurrentStrip) {
00177     // i > Max.
00178     return -1;
00179   }
00180   else if(!pvRightStrip) {
00181     // i = Max.
00182     posLeftStrip  = GetStripPos( pvLeftStrip );
00183     posRightStrip = posMax;
00184   }
00185   else {
00186     // 0 < i < Max.
00187     posLeftStrip  = GetStripPos( pvLeftStrip );
00188     posRightStrip = GetStripPos( pvRightStrip );
00189   }
00190   posCurrentStrip = GetStripPos( pvCurrentStrip );
00191 
00192    G4float distCurrent = std::abs(m_Pos - posCurrentStrip);
00193    G4float distLeft    = std::abs(m_Pos - posLeftStrip);
00194    G4float distRight   = std::abs(m_Pos - posRightStrip);
00195 
00196   //G4cout << "left " << distLeft << " current " << distCurrent << " right " << distRight << G4endl;
00197 
00198   if( (distCurrent <= distLeft) && (distCurrent <= distRight) ) {
00199     return 0;
00200   }
00201   else if(distCurrent > distLeft) {
00202     return -1;
00203   }
00204   else {
00205     return 1;
00206   }
00207 
00208 }

Generated on Tue Nov 29 23:14:28 2016 for BOSS_7.0.2 by  doxygen 1.4.7