PPM-DU analysis  2.3
conversion and analysis of the PPM-DU data
 All Classes Files Functions Variables Pages
/home/alex/Work/Research/Km3NeT/PPM-DU/ppm-du-v2.3/analyser.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <vector>
3 #include <string>
4 #include <ctime>
5 #include <dirent.h>
6 #include <boost/lexical_cast.hpp>
7 #include <math.h>
8 //#include <boost/filesystem/operations.hpp>
9 
10 #include <TSystem.h>
11 #include <TFile.h>
12 #include <TTree.h>
13 #include <TBranch.h>
14 #include <TLeaf.h>
15 
16 #include "rawReader.h"
17 #include "event.h"
18 #include "dom.h"
19 #include "pmt.h"
20 #include "signal.h"
21 #include "signals.h"
22 #include "triggeringDOM.h"
23 #include "triggeredSignals.h"
24 #include "triggeringEvent.h"
25 #include "histo.h"
26 #include "constants.h"
27 
28 
128 using namespace std;
129 
130 int
131 main(int argc, char* argv[])
132 {
133  time_t time0, timeA, timeB;
134  time(&time0);
135  time(&timeA);
136  vector<dom> vSlice;
137  vector<triggeredSignals> vEvents;
138  vector<int> vDomId;
139  vDomId.push_back(101);
140  vDomId.push_back(102);
141  vDomId.push_back(103);
142  vEvents.clear();
143  int eventTotal = 0;
144  int event2Doms = 0;
145  int eventTrigger = 0;
146  //const bool individualPmts = false;
147  //const int refId = -1;
148  TFile hfile(argv[3], "RECREATE");
149  histo hResults(vDomId[domId], domId, pmtId);
150  hResults.InitEventPerSlice(individualPmts, vDomId);
151  hResults.InitSignal();
152  hResults.InitFrequency(vDomId);
153  hResults.InitDurations(vDomId);
154  hResults.InitDeltaT(vDomId);
155  hResults.InitDomDeltaT(vDomId);
156  hResults.InitSliceTimeSeries(vDomId);
157  hResults.InitCoincidenceRate(vDomId);
158  long long int startRunTime = 0;
159  bool startSet = false;
160  bool toWrite = false;
161  long long int endRunTime = 0;
162  if (argc < 4) {
163  cerr << "give the id of the first and last";
164  cerr << " runs you want to analyse and the root file name!" << endl;
165  return 0;
166  }
167  int sliceTot = 0;
168  int nbSlicePmt[domNb] = {0, 0, 0};
169  int badSlice[domNb] = {0, 0, 0};
170  for (int r = boost::lexical_cast<int>(argv[1]); r <= boost::lexical_cast<int>(argv[2]); ++r) {
171  struct dirent* dirStruc;
172  const string dataPath = "/home/alex/Data/Km3NeT/PPM-DU/raw/";
173  hResults.SetRunId(r);
174  DIR* directory = opendir(dataPath.c_str());
175  string filename;
176  char filenameStart[1024];
177  sprintf(filenameStart, "RUN-PPM_DU-%0*d", 5, r);
178  char filenameEnd[1024];
179  sprintf(filenameEnd, ".rdat");
180  while ((dirStruc = readdir(directory))) {
181  const string dirname = string(dirStruc->d_name);
182  if ((dirname.find(filenameStart) != string::npos)
183  && (dirname.find(filenameEnd) != string::npos)) {
184  filename = dataPath + dirname;
185  }
186  }
187  bool goodRun = true;
188  for (int g = 4; g <= argc - 1; ++g) {
189  const int wrongId = boost::lexical_cast<int>(argv[g]);
190  if (r == wrongId) goodRun = false;
191  }
192  ifstream file;
193  file.open(filename.c_str(), ios::binary);
194  int twoGbSteps = 1;
195  if ((!file) || (goodRun == false)) {
196  cerr << r << " is not the correct file name!" << endl;
197  continue;
198  } else {
199  long long int fileLength = GetFileLength(file);
200  twoGbSteps = int(double(fileLength)/2.0e9) + 1;
201  if (twoGbSteps > 1) {
202  cerr << "file " << filename.c_str() << " is larger than 2.0GB - "
203  << twoGbSteps << " loops will be made" << endl;
204  }
205  long long int bitPosition = file.tellg();
206  time(&timeA);
207  cerr << "********** looking for the cut values **********\n";
208  for (int i = 0; i < twoGbSteps; ++i) {
209  vSlice.clear();
210  vSlice.resize(0);
211  bitPosition = FillRaw(file, vSlice, bitPosition, toWrite);
212  for (unsigned int s = 0; s < vSlice.size(); ++s) {
213  const int curId = vSlice[s].GetDomHeader().GetDomId();
214  if (curId == vDomId[domId]) {
215  const long long int curtime = vSlice[s].GetDomHeader().GetDomTime();
216  if (vSlice[s].HasPmtData(pmtId) == true) {
217  pmt curPmt = vSlice[s].GetPmtData(pmtId);
218  if (curPmt.HasSignal() == true) {
219  const vector<signal> vSignal = curPmt.GetSignal();
220  hResults.FillSignal(vSignal, curtime);
221  }
222  }
223  }
224  bool countedDom = false;
225  for (unsigned int j = 0; j < vDomId.size(); ++j) {
226  if (curId == vDomId[j]) {
227  countedDom = true;
228  break;
229  }
230  }
231  if (vDomId.size() == 0) countedDom = false;
232  if (countedDom == false) vDomId.push_back(curId);
233  }
234  hResults.FillSliceTimeSeries(vSlice, vDomId);
235  hResults.FillEventPerSlice(vSlice, individualPmts, vDomId);
236  }
237  }
238  file.close();
239  double cutValues[domNb][pmtNb];
240  hResults.DrawEventPerSlice(individualPmts, cutValues, vDomId);
241  hResults.DrawSignal();
242  file.open(filename.c_str(), ios::binary);
243  long long int bitPosition = file.tellg();
244  time(&timeB);
245  cerr << "cut values are (in kHz):\n";
246  for (int dom = 0; dom < domNb; ++dom) {
247  for (int pmt = 0; pmt < pmtNb; ++pmt) {
248  //cutValues[dom][pmt] = DBL_MAX; // to remove the cuts!
249  cerr << "dom" << dom << " - pmt" << pmt << " - " << cutValues[dom][pmt]/conversion << endl;
250  }
251  }
252  cerr << "time of analysis: " << difftime(timeB, timeA) << 's' << endl;
253  time(&timeA);
254  toWrite = false;
255  vector<triggeredSignals> v2GigaResults;
256  for (int i = 0; i < twoGbSteps; ++i) {
257  //v2GigaResults.clear();
258  cerr << "********** Filling the DOM with data - loop " << i << " **********\n";
259  vSlice.clear();
260  bitPosition = FillRaw(file, vSlice, bitPosition, toWrite);
261  time(&timeB);
262  cerr << "time of analysis: " << difftime(timeB, timeA) << 's' << endl;
263  cerr << "********** Filling histograms **********\n";
264  //const double cutValue = cutValues[cutValues.size() - 1];
265  hResults.FillFrequency(vSlice, cutValues, vDomId);
266  hResults.FillDurations(vSlice, cutValues, vDomId);
267  time(&timeA);
268  cerr << "time of analysis: " << difftime(timeA, timeB) << 's' << endl;
269  cerr << "********** Filling events and first level trigger **********\n";
270  vector<triggeredSignals> vTrig2pmtResult;
271  vTrig2pmtResult.clear();
272  vector<triggeredSignals> vTrigXpmtResult;
273  vTrigXpmtResult.clear();
274  vector<signals> vSignals;
275  vSignals.clear();
276  sliceTot += vSlice.size();
277  for (unsigned int e = 0; e < vSlice.size(); ++e) {
278  //cerr << 100.*double(e)/double(vSlice.size()) << "% \r";
279  const domHeader& domHead = vSlice[e].GetDomHeader();
280  const long long int domTime = domHead.GetDomTime();
281  if (startSet == false) {
282  startRunTime = domTime;
283  startSet = true;
284  }
285  if (e == vSlice.size() - 1) endRunTime = domTime;
286  const int domId = domHead.GetDomId();
287  int domIndex = hResults.FindDomIndex(domId, vDomId);
288  hResults.SetDomId(domIndex);
289  //hResults.InitSignals();
290  const vector<pmt>& pmtSample = vSlice[e].GetPmtsData();
291  if (!pmtSample.size()) continue;
292  int sigInSlice = 0;
293  for (unsigned int j = 0; j < pmtSample.size(); ++j) {
294  vector<signal> sigSample = pmtSample[j].GetSignal();
295  const int sigSampleSize = sigSample.size();
296  sigInSlice += sigSampleSize;
297  if (!sigSampleSize) continue;
298  //const double cutValue = cutValues[cutValues.size() - 1];
299  const int pmtId = pmtSample[j].GetPmtId();
300  if (IsNoisySlice(sigSampleSize, cutValues[domIndex][pmtId])) {
301  ++badSlice[domIndex];
302  } else {
303  ++nbSlicePmt[domIndex];
304  for (int k = 0; k < sigSampleSize; ++k) {
305  const long long int start = sigSample[k].GetStart() + domTime;
306  const signals oneSig(domIndex, pmtId, start, start + sigSample[k].GetDuration());
307  FillSignals(oneSig, vSignals);
308  }
309  }
310  }
311  eventTotal += sigInSlice;
312  }
313  SortSignals(vSignals);
314  //for (unsigned int sig = 0; sig < vSignals.size(); ++sig) {
315  //cout << vSignals[sig].GetDomId() << ' ' << vSignals[sig].GetPmtId() << ' '
316  // << vSignals[sig].GetStart() << ' ' << vSignals[sig].GetStop() << endl;
317  //}
318  time(&timeB);
319  DoT2Pmts(vSignals, vTrig2pmtResult, coincWindowPmts);
320  DoTmultiPmts(vSignals, vTrigXpmtResult, coincWindowDoms);
321  int localmulti = 4;
322  char f4foldname[1024];
323  sprintf(f4foldname, "/home/alex/Data/Km3NeT/PPM-DU/stats/RUN-PPM_DU-%0*d-%dfold-%dns.dat",
324  5, r, localmulti, coincWindowPmts);
325  ofstream out4fold(f4foldname, ios::app);
326  for (unsigned int i = 0; i < vTrigXpmtResult.size(); ++i) {
327  const std::vector<signals>& vSignals4fold = vTrigXpmtResult[i].GetSignals();
328  if (vSignals4fold.size() == unsigned(localmulti)) {
329  out4fold << vSignals4fold[0].GetDomId() << ' ';
330  for (unsigned int j = 0; j < vSignals4fold.size(); ++j) {
331  out4fold << vSignals4fold[j].GetPmtId() << ' ' << vSignals4fold[j].GetStart()
332  << ' ' << vSignals4fold[j].GetStop() << ' ';
333  }
334  out4fold << endl;
335  }
336  }
337  out4fold.close();
338  //for (unsigned int i = 0; i < vTrig2pmtResult.size(); ++i) {
339  //const std::vector<signals>& vSignals = vTrig2pmtResult[i].GetSignals();
340  //const int pmtId = vSignals[0].GetPmtId();
341  //if (vSignals.size() > 2)
342  // cout << pmtId << ' ' << vSignals.size() << endl;
343  //}
344  hResults.FillCoincidenceRate(vTrigXpmtResult);
345  hResults.FillDeltaT(vTrig2pmtResult);
346  vector<triggeredSignals> vTrig2Result;
347  SelectingMultiplicity(vTrigXpmtResult, vTrig2Result, multiplicityForMuon);
348  AddDom2Event(vTrig2Result, v2GigaResults);
349  //}
350  hResults.DrawPmtStats(vSlice, vDomId);
351  time(&timeB);
352  cerr << "time of analysis: " << difftime(timeB, timeA) << 's' << endl;
353  }
354  cerr << "*************** Second level trigger ****************" << endl;
355  Do2DomTrigger(v2GigaResults, vEvents, domTimeWindow);
356  //DoEventTrigger(v2GigaResults, vEvents, domTimeWindow);
357  eventTrigger = vEvents.size();
358  event2Doms = v2GigaResults.size();
359  hResults.FillDomDeltaT(vEvents, vDomId);
360  hResults.DrawDurations();
361  hResults.DrawFrequency();
362  hResults.DrawDeltaT();
363  hResults.DrawSliceTimeSeries();
364  hResults.DrawDomDeltaT();
365  //if (eventTrigger != 0) hResults.FillDomDeltaT(vEvents, vDomId);
366  cout << r << ' ' << sliceTot << " 0 " << nbSlicePmt[0] << ' ' << badSlice[0]
367  << " 1 " << nbSlicePmt[1] << ' ' << badSlice[1]
368  << " 2 " << nbSlicePmt[2] << ' ' << badSlice[2] << endl;
369  }
370  hResults.DrawCoincidenceRate();
371 
372  hfile.Close();
373  cerr << "number of not noisy pmts - number of noisy pmts\n"
374  << "dom 101: " << nbSlicePmt[0] << ' ' << badSlice[0] << "\n"
375  << "dom 102: " << nbSlicePmt[1] << ' ' << badSlice[1] << "\n"
376  << "dom 103: " << nbSlicePmt[2] << ' ' << badSlice[2] << "\n"
377  << "Total number of signals: " << eventTotal
378  << " - number of events for a multiplicity of " << multiplicityForMuon << ": " << event2Doms
379  << " - number of 2 Doms signals: " << eventTrigger << endl;
380  time(&timeA);
381  const double durationInS = double(endRunTime - startRunTime)*1e-9 + 0.134217728;
382  const int runHour = int(durationInS/3600.);
383  const int runMin = int((durationInS - double(3600*runHour))/60.);
384  const double runSec = durationInS - double(3600*runHour) - double(60*runMin);
385  cerr << "time of analysis: " << difftime(timeA, time0) << "s\n"
386  << "run duration: " << runHour << "h " << runMin << "min " << runSec << "s"<< endl;
387  return 0;
388 }
void DrawDeltaT(const int refID)
draw the histo, one per pmt
Definition: histo.cc:570
const bool HasSignal() const
test if one pmt has signal during the slice reading
Definition: pmt.h:46
void Do2DomTrigger(std::vector< triggeredSignals > &vTrigSignals, std::vector< triggeredSignals > &vFinalEvent, const int domTimeWindow)
void SortSignals(std::vector< signals > &vSig)
const int GetDomId() const
get the id of the dom sample
Definition: domHeader.h:59
void DrawSliceTimeSeries()
draw the slice time series histo.
Definition: histo.cc:969
organisation of the data - dom level
Definition: dom.h:35
void InitDeltaT(const int refID)
initialize the delta T histo (time difference between pmts).
Definition: histo.cc:482
void AddDom2Event(std::vector< triggeredSignals > &vTriggeredDom, std::vector< triggeredSignals > &vEventList)
to come...
void FillDeltaT(const std::vector< triggeredSignals > &vTrigger, const int domId, const int refID)
fill the time difference between all pmts and the reference pmt (given by the integer) ...
Definition: histo.cc:522
const int pmtNb
Definition: constants.h:9
void FillFrequency(const int domId, const std::vector< pmt > &pmtSample, double cutValues[domNb][pmtNb])
fill the histo with the time difference between 2 signals for a list of signals (one histo per Pmt nu...
Definition: histo.cc:268
bool DoT2Pmts(const std::vector< signals > &vSig, std::vector< triggeredSignals > &vTrig)
define the 31 pmt signals of an dom for an event
Definition: signals.h:31
bool SelectingMultiplicity(std::vector< triggeredSignals > &vTrigInit, std::vector< triggeredSignals > &vTrigFinal, const int multiplicity)
remove all dom events with a multiplicity lower than the chosen one
long long int FillRaw(std::ifstream &str, std::vector< dom > &vSlice, long long int bitPosition, bool toWrite)
Definition: rawReader.cc:323
const bool individualPmts
Definition: constants.h:48
const int coincWindowDoms
Definition: constants.h:50
void DrawDurations()
draw the histo, one per pmt
Definition: histo.cc:188
Identify and fill the pmts with data.
Definition: pmt.h:34
void InitSignal()
initialize the signal histo.
Definition: histo.cc:20
void FillEventPerSlice(const std::vector< dom > &domSample, const bool individualPmt, const std::vector< int > &vDomId)
fill the event per slice histo.
Definition: histo.cc:833
const int domTimeWindow
Definition: constants.h:51
const std::vector< signal > GetSignal() const
get the signal measured by the pmt (see signal.h for the format)
Definition: pmt.h:48
void FillDomDeltaT(const std::vector< triggeredSignals > &vTrigger, const std::vector< int > &vDomId)
fill the time difference between all Dom neighbors
Definition: histo.cc:716
void SetRunId(const int id)
set the ID of the run
Definition: histo.h:67
void FillSignals(const signals sig, std::vector< signals > &vSig)
Merging of the signals of all the pmts of the dom.
Definition: triggeringDOM.cc:7
const int domId
Definition: constants.h:10
void FillCoincidenceRate(const std::vector< triggeredSignals > &vTrigger)
Fill the coincidence rate histo.
Definition: histo.cc:775
const int domNb
Definition: constants.h:6
make the event trigger (coincidence between doms)
void InitFrequency(const std::vector< int > &vDomId)
initialize the frequency histo (depends on the pmt id).
Definition: histo.cc:246
void DrawDomDeltaT()
draw the histo
Definition: histo.cc:745
bool DoTmultiPmts(const std::vector< signals > &vSig, std::vector< triggeredSignals > &vTrig, const int coincWindow)
make the DOM trigger (coincidence between pmts)
replace drawing.h: do online histos
Definition: histo.h:46
const int coincWindowPmts
Definition: constants.h:49
void DrawCoincidenceRate()
draw the coincidence rate histo.
Definition: histo.cc:805
bool IsNoisySlice(const int signalNb, const double limitNb)
Definition: rawReader.cc:414
void DrawEventPerSlice(const bool individualPmt, double cutValues[domNb][pmtNb], const std::vector< int > &vDomId)
draw the event per slice histo.
Definition: histo.cc:859
void DrawSignal()
draw the histo
Definition: histo.cc:47
void SetDomId(const int id)
set the Id of the DOM
Definition: histo.h:55
void FillSliceTimeSeries(const std::vector< dom > &domSample, const std::vector< int > &vDomId)
fill the slice time series histo.
Definition: histo.cc:956
long long int GetFileLength(std::ifstream &str)
Definition: rawReader.cc:406
void DrawFrequency()
draw the histo, one per pmt
Definition: histo.cc:339
void FillSignal(const signal &sig)
fill the histo with one signal (it can be for instance one signal of one Pmt of one DOM) ...
Definition: histo.cc:29
Fill a dom header from a binary file.
Definition: domHeader.h:30
void InitCoincidenceRate(const std::vector< int > &vDomId)
initialize the coincidence rate histo.
Definition: histo.cc:763
const double conversion
Definition: constants.h:12
void DrawPmtStats(const std::vector< dom > &domSample, const std::vector< int > &vDomId)
draw the number of signal as a function of the pmt number (for one event)
Definition: histo.cc:405
const long long int GetDomTime() const
get the time stamp of each dom sample
Definition: domHeader.h:67
const int multiplicityForMuon
Definition: constants.h:53
void FillDurations(const int domId, const std::vector< pmt > &pmtSample, double cutValues[domNb][pmtNb])
fill the histo with all the signal durations of a list of signal (one histo per Pmt number) ...
Definition: histo.cc:121
int FindDomIndex(const int id, const std::vector< int > &vDomId)
find the index associates to a Dom Id
Definition: histo.cc:10
void InitDomDeltaT(const std::vector< int > &vDomId)
initialize the delta T histo (time difference between doms).
Definition: histo.cc:697
const int pmtId
Definition: constants.h:11
void InitEventPerSlice(const bool individualPmt, const std::vector< int > &vDomId)
initialize the event per slice histo.
Definition: histo.cc:818
void InitSliceTimeSeries(const std::vector< int > &vDomId)
initialize the slice time series histo.
Definition: histo.cc:941
int main(int argc, char *argv[])
Definition: analyser.cc:131
void InitDurations(const std::vector< int > &vDomId)
initialize the duration histo (depends on the pmt id).
Definition: histo.cc:95