Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JKexing.cc File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TF1.h"
#include "JSupernova.hh"
#include "km3net-dataformat/online/JDAQClock.hh"
#include "JDAQ/JDAQEvaluator.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JGizmo/JManager.hh"
#include "JROOT/JROOTClassSelector.hh"
#include "JTools/JQuantile.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JAutoTreeScanner.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JLang/JObjectMultiplexer.hh"
#include "JMath/JMathToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Author
mlincett

Example application to test supernova trigger on run files.

Definition in file JKexing.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 48 of file JKexing.cc.

49 {
50 
51  typedef JRange<int> JRange_t;
52 
53  JMultipleFileScanner<> inputFile;
54  JLimit_t& numberOfEvents = inputFile.getLimit();
55  string outputFile;
56  string detectorFile;
57  double TMax_ns;
58  double TVeto_ns;
59  JROOTClassSelector selector;
60  int debug;
61  int preTriggerThreshold;
62  JRange_t M;
63 
64 
65  // Check input parameters
66 
67  try {
68 
69  JParser<> zap("Example program test supernova triggers.");
70 
71  zap['f'] = make_field(inputFile);
72  zap['o'] = make_field(outputFile) = "kexing.root";
73  zap['n'] = make_field(numberOfEvents) = JLimit::max();
74  zap['a'] = make_field(detectorFile);
75  zap['T'] = make_field(TMax_ns) = 10.0;
76  zap['V'] = make_field(TVeto_ns) = 1000.0;
77  zap['C'] = make_field(selector) = getROOTClassSelection<JDAQTimesliceTypes_t>();
78  zap['d'] = make_field(debug) = 1;
79  zap['M'] = make_field(M) = JRange<int>(6,10);
80  zap['t'] = make_field(preTriggerThreshold) = 4;
81 
82  zap(argc, argv);
83  }
84  catch(const exception &error) {
85  FATAL(error.what() << endl);
86  }
87 
88  cout.tie(&cerr);
89 
91 
92  try {
93  load(detectorFile, detector);
94  }
95  catch(const JException& error) {
96  FATAL(error);
97  }
98 
99  // Configure input streams
100 
102 
104 
105  JTreeScannerInterface<JDAQTimeslice>* pts = zmap[selector];
106 
107  pts->configure(inputFile);
108 
109  // Configure routers
110 
111  const JModuleRouter moduleRouter(detector);
112 
113  const JDAQHitRouter hitRouter(detector);
114 
115  // -----------------------------------
116  // STEP 1: building vetoes from events
117  // -----------------------------------
118 
119  TH1D* h_vtr = new TH1D("VetoTimeRange","VetoTimeRange", 10000, 0, 10000);
120 
122 
123  map<int, JVetoSet> triggeredEvents;
124 
125  for (; evIn.hasNext(); ) {
126 
127  STATUS("event: " << setw(10) << evIn.getCounter() << '\r'); DEBUG(endl);
128 
129  JDAQEvent* event = evIn.next();
130 
131  JVeto vp(*event, hitRouter);
132 
133  triggeredEvents[event->getFrameIndex()].push_back(vp);
134 
135  h_vtr->Fill(vp.getLength());
136 
137  }
138 
139  STATUS(triggeredEvents.size() << " JDAQEvents loaded in veto buffer." << endl);
140 
141  //--------------------------------
142  // STEP 2: timeslice processing
143  // -------------------------------
144 
145  // 0 -> no filter
146  // 1 -> count once per track
147  // 2 -> suppress track
148  // 3 -> suppress based on trigger veto
149 
150  // Output data structures
151 
152  typedef JManager<int, TH1D> JManager_t;
153 
154  JManager_t SNT(new TH1D("SNT_F%", NULL, 100, 0.0, 100));
155 
156  JManager_t MUL(new TH1D("MUL_F%", NULL, 1 + 31, -0.5, 31 + 1 - 0.5));
157 
158  const int nStages = 5;
159  vector<vector<int> > trgHistory(nStages);
160 
161  // Loop
162 
163  counter_type counter = 0;
164 
165  for ( ; pts->hasNext() && counter != inputFile.getLimit(); ++counter) {
166 
167  STATUS("timeslice: " << setw(10) << counter << '\r'); DEBUG(endl);
168 
169  const JDAQTimeslice* timeslice = pts->next();
170 
171  int fIndex = timeslice->getFrameIndex();
172 
173  JDataSN preTrigger(TMax_ns, preTriggerThreshold);
174 
175  preTrigger(timeslice, moduleRouter);
176 
177  JTriggerSN trigger(TVeto_ns);
178 
179  trigger(preTrigger);
180 
181  // generate and configure event-based veto
182 
183  JVetoSet veto;
184 
185  if (triggeredEvents.count(fIndex)) {
186  veto = triggeredEvents.at(fIndex);
187  }
188 
189  trigger.setVeto(veto);
190 
191  // count trigger
192 
193  JSNFilterM trgF0(M, 0);
194  JSNFilterM trgF1(M, 1);
195 
196  JSNFilterMV trgFV(M, veto);
197 
198  JRange<int> A = JRange<int>(2,31);
199  JSNFilterMV trgAV(A, veto);
200 
201  int rawCount = count_if(preTrigger.begin(), preTrigger.end(), trgF0);
202 
203  int trgCountF0 = count_if(trigger.begin(), trigger.end(), trgF0);
204  int trgCountF1 = count_if(trigger.begin(), trigger.end(), trgF1);
205  int trgCountFV = count_if(trigger.begin(), trigger.end(), trgFV);
206  int domCountF1 = trigger.getModules(trgF1).size();
207 
208  trgHistory[0].push_back(rawCount);
209  trgHistory[1].push_back(trgCountF0);
210  trgHistory[2].push_back(trgCountF1);
211  trgHistory[3].push_back(trgCountFV);
212  trgHistory[4].push_back(domCountF1);
213 
214  trigger.fill(MUL[1], trgF0);
215  trigger.fill(MUL[2], trgF1);
216  trigger.fill(MUL[3], trgFV);
217  trigger.fill(MUL[4], trgAV);
218 
219  }
220 
221  //-------------------------------------
222  // STEP 3: generating trigger summaries
223  // ------------------------------------
224 
225  for (int i = 0; i < nStages; i++) {
226  for (unsigned j = 0; j < trgHistory[i].size(); j++) {
227  SNT[i]->Fill(trgHistory[i][j]);
228  }
229  }
230 
231  SNT[0]->SetTitle("M[6,10] count before clustering");
232  SNT[1]->SetTitle("M[6,10] count after clustering");
233  SNT[2]->SetTitle("M[6,10] count after track self-veto");
234  SNT[3]->SetTitle("M[6,10] count after track trigger-veto");
235  SNT[4]->SetTitle("M[6,10] count after track self-veto, unique modules");
236 
237 
238  if (outputFile != "") {
239 
240  TFile out(outputFile.c_str(), "RECREATE");
241 
242  h_vtr->Write();
243  SNT.Write(out);
244  MUL.Write(out);
245 
246  putObject(&out, JMeta(argc,argv));
247 
248  out.Close();
249 
250  }
251 
252 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
Auxiliary class to define a veto time window on a set of optical modules.
Definition: JSupernova.hh:104
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Auxiliary class to select ROOT class based on class name.
SN filter based on veto window.
Definition: JSupernova.hh:384
Router for direct addressing of module data in detector data structure.
Long64_t counter_type
Type definition for counter.
Auxiliary class for a type holder.
Definition: JType.hh:19
string outputFile
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
Auxiliary interface for direct access of elements in ROOT TChain.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
Auxiliary class to manage set of compatible ROOT objects (e.g.
Definition: JManager.hh:42
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
Auxiliary class to apply the supernova trigger to SN data.
Definition: JSupernova.hh:411
Data time slice.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
SN filter based on multiplicity selection optional suppression of multi-module coincidences WARNING: ...
Definition: JSupernova.hh:349
int debug
debug level
Definition: JSirene.cc:61
Auxiliary class to select JTreeScanner based on ROOT class name.
#define FATAL(A)
Definition: JMessage.hh:67
JRange< Double_t > JRange_t
Definition: JFitToT.hh:34
Auxiliary class to build the supernova trigger dataset.
Definition: JSupernova.hh:158
int j
Definition: JPolint.hh:634
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Auxiliary class to manage a set of vetoes.
Definition: JSupernova.hh:277
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.