Skip to content

Instantly share code, notes, and snippets.

@jdbrice
Created November 11, 2021 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdbrice/25a07b8d6663427a0811466d8fb2b14d to your computer and use it in GitHub Desktop.
Save jdbrice/25a07b8d6663427a0811466d8fb2b14d to your computer and use it in GitHub Desktop.
Read sTGC data from RTS_Example and wwrtie to ROOT TTree

Example:

cd /star/u/jdb/work/ssw/stgc-raw-hit-reader/StRoot/RTS/src/RTS_EXAMPLE starver dev make make ./rts_example /star/data03/pwg/jdb/FWD/daq/stgc-cosmic/st_hltcosmic_22314049_raw_0000002.daq -D stgcsctrg > /star/data03/pwg/jdb/FWD/daq/stgc-cosmic/st_hltcosmic_22314049_raw_0000002.daq.dat

If needed, copy output to wherever the above two scripts are root -b -q -l 'read_RTS.C( "/star/data03/pwg/jdb/FWD/daq/stgc-cosmic/st_hltcosmic_22314049_raw_0000002.daq.dat" )' root -b -q -l 'plot.C( "/star/data03/pwg/jdb/FWD/daq/stgc-cosmic/st_hltcosmic_22314049_raw_0000002.daq.dat.root" )'

TCanvas *c = nullptr;
string reportName = "";
void plotTree( TTree*t, string v, bool ly = false ){
string dcmd = (v + " >> h" + v);
t->Draw( dcmd.c_str() );
TH1 * h = (TH1*)gDirectory->Get( ("h" + v).c_str() );
h->Draw();
h->SetTitle( reportName.c_str() );
h->GetXaxis()->SetTitle( v.c_str() );
h->GetYaxis()->SetTitle( "counts" );
gPad->SetLogy(ly);
c->Print( reportName.c_str() );
}
void plotTree2( TTree*t, string v1, string v2, bool lz = false ){
string dcmd = (v1 + ":" + v2 + " >> h" + v1+"_"+v2);
t->Draw( dcmd.c_str() );
TH1 * h = (TH1*)gDirectory->Get( ("h" + v1+"_"+v2).c_str() );
h->Draw("colz");
h->SetTitle( reportName.c_str() );
h->GetXaxis()->SetTitle( v2.c_str() );
h->GetYaxis()->SetTitle( v1.c_str() );
gPad->SetLogy(false);
gPad->SetLogz(lz);
c->Print( reportName.c_str() );
}
void plot( string fn = "st_hltcosmic_22314049_raw_0000002.daq.dat.root" ){
reportName = fn + ".pdf";
TFile * f = new TFile( fn.c_str() );
TTree * t = (TTree*)f->Get( "sTGC_DataDst" );
c = new TCanvas( "c", "c", 11*1455, 8.5*1455 );
c->SetTopMargin( 0.1 );
c->SetRightMargin( 0.25 );
c->SetLeftMargin( 0.13 );
c->Print( (reportName + "[").c_str() );
plotTree( t, "SEC" );
plotTree( t, "RDO" );
plotTree2( t, "SEC", "RDO" );
plotTree( t, "n", true );
plotTree( t, "FEB" );
plotTree( t, "VMM" );
plotTree2( t, "FEB", "VMM" );
plotTree( t, "CH" );
plotTree( t, "BCID" );
plotTree( t, "ADC", false );
plotTree( t, "ADC", true );
plotTree2( t, "ADC", "CH" );
c->Print( (reportName + "]").c_str() );
}
const Int_t mMax = 100000;
struct STGCVMMData
{
// event information
Int_t EventId;
Int_t Sec;
Int_t Rdo;
Int_t n;
//channel information
Int_t Channel_Number[mMax];
Int_t Strip_Number[mMax];
Int_t FEB[mMax];
Int_t FEBVMM[mMax];
Int_t VMM[mMax];
Int_t CH[mMax];
Int_t BCID[mMax];
Int_t ADC[mMax];
Int_t TB[mMax];
};
size_t fttIndex = 0;
TTree * mVMMTree;
STGCVMMData mVMMData;
void parse_evt_line( std::stringstream &ss ){
cout << ss.str() << endl;
if ( mVMMData.EventId >= 0 )
mVMMTree->Fill();
string tok;
ss >> tok; // STGC
ss >> tok; // VMM:
ss >> tok; // evt
ss >> mVMMData.EventId;
ss >> tok; // :
ss >> tok; // sec
ss >> mVMMData.Sec;
ss >> tok; // ,
ss >> tok; // RDO
ss >> mVMMData.Rdo;
ss >> tok; // :
ss >> tok; // hits
ss >> mVMMData.n;
fttIndex = 0;
}
void parse_feb_line( std::stringstream &ss ){
cout << ss.str() << endl;
string tok;
ss >> tok; // FEB
ss >> mVMMData.FEB[fttIndex];
char buf[100];
ss.read( buf, 1 );
ss >> mVMMData.VMM[fttIndex];
ss >> tok; // [0xfeb_vmm],
// cout << tok << endl;;
ss >> tok; // ch
ss >> mVMMData.CH[fttIndex];
ss >> tok; // :
ss >> tok; // ADC
ss >> mVMMData.ADC[fttIndex];
ss >> tok; // ,
ss >> tok; // BCID
ss >> mVMMData.BCID[fttIndex];
ss >> tok; // ,
ss >> tok; // tb
ss >> mVMMData.TB[fttIndex];
fttIndex++;
}
void read_RTS( string fn = "st_hltcosmic_22314049_raw_0000002.daq.dat" ){
mVMMData.EventId = -1;
cout << " Booking the event tree " << endl;
mVMMTree = new TTree("sTGC_DataDst","sTGC_DataDst");
mVMMTree->SetAutoSave(100000000); // 100 MB
// Event information
mVMMTree->Branch("mEvtID", &mVMMData.EventId, "Event/I");
mVMMTree->Branch("SEC", &mVMMData.Sec, "SEC/I");
mVMMTree->Branch("RDO", &mVMMData.Rdo, "RDO/I");
mVMMTree->Branch("n", &mVMMData.n, "n/I");
// Channel information
mVMMTree->Branch("Channel_Number", mVMMData.Channel_Number, "Channel_Number[n]/I");
mVMMTree->Branch("Strip_Number", mVMMData.Strip_Number, "Strip_Number[n]/I");
mVMMTree->Branch("FEB", mVMMData.FEB, "FEB[n]/I");
mVMMTree->Branch("FEBVMM", mVMMData.FEBVMM, "FEBVMM[n]/I");
mVMMTree->Branch("VMM", mVMMData.VMM, "VMM[n]/I");
mVMMTree->Branch("CH", mVMMData.CH, "CH[n]/I");
mVMMTree->Branch("BCID", mVMMData.BCID, "BCID[n]/I");
mVMMTree->Branch("ADC", mVMMData.ADC, "ADC[n]/I");
mVMMTree->Branch("TB", mVMMData.TB, "TB[n]/I");
ifstream inf( fn.c_str() );
std::string line;
while (std::getline(inf, line))
{
std::stringstream ss(line);
if ( line.find( "STGC VMM: evt" ) != string::npos )
parse_evt_line( ss );
else if ( line.find( "FEB" ) != string::npos )
parse_feb_line( ss );
// process pair (a,b)
}
string ofn = fn + ".root";
TFile * fout = new TFile( ofn.c_str(), "RECREATE" );
fout->cd();
mVMMTree->Write();
fout->Write();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment