/* ======================================================================== *\ ! ! * ! * This file is part of MARS, the MAGIC Analysis and Reconstruction ! * Software. It is distributed to you in the hope that it can be a useful ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes. ! * It is distributed WITHOUT ANY WARRANTY. ! * ! * Permission to use, copy, modify and distribute this software and its ! * documentation for any purpose is hereby granted without fee, ! * provided that the above copyright notice appear in all copies and ! * that both that copyright notice and this permission notice appear ! * in supporting documentation. It is provided "as is" without express ! * or implied warranty. ! * ! ! Author(s): Javier Rico 04/2004 ! ! Copyright: MAGIC Software Development, 2000-2004 ! ! \* ======================================================================== */ ////////////////////////////////////////////////////////////////////////////// // // MSrcRotate // // Task to rotate the position of the source as a function of time // // Input Containers: // MSrcPosCam // // Output Containers: // MSrcPosCam // ////////////////////////////////////////////////////////////////////////////// #include #include #include "MParList.h" #include "MRawRunHeader.h" #include "MRawEvtHeader.h" #include "MSrcRotate.h" #include "MAstroSky2Local.h" #include "MObservatory.h" #include "MSrcPosCam.h" #include "MLog.h" #include "MLogManip.h" ClassImp(MSrcRotate); using namespace std; static const TString gsDefName = "MSrcRotate"; static const TString gsDefTitle = "Rotate position of the source"; // ------------------------------------------------------------------------- // // Default constructor. The first (second) argument is the name of the // input (output) MSrcPosCam object containing the source position in the // camera plain // MSrcRotate::MSrcRotate(const char* srcPosIn, const char* srcPosOut, const char *name, const char *title) : fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0) { fName = name ? name : gsDefName.Data(); fTitle = title ? title : gsDefTitle.Data(); SetInputSrcPosName(srcPosIn); SetOutputSrcPosName(srcPosOut); SetInternalHistoName(TString(fName)+"Hist"); } // ------------------------------------------------------------------------- // // Look for/create the needed containers // Check whether RA and DEC have been initialized // Int_t MSrcRotate::PreProcess(MParList *pList) { if(!MSrcPlace::PreProcess(pList)) return kFALSE; // look for MRawRunHeader fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader"); if (!fRunHeader) { *fLog << err << "MSrcRotate::PreProcess Error: MRawRunHeader not found... aborting" << endl; return kFALSE; } // look for MRawEvtHeader fEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader"); if (!fEvtHeader) { *fLog << err << "MSrcRotate::PreProcess Error: MRawEvtHeader not found... aborting." << endl; return kFALSE; } // look for/create the MObservatory fObservatory = (MObservatory*)pList->FindCreateObj("MObservatory"); if(!fObservatory) { *fLog << err << "MSrcRotate::PreProcess Error: MObservatory not found... aborting." << endl; return kFALSE; } // check RA and DEC if(fRA==0. || fDEC ==0) *fLog << warn << "MSrcRotate::PreProcess Warning: RA=" << fRA << "or DEC=" << fDEC << " could be not initialized" << endl; return kTRUE; } // ------------------------------------------------------------------------- // // Perform the rotation of the source position // // FIXME: for the time being, this is computed by assuming constant event rate // Int_t MSrcRotate::ComputeNewSrcPosition() { if(fRunHeader->GetRunNumber()!=fRunNumber) { fRunNumber=fRunHeader->GetRunNumber(); // save the number of events, initial and final times fNEvts = fRunHeader->GetNumEvents(); fIniTime = fRunHeader->GetRunStart(); fFinTime = fRunHeader->GetRunEnd(); fDeltaT = (fFinTime.GetMjd()-fIniTime.GetMjd())/fNEvts; if((ULong_t)TMath::Nint(fIniTime.GetMjd())!=(ULong_t)TMath::Nint(fFinTime.GetMjd())) { *fLog << err << "MSrcRotate::ComputeNewSrcPosition Error: Inial and final MJDs are different ("<GetRunNumber() << endl; cout << "Number of events: " << fNEvts << endl; cout << "Initial MJD date: " << fIniTime.GetMjd() << endl; cout << "Final MJD date: " << fFinTime.GetMjd() << endl; cout << "Delta t: " << fDeltaT << endl; #endif } // Compute the event time // FIXME: for the time being, this is computed by assuming constant event rate MTime eventTime; Double_t newMJD = fIniTime.GetMjd() + (fFinTime.GetMjd()-fIniTime.GetMjd())*fEvtHeader->GetDAQEvtNumber()/fNEvts; eventTime.SetMjd(newMJD); MTime refTime; refTime.SetMjd(fRefMJD); // de-rotate the source position const MAstroSky2Local Observation(eventTime, *fObservatory); const MAstroSky2Local RefObservation(refTime, *fObservatory); #ifdef DEBUG 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", fRunHeader->GetRunNumber(),fEvtHeader->GetDAQEvtNumber(), fIniTime.GetMjd(),fFinTime.GetMjd(),fDeltaT, newMJD,fRefMJD,Observation.RotationAngle(fRA,fDEC), RefObservation.RotationAngle(fRA,fDEC)); // cout << "newMJD=" << newMJD << ", fRefMJD="<GetX()-s*srcposIn->GetY(); Float_t newY = s*srcposIn->GetX()+c*srcposIn->GetY(); #ifdef DEBUG Double_t rotationAngleComp = fObservatory->RotationAngle(0.1256,2.63); cout << "Event " << fEvtHeader->GetDAQEvtNumber() << endl; cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<