StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcAvClusterMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StTpcAvClusterMaker.cxx,v 1.5 2018/10/17 20:45:27 fisyak Exp $
4  *
5  **************************************************************************/
6 #include <assert.h>
7 #include "StTpcAvClusterMaker.h"
8 #include "StEvent.h"
9 #include "StEvent/StTpcHitCollection.h"
10 #include "StEvent/StTpcHit.h"
11 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
12 //_____________________________________________________________
13 Int_t StTpcAvClusterMaker::InitRun(Int_t runnumber) {
14  static Bool_t Done = kFALSE;
15  SetAttr("minSector",1);
16  SetAttr("maxSector",24);
17  SetAttr("minRow",1);
18  Int_t NoRows = St_tpcPadConfigC::instance()->numberOfRows(20);
19  SetAttr("maxRow",NoRows);
20  if (! Done) {
21  TFile *f = GetTFile();
22  if (! f) {
23  gMessMgr->Error() << "with Tpx/Tpc AvLaser you must provide TFile as the 5-th parameter in bfc.C macro" << endm;
24  assert(0);
25  }
26  f->cd();
27  enum {NoDim = 3};
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]);
40  }
41  f->Add(fAvLaser[s-1]);
42  }
43  Done = kTRUE;
44  }
45  // write event header for AvLaser
46  StEvtHddr *header = GetEvtHddr();
47  if (header) {
48  TFile *f = GetTFile();
49  if (! f) {
50  gMessMgr->Error() << "with Tpx/Tpc AvLaser you must provide TFile as the 5-th parameter in bfc.C macro" << endm;
51  assert(0);
52  }
53  f->cd();
54  header->Write();
55  }
56  return kStOK;
57 }
58 //_____________________________________________________________
60 #if 0
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]);
69  }
70  }
71  }
72 #endif
73  return StMaker::Finish();
74 }
75 //_____________________________________________________________
77  StEvent *pEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent"));
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;}
80  StTpcHitCollection *TpcHitCollection = pEvent->tpcHitCollection();
81  if (! TpcHitCollection) {LOG_INFO << "StTpcHitMaker::Make : Tpc hit Collection has not been found " << endm; return kStWarn;}
82  struct pixl_t {
83  Double_t sector, row, pad, time, adc;
84  };
85  pixl_t pixel;
86 
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]);
96  }
97  StTpcSectorHitCollection* sectorCollection = TpcHitCollection->sector(sec-1);
98  if (sectorCollection) {
99  UInt_t numberOfPadrows = sectorCollection->numberOfPadrows();
100  for (UInt_t row = 1; row <= numberOfPadrows; row++) {
101  StTpcPadrowHitCollection *rowCollection = TpcHitCollection->sector(sec-1)->padrow(row-1);
102  if (rowCollection) {
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);
106  pixel.sector = sec;
107  pixel.row = row;
108  pixel.pad = kHit->pad();
109  pixel.time = kHit->timeBucket();
110  pixel.adc = kHit->adc();
111  fAvLaser[sec-1]->Fill(&pixel.row);// ,pixel.adc);
112  }
113  }
114  }
115  }
116  }
117  return kStOK;
118 }
119 //________________________________________________________________________________
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);//, hist->GetChunkSize());
126  hnew->CalculateErrors(kTRUE);
127  delete [] nbins;
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());
132  }
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;
136  Double_t max = -1;
137  for (Long64_t i = 0; i < N; ++i) {
138  Double_t cont = hist->GetBinContent(i, bins);
139  if (cont > max) max = cont;
140  }
141  for (Long64_t i = 0; i < N; ++i) {
142  Double_t cont = hist->GetBinContent(i, bins);
143  if (cont < max/compress) continue;
144  // Long64_t bin = hnew->GetBin(bins);
145  for (Int_t d = 0; d < nd; ++d) {x[d] = hist->GetAxis(d)->GetBinCenter(bins[d]);}
146  hnew->Fill(x,cont);
147  }
148  delete [] bins;
149  delete [] x;
150  cout << hnew->GetName() << " has " << hnew->GetNbins() << " bins after compression." << endl;
151  return hnew;
152 }
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776