LIRawNtAna Class Reference

#include <LIRawNtAna.h>

List of all members.

Public Member Functions

 LIRawNtAna ()
 ~LIRawNtAna ()
void Demo ()
void DemoOpenFile (std::string fileName)
void WriteOutHistos ()

Private Member Functions

void InitialiseLoopVariables ()
void MakeChain ()
void SetChainBranches ()
void SetLoopVariables (Int_t entry)
TFile * OpenFile (Int_t runNumber, std::string prefix) const

Private Attributes

TChain * chain
TFile * fOutFile
Int_t numEvents
Int_t nt_run
Int_t nt_snarl
Int_t nt_timesec
Int_t nt_timenanosec
Int_t nt_errcode
Int_t nt_crate
Int_t nt_varc
Int_t nt_vmm
Int_t nt_vaadc
Int_t nt_vachip
Int_t nt_vachannel
Int_t nt_pixel
Int_t nt_adc
Int_t nt_tdc
Int_t nt_readouttype
Short_t nt_pbox
Short_t nt_pboxopp
Short_t nt_led [nStripPerPixel]
Short_t nt_ledopp [nStripPerPixel]

Static Private Attributes

static const UInt_t nStripPerPixel = 8

Detailed Description

Definition at line 20 of file LIRawNtAna.h.


Constructor & Destructor Documentation

LIRawNtAna::LIRawNtAna (  ) 

Definition at line 55 of file LIRawNtAna.cxx.

References Msg::kDebug, Msg::kInfo, and MSG.

00056 {
00057   MSG("LIRawNtAna", Msg::kDebug) 
00058     <<"Running LIRawNtAna constructor..."<<endl;
00059 
00060   //data members
00061   nt_run=-1;
00062   nt_snarl=-1;
00063   nt_timesec=-1;
00064   nt_timenanosec=-1;
00065   nt_errcode=-1;
00066   nt_crate=-1;
00067   nt_varc=-1;
00068   nt_vmm=-1;
00069   nt_vaadc=-1;
00070   nt_vachip=-1;
00071   nt_vachannel=-1;
00072   nt_pixel=-1;
00073   nt_adc=-1;
00074   nt_tdc=-1;
00075   nt_readouttype=-1;
00076   nt_pbox=-1;
00077   nt_pboxopp=-1;
00078   for (UInt_t i=0;i<nStripPerPixel;++i){
00079     nt_led[i]=-1;
00080     nt_ledopp[i]=-1;
00081   }
00082 
00083   //data members not in tree
00084   fOutFile=0;
00085   chain=0;
00086   numEvents=-1;
00087   
00088   //set up the chain and perform some checks
00089   this->MakeChain();
00090   this->SetChainBranches();
00091   numEvents=static_cast<Int_t>(chain->GetEntries());
00092   MSG("LIRawNtAna",Msg::kInfo) 
00093     <<"Number of events in chain="<<numEvents<<endl; 
00094 
00095   MSG("LIRawNtAna", Msg::kInfo) 
00096     <<"Finished LIRawNtAna constructor"<<endl;
00097 }

LIRawNtAna::~LIRawNtAna (  ) 

Definition at line 101 of file LIRawNtAna.cxx.

References fOutFile, Msg::kDebug, and MSG.

00102 {
00103   MSG("LIRawNtAna", Msg::kDebug) 
00104     <<"Running LIRawNtAna destructor..."<<endl;
00105 
00106   if (fOutFile){
00107     //this makes histos disappear from the canvases 
00108     //so do it at the very end
00109     fOutFile->Close();
00110   }
00111 
00112   MSG("LIRawNtAna", Msg::kDebug) 
00113     <<"Finished LIRawNtAna destructor"<<endl;
00114 }


Member Function Documentation

void LIRawNtAna::Demo (  ) 

Definition at line 352 of file LIRawNtAna.cxx.

