Changeset 2334 for trunk/MagicSoft
- Timestamp:
- 09/15/03 10:59:53 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
r2286 r2334 21 21 // 22 22 // $RCSfile: camera.cxx,v $ 23 // $Revision: 1.5 7$23 // $Revision: 1.58 $ 24 24 // $Author: blanch $ 25 // $Date: 2003-0 7-17 18:02:46$25 // $Date: 2003-09-15 09:59:53 $ 26 26 // 27 27 //////////////////////////////////////////////////////////////////////// … … 58 58 59 59 #include "TArrayC.h" 60 60 #include "TObjArray.h" 61 61 62 #include "MTrigger.hxx" 62 63 #include "MFadc.hxx" … … 75 76 #include "MMcFadcHeader.hxx" 76 77 #include "MGeomCamMagic.h" 78 #include "MGeomCamMagic919.h" 79 #include "MGeomCamMagicHG.h" 80 #include "MGeomCamECO1000.h" 81 #include "MGeomCamECO1000HG.h" 82 #include "MGeomCamCT1.h" 83 #include "MGeomCamCT1Daniel.h" 77 84 #include "MGeomPix.h" 78 85 … … 189 196 static char ct_filename[256]; 190 197 198 //@: Number of CT 199 static int ct_Number; 200 201 //@: Camera geometries 202 static int ct_Geometry; 203 191 204 //@: list of showers to be skipped 192 205 static int *Skip; … … 245 258 246 259 //@: Trigger conditions for a single trigger mode 247 static float qThreshold[CAMERA_PIXELS];248 static int Trigger_multiplicity = 4;249 static int Trigger_topology = 2;260 static float **qThreshold; 261 static int Trigger_multiplicity[100]; 262 static int Trigger_topology[100]; 250 263 251 264 //@: Upper and lower edges of the trigger loop … … 301 314 302 315 //@: table of QE 303 static float *** QE;316 static float ****QE; 304 317 305 318 //@: number of datapoints for the QE curve 306 static int pointsQE ;319 static int pointsQE[100]; 307 320 308 321 //@: table of QE … … 398 411 //@' 399 412 400 char inname [256]; //@< input file name413 char inname_CT[100][256]; //@< array of names for each CT input file 401 414 char starfieldname[256]; //@< starfield input file name 402 415 char qe_filename[256]; //@< qe input file name … … 414 427 char flag[SIZE_OF_FLAGS + 1]; //@< flags in the .rfl file 415 428 char flag_new[SIZE_OF_FLAGS + 1]; //@< New flag for the run header in the .rfl file 416 417 int reflector_file_version; //@< vrsion of he reflector file 418 419 FILE *inputfile; //@< stream for the input file 429 int GeometryCamera[100]; //@< Identification of MGeomCam for each CT 430 int TriggerPixels[100]; //@< Numeber of pixels in the trigger region for each CT 431 432 int reflector_file_version=0; //@< vrsion of he reflector file 433 434 FILE *inputfile[100]; //@< stream for the input file 435 420 436 ofstream datafile; //@< stream for the data file 421 437 … … 426 442 427 443 int inumphe; //@< number of photoelectrons in an event from showers 444 int inumphe_CT[100]; //@< number of photoelectrons in an event from showers 428 445 float inumphensb; //@< number of photoelectrons in an event from nsb 429 446 … … 442 459 int ntshow=0; //@< total number of showers 443 460 int ncph=0; //@< partial number of photons in a given run 461 int ncph_system=0; //@< partial number of photons in a given run 444 462 int ntcph=0; //@< total number of photons 445 463 … … 454 472 int nphe2NSB; //@< From how many phe will we simulate NSB? 455 473 float meanNSB; //@< diffuse NSB mean value (phe per ns per central pixel) 456 float diffnsb_phepns[ iMAXNUMPIX]; //@< diffuse NSB values for each pixel474 float diffnsb_phepns[100][iMAXNUMPIX]; //@< diffuse NSB values for each pixel 457 475 //@< derived from meanNSB 458 476 float nsbrate_phepns[iMAXNUMPIX][iNUMWAVEBANDS]; //@< non-diffuse nsb 459 477 //@< photoelectron rates 460 float nsb_phepns[ iMAXNUMPIX]; //@< NSB values for each pixel461 float nsb_phepns_rotated[ iMAXNUMPIX]; //@< NSB values for each pixel after rotation478 float nsb_phepns[100][iMAXNUMPIX]; //@< NSB values for each pixel 479 float nsb_phepns_rotated[100][iMAXNUMPIX]; //@< NSB values for each pixel after rotation 462 480 463 481 Float_t nsb_trigresp[TRIGGER_TIME_SLICES]; //@< array to write the trigger … … 479 497 float zenfactor=1.0; // correction factor calculated from the extinction 480 498 481 int anaPixels;482 483 499 int nstoredevents = 0; 484 500 int flagstoring = 0; 485 501 486 int ntrigger = 0; //@< number of triggers in the whole file502 int ntrigger[100]; //@< number of triggers in the whole file 487 503 int btrigger = 0; //@< trigger flag 488 504 int ithrescount; //@< counter for loop over threshold trigger … … 516 532 Float_t soffphi = 0.0; 517 533 UInt_t corsika = 5200 ; 534 Float_t maxpimpact = 0.0; 518 535 519 536 // Star Field Rotation variables … … 522 539 Float_t rho , C3 , C2 , C1; 523 540 524 MGeomCamMagic camgeom; // structure holding the camera definition525 526 ct_NPixels=camgeom.GetNumPixels();527 528 541 //!@' @#### Definition of variables for |getopt()|. 529 542 //@' … … 534 547 //@' 535 548 549 qThreshold = new float *[100]; 550 for(i=0;i<100;i++) 551 qThreshold[i] = new float [CAMERA_PIXELS]; 552 536 553 for(i=0;i<iMAXNUMPIX;i++){ 537 nsb_phepns[i]=0; 538 nsb_phepns_rotated[i]=0; 554 for(int ict=0;ict<100;ict++){ 555 nsb_phepns[ict][i]=0; 556 nsb_phepns_rotated[ict][i]=0; 557 } 539 558 for(j=0;j<iNUMWAVEBANDS;j++) 540 559 nsbrate_phepns[i][j]=0.0; //@< Starlight rates initialised at 0.0 … … 597 616 Data_From_STDIN = get_data_from_stdin(); 598 617 618 // get number of telescopes and camera geometries 619 620 ct_Number=get_ct_number(); 621 ct_Geometry=get_ct_geometry(); 622 623 for(int i=0;i<ct_Number;i++){ 624 ntrigger[i]=0; 625 if(ct_Geometry>=i*10){ 626 GeometryCamera[i]=int(ct_Geometry/pow(10.0,i))%10; 627 } 628 else 629 GeometryCamera[i]=0; 630 } 631 632 // structure holding the camera definition 633 634 TObjArray camgeom; 635 636 for (int i=0; i<ct_Number;i++){ 637 switch(GeometryCamera[i]){ 638 case 1: camgeom[i]=new MGeomCamMagic; 639 TriggerPixels[i]=TRIGGER_PIXELS_1; 640 break; 641 case 2: camgeom[i]=new MGeomCamMagic919; 642 TriggerPixels[i]=TRIGGER_PIXELS_2; 643 break; 644 case 3: camgeom[i]=new MGeomCamMagicHG; 645 TriggerPixels[i]=TRIGGER_PIXELS_3; 646 break; 647 case 5: camgeom[i]=new MGeomCamECO1000; 648 TriggerPixels[i]=TRIGGER_PIXELS_5; 649 break; 650 case 6: camgeom[i]=new MGeomCamECO1000HG; 651 TriggerPixels[i]=TRIGGER_PIXELS_6; 652 break; 653 case 8: camgeom[i]=new MGeomCamCT1; 654 TriggerPixels[i]=TRIGGER_PIXELS_8; 655 break; 656 case 9: camgeom[i]=new MGeomCamCT1Daniel; 657 TriggerPixels[i]=TRIGGER_PIXELS_9; 658 break; 659 default: camgeom[i]=new MGeomCamMagic; 660 TriggerPixels[i]=TRIGGER_PIXELS_1; 661 break; 662 } 663 } 664 665 ct_NPixels=0; 666 667 for(int ict=0;ict<ct_Number;ict++) 668 ct_NPixels=(((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels()>(UInt_t)ct_NPixels)? 669 (Int_t)((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels(): 670 ct_NPixels; 671 599 672 // read WC and QE files 600 673 601 strcpy( qe_filename, get_qe_filename()); 602 603 read_QE(qe_filename); 674 // FIX ME ! 675 // Currently the PMT N of any camera with same average QE has the same QE. 676 677 QE = new float *** [ct_Number]; 678 for(int ict=0;ict<ct_Number;ict++){ 679 strcpy( qe_filename, get_qe_filename(ict)); 680 read_QE(qe_filename,ict); 681 } 604 682 read_WC(); 605 683 … … 627 705 &FADC_resp_ampl_out, &FADC_resp_fwhm_out); 628 706 707 // FIXME --- tirgger properties may depend on the Camrea geometry 708 629 709 get_Trigger_properties( &Trigger_gate_length, &Trigger_overlaping_time, &Trigger_response_ampl, &Trigger_response_fwhm); 630 710 … … 635 715 (Trigger_loop_umult-Trigger_loop_lmult+1)* 636 716 (Trigger_loop_utop-Trigger_loop_ltop+1); 717 718 // Trigger loop operation is not implemented for Multi telscopes 719 720 if ( Trigger_Loop && ct_Number > 1 ){ 721 cout<<"ERROR : camera::main : Trigger loop option is not"; 722 cout<<" implemented for Multi Telescopes option. "<<icontrigger<< 723 " "<<ct_Number<<endl; 724 exit(1); 725 } 637 726 638 727 if (!Trigger_Loop){ 639 get_Trigger_Single (qThreshold, &Trigger_multiplicity, &Trigger_topology); 728 get_Trigger_Single (qThreshold, 729 &Trigger_multiplicity[0], 730 &Trigger_topology[0]); 640 731 icontrigger=1; 641 732 } 642 733 else 643 get_threshold(qThreshold );734 get_threshold(qThreshold[0]); 644 735 645 736 // get filenames 646 737 647 strcpy( inname, get_input_filename() ); 738 for(int ict=0;ict<ct_Number;ict++) 739 strcpy( inname_CT[ict], get_input_filename(ict) ); 648 740 649 741 strcpy( starfieldname, get_starfield_filename() ); … … 678 770 "%s:\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n\t%20s:\t%s\n", 679 771 "Filenames", 680 "In", inname ,772 "In", inname_CT[0], 681 773 "Stars", starfieldname, 682 774 "NSB database (inner pixels)", nsbpathname, … … 702 794 "%s:\n\t%20s: %f\n\t%20s: %i\n\t%20s: %i\n", 703 795 "Single Trigger mode", 704 "Threshold",qThreshold[0] ,705 "Multiplicity",Trigger_multiplicity ,706 "Topology",Trigger_topology );796 "Threshold",qThreshold[0][0], 797 "Multiplicity",Trigger_multiplicity[0], 798 "Topology",Trigger_topology[0]); 707 799 } 708 800 else{ … … 711 803 "Single Trigger mode", 712 804 "Threshold","Different for each pixel", 713 "Multiplicity",Trigger_multiplicity ,714 "Topology",Trigger_topology );805 "Multiplicity",Trigger_multiplicity[0], 806 "Topology",Trigger_topology[0]); 715 807 } 716 808 // log flags information … … 798 890 799 891 Int_t Lev0, Lev1; 892 Int_t Lev0MT[100], Lev1MT[100]; 800 893 801 894 fadcValues = new TArrayC(FADC_SLICES); … … 804 897 // number of pixels for parameters 805 898 806 anaPixels = get_ana_pixels();807 anaPixels = (anaPixels == -1) ? camgeom.GetNumPixels() : anaPixels;808 809 899 // Switched off writing TObject 810 900 … … 818 908 // initialise instance of Trigger and FADC classes 819 909 820 MTrigger Trigger(Trigger_gate_length, 910 MTrigger **Trigger_CT; 911 Trigger_CT = new MTrigger *[ct_Number]; 912 913 for (int i=0; i<ct_Number;i++){ 914 Trigger_CT[i] = new MTrigger(TriggerPixels[i], 915 ((MGeomCam*)(camgeom.UncheckedAt(i))), 916 Trigger_gate_length, 821 917 Trigger_overlaping_time, 822 918 Trigger_response_ampl, 823 919 Trigger_response_fwhm); //@< A instance of the Class MTrigger 824 920 } 921 922 for (int ict=0; ict<ct_Number;ict++){ 825 923 // Generate databse for trigger electronic noise 826 Trigger.SetElecNoise(Trigger_noise) ; 924 if (addElecNoise) 925 Trigger_CT[ict]->SetElecNoise(Trigger_noise) ; 827 926 828 927 // Set Right Discriminator threshold, taking into account trigger pixels 829 Trigger.CheckThreshold(&qThreshold[0]);830 928 Trigger_CT[ict]->CheckThreshold(&qThreshold[ict][0],GeometryCamera[ict]); 929 } 831 930 // Set flag in pixel 0 (not used for trigger) that indicates if secure pixel 832 931 // is active: secureDiskThres*10000+riseDiskThres 833 932 834 933 if(riseDiskThres>0.0) 835 qThreshold[0] =((UInt_t)secureDiskThres*100)*100+riseDiskThres;934 qThreshold[0][0]=((UInt_t)secureDiskThres*100)*100+riseDiskThres; 836 935 else 837 qThreshold[0] =0.0;838 936 qThreshold[0][0]=0.0; 937 839 938 // Initialise McTrig information class if we want to save trigger informtion 840 939 … … 843 942 MMcFadcHeader **HeaderFadc = NULL; 844 943 944 int numberBranches; 945 946 if (!Trigger_Loop) 947 numberBranches=ct_Number; 948 else 949 numberBranches=icontrigger; 845 950 846 951 if (Write_McTrig){ 847 952 848 McTrig = new MMcTrig * [ icontrigger];849 850 for (i=0;i< icontrigger;i++) {953 McTrig = new MMcTrig * [numberBranches]; 954 955 for (i=0;i<numberBranches;i++) { 851 956 McTrig[i] = new MMcTrig(); 852 957 } 853 958 854 HeaderTrig = new MMcTrigHeader * [ icontrigger];855 856 for (i=0;i< icontrigger;i++) {959 HeaderTrig = new MMcTrigHeader * [numberBranches]; 960 961 for (i=0;i<numberBranches;i++) { 857 962 HeaderTrig[i] = new MMcTrigHeader(); 858 963 } … … 861 966 if (Write_McFADC){ 862 967 863 HeaderFadc = new MMcFadcHeader * [ icontrigger];864 865 for (i=0;i< icontrigger;i++) {968 HeaderFadc = new MMcFadcHeader * [numberBranches]; 969 970 for (i=0;i<numberBranches;i++) { 866 971 HeaderFadc[i] = new MMcFadcHeader(); 867 972 } 868 973 } 869 974 870 MFadc fadc(FADC_response_ampl,FADC_response_fwhm, 871 FADC_resp_ampl_out,FADC_resp_fwhm_out) ; //@< A instance of the Class MFadc 975 MFadc **Fadc_CT; 976 Fadc_CT = new MFadc *[ct_Number]; 977 978 for (int i=0; i<ct_Number;i++) 979 Fadc_CT[i] = 980 new MFadc(((MGeomCam*)(camgeom.UncheckedAt(i)))->GetNumPixels(), 981 FADC_response_ampl,FADC_response_fwhm, 982 FADC_resp_ampl_out,FADC_resp_fwhm_out) ; //@< A instance of the Class MFadc 983 872 984 873 985 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! … … 883 995 ///////////////////////////////////////////////////////////////////// 884 996 885 Float_t input_pedestals[ CAMERA_PIXELS];886 887 for(i=0;i< CAMERA_PIXELS;i++)997 Float_t input_pedestals[ct_NPixels]; 998 999 for(i=0;i<ct_NPixels;i++) 888 1000 input_pedestals[i]=get_FADC_pedestal(); 889 890 fadc.SetPedestals(input_pedestals); 891 892 // Generate databse for the Fadc electronic noise 893 894 fadc.SetElecNoise(FADC_noise); 895 1001 for (int ict=0; ict<ct_Number;ict++){ 1002 1003 Fadc_CT[ict]->SetPedestals(input_pedestals); 1004 1005 // Generate databse for the Fadc electronic noise 1006 if (addElecNoise) 1007 Fadc_CT[ict]->SetElecNoise(FADC_noise); 1008 } 896 1009 // Prepare the raw data output 897 1010 898 1011 // Header Tree 899 1012 MGeomCam **camdummy = new MGeomCam * [ct_Number]; 1013 for (int ict=0; ict<ct_Number;ict++){ 1014 camdummy[ict]= ((MGeomCam*)(camgeom.UncheckedAt(ict))); 1015 } 900 1016 MRawRunHeader *RunHeader= new MRawRunHeader(); 901 1017 MMcRunHeader *McRunHeader = new MMcRunHeader(); 902 MMcConfigRunHeader *McConfigRunHeader = new MMcConfigRunHeader();903 1018 MMcCorsikaRunHeader *McCorsikaRunHeader = new MMcCorsikaRunHeader(); 904 1019 1020 MMcConfigRunHeader **McConfigRunHeader = NULL; 1021 McConfigRunHeader = new MMcConfigRunHeader * [numberBranches]; 1022 for (i=0;i<numberBranches;i++) { 1023 McConfigRunHeader[i] = new MMcConfigRunHeader(); 1024 } 1025 905 1026 // Header branch 906 1027 … … 908 1029 909 1030 if (Write_RawEvt) { 910 EvtHeader = new MRawEvtHeader * [ icontrigger];911 912 for (i=0;i< icontrigger;i++) {1031 EvtHeader = new MRawEvtHeader * [numberBranches]; 1032 1033 for (i=0;i<numberBranches;i++) { 913 1034 EvtHeader[i] = new MRawEvtHeader(); 914 1035 } … … 920 1041 921 1042 if (Write_RawEvt) { 922 EvtData = new MRawEvtData * [ icontrigger];923 924 for (i=0;i< icontrigger;i++) {1043 EvtData = new MRawEvtData * [numberBranches]; 1044 1045 for (i=0;i<numberBranches;i++) { 925 1046 EvtData[i] = new MRawEvtData(); 926 1047 EvtData[i]->Init(RunHeader); // We need thr RunHeader to read … … 950 1071 &McRunHeader); 951 1072 952 HeaderTree.Branch("MMcConfigRunHeader","MMcConfigRunHeader",953 &McConfigRunHeader);954 955 1073 HeaderTree.Branch("MMcCorsikaRunHeader","MMcCorsikaRunHeader", 956 1074 &McCorsikaRunHeader); 957 1075 958 if(!Trigger_Loop && Write_McTrig ){1076 if(!Trigger_Loop && Write_McTrig && ct_Number==1){ 959 1077 960 1078 HeaderTree.Branch("MMcTrigHeader","MMcTrigHeader", 961 1079 &HeaderTrig[0]); 962 1080 } 963 if (Trigger_Loop && Write_McTrig){ 964 for(char branchname[20],i=0;i<icontrigger;i++){ 1081 if (ct_Number==1) 1082 HeaderTree.Branch("MGeomCam","MGeomCam", 1083 &camdummy[0]); 1084 else{ 1085 char branchname[20]; 1086 for (int ict=0; ict<ct_Number;ict++){ 1087 sprintf(help,"%i",ict+1); 1088 strcpy (branchname, "MGeomCam;"); 1089 strcat (branchname, & help[0]); 1090 strcat (branchname, "."); 1091 HeaderTree.Branch(branchname,"MGeomCam", 1092 &camdummy[ict]); 1093 } 1094 } 1095 1096 if ((Trigger_Loop || ct_Number>1) && Write_McTrig){ 1097 for(char branchname[20],i=0;i<numberBranches;i++){ 965 1098 966 1099 sprintf(help,"%i",i+1); … … 973 1106 } 974 1107 975 if(!Trigger_Loop && Write_McFADC ){1108 if(!Trigger_Loop && Write_McFADC && ct_Number==1){ 976 1109 977 1110 HeaderTree.Branch("MMcFadcHeader","MMcFadcHeader", 978 1111 &HeaderFadc[0]); 979 1112 } 980 if ( Trigger_Loop&& Write_McFADC){981 for(char branchname[20],i=0;i< icontrigger;i++){1113 if ((Trigger_Loop || ct_Number>1) && Write_McFADC){ 1114 for(char branchname[20],i=0;i<numberBranches;i++){ 982 1115 983 1116 sprintf(help,"%i",i+1); … … 999 1132 RunHeader->SetNumSamples(0,FADC_SLICES); 1000 1133 RunHeader->SetNumCrates(1); 1001 RunHeader->SetNumPixInCrate(CAMERA_PIXELS); 1002 1134 RunHeader->SetNumPixInCrate(ct_NPixels); 1003 1135 1004 1136 // Fill branches for MMcTrigHeader 1005 1137 1006 if(!Trigger_Loop && Write_McTrig ){1007 1008 HeaderTrig[0]->SetTopology((Short_t) Trigger_topology );1009 HeaderTrig[0]->SetMultiplicity((Short_t) Trigger_multiplicity );1010 HeaderTrig[0]->SetThreshold(qThreshold );1138 if(!Trigger_Loop && Write_McTrig && ct_Number==1){ 1139 1140 HeaderTrig[0]->SetTopology((Short_t) Trigger_topology[0]); 1141 HeaderTrig[0]->SetMultiplicity((Short_t) Trigger_multiplicity[0]); 1142 HeaderTrig[0]->SetThreshold(qThreshold[0]); 1011 1143 HeaderTrig[0]->SetAmplitud(Trigger_response_ampl); 1012 1144 HeaderTrig[0]->SetFwhm(Trigger_response_fwhm); … … 1015 1147 HeaderTrig[0]->SetElecNoise(Trigger_noise); 1016 1148 } 1149 if(!Trigger_Loop && Write_McTrig && ct_Number>1){ 1150 for(int i=0;i<ct_Number;i++){ 1151 HeaderTrig[i]->SetTopology((Short_t) Trigger_topology[i]); 1152 HeaderTrig[i]->SetMultiplicity((Short_t) Trigger_multiplicity[i]); 1153 HeaderTrig[i]->SetThreshold(qThreshold[i]); 1154 HeaderTrig[i]->SetAmplitud(Trigger_response_ampl); 1155 HeaderTrig[i]->SetFwhm(Trigger_response_fwhm); 1156 HeaderTrig[i]->SetOverlap(Trigger_overlaping_time); 1157 HeaderTrig[i]->SetGate(Trigger_gate_length); 1158 HeaderTrig[i]->SetElecNoise(Trigger_noise); 1159 } 1160 } 1017 1161 if(Trigger_Loop && Write_McTrig){ 1018 1162 … … 1023 1167 HeaderTrig[iconcount]->SetTopology((Short_t) isorttopo[itopocount+Trigger_loop_ltop]); 1024 1168 HeaderTrig[iconcount]->SetMultiplicity((Short_t) imulticount+Trigger_loop_lmult); 1025 for(int i=0;i< CAMERA_PIXELS;i++){1169 for(int i=0;i<ct_NPixels;i++){ 1026 1170 fpixelthres[i]= 1027 ((Float_t)(fthrescount)>=qThreshold[ i])?1028 (Float_t)(fthrescount):qThreshold[ i];1171 ((Float_t)(fthrescount)>=qThreshold[0][i])? 1172 (Float_t)(fthrescount):qThreshold[0][i]; 1029 1173 } 1030 1174 HeaderTrig[iconcount]->SetThreshold( fpixelthres); … … 1039 1183 } 1040 1184 } 1041 1185 1042 1186 // Fill branches for MMcFadcHeader 1043 1187 1044 for(i=0;i< CAMERA_PIXELS;i++){1188 for(i=0;i<ct_NPixels;i++){ 1045 1189 fadc_elecnoise[i]=FADC_noise; 1046 1190 } 1047 1191 1048 fadc.GetPedestals(&fadc_pedestals[0]);1049 1050 if(!Trigger_Loop && Write_McFADC ){1192 Fadc_CT[0]->GetPedestals(&fadc_pedestals[0]); 1193 1194 if(!Trigger_Loop && Write_McFADC && ct_Number==1){ 1051 1195 1052 1196 HeaderFadc[0]->SetShape(0.0); 1053 1197 HeaderFadc[0]->SetAmplitud(FADC_response_ampl); 1054 1198 HeaderFadc[0]->SetFwhm(FADC_response_fwhm); 1055 HeaderFadc[0]->SetPedestal(&fadc_pedestals[0],anaPixels); 1056 HeaderFadc[0]->SetElecNoise(&fadc_elecnoise[0],anaPixels); 1057 } 1199 HeaderFadc[0]->SetPedestal(&fadc_pedestals[0], 1200 ((MGeomCam*)(camgeom.UncheckedAt(0)))->GetNumPixels()); 1201 HeaderFadc[0]->SetElecNoise(&fadc_elecnoise[0], 1202 ((MGeomCam*)(camgeom.UncheckedAt(0)))->GetNumPixels()); 1203 } 1204 if(!Trigger_Loop && Write_McFADC && ct_Number>1){ 1205 for(int i=0;i<ct_Number;i++){ 1206 HeaderFadc[i]->SetShape(0.0); 1207 HeaderFadc[i]->SetAmplitud(FADC_response_ampl); 1208 HeaderFadc[i]->SetFwhm(FADC_response_fwhm); 1209 HeaderFadc[i]->SetPedestal(&fadc_pedestals[0],((MGeomCam*)(camgeom.UncheckedAt(i)))->GetNumPixels()); 1210 HeaderFadc[i]->SetElecNoise(&fadc_elecnoise[0],((MGeomCam*)(camgeom.UncheckedAt(i)))->GetNumPixels()); 1211 } 1212 } 1058 1213 if(Trigger_Loop && Write_McFADC){ 1059 1214 int iconcount; … … 1064 1219 HeaderFadc[iconcount]->SetAmplitud(Trigger_response_ampl); 1065 1220 HeaderFadc[iconcount]->SetFwhm(Trigger_response_fwhm); 1066 HeaderFadc[iconcount]->SetPedestal(&fadc_pedestals[0], anaPixels);1067 HeaderFadc[iconcount]->SetElecNoise(&fadc_elecnoise[0], anaPixels);1221 HeaderFadc[iconcount]->SetPedestal(&fadc_pedestals[0], ct_NPixels); 1222 HeaderFadc[iconcount]->SetElecNoise(&fadc_elecnoise[0], ct_NPixels); 1068 1223 iconcount++; 1069 1224 } … … 1072 1227 } 1073 1228 1074 // Fill the Header Tree with the current leaves of each branch1075 // HeaderTree.Fill() ;1076 1077 1229 1078 1230 // create a Tree for the Event data stream … … 1085 1237 } 1086 1238 1087 if(!Trigger_Loop ){1239 if(!Trigger_Loop && ct_Number==1){ 1088 1240 1241 HeaderTree.Branch("MMcConfigRunHeader","MMcConfigRunHeader", 1242 &McConfigRunHeader[0]); 1243 1089 1244 if (Write_RawEvt){ 1090 1245 EvtTree.Branch("MRawEvtHeader","MRawEvtHeader", … … 1099 1254 } 1100 1255 else{ 1256 1257 if(ct_Number>1) 1258 for(char branchname[10],i=0;i<numberBranches;i++){ 1259 1260 sprintf(help,"%i",i+1); 1261 strcpy (branchname, "MMcConfigRunHeader;"); 1262 strcat (branchname, & help[0]); 1263 strcat (branchname, "."); 1264 HeaderTree.Branch(branchname,"MMcConfigRunHeader", 1265 &McConfigRunHeader[i]); 1266 } 1267 1101 1268 if (Write_McTrig){ 1102 for(char branchname[10],i=0;i< icontrigger;i++){1269 for(char branchname[10],i=0;i<numberBranches;i++){ 1103 1270 1104 1271 sprintf(help,"%i",i+1); … … 1112 1279 } 1113 1280 1114 if ( Trigger_Loop&& Write_RawEvt){1115 for(char branchname[15],i=0;i< icontrigger;i++){1281 if ((Trigger_Loop || ct_Number>1) && Write_RawEvt){ 1282 for(char branchname[15],i=0;i<numberBranches;i++){ 1116 1283 1117 1284 sprintf(help,"%i",i+1); … … 1122 1289 &EvtHeader[i]); 1123 1290 } 1124 for(char branchname[15],i=0;i< icontrigger;i++){1291 for(char branchname[15],i=0;i<numberBranches;i++){ 1125 1292 1126 1293 sprintf(help,"%i",i+1); … … 1133 1300 } 1134 1301 1302 1135 1303 TApplication theAppTrigger("App", &argc, argv); 1136 1304 … … 1171 1339 // 1172 1340 1341 // FIXME --- star NSB different for each camera? 1173 1342 k = produce_nsbrates( starfieldname, 1174 &camgeom, 1175 nsbrate_phepns); 1343 ((MGeomCam*)(camgeom.UncheckedAt(0))), 1344 nsbrate_phepns, 1345 0); 1176 1346 1177 1347 if (k != 0){ … … 1180 1350 } 1181 1351 1182 // calculate diffuse rate correcting for the pixel size 1183 1184 const double size_inner = camgeom[0].GetR(); 1185 1186 for(UInt_t ui=0; ui<camgeom.GetNumPixels(); ui++){ 1187 const double actual_size = camgeom[ui].GetR(); 1188 diffnsb_phepns[ui] = meanNSB * 1189 actual_size*actual_size/(size_inner*size_inner); 1352 // calculate diffuse rate correcting for the pixel size and telescope 1353 1354 float factorNSB_ct; 1355 for(int ict=0;ict<ct_Number;ict++){ 1356 1357 // First we set the factor due to the mirror size respect to the MAGIC mirror. 1358 1359 switch(GeometryCamera[ict]){ 1360 case 1: 1361 case 2: 1362 case 3: 1363 case 4: 1364 factorNSB_ct=1.0; 1365 break; 1366 case 5: 1367 case 6: 1368 case 7: 1369 factorNSB_ct=1000.0/239.0; 1370 break; 1371 case 8: 1372 case 9: 1373 default: 1374 factorNSB_ct=1.0; 1375 break; 1376 } 1377 1378 factorNSB_ct=factorNSB_ct/ 1379 ((*((MGeomCam*)(camgeom.UncheckedAt(ict)))).GetCameraDist()*1000* 1380 (*((MGeomCam*)(camgeom.UncheckedAt(ict)))).GetCameraDist()*1000* 1381 PIXEL_SIZE*PIXEL_SIZE); 1382 1383 for(UInt_t ui=0; 1384 ui<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels(); ui++){ 1385 diffnsb_phepns[ict][ui] = (Int_t(meanNSB*factorNSB_ct*100+0.5))/100.0 * 1386 (*((MGeomCam*)(camgeom.UncheckedAt(ict))))[ui].GetD()* 1387 (*((MGeomCam*)(camgeom.UncheckedAt(ict))))[ui].GetD(); 1388 } 1190 1389 } 1191 1390 1192 1391 // calculate nsb rate including diffuse and starlight 1193 1392 // we also include the extinction effect 1194 for(j=0;j<iNUMWAVEBANDS;j++){ 1393 for(int ict=0;ict<ct_Number;ict++){ 1394 for(j=0;j<iNUMWAVEBANDS;j++){ 1195 1395 // calculate the effect of the atmospheric extinction 1196 1396 1197 1397 zenfactor = pow(10., -0.4 * ext[j] ); 1198 1398 1199 for(UInt_t ui=0; ui< camgeom.GetNumPixels();ui++){1200 nsb_phepns[ui]+=diffnsb_phepns[ui]/iNUMWAVEBANDS + zenfactor *nsbrate_phepns[ui][j];1201 nsb_phepns_rotated[ui]=nsb_phepns[ui];1399 for(UInt_t ui=0; ui<((MGeomCam*)(camgeom.UncheckedAt(0)))->GetNumPixels();ui++){ 1400 nsb_phepns[ict][ui]+=diffnsb_phepns[ict][ui]/iNUMWAVEBANDS + zenfactor *nsbrate_phepns[ui][j]; 1401 nsb_phepns_rotated[ict][ui]=nsb_phepns[ict][ui]; 1202 1402 } 1403 } 1203 1404 } 1204 1405 } … … 1212 1413 if ( Data_From_STDIN ) { 1213 1414 1214 inputfile = stdin;1415 inputfile[0] = stdin; 1215 1416 1216 1417 } 1217 1418 else{ 1218 1419 1219 log( SIGNATURE, "Opening input \"rfl\" file %s\n", inname ); 1220 inputfile = fopen( inname, "r" ); 1221 if ( inputfile == NULL ) 1222 error( SIGNATURE, "Cannot open input file: %s\n", inname ); 1223 1420 for(int ict=0;ict<ct_Number;ict++){ 1421 1422 log( SIGNATURE, "Opening input \"rfl\" file %s\n", inname_CT[ict] ); 1423 inputfile[ict] = fopen( inname_CT[ict], "r" ); 1424 1425 if ( inputfile[ict] == NULL ) 1426 error( SIGNATURE, "Cannot open input file: %s\n", inname_CT[ict] ); 1427 } 1428 1224 1429 } 1225 1430 1226 1431 // get signature, and check it 1227 1432 1228 if((reflector_file_version=check_reflector_file( inputfile ))==FALSE){ 1229 exit(1); 1230 } 1433 for(int ict=0;ict<ct_Number;ict++){ 1434 if((reflector_file_version=check_reflector_file( inputfile[ict] ))==FALSE){ 1435 exit(1); 1436 } 1437 } 1231 1438 1232 1439 // open data file … … 1245 1452 // allocate space for PMTs numbers of pixels 1246 1453 1247 fnpix = new float [ camgeom.GetNumPixels()];1454 fnpix = new float [ct_NPixels]; 1248 1455 1249 1456 … … 1252 1459 1253 1460 // get flag 1254 1255 fread( flag, SIZE_OF_FLAGS, 1, inputfile ); 1461 1462 for(int ict=0;ict<ct_Number;ict++) 1463 fread( flag, SIZE_OF_FLAGS, 1, inputfile[ict] ); 1464 1256 1465 1257 1466 // loop over the file … … 1259 1468 still_in_loop = TRUE; 1260 1469 1470 // FIXME --- check if not eof for all input reflector files 1471 1261 1472 while ( 1262 ((! Data_From_STDIN) && ( !feof(inputfile ) ))1473 ((! Data_From_STDIN) && ( !feof(inputfile[0]) )) 1263 1474 || 1264 1475 (Data_From_STDIN && still_in_loop) … … 1275 1486 else { // found start of run 1276 1487 1277 fread( flag_new, 4, 1, inputfile ); 1278 1279 if(!isA( flag_new, FLAG_START_OF_HEADER)){ 1280 1281 // We break the main loop 1282 cout<<"Warning: Expected start of run header flag, but found:"<<flag_new<<endl; 1283 cout<<" We break the main loop"<<endl; 1284 break; 1285 } 1286 1287 //Float_t flag_temp[SIZE_OF_MCRUNHEADER]; 1288 1289 //fread( flag_temp, (SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile ); 1290 fread((char*)&mcrunh,(SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile ); 1291 1292 nshow=0; 1293 1294 fread( flag, SIZE_OF_FLAGS, 1, inputfile ); 1295 while( isA( flag, FLAG_START_OF_EVENT )){ // while there is a next event 1296 fread( flag_new, 4, 1, inputfile ); 1297 1298 if(!isA( flag_new, FLAG_EVENT_HEADER)){ 1299 1300 // We break while events loop 1301 cout<<"Warning: Expected start of event header flag, but found:"<<flag_new<<endl; 1302 cout<<" We break the while events loop"<<endl; 1488 for(int ict=0;ict<ct_Number;ict++) { 1489 1490 fread( flag_new, 4, 1, inputfile[ict] ); 1491 1492 if(!isA( flag_new, FLAG_START_OF_HEADER)){ 1493 1494 // We break the main loop 1495 cout<<"Warning: Expected start of run header flag, but found:"<<flag_new<<endl; 1496 cout<<" We break the main loop"<<endl; 1303 1497 break; 1304 1498 } 1499 1500 fread((char*)&mcrunh,(SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile[ict] ); 1501 } 1502 1503 nshow=0; 1504 1505 for(int ict=0;ict<ct_Number;ict++){ 1506 fread( flag, SIZE_OF_FLAGS, 1, inputfile[ict] ); 1507 } 1508 while( isA( flag, FLAG_START_OF_EVENT )){ // while there is a next event 1509 for(int ict=0;ict<ct_Number;ict++) { 1510 fread( flag_new, 4, 1, inputfile[ict] ); 1511 if(!isA( flag_new, FLAG_EVENT_HEADER)){ 1512 1513 // We break while events loop 1514 cout<<"Warning: Expected start of event header flag, but found:"<<flag_new<<" "<<ict<<endl; 1515 cout<<" We break the while events loop"<<endl; 1516 break; 1517 } 1518 } 1519 1305 1520 1306 1521 // 1307 1522 // Clear Trigger and Fadc 1308 1523 // 1309 Trigger.Reset() ; 1310 Trigger.ClearFirst(); 1311 Trigger.ClearZero(); 1312 fadc.Reset() ; 1313 1524 for(int ict=0;ict<ct_Number;ict++) { 1525 Trigger_CT[ict]->Reset() ; 1526 Trigger_CT[ict]->ClearFirst(); 1527 Trigger_CT[ict]->ClearZero(); 1528 Fadc_CT[ict]->Reset() ; 1529 } 1530 1314 1531 ++nshow; 1315 1532 if((nshow+ntshow)%100 == 1) … … 1318 1535 // get MCEventHeader 1319 1536 if (reflector_file_version<6){ 1320 fread( (char*)&mcevth, mcevth.mysize(), 1, inputfile ); 1537 for(int ict=0;ict<ct_Number;ict++) 1538 fread( (char*)&mcevth, mcevth.mysize(), 1, inputfile[ict] ); 1321 1539 } 1322 1540 else{ 1323 fread( (char*)&mcevth_2, mcevth_2.mysize(), 1, inputfile ); 1541 for(int ict=0;ict<ct_Number;ict++) 1542 fread( (char*)&mcevth_2, mcevth_2.mysize(), 1, inputfile[ict] ); 1324 1543 } 1325 1544 … … 1461 1680 } 1462 1681 1463 // Read first and last time and put inumphe to 01682 // Read first and last time and put inumphe_CT[0] to 0 1464 1683 1465 1684 if (reflector_file_version<6) … … 1468 1687 mcevth_2.get_times(&arrtmin_ns,&arrtmax_ns); 1469 1688 1689 ncph_system=0; 1470 1690 inumphe=0; 1471 1691 1472 // read the photons and produce the photoelectrons 1473 1474 k = produce_phes( inputfile, 1475 &camgeom, 1476 WAVEBANDBOUND1, 1477 WAVEBANDBOUND6, 1478 &Trigger, // will be changed by the function! 1479 &fadc, // will be changed by the function! 1480 &inumphe, // important for later: the size of photoe[] 1481 fnpix, // will be changed by the function! 1482 &ncph, // will be changed by the function! 1483 &arrtmin_ns, // will be changed by the function! 1484 &arrtmax_ns); // will be changed by the function! 1485 1486 1487 if( k != 0 ){ // non-zero returnvalue means error 1488 cout << "Exiting.\n"; 1489 exit(1); 1692 for(int ict=0;ict<ct_Number;ict++){ 1693 1694 inumphe_CT[ict]=0; 1695 1696 // read the photons and produce the photoelectrons 1697 1698 k = produce_phes( inputfile[ict], 1699 ((MGeomCam*)(camgeom.UncheckedAt(ict))), 1700 WAVEBANDBOUND1, 1701 WAVEBANDBOUND6, 1702 Trigger_CT[ict], // will be changed by the function! 1703 Fadc_CT[ict], // will be changed by the function! 1704 &inumphe_CT[ict], // important for later: the size of photoe[] 1705 fnpix, // will be changed by the function! 1706 &ncph, // will be changed by the function! 1707 &arrtmin_ns, // will be changed by the function! 1708 &arrtmax_ns, // will be changed by the function! 1709 ict); 1710 1711 inumphe=(inumphe<inumphe_CT[ict])?inumphe_CT[ict]:inumphe; 1712 1713 if( k != 0 ){ // non-zero returnvalue means error 1714 cout << "Exiting.\n"; 1715 exit(1); 1716 } 1490 1717 } 1491 1718 1492 1719 // NSB simulation 1493 1720 … … 1516 1743 1517 1744 // Rottion of the NSB 1518 1519 k = size_rotated( 1520 &nsb_phepns_rotated[0], 1521 nsb_phepns, 1522 rho); 1745 // FIXME --- We should rotate for all cameras. Is it always the same rho? 1746 for(int ict=0;ict<ct_Number;ict++){ 1747 k = size_rotated( 1748 &nsb_phepns_rotated[ict][0], 1749 nsb_phepns[ict], 1750 rho); 1751 } 1752 } 1753 1754 // Fill trigger and fadc response in the trigger class from the database 1755 for(int ict=0;ict<ct_Number;ict++){ 1523 1756 1757 for(UInt_t ui=0;ui<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels();ui++) 1758 if(nsb_phepns_rotated[ict][ui]>0.0){ 1759 if((*((MGeomCam*)(camgeom.UncheckedAt(ict))))[ui].GetD()>(*((MGeomCam*)(camgeom.UncheckedAt(ict))))[0].GetD()){ 1760 k=lons_outer.GetResponse(nsb_phepns_rotated[ict][ui],0.01, 1761 & nsb_trigresp[0], 1762 & nsb_fadcresp[0]); 1763 } 1764 else{ 1765 k=lons.GetResponse(nsb_phepns_rotated[ict][ui],0.01, 1766 & nsb_trigresp[0],& nsb_fadcresp[0]); 1767 } 1768 if(k==0){ 1769 cout << "Exiting.\n"; 1770 exit(1); 1771 } 1772 Trigger_CT[ict]->AddNSB(ui,nsb_trigresp); 1773 Fadc_CT[ict]->AddSignal(ui,nsb_fadcresp); 1774 } 1524 1775 } 1525 1526 // Fill trigger and fadc response in the trigger class from the database 1527 for(UInt_t ui=0;ui<camgeom.GetNumPixels();ui++) 1528 if(nsb_phepns_rotated[ui]>0.0){ 1529 if(camgeom[ui].GetR()>camgeom[0].GetR()){ 1530 k=lons_outer.GetResponse(nsb_phepns_rotated[ui],0.1, 1531 & nsb_trigresp[0],& nsb_fadcresp[0]); 1532 } 1533 else{ 1534 k=lons.GetResponse(nsb_phepns_rotated[ui],0.1, 1535 & nsb_trigresp[0],& nsb_fadcresp[0]); 1536 } 1537 if(k==0){ 1538 cout << "Exiting.\n"; 1539 exit(1); 1540 } 1541 Trigger.AddNSB(ui,nsb_trigresp); 1542 fadc.AddSignal(ui,nsb_fadcresp); 1543 } 1544 }// end if(simulateNSB && nphe2NSB<=inumphe) ... 1776 1777 }// end if(simulateNSB && nphe2NSB<=inumphe_CT[0]) ... 1545 1778 1546 1779 inumphensb=0; 1547 for (UInt_t ui=0;ui<camgeom.GetNumPixels();ui++){ 1548 inumphensb+=nsb_phepns[ui]*TOTAL_TRIGGER_TIME; 1780 for (UInt_t ui=0;ui< 1781 ((MGeomCam*)(camgeom.UncheckedAt(0)))->GetNumPixels();ui++){ 1782 inumphensb+=nsb_phepns[0][ui]*TOTAL_TRIGGER_TIME; 1549 1783 } 1550 1551 ntcph+=ncph; 1784 ntcph+=ncph_system; 1552 1785 if ((nshow+ntshow)%100 == 1){ 1553 1786 log(SIGNATURE, "End of this event: %d cphs(+%d). . .\n", 1554 1787 ncph, ntcph); 1555 1788 1556 cout << "Total number of phes : " << inumphe<<" + ";1789 cout << "Total number of phes in CT 0: " << inumphe_CT[0]<<" + "; 1557 1790 cout<<inumphensb<<endl; 1558 1791 } … … 1600 1833 // 1601 1834 1602 if (addElecNoise && nphe2NSB<=inumphe){ 1603 Trigger.ElecNoise(Trigger_noise) ; 1835 for(int ict=0;ict<ct_Number;ict++) { 1836 if (addElecNoise && nphe2NSB<=inumphe){ 1837 1838 Trigger_CT[ict]->ElecNoise(Trigger_noise) ; 1604 1839 1605 fadc.ElecNoise(FADC_noise) ; 1840 Fadc_CT[ict]->ElecNoise(FADC_noise) ; 1841 } 1606 1842 } 1607 1843 1608 1844 // now a shift in the fadc signal due to the pedestlas is 1609 1845 // intorduced 1610 1846 // This is done inside the class MFadc by the method Pedestals 1611 fadc.Pedestals(); 1612 1847 for(int ict=0;ict<ct_Number;ict++) { 1848 Fadc_CT[ict]->Pedestals(); 1849 } 1850 1613 1851 // We study several trigger conditons 1614 1852 if(Trigger_Loop){ … … 1617 1855 btrigger=0; 1618 1856 flagstoring = 0; 1857 1619 1858 // Loop over trigger threshold 1620 1859 int iconcount; 1621 1860 for (iconcount=0, ithrescount=0, fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;ithrescount++, fthrescount+=Trigger_loop_sthres){ 1622 for (i=0;i< CAMERA_PIXELS;i++){1861 for (i=0;i<ct_NPixels;i++){ 1623 1862 fpixelthres[i]= 1624 ((Float_t)(fthrescount)>=qThreshold[ i])?1625 (Float_t)(fthrescount):qThreshold[ i];1863 ((Float_t)(fthrescount)>=qThreshold[0][i])? 1864 (Float_t)(fthrescount):qThreshold[0][i]; 1626 1865 1627 1866 // Rise the discrimnator threshold to avoid huge rates 1628 1867 1629 1868 if(riseDiskThres>0.0 && simulateNSB && nphe2NSB<=inumphe) 1630 for(int ii=0;ii< CAMERA_PIXELS;ii++)1631 if( nsb_phepns_rotated[ ii]>riseDiskThres)1869 for(int ii=0;ii<ct_NPixels;ii++) 1870 if( nsb_phepns_rotated[0][ii]>riseDiskThres) 1632 1871 fpixelthres[ii]=secureDiskThres; 1633 1872 } 1634 Trigger.SetThreshold(fpixelthres); 1635 1636 Trigger.Diskriminate(); 1873 Trigger_CT[0]->SetThreshold(fpixelthres); 1874 1875 Trigger_CT[0]->Diskriminate(); 1876 1877 1637 1878 // 1638 1879 // look if in all the signals in the trigger signal branch … … 1645 1886 1646 1887 // Set trigger flags to zero 1888 Lev0=0; 1647 1889 Lev1=0; 1648 1890 1649 1891 // loop over multiplicity of trigger configuration 1650 1892 for (imulticount=Trigger_loop_lmult;imulticount<=Trigger_loop_umult;imulticount++){ 1651 Trigger .SetMultiplicity(imulticount);1652 Trigger .ClearZero();1653 1654 Lev0=(Short_t) Trigger .ZeroLevel();1893 Trigger_CT[0]->SetMultiplicity(imulticount); 1894 Trigger_CT[0]->ClearZero(); 1895 1896 Lev0=(Short_t) Trigger_CT[0]->ZeroLevel(); 1655 1897 if (Lev0>0 || Write_All_Images || btrigger){ 1656 1898 … … 1664 1906 // if there are 3 or more N pixels. 1665 1907 if(imulticount<3) 1666 Trigger .SetTopology(1);1908 Trigger_CT[0]->SetTopology(1); 1667 1909 else 1668 1910 { 1669 1911 // We should be careful that topologies are sort from 1670 1912 // the less to the more restrictive one. 1671 Trigger .SetTopology(isorttopo[itopocount]);1913 Trigger_CT[0]->SetTopology(isorttopo[itopocount]); 1672 1914 } 1673 Trigger .ClearFirst();1915 Trigger_CT[0]->ClearFirst(); 1674 1916 1675 1917 // … … 1677 1919 // 1678 1920 if(Lev0!=0) 1679 Lev1=Trigger .FirstLevel();1921 Lev1=Trigger_CT[0]->FirstLevel(); 1680 1922 if(Lev1>0) { 1681 1923 btrigger= 1; … … 1694 1936 if (Write_McTrig){ 1695 1937 McTrig[iconcount]->SetFirstLevel ((ii+1)*Lev0); 1696 McTrig[iconcount]->SetTime(Trigger .GetFirstLevelTime(ii),ii+1);1697 Trigger .GetMapDiskriminator(trigger_map);1938 McTrig[iconcount]->SetTime(Trigger_CT[0]->GetFirstLevelTime(ii),ii+1); 1939 Trigger_CT[0]->GetMapDiskriminator(trigger_map); 1698 1940 McTrig[iconcount]->SetMapPixels(trigger_map,ii); 1699 1941 } … … 1702 1944 // 1703 1945 1704 fadc.TriggeredFadc(Trigger.GetFirstLevelTime(ii));1946 Fadc_CT[0]->TriggeredFadc(Trigger_CT[0]->GetFirstLevelTime(ii)); 1705 1947 1706 1948 if( Write_RawEvt ){ … … 1712 1954 // fill pixel information 1713 1955 if (Lev1){ 1714 for(UInt_t i=0;i<camgeom.GetNumPixels();i++){ 1956 for(UInt_t i=0; 1957 i<((MGeomCam*)(camgeom.UncheckedAt(0))) 1958 ->GetNumPixels();i++){ 1715 1959 for (j=0;j<FADC_SLICES;j++){ 1716 fadcValues->AddAt( fadc.GetFadcSignal(i,j),j);1717 fadcValuesLow->AddAt( fadc.GetFadcLowGainSignal(i,j),j);1960 fadcValues->AddAt(Fadc_CT[0]->GetFadcSignal(i,j),j); 1961 fadcValuesLow->AddAt(Fadc_CT[0]->GetFadcLowGainSignal(i,j),j); 1718 1962 } 1719 1963 EvtData[iconcount]->AddPixel(i,fadcValues,0); … … 1776 2020 (UInt_t)(mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot()), 1777 2021 (UInt_t) ncph, 1778 (UInt_t) inumphe ,1779 (UInt_t) inumphensb+inumphe ,2022 (UInt_t) inumphe_CT[0], 2023 (UInt_t) inumphensb+inumphe_CT[0], 1780 2024 -1.0, 1781 2025 -1.0, … … 1813 2057 (UInt_t)(mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot()), 1814 2058 (UInt_t) ncph, 1815 (UInt_t) inumphe ,1816 (UInt_t) inumphensb+inumphe ,2059 (UInt_t) inumphe_CT[0], 2060 (UInt_t) inumphensb+inumphe_CT[0], 1817 2061 mcevth_2.get_ElecFraction(), 1818 2062 mcevth_2.get_MuonFraction(), … … 1825 2069 // Clear the branches 1826 2070 if(Write_McTrig){ 1827 for(i=0;i< icontrigger;i++){2071 for(i=0;i<numberBranches;i++){ 1828 2072 McTrig[i]->Clear() ; 1829 2073 } 1830 2074 } 1831 2075 if( Write_RawEvt ){ 1832 for(i=0;i< icontrigger;i++){2076 for(i=0;i<numberBranches;i++){ 1833 2077 EvtHeader[i]->Clear() ; 1834 2078 EvtData[i]->DeletePixels(); … … 1842 2086 else { 1843 2087 1844 // Setting trigger conditions 1845 Trigger.SetMultiplicity(Trigger_multiplicity); 1846 Trigger.SetTopology(Trigger_topology); 1847 for (int i=0;i<CAMERA_PIXELS;i++) 1848 fpixelthres[i]=qThreshold[i]; 1849 1850 // Rise the discrimnator threshold to avoid huge rates 1851 if(riseDiskThres>0.0 && simulateNSB && nphe2NSB<=inumphe) 1852 for(int ii=0;ii<CAMERA_PIXELS;ii++){ 1853 if( nsb_phepns_rotated[ii]>riseDiskThres) 1854 fpixelthres[ii]=secureDiskThres; 2088 // Set to zero the flag to know if some conditon has triggered 2089 btrigger=0; 2090 flagstoring = 0; 2091 2092 for(int ict=0;ict<ct_Number;ict++){ 2093 2094 // Setting trigger conditions 2095 Trigger_CT[ict]->SetMultiplicity(Trigger_multiplicity[ict]); 2096 Trigger_CT[ict]->SetTopology(Trigger_topology[ict]); 2097 for (int i=0;i<ct_NPixels;i++) 2098 fpixelthres[i]=qThreshold[ict][i]; 2099 2100 // Rise the discrimnator threshold to avoid huge rates 2101 if(riseDiskThres>0.0 && simulateNSB && nphe2NSB<=inumphe) 2102 for(int ii=0;ii<ct_NPixels;ii++){ 2103 if( nsb_phepns_rotated[ict][ii]>riseDiskThres) 2104 fpixelthres[ii]=secureDiskThres; 2105 } 2106 2107 Trigger_CT[ict]->SetThreshold(fpixelthres); 2108 2109 Trigger_CT[ict]->Diskriminate() ; 2110 2111 // 2112 // look if in all the signals in the trigger signal branch 2113 // is a possible Trigger. Therefore we habe to diskriminate all 2114 // the simulated analog signals (Method Diskriminate in class 2115 // MTrigger). We look simultanously for the moments at which 2116 // there are more than TRIGGER_MULTI pixels above the 2117 // CHANNEL_THRESHOLD. 2118 // 2119 2120 Lev0MT[ict] = (Short_t) Trigger_CT[ict]->ZeroLevel() ; 2121 2122 Lev1MT[ict] = 0 ; 2123 2124 // 2125 // Start the First Level Trigger simulation 2126 // 2127 2128 if ( Lev0MT[ict] > 0 || Write_All_Images) { 2129 Lev1MT[ict]= Trigger_CT[ict]->FirstLevel(); 1855 2130 } 1856 1857 Trigger.SetThreshold(fpixelthres); 1858 1859 Trigger.Diskriminate() ; 1860 1861 // 1862 // look if in all the signals in the trigger signal branch 1863 // is a possible Trigger. Therefore we habe to diskriminate all 1864 // the simulated analog signals (Method Diskriminate in class 1865 // MTrigger). We look simultanously for the moments at which 1866 // there are more than TRIGGER_MULTI pixels above the 1867 // CHANNEL_THRESHOLD. 1868 // 1869 1870 Lev0 = (Short_t) Trigger.ZeroLevel() ; 1871 1872 Lev1 = 0 ; 1873 1874 // 1875 // Start the First Level Trigger simulation 1876 // 1877 1878 if ( Lev0 > 0 || Write_All_Images) { 1879 Lev1= Trigger.FirstLevel(); 2131 if (Lev1MT[ict]>0){ 2132 ++ntrigger[ict]; 2133 } 1880 2134 } 1881 if (Lev1>0){ 1882 ++ntrigger; 2135 2136 Int_t NumImages = 0; 2137 Int_t CT_triggered=0; 2138 for(int ict=0;ict<ct_Number;ict++){ 2139 if(NumImages==0 && Lev1MT[ict]>0) 2140 CT_triggered=ict; 2141 NumImages = (NumImages>=Lev1MT[ict])?NumImages:1; 2142 Lev0MT[ict]=1; 2143 if (Lev1MT[ict]==0 && Write_All_Images){ 2144 NumImages=1; 2145 Lev0MT[ict]=0; 2146 } 1883 2147 } 1884 Int_t NumImages = Lev1; 1885 Lev0=1; 1886 if (Lev1==0 && Write_All_Images){ 1887 NumImages=1; 1888 Lev0=0; 1889 } 1890 1891 for(Int_t ii=0;ii<NumImages;ii++){ 1892 // Loop over different level one triggers 1893 2148 2149 for(int ict=0;ict<ct_Number;ict++){ 2150 for(Int_t ii=0;ii<NumImages;ii++){ 2151 2152 btrigger=1; 2153 2154 // Loop over different level one triggers 2155 2156 // 2157 // fill inside class fadc the member output 2158 // 2159 if(Lev1MT[ict]>0) 2160 Fadc_CT[ict]-> 2161 TriggeredFadc(Trigger_CT[ict]->GetFirstLevelTime(ii)); 2162 else 2163 Fadc_CT[ict]-> 2164 TriggeredFadc(Trigger_CT[CT_triggered]->GetFirstLevelTime(ii)); 2165 2166 if(!flagstoring) 2167 nstoredevents++; 2168 flagstoring = 1; 2169 2170 if (Write_McTrig){ 2171 McTrig[ict]->SetFirstLevel (Lev1MT[ict]); 2172 McTrig[ict] 2173 ->SetTime(Trigger_CT[ict]->GetFirstLevelTime(ii),ii+1); 2174 Trigger_CT[ict]->GetMapDiskriminator(trigger_map); 2175 McTrig[ict]->SetMapPixels(trigger_map,ii); 2176 } 2177 2178 // Fill Evt information 2179 2180 if (Write_RawEvt){ 2181 2182 // 2183 // Fill the header of this event 2184 // 2185 2186 EvtHeader[ict] 2187 ->FillHeader ( (UInt_t) (ntshow + nshow) , 20 ) ; 2188 2189 // fill pixel information 2190 2191 if (Lev1MT[ict]){ 2192 for(UInt_t i=0; 2193 i<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels(); 2194 i++){ 2195 for (j=0;j<FADC_SLICES;j++){ 2196 fadcValues->AddAt(Fadc_CT[ict]->GetFadcSignal(i,j),j); 2197 fadcValuesLow->AddAt(Fadc_CT[ict]->GetFadcLowGainSignal(i,j),j); 2198 } 2199 EvtData[ict]->AddPixel(i,fadcValues,0); 2200 EvtData[ict]->AddPixel(i,fadcValuesLow,kTRUE); 2201 } 2202 } 2203 } 2204 } 1894 2205 // 1895 // fill inside class fadc the member output 1896 // 1897 fadc.TriggeredFadc(Trigger.GetFirstLevelTime(ii)); 1898 1899 nstoredevents++; 1900 1901 if (Write_McTrig){ 1902 McTrig[0]->SetFirstLevel ((ii+1)*Lev0); 1903 McTrig[0]->SetTime(Trigger.GetFirstLevelTime(ii),ii+1); 1904 Trigger.GetMapDiskriminator(trigger_map); 1905 McTrig[0]->SetMapPixels(trigger_map,ii); 2206 // if a first level trigger occurred, then 2207 // 1. do some other stuff (not implemented) 2208 // 2. start the gui tool 2209 2210 if(FADC_Scan){ 2211 if ( Lev0MT[ict] > 0 ) { 2212 Fadc_CT[ict]->ShowSignal( McEvt, (Float_t) 60. ) ; 2213 } 1906 2214 } 1907 1908 // Fill Evt information 1909 1910 if (Write_RawEvt){ 1911 1912 // 1913 // Fill the header of this event 1914 // 2215 2216 if(Trigger_Scan){ 2217 if ( Lev0MT[ict] > 0 ) { 2218 Trigger_CT[ict]->ShowSignal(McEvt) ; 2219 } 2220 } 1915 2221 1916 EvtHeader[0]->FillHeader ( (UInt_t) (ntshow + nshow) , 20 ) ; 1917 1918 // fill pixel information 1919 1920 if (Lev1){ 1921 for(UInt_t i=0;i<camgeom.GetNumPixels();i++){ 1922 for (j=0;j<FADC_SLICES;j++){ 1923 fadcValues->AddAt(fadc.GetFadcSignal(i,j),j); 1924 fadcValuesLow->AddAt(fadc.GetFadcLowGainSignal(i,j),j); 1925 } 1926 EvtData[0]->AddPixel(i,fadcValues,0); 1927 EvtData[0]->AddPixel(i,fadcValuesLow,kTRUE); 1928 } 1929 } 1930 } 2222 } // end CT loop 2223 2224 // If there is trigger in some telecope or we store all showers 2225 if(btrigger){ 1931 2226 // 1932 2227 // fill the MMcEvt with all information … … 1964 2259 (UInt_t)(mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot()), 1965 2260 (UInt_t) ncph, 1966 (UInt_t) inumphe ,1967 (UInt_t) inumphensb+inumphe ,2261 (UInt_t) inumphe_CT[0], 2262 (UInt_t) inumphensb+inumphe_CT[0], 1968 2263 -1.0, 1969 2264 -1.0, … … 2001 2296 (UInt_t) (mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot()), 2002 2297 (UInt_t) ncph, 2003 (UInt_t) inumphe ,2004 (UInt_t) inumphensb+inumphe ,2298 (UInt_t) inumphe_CT[0], 2299 (UInt_t) inumphensb+inumphe_CT[0], 2005 2300 mcevth_2.get_ElecFraction(), 2006 2301 mcevth_2.get_MuonFraction(), … … 2009 2304 } 2010 2305 // We don not count photons out of the camera. 2011 2306 2012 2307 2013 2308 // … … 2016 2311 2017 2312 EvtTree.Fill() ; 2018 2019 // 2020 // if a first level trigger occurred, then 2021 // 1. do some other stuff (not implemented) 2022 // 2. start the gui tool 2313 } 2023 2314 2024 if(FADC_Scan){ 2025 if ( Lev0 > 0 ) { 2026 fadc.ShowSignal( McEvt, (Float_t) 60. ) ; 2027 } 2028 } 2029 2030 if(Trigger_Scan){ 2031 if ( Lev0 > 0 ) { 2032 Trigger.ShowSignal(McEvt) ; 2033 } 2034 } 2035 2036 // clear all 2037 if (Write_RawEvt) EvtHeader[0]->Clear() ; 2038 if (Write_RawEvt) EvtData[0]->DeletePixels(); 2039 if (Write_McEvt) McEvt->Clear() ; 2315 // clear all 2316 for(int ict=0;ict<ct_Number;ict++){ 2317 if (Write_RawEvt) EvtHeader[ict]->Clear() ; 2318 if (Write_RawEvt) EvtData[ict]->DeletePixels(); 2319 if (Write_McTrig) McTrig[ict]->Clear() ; 2040 2320 } 2041 if (Write_Mc Trig) McTrig[0]->Clear() ;2321 if (Write_McEvt) McEvt->Clear() ; 2042 2322 } 2043 2323 … … 2064 2344 } 2065 2345 2066 for (int i=0; i<camgeom.GetNumPixels(); ++i) { 2346 for (int i=0; 2347 i<((MGeomCam*)(camgeom.UncheckedAt(0)))->GetNumPixels(); ++i) { 2067 2348 printf("%d (%d): ", i, npixneig[i]); 2068 2349 for (j=0; j<npixneig[i]; ++i) … … 2073 2354 #endif // __DEBUG__ 2074 2355 2356 2357 // We search the maximum impact parameter fo the simualted showers 2358 maxpimpact=maxpimpact<impactD?impactD:maxpimpact; 2075 2359 2076 2360 // look for the next event 2077 2361 2078 fread( flag, SIZE_OF_FLAGS, 1, inputfile ); 2362 for(int ict=0;ict<ct_Number;ict++) 2363 fread( flag, SIZE_OF_FLAGS, 1, inputfile[ict] ); 2079 2364 2080 2365 } // end while there is a next event … … 2088 2373 log(SIGNATURE, "End of this run with %d events . . .\n", nshow); 2089 2374 2090 fread( flag, SIZE_OF_FLAGS, 1, inputfile ); 2375 //fread( flag, SIZE_OF_FLAGS, 1, inputfile ); 2376 for(int ict=0;ict<ct_Number;ict++) 2377 fread( flag, SIZE_OF_FLAGS, 1, inputfile[ict] ); 2091 2378 2092 2379 if( isA( flag, FLAG_END_OF_FILE ) ){ // end of file … … 2094 2381 still_in_loop = FALSE; 2095 2382 log(SIGNATURE, "Reading ASCII files at the end of the reflector file. . .\n"); 2096 read_ascii(inputfile, McConfigRunHeader); 2097 //break; 2098 if ((! Data_From_STDIN) && ( !feof(inputfile) )){ 2383 for(int ict=0;ict<ct_Number;ict++){ 2384 read_ascii(inputfile[ict], McConfigRunHeader[ict]); 2385 } 2386 if ((! Data_From_STDIN) && ( !feof(inputfile[0]) )){ 2099 2387 2100 2388 // we have concatenated input files. 2101 2389 // get signature of the next part and check it. 2102 2390 2103 if((reflector_file_version=check_reflector_file( inputfile ))==FALSE){ 2104 // exit(1); 2391 if((reflector_file_version=check_reflector_file( inputfile[0] ))==FALSE){ 2105 2392 log(SIGNATURE, "Next file is not recognised as a reflector file.\n"); 2106 2393 log(SIGNATURE, "Stopping ...\n"); … … 2109 2396 2110 2397 } 2111 2112 fread( flag, SIZE_OF_FLAGS, 1, inputfile ); 2398 2399 for(int ict=0;ict<ct_Number;ict++) 2400 fread( flag, SIZE_OF_FLAGS, 1, inputfile[ict] ); 2113 2401 2114 2402 } // end if found end of file … … 2124 2412 Float_t ftime; 2125 2413 Float_t rnum; 2414 Float_t viewcone[2]={0,0}; 2126 2415 2127 2416 get_starfield_center(&sfRaH,&sfRaM,&sfRaS,&sfDeD,&sfDeM,&sfDeS); … … 2147 2436 heights[i]=mcevth_2.get_HeightLev (i); 2148 2437 rnum=mcevth_2.get_RunNumber(); 2438 mcevth_2.get_viewcone(&viewcone[0],&viewcone[1]); 2149 2439 } 2150 2440 … … 2166 2456 Write_RawEvt, 2167 2457 addElecNoise, 2168 CAMERA_PIXELS,2458 ct_NPixels, 2169 2459 (UInt_t)ntshow, 2170 2460 (UInt_t)nstoredevents, … … 2185 2475 shphimax, 2186 2476 shphimin, 2477 maxpimpact, 2187 2478 mcevth.get_CWaveLower(), 2188 2479 mcevth.get_CWaveUpper(), … … 2206 2497 Write_RawEvt, 2207 2498 addElecNoise, 2208 CAMERA_PIXELS,2499 ct_NPixels, 2209 2500 (UInt_t)ntshow, 2210 2501 (UInt_t)nstoredevents, … … 2225 2516 shphimax, 2226 2517 shphimin, 2518 maxpimpact, 2227 2519 mcevth_2.get_CWaveLower(), 2228 2520 mcevth_2.get_CWaveUpper(), … … 2257 2549 Float_t constantNFL[4]; 2258 2550 mcrunh.get_constantNFL(&constantNFL[0]); 2259 2551 2260 2552 if(reflector_file_version>5) 2261 2553 McCorsikaRunHeader->Fill(rnum, … … 2281 2573 constantCATM, 2282 2574 constantNFL, 2575 viewcone, 2283 2576 mcrunh.get_wobble(), 2284 2577 mcrunh.get_atmophere() 2285 ); 2286 2287 // Store qe for each PMT in output file 2288 TArrayF qe_pmt; 2289 TArrayF wav_pmt; 2290 McConfigRunHeader->InitSizePMTs(ct_NPixels); 2291 for(int i=0; i<ct_NPixels;i++){ 2292 McConfigRunHeader->AddPMT(i); 2293 MGeomPMT &pmt = McConfigRunHeader->GetPMT(i); 2294 qe_pmt.Set(pointsQE,QE[i][1]); 2295 wav_pmt.Set(pointsQE,QElambda); 2296 pmt.SetArraySize(pointsQE); 2297 pmt.SetPMTContent(i,wav_pmt,qe_pmt); 2298 } 2299 2300 // Store Light Guides factors in the output file 2301 TArrayF theta_lg; 2302 TArrayF factor_lg; 2303 theta_lg.Set(pointsWC,WC[0]); 2304 factor_lg.Set(pointsWC,WC[1]); 2305 McConfigRunHeader->SetLightGuides(theta_lg,factor_lg); 2578 ); 2579 2580 // Store qe for each PMT in output file 2581 TArrayF qe_pmt; 2582 TArrayF wav_pmt; 2583 2584 for(int ict=0;ict<ct_Number;ict++){ 2585 McConfigRunHeader[ict]->InitSizePMTs(ct_NPixels); 2586 for(int i=0; i<(Int_t)((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels();i++){ 2587 McConfigRunHeader[ict]->AddPMT(i); 2588 MGeomPMT &pmt = McConfigRunHeader[ict]->GetPMT(i); 2589 qe_pmt.Set(pointsQE[ict],QE[ict][i][1]); 2590 wav_pmt.Set(pointsQE[ict],QElambda); 2591 pmt.SetArraySize(pointsQE[ict]); 2592 pmt.SetPMTContent(i,wav_pmt,qe_pmt); 2593 } 2594 2595 // Store Light Guides factors in the output file 2596 TArrayF theta_lg; 2597 TArrayF factor_lg; 2598 theta_lg.Set(pointsWC,WC[0]); 2599 factor_lg.Set(pointsWC,WC[1]); 2600 McConfigRunHeader[ict]->SetLightGuides(theta_lg,factor_lg); 2601 2602 } 2306 2603 2307 2604 // Fill the Header Tree with the current leaves of each branch … … 2336 2633 } 2337 2634 else{ 2338 log( SIGNATURE, "Fraction of triggers: %5.1f%% (%d out of %d)\n", 2339 ((float)ntrigger) / ((float)ntshow) * 100.0, ntrigger, ntshow); 2340 datafile<<"Fraction of triggers: "<<((float)ntrigger) / ((float)ntshow) * 100.0<<" ("<<ntrigger<<" out of "<<ntshow<<" )"<<endl; 2635 for(int ict=0;ict<ct_Number;ict++){ 2636 log( SIGNATURE, "Fraction of triggers: %5.1f%% (%d out of %d)\n", 2637 ((float)ntrigger[ict]) / ((float)ntshow) * 100.0, ntrigger[ict], ntshow); 2638 datafile<<"Fraction of triggers: "<<((float)ntrigger[ict]) / ((float)ntshow) * 100.0<<" ("<<ntrigger[ict]<<" out of "<<ntshow<<" )"<<endl; 2639 } 2341 2640 } 2342 2641 … … 2346 2645 2347 2646 if( ! Data_From_STDIN ){ 2348 fclose( inputfile ); 2647 for(int ict=0;ict<ct_Number;ict++) 2648 fclose( inputfile[ict] ); 2349 2649 } 2350 2650 datafile.close(); … … 2740 3040 //!@{ 2741 3041 void 2742 read_QE(char fname[256] ){3042 read_QE(char fname[256], int ict){ 2743 3043 ifstream qefile; 2744 3044 char line[LINE_MAX_LENGTH]; … … 2784 3084 // get the number of datapoints 2785 3085 2786 sscanf(line, "%d", &pointsQE );3086 sscanf(line, "%d", &pointsQE[ict]); 2787 3087 2788 3088 // allocate memory for the table of QEs 2789 3089 2790 QE = new float ** [ct_NPixels];3090 QE[ict] = new float ** [ct_NPixels]; 2791 3091 2792 3092 for ( i=0; i<ct_NPixels; ++i ) { 2793 QE[i ] = new float * [2];2794 QE[i ][0] = new float[pointsQE];2795 QE[i ][1] = new float[pointsQE];3093 QE[ict][i] = new float * [2]; 3094 QE[ict][i][0] = new float[pointsQE[ict]]; 3095 QE[ict][i][1] = new float[pointsQE[ict]]; 2796 3096 } 2797 3097 2798 QElambda = new float [pointsQE ];2799 2800 for ( i=0; i<pointsQE ; ++i ) {3098 QElambda = new float [pointsQE[ict]]; 3099 3100 for ( i=0; i<pointsQE[ict]; ++i ) { 2801 3101 qefile.getline(line, LINE_MAX_LENGTH); 2802 3102 sscanf(line, "%f", &QElambda[i]); … … 2814 3114 2815 3115 if ( ((i-1) < ct_NPixels) && ((i-1) > -1) && 2816 ((j-1) < pointsQE ) && ((j-1) > -1) ) {2817 QE[i -1][0][j-1] = QElambda[j-1];2818 QE[i -1][1][j-1] = qe;3116 ((j-1) < pointsQE[ict]) && ((j-1) > -1) ) { 3117 QE[ict][i-1][0][j-1] = QElambda[j-1]; 3118 QE[ict][i-1][1][j-1] = qe; 2819 3119 } 2820 3120 … … 2825 3125 } 2826 3126 2827 if(icount/pointsQE < ct_NPixels){3127 if(icount/pointsQE[ict] < ct_NPixels){ 2828 3128 error( "read_QE", "The quantum efficiency file is faulty\n (found only %d pixels instead of %d).\n", 2829 icount/pointsQE , ct_NPixels );3129 icount/pointsQE[ict], ct_NPixels ); 2830 3130 } 2831 3131 … … 2837 3137 2838 3138 for(icount=0; icount< ct_NPixels; icount++){ 2839 for(i=0; i<pointsQE ; i++){2840 if( QE[ic ount][0][i] < 100. || QE[icount][0][i] > 1000. ||2841 QE[ic ount][1][i] < 0. || QE[icount][1][i] > 100.){3139 for(i=0; i<pointsQE[ict]; i++){ 3140 if( QE[ict][icount][0][i] < 100. || QE[ict][icount][0][i] > 1000. || 3141 QE[ict][icount][1][i] < 0. || QE[ict][icount][1][i] > 100.){ 2842 3142 error( "read_QE", "The quantum efficiency file is faulty\n pixel %d, point %d is % f, %f\n", 2843 icount, i, QE[ic ount][0][i], QE[icount][1][i] );3143 icount, i, QE[ict][icount][0][i], QE[ict][icount][1][i] ); 2844 3144 } 2845 3145 } … … 2928 3228 read_pixels(struct camera *pcam) 2929 3229 { 2930 ifstream qefile;3230 /* ifstream qefile; 2931 3231 char line[LINE_MAX_LENGTH]; 2932 3232 int n, i, j, icount; … … 3103 3403 3104 3404 log("read_pixels", "Done.\n"); 3105 3405 */ 3106 3406 } 3107 3407 //!@} … … 3148 3448 fgets(line,500,sp); 3149 3449 sscanf(line,"%i",&numref); 3450 TArrayF wavarray(numref); 3451 TArrayF refarray(numref); 3452 fgets(line,500,sp); 3150 3453 for(int i=0; i<numref;i++){ 3151 3454 fgets(line,500,sp); 3152 3455 sscanf(line,"%f %f",&wav,&ref); 3456 wavarray[i]=wav; 3457 refarray[i]=ref; 3458 } 3459 for (int j=0; j<nummir;j++){ 3460 MGeomMirror &mirror = config->GetMirror(j); 3461 mirror.SetArraySize(numref); 3462 mirror.SetReflectivity(wavarray, refarray); 3153 3463 } 3154 3464 continue; … … 3533 3843 #define sqrt3 1.732050807 // = sqrt(3.) 3534 3844 3535 int bpoint_is_in_pix(double dx, double dy, MGeomCam Magic*pgeomcam)3845 int bpoint_is_in_pix(double dx, double dy, MGeomCam *pgeomcam) 3536 3846 { 3537 3847 /* return TRUE if point (dx, dy) is in pixel number ipixnum, else return FALSE (use camera coordinate system) */ … … 3548 3858 { 3549 3859 MGeomPix &pixel = (*pgeomcam)[i]; 3550 const double b = pixel.Get R()/2;3551 const double a = pixel.Get R()/sqrt3;3860 const double b = pixel.GetD()/2; 3861 const double a = pixel.GetD()/sqrt3; 3552 3862 3553 3863 const double xx = dx - pixel.GetX(); 3554 3864 const double yy = dy - pixel.GetY(); 3555 3865 3556 3866 if(((-b <= xx) && (xx <= 0.) && ((-sqrt13 * xx - a) <= yy) && (yy <= ( sqrt13 * xx + a))) || 3557 3867 ((0. < xx) && (xx <= b ) && (( sqrt13 * xx - a) <= yy) && (yy <= (-sqrt13 * xx + a))) ){ … … 3761 4071 3762 4072 int produce_phes( FILE *sp, // the input file 3763 class MGeomCam Magic*camgeom, // the camera layout4073 class MGeomCam *camgeom, // the camera layout 3764 4074 float minwl_nm, // the minimum accepted wavelength 3765 4075 float maxwl_nm, // the maximum accepted wavelength … … 3770 4080 int *incph, // total number of cph read 3771 4081 float *tmin_ns, // minimum arrival time of all phes 3772 float *tmax_ns // maximum arrival time of all phes 4082 float *tmax_ns, // maximum arrival time of all phes 4083 int ict // Telescope that is being analised to get the right QE. 3773 4084 ){ 3774 4085 … … 3866 4177 // set pointer to the QE table of the relevant pixel 3867 4178 3868 qept = (float **)QE[i pixnum];4179 qept = (float **)QE[ict][ipixnum]; 3869 4180 3870 4181 // check if wl is inside table; outside the table, QE is assumed to be zero 3871 4182 3872 if((wl < qept[0][0]) || (wl > qept[0][pointsQE -1])){4183 if((wl < qept[0][0]) || (wl > qept[0][pointsQE[ict]-1])){ 3873 4184 continue; 3874 4185 … … 3878 4189 3879 4190 k = 1; // start at 1 because the condition was already tested for 0 3880 while (k < pointsQE -1 && qept[0][k] < wl){4191 while (k < pointsQE[ict]-1 && qept[0][k] < wl){ 3881 4192 k++; 3882 4193 } … … 3923 4234 fadc->Fill(ipixnum,(t-*tmin_ns) , 3924 4235 trigger->FillShow(ipixnum,t-*tmin_ns), 3925 !((*camgeom)[ipixnum].Get R()>(*camgeom)[0].GetR()));4236 !((*camgeom)[ipixnum].GetD()>(*camgeom)[0].GetD())); 3926 4237 3927 4238 *itotnphe += 1; … … 3944 4255 3945 4256 int produce_nsbrates( char *iname, // the starfield input file name 3946 MGeomCam Magic*camgeom, // camera layout3947 float rate_phepns[iMAXNUMPIX][iNUMWAVEBANDS] // the product of this function:4257 MGeomCam *camgeom, // camera layout 4258 float rate_phepns[iMAXNUMPIX][iNUMWAVEBANDS], // the product of this function: 3948 4259 // the NSB rates in phe/ns for each pixel 4260 int ict 3949 4261 ){ 3950 4262 … … 3952 4264 int k, ii; // counters 3953 4265 3954 MTrigger trigger( Trigger_gate_length, Trigger_overlaping_time, Trigger_response_ampl, Trigger_response_fwhm);4266 MTrigger trigger(397,camgeom,Trigger_gate_length, Trigger_overlaping_time, Trigger_response_ampl, Trigger_response_fwhm); 3955 4267 MFadc flashadc; 3956 4268 3957 4269 static float wl_nm[iNUMWAVEBANDS + 1] = { WAVEBANDBOUND1, 3958 4270 WAVEBANDBOUND2, … … 4100 4412 &incph, 4101 4413 &tmin_ns, 4102 &tmax_ns 4414 &tmax_ns, 4415 0 4103 4416 ); // photons from starfield 4104 4417 … … 4269 4582 // 4270 4583 // $Log: not supported by cvs2svn $ 4584 // Revision 1.57 2003/07/17 18:02:46 blanch 4585 // Several new features introduced as well as fixed bugs 4586 // 4587 // - 1/100 events printed out 4588 // - Low gain implemented 4589 // - Different response for outer and inner pixels 4590 // - Some warnings removed 4591 // - pedestal and qe file from inpuit card 4592 // - Faster electronic simulation 4593 // 4271 4594 // Revision 1.55 2003/02/12 12:22:10 blanch 4272 4595 // *** empty log message *** … … 4436 4759 // is used. 4437 4760 // 4438 // Revision 1.12 2000/09/22 17:40:18 harald4439 // Added a lot of changes done by oscar.4440 //4441 // Revision 1.11 2000/09/21 11:47:33 harald4442 // Oscar found some smaller errors in the calculation of the pixel shape and4443 // corrected it.4444 //4445 // $Log: not supported by cvs2svn $4446 // Revision 1.55 2003/02/12 12:22:10 blanch4447 // *** empty log message ***4448 //4449 // Revision 1.54 2003/02/12 11:55:01 blanch4450 // *** empty log message ***4451 //4452 // Revision 1.53 2003/01/23 18:35:21 blanch4453 // *** empty log message ***4454 //4455 // Revision 1.52 2003/01/20 17:19:20 blanch4456 // It fills the MMcCorsikaRun.4457 //4458 // Revision 1.51 2003/01/14 13:40:17 blanch4459 // MRawRunHeader::fNumEvents has been filled with the number of events in4460 // this file.4461 // Problems in fImpact computation have been solved.4462 // Option to set a dc value to rise the discriminator threshold has been added.4463 //4464 // Revision 1.50 2003/01/07 16:33:31 blanch4465 // Star Field Rotation has been implemented by Raul Orduna. Now there is a4466 // rotation for each shower. It is done by a non enter pixel rotation assuming4467 // a circular symetry of the camera. It is not exact but it is accurate enough and4468 // much faster.4469 //4470 // Revision 1.49 2002/12/13 10:04:07 blanch4471 // *** empty log message ***4472 //4473 // Revision 1.48 2002/12/12 17:40:50 blanch4474 // *** empty log message ***4475 //4476 // Revision 1.47 2002/12/10 17:19:31 blanch4477 // *** empty log message ***4478 //4479 // Revision 1.46 2002/11/08 17:51:00 blanch4480 // *** empty log message ***4481 //4482 // Revision 1.45 2002/10/29 17:15:27 blanch4483 // Reading several reflector versions.4484 //4485 // Revision 1.44 2002/10/18 16:53:03 blanch4486 // Modification to read several reflector files.4487 //4488 // Revision 1.43 2002/09/13 10:53:39 blanch4489 // Minor change to remove some undisired comments.4490 //4491 // Revision 1.42 2002/09/09 16:00:49 blanch4492 // Statement has been included to avoid writting to disk MParContainer and MArray.4493 // It has also been added the effect of the WC, the actual values must be added,4494 // once they are measured.4495 //4496 // Revision 1.41 2002/09/04 09:57:42 blanch4497 // Modifications done to use MGeomCam from MARS.4498 //4499 // Revision 1.40 2002/07/16 16:15:22 blanch4500 // A first implementation of the Star field rotation has been done.4501 //4502 // Revision 1.39 2002/04/27 10:48:39 blanch4503 // Some unused varibles have been removed.4504 //4505 // Revision 1.38 2002/03/18 18:44:29 blanch4506 // Small modificatin to set the electronic Noise in the MMcTrigHeader class.4507 //4508 // Revision 1.37 2002/03/18 16:42:20 blanch4509 // The data member fProductionSite of the MMcRunHeader has been set to 0,4510 // which means that the prodution site is unknown.4511 //4512 // Revision 1.35 2002/03/15 15:15:52 blanch4513 // Several modifications to simulate the actual trigger zone.4514 //4515 // Revision 1.34 2002/03/13 18:13:56 blanch4516 // Some changes to fill correctly the new format of MMcRunHeader.4517 //4518 // Revision 1.33 2002/03/04 17:21:48 blanch4519 // Small and not important changes.4520 //4521 // Revision 1.32 2002/02/28 15:04:52 blanch4522 // A small back has been solved. Before, while not using the option4523 // writte_all_images, not all triggered showers were stored. Now it is solved.4524 // For that it is importatn taht the less restrictive trigger option is4525 // checked first.4526 // A new facility has been introduced and now one can choose the step size in4527 // trigger loop mode for the discriminator threshold.4528 // The close-compact topology for less than 3 pixels does not make sense. Before4529 // the program was ignoring that, now it switch to simple neighbour condition.4530 //4531 // Revision 1.31 2002/01/18 17:41:02 blanch4532 // The option of adding noise to all pixels or to not adding the noise4533 // has been added.4534 // We removed the pixels larger than 577. When there were more than one4535 // trigger in one shower, the pixel number was increasing. Now it is4536 // flagged by the variable MMcTrig::fFirstLvlTrig.4537 //4538 // Revision 1.30 2001/11/27 09:49:54 blanch4539 // Fixing bug which was treating wrongly the extension of star photons.4540 //4541 // Revision 1.29 2001/11/14 17:38:23 blanch4542 // Sveral changes have been done:4543 // - bpoint_in_in_pixel has been dodified to speed up the program4544 // - Some minor changes have been done to remove warnings4545 // - buffer size and split version of the Branches have been removed4546 // - Some modifications were needed to adat the program to the new4547 // MRawEvtData::DeletePixels4548 //4549 // Revision 1.28 2001/10/26 16:31:45 blanch4550 // Removing several warnings.4551 //4552 // Revision 1.27 2001/09/05 10:04:33 blanch4553 // *** empty log message ***4554 //4555 // Revision 1.26 2001/07/19 09:29:53 blanch4556 // Different threshold for each pixel can be used.4557 //4558 // Revision 1.25 2001/05/08 08:07:54 blanch4559 // New numbering for branches from different trigger conditions has been4560 // implemented. Now, they are calles: ClassName;1., ClasNema;2., ...4561 // The MontaCarlo Headers (MMcTrigHeader and MMcFadcHeader) have been move to4562 // the RunHeaders tree. Also the MRawRunHeader is thera with some of its4563 // information already filled.4564 //4565 // Revision 1.24 2001/04/06 16:48:09 magicsol4566 // New camera version able to read the new format of the reflector output:4567 // reflector 0.44568 //4569 // Revision 1.23 2001/03/28 16:13:41 blanch4570 // While feeling the MMcFadeHeader branch the boolean conditoin was wrong. It has4571 // been solved.4572 //4573 // Revision 1.22 2001/03/20 18:52:43 blanch4574 // *** empty log message ***4575 //4576 // Revision 1.21 2001/03/19 19:53:03 blanch4577 // Some print outs have been removed.4578 //4579 // Revision 1.20 2001/03/19 19:30:06 magicsol4580 // Minor changes have been done to improve the FADC pedestals treatment.4581 //4582 // Revision 1.19 2001/03/05 11:14:41 magicsol4583 // I changed the position of readinf a parameter. It is a minnor change.4584 //4585 // Revision 1.18 2001/03/05 10:36:52 blanch4586 // A branch with information about the FADC simulation (MMcFadcHeader) is writen4587 // in the McHeaders tree of the aoutput root file.4588 // The NSB contribution is only applied if the the number of phe form the shower4589 // are above a given number.4590 //4591 // Revision 1.17 2001/02/23 11:05:57 magicsol4592 // Small changes due to slightly different output format and the introduction of4593 // pedesals for teh FADC.4594 //4595 // Revision 1.16 2001/01/18 18:44:40 magicsol4596 // *** empty log message ***4597 //4598 // Revision 1.15 2001/01/17 09:32:27 harald4599 // The changes are neccessary to have the same name for trees in MC and in4600 // data. So now there should be no differences in MC data and real data from4601 // FADC system.4602 //4603 // Revision 1.14 2001/01/15 12:33:34 magicsol4604 // Some modifications have been done to use the new (Dec'2000) Raw data format.4605 // There are also some minnors modifications to adapt the improvements in the4606 // MTrigger class (overlaping time and trigger cells).4607 //4608 // Revision 1.13 2000/10/25 08:14:23 magicsol4609 // The routine that produce poisson random numbers to decide how many phe4610 // form NSB are emmited in each pixel has been replaced. Now a ROOT routine4611 // is used.4612 //4613 4761 // Revision 1.10 2000/07/04 14:10:20 MagicSol 4614 4762 // Some changes have been done in the root output file. The RawEvt tree is only
Note:
See TracChangeset
for help on using the changeset viewer.