// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // #include "IElementField.hxx" #include "IFieldManager.hxx" COMET::IElementField::IElementField(const TVector3* translation, const TRotation* rotation): fTranslation(NULL), fNeedTrans(false), fGlobalToLocalRotation(NULL), fLocalToGlobalRotation(NULL){ if (translation) SetTranslation(*translation); if (rotation) SetRotation(*rotation); addElementField(); } void COMET::IElementField::GlobalToLocal(const Double_t GlobalPoint[4], Double_t LocalPoint[4]) const{ //Apply translation and rotation of the element to go from global coord //to local coord if (fNeedTrans){ TVector3 local(GlobalPoint[0],GlobalPoint[1],GlobalPoint[2]); GlobalToLocal(local); LocalPoint[0]=local[0]; LocalPoint[1]=local[1]; LocalPoint[2]=local[2]; LocalPoint[3]=GlobalPoint[3]; } else{ LocalPoint[0]=GlobalPoint[0]; LocalPoint[1]=GlobalPoint[1]; LocalPoint[2]=GlobalPoint[2]; LocalPoint[3]=GlobalPoint[3]; } } void COMET::IElementField::addFieldValue(const Double_t GlobalPoint[4], Double_t field[6]) const{ if (!fNeedTrans){ if(GlobalPoint[2] < fBoundingBox.MinZ || GlobalPoint[2] > fBoundingBox.MaxZ) return; if(GlobalPoint[0] < fBoundingBox.MinX || GlobalPoint[0] > fBoundingBox.MaxX) return; if(GlobalPoint[1] < fBoundingBox.MinY || GlobalPoint[1] > fBoundingBox.MaxY) return; } Double_t LocalPoint[4]; GlobalToLocal(GlobalPoint,LocalPoint); if (fNeedTrans){ if(LocalPoint[2] < fBoundingBox.MinZ || LocalPoint[2] > fBoundingBox.MaxZ) return; if(LocalPoint[0] < fBoundingBox.MinX || LocalPoint[0] > fBoundingBox.MaxX) return; if(LocalPoint[1] < fBoundingBox.MinY || LocalPoint[1] > fBoundingBox.MaxY) return; } Double_t f[6]; f[0] = f[1] = f[2] = f[3] = f[4] = f[5] = 0.0; // get the field f in local coords getFieldValue(LocalPoint,f); //Rotate the fields and add to field[] if(fLocalToGlobalRotation){ // Initialize rotatedField vector to handle rotation // Only use one vector to cut down on initialization time TVector3 rotatedField; rotatedField.SetXYZ(f[0], f[1], f[2]); rotatedField = (*fLocalToGlobalRotation) * rotatedField; // Return this to actual field result field[0] += rotatedField[0]; field[1] += rotatedField[1]; field[2] += rotatedField[2]; // Do the same for the E field rotatedField.SetXYZ(f[3], f[4], f[5]); rotatedField = (*fLocalToGlobalRotation) * rotatedField; field[3] += rotatedField[0]; field[4] += rotatedField[1]; field[5] += rotatedField[2]; } else for (int i = 0; i < 6; i++) field[i] += f[i]; } void COMET::IElementField::addElementField() { if (IFieldManager::GetObject()->fFields) IFieldManager::GetObject()->fFields->push_back(this); }