Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

CalNtupleAlg.cxx

Go to the documentation of this file.
00001 #define CalNtupleAlg_CPP 
00002 
00003 // Include files
00004 
00005 #include "GaudiKernel/MsgStream.h"
00006 #include "GaudiKernel/AlgFactory.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/SmartDataPtr.h"
00009 #include "GaudiKernel/Algorithm.h"
00010 
00011 
00012 #include "GaudiKernel/INTupleSvc.h"
00013 #include "GaudiKernel/INTuple.h"
00014 #include "GaudiKernel/NTuple.h"
00015 #include "GaudiKernel/SmartDataPtr.h"
00016 #include "GaudiKernel/StatusCode.h"
00017 
00018 #include "ntupleWriterSvc/INTupleWriterSvc.h"
00019 #include "CalRecon/CsIClusters.h"
00020 #include "CalRecon/CalRecLogs.h"
00021 
00022 
00023 
00024 //------------------------------------------------------------------------------
00030 class CalNtupleAlg : public Algorithm {
00031     
00032 public:
00034     CalNtupleAlg(const std::string& name, ISvcLocator* pSvcLocator); 
00035     
00036     StatusCode initialize();
00037     StatusCode execute();
00038     StatusCode finalize();
00039     
00040 private:
00041     std::string m_tupleName;
00042     CsIClusterList* m_cls;
00043     CalRecLogs* m_crl;
00044     INTupleWriterSvc *m_ntupleWriteSvc;
00045     
00046 };
00047 
00048 //------------------------------------------------------------------------------
00049 static const AlgFactory<CalNtupleAlg>  Factory;
00050 const IAlgFactory& CalNtupleAlgFactory = Factory;
00051 //------------------------------------------------------------------------------
00053 CalNtupleAlg::CalNtupleAlg(const std::string& name, ISvcLocator* pSvcLocator) :
00054 Algorithm(name, pSvcLocator){
00055     
00056     declareProperty("tupleName",  m_tupleName="");
00057     
00058     m_cls = 0;
00059 }
00060 
00061 //------------------------------------------------------------------------------
00064 StatusCode CalNtupleAlg::initialize() {
00065     
00066     StatusCode sc = StatusCode::SUCCESS;
00067     
00068     MsgStream log(msgSvc(), name());
00069     log << MSG::INFO << "Initialize" << endreq;
00070     
00071     // Use the Job options service to set the Algorithm's parameters
00072     setProperties();
00073     
00074     // get a pointer to our ntupleWriterSvc
00075     sc = service("ntupleWriterSvc", m_ntupleWriteSvc);
00076     
00077     if( sc.isFailure() ) {
00078         log << MSG::ERROR << "CalNtupleAlg failed to get the ntupleWriterSvc" << endreq;
00079         return sc;
00080     }
00081     
00082     return sc;
00083 }
00084 
00085 
00086 
00087 //------------------------------------------------------------------------------
00088 StatusCode CalNtupleAlg::execute() {
00089     
00090     StatusCode  sc = StatusCode::SUCCESS;
00091     MsgStream   log( msgSvc(), name() );
00092     
00093     m_cls  = SmartDataPtr<CsIClusterList>(eventSvc(),"/Event/CalRecon/CsIClusterList");
00094 
00095         if (m_cls == 0){ sc = StatusCode::FAILURE;
00096         
00097                 log << MSG::ERROR << "CalNtupleAlg failed to access CsIClusterList" << endreq;
00098                         return sc;
00099         }
00100 
00101 
00102         double fit_ener,fitalpha,fitlambda,profchi2,eleak,start;
00103         float energy_sum;
00104 
00105         int nClust = m_cls->num();
00106         //cout << nClust << endl;
00107         for ( int icl = 0; icl<nClust;icl++){
00108                 ICsICluster* cl = m_cls->Cluster(icl);
00109                 energy_sum = cl->energySum();
00110 
00111                 //stop writing NANs to the tuple
00112                 float zpos = -1000.0;
00113                 float xpos = -1000.0;
00114                 float ypos = -1000.0;
00115 
00116                 zpos = (cl->position()).z();
00117                 xpos = (cl->position()).x();
00118                 ypos = (cl->position()).y();
00119 
00120                 const std::vector<double>& eneLayer = cl->getEneLayer();
00121                 const std::vector<Vector>& posLayer = cl->getPosLayer();
00122 
00123                 float trans_rms = cl->getRmsTrans();
00124                 float long_rms = cl->getRmsLong();
00125 
00126                 Vector caldir = cl->direction();
00127                 float caltheta = -1000.0;
00128                 float calphi = -1000.0;
00129         if(abs(caldir.z())<1.){ caltheta=acos(caldir.z());
00130             calphi=float(M_PI/2.);
00131                     if(caldir.x()!=0.) calphi = atan(caldir.y()/caldir.x());
00132         }
00133                 fit_ener = cl->getFitEnergy();
00134                 profchi2 = cl->getProfChisq();
00135                 fitalpha = cl->getCsiAlpha();
00136                 fitlambda = cl->getCsiLambda();
00137                 start = cl->getCsiStart();
00138                 eleak = cl->energyLeak();
00139         float transvOffset = cl->getTransvOffset();
00140         
00141         float eFactor = .26 + .35 / (cl->energyCorrected());
00142         float calFitErrNrm = transvOffset/eFactor;
00143 
00144                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Transv_Offset", transvOffset);
00145                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Fit_errNrm", calFitErrNrm);
00146             
00147         
00148                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Energy_Deposit", energy_sum);
00149                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Energy_Inc_Prof", fit_ener);
00150                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Energy_Inc_LeakCorr", eleak);
00151                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Energy_Incident", fit_ener);  // for the moment
00152                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Energy_Incident_CalTkr", energy_sum);  // to be updated
00153 
00154                 const std::string name_eLayer = "Cal_eLayer";
00155                 const char* digit[8]={"0","1","2","3","4","5","6","7"};
00156                 for (int layer=0; layer<8; layer++)
00157                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), (name_eLayer+digit[layer]).c_str(), eneLayer[layer]);
00158         
00159                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Z", zpos);
00160                 
00161                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_X", xpos);
00162 
00163                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Y", ypos);
00164 
00165                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_transv_rms", trans_rms);
00166                 
00167                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_long_rms", long_rms);
00168 
00169                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_theta", caltheta);
00170 
00171                 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_phi", calphi);
00172 
00173         }
00174 
00175         m_crl = SmartDataPtr<CalRecLogs>(eventSvc(),"/Event/CalRecon/CalRecLogs"); 
00176         if (m_crl == 0){ sc = StatusCode::FAILURE;
00177         
00178                 log << MSG::ERROR << "CalNtupleAlg failed to access CalRecLogs" << endreq;
00179                         return sc;
00180         }
00181         
00182         int no_xtals=0;
00183         int no_xtals_trunc=0;
00184         int nLogs = m_crl->num();
00185         for (int jlog = 0; jlog < nLogs ; jlog++) {
00186                 CalRecLog* recLog = m_crl->Log(jlog);
00187 
00188                 double eneLog = recLog->energy();
00189                 if(eneLog>0)no_xtals++;
00190                 if(eneLog>0.01*energy_sum)no_xtals_trunc++;
00191         }
00192     float cal_xtal_ratio= (no_xtals>0) ? float(no_xtals_trunc)/no_xtals : 0;
00193 
00194     sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_No_Xtals", no_xtals);
00195     sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_No_Xtals_Trunc", no_xtals_trunc);
00196         sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "Cal_Xtal_Ratio", cal_xtal_ratio);
00197  
00198     return sc;
00199 }
00200 
00201 
00202 //------------------------------------------------------------------------------
00203 StatusCode CalNtupleAlg::finalize() {
00204     StatusCode  sc = StatusCode::SUCCESS;
00205     
00206     MsgStream log(msgSvc(), name());
00207     log << MSG::INFO << "finalize CalNtupleAlg " << endreq;
00208     
00209     return StatusCode::SUCCESS;
00210 }
00211 
00212 //------------------------------------------------------------------------------
00213 
00214 
00215 

Generated on Thu Nov 29 16:38:48 2001 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001