using namespace std;
#include "hmdctrigger.h"
#include "hmdcdef.h"
#include "hdebug.h"
#include "hades.h"
#include "hiterator.h"
#include "hruntimedb.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hevent.h"
#include "heventheader.h"
#include "hcategory.h"
#include "hlinearcategory.h"
#include "hstartcal.h"
#include <fstream>
#include <iostream>
#include <iomanip>
#include "TH1.h"
#include "TH2.h"
#include "TFile.h"
ClassImp(HMdcTrigger)
HMdcTrigger::HMdcTrigger(void) {
calStartCat=NULL;
iter_start=NULL;
dotimecut = kFALSE;
startbit=kFALSE;
tofbit=kFALSE;
tofinobit=kFALSE;
fillcontrolhists=kFALSE;
binnum0 =1;
binnum1 =1;
binnum2 =1;
binnum3 =1;
binnum4 =1;
binnum5 =1;
binnum6 =1;
binnum7 =1;
binnum8 =1;
binnum9 =1;
binnum10 =1;
binnum11 =1;
binnum12 =1;
binnum13 =1;
binnum14 =1;
binnum15 =1;
bin0 =1;
bin1 =1;
bin2 =1;
bin3 =1;
bin4 =1;
bin5 =1;
bin6 =1;
bin7 =1;
bin8 =1;
bin9 =1;
bin10 =1;
bin11 =1;
bin12 =1;
bin13 =1;
bin14 =1;
bin15 =1;
countnocut=0;
countmultiplicityStartcut=0;
counttimewindowStartcut=0;
countskipedevents=0;
maxbinnum=10000;
maxX=9999;
setDefaultTimeWindow();
setStartMultiplicityCut(1,2);
setVetoMultiplicityCut(0,1);
setTofMultiplicityCut(1,2);
setTofinoMultiplicityCut(1,2);
}
HMdcTrigger::HMdcTrigger(const Text_t* name,const Text_t* title)
: HReconstructor(name,title) {
calStartCat=NULL;
iter_start=NULL;
dotimecut = kFALSE;
startbit=kFALSE;
tofbit=kFALSE;
tofinobit=kFALSE;
fillcontrolhists=kFALSE;
binnum0 =1;
binnum1 =1;
binnum2 =1;
binnum3 =1;
binnum4 =1;
binnum5 =1;
binnum6 =1;
binnum7 =1;
binnum8 =1;
binnum9 =1;
binnum10 =1;
binnum11 =1;
binnum12 =1;
binnum13 =1;
binnum14 =1;
binnum15 =1;
bin0 =1;
bin1 =1;
bin2 =1;
bin3 =1;
bin4 =1;
bin5 =1;
bin6 =1;
bin7 =1;
bin8 =1;
bin9 =1;
bin10 =1;
bin11 =1;
bin12 =1;
bin13 =1;
bin14 =1;
bin15 =1;
countnocut=0;
countmultiplicityStartcut=0;
counttimewindowStartcut=0;
countskipedevents=0;
maxbinnum=10000;
maxX=9999;
setDefaultTimeWindow();
setStartMultiplicityCut(0,10);
setVetoMultiplicityCut(0,10);
setTofMultiplicityCut(0,10);
setTofinoMultiplicityCut(0,10);
}
HMdcTrigger::~HMdcTrigger(void) {
if (iter_start) delete iter_start;
iter_start=0;
if(file && fillcontrolhists) writeHist(file);
if (fNameRootTrigger) delete fNameRootTrigger;
}
void HMdcTrigger::setDefaultTimeWindow()
{
setTimeWindowStart(-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.);
setTimeWindowVeto (-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.,-1000.,1000.);
}
void HMdcTrigger::setOutputRoot(const Char_t *c)
{
if (fNameRootTrigger) delete fNameRootTrigger;
fNameRootTrigger = new Char_t[strlen(c)+1];
strcpy(fNameRootTrigger, c);
}
Bool_t HMdcTrigger::init(void) {
cout<<"init hmdctrigger"<<endl;
calStartCat=gHades->getCurrentEvent()->getCategory(catStartCal);
if (!calStartCat) {
calStartCat=gHades->getSetup()->getDetector("Start")->buildCategory(catStartCal);
if (!calStartCat) return kFALSE;
else gHades->getCurrentEvent()->addCategory(catStartCal,calStartCat,"Start");
}
iter_start=(HIterator *)calStartCat->MakeIterator("native");
if (fNameRootTrigger && fillcontrolhists)
{file = new TFile(fNameRootTrigger,"RECREATE");}
if (file && fillcontrolhists) createHist(file);
cout<<"****************************************************************************"<<endl;
cout<<"************************HMdcTrigger*****************************************"<<endl;
if(file)cout<<"*"<<" Outputfile: "<<fNameRootTrigger<<endl;
if(!file)cout<<"*"<<" no Outputfile set"<<endl;
if(tofbit)cout<<"*"<<" Tof trigger selected"<<endl;
if(startbit)cout<<"*"<<" Start trigger selected"<<endl;
if(tofinobit)cout<<"*"<<" Tofino trigger selected"<<endl;
if((!startbit)&&(!tofbit)&&(!tofinobit))cout<<"*"<<" no trigger selected"<<endl;
cout<<"* Start multiplicity cut between "<<startmultmin<<" and "<<startmultmax<<endl;
cout<<"* Veto multiplicity cut between "<<vetomultmin<<" and "<<vetomultmax<<endl;
cout<<"* Tof multiplicity cut between "<<tofmultmin<<" and "<<tofmultmax<<endl;
cout<<"* Tofino multiplicity cut between "<<tofinomultmin<<" and "<<tofinomultmax<<endl;
if(dotimecut)
{
cout<<"*"<<" strip0 window from "<<minstrip0<<" to "<<maxstrip0<<endl;
cout<<"*"<<" strip1 window from "<<minstrip1<<" to "<<maxstrip1<<endl;
cout<<"*"<<" strip2 window from "<<minstrip2<<" to "<<maxstrip2<<endl;
cout<<"*"<<" strip3 window from "<<minstrip3<<" to "<<maxstrip3<<endl;
cout<<"*"<<" strip4 window from "<<minstrip4<<" to "<<maxstrip4<<endl;
cout<<"*"<<" strip5 window from "<<minstrip5<<" to "<<maxstrip5<<endl;
cout<<"*"<<" strip6 window from "<<minstrip6<<" to "<<maxstrip6<<endl;
cout<<"*"<<" strip7 window from "<<minstrip7<<" to "<<maxstrip7<<endl;
}
if(!dotimecut)cout<<"* No time window set for strips"<<endl;
cout<<"****************************************************************************"<<endl;
cout<<"****************************************************************************"<<endl;
fActive=kTRUE;
return kTRUE;
}
void HMdcTrigger::writeHist(TFile* file)
{
file->cd();
hstartcutstat->Write();
hstart_time_s0to7->Write();
hstart_time_s0to7_clean->Write();
hstart_time_s8to15->Write();
hstart_time_s8to15_clean->Write();
hstartvetodistribution->Write();
hstartvetodistribution_clean->Write();
for(Int_t i=0;i<8;i++){
hstart_time[i]->Write();
hstart_time_clean[i]->Write();;
hveto_time[i]->Write();
hveto_time_clean[i]->Write();;
}
file->Save();
file->Close();
delete file;
}
void HMdcTrigger::createHist(TFile* file)
{
file->cd();
cout<<"creating histograms"<<endl;
hstartcutstat=new TH1F("hstartcutstat","statistics of cuts on start" ,20,0,20);
hstart_time_s0to7=new TH1F("hstart_time_s01234567","start time spectrum" ,400,-20,20);
hstart_time_s0to7_clean=new TH1F("hstart_time_s01234567_clean","start time spectrum clean" ,400,-20,20);
hstart_time_s8to15=new TH1F("hstart_time_s8to15","veto time spectrum" ,400,-20,20);
hstart_time_s8to15_clean=new TH1F("hstart_time_s8to15_clean","veto time spectrum clean" ,400,-20,20);
hstartvetodistribution = new TH2F("start_veto_distribution","start veto distribution",100,0,10,100,0,10);
hstartvetodistribution->SetXTitle("start multiplicity");
hstartvetodistribution->SetYTitle("veto multiplicity");
hstartvetodistribution_clean= new TH2F("start_veto_distribution_clean","start veto distribution clean",100,0,10,100,0,10);
hstartvetodistribution_clean->SetXTitle("start multiplicity");
hstartvetodistribution_clean->SetYTitle("veto multiplicity");
for(Int_t i=0;i<8;i++){
Char_t title[60], tmp[60];
sprintf(title,"%s%i","start time strip",i);
sprintf(tmp, "%s%i", "hstart_time_s",i);
hstart_time[i] = new TH1F(tmp, title,400 ,-20,20);
sprintf(title,"%s%i%s","start time strip",i," clean");
sprintf(tmp, "%s%i%s", "hstart_time_s",i,"_clean");
hstart_time_clean[i] = new TH1F(tmp, title,400 ,-20,20);
sprintf(title,"%s%i","start time history strip",i);
sprintf(tmp, "%s%i", "hstart_time_history_s",i);
sprintf(title,"%s%i%s","start time history strip",i," clean");
sprintf(tmp, "%s%i%s", "hstart_time_history_s",i,"_clean");
}
for(Int_t i=0;i<8;i++){
Char_t title[60], tmp[60];
sprintf(title,"%s%i","veto time strip",i);
sprintf(tmp, "%s%i", "hveto_time_s",i);
hveto_time[i] = new TH1F(tmp, title,400 ,-20,20);
sprintf(title,"%s%i%s","veto time strip",i," clean");
sprintf(tmp, "%s%i%s", "hveto_time_s",i,"_clean");
hveto_time_clean[i] = new TH1F(tmp, title,400 ,-20,20);
sprintf(title,"%s%i","veto time history strip",i);
sprintf(tmp, "%s%i", "hveto_time_history_s",i);
sprintf(title,"%s%i%s","veto time history strip",i," clean");
sprintf(tmp, "%s%i%s", "hveto_time_history_s",i,"_clean");
}
}
Int_t HMdcTrigger::execute(void) {
countnocut++;
if(fillcontrolhists)hstartcutstat->SetBinContent(1,countnocut);
HStartCal *startcal=NULL;
Int_t startmod;
Int_t sstrip;
Float_t stime;
Int_t strip0=0;
Int_t strip1=0;
Int_t strip2=0;
Int_t strip3=0;
Int_t strip4=0;
Int_t strip5=0;
Int_t strip6=0;
Int_t strip7=0;
Int_t strip8=0;
Int_t strip9=0;
Int_t strip10=0;
Int_t strip11=0;
Int_t strip12=0;
Int_t strip13=0;
Int_t strip14=0;
Int_t strip15=0;
Int_t count_start=0;
Int_t count_start_check=0;
Int_t mul_start=0;
Int_t mul_veto=0;
iter_start ->Reset();
while ((startcal=(HStartCal*)iter_start->Next())!= 0) {
if(startcal->getStrip()<8 && (startcal->getModule()==0)) mul_start++;
if(startcal->getStrip()<8 && (startcal->getModule()==1)) mul_veto++;
count_start++;
}
if(fillcontrolhists) hstartvetodistribution->Fill(mul_start,mul_veto);
iter_start ->Reset();
tofbit=kTRUE;
if(
((startbit)&&((mul_start>=startmultmin&&mul_start<startmultmax)
&&(mul_veto>=vetomultmin&&mul_veto<vetomultmax)))||
((tofbit)&&((mul_start>=startmultmin&&mul_start<startmultmax)
&&(mul_veto>=vetomultmin&&mul_veto<vetomultmax)))||
(((!tofbit)&&(!startbit)&&(!tofinobit))
&&((mul_start>=startmultmin&&mul_start<startmultmax)
&&(mul_veto>=vetomultmin&&mul_veto<vetomultmax)))
)
{
countmultiplicityStartcut++;
if(fillcontrolhists){
hstartvetodistribution_clean->Fill(mul_start,mul_veto);
hstartcutstat->SetBinContent(2,countmultiplicityStartcut);
}
iter_start ->Reset();
while ((startcal=(HStartCal*) iter_start->Next())!= 0) {
count_start_check++;
startmod=startcal->getModule();
if(startmod==0){
sstrip =startcal->getStrip();
}else
{
sstrip =startcal->getStrip()+8;
}
stime =startcal->getTime();
strip0=0;
strip1=0;
strip2=0;
strip3=0;
strip4=0;
strip5=0;
strip6=0;
strip7=0;
strip8=0;
strip9=0;
strip10=0;
strip11=0;
strip12=0;
strip13=0;
strip14=0;
strip15=0;
if(file) file->cd();
if(dotimecut){
if(sstrip==0) {
strip0=1;
if(file){
if(fillcontrolhists){
hstart_time[0]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin0++;}}}
if(sstrip==1) {
strip1=1;
if(file){
if(fillcontrolhists){
hstart_time[1]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin1++;}}}
if(sstrip==2) {
strip2=1;
if(file){
if(fillcontrolhists){
hstart_time[2]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin2++;}}}
if(sstrip==3) {
strip3=1;
if(file){
if(fillcontrolhists){
hstart_time[3]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin3++;}}}
if(sstrip==4) {
strip4=1;
if(file){
if(fillcontrolhists){
hstart_time[4]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin4++;}}}
if(sstrip==5) {
strip5=1;
if(file){
if(fillcontrolhists){
hstart_time[5]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin5++;}}}
if(sstrip==6) {
strip6=1;
if(file){
if(fillcontrolhists){
hstart_time[6]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin6++;}}}
if(sstrip==7) {
strip7=1;
if(file){
if(fillcontrolhists){
hstart_time[7]->Fill(stime);
hstart_time_s0to7->Fill(stime);
bin7++;}}}
if(sstrip==8) {
strip8=1;
if(file){
if(fillcontrolhists){
hveto_time[0]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin8++;}}}
if(sstrip==9) {
strip9=1;
if(file){
if(fillcontrolhists){
hveto_time[1]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin9++;}}}
if(sstrip==10) {
strip10=1;
if(file){
if(fillcontrolhists){
hveto_time[2]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin10++;}}}
if(sstrip==11) {
strip11=1;
if(file){
if(fillcontrolhists){
hveto_time[3]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin11++;}}}
if(sstrip==12) {
strip12=1;
if(file){
if(fillcontrolhists){
hveto_time[4]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin12++;}}}
if(sstrip==13) {
strip13=1;
if(file){
if(fillcontrolhists){
hveto_time[5]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin13++;}}}
if(sstrip==14) {
strip14=1;
if(file){
if(fillcontrolhists){
hveto_time[6]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin14++;}}}
if(sstrip==15) {
strip15=1;
if(file){
if(fillcontrolhists){
hveto_time[7]->Fill(stime);
hstart_time_s8to15->Fill(stime);
bin15++;}}}
}
if(dotimecut){
if(sstrip==0&&((stime>minstrip0)&&(stime<maxstrip0))) {
strip0=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[0]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum0++;}}}
if(sstrip==1&&((stime>minstrip1)&&(stime<maxstrip1))) {
strip1=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[1]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum1++;}}}
if(sstrip==2&&((stime>minstrip2)&&(stime<maxstrip2))) {
strip2=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[2]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum2++;}}}
if(sstrip==3&&((stime>minstrip3)&&(stime<maxstrip3))) {
strip3=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[3]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum3++;}}}
if(sstrip==4&&((stime>minstrip4)&&(stime<maxstrip4))) {
strip4=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[4]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum4++;}}}
if(sstrip==5&&((stime>minstrip5)&&(stime<maxstrip5))) {
strip5=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[5]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum5++;}}}
if(sstrip==6&&((stime>minstrip6)&&(stime<maxstrip6))) {
strip6=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[6]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum6++;}}}
if(sstrip==7&&((stime>minstrip7)&&(stime<maxstrip7))) {
strip7=1;
if(file){
if(fillcontrolhists){
hstart_time_clean[7]->Fill(stime);
hstart_time_s0to7_clean->Fill(stime);
binnum7++;}}}
if(sstrip==8&&((stime>minstrip8)&&(stime<maxstrip8))) {
strip8=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[0]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum8++;}}}
if(sstrip==9&&((stime>minstrip9)&&(stime<maxstrip9))) {
strip9=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[1]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum9++;}}}
if(sstrip==10&&((stime>minstrip10)&&(stime<maxstrip10))) {
strip10=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[2]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum10++;}}}
if(sstrip==11&&((stime>minstrip11)&&(stime<maxstrip11))) {
strip11=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[3]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum11++;}}}
if(sstrip==12&&((stime>minstrip12)&&(stime<maxstrip12))) {
strip12=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[4]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum12++;}}}
if(sstrip==13&&((stime>minstrip13)&&(stime<maxstrip13))) {
strip13=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[5]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum13++;}}}
if(sstrip==14&&((stime>minstrip14)&&(stime<maxstrip14))) {
strip14=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[6]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum14++;}}}
if(sstrip==15&&((stime>minstrip15)&&(stime<maxstrip15))) {
strip15=1;
if(file){
if(fillcontrolhists){
hveto_time_clean[7]->Fill(stime);
hstart_time_s8to15_clean->Fill(stime);
binnum15++;}}}
}
}
}
if ((strip0||strip1)||(strip2||strip3)||(strip4||strip5)||(strip6||strip7)) {
counttimewindowStartcut++;
if(fillcontrolhists)hstartcutstat->SetBinContent(3,counttimewindowStartcut);
return 0;
}
else {
countskipedevents++;
if(fillcontrolhists)hstartcutstat->SetBinContent(4,countskipedevents);
return kSkipEvent;}
}
Last change: Sat May 22 13:04:14 2010
Last generated: 2010-05-22 13:04
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.