/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Tof/tofcalgsec/tofcalgsec-00-02-21/src/TofDataSet.cxx

Go to the documentation of this file.
00001 #include "tofcalgsec/TofDataSet.h"
00002 #include <cmath>
00003 
00004 Record::Record() {
00005   initial();
00006   return;
00007 }
00008 
00009 
00010 Record::~Record() {}
00011 
00012 
00013 void Record::initial() {
00014   m_run     = 0;
00015   m_event   = -1;
00016   m_tofid   = -1;
00017   m_strip   = -1;
00018   m_qleft   = -99.0;
00019   m_qright  = -99.0;
00020   m_tleft   = -99.0;
00021   m_tright  = -99.0;
00022   m_zrhit   = -999.0;
00023   m_dt      = -999.0;
00024   m_texp    = -99.0;
00025   m_path    = -99.0;
00026   m_phi     = -99.0;
00027   m_theta   = -99.0;
00028   m_p       = -9.0;
00029   m_t0      = -99.0;
00030   m_q0      = -99.0;
00031   m_hitcase = -1;
00032   return;
00033 }
00034 
00035 
00036 Record::Record( RecBTofCalHit* hit ) {
00037   initial();
00038   if( hit ) {
00039     m_run     = hit->run();
00040     m_event   = hit->event();
00041     m_tofid   = hit->mod();
00042     m_strip   = int( hit->sinTheta() );
00043     m_qleft   = hit->adc1();
00044     m_qright  = hit->adc2();
00045     m_tleft   = hit->tdc1();
00046     m_tright  = hit->tdc2();
00047     m_zrhit   = hit->zHit();
00048     m_dt      = ( hit->tdc2() - hit->tdc1() )/2.0;
00049     m_texp    = hit->tpred();
00050     m_path    = hit->path();
00051     m_phi     = hit->deltaPhi();
00052     m_theta   = hit->sinTheta();
00053     m_p       = hit->p();
00054     m_hitcase = hit->qual();
00055   }
00056   return;
00057 }
00058 
00059 
00060 Record::Record( RecETofCalHit* hit ) {
00061   initial();
00062   if( hit ) {
00063     m_run     = hit->run();
00064     m_event   = hit->event();
00065     m_tofid   = hit->mod();
00066     m_qleft   = hit->adc();
00067     m_tleft   = hit->tdc();
00068     m_zrhit   = hit->rHit();
00069     m_texp    = hit->tpred();
00070     m_path    = hit->path();
00071     m_phi     = hit->deltaPhi();
00072     m_theta   = hit->cosTheta();
00073     m_p       = hit->p();
00074     m_hitcase = hit->qual();
00075   }
00076   return;
00077 }
00078 
00079 
00080 Record::Record( const rootRecord& one ) {
00081   initial();
00082   if( &one ) {
00083     m_run     = one.run;
00084     m_event   = one.event;
00085     m_tofid   = one.tofid;
00086     m_strip   = one.strip;
00087     m_qleft   = one.qleft;
00088     m_tleft   = one.tleft;
00089     if( ( one.hitcase >= 0 && one.hitcase <=2 ) || ( one.hitcase==5 || one.hitcase==6 ) ) {
00090       m_qright  = one.qright;
00091       m_tright  = one.tright;
00092     }
00093     m_zrhit   = one.zrhit;
00094     m_dt      = one.dt;
00095     m_texp    = one.texp;
00096     m_path    = one.path;
00097     m_phi     = one.phi;
00098     m_theta   = one.theta;
00099     m_p       = one.p;
00100     m_hitcase = one.hitcase;
00101   }
00102   return;
00103 }
00104 
00105 
00106 void TofDataSet::setData( TTree* t, unsigned int isBarrel ) {
00107   if( t && t->GetEntries()>0 ) {
00108     rootRecord item;
00109     t->SetBranchAddress( "run",     &item.run     );
00110     t->SetBranchAddress( "event",   &item.event   );
00111     t->SetBranchAddress( "tofid",   &item.tofid   );
00112     if( NULL != t->FindBranch( "strip" ) ) {
00113       t->SetBranchAddress( "strip",   &item.strip   );
00114     }
00115     t->SetBranchAddress( "qleft",   &item.qleft   );
00116     t->SetBranchAddress( "qright",  &item.qright  );
00117     t->SetBranchAddress( "tleft",   &item.tleft   );
00118     t->SetBranchAddress( "tright",  &item.tright  );
00119     t->SetBranchAddress( "zrhit",   &item.zrhit   );
00120     if( NULL != t->FindBranch( "dt" ) ) {
00121       t->SetBranchAddress( "dt",      &item.dt      );
00122     }
00123     t->SetBranchAddress( "texp",    &item.texp    );
00124     t->SetBranchAddress( "path",    &item.path    );
00125     t->SetBranchAddress( "phi",     &item.phi     );
00126     t->SetBranchAddress( "theta",   &item.theta        );
00127     t->SetBranchAddress( "p",       &item.p       );
00128     t->SetBranchAddress( "hitcase", &item.hitcase );
00129 
00130     for( unsigned int i=0; i<t->GetEntries(); i++ ) {
00131       t->GetEntry(i);
00132       if( isBarrel==1 && item.hitcase>=0 && item.hitcase<=2 ) {
00133         Record *r = new Record( item );
00134         if( r->cutBarrel() ) {
00135           unsigned int tofID = item.tofid;
00136           barrelData[tofID]->push_back(r);
00137         }
00138         else {
00139           delete r;
00140         }
00141       }
00142       else if( isBarrel==0 && ( item.hitcase==3 || item.hitcase==4 ) ) {
00143         Record *r = new Record( item );
00144         if( r->cutEndcap() ) {
00145           unsigned int tofID = item.tofid;
00146           endcapData[tofID]->push_back(r);
00147         }
00148         else {
00149           delete r;
00150         }
00151       }
00152       else if( isBarrel==2 && item.hitcase>=5 && item.hitcase<=6 ) {
00153         Record *r = new Record( item );
00154         if( r->cutEtf() ) {
00155           unsigned int tofID = item.tofid;
00156           unsigned int strip = item.strip;
00157           unsigned int id = tofID*12 + strip;
00158           etfData[id]->push_back(r);
00159         }
00160         else {
00161           delete r;
00162         }
00163       }
00164     }
00165   }
00166   else {
00167     std::cerr << "Error: a invalid tree or a blank tree, When converting a tree to TofDataSet,exit" << std::endl;
00168   }
00169 
00170   return;
00171 }
00172 
00173 
00174 TofDataSet::TofDataSet() {
00175   for( unsigned int i=0; i<NBarrel; i++ ) {
00176     barrelData[i] = new RecordSet;
00177   }
00178   for( unsigned int i=0; i<NEndcap; i++ ) {
00179     endcapData[i] = new RecordSet;
00180   }
00181   for( unsigned int i=0; i<NEtf*NStrip; i++ ) {
00182     etfData[i] = new RecordSet;
00183   }
00184   return;
00185 }
00186 
00187 
00188 TofDataSet::~TofDataSet() {
00189   for( unsigned int i=0; i<NBarrel; i++ ) {
00190     barrelData[i]->clear();
00191     delete barrelData[i];
00192   }
00193   for( unsigned int i=0; i<NEndcap; i++ ) {
00194     endcapData[i]->clear();
00195     delete endcapData[i];
00196   }
00197   for( unsigned int i=0; i<NEtf*NStrip; i++ ) {
00198     etfData[i]->clear();
00199     delete etfData[i];
00200   }
00201   return;
00202 }
00203 
00204 
00205 void TofDataSet::setBarrelDataFiles( std::vector<std::string>& barrelFiles ) {
00206   TChain* data_barrel = new TChain("btrk");
00207   if( !data_barrel ) {
00208     std::cerr << " tofcalgsec Error Msg: creating a tree[barrel] fails in TofDataSet()"<<std::endl;
00209     throw "Error Msg: creating a tree fails in TofDataSet() ";
00210   }
00211   std::cout<<"begin reading barrel data file ... "<<std::endl;
00212   try{
00213     for( std::vector<std::string>::iterator it=barrelFiles.begin(); it!=barrelFiles.end(); it++ ) {
00214       std::cout << " Add file : " << (*it) << std::endl;
00215       data_barrel->Add( (*it).c_str() );
00216     }
00217   }
00218   catch(...){
00219     std::cerr << "tofcalgsec Error Msg : in TofDataSet::setDataFiles(std::vector<std::string>&) " << std::endl;
00220     return;
00221   }
00222   setData( data_barrel, 1 );
00223   delete data_barrel;
00224   return;
00225 }
00226 
00227 
00228 void TofDataSet::setEndcapDataFiles( std::vector<std::string>& endcapFiles ) {
00229   TChain* data_endcap = new TChain("etrk");
00230   if( !data_endcap ) {
00231     std::cerr << " tofcalgsec Error Msg: creating a tree[endcap] fails in TofDataSet()"<<std::endl;
00232     throw "Error Msg: creating a tree fails in TofDataSet() ";
00233   }
00234   std::cout<<"begin reading endcap data file ... "<<std::endl;
00235   try{
00236     for( std::vector<std::string>::iterator it=endcapFiles.begin(); it!=endcapFiles.end(); it++ ) {
00237       std::cout << " Add file : " << (*it) << std::endl;
00238       data_endcap->Add( (*it).c_str() );
00239     }
00240   }
00241   catch(...){
00242     std::cerr << "tofcalgsec Error Msg : in TofDataSet::setDataFiles(std::vector<std::string>&) " << std::endl;
00243     return;
00244   }
00245   setData( data_endcap, 0 );
00246   delete data_endcap;
00247   return;
00248 }
00249 
00250 
00251 void TofDataSet::setEtfDataFiles( std::vector<std::string>& etfFiles ) {
00252   TChain* data_etf = new TChain("etf");
00253   if( !data_etf ) {
00254     std::cerr << " tofcalgsec Error Msg: creating a tree[etf] fails in TofDataSet()"<<std::endl;
00255     throw "Error Msg: creating a tree fails in TofDataSet() ";
00256   }
00257   std::cout<<"begin reading etf data file ... "<<std::endl;
00258   try{
00259     for( std::vector<std::string>::iterator it=etfFiles.begin(); it!=etfFiles.end(); it++ ) {
00260       std::cout << " Add file : " << (*it) << std::endl;
00261       data_etf->Add( (*it).c_str() );
00262     }
00263   }
00264   catch(...){
00265     std::cerr << "tofcalgsec Error Msg : in TofDataSet::setDataFiles(std::vector<std::string>&) " << std::endl;
00266     return;
00267   }
00268   setData( data_etf, 2 );
00269   delete data_etf;
00270   return;
00271 }
00272 
00273 
00274 void TofDataSet::setBarrelData( RecBTofCalHitCol& bhitcol ) {
00275   RecBTofCalHitCol::iterator iter = bhitcol.begin();
00276   for( ; iter!=bhitcol.end(); iter++ ) {
00277     int tofid = (*iter)->mod();
00278     if( tofid<0 || tofid>175 ) continue;
00279     if( fabs( (*iter)->dzHit() - 1.0 )>1.0e-6 ) continue;
00280 
00281     Record *r = new Record( (*iter) );
00282     if( r->cutBarrel() ) {
00283       barrelData[tofid]->push_back(r);
00284     }
00285     else {
00286       delete r;
00287     }
00288   }
00289   return;
00290 }
00291 
00292 
00293 void TofDataSet::setEndcapData( RecETofCalHitCol& ehitcol ) {
00294   RecETofCalHitCol::iterator iter = ehitcol.begin();
00295   for( ; iter!=ehitcol.end(); iter++ ) {
00296     int tofid = (*iter)->mod();
00297     if( tofid<0 || tofid>95 ) continue;
00298 
00299     Record *r = new Record( (*iter) );
00300     if( r->cutEndcap() ) {
00301       endcapData[tofid]->push_back(r);
00302     }
00303     else {
00304       delete r;
00305     }
00306   }
00307   return;
00308 }
00309 
00310 
00311 void TofDataSet::setEtfData( RecBTofCalHitCol& bhitcol ) {
00312   RecBTofCalHitCol::iterator iter = bhitcol.begin();
00313   for( ; iter!=bhitcol.end(); iter++ ) {
00314     int tofid = (*iter)->mod();
00315     int strip = int( (*iter)->sinTheta() );
00316     if( tofid<0 || tofid>71 ) continue;
00317     if( strip<0 || strip>11 ) continue;
00318     if( fabs( (*iter)->dzHit() )>1.0e-6 ) continue;
00319     unsigned int id = tofid*12 + strip;
00320     Record *r = new Record( (*iter) );
00321     if( r->cutEtf() ) {
00322       etfData[id]->push_back(r);
00323     }
00324     else {
00325       delete r;
00326     }
00327   }
00328   return;
00329 }
00330 

Generated on Tue Nov 29 23:14:36 2016 for BOSS_7.0.2 by  doxygen 1.4.7