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);
......
This diff is collapsed.
......@@ -21,15 +21,139 @@
#ifndef _TB_AGATA
#define _TB_AGATA
#include "AGAPRO_TB_Detector.h"
#include "CrystalFrame.h"
class TGeoCombiTrans;
#include "AGAPRO_TB_Detector.h"
namespace AGAPRO {
/// ****** CRYSTAL ******///
class TB_AGATA_CRYSTAL : public TB_Detector
{
protected:
static const int kNCC = ADF::CrystalInterface::kNbCores;
static const int kNSG = ADF::CrystalInterface::kNbSegments;
static const int kMaxTraceLenght = 100;
static const int kCrystalTraceLenght = 100;
static const int kCCrystalTraceLenght = 60;
private:
Float_t SegTraces[kNSG*kMaxTraceLenght];
UShort_t SegTracesu[kNSG*kMaxTraceLenght];
Float_t CoreTraces[kNCC*kMaxTraceLenght];
UShort_t CoreTracesu[kNCC*kMaxTraceLenght];
Float_t SegE[kNSG];
Float_t CoreE[kNCC];
ULong64_t crystalId;
ULong64_t crystalTS;
UInt_t fTraceLenght;
bool WarnedDone = false;
public:
TB_AGATA_CRYSTAL(TString name="", TString ADFKey="");
virtual ~TB_AGATA_CRYSTAL();
void Init();
void InitValues();
void InitTree();
void Process(Int_t idet);
};
/// ****** PSA ******///
class TB_AGATA_PSA : public TB_Detector
{
protected:
static const Int_t MaxHits = 36; // Max number of hits in one event
Int_t nbHits; // Number of hits in the crystal
Float_t hitE[MaxHits]; // Energie of the hit
Float_t hitX[MaxHits]; // X position of the hit in the Crystal Frame
Float_t hitY[MaxHits]; // Y position of the hit in the Crystal Frame
Float_t hitZ[MaxHits]; // Z position of the hit in the Crystal Frame
Float_t hitGX[MaxHits]; // Position x of hit with , in global frame
Float_t hitGY[MaxHits]; // Position y of hit with , in global frame
Float_t hitGZ[MaxHits]; // Position z of hit with , in global frame
Int_t hitSg[MaxHits]; // Crystal ID in which a hit occurs
Int_t coreId; // crystal ID
Float_t coreE0; // Core energy, high gain
Float_t coreE1; // Core energy, low gain
Float_t coreT0; // Core time, high gain
Float_t coreT1; // Core time, low gain
ULong64_t coreTS;
public:
TB_AGATA_PSA(TString name="", TString ADFKey="");
virtual ~TB_AGATA_PSA();
void Init();
void InitValues();
void InitTree();
void Process(Int_t idet);
};
/// ****** Builder ******///
class TB_AGATA_Builder : public TB_Detector
class TB_AGATA_Builder_CRYSTAL : public TB_Detector
{
protected:
static const int kNCC = ADF::CrystalInterface::kNbCores;
static const int kNSG = ADF::CrystalInterface::kNbSegments;
static const int kMaxTraceLenght = 100;
static const int kCrystalTraceLenght = 100;
static const int kCCrystalTraceLenght = 60;
protected:
static const Int_t MaxCore = 180; // Max number of cores in one event
Int_t nbCrystals; // for more than 1 frame (built event)
Int_t crystalId[MaxCore]; // for each crystal fired its ID
ULong64_t crystalTS[MaxCore]; // timestamp of cores
Int_t SegTracesSize;
Float_t SegTraces[kNSG*kMaxTraceLenght*MaxCore];
UShort_t SegTracesu[kNSG*kMaxTraceLenght*MaxCore];
Int_t CoreTracesSize;
Float_t CoreTraces[kNCC*kMaxTraceLenght*MaxCore];
UShort_t CoreTracesu[kNCC*kMaxTraceLenght*MaxCore];
Int_t SegESize;
Float_t SegE[kNSG*MaxCore];
Int_t CoreESize;
Float_t CoreE[kNCC*MaxCore];
ULong64_t EvtCrystalTS;
UInt_t fTraceLenght;
bool WarnedDone = false;
public:
TB_AGATA_Builder_CRYSTAL(TString name="", TString ADFKey="");
virtual ~TB_AGATA_Builder_CRYSTAL();
void Init();
void InitValues();
void InitTree();
void Process(Int_t idet);
};
class TB_AGATA_Builder_PSA : public TB_Detector
{
struct core_property
{
......@@ -58,8 +182,8 @@ protected:
Float_t hitGX[MaxHits]; // Position x of hit with , in global frame
Float_t hitGY[MaxHits]; // Position y of hit with , in global frame
Float_t hitGZ[MaxHits]; // Position z of hit with , in global frame
Int_t hitId[MaxHits]; // Segment ID in which a hit occurs
Int_t hitSg[MaxHits]; // Crystal ID in which a hit occurs
Int_t hitId[MaxHits]; // Crystal ID in which a hit occurs
Int_t hitSg[MaxHits]; // Segment ID in which a hit occurs
Int_t nbCores; // for more than 1 frame (built event)
Int_t nbHitsperCry[MaxCore]; // nb of hits epr crystal
......@@ -68,6 +192,11 @@ protected:
Float_t coreE1[MaxCore]; // Core energy, low gain
Float_t coreT0[MaxCore]; // Core time, high gain
array<Float_t, MaxCore> MaxESeg; // Maximum segment energy in the core
array<Float_t, MaxCore> MaxCoreX; // X position of the max segment energy
array<Float_t, MaxCore> MaxCoreY; // Y position of the max segment energy
array<Float_t, MaxCore> MaxCoreZ; // Z position of the max segment energy
Int_t nbAdd; // Addback multiplicity
Int_t AddId[MaxCore]; // Addback crystal Id of the hit with highest energy
Float_t AddE[MaxCore]; // Addback energy
......@@ -79,11 +208,9 @@ protected:
ULong64_t AddTS[MaxCore]; // timestamp of he hit with highest energy
ULong64_t TSHit;
TObjArray* fMatrixList = nullptr;
public:
TB_AGATA_Builder(TString name="", TString ADFKey="");
virtual ~TB_AGATA_Builder();
TB_AGATA_Builder_PSA(TString name="", TString ADFKey="");
virtual ~TB_AGATA_Builder_PSA();
void Init();
void InitValues();
......@@ -91,10 +218,6 @@ public:
void Process(Int_t idet);
protected:
virtual TGeoCombiTrans* FillTransMatrix(Double_t* trans, Double_t* rot);
virtual void Local2Global(Int_t detID, Double_t xl, Double_t yl, Double_t zl, Double_t& xg, Double_t& yg, Double_t& zg);
virtual bool ReadTransformation();
static bool coreCompare(const core_property& firstElem, const core_property& secondElem) {
return firstElem.E > secondElem.E;
}
......
......@@ -39,7 +39,7 @@ TB_DIAMANT::~TB_DIAMANT()
void TB_DIAMANT::Init()
{
fFrame = fTrigger->AddUtility("data:ranc1",ConfAgent::theGlobalAgent());
fSFrame = fTrigger->AddUtility("data:ranc1",ConfAgent::theGlobalAgent());
fDIAMANTFrame = new MFMDiamantFrame();
LoadLUT();
......@@ -83,7 +83,7 @@ void TB_DIAMANT::Process(Int_t idet)
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("Process()");
Log.SetProcessMethod(Form("Process(%d)",idet));
fCompFrame = (ADF::AgataCompositeFrame*) fTrigger->GetInputSharedFP(idet+1)->GetFrame();
fCompFrame->Scan();
......@@ -101,9 +101,9 @@ void TB_DIAMANT::Process(Int_t idet)
for(Int_t i = 0u; i <nbDIAMANT; i++)
{
fCompFrame->LinkSubFrame(i,fFrame->GetFrame());
fFrame->GetFrame()->Read();
fDIAMANTFrame->SetAttributs(((ADF::RawFrame *)fFrame->GetFrame())->RawBuffer().Address());
fCompFrame->LinkSubFrame(i,fSFrame->GetFrame());
fSFrame->GetFrame()->Read();
fDIAMANTFrame->SetAttributs(((ADF::RawFrame *)fSFrame->GetFrame())->RawBuffer().Address());
DIAMANTBoardId[i] = fDIAMANTFrame->GetBoardId();
DIAMANTChannelId[i] = fDIAMANTFrame->GetTGCristalId() ;
......
......@@ -22,6 +22,8 @@
#include "AGAPRO_TB_Detector.h"
#endif
#include "TGeoMatrix.h"
using namespace AGAPRO;
TB_Detector::TB_Detector(TString name, TString ADFKey) :
......@@ -37,6 +39,125 @@ TB_Detector::~TB_Detector()
{
if(fCompFrame)
delete fCompFrame;
if(fFrame)
delete fFrame;
if(fSFrame)
delete fSFrame;
if(fMatrixList)
delete fMatrixList;
}
TGeoCombiTrans* TB_Detector::FillTransMatrix(Double_t* trans, Double_t* rot)
{
TGeoRotation rotation; rotation.SetMatrix(rot);
TGeoTranslation translation;
translation.SetTranslation(trans[0], trans[1], trans[2]);
return new TGeoCombiTrans(translation, rotation);
}
void TB_Detector::Local2Global(Int_t detID,
Double_t xl, Double_t yl, Double_t zl,
Double_t& xg, Double_t& yg, Double_t& zg)
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("Local2Global()");
Double_t local[3] = {xl, yl, zl};
Double_t global[3] = {0., 0., 0.};
if (detID < 0 || detID > 180) {
Log << error << "Wrong detector id number" << dolog;
return;
}
if(fMatrixList) {
TGeoCombiTrans* mat = static_cast<TGeoCombiTrans*> ( fMatrixList->At(detID) );
mat->LocalToMaster(local, global);
}
xg = global[0];
yg = global[1];
zg = global[2];
}
bool TB_Detector::ReadTransformation()
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("ReadTransformation()");
Log << info << " Ge positions extracted from CrystalPositionLookUpTable " << nline;
TString FileName = fConfPath + "/CrystalPositionLookUpTable";
ifstream in(FileName, ios::in);
if (!in) {
Log << error << Form("file %s not found\n", FileName.Data()) << dolog;
return false;
}
fMatrixList = new TObjArray(180);
fMatrixList->SetOwner();
Int_t nd, k;
Double_t x,y,z;
Double_t trans[3];
Double_t rot[9];
Char_t line[255];
while ( !in.eof() ) {
in.getline(line,255);
if((((TString)line)==""))
continue;
if(sscanf(line, "%d %d %lf %lf %lf", &nd, &k, &x, &y, &z) != 5) {
Log << error << "a Problem reading translation factors" << dolog;
cin.get();
return false;
}
trans[0] = x; trans[1] = y, trans[2] = z;
if (nd > 180) {
Log << error << Form("Id %d too large, max: %d\n", nd, 180) << dolog;
return false;
}
in.getline(line,255);
if(sscanf(line, "%d %lf %lf %lf", &k, &x, &y, &z) != 4) {
Log << error << Form("b Problem reading 1st rotation factors for id %d\n", nd) << dolog;
return false;
}
rot[0] = x; rot[1] = y; rot[2] = z;
in.getline(line,255);
if(sscanf(line, "%d %lf %lf %lf", &k, &x, &y, &z) != 4) {
Log << error << Form("c Problem reading 2nd rotation factors for id %d\n", nd) << dolog;
return false;
}
rot[3] = x; rot[4] = y; rot[5] = z;
in.getline(line,255);
if(sscanf(line, "%d %lf %lf %lf", &k, &x, &y, &z) != 4) {
Log << error << Form("d Problem reading 3rd rotation factors for id %d\n", nd) << dolog;
return false;
}
rot[6] = x; rot[7] = y; rot[8] = z;
// add matrix for the given id
if (fMatrixList->At(nd)) {
Log << error << Form("Matrix transformation already exist for id %d\n", nd) << dolog;
return false;
} else
fMatrixList->AddAt( FillTransMatrix(trans, rot), nd );
}
in.close( );
Log << dolog;
}
......@@ -37,10 +37,16 @@
using namespace std;
using namespace ADF;
class TGeoCombiTrans;
namespace AGAPRO {
class TB_Detector
{
protected:
enum kType { crystal, ccrystal, psa, ppsa, undef };
kType fType;
public:
std::string gMotherClass = "TB_Detector";
std::string gActualClass;
......@@ -57,13 +63,15 @@ protected:
Bool_t fIsTriggered = false;
AgataFrameTrigger *fTrigger = nullptr;
AgataCompositeFrame *fCompFrame = nullptr;
SharedFP *fFrame = nullptr;
SharedFP *fSFrame = nullptr;
Frame *fFrame = nullptr;
TTree *fTree = nullptr;
bool fNoMergerMode = false;
bool fMergerMode = true;
TObjArray* fMatrixList = nullptr;
public:
TB_Detector(TString name="", TString ADFKey="");
......@@ -95,8 +103,13 @@ public:
void SetTriggered(Bool_t ok){fIsTriggered = ok;}
Bool_t IsTriggered(){return fIsTriggered;}
void SetNoMergerMode(Bool_t mode){fNoMergerMode = mode;}
Bool_t GetNoMergerMode(){return fNoMergerMode;}
void SetMergerMode(Bool_t mode){fMergerMode = mode;}
Bool_t GetMergerMode(){return fMergerMode;}
protected:
virtual TGeoCombiTrans* FillTransMatrix(Double_t* trans, Double_t* rot);
virtual void Local2Global(Int_t detID, Double_t xl, Double_t yl, Double_t zl, Double_t& xg, Double_t& yg, Double_t& zg);
virtual bool ReadTransformation();
};
}
......
......@@ -39,7 +39,7 @@ TB_NEDA::~TB_NEDA()
void TB_NEDA::Init()
{
fFrame = fTrigger->AddUtility("data:ranc0",ConfAgent::theGlobalAgent());
fSFrame = fTrigger->AddUtility("data:ranc0",ConfAgent::theGlobalAgent());
fNEDAFrame = new MFMNedaCompFrame();
LoadLUT();
......@@ -87,7 +87,7 @@ void TB_NEDA::Process(Int_t idet)
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("Process()");
Log.SetProcessMethod(Form("Process(%d)",idet));
fCompFrame = (ADF::AgataCompositeFrame*) fTrigger->GetInputSharedFP(idet+1)->GetFrame();
fCompFrame->Scan();
......@@ -105,9 +105,9 @@ void TB_NEDA::Process(Int_t idet)
for(Int_t i = 0u; i <nbNEDA; i++)
{
fCompFrame->LinkSubFrame(i,fFrame->GetFrame());
fFrame->GetFrame()->Read();
fNEDAFrame->SetAttributs(((ADF::RawFrame *)fFrame->GetFrame())->RawBuffer().Address());
fCompFrame->LinkSubFrame(i,fSFrame->GetFrame());
fSFrame->GetFrame()->Read();
fNEDAFrame->SetAttributs(((ADF::RawFrame *)fSFrame->GetFrame())->RawBuffer().Address());
NEDABoardId[i] = fNEDAFrame->GetBoardId();
NEDAChannelId[i] = fNEDAFrame->GetChannelId() ;
......
......@@ -48,7 +48,7 @@ TB_VAMOS::~TB_VAMOS()
void TB_VAMOS::Init()
{
fFrame = fTrigger->AddUtility("data:ranc0",ConfAgent::theGlobalAgent());
fSFrame = fTrigger->AddUtility("data:ranc0",ConfAgent::theGlobalAgent());
fMFMMergeFrame = new MFMMergeFrame();
fMFMCommonFrame = new MFMCommonFrame();
fMFMEBYFrame = new MFMEbyedatFrame();
......@@ -132,15 +132,15 @@ void TB_VAMOS::Process(Int_t idet)
{
Log.ClearMessage();
Log.GetProcessName() = gActualClass;
Log.SetProcessMethod("Process()");
Log.SetProcessMethod(Form("Process(%d)",idet));
if(fAnalysis == nullptr)
return;
fFrame = fTrigger->GetInputSharedFP(idet+1);
fFrame->GetFrame()->Read();
fSFrame = fTrigger->GetInputSharedFP(idet+1);
fSFrame->GetFrame()->Read();
fMFMCommonFrame->SetAttributs(((ADF::RawFrame *)fFrame->GetFrame())->RawBuffer().Address());
fMFMCommonFrame->SetAttributs(((ADF::RawFrame *)fSFrame->GetFrame())->RawBuffer().Address());
fAnalysis->UnPack(fMFMCommonFrame);
fAnalysis->Treat();
......
......@@ -47,11 +47,7 @@ using namespace AGAPRO;
string TreeBuilder::gMotherClass = "TreeBuilder";
string TreeBuilder::gActualClass;
TreeBuilder::TreeBuilder() :
NarvalConsumer()
{
}
TreeBuilder::TreeBuilder() = default;
TreeBuilder::~TreeBuilder()
{
......@@ -67,11 +63,10 @@ TreeBuilder::~TreeBuilder()
fFile->Close();
// in principle not needed ... just in case reset it has not been called by narval
UInt_t error = 0u; process_reset(&error) ;
UInt_t error = 0; process_reset(&error) ;
}
for(int idet=0 ; idet<fListOfDets.size() ; idet++){
TB_Detector *det = fListOfDets[idet];
for(auto det : fListOfDets){
delete det;
}
}
......@@ -129,11 +124,7 @@ void TreeBuilder::process_initialise (UInt_t *error_code)
cServer.Start(gActualClass);
for(int idet=0 ; idet<fListOfDets.size() ; idet++) {
TB_Detector *det = fListOfDets[idet];
det->Init();
}
for(auto det: fListOfDets) det->Init();
NewTree();
......@@ -170,11 +161,10 @@ void TreeBuilder::process_stop (UInt_t *error_code)
Int_t TreeBuilder::SetInput()
{
if(fNoMergerMode == false) {
if(fMergerMode) {
fAgataComposite = dynamic_cast< AgataCompositeFrame *> ( fTrigger->GetInputFrame() );
fAgataComposite->Scan();
timestamp = ((AgataKey*)fAgataComposite->GetKey())->GetTimeStamp();
timestamp = dynamic_cast<AgataKey*>(fAgataComposite->GetKey())->GetTimeStamp();
}
// cout<<AgataKeyFactory::theFactory()->GetMessage(((AgataKey*)fAgataComposite->GetKey())->GetMessage())<<endl;
......@@ -186,12 +176,12 @@ Int_t TreeBuilder::SetInput()
// cout<<endl;
for(int idet=0 ; idet<fListOfDets.size() ; idet ++) {
for(size_t idet=0 ; idet<fListOfDets.size() ; idet ++) {
TB_Detector *det = fListOfDets[idet];
det->InitValues();
if(fNoMergerMode)
if(!fMergerMode)
det->SetTriggered(fTrigger->IsIndividualFired(0));
else
det->SetTriggered(fTrigger->IsIndividualFired(idet+1)); // +1 because the first value is for the global trigger
......@@ -203,7 +193,7 @@ Int_t TreeBuilder::SetInput()
UInt_t TreeBuilder::ProcessBlock(ADF::FrameBlock &inBlock)
{
// attach the input/output buffer to the FrameIO system
fFrameIO.Attach(&inBlock, 0x0);
fFrameIO.Attach(&inBlock, nullptr);
// start the processing
UInt_t error_code = 0;
......@@ -222,9 +212,9 @@ UInt_t TreeBuilder::ProcessBlock(ADF::FrameBlock &inBlock)
Log << error << " During : SetInput()" << dolog;
break;
}
else {
bool has_triggered = false;
for(int idet=0 ; idet<fListOfDets.size() ; idet ++) {
for(size_t idet=0 ; idet<fListOfDets.size() ; idet ++) {
TB_Detector *det = fListOfDets[idet];
if(det->IsTriggered()) {
has_triggered = true;
......@@ -234,7 +224,6 @@ UInt_t TreeBuilder::ProcessBlock(ADF::FrameBlock &inBlock)
if(has_triggered)
fTree->Fill();
}
nevs++;
fReadEvts++;
......@@ -244,7 +233,7 @@ UInt_t TreeBuilder::ProcessBlock(ADF::FrameBlock &inBlock)
}
}
fFrameIO.Detach(&inBlock, 0x0);
fFrameIO.Detach(&inBlock, nullptr);
cServer.Exec(timestamp, nevs);
......@@ -272,9 +261,9 @@ void TreeBuilder::NewTree()
if(fTree == nullptr) {
fTree = new TTree(fTreeName.data(),fTreeName.data());
for(int idet=0 ; idet < fListOfDets.size() ; idet++) {
fListOfDets[idet]->SetTree(fTree);
fListOfDets[idet]->InitTree();
for(auto &fListOfDets: fListOfDets) {