7 #include "StTpcAvClusterMaker.h"
9 #include "StEvent/StTpcHitCollection.h"
10 #include "StEvent/StTpcHit.h"
11 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
13 Int_t StTpcAvClusterMaker::InitRun(Int_t runnumber) {
14 static Bool_t Done = kFALSE;
15 SetAttr(
"minSector",1);
16 SetAttr(
"maxSector",24);
18 Int_t NoRows = St_tpcPadConfigC::instance()->numberOfRows(20);
19 SetAttr(
"maxRow",NoRows);
21 TFile *f = GetTFile();
23 gMessMgr->Error() <<
"with Tpx/Tpc AvLaser you must provide TFile as the 5-th parameter in bfc.C macro" << endm;
28 const Char_t *NameV[NoDim] = {
"row",
"pad",
"time"};
29 const Double_t xMin[NoDim] = {0.5 , 0.5, -0.5};
30 const Double_t xMax[NoDim] = {0.5+NoRows, 182.5, 399.5};
31 Int_t nBins[NoDim] = { NoRows, 8*182, 8*400};
32 fAvLaser =
new THnSparseF *[24];
33 for (Int_t s = 1; s <= 24; s++) {
34 fAvLaser[s-1] =
new THnSparseF(Form(
"AvLaser_%02i",s),
35 Form(
"Averaged laser event for sector %02i",s),
36 NoDim, nBins, xMin, xMax);
37 fAvLaser[s-1]->CalculateErrors(kTRUE);
38 for (Int_t i = 0; i < NoDim; i++) {
39 fAvLaser[s-1]->GetAxis(i)->SetName(NameV[i]);
41 f->Add(fAvLaser[s-1]);
48 TFile *f = GetTFile();
50 gMessMgr->Error() <<
"with Tpx/Tpc AvLaser you must provide TFile as the 5-th parameter in bfc.C macro" << endm;
61 if (GetTFile() && fAvLaser) {
62 for (Int_t sector = 1; sector <= 24; sector++) {
63 if (fAvLaser[sector-1]) {
64 THnSparseF *hnew = CompressTHn(fAvLaser[sector-1]);
65 GetTFile()->Remove(fAvLaser[sector-1]);
66 delete fAvLaser[sector-1];
67 fAvLaser[sector-1] = hnew;
68 GetTFile()->Add(fAvLaser[sector-1]);
78 if (Debug()) {LOG_INFO <<
"StTpcHitMaker::Make : StEvent has been retrieved " <<pEvent<< endm;}
79 if (! pEvent) {LOG_INFO <<
"StTpcHitMaker::Make : StEvent has not been found " << endm;
return kStWarn;}
81 if (! TpcHitCollection) {LOG_INFO <<
"StTpcHitMaker::Make : Tpc hit Collection has not been found " << endm;
return kStWarn;}
83 Double_t sector, row, pad, time, adc;
87 UInt_t numberOfSectors = 24;
88 for (UInt_t sec = 1; sec <= numberOfSectors; sec++) {
89 assert(fAvLaser[sec-1]);
90 if (fAvLaser[sec-1]->GetNbins() > 1000000) {
91 THnSparseF *hnew = CompressTHn(fAvLaser[sec-1]);
92 GetTFile()->Remove(fAvLaser[sec-1]);
93 delete fAvLaser[sec-1];
94 fAvLaser[sec-1] = hnew;
95 GetTFile()->Add(fAvLaser[sec-1]);
98 if (sectorCollection) {
99 UInt_t numberOfPadrows = sectorCollection->numberOfPadrows();
100 for (UInt_t row = 1; row <= numberOfPadrows; row++) {
103 UInt_t NoHits = rowCollection->hits().size();
104 for (UInt_t k = 0; k < NoHits; k++) {
105 StTpcHit* kHit = TpcHitCollection->sector(sec-1)->padrow(row-1)->hits().at(k);
108 pixel.pad = kHit->pad();
109 pixel.time = kHit->timeBucket();
110 pixel.adc = kHit->adc();
111 fAvLaser[sec-1]->Fill(&pixel.row);
120 THnSparseF *StTpcAvClusterMaker::CompressTHn(THnSparseF *hist, Double_t compress) {
121 if (! hist)
return 0;
122 Int_t nd = hist->GetNdimensions();
123 Int_t *nbins =
new Int_t[nd];
124 for (Int_t i = 0; i < nd; i++) nbins[i] = hist->GetAxis(i)->GetNbins();
125 THnSparseF *hnew =
new THnSparseF(hist->GetName(),hist->GetTitle(),nd, nbins, 0, 0);
126 hnew->CalculateErrors(kTRUE);
128 for (Int_t i = 0; i < nd; i++) {
129 TAxis *ax = hist->GetAxis(i);
130 if (ax->IsVariableBinSize()) hnew->GetAxis(i)->Set(ax->GetNbins(), ax->GetXbins()->GetArray());
131 else hnew->GetAxis(i)->Set(ax->GetNbins(), ax->GetXmin(), ax->GetXmax());
133 Int_t *bins =
new Int_t[nd];
134 Double_t *x =
new Double_t[nd];
135 Long64_t N = hist->GetNbins(); cout << hist->GetName() <<
" has " << N <<
" bins before compression." << endl;
137 for (Long64_t i = 0; i < N; ++i) {
138 Double_t cont = hist->GetBinContent(i, bins);
139 if (cont > max) max = cont;
141 for (Long64_t i = 0; i < N; ++i) {
142 Double_t cont = hist->GetBinContent(i, bins);
143 if (cont < max/compress)
continue;
145 for (Int_t d = 0; d < nd; ++d) {x[d] = hist->GetAxis(d)->GetBinCenter(bins[d]);}
150 cout << hnew->GetName() <<
" has " << hnew->GetNbins() <<
" bins after compression." << endl;
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)