Simple Vector to ASCII

I have no knowledge of c++ or root, previously. But now I am working on CMS trying to get data into the form of an ASCII file so that it can be stored in a database. The only code that is written takes the data and immediately creates a series of histograms with it. I need to just get the raw numbers and save them as an ASCII file in the following format:

run=9988

date=02/17/2005

mode=Calibration

file name=/home/fnal/data/HTBf_009988.root

barcode=3040000000000100007

Bin - Channel - Value
0 - 0 - 0.0000
1 - 0 - 0.2342
2 - 0 - 0.2342
3 - 0 - 0.5223
4 - 0 - 0.6243
5 - 0 - 0.7654
… - … - …
… - … - …

The code currently creates three series of histograms with this data with channels numbered 4-9, 10-15, and 16-21. Here is the code that is being used to create the histograms:

void plotPul(const char* filename, int nhtr, int nevt=-1) {

TH1F* pulses[21];
double nvalid[21];
for (int i=0; i<21 ; i++) {
char s[50];
nvalid[i]=0;
sprintf(s,“HTR#%d input %d”,nhtr,i+1);
pulses[i]=new TH1F(s,s,20,-0.5,19.5);
}

TestBeamDataFile f;
f.load(filename);

f.getNextEvent();
double ne=1.0/f.getNEvents();
while (f.getNextEvent()) {
if (nevt>0) {
f.findEvent(nevt);
ne=1;
}

const DCCData* dcc=f.getEventData()->getHCALData()->getDCC(20);
unsigned short buffer[25];
double data[20];
char fiber, qieid, er, dv, cap, qie;

if (!dcc->isHTRPresent(nhtr)) {
if (ne==1) break;
else continue;
}

for (int nchan=4;nchan<=21; nchan++) {
dcc->getQIEData(nhtr,nchan,buffer);
int cap_should_be=0;
bool capok=true;
for (int i=0; i<20; i++) {
DCCData::parseQIE(buffer[i],fiber,qieid, er, dv, cap, qie);
data[i]=DCCData::convertToFC_inv(qie);
if (i==0) cap_should_be=cap;
else {
cap_should_be=(cap_should_be+1)%4;
if (cap_should_be!=cap) {
capok=false;
// printf("%d %d\n",cap_should_be,cap);
}
}
}
if (capok) {
nvalid[nchan-1]+=1.0;
for (int j=0; j<20; j++)
pulses[nchan-1]->Fill(j,data[j]);
}
}
if (nevt>0) break;
}

f.close();

for (int j=0; j<21; j++)
if (nvalid[j]>0) pulses[j]->Scale(1.0/nvalid[j]);

TCanvas* c1 = new TCanvas(“c1”,“Channels 4-9”);
c1->Divide(2,3);
for (int i=0; i<6; i++) {
c1->cd(i+1);
pulses[i+3]->Draw();
}
TCanvas* c2 = new TCanvas(“c2”,“Channels 10-15”);
c2->Divide(2,3);
for (int i=0; i<6; i++) {
c2->cd(i+1);
pulses[i+9]->Draw();
}
TCanvas* c3 = new TCanvas(“c3”,“Channels 16-21”);
c3->Divide(2,3);
for (int i=0; i<6; i++) {
c3->cd(i+1);
pulses[i+15]->Draw();
}
}

I would be very thankful for any help and/or advice.

-Andrew

below a simple example showing how to print the bin contents and
the bin coordinate of histograms (pbins.C)

void pbins() { TH1F h("h","test",20,-2,2); h.FillRandom("gaus",500); int nbins = h.GetXaxis()->GetNbins(); for (int bin=1;bin<=nbins;bin++) { printf("%4d %6.1f %4.1f\n",bin, h.GetXaxis()->GetBinCenter(bin), h.GetBinContent(bin)); } }

execute this script with:

Rene