References det, Form(), fOutFile, RawChannelId::GetChAdd(), InitialiseLoopVariables(), Detector::kFar, Msg::kInfo, ElecType::kVA, MSG, nt_adc, nt_crate, nt_vaadc, nt_vachannel, nt_vachip, nt_varc, nt_vmm, numEvents, OpenFile(), and SetLoopVariables().

00353 {
00354   MSG("LIAnalysis",Msg::kInfo)
00355     <<endl<<" ** Running the Demo method... ** "<<endl;
00356   
00357   //open the file
00358   fOutFile=this->OpenFile(100,"AdcHistos");
00359 
00360   //declare variables
00361   Detector::Detector_t det=Detector::kFar;
00362   ElecType::Elec_t etype=ElecType::kVA;
00363   map<UInt_t,TH1F*> mHistos;
00364   
00365   Bool_t createHistos=true;
00366 
00367   //create histos
00368   if (createHistos) {
00369     for(Int_t crate=0;crate<16;++crate){
00370       for(Int_t varc=0;varc<3;++varc){
00371         for(Int_t vmm=0;vmm<5;++vmm){
00372           for(Int_t vaadc=0;vaadc<2;++vaadc){
00373             for(Int_t vachip=0;vachip<3;++vachip){
00374               for(Int_t vachannel=2;vachannel<18;++vachannel){
00375               
00376                 RawChannelId rcid(det,etype,
00377                                   crate,varc,vmm,vaadc,vachip,vachannel);
00378               
00379                 Int_t index=crate*10000+rcid.GetChAdd();
00380 
00381         /*      MAXMSG("LIRawNtAna",Msg::kInfo,100) 
00382                   <<"c-v-v-v-v-c="<<crate
00383                   <<"-"<<varc
00384                   <<"-"<<vmm
00385                   <<"-"<<vaadc
00386                   <<"-"<<vachip
00387                   <<"-"<<vachannel
00388                   <<", rcid="<<rcid.GetChAdd()
00389                   <<", index="<<index
00390                   <<endl;
00391           */    
00392                 //      string s="hAdc";
00393                 string sChAdd=Form("crate%i_varc%i_vmm%i_vaadc%i_vachip%i_vachannel%i",crate,varc,vmm,vaadc,vachip,vachannel);
00394         //      string sChAdd=Form("%d",rcid.GetChAdd());
00395         //      s=s+sCrate+"_"+sChAdd;
00396          string s=sChAdd;
00397                 mHistos[index]=new TH1F(s.c_str(),s.c_str(),
00398                                         1000,0,1000);
00399 
00400               }
00401             }
00402           }
00403         }
00404       }
00405     }
00406   }
00407   
00411   
00412   this->InitialiseLoopVariables();  
00413   
00414   for(Int_t entry=0;entry<numEvents;entry++){
00415   //for(Int_t entry=0;entry<600000;entry++){
00416   //for(Int_t entry=690000;entry<numEvents;entry++){
00417     this->SetLoopVariables(entry);
00418     
00419     //MAXMSG("LIAnalysis",Msg::kInfo,100)
00420     //<<"snarl="<<nt_snarl<<endl;
00421     
00422     RawChannelId rcid(det,etype,
00423                       nt_crate,nt_varc,nt_vmm,nt_vaadc,
00424                       nt_vachip,nt_vachannel);
00425     
00426     Int_t index=nt_crate*10000+rcid.GetChAdd();
00427 
00428 /*    MAXMSG("LIRawNtAna",Msg::kInfo,100) 
00429       <<"c-v-v-v-v-c="<<nt_crate
00430       <<"-"<<nt_varc
00431       <<"-"<<nt_vmm
00432       <<"-"<<nt_vaadc
00433       <<"-"<<nt_vachip
00434       <<"-"<<nt_vachannel
00435       <<", rcid="<<rcid.GetChAdd()
00436       <<", index="<<index
00437       <<endl;
00438 */
00439     map<UInt_t,TH1F*>::iterator histoItr=mHistos.find(index);
00440     if (histoItr!=mHistos.end()) {//found it
00441       (histoItr->second)->Fill(nt_adc);
00442     }
00443     
00444   }//end of for
00445   
00449   
00450   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00451   
00452   MSG("LIAnalysis",Msg::kInfo)
00453     <<" ** Finished the Demo method ** "<<endl;
00454 }

