HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseMatching.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseMatching.cxx
3 //
11 #include "HarpoAnalyseMatching.h"
12 #include "HarpoConfig.h"
13 #include "HarpoDetSet.h"
14 #include "HarpoDebug.h"
15 #include "HarpoDccEvent.h"
16 #include "Pmm2Event.h"
17 #include "HarpoEvent.h"
18 #include "HarpoRecoEvent.h"
19 #include "HarpoSimEvent.h"
20 
21 #include "TFile.h"
22 #include "TStyle.h"
23 #include "TCanvas.h"
24 #include "TLatex.h"
25 #include "TGraph.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 
36 ClassImp(HarpoAnalyseMatching);
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  if(nEvents%500==0)
58  Info("process","%ld events",nEvents);
59 
60  // Process RAW data
61  if (!gHDetSet->isExist(XDCC)) return;
62  if (!gHDetSet->isExist(YDCC)) return;
65  if ( mX == NULL ) return;
66  if ( mY== NULL ) return;
67 
68 
69 
70  Double_t QchXmax = 0, QchYmax = 0;
71  // Int_t satX[NCHAN], satY[NCHAN];
72  Int_t nSatTX[NADC], nSatTY[NADC];
73  for(Int_t i=0;i<NADC;i++){ // Time bins
74  nSatTX[i] = 0;
75  nSatTY[i] = 0;
76  }
77  Int_t nSatX = 0, nSatY = 0, nChX = 0, nChY = 0;
78  for(Int_t j=0;j<NCHAN;j++){ // Channels
79  Double_t qchX = 0, qchY = 0;
80  for(Int_t i=0;i<NADC;i++){ // Time bins
81  Double_t qX = mX->GetData(j,i);
82  if(qX > -1000)
83  qchX += qX;
84  Double_t qY = mY->GetData(j,i);
85  if(qY > -1000)
86  qchY += qY;
87  if(qchX>fLimSat)
88  nSatTX[i]++;
89  if(qchY>fLimSat)
90  nSatTY[i]++;
91  }
92  if(qchX>QchXmax) QchXmax = qchX;
93  if(qchY>QchYmax) QchYmax = qchY;
94 
95  hQch->Fill(qchX,qchY);
96 
97  if(qchX>fLimSat){
98  // satX[j] = 1;
99  nSatX++;
100  }// else satX[j] = 0;
101  if(qchY>fLimSat){
102  // satY[j] = 1;
103  nSatY++;
104  }// else satY[j] = 0;
105 
106  if(qchX) nChX++;
107  if(qchY) nChY++;
108 
109 
110  }
111 
112  // std::cout << nSatX << " " << nSatY << " " << hNsat << std::endl;
113  hNsat->Fill(nSatX,nSatY);
114 
115  for(Int_t i=0;i<NADC;i++){ // Time bins
116  if(!(nSatTX[i]==0 && nSatTY[i]==0))
117  hNsat2->Fill(nSatTX[i],nSatTY[i]);
118  }
119 
120  Double_t qXtot = 0, qYtot = 0;
121  Double_t qxtot[NCHAN];
122  Int_t xstart[NCHAN];
123  for(Int_t j=0;j<NCHAN;j++){
124  qxtot[j] = 0;
125  xstart[j] = 0;
126  }
127  Int_t n = 0;
128  Double_t meanRatio = 0, sigmaRatio = 0;
129  TArrayD* arrRatio = new TArrayD(NADC);
130  for(Int_t i=0;i<NADC;i++){ // Time bins
131  arrRatio->AddAt(-1,i);
132  Double_t qXch = 0, qYch = 0;
133  for(Int_t j=0;j<NCHAN;j++){ // Channels
134  Double_t qX = mX->GetData(j,i);
135  Double_t qY = mY->GetData(j,i);
136  if(qX > -1000){
137  qXch += qX;
138  qxtot[j] += qX;
139  xstart[j] = 1;
140  }else{
141  if(xstart[j] == 1)
142  xstart[j] = 2;
143  }
144  if(qY > -1000) qYch += qY;
145  }
146  qXtot += qXch;
147  qYtot += qYch;
148 
149  if(qYch>0 && nSatTX[i] <=1 && nSatTY[i] == 0){
150  for(Int_t j=0;j<NCHAN;j++){
151  Double_t qcorr = qYtot + qXtot - qxtot[j];
152  // for(Int_t j2=0;j2<NCHAN;j2++){
153  // if(j2 != j) qcorr -= qxtot[j2];
154  // }
155  // if(mX->GetData(j,i)>-100 && qYch>0 && nSatX <=1)
156  if(xstart[j] != 2){
157  hQxVsQyLog->Fill(qcorr,qxtot[j]);
158  hQxVsQy->Fill(qcorr,qxtot[j]);
159  }
160  }
161  }
162 
163  if(nSatX<5 && nSatY<5 && (qXch>0 || qYch>0)){
164  // std::cout << i << " " << nSatX << ", " << nSatY << " => " << qXtot << ", " << qYtot << std::endl;
165  hSaturation[nSatX][nSatY]->Fill(qXtot,qYtot);
166  }
167 
168  if(nSatTX[i]<5 && nSatTY[i]<5 && (qXch>0 || qYch>0)){
169  // std::cout << i << " " << nSatX << ", " << nSatY << " => " << qXtot << ", " << qYtot << std::endl;
170  hSaturation2[nSatTX[i]][nSatTY[i]]->Fill(qXtot,qYtot);
171  }
172 
173  if(qXch <= 0) continue;
174  Double_t ratio = qYch/qXch/0.92;
175  hRatio->Fill(ratio);
176 
177  if(ratio>0)
178  // hRatioVsZ->Fill(i,TMath::Log(ratio));
179  // hRatioVsNchX->Fill(nChX,TMath::Log(ratio));
180  // hRatioVsNchY->Fill(nChY,TMath::Log(ratio));
181 
182  ratio = TMath::Log(ratio);
183  hRatioVsZ->Fill(i,ratio);
184  hRatioVsNchX->Fill(nChX,ratio);
185  hRatioVsNchY->Fill(nChY,ratio);
186 
187  meanRatio += ratio;
188  sigmaRatio += ratio*ratio;
189  arrRatio->AddAt(ratio,i);
190  n++;
191 
192 
193  }
194 
195 
196  if(n){
197  meanRatio /= n;
198  sigmaRatio /= n;
199  sigmaRatio -= meanRatio*meanRatio;
200  hMeanVsSigmaRatio->Fill(TMath::Sqrt(sigmaRatio),meanRatio);
201  //if(meanRatio>0)
202  // hMeanVsSigmaRatio->Fill(TMath::Sqrt(sigmaRatio),TMath::Log(meanRatio));
203  }
204  Double_t truncM, truncS;
205  TruncMean(arrRatio, truncS, truncM, 0.1, 0.9);
206  delete arrRatio;
207  if(truncM>0)
208  hTruncMeanVsSigmaRatio->Fill(truncS,truncM);
209  // hTruncMeanVsSigmaRatio->Fill(truncS,TMath::Log(truncM));
210 
211  if(qXtot){
212  hTest->Fill(QchXmax,QchYmax);
213  hRatioTot->Fill(n,TMath::Log(qYtot/qXtot));
214  if(QchXmax>fLimSat || QchYmax>fLimSat)
215  hRatioTotCut1->Fill(n,TMath::Log(qYtot/qXtot));
216  else
217  hRatioTotCut2->Fill(n,TMath::Log(qYtot/qXtot));
218  }
219 }
220 
222 {
223 
224  fLimSat = 5e4;
225 
226 
227  // Initialise histograms here
228  hRatioVsZ = new TH2F("hRatioVsZ",";Z",512,0,512,200,-5,5);
229  hRatioVsNchX = new TH2F("hRatioVsNchX",";N_{chX}",288,0,288,200,-5,5);
230  hRatioVsNchY = new TH2F("hRatioVsNchY",";N_{chY}",288,0,288,200,-5,5);
231  hMeanVsSigmaRatio = new TH2F("hMeanVsSigmaRatio","",200,0,5,200,-5,5);
232  hTruncMeanVsSigmaRatio = new TH2F("hTruncMeanVsSigmaRatio","",200,0,5,200,-5,5);
233  hRatioTot = new TH2F("hRatioTot","",512,0,512,2000,-5.,5.);
234  hRatioTotCut1 = new TH2F("hRatioTotCut1","",512,0,512,2000,-5.,5.);
235  hRatioTotCut2 = new TH2F("hRatioTotCut2","",512,0,512,2000,-5.,5.);
236  hTest = new TH2F("hTest","",2,0,2*fLimSat,2,0,2*fLimSat);
237 
238 
239  const Int_t nbinsQcl = 1000;
240  Double_t xminQcl = 10;
241  Double_t xmaxQcl = 1e6;
242  Double_t logxminQcl = TMath::Log(xminQcl);
243  Double_t logxmaxQcl = TMath::Log(xmaxQcl);
244  Double_t binwidthQcl = (logxmaxQcl-logxminQcl)/nbinsQcl;
245  Double_t xbinsQcl[nbinsQcl+1];
246  xbinsQcl[0] = xminQcl;
247  for (Int_t i=1;i<=nbinsQcl;i++)
248  xbinsQcl[i] = TMath::Exp(logxminQcl+i*binwidthQcl);
249  hQch = new TH2F("hQch",";Q_{ch X};Q_{ch Y}",nbinsQcl,xbinsQcl,nbinsQcl,xbinsQcl);
250  for(Int_t i = 0; i<5; i++){
251  for(Int_t j = 0; j<5; j++){
252  hSaturation[i][j] = new TH2F(Form("hSaturation%d_%d",i,j),";Q_{X};Q_{Y}",nbinsQcl,xbinsQcl,nbinsQcl,xbinsQcl);
253  hSaturation2[i][j] = new TH2F(Form("hSaturation2%d_%d",i,j),";Q_{X};Q_{Y}",nbinsQcl,xbinsQcl,nbinsQcl,xbinsQcl);
254  }
255  }
256  hQxVsQyLogLog = new TH2F("hQxVsQyLog",";Q_{X};Q_{Y}",nbinsQcl,xbinsQcl,nbinsQcl,xbinsQcl);
257  hQxVsQyLog = new TH2F("hQxVsQyLog",";Q_{X};Q_{Y}",10000,0,1e6,nbinsQcl,xbinsQcl);
258  hQxVsQy = new TH2F("hQxVsQy",";Q_{X};Q_{Y}",2000,0,1e6,1000,0,1e5);
259 
260  hNsat = new TH2F("hNsat",";N_{satX};N_{satY}",10,0,10,10,0,10);
261  hNsat2 = new TH2F("hNsat2",";N_{satX};N_{satY}",10,0,10,10,0,10);
262 
263 
264 
265  hRatio = new TH1F("hRatio",";Q_{x}/Q_{y}",1000,0.5,1.5);
266 
267 }
268 
269 void HarpoAnalyseMatching::Save(char * /* mode */)
270  {
271 
272  /* TFile* hf = */ OpenHistFile("matching");
273  // Save histograms here
274  hRatioVsZ->Write();
275  hRatioVsNchX->Write();
276  hRatioVsNchY->Write();
277  hMeanVsSigmaRatio->Write();
278  hTruncMeanVsSigmaRatio->Write();
279  hRatioTot->Write();
280  hRatioTotCut1->Write();
281  hRatioTotCut2->Write();
282  hTest->Write();
283  hQxVsQyLogLog->Write();
284  hQxVsQyLog->Write();
285  hQxVsQy->Write();
286 
287 
288  hQch->Write();
289  for(Int_t i = 0; i<5; i++){
290  for(Int_t j = 0; j<5; j++){
291  hSaturation[i][j]->Write();
292  }
293  }
294  for(Int_t i = 0; i<5; i++){
295  for(Int_t j = 0; j<5; j++){
296  hSaturation2[i][j]->Write();
297  }
298  }
299  hNsat->Write();
300  hNsat2->Write();
301 
302  hRatio->Write();
303 
304  }
305 
306 
307 
308 
309 Double_t HarpoAnalyseMatching::TruncMean(TArrayD* vect, Double_t &truncS, Double_t &truncM, Double_t tl, Double_t th)
310 {
311  //
312  // Calculates the truncated mean mean of the non zero value in vect
313  // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
314  //
315  // debug(2,"truncated mean");
316 
317 
318  Int_t size = vect->GetSize();
319  // Info("TruncSigma","size = %d",size);
320  Double_t truncMean = 0;
321  Double_t truncSigma = 0;
322  Int_t* index = new Int_t[size];
323  TMath::Sort(size,vect->GetArray(),index,kFALSE);
324  Int_t t = 0, tLow, tHigh;
325 
326 
327  while(vect->At(index[t])<0&&t<size-1) t++;
328  tLow = TMath::FloorNint(t + (size - t)*tl);
329  tHigh = TMath::FloorNint(t + (size - t)*th);
330 
331  for(Int_t tind = tLow; tind<tHigh; tind++){
332  truncMean += vect->At(index[tind]);
333  truncSigma += vect->At(index[tind])*vect->At(index[tind]);
334  }
335 
336  delete[] index;
337 
338  //Info("TruncMean","%d %d (%d) => %g %g",tLow,tHigh,tHigh-tLow,truncMean,truncSigma);
339  // if(tHigh-tLow == 0) return 0;
340  if(tHigh-tLow < 15) return 0;
341 
342  truncMean /= (tHigh-tLow);
343  truncSigma /= (tHigh-tLow);
344  truncSigma -= truncMean*truncMean;
345 
346  truncM = truncMean;
347  truncS = TMath::Sqrt(truncSigma);
348 
349  return truncSigma;
350 }
#define NCHAN
Definition: HarpoDccMap.h:16
TH1F * hRatio
Redefine empty default.
Double_t TruncMean(TArrayD *vect, Double_t &truncS, Double_t &truncM, Double_t tl, Double_t th)
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
Dcc Plane X.
Definition: HarpoDet.h:19
virtual void print()
FullEvent Header not scecific to the detectors The class is ....
virtual void print()
TFile * OpenHistFile(const char *ananame)
Dummy analysis to run as test and example. Give basic histograms of the data.
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
void print()
Overloaded method which do all job.
#define NADC
Definition: HarpoDccMap.h:18
Unknown Detector.
Definition: HarpoDet.h:18
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
void Save(char *mode=NULL)
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71