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

Pedestals Class Reference

#include <Pedestals.h>

List of all members.

Public Types

typedef std::map< std::string,
std::vector< double > > 
PedMap

Public Member Functions

void GeneratePeds (Knot &k, const char *devs[])
bool LoadPedFile (const char *file)
void WritePedFile (const char *file)
std::vector< double > & GetPeds (const char *device_name)
std::vector< double > & GetMask (const char *device_name)
const PedMapGetPedMap ()
const PedMapGetChMaskMap ()

Private Attributes

PedMap fPeds
PedMap fMask


Member Typedef Documentation

typedef std::map<std::string,std::vector<double> > Pedestals::PedMap
 

Definition at line 12 of file Pedestals.h.


Member Function Documentation

void Pedestals::GeneratePeds Knot k,
const char *  devs[]
 

Generate peds using data in Knot for given devices. The devs[] array must be zero terminated. Can be called multiple times but will overwrite any pre-existing devices

Definition at line 27 of file Pedestals.cxx.

References HistMan::Book(), AcnetDevice::data, fMask, fPeds, HistMan::Get(), Knot::GetDevice(), Knot::GetEntry(), Knot::GetSize(), Swic::GetVmeTimestamp(), Swic::GetVoltage(), ped_devs, Swic::SetAcnetDevice(), and AcnetDevice::timestamp.

Referenced by PlotterManager::GetPeds().

00028 {
00029 
00030     const AcnetDevice* tor = k.GetDevice("E:TOR101");
00031 
00032     HistMan hm("peds");
00033 
00034     // prefill Knot's cache and create hists
00035     int nped_devs=0;
00036     for (int ind = 0; ped_devs[ind]; ++ind) {
00037         k.GetDevice(ped_devs[ind]);
00038         string name = &ped_devs[ind][2];
00039         TH1D* hist = hm.Book<TH1D>(name.c_str(), name.c_str(),96,0,96);
00040         hist->Sumw2();
00041         
00042         ++nped_devs;
00043     }
00044     
00045     int nentries = k.GetSize();
00046     vector<int> npeds_entries(nped_devs,0);
00047     for (int entry=0; entry<nentries; ++entry) {
00048         k.GetEntry(entry);
00049         
00050         // Skip when there is beam in the toroid.
00051         if (tor->data[0] > 0.10) continue;
00052         
00053         bool skip = false;
00054         for (int ind = 0; ped_devs[ind]; ++ind) {
00055             const AcnetDevice* ad = k.GetDevice(ped_devs[ind]);
00056             Swic swic;
00057             if (!swic.SetAcnetDevice(*ad)) {
00058                 cerr << "Entry " << entry << " failed to set acnet data\n";
00059                 skip = true;
00060                 break;
00061             }
00062             if (fabs(swic.GetVmeTimestamp() - ad->timestamp) > 2.0) {
00063                 skip = true;
00064                 break;
00065             }
00066         }
00067         if (skip) continue;
00068         
00069         for (int ind = 0; ped_devs[ind]; ++ind) {
00070             
00071             const AcnetDevice* ad = k.GetDevice(ped_devs[ind]);
00072             Swic swic;
00073             swic.SetAcnetDevice(*ad);
00074             
00075             TH1D* hist = hm.Get<TH1D>(&ped_devs[ind][2]);
00076             
00077             for (int ch=0; ch<96; ++ch) {
00078                 double volts = swic.GetVoltage(ch);
00079                 hist->Fill(ch,volts);
00080             }
00081             ++npeds_entries[ind];
00082         }
00083     }
00084 
00085     for (int ind=0; ped_devs[ind]; ++ind) {
00086         TH1D* hist = hm.Get<TH1D>(&ped_devs[ind][2]);
00087         if (npeds_entries[ind])
00088             hist->Scale(1.0/npeds_entries[ind]);
00089         
00090         vector<double> v;
00091         for (int ch=0; ch<96; ++ch) v.push_back(hist->GetBinContent(ch+1));
00092         fPeds[ped_devs[ind]] = v;
00093     }
00094 
00095     
00096     // mask
00097     for (int ind=0; ped_devs[ind]; ++ind) {
00098         vector<double>& peds = fPeds[ped_devs[ind]];
00099         vector<double> mask(96,1);
00100         string dev(ped_devs[ind]);
00101         if (dev == "E:MMA1DS" || dev == "E:MMA2DS" || dev == "E:MMA3DS") {
00102             fMask[ped_devs[ind]] = mask;
00103             continue;
00104         }
00105 
00106         for (int ch=0; ch<96; ++ch)
00107             if (fabs(peds[ch]) > 50) mask[ch] = 0;
00108         if (dev == "E:M121DS") {
00109             mask[1] = 0; // low (unused channel)
00110             mask[2] = 0; // 1st channel on horiz is noisy
00111             mask[45] = 0; // low (last channel in horiz)
00112             mask[49] = 0; // low (unused channel)
00113             mask[94] = 0; // low (unused channel)
00114         }
00115             
00116         fMask[ped_devs[ind]] = mask;
00117     }
00118 }

