Public Member Functions | Private Member Functions | Private Attributes

WCSimEventWriter Class Reference

#include "WCSimEventWriter.hh"

List of all members.

Public Member Functions

 WCSimEventWriter ()
 ~WCSimEventWriter ()
void AddFile (const char *file)
void WriteOutGeometry (Bool_t yesno=1)
void WriteOutTracks (Bool_t yesno=1)
void WriteOutDigits (Bool_t yesno=1)
void Run (Int_t entries=-1)

Private Member Functions

void Initialize ()
void WriteThisDigit ()
void WriteThisTrack ()
void CloseFiles ()

Private Attributes

Double_t fScale
Int_t fPMTs
Double_t * fPmtX
Double_t * fPmtY
Double_t * fPmtZ
Int_t * fPmtRegion
Int_t fRun
Int_t fEventNumber
Int_t fSubEventNumber
Int_t fTube
Int_t fRegion
Double_t fXpos
Double_t fYpos
Double_t fZpos
Double_t fQPEs
Double_t fTime
Int_t fTrackNumber
Int_t fPdg
Int_t fFlag
Double_t fM
Double_t fP
Double_t fE
Double_t fTrkDirX
Double_t fTrkDirY
Double_t fTrkDirZ
Double_t fVtxX
Double_t fVtxY
Double_t fVtxZ
Double_t fVtxTime
Double_t fEndX
Double_t fEndY
Double_t fEndZ
Int_t fPdgParent
TFile * fFileDigits
TTree * fTreeDigits
TFile * fFileTracks
TTree * fTreeTracks
TFile * fFileGeometry
TTree * fTreeGeometry
Bool_t fWriteOutGeometry
Bool_t fWriteOutTracks
Bool_t fWriteOutDigits
TChain * fChain
TChain * fChainGeom
WCSimRootEvent * fEvent
WCSimRootGeom * fGeometry

Detailed Description

Definition at line 13 of file WCSimEventWriter.hh.


Constructor & Destructor Documentation

WCSimEventWriter::WCSimEventWriter (  ) 
WCSimEventWriter::~WCSimEventWriter (  ) 

Definition at line 35 of file WCSimEventWriter.cc.

{
  
}


Member Function Documentation

void WCSimEventWriter::AddFile ( const char *  file  ) 

Definition at line 55 of file WCSimEventWriter.cc.

References fChain, and fChainGeom.

{
  std::cout << " adding: " << file << std::endl;

  fChain->Add(file);
  fChainGeom->Add(file);

  std::cout << "   ... total entries=" << fChain->GetEntries() << std::endl;

  // bug fix
  // =======
  // if( fChain->GetEntries()>0 ){
  //   std::cout << " applying fix: GetBranch(\"wcsimrootevent\")->SetAutoDelete(true) " << std::endl;
  //   fChain->GetBranch("wcsimrootevent")->SetAutoDelete(true);
  // }

  return;
}

void WCSimEventWriter::CloseFiles (  )  [private]

Definition at line 256 of file WCSimEventWriter.cc.

References fFileDigits, fFileTracks, fTreeDigits, fTreeTracks, fWriteOutDigits, and fWriteOutTracks.

Referenced by Run().

{
  TDirectory* tmpd = 0;

  // Write out Tracks
  // ================
  if( fWriteOutTracks ){
    tmpd = gDirectory;
    fFileTracks->cd();
    fTreeTracks->Write();
    fFileTracks->Close();
    gDirectory = tmpd;
  }

  // Write out Digits
  // ================
  if( fWriteOutDigits ){
    tmpd = gDirectory;
    fFileDigits->cd();
    fTreeDigits->Write();
    fFileDigits->Close();
    gDirectory = tmpd;
  }
}

void WCSimEventWriter::Initialize (  )  [private]

Definition at line 40 of file WCSimEventWriter.cc.

References fChain, fChainGeom, fEvent, and fGeometry.

{
  // create event chain
  if( !fChain ){
    fChain = new TChain("wcsimT","chain");
    fChain->SetBranchAddress("wcsimrootevent",&fEvent);
  }

  // create geometry chain
  if( !fChainGeom ){
    fChainGeom = new TChain("wcsimGeoT","chainGeom");
    fChainGeom->SetBranchAddress("wcsimrootgeom",&fGeometry);
  }
}

void WCSimEventWriter::Run ( Int_t  entries = -1  ) 

Definition at line 74 of file WCSimEventWriter.cc.

