FEDRA emulsion software from the OPERA Collaboration
ShowRec_Alg_N3.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void N3_Create_ALG_MLP (TTree *inputtree, Int_t parasetnr)
 
void N3_Dump_ALG_MLP_weights (TMultiLayerPerceptron *mlp, Int_t parasetnr)
 
void N3_FindBestCompliments (EdbSegP *seg, EdbPattern *TestPattern, EdbPVRec *local_gAli, Int_t Downstream, Float_t &mindeltaZ, Float_t &mindT, Float_t &mindR, Float_t &mindMinDist, Int_t &nDifferentSegs)
 
void N3_Load_ALG_MLP_weights (TMultiLayerPerceptron *mlp, Int_t parasetnr)
 
void N3_ReadOptionFile ()
 

Variables

Int_t N3_ANN_EQUALIZESGBG
 
Int_t N3_ANN_INPUTNEURONS
 
TString N3_ANN_Layout =""
 
Int_t N3_ANN_NHIDDENLAYER
 
Int_t N3_ANN_NInput
 
Int_t N3_ANN_NTRAINEPOCHS
 
Double_t N3_ANN_OUTPUTTHRESHOLD
 
Int_t N3_ANN_PLATE_DELTANMAX
 
Bool_t N3_DoTrain =kTRUE
 
Double_t N3_Inputvar [24]
 
Double_t N3_OutputValue =0
 
TMultiLayerPerceptron * N3_TMLP_ANN
 
Int_t N3_TrainNMax
 
Int_t N3_Type
 

Function Documentation

◆ N3_Create_ALG_MLP()

void N3_Create_ALG_MLP ( TTree *  inputtree,
Int_t  parasetnr 
)
657{
658 Log(2, "ShowRec.cpp", "--- void N3_Create_ALG_MLP() ---");
659
660 if (!gROOT->GetClass("TMultiLayerPerceptron")) {
661 gSystem->Load("libMLP");
662 }
663
665 cout << "N3_ANN_Layout: " << N3_ANN_Layout.Data() << endl;
666 // Full layout would look like:
667// N3_ANN_Layout: N3_Inputvar[0],N3_Inputvar[1],N3_Inputvar[2],N3_Inputvar[3],N3_Inputvar[4],N3_Inputvar[5],N3_Inputvar[6],N3_Inputvar[7],N3_Inputvar[8],N3_Inputvar[9],N3_Inputvar[10],N3_Inputvar[11],N3_Inputvar[12],N3_Inputvar[13],N3_Inputvar[14],N3_Inputvar[15],N3_Inputvar[16],N3_Inputvar[17],N3_Inputvar[18],N3_Inputvar[19],N3_Inputvar[20],N3_Inputvar[21],N3_Inputvar[22],N3_Inputvar[23],N3_Inputvar[24],N3_Inputvar[25],N3_Inputvar[26],N3_Inputvar[27],N3_Inputvar[28]:29:29:29:29:29:N3_Type
668
669 // Create the network:
670 // Attention: for training case, the tree "simu" has already to be filled with the entries.
671 N3_TMLP_ANN = new TMultiLayerPerceptron(N3_ANN_Layout, simu, "(Entry$)%2", "(Entry$+1)%2");
672// N3_TMLP_ANN = new TMultiLayerPerceptron(N3_ANN_Layout, simu, "(Entry$)%5", "(Entry$+1)%5");
673 // This network does use the dZ to InBT (variable N3_Inputvar[0]) as primary weight
674// N3_TMLP_ANN = new TMultiLayerPerceptron(N3_ANN_Layout, "N3_Inputvar[0]", simu, "(Entry$)%2", "(Entry$+1)%2");
675 //N3_TMLP_ANN->Print();
676
677 Log(2, "ShowRec.cpp", "--- void N3_Create_ALG_MLP() done.");
678 return;
679}
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
void N3_Create_Layout()
Definition: ShowRec_Alg_N3.cpp:618
TMultiLayerPerceptron * N3_TMLP_ANN
Definition: ShowRec_Alg_N3.h:5
TString N3_ANN_Layout
Definition: ShowRec_Alg_N3.h:14
TTree * simu
Definition: testBGReduction_By_ANN.C:12

◆ N3_Dump_ALG_MLP_weights()

