void raw_adc(void) { gROOT->Reset(); TFile *f = new TFile("bcal_mon02334.root"); TH2F *id_vs_adc = (TH2F*)gROOT->FindObject("id_vs_adc"); TH2F *channel_vs_ped_slot18 = (TH2F*)gROOT->FindObject("channel_vs_ped_slot18"); TH2F *channel_vs_ped_slot19 = (TH2F*)gROOT->FindObject("channel_vs_ped_slot19"); // Make canvas TCanvas *c1 = new TCanvas("c1","",1000,800); c1->SetTickx(); c1->SetTicky(); // Get pedestals from peds file short ped_slot18[32], ped_slot19[32]; GetPeds(2334, ped_slot18, ped_slot19); // Convert from geometric to detector indexing of pedestals short peds[65]; ConvertToDetectorIndexes(ped_slot18, ped_slot19, peds); // Make labels list (seems dificult to pull this from histogram itself) char *labels[65]; for(int i=0; i<=64; i++)labels[i]="NA"; for(int i=1; i<=18; i++){ char label[256]; sprintf(label,"BCALN%02d",i); labels[i] = strdup(label); sprintf(label,"BCALS%02d",i); labels[i+32] = strdup(label); } labels[62] = strdup("VETO"); labels[63] = strdup("COSMIC1"); labels[64] = strdup("COSMIC2"); // Get parameters of X-axis histogram TAxis *xaxis = id_vs_adc->GetXaxis(); int Nxbins = xaxis->GetNbins(); double xlo = xaxis->GetBinLowEdge(1); double xhi = xaxis->GetBinUpEdge(Nxbins); // loop over channels for(int i=1; i<=id_vs_adc->GetNbinsY(); i++){ if(!strcmp(labels[i], "NA"))continue; // Create histogram and project from 2D histo onto it char title[256]; sprintf(title, "Raw ADC spectrum for %s, run 2334", labels[i]); TH1D *h = new TH1D(labels[i],title, Nxbins, xlo, xhi); id_vs_adc->ProjectionX(labels[i], i, i); // Draw histogram h->SetFillStyle(3001); h->SetFillColor(kMagenta); h->Draw(); // Draw Pedestal histogram TH1D *h_ped = GetPedHisto(i, labels[i], channel_vs_ped_slot18, channel_vs_ped_slot19); h_ped->SetFillStyle(3001); h_ped->SetFillColor(kMagenta); TAxis *xaxis = h_ped->GetXaxis(); double xmax = xaxis->GetBinCenter(h_ped->GetMaximumBin()); xaxis->SetRangeUser(xmax-50.0, xmax+50.0); TPad *mypad = new TPad("mypad","", 0.4, 0.45, 0.87, 0.8); mypad->SetTickx(); mypad->SetTicky(); mypad->Draw(); mypad->cd(); h_ped->Draw(); // Draw line at pedestal double ped = (double)peds[i]; TLine *l = new TLine(ped, 0.0, ped, h_ped->GetMaximum()*1.05); l->SetLineColor(kBlue); l->SetLineWidth(2); l->Draw(); c1->cd(0); c1->Update(); char fname[256]; sprintf(fname, "%s_raw.gif", labels[i]); c1->SaveAs(fname); sprintf(fname, "%s_raw.eps", labels[i]); c1->SaveAs(fname); } } const char* strdup(const char*in) { char *out = new char[strlen(in)+1]; strcpy(out, in); return out; } typedef struct{ short slot18[32]; short slot19[32]; int run; }ped_t; void GetPeds(int run, short *ped_slot18, short *ped_slot19) { // Pedestals are contained in the ROOT file bcal_peds.root for // all runs (at least those from which they could be extracted). // Try opening this file in the local directory and reading in // the pedestals for the run number closest to the one we're // processing. TFile *f = new TFile("bcal_peds.root"); if(f){ ped_t ped_run; TTree *ped = (TTree*)f->Get("ped"); if(ped){ // Set Branch addresses ped->SetBranchAddress("slot18", ped_run.slot18); ped->SetBranchAddress("slot19", ped_run.slot19); ped->SetBranchAddress("run", &ped_run.run); // loop over pedestal entries, looking for the closest run number int Nentries = ped->GetEntries(); int myrun=0; for(int i=0; iGetEntry(i+1); if(abs(myrun-ped_run.run)>abs(run-ped_run.run)){ // This run is closer myrun = ped_run.run; for(int channel=0; channel<32; channel++){ ped_slot18[channel] = ped_run.slot18[channel]; ped_slot19[channel] = ped_run.slot19[channel]; } } } cout<<"[[[[[[[[[[[ Using pedestals from run "<32 ? channel_vs_ped_slot19:channel_vs_ped_slot18; // Get X-axis info TAxis *xaxis = chan_vs_ped->GetXaxis(); int Nxbins = xaxis->GetNbins(); double xlo = xaxis->GetBinLowEdge(1); double xhi = xaxis->GetBinUpEdge(Nxbins); // Create histo to project onto char str[256]; sprintf(str, "ped_%s", name); TH1D *h = new TH1D(str,str,Nxbins, xlo, xhi); chan_vs_ped->ProjectionX(str, chan+1, chan+1); return h; }