///////////////////////////////////////////////////////////////////////////// // // fill Sts branches of GEANT ROOT tree // // last modified on 30/11/2015 by I. Koenig ///////////////////////////////////////////////////////////////////////////// #include "fillsts.h" #include "cfortran.h" #include "hgeantsts.h" #include "hgeantmaxtrk.h" #include "hades.h" #include "hlocation.h" #include "hcategory.h" #include "hrecevent.h" #include "hpartialevent.h" #include "hgeantkine.h" #include struct STS_DEF { // structure mapped to STSTUPLE Fortran COMMON block Int_t ntrk; Int_t ststrk[MAXTRKSTS]; Int_t stspart[MAXTRKSTS]; Int_t stsmod[MAXTRKSTS]; Int_t stslayer[MAXTRKSTS]; Int_t stscell[MAXTRKSTS]; Int_t stssub[MAXTRKSTS]; Float_t stsx[MAXTRKSTS]; Float_t stsy[MAXTRKSTS]; Float_t stsz[MAXTRKSTS]; Float_t stspx[MAXTRKSTS]; Float_t stspy[MAXTRKSTS]; Float_t stspz[MAXTRKSTS]; Float_t ststof[MAXTRKSTS]; Float_t stslen[MAXTRKSTS]; Float_t stse[MAXTRKSTS]; }; #define STSTUPLE COMMON_BLOCK(STSTUPLE,ststuple) COMMON_BLOCK_DEF(STS_DEF,STSTUPLE); bool same_hits(const Hit & h1, const Hit & h2) { return (h1.track == h2.track) && (h1.module == h2.module) && (h1.layer == h2.layer) && (h1.cell == h2.cell) && (h1.subcell == h2.subcell); } void fillsts(void) { HRecEvent* pHGeantEvent = (HRecEvent*)(gHades->getCurrentEvent()); // get pointer to event HPartialEvent* pSimul = pHGeantEvent->getPartialEvent(catSimul); HCategory* pStsCat = pSimul->getCategory(catStsGeantRaw); // get category pStsCat->Clear(); // clear category if 1st sector HCategory* pKin = pSimul->getCategory(catGeantKine); // get KINE cat Int_t gmodule, glayer, gcell, gsub; Int_t old_hitid = -1; Hit old_hit; old_hit.track = -1; old_hit.module = -1; old_hit.layer = -1; old_hit.cell = -1; old_hit.subcell = 0; old_hit.mult = 0; // loop over tracks (TClonesArray, expands if necessary) for(Int_t idx = 0; idx < STSTUPLE.ntrk; ++idx) { gmodule = STSTUPLE.stsmod[idx]-1; //GEANT indexing is from 1 glayer = STSTUPLE.stslayer[idx]-1; gcell = STSTUPLE.stscell[idx]-1; gsub = STSTUPLE.stssub[idx]; Hit hit; hit.module = -1; hit.layer = -1; hit.cell = -1; hit.subcell = 0; hit.mult = 1; hit.index = idx; hit.track = STSTUPLE.ststrk[idx]; hit.px = STSTUPLE.stspx[idx]; hit.py = STSTUPLE.stspy[idx]; hit.pz = STSTUPLE.stspz[idx]; hit.x = STSTUPLE.stsx[idx]; hit.y = STSTUPLE.stsy[idx]; hit.z = STSTUPLE.stsz[idx]; hit.tof = STSTUPLE.ststof[idx]; hit.trklen = STSTUPLE.stslen[idx]; hit.eloss = STSTUPLE.stse[idx]; hit.module = gmodule; hit.layer = glayer; hit.cell = gcell; hit.subcell = gsub; // if this is reentry of the track to the same volume, ignore it if (same_hits(hit, old_hit)) continue; fillStsHit(pKin, pStsCat, hit); old_hit.module = gmodule; old_hit.layer = glayer; old_hit.cell = gcell; old_hit.subcell = gsub; old_hit.track = hit.track; } if (old_hitid != -1) { old_hit.px /= old_hit.mult; old_hit.py /= old_hit.mult; old_hit.pz /= old_hit.mult; old_hit.x /= old_hit.mult; old_hit.y /= old_hit.mult; old_hit.z /= old_hit.mult; fillStsHit(pKin, pStsCat, old_hit); } } Bool_t fillStsHit(HCategory* pKin, HCategory* pStsCat, const Hit & hit) { HLocation loc; loc.set(0); HGeantSts* pSts = (HGeantSts*)pStsCat->getNewSlot(loc); // get slot if (pSts == NULL) { printf("\n*** FILLSTS: HGeantSts location not found ! ***\n"); printf("index=%d\n", hit.index); return kFALSE; } pSts = new(pSts) HGeantSts; // Sts track data if (!pSts) return kFALSE; pSts->setTrack(hit.track); pSts->setAddress(hit.module, hit.layer, hit.cell, hit.subcell); pSts->setHit(hit.x, hit.y, hit.z, hit.px, hit.py, hit.pz, hit.tof, hit.trklen, hit.eloss); // add hit to linked list of track if (pKin != NULL && hit.track > 0) { ((HGeantKine*)pKin->getObject(hit.track-1))->setStsHitIndex(hit.index); } return kTRUE; } // wrapping of the c++ routine as Fortran-subroutine using cfortran.h of Cern-library FCALLSCSUB0(fillsts,FILLSTS,fillsts)