00001 #include <mcRootData/McIntegratingHit.h>
00002 #include <commonRootData/RootDataUtil.h>
00003 #include "TRefArray.h"
00004 #include "Riostream.h"
00005
00006 #include "McObjectManager.h"
00007
00008 ClassImp(McIntegratingHit)
00009
00010
00011 McIntegratingHit::McIntegratingHit() {
00012 Clear();
00013 }
00014
00015 McIntegratingHit::~McIntegratingHit() {
00016
00017 Clear();
00018 }
00019
00020
00021 void McIntegratingHit::initialize(const VolumeIdentifier& id) {
00022 m_volumeId = id;
00023 }
00024
00025
00026 void* McIntegratingHit::operator new(size_t size)
00027 {
00028 McIntegratingHit* temp = McObjectManager::getPointer()->getNewMcIntegratingHit();
00029
00030
00031 temp->m_mcPartArr.Clear();
00032 temp->m_energyPtrArr.clear();
00033
00034 return temp;
00035 }
00036
00037 void* McIntegratingHit::operator new(size_t size, void* vp)
00038 {
00039 return vp;
00040 }
00041
00042 McIntegratingHit& McIntegratingHit::operator =(const McIntegratingHit& rhs)
00043 {
00044 m_totalEnergy = rhs.m_totalEnergy;
00045 m_energyArray[0] = rhs.m_energyArray[0];
00046 m_energyArray[1] = rhs.m_energyArray[1];
00047 m_energyArray[2] = rhs.m_energyArray[2];
00048 m_packedFlags = rhs.m_packedFlags;
00049 m_volumeId = rhs.m_volumeId;
00050 m_moment1Seed = rhs.m_moment1Seed;
00051 m_moment2Seed = rhs.m_moment2Seed;
00052 m_mapPtr = rhs.m_mapPtr;
00053
00054 for(int idx=0; idx < rhs.m_mcPartArr.GetEntries(); idx++)
00055 m_mcPartArr.Add(rhs.m_mcPartArr.At(idx));
00056
00057 return *this;
00058 }
00059
00060 void McIntegratingHit::Clear( Option_t * )
00061 {
00062 m_mcPartArr.Clear();
00063 m_energyPtrArr.clear();
00064 m_packedFlags = 0;
00065 m_totalEnergy = 0.0;
00066 m_moment1Seed = TVector3(0., 0., 0.);
00067 m_moment2Seed = TVector3(0., 0., 0.);
00068 m_volumeId.Clear();
00069 m_mapPtr = 0;
00070 m_energyArray[0] = 0.; m_energyArray[1] = 0.; m_energyArray[2] = 0.;
00071 }
00072
00073
00074 void McIntegratingHit::Fake( Int_t , UInt_t , Float_t ) {
00075
00076 Clear() ;
00077
00078 VolumeIdentifier id ;
00079 id.Clear() ;
00080 id.append(0) ;
00081 initialize(id) ;
00082
00083
00084
00085
00086
00087 double totE = 5.5;
00088 double energyArr[3] = { 2.5, 3.0, 0.0 };
00089 TVector3 moment1(1.0, 2.0, 3.0);
00090 TVector3 moment2(2.0, 4.0, 6.0);
00091 setEnergyItems(totE,energyArr,moment1,moment2) ;
00092
00093 }
00094
00095 #define COMPARE_IN_RANGE(att) rootdatautil::CompareInRange(get ## att,ref.get ## att,#att)
00096
00097 Bool_t McIntegratingHit::CompareInRange( const McIntegratingHit & ref, const std::string & name ) const {
00098
00099 Bool_t result = true ;
00100
00101 result = COMPARE_IN_RANGE(VolumeId()) && result ;
00102
00103 result = COMPARE_IN_RANGE(TotalEnergy()) && result ;
00104 result = COMPARE_IN_RANGE(Moment1()) && result ;
00105 result = COMPARE_IN_RANGE(Moment2()) && result ;
00106
00107 result = COMPARE_IN_RANGE(McParticleEnergy(McIntegratingHit::PRIMARY)) && result ;
00108 result = COMPARE_IN_RANGE(McParticleEnergy(McIntegratingHit::ELECTRON)) && result ;
00109 result = COMPARE_IN_RANGE(McParticleEnergy(McIntegratingHit::POSITRON)) && result ;
00110
00111 itemizedEnergyReset() ;
00112 ref.itemizedEnergyReset() ;
00113 result = rootdatautil::CompareInRange(itemizedEnergySize(),ref.itemizedEnergySize(),"itemizedEnergySize") && result ;
00114 const McParticle * myPart, * refPart ;
00115 double myEnergy, refEnergy ;
00116 int count = 0 ;
00117 while ( (myPart = itemizedEnergyNext(myEnergy)) ) {
00118 ++count ;
00119 refPart = ref.itemizedEnergyNext(refEnergy) ;
00120 result = rootdatautil::CompareInRange(*myPart,*refPart,"itemizedEnergyNext Particle") && result ;
00121 result = rootdatautil::CompareInRange(myEnergy,refEnergy,"itemizedEnergyNext Energy") && result ;
00122 }
00123 if (count==0) {
00124 std::cout
00125 <<"No Error : cannot read map which stores TRefs using "
00126 <<" compiled code and ROOT 3.02.07 "
00127 <<std::endl ;
00128 }
00129
00130 if (!result) {
00131 if ( name == "" ) {
00132 std::cout<<"Comparison ERROR for "<<ClassName()<<std::endl ;
00133 }
00134 else {
00135 std::cout<<"Comparison ERROR for "<<name<<std::endl ;
00136 }
00137 }
00138 return result ;
00139
00140 }
00141
00142 void McIntegratingHit::Print(Option_t *option) const {
00143 using namespace std;
00144 TObject::Print(option);
00145 UInt_t p = 2;
00146 cout.precision(p);
00147 m_volumeId.Print(option);
00148 cout << "Flags: " << m_packedFlags
00149 << " Energy: " << m_totalEnergy << endl;
00150 cout << "Mom1: (" << m_moment1Seed.X() << "," << m_moment1Seed.Y() << ","
00151 << m_moment1Seed.Z() << ") ";
00152 cout << "Mom2: (" << m_moment2Seed.X() << "," << m_moment2Seed.Y() << ","
00153 << m_moment2Seed.Z() << ")" << endl;
00154 if (m_energyPtrArr.size() > 0) {
00155 cout << "Energy Map: Size of energy vector: " << m_energyPtrArr.size();
00156 cout << " Size of McParticle array: " << m_mcPartArr.GetEntries()
00157 << endl;
00158 } else {
00159 cout << "energies stored: " << m_energyArray[0] << " , "
00160 << m_energyArray[1] << " , " << m_energyArray[2] << endl;
00161 }
00162 TRefArrayIter mcPartIter(&m_mcPartArr);
00163 McParticle *mcPart = 0;
00164 UInt_t iEnergy = 0;
00165 cout << "Energy :" << endl;
00166 while( (mcPart = (McParticle*)mcPartIter.Next()) ) {
00167 cout << "( " << mcPart->getParticleId() << ", " << m_energyPtrArr[iEnergy]
00168 << " ) " << endl;
00169 ++iEnergy;
00170 }
00171
00172 }
00173
00174
00175 const McParticle* McIntegratingHit::itemizedEnergyNext(Double_t &energy) const {
00176
00177
00178
00179
00180 if ( m_mapPtr < (UInt_t)m_mcPartArr.GetEntries() ) {
00181 energy = m_energyPtrArr[m_mapPtr];
00182 return (McParticle*) m_mcPartArr.At(m_mapPtr++);
00183 }
00184 energy = 0;
00185 return 0;
00186 }
00187
00188 Double_t McIntegratingHit::getMcParticleEnergy(Particle p) const {
00189 return m_energyArray[p];
00190 }
00191
00192 void McIntegratingHit::addEnergyItem(const Double_t& energy, McParticle* t,
00193 const TVector3& pos)
00194 {
00195
00196
00197
00198 m_mcPartArr.Add(t);
00199 m_energyPtrArr.push_back(energy);
00200 TVector3 pos2 = TVector3(pos.X()*pos.X(), pos.Y()*pos.Y(), pos.Z()*pos.Z());
00201 m_totalEnergy += energy;
00202 m_moment1Seed += energy * pos;
00203 m_moment2Seed += energy * pos2;
00204 }
00205
00206
00207 void McIntegratingHit::setEnergyItems(const Double_t& totE, const Double_t *energyArr,
00208 const TVector3& moment1, const TVector3& moment2) {
00209
00210
00211
00212 m_totalEnergy = totE;
00213 m_energyArray[McIntegratingHit::PRIMARY] = energyArr[McIntegratingHit::PRIMARY];
00214 m_energyArray[McIntegratingHit::ELECTRON] = energyArr[McIntegratingHit::ELECTRON];
00215 m_energyArray[McIntegratingHit::POSITRON] = energyArr[McIntegratingHit::POSITRON];
00216 m_moment1Seed = moment1 * totE;
00217 m_moment2Seed = moment2 * totE;
00218 }
00219
00220 const TVector3 McIntegratingHit::getMoment1 () const
00221 {
00222
00223
00224 return m_moment1Seed * (1./m_totalEnergy);
00225 }
00226
00227
00228 const TVector3 McIntegratingHit::getMoment2 () const
00229 {
00230
00231
00232 return m_moment2Seed * (1./m_totalEnergy);
00233 }
00234