Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Shervin working #19

Open
wants to merge 7 commits into
base: newTextInputFormat_Working
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DataFormats/interface/SKIROCParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace SKIROC
{
static const unsigned char NCHANNELS = 64; ///< number of channels read by one SKIROC
static const unsigned char MAXSAMPLES = 2; ///< one sample for high gain and one for low gain // 15 is the real max of the skiroc
static const unsigned int NLAYERS = 1; ///< number of layers \todo this should not be hard coded here
}


Expand Down
2 changes: 2 additions & 0 deletions Geometry/interface/HGCalTBCellParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace HGCAL_TB_CELL
static const double FULL_CELL_SIDE = 0.6496345; // in cm
static const double CALIB_PAD_SIDE = 0.24; // in cm
static const double MOUSE_BITE_SIDE = 0.39; // in cm
static const unsigned int HalfHexVertices = 4;
static const unsigned int FullHexVertices = 6;
}
#endif
11 changes: 11 additions & 0 deletions Geometry/interface/HGCalTBCellVertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ class HGCalTBCellVertices

std::vector<std::pair<double, double>> GetCellCoordinates(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize, bool flipX = false); ///< returns the coordinates of each vertex of cell in the lab frame \b (x,y)


inline std::vector<std::pair<double, double>> GetCellCoordinatesForPlots(const HGCalTBDetId& detId, int sensorSize)
{
return GetCellCoordinatesForPlots(detId.layer(), detId.sensorIU(), detId.sensorIV(), detId.iu(), detId.iv(), sensorSize);
}

inline std::vector<std::pair<double, double>> GetCellCoordinatesForPlots(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize)
{
return GetCellCoordinates(layer, sensor_iu, sensor_iv, iu, iv, sensorsize, true);
}; ///< returns the coordinates of each vertex of cell in the lab frame \b (x,y)

std::pair<double, double> GetCellCentreCoordinates(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize, bool flipX = false); ///< returns the center of the cell in absolute coordinates: \b (x,y)

