HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseBaselineFluct.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseBaselineFluct.cxx
3 //
13 #include "HarpoConfig.h"
14 #include "HarpoDetSet.h"
15 #include "HarpoDebug.h"
16 #include "HarpoDccEvent.h"
17 #include "HarpoEvent.h"
18 #include "HarpoRecoEvent.h"
19 
20 #include "TFile.h"
21 #include "TStyle.h"
22 #include "TCanvas.h"
23 #include "TLatex.h"
24 #include "TGraph.h"
25 #include "TProfile.h"
26 #include "TF1.h"
27 #include "TMath.h"
28 #include "TSystem.h"
29 
30 #include <cstdlib>
31 #include <cstring>
32 #include <cassert>
33 #include <fstream>
34 #include <iostream>
35 
37 
39  {
40  unsigned int nd; // number of detectors
42 
43  assert(hdr != NULL);
44  hdr->print();
45 
46  for (nd = 0; nd < gkNDetectors; nd++) {
47  // if (fEvt->isdataExist(nd)) {
48  HarpoDccMap *plane = fEvt->GetDccMap(nd);
49  if (plane != NULL )plane->print();
50  }
51  }
52 
54 {
55  // Bool_t drawEvent = kFALSE;
56  nEvents++;
57  // Process Reconstructed data (clusters, tracks, matched tracks)
58  HarpoRecoEvent* reco = fEvt->GetRecoEvent();
59 
60  //std::cout << "PROCESSING RAW DATA" << std::endl;
61  Double_t xStart[2] = {0, 0};
62  Double_t tStart[2] = {0, 0};
63 
64  Int_t nNoiseChan[2];
65  // Process RAW data
66  // Double_t sigQ[NADC][2];
67  for(UInt_t ndet=0;ndet<2;ndet++) {
68  if (!gHDetSet->isExist(ndet)) continue;
69  HarpoDccMap* m = fEvt->GetDccMap(ndet);
70  if ( m == NULL ) continue;
71  // Double_t limNch = 30, limSig = 0.06, limDelta = 5;
72  // Double_t limNch = 30, limSig = 20, limDelta = 5;
73  // Double_t limTruncL = 0.1, limTruncH = 0.7;
74  Double_t meanNoise = 0, qNoise = 0;
75  Int_t nChan = 0;
76  TH2F* hNoise = new TH2F("hNoise","",511,0,511,4096,-300,3796);
77  TH2F* hNoiseTot = new TH2F("hNoiseTot","",511,0,511,1000,-3000,1e5);
78  TH2F* hSignal = new TH2F("hSignal","",511,0,511,4096,-300,3796);
79  Double_t xNoiseMin = 511, xNoiseMax = 1, qNoiseMax = 1;
80  nNoiseChan[ndet] = 0;
81  Double_t qStart = 0;
82  Int_t nbinsStart = 0;
83  for(Int_t i=0;i<NADC;i++){ //Time bins
84 
85  Double_t qTot = 0;
86  Double_t sigmaQ = 0;
87  TArrayD* arr = new TArrayD(NCHAN);
88  for(Int_t j=0;j<NCHAN;j++){ // Channels
89  Double_t q = m->GetRawData(j,i);
90  //if(q<400) m->SetRawData(j,i,-1); // FIXME
91  //continue; // FIXME
92  if(q < 0) continue; // NO DATA
93  arr->AddAt(q,j);
94  qTot += q;
95  sigmaQ += q*q;
96  nChan++;
97 
98  if(nbinsStart<4){
99  xStart[ndet] += j*q;
100  tStart[ndet] += i*q;
101  qStart += q;
102  }
103  }
104  if(qTot>0) nbinsStart++;
105 
106  // Calculate truncated mean and sigma for that time bin
107  Double_t truncSig = 0, truncMean = 0;
108  TruncSigma(arr,truncSig,truncMean,fLimTruncL,fLimTruncH);
109  delete arr;
110 
111  if(truncMean){
112  hSigma2[ndet]->Fill(truncSig/truncMean);
113  }
114 
115  Double_t qNoiseT = 0;
116  if(truncSig){
117  // Info("process","truncSig/truncMean = %f/%f = %f", truncSig, truncMean, truncSig/truncMean);
118  if(nChan>fLimNch && truncSig<fLimSig) nNoiseChan[ndet]++;
119  hSigma[ndet]->Fill(truncSig);
120  for(Int_t j=0;j<NCHAN;j++){ // Channels
121  Double_t q = m->GetRawData(j,i);
122  Double_t q2 = m->GetData(j,i);
123  if( q < 0 ) continue; // NO DATA
124  hSigmaVsMean[ndet]->Fill(truncSig,TMath::Abs(q-truncMean)/truncSig);
125  // if(nChan>fLimNch && truncSig/truncMean<fLimSig && TMath::Abs(q-truncMean)<fLimDelta*truncSig){
126  if(nChan>fLimNch && truncSig<fLimSig && TMath::Abs(q-truncMean)<fLimDelta*truncSig){
127  hSigmaVsMeanCut[ndet]->Fill(truncSig,TMath::Abs(q-truncMean)/truncSig);
128  meanNoise += i*q2;
129  qNoise += q2;
130  qNoiseT += q2;
131  //Info("process","%g",q);
132  hNoise->Fill(i,q2);
133  if(xNoiseMin>i) xNoiseMin = i;
134  if(xNoiseMax<i) xNoiseMax = i;
135  if(qNoiseMax<q2) qNoiseMax = q2;
136  q = 0;
137  // Info("process","Remove pixel %d %d",j,i);
138  m->SetRawData(j,i,-1);
139  }else{
140  hSignal->Fill(i,q2);
141  }
142  }
143  hNoiseTot->Fill(i,qNoiseT);
144  }
145 
146 
147  }
148 
149  if(qStart>0){
150  xStart[ndet] /= qStart;
151  tStart[ndet] /= qStart;
152  }
153 
154  // if(nNoiseChan[ndet] > 4){
155  if(qNoise > 250){
156  TProfile* pNoise = hNoise->ProfileX(Form("pNoise%d",ndet));
157 
158  Double_t mean = 0, qTot = 0;
159  Int_t binmax = pNoise->GetMaximumBin();
160  for(Int_t bin = binmax-2; bin<binmax+3; bin++){
161  Double_t q = pNoise->GetBinContent(bin);
162  mean += bin*q;
163  qTot += q;
164  }
165  pNoise->Delete();
166 
167  Double_t qSignal = 0;
168  if(qTot>0){
169  for(Int_t i = 0; i<511;i++){
170  Double_t qSigTot = 0, qSigMax = 0;
171  for(Int_t j = 0; j<4096; j++){
172  hNoiseShape[ndet]->Fill(i-mean/qTot,hNoise->GetYaxis()->GetBinCenter(j+1),hNoise->GetBinContent(i+1,j+1));
173  hNoiseShapeTot[ndet]->Fill(i-mean/qTot,hNoiseTot->GetYaxis()->GetBinCenter(j+1),hNoiseTot->GetBinContent(i+1,j+1));
174  hNoiseShapeNorm[ndet]->Fill(i-mean/qTot,hNoise->GetYaxis()->GetBinCenter(j+1)/TMath::Abs(qTot),hNoise->GetBinContent(i+1,j+1));
175  // hSignalShape[ndet]->Fill(i-mean/qTot,hNoise->GetYaxis()->GetBinCenter(j+1),hSignal->GetBinContent(i+1,j+1));
176  Double_t qSig = hNoise->GetYaxis()->GetBinCenter(j+1);
177  qSigTot += qSig*hSignal->GetBinContent(i+1,j+1);
178  if(qSig>qSigMax && hSignal->GetBinContent(i+1,j+1)>0) qSigMax = qSig;
179  }
180  hSignalShape[ndet]->Fill(i-mean/qTot,qSigTot*0.01);
181  hSignalShape2[ndet]->Fill(i-mean/qTot,qSigMax*0.5);
182  if(TMath::Abs(i-mean/qTot+13)<10) qSignal += qSigTot;
183  }
184  }
185  hSignalVsNoise[ndet]->Fill(qNoise,qSignal);
186  }
187 
188  hNoise->Delete();
189  hNoiseTot->Delete();
190  hSignal->Delete();
191 
192 
193  for(Int_t j=0;j<NCHAN;j++){ // Channels
194  Int_t nPix = 0;
195  for(Int_t i=0;i<NADC;i++){ //Time bins
196  Double_t q = m->GetRawData(j,i);
197  if(q < 0 && nPix == 0) continue;
198  if(q < 0){
199  if(nPix<10){
200  if(gHarpoDebug>1)
201  Info("process","Remove small cluster on channel %d, t = %d",j,i);
202  for(Int_t iTmp = i - nPix; iTmp<i; iTmp++)
203  m->SetRawData(j,iTmp,-1);
204  }
205  nPix = 0;
206  }else nPix++;
207  }
208  }
209  }
210 
211  reco->SetXstart(xStart[0]);
212  reco->SetYstart(xStart[1]);
213  reco->SetTstart(0.5*(tStart[0]+tStart[1]));
214 
215  if(nEvents%100 == 0)
216  std::cout << "Event " << nEvents << " done" << std::endl;
217 }
218 
220  {
221 
222  fLimNch = 30;
223  fLimSig = 20;
224  fLimDelta = 5;
225  fLimTruncL = 0.1;
226  fLimTruncH = 0.7;
227 
228  const Int_t nbinsQ = 100;
229  Double_t xminQ = 250;
230  Double_t xmaxQ = 1e7;
231  Double_t logxminQ = TMath::Log(xminQ);
232  Double_t logxmaxQ = TMath::Log(xmaxQ);
233  Double_t binwidthQ = (logxmaxQ-logxminQ)/nbinsQ;
234  Double_t xbinsQ[nbinsQ+1];
235  xbinsQ[0] = xminQ;
236  for (Int_t i=1;i<=nbinsQ;i++)
237  xbinsQ[i] = TMath::Exp(logxminQ+i*binwidthQ);
238  hSignalVsNoise[0] = new TH2F("hSignalVsNoiseX",";Q_{noise} [ADC];Q_{signal} [ADC]",nbinsQ,xbinsQ,nbinsQ,xbinsQ);
239  hSignalVsNoise[1] = new TH2F("hSignalVsNoiseY",";Q_{noise} [ADC];Q_{signal} [ADC]",nbinsQ,xbinsQ,nbinsQ,xbinsQ);
240 
241  hNoiseShape[0] = new TH2F("hNoiseShapeX",";t-t_{noise} [30ns];q [ADCch]",1000,-250,250,4096,-300,3796);
242  hNoiseShape[1] = new TH2F("hNoiseShapeY",";t-t_{noise} [30ns];q [ADCch]",1000,-250,250,4096,-300,3796);
243  hNoiseShapeTot[0] = new TH2F("hNoiseShapeTotX",";t-t_{noise} [30ns];q [ADCch]",1000,-250,250,1000,-3000,1e5);
244  hNoiseShapeTot[1] = new TH2F("hNoiseShapeTotY",";t-t_{noise} [30ns];q [ADCch]",1000,-250,250,1000,-3000,1e5);
245  hNoiseShapeNorm[0] = new TH2F("hNoiseShapeNormX",";t-t_{noise} [30ns];q_{norm}",1000,-250,250,500,-1,1);
246  hNoiseShapeNorm[1] = new TH2F("hNoiseShapeNormY",";t-t_{noise} [30ns];q_{norm}",1000,-250,250,500,-1,1);
247  hSignalShape[0] = new TH2F("hSignalShapeX",";t-t_{noise} [30ns];q_{tot} [ADCch]",1000,-250,250,4096,-300,3796);
248  hSignalShape[1] = new TH2F("hSignalShapeY",";t-t_{noise} [30ns];q_{tot} [ADCch]",1000,-250,250,4096,-300,3796);
249  hSignalShape2[0] = new TH2F("hSignalShape2X",";t-t_{noise} [30ns];q_{max} [ADCch]",1000,-250,250,4096,-300,3796);
250  hSignalShape2[1] = new TH2F("hSignalShape2Y",";t-t_{noise} [30ns];q_{max} [ADCch]",1000,-250,250,4096,-300,3796);
251 
252  hSigma[0] = new TH1F("hSigmaX",";#sigma_{trunc}",500,0,200);
253  hSigma[1] = new TH1F("hSigmaY",";#sigma_{trunc}",500,0,200);
254  hSigmaVsMean[0] = new TH2F("hSigmaVsMeanX",";#sigma_{trunc};(q-#mu_{trunc})/#sigma_{trunc}",500,0,200,500,0,50);
255  hSigmaVsMean[1] = new TH2F("hSigmaVsMeanY",";#sigma_{trunc};(q-#mu_{trunc})/#sigma_{trunc}",500,0,200,500,0,50);
256  hSigmaVsMeanCut[0] = new TH2F("hSigmaVsMeanCutX",";#sigma_{trunc};(q-#mu_{trunc})/#sigma_{trunc}",500,0,200,500,0,50);
257  hSigmaVsMeanCut[1] = new TH2F("hSigmaVsMeanCutY",";#sigma_{trunc};(q-#mu_{trunc})/#sigma_{trunc}",500,0,200,500,0,50);
258  hSigmaVsTruncH[0] = new TH2F("hSigmaVsTruncHX",";#sigma_{trunc};truncH",500,0,200,20,0,100);
259  hSigmaVsTruncH[1] = new TH2F("hSigmaVsTruncHY",";#sigma_{trunc};truncH",500,0,200,20,0,100);
260  hSigma2[0] = new TH1F("hSigma2X",";#sigma_{trunc}/#mu_{trunc}",500,0,5);
261  hSigma2[1] = new TH1F("hSigma2Y",";#sigma_{trunc}/#mu_{trunc}",500,0,5);
262 
263  }
264 
265 void HarpoAnalyseBaselineFluct::Save(char * /* mode */)
266 {
267 
268  OpenHistFile("baseline");
269 
270 
271  // Save Run header (contains all DB info about the run)
272  // if(fRunHeader != NULL)
273  // fRunHeader->Write("fRunHeader");
274  hSigma[0]->Write();
275  hSigma[1]->Write();
276  hSigmaVsMean[0]->Write();
277  hSigmaVsMean[1]->Write();
278  hSigmaVsMeanCut[0]->Write();
279  hSigmaVsMeanCut[1]->Write();
280  hSigma2[0]->Write();
281  hSigma2[1]->Write();
282 
283  hNoiseShape[0]->Write();
284  hNoiseShape[1]->Write();
285  hNoiseShapeTot[0]->Write();
286  hNoiseShapeTot[1]->Write();
287  hNoiseShapeNorm[0]->Write();
288  hNoiseShapeNorm[1]->Write();
289  hSignalShape[0]->Write();
290  hSignalShape[1]->Write();
291  hSignalShape2[0]->Write();
292  hSignalShape2[1]->Write();
293 
294  hSigmaVsTruncH[0]->Write();
295  hSigmaVsTruncH[1]->Write();
296 
297  hSignalVsNoise[0]->Write();
298  hSignalVsNoise[1]->Write();
299 
300 }
301 
302 
303 
304 Double_t HarpoAnalyseBaselineFluct::TruncSigma(TArrayD* vect, Double_t &truncS, Double_t &truncM, Double_t tl, Double_t th)
305 {
306  //
307  // Calculates the truncated mean mean of the non zero value in vect
308  // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
309  //
310  // debug(2,"truncated mean");
311 
312 
313  Int_t size = vect->GetSize();
314  // Info("TruncSigma","size = %d",size);
315  Double_t truncMean = 0;
316  Double_t truncSigma = 0;
317  Int_t* index = new Int_t[size];
318  TMath::Sort(size,vect->GetArray(),index,kFALSE);
319  Int_t t = 0, tLow, tHigh;
320 
321 
322  while(vect->At(index[t])<10&&t<size-1) t++;
323  tLow = TMath::FloorNint(t + (size - t)*tl);
324  tHigh = TMath::FloorNint(t + (size - t)*th);
325 
326  for(Int_t tind = tLow; tind<tHigh; tind++){
327  truncMean += vect->At(index[tind]);
328  truncSigma += vect->At(index[tind])*vect->At(index[tind]);
329  }
330 
331  delete[] index;
332 
333  // if(tHigh-tLow == 0) return 0;
334  if(tHigh-tLow < 15) return 0;
335 
336  truncMean /= (tHigh-tLow);
337  truncSigma /= (tHigh-tLow);
338  truncSigma -= truncMean*truncMean;
339 
340  truncM = truncMean;
341  truncS = TMath::Sqrt(truncSigma);
342 
343  return truncSigma;
344 }
HarpoRecoEvent * GetRecoEvent()
Definition: HarpoEvent.h:46
#define NCHAN
Definition: HarpoDccMap.h:16
Double_t GetRawData(Int_t i, Int_t j)
Definition: HarpoDccMap.cxx:75
Analysis and suppression of baseline fluctuations.
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
Object containing the reconstruction information for one event (with array of HarpoRecoClusters Harpo...
Double_t TruncSigma(TArrayD *vect, Double_t &truncS, Double_t &truncM, Double_t tl, Double_t th)
virtual void print()
FullEvent Header not scecific to the detectors The class is ....
virtual void print()
TFile * OpenHistFile(const char *ananame)
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
void print()
Ovreloaded medod whic do all job.
void SetTstart(Double_t val)
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
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
void SetYstart(Double_t val)
void SetRawData(Int_t i, Int_t j, Double_t val)
Definition: HarpoDccMap.cxx:94
void SetXstart(Double_t val)
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71