Commit 87406c69 authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

Merge branch 'preprod' into 'preprod'

Merge TreeBuilder branch in preprod and correct EventBuilder bug

See merge request IPNL_GAMMA/narval_emulator!62
parents d125cd9a 92b09a91
......@@ -39,6 +39,8 @@ Frame: Agata data:ranc2 4 0 Agata data:ranc2 65000 0
Frame: Agata data:psa 4 0 Agata data:psa 0 0
Frame: Agata data:tracked 4 0 Agata data:tracked 1 0
Frame: Agata event:data 4 0 Agata event:data 4 0
Frame: Agata event:data:crystal 4 0 Agata event:data:crystal 4 0
Frame: Agata event:data:ccrystal 4 0 Agata event:data:ccrystal 4 0
Frame: Agata event:data:psa 4 0 Agata event:data:psa 4 0
Frame: Agata event:data:ranc0 4 0 Agata event:data:ranc0 4 0
Frame: Agata event:data:ranc1 4 0 Agata event:data:ranc1 4 0
......
......@@ -765,7 +765,7 @@ UInt_t EventBuilder::GetParameters(const std::string& confFile, Bool_t doList)
}
}
if(conf.Seen("TstampCorrect")) {
int which = conf.Find("TimestampCorrect");
int which = conf.Find("TstampCorrect");
int times = conf.Times(which);
for(int nn = 0; nn < times; nn++) {
conf.Restore(which, nn);
......
......@@ -22,36 +22,383 @@
#include "AGAPRO_TB_AGATA.h"
#endif
#include <utility>
#include <algorithm>
#include "TrackedFrame.h"
#include "PSAFrame.h"
#include "TGeoMatrix.h"
using namespace AGAPRO;
/// ****** Builder ******///
TB_AGATA_Builder::TB_AGATA_Builder(TString name, TString ADFKey) : TB_Detector(name,ADFKey)
/// ****** CRYSTAL ******///
TB_AGATA_CRYSTAL::TB_AGATA_CRYSTAL(TString name, TString ADFKey) : TB_Detector(move(name),move(ADFKey))
{
gActualClass = "TB_AGATA_CRYSTAL";
}
TB_AGATA_CRYSTAL::~TB_AGATA_CRYSTAL() = default;
void TB_AGATA_CRYSTAL::Init()
{
if(fTriggerName.Contains("ccrystal")) {
fTraceLenght = kCCrystalTraceLenght;
fType = ccrystal;
}
else if(fTriggerName.Contains("crystal")) {
fTraceLenght = kCrystalTraceLenght;
fType = crystal;
}
else {
fTraceLenght = kMaxTraceLenght;
fType = undef;
}
}
void TB_AGATA_CRYSTAL::InitValues()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("InitValues()");
crystalTS = 0;
crystalId = 0;
if(fType == crystal) {
memset(SegTracesu, 0, sizeof(SegTracesu));
memset(CoreTracesu, 0, sizeof(CoreTracesu));
}
else if(fType == ccrystal) {
memset(SegTraces, 0, sizeof(SegTraces));
memset(CoreTraces, 0, sizeof(CoreTraces));
}
memset(SegE, 0, sizeof(SegE));
memset(CoreE, 0, sizeof(CoreE));
}
void TB_AGATA_CRYSTAL::InitTree()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("InitTree()");
if(fTree == nullptr)
return;
if(fType == crystal) {
fTree->Branch("SegTraces", SegTracesu, Form("SegTraces[%d]/S",kNSG*fTraceLenght));
fTree->Branch("CoreTraces", CoreTracesu, Form("CoreTraces[%d]/S",kNCC*fTraceLenght));
}
else if(fType == ccrystal){
fTree->Branch("SegTraces", SegTraces, Form("SegTraces[%d]/F",kNSG*fTraceLenght));
fTree->Branch("CoreTraces", CoreTraces, Form("CoreTraces[%d]/F",kNCC*fTraceLenght));
}
fTree->Branch("SegE", SegE, Form("SegE[%d]/F",kNSG));
fTree->Branch("CoreE", CoreE, Form("CoreE[%d]/F",kNCC));
fTree->Branch("CrystalId", &crystalId, "CrystalId/I");
fTree->Branch("CrystalTS", &crystalTS, "CrystalTS/l");
}
void TB_AGATA_CRYSTAL::Process(Int_t idet)
{
Log.ClearMessage();
Log.GetProcessName() = "TB_AGATA_CRYSTAL";
Log.SetProcessMethod(Form("Process(%d)",idet));
fSFrame = fTrigger->GetInputSharedFP();
fSFrame->GetFrame()->Read();
auto *data = GetDataPointer<CrystalInterface>(fSFrame);
crystalTS = (dynamic_cast<AgataKey *>(fSFrame->GetFrame()->GetKey()))->GetTimeStamp();
crystalId = data->GetUID();
if(!WarnedDone && data && data->GetCore(0)->GetSignal()->GetLength()!=fTraceLenght) {
Log << error << " Signal length: " << data->GetCore(0)->GetSignal()->GetLength() << " ; Stored length in tree: " << fTraceLenght << nline;
WarnedDone = true;
}
for (Int_t i = 0; i < kNCC; i++ ) {
if(fType==crystal)
memcpy(&CoreTracesu[i*fTraceLenght],data->GetCore(i)->GetSignal()->Address(CoreTracesu),sizeof(UShort_t)*fTraceLenght);
else if(fType == ccrystal)
memcpy(&CoreTraces[i*fTraceLenght],data->GetCore(i)->GetSignal()->Address(CoreTraces),sizeof(Float_t)*fTraceLenght);
CoreE[i] = data->GetCore(i)->GetE();
}
for (Int_t i = 0; i < kNSG; i++ ) {
if(fType==crystal)
memcpy(&SegTracesu[i*fTraceLenght],data->GetSegment(i)->GetSignal()->Address(SegTracesu),sizeof(UShort_t)*fTraceLenght);
if(fType==ccrystal)
memcpy(&SegTraces[i*fTraceLenght],data->GetSegment(i)->GetSignal()->Address(SegTraces),sizeof(Float_t)*fTraceLenght);
SegE[i] = data->GetSegment(i)->GetE();
}
}
/// ****** PSA ******///
TB_AGATA_PSA::TB_AGATA_PSA(TString name, TString ADFKey) : TB_Detector(move(name),move(ADFKey))
{
gActualClass = "TB_AGATA_PSA";
}
TB_AGATA_PSA::~TB_AGATA_PSA() = default;
void TB_AGATA_PSA::Init()
{
ReadTransformation();
}
void TB_AGATA_PSA::InitValues()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("InitValues()");
nbHits = 0;
coreId = 0.;
coreE0 = 0.;
coreE1 = 0.;
coreT0 = 0.;
coreT1 = 0.;
coreTS = 0.;
}
void TB_AGATA_PSA::InitTree()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("InitPSAHits()");
if(fTree == nullptr)
return;
fTree->Branch("nbHits", &nbHits, "nbHits/I");
fTree->Branch("hitE", hitE, "hitE[nbHits]/F");
fTree->Branch("hitX", hitX, "hitX[nbHits]/F");
fTree->Branch("hitY", hitY, "hitY[nbHits]/F");
fTree->Branch("hitZ", hitZ, "hitZ[nbHits]/F");
fTree->Branch("hitGX", hitGX, "hitGX[nbHits]/F");
fTree->Branch("hitGY", hitGY, "hitGY[nbHits]/F");
fTree->Branch("hitGZ", hitGZ, "hitGZ[nbHits]/F");
fTree->Branch("hitSg", hitSg, "hitSg[nbHits]/I");
fTree->Branch("coreId", &coreId, "coreId/I");
fTree->Branch("coreE0", &coreE0, "coreE0/F");
fTree->Branch("coreE1", &coreE1, "coreE1/F");
fTree->Branch("coreT0", &coreT0, "coreT0/F");
fTree->Branch("coreT1", &coreT1, "coreT1/F");
fTree->Branch("coreTS", &coreTS, "coreTS/l");
}
void TB_AGATA_PSA::Process(Int_t idet)
{
Log.ClearMessage();
Log.GetProcessName() = "TB_AGATA_PSA";
Log.SetProcessMethod(Form("Process(%d)",idet));
fSFrame = fTrigger->GetInputSharedFP();
fSFrame->GetFrame()->Read();
auto *data = GetDataPointer<PSAInterface>(fSFrame);
nbHits = data->GetNbHits();
if ( nbHits > MaxHits ) {
Log << error << " Number of Hits : " << nbHits << " ; Max nbHits = " << MaxHits << nline;
InitValues();
return;
}
// Core like branches
coreId = data->GetUID();
coreE0 = data->GetE(0);
coreE1 = data->GetE(1);
coreT0 = data->GetT(0);
coreT1 = data->GetT(1);
coreTS = dynamic_cast<AgataKey *>(fSFrame->GetFrame()->GetKey())->GetTimeStamp();
// Loop on the hits
for (Int_t j = 0; j < nbHits ; ++j) {
const PSAHit* pHit = dynamic_cast<PSAHit *>(data->GetHit(j));
hitE[j] = pHit->GetE();
hitX[j] = pHit->GetX();
hitY[j] = pHit->GetY();
hitZ[j] = pHit->GetZ();
hitSg[j] = pHit->GetID();
//Get hit position
Double_t xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal;
pHit->GetXYZ(xLocal, yLocal, zLocal);
//To the AGATA global ref
Local2Global(data->GetUID(), xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal);
// Set the Position of the hit in global ref
hitGX[j]= xGlobal; // inversion X-Y and opposite direction
hitGY[j]= yGlobal; // inversion Y-X and opposite direction
hitGZ[j]= zGlobal; // z
}
}
/// ****** Builder CRYSTAL ******///
TB_AGATA_Builder_CRYSTAL::TB_AGATA_Builder_CRYSTAL(TString name, TString ADFKey) : TB_Detector(move(name),move(ADFKey))
{
gActualClass = "TB_AGATA_Builder";
gActualClass = "TB_AGATA_Builder_CRYSTAL";
}
TB_AGATA_Builder::~TB_AGATA_Builder()
TB_AGATA_Builder_CRYSTAL::~TB_AGATA_Builder_CRYSTAL() = default;
void TB_AGATA_Builder_CRYSTAL::Init()
{
if(fMatrixList)
delete fMatrixList;
if(fTriggerName.Contains("ccrystal")) {
fSFrame = fTrigger->AddUtility("data:ccrystal",ConfAgent::theGlobalAgent());
fTraceLenght = kCCrystalTraceLenght;
fType = ccrystal;
}
else if(fTriggerName.Contains("crystal")){
fSFrame = fTrigger->AddUtility("data:crystal",ConfAgent::theGlobalAgent());
fTraceLenght = kCrystalTraceLenght;
fType = crystal;
}
else {
fTraceLenght = kMaxTraceLenght;
}
}
void TB_AGATA_Builder_CRYSTAL::InitValues()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("InitValues()");
nbCrystals = 0;
SegTracesSize = 0;
CoreTracesSize = 0;
SegESize = 0;
CoreESize = 0;
EvtCrystalTS = 0;
}
void TB_AGATA_Builder_CRYSTAL::InitTree()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("InitTree()");
if(fTree == nullptr)
return;
fTree->Branch("nbCrystals", &nbCrystals, "nbCrystals/I");
fTree->Branch("CrystalId", crystalId, "CrystalId[nbCrystals]/F");
fTree->Branch("CrystalTS", crystalTS, "CrystalTS[nbCrystals]/F");
fTree->Branch("SegTracesSize", &SegTracesSize, "SegTracesSize/I");
if(fType == crystal)
fTree->Branch("SegTraces", SegTracesu, "SegTraces[SegTracesSize]/S");
else if(fType == ccrystal)
fTree->Branch("SegTraces", SegTraces, "SegTraces[SegTracesSize]/F");
fTree->Branch("CoreTracesSize", &CoreTracesSize, "CoreTracesSize/I");
if(fType == crystal)
fTree->Branch("CoreTraces", CoreTracesu, "CoreTraces[CoreTracesSize]/S");
else if(fType == ccrystal)
fTree->Branch("CoreTraces", CoreTraces, "CoreTraces[CoreTracesSize]/F");
fTree->Branch("SegESize", &SegESize, "SegESize/I");
fTree->Branch("SegE", SegE, "SegE[SegESize]/F");
fTree->Branch("CoreESize", &CoreESize, "CoreESize/I");
fTree->Branch("CoreE", CoreE, "CoreE[CoreESize]/F");
fTree->Branch("EvtCrystalTS", &EvtCrystalTS, "EvtCrystalTS/l");
}
void TB_AGATA_Builder::Init()
void TB_AGATA_Builder_CRYSTAL::Process(Int_t idet)
{
fFrame = fTrigger->AddUtility("data:psa",ConfAgent::theGlobalAgent());
Log.ClearMessage();
Log.GetProcessName() = "TB_AGATA_Builder_CRYSTAL";
Log.SetProcessMethod(Form("Process(%d)",idet));
if(!fMergerMode)
fCompFrame = dynamic_cast<AgataCompositeFrame*>(fTrigger->GetInputSharedFP()->GetFrame());
else
fCompFrame = dynamic_cast<AgataCompositeFrame*>(fTrigger->GetInputSharedFP(idet+1)->GetFrame());
fCompFrame->Scan();
EvtCrystalTS = dynamic_cast<AgataKey*>(fCompFrame->GetKey())->GetTimeStamp();
nbCrystals = fCompFrame->GetNbSubFrame();
CoreTracesSize = nbCrystals*kNCC*fTraceLenght;
CoreESize = nbCrystals*kNCC;
SegTracesSize = nbCrystals*kNSG*fTraceLenght;
SegESize = nbCrystals*kNSG;
for(Int_t i=0 ; i < nbCrystals ; i++) {
fCompFrame->LinkSubFrame(i,fSFrame->GetFrame());
fSFrame->GetFrame()->Read();
auto *data = GetDataPointer<CrystalInterface>(fSFrame);
if(!WarnedDone && data && data->GetCore(0)->GetSignal()->GetLength()!=fTraceLenght) {
Log << error << " Signal length: " << data->GetCore(0)->GetSignal()->GetLength() << " ; Stored length in tree: " << fTraceLenght << nline;
WarnedDone = true;
}
crystalTS[i] = dynamic_cast<AgataKey*>(fSFrame->GetFrame()->GetKey())->GetTimeStamp();
crystalId[i] = data->GetUID();
for (Int_t j = 0; j < kNCC; j++ ) {
if(fType==crystal)
memcpy(&CoreTracesu[i*fTraceLenght*kNCC+fTraceLenght*j],data->GetCore(j)->GetSignal()->Address(CoreTracesu),sizeof(UShort_t)*fTraceLenght);
else if(fType == ccrystal)
memcpy(&CoreTraces[i*fTraceLenght*kNCC+fTraceLenght*j],data->GetCore(j)->GetSignal()->Address(CoreTraces),sizeof(Float_t)*fTraceLenght);
CoreE[i*kNCC+j] = data->GetCore(j)->GetE();
}
for (Int_t j = 0; j < kNSG; j++ ) {
if(fType==crystal)
memcpy(&SegTracesu[i*fTraceLenght*kNSG+fTraceLenght*j],data->GetSegment(j)->GetSignal()->Address(SegTracesu),sizeof(UShort_t )*fTraceLenght);
else if(fType == ccrystal)
memcpy(&SegTraces[i*fTraceLenght*kNSG+fTraceLenght*j],data->GetSegment(j)->GetSignal()->Address(SegTraces),sizeof(Float_t)*fTraceLenght);
SegE[i*kNSG+j] = data->GetSegment(j)->GetE();
}
}
}
/// ****** Builder PSA ******///
TB_AGATA_Builder_PSA::TB_AGATA_Builder_PSA(TString name, TString ADFKey) : TB_Detector(move(name),move(ADFKey))
{
gActualClass = "TB_AGATA_Builder_PSA";
}
TB_AGATA_Builder_PSA::~TB_AGATA_Builder_PSA() = default;
void TB_AGATA_Builder_PSA::Init()
{
fSFrame = fTrigger->AddUtility("data:psa",ConfAgent::theGlobalAgent());
ReadTransformation();
}
void TB_AGATA_Builder::InitValues()
void TB_AGATA_Builder_PSA::InitValues()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
......@@ -64,7 +411,7 @@ void TB_AGATA_Builder::InitValues()
}
void TB_AGATA_Builder::InitTree()
void TB_AGATA_Builder_PSA::InitTree()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
......@@ -103,59 +450,58 @@ void TB_AGATA_Builder::InitTree()
fTree->Branch("TSHit", &TSHit, "TSHit/l");
TString temparray[45];
temparray[0] = "1 2 13 12 3";
temparray[1] = "2 0 3 5 22 20";
temparray[2] = "0 1 20 17 16 13";
temparray[3] = "0 6 4 5 1 ";
temparray[4] = "3 5 26 28 8 6 ";
temparray[5] = "1 3 4 26 23 22";
temparray[6] = "3 4 8 7 9";
temparray[7] = "6 9 11 34 32 8 ";
temparray[8] = "4 6 7 32 29 28";
temparray[9] = "12 10 11 7 6";
temparray[10] = "9 12 14 40 38 11";
temparray[11] = "7 9 10 38 35 34";
temparray[12] = "9 10 14 13 0";
temparray[13] = "0 2 16 44 14 12";
temparray[14] = "10 12 13 44 41 40";
temparray[15] = "17 16 42";
temparray[16] = "2 17 15 42 44 13";
temparray[17] = "15 16 2 20 19";
temparray[18] = "19 20 22 21";
temparray[19] = "17 20 18";
temparray[20] = "1 22 18 19 17 2 ";
temparray[21] = "18 22 23";
temparray[22] = "1 5 23 21 18 20";
temparray[23] = "21 22 5 26 25";
temparray[24] = "25 26 28 27";
temparray[25] = "23 26 24";
temparray[26] = "5 4 28 24 25 23";
temparray[27] = "24 28 29";
temparray[28] = "24 26 4 8 29 27";
temparray[29] = "27 28 8 32 31";
temparray[30] = "31 32 34 33";
temparray[31] = "29 32 30";
temparray[32] = "31 29 8 7 34 30";
temparray[33] = "30 34 35";
temparray[34] = "30 32 7 11 35 33";
temparray[35] = "33 34 11 38 37";
temparray[36] = "37 38 40 39";
temparray[37] = "35 38 36";
temparray[38] = "11 10 40 36 37 35";
temparray[39] = "36 40 41";
temparray[40] = "10 14 41 39 36 38";
temparray[41] = "39 40 14 44 43";
temparray[42] = "43 44 16 15";
temparray[43] = "41 44 42";
temparray[44] = "13 16 42 43 41 14";
for(int i=0 ; i<45 ; i++)
{
const auto NCrystals = 45;
auto it=0;
array<TString,NCrystals> temparray;
temparray[it++] = "1 2 13 12 3";
temparray[it++] = "2 0 3 5 22 20";
temparray[it++] = "0 1 20 17 16 13";
temparray[it++] = "0 6 4 5 1 ";
temparray[it++] = "3 5 26 28 8 6 ";
temparray[it++] = "1 3 4 26 23 22";
temparray[it++] = "3 4 8 7 9";
temparray[it++] = "6 9 11 34 32 8 ";
temparray[it++] = "4 6 7 32 29 28";
temparray[it++] = "12 10 11 7 6";
temparray[it++] = "9 12 14 40 38 11";
temparray[it++] = "7 9 10 38 35 34";
temparray[it++] = "9 10 14 13 0";
temparray[it++] = "0 2 16 44 14 12";
temparray[it++] = "10 12 13 44 41 40";
temparray[it++] = "17 16 42";
temparray[it++] = "2 17 15 42 44 13";
temparray[it++] = "15 16 2 20 19";
temparray[it++] = "19 20 22 21";
temparray[it++] = "17 20 18";
temparray[it++] = "1 22 18 19 17 2 ";
temparray[it++] = "18 22 23";
temparray[it++] = "1 5 23 21 18 20";
temparray[it++] = "21 22 5 26 25";
temparray[it++] = "25 26 28 27";
temparray[it++] = "23 26 24";
temparray[it++] = "5 4 28 24 25 23";
temparray[it++] = "24 28 29";
temparray[it++] = "24 26 4 8 29 27";
temparray[it++] = "27 28 8 32 31";
temparray[it++] = "31 32 34 33";
temparray[it++] = "29 32 30";
temparray[it++] = "31 29 8 7 34 30";
temparray[it++] = "30 34 35";
temparray[it++] = "30 32 7 11 35 33";
temparray[it++] = "33 34 11 38 37";
temparray[it++] = "37 38 40 39";
temparray[it++] = "35 38 36";
temparray[it++] = "11 10 40 36 37 35";
temparray[it++] = "36 40 41";
temparray[it++] = "10 14 41 39 36 38";
temparray[it++] = "39 40 14 44 43";
temparray[it++] = "43 44 16 15";
temparray[it++] = "41 44 42";
temparray[it++] = "13 16 42 43 41 14";
for(int i=0 ; i<NCrystals ; i++) {
TObjArray *arr = temparray[i].ReplaceAll("\t"," ").Tokenize(" ");
for(int j=0 ; j<arr->GetEntries() ; j++)
{
for(int j=0 ; j<arr->GetEntries() ; j++) {
Int_t det = ((TString)arr->At(j)->GetName()).Atoi();
TString name = Form("%.2d:%.2d",i,det);
fAreNeighbours[name] = true;
......@@ -164,48 +510,41 @@ void TB_AGATA_Builder::InitTree()
}
void TB_AGATA_Builder::Process(Int_t idet)
void TB_AGATA_Builder_PSA::Process(Int_t idet)
{
Log.ClearMessage();
Log.GetProcessName() = "TB_AGATA_Builder";
Log.SetProcessMethod("Process()");
Log.SetProcessMethod(Form("Process(%d)",idet));
if(fNoMergerMode)
fCompFrame = (AgataCompositeFrame*) fTrigger->GetInputSharedFP()->GetFrame();
if(!fMergerMode)
fCompFrame = dynamic_cast<AgataCompositeFrame*>(fTrigger->GetInputSharedFP()->GetFrame());
else
fCompFrame = (AgataCompositeFrame*) fTrigger->GetInputSharedFP(idet+1)->GetFrame();
fCompFrame = dynamic_cast<AgataCompositeFrame*>(fTrigger->GetInputSharedFP(idet+1)->GetFrame());
fCompFrame->Scan();
TSHit = ((AgataKey *)fCompFrame->GetKey())->GetTimeStamp();
TSHit = dynamic_cast<AgataKey*>(fCompFrame->GetKey())->GetTimeStamp();
Double_t xLocal, yLocal, zLocal, xGlobal, yGlobal, zGlobal;
nbCores = fCompFrame->GetNbSubFrame();
// cout<<"builder "<<TSHit<<" "<<nbCores<<endl;
Float_t MaxE[nbCores];
Float_t coreX[nbCores];
Float_t coreY[nbCores];
Float_t coreZ[nbCores];
memset(MaxE, 0., sizeof(MaxE));
memset(coreX, 0., sizeof(coreX));
memset(coreY, 0., sizeof(coreY));
memset(coreZ, 0., sizeof(coreZ));
for(auto i=0 ;i<nbCores ; i++) {
MaxESeg.at(i) = 0;
MaxCoreX.at(i) = 0;
MaxCoreY.at(i) = 0;