void N3_Dump_ALG_MLP_weights ( TMultiLayerPerceptron *  mlp,
Int_t  parasetnr 
)
698{
699 Log(2, "ShowRec.cpp", "--- void N3_Dump_ALG_MLP_weights() ---");
700 cout << "parasetnr = " << parasetnr << endl;
701 cout << "weightfilestring = " << Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr) << endl;
702 mlp->DumpWeights(Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr));
703 mlp->GetStructure();
704 mlp->Print();
705 Log(2, "ShowRec.cpp", "--- void N3_Dump_ALG_MLP_weights() done.");
706 return;
707}
TMultiLayerPerceptron * mlp
Definition: testBGReduction_By_ANN.C:61

◆ N3_FindBestCompliments()

void N3_FindBestCompliments ( EdbSegP seg,
EdbPattern TestPattern,
EdbPVRec local_gAli,
Int_t  Downstream,
Float_t &  mindeltaZ,
Float_t &  mindT,
Float_t &  mindR,
Float_t &  mindMinDist,
Int_t &  nDifferentSegs 
)
773 {
774
775 Log(4, "ShowRec.cpp", "--- void N3_FindBestCompliments() ---");
776
777 if (gEDBDEBUGLEVEL>3) {
778 cout << "Looking for best compliments for segment " << seg << " of pattern " << TestPattern << " ... " << endl;
779 cout << "Looking for pattern with Downstream = " << Downstream << endl;
780 seg->PrintNice();
781 }
782
783 EdbPattern* OtherPattern = NULL;
784 EdbPattern* OtherPatternInterim = NULL;
785
786 // Speculative calculation of delta Z value. To be refined later.
787 // See further down below.
788 // It is basically seg->Z() - OtherPattern->Z().
789 mindeltaZ = 0.0 - Downstream * 1300.0;
790
791 // Dumb workaround for the selection method, but working.
792 // Quick and dirty approach:
793 if (Downstream==0) {
794 // Will be the same plate.
795 // Take care not to compare segment with segment itself further down!!
796 OtherPattern = TestPattern;
797 }
798 else if (Downstream==1) {
799 OtherPattern = local_gAli->GetPatternSucceding(TestPattern);
800 }
801 else if (Downstream==2) {
802 OtherPatternInterim = local_gAli->GetPatternSucceding(TestPattern);
803 if (NULL==OtherPatternInterim) {
804 OtherPattern=NULL;
805 }
806 else {
807 OtherPattern = local_gAli->GetPatternSucceding(OtherPatternInterim);
808 }
809 }
810 else if (Downstream==-1) {
811 OtherPattern = local_gAli->GetPatternPreceding(TestPattern);
812 }
813 else if (Downstream==-2) {
814 OtherPatternInterim = local_gAli->GetPatternPreceding(TestPattern);
815 if (NULL==OtherPatternInterim) {
816 OtherPattern=NULL;
817 }
818 else {
819 OtherPattern = local_gAli->GetPatternPreceding(OtherPatternInterim);
820 }
821 }
822 else {
823// cout << "WARNING Downstream variable out of bounds. Return NULL as OtherPattern." << endl;
824 }
825
826 if (NULL == OtherPattern) {
827// cout << "WARNING NULL == OtherPattern. Return now." << endl;
828 return;
829 }
830
831// cout << "TestPattern has Z() of: " << TestPattern << " and next/overnext pattern has Z of: " << OtherPattern->Z() << endl;
832
833 // How many segments are there in the check_pattern?
834 Int_t nSeg = OtherPattern->N();
835// cout << "TestPattern has N entries: " << nSeg << " (one maybe the test segment)" << endl;
836 // Whats the Z difference for segment and actual pattern?
837 mindeltaZ = seg->Z() - OtherPattern->Z();
838
839 Double_t testval_dR=0;
840 Double_t testval_dT=0;
841 Double_t testval_dminDins=0;
842 Int_t IDmindR = -1;
843 Int_t IDmindT = -1;
844 Int_t IDmindminDist = -1;
845
846 // Reset minimal values to incredibly large values for first time check:
847 mindT=9999999;
848 mindR=9999999;
849 mindMinDist=9999999;
850
851 // Do finding routine now, simple comparison...
852 for (Int_t i=0; i<nSeg; ++i) {
853 EdbSegP* otherSeg = OtherPattern->GetSegment(i);
854 // dont match segment with itsself:
855 if (otherSeg==seg) continue;
856
857 // Quick Preselection: we aussume, that large away segments do not
858 // contribute to any of the minimum selection segments.
859 if (TMath::Abs(seg->X() - otherSeg->X()) > 1000 || TMath::Abs(seg->Y() - otherSeg->Y()) > 1000 ) continue;
860// cout << "seg = " << seg << " and otherSeg = " << otherSeg << endl;
861// cout << "deltaX = seg->X() - otherSeg->X() " << seg->X() - otherSeg->X() << endl;
862// cout << "deltaY = seg->Y() - otherSeg->Y() " << seg->Y() - otherSeg->Y() << endl;
863
864 // always propagate from seg to other seg (from i to j)
865 testval_dR = GetdR(seg, otherSeg);
866 testval_dT = GetdeltaThetaSingleAngles(seg, otherSeg);
867 testval_dminDins = GetdMinDist(seg, otherSeg);
868 //printf("i otherSeg->ID() testval_dR testval_dT testval_dminDins %d, %d, %.03f %.03f %.03f \n",i,otherSeg->ID(), testval_dR ,testval_dT ,testval_dminDins );
869 if (testval_dR < mindR ) {
870 mindR = testval_dR;
871 IDmindR = otherSeg->ID();
872 }
873 if (testval_dT < mindT ) {
874 mindT = testval_dT;
875 IDmindT = otherSeg->ID();
876 }
877 if (testval_dminDins < mindMinDist ) {
878 mindMinDist = testval_dminDins;
879 IDmindminDist = otherSeg->ID();
880 }
881 }
882
883 /*
884 cout << "Comparison for all segments gives following results: " << endl;
885 printf("IDmindR = %d, mindR = %.03f\n", IDmindR , mindR);
886 printf("IDmindT = %d, mindT = %.03f\n", IDmindT , mindT);
887 printf("IDmindminDist = %d, mindMinDist = %.03f\n", IDmindminDist , mindMinDist);
888 */
889
890 // Now check, how many different otherSeg ID() values we have...
891// cout << "Now check, how many different otherSeg ID() values we have..." << endl;
892 // Comparing ID of mindR mit mindT
893 Int_t ndifferent=3;
894 if (IDmindR==IDmindT || IDmindR==IDmindminDist || IDmindminDist==IDmindT) {
895 ndifferent=2;
896 if (IDmindR==IDmindT && IDmindR==IDmindminDist && IDmindminDist==IDmindT) ndifferent=1;
897 }
898 if (nSeg==0) ndifferent=0; // no, if no other segment was around...
899 if (nSeg==1 && OtherPattern==TestPattern) ndifferent=0; // no, if no other segment was around...
900 // Hand over new value:
901 nDifferentSegs= ndifferent;
902// cout << "nDifferentSegs contributing to min values " << nDifferentSegs << endl;
903
904 Log(4, "ShowRec.cpp", "--- void N3_FindBestCompliments() done.");
905 return;
906}
Double_t GetdeltaThetaSingleAngles(EdbSegP *s1, EdbSegP *s2)
Definition: ShowRec.cpp:7258
Double_t GetdMinDist(EdbSegP *s1, EdbSegP *s2)
Definition: ShowRec.h:170
Double_t GetdR(EdbSegP *s1, EdbSegP *s2)
Definition: ShowRec.h:167
Definition: EdbPattern.h:273
EdbPattern * GetPatternPreceding(EdbPattern *pat) const
Definition: EdbPattern.cxx:1851
EdbPattern * GetPatternSucceding(EdbPattern *pat) const
Definition: EdbPattern.cxx:1845
Definition: EdbSegP.h:21
Int_t ID() const
Definition: EdbSegP.h:147
Float_t X() const
Definition: EdbSegP.h:173
Float_t Z() const
Definition: EdbSegP.h:153
Float_t Y() const
Definition: EdbSegP.h:174
void PrintNice() const
Definition: EdbSegP.cxx:392
Float_t Z() const
Definition: EdbPattern.h:84
Int_t N() const
Definition: EdbPattern.h:86
EdbSegP * GetSegment(int i) const
Definition: EdbPattern.h:66
gEDBDEBUGLEVEL
Definition: energy.C:7
#define NULL
Definition: nidaqmx.h:84

