//------------------------------------------------------------------------------ // See Documentation in the header file. //------------------------------------------------------------------------------ #include using namespace std; #include "TROOT.h" #include "TFolder.h" #include "BaBar/Experiment.hh" #include "Edm/EventRecord.hh" #include "Edm/ConstHandle.hh" #include "Framework/AppResult.hh" #include "TrackingObjects/Storable/CdfTrackColl.hh" #include "TrackingObjects/Storable/CdfTrackView.hh" #include "ParticleDB/PartIds.hh" #include "BottomAlgs/BeamCorrector.hh" #include "TofObjects/Event/TofMatches.hh" #include "TofObjects/Event/TofMatchesColl.hh" #include "TofObjects/Event/TofT0Coll.hh" #include #include #include #include #include #include #include //----------------------------------------------------------------------------- Int_t InitTofMatch(TStnTofMatch* tof, TofMatches* tofData) { // Initialize all quantities tof->Reset(); // Fill nTuple quantities for TOF tof->fTofNPulses = (tofData->getTrackPulses()).size(); if(tof->fTofNPulses > 0 ){ tof->fTofZBar = (tofData->getTrackPulses())[0]->getHitBar().getInZ(); tof->fTofNBar = (tofData->getTrackPulses())[0]->getHitBar().getBarNumber(); } tof->fPathLength = tofData->getPathLength(); tof->fArcLength = tofData->getArcLength(); tof->fMomentum = tofData->getMomentum(); tof->fArrivalTime = tofData->getArrivalTime(); tof->fArrivalTimeError = tofData->getArrivalTimeError(); tof->fTof = tofData->getTof(); tof->fTofErr = tofData->getTofError(); tof->fTZero = tofData->getTZero(); tof->fTZeroError = tofData->getTZeroError(); tof->fTofMatches = tofData; return 0; } //------------------------------------------------------------------------------ Int_t StntupleInitTofMatchBlock(TStnDataBlock* block, AbsEvent* event, int mode) { // initialize Candidate data block with the 'event' data // return -1, if bank doesn't exist, 0, if everything is OK int evtNumber, runNumber; //---------------------------------------------------------------------------- // save time: don't do initialization twice for the same event //---------------------------------------------------------------------------- evtNumber = AbsEnv::instance()->trigNumber(); runNumber = AbsEnv::instance()->runNumber(); if (block->Initialized(evtNumber,runNumber)) return 0; TStnTofMatchBlock* data = (TStnTofMatchBlock*) block; data->Clear(); char process[100], description[100]; StntupleGetProcessName(data->CollName()->Data(),process,description); ConstHandle handle(StntupleGetIterator(event,"TofMatchesColl",process,description)); if (handle.is_null()) return -1; //find TofT0Coll TofT0Coll_ch tofT0Coll; TofT0Coll::find(tofT0Coll); int rc = 0; for (TofMatchesColl::const_iterator is = handle->contents().begin(); is != handle->contents().end(); is++) { TofMatches* s = const_cast( &(*is) ); //not every match is real match const CdfTrack* cdftrack = &(*s->getCdfTrack()); if(cdftrack == NULL) continue; TStnTofMatch* tof = data->NewTofMatch(); InitTofMatch(tof,s); rc++; if(tofT0Coll.is_null()) continue; for (TofT0Coll::const_iterator t0 = tofT0Coll->contents().begin(); t0 != tofT0Coll->contents().end(); t0++) { if (t0->isAssociatedWith(s->getParentId())) { tof->fTZeroZpos = t0->getZ0(); break; } } } //---------------------------------------------------------------------------- // On return mark block as initialized for given event/run //---------------------------------------------------------------------------- data->f_RunNumber = runNumber; data->f_EventNumber = evtNumber; return rc; } Int_t StntupleTofMatchBlockLinks(TStnDataBlock* block,AbsEvent* event,int mode) { // set links between the vertex and the tracks // returns: 0 if everything is OK // -1 if block itself has not been initialized TStnTofMatchBlock* tof_block = (TStnTofMatchBlock*) block; // assume that the block exists, it // is supposed to be initialized int ev_number = AbsEnv::instance()->trigNumber(); int rn_number = AbsEnv::instance()->runNumber(); if (! block->Initialized(ev_number,rn_number)) return -1; // do not do initialize links 2nd time if (block->LinksInitialized()) return 0; //----------------------------------------------------------------------------- // pointers to the default track block and to the list of HPT leptons //----------------------------------------------------------------------------- TStnEvent* ev = tof_block->GetEvent(); TStnTrackBlock* track_block = (TStnTrackBlock*) ev->GetDataBlock("TrackBlock"); int nmatches = tof_block->NTofMatches(); int rc = 0; for (int imatch=0; imatch < nmatches; imatch++) { TStnTofMatch* stmatch = tof_block->TofMatch(imatch); TofMatches* tmatch = stmatch->GetTofMatches(); const CdfTrack* cdftrack = &(*tmatch->getCdfTrack() ); //tof points to COTParent of the track, so have to loop over all DefTracks //in Stntuple and try to find a parent int nDefTracks = track_block->NTracks(); for(int itrk = 0; itrk < nDefTracks; itrk++){ TStnTrack* sttrk = track_block->Track(itrk); CdfTrack* ptrack = sttrk->GetCdfTrack(); const CdfTrack* cotParent = ptrack; bool found = false; while(cotParent->parent().is_nonnull()){ cotParent = &*(cotParent->parent()); if(cotParent == cdftrack){ stmatch->fTrack = sttrk; stmatch->SetTrackNumber(itrk); found = true; break; } } if(found){ rc++; break; } } } tof_block->fLinksInitialized = 1; return rc; }