00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013
00014
00015 #include <cstdio>
00016 #include <cctype>
00017 #include <vector>
00018
00019 #include <TVirtualPS.h>
00020 #include <TPad.h>
00021
00022 #include "Marana/TMarEvent.h"
00023 #include "Marana/TMarBody.h"
00024 #include "SFHMarana/MaranaEventLoop.h"
00025 #include "SFHMarana/MarSysBinningFun.h"
00026
00027 #include "jbltools/sfh/SFH1F.h"
00028 #include "jbltools/sfh/SFSetOfHistograms.h"
00029 #include "jbltools/sfh/SFMatrixOfHistograms.h"
00030 #include "jbltools/sfh/SFHProf.h"
00031 #include "jbltools/sfh/SFSetOfHProf.h"
00032 #include "jbltools/sfh/SFH2F.h"
00033 #include "jbltools/sfh/SFSetOfH2F.h"
00034 #include "jbltools/sfh/SFROList.h"
00035 #include "jbltools/sfh/SFCutROList.h"
00036 #include "jbltools/sfh/FloatFun.h"
00037 #include "jbltools/sfh/BinningFun.h"
00038 #include "jbltools/sfh/FloatFunBinning.h"
00039 #include "jbltools/sfh/FillIterator.h"
00040 #include "jbltools/sfh/BaseCut.h"
00041 #include "jbltools/sfh/IntFun.h"
00042 #include "jbltools/sfh/FloatFun.h"
00043 #include "jbltools/sfh/Binning.h"
00044 #include "jbltools/sfh/NamedBinning.h"
00045 #include "jbltools/sfh/JBLParserResult.h"
00046
00047 ClassImp(MaranaEventLoop)
00048
00049 MaranaEventLoop::MaranaEventLoop(const TRunHisto& run,string Tag,string textfile)
00050 {
00051
00052 sysfun = new MarSysBinningFun (run.Syst, run.output_file_root);
00053 syscut = &(*sysfun == 0);
00054 syscut->setName("syscut");
00055 rolist = 0;
00056 fillrolist = new SFROList();
00057
00058
00059 debug=run.debug;
00060
00061 NumSelEve=0;
00062 NumEve=0;
00063 NumSelEvePerRun=0;
00064 NumSelEvePerRunOld=0;
00065 fp=NULL;
00066 hatCopy=NULL;
00067 modsCopy=NULL;
00068
00069
00070 if(textfile!=""){
00071
00072 if ((fp = fopen(textfile.c_str(),"w+")) == NULL) {
00073 cout << "THisto::THisto : error in opening "<< textfile <<endl;
00074 }
00075 }
00076
00077 ReadParameters(run.histo_par_file,Tag,0);
00078
00079
00080 TList* dir=run.output_file_root->GetListOfKeys();
00081 for(int i=0;i<dir->GetSize();i++){
00082 cout << "--> Create histo in dir "<< dir->At(i)->GetName() << endl;
00083 run.output_file_root->cd(dir->At(i)->GetName());
00084
00085 ReadParameters(run.histo_par_file,Tag,i+1);
00086 }
00087 run.output_file_root->cd();
00088
00089
00090
00091 if(run.out_file_mods_hat!=""){
00092
00093
00094 for(list<string>::const_iterator itag=run.TagToBeWritten.begin();itag!=run.TagToBeWritten.end();itag++)
00095 {
00096
00097
00098 if((*itag)==Tag){
00099 string dir="";
00100 string file="";
00101 unsigned int pos=run.out_file_mods_hat.rfind("/");
00102 if(pos!=string::npos){
00103 dir=run.out_file_mods_hat.substr(0,pos+1);
00104 file=run.out_file_mods_hat.substr(pos+1) ;
00105
00106 } else {
00107 file=run.out_file_mods_hat;
00108
00109 }
00110
00111
00112 if ( gH1Tree->GetChain(3)) {
00113 string hatname;
00114
00115 hatname=dir+"HAT."+Tag+"."+file;
00116 cout << "\n--> output hat: "<< hatname<<endl;
00117
00118 hatCopy = gH1Tree->CopyTree("HAT", hatname.c_str() );
00119 if (!hatCopy) throw string("THisto::THisto= could not copy HAT-tree!");
00120
00121
00122 }
00123
00124 if ( gH1Tree->GetChain(2) ) {
00125 string modsname;
00126 modsname=dir+"MODS."+Tag+"."+file;
00127 cout << "\n--> output mods: "<< modsname<<endl;
00128
00129 modsCopy = gH1Tree->CopyTree("MODS", modsname.c_str());
00130 if (!modsCopy)throw string("THisto::THisto= could not copy MODS-tree!");
00131 }
00132 }
00133
00134 }
00135 }
00136
00137 }
00138
00139 MaranaEventLoop::~MaranaEventLoop()
00140 {}
00141
00142
00143 void MaranaEventLoop::Fill()
00144 {
00145
00146 fillrolist->Fill();
00147 return;
00148 }
00149
00150 void MaranaEventLoop::Draw(TPad *pad, TVirtualPS *ps,
00151 Option_t *option,
00152 bool across,
00153 Int_t nx, Int_t ny,
00154 bool log, bool recursive) {
00155 if (fillrolist)
00156 fillrolist->Draw(pad, ps, option, across, nx, ny, log, recursive);
00157 }
00158
00159
00160
00161 bool MaranaEventLoop::ParseHistos(istringstream& inParams, string&type, Int_t hoffset,
00162 string Tag, list<string>& PartTags,const Short_t SysNum)
00163 {
00164
00165 rolist = new SFCutROList (fillrolist);
00166
00167
00168 bool stop=false;
00169 string item;
00170 string end="end_";
00171 char line[1024];
00172 while (!stop && inParams.getline(line, 1024)) {
00173 istringstream linestream(line);
00174 item = "";
00175 linestream >> item;
00176
00177 if(item=="h1f") {
00178 ReadParamsh1f(linestream,type,hoffset,SysNum,kFALSE);
00179 }
00180 else if(item=="h1f_sys"){
00181 ReadParamsh1f(linestream,type,hoffset,SysNum,kTRUE);
00182 }
00183 else if(item=="h2f"){
00184 ReadParamsh2f(linestream,type,hoffset,SysNum,kFALSE);
00185 }
00186 else if(item=="h2f_sys"){
00187 ReadParamsh2f(linestream,type,hoffset,SysNum,kTRUE);
00188 }
00189
00190 else if(item=="h1fgeneric") {
00191 ReadParamsh1fgeneric(linestream,type,hoffset,PartTags,SysNum,kFALSE);
00192 }
00193 else if(item=="h1fgeneric_sys") {
00194 ReadParamsh1fgeneric(linestream,type,hoffset,PartTags,SysNum,kTRUE);
00195 }
00196
00197
00198 else if(item=="2dbin"){
00199 ReadParams2dbin(linestream,type,hoffset,SysNum);
00200 }
00201
00202
00203 else if(item=="1binfh1f"){
00204 ReadParams1binfh1f(linestream,type,hoffset,SysNum,kFALSE);
00205 }
00206 else if(item=="1binfh1f_sys"){
00207 ReadParams1binfh1f(linestream,type,hoffset,SysNum,kTRUE);
00208 }
00209
00210 else if(item=="1binvbh1f"){
00211 ReadParams1binVarSizeh1f(linestream,type,hoffset,SysNum,kFALSE);
00212 }
00213 else if(item=="1binvbh1f_sys"){
00214 ReadParams1binVarSizeh1f(linestream,type,hoffset,SysNum,kTRUE);
00215 }
00216
00217 else if(item=="1binvh1f"){
00218 ReadParams1binvh1f(linestream,type,hoffset,SysNum,kFALSE);
00219 }
00220 else if(item=="1binvh1f_sys"){
00221 ReadParams1binvh1f(linestream,type,hoffset,SysNum,kTRUE);
00222 }
00223
00224 else if(item=="2binfh1f"){
00225 ReadParams2binfh1f(linestream,type,hoffset,SysNum,kFALSE);
00226 }
00227 else if(item=="2binfh1f_sys"){
00228 ReadParams2binfh1f(linestream,type,hoffset,SysNum,kTRUE);
00229 }
00230
00231 else if(item=="2binvh1f"){
00232 ReadParams2binvh1f(linestream,type,hoffset,SysNum,kFALSE);
00233 }
00234 else if(item=="2binvh1f_sys"){
00235 ReadParams2binvh1f(linestream,type,hoffset,SysNum,kTRUE);
00236 }
00237 else if (item=="sfh1f"){
00238
00239 ReadParamssfh1f(linestream,type,hoffset,SysNum,kFALSE);
00240 }
00241 else if (item=="sfh1f_sys"){
00242
00243 ReadParamssfh1f(linestream,type,hoffset,SysNum,kTRUE);
00244 }
00245 else if (item=="sfhprof"){
00246
00247 ReadParamssfhprof(linestream,type,hoffset,SysNum,kFALSE);
00248 }
00249 else if (item=="sfhprof_sys"){
00250
00251 ReadParamssfhprof(linestream,type,hoffset,SysNum,kTRUE);
00252 }
00253 else if (item=="sfh2f"){
00254
00255 ReadParamssfh2f(linestream,type,hoffset,SysNum,kFALSE);
00256 }
00257 else if (item=="sfh2f_sys"){
00258
00259 ReadParamssfh2f(linestream,type,hoffset,SysNum,kTRUE);
00260 }
00261 else if (item=="sfseth1f"){
00262
00263 ReadParamssfseth1f(linestream,type,hoffset,SysNum,kFALSE);
00264 }
00265 else if (item=="sfseth1f_sys"){
00266
00267 ReadParamssfseth1f(linestream,type,hoffset,SysNum,kTRUE);
00268 }
00269 else if (item=="def"){
00270
00271 ReadParamsdef(linestream,SysNum);
00272 }
00273 else if (item=="bin"){
00274
00275 ReadParamsbin(linestream,SysNum);
00276 }
00277 else if (item=="typecut"){
00278 cout << "assigning cut to type" << endl;
00279 ReadParamstypecut(linestream,type);
00280 }
00281 else if (item == end + Tag) {
00282 stop = true;
00283 }
00284
00285 }
00286 return stop;
00287 }
00288
00289
00290
00291 void MaranaEventLoop::ReadParamssfh1f(istream &inParams, const string& type, Int_t hoffset, Short_t SysNum, Bool_t BookforSys)
00292 {
00294
00296
00297 if (SysNum != 0) return;
00298
00299 int num=0;
00300 string name, comment;
00301 string xfun, cut, wfun;
00302
00303 inParams >> num >> name;
00304 cout << "MaranaEventLoop::ReadParamssfh1f: reading parameters\n";
00305 cout << " num=" << num << "\n";
00306 cout << " name='" << name << "'\n";
00307 num += hoffset;
00308
00309
00310 comment = ReadString (inParams);
00311 cout << " comment='" << comment << "'\n";
00312
00313 Binning *binning = ReadBinningInfo (inParams);
00314 if (!binning) {
00315 cerr << "MaranaEventLoop::ReadParamssfh1f: Cannot read binning!" << endl;
00316 return;
00317 }
00318
00319 xfun = ReadString (inParams);
00320 cut = ReadString (inParams);
00321 wfun = ReadString (inParams);
00322
00323 cout << " xfun='" << xfun << "'\n";
00324 cout << " cut='" << cut << "'\n";
00325 cout << " wfun='" << wfun << "'\n";
00326
00327
00328 name="h"+type+name;
00329 comment=comment+" ("+type+")";
00330 if(SysNum==0) cout << num <<" " <<name <<" : "<< comment << endl;
00331
00332 FloatFun *xf;
00333 BaseCut *c;
00334 FloatFun *wf;
00335 FillIterator *it;
00336
00337 if(SysNum==0) {
00338 if (BookforSys) {
00339 cout << "ParseHistos: Creating SFSetOfHistograms" << endl;
00340 SFSetOfHistograms *sh = new SFSetOfHistograms (name.c_str(),
00341 comment.c_str(), *binning,
00342 rolist, xfun, cut, wfun, *sysfun, 0);
00343 xf = sh->getXFun();
00344 c = sh->getCut();
00345 wf = sh->getWFun();
00346 it = sh->getIter();
00347 }
00348 else {
00349 BaseCut *bc = BaseCutPoR(cut).pbc;
00350 BaseCut *thecut;
00351 if (bc) thecut = &(*syscut && *bc);
00352 else thecut = syscut;
00353 cout << "ParseHistos: Creating SFH1F" << endl;
00354 SFH1F *h = new SFH1F (name.c_str(),
00355 comment.c_str(), *binning,
00356 rolist, xfun, thecut, 0);
00357 xf = h->getXFun();
00358 c = h->getCut();
00359 wf = h->getWFun();
00360 it = h->getIter();
00361
00362 }
00363 if (xf) cout << " ParseHistos: XFun = " << xf->getName() << endl;
00364 if (c) cout << " ParseHistos: Cut = " << c->getName() << endl;
00365 if (wf) cout << " ParseHistos: WFun = " << wf->getName() << endl;
00366 if (it) cout << " ParseHistos: Iter = " << it->getName() << endl;
00367 delete binning;
00368 }
00369
00370 return;
00371 }
00372
00373 void MaranaEventLoop::ReadParamssfhprof(istream &inParams, const string& type, Int_t hoffset, Short_t SysNum, Bool_t BookforSys)
00374 {
00376
00378
00379 if (SysNum != 0) return;
00380
00381 int num=0;
00382 string name, comment;
00383 string xfun, yfun, cut, wfun;
00384 float ylow, yup;
00385 string option;
00386
00387 inParams >> num >> name;
00388 cout << "MaranaEventLoop::ReadParamssfhprof: reading parameters\n";
00389 cout << " num=" << num << "\n";
00390 cout << " name='" << name << "'\n";
00391 num += hoffset;
00392
00393 comment = ReadString (inParams);
00394 cout << " comment='" << comment << "'\n";
00395
00396 Binning *binning = ReadBinningInfo (inParams);
00397 if (!binning) {
00398 cerr << "MaranaEventLoop::ReadParamssfhprof: Cannot read binning!" << endl;
00399 return;
00400 }
00401
00402 inParams >> ylow >> yup;
00403 option = ReadString (inParams);
00404
00405 xfun = ReadString (inParams);
00406 yfun = ReadString (inParams);
00407 cut = ReadString (inParams);
00408 wfun = ReadString (inParams);
00409
00410 cout << " ylow= " << ylow << "'\n";
00411 cout << " yup= " << yup << "'\n";
00412 cout << " option='" << option << "'\n";
00413 cout << " xfun= '" << xfun << "'\n";
00414 cout << " yfun= '" << yfun << "'\n";
00415 cout << " cut= '" << cut << "'\n";
00416 cout << " wfun= '" << wfun << "'\n";
00417
00418
00419 name="h"+type+name;
00420 comment=comment+" ("+type+")";
00421 if(SysNum==0) cout << num <<" " <<name <<" : "<< comment << endl;
00422
00423 FloatFun *xf;
00424 FloatFun *yf;
00425 BaseCut *c;
00426 FloatFun *wf;
00427 FillIterator *it;
00428
00429 if(SysNum==0) {
00430 if (BookforSys) {
00431 cout << "ParseHistos: Creating SFSetOfHProf" << endl;
00432 SFSetOfHProf *sh = new SFSetOfHProf (name.c_str(),
00433 comment.c_str(), *binning, ylow, yup, option.c_str(),
00434 rolist, xfun, yfun, cut, wfun, *sysfun, 0);
00435 xf = sh->getXFun();
00436 yf = sh->getYFun();
00437 c = sh->getCut();
00438 wf = sh->getWFun();
00439 it = sh->getIter();
00440 }
00441 else {
00442 BaseCut *bc = BaseCutPoR(cut).pbc;
00443 BaseCut *thecut;
00444 if (bc) thecut = &(*syscut && *bc);
00445 else thecut = syscut;
00446 cout << "ParseHistos: Creating SFHProf" << endl;
00447 SFHProf *h = new SFHProf (name.c_str(),
00448 comment.c_str(), *binning, ylow, yup, option.c_str(),
00449 rolist, xfun, yfun, thecut, wfun);
00450 xf = h->getXFun();
00451 yf = h->getYFun();
00452 c = h->getCut();
00453 wf = h->getWFun();
00454 it = h->getIter();
00455
00456 }
00457 if (xf) cout << " ParseHistos: XFun = " << xf->getName() << endl;
00458 if (yf) cout << " ParseHistos: YFun = " << yf->getName() << endl;
00459 if (c) cout << " ParseHistos: Cut = " << c->getName() << endl;
00460 if (wf) cout << " ParseHistos: WFun = " << wf->getName() << endl;
00461 if (it) cout << " ParseHistos: Iter = " << it->getName() << endl;
00462 delete binning;
00463 }
00464
00465 return;
00466 }
00467
00468 void MaranaEventLoop::ReadParamssfh2f(istream &inParams, const string& type, Int_t hoffset, Short_t SysNum, Bool_t BookforSys)
00469 {
00471
00473
00474 if (SysNum != 0) return;
00475
00476 int num=0;
00477 string name, comment;
00478 string xfun, yfun, cut, wfun;
00479
00480 inParams >> num >> name;
00481 cout << "MaranaEventLoop::ReadParamssfh2f: reading parameters\n";
00482 cout << " num=" << num << "\n";
00483 cout << " name='" << name << "'\n";
00484 num += hoffset;
00485
00486 comment = ReadString (inParams);
00487 cout << " comment='" << comment << "'\n";
00488
00489 Binning *xbinning = ReadBinningInfo (inParams);
00490 if (!xbinning) {
00491 cerr << "MaranaEventLoop::ReadParamssfh2f: Cannot read x binning!" << endl;
00492 return;
00493 }
00494
00495 Binning *ybinning = ReadBinningInfo (inParams);
00496 if (!ybinning) {
00497 cerr << "MaranaEventLoop::ReadParamssfh2f: Cannot read y binning!" << endl;
00498 return;
00499 }
00500
00501 xfun = ReadString (inParams);
00502 yfun = ReadString (inParams);
00503 cut = ReadString (inParams);
00504 wfun = ReadString (inParams);
00505
00506 cout << " xfun= '" << xfun << "'\n";
00507 cout << " yfun= '" << xfun << "'\n";
00508 cout << " cut= '" << cut << "'\n";
00509 cout << " wfun= '" << wfun << "'\n";
00510
00511
00512 name="h"+type+name;
00513 comment=comment+" ("+type+")";
00514 if(SysNum==0) cout << num <<" " <<name <<" : "<< comment << endl;
00515
00516 FloatFun *xf;
00517 FloatFun *yf;
00518 BaseCut *c;
00519 FloatFun *wf;
00520 FillIterator *it;
00521
00522 if(SysNum==0) {
00523 if (BookforSys) {
00524 cout << "ParseHistos: Creating SFSetOfH2F" << endl;
00525 SFSetOfH2F *sh = new SFSetOfH2F (name.c_str(),
00526 comment.c_str(), *xbinning, *ybinning,
00527 rolist, xfun, yfun, cut, wfun, *sysfun);
00528 xf = sh->getXFun();
00529 yf = sh->getYFun();
00530 c = sh->getCut();
00531 wf = sh->getWFun();
00532 it = sh->getIter();
00533 }
00534 else {
00535 BaseCut *bc = BaseCutPoR(cut).pbc;
00536 BaseCut *thecut;
00537 if (bc) thecut = &(*syscut && *bc);
00538 else thecut = syscut;
00539 cout << "ParseHistos: Creating SFH2F" << endl;
00540 SFH2F *h = new SFH2F (name.c_str(),
00541 comment.c_str(), *xbinning, *ybinning,
00542 rolist, xfun, yfun, thecut, wfun);
00543 xf = h->getXFun();
00544 yf = h->getYFun();
00545 c = h->getCut();
00546 wf = h->getWFun();
00547 it = h->getIter();
00548
00549 }
00550 if (xf) cout << " ParseHistos: XFun = " << xf->getName() << endl;
00551 if (yf) cout << " ParseHistos: YFun = " << yf->getName() << endl;
00552 if (c) cout << " ParseHistos: Cut = " << c->getName() << endl;
00553 if (wf) cout << " ParseHistos: WFun = " << wf->getName() << endl;
00554 if (it) cout << " ParseHistos: Iter = " << it->getName() << endl;
00555 delete xbinning;
00556 delete ybinning;
00557 }
00558
00559 return;
00560 }
00561
00562
00563 void MaranaEventLoop::ReadParamsdef(istream &inParams, Short_t SysNum)
00564 {
00566
00568
00569 if (SysNum != 0) return;
00570
00571 string name;
00572
00573 inParams >> name;
00574
00575
00576
00577 JBLParserResult definition;
00578 inParams >> definition;
00579
00580
00581 if (definition.isIntFun()) {
00582 IntFun& fun = *definition.getIntFunValue();
00583 fun.setName(name);
00584 cout << "Definition of new FloatFun '" << fun.getName() << "', definition " << fun.getDefinition() << endl;
00585 } else if (definition.isFloatFun()) {
00586 FloatFun& fun = *definition.getFloatFunValue();
00587 assert (&fun);
00588 fun.setName(name);
00589 cout << "Definition of new FloatFun '" << fun.getName() << "', definition " << fun.getDefinition() << endl;
00590 } else if (definition.isBaseCut()) {
00591 BaseCut& cut = *definition.getBaseCutValue();
00592 assert (&cut);
00593 cut.setName(name);
00594 cout << "Definition of new BaseCut '" << cut.getName() << "', definition " << cut.getDefinition() << endl;
00595 } else if (definition.isInt()) {
00596 IntFun& fun = *new ConstIntFun (definition.getIntValue(), name);
00597 cout << "Definition of new Integer '" << fun.getName() << "', definition " << fun.getDefinition() << endl;
00598 } else if (definition.isFloat()) {
00599 FloatFun& fun = *new ConstFun (definition.getFloatValue(), name);
00600 cout << "Definition of new Float '" << fun.getName() << "', definition " << fun.getDefinition() << endl;
00601 } else if (definition.isBool()) {
00602 BaseCut& fun = *new ConstBaseCut (definition.getBoolValue(), name);
00603 cout << "Definition of new Bool '" << fun.getName() << "', definition " << fun.getDefinition() << endl;
00604 }
00605 else cerr << "MaranaEventLoop::ReadParamsdef: Cannot define '" << name << "'\n";
00606 return;
00607 }
00608
00609 void MaranaEventLoop::ReadParamssfseth1f(istream &inParams, const string& type, Int_t hoffset, Short_t SysNum, Bool_t BookforSys)
00610 {
00612
00614
00615 if (SysNum != 0) return;
00616
00617 int num=0;
00618 string name, comment;
00619 string xfun, cut, wfun;
00620
00621 inParams >> num >> name;
00622 cout << "MaranaEventLoop::ReadParamssfseth1f: reading parameters\n";
00623 cout << " num=" << num << "\n";
00624 cout << " name='" << name << "'\n";
00625 num += hoffset;
00626
00627 comment = ReadString (inParams);
00628 cout << " comment='" << comment << "'\n";
00629
00630 Binning *axisbinning = ReadBinningInfo (inParams);
00631 if (!axisbinning) {
00632 cerr << "MaranaEventLoop::ReadParamssfseth1f: Cannot read binning!" << endl;
00633 return;
00634 }
00635
00636 xfun = ReadString (inParams);
00637 cut = ReadString (inParams);
00638 wfun = ReadString (inParams);
00639
00640 cout << " xfun='" << xfun << "'\n";
00641 cout << " cut=" << cut << "\n";
00642 cout << " wfun=" << wfun << "\n";
00643
00644 BinningFun *binningfun = ReadBinningFunInfo (inParams);
00645 if (!binningfun) {
00646 cerr << "MaranaEventLoop::ReadParamssfseth1f: Cannot read binning function!" << endl;
00647 return;
00648 }
00649
00650 name="h"+type+name;
00651 comment=comment+" ("+type+")";
00652 if(SysNum==0) cout << num <<" " <<name <<" : "<< comment << endl;
00653 FloatFun *xf;
00654 BaseCut *c;
00655 FloatFun *wf;
00656 FillIterator *it;
00657
00658 if(SysNum==0) {
00659 if (BookforSys) {
00660 cout << "ParseHistos: Creating SFMatrixOfHistograms" << endl;
00661 SFMatrixOfHistograms *mh = new SFMatrixOfHistograms (name.c_str(),
00662 comment.c_str(), *axisbinning,
00663 rolist, xfun, cut, wfun, *sysfun, *binningfun);
00664 xf = mh->getXFun();
00665 c = mh->getCut();
00666 wf = mh->getWFun();
00667 it = mh->getIter();
00668 }
00669 else {
00670 BaseCut *bc = BaseCutPoR(cut).pbc;
00671 BaseCut *thecut;
00672 if (bc) thecut = &(*syscut && *bc);
00673 else thecut = syscut;
00674 cout << "ParseHistos: Creating SFSetOfHistograms" << endl;
00675 SFSetOfHistograms *sh = new SFSetOfHistograms (name.c_str(),
00676 comment.c_str(), *axisbinning,
00677 rolist, xfun, thecut, wfun, *binningfun);
00678
00679 xf = sh->getXFun();
00680 c = sh->getCut();
00681 wf = sh->getWFun();
00682 it = sh->getIter();
00683 }
00684 if (xf) cout << " ParseHistos: XFun = " << xf->getName() << endl;
00685 if (c) cout << " ParseHistos: Cut = " << c->getName() << endl;
00686 if (wf) cout << " ParseHistos: WFun = " << wf->getName() << endl;
00687 if (it) cout << " ParseHistos: Iter = " << it->getName() << endl;
00688 delete axisbinning;
00689 }
00690
00691 return;
00692 }
00693
00694
00695 void MaranaEventLoop::ReadParamsbin(istream &inParams, Short_t SysNum)
00696 {
00698
00700
00701 if (SysNum != 0) return;
00702
00703 string name;
00704
00705 inParams >> name;
00706 cout << "MaranaEventLoop::ReadParamsbin: reading parameters\n";
00707 cout << " name='" << name << "'\n";
00708
00709 Binning *binning = ReadBinningInfo (inParams);
00710 if (!binning) {
00711 cerr << "MaranaEventLoop::ReadParamsbin: Cannot create binning!";
00712 }
00713
00714 NamedBinning& result = *new NamedBinning(*binning, name);
00715 delete binning;
00716 std::string definition = "";
00717 if (result.isEquidistant()) {
00718 definition = NamedO::str('(')+NamedO::str(result.getNBins())+", "
00719 +NamedO::str(result.getLowerEdge())+", "+NamedO::str(result.getUpperEdge())+')';
00720 }
00721 else {
00722 definition = NamedO::str('{');
00723 for (int i = 0; i < result.getNBins(); i++)
00724 definition += NamedO::str(result.getLowerBinEdge(i))+", ";
00725 definition += NamedO::str(result.getUpperEdge())+'}';
00726 }
00727 result.setDefinition(definition);
00728 cout << "created binning " << result << endl;
00729 return;
00730 }
00731
00732 void MaranaEventLoop::ReadParamstypecut(istream &inParams, const string& type) {
00733 cout << "ReadParamstypecut, type='" << type << "'" << endl;
00734 bool doesapply = false;
00735 string thistype;
00736 string cut;
00737 do {
00738 thistype = ReadString (inParams, ',');
00739 cout << " ...type = '" << thistype << "', peek=" << inParams.peek() << endl;
00740 if (thistype == type) doesapply = true;
00741 if (inParams.peek()!=',') break;
00742 inParams.get();
00743 } while (inParams);
00744 cut = ReadString (inParams);
00745 if (doesapply && rolist) {
00746 cout << " cut '" << cut << "' applies to type '" << type << "'" << endl;
00747 BaseCutPoR newcut(cut);
00748 BaseCut *oldcut = rolist->getCut();
00749 if (newcut.pbc) {
00750 cout << " Additional cut is '" << newcut.pbc->getName() << "'" << endl;
00751 if (oldcut) {
00752 cout << " Old cut is '" << oldcut->getName() << "'" << endl;
00753 rolist->setCut(*oldcut && *newcut.pbc);
00754 }
00755 else {
00756 rolist->setCut(newcut.pbc);
00757 }
00758 }
00759 if (rolist->getCut())
00760 cout << " Cut is now '" << rolist->getCut()->getName() << "'." << endl;
00761 }
00762 }
00763
00764 Binning *MaranaEventLoop::ReadBinningInfo (istream &is) {
00765 Binning *result = 0;
00766 cout << "MaranaEventLoop::ReadBinningInfo starting..." << endl;
00767 std::string word;
00768
00769
00770
00771 while (isblank(is.peek())) is.get();
00772
00773 if (is.peek() == '{') {
00774 cout << "parsing non-equidistant binning" << endl;
00775
00776 is.get();
00777 double d = 0;
00778 std::vector<double> boundaries;
00779 while (is && is.peek() != '}') {
00780 is >> d;
00781 cout << " boundary " << d << endl;
00782 boundaries.push_back(d);
00783 while (isblank(is.peek())) is.get();
00784 if (is.peek() == ',') is.get();
00785 while (isblank(is.peek())) is.get();
00786 }
00787 if (!is) {
00788 cerr << "Error in MaranaEventLoop::ReadBinningInfo: "
00789 << "encountered input end before '}' was found!" << endl;
00790 }
00791 else {
00792
00793 is.get();
00794 }
00795 if (boundaries.size() > 1) {
00796 result = new Binning (boundaries.size()-1, &(boundaries[0]));
00797 }
00798 else {
00799 cerr << "Error in MaranaEventLoop::ReadBinningInfo: "
00800 << "Less than 2 bin boundaries found!" << endl;
00801 }
00802 }
00803 else if (isdigit(is.peek()) || is.peek() == '.') {
00804 cout << "parsing equidistant binning" << endl;
00805 int nbins;
00806 double xlow, xup;
00807 is >> nbins >> xlow >> xup;
00808 cout << " nbins = " << nbins
00809 << ", xlow = " << xlow << ", xup " << xup << endl;
00810 result = new Binning (nbins, xlow, xup);
00811 }
00812 else {
00813 cout << "parsing named binning" << endl;
00814 std::string identifier;
00815 is >> identifier;
00816 NamedBinning *def = NamedBinning::getObject(identifier);
00817 if (def) {
00818 result = new Binning (*def);
00819 cout << " found " << *def << endl;
00820 }
00821 else {
00822 cerr << "Error in MaranaEventLoop::ReadBinningInfo: "
00823 << "Cannot find named binning '" << identifier << "'!" << endl;
00824 }
00825 }
00826 return result;
00827 }
00828
00829 BinningFun *MaranaEventLoop::ReadBinningFunInfo (istream &is) {
00830 BinningFun *result = 0;
00831 FloatFun *fun = 0;
00832 cout << "MaranaEventLoop::ReadBinningFunInfo starting..." << endl;
00833
00834
00835 while (isblank(is.peek())) is.get();
00836
00837 if (is.peek() == '[') {
00838 is.get();
00839 cout << " parsing FloatFun definition\n";
00840
00841 std::string word;
00842 is >> word;
00843
00844 JBLParserResult definition = JBLParserResult::parseExpression (word);
00845 cout << " definition='" << definition << "'\n";
00846
00847 if (definition.isFloatFun()) {
00848 fun = definition.getFloatFunValue();
00849 cout << " Found FloatFun '" << fun->getName() << "', definition " << fun->getDefinition() << endl;
00850 }
00851 else {
00852 cerr << "MaranaEventLoop::ReadBinningFunInfo: Expected a '" << definition.getName()
00853 << "' to be a FloatFun definition!\n";
00854 return 0;
00855 }
00856
00857 Binning *binning = ReadBinningInfo(is);
00858
00859 if (!binning) {
00860 cerr << "MaranaEventLoop::ReadBinningFunInfo: Expected a binning here!\n";
00861 return 0;
00862 }
00863
00864 result = new FloatFunBinning (*fun, *binning, fun->getName());
00865
00866
00867 while (isblank(is.peek())) is.get();
00868
00869 if (is.peek() == ']') {
00870 is.get();
00871 }
00872 else {
00873 cerr << "MaranaEventLoop::ReadBinningFunInfo: Expected a ']' instead of " << is.peek() << "!\n";
00874 return result;
00875 }
00876 }
00877 else {
00878 cerr << "MaranaEventLoop::ReadBinningFunInfo: Cannot handle named FloatFunBinnings yet!\n";
00879 return 0;
00880 }
00881 return result;
00882 }
00883
00884
00885 std::string MaranaEventLoop::ReadString (istream &is, char delim) {
00886 std::string result;
00887
00888
00889 while (is && isblank(is.peek())) is.get();
00890
00891 if (is && is.peek() == '\047') {
00892
00893 is.get();
00894 while (is && isblank(is.peek())) is.get();
00895 while (is && is.peek() != '\047' && is.peek()!='\377') result += is.get();
00896 if (is && is.peek()!='\377') is.get();
00897 }
00898 else if (is && is.peek() == '"') {
00899
00900 is.get();
00901 while (is && isblank(is.peek())) is.get();
00902 while (is && is.peek() != '"' && is.peek()!='\377') result += is.get();
00903 if (is && is.peek()!='\377') is.get();
00904 }
00905 else {
00906
00907 while (is && !isblank(is.peek()) && is.peek()!=delim && is.peek()!='\377') result += is.get();
00908 }
00909
00910 while (is && isblank(is.peek())) is.get();
00911
00912
00913 string::size_type pos = result.find_last_not_of (' ');
00914 if (pos != string::npos) result.erase (pos+1);
00915 return result;
00916 }