// $Id$ // // File: MyProcessor.cc // Created: Mon Aug 21 14:42:12 EDT 2006 // Creator: davidl (on Darwin swire-b241.jlab.org 8.7.0 powerpc) // #include "DEventSourceET/DADC.h" #include "DEventSourceET/DTDC.h" #include "DEventSourceET/DTrigger.h" #include "BCAL/DBCAL_ADCHit.h" #include "BCAL/DBCAL_TDCHit.h" #include "TRIGGER/DTRIGGER_TDCHit.h" #include "TAGGER/DTAGGER_EHit.h" #include "TAGGER/DTAGGER_THit.h" #include "TAGGER/DTAGGER_ETCoinc.h" #include "MyProcessor.h" //------------------ // init //------------------ jerror_t MyProcessor::init(void) { file = NULL; histServer = NULL; return NOERROR; } //------------------ // brun //------------------ jerror_t MyProcessor::brun(JEventLoop *eventLoop, int runnumber) { // Special events (like prestart and go) will not have run number // info in them. Ignore these. if(runnumber==0)return NOERROR; // EPICS events work to confuse us. They will have a run number of // zero (which we handle just above). However, the next event // changes the run number back and causes us to reopen the file. // Here, we catch these cases and avoid re-opening the file if // the runnumber hasn't actually changes since we opened it. static int last_runnumber = 0; if(runnumber == last_runnumber)return NOERROR; last_runnumber = runnumber; // Create ROOT file char fname[256]; sprintf(fname,"bcal_mon%05d.root", runnumber); file = new TFile(fname, "RECREATE"); cout<<"Opened \""<SetXTitle("Time"); eid_vs_time->SetYTitle("E-counter ID"); tidl_vs_time=new TH2F("tidl_vs_time","Left T-counter ID vs. time", 4000,0,40000 , 61,0.5,61.5); tidl_vs_time->SetXTitle("Time"); tidl_vs_time->SetYTitle("T-counter ID"); tidr_vs_time=new TH2F("tidr_vs_time","Right T-counter ID vs. time", 4000,0, 40000 , 61,0.5,61.5); tidr_vs_time->SetXTitle("Time"); tidr_vs_time->SetYTitle("T-counter ID"); tid_vs_time= new TH2F("tid_vs_time","T-counter ID vs. mean time", 1500,550,700, 61,0.5,61.5); tid_vs_time->SetXTitle("Mean Time (ns)"); tid_vs_time->SetYTitle("T-counter ID"); tid_vs_eid = new TH2F("tid_vs_eid","T-counter id vs E-counter id", 384,0.5,384.5,61,0.5,61.5); tid_vs_eid->SetXTitle("E-counter ID"); tid_vs_eid->SetYTitle("T-counter ID"); tid_vs_bcal_ssum= new TH2F("tid_vs_bcal_ssum", "T-counter ID vs BCAL S Sum", 500,0,4000, 61,0.5,61.5); tid_vs_bcal_ssum->SetXTitle("BCAL S Sum"); tid_vs_bcal_ssum->SetYTitle("T_id"); tid_vs_bcal_nsum= new TH2F("tid_vs_bcal_nsum", "T-counter ID vs BCAL N Sum", 500,0,4000, 61,0.5,61.5); tid_vs_bcal_nsum->SetXTitle("BCAL N Sum"); tid_vs_bcal_nsum->SetYTitle("T_id"); tag_et_tdiff= new TH1F("tag_et_tdiff", "Time difference between E's and T's after geometric matching", 500,-250,250); tag_et_tdiff->SetXTitle("#Deltat (ns)"); egamma=new TH1F("egamma","Tagged photon energy",700,0,700); egamma->SetXTitle("E[g] (MeV)"); // pedestal histograms channel_vs_ped_slot18 = new TH2F("channel_vs_ped_slot18", "ADC pedestal vs. channel slot 18", 512, 0.0, 512.0, 32, -0.5, 31.5); channel_vs_ped_slot19 = new TH2F("channel_vs_ped_slot19", "ADC pedestal vs. channel slot 19", 512, 0.0, 512.0, 32, -0.5, 31.5); // Trigger labels const char *tlabels[12] = {"MOR", "BCAL-OR", "BCAL-AND", "MOR AND BCAL-OR", "MOR AND BCAL-AND", "COSMIC", "Pulser", "unused", "unused", "VETO", "BCAL-S", "BCAL-N"}; // ADC Histogram id_vs_adc = new TH2F("id_vs_adc", "ADC vs. ID", 256, 0.0, 4096.0, 64, -0.5, 63.5); TAxis *axis = id_vs_adc->GetYaxis(); axis->SetLabelSize(0.025); for(int i=1; i<=18; i++){ char label[256]; sprintf(label,"BCALN%02d",i); axis->SetBinLabel(i, label); sprintf(label,"BCALS%02d",i); axis->SetBinLabel(i+32, label); } axis->SetBinLabel(62, "VETO"); axis->SetBinLabel(63, "COSMIC1"); axis->SetBinLabel(64, "COSMIC2"); id_vs_adc->SetXTitle("ADC value (adc counts)"); // TDC Histogram id_vs_tdc = new TH2F("id_vs_tdc", "ID vs. TDC", 256, 0.0, 4096.0, 64, -0.5, 63.5); axis = id_vs_tdc->GetYaxis(); axis->SetLabelSize(0.025); for(int i=1, bin=1; i<=18; i++){ if(i==1 || i==13)continue; char label[256]; sprintf(label,"BCALN%02d",i); axis->SetBinLabel(bin, label); sprintf(label,"BCALS%02d",i); axis->SetBinLabel(bin+16, label); bin++; } for(int i=1; i<=12; i++){ // Triggers start at channel 30 of slot 11 and go backwards axis->SetBinLabel(64-i, tlabels[i-1]); } axis->SetBinLabel(33, "BCALN01"); axis->SetBinLabel(34, "BCALN13"); axis->SetBinLabel(35, "BCALS01"); axis->SetBinLabel(36, "BCALS13"); axis->SetBinLabel(37, "VETO"); axis->SetBinLabel(38, "COSMIC1"); axis->SetBinLabel(39, "COSMIC2"); id_vs_tdc->SetXTitle("TDC value (tdc counts)"); // Time histogram id_vs_t = new TH2F("id_vs_t", "ID vs. time(ns)", 256, -255.0, 256.0, 36, 0.5, 36.5); axis = id_vs_t->GetYaxis(); axis->SetLabelSize(0.025); for(int i=1; i<=18; i++){ char label[256]; sprintf(label,"BCALN%02d",i); axis->SetBinLabel(i, label); sprintf(label,"BCALS%02d",i); axis->SetBinLabel(i+18, label); } id_vs_t->SetXTitle("Time (ns)"); // Time diff histogram id_vs_tdiff = new TH2F("id_vs_tdiff", "ID vs. time diff(ns)", 512, -255.0, 256.0, 18, 0.5, 18.5); id_vs_tavg = new TH2F("id_vs_tavg", "ID vs. time avg(ns)", 512, -255.0, 256.0, 18, 0.5, 18.5); axis = id_vs_tdiff->GetYaxis(); TAxis *axis2 = id_vs_tavg->GetYaxis(); axis->SetLabelSize(0.025); axis2->SetLabelSize(0.025); for(int i=1; i<=18; i++){ char label[256]; sprintf(label,"BCAL%02d",i); axis->SetBinLabel(i, label); axis2->SetBinLabel(i, label); } id_vs_tdiff->SetXTitle("North - South Time Diff (ns)"); id_vs_tavg->SetXTitle("North/South Time Avg. (ns)"); // Trigger latch trigger = new TH1F("trigger","Triggers in latch word",12, 0.5,12.5); axis = trigger->GetXaxis(); for(int i=0;i<12;i++)axis->SetBinLabel(i+1,tlabels[i]); trigger->SetStats(0); trigger->SetBarWidth(); trigger->SetBarOffset(); trigger->SetFillColor(kBlue); // Trigger TDC trig_vs_t = new TH2F("trig_vs_t", "Trigger vs. time(ns)", 256, -255.0, 256.0, 12, 0.5, 12.5); axis = trig_vs_t->GetYaxis(); axis->SetLabelSize(0.025); for(int i=0;i<12;i++)axis->SetBinLabel(i+1,tlabels[i]); trig_vs_t->SetStats(0); // Energy Histogram id_vs_E = new TH2F("id_vs_E", "Energy(MeV) vs. ID", 440, 0.0, 220.0, 36, 0.5, 36.5); axis = id_vs_E->GetYaxis(); axis->SetLabelSize(0.025); for(int i=1; i<=18; i++){ char label[256]; sprintf(label,"BCALN%02d",i); axis->SetBinLabel(i, label); sprintf(label,"BCALS%02d",i); axis->SetBinLabel(i+18, label); } id_vs_adc->SetXTitle("Energy (MeV)"); // North and South ADC sums adcsumN = new TH1F("adcsumN","ADC sum of North PMTs",1000,-100.0,7500.0); adcsumS = new TH1F("adcsumS","ADC sum of South PMTs",1000,-100.0,7500.0); adcsumN_vs_adcsumS = new TH2F("adcsumN_vs_adcsumS","North vs.South PMT sums",200,-100.0, 7500.0,200,-100.0, 7500.0); return NOERROR; } //------------------ // evnt //------------------ jerror_t MyProcessor::evnt(JEventLoop *loop, int eventnumber) { // If ROOT file is not open, then do nothing if(!file)return NOERROR; // Get data vector dadcs; vector dtdcs; vector dtriggers; vector adchits; vector tdchits; vector trighits; vector tage_hits; vector tagt_hits; vectortaget_hits; loop->Get(dadcs); loop->Get(dtdcs); loop->Get(dtriggers); loop->Get(adchits); loop->Get(tdchits); loop->Get(trighits); loop->Get(tage_hits); loop->Get(tagt_hits); loop->Get(taget_hits); // Lock //histServer->Lock(); // Fill histograms // TAGGER for (unsigned int i=0;iFill(ehit->time,ehit->E_id); } for (unsigned int i=0;iT_side==0) tidl_vs_time->Fill(thit->time,thit->T_id); else tidr_vs_time->Fill(thit->time,thit->T_id); } for (unsigned int i=0;iFill(ethit->time,ethit->T_id); if (ethit->energy>0) egamma->Fill(ethit->energy); for (unsigned int j=0;jeid_list.size();j++){ tid_vs_eid->Fill(ethit->eid_list[j].id,ethit->T_id); tag_et_tdiff->Fill(ethit->time-ethit->eid_list[j].time); } } // ADC for(unsigned int i=0; ioverflow)continue; if(dadc->slot==18)channel_vs_ped_slot18->Fill(dadc->adc, dadc->channel); if(dadc->slot==19)channel_vs_ped_slot19->Fill(dadc->adc, dadc->channel); int id = dadc->channel + (dadc->slot-18)*32; id_vs_adc->Fill(dadc->adc, id); } // TDC for(unsigned int i=0; ichannel + (dtdc->slot-10)*32; id_vs_tdc->Fill(dtdc->tdc, id); } // Trigger if(dtriggers.size()==1){ unsigned int latch = (dtriggers[0])->latch; for(int i=1; i<=12; i++){ if((latch>>(i-1)) & 0x1)trigger->Fill(i); } } // Energy float sumN=0.0, sumS=0.0; for(unsigned int i=0; isector-1)*6 + adchit->layer; if(adchit->end==1)id+=18; id_vs_E->Fill(adchit->E_attenuated*1000.0,id); if(adchit->end==0)sumN += (float)(adchit->adc-adchit->ped); if(adchit->end==1)sumS += (float)(adchit->adc-adchit->ped); } adcsumN->Fill(sumN); adcsumS->Fill(sumS); adcsumN_vs_adcsumS->Fill(sumS, sumN); for (unsigned int i=0;iT_side==0){ tid_vs_bcal_ssum->Fill(sumS,thit->T_id); tid_vs_bcal_nsum->Fill(sumN,thit->T_id); } } // Time float tN[18], tS[18]; for(int i=0; i<18; i++)tN[i]=tS[i]=-1.0E6; for(unsigned int i=0; iFill(tdc->t, tdc->cid + (tdc->end==0 ? 0:18)); if((tdc->cid>=1) && (tdc->cid<=18)){ if(tdc->end==0) tN[tdc->cid-1] = tdc->t; else tS[tdc->cid-1] = tdc->t; } } for(int i=0; i<18; i++){ if((tN[i]<-1.0E5) || (tS[i]<-1.0E5))continue; id_vs_tdiff->Fill(tN[i]-tS[i] ,i+1); id_vs_tavg->Fill((tN[i]+tS[i])/2.0, i+1); } // Trig time for(unsigned int i=0; iFill(tdc->t, tdc->tid); } // Unlock //histServer->Unlock(); return NOERROR; } //------------------ // erun //------------------ jerror_t MyProcessor::erun(void) { // Delete ROOT hist server if(histServer)delete histServer; histServer = NULL; return NOERROR; } //------------------ // fini //------------------ jerror_t MyProcessor::fini(void) { // This should be in erun, but is getting called by EPICS events // with run number=0! // Close file if(file){ cout<<"Closing \""<GetName()<<"\""<Write(); file->Close(); delete file; } file = NULL; return NOERROR; }