StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcHitCollection.cxx
1 // $Id: StEmcHitCollection.cxx,v 1.9 2004/05/03 23:32:39 perev Exp $
2 // $Log: StEmcHitCollection.cxx,v $
3 // Revision 1.9 2004/05/03 23:32:39 perev
4 // Possible non init WarnOff
5 //
6 // Revision 1.8 2003/09/02 17:59:28 perev
7 // gcc 3.2 updates + WarnOff
8 //
9 // Revision 1.7 1999/09/24 01:23:38 fisyak
10 // Reduced Include Path
11 //
12 // Revision 1.6 1999/07/16 18:04:00 pavlinov
13 // Little correction for StEclMake
14 //
15 // Revision 1.5 1999/07/02 03:01:56 pavlinov
16 // Little corrections for Linux
17 //
18 // Revision 1.3 1999/03/03 04:12:15 fisyak
19 // replace kStErr to kStWarn
20 //
21 // Revision 1.2 1999/02/21 21:00:15 pavlinov
22 // Delete one line with debugging print
23 //
24 // Revision 1.1 1999/02/12 19:15:19 akio
25 // *** empty log message ***
26 //
27 // Revision 1.1 1998/12/15 22:39:53 akio
28 // Add emc_hit object and adc_to_energy in here.
29 //
31 // //
32 // StEmcHitCollection class for EMC Calibrated hits //
33 // //
35 #include <Stiostream.h>
36 #include <math.h>
37 #include "StEmcHitCollection.h"
38 #include "St_TableSorter.h"
39 #include "TArrayF.h"
40 #include "TArrayL.h"
41 #include "emc_def.h"
42 ClassImp(StEmcHitCollection)
43 
45  SetTitle("emc_hit");
46  mNHit = 0; mEnergySum = 0.0, mEtSum = 0.0;
47  mModule = 0;
48  mNumsModule.Set(120); mIndexFirstLast.Set(121);
49 }
50 //_____________________________________________________________________________
51 StEmcHitCollection::StEmcHitCollection(const Char_t *Name) : St_DataSet(Name) , StEmcGeom(Name) {
52  //construct with name and detector #
53  SetTitle("emc_hit");
54  mNHit = 0; mEnergySum = 0.0, mEtSum = 0.0;
55  mModule = 0;
56  mNumsModule.Set(120); mIndexFirstLast.Set(121);
57 }
58 //_____________________________________________________________________________
59 StEmcHitCollection::~StEmcHitCollection(){ /* noopt */ }
60 //_____________________________________________________________________________
61 Int_t StEmcHitCollection::ADCtoEnergy(St_emc_hits *emc_hit){
62  //Apply calibration and convert ADC to energy
63  Float_t E;
64  Int_t i; TString name(GetName());
65  Int_t n = emc_hit->GetNRows();
66  emc_hits_st *hit = emc_hit->GetTable();
67  //Getting calibration data
68  TString n_ped_h="emc/new/"+name+"/pedestal/ped_"+name+"_h";
69  TString n_ped ="emc/new/"+name+"/pedestal/ped_"+name;
70  TString n_slp_h="emc/new/"+name+"/gain/slp_"+name+"_h";
71  TString n_slp ="emc/new/"+name+"/gain/slp_"+name;
72 
73  St_DataSetIter local(mEmcCalib);
74  St_emc_calib_header *m_ped_h = (St_emc_calib_header *) local(n_ped_h);
75  St_emc_pedestal *m_ped = (St_emc_pedestal *) local(n_ped);
76  St_emc_calib_header *m_slp_h = (St_emc_calib_header *) local(n_slp_h);
77  St_emc_adcslope *m_slp = (St_emc_adcslope *) local(n_slp);
78  if(m_ped_h && m_ped && m_slp_h && m_slp){
79  emc_calib_header_st *ped_h = m_ped_h->GetTable();
80  emc_pedestal_st *ped = m_ped->GetTable();
81  emc_calib_header_st *slp_h = m_slp_h->GetTable();
82  emc_adcslope_st *slp = m_slp->GetTable();
83  if(ped_h->det != Detector()){
84  cout << "***StEmcHitCollection::ADCtoEnergy: Pedestal data is not for this datector: "
85  << name << endl;
86  return kStWarn;
87  }
88  if(slp_h->det != Detector()){
89  cout << "***StEmcHitCollection::ADCtoEnergy: Gain data is not for this datector: "
90  << name << endl;
91  return kStWarn;
92  }
93  if(ped_h->nmodule != NModule() ||
94  ped_h->neta != NEta() ||
95  ped_h->nsub != NSub() ||
96  slp_h->nmodule != NModule() ||
97  slp_h->neta != NEta() ||
98  slp_h->nsub != NSub() ){
99  cout << "***StEmcHitCollection::ADCtoEnergy: Inconsistent Ped or Gain data: "
100  << name << endl;
101  return kStWarn;
102  }
103 
104  mNHit=0; mEnergySum=0.0; mEtSum =0.0;
105  switch(slp_h->func){
106  case 1:
107 
108  for(i = 0; i<n; i++){
109  Float_t eta, phi; Int_t id,m,e,s;
110  m = (Int_t)hit[i].module;
111  e = (Int_t)hit[i].eta;
112  s = (Int_t)hit[i].sub;
113 
114  if(!getId(m, e, s, id)){ // Check bound of index
115  getEta(m, e, eta); getPhi(m, s, phi);
116 
117  if(hit[i].adc>-1){
118  if(slp[id].p0 > 0.0){
119  Float_t Et = (hit[i].adc-ped[id].ped)/slp[id].p0;
120  E = Et * cosh(eta); // ??
121  if(E<=0.0) E=0.0;
122  else{
123  mEnergy[mNHit]=E; mId[mNHit]=id;
124  mNHit++; mEnergySum+=E; mEtSum+=Et;
125  }
126  } else {
127  cout << "StEmcHitCollection::ADCtoEnergy: Adcslope is less equal 0: "
128  << name << " : " << id <<endl;
129  E = -1.0;
130  }
131  }else{ // if adc<0, use GEANT energy
132  E = hit[i].energy;
133  mEnergy[mNHit]=E; mId[mNHit]=id;
134  mNHit++; mEnergySum+=E; mEtSum+=E/cosh(eta);
135  }
136  } else {
137  cout<<" Bad index m "<<m<<" e "<<e<<" s "<<s<<endl;
138  }
139  }
140  break;
141  default:
142  cout<< "***StEmcHitCollection::ADCtoEnergy: Function has not been implimented yet: "
143  <<name<<" : "<<slp_h->func<<endl;
144  return kStWarn;
145  }
146  }else{
147  cout<< "StEmcHitCollection::ADCtoEnergy: Not enough information, use GEANT energy: "
148  << name << " Nhits " << n << endl;
149  for(i = 0; i<n; i++){
150  if(hit[i].energy>0.0){
151  Float_t eta, phi; Int_t id,m,e,s;
152  m = (Int_t)hit[i].module;
153  e = (Int_t)hit[i].eta;
154  s = (Int_t)hit[i].sub;
155 
156  if(!getId(m, e, s, id)){ // Check bound of index
157  getEta(m, e, eta); getPhi(m, s, phi);
158  E = hit[i].energy;
159  if(E>0.0){
160  mEnergy[mNHit]=E; mId[mNHit]=id;
161  mNHit++; mEnergySum+=E; mEtSum+=E/cosh(eta);
162  }
163  } else {
164  cout<<" Bad index m "<<m<<" e "<<e<<" s "<<s<<endl;
165  }
166  }
167  }
168  }
169  return kStOK;
170 }
171 //_____________________________________________________________________________
172 Int_t StEmcHitCollection::fill(St_emc_hits *emc_hits)
173 {
174  //Fill energy from emc_hit table(ADC).
175  int i;
176 
177  Int_t n=emc_hits->GetNRows();
178  if(n==0) { return kStOK; cout<<" No ADC in "<<GetName()<<endl;}
179 
180  emc_hits_st *hit = emc_hits->GetTable();
181  if(hit[0].det<1 || hit[0].det>MAXDET){
182  cout<< "StEmcHitCollection::Fill: Bad detector# in emc_hits_st : "
183  << hit[0].det<<" "<< GetName() <<endl;
184  return kStWarn;
185  }
186 
187  mId.Set(n); mEnergy.Set(n); // Memory alocation
188  if(ADCtoEnergy(emc_hits ) != kStOK) return kStWarn;
189 
190  // Sort on id
191  TArrayF ecopy=mEnergy;
192  TArrayL idcopy(mNHit);
193  for(i=0; i< mNHit; i++) {idcopy[i] =(Long_t)mId[i];}
194 
195  St_TableSorter sort(idcopy.GetArray(), mNHit);
196  for(i=0; i< mNHit; i++) {
197  Int_t j=sort.GetIndex(i);
198  mId[i] = idcopy[j];
199  mEnergy[i] = ecopy[j];
200  }
201 
202  // To calculate modules boundary => Service information
203  Int_t id, m, e, s, mold;
204  id = HitId(0); // First hit
205  getBin(id, mold, e, s);
206  mNumsModule[0] = (Short_t)mold;
207  mIndexFirstLast[0] = 0;
208  mIndexFirstLast[1] = mNHit;
209  mModule = 1;
210 
211  if(mNHit > 1){
212  for(i=1; i<mNHit; i++){
213  id = HitId(i);
214  getBin(id, m, e, s);
215  if(m != mold){
216  mold = m;
217  mNumsModule[mModule] = (Short_t)mold;
218  mIndexFirstLast[mModule] = i;
219  mIndexFirstLast[mModule+1] = mNHit;
220  ++mModule;
221  }
222  }
223  }
224  // mNumsModule.Set(mModule);
225  //mIndexFirstLast.Set(mModule+1);
226 
227  return kStOK;
228 }
229 //_____________________________________________________________________________
230 St_emc_hits* StEmcHitCollection::copyToTable(const Char_t *Name){
231  //Create a table emc_hits and restore hits.
232  Int_t i, id, m, e, s, n=0;
233  emc_hits_st raw;
234  St_emc_hits *emc_hits = new St_emc_hits((Text_t*)Name, mNHit);
235  for(i=0; i<mNHit; i++){
236  if(mEnergy[i]>0.0){
237  id = (Int_t) mId[i];
238  getBin(id, m, e, s);
239  raw.det = Detector();
240  raw.module = m;
241  raw.eta = e;
242  raw.sub = s;
243  raw.adc = -2;
244  raw.energy = mEnergy[i];
245  emc_hits->AddAt(&raw, n);
246  n++;
247  }
248  }
249  return emc_hits;
250 }
251 //_____________________________________________________________________________
252 void StEmcHitCollection::printHits(Int_t n, Int_t start){
253  //Print hits
254  Int_t i, m, e, s,id;
255  cout << endl << GetName() << " : ";
256  if(mNHit<=0){cout << "No hits" << endl; return;}
257  else{cout << mNHit << " hits" << " Modules "<<mModule<< endl;}
258  cout << "Raw ID Module Eta Sub Energy"<<endl;
259  if(start<0) start=0;
260  if(n<=0) n=1;
261  if(start>=mNHit) start=mNHit-1;
262  if(start+n>=mNHit) n=mNHit-start;
263 
264  int mold=-999999;
265  for(i=start; i<start+n; i++){
266  id = (Int_t) mId[i]; getBin(id, m, e, s);
267  if(i == start) mold=m;
268  if(mold != m) {
269  cout << "-------------------------------"<<endl;
270  mold = m;
271  }
272  cout <<i<<" "<<id<<" "<<m<<" "<<e<<" "<<s<<" "<<mEnergy[i]<<endl;
273  }
274 
275  for(i=0; i<mModule; i++){
276  Int_t jm=mIndexFirstLast[i+1] - mIndexFirstLast[i];
277  cout<<i<<" #Modules "<<mNumsModule[i]<<" jm "<<jm<<
278  " First "<<mIndexFirstLast[i]<<" Last "<<mIndexFirstLast[i+1]-1<<endl;
279  }
280 }
281 //_____________________________________________________________________________
282 void StEmcHitCollection::printHitsAll(){
283  //Print all the hits
284  printHits(mNHit, 0);
285 }
286 //_____________________________________________________________________________
287 void StEmcHitCollection::Browse(TBrowser *b){
288  //Print all the hits
289  printHits(mNHit, 0);
290 }
291 //_____________________________________________________________________________
292 void StEmcHitCollection::printNameTable(){
293  if(mEmcCalib) printf(" mEmcCalib unzero, name %s \n", mEmcCalib->GetName());
294  else printf(" <E> Pointer of mEmcCalib is zero ************** \n");
295 }
void Browse(TBrowser *b)
Browse this dataset (called by TBrowser).
Definition: Stypes.h:42
Definition: Stypes.h:40
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321