00001 #include "SimDaqTrigMaker.h"
00002 #include "SimDaqEnergyTrigger.h"
00003 #include "MessageService/MsgService.h"
00004 #include <vector>
00005
00006 CVSID("$Id: SimDaqEnergyTrigger.cxx,v 1.5 2007/03/01 17:22:11 rhatcher Exp $");
00007
00008 SimDaqTrigMakerProxy<SimDaqEnergyTrigger> gSimDaqEnergyTriggerProxy("EnergyTrigger");
00009
00010 ClassImp(SimDaqEnergyTrigger)
00011
00012
00013 Bool_t SimDaqEnergyTrigger::ApplyTriggerAt(PlexHandle plex,
00014 SimDigitList& sortedDigitList,
00015 UInt_t startAt,
00016 UInt_t stopAt
00017 )
00018 {
00019
00020
00021
00022
00023
00024
00025 MSG("DetSim",Msg::kDebug) << "Energy Trigger Running: "
00026 << fThreshold << " ADC and "
00027 << fNhits << " hits and "
00028 << fN << " planes hit in a window of "
00029 << fM << " planes.\n";
00030
00031
00032 if(Int_t(stopAt-startAt) < fN) return false;
00033
00034
00035 if(Int_t(stopAt-startAt) < fNhits) return false;
00036
00037
00038 std::vector<Int_t> planeEnergy(600,0);
00039 std::vector<Int_t> planeHits(600,0);
00040
00041 Int_t totADC = 0;
00042 Int_t firstPlane = 9999;
00043 Int_t lastPlane = -9999;
00044
00045 for(UInt_t idig = startAt; idig<stopAt; idig++) {
00046
00047 if(sortedDigitList[idig].GetErrors()) continue;
00048 PlexPixelSpotId psid = sortedDigitList[idig].GetPixelSpotId();
00049 PlexStripEndId seid = plex.GetStripEndId(psid);
00050 if(!seid.IsValid()) {
00051 psid.SetSpot(1);
00052 seid = plex.GetStripEndId(psid);
00053 }
00054 Int_t plane = seid.GetPlane();
00055 Int_t adc = sortedDigitList[idig].GetADC();
00056 totADC+=adc;
00057
00058 if( (UInt_t)plane >= planeEnergy.size()) continue;
00059
00060
00061 if(planeEnergy[plane] ==0){
00062 if(plane<firstPlane) firstPlane = plane;
00063 if(plane>lastPlane) lastPlane = plane;
00064 }
00065
00066 planeEnergy[plane]+= adc;
00067 planeHits[plane]+= 1;
00068 }
00069
00070
00071 if(totADC < fThreshold) return false;
00072
00073
00074
00075 for(Int_t i = firstPlane; i <= lastPlane; i++) {
00076 Int_t local_energy = 0;
00077 Int_t local_nhit = 0;
00078 Int_t local_planeshit = 0;
00079
00080 for (Int_t j=0; (j<fM) && (i+j<=lastPlane); j++) {
00081 local_energy += planeEnergy[i+j];
00082 local_nhit += planeHits[i+j];
00083 if(planeHits[i+j]>0) local_planeshit++;
00084 }
00085 if ((local_energy >= fThreshold) && (local_nhit >=fNhits) && (local_planeshit >= fN)) {
00086 return true;
00087 }
00088
00089 if (i+fM>lastPlane) break;
00090 }
00091
00092 return false;
00093 }