Changeset 7194 for trunk/MagicSoft/Mars/msignal
- Timestamp:
- 07/15/05 13:25:57 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/msignal
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
r7134 r7194 70 70 #include "MRawRunHeader.h" 71 71 #include "MCalibrationPattern.h" 72 #include "MExtractedSignalCam.h" 72 73 73 74 #include "MPedestalPix.h" … … 142 143 if (fWindowSizeHiGain > availhirange) 143 144 { 144 // Please simplify this!145 *fLog << warn << GetDescriptor()146 << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",fWindowSizeHiGain,147 " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl; 145 *fLog << warn << GetDescriptor() << ": Hi Gain window size: " << Form("%2i",fWindowSizeHiGain); 146 *fLog << " is bigger than available range: [" << Form("%2i", (int)fHiGainFirst); 147 *fLog << "," << Form("%21", (int)fHiGainLast) << "]" << endl; 148 148 149 fHiGainLast = fHiGainFirst + fWindowSizeHiGain; 149 *fLog << warn << GetDescriptor() 150 150 151 *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fHiGainLast << endl; 151 152 } 152 153 … … 163 164 if (fWindowSizeLoGain > availlorange) 164 165 { 165 // Please simplify this!166 *fLog << warn << GetDescriptor()167 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",fWindowSizeLoGain,168 " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl; 169 fLoGainLast = fLoGainFirst + fWindowSizeLoGain;170 *fLog << warn << GetDescriptor() 171 << ": Will set the upper range to: " << (int)fLoGainLast << endl;166 *fLog << warn << GetDescriptor() << ": Lo Gain window size: " << Form("%2i",fWindowSizeLoGain); 167 *fLog << " is bigger than available range: [" << Form("%2i", (int)fLoGainFirst); 168 *fLog << "," << Form("%21", (int)fLoGainLast) << "]" << endl; 169 170 fLoGainLast = fLoGainFirst + fWindowSizeLoGain; 171 172 *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fLoGainLast << endl; 172 173 } 173 174 … … 205 206 // -------------------------------------------------------------------------- 206 207 // 207 // InitArrays 208 // 209 // Gets called in the ReInit() and initialized the arrays 210 // 211 Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays() 212 { 213 if (!fRunHeader) 208 // The weights are determined using GetAutimaticWeights(). 209 // 210 // kFALSE is returned if it returned an error. 211 // kTRUE is returned if no new weights were set. 212 // 213 // If new weights are set 214 // fTimeShiftHiGain 215 // fTimeShiftLoGain 216 // fNumHiGainSamples 217 // fNumLoGainSamples 218 // fSqrtHiGainSamples 219 // fSqrtLoGainSamples 220 // and 221 // fSignals->SetUsedFADCSlices(...) 222 // is updated accordingly. 223 // 224 Bool_t MExtractTimeAndChargeDigitalFilter::GetWeights() 225 { 226 switch (GetAutomaticWeights()) 227 { 228 case kERROR: // An error occured 214 229 return kFALSE; 215 216 const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast); 217 const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1); 218 219 fHiGainSignal.Set(rangehi); 220 fLoGainSignal.Set(rangelo); 221 222 // Try to get automatic weights 223 if (!ReadAutomaticWeightsFile()) 224 return kFALSE; 225 226 // If still no weights set try conservative way 227 if (fNameWeightsFileSet.IsNull()) 228 if (!ReadWeightsFile(fNameWeightsFile)) 229 return kFALSE; 230 231 fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain; 230 case kFALSE: // No new weights set 231 return kTRUE; 232 } 233 234 // New weights set 235 fTimeShiftHiGain = 0.5 + 1./fBinningResolutionHiGain + fHiGainFirst; 232 236 fTimeShiftLoGain = 0.5 + 1./fBinningResolutionLoGain; 237 233 238 // 234 239 // We need here the effective number of samples which is about 2.5 in the case of a window … … 240 245 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); 241 246 247 // From MExtractTimeAndCharge::ReInit 248 if (fSignals) 249 fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples, 250 fLoGainFirst, fLoGainLast, fNumLoGainSamples); 242 251 return kTRUE; 252 } 253 254 // -------------------------------------------------------------------------- 255 // 256 // InitArrays 257 // 258 // Gets called in the ReInit() and initialized the arrays 259 // 260 Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays() 261 { 262 if (!fRunHeader) 263 return kFALSE; 264 265 const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast); 266 const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1); 267 268 fHiGainSignal.Set(rangehi); 269 fLoGainSignal.Set(rangelo); 270 271 return GetWeights(); 272 } 273 274 // -------------------------------------------------------------------------- 275 // 276 // Check if reading a new weights file is necessary because the calibration 277 // pattern has changed. (Cannot be done in ReInit, because at this time 278 // the calibration pattern is not available. 279 // Then process the event. 280 // 281 Int_t MExtractTimeAndChargeDigitalFilter::Process() 282 { 283 // Change Weights if the calibration patter changes 284 if (!GetWeights()) 285 return kERROR; 286 287 // Process event 288 return MExtractTimeAndCharge::Process(); 243 289 } 244 290 … … 643 689 //---------------------------------------------------------------------------- 644 690 // 691 // If automatic weights are requested, no default weights (name.IsNull()) 692 // are requested, fRunHeader is available and fRunHeader->IsMonteCarloRun() 693 // is true prepend "MC_" in from of the name. 694 // 695 // return poth+name; 696 // 697 TString MExtractTimeAndChargeDigitalFilter::CompileWeightFileName(TString path, const TString &name) const 698 { 699 if (fAutomaticWeights && !name.IsNull() && fRunHeader && fRunHeader->IsMonteCarloRun()) 700 path += "MC_"; 701 702 path += name; 703 704 return path; 705 } 706 707 //---------------------------------------------------------------------------- 708 // 645 709 // Read a pre-defined weights file into the class. 646 710 // This is mandatory for the extraction … … 648 712 // If filenname is empty, then all weights will be set to 1. 649 713 // 650 Bool_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename) 651 { 652 653 // This is a fix for TEnv files edited with windows editors 654 filename.ReplaceAll("\015", ""); 655 656 fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain); 657 fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain); 658 fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain); 659 fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain); 660 661 if (fNameWeightsFile.IsNull() || fNameWeightsFile=="-") 662 { 714 // Returns: 715 // kTRUE: new weights set 716 // kFALSE: no weights set 717 // kERROR: error 718 // 719 Int_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename, TString path) 720 { 721 if (filename.IsNull()) 722 { 723 fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain); 724 fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain); 725 fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain); 726 fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain); 727 663 728 fAmpWeightsHiGain.Reset(1); 664 729 fTimeWeightsHiGain.Reset(1); 665 730 fAmpWeightsLoGain.Reset(1); 666 731 fTimeWeightsLoGain.Reset(1); 667 fNameWeightsFileSet = "-";668 732 return kTRUE; 669 733 } 670 734 735 // Add "MC_" in front of the filename if necessary 736 filename = CompileWeightFileName(path, filename); 737 671 738 //filename = MJob::ExpandPath(filename); 672 739 673 740 if (fNameWeightsFileSet==filename) 674 return k TRUE;741 return kFALSE; // No file read 675 742 676 743 ifstream fin(filename.Data()); … … 679 746 *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": "; 680 747 *fLog << strerror(errno) << endl; 681 return k FALSE;682 } 683 684 *fLog << all << "DigitalFilter: Reading weights in " << filename << "..." << flush;748 return kERROR; 749 } 750 751 *fLog << all << GetDescriptor() << ": Reading weights in " << filename << "..." << flush; 685 752 686 753 Int_t len = 0; … … 705 772 { 706 773 *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl; 707 return k FALSE;774 return kERROR; 708 775 } 709 776 … … 712 779 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl; 713 780 *fLog << str << endl; 714 return k FALSE;781 return kERROR; 715 782 } 716 783 … … 727 794 { 728 795 *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl; 729 return k FALSE;796 return kERROR; 730 797 } 731 798 … … 734 801 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl; 735 802 *fLog << str << endl; 736 return k FALSE;803 return kERROR; 737 804 } 738 805 … … 758 825 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl; 759 826 *fLog << str << endl; 760 return k FALSE;827 return kERROR; 761 828 } 762 829 … … 770 837 if (cnt != len) 771 838 { 772 *fLog << err << " Size mismatch in weights file " << filename << endl;773 return k FALSE;839 *fLog << err << "ERROR - Size mismatch in weights file " << filename << endl; 840 return kERROR; 774 841 } 775 842 776 843 if (!hi) 777 844 { 778 *fLog << err << " No correct header found in weights file " << filename << endl;779 return k FALSE;845 *fLog << err << "ERROR - No correct header found in weights file " << filename << endl; 846 return kERROR; 780 847 } 781 848 … … 824 891 //---------------------------------------------------------------------------- 825 892 // 826 // If automatic weight disabled or run type is pedestal no action is taken 827 // and kTRUE is returned. 828 // 829 // Otherwise: 830 // - If runtype is kRTData and filename starts with "MC_weights" "MC" is 831 // replaced by "cosmics" 832 // - If runtype is kRTMonteCarlo and filename starts with "cosmics_weights" 833 // "cosmics" is replaced by "MC" 834 // - If name filename begins with "calibration_weights_" for blue and green 835 // "UV" is replaced by "blue" 836 // - If name filename begins with "calibration_weights_" for UV and CT1 837 // "blue" is replaced by "UV" 838 // 839 // The replacements are done in this order. If no match is found no 840 // replacement is done. Afterwards ReadWeightsFile for the resulting 841 // path-/filename is called. 842 // 843 Bool_t MExtractTimeAndChargeDigitalFilter::ReadAutomaticWeightsFile() 844 { 845 if (!fAutomaticWeights || fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal) 846 return kTRUE; 847 848 if (fNameWeightsFile.IsNull()) 849 { 850 *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl; 851 return kFALSE; 852 } 853 854 *fLog << dbg << endl; 855 *fLog << underline << GetDescriptor() << endl; 856 *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl; 857 893 // The default (+ prepending possible "MC_") is read for: 894 // 895 // - RunType: Pedestal (independant of fAutomaticWeights) 896 // - fAutomaticWeights disabled 897 // 898 // if fAutomaticWeights enabled: 899 // - fNameWeightsFile.IsNull() 900 // - !fCalibPattern 901 // - fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE 902 // 903 // If automatic weights are enabled, the case above didn't take place and 904 // fNameWeightsFile starts with "calibration_weights_" 905 // - the color (blue, UV) is replaced by the appropriate one 906 // taken from the calibration pattern 907 // 908 // In most cases a debug output is printed. Further output about the color 909 // determination can be switched on with debug level > 5; 910 // 911 // Returns: 912 // kFALSE: No new weights set 913 // kTRUE: New weights set 914 // kERROR: Error 915 // 916 Int_t MExtractTimeAndChargeDigitalFilter::GetAutomaticWeights() 917 { 858 918 const Ssiz_t pos = fNameWeightsFile.Last('/')+1; 859 919 const Ssiz_t len = fNameWeightsFile.Length(); 860 920 921 // Split file name in path and name 861 922 TString path = fNameWeightsFile(0, pos>=0?pos:len); 862 923 TString name = fNameWeightsFile(pos>=0?pos:0, len); 863 924 864 if (name.BeginsWith("cosmics_weights") && fRunHeader->GetRunType()==MRawRunHeader::kRTMonteCarlo) 865 { 866 name.Remove(0, 7); 867 name.Prepend("MC"); 868 *fLog << "Run type: Monte Carlo data" << endl; 869 } 870 if (name.BeginsWith("MC_weights") && fRunHeader->GetRunType()==MRawRunHeader::kRTData) 871 { 872 name.Remove(0, 2); 873 name.Prepend("cosmics"); 874 *fLog << "Run type: Cosmics data" << endl; 925 // Remove trailing "MC_" for automatic weights 926 if (fAutomaticWeights && name.BeginsWith("MC_")) 927 name.Remove(0, 3); 928 929 // In case of a pedetsal run no calibration pattern can be available 930 // the default weights are always used. 931 if (fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal) 932 { 933 *fLog << dbg << "Pedestal file... using default weights: " << fNameWeightsFile << endl; 934 return ReadWeightsFile(name, path); 935 } 936 937 // If automatic weights are switched off use default weights 938 if (!fAutomaticWeights) 939 { 940 *fLog << dbg << "Automatic weights switched off... using default weights: " << fNameWeightsFile << endl; 941 return ReadWeightsFile(name, path); 942 } 943 944 // If automatic weights are switched on but no filename is given raise error 945 if (fNameWeightsFile.IsNull()) 946 { 947 *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl; 948 return kERROR; 949 } 950 951 // If this is no pedestal run, automatic weights are requested and a 952 // filename for the weights file is given pedestal-extraction from 953 // cosmics data is assumed. 954 if (!fCalibPattern) 955 { 956 *fLog << dbg << "No decoded calibration pattern available... using default weights: " << fNameWeightsFile << endl; 957 return ReadWeightsFile(name, path); 958 } 959 960 const Bool_t debug = gLog.GetDebugLevel()>5; 961 962 // If no calibration pattern is available do not change the 963 // current weighs or current weights file name. 964 if (fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE) 965 { 966 // If we are extracting data and the calibration pattern is kNONE 967 // we assume that it is a data file without interleaved events 968 // and calibration pattern information available. 969 if ((fRunHeader->GetRunType()!=MRawRunHeader::kRTData && !fRunHeader->IsMonteCarloRun()) || debug) 970 *fLog << dbg << "No calibration color set so far... guessing default: " << fNameWeightsFile << endl; 971 972 return ReadWeightsFile(name, path); 973 } 974 975 if (debug) 976 { 977 *fLog << dbg << endl; 978 *fLog << underline << GetDescriptor() << endl; 979 *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl; 980 *fLog << " Run type: "; 875 981 } 876 982 877 983 if (name.BeginsWith("calibration_weights_") && fCalibPattern) 878 984 { 879 *fLog << " Run type: Calibration with color " << (int)fCalibPattern->GetPulserColor() << ", setting "; 985 if (debug) 986 *fLog << " Calibration with color " << fCalibPattern->GetPulserColorStr() << ", setting "; 880 987 switch (fCalibPattern->GetPulserColor()) 881 988 { 882 989 case MCalibrationCam::kBLUE: // 2 883 990 case MCalibrationCam::kGREEN: // 1 884 *fLog << "blue/green" << endl; 991 if (debug) 992 *fLog << "blue/green, "; 885 993 name.ReplaceAll("UV", "blue"); 886 994 break; … … 888 996 case MCalibrationCam::kUV: // 3 889 997 case MCalibrationCam::kCT1: // 0 890 *fLog << "UV/CT1" << endl; 998 if (debug) 999 *fLog << "UV/CT1, "; 891 1000 name.ReplaceAll("blue", "UV"); 892 1001 break; 893 1002 case MCalibrationCam::kNONE: 894 *fLog << "None" << endl;895 1003 break; 896 default: // kNONE=4 897 *fLog << "???" << endl; 898 } 899 } 900 901 path += name; 902 903 return ReadWeightsFile(path); 1004 default: // kNone + etc 1005 *fLog << err << "ERROR - Cannot get automatic weights for " << fCalibPattern->GetPulserColorStr() << endl; 1006 return kERROR; 1007 } 1008 } 1009 1010 return ReadWeightsFile(name, path); 904 1011 } 905 1012 -
trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
r7099 r7194 69 69 // MExtractTimeAndChargeDigitalFilter 70 70 void CalcBinningResArrays(); 71 Bool_t ReadAutomaticWeightsFile(); 71 Int_t GetAutomaticWeights(); 72 Bool_t GetWeights(); 73 Int_t ReadWeightsFile(TString filename, TString path=""); 74 TString CompileWeightFileName(TString path, const TString &name) const; 72 75 73 76 // MExtractTimeAndCharge … … 76 79 // MTask 77 80 Int_t PreProcess(MParList *pList); 81 Int_t Process(); 78 82 79 83 protected: … … 85 89 ~MExtractTimeAndChargeDigitalFilter() { } 86 90 87 Bool_t ReadWeightsFile(TString filename);88 89 91 Bool_t WriteWeightsFile(TString filename, 90 92 TH1F *shapehi, TH2F *autocorrhi, … … 92 94 93 95 94 void SetNameWeightsFile(TString s="") { fNameWeightsFile = s; fNameWeightsFileSet=""; } 96 void SetNameWeightsFile(TString s="") { s.ReplaceAll("\015", ""); // This is a fix for TEnv files edited with windows editors 97 fNameWeightsFile = s; fNameWeightsFileSet=""; } 95 98 void EnableAutomaticWeights(Bool_t b=kTRUE) { fAutomaticWeights = b; } 96 99
Note:
See TracChangeset
for help on using the changeset viewer.