inline std::pair<double, double> GetCellCentreCoordinatesForPlots(const HGCalTBDetId& detId, int sensorSize)
{
return GetCellCentreCoordinatesForPlots(detId.layer(), detId.sensorIU(), detId.sensorIV(), detId.iu(), detId.iv(), sensorSize);
}
inline std::pair<double, double> GetCellCentreCoordinatesForPlots(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize)
{
return GetCellCentreCoordinates(layer, sensor_iu, sensor_iv, iu, iv, sensorsize, true);
Expand All @@ -41,6 +51,7 @@ class HGCalTBCellVertices

// void CellType(int iu, int v, bool ValidFlag);// 1 for full hex, 2 for half hex and 3 for the pentagons(to be implemented later)
private:

double a = HGCAL_TB_CELL::FULL_CELL_SIDE; // Size in terms of 1 unit of x/y co-ordinates of a cell side which is 0.064 cm
double x_a = sqrt(3) / 2; // cosine pi/6
double y_a = 1 / 2.; // sine pi/6
Expand Down
6 changes: 4 additions & 2 deletions Geometry/interface/HGCalTBGeometryParameters.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* now we have only 2 layers */
#define MAXSKIROCS 16
/* MAXLAYERS = MAXSKIROCS/2 */
#define MAXLAYERS 8
/* */
#define MAXSKIROCS_PER_BOARD 2
/* now we have only 2 layers */
#define MAXSKIROCS MAXLAYERS*MAXSKIROCS_PER_BOARD
1 change: 0 additions & 1 deletion Geometry/interface/HGCalTBSpillParameters.h

This file was deleted.

9 changes: 8 additions & 1 deletion Geometry/interface/HGCalTBTopology.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef HGCAL_GEOMETRY_HGCALTBTOPOLOGY_H
#define HGCAL_GEOMETRY_HGCALTBTOPOLOGY_H 1

#include "HGCal/DataFormats/interface/HGCalTBDetId.h"
/** \class HGCalTBTopology
*
* Reference: https://indico.cern.ch/event/456955/
Expand All @@ -14,7 +14,14 @@ class HGCalTBTopology
public:
// valid sensorSizes are 128 and 256
bool iu_iv_valid(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorSize) const;

inline bool iu_iv_valid(const HGCalTBDetId& detId, int sensorSize) const
{
return iu_iv_valid(detId.layer(), detId.sensorIU(), detId.sensorIV(), detId.iu(), detId.iv(), sensorSize);
};

double Cell_Area(int cell_type) const;//returns area in cm*cm

};

#endif
216 changes: 99 additions & 117 deletions RawToDigi/plugins/DigiPlotter.cc

Large diffs are not rendered by default.

81 changes: 38 additions & 43 deletions RawToDigi/plugins/HGCalTBRawToDigi.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#include <iostream>
#include "HGCal/RawToDigi/plugins/HGCalTBRawToDigi.h"

// provides the maximum number of layers and number of skirocs per board
#include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
#include "HGCal/Geometry/interface/HGCalTBSpillParameters.h"

// provide the number of channels in a skiroc and number of samples
#include "HGCal/DataFormats/interface/SKIROCParameters.h"

//#define DEBUG
#ifdef DEBUG
#include <iostream>
#endif

using namespace std;

unsigned int gray_to_binary (unsigned int gray);

HGCalTBRawToDigi::HGCalTBRawToDigi(edm::ParameterSet const& conf):
dataTag_(conf.getParameter<edm::InputTag>("InputLabel")),
fedId_(conf.getUntrackedParameter<int>("fedId")),
Expand Down Expand Up @@ -36,52 +46,37 @@ void HGCalTBRawToDigi::produce(edm::Event& e, const edm::EventSetup& c)
const FEDRawData& fed = rawraw->FEDData(fedId_);
if (fed.size() != 0) { /// \todo Exception if 0????
// we can figure out the number of samples from the size of the raw data
int nsamples = fed.size() / (sizeof(uint16_t) * SKIROC::NCHANNELS * 2); // 2 is for ADC and TDC
digis = std::auto_ptr<SKIROC2DigiCollection>(new SKIROC2DigiCollection(nsamples));
size_t nSkirocs = fed.size() / (sizeof(uint16_t) * SKIROC::NCHANNELS * SKIROC::MAXSAMPLES);
size_t nBoards = nSkirocs / MAXSKIROCS_PER_BOARD;
digis = std::auto_ptr<SKIROC2DigiCollection>(new SKIROC2DigiCollection(nSkirocs * SKIROC::NCHANNELS * SKIROC::MAXSAMPLES));
const uint16_t* pdata = (const uint16_t*)(fed.data());

// we start from the back...
int ptr = fed.size() / sizeof(uint16_t) - 1;
/*
printf("Starting on SKIROC %x\n", pdata[ptr]);
ptr--; // now we are pointing at a relatively-useless header word
ptr--; // now we are pointing at the first TDC word
*/

for (int ichan = 0; ichan < SKIROC::NCHANNELS; ichan++) {
for (int ski = MAXSKIROCS; ski >= 0; ski--) {
HGCalTBElectronicsId eid(ski, ichan);
if (!essource_.emap_.existsEId(eid.rawId())) {
// std::cout << "We do not have a mapping for " << eid;
} else {
HGCalTBDetId did = essource_.emap_.eid2detId(eid);
digis->addDataFrame(did);
if((ski % 2) == 0){
if((ichan % 2) == 0){
ptradc1 = ptr - ichan*2 - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS));
ptradc2 = ptr - ichan*2 - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS)) - (2*SKIROC::NCHANNELS);
}
else{
ptradc1 = ptr - (ichan*2 - 1) - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS));
ptradc2 = ptr - (ichan*2 - 1) - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS)) - (2*SKIROC::NCHANNELS);
}
// size_t ski = 0; // the skirocs have an absolute numbering, start counting from the first board till the last(Activate post consistent change in the EMAP)
for (unsigned int i_board = 0 ; i_board < nBoards; ++i_board) {
//The way the entries have been pushed they correspond to the Map a Ski 2,1,4,3,6,5...16,15 so for a simpler logic the EMAP will have to be modified that will be done later.
// for(size_t i_skiroc = 0; i_skiroc < MAXSKIROCS_PER_BOARD; ++i_skiroc) {//(Activate Post consistent change in EMAP)
for(size_t i_skiroc = MAXSKIROCS_PER_BOARD; i_skiroc >= 1; i_skiroc--) {//(De-Activate Post consistent change in EMAP)
for (int ichan = SKIROC::NCHANNELS - 1; ichan >= 0; ichan--) {
// HGCalTBElectronicsId eid(ski, ichan);//(Activate Post consistent change in EMAP)
HGCalTBElectronicsId eid(2*i_board + i_skiroc, ichan);//(De-Activate Post consistent change in EMAP)
if (essource_.emap_.existsEId(eid.rawId())) {
HGCalTBDetId did = essource_.emap_.eid2detId(eid);
digis->addDataFrame(did);
#ifdef DEBUG
if(i_board == 0) std::cout << (*pdata & 0xFFF) << "\t" << (*(pdata + 1) & 0xFFF) << "\t" << (*(pdata + 2) & 0xFFF) << std::endl;
cout<<endl<<dec<<"SKI= "<<(2*i_board + i_skiroc )<<" chan= "<<ichan<<" "<<" High= "<<hex<<*(pdata)<<dec<<" "<<gray_to_binary(*(pdata) & 0xFFF)<<" Low= "<<hex<<(*(pdata + SKIROC::NCHANNELS))<<" "<<dec<<gray_to_binary(*(pdata + SKIROC::NCHANNELS) & 0xFFF)<<endl;
#endif

digis->backDataFrame().setSample(0, gray_to_binary(*(pdata + SKIROC::NCHANNELS) & 0xFFF), gray_to_binary( *(pdata) & 0xFFF), 0);
}
else{
if((ichan % 2) == 0){
ptradc1 = ptr - (ichan*2 + 2) - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS));
ptradc2 = ptr - (ichan*2 + 2) - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS)) - (2*SKIROC::NCHANNELS);
}
else{
ptradc1 = ptr - (ichan*2 + 1) - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS));
ptradc2 = ptr - (ichan*2 + 1) - (((MAXSKIROCS - ski)/2)*(4*SKIROC::NCHANNELS)) - (2*SKIROC::NCHANNELS);
}
}
digis->backDataFrame().setSample(0, gray_to_binary(pdata[ptradc1] & 0xFFF), gray_to_binary( pdata[ptradc2] & 0xFFF), 0);
// cout<<endl<<dec<<"SKI= "<<ski<<" chan= "<<ichan<<" "<<ptradc1<<" "<<ptradc2<<" "<<" High= "<<hex<<(pdata[ptradc1])<<dec<<" "<<gray_to_binary(pdata[ptradc1] & 0xFFF)<<" Low= "<<hex<<( pdata[ptradc2] & 0xFFF)<<" "<<dec<<gray_to_binary( pdata[ptradc2] & 0xFFF)<<endl;
pdata++;//Note this has to be outside the if condition, as for the test channel we wont enter the if condition but still have to increment the pointer address
}
}//loop over skirocs
//We have pushed back the high gain and low gain entries which are independent FED entries for all SKIROC::NCHANNELS so we need to jump by SKIROC::NCHANNELS
pdata = pdata + SKIROC::NCHANNELS;
// ++ski; //increment the absolute ID of the skiroc(Activate post consistent change in the EMAP)
}
}
// }


}// fed size > 0

Expand Down
4 changes: 3 additions & 1 deletion RawToDigi/plugins/HGCalTBRawToDigi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#include "HGCal/DataFormats/interface/HGCalTBDataFrameContainers.h"


#include "HGCal/DataFormats/interface/SKIROCParameters.h"

#include <iostream>

/**
* \class HGCal/RawToDigi/plugins/HGCalTBRawToDigi.h HGCalTBRawToDigi.h HGCalTBRawToDigi
* \brief Produces a digi collection starting from FEDRawData
* \author Shervin Nourbakhsh (UMN)
* \author Rajdeep Mohan Chatterjee (UMN)
* \author Jeremy Mans (UMN)
*/


Expand Down
58 changes: 31 additions & 27 deletions RawToDigi/plugins/HGCalTBTextSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "stdlib.h"
#include "HGCal/RawToDigi/plugins/HGCalTBTextSource.h"
#include "HGCal/Geometry/interface/HGCalTBGeometryParameters.h"
#include "HGCal/Geometry/interface/HGCalTBSpillParameters.h"
using namespace std;
#define TXTLINES 69

//#define DEBUG
/**
RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=09 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=12 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=14 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=17 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=18 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=19 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=22 RUN=000880 SPILL=01 EVENT=000000 GLOBALTIME=0x01B6EAF2 BOARD=23
Expand Down Expand Up @@ -40,8 +40,7 @@ bool HGCalTBTextSource::setRunAndEventInfo(edm::EventID& id, edm::TimeValue_t& t
id = edm::EventID(m_run, m_spill, m_event);

time = (edm::TimeValue_t) m_time;
if(m_spill <= NSpills) return true;
else return false;
return true;
}

// sets m_run, m_spill, m_even, m_time
Expand Down Expand Up @@ -74,53 +73,59 @@ bool HGCalTBTextSource::readLines()
{
max_boards = 0;
for( auto& board : m_lines) {
board.clear();
for( auto& skiroc : board) {
skiroc.clear();
}
}

char buff[1024], buff_SK0[1024], buff_SK1[1024];
char buff[1024], buff_SK[1024];
buff[0] = 0;
unsigned int data_sk0, data_sk1;
unsigned int data_sk;

// loop over all the lines
for(unsigned int i = 0; i < 69 && !feof(m_file); ++i) {
for(unsigned int i = 0; i < TXTLINES && !feof(m_file); ++i) {
buff[0] = 0;
fgets(buff, 1000, m_file);
if((i < 1) || (i > 64)) continue;// Only these are data words, the rest dont interest us for now
// loop over one line of the text file
std::string b = buff;
std::istringstream buffer(b);
unsigned int board_counter = 0;
if((i < 1) || (i > 64)) continue;// Only these are data words, the rest dont interest us for now
while( buffer.peek() != EOF && board_counter < MAXLAYERS) { //buffer.good() gives compilation errors
// read the data of the two skirocs of one board
buffer >> buff_SK1;
buffer >> buff_SK0;
data_sk0 = strtoul(buff_SK0,NULL,0);
data_sk1 = strtoul(buff_SK1,NULL,0);

while( buffer.peek() != '\n' && buffer.good()) {
//continue for all the boards
// extra security
m_lines[board_counter].push_back(data_sk0);
m_lines[board_counter].push_back(data_sk1);

for(size_t iSkiroc = 0; iSkiroc < MAXSKIROCS_PER_BOARD; ++iSkiroc) {
// read the data of the one skiroc of one board
buffer >> buff_SK;
data_sk = strtoul(buff_SK, NULL, 0);
m_lines[board_counter][iSkiroc].push_back(data_sk);
}
++board_counter;
if(board_counter > max_boards) max_boards = board_counter;
}

}
// if(sscanf(buffer, "Event header for event %x with (200ns) timestamp %x", &tmp_event, &m_time) == 2) {
return !m_lines.empty();
return true;
}

/** DATA in the FEDRAWDATA in the following order:
* BOARD, SKIROC, CHANNEL
* so [Board0 [Skiroc0 [Channel0][Channel1][Channel2]...][Skiroc1 [Channel0][Channel1][Channel2]...]]
*/
void HGCalTBTextSource::produce(edm::Event & e)
{
std::auto_ptr<FEDRawDataCollection> bare_product(new FEDRawDataCollection());
// here we parse the data
std::vector<uint16_t> skiwords;
// make sure there are an even number of 32-bit-words (a round number of 64 bit words...

for (unsigned int i_board = 0 ; i_board < max_boards; ++i_board) {
auto board = m_lines[i_board];
for (auto skiword : board) {
skiwords.push_back(skiword >> 16);
skiwords.push_back(skiword);
for (size_t i_board = 0 ; i_board < max_boards; ++i_board) {
for(size_t i_skiroc = 0; i_skiroc < MAXSKIROCS_PER_BOARD; ++i_skiroc) {
auto& board = m_lines[i_board][i_skiroc];
for (auto& skiword : board) {
skiwords.push_back(skiword >> 16);
skiwords.push_back(skiword);
}
}
}

Expand All @@ -139,7 +144,6 @@ void HGCalTBTextSource::fillDescriptions(edm::ConfigurationDescriptions& descrip
desc.setComment("TEST");
desc.addUntracked<int>("run", 101);
desc.addUntracked<std::vector<std::string> >("fileNames");
desc.addUntracked<unsigned int>("nSpills", 6);
descriptions.add("source", desc);
}

Expand Down
Loading