Can TTree::Draw & TCut be used for this task?

Dear ROOTers,

I have a root tree containing the information from different instruments and detectors including a prilimiary anlysis:

Instrument01
|_std::vector
| |_std::vector<int16_t> waveform
| |_std::vector
| | |_doubles containing information about peak
| |_some doubles storing information about a channel
|
|_std::vector
| |_std::vector
| | |_double x
| | |_double y
| | |_double t
| |_some doubles storing information about detector
|_some doubles storing information about instrument

Instrument02
|_std::vector
|_std::vector
| |_uint16_t x
| |_uint16_t y
| |_double e
|_std::vector<uint16_t>frame
|_some doubles storing information about a frame

Instrument03
|_std::vector<uint16_t>diffrerentframe
|_some doubles storing information about a frame

Instrument04
|_std::map<std::string, double>
|_some doubles storing information about instrument / event

where Instrument01 - 04, Channel, Detector and differentDetector are classes. frame and differentframe are linearized 2D arrays.

Right now I am using for loops and if statements to fill histograms containing what I want to look at.

1.)
//when in the differentdetector frame there are enough pixels between a given boarder display it//
TH2D h2("DetPicture","DetPicture",nCols,-0.5,nCols,nRows,-0.5,nRows);
size_t integral=0;
const std::vector<uint16_t> &frame = Instrument02.differentdetectors[0].frame;
for (size_t i=0 ; i<frame.size(); ++i )
  if((frame[i] > 50)&&(frame[i]<200))++integral;
if (integral < 250)
  for (size_t iRow=0; iRow<nRows ;++iRow)
    for (size_t iCol=0; iCol<nCols ;++iCol)
      h2.Fill(iCol,iRow, frame[iCol+nCols*iRow]);

2.)
//when in the differentframe the integral in certain area is above a certain//
//threshold plot the differentdetector frame//
TH2D h2("DetPicture","DetPicture",nCols,-0.5,nCols,nRows,-0.5,nRows);
size_t intensity=0;
const std::vector<uint16_t> &frame = Instrument02.differentdetectors[0].frame;
const std::vector<uint16_t> &dframe = Instrument02.differentframe;
for (size_t iRow=ylowlimit; iRow<yhighlimit ;++iRow)
  for (size_t iCol=xlowlimit; iCol<xhighlimit ;++iCol)
    intensity += dframe[iCol+dnCols*iRow]);
if (intensity  > 2e6)
  for (size_t iRow=0; iRow<nRows ;++iRow)
    for (size_t iCol=0; iCol<nCols ;++iCol)
      h2.Fill(iCol,iRow, frame[iCol+nCols*iRow]);

3.)
//when in the waveform of a channel within a given boarder there is enough signal//
//plot the differentdetector frame
TH2D h2("DetPicture","DetPicture",nCols,-0.5,nCols,nRows,-0.5,nRows);
const std::vector<int16_t> &wave = Instrument01.channels[0].waveform;
size_t intensity=0;
for (size_t iWave=lowlimit; iWave<highlimit ;++iWave)
  intensity += wave[iWave]);
if (intensity  > 2e6)
  for (size_t iRow=0; iRow<nRows ;++iRow)
    for (size_t iCol=0; iCol<nCols ;++iCol)
      h2.Fill(iCol,iRow, frame[iCol+nCols*iRow]);

4.)
//go through all detector hits and if there is at least one that fullfilles all boarders//
//draw the energy of all photonhits of the differentdetector
TH1D h1("Spec","spec",800,0,16000);
const std::vector<Hit> &hits = Instrument01.detectors[0].hits;
const std::vector<Hit> &phits = Instrument02.detectors[0].photonHits;
bool flag=false;
for (size_t iHit=0; iHit<hits.size(); ++iHit)
{
  const Hit &hit = hits[iHit];
  if( (hit.x > xLow) && (hit.x < xHigh) && 
      (hit.y > yLow) && (hit.y < yHigh) &&
      (hit.t > tLow) && (hit.t < tHigh) )
    flag = true;
}
if (flag)
  for (size_t ipHit=0; ipHit<pHits.size() ;++ipHit)
  {
     const photonHit &phit = pHits[i];
     h1.Fill(phit.e);
  }

5.)
//plot the detector picture for a given t//
//plot tof for given x,y//
TH2D h2("DetPicture","DetPicture",300,-60,60,300,-60,60);
TH1D h1("tof","tof",1000,0,maxTof);
const std::vector<Hit> &hits = Instrument01.detectors[0].hits;
for (size_t iHit=0; iHit<hits.size(); ++iHit)
{
  const Hit &hit = hits[iHit];
  if( (hit.t > tLow) && (hit.t < tHigh) )
    h2.Fill(hit.x,hit.y);
  if( (hit.x > xLow) && (hit.x < xHigh) && 
      (hit.y > yLow) && (hit.y < yHigh) )
    h1.Fill(hit.t);
}

6.)
//plot t1 vs t2 of the same detector no condition//
TH2D h2("coincidence","coincidence",300,0,maxtof,300,0,maxtof);
const std::vector<Hit> &hits = Instrument01.detectors[0].hits;
for (size_t iHit=0; iHit<hits.size(); ++iHit)
  for (size_t iHit2=iHit+1; iHit2<hits.size(); ++iHit2)
  {
    const Hit &hit = hits[iHit];
    const Hit &hit2 = hits[iHit2];
    h2.Fill(hit.t, hit2.t);
  }

7.)
//plot t1 vs t2 of the two detectors no condition//
TH2D h2("coincidence","coincidence",300,0,maxtof,300,0,maxtof);
const std::vector<Hit> &hits  = Instrument01.detectors[0].hits;
const std::vector<Hit> &hits2 = Instrument01.detectors[1].hits;
for (size_t iHit=0; iHit<hits.size(); ++iHit)
  for (size_t iHit2=0; iHit2<hits2.size(); ++iHit2)
  {
    const Hit &hit = hits[iHit];
    const Hit &hit2 = hits2[iHit2];
    h2.Fill(hit.t, hit2.t);
  }

8.)
//instrument information contained in map is with a given value//
//plot spectrum//
TH1D h1("Spec","spec",800,0,16000);
std::map<std::string, double> &info = Instrument04.map;
if (info["someInfo"] >lowlimit && info["someInfo"] < highlimit)
  for (size_t ipHit=0; ipHit<pHits.size() ;++ipHit)
  {
     const photonHit &phit = pHits[i];
     h1.Fill(phit.e);
  }

Can I use the TTree::Draw and TCuts for the conditions to do this?
I have been reading the TTree chapter of the current users guide. Especially the TTree::Draw Examples. But it was
not obvious to me how I can use the TTree::Draw and TCuts to archieve the above.
If I can use TCuts, how do I have to do it? Could you point me to another resource where something, like I want
to archive is beeing described?

Thank you,
Lutz

Hi,

sorry for the late reply! Yes, you should be able to do the same with TCut and TTree::Draw(). We don’t have a tutorial, but see e.g. this ancient list mail: root.cern.ch/root/roottalk/roottalk01/3437.html Also see the doc of TTree::Draw() which explains how to retrieve or define the histogram filled by TTree::Draw().

Let us know if you need more hints!

Cheers, Axel.