◆ N3_Load_ALG_MLP_weights()

void N3_Load_ALG_MLP_weights ( TMultiLayerPerceptron *  mlp,
Int_t  parasetnr 
)
684{
685 Log(2, "ShowRec.cpp", "--- void N3_Load_ALG_MLP_weights() ---");
686 cout << "parasetnr = " << parasetnr << endl;
687 cout << "weightfilestring = " << Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr) << endl;
688 mlp->LoadWeights(Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr));
689 mlp->GetStructure();
690 mlp->Print();
691 Log(2, "ShowRec.cpp", "--- void N3_Load_ALG_MLP_weights() done.");
692 return;
693}

◆ N3_ReadOptionFile()

void N3_ReadOptionFile ( )
713{
714 Log(2, "ShowRec.cpp", "--- void N3_ReadOptionFile() ---");
715 cout << "Read OptionFile N3_Options.txt (no change of name possible currently)" << endl;
716
717 // read parameters from par-file
718 // return: 0 if ok
719 // -1 if file access failed
720 char buf[256];
721 char key[256];
722 char name[256];
723 const char *file="N3_Options.txt";
724
725 FILE *fp = fopen(file,"r");
726 if (!fp) {
727 Log(1,"N3_ReadOptionFile","ERROR open file: %s", file);
728 return;
729 }
730 else Log(2,"N3_ReadOptionFile","Read shower parameters from file: %s", file );
731
732 Int_t id;
733 Int_t int_eUse;
734 int dospec;
735 TString tmpString;
736 char tmpchar[256];
737
738 while (fgets(buf, sizeof(buf), fp)) {
739 for (Int_t i = 0; i < (Int_t)strlen(buf); ++i)
740 if (buf[i]=='#') {
741 buf[i]='\0'; // cut out comments starting from #
742 break;
743 }
744
745 if ( sscanf(buf,"%s",key)!=1 ) continue;
746
747 if ( !strcmp(key,"N3_TRAIN") )
748 {
749 int train;
750 sscanf(buf+strlen(key),"%d",&train);
751 cout << "N3_ReadOptionFile train = " << train << endl;
752 N3_DoTrain=train;
753 }
754 else if ( !strcmp(key,"N3_TRAIN_NMAX") )
755 {
756 int trainNMax;
757 sscanf(buf+strlen(key),"%d",&trainNMax);
758 cout << "N3_ReadOptionFile trainNMax = " << trainNMax << endl;
759 N3_TrainNMax=trainNMax;
760 }
761
762 } // end of while (fgets(buf, sizeof(buf), fp)) loop
763 fclose(fp);
764
765
766 Log(2, "ShowRec.cpp", "--- void N3_ReadOptionFile() done.");
767 return;
768}
Int_t N3_TrainNMax
Definition: ShowRec_Alg_N3.h:16
Bool_t N3_DoTrain
Definition: ShowRec_Alg_N3.h:6
TFile * file
Definition: write_pvr.C:3
fclose(pFile)
const char * name
Definition: merge_Energy_SytematicSources_Electron.C:24
UInt_t id
Definition: tlg2couples.C:117

Variable Documentation

◆ N3_ANN_EQUALIZESGBG

Int_t N3_ANN_EQUALIZESGBG

◆ N3_ANN_INPUTNEURONS

Int_t N3_ANN_INPUTNEURONS

◆ N3_ANN_Layout

TString N3_ANN_Layout =""

◆ N3_ANN_NHIDDENLAYER

Int_t N3_ANN_NHIDDENLAYER

◆ N3_ANN_NInput

Int_t N3_ANN_NInput

◆ N3_ANN_NTRAINEPOCHS

Int_t N3_ANN_NTRAINEPOCHS

◆ N3_ANN_OUTPUTTHRESHOLD

Double_t N3_ANN_OUTPUTTHRESHOLD

◆ N3_ANN_PLATE_DELTANMAX

Int_t N3_ANN_PLATE_DELTANMAX

◆ N3_DoTrain

Bool_t N3_DoTrain =kTRUE

◆ N3_Inputvar

Double_t N3_Inputvar[24]

◆ N3_OutputValue

Double_t N3_OutputValue =0

◆ N3_TMLP_ANN

TMultiLayerPerceptron* N3_TMLP_ANN

◆ N3_TrainNMax

Int_t N3_TrainNMax

◆ N3_Type

Int_t N3_Type