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 
)
656 {
657  Log(2, "ShowRec.cpp", "--- void N3_Create_ALG_MLP() ---");
658 
659  if (!gROOT->GetClass("TMultiLayerPerceptron")) {
660  gSystem->Load("libMLP");
661  }
662 
664  cout << "N3_ANN_Layout: " << N3_ANN_Layout.Data() << endl;
665  // Full layout would look like:
666 // 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
667 
668  // Create the network:
669  // Attention: for training case, the tree "simu" has already to be filled with the entries.
670  N3_TMLP_ANN = new TMultiLayerPerceptron(N3_ANN_Layout, simu, "(Entry$)%2", "(Entry$+1)%2");
671 // N3_TMLP_ANN = new TMultiLayerPerceptron(N3_ANN_Layout, simu, "(Entry$)%5", "(Entry$+1)%5");
672  // This network does use the dZ to InBT (variable N3_Inputvar[0]) as primary weight
673 // N3_TMLP_ANN = new TMultiLayerPerceptron(N3_ANN_Layout, "N3_Inputvar[0]", simu, "(Entry$)%2", "(Entry$+1)%2");
674  //N3_TMLP_ANN->Print();
675 
676  Log(2, "ShowRec.cpp", "--- void N3_Create_ALG_MLP() done.");
677  return;
678 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
void N3_Create_Layout()
Definition: ShowRec_Alg_N3.cpp:617
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 
)
697 {
698  Log(2, "ShowRec.cpp", "--- void N3_Dump_ALG_MLP_weights() ---");
699  cout << "parasetnr = " << parasetnr << endl;
700  cout << "weightfilestring = " << Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr) << endl;
701  mlp->DumpWeights(Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr));
702  mlp->GetStructure();
703  mlp->Print();
704  Log(2, "ShowRec.cpp", "--- void N3_Dump_ALG_MLP_weights() done.");
705  return;
706 }
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 
)
772  {
773 
774  Log(4, "ShowRec.cpp", "--- void N3_FindBestCompliments() ---");
775 
776  if (gEDBDEBUGLEVEL>3) {
777  cout << "Looking for best compliments for segment " << seg << " of pattern " << TestPattern << " ... " << endl;
778  cout << "Looking for pattern with Downstream = " << Downstream << endl;
779  seg->PrintNice();
780  }
781 
782  EdbPattern* OtherPattern = NULL;
783  EdbPattern* OtherPatternInterim = NULL;
784 
785  // Speculative calculation of delta Z value. To be refined later.
786  // See further down below.
787  // It is basically seg->Z() - OtherPattern->Z().
788  mindeltaZ = 0.0 - Downstream * 1300.0;
789 
790  // Dumb workaround for the selection method, but working.
791  // Quick and dirty approach:
792  if (Downstream==0) {
793  // Will be the same plate.
794  // Take care not to compare segment with segment itself further down!!
795  OtherPattern = TestPattern;
796  }
797  else if (Downstream==1) {
798  OtherPattern = local_gAli->GetPatternSucceding(TestPattern);
799  }
800  else if (Downstream==2) {
801  OtherPatternInterim = local_gAli->GetPatternSucceding(TestPattern);
802  if (NULL==OtherPatternInterim) {
803  OtherPattern=NULL;
804  }
805  else {
806  OtherPattern = local_gAli->GetPatternSucceding(OtherPatternInterim);
807  }
808  }
809  else if (Downstream==-1) {
810  OtherPattern = local_gAli->GetPatternPreceding(TestPattern);
811  }
812  else if (Downstream==-2) {
813  OtherPatternInterim = local_gAli->GetPatternPreceding(TestPattern);
814  if (NULL==OtherPatternInterim) {
815  OtherPattern=NULL;
816  }
817  else {
818  OtherPattern = local_gAli->GetPatternPreceding(OtherPatternInterim);
819  }
820  }
821  else {
822 // cout << "WARNING Downstream variable out of bounds. Return NULL as OtherPattern." << endl;
823  }
824 
825  if (NULL == OtherPattern) {
826 // cout << "WARNING NULL == OtherPattern. Return now." << endl;
827  return;
828  }
829 
830 // cout << "TestPattern has Z() of: " << TestPattern << " and next/overnext pattern has Z of: " << OtherPattern->Z() << endl;
831 
832  // How many segments are there in the check_pattern?
833  Int_t nSeg = OtherPattern->N();
834 // cout << "TestPattern has N entries: " << nSeg << " (one maybe the test segment)" << endl;
835  // Whats the Z difference for segment and actual pattern?
836  mindeltaZ = seg->Z() - OtherPattern->Z();
837 
838  Double_t testval_dR=0;
839  Double_t testval_dT=0;
840  Double_t testval_dminDins=0;
841  Int_t IDmindR = -1;
842  Int_t IDmindT = -1;
843  Int_t IDmindminDist = -1;
844 
845  // Reset minimal values to incredibly large values for first time check:
846  mindT=9999999;
847  mindR=9999999;
848  mindMinDist=9999999;
849 
850  // Do finding routine now, simple comparison...
851  for (Int_t i=0; i<nSeg; ++i) {
852  EdbSegP* otherSeg = OtherPattern->GetSegment(i);
853  // dont match segment with itsself:
854  if (otherSeg==seg) continue;
855 
856  // Quick Preselection: we aussume, that large away segments do not
857  // contribute to any of the minimum selection segments.
858  if (TMath::Abs(seg->X() - otherSeg->X()) > 1000 || TMath::Abs(seg->Y() - otherSeg->Y()) > 1000 ) continue;
859 // cout << "seg = " << seg << " and otherSeg = " << otherSeg << endl;
860 // cout << "deltaX = seg->X() - otherSeg->X() " << seg->X() - otherSeg->X() << endl;
861 // cout << "deltaY = seg->Y() - otherSeg->Y() " << seg->Y() - otherSeg->Y() << endl;
862 
863  // always propagate from seg to other seg (from i to j)
864  testval_dR = GetdR(seg, otherSeg);
865  testval_dT = GetdeltaThetaSingleAngles(seg, otherSeg);
866  testval_dminDins = GetdMinDist(seg, otherSeg);
867  //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 );
868  if (testval_dR < mindR ) {
869  mindR = testval_dR;
870  IDmindR = otherSeg->ID();
871  }
872  if (testval_dT < mindT ) {
873  mindT = testval_dT;
874  IDmindT = otherSeg->ID();
875  }
876  if (testval_dminDins < mindMinDist ) {
877  mindMinDist = testval_dminDins;
878  IDmindminDist = otherSeg->ID();
879  }
880  }
881 
882  /*
883  cout << "Comparison for all segments gives following results: " << endl;
884  printf("IDmindR = %d, mindR = %.03f\n", IDmindR , mindR);
885  printf("IDmindT = %d, mindT = %.03f\n", IDmindT , mindT);
886  printf("IDmindminDist = %d, mindMinDist = %.03f\n", IDmindminDist , mindMinDist);
887  */
888 
889  // Now check, how many different otherSeg ID() values we have...
890 // cout << "Now check, how many different otherSeg ID() values we have..." << endl;
891  // Comparing ID of mindR mit mindT
892  Int_t ndifferent=3;
893  if (IDmindR==IDmindT || IDmindR==IDmindminDist || IDmindminDist==IDmindT) {
894  ndifferent=2;
895  if (IDmindR==IDmindT && IDmindR==IDmindminDist && IDmindminDist==IDmindT) ndifferent=1;
896  }
897  if (nSeg==0) ndifferent=0; // no, if no other segment was around...
898  if (nSeg==1 && OtherPattern==TestPattern) ndifferent=0; // no, if no other segment was around...
899  // Hand over new value:
900  nDifferentSegs= ndifferent;
901 // cout << "nDifferentSegs contributing to min values " << nDifferentSegs << endl;
902 
903  Log(4, "ShowRec.cpp", "--- void N3_FindBestCompliments() done.");
904  return;
905 }
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:280
EdbPattern * GetPatternPreceding(EdbPattern *pat) const
Definition: EdbPattern.cxx:2017
EdbPattern * GetPatternSucceding(EdbPattern *pat) const
Definition: EdbPattern.cxx:2011
Definition: EdbSegP.h:18
Int_t ID() const
Definition: EdbSegP.h:144
Float_t X() const
Definition: EdbSegP.h:170
Float_t Z() const
Definition: EdbSegP.h:150
Float_t Y() const
Definition: EdbSegP.h:171
void PrintNice() const
Definition: EdbSegP.cxx:418
Float_t Z() const
Definition: EdbPattern.h:87
Int_t N() const
Definition: EdbPattern.h:89
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 
)
683 {
684  Log(2, "ShowRec.cpp", "--- void N3_Load_ALG_MLP_weights() ---");
685  cout << "parasetnr = " << parasetnr << endl;
686  cout << "weightfilestring = " << Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr) << endl;
687  mlp->LoadWeights(Form("N3_ANN_WEIGHTS_PARASET_%d.txt",parasetnr));
688  mlp->GetStructure();
689  mlp->Print();
690  Log(2, "ShowRec.cpp", "--- void N3_Load_ALG_MLP_weights() done.");
691  return;
692 }

◆ N3_ReadOptionFile()

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

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