IO With LArLite Datafiles - twongjirad/LArLiteSoftCookBook GitHub Wiki

If you are at this stage then you have presumably taken some events, done some sort of analysis on them, and then generated a LArLite type ROOT file. In order to access the data, use the larlite data manager tool. The general method goes as follows (in Python)

 from ROOT import larlite
 YOUR_MANAGER = larlite.storage_manager()
 YOUR_MANAGER.set_io_mode(YOUR_MANAGER.kREAD) # or kWRITE or kBOTH
 YOUR_MANAGER.add_in_filename(YOUR_FILE)
 YOUR_MANAGER.set_in_rootdir("") #Must include even if trees are not in subdirs
 YOUR_MANAGER.open()

If you are lost at any point and want to know your options or the appropriate syntax, you can type

 help(YOUR_MANAGER)

A typical thing you'll want to do is loop through all events stored in a LArLite tree and get various bits of info. To initialize the loop:

 while YOUR_MANAGER.next_event():

If you are interested in the data products of a certain module, then we can return a vector with this info by doing:

 YOUR_DATA_VEC = YOUR_MANAGER.get_data(larlite.data.DATA_TYPE,"MODULE_NAME")

Where MODULE_NAME is the name of the module which produced that data you are interested in (for example "generator" or "opflash". The corresponding LArLite data type can be found by inspecting the LArlite ROOT trees if you don't know them. For example to get the Monte Carlo truth data from module "generator" the data type is kMCTruth, and the data from "opflash" is kOpFlash.

Depending on the nature of the module you used, YOUR_DATA_VEC may contain several events (such as with opflash if multiple flashes are found) or may have only one entry (such as with generator if only one particle was produced). To check what values are available to inspect, you can again use the help function to list them as

 help(YOUR_DATA_VEC[0])  #or another number if the vector has multiple entries

For example, if YOUR_DATA_VEC was associated with opflash, you will find that things such as Time() or TotalPE() are available and can be accessed simply by

 YOUR_DATA_VEC[0].Time()
 YOUR_DATA_VEC[0].TotalPE()    #Or again whichever entry interests you

Other times if you inspect the help menu you'll find that calling certain functions will lead you to subcategories of data. For instance if you made single particles with generator then typing help(YOUR_DATA_VEC[0]) would show you that you could type YOUR_DATA_VEC[0].GetParticles(). The help menu would inform you that GetParticles() will return a vector of particles that was produced for that event. The help menu will again show you what is available to do next. For example maybe for the first (only for single gen) particle you want to get trajectory information, which is then accessed by using YOUR_DATA_VEC[0].GetParticles()[0].Trajectory(). Basically just use the help menu to work your way through the available products (or ask someone who knows specifically where they are)

An example of an inefficient, yet sill effective code is here

Among other things this code reads in the position and initial particle energy of some Monte Carlo single generated particle. It also reads in some data from opflash whih was run on said MC sample such as Total PEs and time since trigger.