Go to the source code of this file.
Functions | |
| void | pedmaker (TTree &tree, const char *outhist_filename, const char *outpeds_filename) |
|
||||||||||||||||
|
Definition at line 34 of file pedmaker.cxx. References HistMan::Book(), AcnetDevice::data, Form(), HistMan::Get(), Knot::GetDevice(), Knot::GetEntry(), Knot::GetSize(), Swic::GetVmeTimestamp(), Swic::GetVoltage(), ped_devs, Swic::SetAcnetDevice(), Swic::SetMvPerADC(), AcnetDevice::timestamp, and HistMan::WriteOut(). 00036 {
00037 ofstream fstr(outpeds_filename);
00038 if (!fstr) {
00039 cerr << "Can't open " << outpeds_filename << endl;
00040 return;
00041 }
00042
00043 Knot k(tree);
00044
00045 const AcnetDevice* tor = k.GetDevice("E:TOR101");
00046
00047 HistMan hm("peds");
00048
00049 // prefill Knot's cache and create hists
00050 int nped_devs=0;
00051 for (int ind = 0; ped_devs[ind]; ++ind) {
00052 k.GetDevice(ped_devs[ind]);
00053 string name = &ped_devs[ind][2];
00054 TH1D* hist = hm.Book<TH1D>(name.c_str(), name.c_str(),96,0,96);
00055 hist->Sumw2();
00056 hm.Book<TH1D>(Form("%s_sigma",name.c_str()),
00057 Form("%s sigma away from mean",name.c_str()),96,0,96);
00058 hm.Book<TH1D>(Form("%s_diff",name.c_str()),
00059 Form("%s dist away from mean",name.c_str()),100,0,100);
00060
00061 ++nped_devs;
00062 }
00063 hm.Book<TH1D>("sigmas","Sigma of pedestals",nped_devs,0,nped_devs);
00064 hm.Book<TH1D>("means","Mean of pedestals",nped_devs,0,nped_devs);
00065
00066 int nentries = k.GetSize();
00067 vector<int> npeds_entries(nped_devs,0);
00068 for (int entry=0; entry<nentries; ++entry) {
00069 k.GetEntry(entry);
00070
00071 // Skip when there is beam in the toroid.
00072 if (tor->data[0] > 0.10) continue;
00073
00074 bool skip = false;
00075 for (int ind = 0; ped_devs[ind]; ++ind) {
00076 const AcnetDevice* ad = k.GetDevice(ped_devs[ind]);
00077 Swic swic;
00078 if (!swic.SetAcnetDevice(*ad)) {
00079 cerr << "Entry " << entry << " failed to set acnet data\n";
00080 skip = true;
00081 break;
00082 }
00083 if (fabs(swic.GetVmeTimestamp() - ad->timestamp) > 2.0) {
00084 skip = true;
00085 break;
00086 }
00087 }
00088 if (skip) continue;
00089
00090 for (int ind = 0; ped_devs[ind]; ++ind) {
00091
00092 const AcnetDevice* ad = k.GetDevice(ped_devs[ind]);
00093 Swic swic;
00094 swic.SetMvPerADC(1.0); // Use ADC value
00095 swic.SetAcnetDevice(*ad);
00096
00097 TH1D* hist = hm.Get<TH1D>(&ped_devs[ind][2]);
00098
00099 for (int ch=0; ch<96; ++ch) {
00100 double volts = swic.GetVoltage(ch);
00101 hist->Fill(ch,volts);
00102 }
00103 ++npeds_entries[ind];
00104 }
00105 }
00106
00107 for (int ind=0; ped_devs[ind]; ++ind) {
00108 TH1D* hist = hm.Get<TH1D>(&ped_devs[ind][2]);
00109 if (npeds_entries[ind])
00110 hist->Scale(1.0/npeds_entries[ind]);
00111 }
00112
00113 fstr << "Chan ";
00114 for (int ind=0; ped_devs[ind]; ++ind)
00115 fstr << ped_devs[ind] << " ";
00116 fstr << endl;
00117
00118 for (int ch=0; ch<96; ++ch) {
00119 fstr << ch << " ";
00120 for (int ind=0; ped_devs[ind]; ++ind) {
00121 TH1D* hist = hm.Get<TH1D>(&ped_devs[ind][2]);
00122 fstr << hist->GetBinContent(ch+1) << " ";
00123 }
00124 fstr << endl;
00125 }
00126
00127 TH1D* sigmas_hist = hm.Get<TH1D>("sigmas");
00128 TH1D* means_hist = hm.Get<TH1D>("means");
00129 for (int ind=0; ped_devs[ind]; ++ind) {
00130 sigmas_hist->GetXaxis()->SetBinLabel(ind+1,ped_devs[ind]);
00131 means_hist->GetXaxis()->SetBinLabel(ind+1,ped_devs[ind]);
00132
00133 double x = 0, x2 = 0;
00134 string name = &ped_devs[ind][2];
00135 TH1D* hist = hm.Get<TH1D>(name.c_str());
00136 for (int ch=0; ch<96; ++ch) {
00137 double c = hist->GetBinContent(ch+1);
00138 double e = hist->GetBinError(ch+1);
00139 e *= e;
00140 x += c/e;
00141 x2 += 1.0/e;
00142 }
00143 double mean = x/x2;
00144 double sigma = sqrt(x2);
00145 sigmas_hist->Fill(ind,sigma);
00146 means_hist->Fill(ind,mean);
00147
00148 TH1D* hist_sigma = hm.Get<TH1D>(Form("%s_sigma",name.c_str()));
00149 TH1D* hist_diff = hm.Get<TH1D>(Form("%s_diff",name.c_str()));
00150 for (int ch=0; ch<96; ++ch) {
00151 double c = hist->GetBinContent(ch+1);
00152 hist_sigma->SetBinContent(ch+1,(c-mean)/sigma);
00153 hist_diff->Fill(fabs(c-mean));
00154 }
00155 }
00156
00157 TFile file(outhist_filename,"RECREATE");
00158 hm.WriteOut(file);
00159 file.Close();
00160 }
|
1.3.9.1