Commit a8f9dd45 authored by vpalladi's avatar vpalladi
Browse files

Added new features:

- README.txt is a text file with some info and useful commands

- python dir contailns the tool to generate what we need for tables and navigation

- in interface/navigation there is a navigaiton tool able to move in trigger cell to trigger cell. This tool need table generated by the python script.
parent 3b22f706
Pipeline #6835 skipped
# compiler
CXX = g++
####################
### useful paths ###
####################
# top
TOP = $(shell pwd)
# python
PYTHON_LOCAL_DIR = $(TOP)/python
NAMING_DIR = $(PYTHON_LOCAL_DIR)/naming
PYTHON_2_7 = /usr/include/python2.7
# local interface
INTERFACE_DIR = $(TOP)/interface
NAVIGATION_INC = $(INTERFACE_DIR)/navigation
# lib
LIB_DIR = $(TOP)/lib
# HepMC Dir
HEPMC_DIR = $(TOP)/HepMC/2.06.09
# python 2.7
PYTHON_2_7 = /usr/include/python2.7
##################################################
### create $TOP/bin directory if it does not exist
##################################################
#MKD_BIN = mkdir -p ./bin
##########################
### flags and libs and INC
##########################
#root
ROOT_CFLAGS = $(shell root-config --cflags)
ROOT_GLIBS = $(shell root-config --glibs)
# HepMC flags
HEPMCFLAGS = -I$(HEPMC_DIR)/include -L$(HEPMC_DIR)/lib -lHepMC -lHepMCfio
# CXX flags
CXXFLAGS = -Wall -std=c++0x
CXXFLAGS += $(ROOT_CFLAGS)
CXXFLAGS += -I$(INTERFACE_DIR) -I$(NAVIGATION_INC)
CXXFLAGS += -I$(TOP)/src -I$(PYTHON_2_7)
CXXFLAGS += $(HEPMCFLAGS)
# CXX LIBS
CXXLIBS = $(ROOT_GLIBS)
# all my files .ccp .cc and .hh
MAINS_CPP := $(wildcard $(TOP)/src/*.cpp)
SOURCES_CC := $(wildcard $(TOP)/src/*.cc)
INCLUDES_HH := $(wildcard $(INTERFACE_DIR)/*.hh)
EXES := $(MAINS_CPP:.cpp=.exe)
all: $(EXES)
%.exe: %.cpp
$(CXX) -o bin/$(notdir $@) $< $(CXXFLAGS) $(CXXLIBS)
py_lib:
make TOP=$(TOP) -C $(INTERFACE_DIR)
echo:
echo $(HEPMCFLAGS)
# echo $(TOP)
# echo $(INTERFACE_DIR)
# echo $(CXX) $(CXXFLAGS) -o bin/$@ $<
# echo $(EXES)
# echo $(MAINS_CPP)
mkdbin:
$(MKD_BIN)
1. HepMC:
DISCLAIMER: cmake is required
a. http://lcgapp.cern.ch/project/simu/HepMC/ls ()
b. download the version (e.g. HepMC-2.06.09.tar.gz)
c. install:
c.1. create a directory called HepMC in your root dir, copy the tar.gz in there
c.2. untar: tar -xvf HepMC-2.06.09.tar.gz
c.3. mkdir 2.06.09
c.3. cd 2.06.09
c.4. cmake -DCMAKE_INSTALL_PREFIX=~/$(ROOT_DIR)/HepMC/2.06.09 -Dmomentum:STRINGC=GEV -Dlength:STRING=CM ../HepMC-2.06.09
c.5. make
c.6. make test
c.7. make install
2. matplotlib:
#ifndef AnalysisOccupancy_HH
#define AnalysisOccupancy_HH
#include <cassert>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include "TH1F.h"
#include "TH2F.h"
#include "TProfile.h"
#include "Random.hh"
#include "TE1F.hh"
#include "TE2F.hh"
#include "TH2B.hh"
#include "AnalysisBase.hh"
#include "Event.hh"
class AnalysisOccupancy : public AnalysisBase {
public:
enum {
kCutBins=50
};
AnalysisOccupancy(const std::string &sName="AnalysisOccupancy") :
AnalysisBase(sName), fTwoPi(2.0*acos(-1.0)) {
std::vector<std::string> sNse(numbers("Noise",3));
std::vector<std::string> sNum(numbers("MIPs",kCutBins+1));
for(unsigned n(0);n<3;n++) {
hNumberOfWafers[n]=new TH2F((sName+"_"+sNse[n]+"NumberOfWafers").c_str(),
";Layer;#rho (cm);Number",
40,0.0,40.0,50,0.0,200.0);
hNumberOfCells[n]=new TH2F((sName+"_"+sNse[n]+"NumberOfCells").c_str(),
";Layer;#rho (cm);Number",
40,0.0,40.0,200,0.0,200.0);
for(unsigned i(0);i<kCutBins;i++) {
hNumberOfWaferHits[n][i]=new TH2F((sName+"_"+sNse[n]+sNum[i+1]+"NumberOfWaferHits").c_str(),
";Layer;#rho (cm);Occupancy",
40,0.0,40.0,50,0.0,200.0);
hNumberOfCellHits[n][i]=new TH2F((sName+"_"+sNse[n]+sNum[i+1]+"NumberOfCellHits").c_str(),
";Layer;#rho (cm);Occupancy",
40,0.0,40.0,50,0.0,200.0);
}
}
for(unsigned l(0);l<Geometry::kNumberOfLayers;l++) {
hCellsGeo[l]=new TH2B((sName+sLayerLabel[l]+"CellsGeo").c_str(),
(sLayerTitle[l]+";x (cm);y (cm)").c_str(),
3600,-180.0,180.0,3600,-180.0,180.0);
//1200,-60.0,60.0,1200,-60.0,60.0);
hCellsEta[l]=new TH2B((sName+sLayerLabel[l]+"CellsEta").c_str(),
(sLayerTitle[l]+";x (cm);y (cm)").c_str(),
3600,-180.0,180.0,3600,-180.0,180.0);
//1200,-60.0,60.0,1200,-60.0,60.0);
hCellsHit[l]=new TH2B((sName+sLayerLabel[l]+"CellsHit").c_str(),
(sLayerTitle[l]+";x (cm);y (cm)").c_str(),
3600,-180.0,180.0,3600,-180.0,180.0);
//1200,-60.0,60.0,1200,-60.0,60.0);
}
for(unsigned l(0);l<Geometry::kNumberOfLayers;l++) {
for(unsigned w(0);w<Geometry::numberOfWafers(l);w++) {
if(Geometry::validWafer(l,w)) {
fWaferRho[l][w]=Geometry::waferPoint(l,w).rho();
for(unsigned c(0);c<Geometry::numberOfCells(l,w);c++) {
Point p(Geometry::waferCellPoint(1,l,w,c));
fCellRho[l][w][c]=p.rho();
hCellsGeo[l]->Fill(p.x(),p.y());
if(p.eta()>1.47 && p.eta()<3.0) hCellsEta[l]->Fill(p.x(),p.y());
}
}
}
}
}
virtual ~AnalysisOccupancy() {
}
virtual bool event(Event &event) {
std::cout << fName << " Event " << fEventNumber << std::endl;
for(unsigned j(0);j<3;j++) {
if(j==0) {
DigNoise::setIrradiated(false);
DigNoise::setScale(0.0);
}
if(j==1) {
DigNoise::setIrradiated(false);
DigNoise::resetScale();
}
if(j==2) {
DigNoise::setIrradiated(true);
DigNoise::resetScale();
}
event.digHitProcessor();
for(unsigned e(0);e<Geometry::kNumberOfEndcaps;e++) {
for(unsigned l(0);l<Geometry::kNumberOfLayers;l++) {
for(unsigned w(0);w<Geometry::numberOfWafers(l);w++) {
if(Geometry::validWafer(l,w)) {
DigHit *vDigHit(event.digHits(e,l,w));
for(unsigned c(0);c<Geometry::numberOfCells(l,w);c++) {
hNumberOfWafers[j]->Fill(l,fWaferRho[l][w]);
hNumberOfCells[j]->Fill(l,fCellRho[l][w][c]);
if(vDigHit[c].simMips()>0.0) {
Point p(Geometry::waferCellPoint(1,l,w,c));
hCellsHit[l]->Fill(p.x(),p.y());
}
double m(vDigHit[c].mips());
for(unsigned i(0);i<kCutBins;i++) {
if(m>=0.1*(i+1)) {
hNumberOfWaferHits[j][i]->Fill(l,fWaferRho[l][w]);
hNumberOfCellHits[j][i]->Fill(l,fCellRho[l][w][c]);
}
}
}
}
}
}
}
}
return true;
}
private:
const double fTwoPi;
double fWaferRho[Geometry::kNumberOfLayers][Geometry::kMaximumNumberOfWafers];
double fCellRho[Geometry::kNumberOfLayers][Geometry::kMaximumNumberOfWafers][Geometry::kMaximumNumberOfCells];
TH2F *hNumberOfWafers[3];
TH2F *hNumberOfCells[3];
TH2F *hNumberOfWaferHits[3][kCutBins];
TH2F *hNumberOfCellHits[3][kCutBins];
TH2B *hCellsGeo[Geometry::kNumberOfLayers];
TH2B *hCellsEta[Geometry::kNumberOfLayers];
TH2B *hCellsHit[Geometry::kNumberOfLayers];
};
#endif
This diff is collapsed.
PYTHON_2_7 = /usr/include/python2.7
LIB_DIR = $(TOP)/python/naming/Geometry
all:
mkdir -p $(LIB_DIR)
touch $(LIB_DIR)/__init__.py
cp Geometry.hh Geometry.cpp
x86_64-linux-gnu-gcc -DPYTHON_WRAPPER -std=c++11 -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I$(PYTHON_2_7) -c Geometry.cpp -o Geometry.o
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security Geometry.o -lboost_python -o $(LIB_DIR)/geom.so
rm Geometry.o Geometry.cpp
#ifndef BASE_HH
#define BASE_HH 1
#include <iostream>
using namespace std;
class base {
public:
base() { ; }
base(int id) { fId = id; }
void setId(int id) { fId = id; }
int getId() { return fId; }
protected:
int fId;
};
#endif
#ifndef ENDCAP_HH
#define ENDCAP_HH 1
#include <vector>
#include <map>
#include "base.hh"
#include "layer.hh"
#include "triggerCell.hh"
class hgcEndcap {
public:
hgcEndcap() { this->initLayers(); }
hgcEndcap(int id) { this->initLayers(); fId =id; }
void addWafer(hgcWafer wafer) {
fLayers[wafer.getLayerId()].addWafer(wafer);
}
void addTriggerCell(hgcTriggerCell triggerCell) {
fLayers[triggerCell.getLayerId()].getWafer(triggerCell.getWaferId())->addTriggerCell(triggerCell);
}
hgcTriggerCell* getTriggerCell(int triggerCellId, int waferId, int layerId){
if (layerId<40)
return fLayers[layerId].getWafer(waferId)->getTriggerCell(triggerCellId);
}
hgcWafer* getWafer(int layerId, int waferId) {
if (layerId<40)
return fLayers[layerId].getWafer(waferId);
}
hgcLayer* getLayer(int layerId) {
if (layerId<40)
return &fLayers[layerId];
}
void print(){
for(int i_l=0; i_l<40; i_l++){
fLayers[i_l].print();
}
}
private:
int fId;
hgcLayer fLayers[40];
void initLayers() {
for(int i_l=0; i_l<40; i_l++)
fLayers[i_l].setId(i_l);
}
};
#endif
#ifndef LAYER_HH
#define LAYER_HH 1
#include <iostream>
#include "wafer.hh"
using namespace std;
class hgcLayer{
public:
hgcLayer() { ; }
hgcLayer(int id) { setId(id); }
void setId(int id) { fId = id; }
void addWafer(hgcWafer wafer) {
fWafers[wafer.getId()] = wafer;
fWafersValid[wafer.getId()] = true;
}
hgcWafer* getWafer(int waferId) { return &fWafers[waferId]; }
void print(){
cout << " >>> LAYER " << fId << endl;
for(int i_w=0; i_w<1000; i_w++){
if( fWafersValid[i_w] ){
fWafers[i_w].print();
}
}
}
private:
int fId;
hgcWafer fWafers[1000];
bool fWafersValid[1000];
};
#endif
#ifndef READER_HH
#define READER_HH 1
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <utility>
#include "endcap.hh"
using namespace std;
class reader {
public:
reader() {
fEndcap = new hgcEndcap(0);
}
reader(char* fileName, int layerId) {
fEndcap = new hgcEndcap(0);
this->process(fileName, layerId);
}
void process(char* fileName, int layerId);
hgcEndcap* getEncap() { return fEndcap; }
private:
hgcEndcap* fEndcap;
void getHeaderValue(string line, string &header, string &value);
template<typename A, typename B>
void read2DpythonList(string value, vector< pair<A,B> > &out);
void clearString(string &value);
};
void reader::process(char* fileName, int layerId){
ifstream inFile;
inFile.open(fileName);
string line;
string header, value;
int waferId = 0;
while ( inFile.good() ) {
getline(inFile, line);
this->getHeaderValue(line, header, value);
if( header == "wafer" ){
waferId = atoi( value.c_str() );
hgcWafer w(waferId, layerId);
cout << w.getId() << endl;
do{
getline(inFile, line); // skip the wafer corners
this->getHeaderValue(line, header, value);
}while ( header != "wafer_neighbours" );
vector< pair<int,int> > out_dd;
this->read2DpythonList( value, out_dd );
w.addNeighbours(out_dd);
fEndcap->addWafer(w);
}else{
continue;
}
do{
getline(inFile, line); // skip the wafer corners
this->getHeaderValue(line, header, value);
if(header == "tc"){
hgcTriggerCell tc(atoi( value.c_str() ), waferId);
do{
getline(inFile, line); // skip the wafer corners
this->getHeaderValue(line, header, value);
}while ( header != "tc_neighbours" );
vector< pair<int,int> > out_dd;
this->read2DpythonList( value, out_dd);
tc.addNeighbours(out_dd);
fEndcap->addTriggerCell(tc);
}
}while ( header != "wafer_end" );
}
fEndcap->print();
}
void reader::getHeaderValue(string line, string &header, string &value){
stringstream s(line);
getline(s, header, '#');
getline(s, value);
}
template<typename A, typename B>
void reader::read2DpythonList(string value, vector< pair<A,B> > &out){
double _A, _B;
string::size_type i = 0;
string::size_type j = value.find(']');
string tmp;
vector<string> pairs;
while (j != string::npos) {
tmp = value.substr(i, j-i);
this->clearString(tmp);
if(tmp != "") pairs.push_back(tmp);
i = ++j;
j = value.find(']', j);
if (j == string::npos){
tmp = value.substr(i, value.length());
this->clearString(tmp);
if(tmp != "") pairs.push_back(tmp);
}
}
for(int i=0; i<pairs.size(); i++){
size_t index;
size_t end = pairs.at(i).size();
index = pairs.at(i).find(",");
tmp = pairs.at(i).substr(0, index);
_A = atof(tmp.c_str());
tmp = pairs.at(i).substr(index+1, end);
_B = atof(tmp.c_str());
pair<A,B> p((A)_A, (B)_B);
out.push_back(p);
}
}
void reader::clearString(string &value){
size_t index;
index = value.find("[[");
if ( index != string::npos ){
value.erase(index, 2);
}
index = value.find(", [");
if ( index != string::npos ){
value.erase(index, 3);
}
index = value.find(" ");
while (index != string::npos ) {
value.erase(index, 1);
index = value.find(" ");
}
}
#endif
#ifndef TC_HH
#define TC_HH 1
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
class hgcTriggerCell {
public:
hgcTriggerCell() { ; }
hgcTriggerCell(int Id) { this->setId(Id); }
hgcTriggerCell(int Id, int waferId) { this->setId(Id); this->setWaferId(waferId); }
void addNeighbour(int waferId, int triggerCellId) { fNeighbours[waferId].push_back(triggerCellId); }
void addNeighbours(vector< pair<int,int> > n) {
for(int i=0; i<n.size(); i++){
fNeighbours[n.at(i).first].push_back(n.at(i).second);
}
}
bool isNeigbour(int waferId, int triggerCellId) {
if( find(fNeighbours[waferId].begin(), fNeighbours[waferId].end(), triggerCellId) != fNeighbours[waferId].end() )