CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibCalorimetry/EcalLaserAnalyzer/src/TAPD.cc

Go to the documentation of this file.
00001 /* 
00002  *  \class TAPD
00003  *
00004  *  $Date: 2012/02/09 10:08:10 $
00005  *  \author: Julie Malcles  - CEA/Saclay
00006  */
00007 
00008 #include <CalibCalorimetry/EcalLaserAnalyzer/interface/TMom.h>
00009 #include <CalibCalorimetry/EcalLaserAnalyzer/interface/TAPD.h>
00010 #include <CalibCalorimetry/EcalLaserAnalyzer/interface/TMarkov.h>
00011 #include <TMath.h>
00012 
00013 using namespace std;
00014 #include <iostream>
00015 #include <cassert>
00016 
00017 //ClassImp(TAPD)
00018 
00019 
00020 // Default Constructor...
00021 TAPD::TAPD()
00022 {
00023   init();
00024 }
00025 
00026 
00027 // Destructor
00028 TAPD::~TAPD()
00029 {
00030 }
00031 
00032 void TAPD::init()
00033 {
00034 
00035   for(int j=0;j<nOutVar;j++){
00036 
00037     _apdcuts[0][j].clear();
00038     _apdcuts[1][j].clear();
00039     _cutvars[j].clear();
00040 
00041     _apdcuts[0][j].push_back(0.0);
00042     _apdcuts[1][j].push_back(10.0e6);
00043     _cutvars[j].push_back(j);
00044     
00045     mom[j]=new TMom();
00046   }
00047 }
00048 
00049 void TAPD::addEntry(double apd, double pn, double pn0, double pn1, double time)
00050 {
00051   addEntry(apd, pn, pn0, pn1, time, 0.0, 0.0);
00052 }
00053 
00054 void TAPD::addEntry(double apd, double pn, double pn0, double pn1, double time, double apd0, double apd1)
00055 {
00056 
00057   double val[nOutVar];
00058   std::vector <double> valcuts[nOutVar];
00059 
00060   val[iAPD]=apd;
00061   if(pn!=0) val[iAPDoPN]=apd/pn;
00062   else val[iAPDoPN]=0.0;
00063   if(pn0!=0) val[iAPDoPN0]=apd/pn0;
00064   else val[iAPDoPN0]=0.0;
00065   if(pn1!=0) val[iAPDoPN1]=apd/pn1;
00066   else val[iAPDoPN1]=0.0;
00067   val[iTime]=time;
00068   if(apd0!=0.)val[iAPDoAPD0]=apd/apd0;
00069   else val[iAPDoAPD0]=0.0;
00070   if(apd1!=0.)val[iAPDoAPD1]=apd/apd1;
00071   else val[iAPDoAPD1]=0.0;
00072 
00073   
00074   
00075   for(int ivar=0;ivar<nOutVar;ivar++){
00076     int dimcut=_cutvars[ivar].size();
00077     for(int ic=0;ic<dimcut;ic++){
00078       assert(_cutvars[ivar].at(ic)<nOutVar);
00079       valcuts[ivar].push_back(val[_cutvars[ivar].at(ic)]);
00080     }
00081   }
00082 
00083   for(int ivar=0;ivar<nOutVar;ivar++){
00084     mom[ivar]->addEntry(val[ivar],valcuts[ivar]); 
00085     //    std::cout << "addEntry: val[ivar=" << ivar <<"] = "<<val[ivar]<< std::endl;
00086     
00087     for(size_t ic=0;ic<_cutvars[ivar].size();ic++){
00088       //      std::cout << "addEntry: valcuts[ivar="<< ivar <<"][ic="<<ic<<"] = "<<valcuts[ivar].at(ic)<< std::endl;
00089       for(size_t iv=0;iv<_cutvars[ivar].size();iv++){
00090         //      std::cout <<"low cut:"<<_apdcuts[0][ivar].at(iv)<<", high cut:"<<_apdcuts[1][ivar].at(iv)<<", cutvar: "<<_cutvars[ivar].at(iv)<< std::endl;
00091       }
00092     }
00093   }
00094   
00095 }
00096   
00097 void TAPD::setCut(int ivar, double mean, double sig){
00098   
00099   assert(ivar<nOutVar);
00100   
00101   std::vector <int>cutvar;
00102   cutvar.push_back(ivar);
00103   
00104   std::vector <double>lowcut;
00105   std::vector <double>highcut;
00106 
00107   double low=mean-2.0*sig;
00108   if (low<0) low=0.0;
00109   double high=mean+2.0*sig;
00110 
00111   lowcut.push_back(low);
00112   highcut.push_back(high);
00113 
00114   setCut(ivar,cutvar,lowcut,highcut);  
00115 
00116 }
00117 
00118 void TAPD::setCut(int ivar, std::vector<int> cutVars, std::vector<double> lowCut, std::vector<double> highCut){
00119   
00120   assert(ivar<nOutVar);
00121   int cutdim=cutVars.size();
00122   assert(cutdim<nOutVar);
00123   assert(cutdim==(int)lowCut.size());
00124   assert(cutdim==(int)highCut.size());
00125   
00126   _apdcuts[0][ivar].clear();
00127   _apdcuts[1][ivar].clear();
00128   _cutvars[ivar].clear();
00129   
00130   for (int ic=0;ic<cutdim;ic++){
00131     
00132     // FINISH THIS
00133     if(lowCut.at(ic)>0){
00134       _apdcuts[0][ivar].push_back(lowCut.at(ic));
00135     }else _apdcuts[0][ivar].push_back(0.0);
00136     
00137     _apdcuts[1][ivar].push_back(highCut.at(ic));
00138     _cutvars[ivar].push_back(cutVars.at(ic));
00139 
00140   }
00141  
00142   mom[ivar]->setCut(_apdcuts[0][ivar],_apdcuts[1][ivar]);
00143 }
00144 
00145 // Simple 1D cuts on main variable at 2 sigmas
00146 // ===========================================
00147 
00148 void  TAPD::setAPDCut(double mean, double sig){setCut(TAPD::iAPD,mean,sig);}
00149 void  TAPD::setAPDoPNCut(double mean, double sig){setCut(TAPD::iAPDoPN,mean,sig);}
00150 void  TAPD::setAPDoPN0Cut(double mean, double sig){setCut(TAPD::iAPDoPN0,mean,sig);}
00151 void  TAPD::setAPDoPN1Cut(double mean, double sig){setCut(TAPD::iAPDoPN1,mean,sig);}
00152 void  TAPD::setTimeCut(double mean, double sig){setCut(TAPD::iTime,mean,sig);}
00153 
00154 // More complicated 2D cuts
00155 // ========================= 
00156 
00157 // Cut on main var and Time:
00158 void  TAPD::set2DCut(int ivar, std::vector<double> lowCut,std::vector<double> highCut){
00159   
00160   assert (lowCut.size()==2);
00161   assert (highCut.size()==2);
00162   std::vector<int> cutVars;
00163   cutVars.push_back(ivar);
00164   cutVars.push_back(TAPD::iTime); 
00165   setCut(ivar, cutVars, lowCut, highCut);
00166   
00167 }
00168 
00169 
00170 void  TAPD::set2DAPDCut(std::vector<double> lowCut,std::vector<double> highCut){
00171   set2DCut(TAPD::iAPD, lowCut, highCut);
00172 }
00173 void  TAPD::set2DAPDoPNCut(std::vector<double> lowCut,std::vector<double> highCut){
00174   set2DCut(TAPD::iAPDoPN, lowCut, highCut);
00175 }
00176 void  TAPD::set2DAPDoPN0Cut(std::vector<double> lowCut,std::vector<double> highCut){
00177   set2DCut(TAPD::iAPDoPN0, lowCut, highCut);
00178 }
00179 void  TAPD::set2DAPDoPN1Cut(std::vector<double> lowCut,std::vector<double> highCut){
00180   set2DCut(TAPD::iAPDoPN1, lowCut, highCut);
00181 }
00182 
00183 
00184 void  TAPD::set2DAPDoAPD0Cut(std::vector<double> lowCut,std::vector<double> highCut){
00185 
00186   assert (lowCut.size()==2);
00187   assert (highCut.size()==2);
00188   std::vector<int> cutVars;
00189   cutVars.push_back(TAPD::iAPD);
00190   cutVars.push_back(TAPD::iTime); 
00191   setCut(TAPD::iAPDoAPD0, cutVars, lowCut, highCut);
00192 }
00193 void  TAPD::set2DAPDoAPD1Cut(std::vector<double> lowCut,std::vector<double> highCut){
00194 
00195   assert (lowCut.size()==2);
00196   assert (highCut.size()==2);
00197   std::vector<int> cutVars;
00198   cutVars.push_back(TAPD::iAPD);
00199   cutVars.push_back(TAPD::iTime); 
00200   setCut(TAPD::iAPDoAPD1, cutVars, lowCut, highCut);
00201 }
00202 
00203 void  TAPD::set2DTimeCut(std::vector<double> lowCut,std::vector<double> highCut){
00204 
00205   assert (lowCut.size()==2);
00206   assert (highCut.size()==2);
00207   std::vector<int> cutVars;
00208   cutVars.push_back(TAPD::iAPD);
00209   cutVars.push_back(TAPD::iTime); 
00210   setCut(TAPD::iTime, cutVars, lowCut, highCut);
00211 }
00212 
00213 
00214 
00215 std::vector<double> TAPD::get(int ivar){ 
00216 
00217   std::vector<double> res;
00218   
00219   if(ivar<nOutVar){
00220 
00221     res.push_back(mom[ivar]->getMean());
00222     res.push_back(mom[ivar]->getRMS());
00223     res.push_back(mom[ivar]->getM3());
00224     res.push_back(mom[ivar]->getNevt());
00225     res.push_back(mom[ivar]->getMin());
00226     res.push_back(mom[ivar]->getMax());
00227 
00228   }
00229 
00230   //  std::cout << "In get: ivar="<< ivar << ", mean="<< mom[ivar]->getMean()<<" res size="<< res.size()<< std::endl;
00231 
00232   return res;
00233 
00234 }
00235 
00236 std::vector<double>   TAPD::getAPD(){std::vector<double> x=get(TAPD::iAPD); return x;}
00237 std::vector<double>   TAPD::getAPDoPN(){std::vector<double> x=get(TAPD::iAPDoPN); return x;}
00238 std::vector<double>   TAPD::getAPDoPN0(){std::vector<double> x=get(TAPD::iAPDoPN0); return x;}
00239 std::vector<double>   TAPD::getAPDoPN1(){std::vector<double> x=get(TAPD::iAPDoPN1); return x;}
00240 std::vector<double>   TAPD::getTime(){std::vector<double> x=get(TAPD::iTime); return x;}
00241 std::vector<double>   TAPD::getAPDoAPD0(){
00242 std::vector<double> x=get(TAPD::iAPDoAPD0); 
00243 // std::cout<< "In GetAPDoAPD0: x[0]="<< x.at(0) << std::endl;
00244  return x;
00245 }
00246 std::vector<double>   TAPD::getAPDoAPD1(){std::vector<double> x=get(TAPD::iAPDoAPD1); return x;}