ROOT logo
#include "hflexfiller.h"
#include "hades.h"
#include "haddef.h"
#include "hruntimedb.h"
#include "hevent.h"
#include "hcategorymanager.h"

#include <iostream>

using namespace std;



//_HADES_CLASS_DESCRIPTION
////////////////////////////////////////////////////////////////////////////////
//
//
// HFlexFiller
//
// This HReconstructor allows the user to plugin a private fill function
// defined in a macro into the Hades eventloop with full access to all data levels.
// The user can fill the category of HFlex objects.
//
// The user can provide his own selection fill via
// setUserFill(Int_t (*function)(HHistMap*,TObjArray* ),HHistMap* hM=0,TObjArray* params=0,Bool_t createMap=kTRUE)
// Parameters for the function can be passed via the TObjArray from the macro.
// Histogram pointers can be passed by HHistMap
// If the pointers are NULL they are simply ignored.
//
//----------------------------------------------
// example:
//
//
//Int_t fillFlex(HHistMap* hM=0,TObjArray* pars=0){
//
//
//    HCategory* candCat  = (HCategory*)HCategoryManager::getCategory(catParticleCand ,kTRUE ,"catParticleCand");
//    HCategory* flexCat  = (HCategory*)HCategoryManager::getCategory(catFlex         ,kTRUE ,"catFlex");
//
//    if(!flexCat) { cout<<"NO FlexCat!"<<endl; }
//    if(!candCat) { cout<<"NO candCat!"<<endl; }
//
//    if(candCat&&flexCat)
//    {
//      HLocation loc; // dummy loc object
//	HFlex fl;
//	fl.addVars("candInd=-1","chi2=-1");  // some variables  + init values
//
//	Int_t n = candCat->getEntries();
//	for(Int_t i=0; i < n; i++){
//
//	    HParticleCand* cand = HCategoryManager::getObject(cand,candCat,i);
//	    if(cand){
//
//		Int_t   ind  = cand->getIndex();
//                Float_t chi2 = cand->getChi2();
//                HFlex* flex = 0;
//                Int_t index;
//
//		flex = (HFlex*) flexCat->getNewSlot(loc,&index);
//       	if(flex){
//		    flex = new (flex) HFlex(fl);
//
//		    flex->setI("candInd",ind);
//                    flex->setD("chi2"   ,chi2);
//
//		}
//
//		if(hM){
//                  if(hM->get("chi2")) hM->get("chi2")->Fill(chi2);
//		}
//
//	    }
//
//	} // end loop candidates
//
//
//   }
//    return 0;
//}
//
//
// int dst(){
//
//    .... hades dst macro....
//
//
//
//    HHistMap hM("testHists.root");                              // set output file for hists
//    hM.addHist(new TH1F("chi2","chi2",1000,0,1000),"tracking"); // hist will be written to directory "tracking"
//
//
//    HFlexFiller* flexfiller = new HFlexFiller("FlexFiller","FlexFiller");
//    flexfiller->setUserFill(fillFlex,&hM);                      // connect your private function
//
//
//    .......
//
//
//    // add recontructor to the end of the tasklist
//    masterTaskSet->add(flexfiller);                             // connect the filler
//
//
//    gHades->init();                                             // init params etc
//    gHades->eventLoop(nEvents,startEvt);                        // loop over events. the function will called for each event
//
//    hM.writeHists();                                            // store the hists
//
//    delete gHades;
// }
//
////////////////////////////////////////////////////////////////////////////////

ClassImp(HFlexFiller)


HFlexFiller::HFlexFiller(void)
    : HReconstructor("FlexFiller", "User fill of HFlex category")
{
    clear();
}

HFlexFiller::HFlexFiller(const Text_t* name,const Text_t* title)
: HReconstructor(name, title)
{
    clear();
}

HFlexFiller::~HFlexFiller(void)
{

}

void HFlexFiller::clear()
{
    createCat = kFALSE;
    pUserFill = NULL;
    parameters= NULL;
    hM        = NULL;
}

Bool_t HFlexFiller::init(void)
{
    // create the catFlex category if needed

    if(createCat){
	if(gHades->getCurrentEvent()->getCategory(catFlex)){
	    Error("HFlexFiller::init()"," HFlexCategory exists already!");
	    exit(1);
	}


	HCategory* cat = HCategoryManager::addCategory(catFlex,"HFlex",5000,"",kTRUE);
	if (!cat) {
	    Error("HFlexFiller::init()"," Could not create HFlex category!");
	    return kFALSE;
	}
    }
    return kTRUE;
}

Int_t HFlexFiller::execute(void)
{
    // call the user funcion once per event
    if(!pUserFill) return 0; // nothing to do
    return (*pUserFill)(hM,parameters);

}

