Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

StandardMacroCell - source file

// class StandardMacroCell
// $Id: StandardMacroCell.cc,v 1.23 2005/05/16 11:17:49 thea Exp $
// M. Pallavicini - created  20-5-01
// from the original MacroCell class
// modified 8-10-03

#include <iostream>
#include <math.h>

#include "euso.hh"
#include "StandardMacroCell.hh"
#include "FrontEndChip.hh"
#include "Config.hh"
#include "ChipGtuData.hh"
#include "MacroCellData.hh"
#include "Photomultiplier.hh"
#include "EEvent.hh"
#include "EEventCellStatisticsAdder.hh"

ClassImp(StandardMacroCell)
 
//______________________________________________________________________________ 
 StandardMacroCell::StandardMacroCell(Int_t rows, Int_t columns) 
   : MacroCell( rows, columns) {
    // 
    // ctor
    //
}

//______________________________________________________________________________
 StandardMacroCell::~StandardMacroCell() {
    //
    // Dtor
    // 
}

//______________________________________________________________________________
 MacroCellData* StandardMacroCell::Simulate(Int_t night_glow_code) {
    //
    // Electronics simulation for this macrocell
    //

    ConfigFileParser *pConfig = Config::Get()->GetCF("Electronics","MacroCell");
    Bool_t fFlag = pConfig->GetBool("MacroCell.fSaveAllChipGtuData");

    MacroCellData* pData = NULL;

    CheckPmtState();

    // created the data object where MacroCell info is stored
    pData = new MacroCellData( this );

    // compute the number of required GTUs
    Double_t time_interval = LastHitTime() - GetGtuBegin();
    Int_t n_gtus = (Int_t)(time_interval / GetGtuLength() ) + 2;

    // time edges for the first GTU
    Double_t edge_1 = GetGtuBegin();
    Double_t edge_2 = edge_1 + GetGtuLength();

    // some statistics to be put in root file
    Int_t NumChips=0;         // number of fe chips with at least one hit
    Int_t NumPixels=0;        //   "    "  fe chans "    "   "    "   "
    Int_t NumCounts=0;        //   "    "  fe detected counts

    // verify if nightglow must be added or not
    Bool_t doNightGlow = kFALSE;
    switch ( night_glow_code ) {

        // background always everywhere
        case -2: 
            doNightGlow = kTRUE;
            break;

            // background only in macrocells with at least 1 photon
        case -1:
            doNightGlow = kTRUE;
            if ( IsEmpty() )
                return pData;
            break;

            // no background
        case 0:
            doNightGlow = kFALSE;
            if ( IsEmpty() )
                return pData;
            break;

            // background in a specified macrocell only
        default:
            doNightGlow = kFALSE;
            if ( night_glow_code == Id() )
                doNightGlow = kTRUE;
            else {
                if ( !IsEmpty() ) {
                    Msg(EsafMsg::Warning) << "Cell " << Id() 
                        << " has signal but background in enabled only for macrocell " << night_glow_code << MsgDispatch;
                }
            }
            break;
    }

    // simulate all GTUs for this MacroCell
    for( Int_t gtu_counter=0; gtu_counter < n_gtus; gtu_counter++) {

        // call simulate for all front end chips
        // store the chip signal outputs into the MacroCellData object
        for( size_t iEC=0; iEC < GetNumECs(); iEC++ ) {

            ElementaryCell *pEC = GetEC( iEC );
            FrontEndChip *pChip = pEC->FrontEnd();

            ChipGtuData *pChipData = pChip->Gtu(gtu_counter,edge_1,edge_2,doNightGlow);

            Int_t counts = pChipData->GetTotalCounts();
            
            if ( counts )
                NumCounts += counts;

            if ( counts && (fFlag || !pChipData->IsEmpty()) ) {
                pData->Add( gtu_counter, pChipData );
            } else {
                delete pChipData;
            }
        }

        // compute the MacroCell response in this GTU
        if ( IsLogicEnabled())
            pData->BuildGtu( gtu_counter );

        // edge for next GTU window
        edge_1 += GetGtuLength();
        edge_2 = edge_1 + GetGtuLength();
    }

    // do some statistics
    for(size_t i=0; i < GetNumECs(); i++ ) { 
        if ( !GetEC(i)->FrontEnd()->IsEmpty() ) {
            NumChips++;
            NumPixels += GetEC(i)->FrontEnd()->NumActivePixels();
        }
    }

    // simulate trigger response
    pData->SimulateTrigger();

    // put some statistics infos into root event
    if ( EEvent::GetCurrent() && NumChips ) {
        EEventCellStatisticsAdder a( Id(), NumChips, NumPixels, NumCounts, pData );
        EEvent::GetCurrent()->Fill( a );
    }

    return pData;
}
About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update Wed Nov 16 16:57:39 2005 Wed Nov 16 16:29:22 2005