// JEventProcessor_danaevio.cc // // // JANA plugin writes out DANA objects to EVIO files // // // Implements JANA command-line parameters: // // EVIOFILENAME output file name, default "dana_events.evio" // EVIOBUFSIZE serialized event internal buffer size, default 100000 words // DANAEVIO specify which objects to serialize, see below for defaults // WRITEOUT specify which objects to serialize, see below for defaults // // // Specifying which objects to serialize: // // Comma-separated, case-insensitive list (best not to included embedded whitespace) // Accepts "all", "none", "truth" and "hits", as well as individual DANA object names // Use prefix "-" to invert selection, "+" also accepted // // // dana_evio_dict.xml is corresponding evio2xml dictionary // // // // Elliott Wolin, 9-Feb-2010 // // // still to do: // bank tags // optimize multi-threading // add evio to external packages // create makefile.evio // bool vs int8_t in evio? #include #include #include #include #include #include "DANA/DApplication.h" #include "TRACKING/DMCThrown.h" #include "TRACKING/DMCTrackHit.h" #include "TRACKING/DTrackTimeBased.h" #include "TRACKING/DMCTrajectoryPoint.h" #include "FCAL/DFCALTruthShower.h" #include "FCAL/DFCALHit.h" #include "BCAL/DBCALTruthShower.h" #include "BCAL/DHDDMBCALHit.h" #include "TOF/DTOFTruth.h" #include "TOF/DHDDMTOFHit.h" #include "CDC/DCDCHit.h" #include "FDC/DFDCHit.h" #include "PID/DBeamPhoton.h" #include "PID/DPhoton.h" #include "PID/DChargedTrack.h" #include "START_COUNTER/DSCHit.h" #include "START_COUNTER/DSCTruthHit.h" #include "SplitString.h" #include "evioFileChannel.hxx" #include "evioUtil.hxx" using namespace std; using namespace jana; using namespace evio; // evio output file name, use EVIOFILENAME command-line parameter to override static string evioFileName = "dana_events.evio"; // internal evio buffer size, use EVIOBUFSIZE command-line parameter to override static int evioBufSize=200000; // dana objects that can be written out in evio format and default output flag // use DANAEVIO or WRITEOUT command-line parameters to override // *** if you add to this list be sure to modify decode_object_parameters() appropriately *** static pair danaObs[] = { pair ("dmctrackhit", false), pair ("dbeamphoton", true), pair ("dmcthrown", true), pair ("dfcaltruthshower", true), pair ("dbcaltruthshower", true), pair ("dtoftruth", true), pair ("dsctruthhit", true), pair ("dmctrajectorypoint", false), pair ("dcdchit", true), pair ("dfdchit", true), pair ("dfcalhit", true), pair ("dhddmbcalhit", true), pair ("dhddmtofhit", true), pair ("dschit", true), pair ("dtracktimebased", false), pair ("dchargedtrack", false), pair ("dphoton", false), }; static map evioMap(danaObs,danaObs+sizeof(danaObs)/sizeof(danaObs[0])); // id maps for all banks needed to create indices to associated objects static map emptyMap; static pair > idPairs[] = { pair > ("dmctrackhit", emptyMap), pair > ("dbeamphoton", emptyMap), pair > ("dmcthrown", emptyMap), pair > ("dfcalthruthshower", emptyMap), pair > ("dbcalthruthshower", emptyMap), pair > ("dtoftruth", emptyMap), pair > ("dsctruthhit", emptyMap), pair > ("dmctrajectorypoint", emptyMap), pair > ("dcdchit", emptyMap), pair > ("dfdchit", emptyMap), pair > ("dfcalhit", emptyMap), pair > ("dhddmbcalhit", emptyMap), pair > ("dhddmtofhit", emptyMap), pair > ("dschit", emptyMap), pair > ("dtracktimebased", emptyMap), pair > ("dchargedtrack", emptyMap), pair > ("dphoton", emptyMap), }; static map > idMap(idPairs,idPairs+sizeof(idPairs)/sizeof(idPairs[0])); // evio bank tag definitions (totally arbitrary at the moment) static pair tagPairs[] = { pair ("danaevent", 10000), pair ("dmctrackhit", 10100), pair ("dbeamphoton", 10200), pair ("dmcthrown", 10300), pair ("dfcaltruthshower", 10400), pair ("dbcaltruthshower", 10500), pair ("dtoftruth", 10600), pair ("dsctruthhit", 10700), pair ("dmctrajectorypoint", 10800), pair ("dcdchit", 10900), pair ("dfdchit", 11000), pair ("dfcalhit", 11100), pair ("dhddmbcalhit", 11200), pair ("dhddmtofhit", 11300), pair ("dschit", 11400), pair ("dtracktimebased", 11500), pair ("dchargedtrack", 11600), pair ("dphoton", 11700), }; static map tagMap(tagPairs,tagPairs+sizeof(tagPairs)/sizeof(tagPairs[0])); // mutex needed to protect serialization and writing to file static pthread_mutex_t evioMutex = PTHREAD_MUTEX_INITIALIZER; //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- class JEventProcessor_danaevio : public JEventProcessor { private: // file channel handle evioFileChannel *chan; //---------------------------------------------------------------------------- public: const char* className(void){ return "JEventProcessor_danaevio"; } //---------------------------------------------------------------------------- JEventProcessor_danaevio() { // check for EVIOFILENAME output file name parameter gPARMS->SetDefaultParameter("EVIOFILENAME",evioFileName); jout << endl << " EVIO output file name is " << evioFileName << endl << endl; // check for DANAEVIO and WRITEOUT parameters which control which objects to output decode_object_parameters(); map::iterator iter; jout << endl << " DANA object output flags:" << endl << endl; for(iter=evioMap.begin(); iter!=evioMap.end(); iter++) { jout << " " << setiosflags(ios::left) << setw(25) << iter->first << setw(2) << iter->second << endl; } jout << endl << endl; // check for EVIOBUFSIZE internal buffer size parameter gPARMS->SetDefaultParameter("EVIOBUFSIZE",evioBufSize); jout << endl << " EVIO internal buf size is " << evioBufSize << endl << endl; // create file channel and open file try { chan = new evioFileChannel(evioFileName,"w",evioBufSize); chan->open(); } catch (evioException e) { jerr << endl << " ?evioException in JEventProcessor_danaevio" << endl << endl << e.toString() << endl; } catch (...) { jerr << endl << " ?unknown exception in JEventProcessor_danaevio, unable to open output file" << endl << endl; } } //---------------------------------------------------------------------------- ~JEventProcessor_danaevio() { // close file and delete file channel object try { chan->close(); } catch (evioException e) { jerr << endl << " ?evioException in ~JEventProcessor_danaevio" << endl << endl << e.toString() << endl; } catch (...) { jerr << endl << " ?unknown exception in ~JEventProcessor_danaevio, unable to close output file" << endl << endl; } delete(chan); } //---------------------------------------------------------------------------- private: // needed until bug fixed in jana framework ??? jerror_t fini() { chan->close(); return(NOERROR); } //---------------------------------------------------------------------------- jerror_t evnt(JEventLoop *eventLoop, int eventnumber) { static int count = 0; count++; // create evio DOM tree evioDOMTree tree(tagMap["danaevent"],0); // add various banks to tree if(evioMap["dmctrackhit" ]) addDMCTrackHit(eventLoop,tree); if(evioMap["dbeamphoton" ]) addDBeamPhoton(eventLoop,tree); if(evioMap["dmcthrown" ]) addDMCThrown(eventLoop,tree); if(evioMap["dfcaltruthshower" ]) addDFCALTruthShower(eventLoop,tree); if(evioMap["dbcaltruthshower" ]) addDBCALTruthShower(eventLoop,tree); if(evioMap["dtoftruth" ]) addDTOFTruth(eventLoop,tree); if(evioMap["dsctruthhit" ]) addDSCTruthHit(eventLoop,tree); if(evioMap["dmctrajectorypoint" ]) addDMCTrajectoryPoint(eventLoop,tree); if(evioMap["dcdchit" ]) addDCDCHit(eventLoop,tree); if(evioMap["dfdchit" ]) addDFDCHit(eventLoop,tree); if(evioMap["dfcalhit" ]) addDFCALHit(eventLoop,tree); if(evioMap["dhddmbcalhit" ]) addDHDDMBCALHit(eventLoop,tree); if(evioMap["dhddmtofhit" ]) addDHDDMTOFHit(eventLoop,tree); if(evioMap["dschit" ]) addDSCHit(eventLoop,tree); if(evioMap["dtracktimebased" ]) addDTrackTimeBased(eventLoop,tree); if(evioMap["dchargedtrack" ]) addDChargedTrack(eventLoop,tree); if(evioMap["dphoton" ]) addDPhoton(eventLoop,tree); // get lock, write out evio tree, unlock pthread_mutex_lock(&evioMutex); try { chan->write(tree); } catch (evioException e) { jerr << endl << " ?evioException in JEventProcessor_danaevio::evnt" << endl << endl << e.toString() << endl; } catch (...) { jerr << endl << " ?unknown exception in JEventProcessor_danaevio::evnt, unable to write to file" << endl << endl; } pthread_mutex_unlock(&evioMutex); // done return NOERROR; } //---------------------------------------------------------------------------- void addDMCThrown(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector mcthrowns; eventLoop->Get(mcthrowns); if(mcthrowns.size()<=0)return; // create mcthrown bank and add to event tree evioDOMNodeP mcthrown = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],0); tree << mcthrown; // create data banks and add to mcthrown evioDOMNodeP typeBank = evioDOMNode::createEvioDOMNode (tagMap["dmcthrown"],1); evioDOMNodeP pdgtypeBank = evioDOMNode::createEvioDOMNode (tagMap["dmcthrown"],2); evioDOMNodeP myidBank = evioDOMNode::createEvioDOMNode (tagMap["dmcthrown"],3); evioDOMNodeP parentidBank = evioDOMNode::createEvioDOMNode (tagMap["dmcthrown"],4); evioDOMNodeP mechBank = evioDOMNode::createEvioDOMNode (tagMap["dmcthrown"],5); evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],6); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],7); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],8); evioDOMNodeP pxBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],9); evioDOMNodeP pyBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],10); evioDOMNodeP pzBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],11); evioDOMNodeP energyBank = evioDOMNode::createEvioDOMNode(tagMap["dmcthrown"],12); *mcthrown << typeBank << pdgtypeBank << myidBank << parentidBank << mechBank << xBank << yBank << zBank << pxBank << pyBank << pzBank << energyBank; // add track data to banks idMap["dmcthrown"].clear(); for(unsigned int i=0; itype; *pdgtypeBank << mcthrowns[i]->pdgtype; *myidBank << mcthrowns[i]->myid; *parentidBank << mcthrowns[i]->parentid; *mechBank << mcthrowns[i]->mech; DVector3 pos = mcthrowns[i]->position(); *xBank << pos.X(); *yBank << pos.Y(); *zBank << pos.Z(); DVector3 mom = mcthrowns[i]->momentum(); *pxBank << mom.X(); *pyBank << mom.Y(); *pzBank << mom.Z(); *energyBank << mcthrowns[i]->energy(); idMap["dmcthrown"][mcthrowns[i]->id]=i; } } //------------------------------------------------------------------------------ void addDMCTrackHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector mctrackhits; eventLoop->Get(mctrackhits); if(mctrackhits.size()<=0)return; // create mctrackhit bank and add to event tree evioDOMNodeP mctrackhit = evioDOMNode::createEvioDOMNode(tagMap["dmctrackhit"],0); tree << mctrackhit; // create data banks and add to mctrackhit bank evioDOMNodeP rBank = evioDOMNode::createEvioDOMNode(tagMap["dmctrackhit"],1); evioDOMNodeP phiBank = evioDOMNode::createEvioDOMNode(tagMap["dmctrackhit"],2); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode(tagMap["dmctrackhit"],3); evioDOMNodeP trackBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrackhit"],4); evioDOMNodeP primaryBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrackhit"],5); evioDOMNodeP ptypeBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrackhit"],6); evioDOMNodeP systemBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrackhit"],7); *mctrackhit << rBank << phiBank << zBank << trackBank << primaryBank << ptypeBank << systemBank; // add track data to banks idMap["dmctrackhit"].clear(); for(unsigned int i=0; ir; *phiBank << mctrackhits[i]->phi; *zBank << mctrackhits[i]->z; *trackBank << mctrackhits[i]->track; *primaryBank << mctrackhits[i]->primary; *ptypeBank << mctrackhits[i]->ptype; *systemBank << mctrackhits[i]->system; idMap["dmctrackhit"][mctrackhits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDTOFTruth(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector toftruths; eventLoop->Get(toftruths); if(toftruths.size()<=0)return; // create toftruth bank and add to event tree evioDOMNodeP toftruth = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],0); tree << toftruth; // create data banks and add to toftruth bank evioDOMNodeP trackBank = evioDOMNode::createEvioDOMNode (tagMap["dtoftruth"],1); evioDOMNodeP primaryBank = evioDOMNode::createEvioDOMNode (tagMap["dtoftruth"],2); evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],3); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],4); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],5); evioDOMNodeP pxBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],6); evioDOMNodeP pyBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],7); evioDOMNodeP pzBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],8); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],9); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode(tagMap["dtoftruth"],10); evioDOMNodeP ptypeBank = evioDOMNode::createEvioDOMNode (tagMap["dtoftruth"],11); *toftruth << trackBank << primaryBank << xBank << yBank << zBank << pxBank << pyBank << pzBank << tBank << EBank << ptypeBank; // add track data to banks idMap["dtoftruth"].clear(); for(unsigned int i=0; itrack; *primaryBank << toftruths[i]->primary; *xBank << toftruths[i]->x; *yBank << toftruths[i]->y; *zBank << toftruths[i]->z; *pxBank << toftruths[i]->px; *pyBank << toftruths[i]->py; *pzBank << toftruths[i]->pz; *tBank << toftruths[i]->t; *EBank << toftruths[i]->E; *ptypeBank << toftruths[i]->ptype; idMap["dtoftruth"][toftruths[i]->id]=i; } } //------------------------------------------------------------------------------ void addDFCALTruthShower(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector fcaltruthshowers; eventLoop->Get(fcaltruthshowers); if(fcaltruthshowers.size()<=0)return; // create fcaltruthshower bank and add to event tree evioDOMNodeP fcaltruthshower = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],0); tree << fcaltruthshower; // create data banks and add to fcaltruthshower evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],1); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],2); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],3); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],4); evioDOMNodeP pxBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],5); evioDOMNodeP pyBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],6); evioDOMNodeP pzBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],7); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],8); evioDOMNodeP primaryBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],9); evioDOMNodeP trackBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],10); evioDOMNodeP typeBank = evioDOMNode::createEvioDOMNode(tagMap["dfcaltruthshower"],11); *fcaltruthshower << xBank << yBank << zBank << tBank << pxBank << pyBank<< pzBank<< EBank << primaryBank<< trackBank<< typeBank; // add track data to banks idMap["dfcaltruthshower"].clear(); for(unsigned int i=0; ix(); *yBank << fcaltruthshowers[i]->y(); *zBank << fcaltruthshowers[i]->z(); *tBank << fcaltruthshowers[i]->t(); *pxBank << fcaltruthshowers[i]->px(); *pyBank << fcaltruthshowers[i]->py(); *pzBank << fcaltruthshowers[i]->pz(); *EBank << fcaltruthshowers[i]->E(); *primaryBank << fcaltruthshowers[i]->primary(); *trackBank << fcaltruthshowers[i]->track(); *typeBank << fcaltruthshowers[i]->type(); idMap["dfcaltruthshower"][fcaltruthshowers[i]->id]=i; } } //------------------------------------------------------------------------------ void addDBCALTruthShower(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector bcaltruthshowers; eventLoop->Get(bcaltruthshowers); if(bcaltruthshowers.size()<=0)return; // create bcaltruthshower bank and add to event tree evioDOMNodeP bcaltruthshower = evioDOMNode::createEvioDOMNode(tagMap["dbcaltruthshower"],0); tree << bcaltruthshower; // create data banks and add to bcaltruthshower evioDOMNodeP trackBank = evioDOMNode::createEvioDOMNode (tagMap["dbcaltruthshower"],1); evioDOMNodeP primaryBank = evioDOMNode::createEvioDOMNode (tagMap["dbcaltruthshower"],2); evioDOMNodeP phiBank = evioDOMNode::createEvioDOMNode(tagMap["dbcaltruthshower"],3); evioDOMNodeP rBank = evioDOMNode::createEvioDOMNode(tagMap["dbcaltruthshower"],4); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode(tagMap["dbcaltruthshower"],5); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode(tagMap["dbcaltruthshower"],6); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode(tagMap["dbcaltruthshower"],7); *bcaltruthshower << trackBank << primaryBank << phiBank << rBank << zBank << tBank << EBank; // add track data to banks idMap["dbcaltruthshower"].clear(); for(unsigned int i=0; itrack; *primaryBank << bcaltruthshowers[i]->primary; *phiBank << bcaltruthshowers[i]->phi; *rBank << bcaltruthshowers[i]->r; *zBank << bcaltruthshowers[i]->z; *tBank << bcaltruthshowers[i]->t; *EBank << bcaltruthshowers[i]->E; idMap["dbcaltruthshower"][bcaltruthshowers[i]->id]=i; } } //------------------------------------------------------------------------------ void addDCDCHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector cdchits; eventLoop->Get(cdchits); if(cdchits.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP cdchit = evioDOMNode::createEvioDOMNode(tagMap["dcdchit"],0); tree << cdchit; // create data banks and add to cdchit bank evioDOMNodeP ringBank = evioDOMNode::createEvioDOMNode (tagMap["dcdchit"],1); evioDOMNodeP strawBank = evioDOMNode::createEvioDOMNode (tagMap["dcdchit"],2); evioDOMNodeP dEBank = evioDOMNode::createEvioDOMNode(tagMap["dcdchit"],3); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode(tagMap["dcdchit"],4); *cdchit << ringBank << strawBank << dEBank << tBank; // add track data to banks idMap["dcdchit"].clear(); for(unsigned int i=0; iring; *strawBank << cdchits[i]->straw; *dEBank << cdchits[i]->dE; *tBank << cdchits[i]->t; idMap["dcdchit"][cdchits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDMCTrajectoryPoint(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector mctrajectorypoints; eventLoop->Get(mctrajectorypoints); if(mctrajectorypoints.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP mctrajectorypoint = evioDOMNode::createEvioDOMNode(tagMap["dmctrajectorypoint"],0); tree << mctrajectorypoint; // create data banks and add to cdchit bank evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],1); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],2); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],3); evioDOMNodeP pxBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],4); evioDOMNodeP pyBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],5); evioDOMNodeP pzBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],6); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],7); evioDOMNodeP dEBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],8); evioDOMNodeP primary_trackBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],9); evioDOMNodeP trackBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],10); evioDOMNodeP partBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],11); evioDOMNodeP radlenBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],12); evioDOMNodeP stepBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],13); evioDOMNodeP mechBank = evioDOMNode::createEvioDOMNode (tagMap["dmctrajectorypoint"],14); *mctrajectorypoint << xBank << yBank << zBank << pxBank << pyBank << pzBank << EBank << dEBank << primary_trackBank << trackBank << partBank << radlenBank << stepBank << mechBank; // add track data to banks idMap["dmctrajectorypoint"].clear(); for(unsigned int i=0; ix; *yBank << mctrajectorypoints[i]->y; *zBank << mctrajectorypoints[i]->z; *pxBank << mctrajectorypoints[i]->px; *pyBank << mctrajectorypoints[i]->py; *pzBank << mctrajectorypoints[i]->pz; *EBank << mctrajectorypoints[i]->E; *dEBank << mctrajectorypoints[i]->dE; *primary_trackBank << mctrajectorypoints[i]->primary_track; *trackBank << mctrajectorypoints[i]->track; *partBank << mctrajectorypoints[i]->part; *radlenBank << mctrajectorypoints[i]->radlen; *stepBank << mctrajectorypoints[i]->step; *mechBank << mctrajectorypoints[i]->mech; idMap["dmctrajectorypoint"][mctrajectorypoints[i]->id]=i; } } //------------------------------------------------------------------------------ void addDFDCHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector fdchits; eventLoop->Get(fdchits); if(fdchits.size()<=0)return; // create fdchit bank and add to event tree evioDOMNodeP fdchit = evioDOMNode::createEvioDOMNode(tagMap["dfdchit"],0); tree << fdchit; // create data banks and add to fdchit bank evioDOMNodeP layerBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],1); evioDOMNodeP moduleBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],2); evioDOMNodeP elementBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],3); evioDOMNodeP planeBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],4); evioDOMNodeP gPlaneBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],5); evioDOMNodeP gLayerBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],6); evioDOMNodeP qBank = evioDOMNode::createEvioDOMNode(tagMap["dfdchit"],7); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode(tagMap["dfdchit"],8); evioDOMNodeP rBank = evioDOMNode::createEvioDOMNode(tagMap["dfdchit"],9); evioDOMNodeP typeBank = evioDOMNode::createEvioDOMNode (tagMap["dfdchit"],10); *fdchit << layerBank << moduleBank << elementBank << planeBank << gPlaneBank << gLayerBank << qBank << tBank << rBank << typeBank; // add track data to banks idMap["dfdchit"].clear(); for(unsigned int i=0; ilayer; *moduleBank << fdchits[i]->module; *elementBank << fdchits[i]->element; *planeBank << fdchits[i]->plane; *gPlaneBank << fdchits[i]->gPlane; *gLayerBank << fdchits[i]->gLayer; *qBank << fdchits[i]->q; *tBank << fdchits[i]->t; *rBank << fdchits[i]->r; *typeBank << fdchits[i]->type; idMap["dfdchit"][fdchits[i]->id]=i; } } //---------------------------------------------------------------------------- void addDBeamPhoton(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector beamphotons; eventLoop->Get(beamphotons); if(beamphotons.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP beamphoton = evioDOMNode::createEvioDOMNode(tagMap["dbeamphoton"],0); tree << beamphoton; // create data banks and add to cdchit bank evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],1); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],2); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],3); evioDOMNodeP pxBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],4); evioDOMNodeP pyBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],5); evioDOMNodeP pzBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],6); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode (tagMap["dbeamphoton"],7); *beamphoton << xBank<< yBank<< zBank<< pxBank<< pyBank<< pzBank << tBank; // add track data to banks idMap["dbeamphoton"].clear(); for(unsigned int i=0; iposition(); *xBank << pos.X(); *yBank << pos.Y(); *zBank << pos.Z(); DVector3 mom = beamphotons[i]->momentum(); *pxBank << mom.X(); *pyBank << mom.Y(); *pzBank << mom.Z(); *tBank << beamphotons[i]->t; idMap["dbeamphoton"][beamphotons[i]->id]=i; } } //------------------------------------------------------------------------------ void addDSCTruthHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector sctruthhits; eventLoop->Get(sctruthhits); if(sctruthhits.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP sctruthhit = evioDOMNode::createEvioDOMNode(tagMap["dsctruthhit"],0); tree << sctruthhit; // create data banks and add to cdchit bank evioDOMNodeP dEdxBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],1); evioDOMNodeP primaryBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],2); evioDOMNodeP trackBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],3); evioDOMNodeP ptypeBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],4); evioDOMNodeP rBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],5); evioDOMNodeP phiBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],6); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],7); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],8); evioDOMNodeP sectorBank = evioDOMNode::createEvioDOMNode (tagMap["dsctruthhit"],9); *sctruthhit << dEdxBank << primaryBank << trackBank << ptypeBank << rBank << phiBank << zBank << tBank << sectorBank; // add track data to banks idMap["dsctruthhit"].clear(); for(unsigned int i=0; idEdx; *primaryBank << (int8_t)sctruthhits[i]->primary; *trackBank << sctruthhits[i]->track; *ptypeBank << sctruthhits[i]->ptype; *rBank << sctruthhits[i]->r; *phiBank << sctruthhits[i]->phi; *zBank << sctruthhits[i]->z; *tBank << sctruthhits[i]->t; *sectorBank << sctruthhits[i]->sector; idMap["dsctruthhit"][sctruthhits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDFCALHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector fcalhits; eventLoop->Get(fcalhits); if(fcalhits.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP fcalhit = evioDOMNode::createEvioDOMNode(tagMap["dfcalhit"],0); tree << fcalhit; // create data banks and add to cdchit bank evioDOMNodeP rowBank = evioDOMNode::createEvioDOMNode (tagMap["dfcalhit"],1); evioDOMNodeP columnBank = evioDOMNode::createEvioDOMNode (tagMap["dfcalhit"],2); evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode (tagMap["dfcalhit"],3); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode (tagMap["dfcalhit"],4); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode (tagMap["dfcalhit"],5); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode (tagMap["dfcalhit"],6); *fcalhit << rowBank << columnBank << xBank << yBank << EBank << tBank; // add track data to banks idMap["dfcalhit"].clear(); for(unsigned int i=0; irow; *columnBank << fcalhits[i]->column; *xBank << fcalhits[i]->x; *yBank << fcalhits[i]->y; *EBank << fcalhits[i]->E; *tBank << fcalhits[i]->t; idMap["dfcalhit"][fcalhits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDHDDMBCALHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector hddmbcalhits; eventLoop->Get(hddmbcalhits); if(hddmbcalhits.size()<=0)return; // create hddm bcal bank and add to event tree evioDOMNodeP hddmbcalhit = evioDOMNode::createEvioDOMNode(tagMap["dhddmbcalhit"],0); tree << hddmbcalhit; // create data banks and add to cdchit bank evioDOMNodeP moduleBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmbcalhit"],1); evioDOMNodeP layerBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmbcalhit"],2); evioDOMNodeP sectorBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmbcalhit"],3); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmbcalhit"],4); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmbcalhit"],5); evioDOMNodeP zLocalBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmbcalhit"],6); *hddmbcalhit << moduleBank << layerBank << sectorBank << EBank << tBank << zLocalBank; // add track data to banks idMap["dhddmbcalhit"].clear(); for(unsigned int i=0; imodule; *layerBank << hddmbcalhits[i]->layer; *sectorBank << hddmbcalhits[i]->sector; *EBank << hddmbcalhits[i]->E; *tBank << hddmbcalhits[i]->t; *zLocalBank << hddmbcalhits[i]->zLocal; idMap["dhddmbcalhit"][hddmbcalhits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDHDDMTOFHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector hddmtofhits; eventLoop->Get(hddmtofhits); if(hddmtofhits.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP hddmtofhit = evioDOMNode::createEvioDOMNode(tagMap["dhddmtofhit"],0); tree << hddmtofhit; // create data banks and add to cdchit bank evioDOMNodeP planeBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],1); evioDOMNodeP barBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],2); evioDOMNodeP ptypeBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],3); evioDOMNodeP t_northBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],4); evioDOMNodeP dE_northBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],5); evioDOMNodeP t_southBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],6); evioDOMNodeP dE_southBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],7); evioDOMNodeP xBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],8); evioDOMNodeP yBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],9); evioDOMNodeP zBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],10); evioDOMNodeP pxBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],11); evioDOMNodeP pyBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],12); evioDOMNodeP pzBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],13); evioDOMNodeP EBank = evioDOMNode::createEvioDOMNode (tagMap["dhddmtofhit"],14); *hddmtofhit << planeBank << barBank << ptypeBank << t_northBank << dE_northBank << t_southBank << dE_southBank << xBank << yBank << zBank << pxBank << pyBank << pzBank<< EBank; // add track data to banks idMap["dhddmtofhit"].clear(); for(unsigned int i=0; iplane; *barBank << hddmtofhits[i]->bar; *ptypeBank << hddmtofhits[i]->ptype; *t_northBank << hddmtofhits[i]->t_north; *dE_northBank << hddmtofhits[i]->dE_north; *t_southBank << hddmtofhits[i]->t_south; *dE_southBank << hddmtofhits[i]->dE_south; *xBank << hddmtofhits[i]->x; *yBank << hddmtofhits[i]->y; *zBank << hddmtofhits[i]->z; *pxBank << hddmtofhits[i]->px; *pyBank << hddmtofhits[i]->py; *pzBank << hddmtofhits[i]->pz; *EBank << hddmtofhits[i]->E; idMap["dhddmtofhit"][hddmtofhits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDSCHit(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector schits; eventLoop->Get(schits); if(schits.size()<=0)return; // create cdchit bank and add to event tree evioDOMNodeP schit = evioDOMNode::createEvioDOMNode(tagMap["dschit"],0); tree << schit; // create data banks and add to cdchit bank evioDOMNodeP dEBank = evioDOMNode::createEvioDOMNode (tagMap["dschit"],1); evioDOMNodeP tBank = evioDOMNode::createEvioDOMNode (tagMap["dschit"],2); evioDOMNodeP sectorBank = evioDOMNode::createEvioDOMNode (tagMap["dschit"],3); *schit << dEBank << tBank << sectorBank; // add track data to banks idMap["dschit"].clear(); for(unsigned int i=0; idE; *tBank << schits[i]->t; *sectorBank << schits[i]->sector; idMap["dschit"][schits[i]->id]=i; } } //------------------------------------------------------------------------------ void addDTrackTimeBased(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector timebasedtracks; eventLoop->Get(timebasedtracks); if(timebasedtracks.size()<=0)return; // create timebasedtrack bank and add to event tree evioDOMNodeP timebasedtrack = evioDOMNode::createEvioDOMNode(tagMap["dtracktimebased"],0); tree << timebasedtrack; // create data banks and add to cdchit bank evioDOMNodeP chisq = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],1); evioDOMNodeP Ndof = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],2); evioDOMNodeP FOM = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],3); evioDOMNodeP x = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],4); evioDOMNodeP y = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],5); evioDOMNodeP z = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],6); evioDOMNodeP px = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],7); evioDOMNodeP py = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],8); evioDOMNodeP pz = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],9); evioDOMNodeP q = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],10); evioDOMNodeP E = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],11); evioDOMNodeP mass = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],12); evioDOMNodeP t0 = evioDOMNode::createEvioDOMNode (tagMap["dtracktimebased"],13); *timebasedtrack << chisq << Ndof << FOM << x << y << z << px << py << pz << q << E << mass << t0; // add track data to banks idMap["dtracktimebased"].clear(); for(unsigned int i=0; ichisq; *Ndof << timebasedtracks[i]->Ndof; *FOM << timebasedtracks[i]->FOM; *x << timebasedtracks[i]->x(); *y << timebasedtracks[i]->y(); *z << timebasedtracks[i]->z(); *px << timebasedtracks[i]->px(); *py << timebasedtracks[i]->py(); *pz << timebasedtracks[i]->pz(); *q << timebasedtracks[i]->charge(); *E << timebasedtracks[i]->energy(); *mass << timebasedtracks[i]->mass(); *t0 << timebasedtracks[i]->t0(); idMap["dtracktimebased"][timebasedtracks[i]->id]=i; } } //------------------------------------------------------------------------------ void addDChargedTrack(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector chargedtracks; eventLoop->Get(chargedtracks); if(chargedtracks.size()<=0)return; // create chargedtrack bank and add to event tree evioDOMNodeP chargedtrack = evioDOMNode::createEvioDOMNode(tagMap["dchargedtrack"],0); tree << chargedtrack; // create index bank for each charged track and add to chargedtrack bank idMap["dchargedtrack"].clear(); for(unsigned int i=0; i (tagMap["dchargedtrack"],1); *chargedtrack << hypotheses; for(unsigned int j=0; jhypotheses.size(); j++) { *hypotheses<< idMap["dtracktimebased"][chargedtracks[i]->hypotheses[j]->id]; } idMap["dchargedtrack"][chargedtracks[i]->id]=i; } } //------------------------------------------------------------------------------ void addDPhoton(JEventLoop *eventLoop, evioDOMTree &tree) { // is there any data vector photons; eventLoop->Get(photons); if(photons.size()<=0)return; // create photon bank and add to event tree evioDOMNodeP photon = evioDOMNode::createEvioDOMNode(tagMap["dphoton"],0); tree << photon; // create data banks and add to photon bank evioDOMNodeP E = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],1); evioDOMNodeP px = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],2); evioDOMNodeP py = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],3); evioDOMNodeP pz = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],4); evioDOMNodeP x = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],5); evioDOMNodeP y = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],6); evioDOMNodeP z = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],7); evioDOMNodeP t = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],8); evioDOMNodeP Tag = evioDOMNode::createEvioDOMNode (tagMap["dphoton"],9); *photon << E << px << py << pz << x << y << z << t << Tag; // add track data to banks idMap["dphoton"].clear(); for(unsigned int i=0; ienergy(); *px << photons[i]->px(); *py << photons[i]->py(); *pz << photons[i]->pz(); *x << photons[i]->x(); *y << photons[i]->y(); *z << photons[i]->z(); *t << photons[i]->getTime(); *Tag << photons[i]->getTag(); idMap["dphoton"][photons[i]->id]=i; } } //------------------------------------------------------------------------------ void decode_object_parameters(void) { // params are comma-separated and case-insensitive // "-" means invert // "+" is ignored // also supported: "all", "none", "truth" "hits", "tracks" // otherwise parameter must be the name of a DANA object that is processed by this program // first check for DANAEVIO tag, then WRITEOUT tag map::iterator iter; string danaevio= ""; gPARMS->SetDefaultParameter("DANAEVIO",danaevio); if(danaevio=="") gPARMS->SetDefaultParameter("WRITEOUT",danaevio); if(danaevio!="") { vector params; SplitString(danaevio,params,","); for(unsigned int i=0; isecond=!minus; } else if(value=="none") { for(iter=evioMap.begin(); iter!=evioMap.end(); iter++) iter->second=minus; } else if(value=="truth") { evioMap["dbeamphoton"]=!minus; evioMap["dmcthrown"]=!minus; evioMap["dmctrackhit"]=!minus; evioMap["dfcaltruthshower"]=!minus; evioMap["dbcaltruthshower"]=!minus; evioMap["dtoftruth"]=!minus; evioMap["dsctruth"]=!minus; } else if(value=="hits") { evioMap["dcdchit"]=!minus; evioMap["dfdchit"]=!minus; evioMap["dfcalchit"]=!minus; evioMap["dhddmbcalchit"]=!minus; evioMap["dhddmtofchit"]=!minus; evioMap["dschit"]=!minus; } else if(value=="tracks") { evioMap["dtracktimebased"]=!minus; evioMap["dchargedtrack"]=!minus; evioMap["dphoton"]=!minus; } else { map::iterator found = evioMap.find(value); if(found!=evioMap.end()) { found->second=!minus; } else { jerr << endl << " ?unknown DANAEVIO or WRITEOUT parameter: " << params[i] << endl; } } } } // if DChargedTrack requested then DTrackTimeBased must be also be present if(evioMap["dchargedtrack"])evioMap["dtracktimebased"]=true; } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- }; // for initializing plugin extern "C" { void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddProcessor(new JEventProcessor_danaevio()); } } // "extern C" //----------------------------------------------------------------------------