HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseNoiseSuppression.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseNoiseSuppression.cxx
3 //
13 #include "HarpoConfig.h"
14 #include "HarpoDetSet.h"
15 //#include "HarpoDetSet.h"
16 #include "HarpoDccHeader.h"
17 #include "HarpoFeminosHeader.h"
18 #include "HarpoDccEvent.h"
19 #include "HarpoEvent.h"
20 #include "Pmm2Event.h"
21 #include "HarpoSimEvent.h"
22 
23 #include "TFile.h"
24 #include "TStyle.h"
25 #include "TCanvas.h"
26 #include "TLatex.h"
27 #include "TGraph.h"
28 #include "TF1.h"
29 #include "TLinearFitter.h"
30 #include "TMath.h"
31 
32 #include <cstdlib>
33 #include <cstring>
34 #include <cassert>
35 #include <fstream>
36 #include <iostream>
37 
39 
40 const int bufsize = 16000;
41 const int splitlevel = 2;
42 const int compress = 6; //default ???
43 
44 
45 
47 {
48 
49 
50  }
51 
53  {
54  unsigned int nd; // number of detectors
56 
57  assert(hdr != NULL);
58  hdr->print();
59 
60  for (nd = 0; nd < gkNDetectors; nd++) {
61  // if (fEvt->isdataExist(nd)) {
62  HarpoDccMap *plane = fEvt->GetDccMap(nd);
63  if (plane != NULL )plane->print();
64  }
65  }
66 
68  {
69  nEvents++;
70  if(nEvents%1000 == 0)
71  std::cout << " Processing Event " << nEvents<< std::endl;
72 
73  if(isZS>3) return;
74 
75  TLinearFitter* fFitCh = new TLinearFitter(1,"pol2","D");
76 
77  // Bool_t noZeroSuppr = kFALSE;
78  for(Int_t ndet=0;ndet<2;ndet++) {
79  if (!gHDetSet->isExist(ndet)){
80  continue;
81  }
82  if(gHarpoDebug>1) Info("process","Processing detector %d", ndet);
83  HarpoDccMap * m = fEvt->GetDccMap(ndet);
84  std::cout << "Event " << nEvents << ", detector " << ndet << " " << m << std::endl;
85  if ( m == NULL ){
86  Warning("process","Event %ld, No Data Map for plane %d", nEvents, ndet);
87  continue;
88  }
89  Int_t Qnoise = 0;
90  for(Int_t i=0;i<NADC;i++){ //Time bins
91  for(Int_t j=NCHAN;j<NALL;j++){ // Channels
92  Double_t q = m->GetRawData(j,i);
93  Qnoise += q;
94  }
95  }
96  // if(!((HarpoDccEvent*)fEvt->GetDetEvent(ndet))->IsZeroSuppressed()){
97  if(Qnoise<NADC*50){
98  //if(gHarpoDebug>2)
99  Info("process","Data ZERO SUPPRESSED (%d)",Qnoise);
100  isZS++;
101  continue;
102  }
103  if(gHarpoDebug>2) Info("process","Data FULL (%d)",Qnoise);
104  for(Int_t i=0;i<NADC;i++){ //Time bins
105  TArrayD* valuesTB = new TArrayD(NALL);
106  for(Int_t j=0;j<NALL;j++){ // Channels
107  Double_t q = m->GetData(j,i);
108  valuesTB->AddAt(q,j);
109  }
110  Double_t noiseTB = TruncMean(valuesTB,0.16,0.84);
111  TGraph* gMinusCh = new TGraph();
112  for(Int_t j=0;j<NALL;j++){ // Channels
113  Double_t q = m->GetData(j,i);
114  q -= noiseTB;
115  m->SetData(j,i,q);
116  gMinusCh->SetPoint(gMinusCh->GetN(),j,q);
117  }
118  fFitCh->AssignData(gMinusCh->GetN(), 1, gMinusCh->GetX(), gMinusCh->GetY());
119  fFitCh->Eval();
120  delete gMinusCh;
121  Double_t mean = 0, rms = 0;
122  Int_t nnoise = 0;
123  for(Int_t j=0;j<NALL;j++){ // Channels
124  Double_t q = m->GetData(j,i);
125  q -= fFitCh->GetParameter(0) + j*fFitCh->GetParameter(1) + j*j*fFitCh->GetParameter(2);
126  m->SetData(j,i,q);
127  if(q<100){
128  mean += q;
129  rms += q*q;
130  nnoise++;
131  }
132  }
133  rms = TMath::Sqrt(rms/nnoise - mean*mean/nnoise/nnoise);
134  for(Int_t j=0;j<NALL;j++){ // Channels
135  Double_t q = m->GetData(j,i);
136  if(gHarpoDebug>4) Info("process","%d %d => %g (%g)",j,i,q,fNoiseCut*rms);
137  if(q>fNoiseCut*rms){
138  m->SetData(j,i,q);
139  }else{
140  m->SetRawData(j,i,-1);
141  }
142  }
143  delete valuesTB;
144  //((HarpoDccEvent*)fEvt->GetDetEvent(ndet))->SetZeroSuppressed(false);
145  //((HarpoDccEvent*)fEvt->GetDetEvent(ndet))->SetZeroSuppressed(false);
146  }
147  }
148  fFitCh->Delete();
149 
150 
151 }
152 
154  {
155 
156 
157  fNoiseCut = 5.;
158  Double_t noiseCut;
159  if ( ! gHConfig->Lookup("NoiseSuppr.NoiseCut",noiseCut) )
160  Info("Constructor","Use default Noise Cut %g",fNoiseCut);
161  else{
162  fNoiseCut = noiseCut;
163  Info("Constructor","Use Noise Cut %g",fNoiseCut);
164  }
165 
166  isZS = 0;
167 
168  }
169 
170 void HarpoAnalyseNoiseSuppression::Save(char * /* mode */ )
171  {
172 
173  }
174 
175 Double_t HarpoAnalyseNoiseSuppression::TruncMean(TArrayD* vect, Double_t tl, Double_t th)
176 {
177  //
178  // Calculates the truncated mean mean of the non zero value in vect
179  // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
180  //
181  // debug(2,"truncated mean");
182 
183 
184  Int_t size = vect->GetSize();
185  Double_t truncMean = 0;
186  Int_t* index = new Int_t[size];
187  TMath::Sort(size,vect->GetArray(),index,kFALSE);
188  Int_t t = 0, tLow, tHigh;
189 
190 
191  // while(vect->At(index[t])<10&&t<size-1) t++;
192  while(vect->At(index[t])==-1000&&t<size-1) t++;
193  tLow = TMath::FloorNint(t + (size - t)*tl);
194  tHigh = TMath::FloorNint(t + (size - t)*th);
195 
196  for(Int_t tind = tLow; tind<tHigh; tind++) truncMean += vect->At(index[tind]);
197  delete[] index;
198  if(tHigh-tLow) {
199  return truncMean/(tHigh-tLow);
200  }
201  else return 0;
202 }
203 
204 
205 
#define NALL
Definition: HarpoDccMap.h:15
const int compress
const int bufsize
const int splitlevel
#define NCHAN
Definition: HarpoDccMap.h:16
Double_t GetRawData(Int_t i, Int_t j)
Definition: HarpoDccMap.cxx:75
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
void SetData(Int_t i, Int_t j, Double_t val)
Int_t isZS
Redefine empty default.
virtual void print()
FullEvent Header not scecific to the detectors The class is ....
virtual void print()
Double_t TruncMean(TArrayD *vect, Double_t tl, Double_t th)
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
Definition: HarpoDccMap.h:29
#define NADC
Definition: HarpoDccMap.h:18
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
Bool_t Lookup(const char *path, Bool_t &val)
Lookup function for scalar values.
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
Suppresses baseline fluctuations in non-zerosuppressed data.
HarpoConfig * gHConfig
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
void SetRawData(Int_t i, Int_t j, Double_t val)
Definition: HarpoDccMap.cxx:94
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
void print()
Overload, method which do all job.