void LIRawNtAna::DemoOpenFile ( std::string  fileName  ) 

Definition at line 458 of file LIRawNtAna.cxx.

References det, Form(), RawChannelId::GetChAdd(), Detector::kFar, Msg::kInfo, ElecType::kVA, and MAXMSG.

00459 {
00460   //TFile* file=TFile::Open(fileName.c_str());
00461   TFile::Open(fileName.c_str());
00462   
00463   //declare variables
00464   Detector::Detector_t det=Detector::kFar;
00465   ElecType::Elec_t etype=ElecType::kVA;
00466 
00467   //create histos
00468   for(Int_t crate=0;crate<16;++crate){
00469     for(Int_t varc=0;varc<3;++varc){
00470       for(Int_t vmm=0;vmm<6;++vmm){
00471         for(Int_t vaadc=0;vaadc<2;++vaadc){
00472           for(Int_t vachip=0;vachip<3;++vachip){
00473             for(Int_t vachannel=2;vachannel<18;++vachannel){
00474               
00475               RawChannelId rcid(det,etype,
00476                                 crate,varc,vmm,vaadc,vachip,vachannel);
00477               
00478               Int_t index=crate*10000+rcid.GetChAdd();
00479               
00480               MAXMSG("LIRawNtAna",Msg::kInfo,100) 
00481                 <<"c-v-v-v-v-c="<<crate
00482                 <<"-"<<varc
00483                 <<"-"<<vmm
00484                 <<"-"<<vaadc
00485                 <<"-"<<vachip
00486                 <<"-"<<vachannel
00487                 <<", rcid="<<rcid.GetChAdd()
00488                 <<", index="<<index
00489                 <<endl;
00490               
00491               string s="hAdc";
00492               string sCrate=Form("%d",crate);
00493               string sChAdd=Form("%d",rcid.GetChAdd());
00494               s=s+sCrate+"_"+sChAdd;
00495 
00496               TH1F* h=(TH1F*)gROOT->FindObject(s.c_str());
00497               
00498               if (h) {
00499                 MAXMSG("LIRawNtAna",Msg::kInfo,1000) 
00500                   <<"mean="<<h->GetMean()<<endl;
00501               }
00502               else cout<<"No histo with name="<<s<<endl;
00503             }
00504           }
00505         }
00506       }
00507     }
00508   }
00509 
00510 
00511 }

void LIRawNtAna::InitialiseLoopVariables (  )  [private]

Definition at line 314 of file LIRawNtAna.cxx.

References Msg::kInfo, and MSG.

Referenced by Demo().

00315 {
00316   MSG("LIRawNtAna",Msg::kInfo)<<"Initialising loop variables..."<<endl;
00317   /*
00318   liEvent=-1;//want first event to be 0 not 1
00319   lastLed=-1;
00320   lastPulserBox=-1;
00321   lastCalibPoint=-1;
00322   liRunNum=0;
00323   run=0;
00324 
00325   //get first event
00326   chain->GetEvent(0);  
00327   previousRunNumber=runNumber;
00328   */
00329   MSG("LIRawNtAna",Msg::kInfo)<<"Initialisation complete"<<endl;
00330 }

void LIRawNtAna::MakeChain (  )  [private]

Definition at line 217 of file LIRawNtAna.cxx.

References chain, exit(), Msg::kDebug, Msg::kFatal, Msg::kInfo, and MSG.

