#include "ROOTMaker.h" // I hate these global variables, but I'm in too deep now. extern char DETECTOR[128]; extern int HOSTROC; extern int TTROCID; extern unsigned long int EventCounter; extern unsigned int NAboveThreshold[20][72]; ROOTMaker::ROOTMaker(){ char* RateHomePath; RateHomePath = getenv("RATE_HOME"); if(RateHomePath == NULL) cout << " RATE_HOME env variable not set!!!!!" << endl; outputFile = new TFile( Form("%s/output/RateMeasurement%s%i.root", RateHomePath, DETECTOR, HOSTROC), "RECREATE"); BookHistograms(); } void ROOTMaker::BookHistograms(){ // One histogram per ring on the CDC //number of straws in each ring, starts with 0 so that straws[1] is the number of straws in ring 1 const Int_t straws[29] = {0,42,42,54,54,66,66,80,80,93,93,106,106,123,123,135,135,146,146,158,158,170,170,182,182,197,197,209,209}; outputFile->mkdir("CDC"); outputFile->cd("CDC"); for (unsigned int i=1; i < 29;i++){ TString histoName = Form ("CDCRing%i", i); CDCHists[i] = new TH1F(histoName,Form("%s;Straw Number;Rate[Hz]", histoName.Data()),straws[i], 0.5, straws[i] + 0.5); } outputFile->cd(); // One histogram per FDC plane // 6x readout boards per package, each upstream and downstream // 48 total readout planes // Middle of readout segmented into "a and b" sides // 84 strips, then the 24 a, the 84 more. Need to decide where to put a and b outputFile->mkdir("FDC"); outputFile->cd("FDC"); for (unsigned int i=0; i < 48;i++){ TString view; if (i%2) view = "Upstream"; else view = "Downstream"; TString histoName = Form("Package%iCell%i%s", i/12 + 1, (i/2)%6 + 1, view.Data()); FDCHists[i] = new TH1F(histoName, Form("%s;Strip Number;Rate[Hz]", histoName.Data()), 192, 0.5, 192.5); } outputFile->cd(); } void ROOTMaker::FillHistograms(DTranslationTable * tt, int nTriggers, int NADCSAMPLES){ // SetBinContent(bin, content); // SetBinError(bin, erroror); int SLOT = 0; for(int iSlot = 0; iSlot < 20; iSlot++){ if (iSlot < 8) SLOT = iSlot + 3; else SLOT = iSlot + 5; for (int iChan = 0; iChan < 72; iChan++){ if (NAboveThreshold[iSlot][iChan] == 0 || NAboveThreshold[iSlot][iChan] > (unsigned int) (nTriggers - 10) ) continue; // Hot channel or no counts float time = nTriggers * NADCSAMPLES * 8.0E-9; float rate = NAboveThreshold[iSlot][iChan] / time; float error = sqrt(NAboveThreshold[iSlot][iChan]) / time; cout << "TTROCID " << TTROCID << endl; const DTranslationTable::csc_t CSC = {TTROCID, SLOT, iChan}; DTranslationTable::DChannelInfo channel = tt->GetDetectorIndex(CSC); switch ( channel.det_sys ) { case DTranslationTable::CDC: { cout << "ring = " << channel.cdc.ring << " straw = " << channel.cdc.straw << endl; CDCHists[channel.cdc.ring]->SetBinContent(channel.cdc.straw, rate); CDCHists[channel.cdc.ring]->SetBinError(channel.cdc.straw, error); break; } case DTranslationTable::FDC_CATHODES: { cout << "package = " << channel.fdc_cathodes.package << " chamber = " << channel.fdc_cathodes.chamber << " view = " << channel.fdc_cathodes.view << " strip = " << channel.fdc_cathodes.strip << " strip type = " << channel.fdc_cathodes.strip_type; TString view; if (channel.fdc_cathodes.view == 1) view = "Upstream"; else view = "Downstream"; TString histoName = Form("FDC/Package%iCell%i%s", channel.fdc_cathodes.package, channel.fdc_cathodes.chamber, view.Data()); TH1F *thisHist = (TH1F *) outputFile->Get(histoName); if (thisHist == NULL) cout << "Histogram Not Found !!! " << endl; else{ //Histogram found Float_t binContent = thisHist->GetBinContent(channel.fdc_cathodes.strip); Float_t binError = thisHist->GetBinError(channel.fdc_cathodes.strip); Float_t newBinContent = binContent + rate; Float_t newBinError = sqrt( binError * binError + error * error); // Add errors in quadrature thisHist->SetBinContent(channel.fdc_cathodes.strip, newBinContent); thisHist->SetBinContent(channel.fdc_cathodes.strip, newBinError); } break; } default: { cout << "Unrecognized crate? " << endl; break; } } } } cout << "Done Filling histograms " << endl; }