11 #include <boost/bind.hpp>
19 UInt_t bank_index = 0;
20 Double_t raw_time_arb_unit = 0.0;
21 Double_t ref_time_arb_unit = 0.0;
22 Double_t time_arb_unit = 0.0;
25 Bool_t local_debug =
false;
28 TString reference_name1 =
"MasterTrigger";
29 TString reference_name2 =
"CopyMasterTrigger";
31 std::vector<QwHit>::iterator end=
fTDCHits.end();
32 for ( std::vector<QwHit>::iterator hit=
fTDCHits.begin(); hit!=end; hit++ )
35 bank_index = hit -> GetSubbankID();
36 slot_num = hit -> GetModule();
37 raw_time_arb_unit = (Double_t) hit -> GetRawTime();
62 ref_time_arb_unit =
fF1RefContainer -> GetReferenceTimeAU(bank_index, reference_name1);
66 if(ref_time_arb_unit==0.0) {
74 hit -> SetTime(time_arb_unit);
75 hit -> SetRawRefTime((UInt_t) ref_time_arb_unit);
79 <<
" BankIndex " << std::setw(2) << bank_index
80 <<
" Slot " << std::setw(2) << slot_num
81 <<
" RawTime : " << std::setw(6) << raw_time_arb_unit
82 <<
" RefTime : " << std::setw(6) << ref_time_arb_unit
83 <<
" time : " << std::setw(6) << time_arb_unit
215 Double_t dt_= drifttime;
218 Double_t resolution=1.0;
220 if(dt_>=0 && dt_<130){
221 Int_t index = (Int_t) (dt_/resolution);
293 Bool_t local_debug =
false;
298 if (tdcindex not_eq -1) {
306 Int_t plane =
fTDCPtrs.at(tdcindex).at(chan).fPlane;
307 Int_t wire =
fTDCPtrs.at(tdcindex).at(chan).fElement;
309 Int_t octant =
fTDCPtrs.at(tdcindex).at(chan).fOctant;
313 if (plane == -1 or wire == -1){
348 std::cout <<
"At QwDriftChamberHDC::FillRawTDCWord " <<
"\n";
349 std::cout <<
" hitcnt " << hitcnt
350 <<
" plane " << plane
352 <<
" package " <<
package
353 << " fTDCHits.size() " << fTDCHits.size()
405 bool temp_local_debug =
false;
407 if (temp_local_debug){
408 std::cout <<
" QwDriftChamberHDC::AddChannelDefinition"<<std::endl;
417 if(temp_local_debug){
418 std::cout <<
"wire #" << i
427 for (
size_t j=0; j<
fTDC_Index.at(i).size(); j++){
429 if (mytdc not_eq -1){
430 for (
size_t k=0; k<
fTDCPtrs.at(mytdc).size(); k++){
432 Int_t plane =
fTDCPtrs.at(mytdc).at(k).fPlane;
434 Int_t wire =
fTDCPtrs.at(mytdc).at(k).fElement;
435 fWireData.at(plane).at(wire).SetElectronics(i,j,k);
436 if(temp_local_debug) {
437 std::cout <<
"mytdc " << mytdc
439 <<
" plane " << plane
440 <<
" (i j k) (" << i <<
" " << j <<
" "<< k <<
")"
468 Bool_t local_debug =
false;
472 TString varname, varvalue;
490 while (mapstr.ReadNextLine()) {
491 mapstr.TrimComment(
'!');
492 mapstr.TrimWhitespace();
493 if (mapstr.LineIsEmpty())
continue;
495 if (mapstr.HasVariablePair(
"=",varname,varvalue)) {
500 value = atol(varvalue.Data());
502 if (varname==
"roc") {
506 else if (varname==
"bank") {
510 else if (varname==
"pkg") {
515 else if (varname==
"slot") {
521 else if (DIRMODE==0) {
523 chan = mapstr.GetTypedNextToken<Int_t>();
524 plane = mapstr.GetTypedNextToken<Int_t>();
526 name = mapstr.GetTypedNextToken<TString>();
534 printf(
"chan %8d plan %4d wire %12s\n", chan, plane, name.Data());
539 if (name==
"MasterTrigger" ) {
551 else if (DIRMODE==1) {
553 plane = mapstr.GetTypedNextToken<Int_t>();
612 options.
AddOptions(
"Tracking options") (
"R2-octant",
613 po::value<int>()->default_value(1),
614 "MD Package 2 of R2 is in front of" );
625 if ( folder ) folder->cd();
630 const Short_t buffer_size = 2000;
631 Float_t bin_offset = -0.5;
633 std::size_t total_plane_number = 0;
636 TotHits.resize(total_plane_number);
637 TOFP.resize(total_plane_number);
638 TOFP_raw.resize(total_plane_number);
639 WiresHit.resize(total_plane_number);
640 TOFW.resize(total_plane_number);
641 TOFW_raw.resize(total_plane_number);
642 HitsWire.resize(total_plane_number);
644 std::size_t iplane = 0;
662 for ( iplane=1; iplane<total_plane_number; iplane++) {
666 Form(
"%s%sHitsOnEachWirePlane%d", prefix.Data(), region.Data(), (Int_t) iplane),
667 Form(
"Total hits on all wires in plane %d", (Int_t) iplane),
671 TotHits[iplane]->GetXaxis()->SetTitle(
"Wire #");
672 TotHits[iplane]->GetYaxis()->SetTitle(
"Events");
675 Form(
"%s%sWiresHitPlane%d", prefix.Data(), region.Data(), (Int_t) iplane),
676 Form(
"Number of Wires Hit in plane %d",(Int_t) iplane),
677 20, bin_offset, 20+bin_offset
679 WiresHit[iplane]->GetXaxis()->SetTitle(
"Wires Hit per Event");
680 WiresHit[iplane]->GetYaxis()->SetTitle(
"Events");
683 Form(
"%s%sHitsOnEachWirePerEventPlane%d", prefix.Data(), region.Data(), (Int_t) iplane),
684 Form(
"hits on all wires per event in plane %d", (Int_t) iplane),
686 7, -bin_offset, 7-bin_offset
688 HitsWire[iplane]->GetXaxis()->SetTitle(
"Wire Number");
689 HitsWire[iplane]->GetYaxis()->SetTitle(
"Hits");
691 TOFP[iplane] =
new TH1F(
692 Form(
"%s%sTimeofFlightPlane%d", prefix.Data(), region.Data(), (Int_t) iplane),
693 Form(
"Subtracted time of flight for events in plane %d", (Int_t) iplane),
696 TOFP[iplane] -> SetDefaultBufferSize(buffer_size);
697 TOFP[iplane] -> GetXaxis()->SetTitle(
"Time of Flight");
698 TOFP[iplane] -> GetYaxis()->SetTitle(
"Hits");
702 Form(
"%s%sRawTimeofFlightPlane%d", prefix.Data(), region.Data(), (Int_t) iplane),
703 Form(
"Raw time of flight for events in plane %d", (Int_t) iplane),
707 TOFP_raw[iplane] -> SetDefaultBufferSize(buffer_size);
708 TOFP_raw[iplane]->GetXaxis()->SetTitle(
"Time of Flight");
709 TOFP_raw[iplane]->GetYaxis()->SetTitle(
"Hits");
711 TOFW[iplane] =
new TH2F(
712 Form(
"%s%sTimeofFlightperWirePlane%d", prefix.Data(), region.Data(), (Int_t) iplane),
713 Form(
"Subtracted time of flight for each wire in plane %d",(Int_t) iplane),
718 TOFW[iplane]->GetXaxis()->SetTitle(
"Wire Number");
719 TOFW[iplane]->GetYaxis()->SetTitle(
"Time of Flight");
722 Form(
"%s%sRawTimeofFlightperWirePlane%d", prefix.Data() ,region.Data(),(Int_t)iplane),
723 Form(
"Raw time of flight for each wire in plane %d",(Int_t)iplane),
728 TOFW_raw[iplane]->GetXaxis()->SetTitle(
"Wire Number");
729 TOFW_raw[iplane]->GetYaxis()->SetTitle(
"Time of Flight");
738 Bool_t local_debug =
false;
754 std::vector<QwHit>::iterator end=
fTDCHits.end();
755 for(std::vector<QwHit>::iterator hit=
fTDCHits.begin(); hit!=end; hit++) {
757 this_detid = hit->GetDetectorID();
758 plane = this_detid.
fPlane;
761 if (plane<=0 or element<=0) {
763 QwMessage <<
"QwDriftChamberHDC::FillHistograms: Bad plane or element index:"
764 <<
" fPlane = " << plane
765 <<
" fElement= " << element
772 this_det= &(
fWireData.at(plane).at(element));
774 if (hit->IsFirstDetectorHit()) {
780 TotHits[plane]->Fill(element,1);
782 wireshitperplane.at(plane) += 1;
785 raw_time = hit->GetRawTime();
786 time = hit->GetTimeNs();
790 TOFW_raw[plane]->Fill(element, raw_time);
791 TOFP [plane]->Fill(time);
792 TOFW [plane]->Fill(element, time);
795 std::size_t iplane = 0;
798 WiresHit[iplane]->Fill(wireshitperplane[iplane]);
809 std::vector<QwHit>::iterator end=
fTDCHits.end();
810 for (std::vector<QwHit>::iterator hit1=
fTDCHits.begin(); hit1!=end; hit1++) {
811 this_det = hit1->GetDetectorID();
836 std::vector<QwHit>::iterator end=
fTDCHits.end();
837 for(std::vector<QwHit>::iterator iter=
fTDCHits.begin(); iter!=end; ++iter)
840 local_id = iter->GetDetectorID();
841 package = local_id.fPackage;
842 plane = local_id.fPlane - 1;
845 iter->SetDetectorInfo(local_info);
859 Double_t t0_NS = 0.0;
861 Double_t educated_guess_t0_correction_AU = 11255.0;
862 Double_t educated_guess_t0_correction_NS = educated_guess_t0_correction_AU*
fF1TDCResolutionNS;
868 for(std::size_t i=0;i<nhits;i++)
870 package = fTDCHits.at(i).GetPackage();
874 t0_NS = t0_NS - educated_guess_t0_correction_NS;
876 fTDCHits.at(i).SubtractTimeNsOffset(t0_NS);
887 while (mapstr.ReadNextLine())
889 mapstr.TrimComment(
'!');
890 mapstr.TrimWhitespace();
891 if (mapstr.LineIsEmpty())
continue;
893 mapstr.GetTypedNextToken<Double_t>();
894 Double_t d = mapstr.GetTypedNextToken<Double_t>();
909 TString varname,varvalue;
910 Int_t plane=0,wire=0;
914 while ( mapstr.ReadNextLine() )
916 mapstr.TrimComment (
'!' );
917 mapstr.TrimWhitespace();
918 if ( mapstr.LineIsEmpty() )
continue;
919 if ( mapstr.HasVariablePair (
"=",varname,varvalue ) )
922 if ( varname==
"package" )
924 package = ( EQwDetectorPackage ) atoi ( varvalue.Data() );
927 else if ( varname==
"plane" )
930 plane = atoi ( varvalue.Data() );
942 wire = mapstr.GetTypedNextToken<Int_t>();
943 t0 = mapstr.GetTypedNextToken<Int_t>();
945 if ( wire > ( Int_t )
fTimeWireOffsets.at ( package-1 ).at ( plane-1 ).size() )
#define QwMessage
Predefined log drain for regular messages.
std::vector< TH1F * > TOFP
std::vector< std::vector< Int_t > > fTDC_Index
std::vector< TH1F * > WiresHit
std::map< TString, TString > fDetectorMaps
size_t fCurrentBankIndex
Name of this subsystem (the region).
std::vector< std::vector< std::vector< Double_t > > > fTimeWireOffsets
std::vector< TH2F * > HitsWire
std::vector< TH2F * > TOFW_raw
const QwGeometry in(const EQwRegionID &r) const
Get detectors in given region.
Double_t fF1TDCResolutionNS
static UInt_t GetUInt(const TString &varvalue)
Double_t CalculateDriftDistance(Double_t drifttime, QwDetectorID detector)
std::vector< std::vector< UInt_t > > fDirectionData
Bool_t HasDataLoaded() const
Double_t GetReferenceTimeAU(Int_t bank_index, TString name)
void SubtractReferenceTimes()
std::vector< TH2F * > TOFW
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
std::vector< TH1F * > TOFP_raw
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Int_t fElement
trace number for R1; wire number for R2 & R3; PMT number for others
T GetValue(const std::string &key)
Get a templated value.
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
A logfile class, based on an identical class in the Hermes analyzer.
void FillHistograms()
Fill the histograms for this subsystem.
Int_t LinkReferenceChannel(const UInt_t chan, const Int_t plane, const Int_t wire)
std::vector< std::vector< QwDetectorID > > fTDCPtrs
QwGeometry fDetectorInfo
Geometry information of this subsystem.
void ProcessOptions(QwOptions &options)
Process the command line options.
Double_t ReferenceSignalCorrection(Double_t raw_time, Double_t ref_time, Int_t bank_index, Int_t slot)
void FillRawTDCWord(Int_t bank_index, Int_t slot_num, Int_t chan, UInt_t data)
void SetReferenceSignal(Int_t bank_index, Int_t slot, Int_t chan, UInt_t data, Bool_t debug=false)
Int_t fPlane
R or theta index for R1; plane index for R2 & R3.
QwF1TDContainer * fF1TDContainer
Bool_t WireMatches(EQwRegionID region, EQwDetectorPackage package, Int_t plane, Int_t wire)
std::vector< TH1F * > TotHits
Int_t LoadChannelMap(TString mapfile)
Mandatory map file definition.
Int_t BuildWireDataStructure(const UInt_t chan, const EQwDetectorPackage package, const Int_t octant, const Int_t plane, const Int_t wire)
std::vector< Double_t > fTtoDNumbers
std::vector< std::vector< Double_t > > fReferenceData
void SubtractWireTimeOffset()
Int_t RegisterSubbank(const UInt_t bank_id)
Int_t AddChannelDefinition()
static std::ostream & endl(std::ostream &)
End of the line.
Int_t GetTDCIndex(size_t bank_index, size_t slot_num) const
Int_t RegisterSlotNumber(const UInt_t slot_id)
static const Int_t kReferenceChannelPlaneNumber
Hit structure uniquely defining each hit.
void LoadTtoDParameters(TString ttod_map)
std::vector< QwHit > fTDCHits
Int_t LoadTimeWireOffset(TString t0_map)
void FillDriftDistanceToHits()
std::vector< Int_t > fWiresPerPlane
#define RegisterSubsystemFactory(A)
TString GetSubsystemName() const
Int_t RegisterROCNumber(const UInt_t roc_id, const UInt_t bank_id)
Tell the object that it will decode data from this ROC and sub-bank.
F1TDCReferenceContainer * fF1RefContainer
std::vector< std::vector< QwDetectorInfo > > fWireData
void SetDataLoaded(Bool_t flag)