32 #include "TObjArray.h"
39 #include "TEntryList.h"
41 #include "TChainElement.h"
48 #include "BashColor.h"
63 fEndOfFrame(
"EndOfFrame"),
64 fFrameEventPsa_Out(NULL),
66 fTrigger(
"event:data:psa"),
73 fDataChain(new TChain(
"TreeMaster",
"TreeMaster")),
76 IsADHitTreeModeOn(false),
78 fProcessPacking(true),
79 fSpatialResolution(5.),
80 fApplyEnergyResolution(true),
83 if(fdebug) std::cout<<
"\E[31;1m"<<
"Construct in"<<
"\E[m"<<
std::endl;
90 fSourceOfFrames.
SetModeIO(ConfAgent::kRead);
97 if(fdebug) std::cout<<
"\E[31;1m"<<
"Construct out"<<
"\E[m"<<
std::endl;
113 NarvalInterface::process_config(directory_path,error_code);
115 if ( (*error_code) == 0u ) {
123 if(fdebug) std::cout<<
"\E[31;1m"<<
"ProcessBlock in"<<
"\E[m"<<
std::endl;
149 unsigned int EventLenght = frame_out->
GetLength();
154 cout<<
"EventLenght = "<<EventLenght<<
endl;
159 if(out.
Reserve(EventLenght,
true))
182 if(fdebug) std::cout<<
"\E[31;1m"<<
"ProcessBlock out"<<
"\E[m"<<
std::endl;
183 if (
GetFrameIO().GetStatus() == BaseFrameIO::kFinished)
return 1u;
191 if(fdebug) std::cout<<
"\E[31;1m"<<
"process_initialise in"<<
"\E[m"<<
std::endl;
197 conffile +=
"StogsAFP.conf";
219 gROOT->ProcessLine(
".qqqqqqqqqqqqqqqq");
234 if(fdebug) std::cout<<
"\E[31;1m"<<
"process_initialise out"<<
"\E[m"<<
std::endl;
253 TList *ListOfRootFiles;
254 ListOfRootFiles =
new TList();
256 TString TreeName =
"TreeMaster";
260 std::ifstream filein(ConfFilePath);
261 if ( filein.is_open())
266 while ( filein.good() && !filein.eof() )
268 getline(filein,Line);
271 if(Buffer.BeginsWith(
"#"))
continue;
272 if(Buffer.BeginsWith(
"b") || Buffer.BeginsWith(
"r"))
274 TObjArray *TokenArray = Buffer.Tokenize(
" ");
276 if(Buffer.BeginsWith(
"b") && TokenArray->GetEntries() != 4)
continue;
277 if(Buffer.BeginsWith(
"r") && TokenArray->GetEntries() != 5)
continue;
279 TString Path = TokenArray->At(1)->GetName();
280 if(!Path.EndsWith(
"/")) Path.Append(
"/");
281 TString BaseName = TokenArray->At(2)->GetName();
282 int FirstFileNbr = ((TString)TokenArray->At(3)->GetName()).Atoi();
283 int LastFileNbr = FirstFileNbr+1;
284 if(Buffer.BeginsWith(
"r")) LastFileNbr = ((TString)TokenArray->At(4)->GetName()).Atoi();
286 TString FileName = Form(
"%s%s_%.4d.root",Path.Data(),BaseName.Data(),FirstFileNbr);
289 while(gSystem->IsFileInIncludePath(FileName) && FirstFileNbr<=LastFileNbr)
291 TFile *f = TFile::Open(FileName);
292 ListOfRootFiles->Add(f);
293 FileName = Form(
"%s%s_%.4d.root",Path.Data(),BaseName.Data(),++FirstFileNbr);
295 if(Buffer.BeginsWith(
"b")) LastFileNbr++;
300 cout<<
"File "<<FileName<<
" not found !"<<
endl;
304 if(Buffer.BeginsWith(
"l"))
306 TObjArray *TokenArray = Buffer.Tokenize(
" ");
308 if(TokenArray->GetEntries() != 2)
continue;
310 TString FileName = TokenArray->Last()->GetName();
312 TFile *f = TFile::Open(FileName);
313 if(gSystem->IsFileInIncludePath(FileName)) ListOfRootFiles->Add(f);
317 cout<<
"File "<<FileName<<
" not found !"<<
endl;
321 if(Buffer.BeginsWith(
"el"))
323 TObjArray *TokenArray = Buffer.Tokenize(
" ");
324 int TokenSize = TokenArray->GetEntries();
325 if(TokenSize != 2 && TokenSize != 3)
continue;
327 TString EntryListName =
"";
328 TEntryList *EntryList = 0x0;
330 TString FileName = ((TString)TokenArray->At(1)->GetName());
331 TFile *f = TFile::Open(FileName);
332 if(!gSystem->IsFileInIncludePath(FileName))
335 cout<<
"File "<<FileName<<
" not found !"<<
endl;
342 EntryListName = TokenArray->Last()->GetName();
343 EntryList = (TEntryList*)f->Get(EntryListName)->Clone();
347 cout<<
"EntryList "<<EntryListName<<
" not found in file "<<FileName<<
"!"<<
endl;
354 TList *ListOfKeys = f->GetListOfKeys();
356 for(
int i=0 ; i<ListOfKeys->GetSize() ; i++)
358 TKey *key = (TKey*)ListOfKeys->At(i);
360 if((TString)key->GetClassName()==
"TEntryList")
362 EntryList = (TEntryList*)f->Get(key->GetName())->Clone();
368 cout<<
"No EntryList found in file "<<FileName<<
"!"<<
endl;
377 EntryList->SetDirectory(0);
381 cout<<
"EntryList "<<EntryList->GetName()<<
" loaded for file "<<EntryList->GetFileName()<<
endl;
384 if(Buffer.BeginsWith(
"n"))
386 TObjArray *TokenArray = Buffer.Tokenize(
" ");
387 if(TokenArray->GetEntries() != 2)
390 std::cout<<
"The TTree name has not been undestood..."<<
std::endl;
394 TreeName = TokenArray->Last()->GetName();
402 std::cout<<ConfFilePath<<
" not found !"<<
std::endl;
403 gROOT->ProcessLine(
".qqqqqqqqqqqqqqqqq");
408 for(
int i=0 ; i<ListOfRootFiles->GetSize() ; i++)
410 TFile *f = (TFile*)ListOfRootFiles->At(i);
415 gErrorIgnoreLevel = kFatal;
419 TObjArray *fFiles =
fDataChain->GetListOfFiles();
420 Int_t ne = fFiles->GetEntries();
422 TString treename, filename;
424 TEntryList *templist = 0;
425 for (Int_t ie = 0; ie<ne; ie++){
426 treename = gSystem->BaseName( ((TChainElement*)fFiles->UncheckedAt(ie))->GetName() );
427 filename = ((TChainElement*)fFiles->UncheckedAt(ie))->GetTitle();
428 templist =
fEntryList->GetEntryList(treename.Data(), filename.Data());
431 TString BaseFilename = gSystem->BaseName(filename);
432 templist =
fEntryList->GetEntryList(treename.Data(), BaseFilename.Data());
433 if(templist) templist->SetFileName(filename);
435 if (templist) listfound++;
441 cout<<
"The selected EntryLists are not compatible with input TTrees, EntryList ignored."<<
endl;
452 gErrorIgnoreLevel = kPrint;
461 fDataChain->SetBranchAddress(
"nbHits", &NbHits);
471 fDataChain->SetBranchAddress(
"nbCores", &NbCores);
472 fDataChain->SetBranchAddress(
"coreE0", CoreE0);
473 fDataChain->SetBranchAddress(
"coreE1", CoreE1);
474 fDataChain->SetBranchAddress(
"coreT0", CoreT0);
475 fDataChain->SetBranchAddress(
"coreT1", CoreT1);
476 fDataChain->SetBranchAddress(
"hit_per_cryst", NbHitsPerCrystal);
478 fDataChain->SetBranchAddress(
"TSHit", &fTimestamp);
482 for(
int i=0 ; i<MaxHits ; i++)
497 NbHitsPerCrystal[i]=0;
507 fDataChain->SetBranchAddress(
"Ev.", &fStogsEv);
537 TString GlobMessType = AgataKeyFactory::theFactory()->GetMessage(((
AgataKey*)frame_out->
GetKey())->GetMessage());
540 cout<<
"New Main frame: "<<GlobMessType<<
endl;
543 cout<<
" --Number of total hits: "<<NbHits<<
" in "<<NbCores<<
" core"<<
endl;
548 for(
int icore=0 ; icore< NbCores ; icore++)
556 PSAInterface *data_out = GetDataPointer<PSAInterface>(PSAFrame);
557 data_out->
SetE(CoreE0[icore],0);
558 data_out->
SetE(CoreE1[icore],1);
559 data_out->
SetT(CoreT0[icore],0);
560 data_out->
SetT(CoreT1[icore],1);
561 data_out->
SetUID(HitId[hit]);
565 TString MessageType = AgataKeyFactory::theFactory()->GetMessage(((
AgataKey*)PSAFrame->
GetKey())->GetMessage());
567 cout<<
" New subframe: "<<MessageType<<
endl;
568 cout<<
" --CoreID: "<<HitId[hit]<<
" ==> E0 = "<<CoreE0[icore]<<
", T0 = "<<CoreT0[icore]<<
endl;
569 cout<<
" --Number of crystal hits: "<<NbHitsPerCrystal[icore]<<
endl;
574 for(
int iseg=0 ; iseg<NbHitsPerCrystal[icore] ; iseg++)
578 pOut->
SetXYZ(HitX[hit],HitY[hit],HitZ[hit]);
579 pOut->
SetE(HitE[hit]);
580 pOut->
SetID(HitSg[hit],0);
581 pOut->
SetID(HitId[hit],1);
586 cout<<
" hit nb: "<<iseg<<
" : E = "<<HitE[hit]<<
", SegID = "<<HitId[hit]<<
", SegNbr = "<<HitSg[hit]<<
", (X,Y,Z): ("<<HitX[hit]<<
","<<HitY[hit]<<
","<<HitZ[hit]<<
")"<<
endl;
600 cout<<
" ==> Number of subframes in the global frame: "<<frame_out->
GetNbSubFrame()<<
endl;
602 cout<<
"_____________________________________________"<<
endl<<
endl;
629 if(!test.EqualTo(
"y",TString::kIgnoreCase))
return false;
633 SBREvent *PackingEvt = FilteredEvent;
653 cout<<
"*** New Event : NbHits = "<<NbHits<<
endl;
667 PSAInterface *data_out = GetDataPointer<PSAInterface>(PSAFrame);
671 int CoreId = a_hit->
fUID;
679 int nHitsPerCrystal = 0;
682 while(( hit<NbHits ) && ( a_hit->fUID == CoreId ))
684 if(nHitsPerCrystal ==100)
break;
687 pOut->
SetXYZ(a_hit->fX,a_hit->fY,a_hit->fZ);
688 double ahitE = a_hit->fE;
692 pOut->
SetID(CoreId,1);
694 if(fdebug || ahitE<=0)
698 cout<<
" hit nb: "<<nHitsPerCrystal<<
" : E = "<<a_hit->fE<<
", SegID = "<<a_hit->fUID<<
", (X,Y,Z): ("<<a_hit->fX<<
","<<a_hit->fY<<
","<<a_hit->fZ<<
")"<<
endl;
705 a_hit = PackingEvt->
GetHit(hit);
708 data_out->
SetE(CoreE,0);
716 int FrameSize = PSAFrame->
Write();
727 TString MessageType = AgataKeyFactory::theFactory()->GetMessage(((
AgataKey*)PSAFrame->
GetKey())->GetMessage());
729 cout<<
" New subframe: "<<MessageType<<
endl;
730 cout<<
" --CoreID: "<<CoreId<<
" ==> E0 = "<<CoreE<<
endl;
731 cout<<
" --Number of crystal hits: "<<nHitsPerCrystal<<
endl;
737 delete FilteredEvent;
741 TString GlobMessType = AgataKeyFactory::theFactory()->GetMessage(((
AgataKey*)frame_out->
GetKey())->GetMessage());
744 cout<<
"New Main frame: "<<GlobMessType<<
endl;
747 cout<<
" --Number of total hits: "<<NbHits<<
" in "<<nbCores<<
" core"<<
endl;
749 cout<<
" ==> Number of subframes in the global frame: "<<frame_out->
GetNbSubFrame()<<
endl;
751 cout<<
"_____________________________________________"<<endl<<
endl;
755 if(NbHits==0)
return false;
769 std::cout<<
"Number of good events : "<<fNEvts<<
std::endl;
773 std::cout<<
"********************************************"<<
std::endl;
781 ListOfHits =
new TList();
782 TList *ListOfPackedHits;
783 ListOfPackedHits =
new TList();
787 for(
int i=0 ; i<NbHits ; i++)
792 a_hit->
fX = a_hit->
fX*10.;
793 a_hit->
fY = a_hit->
fY*10.;
794 a_hit->
fZ = a_hit->
fZ*10.;
797 a_hit->
fE = a_hit->
fE*1e3;
800 if(a_hit->
fE > 1e5) cout<<
"Warning !!! E = "<<a_hit->
fE<<
" keV, initial energies should be already in keV ?!"<<
endl;
801 if(TMath::Abs(a_hit->
fZ) > 1000.) cout<<
"Warning !!! Z = "<<a_hit->
fZ<<
" mm, initial distances should be already in mm ?!"<<
endl;
804 ListOfHits->Add(a_hit);
807 while(ListOfHits->GetSize())
812 for(
int i=0 ; i<ListOfHits->GetSize() ; i++)
815 if(PackedHit == 0x0) PackedHit = a_hit;
816 else if(a_hit->
fE > PackedHit->
fE) PackedHit = a_hit;
820 ListOfHits->Remove(PackedHit);
821 ListOfPackedHits->Add(PackedHit);
823 TVector3 PackedHitPosPond(PackedHit->
fX*PackedHit->
fE,PackedHit->
fY*PackedHit->
fE,PackedHit->
fZ*PackedHit->
fE);
824 double PondFactor = PackedHit->
fE;
826 TVector3 PackedHitPos(PackedHit->
fX,PackedHit->
fY,PackedHit->
fZ);
829 for(
int i=0 ; i<ListOfHits->GetSize() ; i++)
832 TVector3 HitPos(a_hit->
fX,a_hit->
fY,a_hit->
fZ);
834 TVector3 Diff = HitPos-PackedHitPos;
836 double distance = Diff.Mag();
840 TVector3 HitPosPond(a_hit->
fX*a_hit->
fE,a_hit->
fY*a_hit->
fE,a_hit->
fZ*a_hit->
fE);
841 PackedHitPosPond += HitPosPond;
842 PackedHit->
fE = PackedHit->
fE + a_hit->
fE;
843 PondFactor += a_hit->
fE;
845 ListOfHits->Remove(a_hit);
850 PackedHitPosPond = PackedHitPosPond*(1./PondFactor);
851 PackedHit->
fX = PackedHitPosPond.x();
852 PackedHit->
fY = PackedHitPosPond.y();
853 PackedHit->
fZ = PackedHitPosPond.z();
859 for(
int i=0 ; i<ListOfPackedHits->GetSize() ; i++)
866 delete ListOfPackedHits;
875 for(
int i=0 ; i<NbHits ; i++)
879 double Ener = a_hit->
fE;
881 double WFHM = (2.1-1.2)/(1333.-60.)*(Ener-1333.)+2.1;
882 double sigma = WFHM/sqrt(8.*log(2.));
884 Ener = TMath::Abs(gRandom->Gaus(Ener,sigma));
894 for(
int i=0 ; i<NbHits ; i++)
910 ListOfHits =
new TList();
912 TList *ListOfOrderedHits;
913 ListOfOrderedHits =
new TList();
917 for(
int i=0 ; i<NbHits ; i++)
920 if(a_hit->
fUID < 180) ListOfHits->Add(a_hit);
924 while(ListOfHits->GetSize())
927 int firstUID = FirstHit->
fUID;
928 ListOfOrderedHits->Add(FirstHit);
929 ListOfHits->Remove(FirstHit);
931 for(
int i=0 ; i<ListOfHits->GetSize() ; i++)
935 if(a_hit->
fUID == firstUID)
937 ListOfOrderedHits->Add(a_hit);
938 ListOfHits->Remove(a_hit);
947 for(
int i=0 ; i<ListOfOrderedHits->GetSize() ; i++)
950 FilterdEvent->
AddHit(a_hit);
954 delete ListOfOrderedHits;
void InitDataChainADHitTree()
******************************************************************************************/// ...
virtual UInt_t GetLength() const
total length for that frame
virtual Key * GetKey()=0
To get the Key associated to this frame.
virtual void Reset()
Reset the current frame.
virtual Frame * GetFrame() const
SBREvent * ProcessPacking(SBREvent *StogsEvt)
bool ReadEventADHitTree()
******************************************************************************************/// ...
It defines the interface needed to be a narval actor (producer).
header file for AgataFrameFactory.cpp
LogMessage & error(LogMessage &)
void InitDataChainStogs()
******************************************************************************************/// ...
virtual Key * GetKey()
To get the Key associated to this frame.
virtual void SetModeIO(ConfAgent::EMode mode)
void ApplyEnergyResolution(SBREvent *StogsEvt)
void SetModel(ConfAgent::EModel model)
static ConfAgent * theGlobalAgent(std::string="Agata")
to get the global agent
bool ReadEventStogs()
******************************************************************************************/// ...
SBRHit * AddHit()
add a hit to the current event
void Fired(Bool_t b=true)
Fired (default) or not this trigger.
ADF::SharedFP * fFrameEventPsa_Out
SBREvent * FilterEvent(SBREvent *GlobEvt)
virtual Bool_t Register(DFTrigger *)
To register a trigger.
ADF::SharedFP * fSPSAFrame
virtual Bool_t AddSubFrame(const Frame &)
Add a subframe to that frame (only if composite)
unsigned int fRejectedEvents
virtual void SetUID(Int_t)=0
to set the crystal ID
virtual void process_reset(unsigned int *error_code)
Destructor implementation.
header file for PSAFrame.cpp
double fSpatialResolution
virtual void SetE(Double_t, UInt_t=0u)=0
to set the energy associated to the core
const std::string & GetConfPath()
To get the algo path associated with the current actor.
Base class for a CompositeFrame.
virtual SharedFP * SetOutputFrame(Frame *frame)
Once a trigger has fired, the result of the algorithm is set through this.
header file for BufferIO.cpp
virtual void Detach(FrameBlock *in, FrameBlock *out)
UInt_t FreeSize() const
it returns the number of free bytes to the end
bool ReadConfFile(TString ConfFilePath)
******************************************************************************************/// ...
virtual void SetE(Double_t e)
void SetStatus(EStatus stat)
virtual void SetProcessMethod(const char *)
To set the current method.
header file for AgataKeyFactory.cpp
LogMessage & dolog(LogMessage &)
virtual UInt_t Write()
It writes to the Frame the content of the dedicated structures.
static void process_config(const char *, unsigned int *)
to init globals (static) from a directory
SBRHit * GetHit(Int_t)
to get a Hit
virtual BufferIO * GetBufferIO(UInt_t which=0u)=0
To get the address of the underlying buffer.
virtual void ClearMessage()
To clear the current message.
virtual void Clear(Option_t *opt)
clear the collection of hits, set H, K to 0
virtual void SetXYZ(Double_t x, Double_t y, Double_t z)
virtual Hit * NewHit()=0
Add a NewHit to the stack of Hits associated to this PSAFrame.
virtual Bool_t Record(DFTrigger *)
To record a frame trigger.
virtual void Reset()=0
Reset the current frame.
bool fApplyEnergyResolution
ADF::AgataFrameTrigger fTrigger
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual void process_initialise(unsigned int *error_code)
Constructor implementation.
virtual void SetT(Double_t, UInt_t=0u)=0
to set the time associated to the core
virtual void SetID(Int_t id, Int_t which_id=0)
set crystal/segment id. if which_id > 0, set crystal ID.
void ApplySmearing(SBREvent *StogsEvt)
virtual ~StogsAFP()
******************************************************************************************/// ...
virtual Bool_t Reserve(UInt_t, Bool_t=false, UInt_t=0u)
Reserve the given size for writing.
virtual void Print(std::ostream &out=std::cout) const
Print some informations (statistics)
virtual void Attach(FrameBlock *in, FrameBlock *out)
Attach a block to this. Rewind called if DoRewind set to true (Default)
Int_t GetNbHits() const
helper function
virtual SharedFP * AddUtility(const FactoryItem &key_item, const FactoryItem &frame_item, const ConfAgent *agent)
Add utilities, used to decode/encode composite frames.
virtual unsigned int ProcessBlock(ADF::FrameBlock &)
Produce one block of data.
virtual std::string & GetProcessName()
To get the Process name.
LogMessage Log
to send messages to the log server
virtual void SetName(const char *name)
virtual UInt_t GetNbSubFrame() const
Returns the number of sub-frames composing this frame. Scan have to be called first.