Bool_t HFlexFiller::finalize(void)
{
    return kTRUE;
}
 hflexfiller.cc:1
 hflexfiller.cc:2
 hflexfiller.cc:3
 hflexfiller.cc:4
 hflexfiller.cc:5
 hflexfiller.cc:6
 hflexfiller.cc:7
 hflexfiller.cc:8
 hflexfiller.cc:9
 hflexfiller.cc:10
 hflexfiller.cc:11
 hflexfiller.cc:12
 hflexfiller.cc:13
 hflexfiller.cc:14
 hflexfiller.cc:15
 hflexfiller.cc:16
 hflexfiller.cc:17
 hflexfiller.cc:18
 hflexfiller.cc:19
 hflexfiller.cc:20
 hflexfiller.cc:21
 hflexfiller.cc:22
 hflexfiller.cc:23
 hflexfiller.cc:24
 hflexfiller.cc:25
 hflexfiller.cc:26
 hflexfiller.cc:27
 hflexfiller.cc:28
 hflexfiller.cc:29
 hflexfiller.cc:30
 hflexfiller.cc:31
 hflexfiller.cc:32
 hflexfiller.cc:33
 hflexfiller.cc:34
 hflexfiller.cc:35
 hflexfiller.cc:36
 hflexfiller.cc:37
 hflexfiller.cc:38
 hflexfiller.cc:39
 hflexfiller.cc:40
 hflexfiller.cc:41
 hflexfiller.cc:42
 hflexfiller.cc:43
 hflexfiller.cc:44
 hflexfiller.cc:45
 hflexfiller.cc:46
 hflexfiller.cc:47
 hflexfiller.cc:48
 hflexfiller.cc:49
 hflexfiller.cc:50
 hflexfiller.cc:51
 hflexfiller.cc:52
 hflexfiller.cc:53
 hflexfiller.cc:54
 hflexfiller.cc:55
 hflexfiller.cc:56
 hflexfiller.cc:57
 hflexfiller.cc:58
 hflexfiller.cc:59
 hflexfiller.cc:60
 hflexfiller.cc:61
 hflexfiller.cc:62
 hflexfiller.cc:63
 hflexfiller.cc:64
 hflexfiller.cc:65
 hflexfiller.cc:66
 hflexfiller.cc:67
 hflexfiller.cc:68
 hflexfiller.cc:69
 hflexfiller.cc:70
 hflexfiller.cc:71
 hflexfiller.cc:72
 hflexfiller.cc:73
 hflexfiller.cc:74
 hflexfiller.cc:75
 hflexfiller.cc:76
 hflexfiller.cc:77
 hflexfiller.cc:78
 hflexfiller.cc:79
 hflexfiller.cc:80
 hflexfiller.cc:81
 hflexfiller.cc:82
 hflexfiller.cc:83
 hflexfiller.cc:84
 hflexfiller.cc:85
 hflexfiller.cc:86
 hflexfiller.cc:87
 hflexfiller.cc:88
 hflexfiller.cc:89
 hflexfiller.cc:90
 hflexfiller.cc:91
 hflexfiller.cc:92
 hflexfiller.cc:93
 hflexfiller.cc:94
 hflexfiller.cc:95
 hflexfiller.cc:96
 hflexfiller.cc:97
 hflexfiller.cc:98
 hflexfiller.cc:99
 hflexfiller.cc:100
 hflexfiller.cc:101
 hflexfiller.cc:102
 hflexfiller.cc:103
 hflexfiller.cc:104
 hflexfiller.cc:105
 hflexfiller.cc:106
 hflexfiller.cc:107
 hflexfiller.cc:108
 hflexfiller.cc:109
 hflexfiller.cc:110
 hflexfiller.cc:111
 hflexfiller.cc:112
 hflexfiller.cc:113
 hflexfiller.cc:114
 hflexfiller.cc:115
 hflexfiller.cc:116
 hflexfiller.cc:117
 hflexfiller.cc:118
 hflexfiller.cc:119
 hflexfiller.cc:120
 hflexfiller.cc:121
 hflexfiller.cc:122
 hflexfiller.cc:123
 hflexfiller.cc:124
 hflexfiller.cc:125
 hflexfiller.cc:126
 hflexfiller.cc:127
 hflexfiller.cc:128
 hflexfiller.cc:129
 hflexfiller.cc:130
 hflexfiller.cc:131
 hflexfiller.cc:132
 hflexfiller.cc:133
 hflexfiller.cc:134
 hflexfiller.cc:135
 hflexfiller.cc:136
 hflexfiller.cc:137
 hflexfiller.cc:138
 hflexfiller.cc:139
 hflexfiller.cc:140
 hflexfiller.cc:141
 hflexfiller.cc:142
 hflexfiller.cc:143
 hflexfiller.cc:144
 hflexfiller.cc:145
 hflexfiller.cc:146
 hflexfiller.cc:147
 hflexfiller.cc:148
 hflexfiller.cc:149
 hflexfiller.cc:150
 hflexfiller.cc:151
 hflexfiller.cc:152
 hflexfiller.cc:153
 hflexfiller.cc:154
 hflexfiller.cc:155
 hflexfiller.cc:156
 hflexfiller.cc:157
 hflexfiller.cc:158
 hflexfiller.cc:159
 hflexfiller.cc:160
 hflexfiller.cc:161
 hflexfiller.cc:162
 hflexfiller.cc:163
 hflexfiller.cc:164
 hflexfiller.cc:165
 hflexfiller.cc:166
 hflexfiller.cc:167
 hflexfiller.cc:168
 hflexfiller.cc:169
 hflexfiller.cc:170
 hflexfiller.cc:171
 hflexfiller.cc:172
 hflexfiller.cc:173