Index: ct/tools/marsmacros/mc2csv/MonteCarlo.C
===================================================================
--- /fact/tools/marsmacros/mc2csv/MonteCarlo.C	(revision 14797)
+++ 	(revision )
@@ -1,998 +1,0 @@
-#include "MonteCarlo.h"
-
-// --------------------------------------------------------------------------
-// Default constructor. Initiates Pointers and Variables to NULL or 0
-//
-MonteCarlo::MonteCarlo()
-{
-    InitVariables();
-
-    return;
-}
-
-MonteCarlo::MonteCarlo(
-        TString filename
-        )
-{
-    InitVariables();
-
-    mFileName   = filename;
-
-    // open root file return if it cannot be opend
-    if ( !OpenRootFile() ) return;
-
-    LoadEventTree(  "Events");
-    LoadHeaderTree( "RunHeaders");
-
-    ReadRunHeader();
-
-    return;
-}
-
-MonteCarlo::MonteCarlo(
-        TString filename,
-        TString evtsTreeName
-        )
-{
-    InitVariables();
-
-    mFileName   = filename;
-
-    // open root file return if it cannot be opend
-    if ( !OpenRootFile() ) return;
-
-    LoadEventTree(  evtsTreeName);
-    LoadHeaderTree( "RunHeaders");
-
-    ReadRunHeader();
-
-    return;
-}
-
-MonteCarlo::MonteCarlo(
-        TString filename,
-        TString evtsTreeName,
-        TString headerTreeName
-        )
-{
-    InitVariables();
-
-    mFileName   = filename;
-
-    // open root file return if it cannot be opend
-    if ( !OpenRootFile() ) return;
-
-    LoadEventTree(  evtsTreeName);
-    LoadHeaderTree( headerTreeName);
-
-    ReadRunHeader();
-
-    return;
-}
-
-// --------------------------------------------------------------------------
-// Destructor
-//
-MonteCarlo::~MonteCarlo(void)
-{
-    delete[] mpPixel;
-
-    CloseRootFile();
-
-    delete mpRootFile;
-
-    return;
-}
-
-// --------------------------------------------------------------------------
-// Initiates Pointers and Variables to NULL or 0
-//
-void
-MonteCarlo::InitVariables()
-{
-    // set variables' default values
-    mEventNumber    = 0;
-    mNumberOfEvents = 2;
-    mVerbosityLvl   = 3;
-    mFileName       = "";
-
-    // set default seperator in CSV
-    mSeparator      = " ";
-
-    // source file
-    mpRootFile      = NULL;
-    mRootFileOpend  = false;
-
-    // Trees
-    mpEventTree     = NULL;
-    mpHeaderTree    = NULL;
-
-
-    //header data types
-    mpIntendedPulsePos      = NULL;
-    mpMcRunHeader           = NULL;
-    mpGeomCam               = NULL;
-    mpRawRunHeader          = NULL;
-    mpCorsikaRunHeader      = NULL;
-
-    //Evt data types
-    mpElectronicNoise       = NULL;
-    mpRawEventData          = NULL;
-    mpIncidentAngle         = NULL;
-    mpMcEventMetaData       = NULL;
-    mpRawEventHeader        = NULL;
-    mpCorsikaEvtHeader      = NULL;
-    //
-
-    // containers
-    mpPixel         = NULL;
-//    mpSamples       = NULL;
-
-    return;
-}
-
-// ==========================================================================
-// Setters
-//
-
-void
-MonteCarlo::SetVerbosityLevel(int verbLvl)
-{
-    mVerbosityLvl = verbLvl;
-    return;
-}
-
-void
-MonteCarlo::SetSeparator(char sep)
-{
-    mSeparator = sep;
-    return;
-}
-
-// ==========================================================================
-// Getters
-//
-
-int
-MonteCarlo::GetVerbosityLevel()
-{
-    return mVerbosityLvl;
-}
-
-TString
-MonteCarlo::GetSeparator()
-{
-    return mSeparator;
-}
-
-// ==========================================================================
-// Root file handling
-//
-
-int
-MonteCarlo::OpenRootFile()
-{
-    if (mVerbosityLvl > 0) cout << "...opening root file: " << mFileName << endl;
-
-    mpRootFile = new TFile(mFileName, "READ");
-
-    //check if root file could be opened
-    if (!mpRootFile->IsOpen())
-    {
-        cout << "ERROR - Could not find file " << mFileName << endl;
-        mRootFileOpend =false;
-        return 0;
-    }
-    mRootFileOpend = true;
-    return 1;
-}
-
-void
-MonteCarlo::CloseRootFile()
-{
-    if (mVerbosityLvl > 0) cout << "...closing root file: " << mFileName << endl;
-
-    // close root file
-    // If option == "R", all TProcessIDs referenced by this file are deleted.
-    mpRootFile->Close("R");
-
-    mpRootFile=NULL;
-
-    return;
-}
-
-void
-MonteCarlo::LoadHeaderTree(TString treeName)
-{
-    if (mVerbosityLvl > 0) cout << "...loading run header tree" << endl;
-
-    mpHeaderTree       = (TTree*)mpRootFile->Get(treeName);
-
-    //check if mpHeaderTree exists
-    if (mpHeaderTree->IsZombie())
-    {
-        cout << "...could not load tree" << endl;
-        return;
-    }
-
-    // =======================================================================
-    //Set Adresses to Branches in RunHeader-Tree
-
-    // -----------------------------------------------------------------------
-
-    // MGeomCam
-    if ( mpHeaderTree->GetBranchStatus("MGeomCam.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MGeomCam" << endl;
-        mpHeaderTree->SetBranchAddress("MGeomCam.",         &mpGeomCam);
-    }
-    else cout << "...could not load branch: MGeomCam" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // IntendedPulsePos
-    if ( mpHeaderTree->GetBranchStatus("IntendedPulsePos.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...IntendedPulsePos" << endl;
-        mpHeaderTree->SetBranchAddress("IntendedPulsePos.", &mpIntendedPulsePos);
-    }
-    else cout << "...could not load branch: IntendedPulsePos" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MMcRunHeader
-    if ( mpHeaderTree->GetBranchStatus("MMcRunHeader.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MMcRunHeader" << endl;
-        mpHeaderTree->SetBranchAddress("MMcRunHeader.",     &mpMcRunHeader);
-    }
-    else cout << "...could not load branch: MMcRunHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // ElectronicNoise
-    if ( mpHeaderTree->GetBranchStatus("ElectronicNoise.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...ElectronicNoise" << endl;
-        mpHeaderTree->SetBranchAddress("ElectronicNoise.",  &mpElectronicNoise);
-    }
-    else cout << "...could not load branch: ElectronicNoise" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MRawRunHeader
-    if ( mpHeaderTree->GetBranchStatus("MRawRunHeader.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MRawRunHeader" << endl;
-        mpHeaderTree->SetBranchAddress("MRawRunHeader.",    &mpRawRunHeader);
-    }
-    else cout << "...could not load branch: MRawRunHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MCorsikaRunHeader
-    if ( mpHeaderTree->GetBranchStatus("MCorsikaRunHeader.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MCorsikaRunHeader" << endl;
-        mpHeaderTree->SetBranchAddress("MCorsikaRunHeader.",&mpCorsikaRunHeader);
-    }
-    else cout << "...could not load branch: MCorsikaRunHeader" << endl;
-
-    // =======================================================================
-
-    return;
-}
-
-
-void
-MonteCarlo::ReadRunHeader()
-{
-    // Read Values from RunHeader-Tree
-
-    if (mVerbosityLvl > 0)
-        cout << "...reading run header " << mpHeaderTree << endl;
-
-    //Get first and only entry
-    mpHeaderTree->GetEntry();
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MGeomCam" Branch
-    if ( mpGeomCam != NULL)
-    {
-        //Getter functions from "MGeomCamFACT.h"
-        mCamDist                = mpGeomCam->GetCameraDist();
-        mNumberOfPixels         = mpGeomCam->GetNumPixels();
-        mNumberOfSectors        = mpGeomCam->GetNumSectors();
-        mNumberOfAreas          = mpGeomCam->GetNumAreas();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MGeomCam" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "IntendedPulsePos" Branch
-    if ( mpIntendedPulsePos != NULL)
-    {
-        mIntendedPulsePos       = mpIntendedPulsePos->GetVal();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: IntendedPulsePos" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MMcRunHeader" Branch from event Tree
-    if ( mpMcRunHeader != NULL)
-    {
-        //Getter functions from "MMcRunHeader.hxx"
-        mNumSimulatedShowers    = mpMcRunHeader->GetNumSimulatedShowers();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MMcRunHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get number of Events from event Tree
-    if ( mpEventTree != NULL)
-    {
-        mNumberOfEntries        = mpEventTree->GetEntries();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read number of Events from event Tree" << endl;
-
-    if (mVerbosityLvl > 0)
-        cout << "Event Tree has " << mNumberOfEntries << " entries" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MRawRunHeader" Branch
-    if ( mpRawRunHeader != NULL)
-    {
-        //Getter functions from "MRawRunHeader.h"
-        mNumberOfEvents         = mpRawRunHeader->GetNumEvents();
-        mNumberOfEventsRead     = mpRawRunHeader->GetNumEventsRead();
-        mSamplingFrequency      = mpRawRunHeader->GetFreqSampling();
-        mSourceName             = mpRawRunHeader->GetSourceName();
-        mFileNumber             = mpRawRunHeader->GetFileNumber();
-        mNumberOfSamples        = mpRawRunHeader->GetNumSamplesHiGain();
-        mNumberOfBytes          = mpRawRunHeader->GetNumBytesPerSample();
-        mRunNumber              = mpRawRunHeader->GetRunNumber();
-        mRunType                = mpRawRunHeader->GetRunType();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MRawRunHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MCorsikaRunHeader" Branch
-    if ( mpCorsikaRunHeader != NULL)
-    {
-        //Getter functions from "MCorsikaRunHeader.h"
-        mSlopeSpectrum          = mpCorsikaRunHeader->GetSlopeSpectrum();
-        mEnergyMin              = mpCorsikaRunHeader->GetEnergyMin();
-        mEnergyMax              = mpCorsikaRunHeader->GetEnergyMax();
-        mZdMin                  = mpCorsikaRunHeader->GetZdMin();
-        mZdMax                  = mpCorsikaRunHeader->GetZdMax();
-        mAzMin                  = mpCorsikaRunHeader->GetAzMin();
-        mAzMax                  = mpCorsikaRunHeader->GetAzMax();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MCorsikaRunHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // delete Pixel Array before you set refferences for a new one
-    // in case it is existing
-    if (mpPixel != NULL)
-    {
-        delete[] mpPixel;
-    }
-    mpPixel = new pixel_t[mNumberOfPixels];
-
-    // -----------------------------------------------------------------------
-
-    //Get Pedestal from "ElectronicNoise" Branch
-    if ( mpElectronicNoise != NULL)
-    {
-        if (mVerbosityLvl > 1) cout << "   ...reading pedestal offsets" << endl;
-
-        // Loop over all pixel: Read Pedestal Offset
-        for ( int i = 0; i < mNumberOfPixels; i++ )
-        {
-            // check if array entry exists
-            if ( &(mpElectronicNoise[0][i]) != NULL)
-            {
-                //tricky stuff!!!
-                // mpElectronicNoise is a MPedestalCam Array
-                // individual pixel pedestals are stored in a MPedestalPix array
-                // the [] operator is overloaded in MPedestalCam
-                // and returning a MPedestalPix at position [i]
-                // MPedestalPix hast a Getter called GetPedestal()
-                mpPixel[i].pedestal   = mpElectronicNoise[0][i].GetPedestal();
-            }
-            else if (mVerbosityLvl > 2)
-            {
-                cout << "   ...cannot read pedestal offset" << endl;
-            }
-        }
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: ElectronicNoise" << endl;
-
-    return;
-}
-
-void
-MonteCarlo::LoadEventTree(TString treeName)
-{
-    if (mVerbosityLvl > 0) cout << "...loading event tree" << endl;
-
-    mpEventTree       = (TTree*)mpRootFile->Get(treeName);
-
-    if (mpEventTree->IsZombie())
-    {
-        cout << "...could not load tree" << endl;
-        return;
-    }
-
-    // =======================================================================
-    //Set Adresses to Branches in Events-Tree
-
-    if (mVerbosityLvl > 1) cout << "...SetBranchAddresses:" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MRawEvtData
-    if ( mpEventTree->GetBranchStatus("MRawEvtData.") != -1 )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MRawEvtData" << endl;
-        mpEventTree->SetBranchAddress("MRawEvtData.",       &mpRawEventData);
-    }
-    else cout << "...could not load branch: MRawEvtData" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // IncidentAngle
-    if ( mpEventTree->GetBranchStatus("IncidentAngle.") )
-    {
-        //FIX ME: THIS VALUE IS NOT EXISTANT IN EVERY MC FILE
-
-        if (mVerbosityLvl > 1) cout << "   ...IncidentAngle" << endl;
-        mpEventTree->SetBranchAddress("IncidentAngle.",     &mpIncidentAngle);
-    }
-    else cout << "...could not load branch: IncidentAngle" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MMcEvt
-    if ( mpEventTree->GetBranchStatus("MMcEvt.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...McEvt" << endl;
-        mpEventTree->SetBranchAddress("MMcEvt.",            &mpMcEventMetaData);
-    }
-    else cout << "...could not load branch: McEvt" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MRawEvtHeader
-    if ( mpEventTree->GetBranchStatus("MRawEvtHeader.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MRawEventHeader" << endl;
-        mpEventTree->SetBranchAddress("MRawEvtHeader.",     &mpRawEventHeader);
-    }
-    else cout << "...could not load branch: MRawEvtHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // MCorsikaEvtHeader
-    if ( mpEventTree->GetBranchStatus("MCorsikaEvtHeader.") )
-    {
-        if (mVerbosityLvl > 1) cout << "   ...MCorsikaEvtHeader" << endl;
-        mpEventTree->SetBranchAddress("MCorsikaEvtHeader.", &mpCorsikaEvtHeader);
-    }
-    else cout << "...could not load branch: MCorsikaEvtHeader" << endl;
-
-    // =======================================================================
-
-    return;
-}
-
-void
-MonteCarlo::ReadEventMetaData()
-{
-    if (mVerbosityLvl > 1)
-        cout << "...reading event header" << endl;
-
-    //Get values from "MGeomCamFACT" Branch
-    if ( mpIncidentAngle != NULL)
-    {
-        //Getter functions from "MGeomCamFACT.h"
-        mIncidentAngle          = mpIncidentAngle->GetVal();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MGeomCamFACT" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MMcEvt" Branch
-    if ( mpMcEventMetaData != NULL)
-    {
-        //The following Getter Functions can be found in MMcEvt.h
-        mCorsikaEventNumber     = mpMcEventMetaData->GetEvtNumber();
-        mPhotElFromShower       = mpMcEventMetaData->GetPhotElfromShower();
-        mPhotElinCamera         = mpMcEventMetaData->GetPhotElinCamera();
-            //The following Getter Functions can be found in MMcEvtBasic.h
-        mPartId                 = mpMcEventMetaData->GetPartId();
-        mPartName               = mpMcEventMetaData->GetParticleName(mPartId);
-        mPartSymbol             = mpMcEventMetaData->GetParticleSymbol(mPartId);
-        mEnergy                 = mpMcEventMetaData->GetEnergy();
-        mImpact                 = mpMcEventMetaData->GetImpact();
-        mTelescopePhi           = mpMcEventMetaData->GetTelescopePhi();
-        mTelescopeTheta         = mpMcEventMetaData->GetTelescopeTheta();
-        mPhi                    = mpMcEventMetaData->GetParticlePhi();
-        mTheta                  = mpMcEventMetaData->GetParticleTheta();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MMcEvt" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MRawEventHeader" Branch
-    if ( mpRawEventHeader != NULL)
-    {
-        //Getter functions from "MRawEventHeader.h"
-        mEventNumber            = mpRawEventHeader->GetDAQEvtNumber();
-        mNumTriggerLvl1         = mpRawEventHeader->GetNumTrigLvl1();
-        mNumTriggerLvl2         = mpRawEventHeader->GetNumTrigLvl2();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MRawEventHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    //Get values from "MCorsikaEvtHeader" Branch
-    if ( mpCorsikaEvtHeader != NULL)
-    {
-        //Getter functions from "MCorsikaEvtHeader.h"
-        mFirstInteractionHeight = mpCorsikaEvtHeader->GetFirstInteractionHeight();
-        mEvtReuse               = mpCorsikaEvtHeader->GetNumReuse();
-        mMomentumX              = mpCorsikaEvtHeader->GetMomentum().X();
-        mMomentumY              = mpCorsikaEvtHeader->GetMomentum().Y();
-        mMomentumZ              = mpCorsikaEvtHeader->GetMomentum().Z();
-        mZd                     = mpCorsikaEvtHeader->GetZd();
-        mAz                     = mpCorsikaEvtHeader->GetAz();
-        mX                      = mpCorsikaEvtHeader->GetX();
-        mY                      = mpCorsikaEvtHeader->GetY();
-    }
-    else if (mVerbosityLvl > 2)
-        cout << "...could not read data from: MCorsikaEvtHeader" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // mWeightedNumPhotons     = mpCorsikaEvtHeader->Get;
-    // no getter function, no idea how to extract information
-
-    return;
-}
-
-void
-MonteCarlo::ReadEventRawData()
-{
-    if (mVerbosityLvl > 1) cout << "...reading event raw data" << endl;
-
-    // -----------------------------------------------------------------------
-
-    // delete Pixel Array before you set refferences for a new one
-    // in case it is existing
-    if (mpPixel != NULL)
-    {
-        delete[] mpPixel;
-    }
-    mpPixel = new pixel_t[mNumberOfPixels];
-
-    // -----------------------------------------------------------------------
-
-    if ( mpRawEventData == NULL)
-    {
-        cout << "ERROR: cannot read event data" << endl;
-        return;
-    }
-
-    // you have to set this before you can read information
-    // from a magic binary file
-    mpRawEventData->InitRead(mpRawRunHeader);
-
-    int pix_first_sample;
-
-    // -----------------------------------------------------------------------
-
-    //array to contain alle samples of all pixel of a event
-    unsigned short* all_raw_data    = NULL;
-
-    if ( mpRawEventData != NULL)
-    {
-        // point raw data array to RawEventData Array in Event Tree
-        all_raw_data    = (unsigned short*) mpRawEventData->GetSamples();
-        /*
-//  FADC samples (hi gain) of all pixels
-//  This is an array of Byte_t variables. The value of a FADC sample has a
-//  size of n=fNumBytesPerSample bytes. Therefore, a FADC sample value will
-//  occupy n consecutive elements of this array (little endian ordering, i.e,
-//  less significant bits (and bytes) go first.
-//  If m = GetNumHiGainSamples(), the n bytes corresponding to the value of the
-//  i-th FADC sample of the j-th pixel are stored in the n consecutive
-//  positions of this array, starting from fHiGainFadcSamples[j*n*m+i*n]
-*/
-    }
-    else cout << "...cannot read event raw data" << endl;
-
-    // -----------------------------------------------------------------------
-
-    if (mVerbosityLvl > 1)
-        cout << "...pixel progress: ";
-
-    //Loop over all camera pixel and read eEvent raw data, pixel ID and pedestal offset
-    for ( int i = 0; i < mNumberOfPixels; i++ )
-    {
-        if (mVerbosityLvl > 1){
-            if ( !(i%(mNumberOfPixels/10) ))
-                cout << i/(mNumberOfPixels*1.0)*100 << "%.." ;
-            if ( i == mNumberOfPixels-1)
-                cout << "100% " ;
-        }
-
-        // Read Pedestal Offset and store it in classes pixel_t array
-        if ( mpElectronicNoise != NULL)
-        {
-            mpPixel[i].pedestal   = mpElectronicNoise[0][i].GetPedestal();
-        }
-        else cout << "...cannot read pedestal offset" << endl;
-
-        // Read Pixel SoftId and store it in classes pixel_t array
-        if ( mpRawEventData != NULL)
-        {
-            mpPixel[i].SoftId     = mpRawEventData->GetPixelIds()[i];
-        }
-        else cout << "...cannot read pixel id" << endl;
-
-        pix_first_sample        = i*mNumberOfSamples;
-
-        // point beginning of class' pixel_t array to the address
-        // of pixel's first sample's adress in TTree
-        mpPixel[i].rawData      = &(all_raw_data[pix_first_sample]);
-
-    }
-
-    if (mVerbosityLvl > 1)
-        cout << endl;
-
-    return;
-}
-
-void
-MonteCarlo::ReadEvent(int Event)
-{
-    if (mVerbosityLvl > 0) cout << endl
-                                << "====================" << endl
-                                << "...reading Event: " << Event << endl
-                                << "====================" << endl;
-
-
-    //load certain event from tree
-    mpEventTree->GetEntry(Event);
-
-    //Get Event header data from TTree
-    ReadEventMetaData();
-
-    //Get Event raw data from TTree
-    ReadEventRawData();
-
-    return;
-}
-
-// ==========================================================================
-// csv file handling
-//
-
-void
-MonteCarlo::OpenCsvFile(TString fileName)
-{
-    mCsvFileName    = fileName;
-
-    if (mVerbosityLvl > 0) cout << "...opening csv file: " << mCsvFileName << endl;
-
-    mCsv.open( mCsvFileName );
-
-    return;
-}
-
-void
-MonteCarlo::CloseCsvFile()
-{
-    if (mVerbosityLvl > 0) cout << "...closing csv file: " << mCsvFileName << endl;
-
-    mCsv.close();
-
-    return;
-}
-
-void
-MonteCarlo::WriteMc2Csv(TString filename)
-{
-    if ( !mRootFileOpend ){
-        cout << "ERROR - no rootfile loaded, no data loaded, cannot write csv"
-             << endl;
-        return;
-    }
-
-    cout << "...writing mc to csv: " << filename << endl;
-    cout << "...processing " << mNumberOfEntries << "Events" << endl;
-
-    mCsvFileName = filename;
-    OpenCsvFile(mCsvFileName);
-
-    WriteFileInfo2Csv();
-    WriteRunHeaderInfo2Csv();
-    WriteRunHeader2Csv();
-
-    WritePedestalInfo2Csv();
-    WritePedestal2Csv();
-
-    WriteEventHeaderInfo2Csv();
-    WriteEventDataInfo2Csv();
-
-    // loop over all events from tree and write content to csv
-    //    for (int evt = 0; evt < mNumberOfEvents; evt++)
-    for (int evt = 0; evt < mNumberOfEntries; evt++)
-    {
-        ReadEvent(evt);
-        WriteEventHeader2Csv();
-        WriteEventData2Csv();
-    }
-
-    cout << endl << "...conversion done " << endl;
-
-    CloseCsvFile();
-    return;
-}
-
-void
-MonteCarlo::WriteFileInfo2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing file header to csv" << endl;
-
-    mCsv << "### ==========================================================="
-            << endl;
-    mCsv << "### =             FACT Monte Carlo                            ="
-            << endl;
-    mCsv << "### ==========================================================="
-            << endl;
-    mCsv << "### = FileInfo:                                               "
-            << endl;
-    mCsv << "### =                                                         "
-            << endl;
-    mCsv << "### = Source Name:       " << mSourceName << endl;
-    mCsv << "### = Number of Entries: " << mNumberOfEntries << endl;
-    mCsv << "### = Run Number:        " << mRunNumber << endl;
-    mCsv << "### = Run Type  :        " << mRunType << endl;
-    mCsv << "### = File Number:       " << mFileNumber << endl;
-    mCsv << "### ==========================================================="
-         << endl ;
-    mCsv << "###"
-         << endl ;
-
-    return;
-}
-
-void
-MonteCarlo::WriteRunHeaderInfo2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing run header names to csv" << endl;
-
-    mCsv << "### [RunHeader]" << endl;
-
-    mCsv << "# mNumberOfEntries" << mSeparator;
-    mCsv << "mIntendedPulsePos" << mSeparator;
-//    Csv << "mPedestalOffset" << mSeparator;
-    mCsv << "mNumSimulatedShowers" << mSeparator;
-    mCsv << "mNumberOfPixels" << mSeparator;
-    mCsv << "mNumberOfSamples" << mSeparator;
-//    mCsv << "mSampleSize" << mSeparator;
-    mCsv << "mCamDist" << mSeparator;
-    mCsv << "mSourceName" << mSeparator;
-    mCsv << "mSlopeSpectrum" << mSeparator;
-    mCsv << "mEnergyMin" << mSeparator;
-    mCsv << "mEnergyMax" << mSeparator;
-    mCsv << "mZdMin" << mSeparator;
-    mCsv << "mZdMax" << mSeparator;
-    mCsv << "mAzMin" << mSeparator;
-    mCsv << "mAzMax" << mSeparator;
-    mCsv << "mFileNumber" << mSeparator;
-    mCsv << "mRunnumber" << mSeparator;
-    mCsv << "mRunType" << endl;
-
-    return;
-}
-
-void
-MonteCarlo::WriteRunHeader2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing run header to csv" << endl;
-
-    mCsv << mNumberOfEntries << mSeparator;
-    mCsv << mIntendedPulsePos << mSeparator;
-//    mCsv << mPedestalOffset << mSeparator;
-    mCsv << mNumSimulatedShowers << mSeparator;
-    mCsv << mNumberOfPixels << mSeparator;
-    mCsv << mNumberOfSamples << mSeparator;
-//    mCsv << mSampleSize << mSeparator;
-    mCsv << mCamDist << mSeparator;
-    mCsv << mSourceName << mSeparator;
-    mCsv << mSlopeSpectrum << mSeparator;
-    mCsv << mEnergyMin << mSeparator;
-    mCsv << mEnergyMax << mSeparator;
-    mCsv << mZdMin << mSeparator;
-    mCsv << mZdMax << mSeparator;
-    mCsv << mAzMin << mSeparator;
-    mCsv << mAzMax << mSeparator;
-    mCsv << mFileNumber << mSeparator;
-    mCsv << mRunNumber << mSeparator;
-    mCsv << mRunType << endl;
-
-    return;
-}
-
-void
-MonteCarlo::WriteEventHeaderInfo2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing event header names to csv" << endl;
-
-    mCsv << "### [EventHeader]" << endl;
-
-    mCsv << "# mEventNumber" << mSeparator;
-    mCsv << "mNumberOfBytes" << mSeparator;
-    mCsv << "mIncidentAngle" << mSeparator;
-    mCsv << "mPartId" << mSeparator;
-    mCsv << "mEnergy" << mSeparator;
-    mCsv << "mImpact" << mSeparator;
-    mCsv << "mTelescopePhi" << mSeparator;
-    mCsv << "mTelescopeTheta" << mSeparator;
-    mCsv << "mPhi" << mSeparator;
-    mCsv << "mTheta" << mSeparator;
-    mCsv << "mCorsikaEventNumber" << mSeparator;
-    mCsv << "mPhotElFromShower" << mSeparator;
-    mCsv << "mEvtReuse" << mSeparator;
-    mCsv << "mNumTriggerLvl1" << mSeparator;
-    mCsv << "mFirstInteractionHeight" << mSeparator;
-    mCsv << "mMomentumX" << mSeparator;
-    mCsv << "mMomentumY" << mSeparator;
-    mCsv << "mMomentumZ" << mSeparator;
-    mCsv << "mZd" << mSeparator;
-    mCsv << "mAz" << mSeparator;
-    mCsv << "mX" << mSeparator;
-    mCsv << "mY" << mSeparator;
-//    mCsv << "mWeightedNumPhotons" ;
-    mCsv << endl;
-
-    return;
-}
-
-void
-MonteCarlo::WriteEventHeader2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing event header to csv" << endl;
-
-    mCsv << mEventNumber << mSeparator;
-    mCsv << mNumberOfBytes << mSeparator;
-    mCsv << mIncidentAngle << mSeparator;
-    mCsv << mPartId << mSeparator;
-    mCsv << mEnergy << mSeparator;
-    mCsv << mImpact << mSeparator;
-    mCsv << mTelescopePhi << mSeparator;
-    mCsv << mTelescopeTheta << mSeparator;
-    mCsv << mPhi << mSeparator;
-    mCsv << mTheta << mSeparator;
-    mCsv << mCorsikaEventNumber << mSeparator;
-    mCsv << mPhotElFromShower << mSeparator;
-    mCsv << mEvtReuse << mSeparator;
-    mCsv << mNumTriggerLvl1 << mSeparator;
-    mCsv << mFirstInteractionHeight << mSeparator;
-    mCsv << mMomentumX << mSeparator;
-    mCsv << mMomentumY << mSeparator;
-    mCsv << mMomentumZ << mSeparator;
-    mCsv << mZd << mSeparator;
-    mCsv << mAz << mSeparator;
-    mCsv << mX << mSeparator;
-    mCsv << mY << mSeparator;
-//    mCsv << mWeightedNumPhotons ;
-    mCsv << endl;
-
-    return;
-}
-
-void
-MonteCarlo::WriteEventDataInfo2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing event categories to csv" << endl;
-
-    mCsv << "### [RawData]" << endl;
-    mCsv << "# mEventNumber" << mSeparator;
-    mCsv << "pixelID" << mSeparator;
-//     mCsv << "pixelPedestal" << mSeparator;
-
-    // Loop over number of all samples in pixel
-    for (int i = 0; i < mNumberOfSamples; i++)
-    {
-        mCsv << "Raw_" << i << mSeparator;
-    }
-    mCsv << endl;
-
-    return;
-}
-
-void
-MonteCarlo::WriteEventData2Csv()
-{
-    if (mVerbosityLvl > 0) cout << "...writing event data to csv" << endl;
-
-    // Loop over all pixels and write pixeldata to csv
-    for (int i = 0; i < mNumberOfPixels; i++)
-    {
-        WritePixelData2Csv(i);
-    }
-
-    return;
-}
-
-void
-MonteCarlo::WritePixelData2Csv(int pixelID)
-{
-    if (mVerbosityLvl > 3) cout << "...writing pixel data to csv" << endl;
-    mCsv << mEventNumber << mSeparator;
-    mCsv << mpPixel[pixelID].SoftId << mSeparator;
-//    mCsv << mpPixel[pixelID].pedestal << mSeparator;
-
-    // Loop over number of all samples in pixel and write samples content to csv
-    for (int i = 0; i < mNumberOfSamples; i++)
-    {
-         mCsv << mpPixel[pixelID].rawData[i] << mSeparator;
-    }
-    mCsv << endl;
-
-    return;
-}
-
-void
-MonteCarlo::WritePedestalInfo2Csv()
-{
-    mCsv << "### [Pedestal]" << endl;
-//    mCsv << "# SoftID" ;
-//    mCsv << mSeparator ;
-//    mCsv << "Pedestal" << endl;
-}
-
-void
-MonteCarlo::WritePedestal2Csv()
-{
-    if (mVerbosityLvl > 3) cout << "...writing pedestal info to csv" << endl;
-
-    // Loop over all pixels and write pixel pedestal to csv
-    for (int pixelID = 0; pixelID < mNumberOfPixels; pixelID++)
-    {
-//        mCsv << mpPixel[pixelID].SoftId;
-        mCsv << mpPixel[pixelID].pedestal;
-        if (pixelID < mNumberOfPixels -1)
-            mCsv << mSeparator;
-    }
-    mCsv << endl;
-
-    return;
-}
-
-
-
-
-
-
-
-
Index: ct/tools/marsmacros/mc2csv/MonteCarlo.h
===================================================================
--- /fact/tools/marsmacros/mc2csv/MonteCarlo.h	(revision 14797)
+++ 	(revision )
@@ -1,420 +1,0 @@
-#ifndef MONTECARLO_H
-#define MONTECARLO_H
-
-/*! \class MonteCarlo
- * \brief Monte Carlo class to handle MC-Data from mars-root-file produced with ceres.
- *
- * #include "MonteCarlo.h" <BR>
- * -llib
- *
- * Class can be used in Mars to load Monte Carlo data from a root-file
- * containing Mars classes that where produced by CERES
- *
- * @see something
- */
-
-
-// SYSTEM INCLUDES
-#include <vector>
-#include <fstream>
-#include <endian.h>
-#include <stdio.h>
-
-#include <TSystem.h>
-#include <TString.h>
-#include <TStyle.h>
-#include <TCanvas.h>
-#include <TMath.h>
-#include <TFile.h>
-#include <TH1.h>
-#include <TH2F.h>
-#include <TF1.h>
-#include <TTree.h>
-//
-
-// PROJECT INCLUDES
-#include "MStatusDisplay.h"
-#include "MStatusArray.h"
-#include "MParContainer.h"
-
-#include "MParameters.h"
-#include "MPedestalCam.h"
-#include "MMcRunHeader.hxx"
-#include "MGeomCamFACT.h"
-#include "MRawRunHeader.h"
-#include "MCorsikaRunHeader.h"
-
-//Evt data types
-#include "MRawEvtData.h"
-#include "MPedestalCam.h"
-#include "MMcEvt.hxx"
-#include "MMcEvtBasic.h"
-#include "MRawEvtHeader.h"
-#include "MCorsikaEvtHeader.h"
-
-
-
-//
-
-// LOCAL INCLUDES
-//
-
-// FORWARD REFERENCES
-//
-
-using namespace std;
-using namespace TMath;
-
-struct pixel_t          //struct gathering information of a camera pixel
-{
-    int                 SoftId;         //Mars Software ID of Pixel
-//    int                 ChId;         //continous Hardware ID of Pixel
-    unsigned short*     rawData;        //array with raw data of slices* amplitudes
-    float               pedestal;       //amplitude of baseline
-};
-
-class MonteCarlo
-{
-public:
-// LIFECYCLE
-
-    /** Default constructor.
-    */
-    MonteCarlo();                       // Default constructor
-    /*! constructor
-     * \param filename name of mc data file that will to load
-    */
-    MonteCarlo( TString filename);      // name of mc data file will to load
-    /*! constructor
-     * \param filename name of mc data file that will to load
-     * \param evtsTreeName name of tree containg events
-    */
-    MonteCarlo( TString filename,       // name of mc data file will to load
-                TString evtsTreeName);  // name of tree containg events
-    /*! constructor
-     * \param filename name of mc data file that will to load
-     * \param evtsTreeName name of tree containg events
-     * \param headerTreeName name of tree containg run meta data
-    */
-    MonteCarlo( TString filename,       // name of mc data file will to load
-                TString evtsTreeName,   // name of tree containg events
-                TString headerTreeName);// name of tree containg meta data
-
-
-//    /** Copy constructor.
-//    *
-//    * @param from The value to copy to this object.
-//    */
-//    MonteCarlo(const MonteCarlo& from);
-
-
-    /** Destructor.
-    */
-    ~MonteCarlo(void);
-
-
-// OPERATORS
-
-//    /** Assignment operator.
-//    *
-//    * @param from THe value to assign to this object.
-//    *
-//    * @return A reference to this object.
-//    */
-//    MonteCarlo&                     operator=(const XX& from);
-
-// OPERATIONS
-private:
-    /*! Initiate all pointer Variables to NULL*/
-    void InitVariables();
-
-public:
-    /*! Write Monte Carlo Data into a Csv-file WriteMc2Csv(filename)
-     * \param filename The Filename of the CSV File to which data will be written
-    */
-    void WriteMc2Csv(TString filename );
-
-    /*! write pixels' raw data for a given pixel into the given csv file
-     * \param pixelID Software ID of pixel
-     */
-    void WritePixelData2Csv(int pixelID);
-
-    /*! loop over all pixels and call WritePixelData2Csv
-     */
-    void WriteEventData2Csv();
-
-    /*! write table headings for coulums with pixels' raw data
-     */
-    void WriteEventDataInfo2Csv();
-
-    /*! write table headings for coulums with event meta information
-     */
-    void WriteEventHeaderInfo2Csv();
-
-    /*! write meta information of current event to csv
-     */
-    void WriteEventHeader2Csv();
-
-    /*! write table headings for coulums with run meta information
-     */
-    void WriteRunHeaderInfo2Csv();
-
-    /*! write meta information of current run to csv
-     */
-    void WriteRunHeader2Csv();
-
-    /*! write the header of the csv file containing brief info about the converted mc file
-     */
-    void WriteFileInfo2Csv();
-
-    /*! write table headings for coulums with pixels' pedestal amplitude
-     */
-    void WritePedestal2Csv();
-
-    /*! write table headings for coulums with pixels' pedestal amplitude
-     */
-    void WritePedestalInfo2Csv();
-
-
-// ACCESS
-    /*! set column seperator for csv
-     * \param sep column seperator for csv
-     */
-    void SetSeparator(char sep);
-
-    /*! Get column seperator for csv
-     * \param sep column seperator for csv
-     */
-    TString GetSeparator();
-
-    /*! set the verbosity level for verbosity cout on cmd-line
-     * \param verbLvl Votrbosity Level
-     */
-    void SetVerbosityLevel(int verbLvl);
-
-    /*! Get the verbosity level for verbosity cout on cmd-line
-     */
-    int  GetVerbosityLevel();
-
-    /*! Open the mars-root-file produced with ceres
-     */
-    int  OpenRootFile();
-
-    /*!  Close the mars-root-file produced with ceres
-     */
-    void CloseRootFile();
-
-    /*! Open csv-file to which data will be written
-     * \param fileName Filename of the csv-file e.g. "mc20120605.csv"
-     */
-    void OpenCsvFile(   TString fileName);
-
-    /*! Close csv-file to which data was be written
-     */
-    void CloseCsvFile();
-
-    /*! set according pointers to tree containing event information and its branches
-     * \param treeName Name of TTree containing event information
-     */
-    void LoadEventTree( TString treeName);
-
-    /*! set according pointers to tree containing run information and its branches
-     * \param treeName Name of TTree containing run information
-     */
-    void LoadHeaderTree(TString treeName);
-
-    /*! set values of members  to according leafs in TTree for run meta data
-     */
-    void ReadRunHeader();
-
-    /*! set values of members  to according leafs in TTree for event raw data
-     */
-    void ReadEventRawData();
-
-    /*! set values of members  to according leafs in TTree for event meta data
-     */
-    void ReadEventMetaData();
-
-    /*! call ReadEventRawData() and ReadEventMetaData() for given event
-     * \param Event Event ID to read data
-     */
-    void ReadEvent(int Event);
-
-// INQUIRY
-private:
-    /*! Verbostiy Level */
-    int                 mVerbosityLvl;
-    /*! Whether the rootfile is open */
-    bool                mRootFileOpend;
-
-    /*! filename of output csv file */
-    TString             mCsvFileName;
-    /*! steam into csv output file */
-    ofstream            mCsv;
-    /*! filename of input root file */
-    TString             mFileName;
-    /*! pointer to input root file */
-    TFile*              mpRootFile;
-    /*! Array for pixels' raw data */
-    pixel_t*            mpPixel;
-
-    /*! pointer to event tree */
-    TTree*              mpEventTree;
-    /*! pointer to run header tree */
-    TTree*              mpHeaderTree;
-
-    //run header tree branches
-    /*! mars class pointer to branch with same name in TTree */
-    MParameterD*        mpIntendedPulsePos;
-    /*! mars class pointer to branch with same name in TTree */
-    MMcRunHeader*       mpMcRunHeader;
-    /*! mars class pointer to branch with same name in TTree */
-    MGeomCamFACT*       mpGeomCam;
-    /*! mars class pointer to branch with same name in TTree */
-    MRawRunHeader*      mpRawRunHeader;
-    /*! mars class pointer to branch with same name in TTree */
-    MCorsikaRunHeader*  mpCorsikaRunHeader;
-
-    //Event tree branches
-    /*! mars class pointer to branch with same name in TTree */
-    MPedestalCam*       mpElectronicNoise;
-    /*! mars class pointer to branch with same name in TTree */
-    MRawEvtData*        mpRawEventData;
-    /*! mars class pointer to branch with same name in TTree */
-    MParameterD*        mpIncidentAngle;
-    /*! mars class pointer to branch "MMcEvt" in TTree */
-    MMcEvt*             mpMcEventMetaData;
-    /*! mars class pointer to branch with same name in TTree */
-    MRawEvtHeader*      mpRawEventHeader;
-    /*! mars class pointer to branch with same name in TTree */
-    MCorsikaEvtHeader*  mpCorsikaEvtHeader;
-
-//    /*! array with MC events raw data */
-//    unsigned short *    mpSamples;          // array with MC events raw data
-    /*! coulumn seperator in csv file */
-    TString             mSeparator;
-
-    //Run Meta Data
-    /*! number of entries(events) in event tree  */
-    int                 mNumberOfEntries;
-    /*! number of events in file NOT WORKING WITH CURRENT CERES VERSION */
-    int                 mNumberOfEvents;
-    /*! position (slice) of simulated cherenkov pulse in pixel */
-    float               mIntendedPulsePos;
-    /*! number of showers simulated by corsika*/
-    int                 mNumSimulatedShowers;
-    /*! total number of simulated camera pixels */
-    int                 mNumberOfPixels;
-    /*! ??? */
-    int                 mNumberOfSectors;
-    /*! ??? */
-    int                 mNumberOfAreas;
-    /*! number of Samples (slices) -> simulated Region of interest */
-    float               mNumberOfSamples;
-    /*! simulated sampling frequency  */
-    float               mSamplingFrequency;
-    /*! ??? */
-    int                 mNumberOfEventsRead;
-    /*! ??? */
-    float               mCamDist;
-    /*! name of simulated source */
-    const char*         mSourceName;
-    /*! slope of simulated spectrum */
-    float               mSlopeSpectrum;
-    /*! minimum of simulated spectrum  */
-    float               mEnergyMin;
-    /*! maximum of simulated spectrum */
-    float               mEnergyMax;
-    /*! minimum Zenidth of simulated showers */
-    float               mZdMin;
-    /*! maximum Zenidth of simulated showers */
-    float               mZdMax;
-    /*! minimum Azimuth of simulated showers */
-    float               mAzMin;
-    /*! maximum Azimuth of simulated showers */
-    float               mAzMax;
-    /*! file number from raw run header */
-    unsigned int        mFileNumber;
-    /*! corsika run number */
-    int                 mRunNumber;
-    /*! runtype: e.g. Pedestal, data, calibration run,... */
-    int                 mRunType;
-    /*! number of bytes per sample */
-    int                 mNumberOfBytes;
-
-    //Event Meta Data
-    /*! Incident Angle */
-    float               mIncidentAngle;
-    /*! id of primary particle of shower */
-    int                 mPartId;
-    /*! energy of primary particle of shower */
-    float               mEnergy;
-    /*! impact parameter of primary particle of shower  */
-    float               mImpact;
-    /*! Telescope Phi of shower */
-    float               mTelescopePhi;
-    /*! Telescope Theta of shower */
-    float               mTelescopeTheta;
-    /*! Phi of shower */
-    float               mPhi;
-    /*! Theta of shower */
-    float               mTheta;
-    /*! name of primary particle of shower */
-    TString             mPartName;
-    /*! symbol of primary particle of shower */
-    TString             mPartSymbol;
-    /*! corsika event number */
-    unsigned int        mCorsikaEventNumber;
-    /*! Passed qe, coming from the shower */
-    unsigned int        mPhotElFromShower;
-    /*! usPhotElfromShower + mean of phe from NSB */
-    unsigned int        mPhotElinCamera;
-    /*! Number running from 0 to N-1, being N the number
-     * of times a Corsika event has been reused, by
-     * orienting the telescope in different ways or by
-     * setting it at a different location on the ground. */
-    int                 mEvtReuse;
-    /*! Number of Events from DAQ */
-    int                 mEventNumber;
-    /*! Number of 1st level tiggers between 2 events Used in MSimTrigger for the index of the trigger channel */
-    float               mNumTriggerLvl1;
-    /*! Number of 2nd level tiggers between 2 events */
-    float               mNumTriggerLvl2;
-    /*! [cm] z coordinate, first intercation height */
-    float               mFirstInteractionHeight;
-    /*! [GeV/c] "+west"    "-east" */
-    float               mMomentumX;
-    /*! [GeV/c] "+south"   "-north"
-     * (north denotes the magnet north which is defined to be in the geografic north!)
-     */
-    float               mMomentumY;
-    /*! [GeV/c] "+upwards" "-downwards" */
-    float               mMomentumZ;
-    /*! [rad] Zenith distance */
-    float               mZd;
-    /*! [rad] Azimuth (north=0; east=90)
-     * (north denotes the magnet north which is defined to be in the geografic north!)
-    */
-    float               mAz;
-    /*! [cm] Position of telescope on ground x / - impact parameter x */
-    float               mX;
-    /*! [cm] Position of telescope on gorund y / - impact parameter y */
-    float               mY;
-    /*! weighted number of photons arriving at observation level */
-//    int                 mWeightedNumPhotons;
-
-
-
-
-protected:
-
-};
-
-// INLINE METHODS
-//
-
-// EXTERNAL REFERENCES
-//
-
-#endif // MONTECARLO_H
-
Index: /fact/tools/marsmacros/mc2csv/MonteCarlo/MonteCarlo.C
===================================================================
--- /fact/tools/marsmacros/mc2csv/MonteCarlo/MonteCarlo.C	(revision 14798)
+++ /fact/tools/marsmacros/mc2csv/MonteCarlo/MonteCarlo.C	(revision 14798)
@@ -0,0 +1,998 @@
+#include "MonteCarlo.h"
+
+// --------------------------------------------------------------------------
+// Default constructor. Initiates Pointers and Variables to NULL or 0
+//
+MonteCarlo::MonteCarlo()
+{
+    InitVariables();
+
+    return;
+}
+
+MonteCarlo::MonteCarlo(
+        TString filename
+        )
+{
+    InitVariables();
+
+    mFileName   = filename;
+
+    // open root file return if it cannot be opend
+    if ( !OpenRootFile() ) return;
+
+    LoadEventTree(  "Events");
+    LoadHeaderTree( "RunHeaders");
+
+    ReadRunHeader();
+
+    return;
+}
+
+MonteCarlo::MonteCarlo(
+        TString filename,
+        TString evtsTreeName
+        )
+{
+    InitVariables();
+
+    mFileName   = filename;
+
+    // open root file return if it cannot be opend
+    if ( !OpenRootFile() ) return;
+
+    LoadEventTree(  evtsTreeName);
+    LoadHeaderTree( "RunHeaders");
+
+    ReadRunHeader();
+
+    return;
+}
+
+MonteCarlo::MonteCarlo(
+        TString filename,
+        TString evtsTreeName,
+        TString headerTreeName
+        )
+{
+    InitVariables();
+
+    mFileName   = filename;
+
+    // open root file return if it cannot be opend
+    if ( !OpenRootFile() ) return;
+
+    LoadEventTree(  evtsTreeName);
+    LoadHeaderTree( headerTreeName);
+
+    ReadRunHeader();
+
+    return;
+}
+
+// --------------------------------------------------------------------------
+// Destructor
+//
+MonteCarlo::~MonteCarlo(void)
+{
+    delete[] mpPixel;
+
+    CloseRootFile();
+
+    delete mpRootFile;
+
+    return;
+}
+
+// --------------------------------------------------------------------------
+// Initiates Pointers and Variables to NULL or 0
+//
+void
+MonteCarlo::InitVariables()
+{
+    // set variables' default values
+    mEventNumber    = 0;
+    mNumberOfEvents = 2;
+    mVerbosityLvl   = 3;
+    mFileName       = "";
+
+    // set default seperator in CSV
+    mSeparator      = " ";
+
+    // source file
+    mpRootFile      = NULL;
+    mRootFileOpend  = false;
+
+    // Trees
+    mpEventTree     = NULL;
+    mpHeaderTree    = NULL;
+
+
+    //header data types
+    mpIntendedPulsePos      = NULL;
+    mpMcRunHeader           = NULL;
+    mpGeomCam               = NULL;
+    mpRawRunHeader          = NULL;
+    mpCorsikaRunHeader      = NULL;
+
+    //Evt data types
+    mpElectronicNoise       = NULL;
+    mpRawEventData          = NULL;
+    mpIncidentAngle         = NULL;
+    mpMcEventMetaData       = NULL;
+    mpRawEventHeader        = NULL;
+    mpCorsikaEvtHeader      = NULL;
+    //
+
+    // containers
+    mpPixel         = NULL;
+//    mpSamples       = NULL;
+
+    return;
+}
+
+// ==========================================================================
+// Setters
+//
+
+void
+MonteCarlo::SetVerbosityLevel(int verbLvl)
+{
+    mVerbosityLvl = verbLvl;
+    return;
+}
+
+void
+MonteCarlo::SetSeparator(char sep)
+{
+    mSeparator = sep;
+    return;
+}
+
+// ==========================================================================
+// Getters
+//
+
+int
+MonteCarlo::GetVerbosityLevel()
+{
+    return mVerbosityLvl;
+}
+
+TString
+MonteCarlo::GetSeparator()
+{
+    return mSeparator;
+}
+
+// ==========================================================================
+// Root file handling
+//
+
+int
+MonteCarlo::OpenRootFile()
+{
+    if (mVerbosityLvl > 0) cout << "...opening root file: " << mFileName << endl;
+
+    mpRootFile = new TFile(mFileName, "READ");
+
+    //check if root file could be opened
+    if (!mpRootFile->IsOpen())
+    {
+        cout << "ERROR - Could not find file " << mFileName << endl;
+        mRootFileOpend =false;
+        return 0;
+    }
+    mRootFileOpend = true;
+    return 1;
+}
+
+void
+MonteCarlo::CloseRootFile()
+{
+    if (mVerbosityLvl > 0) cout << "...closing root file: " << mFileName << endl;
+
+    // close root file
+    // If option == "R", all TProcessIDs referenced by this file are deleted.
+    mpRootFile->Close("R");
+
+    mpRootFile=NULL;
+
+    return;
+}
+
+void
+MonteCarlo::LoadHeaderTree(TString treeName)
+{
+    if (mVerbosityLvl > 0) cout << "...loading run header tree" << endl;
+
+    mpHeaderTree       = (TTree*)mpRootFile->Get(treeName);
+
+    //check if mpHeaderTree exists
+    if (mpHeaderTree->IsZombie())
+    {
+        cout << "...could not load tree" << endl;
+        return;
+    }
+
+    // =======================================================================
+    //Set Adresses to Branches in RunHeader-Tree
+
+    // -----------------------------------------------------------------------
+
+    // MGeomCam
+    if ( mpHeaderTree->GetBranchStatus("MGeomCam.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MGeomCam" << endl;
+        mpHeaderTree->SetBranchAddress("MGeomCam.",         &mpGeomCam);
+    }
+    else cout << "...could not load branch: MGeomCam" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // IntendedPulsePos
+    if ( mpHeaderTree->GetBranchStatus("IntendedPulsePos.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...IntendedPulsePos" << endl;
+        mpHeaderTree->SetBranchAddress("IntendedPulsePos.", &mpIntendedPulsePos);
+    }
+    else cout << "...could not load branch: IntendedPulsePos" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MMcRunHeader
+    if ( mpHeaderTree->GetBranchStatus("MMcRunHeader.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MMcRunHeader" << endl;
+        mpHeaderTree->SetBranchAddress("MMcRunHeader.",     &mpMcRunHeader);
+    }
+    else cout << "...could not load branch: MMcRunHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // ElectronicNoise
+    if ( mpHeaderTree->GetBranchStatus("ElectronicNoise.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...ElectronicNoise" << endl;
+        mpHeaderTree->SetBranchAddress("ElectronicNoise.",  &mpElectronicNoise);
+    }
+    else cout << "...could not load branch: ElectronicNoise" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MRawRunHeader
+    if ( mpHeaderTree->GetBranchStatus("MRawRunHeader.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MRawRunHeader" << endl;
+        mpHeaderTree->SetBranchAddress("MRawRunHeader.",    &mpRawRunHeader);
+    }
+    else cout << "...could not load branch: MRawRunHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MCorsikaRunHeader
+    if ( mpHeaderTree->GetBranchStatus("MCorsikaRunHeader.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MCorsikaRunHeader" << endl;
+        mpHeaderTree->SetBranchAddress("MCorsikaRunHeader.",&mpCorsikaRunHeader);
+    }
+    else cout << "...could not load branch: MCorsikaRunHeader" << endl;
+
+    // =======================================================================
+
+    return;
+}
+
+
+void
+MonteCarlo::ReadRunHeader()
+{
+    // Read Values from RunHeader-Tree
+
+    if (mVerbosityLvl > 0)
+        cout << "...reading run header " << mpHeaderTree << endl;
+
+    //Get first and only entry
+    mpHeaderTree->GetEntry();
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MGeomCam" Branch
+    if ( mpGeomCam != NULL)
+    {
+        //Getter functions from "MGeomCamFACT.h"
+        mCamDist                = mpGeomCam->GetCameraDist();
+        mNumberOfPixels         = mpGeomCam->GetNumPixels();
+        mNumberOfSectors        = mpGeomCam->GetNumSectors();
+        mNumberOfAreas          = mpGeomCam->GetNumAreas();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MGeomCam" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "IntendedPulsePos" Branch
+    if ( mpIntendedPulsePos != NULL)
+    {
+        mIntendedPulsePos       = mpIntendedPulsePos->GetVal();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: IntendedPulsePos" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MMcRunHeader" Branch from event Tree
+    if ( mpMcRunHeader != NULL)
+    {
+        //Getter functions from "MMcRunHeader.hxx"
+        mNumSimulatedShowers    = mpMcRunHeader->GetNumSimulatedShowers();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MMcRunHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get number of Events from event Tree
+    if ( mpEventTree != NULL)
+    {
+        mNumberOfEntries        = mpEventTree->GetEntries();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read number of Events from event Tree" << endl;
+
+    if (mVerbosityLvl > 0)
+        cout << "Event Tree has " << mNumberOfEntries << " entries" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MRawRunHeader" Branch
+    if ( mpRawRunHeader != NULL)
+    {
+        //Getter functions from "MRawRunHeader.h"
+        mNumberOfEvents         = mpRawRunHeader->GetNumEvents();
+        mNumberOfEventsRead     = mpRawRunHeader->GetNumEventsRead();
+        mSamplingFrequency      = mpRawRunHeader->GetFreqSampling();
+        mSourceName             = mpRawRunHeader->GetSourceName();
+        mFileNumber             = mpRawRunHeader->GetFileNumber();
+        mNumberOfSamples        = mpRawRunHeader->GetNumSamplesHiGain();
+        mNumberOfBytes          = mpRawRunHeader->GetNumBytesPerSample();
+        mRunNumber              = mpRawRunHeader->GetRunNumber();
+        mRunType                = mpRawRunHeader->GetRunType();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MRawRunHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MCorsikaRunHeader" Branch
+    if ( mpCorsikaRunHeader != NULL)
+    {
+        //Getter functions from "MCorsikaRunHeader.h"
+        mSlopeSpectrum          = mpCorsikaRunHeader->GetSlopeSpectrum();
+        mEnergyMin              = mpCorsikaRunHeader->GetEnergyMin();
+        mEnergyMax              = mpCorsikaRunHeader->GetEnergyMax();
+        mZdMin                  = mpCorsikaRunHeader->GetZdMin();
+        mZdMax                  = mpCorsikaRunHeader->GetZdMax();
+        mAzMin                  = mpCorsikaRunHeader->GetAzMin();
+        mAzMax                  = mpCorsikaRunHeader->GetAzMax();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MCorsikaRunHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // delete Pixel Array before you set refferences for a new one
+    // in case it is existing
+    if (mpPixel != NULL)
+    {
+        delete[] mpPixel;
+    }
+    mpPixel = new pixel_t[mNumberOfPixels];
+
+    // -----------------------------------------------------------------------
+
+    //Get Pedestal from "ElectronicNoise" Branch
+    if ( mpElectronicNoise != NULL)
+    {
+        if (mVerbosityLvl > 1) cout << "   ...reading pedestal offsets" << endl;
+
+        // Loop over all pixel: Read Pedestal Offset
+        for ( int i = 0; i < mNumberOfPixels; i++ )
+        {
+            // check if array entry exists
+            if ( &(mpElectronicNoise[0][i]) != NULL)
+            {
+                //tricky stuff!!!
+                // mpElectronicNoise is a MPedestalCam Array
+                // individual pixel pedestals are stored in a MPedestalPix array
+                // the [] operator is overloaded in MPedestalCam
+                // and returning a MPedestalPix at position [i]
+                // MPedestalPix hast a Getter called GetPedestal()
+                mpPixel[i].pedestal   = mpElectronicNoise[0][i].GetPedestal();
+            }
+            else if (mVerbosityLvl > 2)
+            {
+                cout << "   ...cannot read pedestal offset" << endl;
+            }
+        }
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: ElectronicNoise" << endl;
+
+    return;
+}
+
+void
+MonteCarlo::LoadEventTree(TString treeName)
+{
+    if (mVerbosityLvl > 0) cout << "...loading event tree" << endl;
+
+    mpEventTree       = (TTree*)mpRootFile->Get(treeName);
+
+    if (mpEventTree->IsZombie())
+    {
+        cout << "...could not load tree" << endl;
+        return;
+    }
+
+    // =======================================================================
+    //Set Adresses to Branches in Events-Tree
+
+    if (mVerbosityLvl > 1) cout << "...SetBranchAddresses:" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MRawEvtData
+    if ( mpEventTree->GetBranchStatus("MRawEvtData.") != -1 )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MRawEvtData" << endl;
+        mpEventTree->SetBranchAddress("MRawEvtData.",       &mpRawEventData);
+    }
+    else cout << "...could not load branch: MRawEvtData" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // IncidentAngle
+    if ( mpEventTree->GetBranchStatus("IncidentAngle.") )
+    {
+        //FIX ME: THIS VALUE IS NOT EXISTANT IN EVERY MC FILE
+
+        if (mVerbosityLvl > 1) cout << "   ...IncidentAngle" << endl;
+        mpEventTree->SetBranchAddress("IncidentAngle.",     &mpIncidentAngle);
+    }
+    else cout << "...could not load branch: IncidentAngle" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MMcEvt
+    if ( mpEventTree->GetBranchStatus("MMcEvt.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...McEvt" << endl;
+        mpEventTree->SetBranchAddress("MMcEvt.",            &mpMcEventMetaData);
+    }
+    else cout << "...could not load branch: McEvt" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MRawEvtHeader
+    if ( mpEventTree->GetBranchStatus("MRawEvtHeader.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MRawEventHeader" << endl;
+        mpEventTree->SetBranchAddress("MRawEvtHeader.",     &mpRawEventHeader);
+    }
+    else cout << "...could not load branch: MRawEvtHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // MCorsikaEvtHeader
+    if ( mpEventTree->GetBranchStatus("MCorsikaEvtHeader.") )
+    {
+        if (mVerbosityLvl > 1) cout << "   ...MCorsikaEvtHeader" << endl;
+        mpEventTree->SetBranchAddress("MCorsikaEvtHeader.", &mpCorsikaEvtHeader);
+    }
+    else cout << "...could not load branch: MCorsikaEvtHeader" << endl;
+
+    // =======================================================================
+
+    return;
+}
+
+void
+MonteCarlo::ReadEventMetaData()
+{
+    if (mVerbosityLvl > 1)
+        cout << "...reading event header" << endl;
+
+    //Get values from "MGeomCamFACT" Branch
+    if ( mpIncidentAngle != NULL)
+    {
+        //Getter functions from "MGeomCamFACT.h"
+        mIncidentAngle          = mpIncidentAngle->GetVal();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MGeomCamFACT" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MMcEvt" Branch
+    if ( mpMcEventMetaData != NULL)
+    {
+        //The following Getter Functions can be found in MMcEvt.h
+        mCorsikaEventNumber     = mpMcEventMetaData->GetEvtNumber();
+        mPhotElFromShower       = mpMcEventMetaData->GetPhotElfromShower();
+        mPhotElinCamera         = mpMcEventMetaData->GetPhotElinCamera();
+            //The following Getter Functions can be found in MMcEvtBasic.h
+        mPartId                 = mpMcEventMetaData->GetPartId();
+        mPartName               = mpMcEventMetaData->GetParticleName(mPartId);
+        mPartSymbol             = mpMcEventMetaData->GetParticleSymbol(mPartId);
+        mEnergy                 = mpMcEventMetaData->GetEnergy();
+        mImpact                 = mpMcEventMetaData->GetImpact();
+        mTelescopePhi           = mpMcEventMetaData->GetTelescopePhi();
+        mTelescopeTheta         = mpMcEventMetaData->GetTelescopeTheta();
+        mPhi                    = mpMcEventMetaData->GetParticlePhi();
+        mTheta                  = mpMcEventMetaData->GetParticleTheta();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MMcEvt" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MRawEventHeader" Branch
+    if ( mpRawEventHeader != NULL)
+    {
+        //Getter functions from "MRawEventHeader.h"
+        mEventNumber            = mpRawEventHeader->GetDAQEvtNumber();
+        mNumTriggerLvl1         = mpRawEventHeader->GetNumTrigLvl1();
+        mNumTriggerLvl2         = mpRawEventHeader->GetNumTrigLvl2();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MRawEventHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    //Get values from "MCorsikaEvtHeader" Branch
+    if ( mpCorsikaEvtHeader != NULL)
+    {
+        //Getter functions from "MCorsikaEvtHeader.h"
+        mFirstInteractionHeight = mpCorsikaEvtHeader->GetFirstInteractionHeight();
+        mEvtReuse               = mpCorsikaEvtHeader->GetNumReuse();
+        mMomentumX              = mpCorsikaEvtHeader->GetMomentum().X();
+        mMomentumY              = mpCorsikaEvtHeader->GetMomentum().Y();
+        mMomentumZ              = mpCorsikaEvtHeader->GetMomentum().Z();
+        mZd                     = mpCorsikaEvtHeader->GetZd();
+        mAz                     = mpCorsikaEvtHeader->GetAz();
+        mX                      = mpCorsikaEvtHeader->GetX();
+        mY                      = mpCorsikaEvtHeader->GetY();
+    }
+    else if (mVerbosityLvl > 2)
+        cout << "...could not read data from: MCorsikaEvtHeader" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // mWeightedNumPhotons     = mpCorsikaEvtHeader->Get;
+    // no getter function, no idea how to extract information
+
+    return;
+}
+
+void
+MonteCarlo::ReadEventRawData()
+{
+    if (mVerbosityLvl > 1) cout << "...reading event raw data" << endl;
+
+    // -----------------------------------------------------------------------
+
+    // delete Pixel Array before you set refferences for a new one
+    // in case it is existing
+    if (mpPixel != NULL)
+    {
+        delete[] mpPixel;
+    }
+    mpPixel = new pixel_t[mNumberOfPixels];
+
+    // -----------------------------------------------------------------------
+
+    if ( mpRawEventData == NULL)
+    {
+        cout << "ERROR: cannot read event data" << endl;
+        return;
+    }
+
+    // you have to set this before you can read information
+    // from a magic binary file
+    mpRawEventData->InitRead(mpRawRunHeader);
+
+    int pix_first_sample;
+
+    // -----------------------------------------------------------------------
+
+    //array to contain alle samples of all pixel of a event
+    unsigned short* all_raw_data    = NULL;
+
+    if ( mpRawEventData != NULL)
+    {
+        // point raw data array to RawEventData Array in Event Tree
+        all_raw_data    = (unsigned short*) mpRawEventData->GetSamples();
+        /*
+//  FADC samples (hi gain) of all pixels
+//  This is an array of Byte_t variables. The value of a FADC sample has a
+//  size of n=fNumBytesPerSample bytes. Therefore, a FADC sample value will
+//  occupy n consecutive elements of this array (little endian ordering, i.e,
+//  less significant bits (and bytes) go first.
+//  If m = GetNumHiGainSamples(), the n bytes corresponding to the value of the
+//  i-th FADC sample of the j-th pixel are stored in the n consecutive
+//  positions of this array, starting from fHiGainFadcSamples[j*n*m+i*n]
+*/
+    }
+    else cout << "...cannot read event raw data" << endl;
+
+    // -----------------------------------------------------------------------
+
+    if (mVerbosityLvl > 1)
+        cout << "...pixel progress: ";
+
+    //Loop over all camera pixel and read eEvent raw data, pixel ID and pedestal offset
+    for ( int i = 0; i < mNumberOfPixels; i++ )
+    {
+        if (mVerbosityLvl > 1){
+            if ( !(i%(mNumberOfPixels/10) ))
+                cout << i/(mNumberOfPixels*1.0)*100 << "%.." ;
+            if ( i == mNumberOfPixels-1)
+                cout << "100% " ;
+        }
+
+        // Read Pedestal Offset and store it in classes pixel_t array
+        if ( mpElectronicNoise != NULL)
+        {
+            mpPixel[i].pedestal   = mpElectronicNoise[0][i].GetPedestal();
+        }
+        else cout << "...cannot read pedestal offset" << endl;
+
+        // Read Pixel SoftId and store it in classes pixel_t array
+        if ( mpRawEventData != NULL)
+        {
+            mpPixel[i].SoftId     = mpRawEventData->GetPixelIds()[i];
+        }
+        else cout << "...cannot read pixel id" << endl;
+
+        pix_first_sample        = i*mNumberOfSamples;
+
+        // point beginning of class' pixel_t array to the address
+        // of pixel's first sample's adress in TTree
+        mpPixel[i].rawData      = &(all_raw_data[pix_first_sample]);
+
+    }
+
+    if (mVerbosityLvl > 1)
+        cout << endl;
+
+    return;
+}
+
+void
+MonteCarlo::ReadEvent(int Event)
+{
+    if (mVerbosityLvl > 0) cout << endl
+                                << "====================" << endl
+                                << "...reading Event: " << Event << endl
+                                << "====================" << endl;
+
+
+    //load certain event from tree
+    mpEventTree->GetEntry(Event);
+
+    //Get Event header data from TTree
+    ReadEventMetaData();
+
+    //Get Event raw data from TTree
+    ReadEventRawData();
+
+    return;
+}
+
+// ==========================================================================
+// csv file handling
+//
+
+void
+MonteCarlo::OpenCsvFile(TString fileName)
+{
+    mCsvFileName    = fileName;
+
+    if (mVerbosityLvl > 0) cout << "...opening csv file: " << mCsvFileName << endl;
+
+    mCsv.open( mCsvFileName );
+
+    return;
+}
+
+void
+MonteCarlo::CloseCsvFile()
+{
+    if (mVerbosityLvl > 0) cout << "...closing csv file: " << mCsvFileName << endl;
+
+    mCsv.close();
+
+    return;
+}
+
+void
+MonteCarlo::WriteMc2Csv(TString filename)
+{
+    if ( !mRootFileOpend ){
+        cout << "ERROR - no rootfile loaded, no data loaded, cannot write csv"
+             << endl;
+        return;
+    }
+
+    cout << "...writing mc to csv: " << filename << endl;
+    cout << "...processing " << mNumberOfEntries << "Events" << endl;
+
+    mCsvFileName = filename;
+    OpenCsvFile(mCsvFileName);
+
+    WriteFileInfo2Csv();
+    WriteRunHeaderInfo2Csv();
+    WriteRunHeader2Csv();
+
+    WritePedestalInfo2Csv();
+    WritePedestal2Csv();
+
+    WriteEventHeaderInfo2Csv();
+    WriteEventDataInfo2Csv();
+
+    // loop over all events from tree and write content to csv
+    //    for (int evt = 0; evt < mNumberOfEvents; evt++)
+    for (int evt = 0; evt < mNumberOfEntries; evt++)
+    {
+        ReadEvent(evt);
+        WriteEventHeader2Csv();
+        WriteEventData2Csv();
+    }
+
+    cout << endl << "...conversion done " << endl;
+
+    CloseCsvFile();
+    return;
+}
+
+void
+MonteCarlo::WriteFileInfo2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing file header to csv" << endl;
+
+    mCsv << "### ==========================================================="
+            << endl;
+    mCsv << "### =             FACT Monte Carlo                            ="
+            << endl;
+    mCsv << "### ==========================================================="
+            << endl;
+    mCsv << "### = FileInfo:                                               "
+            << endl;
+    mCsv << "### =                                                         "
+            << endl;
+    mCsv << "### = Source Name:       " << mSourceName << endl;
+    mCsv << "### = Number of Entries: " << mNumberOfEntries << endl;
+    mCsv << "### = Run Number:        " << mRunNumber << endl;
+    mCsv << "### = Run Type  :        " << mRunType << endl;
+    mCsv << "### = File Number:       " << mFileNumber << endl;
+    mCsv << "### ==========================================================="
+         << endl ;
+    mCsv << "###"
+         << endl ;
+
+    return;
+}
+
+void
+MonteCarlo::WriteRunHeaderInfo2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing run header names to csv" << endl;
+
+    mCsv << "### [RunHeader]" << endl;
+
+    mCsv << "# mNumberOfEntries" << mSeparator;
+    mCsv << "mIntendedPulsePos" << mSeparator;
+//    Csv << "mPedestalOffset" << mSeparator;
+    mCsv << "mNumSimulatedShowers" << mSeparator;
+    mCsv << "mNumberOfPixels" << mSeparator;
+    mCsv << "mNumberOfSamples" << mSeparator;
+//    mCsv << "mSampleSize" << mSeparator;
+    mCsv << "mCamDist" << mSeparator;
+    mCsv << "mSourceName" << mSeparator;
+    mCsv << "mSlopeSpectrum" << mSeparator;
+    mCsv << "mEnergyMin" << mSeparator;
+    mCsv << "mEnergyMax" << mSeparator;
+    mCsv << "mZdMin" << mSeparator;
+    mCsv << "mZdMax" << mSeparator;
+    mCsv << "mAzMin" << mSeparator;
+    mCsv << "mAzMax" << mSeparator;
+    mCsv << "mFileNumber" << mSeparator;
+    mCsv << "mRunnumber" << mSeparator;
+    mCsv << "mRunType" << endl;
+
+    return;
+}
+
+void
+MonteCarlo::WriteRunHeader2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing run header to csv" << endl;
+
+    mCsv << mNumberOfEntries << mSeparator;
+    mCsv << mIntendedPulsePos << mSeparator;
+//    mCsv << mPedestalOffset << mSeparator;
+    mCsv << mNumSimulatedShowers << mSeparator;
+    mCsv << mNumberOfPixels << mSeparator;
+    mCsv << mNumberOfSamples << mSeparator;
+//    mCsv << mSampleSize << mSeparator;
+    mCsv << mCamDist << mSeparator;
+    mCsv << mSourceName << mSeparator;
+    mCsv << mSlopeSpectrum << mSeparator;
+    mCsv << mEnergyMin << mSeparator;
+    mCsv << mEnergyMax << mSeparator;
+    mCsv << mZdMin << mSeparator;
+    mCsv << mZdMax << mSeparator;
+    mCsv << mAzMin << mSeparator;
+    mCsv << mAzMax << mSeparator;
+    mCsv << mFileNumber << mSeparator;
+    mCsv << mRunNumber << mSeparator;
+    mCsv << mRunType << endl;
+
+    return;
+}
+
+void
+MonteCarlo::WriteEventHeaderInfo2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing event header names to csv" << endl;
+
+    mCsv << "### [EventHeader]" << endl;
+
+    mCsv << "# mEventNumber" << mSeparator;
+    mCsv << "mNumberOfBytes" << mSeparator;
+    mCsv << "mIncidentAngle" << mSeparator;
+    mCsv << "mPartId" << mSeparator;
+    mCsv << "mEnergy" << mSeparator;
+    mCsv << "mImpact" << mSeparator;
+    mCsv << "mTelescopePhi" << mSeparator;
+    mCsv << "mTelescopeTheta" << mSeparator;
+    mCsv << "mPhi" << mSeparator;
+    mCsv << "mTheta" << mSeparator;
+    mCsv << "mCorsikaEventNumber" << mSeparator;
+    mCsv << "mPhotElFromShower" << mSeparator;
+    mCsv << "mEvtReuse" << mSeparator;
+    mCsv << "mNumTriggerLvl1" << mSeparator;
+    mCsv << "mFirstInteractionHeight" << mSeparator;
+    mCsv << "mMomentumX" << mSeparator;
+    mCsv << "mMomentumY" << mSeparator;
+    mCsv << "mMomentumZ" << mSeparator;
+    mCsv << "mZd" << mSeparator;
+    mCsv << "mAz" << mSeparator;
+    mCsv << "mX" << mSeparator;
+    mCsv << "mY" << mSeparator;
+//    mCsv << "mWeightedNumPhotons" ;
+    mCsv << endl;
+
+    return;
+}
+
+void
+MonteCarlo::WriteEventHeader2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing event header to csv" << endl;
+
+    mCsv << mEventNumber << mSeparator;
+    mCsv << mNumberOfBytes << mSeparator;
+    mCsv << mIncidentAngle << mSeparator;
+    mCsv << mPartId << mSeparator;
+    mCsv << mEnergy << mSeparator;
+    mCsv << mImpact << mSeparator;
+    mCsv << mTelescopePhi << mSeparator;
+    mCsv << mTelescopeTheta << mSeparator;
+    mCsv << mPhi << mSeparator;
+    mCsv << mTheta << mSeparator;
+    mCsv << mCorsikaEventNumber << mSeparator;
+    mCsv << mPhotElFromShower << mSeparator;
+    mCsv << mEvtReuse << mSeparator;
+    mCsv << mNumTriggerLvl1 << mSeparator;
+    mCsv << mFirstInteractionHeight << mSeparator;
+    mCsv << mMomentumX << mSeparator;
+    mCsv << mMomentumY << mSeparator;
+    mCsv << mMomentumZ << mSeparator;
+    mCsv << mZd << mSeparator;
+    mCsv << mAz << mSeparator;
+    mCsv << mX << mSeparator;
+    mCsv << mY << mSeparator;
+//    mCsv << mWeightedNumPhotons ;
+    mCsv << endl;
+
+    return;
+}
+
+void
+MonteCarlo::WriteEventDataInfo2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing event categories to csv" << endl;
+
+    mCsv << "### [RawData]" << endl;
+    mCsv << "# mEventNumber" << mSeparator;
+    mCsv << "pixelID" << mSeparator;
+//     mCsv << "pixelPedestal" << mSeparator;
+
+    // Loop over number of all samples in pixel
+    for (int i = 0; i < mNumberOfSamples; i++)
+    {
+        mCsv << "Raw_" << i << mSeparator;
+    }
+    mCsv << endl;
+
+    return;
+}
+
+void
+MonteCarlo::WriteEventData2Csv()
+{
+    if (mVerbosityLvl > 0) cout << "...writing event data to csv" << endl;
+
+    // Loop over all pixels and write pixeldata to csv
+    for (int i = 0; i < mNumberOfPixels; i++)
+    {
+        WritePixelData2Csv(i);
+    }
+
+    return;
+}
+
+void
+MonteCarlo::WritePixelData2Csv(int pixelID)
+{
+    if (mVerbosityLvl > 3) cout << "...writing pixel data to csv" << endl;
+    mCsv << mEventNumber << mSeparator;
+    mCsv << mpPixel[pixelID].SoftId << mSeparator;
+//    mCsv << mpPixel[pixelID].pedestal << mSeparator;
+
+    // Loop over number of all samples in pixel and write samples content to csv
+    for (int i = 0; i < mNumberOfSamples; i++)
+    {
+         mCsv << mpPixel[pixelID].rawData[i] << mSeparator;
+    }
+    mCsv << endl;
+
+    return;
+}
+
+void
+MonteCarlo::WritePedestalInfo2Csv()
+{
+    mCsv << "### [Pedestal]" << endl;
+//    mCsv << "# SoftID" ;
+//    mCsv << mSeparator ;
+//    mCsv << "Pedestal" << endl;
+}
+
+void
+MonteCarlo::WritePedestal2Csv()
+{
+    if (mVerbosityLvl > 3) cout << "...writing pedestal info to csv" << endl;
+
+    // Loop over all pixels and write pixel pedestal to csv
+    for (int pixelID = 0; pixelID < mNumberOfPixels; pixelID++)
+    {
+//        mCsv << mpPixel[pixelID].SoftId;
+        mCsv << mpPixel[pixelID].pedestal;
+        if (pixelID < mNumberOfPixels -1)
+            mCsv << mSeparator;
+    }
+    mCsv << endl;
+
+    return;
+}
+
+
+
+
+
+
+
+
Index: /fact/tools/marsmacros/mc2csv/MonteCarlo/MonteCarlo.h
===================================================================
--- /fact/tools/marsmacros/mc2csv/MonteCarlo/MonteCarlo.h	(revision 14798)
+++ /fact/tools/marsmacros/mc2csv/MonteCarlo/MonteCarlo.h	(revision 14798)
@@ -0,0 +1,420 @@
+#ifndef MONTECARLO_H
+#define MONTECARLO_H
+
+/*! \class MonteCarlo
+ * \brief Monte Carlo class to handle MC-Data from mars-root-file produced with ceres.
+ *
+ * #include "MonteCarlo.h" <BR>
+ * -llib
+ *
+ * Class can be used in Mars to load Monte Carlo data from a root-file
+ * containing Mars classes that where produced by CERES
+ *
+ * @see something
+ */
+
+
+// SYSTEM INCLUDES
+#include <vector>
+#include <fstream>
+#include <endian.h>
+#include <stdio.h>
+
+#include <TSystem.h>
+#include <TString.h>
+#include <TStyle.h>
+#include <TCanvas.h>
+#include <TMath.h>
+#include <TFile.h>
+#include <TH1.h>
+#include <TH2F.h>
+#include <TF1.h>
+#include <TTree.h>
+//
+
+// PROJECT INCLUDES
+#include "MStatusDisplay.h"
+#include "MStatusArray.h"
+#include "MParContainer.h"
+
+#include "MParameters.h"
+#include "MPedestalCam.h"
+#include "MMcRunHeader.hxx"
+#include "MGeomCamFACT.h"
+#include "MRawRunHeader.h"
+#include "MCorsikaRunHeader.h"
+
+//Evt data types
+#include "MRawEvtData.h"
+#include "MPedestalCam.h"
+#include "MMcEvt.hxx"
+#include "MMcEvtBasic.h"
+#include "MRawEvtHeader.h"
+#include "MCorsikaEvtHeader.h"
+
+
+
+//
+
+// LOCAL INCLUDES
+//
+
+// FORWARD REFERENCES
+//
+
+using namespace std;
+using namespace TMath;
+
+struct pixel_t          //struct gathering information of a camera pixel
+{
+    int                 SoftId;         //Mars Software ID of Pixel
+//    int                 ChId;         //continous Hardware ID of Pixel
+    unsigned short*     rawData;        //array with raw data of slices* amplitudes
+    float               pedestal;       //amplitude of baseline
+};
+
+class MonteCarlo
+{
+public:
+// LIFECYCLE
+
+    /** Default constructor.
+    */
+    MonteCarlo();                       // Default constructor
+    /*! constructor
+     * \param filename name of mc data file that will to load
+    */
+    MonteCarlo( TString filename);      // name of mc data file will to load
+    /*! constructor
+     * \param filename name of mc data file that will to load
+     * \param evtsTreeName name of tree containg events
+    */
+    MonteCarlo( TString filename,       // name of mc data file will to load
+                TString evtsTreeName);  // name of tree containg events
+    /*! constructor
+     * \param filename name of mc data file that will to load
+     * \param evtsTreeName name of tree containg events
+     * \param headerTreeName name of tree containg run meta data
+    */
+    MonteCarlo( TString filename,       // name of mc data file will to load
+                TString evtsTreeName,   // name of tree containg events
+                TString headerTreeName);// name of tree containg meta data
+
+
+//    /** Copy constructor.
+//    *
+//    * @param from The value to copy to this object.
+//    */
+//    MonteCarlo(const MonteCarlo& from);
+
+
+    /** Destructor.
+    */
+    ~MonteCarlo(void);
+
+
+// OPERATORS
+
+//    /** Assignment operator.
+//    *
+//    * @param from THe value to assign to this object.
+//    *
+//    * @return A reference to this object.
+//    */
+//    MonteCarlo&                     operator=(const XX& from);
+
+// OPERATIONS
+private:
+    /*! Initiate all pointer Variables to NULL*/
+    void InitVariables();
+
+public:
+    /*! Write Monte Carlo Data into a Csv-file WriteMc2Csv(filename)
+     * \param filename The Filename of the CSV File to which data will be written
+    */
+    void WriteMc2Csv(TString filename );
+
+    /*! write pixels' raw data for a given pixel into the given csv file
+     * \param pixelID Software ID of pixel
+     */
+    void WritePixelData2Csv(int pixelID);
+
+    /*! loop over all pixels and call WritePixelData2Csv
+     */
+    void WriteEventData2Csv();
+
+    /*! write table headings for coulums with pixels' raw data
+     */
+    void WriteEventDataInfo2Csv();
+
+    /*! write table headings for coulums with event meta information
+     */
+    void WriteEventHeaderInfo2Csv();
+
+    /*! write meta information of current event to csv
+     */
+    void WriteEventHeader2Csv();
+
+    /*! write table headings for coulums with run meta information
+     */
+    void WriteRunHeaderInfo2Csv();
+
+    /*! write meta information of current run to csv
+     */
+    void WriteRunHeader2Csv();
+
+    /*! write the header of the csv file containing brief info about the converted mc file
+     */
+    void WriteFileInfo2Csv();
+
+    /*! write table headings for coulums with pixels' pedestal amplitude
+     */
+    void WritePedestal2Csv();
+
+    /*! write table headings for coulums with pixels' pedestal amplitude
+     */
+    void WritePedestalInfo2Csv();
+
+
+// ACCESS
+    /*! set column seperator for csv
+     * \param sep column seperator for csv
+     */
+    void SetSeparator(char sep);
+
+    /*! Get column seperator for csv
+     * \param sep column seperator for csv
+     */
+    TString GetSeparator();
+
+    /*! set the verbosity level for verbosity cout on cmd-line
+     * \param verbLvl Votrbosity Level
+     */
+    void SetVerbosityLevel(int verbLvl);
+
+    /*! Get the verbosity level for verbosity cout on cmd-line
+     */
+    int  GetVerbosityLevel();
+
+    /*! Open the mars-root-file produced with ceres
+     */
+    int  OpenRootFile();
+
+    /*!  Close the mars-root-file produced with ceres
+     */
+    void CloseRootFile();
+
+    /*! Open csv-file to which data will be written
+     * \param fileName Filename of the csv-file e.g. "mc20120605.csv"
+     */
+    void OpenCsvFile(   TString fileName);
+
+    /*! Close csv-file to which data was be written
+     */
+    void CloseCsvFile();
+
+    /*! set according pointers to tree containing event information and its branches
+     * \param treeName Name of TTree containing event information
+     */
+    void LoadEventTree( TString treeName);
+
+    /*! set according pointers to tree containing run information and its branches
+     * \param treeName Name of TTree containing run information
+     */
+    void LoadHeaderTree(TString treeName);
+
+    /*! set values of members  to according leafs in TTree for run meta data
+     */
+    void ReadRunHeader();
+
+    /*! set values of members  to according leafs in TTree for event raw data
+     */
+    void ReadEventRawData();
+
+    /*! set values of members  to according leafs in TTree for event meta data
+     */
+    void ReadEventMetaData();
+
+    /*! call ReadEventRawData() and ReadEventMetaData() for given event
+     * \param Event Event ID to read data
+     */
+    void ReadEvent(int Event);
+
+// INQUIRY
+private:
+    /*! Verbostiy Level */
+    int                 mVerbosityLvl;
+    /*! Whether the rootfile is open */
+    bool                mRootFileOpend;
+
+    /*! filename of output csv file */
+    TString             mCsvFileName;
+    /*! steam into csv output file */
+    ofstream            mCsv;
+    /*! filename of input root file */
+    TString             mFileName;
+    /*! pointer to input root file */
+    TFile*              mpRootFile;
+    /*! Array for pixels' raw data */
+    pixel_t*            mpPixel;
+
+    /*! pointer to event tree */
+    TTree*              mpEventTree;
+    /*! pointer to run header tree */
+    TTree*              mpHeaderTree;
+
+    //run header tree branches
+    /*! mars class pointer to branch with same name in TTree */
+    MParameterD*        mpIntendedPulsePos;
+    /*! mars class pointer to branch with same name in TTree */
+    MMcRunHeader*       mpMcRunHeader;
+    /*! mars class pointer to branch with same name in TTree */
+    MGeomCamFACT*       mpGeomCam;
+    /*! mars class pointer to branch with same name in TTree */
+    MRawRunHeader*      mpRawRunHeader;
+    /*! mars class pointer to branch with same name in TTree */
+    MCorsikaRunHeader*  mpCorsikaRunHeader;
+
+    //Event tree branches
+    /*! mars class pointer to branch with same name in TTree */
+    MPedestalCam*       mpElectronicNoise;
+    /*! mars class pointer to branch with same name in TTree */
+    MRawEvtData*        mpRawEventData;
+    /*! mars class pointer to branch with same name in TTree */
+    MParameterD*        mpIncidentAngle;
+    /*! mars class pointer to branch "MMcEvt" in TTree */
+    MMcEvt*             mpMcEventMetaData;
+    /*! mars class pointer to branch with same name in TTree */
+    MRawEvtHeader*      mpRawEventHeader;
+    /*! mars class pointer to branch with same name in TTree */
+    MCorsikaEvtHeader*  mpCorsikaEvtHeader;
+
+//    /*! array with MC events raw data */
+//    unsigned short *    mpSamples;          // array with MC events raw data
+    /*! coulumn seperator in csv file */
+    TString             mSeparator;
+
+    //Run Meta Data
+    /*! number of entries(events) in event tree  */
+    int                 mNumberOfEntries;
+    /*! number of events in file NOT WORKING WITH CURRENT CERES VERSION */
+    int                 mNumberOfEvents;
+    /*! position (slice) of simulated cherenkov pulse in pixel */
+    float               mIntendedPulsePos;
+    /*! number of showers simulated by corsika*/
+    int                 mNumSimulatedShowers;
+    /*! total number of simulated camera pixels */
+    int                 mNumberOfPixels;
+    /*! ??? */
+    int                 mNumberOfSectors;
+    /*! ??? */
+    int                 mNumberOfAreas;
+    /*! number of Samples (slices) -> simulated Region of interest */
+    float               mNumberOfSamples;
+    /*! simulated sampling frequency  */
+    float               mSamplingFrequency;
+    /*! ??? */
+    int                 mNumberOfEventsRead;
+    /*! ??? */
+    float               mCamDist;
+    /*! name of simulated source */
+    const char*         mSourceName;
+    /*! slope of simulated spectrum */
+    float               mSlopeSpectrum;
+    /*! minimum of simulated spectrum  */
+    float               mEnergyMin;
+    /*! maximum of simulated spectrum */
+    float               mEnergyMax;
+    /*! minimum Zenidth of simulated showers */
+    float               mZdMin;
+    /*! maximum Zenidth of simulated showers */
+    float               mZdMax;
+    /*! minimum Azimuth of simulated showers */
+    float               mAzMin;
+    /*! maximum Azimuth of simulated showers */
+    float               mAzMax;
+    /*! file number from raw run header */
+    unsigned int        mFileNumber;
+    /*! corsika run number */
+    int                 mRunNumber;
+    /*! runtype: e.g. Pedestal, data, calibration run,... */
+    int                 mRunType;
+    /*! number of bytes per sample */
+    int                 mNumberOfBytes;
+
+    //Event Meta Data
+    /*! Incident Angle */
+    float               mIncidentAngle;
+    /*! id of primary particle of shower */
+    int                 mPartId;
+    /*! energy of primary particle of shower */
+    float               mEnergy;
+    /*! impact parameter of primary particle of shower  */
+    float               mImpact;
+    /*! Telescope Phi of shower */
+    float               mTelescopePhi;
+    /*! Telescope Theta of shower */
+    float               mTelescopeTheta;
+    /*! Phi of shower */
+    float               mPhi;
+    /*! Theta of shower */
+    float               mTheta;
+    /*! name of primary particle of shower */
+    TString             mPartName;
+    /*! symbol of primary particle of shower */
+    TString             mPartSymbol;
+    /*! corsika event number */
+    unsigned int        mCorsikaEventNumber;
+    /*! Passed qe, coming from the shower */
+    unsigned int        mPhotElFromShower;
+    /*! usPhotElfromShower + mean of phe from NSB */
+    unsigned int        mPhotElinCamera;
+    /*! Number running from 0 to N-1, being N the number
+     * of times a Corsika event has been reused, by
+     * orienting the telescope in different ways or by
+     * setting it at a different location on the ground. */
+    int                 mEvtReuse;
+    /*! Number of Events from DAQ */
+    int                 mEventNumber;
+    /*! Number of 1st level tiggers between 2 events Used in MSimTrigger for the index of the trigger channel */
+    float               mNumTriggerLvl1;
+    /*! Number of 2nd level tiggers between 2 events */
+    float               mNumTriggerLvl2;
+    /*! [cm] z coordinate, first intercation height */
+    float               mFirstInteractionHeight;
+    /*! [GeV/c] "+west"    "-east" */
+    float               mMomentumX;
+    /*! [GeV/c] "+south"   "-north"
+     * (north denotes the magnet north which is defined to be in the geografic north!)
+     */
+    float               mMomentumY;
+    /*! [GeV/c] "+upwards" "-downwards" */
+    float               mMomentumZ;
+    /*! [rad] Zenith distance */
+    float               mZd;
+    /*! [rad] Azimuth (north=0; east=90)
+     * (north denotes the magnet north which is defined to be in the geografic north!)
+    */
+    float               mAz;
+    /*! [cm] Position of telescope on ground x / - impact parameter x */
+    float               mX;
+    /*! [cm] Position of telescope on gorund y / - impact parameter y */
+    float               mY;
+    /*! weighted number of photons arriving at observation level */
+//    int                 mWeightedNumPhotons;
+
+
+
+
+protected:
+
+};
+
+// INLINE METHODS
+//
+
+// EXTERNAL REFERENCES
+//
+
+#endif // MONTECARLO_H
+
