Commit 01af1752 authored by Riccardo Longo's avatar Riccardo Longo
Browse files

Merge branch 'LHCf_Full_Processing' into 'master'

Added functionality of parsing LHCf driven files and analyzing them.\n Added a...

See merge request !9
parents e46680fc 66f71fa8
......@@ -12,12 +12,14 @@
#include "TTree.h"
#include "TFile.h"
#include "TKey.h"
#include "TBranch.h"
#include "TLeaf.h"
#include "TCanvas.h"
#include "TH1D.h"
#include "TH2D.h"
#include <vector>
#include <string>
#include "DataReader2021.h"
#include "LHCf_Trigger1.h"
......@@ -35,6 +37,8 @@ class LHCf_reader : public DataReader2021{
void OpenFile( void );
void OpenFileName( std::string _fileName );
void ConvertFile( void );
void GetEventWaveforms( int iEvent );
void InitializeHistograms( void );
void SetSkipPedestal ( bool _wantToSkip ) { m_skipPedestal = _wantToSkip; }
......@@ -44,9 +48,9 @@ class LHCf_reader : public DataReader2021{
void ShowEvent( int iEvent );
void ReadEvents( int iStartEvent = -1, int iEndEvent = -1 );
std::vector < unsigned int > GetGroupSample(unsigned int dwrd_0,
unsigned int dwrd_1,
unsigned int dwrd_2);
std::vector < float > GetGroupSample(unsigned int dwrd_0,
unsigned int dwrd_1,
unsigned int dwrd_2);
void VisualizeChannels ( void );
......@@ -63,8 +67,8 @@ class LHCf_reader : public DataReader2021{
std::vector < Channel* > m_v_Channel;
//std::vector < Channel* > m_v_digitizedChannels;
std::vector < std::vector < unsigned int > > m_v_Channels;
std::vector < std::vector < unsigned int > > m_v_Channels_Corrected;
std::vector < std::vector < float > > m_v_Channels;
std::vector < std::vector < float > > m_v_Channels_Corrected;
bool m_debug = true;
......@@ -74,6 +78,7 @@ class LHCf_reader : public DataReader2021{
bool m_skipBeam = false;
unsigned int m_nGroups = 3;
unsigned int m_nChPerGroup= 8;
};
#endif
......@@ -15,7 +15,7 @@ public:
virtual ~caen_correction () {};
int init( unsigned int *index_cell, int nChips,
std::vector < std::vector < unsigned int > > m_v_Channels );
std::vector < std::vector < float > > m_v_Channels );
float caen_corrected(const int sample, const int channel) const;
float caen_time(const int sample, const int channel) const;
......
......@@ -139,7 +139,7 @@ Channel* Detector::GetElement(std::string _name){
void Detector::SetBranches( TTree *_dataTree ){
for( uint ch = 0; ch < m_Element.size(); ch++ ){
_dataTree->SetBranchAddress( ("Raw" + m_Element.at(ch)->name).c_str(), &m_Element.at(ch)->pWF );
if( m_Element[ch]->is_on) _dataTree->SetBranchAddress( ("Raw" + m_Element.at(ch)->name).c_str(), &m_Element.at(ch)->pWF );
}
}
......@@ -183,6 +183,7 @@ void Detector::DeclareHistograms(){
*/
void Detector::FillHistograms(){
for( uint ch = 0; ch < m_Element.size(); ch++ ){
if (!m_Element.at(ch)->is_on) continue;
m_Element.at(ch)->WF_histo->Reset();
m_Element.at(ch)->PWF_histo->Reset();
m_Element.at(ch)->FirstDerivative->Reset();
......
......@@ -74,7 +74,7 @@ void LHCf_reader::OpenFileName( std::string _fileName ){
}
// Get 3 32 bit dwords and return 8 Ch sample values of the group Ch 0,1,2…7
std::vector<unsigned int> LHCf_reader::GetGroupSample(unsigned int dwrd_0, unsigned int dwrd_1, unsigned int dwrd_2){
std::vector<float> LHCf_reader::GetGroupSample(unsigned int dwrd_0, unsigned int dwrd_1, unsigned int dwrd_2){
/*
Get 3 32 bit dwords and return 8 Ch sample values
of the group Ch 0,1,2…7.
......@@ -87,7 +87,7 @@ std::vector<unsigned int> LHCf_reader::GetGroupSample(unsigned int dwrd_0, unsi
x/(2^n)%2^m
===============================================
*/
std::vector<unsigned int> sample;
std::vector<float> sample;
sample.push_back(dwrd_0%4096); // CH0
sample.push_back((dwrd_0/4096)%4096); // CH1
sample.push_back((dwrd_0/16777216)%4096 ^ (dwrd_1%16)*256); // CH2
......@@ -104,6 +104,180 @@ void LHCf_reader::ShowEvent( int iEvent ){
m_readTrigger1->Show( iEvent );
}
void LHCf_reader::ConvertFile(){
std::string outputDir = Form("%s/ProcessedLHCf",std::getenv("JZCaPA"));
gSystem->Exec( Form("mkdir -p %s", outputDir.c_str() ) );
std::string base_filename = m_fNameIn.substr(m_fNameIn.find_last_of("/\\") + 1);
std::string of = Form("%s/%s",outputDir.c_str() ,base_filename.c_str() );
if (m_debug) printf(" output file:%s\n",of.c_str());
TFile* out_file = TFile::Open(of.c_str(),"RECREATE");
TObject *obj;
TKey *key;
TTree* tree[5];
TIter next( m_filePointer->GetListOfKeys());
int id = 0;
bool readCurrent = 0;
int RunNumber;
int evt;
// Get runNumber
std::string fname_str(base_filename.c_str());
std::string result = fname_str.substr(0, fname_str.find_last_of("."));
RunNumber = atoi(result.substr(result.find_last_not_of("0123456789") + 1).c_str());
for ( int iCh = 0; iCh < m_nCh; iCh++){
std::vector < float > v_buffer, v_buffer2;
v_buffer.resize( m_nSamp );
v_buffer2.resize( m_nSamp );
m_v_Channels.push_back( v_buffer );
m_v_Channels_Corrected.push_back( v_buffer2 );
}
while ((key = (TKey *) next())) {
obj = m_filePointer->Get(key->GetName()); // copy object to memory
if (strcmp(key->GetClassName(),"TTree")) continue;
if (m_debug) printf(" found object:%s\n",key->GetName());
if (!strcmp(((TTree*)obj)->GetName(),"Trigger1")){
if (readCurrent) continue;
readCurrent = 1;
// Do Things with Trigger1
TTree* tree_to_read = (TTree*)obj;
if (m_debug) printf(" Nubmer of entries:%lld\n",tree_to_read->GetEntries());
// Deactivate the branch which needs to be processed
tree_to_read->SetBranchStatus("ZDCH",0);
// Clone skimmed
if (m_debug) printf(" About to clone LHCf branches\n");
tree[id] = tree_to_read->CloneTree(0);
tree[id]->CopyEntries(tree_to_read);
tree[id]->SetBranchStatus("*",0);
if (m_debug) printf(" Successfully cloned LHCf branches\n");
// Reactivate ZDCH
tree_to_read->SetBranchStatus("*",0);
tree_to_read->SetBranchStatus("ZDCH",1);
//Create run number and event number branches
tree[id]->Branch("RunNumber", &RunNumber, "RunNumber/I" );
tree[id]->Branch("EventNumber", &evt, "EventNumber/I" );
// Generate new Branches for unpacking
if (m_debug) printf(" About to generate ZDCH WF branches\n");
for (int ch=0;ch<m_nChPerGroup*m_nGroups;ch++){
tree[id]->Branch( Form( "RawSignal%d", ch), "std::vector<float>", &m_v_Channels_Corrected.at(ch) );
}
if (m_debug) printf(" Finished generating ZDCH WF branches\n");
// Run over all events and unpack, as per the 2 event shift
int MaxEvents = tree_to_read->GetEntries();
for(evt=0;evt<MaxEvents;evt++){
// Get Samples from evt+2
if ((MaxEvents-evt) < 3) continue;// Fill Empty
GetEventWaveforms(evt+2);
tree[id]->Fill();
}
tree[id]->SetEntries(MaxEvents);
tree[id]->SetName("tree"); // Temporary to see if solves JZCaPA issue
}else{
if (m_debug) printf(" Writing to TTree with ID: %d\n",id);
tree[id] = ((TTree*)obj)->CloneTree();
}
id++;
}
if (m_filePointer) m_filePointer->Close();
if (m_debug) printf(" Moving into new file.\n");
out_file->cd();
if (m_debug) printf(" Writing into new file.\n");
out_file->Write();
if (m_debug) printf(" Finished writing.\n");
out_file->Close();
}
void LHCf_reader::GetEventWaveforms(int iEvent){
m_v_Channels.clear();
m_v_Channels_Corrected.clear();
m_readTrigger1->GetEntry( iEvent );
bool trg_beam = false;
bool trg_pede = false;
trg_beam = (m_readTrigger1->GPI0_GPI0[0] >> 8) & 0x1;
trg_pede = (m_readTrigger1->GPI0_GPI0[0] >> 5) & 0x1;
//Checking trigger ADCs
double adc[2];
adc[0] = m_readTrigger1->ADC2_ADC2[0] - m_readTrigger1->ADC2_ADC2[32];// trg.scin 1
adc[1] = m_readTrigger1->ADC2_ADC2[2] - m_readTrigger1->ADC2_ADC2[34];// trg.scin 2
if(trg_pede) {
std::cout << "PEDESTAL TRIGGER - SKIP " << std::endl;
// return;
}
if(trg_beam){
std::cout << "BEAM TRIGGER " << std::endl;
}
for ( int iCh = 0; iCh < m_nCh; iCh++){
std::vector < float > v_buffer, v_buffer2;
v_buffer.resize( m_nSamp );
v_buffer2.resize( m_nSamp );
m_v_Channels.push_back( v_buffer );
m_v_Channels_Corrected.push_back( v_buffer2 );
}
//Retrieving calibration file from Util folder
std::string calibFile = std::getenv("JZCaPA") + std::string("/Utils/calib_0234_2G_0.dat");
caen_correction *cc;
cc = new caen_correction ( calibFile.c_str() );
unsigned int curser = 4;
unsigned int n_words_for_group_data_extraction;
unsigned int c_stop_flag;
//NSI - Noise subtraction implementation
unsigned int index_cell[m_nGroups];
// For group 1
for (int gid = 0; gid < m_nGroups; gid++){
n_words_for_group_data_extraction = m_readTrigger1->ZDCH_ZDCH[curser]%4096;
index_cell[gid] = (m_readTrigger1->ZDCH_ZDCH[curser]/1048576)%4096;
if(m_debug)
std::cout << "GID: " << gid << " n_words_for_group_data_extraction: " << n_words_for_group_data_extraction << std::endl;
//std::cout << "TR: " << (m_readTrigger1->ZDCH_ZDCH[curser]/4096)%2 << std::endl;
curser += 1;
c_stop_flag = curser + n_words_for_group_data_extraction;
// run over the dwords and extract each sample
int iBin = 0;
if(m_debug)
std::cout << "PRE --> CURSER: " << curser << " - CSTOPFLAG: " << c_stop_flag << std::endl;
for (int dummy = 0; curser < c_stop_flag; curser+=3){
std::vector < float > sample_vec = GetGroupSample(m_readTrigger1->ZDCH_ZDCH[curser],m_readTrigger1->ZDCH_ZDCH[curser+1],m_readTrigger1->ZDCH_ZDCH[curser+2]);
// store samples
for ( int iSamp = 0; iSamp < m_nChPerGroup; iSamp++){
m_v_Channels.at( (gid * m_nChPerGroup) + iSamp ).at(iBin) = sample_vec.at(iSamp);
}
iBin++;
}
if(m_debug)
std::cout << "POST --> CURSER: " << curser << " - CSTOPFLAG: " << c_stop_flag << std::endl;
// Move to next group data words
curser += 1;
}
// Perform signal correction using firmware values
cc->init(index_cell, m_nGroups, m_v_Channels);
for(int iCh = 0; iCh < m_nChPerGroup*m_nGroups; iCh++){
for(int iSamp = 0; iSamp < m_nSamp; iSamp++){
m_v_Channels_Corrected.at( iCh ).at( iSamp ) = cc->caen_corrected( iSamp, iCh );
}
}
}
void LHCf_reader::ReadEvents( int iStartEvent, int iEndEvent ){
if( iStartEvent == -1 ) iStartEvent = 0;
......@@ -138,7 +312,7 @@ void LHCf_reader::ReadEvents( int iStartEvent, int iEndEvent ){
}
for ( int iCh = 0; iCh < m_nCh; iCh++){
std::vector < unsigned int > v_buffer, v_buffer2;
std::vector < float > v_buffer, v_buffer2;
v_buffer.resize( m_nSamp );
v_buffer2.resize( m_nSamp );
m_v_Channels.push_back( v_buffer );
......@@ -173,7 +347,7 @@ void LHCf_reader::ReadEvents( int iStartEvent, int iEndEvent ){
std::cout << "PRE --> CURSER: " << curser << " - CSTOPFLAG: " << c_stop_flag << std::endl;
for (int dummy = 0; curser < c_stop_flag; curser+=3){
std::vector < unsigned int > sample_vec = GetGroupSample(m_readTrigger1->ZDCH_ZDCH[curser],m_readTrigger1->ZDCH_ZDCH[curser+1],m_readTrigger1->ZDCH_ZDCH[curser+2]);
std::vector < float > sample_vec = GetGroupSample(m_readTrigger1->ZDCH_ZDCH[curser],m_readTrigger1->ZDCH_ZDCH[curser+1],m_readTrigger1->ZDCH_ZDCH[curser+2]);
// store samples
for ( int iSamp = 0; iSamp < nPerGroup; iSamp++){
m_v_Channels.at( (gid * nPerGroup) + iSamp ).at(iBin) = sample_vec.at(iSamp);
......
......@@ -6,6 +6,11 @@
using namespace std;
/*
Original code by Martin Purschke (sPhenix)
Modified for JZCaPA LHCf data by Riccardo Longo, Yftach Moyal
*/
caen_correction::caen_correction ( const char *calibdata)
{
......@@ -71,7 +76,7 @@ caen_correction::caen_correction ( const char *calibdata)
}
int caen_correction::init ( unsigned int *index_cell, int nChips,
std::vector < std::vector < unsigned int > > m_v_Channels )
std::vector < std::vector < float > > m_v_Channels )
{
int chip,c,i,idx;
......
......@@ -23,8 +23,9 @@ int main(int argc, char *argv[]){
LHCf_reader* myReader = new LHCf_reader( fNameIn.c_str() );
myReader->OpenFile();
myReader->ReadEvents( 215, 220 );
//myReader->ReadEvents( 215, 220 );
myReader->ConvertFile();
myReader->VisualizeChannels();
//myReader->VisualizeChannels();
return 0;
}
......@@ -10333,6 +10333,93 @@
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal24</name>
<detector>UEM</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1400</hv_set>
<is_on>false</is_on>
<mapping_row>1</mapping_row>
<mapping_column>2</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal25</name>
<detector>UEM</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1400</hv_set>
<is_on>false</is_on>
<mapping_row>2</mapping_row>
<mapping_column>2</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal26</name>
<detector>UEM</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1400</hv_set>
<is_on>false</is_on>
<mapping_row>3</mapping_row>
<mapping_column>2</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal27</name>
<detector>UEM</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1400</hv_set>
<is_on>false</is_on>
<mapping_row>1</mapping_row>
<mapping_column>1</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal28</name>
<detector>UEM</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1400</hv_set>
<is_on>false</is_on>
<mapping_row>2</mapping_row>
<mapping_column>1</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal29</name>
<detector>UEM</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1400</hv_set>
<is_on>false</is_on>
<mapping_row>3</mapping_row>
<mapping_column>1</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal0</name>
<detector>TRIGGER</detector>
......@@ -10361,6 +10448,35 @@
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal34</name>
<detector>TRIGGER</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1750</hv_set>
<is_on>false</is_on>
<mapping_row>2</mapping_row>
<mapping_column>1</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal35</name>
<detector>TRIGGER</detector>
<start_run>70000</start_run>
<end_run>70220</end_run>
<hv_set>1700</hv_set>
<is_on>false</is_on>
<mapping_row>2</mapping_row>
<mapping_column>2</mapping_column>
<pmt_code>DUMMY</pmt_code>
<is_pos_polarity>false</is_pos_polarity>
<adc_per_mv>0.244</adc_per_mv>
</channel>
<channel>
<name>Signal8</name>
<detector>PFRPD</detector>
......@@ -10589,7 +10705,7 @@
<name>Signal5</name>
<detector>HAD</detector>
<start_run>70000</start_run>
<end_run>0</end_run>
<end_run>70220</end_run>
<hv_set>1700</hv_set>
<is_on>true</is_on>
<mapping_row>0</mapping_row>
......@@ -10603,7 +10719,7 @@
<name>Signal6</name>
<detector>HAD</detector>
<start_run>70000</start_run>
<end_run>0</end_run>
<end_run>70220</end_run>
<hv_set>1700</hv_set>
<is_on>true</is_on>
<mapping_row>0</mapping_row>
......@@ -10617,7 +10733,7 @@
<name>Signal7</name>
<detector>HAD</detector>
<start_run>70000</start_run>
<end_run>0</end_run>
<end_run>70220</end_run>
<hv_set>1700</hv_set>
<is_on>true</is_on>
<mapping_row>0</mapping_row>
......
......@@ -197,7 +197,7 @@
<!-- H4-SM1 (1) -->
<Survey>
<start_run>785</start_run>
<end_run>853</end_run>
<end_run>864</end_run>
<detector>UEM</detector>
<x_pos>8.575</x_pos>
<y_pos>-9.51</y_pos>
......@@ -213,7 +213,7 @@
</Survey>
<Survey>
<start_run>785</start_run>
<end_run>853</end_run>
<end_run>864</end_run>
<detector>PFRPD</detector>
<x_pos>4.8</x_pos>
<y_pos>-5.375</y_pos>
......@@ -229,7 +229,7 @@
</Survey>
<Survey>
<start_run>785</start_run>
<end_run>853</end_run>
<end_run>864</end_run>
<detector>HAD1</detector>
<x_pos>0.35</x_pos>
<y_pos>9.4</y_pos>
......@@ -245,7 +245,7 @@
</Survey>
<Survey>
<start_run>785</start_run>
<end_run>853</end_run>
<end_run>864</end_run>
<detector>HAD2</detector>
<x_pos>-104.25</x_pos>
<y_pos>4.275</y_pos>
......@@ -261,7 +261,7 @@
</Survey>
<Survey>
<start_run>785</start_run>
<end_run>853</end_run>
<end_run>864</end_run>
<detector>HAD3</detector>
<x_pos>-212.0</x_pos>
<y_pos>4.65</y_pos>
......@@ -374,7 +374,7 @@
</Survey>
<!-- H4-SM2 -->
<Survey>
<start_run>70182</start_run>
<start_run>70178</start_run>
<end_run>70220</end_run>
<detector>UEM</detector>
<x_pos>8.575</x_pos>
......@@ -390,7 +390,7 @@
<trigger_y>52.069</trigger_y>
</Survey>
<Survey>
<start_run>70182</start_run>
<start_run>70178</start_run>
<end_run>70220</end_run>
<detector>PFRPD</detector>
<x_pos>9.3</x_pos>
......@@ -406,7 +406,7 @@
<trigger_y>52.069</trigger_y>
</Survey>
<Survey>
<start_run>70182</start_run>
<start_run>70178</start_run>
<end_run>70220</end_run>
<detector>HAD1</detector>
<x_pos>0.35</x_pos>
......@@ -422,7 +422,7 @@
<trigger_y>52.069</trigger_y>
</Survey>
<Survey>
<start_run>70182</start_run>
<start_run>70178</start_run>
<end_run>70220</end_run>
<detector>HAD2</detector>
<x_pos>-104.25</x_pos>
......@@ -438,7 +438,7 @@
<trigger_y>52.069</trigger_y>
</Survey>
<Survey>
<start_run>70182</start_run>
<start_run>70178</start_run>
<end_run>70220</end_run>
<detector>HAD3</detector>
<x_pos>-212.0</x_pos>
......@@ -454,7 +454,7 @@
<trigger_y>52.069</trigger_y>
</Survey>
<Survey>
<start_run>70182</start_run>
<start_run>70178</start_run>
<end_run>70220</end_run>
<detector>ADAMO</detector>
<x_pos>-5.5</x_pos>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment