-// this is example for
-
+#include "base/ProcMgr.h"
+#include "hadaq/HldProcessor.h"
+#include "hadaq/TdcProcessor.h"
+#include "hadaq/TrbProcessor.h"
void first()
{
- //base::ProcMgr::instance()->SetRawAnalysis(true);
+ // base::ProcMgr::instance()->SetRawAnalysis(true);
base::ProcMgr::instance()->SetTriggeredAnalysis(true);
// all new instances get this value
base::ProcMgr::instance()->SetHistFilling(4);
- // configure bubbles
- //hadaq::TdcProcessor::SetBubbleMode(3, 18);
-
- // this limits used for linear calibrations when nothing else is available
- hadaq::TdcMessage::SetFineLimits(81, 464);
+ // this limits used for liner calibrations when nothing else is available
+ hadaq::TdcMessage::SetFineLimits(28, 350);
// default channel numbers and edges mask
+ // 1 - use only rising edge, falling edge is ignore
+ // 2 - falling edge enabled and fully independent from rising edge
+ // 3 - falling edge enabled and uses calibration from rising edge
+ // 4 - falling edge enabled and common statistic is used for calibration
hadaq::TrbProcessor::SetDefaults(33, 2);
// [min..max] range for TDC ids
- hadaq::TrbProcessor::SetTDCRange(0x1200, 0x15FF);
+ hadaq::TrbProcessor::SetTDCRange(0x1600, 0x16FF);
// [min..max] range for HUB ids
- hadaq::TrbProcessor::SetHUBRange(0x8000, 0x8fff);
+ hadaq::TrbProcessor::SetHUBRange(0x8800, 0x88FF);
// when first argument true - TRB/TDC will be created on-the-fly
// second parameter is function name, called after elements are created
hadaq::HldProcessor* hld = new hadaq::HldProcessor(true, "after_create");
- const char* calname = getenv("CALNAME");
- if ((calname==0) || (*calname==0)) calname = "test_";
- const char* calmode = getenv("CALMODE");
- int cnt = (calmode && *calmode) ? atoi(calmode) : 100000;
- //cnt=100000;
- const char* caltrig = getenv("CALTRIG");
- unsigned trig = (caltrig && *caltrig) ? atoi(caltrig) : 0x1;
- const char* uset = getenv("USETEMP");
- unsigned use_temp = 0; // 0x80000000;
- if ((uset!=0) && (*uset!=0) && (strcmp(uset,"1")==0)) use_temp = 0x80000000;
-
- printf("TDC CALIBRATION MODE %d\n", cnt);
-
- //printf("HLD configure calibration calfile:%s cnt:%d trig:%X temp:%X\n", calname, cnt, trig, use_temp);
-
// first parameter if filename prefix for calibration files
// and calibration mode (empty string - no file I/O)
// second parameter is hits count for autocalibration
// 0 - only load calibration
// -1 - accumulate data and store calibrations only at the end
+ // -77 - accumulate data and store linear calibrations only at the end
// >0 - automatic calibration after N hits in each active channel
+ // if value ends with 77 like 10077 linear calibration will be calculated
+ // >1000000000 - automatic calibration after N hits only once, 1e9 excluding
// third parameter is trigger type mask used for calibration
// (1 << 0xD) - special 0XD trigger with internal pulser, used also for TOT calibration
// 0x3FFF - all kinds of trigger types will be used for calibration (excluding 0xE and 0xF)
// 0x80000000 in mask enables usage of temperature correction
- hld->ConfigureCalibration(calname, cnt, (1 << trig) | use_temp);
- //hld->ConfigureCalibration(calname, 100000, 1);
+ hld->ConfigureCalibration("test", 1e6 , (1 << 0xD));
// only accept trigger type 0x1 when storing file
// new hadaq::HldFilter(0x1);
// create ROOT file store
- //base::ProcMgr::instance()->CreateStore("td.root");
+ // base::ProcMgr::instance()->CreateStore("td.root");
// 0 - disable store
// 1 - std::vector<hadaq::TdcMessageExt> - includes original TDC message
// 2 - std::vector<hadaq::MessageFloat> - compact form, without channel 0, stamp as float (relative to ch0)
// 3 - std::vector<hadaq::MessageDouble> - compact form, with channel 0, absolute time stamp as double
- base::ProcMgr::instance()->SetStoreKind(0);
+ base::ProcMgr::instance()->SetStoreKind(2);
// when configured as output in DABC, one specifies:
// <OutputPort name="Output2" url="stream://file.root?maxsize=5000&kind=3"/>
+ hadaq::TdcProcessor::SetUseDTrigForRef(true);
+ // hadaq::TdcProcessor::(true);
+
}
// extern "C" required by DABC to find function from compiled code
hadaq::TrbProcessor* trb = hld->GetTRB(k);
if (trb==0) continue;
printf("Configure %s!\n", trb->GetName());
- trb->SetPrintErrors(100);
+ trb->SetPrintErrors(10);
}
for (unsigned k=0;k<hld->NumberOfTDC();k++) {
hadaq::TdcProcessor* tdc = hld->GetTDC(k);
+
if (tdc==0) continue;
printf("Configure %s!\n", tdc->GetName());
- tdc->SetUseLastHit(false);
+ //tdc->SetToTRange(12.8, 5., 60.);
- //tdc->SetStoreEnabled();
- for (unsigned nch=1; nch<tdc->NumChannels(); nch++) {
- tdc->SetRefChannel(nch, nch-1, 0xffff, 10000, -90., 90.);
- }
+ //tdc->SetUseLastHit(true);
+ for (unsigned nch=2;nch<tdc->NumChannels();nch++)
+ tdc->SetRefChannel(nch, 1, 0xffff, 20000, -50., 50.);
+ //tdc->SetRefChannel(nch, 1, 0xffff, 20000, -50., 50.);
- // for (unsigned j=10; j<33; j++) {
- // tdc->SetRefChannel(j, 1, 0xffff, 10000, -40., 40.);
- //}
+ //tdc->SetRefChannel(14, 12, 0xffff, 10000, -10., 10.);
+ // tdc->SetRefChannel(5, 1, 0xffff, 10000, -100., 100.);
+ //tdc->SetRefChannel(1, 2, 0xffff, 30000, -40., 40.);
- tdc->SetRefChannel(6, 0, 0xffff, 10000, -100.,100.);
- //tdc->SetRefChannel(0, 0, 0x1202, 10000, -20., 20.);
- //tdc->SetRefChannel(4, 2, 0xffff, 10000, -20., 20.);
- //tdc->SetRefChannel(1, tdc->NumChannels() -1 , 0xffff, 20000, -10., 10.);
+ // select histogram 6: Window: -1e12 to 0, print max 100 events
+ //tdc->EnableRefCondPrint(1, 0, 1e12, 100);
+ //tdc->EnableRefCondPrint(1, -1e12, 0, 100);
- // tdc->SetRefChannel(6, 2 , 0xffff, 20000, -10., 10.);
- //tdc->SetRefChannel(4, 2 , 0xffff, 20000, -10., 10.);
- //tdc->SetRefChannel(7, 6 , 0xffff, 20000, -10., 10.);
-
-
}
}
-#include <stdio.h>
+#include <cstdio>
-// #include "TTree.h"
+#include "TTree.h"
+#include "TH1.h"
#include "base/EventProc.h"
#include "base/Event.h"
#include "hadaq/TdcSubEvent.h"
+#include "hadaq/TdcProcessor.h"
-class SecondProc : public base::EventProc {
+const int NumChannels = 33;
+
+class DebugProc : public base::EventProc {
protected:
- std::string fTdcId; //!< tdc id where channels will be selected
+ std::string fTdcId; //!< tdc id where channels will be selected "TDC_8a00"
- double fHits[33][2]; //!< 33 channel, abstract hits, two dges
+ double fHits[NumChannels]; //!< 16 channel, last hit in every channel
base::H1handle hNumHits; //!< histogram with hits number
- base::H1handle hDif1; //!< histogram with hits number
- base::H1handle hDif2; //!< histogram with hits number
- base::H2handle hUser; //!< user-defined 2D histogram
+
+ base::H1handle hRefHist; //!< histogram with hits number
public:
- SecondProc(const char* procname, const char* _tdcid) :
+ DebugProc(const char* procname, const char* _tdcid) :
base::EventProc(procname),
- fTdcId(_tdcid),
- hUser(0)
+ fTdcId(_tdcid)
{
printf("Create %s for %s\n", GetName(), fTdcId.c_str());
- hNumHits = MakeH1("NumHits","Num hits", 100, 0, 100, "number");
-
- /*
- hDif1 = MakeH1("ToT1","ToT of channel 17 (18)", 1000, 0.5, 3.0, "ns");
- hDif2 = MakeH1("LED_diff1","LED diff channel 17 - 21", 1000, -2., -1., "ns");
- hUser = MakeH2("ToT_vs_LED","ToT versus LED difference", 500, -4, 0, 500, -2, -1, "ToT/ns;LED diff/ns");
- */
-
- hDif1 = MakeH1("LE1","1 vs. 2", 30000, -90, 90, "ns");
- hDif2 = MakeH1("TE2","1 vs. 2", 30000, -90, 90, "ns");
-
-
- /*
- hDif1 = MakeH1("ToT1","ToT of channel 9", 1000, 32, 40, "ns");
- hDif2 = MakeH1("LED_diff1","LED diff channel 9 - 11", 1000, -3, -1, "ns");
- hUser = MakeH2("ToT_vs_LED","ToT versus LED difference", 500, 32, 40, 500, -4, -0, "ToT/ns;LED diff/ns");
- */
-
+ hNumHits = MakeH1("NumHits","Number of hits", 100, 0, 100, "number");
+
+ hRefHist = MakeH1("RefHist", "Difference between channels", 1000, -5, 5, "ns");
+
// enable storing already in constructor
- // SetStoreEnabled();
+ SetStoreEnabled();
}
+
virtual void CreateBranch(TTree* t)
{
- // only called when tree is created in first.C
- // one can ignore
- // t->Branch(GetName(), fHits, "hits[8]/D");
+ t->Branch(GetName(), fHits, "hits[16]/D");
}
- unsigned eventnumber = 0;
virtual bool Process(base::Event* ev)
{
- for (unsigned n=0;n<33;n++) {
- fHits[n][0] = 0.;
- fHits[n][1] = 0.;
- }
-
- eventnumber++;
+ for (unsigned n=0;n<NumChannels;n++) fHits[n] = 0.;
+
hadaq::TdcSubEventFloat* sub =
dynamic_cast<hadaq::TdcSubEventFloat*> (ev->GetSubEvent(fTdcId));
- //printf("%s process sub %p %s\n", GetName(), sub, fTdcId.c_str());
+ if (!sub) {
+ printf("Not found subevent %s\n", fTdcId.c_str());
+ return false;
+ }
- // when return false, event processing is cancelled
- if (sub==0) return true;
+ // printf("%s process sub %p %s\n", GetName(), sub, fTdcId.c_str());
- double num(0);
+ double num = 0;
for (unsigned cnt=0;cnt<sub->Size();cnt++) {
const hadaq::MessageFloat& msg = sub->msg(cnt);
+ float tm = msg.getStamp();
unsigned chid = msg.getCh();
- unsigned edge = msg.getEdge(); // 0 - rising, 1 - falling
- // if (chid==0) { ch0tm = ext.GetGlobalTime(); continue; }
+ bool isrising = msg.isRising();
- // time relative ch0
- double tm = msg.stamp;
-
- if (chid<33) fHits[chid][edge] = tm;
+ if ((chid < NumChannels) && isrising)
+ fHits[chid] = tm;
- //printf(" ch:%3d tm:%f, edge:%d\n", chid, tm, edge);
- num+=1;
+ num++;
}
-
- //printf("tot(%d): %f %f\n", eventnumber, (fHits[9][0] - fHits[9][1]), (fHits[11][0] - fHits[11][1]));
- //printf("led(%d): %f %f\n", eventnumber, (fHits[9][0] - fHits[11][0]), (fHits[9][1] - fHits[11][1]));
FillH1(hNumHits, num);
- /*
- FillH1(hDif1, (fHits[9][1] - fHits[9][0]) );
- FillH1(hDif2, (fHits[9][0] - fHits[11][0]) );
- FillH2(hUser, (fHits[9][1] - fHits[9][0]) , (fHits[9][0] - fHits[11][0]) );
- */
+ if (fHits[14] && fHits[12])
+ FillH1(hRefHist, fHits[14] - fHits[12]);
-
- FillH1(hDif1, (fHits[1][0] - fHits[2][0]) );
- FillH1(hDif2, (fHits[1][1] - fHits[2][1]) );
+ return true;
+ }
+};
+
+
+class PrintProc : public base::EventProc {
+ protected:
+
+ std::string fTdcId; //!< tdc id where channels will be selected "TDC_8a00"
+
+ int fCounter;
+
+ public:
+ PrintProc(const char* procname, const char* _tdcid) :
+ base::EventProc(procname),
+ fTdcId(_tdcid)
+ {
+ printf("Create %s for %s\n", GetName(), fTdcId.c_str());
+
+ fCounter = 0;
+
+ // enable storing already in constructor
+ SetStoreEnabled();
+ }
+
+
+ virtual bool Process(base::Event* ev)
+ {
+ fCounter++;
+ if (fCounter % 100000 == 0) {
+ int kRisingRefId = 2, kTotId = 5;
+
+ hadaq::TdcProcessor *tdc = dynamic_cast<hadaq::TdcProcessor *>(mgr()->FindProc(fTdcId.c_str()));
+
+ int i;
+ for (i=1; i<33; i++) {
+ TH1 *hist = tdc ? (TH1 *) tdc->GetHist(i, kRisingRefId) : 0; // rising ref for channel 1
+ if (hist) printf("%s channel %2d ref mean:% 4.2f ns rms:% 5.1f ps ", fTdcId.c_str(), i, hist->GetMean(), hist->GetRMS()*1000);
+ hist = tdc ? (TH1 *) tdc->GetHist(i, kTotId) : 0; // Tot for channel 1
+ if (hist) printf("ToT mean:% 4.2f rms:% 4.2f ps\n", hist->GetMean(), hist->GetRMS()*1000);
+
+ }
+
+ #if 0
+ hist = tdc ? (TH1 *) tdc->GetHist(1, kTotId) : 0; // Tot for channel 1
+ if (hist) printf("%s channel 1 ToT mean %f rms %f\n", fTdcId.c_str(), hist->GetMean(), hist->GetRMS());
+ hist = tdc ? (TH1 *) tdc->GetHist(5, kRisingRefId) : 0; // rising ref for channel 5
+ if (hist) printf("%s channel 5 ref mean %3.4f rms %3.5f\n", fTdcId.c_str(), hist->GetMean(), hist->GetRMS());
+ hist = tdc ? (TH1 *) tdc->GetHist(5, kTotId) : 0; // Tot for channel 5
+ if (hist) printf("%s channel 5 ToT mean %f rms %f\n", fTdcId.c_str(), hist->GetMean(), hist->GetRMS());
+ #endif
+ //hist = tdc ? (TH1 *) tdc->GetHist(14, kRisingRefId) : 0; // rising ref for channel 14
+ //if (hist) printf("TDC %s channel 14 mean %f rms %f\n", fTdcId.c_str(), hist->GetMean(), hist->GetRMS());
+ }
return true;
}
void second()
{
- //new SecondProc("A", "TDC_1133");
- //new SecondProc("A", "TDC_1580");
- new SecondProc("A", "TDC_1209");
+ // uncomment line to create tree for the events storage
+ // base::ProcMgr::instance()->CreateStore("file.root");
+
+ // new DebugProc("Debug1", "TDC_16F7");
+
+ new PrintProc("Print", "TDC_16EB");
}