References WCSimGeometry::BuildGeometry(), CloseFiles(), fChain, fChainGeom, fE, fEndX, fEndY, fEndZ, fEvent, fEventNumber, fFlag, fGeometry, fM, fP, fPdg, fPdgParent, fQPEs, fRegion, fRun, fScale, fSubEventNumber, fTime, fTrackNumber, fTrkDirX, fTrkDirY, fTrkDirZ, fTube, fVtxTime, fVtxX, fVtxY, fVtxZ, fWriteOutDigits, fWriteOutGeometry, fWriteOutTracks, fXpos, fYpos, fZpos, WCSimGeometry::GetRegion(), WCSimGeometry::GetX(), WCSimGeometry::GetY(), WCSimGeometry::GetZ(), WCSimGeometry::Instance(), WCSimGeometry::WriteGeometry(), WriteThisDigit(), and WriteThisTrack().

{
  std::cout << " *** WCSimEventWriter::Run() *** " << std::endl;

  // check for events
  if( fChain->GetEntries()<=0 ){
    return;
  }

  // check for geometry
  if( fChainGeom->GetEntries()<=0 ){
    return;
  }

  // Load Geometry
  // =============
  // get first entry of geometry tree
  fChainGeom->GetEntry(0);

  // build geometry
  WCSimGeometry::BuildGeometry(fGeometry);

  if( fWriteOutGeometry ){
    WCSimGeometry::WriteGeometry();
  }
    
  // convert [cm] to [m]
  fScale = 0.01;

  // Loop over entries
  // =================
  Int_t nLast = entries;
  if( nLast>fChain->GetEntries() ) nLast = fChain->GetEntries();
  if( nLast<0 ) nLast = fChain->GetEntries();

  std::cout << "  looping over " << nLast << " entries " << std::endl;
  
  // loop over entries
  for( Int_t nEvent = 0; nEvent<nLast; nEvent++ ){
    std::cout << " " << nEvent << "/" << fChain->GetEntries() << " " << std::endl;

    if( fEvent ) delete fEvent; fEvent = 0;
    fChain->GetEntry(nEvent);

    for( Int_t nTrigger = 0; nTrigger<fEvent->GetNumberOfEvents(); nTrigger++ ){
      WCSimRootTrigger* myTrigger = (WCSimRootTrigger*)(fEvent->GetTrigger(nTrigger));

      // Event Header
      // ============
      WCSimRootEventHeader* myHeader = (WCSimRootEventHeader*)(myTrigger->GetHeader());
      fRun = myHeader->GetRun();
      fEventNumber = myHeader->GetEvtNum();
      fSubEventNumber = myHeader->GetSubEvtNumber();

      // Get Array of True Tracks
      // ========================
      TClonesArray* fTrackArray = (TClonesArray*)(myTrigger->GetTracks());

      for( Int_t nTrack=0; nTrack<1+fTrackArray->GetLast(); nTrack++ ){
        WCSimRootTrack* myTrack = (WCSimRootTrack*)(fTrackArray->At(nTrack));

        fTrackNumber = nTrack;
        fPdg = myTrack->GetIpnu();
        fFlag = myTrack->GetFlag();
        fM = myTrack->GetM();
        fP = myTrack->GetP();
        fE = myTrack->GetE();
        fTrkDirX = myTrack->GetDir(0);
        fTrkDirY = myTrack->GetDir(1);
        fTrkDirZ = myTrack->GetDir(2);
        fVtxX = fScale*myTrack->GetStart(0);
        fVtxY = fScale*myTrack->GetStart(1);
        fVtxZ = fScale*myTrack->GetStart(2);
        fVtxTime = myTrack->GetTime();
        fEndX = fScale*myTrack->GetStop(0);
        fEndY = fScale*myTrack->GetStop(1);
        fEndZ = fScale*myTrack->GetStop(2);
        fPdgParent = myTrack->GetParenttype();

        if( fWriteOutTracks ) this->WriteThisTrack();
      }

      // Get Array of Digitized Hits
      // ===========================
      TClonesArray* fDigiHitArray = (TClonesArray*)(myTrigger->GetCherenkovDigiHits());

      for( Int_t nDigit=0; nDigit<1+fDigiHitArray->GetLast(); nDigit++ ){
        WCSimRootCherenkovDigiHit* myDigit = (WCSimRootCherenkovDigiHit*)(fDigiHitArray->At(nDigit));

        fTube = myDigit->GetTubeId();
        fQPEs = myDigit->GetQ();
        fTime = myDigit->GetT();

        fRegion = WCSimGeometry::Instance()->GetRegion(fTube);
        fXpos = fScale*WCSimGeometry::Instance()->GetX(fTube);
        fYpos = fScale*WCSimGeometry::Instance()->GetY(fTube);
        fZpos = fScale*WCSimGeometry::Instance()->GetZ(fTube);
        
        if( fWriteOutDigits ) this->WriteThisDigit();
      }

    } // nTrigger
  } // nEvent


  // Write out data
  // ==============
  this->CloseFiles();

  return;
}

void WCSimEventWriter::WriteOutDigits ( Bool_t  yesno = 1  )  [inline]

Definition at line 29 of file WCSimEventWriter.hh.

References fWriteOutDigits.

                                       {
    fWriteOutDigits = yesno;
  }

void WCSimEventWriter::WriteOutGeometry ( Bool_t  yesno = 1  )  [inline]

Definition at line 21 of file WCSimEventWriter.hh.

References fWriteOutGeometry.

                                         {
    fWriteOutGeometry = yesno;
  }

void WCSimEventWriter::WriteOutTracks ( Bool_t  yesno = 1  )  [inline]

Definition at line 25 of file WCSimEventWriter.hh.

References fWriteOutTracks.

                                       {
    fWriteOutTracks = yesno;
  }

void WCSimEventWriter::WriteThisDigit (  )  [private]

Definition at line 186 of file WCSimEventWriter.cc.

References fEventNumber, fFileDigits, fQPEs, fRun, fSubEventNumber, fTime, fTreeDigits, fTube, fWriteOutDigits, fXpos, fYpos, and fZpos.

Referenced by Run().

{  
  if( !fWriteOutDigits ) return;

  TDirectory* tmpd = 0;

  if( !fFileDigits ){
    tmpd = gDirectory;
    fFileDigits = new TFile("wcsim.digits.root","recreate");
    fTreeDigits = new TTree("ntuple","list of wc digits");
    fTreeDigits->Branch("run",&fRun,"run/I");
    fTreeDigits->Branch("event",&fEventNumber,"event/I");
    fTreeDigits->Branch("subevent",&fSubEventNumber,"subevent/I");
    fTreeDigits->Branch("tube",&fTube,"tube/I");
    fTreeDigits->Branch("x",&fXpos,"x/D");
    fTreeDigits->Branch("y",&fYpos,"y/D");
    fTreeDigits->Branch("z",&fZpos,"z/D");
    fTreeDigits->Branch("q",&fQPEs,"q/D");
    fTreeDigits->Branch("t",&fTime,"t/D");
    fTreeDigits->SetAutoSave(100);
    gDirectory = tmpd;
  }

  tmpd = gDirectory;
  fFileDigits->cd();
  fTreeDigits->Fill();     
  gDirectory = tmpd;
}

void WCSimEventWriter::WriteThisTrack (  )  [private]

Definition at line 215 of file WCSimEventWriter.cc.

References fE, fEndX, fEndY, fEndZ, fEventNumber, fFileTracks, fFlag, fM, fP, fPdg, fPdgParent, fRun, fSubEventNumber, fTrackNumber, fTreeTracks, fTrkDirX, fTrkDirY, fTrkDirZ, fVtxTime, fVtxX, fVtxY, fVtxZ, and fWriteOutTracks.

Referenced by Run().

{
  if( !fWriteOutTracks ) return;

  TDirectory* tmpd = 0;

  if( !fFileTracks ){
    tmpd = gDirectory;
    fFileTracks = new TFile("wcsim.tracks.root","recreate");
    fTreeTracks = new TTree("ntuple","list of tracks");
    fTreeTracks->Branch("run",&fRun,"run/I");
    fTreeTracks->Branch("event",&fEventNumber,"event/I");
    fTreeTracks->Branch("subevent",&fSubEventNumber,"subevent/I");
    fTreeTracks->Branch("track",&fTrackNumber,"track/I");
    fTreeTracks->Branch("pdg",&fPdg,"pdg/I");
    fTreeTracks->Branch("flag",&fFlag,"flag/I");
    fTreeTracks->Branch("M",&fM,"M/D");
    fTreeTracks->Branch("P",&fP,"P/D");
    fTreeTracks->Branch("E",&fE,"E/D");
    fTreeTracks->Branch("trkdirX",&fTrkDirX,"trkdirX/D");
    fTreeTracks->Branch("trkdirY",&fTrkDirY,"trkdirY/D");
    fTreeTracks->Branch("trkdirZ",&fTrkDirZ,"trkdirZ/D");
    fTreeTracks->Branch("vtxX",&fVtxX,"vtxX/D");
    fTreeTracks->Branch("vtxY",&fVtxY,"vtxY/D");
    fTreeTracks->Branch("vtxZ",&fVtxZ,"vtxZ/D");
    fTreeTracks->Branch("vtxTime",&fVtxTime,"vtxTime/D");
    fTreeTracks->Branch("endX",&fEndX,"endX/D");
    fTreeTracks->Branch("endY",&fEndY,"endY/D");
    fTreeTracks->Branch("endZ",&fEndZ,"endZ/D");
    fTreeTracks->Branch("pdgparent",&fPdgParent,"pdgparent/I");
    
    fTreeTracks->SetAutoSave(100); 
    gDirectory = tmpd;
  }
 
  tmpd = gDirectory;
  fFileTracks->cd();
  fTreeTracks->Fill();
  gDirectory = tmpd;       
}


