GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » General » Access to MC information after the digitization stage
Re: Access to MC information after the digitization stage [message #18411 is a reply to message #18400] Tue, 11 August 2015 16:07 Go to previous message
Dominik Steinschaden is currently offline  Dominik Steinschaden
Messages: 28
Registered: April 2015
continuous participant
From: *smi.oeaw.ac.at
Attached you find an macro using the PandaRoot classes to manage the data and using the FairLinks to go through the different data stages.



using std::cout;
using std::endl;

void link_basic_2(){

  // Set your inpute files here
  TString simFile ="data_sim/sim_s_gc_G4_6.root";
  TString parFile = "data_sim/sim_s_gc_G4_6_params.root";
  TString digiFile ="data_digi/digi_s_gc_G4_6_1000.root";
  TString outFile = "output.root";

  int Ev_start = 24;
  int Ev_end = 61;     // take 0 for all events

 TStopwatch timer;
  timer.Start();

  // -----   Initialize Run manager   -------------------------------------------
 FairRunAna *fRun= new FairRunAna();
 fRun->SetInputFile(digiFile);
 fRun->AddFriend(simFile);
 fRun->SetOutputFile(outFile); 
 fRun->SetUseFairLinks(kTRUE);

  // -----  Parameter database   --------------------------------------------
  TString allDigiFile = gSystem->Getenv("VMCWORKDIR");
  allDigiFile += "/macro/params/all.par";

  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
  FairParRootFileIo* parInput1 = new FairParRootFileIo();
  parInput1->open(parFile.Data());

  FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo();
  parIo1->open(allDigiFile.Data(),"in");
  rtdb->setFirstInput(parInput1);
  rtdb->setSecondInput(parIo1);

  fRun->Init();

  // ----------------- Initialize Used Variables and Branches ------------------------------
  FairRootManager* ioman = FairRootManager::Instance();
 
  TClonesArray* mcTrackArray = (TClonesArray*)ioman->GetObject("MCTrack");  // if not "initialized" here it may produces error at the first access
  TClonesArray* scitPointArray = (TClonesArray*)ioman->GetObject("SciTPoint");
  TClonesArray* scitHitArray = (TClonesArray*)ioman->GetObject("SciTHit");
  PndMCTrack* mcTrack = NULL;
  PndSciTPoint* scitPoint = NULL;
  PndSciTHit* scitHit = NULL;
  FairMultiLinkedData mcLink, pointLink;

  if (Ev_end == 0)  Ev_end = Int_t((ioman->GetInChain())->GetEntries())-1;
  for (int i_Event=Ev_start; i_Event <= Ev_end; i_Event++) { // ------- Loop over digitized events ---------------

    ioman->ReadEvent(i_Event);

    for (Int_t i_Array=0; i_Array < scitHitArray->GetEntries() ;i_Array++){ //------- loop over array entries
      scitHit = (PndSciTHit*) scitHitArray->At(i_Array);

 // ------------- do some stuff with the SciTHit data here -------------

      pointLink = scitHit->GetLinksWithType(ioman->GetBranchId("SciTPoint")); // --- get all links to the wanted Branch.
      //mcLink = scitHit->GetLinksWithType(ioman->GetBranchId("MCTrack"));      //You can also get direct Access to "MCTrack"
      scitPoint = (PndSciTPoint* ) ioman->GetCloneOfLinkData(pointLink.GetLink(0)); // -- load the Data of the chosen Link

      // ------------- do some stuff with the SciTPoint data here -------------

      mcLink = scitPoint->GetLinksWithType(ioman->GetBranchId("MCTrack"));   // you can also use the Links of the linked file.
      mcTrack = (PndMCTrack *) ioman->GetCloneOfLinkData(mcLink.GetLink(0));

    // ------------- do stuff with the McTrack data ---------------------

    }
  }   //------- end of event loop
  

  timer.Stop();
  Double_t rtime = timer.RealTime();
  Double_t ctime = timer.CpuTime();
  cout << endl << endl;
  cout << "Macro finished succesfully." << endl;
  cout << "Output file is "    << outFile << endl;
  cout << "Parameter file is " << parFile << endl;
  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
  cout << endl;
  // -----------
  
}

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Update on the SciTil Detector
Next Topic: momentum vs beta for barrel TOF
Goto Forum:
  


Current Time: Sat Apr 20 15:24:21 CEST 2024

Total time taken to generate the page: 0.01070 seconds