const PedMap& Pedestals::GetChMaskMap  )  [inline]
 

Definition at line 42 of file Pedestals.h.

00042 { return fMask; }

vector< double > & Pedestals::GetMask const char *  device_name  ) 
 

Return a vector holding 1 or 0 indicating this channel is good or bad. Check vector::size() to be non-zero if it fails to find the device.

Definition at line 22 of file Pedestals.cxx.

References fMask.

Referenced by ProtonDist::Fill().

00023 {
00024     return fMask[device_name];
00025 }

const PedMap& Pedestals::GetPedMap  )  [inline]
 

Definition at line 41 of file Pedestals.h.

00041 { return fPeds; }

vector< double > & Pedestals::GetPeds const char *  device_name  ) 
 

Get the pedestal for given device. Check vector::size() to be non-zero if it fails to find on.

Definition at line 17 of file Pedestals.cxx.

References fPeds.

Referenced by book_and_fill(), and ProtonDist::Fill().

00018 {
00019     return fPeds[device_name];
00020 }

bool Pedestals::LoadPedFile const char *  file  ) 
 

Files format is: No.of devs D:EVICE1 D:EVICE2 ... D:EVICEN 0 ped ped ... ped 1 ped ped ... ped

Definition at line 149 of file Pedestals.cxx.

References fPeds.

Referenced by make_plots().

00150 {
00151     ifstream fstr(file);
00152     if (!fstr) {
00153         cerr << "Failed to load pedestal file: \"" << file << "\"\n";
00154         return false;
00155     }
00156 
00157     int ndevs;
00158     vector<string> devs;
00159 
00160     fstr >> ndevs;
00161     for (int ind=0; ind<ndevs; ++ind) {
00162         string dev;
00163         fstr >> dev;
00164         devs.push_back(dev);
00165         cerr << dev << " ";
00166     }
00167     cerr << endl;
00168     for (int ch=0; ch<96; ++ch) {
00169         int channel;
00170         fstr >> channel;
00171         for (int dev=0; dev<ndevs; ++dev) {
00172             double scale;
00173             fstr >> scale;
00174             string devname = devs[dev];
00175             //cerr << devname << ": " << scale << endl;
00176             if (!ch) {
00177                 vector<double> v;
00178                 fPeds[devname] = v;
00179             }
00180             fPeds[devname].push_back(scale);
00181         }
00182     }
00183     return true;
00184 }

void Pedestals::WritePedFile const char *  file  ) 
 

Definition at line 122 of file Pedestals.cxx.

References done(), fPeds, and ped_devs.

00123 {
00124     ofstream fstr(file);
00125     if (!fstr) {
00126         cerr << "Can't open " << file << endl;
00127         return;
00128     }
00129 
00130     fstr << fPeds.size() << " ";
00131     vector<string> ped_devs;
00132     PedMap::iterator it, done = fPeds.end();
00133     for (it=fPeds.begin(); it != done; ++it) {
00134         ped_devs.push_back(it->first);
00135         fstr << it->first << " ";
00136     }
00137     fstr << endl;
00138 
00139     for (int ch=0; ch<96; ++ch) {
00140         fstr << ch << " ";
00141         for (size_t ind=0; ped_devs.size(); ++ind) {
00142             double ped = fPeds[ped_devs[ind]][ch];
00143             fstr << ped << " ";
00144         }
00145         fstr << endl;
00146     }
00147 }


Member Data Documentation

PedMap Pedestals::fMask [private]
 

Definition at line 46 of file Pedestals.h.

Referenced by GeneratePeds(), and GetMask().

PedMap Pedestals::fPeds [private]
 

Definition at line 45 of file Pedestals.h.

Referenced by GeneratePeds(), GetPeds(), LoadPedFile(), and WritePedFile().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:10:00 2010 for loon by  doxygen 1.3.9.1