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

BeamMonSpill.cxx

Go to the documentation of this file.
00001 #include "BeamMonSpill.h"
00002 
00003 #include <cmath>
00004 
00005 #include <DatabaseInterface/DbiResultSet.h>
00006 #include <DatabaseInterface/DbiOutRowStream.h>
00007 
00008 #include <Validity/VldRange.h>
00009 
00010 #include <MessageService/MsgService.h>
00011 CVSID("$Id: BeamMonSpill.cxx,v 1.17 2007/05/07 19:06:16 mdier Exp $");
00012 
00013 BeamMonSpill::BeamMonSpill()
00014     : fDaeTime(VldTimeStamp(2038,1,1,0,0,0)) // end of time
00015     , fVmeTime(VldTimeStamp(2038,1,1,0,0,0)) // end of time
00016     , fTor101(0.0), fTr101d(0.0), fTortgt(0.0), fTrtgtd(0.0)
00017     , fHornCur(0.0)
00018     , fTargProfX(0.0), fTargProfY(0.0)
00019     , fProfWidX(0.0), fProfWidY(0.0)
00020     , fHadInt(0.0), fMuInt1(0.0), fMuInt2(0.0), fMuInt3(0.0)
00021 {
00022     fStatus.integer = 0;
00023     for (int ind=0; ind<6; ++ind) 
00024         fTargBpmX[ind] = fTargBpmY[ind] = fBpmInt[ind] = 0.0;
00025 }
00026 
00027 BeamMonSpill::~BeamMonSpill()
00028 {
00029 }
00030 
00031 DbiTableRow* BeamMonSpill::CreateTableRow() const
00032 {
00033     return new BeamMonSpill;
00034 }
00035 
00036 void BeamMonSpill::Fill(DbiResultSet& rs, const DbiValidityRec* /*vrec*/)
00037 {
00038     int ns=0;
00039 
00040     rs >> fDaeTime;
00041     rs >> ns;
00042     fDaeTime.Add(VldTimeStamp(0,ns));
00043 
00044     rs >> fVmeTime;
00045     rs >> ns;
00046     fVmeTime.Add(VldTimeStamp(0,ns));
00047 
00048     rs >> fTor101 >> fTr101d >> fTortgt >> fTrtgtd;
00049     rs >> fHornCur;
00050 
00051     for (int ind=0; ind<6; ++ind) 
00052         rs >> fTargBpmX[ind] >> fTargBpmY[ind] >> fBpmInt[ind];
00053 
00054     rs >> fTargProfX >> fTargProfY >> fProfWidX >> fProfWidY;
00055     rs >> fHadInt >> fMuInt1 >> fMuInt2 >> fMuInt3;    
00056     rs >> fStatus.integer;
00057 }
00058 
00059 void BeamMonSpill::Store(DbiOutRowStream& ors, const DbiValidityRec* /*vrec*/) const
00060 {
00061     ors << fDaeTime << fDaeTime.GetNanoSec()
00062         << fVmeTime << fVmeTime.GetNanoSec();
00063     ors << fTor101 << fTr101d << fTortgt << fTrtgtd;
00064     ors << fHornCur;
00065     for (int ind=0; ind<6; ++ind) 
00066         ors << fTargBpmX[ind] << fTargBpmY[ind] << fBpmInt[ind];
00067     ors << fTargProfX << fTargProfY << fProfWidX << fProfWidY;
00068     ors << fHadInt << fMuInt1 << fMuInt2 << fMuInt3;    
00069     ors << fStatus.integer;
00070 }
00071 
00072 double BeamMonSpill::BpmAtTarget(double &xmean, double &ymean, double &xrms, double &yrms) const
00073 {
00074     xmean=ymean=xrms=yrms=0.0;
00075 
00076     double Itot = 0, ix=0,iy=0,ix2=0,iy2=0;
00077     for (int ind=0; ind<6; ++ind) {
00078         if (fBpmInt[ind] == 0.0) continue;
00079         
00080         double X = fTargBpmX[ind];
00081         double Y = fTargBpmY[ind];
00082         double I = fBpmInt[ind];
00083         I = I > 0 ? I : 0;
00084         Itot += I;
00085 
00086         ix += I*X;
00087         iy += I*Y;
00088 
00089         ix2 += I*X*X;
00090         iy2 += I*Y*Y;
00091     }
00092 
00093     if (Itot <= 0.0) return 0.0;
00094 
00095     xmean = ix/Itot;
00096     double xtmp = ix2/Itot-xmean*xmean;
00097     if (xtmp > 0.0) xrms = sqrt(xtmp);
00098 
00099     ymean = iy/Itot;
00100     double ytmp = iy2/Itot-ymean*ymean;
00101     if (ytmp > 0.0) yrms = sqrt(ytmp);
00102 
00103     return Itot;
00104 }
00105 
00106 
00107 BeamType::BeamType_t BeamMonSpill::BeamType() const
00108 {
00109     BeamType::BeamType_t btype = BeamType::kUnknown;
00110     //
00111     Int_t db_btyp = this->GetStatusBits().beam_type;    
00112 
00113     // Overwrite the beamtype that is in the database for spills
00114     // after May 2006
00115     // Change triggered by problems observed for Summer 2006 spills
00116     // Some spills during pME & pHE running had a beamtype in the
00117     // database of 1, which means le running. And a large fraction of
00118     // spills in September had a beamtype of 4, i.e. pME.
00119     // The most likely casue for this is that the timing used to
00120     // determine the target position when filling the database was screwed up. 
00121 
00122     double spilltime = this->SpillTime().GetSec();
00123     if (spilltime > 1149202720 && spilltime <= 1150047812) db_btyp=4;  // pME
00124     else if (spilltime > 1150047812 && spilltime <= 1155664632 ) db_btyp=5;  // pHE
00125     else if (spilltime > 1155664632 ) db_btyp=1;  // LE
00126 
00127     
00128     if (db_btyp==1){
00129         if (this->SpillTime().GetSec() <= 1112010000){ // early real LE data
00130             if (fHornCur < -190)                     // nominal at -200kA
00131                 btype = BeamType::kL000z200i;        // 
00132         }
00133         else {                                       // later on LE-10 data
00134             if (fHornCur < -190)                     //  -200 kA
00135                 btype = BeamType::kL010z200i;
00136             else if (fHornCur < -175){               //  -185kA 
00137                 btype = BeamType::kL010z185i;        //  nominal
00138             }
00139             else if (fHornCur < -160)
00140                 btype = BeamType::kL010z170i;
00141             else if (fHornCur > -5)
00142                 btype = BeamType::kL010z000i;
00143         }        
00144     }
00145     else if (db_btyp==2 || db_btyp==4){                 // (p)ME
00146         if (this->SpillTime().GetSec() > 1149202720 &&
00147             this->SpillTime().GetSec() <= 1150047812){  // pME-150
00148             if (fHornCur < -190)                        // 
00149                 btype = BeamType::kL150z200i;           //  -200 kA
00150         }
00151         else {
00152             if (fHornCur < -190)                        // pME-100 
00153                 btype = BeamType::kL100z200i;           //  -200 kA
00154         }
00155     }
00156     else if (db_btyp==3 || db_btyp==5){             // (p)HE
00157         if (fHornCur < -190)                        // pHE-250 
00158             btype = BeamType::kL250z200i;           //  -200 kA
00159     }
00160 
00161     return btype;
00162 }
00163 
00164 VldTimeStamp BeamMonSpill::SpillTime() const
00165 {
00166   //    if (fStatus.bits.time_source) return fDaeTime;
00167   if (fStatus.integer&0x100) return fDaeTime;
00168     return fVmeTime;
00169 }
00170 
00171 
00172 void BeamMonSpill::SetBPM(const vector<double> &xpos, const vector<double> &ypos,
00173                           const vector<double> &intensities)
00174 {
00175     for (size_t ind=0;ind<6 && ind<xpos.size(); ++ind)
00176         fTargBpmX[ind] = xpos[ind];
00177     for (size_t ind=0;ind<6 && ind<ypos.size(); ++ind)
00178         fTargBpmY[ind] = ypos[ind];
00179     for (size_t ind=0;ind<6 && ind<intensities.size(); ++ind)
00180         fBpmInt[ind] = intensities[ind];
00181 }
00182 
00183 
00184 ClassImp(BeamMonSpill)

Generated on Mon Feb 15 11:06:25 2010 for loon by  doxygen 1.3.9.1