Access to MC information after the digitization stage [message #18400] |
Tue, 04 August 2015 14:01 |
Dominik Steinschaden
Messages: 28 Registered: April 2015
|
continuous participant |
From: *smi.oeaw.ac.at
|
|
Hallo,
recently I updated the stored Fairlinks in the implementation of the SciTil detector.
Now I'm trying to make use out of them in a timebased simulation . Therefore I created root files for the simulation and the digitization stage.
As usual I'm able to get access to the stored data in the root files using a macro which is basically based on the example shown on the wiki page:
https://panda-wiki.gsi.de/foswiki/bin/view/Computing/PandaRootRawHits
has someone maybe a simple example macro, that shows me how to load both root files (sim.root and digi.root) in a macro and get for example for every hit in the digi.root file the corresponding MCTrack infos using these Fairlinks.
or is there an other standard way of accessing these data. (like a mandatory use of the FairrunAna() class and writing and compiling a specific Task for analysing. but this seems rather complicate if I just want to compare the numbers of primaries in a detector after the simulation stage and after the digitization for example)
regards dominik
[Updated on: Tue, 04 August 2015 15:48] Report message to a moderator
|
|
|
|
|
|
Re: Access to MC information after the digitization stage [message #18411 is a reply to message #18400] |
Tue, 11 August 2015 16:07 |
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;
// -----------
}
|
|
|