46 static const char SEPARATOR =
';';
55 friend inline std::istream&
operator>>(std::istream&
in, JCondition&
object)
62 if ((in >>
object.
range) && ! (in >>
object.weight)) {
77 friend inline std::ostream&
operator<<(std::ostream& out,
const JCondition&
object)
79 out <<
object.formula << SEPARATOR <<
object.range <<
' ' <<
object.weight << std::endl;
119 int main(
int argc,
char **argv)
124 typedef JRange<int> JRange_t;
136 JCondition_t condition;
144 JParser<> zap(
"Main program to evaluate quality data from data base."\
145 "\nThe condition and veto can be any TFormula compatible expression involving QA/QC parameters (see e.g. JQAQC.sh -h).");
151 zap[
'f'] =
make_field(inputFile,
"Optional input file instead of database.") =
"";
152 zap[
'o'] =
make_field(
outputFile,
"Output file containing histograms and n-tuple or ASCII file.") =
"quality.root";
154 zap[
'R'] =
make_field(runs,
"Run range") = JRange_t(1, JRange_t::getMaximum());
155 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v.*\\..*\\..*"), JGITTags_t::key_type(
"2019-04-12"));
164 catch(
const exception &error) {
165 FATAL(error.what() << endl);
171 for (JCondition_t::const_iterator i = condition.begin(); i != condition.end(); ++i) {
177 FATAL(
"Invalid total weight: " << W << endl);
186 if (inputFile ==
"") {
197 ID = to_value<int>(detid);
207 selection += getSelector<JRuns>(
ID);
209 ResultSet& rs =
getResultSet(getTable<JRuns>(), selection);
212 if (TString(parameters.RUNSETUPNAME.c_str()).Contains(regexp)) {
213 setups.put(parameters);
228 JSelector selector = getSelector<JRunSummaryNumbers>(detid, runs.getLowerLimit(), runs.getUpperLimit());
230 selector.add(&JRunSummaryNumbers::SOURCE_NAME, *git);
234 ResultSet& rs =
getResultSet(getTable<JRunSummaryNumbers>(), selector);
236 for (JRunSummaryNumbers parameters; rs >>
parameters; ) {
237 if (setups.has(parameters.RUN)) {
238 zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
244 catch(
const exception& error) {}
246 for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
251 quality.detector =
ID;
252 quality.run = run->first;
254 for (data_type::const_iterator i = run->second.begin(); i != run->second.end(); ++i) {
255 quality.put(i->first, i->second);
258 buffer.insert(quality);
262 catch(
const exception& error) {
263 FATAL(error.what() << endl);
272 TClass* rc = (TClass*) TDictionary::GetDictionary(
typeid(JRunQuality));
274 TIterator* i = rc->GetListOfDataMembers()->MakeIterator();
276 for (
const TDataMember* p; (p = (
const TDataMember*) i->Next()) != NULL; ) {
277 if (JRootClass::is_class(p->GetName())) {
283 ifstream
in(inputFile.c_str());
290 istringstream
is(zbuf);
292 nc =
distance(istream_iterator<string>(is), istream_iterator<string>());
300 for (JRunQuality quality; reader.getObject(quality); ) {
302 buffer.insert(quality);
308 reader.getObject(setup);
310 setups[quality.run] = setup;
318 if (buffer.empty()) {
319 FATAL(
"No data." << endl);
325 runs = JRange_t(buffer.begin()->run, buffer.rbegin()->run);
327 TH1D h0(
"h0", NULL, 1000, 0.0, 1.01);
328 TH1D
h1(
"h1", NULL, condition.size(), -0.5, condition.size() + 0.5);
331 h0.SetMaximum(1.1 * (runs.getUpperLimit() - runs.getLowerLimit()));
334 h1.SetMaximum(1.1 * (runs.getUpperLimit() - runs.getLowerLimit()));
336 const Double_t xmin = runs.getLowerLimit() - 0.5;
337 const Double_t xmax = runs.getUpperLimit() + 0.5;
339 JManager<TString, TH1D>
H1(
new TH1D(
"%", NULL, runs.getLength() + 1, xmin, xmax));
343 for (JCondition_t::const_iterator i = condition.begin(); i != condition.end();++i) {
344 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(i->formula <<
":upper"),
MAKE_CSTRING(i->range.getUpperLimit()), xmin, xmax));
345 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(i->formula <<
":lower"),
MAKE_CSTRING(i->range.getLowerLimit()), xmin, xmax));
348 for (JCondition_t::const_iterator i = veto.begin(); i != veto.end();++i) {
349 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(i->formula <<
":upper"),
MAKE_CSTRING(i->range.getUpperLimit()), xmin, xmax));
350 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(i->formula <<
":lower"),
MAKE_CSTRING(i->range.getLowerLimit()), xmin, xmax));
357 for (
size_t i = 0; i != condition.size(); ++i) {
358 os <<
":" << (char) (
'a' + i);
363 TNtuple n1(
"n1",
"quality", os.str().c_str());
380 for (
size_t i = 0; i != condition.size(); ++i) {
382 const JCondition& ps = condition[i];
383 const double y =
getResult(ps.formula, *quality);
385 DEBUG(ps.formula <<
' ' << y << endl);
387 tuple.push_back((Float_t) y);
389 TH1D* p = H1[ps.formula];
391 p->SetBinContent(p->FindBin((
double) quality->run), y);
392 p->SetBinError (p->FindBin((
double) quality->run), 0.0);
398 h1.AddBinContent(i + 1, ps.range(y) ? 1.0 : 0.0);
401 const double Q = w/W;
403 tuple.push_back((Float_t) Q);
407 for (
size_t i = 0; i != veto.size(); ++i) {
409 const JCondition& ps = veto[i];
410 const double y =
getResult(ps.formula, *quality);
412 TH1D* p = H1[
MAKE_STRING(
"VETO[" << ps.formula <<
"]")];
414 p->SetBinContent(p->FindBin((
double) quality->run), ps.range(y) ? 0.0 : 1.0);
415 p->SetBinError (p->FindBin((
double) quality->run), 0.0);
422 tuple.push_back((Float_t) V);
423 tuple.push_back((Float_t) setups.get(quality->run));
426 n1.Fill(tuple.data());
428 cout << setw(8) << quality->run <<
' ' <<
FIXED(5,3) << Q <<
' ' << setw(2) << V << endl;
433 for (Int_t i = 0; i <= h0.GetXaxis()->GetNbins(); ++i) {
434 h0.SetBinContent(i, (w += h0.GetBinContent(i)));
441 out << h0 << h1 << n1 <<
H1;
458 writer.putObject(*i);
462 writer.putObject(setups.get(i->run));
Utility class to parse command line options.
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
std::vector< std::string > getGITTags(const TRegexp regexp, const JGITTags_t::key_type date)
Get selection of GIT tags.
Print objects in ASCII format using ROOT dictionary.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
#define MAKE_CSTRING(A)
Make C-string.
then for HISTOGRAM in h0 h1
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
bool resetObject(JManager< JKey_t, JValue_t > *object, const bool reset=false)
Reset JManager object.
#define MAKE_STRING(A)
Make string.
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
#define ASSERT(A,...)
Assert macro.
T & getInstance(const T &object)
Get static instance from temporary object.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
bool is_integer(const std::string &buffer)
Check if string is an integer.
General purpose messaging.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
std::string getFilenameExtension(const std::string &file_name)
Get file name extension, i.e. part after last JEEP::FILENAME_SEPARATOR if any.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
ResultSet & getResultSet(const std::string &query)
Get result set.
std::vector< JServer > getServernames()
Get list of names of available database servers.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
std::vector< double > weight