Changeset 4072 for trunk/MagicSoft/Mars/mtemp/mifae/library
- Timestamp:
- 05/14/04 16:35:57 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mtemp/mifae/library
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtemp/mifae/library/IFAELinkDef.h
r4061 r4072 8 8 #pragma link C++ class MPSFFit+; 9 9 #pragma link C++ class MPSFFitCalc+; 10 #pragma link C++ class MSrcPlace+; 10 11 #pragma link C++ class MSrcPosFromFile+; 11 12 #pragma link C++ class MSrcRotate+; -
trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.cc
r3947 r4072 27 27 // MSrcPosFromFile 28 28 // 29 // Task to calculate the position of the source as a function of run number 29 // Task to set the position of the source as a function of run number according 30 // to the positions read from an input file 30 31 // 31 32 // Output Containers: … … 39 40 40 41 #include "MParList.h" 41 42 42 #include "MSrcPosFromFile.h" 43 43 … … 53 53 54 54 static const TString gsDefName = "MSrcPosFromFile"; 55 static const TString gsDefTitle = " Calculate position of the (off axis) source";55 static const TString gsDefTitle = "Set the position of the (off axis) source according to input file"; 56 56 57 57 // ------------------------------------------------------------------------- 58 58 // 59 // Default constructor 59 // Default constructor. cardpath is the name of the input file (.pos) where the 60 // source positions are stored in the format Run# x y (in mm). mode indicates whether 61 // to read or to save the positions of the source in/from the internal histogram 60 62 // 61 63 MSrcPosFromFile::MSrcPosFromFile(TString cardpath, OnOffMode_t mode, const char *name, const char *title) 62 : fRawRunHeader(NULL), fSrcPos(NULL), fMode(mode), fSourcePositionFilePath(cardpath) 63 { 64 fName = name ? name : gsDefName.Data(); 65 fTitle = title ? title : gsDefTitle.Data(); 66 67 fLastRun = 0; 68 69 // Count the number of runs in the card with the source poistions 70 ReadSourcePositionsFile(kCount); 71 72 fRunList = new Int_t[fNumRuns]; 73 fRunSrcPos = new MSrcPosCam[fNumRuns]; 74 fRunMap = new TExMap(fNumRuns); 75 76 Float_t cameraSize = 600; //[mm] 77 Float_t binPrecision = 3; //[mm] ~ 0.01 deg 78 79 UInt_t nbins = (UInt_t)(cameraSize*2/binPrecision); 80 81 fHistSrcPos = new TH2F("HistSrcPos","",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize); 82 83 // Read card with the source poistions 84 ReadSourcePositionsFile(kRead); 64 : fRawRunHeader(NULL), fSourcePositionFilePath(cardpath) 65 { 66 fName = name ? name : gsDefName.Data(); 67 fTitle = title ? title : gsDefTitle.Data(); 68 SetMode(mode); 69 70 fLastRun = 0; 71 72 // Count the number of runs in the card with the source poistions 73 ReadSourcePositionsFile(kCount); 74 75 fRunList = new Int_t[fNumRuns]; 76 fRunSrcPos = new MSrcPosCam[fNumRuns]; 77 fRunMap = new TExMap(fNumRuns); 78 79 // Read card with the source poistions 80 ReadSourcePositionsFile(kRead); 85 81 } 86 82 87 83 MSrcPosFromFile::~MSrcPosFromFile() 88 84 { 89 delete [] fRunList; 90 delete [] fRunSrcPos; 91 delete fRunMap; 92 delete fHistSrcPos; 85 delete [] fRunList; 86 delete [] fRunSrcPos; 87 delete fRunMap; 93 88 } 94 89 … … 97 92 Int_t MSrcPosFromFile::PreProcess(MParList *pList) 98 93 { 99 100 fRawRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader")); 101 if (!fRawRunHeader) 94 if(!SearchForSrcPos(pList)) 95 return kFALSE; 96 97 fRawRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader")); 98 if (!fRawRunHeader) 102 99 { 103 100 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found ... aborting" << endl; 104 return kFALSE; 105 } 106 107 fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam"); 108 if (!fSrcPos) 109 return kFALSE; 110 111 return kTRUE; 101 return kFALSE; 102 } 103 104 return kTRUE; 112 105 } 113 106 114 107 // -------------------------------------------------------------------------- 115 108 // 109 // In case we enter a new run, look for the position in the read list 110 // If there is no value for that run, take the previous one 116 111 // 117 Bool_t MSrcPosFromFile::ReInit(MParList *pList) 118 { 112 Int_t MSrcPosFromFile::ComputeNewSrcPosition() 113 { 114 const UInt_t run = fRawRunHeader->GetRunNumber(); 115 if(run!=fLastRun) 116 { 117 fLastRun=run; 118 MSrcPosCam* srcpos = (MSrcPosCam*)fRunMap->GetValue(run); 119 120 Float_t x; 121 Float_t y; 122 123 if (srcpos) 124 { 125 x = srcpos->GetX(); 126 y = srcpos->GetY(); 127 128 GetSrcPosCam()->SetXY(x,y); 129 130 *fLog << inf << "Source position for run " << run; 131 *fLog << inf << "\tX\t" << setprecision(3) << x; 132 *fLog << inf << "\tY\t" << setprecision(3) << y << endl; 133 } 134 else 135 { 136 *fLog << inf << "Source position for run " << run << " not found in file. "; 137 *fLog << inf << "Taking previous position: "; 138 *fLog << inf << "\tX\t" << setprecision(3) << x; 139 *fLog << inf << "\tY\t" << setprecision(3) << y << endl; 140 } 141 } 142 119 143 return kTRUE; 120 144 } … … 122 146 // -------------------------------------------------------------------------- 123 147 // 148 // Read file with table of source positions as function of run 124 149 // 125 Int_t MSrcPosFromFile::Process() 126 { 127 128 switch(fMode) 150 Int_t MSrcPosFromFile::ReadSourcePositionsFile(UShort_t readmode) 151 { 152 153 ifstream fin(fSourcePositionFilePath); 154 if(!fin) 155 { 156 *fLog << err << "MSrcPosFromFile::ReadSourcePositionsFile. Cannot open file " << fSourcePositionFilePath << endl; 157 return kFALSE; 158 } 159 160 UInt_t run; 161 Float_t x,y; 162 163 fNumRuns=0; 164 165 *fLog << dbg << "MSrcPosFromFile::ReadSourcePositionsFile(" << readmode << ')' << endl; 166 while(1) 167 { 168 fin >> run >> x >> y; 169 if(fin.eof()) 170 break; 171 172 switch(readmode) 129 173 { 130 case kOn: 131 { 132 const UInt_t run = fRawRunHeader->GetRunNumber(); 133 134 MSrcPosCam* srcpos = (MSrcPosCam*)fRunMap->GetValue(run); 135 136 Float_t x; 137 Float_t y; 138 139 if (srcpos) 140 { 141 x = srcpos->GetX(); 142 y = srcpos->GetY(); 143 144 145 if (srcpos && run != fLastRun) 146 { 147 fSrcPos->SetXY(x,y); 174 case kCount: 175 { 148 176 149 *fLog << inf << "Source position for run " << run; 150 *fLog << inf << "\tX\t" << setprecision(2) << x; 151 *fLog << inf << "\tY\t" << setprecision(2) << y << endl; 152 } 153 154 fLastRun = run; 155 } 156 157 x = fSrcPos->GetX(); 158 y = fSrcPos->GetY(); 159 160 fHistSrcPos->Fill(x,y); 161 break; 162 } 163 case kOff: 164 { 165 Axis_t x; 166 Axis_t y; 167 168 fHistSrcPos->GetRandom2(x,y); 169 fSrcPos->SetXY(x,y); 170 171 break; 172 } 173 default: 174 *fLog << err << "Wrond mode " << fMode << endl; 175 return kFALSE; 177 *fLog << dbg << "Source position for run " << run; 178 *fLog << dbg << "\tX\t" << x << " mm"; 179 *fLog << dbg << "\tY\t" << y << " mm" << endl; 180 181 fNumRuns++; 182 break; 183 } 184 case kRead: 185 { 186 fRunList[fNumRuns] = run; 187 fRunSrcPos[fNumRuns].SetXY(x,y); 188 fRunMap->Add(fRunList[fNumRuns],(Long_t)&(fRunSrcPos[fNumRuns])); 189 fNumRuns++; 190 break; 191 } 192 default: 193 *fLog << err << "Read mode " << readmode << " node defined" << endl; 194 return kFALSE; 176 195 } 177 178 return kTRUE; 179 } 180 181 182 Int_t MSrcPosFromFile::PostProcess() 183 { 184 185 *fLog << dbg << endl; 186 *fLog << dbg << "fHistSrcPos->GetEntries() " << fHistSrcPos->GetEntries() << endl; 187 *fLog << dbg << "fHistSrcPos->ProjectionX()->GetMean() " << fHistSrcPos->ProjectionX()->GetMean() << endl; 188 *fLog << dbg << "fHistSrcPos->ProjectionX()->GetRMS() " << fHistSrcPos->ProjectionX()->GetRMS() << endl; 189 *fLog << dbg << "fHistSrcPos->ProjectionY()->GetMean() " << fHistSrcPos->ProjectionY()->GetMean() << endl; 190 *fLog << dbg << "fHistSrcPos->ProjectionY()->GetRMS() " << fHistSrcPos->ProjectionY()->GetRMS() << endl; 191 192 return kTRUE; 193 } 194 195 196 Int_t MSrcPosFromFile::ReadSourcePositionsFile(UShort_t readmode) 197 { 198 199 ifstream fin(fSourcePositionFilePath); 200 if(!fin) 201 { 202 *fLog << err << "MSrcPosFromFile::ReadSourcePositionsFile. Cannot open file " << fSourcePositionFilePath << endl; 203 return kFALSE; 204 } 205 206 UInt_t run; 207 Float_t x,y; 208 209 fNumRuns=0; 210 211 *fLog << dbg << "MSrcPosFromFile::ReadSourcePositionsFile(" << readmode << ')' << endl; 212 while(1) 213 { 214 fin >> run >> x >> y; 215 if(fin.eof()) 216 break; 217 218 switch(readmode) 219 { 220 case kCount: 221 { 222 223 *fLog << dbg << "Source position for run " << run; 224 *fLog << dbg << "\tX\t" << x << " mm"; 225 *fLog << dbg << "\tY\t" << y << " mm" << endl; 226 227 fNumRuns++; 228 break; 229 } 230 case kRead: 231 { 232 fRunList[fNumRuns] = run; 233 fRunSrcPos[fNumRuns].SetXY(x,y); 234 fRunMap->Add(fRunList[fNumRuns],(Long_t)&(fRunSrcPos[fNumRuns])); 235 fNumRuns++; 236 break; 237 } 238 default: 239 *fLog << err << "Read mode " << readmode << " node defined" << endl; 240 return kFALSE; 241 } 242 } 243 244 fin.close(); 245 246 247 return kTRUE; 248 } 196 } 197 198 fin.close(); 199 200 201 return kTRUE; 202 } -
trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPosFromFile.h
r3947 r4072 2 2 #define MARS_MSrcPosFromFile 3 3 4 #ifndef MARS_M Task5 #include "M Task.h"4 #ifndef MARS_MSrcPlace 5 #include "MSrcPlace.h" 6 6 #endif 7 7 … … 10 10 #endif 11 11 12 class TH2F;13 14 12 class MRawRunHeader; 15 13 class MSrcPosCam; 16 14 17 class MSrcPosFromFile : public M Task15 class MSrcPosFromFile : public MSrcPlace 18 16 { 19 17 private: 20 18 21 19 MRawRunHeader *fRawRunHeader; 22 MSrcPosCam *fSrcPos; // Pointer to the source position23 20 24 21 Int_t fNumRuns; … … 29 26 TExMap *fRunMap; // list of run numbers positions 30 27 31 TH2F *fHistSrcPos; 32 UShort_t fMode; 28 TString fSourcePositionFilePath; 33 29 34 TString fSourcePositionFilePath; 35 Int_t ReadSourcePositionsFile(UShort_t readmode); 36 37 Int_t PreProcess(MParList *plist); 38 Bool_t ReInit(MParList *plist); 39 Int_t Process(); 40 Int_t PostProcess(); 41 42 public: 30 virtual Int_t ReadSourcePositionsFile(UShort_t readmode); 31 virtual Int_t ComputeNewSrcPosition(); 43 32 33 virtual Int_t PreProcess(MParList *plist); 34 35 public: 44 36 enum ReadMode_t {kCount=0,kRead}; 45 enum OnOffMode_t {kOn=0,kOff};46 37 47 38 MSrcPosFromFile(TString cardpath, OnOffMode_t mode=kOn, const char *name=NULL, const char *title=NULL); 48 39 ~MSrcPosFromFile(); 49 50 void SetMode(OnOffMode_t mode) {fMode=mode;}51 40 52 41 ClassDef(MSrcPosFromFile, 0) // task to calculate the position of the source as a function of the run number -
trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc
r4056 r4072 26 26 // MSrcRotate 27 27 // 28 // Task to rotate the position of the source as a function of Azimuth and 29 // Zenith angles 28 // Task to rotate the position of the source as a function of time 30 29 // 31 30 // Input Containers: … … 45 44 #include "MRawEvtHeader.h" 46 45 #include "MSrcRotate.h" 47 #include "MSrcPosCam.h"48 #include "MDCA.h"49 46 50 47 #include "MAstroSky2Local.h" 51 48 #include "MObservatory.h" 49 #include "MSrcPosCam.h" 50 #include "MDCA.h" 52 51 53 52 #include "MLog.h" … … 59 58 60 59 static const TString gsDefName = "MSrcRotate"; 61 static const TString gsDefTitle = " De-rotate position of the source";60 static const TString gsDefTitle = "Rotate position of the source"; 62 61 63 62 // ------------------------------------------------------------------------- … … 68 67 // 69 68 MSrcRotate::MSrcRotate(const char* srcPos, const char* dca, const char *name, const char *title) 70 : f SrcPos(NULL), fDCA(NULL), fRA(0), fDEC(0), fRunNumber(0)69 : fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0) 71 70 { 72 71 fName = name ? name : gsDefName.Data(); 73 72 fTitle = title ? title : gsDefTitle.Data(); 74 73 75 fSrcPosName = srcPos;76 fDCAName = dca;74 SetSrcPosName(srcPos); 75 SetDCAName(dca); 77 76 } 78 77 … … 84 83 Int_t MSrcRotate::PreProcess(MParList *pList) 85 84 { 86 // look for/create MSrcPosCam 87 fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosName), "MSrcPosCam"); 88 if (!fSrcPos) 89 { 90 *fLog << warn << AddSerialNumber(fSrcPosName) << " [MSrcPosCam] not found... creating default container." << endl; 91 fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosName)); 92 if(!fSrcPos) 93 return kFALSE; 94 } 95 96 // look for/create MDCA 97 fDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA"); 98 if (!fDCA) 99 { 100 *fLog << warn << AddSerialNumber(fDCAName) << " [MDCA] not found... creating default container." << endl; 101 fDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName)); 102 if(!fDCA) 103 return kFALSE; 104 } 105 85 if(!SearchForSrcPos(pList)) 86 return kFALSE; 87 106 88 // look for MRawRunHeader 107 89 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader"); … … 141 123 // FIXME: for the time being, this is computed by assuming constant event rate 142 124 // 143 Int_t MSrcRotate:: Process()125 Int_t MSrcRotate::ComputeNewSrcPosition() 144 126 { 145 127 if(fRunHeader->GetRunNumber()!=fRunNumber) 146 128 { 147 129 fRunNumber=fRunHeader->GetRunNumber(); 148 130 149 131 // save the number of events, initial and final times 150 132 fNEvts = fRunHeader->GetNumEvents(); … … 155 137 if((ULong_t)TMath::Nint(fIniTime.GetMjd())!=(ULong_t)TMath::Nint(fFinTime.GetMjd())) 156 138 { 157 *fLog << err << "MSrcRotate:: ProcessError: Inial and final MJDs are different ("<<fIniTime.GetMjd()<<"!="<<fFinTime.GetMjd()<<")" << endl;139 *fLog << err << "MSrcRotate::ComputeNewSrcPosition Error: Inial and final MJDs are different ("<<fIniTime.GetMjd()<<"!="<<fFinTime.GetMjd()<<")" << endl; 158 140 return kFALSE; 159 141 } 160 142 161 143 #ifdef DEBUG 162 144 cout << endl << "********************" << endl; … … 169 151 } 170 152 171 153 172 154 // Compute the event time 173 155 // FIXME: for the time being, this is computed by assuming constant event rate … … 177 159 MTime refTime; 178 160 refTime.SetMjd(fRefMJD); 179 161 180 162 // de-rotate the source position 181 163 const MAstroSky2Local Observation(eventTime, *fObservatory); 182 164 const MAstroSky2Local RefObservation(refTime, *fObservatory); 183 165 184 166 #ifdef DEBUG 185 167 printf("Run:%d, Event:%d, iniMJD=%15.5f, finMJD=%15.5f, fDeltaT=%15.5f, newMJD=%15.5f, fRefMJD=%15.5f, rotation=%15.5f, ref=%15.5f\n", … … 190 172 // cout << "newMJD=" << newMJD << ", fRefMJD="<<fRefMJD<<", rotation="<<Observation.RotationAngle(fRA,fDEC)<<", ref="<<RefObservation.RotationAngle(fRA,fDEC)<< endl; 191 173 #endif 192 193 Double_t rotationAngle = Observation.RotationAngle(fRA,fDEC)-RefObservation.RotationAngle(fRA,fDEC); 174 175 Double_t rotationAngle = fRefMJD ? 176 Observation.RotationAngle(fRA,fDEC)-RefObservation.RotationAngle(fRA,fDEC) : 177 Observation.RotationAngle(fRA,fDEC) ; 178 MSrcPosCam* srcpos = GetSrcPosCam(); 179 MDCA* dca = GetDCA(); 194 180 195 181 Float_t c = TMath::Cos(rotationAngle); 196 182 Float_t s = TMath::Sin(rotationAngle); 197 183 // perform a rotation of -rotationAngle to move the source back to the "initial" position 198 Float_t newX = c* fSrcPos->GetX()-s*fSrcPos->GetY();199 Float_t newY = s* fSrcPos->GetX()+c*fSrcPos->GetY();200 184 Float_t newX = c*srcpos->GetX()-s*srcpos->GetY(); 185 Float_t newY = s*srcpos->GetX()+c*srcpos->GetY(); 186 201 187 #ifdef DEBUG 202 188 Double_t rotationAngleComp = fObservatory->RotationAngle(0.1256,2.63); 203 189 cout << "Event " << fEvtHeader->GetDAQEvtNumber() << endl; 204 cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<<fIniSrcPos.GetX()<< ", oldY="<<fIniSrcPos.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl ,190 cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<<fIniSrcPos.GetX()<< ", oldY="<<fIniSrcPos.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl; 205 191 #endif 206 207 fSrcPos->SetX(newX);208 fSrcPos->SetY(newY);209 fDCA->SetRefPoint(newX,newY);192 193 srcpos->SetX(newX); 194 srcpos->SetY(newY); 195 dca->SetRefPoint(newX,newY); 210 196 211 197 return kTRUE; -
trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.h
r4056 r4072 2 2 #define MARS_MSrcRotate 3 3 4 #ifndef MARS_M Task5 #include "M Task.h"4 #ifndef MARS_MSrcPlace 5 #include "MSrcPlace.h" 6 6 #endif 7 7 8 #include <TArrayF.h>9 8 #include "MTime.h" 10 #include "MSrcPosCam.h"11 9 12 class MDCA;13 10 class MObservatory; 14 11 class MRawEvtHeader; 15 12 class MRawRunHeader; 16 13 17 class MSrcRotate : public M Task14 class MSrcRotate : public MSrcPlace 18 15 { 19 private: 20 MSrcPosCam* fSrcPos; // Pointer to the source position 21 MDCA* fDCA; // Pointer to the MDCA object 22 MRawEvtHeader* fEvtHeader; // Pointer to the event header 23 MRawRunHeader* fRunHeader; // Pointer to the run header 24 MObservatory* fObservatory; // Pointer to the MObservatory 25 26 TString fSrcPosName; 27 TString fDCAName; 28 29 Double_t fRA; // [rad] Right ascention 30 Double_t fDEC; // [rad] Declination 31 Double_t fRefMJD; // [MJ date] reference time for rotation 32 UInt_t fNEvts; // Number of events in file 33 MTime fIniTime; // Run initial time 34 MTime fFinTime; // Run final time 35 Double_t fDeltaT; // DeltaT between two events 36 UInt_t fRunNumber; // Current run number 37 38 Int_t PreProcess(MParList *plist); 39 Int_t Process(); 40 41 public: 42 MSrcRotate(const char* src="MSrcPosCam", const char* dca="MDCA", 43 const char* name=NULL, const char* title=NULL); 44 45 void SetRAandDECandRefMJD(Double_t ra, Double_t dec, Double_t ref) {fRA=ra;fDEC=dec;fRefMJD=ref;} 46 47 ClassDef(MSrcRotate, 0) // task to rotate the position of the source as a function of Azimuth and Zenith angles 16 private: 17 MRawEvtHeader* fEvtHeader; // Pointer to the event header 18 MRawRunHeader* fRunHeader; // Pointer to the run header 19 MObservatory* fObservatory; // Pointer to the MObservatory 20 21 Double_t fRA; // [rad] Right ascenssion 22 Double_t fDEC; // [rad] Declination 23 Double_t fRefMJD; // [MJ date] reference time for rotation 24 UInt_t fNEvts; // Number of events in file 25 MTime fIniTime; // Run initial time 26 MTime fFinTime; // Run final time 27 Double_t fDeltaT; // DeltaT between two events 28 UInt_t fRunNumber; // Current run number 29 30 virtual Int_t PreProcess(MParList *plist); 31 32 public: 33 MSrcRotate(const char* src="MSrcPosCam", const char* dca="MDCA", 34 const char* name=NULL, const char* title=NULL); 35 36 void SetRAandDECandRefMJD(Double_t ra, Double_t dec, Double_t ref=0) {fRA=ra;fDEC=dec;fRefMJD=ref;} 37 void SetRAandDEC(Double_t ra, Double_t dec){SetRAandDECandRefMJD(ra,dec);} 38 virtual Int_t ComputeNewSrcPosition(); 39 40 ClassDef(MSrcRotate, 0) // task to rotate the position of the source as a function of Azimuth and Zenith angles 48 41 }; 49 42 -
trunk/MagicSoft/Mars/mtemp/mifae/library/Makefile
r4061 r4072 51 51 MPSFFit.cc \ 52 52 MPSFFitCalc.cc \ 53 MSrcPlace.cc \ 53 54 MSrcPosFromFile.cc \ 54 55 MSrcRotate.cc \
Note:
See TracChangeset
for help on using the changeset viewer.