Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

HitProfile.cxx

Go to the documentation of this file.
00001 #include "Simulation/HitProfile.h"
00002 
00003 using namespace sim;
00004 ClassImp(HitProfile);
00005 
00006 HitProfile::HitProfile() :
00007   fTrackId(0), fFraction(0), kNoiseId(65535)
00008 {
00009 }
00010 
00011 //__________________________________________________________
00012 
00013 HitProfile::~HitProfile() {
00014 }
00015 
00016 //__________________________________________________________
00017 
00018 unsigned int HitProfile::NComponents() const {
00019 
00020   char msg[256];
00021   sprintf(msg,"HitProfile::NComponents() inconsistent size!");
00022   assert_jobc(fTrackId.size()==fFraction.size(),msg);
00023   
00024   return fTrackId.size();
00025 }
00026 
00027 //__________________________________________________________
00028 
00029 std::pair<unsigned short, float> HitProfile::Component(unsigned int i) const
00030 {
00031   char msg[256];
00032   sprintf(msg,"HitProfile::Component(%d) out of range!",i);
00033   assert_jobc(i<fTrackId.size(),msg);
00034 
00035   std::pair<unsigned short, float> component;
00036   component.first  = fTrackId[i];
00037   component.second = fFraction[i];
00038 
00039   return component;
00040 }
00041 
00042 //__________________________________________________________
00043 
00044 std::pair<unsigned short, float> HitProfile::Component(unsigned int i, float fact) const
00045 {
00046   char msg[256];
00047   sprintf(msg,"HitProfile::Component(%d) out of range!",i);
00048   assert_jobc(i<fTrackId.size(),msg);
00049 
00050   std::pair<unsigned short, float> component;
00051   component.first  = fTrackId[i];
00052   component.second = fFraction[i] * fact;
00053 
00054   return component;
00055 }
00056 
00057 //__________________________________________________________
00058 
00059 unsigned short HitProfile::NoiseId()   const
00060 {
00061   return kNoiseId;
00062 
00063 }
00064 
00065 //__________________________________________________________
00066 
00067 unsigned short HitProfile::TrackId(unsigned int i)   const
00068 {
00069   char msg[256];
00070   sprintf(msg,"HitProfile::TrackId(%d) out of range!",i);
00071   assert_jobc(i<fTrackId.size(),msg);
00072 
00073   return fTrackId[i];
00074 
00075 }
00076 
00077 //__________________________________________________________
00078 
00079 float HitProfile::Fraction(unsigned int i)  const
00080 {
00081   char msg[256];
00082   sprintf(msg,"HitProfile::Fraction(%d) out of range!",i);
00083   assert_jobc(i<fFraction.size(),msg);
00084 
00085   return fFraction[i];
00086 }
00087 
00088 //__________________________________________________________
00089 
00090 void HitProfile::Push(std::pair<unsigned short, float> component)
00091 {
00092   fTrackId.push_back(component.first);
00093   fFraction.push_back(component.second);
00094   return;
00095 }
00096 
00097 //__________________________________________________________
00098 
00099 void HitProfile::Push(unsigned short trackid, float fraction)
00100 {
00101   fTrackId.push_back(trackid);
00102   fFraction.push_back(fraction);
00103   return;
00104 }
00105 
00106 //__________________________________________________________
00107 
00108 void HitProfile::SetFraction(unsigned int i, float fraction)
00109 {
00110   char msg[256];
00111   sprintf(msg,"HitProfile::SetFraction(%d) out of range!",i);
00112   assert_jobc(i<fFraction.size(),msg);
00113 
00114   fFraction[i] = fraction;
00115 
00116   return;
00117 
00118 }
00119 
00120 //__________________________________________________________
00121 
00122 void HitProfile::NormalizeFraction()
00123 {
00124   if(this->NComponents()==0) return;
00125 
00126   float total = 0.;
00127   for(unsigned int j=0; j<this->NComponents(); j++) 
00128     total += fFraction[j];
00129 
00130   if(total==0) return;
00131 
00132   for(unsigned int j=0; j<this->NComponents(); j++) 
00133     fFraction[j] /= total;
00134 
00135   return;
00136 }
00137     
00138 //__________________________________________________________
00139 
00140 void HitProfile::Combine()
00141 {
00142   std::vector<unsigned short> copyTrackId = fTrackId;
00143   std::vector<float>          copyFraction = fFraction;
00144   
00145   fTrackId.clear();
00146   fFraction.clear();
00147 
00148   for(unsigned int i=0; i<copyTrackId.size(); i++) {
00149 
00150     bool duplicated = false;
00151 
00152     for(unsigned int j=0; j<fTrackId.size(); j++) {
00153 
00154       if(copyTrackId[i]==fTrackId[j]) {
00155         fFraction[j] += copyFraction[i];
00156         duplicated = true;
00157         continue;
00158       }
00159     }
00160 
00161     if(!duplicated) {
00162       fTrackId.push_back(copyTrackId[i]);
00163       fFraction.push_back(copyFraction[i]);
00164     }
00165 
00166   }
00167 
00168   return;
00169 }
00170 
00171 //__________________________________________________________
00172 
00173 void HitProfile::Clear()
00174 {
00175   fTrackId.clear();
00176   fFraction.clear();
00177   return;
00178 }
00179 
00181 

Generated on Mon Dec 1 02:35:18 2008 for NOvA Offline by  doxygen 1.3.9.1