//************************************************
// Author: Federica Lionetto
// Created on: 05/12/2014
//************************************************

/*
   Masking is used to mask the Beetle channels close to the header and the Beetle channels that have problems.

   int maskBeetle1[NBeetle] and int maskBeetle2[NBeetle] are two global variables and have a 0/1 for each Beetle channel, where 0 stands for not masked and 1 stands for masked.
   int chNotMaskedBeetle1 and int chNotMaskedBeetle2 are two global variables and represents the number of Beetle channels that are not masked.

   The masking is done according to the sensor under consideration, looking at the noise as a function of the Beetle channel for that particular sensor.
   */

// Header guard.
#ifndef __MASKING_C_INCLUDED__
#define __MASKING_C_INCLUDED__

#include "Par.C"

int maskBeetle1[NBeetle];
int maskBeetle2[NBeetle];
int chNotMaskedBeetle1;
int chNotMaskedBeetle2;

void Masking(string sensor);

void Masking(string sensor)
{
    cout << "**************************************************" << endl;
    cout << "Masking Beetle channels..." << endl;
    cout << "**************************************************" << endl;

    // Initialization of the masking arrays.
    for (int iChannel=0;iChannel<NBeetle;++iChannel)
        maskBeetle1[iChannel] = 0;

    for (int iChannel=NBeetle;iChannel<N;++iChannel)
        maskBeetle2[iChannel-NBeetle] = 0;

    // Masking.
    // Modify it!
    if ((sensor == "UZHDaughterBoard") || (sensor == "Hans410") || (sensor == "Hans320") || (sensor == "ATLAS") || (sensor== "NoSensor"))
    {
        int start_header = 0;
        int end_header = 10;

        int start_nextHeader = 117;
        int end_nextHeader = 127;

        // chNotMaskedBeetle1 = NBeetle-(end_header-start_header+1)-(end_group-start_group+1)-(end_nextHeader-start_nextHeader+1);
        chNotMaskedBeetle1 = NBeetle;
        chNotMaskedBeetle2 = NBeetle;

        for (int iChannel=0;iChannel<NBeetle;++iChannel) {
            if (((iChannel>=start_header) && (iChannel<=end_header)) || ((iChannel>=start_nextHeader) && (iChannel<=end_nextHeader)) || (iChannel%NSkip!=0))
            {
                maskBeetle1[iChannel] = 1;
                chNotMaskedBeetle1 -= 1;
            }
            if (((iChannel>=start_header) && (iChannel<=end_header)) || ((iChannel>=start_nextHeader) && (iChannel<=end_nextHeader)) || (iChannel%NSkip!=0))
            {
                maskBeetle2[iChannel] = 1;
                chNotMaskedBeetle2 -= 1;
            }
        }

    }

    cout << chNotMaskedBeetle1 << " not masked channels on Beetle 1" << endl;
    cout << chNotMaskedBeetle2 << " not masked channels on Beetle 2" << endl;
    
    // Print masking for Beetle 1.
    for (int iChannel=0;iChannel<NBeetle;++iChannel)
        cout << "Beetle channel #" << iChannel << ": " << maskBeetle1[iChannel] << endl;

    // Print masking for Beetle 2.
    for (int iChannel=NBeetle;iChannel<N;++iChannel)
        cout << "Beetle channel #" << iChannel << ": " << maskBeetle2[iChannel-NBeetle] << endl;

    return;
}

#endif
