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

BDHadMuMon.cxx

Go to the documentation of this file.
00001 #include "BDHadMuMon.h"
00002 
00003 
00004 #include <Conventions/Munits.h>
00005 #include <MessageService/MsgService.h>
00006 CVSID("$Id: BDHadMuMon.cxx,v 1.6 2005/05/16 16:23:02 bv Exp $");
00007 
00008 
00009 #include <cmath>
00010 #include <string>
00011 using namespace std;
00012 
00013 BDHadMuMon::BDHadMuMon()
00014     : BDSwicDevice(), fNrowcol(0),fNchannels(0),fRowColSpacing(0.0)
00015 {
00016 }
00017     
00018 BDHadMuMon::BDHadMuMon(const RawBeamData& hadmu_data)
00019     : BDSwicDevice(hadmu_data), fNrowcol(0),fNchannels(0),fRowColSpacing(0.0)
00020 {
00021     this->UpdateCache();
00022 }
00023 BDHadMuMon::~BDHadMuMon()
00024 {
00025 }
00026 
00027 void BDHadMuMon::SetData(const RawBeamData& hadmu_data)
00028 {
00029     this->BDSwicDevice::SetData(hadmu_data);
00030     this->UpdateCache();
00031 }
00032 
00033 void BDHadMuMon::UpdateCache()
00034 {
00035     if (!this->IsValid()) {
00036         MSG("BD",Msg::kDebug)
00037             << "UpdateCache called with invalid device data\n";
00038         return;
00039     }
00040     RawBeamData& rbd = this->GetData();
00041     string name = rbd.GetName();
00042     if (name == "E:HADMDS") {   // hadron monitor
00043         fNrowcol = 7;
00044         fNchannels = 7*7;
00045         fRowColSpacing = 11.43*Munits::cm;
00046     }
00047     else {                      // muon monitor
00048         fNrowcol = 9;
00049         fNchannels = 9*9;
00050         fRowColSpacing = 25.4*Munits::cm;
00051     }
00052 
00053 }
00054 
00055 int BDHadMuMon::Index(int channel)
00056 {
00057     --channel;                  // internally we use 0 based counting
00058 
00059     //   offset  = (00-47)(48-95)
00060     //   channel = (48-95)(00-47)
00061     if (channel < 0 || channel >= fNchannels) return -1;
00062     if (channel < 48) return channel + 48;
00063     return channel - 48;        // array offset is by definition 0 based
00064 }
00065 int BDHadMuMon::Channel(int row, int col)
00066 {
00067     --row;                      // internally we use
00068     --col;                      // 0 based counting
00069 
00070     int chan = -2;
00071 
00072     if (row<0||row>=fNrowcol||col<0||col>=fNrowcol) {
00073         MSG("BD",Msg::kWarning)
00074             << "BDHadMuMon::Channel: row/col out of bounds, r,c = "
00075             << row << "," << col << endl;
00076         return -2;
00077     }
00078 
00079     // The PTB decided to transpose the channel numbering between the two....
00080     if (fNrowcol == 7)          // hadron monitor
00081         chan = (6-row)*fNrowcol + col;
00082     else if (fNrowcol == 9)             // muon monitors
00083         chan = col*fNrowcol + (8-row);
00084     else
00085         MSG("BD",Msg::kWarning)
00086             << "BDHadMuMon::Channel: Unknown number or rows/columns: " << fNrowcol << endl;
00087 
00088     return chan+1;              // externally Had/Mu channes are 1 based counting
00089 }
00090 double BDHadMuMon::PixelPosition(int rowcol)
00091 {
00092     --rowcol;                   // internally we use 0 based counting
00093     return (rowcol - (fNrowcol-1)/2) * fRowColSpacing;
00094 }
00095 double BDHadMuMon::GetStats(double& xmean, double &ymean, double &xrms, double &yrms)
00096 {
00097     double qy=0,qx=0,q=0,q2y2=0,q2x2=0,max=0;
00098 
00099     for (int col=0; col<fNrowcol; ++col) {
00100         double X = (col-(fNrowcol-1)/2)* fRowColSpacing;
00101 
00102         for (int row=0; row <fNrowcol; ++row) {
00103             double Y = (row-(fNrowcol-1)/2)*fRowColSpacing;
00104 
00105             int offset = this->Index(Channel(row+1,col+1));
00106             double Q = this->GetCharge(offset);
00107 
00108             q += Q;
00109             qx += Q*X;
00110             qy += Q*Y;
00111             q2x2 += Q*X*Q*X;
00112             q2y2 += Q*Y*Q*Y;
00113             if (max<q) max = q;
00114         }
00115     }
00116     if (q == 0.0) return q;
00117 
00118     xmean = qx/q;
00119     ymean = qy/q;
00120     xrms = sqrt(q2x2)/fabs(q);
00121     yrms = sqrt(q2y2)/fabs(q);
00122     return q;
00123 
00124 }

Generated on Sat Nov 21 22:45:30 2009 for loon by  doxygen 1.3.9.1