//_____________________________________________________________________________ // Forward Detector analysis module: below are the examples of what one // can do in the interactive session //_____________________________________________________________________________ /* ****** to run: (note naming convention: class_name = "T"+module_name+"Module"), the source code of the class is stored in TStnAna x("results/ar0192ea.0001cmu0.stn_new"); TStnAna x("results/dataval_muon.root"); .L TFwdDetAnaModule.cc+ x.AddModule(new TFwdDetAnaModule); x.Run(); ****** to display a histogram TFwdDetAnaModule::Hist_t* c; TFwdDetAnaModule* m = (TFwdDetAnaModule*) x.GetModule("FwdDetAna"); c = m->GetHist(); c->fAdcCounts[0]->Draw(); ****** to process one event (#11 in the ntuple) and to print the data x.ProcessEvent(11) TFwdDetAnaModule* m = (TFwdDetAnaModule*) x.GetModule("FwdDetAna"); TFwdDetDataBlock* fwddet = m->GetFwdDetDataBlock(); TStnHeaderBlock* hdr = m->GetHeaderBlock (); fwddet->Print(); hdr->Print(); */ #include "TF1.h" #include "TCanvas.h" #include "Stntuple/obj/TStnHeaderBlock.hh" #include "Stntuple/obj/TStnTrackBlock.hh" #include "TFwdDetAnaModule.hh" // ClassImp(TFwdDetAnaModule) //_____________________________________________________________________________ TFwdDetAnaModule::TFwdDetAnaModule(const char* name, const char* title): TStnModule(name,title) { } //_____________________________________________________________________________ TFwdDetAnaModule::~TFwdDetAnaModule() { } //_____________________________________________________________________________ void TFwdDetAnaModule::BookHistograms() { char name [200]; char title[200]; Delete("hist"); // book histograms // BSC part for (int ich=0; ich<18; ich++) { sprintf(name, "%s_adc_bsc%1i_%1i%1c",GetName(), GetBscStation(ich),GetBscCounter(ich),GetBscSide(ich)); sprintf(title,"%s: ADC spectrum BSC%1i-%1i%1c",GetName(), GetBscStation(ich),GetBscCounter(ich),GetBscSide(ich)); fHist.fBscCounts[ich]= new TH1F(name, title,300,0,30000); AddHistogram(fHist.fBscCounts[ich]); } // RPT part for (int ich=0; ich<3; ich++) { sprintf(name, "%s_adc_rpt%1i",GetName(),ich+1); sprintf(title,"%s: ADC spectrum RPT%1i",GetName(),ich+1); fHist.fRptCounts[ich]= new TH1F(name, title,300,0,30000); AddHistogram(fHist.fRptCounts[ich]); } // RPS part for (int ip=0; ip<3; ip++) { for (int it=0; it<2; it++) { for (int ifib=0; ifib<40; ifib++) { sprintf(name, "%s_adc_rps%1i%1c_%2i",GetName(), ip+1,(it==0)?'X':'Y',ifib); sprintf(title,"%s: ADC spectrum RPS%1i%1c-%2i",GetName(), ip+1,(it==0)?'X':'Y',ifib); fHist.fRpsCounts[ip][it][ifib] = new TH1F(name, title,200,0,10000); AddHistogram(fHist.fRpsCounts[ip][it][ifib]); } } } // MP part for (int is=0; is<2; is++) { for (int ich=0; ich<18; ich++) { sprintf(name, "%s_adc_mpsumtow_%2i%1c",GetName(), ich,(is==0)?'W':'E'); sprintf(title,"%s: ADC spectrum MPSumTow-%2i%1c",GetName(), ich,(is==0)?'W':'E'); fHist.fMpSumTowerCounts[is][ich]= new TH1F(name, title,300,0,30000); AddHistogram(fHist.fMpSumTowerCounts[is][ich]); } for (int ich=0; ich<84; ich++) { sprintf(name, "%s_adc_mptow_%2i%1c",GetName(), ich,(is==0)?'W':'E'); sprintf(title,"%s: ADC spectrum MPTow-%2i%1c",GetName(), ich,(is==0)?'W':'E'); fHist.fMpTowerCounts[is][ich]= new TH1F(name, title,300,0,30000); AddHistogram(fHist.fMpTowerCounts[is][ich]); } } } //_____________________________________________________________________________ int TFwdDetAnaModule::BeginJob() { // register the data block fFwdDetDataBlock = (TFwdDetDataBlock*) RegisterDataBlock("FwdDetDataBlock", "TFwdDetDataBlock"); // book histograms BookHistograms(); if (! fFwdDetDataBlock) fEnabled = 0; firstBsc = true; firstRpt = true; firstRps = true; firstMp = true; return 0; } //_____________________________________________________________________________ int TFwdDetAnaModule::BeginRun() { return 0; } //_____________________________________________________________________________ int TFwdDetAnaModule::Event(int ientry) { fFwdDetDataBlock->GetEntry(ientry); // do whatever you want if (PrintLevel()) { if (firstBsc) fFwdDetDataBlock->Print("bsc_banner"); firstBsc = false; fFwdDetDataBlock->Print("bsc"); //if (firstRpt) fFwdDetDataBlock->Print("rpt_banner"); //firstRpt = false; //fFwdDetDataBlock->Print("rpt"); //if (firstRps) fFwdDetDataBlock->Print("rps_banner"); //firstRps = false; //fFwdDetDataBlock->Print("rps"); //if (firstMp) fFwdDetDataBlock->Print("mp_banner"); //firstMp = false; //fFwdDetDataBlock->Print("mp"); } // BSC part for (int ich=0; ich<18; ich++) { fHist.fBscCounts[ich]-> Fill((int)fFwdDetDataBlock->GetBscData(ich)); } // RPT part for (int ich=0; ich<3; ich++) { fHist.fRptCounts[ich]-> Fill((int)fFwdDetDataBlock->GetRptData(ich)); } // RPS part int il; for (int ip=0; ip<3; ip++) { for (int it=0; it<2; it++) { il = it + 2*ip; for (int ifib=0; ifib<40; ifib++) { fHist.fRpsCounts[ip][it][ifib]-> Fill((int)fFwdDetDataBlock->GetRpsData(il, ifib)); } } } // MP part for (int is=0; is<2; is++) { for (int itow=0; itow<18; itow++) { fHist.fMpSumTowerCounts[is][itow]-> Fill((int)fFwdDetDataBlock->GetMpSumTowerData(is, itow)); } for (int itow=0; itow<84; itow++) { fHist.fMpTowerCounts[is][itow]-> Fill(fFwdDetDataBlock->GetMpTowerData(is, itow)); } } return 0; } //_____________________________________________________________________________ void TFwdDetAnaModule::DisplayEvent() { /**** char name[] = "TFwdDetAnaModule_DisplayEvent_canvas"; char title[] = "BSC events"; TCanvas* c = (TCanvas*) gROOT->FindObject(name); if (! c) { c = new TCanvas(name, title,0,0,800,600); c->Divide(2,2); } for (int k=0; k<2; k++) { c->cd(2*k+1); fHist.fStripProfile[k]->Draw(); c->cd(2*k+2); fHist.fWireProfile[k]->Draw(); } c->Modified(); c->Update(); ****/ } //_____________________________________________________________________________ int TFwdDetAnaModule::EndJob() { printf("----- end job: ---- %s\n",GetName()); return 0; } //_____________________________________________________________________________ char TFwdDetAnaModule::GetBscSide(int ch) { if ((ch >= 0) && (ch < 8)) return 'E'; else if ((ch >= 8) && (ch < 18)) return 'W'; return ' '; } //_____________________________________________________________________________ int TFwdDetAnaModule::GetBscStation(int ch) { if ((ch >= 0) && (ch < 4)) return 1; else if ((ch >= 4) && (ch < 6)) return 2; else if ((ch >= 6) && (ch < 8)) return 3; else if ((ch >= 8) && (ch < 12)) return 1; else if ((ch >= 12) && (ch < 14)) return 2; else if ((ch >= 14) && (ch < 16)) return 3; else if ((ch >= 16) && (ch < 18)) return 4; return 0; } //_____________________________________________________________________________ int TFwdDetAnaModule::GetBscCounter(int ch) { if ((ch >= 0) && (ch < 4)) return (ch+1); else if ((ch >= 4) && (ch < 6)) return (ch-3); else if ((ch >= 6) && (ch < 8)) return (ch-5); else if ((ch >= 8) && (ch < 12)) return (ch-7); else if ((ch >= 12) && (ch < 14)) return (ch-11); else if ((ch >= 14) && (ch < 16)) return (ch-13); else if ((ch >= 16) && (ch < 18)) return (ch-15); return 0; }