00218 {
00219   MSG("LIRawNtAna", Msg::kDebug)<<"Running MakeChain method..."<<endl;
00220 
00221   //LI data files to read in
00222   char* envVariable=getenv("LIDATA");
00223   if (envVariable==NULL){
00224     MSG("LIRawNtAna",Msg::kFatal)
00225       <<endl<<endl
00226       <<"*************************************************************"
00227       <<endl<<"Environmental variable LIDATA not set!"<<endl
00228       <<"Please set LIDATA to the directory containing the"
00229       <<" liraw*.root files"<<endl
00230       <<"Note: If more than one file is found they will be"
00231       <<" concatenated and treated as one"<<endl
00232       <<"*************************************************************"
00233       <<endl<<endl<<"Program will exit here"<<endl;
00234     exit(0);
00235   }
00236   string sEnv=envVariable;
00237   MSG("LIRawNtAna",Msg::kInfo)
00238     <<"Looking for liraw*.root files using the env variable"<<endl
00239     <<"LIDATA="<<sEnv<<endl;
00240   
00241   string sFileName=sEnv+"/liraw*.root";
00242 
00243   // create a chain with li_tree
00244   //chain=new TChain("li_tree");  
00245   chain=new TChain("liraw");  
00246   //add the files to the chain
00247   Int_t nf=chain->Add(sFileName.c_str());
00248 
00249   if(nf==0){
00250     MSG("LIRawNtAna",Msg::kFatal)
00251       <<endl<<endl
00252       <<"*************************************************************"
00253       <<endl<<"No liraw*.root files found in "<<sEnv<<endl
00254       <<"Please set LIDATA to the directory containing the"
00255       <<" liraw*.root files"<<endl
00256       <<"Note: If more than one file is found they will be"
00257       <<" concatenated and treated as one"<<endl
00258       <<"*************************************************************"
00259       <<endl<<endl<<"Program will exit here"<<endl;
00260     exit(0);
00261   }
00262     
00263   MSG("LIRawNtAna",Msg::kInfo) 
00264     <<"Printing tree information:"<<endl;
00265   chain->Show(1);
00266   //chain->Print()
00267   
00268   if (nf==1){
00269     MSG("LIRawNtAna",Msg::kInfo) 
00270       <<endl<<"Analysing "<<nf<<" file of the form liraw*.root in"
00271       <<endl<<"LIDATA="<<sEnv<<endl<<endl;
00272   }
00273   else{
00274     MSG("LIRawNtAna",Msg::kInfo)
00275       <<endl<<"Analysing "<<nf
00276       <<" files of the form liraw*.root in directory"
00277       <<endl<<"LIDATA="<<sEnv<<endl<<endl;
00278     MSG("LIRawNtAna",Msg::kInfo)
00279       <<"Reading in files..."<<endl;
00280   }
00281 
00282   MSG("LIRawNtAna", Msg::kDebug)<<"Finished the MakeChain method"<<endl;
00283 }

TFile * LIRawNtAna::OpenFile ( Int_t  runNumber,
std::string  prefix 
) const [private]

Definition at line 140 of file LIRawNtAna.cxx.

References Form(), Msg::kInfo, and MSG.

Referenced by Demo().

00141 {
00142   //call this static function to ensure any histograms created
00143   //after the file is opened are added
00144   TH1::AddDirectory(true);
00145 
00146   //create the tfile pointer to be returned
00147   TFile* outputFile=0;
00148   
00149   //get the environmental variable
00150   char *anaDir=getenv("NUANA_DIR");
00151   
00152   //use a string to hold env instead 
00153   string sAnaDir="";
00154   
00155   if (anaDir!=NULL) {
00156     sAnaDir=anaDir;
00157   }
00158   else {
00159     MSG("LIRawNtAna",Msg::kInfo) 
00160       <<"Environmental variable $NUANA_DIR not set." 
00161       <<" Writing file(s) to current directory"<<endl;
00162     sAnaDir=".";
00163   }
00164   
00165   //convert variables to string
00166   string sRunNumber=Form("%d",runNumber);
00167   string sZeros="";
00168   if (runNumber>=0 && runNumber<10) sZeros="00000000";
00169   else if (runNumber>=10 && runNumber<100) sZeros="000000";
00170   else if (runNumber>=100 && runNumber<1000) sZeros="00000";
00171   else if (runNumber>=1000 && runNumber<10000) sZeros="0000";
00172   else if (runNumber>=10000 && runNumber<100000) sZeros="000";
00173   else if (runNumber>=100000 && runNumber<1000000) sZeros="00";
00174   else if (runNumber>=1000000 && runNumber<10000000) sZeros="0";
00175   else if (runNumber>=10000000 && runNumber<100000000) sZeros="";
00176   sRunNumber=sZeros+sRunNumber;
00177 
00178   //string sDetectorType="C";
00179   string sDetector="";
00180   //string sPrefix="h";//default
00181   string sPrefix="";//default
00182   if (prefix!="") sPrefix+=prefix;
00183   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00184   string sFileName=sBase+".root";
00185   
00186   //test if file already exists
00187   ifstream Test(sFileName.c_str());
00188   
00189   //open the appropriate file
00190   if(!Test){
00191     outputFile=new TFile(sFileName.c_str(),"RECREATE");
00192   }
00193   else {
00194     //Need new filename
00195     Int_t fred=1;
00196     while(Test) {
00197       Test.close();
00198       string sAppendage=Form("%d",fred);
00199       sFileName=sBase+"_"+sAppendage+".root";
00200       Test.open(sFileName.c_str());
00201       fred++;
00202     }
00203     outputFile=new TFile(sFileName.c_str(),"NEW");
00204     outputFile->SetCompressionLevel(9);
00205   }
00206   
00207   string sTmp="No File!";
00208   if (outputFile) sTmp=outputFile->GetName();
00209 
00210   MSG("LIRawNtAna",Msg::kInfo) 
00211     <<"Output file opened: "<<sTmp<<endl;
00212   return outputFile;
00213 }

void LIRawNtAna::SetChainBranches (  )  [private]

Definition at line 287 of file LIRawNtAna.cxx.

References chain, nt_adc, nt_crate, nt_errcode, nt_led, nt_ledopp, nt_pbox, nt_pboxopp, nt_pixel, nt_readouttype, nt_run, nt_snarl, nt_tdc, nt_timenanosec, nt_timesec, nt_vaadc, nt_vachannel, nt_vachip, nt_varc, and nt_vmm.

00288 {
00289   //chain->SetBranchAddress("ashtray",&ashtray);
00290   chain -> SetBranchAddress("run", &nt_run);
00291   chain -> SetBranchAddress("snarl", &nt_snarl);
00292   chain -> SetBranchAddress("timesec", &nt_timesec);
00293   chain -> SetBranchAddress("timenanosec", &nt_timenanosec);
00294   chain -> SetBranchAddress("errcode", &nt_errcode);
00295   chain -> SetBranchAddress("crate", &nt_crate);
00296   chain -> SetBranchAddress("varc", &nt_varc);
00297   chain -> SetBranchAddress("vmm", &nt_vmm);
00298   chain -> SetBranchAddress("vaadc", &nt_vaadc);
00299   chain -> SetBranchAddress("vachip", &nt_vachip);
00300   chain -> SetBranchAddress("vachannel", &nt_vachannel);
00301   chain -> SetBranchAddress("pixel", &nt_pixel);
00302   chain -> SetBranchAddress("adc", &nt_adc);
00303   chain -> SetBranchAddress("tdc", &nt_tdc);
00304   chain -> SetBranchAddress("readouttype", &nt_readouttype);
00305   chain -> SetBranchAddress("pbox", &nt_pbox);
00306   chain -> SetBranchAddress("pboxopp", &nt_pboxopp);
00307   chain -> SetBranchAddress("led", nt_led);
00308   chain -> SetBranchAddress("ledopp", nt_ledopp);
00309 
00310 }

void LIRawNtAna::SetLoopVariables ( Int_t  entry  )  [private]

Definition at line 334 of file LIRawNtAna.cxx.

References chain, Msg::kInfo, MSG, and numEvents.

Referenced by Demo().

00335 {
00336 
00337   //Float_t fract=ceil(numEvents/10.);
00338   Float_t fract=ceil(numEvents/10000.);
00339   
00340   if (ceil(((Float_t)entry)/fract)==((Float_t)entry)/fract){
00341     MSG("LIRawNtAna",Msg::kInfo) 
00342       <<"Fraction of loop complete: "<<entry 
00343       <<"/"<<numEvents<<"  ("
00344       <<(Int_t)(100.*entry/numEvents)<<"%)"<<endl;
00345   }
00346 
00347   chain->GetEvent(entry);
00348 }  

void LIRawNtAna::WriteOutHistos (  ) 

Definition at line 118 of file LIRawNtAna.cxx.

References fOutFile, Msg::kInfo, Msg::kWarning, and MSG.

00119 {
00120   //write out the histos to the file, if it's open
00121   if (fOutFile){
00122     if (fOutFile->IsWritable()) {
00123       fOutFile->cd();
00124 
00125       MSG("LIRawNtAna",Msg::kInfo)
00126         <<"Writing histos to: "<<fOutFile->GetName()<<" ..."<<endl;
00127       fOutFile->Write();
00128       //fOutFile->Close();//this makes histos disappear from canvases
00129       //so do it in the destructor (need to make LIRawNtAna on heap)
00130     }
00131     else {
00132       MSG("LIRawNtAna",Msg::kWarning)
00133         <<"File not writable!"<<endl;
00134     }
00135   }
00136 }


Member Data Documentation

TChain* LIRawNtAna::chain [private]

Definition at line 42 of file LIRawNtAna.h.

Referenced by MakeChain(), SetChainBranches(), and SetLoopVariables().

TFile* LIRawNtAna::fOutFile [private]

Definition at line 43 of file LIRawNtAna.h.

Referenced by Demo(), WriteOutHistos(), and ~LIRawNtAna().

const UInt_t LIRawNtAna::nStripPerPixel = 8 [static, private]

Definition at line 46 of file LIRawNtAna.h.

Int_t LIRawNtAna::nt_adc [private]

Definition at line 60 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::nt_crate [private]

Definition at line 53 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::nt_errcode [private]

Definition at line 52 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Short_t LIRawNtAna::nt_led[nStripPerPixel] [private]

Definition at line 65 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Definition at line 66 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Short_t LIRawNtAna::nt_pbox [private]

Definition at line 63 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Short_t LIRawNtAna::nt_pboxopp [private]

Definition at line 64 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_pixel [private]

Definition at line 59 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_readouttype [private]

Definition at line 62 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_run [private]

Definition at line 48 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_snarl [private]

Definition at line 49 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_tdc [private]

Definition at line 61 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_timenanosec [private]

Definition at line 51 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_timesec [private]

Definition at line 50 of file LIRawNtAna.h.

Referenced by SetChainBranches().

Int_t LIRawNtAna::nt_vaadc [private]

Definition at line 56 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::nt_vachannel [private]

Definition at line 58 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::nt_vachip [private]

Definition at line 57 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::nt_varc [private]

Definition at line 54 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::nt_vmm [private]

Definition at line 55 of file LIRawNtAna.h.

Referenced by Demo(), and SetChainBranches().

Int_t LIRawNtAna::numEvents [private]

Definition at line 44 of file LIRawNtAna.h.

Referenced by Demo(), and SetLoopVariables().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1