Member Data Documentation

TChain* WCSimEventWriter::fChain [private]

Definition at line 95 of file WCSimEventWriter.hh.

Referenced by AddFile(), Initialize(), and Run().

TChain* WCSimEventWriter::fChainGeom [private]

Definition at line 96 of file WCSimEventWriter.hh.

Referenced by AddFile(), Initialize(), and Run().

Double_t WCSimEventWriter::fE [private]

Definition at line 69 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fEndX [private]

Definition at line 77 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fEndY [private]

Definition at line 78 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fEndZ [private]

Definition at line 79 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

WCSimRootEvent* WCSimEventWriter::fEvent [private]

Definition at line 98 of file WCSimEventWriter.hh.

Referenced by Initialize(), and Run().

Definition at line 53 of file WCSimEventWriter.hh.

Referenced by Run(), WriteThisDigit(), and WriteThisTrack().

Definition at line 82 of file WCSimEventWriter.hh.

Referenced by CloseFiles(), and WriteThisDigit().

Definition at line 88 of file WCSimEventWriter.hh.

Definition at line 85 of file WCSimEventWriter.hh.

Referenced by CloseFiles(), and WriteThisTrack().

Int_t WCSimEventWriter::fFlag [private]

Definition at line 66 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

WCSimRootGeom* WCSimEventWriter::fGeometry [private]

Definition at line 99 of file WCSimEventWriter.hh.

Referenced by Initialize(), and Run().

Double_t WCSimEventWriter::fM [private]

Definition at line 67 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fP [private]

Definition at line 68 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Int_t WCSimEventWriter::fPdg [private]

Definition at line 65 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Definition at line 80 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Int_t* WCSimEventWriter::fPmtRegion [private]

Definition at line 50 of file WCSimEventWriter.hh.

Int_t WCSimEventWriter::fPMTs [private]

Definition at line 46 of file WCSimEventWriter.hh.

Double_t* WCSimEventWriter::fPmtX [private]

Definition at line 47 of file WCSimEventWriter.hh.

Double_t* WCSimEventWriter::fPmtY [private]

Definition at line 48 of file WCSimEventWriter.hh.

Double_t* WCSimEventWriter::fPmtZ [private]

Definition at line 49 of file WCSimEventWriter.hh.

Double_t WCSimEventWriter::fQPEs [private]

Definition at line 61 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisDigit().

Int_t WCSimEventWriter::fRegion [private]

Definition at line 57 of file WCSimEventWriter.hh.

Referenced by Run().

Int_t WCSimEventWriter::fRun [private]

Definition at line 52 of file WCSimEventWriter.hh.

Referenced by Run(), WriteThisDigit(), and WriteThisTrack().

Double_t WCSimEventWriter::fScale [private]

Definition at line 44 of file WCSimEventWriter.hh.

Referenced by Run().

Definition at line 54 of file WCSimEventWriter.hh.

Referenced by Run(), WriteThisDigit(), and WriteThisTrack().

Double_t WCSimEventWriter::fTime [private]

Definition at line 62 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisDigit().

Definition at line 64 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Definition at line 83 of file WCSimEventWriter.hh.

Referenced by CloseFiles(), and WriteThisDigit().

Definition at line 89 of file WCSimEventWriter.hh.

Definition at line 86 of file WCSimEventWriter.hh.

Referenced by CloseFiles(), and WriteThisTrack().

Double_t WCSimEventWriter::fTrkDirX [private]

Definition at line 70 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fTrkDirY [private]

Definition at line 71 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fTrkDirZ [private]

Definition at line 72 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Int_t WCSimEventWriter::fTube [private]

Definition at line 56 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisDigit().

Double_t WCSimEventWriter::fVtxTime [private]

Definition at line 76 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fVtxX [private]

Definition at line 73 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fVtxY [private]

Definition at line 74 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Double_t WCSimEventWriter::fVtxZ [private]

Definition at line 75 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisTrack().

Definition at line 93 of file WCSimEventWriter.hh.

Referenced by CloseFiles(), Run(), WriteOutDigits(), and WriteThisDigit().

Definition at line 91 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteOutGeometry().

Definition at line 92 of file WCSimEventWriter.hh.

Referenced by CloseFiles(), Run(), WriteOutTracks(), and WriteThisTrack().

Double_t WCSimEventWriter::fXpos [private]

Definition at line 58 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisDigit().

Double_t WCSimEventWriter::fYpos [private]

Definition at line 59 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisDigit().

Double_t WCSimEventWriter::fZpos [private]

Definition at line 60 of file WCSimEventWriter.hh.

Referenced by Run(), and WriteThisDigit().


The documentation for this class was generated from the following files: