Skip to content

Instantly share code, notes, and snippets.

@vp1981
Created August 20, 2018 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vp1981/84f91674b6a7b696131b6d72b9eafd57 to your computer and use it in GitHub Desktop.
Save vp1981/84f91674b6a7b696131b6d72b9eafd57 to your computer and use it in GitHub Desktop.
#ifndef _CLUSTER_CXX_
#define _CLUSTER_CXX_
#include "cluster.h"
#include "prova.h"
#include <iostream>
#include <vector>
#include <string.h>
#include <map>
#include "TROOT.h"
using namespace std;
Cluster::Cluster(map<int, int> &map, string &name)
{
this->reset();
if(map.size()>1)
{
_n_clu = 0;
vector<int> temp_cluster, temp_max_q, vec_strip, vec_max_q;
for(std::map<int,int>::iterator it=map.begin(); it!=map.end(); it++)
{
vec_strip.push_back(it->first);//copio gli elementi della mappa su due vettori d'appoggio
vec_max_q.push_back(it->second);
}
unsigned int k = 0; // variabile che mi tiene conto dello scorrere degli elementi dei vettori
while(k<(vec_strip.size()-1))
{ //giro su tutto il vettore delle strip
int j = 0; //variabile che mi tiene conto del numero di volte che sono entrato nel ciclo
double centroid_coord = 0;
int temp_q_sum = 0;//variabili per il calcolo del centroide
while((k<(vec_strip.size()-1)) && ((vec_strip.at(k+1) - vec_strip.at(k)) <= 3))
{ //controllo cluster
if((vec_strip.at(k+1) - vec_strip.at(k)) == 2)
_n_holes++;
if(j<1)
{ //ci entro solo all'inizio del cluster
temp_cluster.push_back(vec_strip.at(k));//riempio i vettori con gli elementi dell'inizio del cluster
temp_max_q.push_back(vec_max_q.at(k));
centroid_coord += (vec_strip.at(k)*pitch*vec_max_q.at(k));
temp_q_sum += vec_max_q.at(k);
}
temp_cluster.push_back(vec_strip.at(k+1));//riempio i vettori con gli elementi successivi del cluster
temp_max_q.push_back(vec_max_q.at(k+1));
centroid_coord += (vec_strip.at(k+1)*pitch*vec_max_q.at(k+1));
temp_q_sum += vec_max_q.at(k+1);
j++;//tiene conto della grandezza del cluster
k++;
}
if(j > 10 || _n_holes > n_holes_max)
{ //controllo che il cluster non sia troppo grande
temp_cluster.clear();
temp_max_q.clear();
centroid_coord = 0;
temp_q_sum = 0;
}
else
if(j!= 0 && j<= 10)
{ //controllo che il cluster ci sia e che sia minore di 10 strips. Inoltre calcolo il centroide
_n_clu++;
for(UInt_t i = 0; i<temp_cluster.size(); i++)
{
_strip.push_back(temp_cluster.at(i));//riempio il vettore con le strip del cluster
_max_q.push_back(temp_max_q.at(i));//riempio il vettore con la carica delle strip
_chamb.push_back(name); //riempio il vettore con il nome della camera a cui appartiene il cluster
if(i == 0)
{
_sum_q.push_back(temp_q_sum);
_n_cluster.push_back(_n_clu);//do un numero al cluster
_centroid.push_back(centroid_coord/temp_q_sum);//mi segno il valore del centroide del cluster
_pcb.push_back((int)((((centroid_coord/temp_q_sum)/pitch)-1)/512)+1);
pcb_n_cluster[(int)((((centroid_coord/temp_q_sum)/pitch)-1)/512)+((int)(atoi(name).substr(1,1).c_str())-1)*5] += 1;
}
else
{
_sum_q.push_back(0);
_n_cluster.push_back(0);//do un numero al cluster
_centroid.push_back(0);//mi segno il valore del centroide del cluster
_pcb.push_back(0);
}
}
temp_cluster.clear();//svuoto entrambi i vettori dei cluster
temp_max_q.clear();
}
while((k<(vec_strip.size()-1)) && ((vec_strip.at(k+1) - vec_strip.at(k))>3))
{ //se non c'è un cluster, comunque scorro sul vettore con il k
k++;
}
}
}
}
void Cluster::reset()
{
_strip.clear();
_chamb.clear();
_max_q.clear();
_centroid.clear();
_sum_q.clear();
_n_cluster.clear();
_pcb.clear();
_pcb_n_cluster.clear();
_n_holes = 0;
}
vector<string> Cluster::GetChamb()
{
return _chamb;
}
vector<double> Cluster::GetCentroid()
{
return _centroid;
}
vector<int> Cluster::GetClusterStrip()
{
return _strip;
}
vector<int> Cluster::GetClusterMax_q()
{
return _max_q;
}
vector<int> Cluster::GetSum_q()
{
return _sum_q;
}
int Cluster::GetN_Cluster()
{
return _n_clu;
}
vector<int> Cluster::GetPCB()
{
return _pcb;
}
Cluster::isGoodCluster(int charge_min, string &name) const
{
for(UInt_t i = 0; i<chamb.size(); i++)
{
if(chamb.at(i) == name && cluster_max_q.at(i)<charge_min)
return false;
}
return true;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment