Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

detector.cxx

Go to the documentation of this file.
00001 #include "detector.h"
00002 #include "Plex/PlexHandle.h"
00003 #include "Plex/PlexSEIdAltL.h"
00004 
00005 Detector::Detector()
00006 {
00007   memset(channels,0,sizeof(channels));
00008   first_time=0;
00009   
00010   const char *dir = gSystem->Getenv("LISUMMARY_OUTPUT_DIR");
00011   if (!dir) {
00012     cerr << "Set LISUMMARY_OUTPUT_DIR first!\n";
00013     exit(1);
00014   }
00015   
00016   sprintf(filename,"%s/combined.root",dir);
00017   outfile = new TFile(filename,"NEW");
00018   if(!outfile->IsOpen()){
00019     cout << " ** file already exists, making different name ** " << endl;
00020     sprintf(filename,"%s/combined_1.root",dir);
00021     outfile = new TFile(filename,"NEW");
00022   }
00023   cout << " ** Created output file " << filename << " ** " << endl;
00024   InitialiseTree();
00025   cout << " ** Made detector ** " << endl;
00026 }
00027 
00028 
00029 
00030 void Detector::Update(Int_t new_led,
00031                       Int_t new_pulse_height,
00032                       Int_t new_pulse_width,
00033                       Int_t new_pulserbox,
00034                       Int_t new_calibpoint,
00035                       VldTimeStamp new_time, 
00036                       Int_t new_calibtype,
00037                       Int_t new_pulses,
00038                       Int_t new_period){
00039   
00040 
00041   
00042   if(first_time==0){
00043     first_time=1;
00044     calibpoint = new_calibpoint;
00045     pulse_height = new_pulse_height;
00046     pulse_width = new_pulse_width;
00047     pulserbox = new_pulserbox;
00048     led = new_led;
00049     time = new_time;
00050     period = new_period;
00051     calibtype = new_calibtype;
00052     pulses = new_pulses;
00053     
00054     cout << " ** Found first point " << new_pulserbox << " :: " 
00055          << new_led << " at time " << new_time << " ** " << endl;
00056 
00057     cout << " ** opening database ** " << endl;
00058     myplexhandle = new PlexHandle(validity);
00059     
00060   }
00061   
00062   if( (new_led != led) 
00063       || (new_pulse_height != pulse_height)
00064       || (new_pulse_width != pulse_width)
00065       || (new_pulserbox != pulserbox)
00066       || (new_calibpoint != calibpoint)){
00067     
00068     cout << " ** Found new point " << new_pulserbox << " :: " 
00069          << new_led << " at time " << new_time << " ** " << endl;
00070     
00071     // Write out data here...
00072     Int_t channel_address;
00073     
00074     for(Int_t crate_loop=0;crate_loop<10;crate_loop++){
00075       for(Int_t chad_loop=0;chad_loop<6000;chad_loop++){
00076         channel_address = (crate_loop*6000) + chad_loop;
00077         if(channels[channel_address] !=0){
00078           timestamp = new_time.GetSec();
00079 
00080           mean = channels[channel_address]->GetMean();
00081           rms = channels[channel_address]->GetRMS();
00082           no_entries = channels[channel_address]->GetEntries();
00083           
00084           crate = channels[channel_address]->GetChannelId().GetCrate();
00085           chAdd = channels[channel_address]->GetChannelId().GetChAdd();
00086           vaarc = channels[channel_address]->GetChannelId().GetVarcId();
00087           vmm = channels[channel_address]->GetChannelId().GetVmm();
00088           vaadc = channels[channel_address]->GetChannelId().GetVaAdcSel();
00089           
00090           chip = channels[channel_address]->GetChannelId().GetVaChip();
00091           channel = channels[channel_address]->GetChannelId().GetVaChannel();
00092           plane = myplexhandle->GetSEIdAltL(channels[channel_address]->GetChannelId()).GetPlane();
00093 
00094           outtree->Fill();
00095         }
00096       }
00097     }
00098     // Clean all channels..
00099 
00100     memset(channels,0,sizeof(channels));
00101     
00102 
00103 
00104     first_time=1;
00105     calibpoint = new_calibpoint;
00106     pulse_height = new_pulse_height;
00107     pulse_width = new_pulse_width;
00108     pulserbox = new_pulserbox;
00109     led = new_led;
00110     period = new_period;
00111     calibtype = new_calibtype;
00112     pulses = new_pulses;
00113 
00114 
00115   }
00116 
00117 
00118 };
00119 
00120 void Detector::AddEntry(RawChannelId channelid,
00121                         Double_t mean,
00122                         Double_t rms,
00123                         Int_t no_entries
00124                         ){
00125   Int_t channel_address=0;
00126   channel_address = (channelid.GetCrate()*6000) + channelid.GetChAdd();
00127   
00128   if(channels[ channel_address ] ==0){
00129     channels[ channel_address ] = new Channel(channelid);
00130   }
00131   
00132   channels[channel_address]->AddEntry(no_entries,mean,rms);
00133     
00134 };
00135  
00136 
00137 
00138 void Detector::InitialiseTree(){
00139   cout << " Making Tree " << endl;
00140   outfile = new TFile(filename,"RECREATE");
00141   outtree = new TTree("li_tree","li_tree");
00142   
00143 
00144   outtree->Branch("calibpoint",&calibpoint,"calibpoint/I",32000);
00145   outtree->Branch("pulserbox",&pulserbox,"pulserbox/I",32000); 
00146   outtree->Branch("led",&led,"led/I",32000);
00147   outtree->Branch("pulse_height",&pulse_height,"pulse_height/I",32000);
00148   outtree->Branch("pulse_width",&pulse_width,"pulse_width/I",32000);
00149   outtree->Branch("period",&period,"period/I",32000);
00150   outtree->Branch("calibtype",&calibtype,"calibtype/I",32000);
00151   outtree->Branch("pulses",&pulses,"pulses/I",32000);
00152   outtree->Branch("timestamp",&timestamp,"timestamp/I",32000);
00153 
00154 
00155   outtree->Branch("crate",&crate,"crate/I",32000);
00156   outtree->Branch("chAdd",&chAdd,"chAdd/I",32000);
00157   outtree->Branch("vaarc",&vaarc,"vaarc/I",32000);
00158   outtree->Branch("vmm",&vmm,"vmm/I",32000);
00159   outtree->Branch("vaadc",&vaadc,"vaadc/I",32000);
00160 
00161 
00162   outtree->Branch("plane",&plane,"plane/I",32000);
00163   outtree->Branch("chip",&chip,"chip/I",32000);
00164   outtree->Branch("channel",&channel,"channel/I",32000);
00165 
00166   outtree->Branch("no_entries",&no_entries,"no_entries/I",32000);
00167   outtree->Branch("mean",&mean,"mean/D",32000);
00168   outtree->Branch("rms",&rms,"rms/D",32000);
00169 
00170   cout <<" ** Made Tree ** " << endl;
00171 
00172 };

Generated on Mon Feb 15 11:06:37 2010 for loon by  doxygen 1.3.9.1