HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseRates.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseRates.cxx
3 //
11 #include "HarpoAnalyseRates.h"
12 #include "HarpoConfig.h"
13 #include "HarpoDetSet.h"
14 #include "HarpoDebug.h"
15 #include "HarpoDccEvent.h"
16 #include "Pmm2Event.h"
17 #include "Pmm2Header.h"
18 #include "HarpoEvent.h"
19 #include "HarpoRecoEvent.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 "TRandom.h"
29 #include "TSystem.h"
30 
31 #include <cstdlib>
32 #include <cstring>
33 #include <cassert>
34 #include <fstream>
35 #include <iostream>
36 
37 ClassImp(HarpoAnalyseRates);
38 
40  {
41  unsigned int nd; // number of detectors
43 
44  assert(hdr != NULL);
45  hdr->print();
46 
47  for (nd = 0; nd < gkNDetectors; nd++) {
48  // if (fEvt->isdataExist(nd)) {
49  HarpoDccMap *plane = fEvt->GetDccMap(nd);
50  if (plane != NULL )plane->print();
51  }
52  }
53 
55 {
56  // Bool_t drawEvent = kFALSE;
57  nEvents++;
58 
59  if(!gHDetSet->isExist(PMM2))
60  return;
61 
62  if(nEvents%10000 == 0)
63  Info("process","Event %ld", nEvents);
64 
65  Pmm2Event *anaEvt = static_cast<Pmm2Event *>(fEvt->GetDetEvent(PMM2));
66 
67  Double_t timestamp = fEvt->GetTimeStamp();
68  if(!timestamp) timestamp = 10*anaEvt->GetTimeStamp();
69  if(timestamp==0)
70  return;
71  // Info("process","TS %g", timestamp);
72 
73  if(fInit == kFALSE){
74  fInit = kTRUE;
75 
76  fTimeStart = timestamp;
77 
79  fTriggerTimeTot = 0;
80  for(Int_t i = 0; i<kNtriggerTypes; i++){
81  fTriggerTime[i] = 0;
82  fTriggerDownscaling[i] = 1;
83  if(pmm2Hdr == NULL) continue;
84  Pmm2Status* pmm2Stat = pmm2Hdr->getStatus();
85  if(pmm2Stat == NULL) continue;
86  unsigned int triggerinfo = pmm2Stat->getTrigger(i); // 32bits:
87  fTriggerTime[i] = triggerinfo/65536;
88  fTriggerDownscaling[i] = triggerinfo%65536;
89  }
90  for(Int_t i = 0; i<kNtriggerTypes; i++)
92  Info("Init","TriggerTimeTot = %d", fTriggerTimeTot);
93  for(Int_t i = 0; i<kNtriggerTypes; i++){
94  Double_t trigCorr = 1.;
95  if(fTriggerTime[i])
96  trigCorr /= fTriggerTime[i]*1./fTriggerTimeTot;
97  if(fTriggerDownscaling[i])
98  trigCorr *= fTriggerDownscaling[i];
99  hTriggerCorrection->SetBinContent(i+3,trigCorr);
100  Info("Init","Trigger param %d %d => %g",fTriggerTime[i],fTriggerDownscaling[i],trigCorr);
101  }
102  hTriggerCorrection->SetBinContent(1,1);
103  hTriggerCorrection->SetBinContent(2,1);
104  hTriggerCorrection->SetBinContent(3,1);
105  hCycle = new TH2F("hCycle",";t;trigger",fTriggerTimeTot,0,fTriggerTimeTot*100000,20,-2,18);
106  hCycleNew = new TH2F("hCycleNew",";t;trigger",fTriggerTimeTot,0,fTriggerTimeTot*100000,20,-2,18);
107  //hTlowhigh = new TH2F("hTlowhigh",";t_{low};t_{high}",fTriggerTimeTot,0,fTriggerTimeTot*100000,fTriggerTimeTot,0,fTriggerTimeTot*100000);
108  for(Int_t i = 0; i<kNtriggerTypes; i++){
109  fTlow[i] = fTriggerTimeTot*100000;
110  fThigh[i] = 0;
111  }
112  }
113 
114  //timestamp -= fTimeStart;
115 
116 
117 
118  Int_t triggerType = -1;
119 
120  // Pmm2Event *anaEvt = static_cast<Pmm2Event *>(fEvt->GetDetEvent(PMM2));
121  triggerType = anaEvt->GetTriggerType(); // Trigger line (with mesh, without, traversing tracks, ...)
122 
123  int imes;
124  int esize = anaEvt->GetHeader()->eventSize; // number of PMs hit
125  Pmm2MesVect * pm = anaEvt->GetMesurements(); // data for each included PM
126  for(imes=0;imes<esize;imes++) {
127  // int tsPm = pm->at(imes).getTimeStamp(); // charge
128  Double_t tsPm = pm->at(imes).getTimeStamp() + 16777216*Double_t(pm->at(imes).getPPS());
129  hTimestampPmm2->Fill(Double_t(tsPm)*10. - Double_t(timestamp+fTimeStart));
130  //Info("process","%d - %d/10 = %g",Int_t(tsPm),Int_t(timestamp),Double_t(tsPm) - Double_t(timestamp)/10.);
131  }
132 
133  hCycle->Fill(fmod(timestamp,fTriggerTimeTot*100000.),triggerType);
134 
135  // if(triggerType == -1)
136  // Info("process","Unknown trigger %d %d",triggerType,fTriggerOld);
137  // if(triggerType != fTriggerOld && fTriggerOld != -1){
138  if(triggerType == -1){
139  Int_t tLow = fTlow[fTriggerOld];
140  // Int_t iMax = fTriggerOld - 8;
141  // if(iMax<0) iMax += kNtriggerTypes;
142  // for(Int_t i = 0; i<=iMax; i++){
143  // tLow += fTriggerTime[i+8]*100000;
144  // if(tLow>fTriggerTimeTot*100000) tLow -= fTriggerTimeTot*100000;
145  // }
146  //Info("process","Unknown trigger => correction %.3g %.3g %.3g",fmod(timestamp,fTriggerTimeTot*100000.)*1.,tLow*1.,fmod(timestamp,fTriggerTimeTot*100000.)*1./tLow);
147  if(fmod(timestamp,fTriggerTimeTot*100000.) < tLow){
148  triggerType = fTriggerOld;
150  }
151  for(Int_t i = 0; i<kNtriggerTypes; i++){
152  if(fmod(timestamp,fTriggerTimeTot*100000.) > fTlow[i] && fmod(timestamp,fTriggerTimeTot*100000.) < fThigh[i]){
153  triggerType = i;
154  hChangeTrigger->Fill(i);
155  }
156  }
157  }
158  // }else{
159 
160  if( (triggerType-fTriggerOld)==1 || (triggerType-fTriggerOld)==kNtriggerTypes-1){
161  Int_t tLow = fmod(fTimestampOld,fTriggerTimeTot*100000.);
162  Int_t tHigh = fmod(timestamp,fTriggerTimeTot*100000.);
163  //Info("process","**** %d %d",tLow,tHigh);
164  // Int_t iMax = triggerType - 8;
165  // if(iMax<0) iMax += kNtriggerTypes;
166  // for(Int_t i = 0; i<iMax; i++){
167  // tLow -= fTriggerTime[i+8]*100000;
168  // tHigh -= fTriggerTime[i+8]*100000;
169  // if(tLow<0) tLow += fTriggerTimeTot*100000;
170  // if(tHigh<0) tHigh += fTriggerTimeTot*100000;
171  // //Info("process"," %d %d",tLow,tHigh);
172  // }
173  if(tLow<fTlow[triggerType]) fTlow[triggerType] = tLow;
174  if(tHigh>fThigh[fTriggerOld]) fThigh[fTriggerOld] = tHigh;
175  // hTlowhigh->Fill(tLow,tHigh);
176  // gTlow->SetPoint(gTlow->GetN(),timestamp,fTlow[fTriggerOld]);
177  // gThigh->SetPoint(gThigh->GetN(),timestamp,fThigh[fTriggerOld]);
178  gTlow->SetPoint(gTlow->GetN(),fTlow[fTriggerOld],fTriggerOld + timestamp*1e-12);
179  gThigh->SetPoint(gThigh->GetN(),fThigh[fTriggerOld],fTriggerOld + timestamp*1e-12);
180  }
181  //Info("process","Trigger change %d %d, %d %d",triggerType,fTriggerOld,fTlow,fThigh);
182  // }
183 
184  hCycleNew->Fill(fmod(timestamp,fTriggerTimeTot*100000.),triggerType);
185 
186 
187  if(triggerType == fTriggerOld || triggerType == -1)
188  hDeltaTlog->Fill(triggerType,Double_t(timestamp - fTimestampOld)/1e5 + 0.05*gRandom->Rndm());
189  if(triggerType == -1){
190  triggerType = fTriggerOld;
191 
192  // for(Int_t i = 0; i<kNtriggerTypes; i++)
193  // fTriggerTimeTot += fTriggerTime[i];
194 
195  }
196 
197  if(triggerType == fTriggerOld){
198  hDeltaT->Fill(triggerType,Double_t(timestamp - fTimestampOld)/1e5);
199  }
200  else{
201  hDeltaTchange->Fill(triggerType,fTriggerOld,Double_t(timestamp - fTimestampOld)/1e5);
202  hTriggerChange->Fill(triggerType,fTriggerOld);
203  }
204 
205 
206 
207 
208  hRate->Fill(triggerType);
209 
210  if(triggerType == 0 && fTriggerOld != 0)
211  fOffset = timestamp;
212 
213  // hCycle->Fill(timestamp-fOffset,triggerType);
214 
215  // gTimestamp0->SetPoint(gTimestamp0->GetN(),nEvents,fEvt->GetTimeStamp(XDCC));
216  // // gTimestamp1->SetPoint(gTimestamp1->GetN(),nEvents,fEvt->GetTimeStamp(YDCC));
217  // gTimestamp1->SetPoint(gTimestamp1->GetN(),nEvents,timestamp);
218  // gTimestamp2->SetPoint(gTimestamp2->GetN(),nEvents,fEvt->GetTimeStamp(PMM2));
219 
220  fTimestampOld = timestamp;
221  if(triggerType >=0)
222  fTriggerOld = triggerType;
223 
224 }
225 
227 {
228 
229  fInit = kFALSE;
230 
231  fTimestampOld = 0;
232  fTriggerOld = -4;
233  fOffset = 0;
234  fTimeStart = 0;
235 
236  const Int_t nbinsDt = 1000;
237  Double_t xminDt = 1;
238  Double_t xmaxDt = 1e4;
239  Double_t logxminDt = TMath::Log(xminDt);
240  Double_t logxmaxDt = TMath::Log(xmaxDt);
241  Double_t binwidthDt = (logxmaxDt-logxminDt)/nbinsDt;
242  Double_t xbinsDt[nbinsDt+1];
243  xbinsDt[0] = xminDt;
244  for (Int_t i=1;i<=nbinsDt;i++)
245  xbinsDt[i] = TMath::Exp(logxminDt+i*binwidthDt);
246 
247 
248  // Initialise histograms here
249  hTimestampPmm2 = new TH1F("hTimestampPmm2","t_{PMM2} - t",50,-1310,-1260);
250  hDeltaT = new TH2F("hDeltaT",";trigger;#Deltat [ms]",20,-2,18,1000,0,500);
251  hDeltaTlog = new TH2F("hDeltaTlog",";trigger;#Deltat [ms]",20,-2,18,nbinsDt,xbinsDt);
252  hRate = new TH1F("hRate",";trigger;Rate",20,-2,18);
253  hTriggerCorrection = new TH1F("hTriggerCorrection",";trigger;Rate",20,-2,18);
254  for(Int_t i = 1; i<= 20; i++)
255  hTriggerCorrection->SetBinContent(i,1);
256  hDeltaTchange = new TH3F("hDeltaTchange","trigger_{n};trigger_{n-1};#Deltat [ms]",20,-2,18,20,-2,18,1000,0,100);
257  hTriggerChange = new TH2F("hTriggerChange",";trigger_{n};trigger_{n-1};",20,-2,18,20,-2,18);
258  hChangeTrigger = new TH1F("hChangeTrigger",";changed trigger;",20,-2,18);
259 
260 
261 
262  gTimestamp0 = new TGraph();
263  gTimestamp1 = new TGraph();
264  gTimestamp2 = new TGraph();
265 
266  gTlow = new TGraph();
267  gThigh = new TGraph();
268 
269 
270 
271 
272  }
273 
274 void HarpoAnalyseRates::Save(char * /* mode */)
275  {
276 
277 
278 
279  hTriggerCorrection->Multiply(hRate);
280  Double_t scale = 1.;
281  if(fTimestampOld)
282  scale = 1e8/fTimestampOld;
283  Info("Save","scale = 1e8/%g = %g",fTimestampOld,scale);
284  hTriggerCorrection->Scale(scale);
285  Info("Save","fTimestampOld = %g",fTimestampOld);
286 
287 
288  /* TFile* hf = */ OpenHistFile("rates");
289  // Save histograms here
290  hDeltaT->Write();
291  hDeltaTlog->Write();
292  hDeltaTchange->Write();
293  hTriggerChange->Write();
294  hTimestampPmm2->Write();
295  if(fInit){
296  hCycle->Write();
297  hCycleNew->Write();
298  // hTlowhigh->Write();
299  }
300  hChangeTrigger->Write();
301  hRate->Write();
302  hTriggerCorrection->Write();
303  gTimestamp0->Write("gTimestamp0");
304  gTimestamp1->Write("gTimestamp1");
305  gTimestamp2->Write("gTimestamp2");
306  gTlow->Write("gTlow");
307  gThigh->Write("gThigh");
308 
309  }
310 
Dummy analysis to run as test and example. Give basic histograms of the data.
Dcc Plane Y.
Definition: HarpoDet.h:20
A class Pmm2Status is bits representation of pmm2 status register (0x400).
Definition: Pmm2Status.h:12
HarpoDetHeader * GetHeader(UInt_t ndet=XDCC)
static const Int_t kNtriggerTypes
Int_t fTriggerDownscaling[kNtriggerTypes]
Int_t fThigh[kNtriggerTypes]
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
void print()
Overloaded method which do all job.
UInt_t eventSize
Raw Event size.
Definition: HarpoDetEvent.h:28
A class hold HARPO run information.
Definition: Pmm2Header.h:17
unsigned int getTrigger(int trig) const
Definition: Pmm2Status.cxx:168
Bool_t fInit
Redefine empty default.
virtual void print()
FullEvent Header not scecific to the detectors The class is ....
Int_t GetTriggerType()
Definition: Pmm2Event.h:29
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
HarpoDetEvent * GetDetEvent(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:93
Pmm2MesVect * GetMesurements()
Return pointer to decoded data.
Definition: Pmm2Event.cxx:78
Pmm2Status * getStatus()
Definition: Pmm2Header.h:36
ULong_t GetTimeStamp(Int_t after=0)
Data Format.
Definition: Pmm2Event.cxx:92
A class store HARPO raw PMM2 event buffer and header. End provide access metods to the row data...
Definition: Pmm2Event.h:19
virtual const EventHeader_t * GetHeader() const
Definition: HarpoDetEvent.h:38
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
HarpoRunHeader * fRunHeader
Definition: HarpoAnalyse.h:76
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
Int_t getTimeStamp() const
Definition: Pmm2Mes.h:32
ULong_t GetTimeStamp(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:149
Int_t getPPS() const
Definition: Pmm2Mes.h:60
Int_t fTlow[kNtriggerTypes]
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
Int_t fTriggerTime[kNtriggerTypes]
A list of all mesurements in one Event for Pmm2 v2 card The class is place holder for all unpacked me...
Definition: Pmm2MesList.h:19
Pmm2Mes at(ULong_t idx)
Definition: Pmm2MesList.h:37
void Save(char *mode=NULL)
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71