int main(int argc, char** argv) { string inputfilelist; string filenameext = ".TWin.root"; string outputfilebase; string outputfile; TChain *SubEvt = new TChain("SubEvt"); if( argc != 3 ) { cout<<"Usage:"<<endl; cout<<" TWin inputfiles.list output/path/namebase"<<endl; cout<<endl; return 1; } else { inputfilelist = argv[1]; outputfilebase = argv[2]; /// The input file parsing ifstream inlist( inputfilelist.c_str() ); string line; while( getline( inlist, line ) ) { SubEvt->Add( line.c_str() ); } /// The output file outputfile = outputfilebase + filenameext; } /// Do the work /// ########### // Load the SubEvt Tree // This should a TChain // Get the SubEvt Tree reader SEReader = new SubEvtReader; SEReader->Init(SubEvt); // Prepare the output tree aEventTree = new EventTree("Event",outputfile.c_str(),0); /// Prepare to Start BeginJob(); /// The main loop /// ############# unsigned int entries = SubEvt->GetEntries(); for( unsigned int entry=0; entry<entries; entry++ ) { int ret = SEReader->GetEntry( entry ); if( ret==0 ) { cout<<"Warning: Read error"<<endl; } if( SEReader->Run != CurrRun ) { if( CurrRun != 0 ) { EndRun(); } BeginRun(); } /* A few key variables */ CurrSubEvtTime = TimeStamp(SEReader->SubEvtSec, SEReader->SubEvtNano); bool GoodSingleAdSubEvt = false; TimeStamp T2PrevMuon; if( PrevMuonTime == TimeStamp::GetBOT() ) { T2PrevMuon == TimeStamp(0,0); } else { T2PrevMuon = CurrSubEvtTime - PrevMuonTime; } CurrSingleDet = 0; if( SEReader->NDet == 1 ) { for( unsigned int i=0; i<7; i++ ) { if( SEReader->Valid[i] ) { CurrSingleDet = SEReader->Det[i]; } } } if( SEReader->MuonProb < 0.5 && /// SEReader->RetrigProb < 0.5 && /// This turns out to be not very useful SEReader->NDet == 1 && CurrSingleDet <= 4 && T2PrevMuon.GetSeconds() > cuts.SpallDt/second ) { GoodSingleAdSubEvt = true; } /* For non-muon-event, if it is a single AD sub event */ /* Need to filter out non-physical events. They should not go into the searching queue. */ if( SEReader->MuonProb < 0.5 ) { if( GoodSingleAdSubEvt ) { /* Skip flashers */ double Quadrant = SEReader->Quadrant[ CurrSingleDet - 1 ]; double QMax2Sum = SEReader->QMax2Sum[ CurrSingleDet - 1 ]; double ellipse = sqrt( (Quadrant)*(Quadrant) + (QMax2Sum)/0.45*(QMax2Sum)/0.45 ); if( ellipse>1 ) goto EndEachSubEvent; /* Remove low and high energy events */ if( SEReader->E[ CurrSingleDet - 1 ] < cuts.QSumLow/MeV ) { goto EndEachSubEvent; } } } /// Each AD has its own queue for( int AdNo = 1; AdNo <= 4; AdNo++ ) { RunStatus::RunStatus_t & ThisAdStatus = RunStatusDict[ AdNo ]; Event ThisAdEvent = EventDict[ AdNo ]; TimeStamp ThisAdEventTime( ThisAdEvent.TimeSec, ThisAdEvent.TimeNano ); TimeStamp T2FirstSubEvt = CurrSubEvtTime - ThisAdEventTime; bool SameAd = (CurrSingleDet == AdNo); /* How to normally end an event */ /*##############################*/ if( ThisAdStatus == RunStatus::inEvent && T2FirstSubEvt.GetSeconds() > cuts.CoinDt/second ) { ThisAdStatus = RunStatus::waiting; NormalEndEvent( AdNo ); } /* How to abruptly stop an event */ /*###############################*/ if( ThisAdStatus == RunStatus::inEvent && T2FirstSubEvt.GetSeconds() < cuts.CoinDt/second && !GoodSingleAdSubEvt ) { ThisAdStatus = RunStatus::waiting; AbruptStopEvent( AdNo ); } /* How to append a sub-event */ /*###########################*/ if( ThisAdStatus == RunStatus::inEvent && SameAd && T2FirstSubEvt.GetSeconds() < cuts.CoinDt/second && GoodSingleAdSubEvt ) { AppendSubEvt( AdNo ); } /* How to begin an event */ /*#######################*/ if( ThisAdStatus == RunStatus::waiting && SameAd && GoodSingleAdSubEvt ) { ThisAdStatus = RunStatus::inEvent; CurrEventAd = CurrSingleDet; BeginEvent( AdNo ); AppendSubEvt( AdNo ); } } EndEachSubEvent: /* Live time calculation */ if( SEReader->MuonProb > 0.5 ) { MuonCounter += 1; double shadowTime = (cuts.SpallDt + cuts.CoinDt)/second ; double T2PrevMuon = (CurrSubEvtTime - PrevMuonTime).GetSeconds(); if( T2PrevMuon < (cuts.SpallDt + cuts.CoinDt)/second ) { shadowTime = T2PrevMuon; } MuonShadowTime.Add( shadowTime ); PrevMuonTime = TimeStamp( SEReader->SubEvtSec, SEReader->SubEvtNano ); } PrevSubEvtTime = TimeStamp( SEReader->SubEvtSec, SEReader->SubEvtNano ); continue; } AbruptStopEvent( 1 ); AbruptStopEvent( 2 ); AbruptStopEvent( 3 ); AbruptStopEvent( 4 ); EndRun(); aEventTree->Close(); EndJob(); return 1; }
void DailyPlot() { cout<<" [ Measured and predicted rate ] "<<endl; /* Predicted daily rate */ IGetFluxXsec* GetFluxXsec; if( Basic::DailyFlux == true ) { /// Daily flux blinded. } else { GetFluxXsec = gGetFluxXsec; } /* Daily rate */ TimeStamp BeginTime(2011,12,24,0,0,0); TimeStamp EndTime (2012,02,11,0,0,0); TimeStamp Week(7*24*60*60); TimeStamp Day(24*60*60); map< TimeStamp, double > Rate[ Basic::NoAd ]; for( TimeStamp Time = BeginTime; Time <= EndTime; Time.Add( Week ) ) { for( unsigned int m_AdNo = 1; m_AdNo<=Basic::NoAd; m_AdNo++ ) { double Sum=0; for( unsigned int BinIdx = 1; BinIdx <= Binning::NHistoBin; BinIdx++ ) { for( unsigned int RctIdx = 1; RctIdx <= Basic::NoRct; RctIdx++ ) { Sum += GetFluxXsec->Get( Time, RctIdx, BinIdx ) * (Binning::EndEnergy-Binning::BeginEnergy)/Binning::NHistoBin * pow( Baseline(RctIdx, m_AdNo), -2 ) / 4 /3.1415926 * gProtonNumber->Get( Time, m_AdNo ).NPGdLs * Day.GetSeconds()*CLHEP::second; } } Rate[m_AdNo-1][Time] = Sum; } } /// Sum over all live time double Sum8[Basic::NoAd]; const std::vector< RunBrief* > Runs = gAnalyzeData->GetRuns(); /* ============================================== */ for( unsigned int m_AdNo=1; m_AdNo<=Basic::NoAd; m_AdNo++ ) { Sum8[m_AdNo-1] = 0; int Site = ToSite(m_AdNo); int LocalAdNo = ToLocalAdNo(m_AdNo); for( std::vector< RunBrief* >::const_iterator iRun = Runs.begin(); iRun!=Runs.end(); iRun++ ) { const RunBrief* const Brief = (*iRun); if( Dataset::GdCap != Brief->Dataset ) continue; /* Must be from the same site */ if( Site != Brief->Site ) continue; /* Cache run info */ double fulltime = Brief->Fulltime; double livefraction = Brief->Livetime[ LocalAdNo-1 ] / fulltime; /* split it into days */ for( TimeStamp Time = Brief->StartTime; Time < Brief->StopTime; /* Complex increment */) { /* Through this, runs span over a day are split into days at exactly 00:00:00 */ unsigned int StartDate,StartYY,StartMM,StartDD; unsigned int StopDate, StopYY, StopMM, StopDD; StartDate = Time.GetDate( true, 0, &StartYY, &StartMM, &StartDD ); StopDate = Brief->StopTime.GetDate( true, 0, &StopYY, &StopMM, &StopDD ); TimeStamp Step(0,0); /* Alway init a TimeStamp, otherwise it will be inited to sys time and too slow. */ if( StartDate == StopDate ) { /* The same day */ Step = Brief->StopTime - Time; } else { /* The closest day's end */ TimeStamp DaysEnd( StartYY,StartMM,StartDD+1, 0, 0, 0, 0); Step = DaysEnd - Time; } for( unsigned int BinIdx = 1; BinIdx <= Binning::NHistoBin; BinIdx++ ) { for( unsigned int RctIdx = 1; RctIdx <= Basic::NoRct; RctIdx++ ) { Sum8[m_AdNo-1] += GetFluxXsec->Get( Time, RctIdx, BinIdx ) * (Binning::EndEnergy-Binning::BeginEnergy)/Binning::NHistoBin * pow( Baseline(RctIdx, m_AdNo), -2 ) / 4 /3.1415926 * gProtonNumber->Get( Time, m_AdNo ).NPGdLs * Step.GetSeconds()*CLHEP::second; } } /* After all calculation, calculate the addtion for Time */ Time.Add( Step ); } } } /// Printout cout<<" [ Weekly rate (day^-1), no oscillation ] "<<endl; for( TimeStamp Time = BeginTime; Time <= EndTime; Time.Add( Week ) ) { cout<<Time<<"\t"; for( unsigned int m_AdNo = 1; m_AdNo<=Basic::NoAd; m_AdNo++ ) { cout<<Rate[m_AdNo-1][Time]<<"\t"; } cout<<endl; } cout<<"Sum "; for( unsigned int m_AdNo = 1; m_AdNo<=Basic::NoAd; m_AdNo++ ) cout<<Sum8[m_AdNo-1]<<"\t"; cout<<endl; }
int Truth::SetupTruth() { if( RepeatPRL ) { return 1; } /// Reset all bin contents Reset(); IGetFluxXsec* GetFluxXsec; if( Basic::DailyFlux == true ) { /// Daily flux blinded. } else { GetFluxXsec = gGetFluxXsec; } const std::vector< RunBrief* > Runs = gAnalyzeData->GetRuns(); /* ============================================== */ for( std::vector< RunBrief* >::const_iterator iRun = Runs.begin(); iRun!=Runs.end(); iRun++ ) { const RunBrief* const Brief = (*iRun); int Dataset = Brief->Dataset; if( m_dataset != Dataset ) continue; int Site = ToSite(m_AdNo); int LocalAdNo = ToLocalAdNo(m_AdNo); /* Must be from the same site */ if( Site != Brief->Site ) continue; /* Cache run info */ double fulltime = Brief->Fulltime; double livefraction = Brief->Livetime[ LocalAdNo-1 ] / fulltime; double OstwEff = Brief->OstwEff[ LocalAdNo-1 ]; /* split it into days */ for( TimeStamp Time = Brief->StartTime; Time < Brief->StopTime; /* Complex increment */) { /* Through this, runs span over a day are split into days at exactly 00:00:00 */ unsigned int StartDate,StartYY,StartMM,StartDD; unsigned int StopDate, StopYY, StopMM, StopDD; StartDate = Time.GetDate( true, 0, &StartYY, &StartMM, &StartDD ); StopDate = Brief->StopTime.GetDate( true, 0, &StopYY, &StopMM, &StopDD ); TimeStamp Step(0,0); /* Alway init a TimeStamp, otherwise it will be inited to sys time and too slow. */ if( StartDate == StopDate ) { /* The same day */ Step = Brief->StopTime - Time; } else { /* The closest day's end */ TimeStamp DaysEnd( StartYY,StartMM,StartDD+1, 0, 0, 0, 0); Step = DaysEnd - Time; } /* live time in this step */ double thislivetime = Step.GetSeconds()*CLHEP::second * livefraction; for( unsigned int BinIdx = 1; BinIdx <= Binning::NHistoBin; BinIdx++ ) { for( unsigned int RctIdx = 1; RctIdx <= Basic::NoRct; RctIdx++ ) { double NTruth = GetBinContent( BinIdx ); double Increment = 0; double Incre8 = 0, Incre22 = 0; double Evis = Binning::BeginEnergy + (BinIdx-1) * (Binning::EndEnergy-Binning::BeginEnergy)/Binning::NHistoBin; double Enu = Evis + Phys::EnuToEprompt; if( m_dataset == Dataset::GdCap ) { Incre8 += GetFluxXsec->Get( Time, RctIdx, BinIdx ) * (Binning::EndEnergy-Binning::BeginEnergy)/Binning::NHistoBin * pow( Baseline(RctIdx, m_AdNo), -2 ) / 4 /3.1415926 * gProtonNumber->Get( Time, m_AdNo ).NPGdLs * thislivetime * OstwEff * SurvProb( s_2_2_13, Baseline(RctIdx, m_AdNo), Enu) * Phys::Gd_Cap_Pmpt_eff * Phys::Gd_Cap_Dlyd_eff * Phys::GdLS_Gd_Cap_Frac * Phys::GdLS_Distance_8_eff /* 100% */ * Eff::Flasher_8_eff * Eff::Time_8_eff * Eff::Spill_in_8_eff; } if( m_dataset == Dataset::HCap ) { /// GdLS part Incre22 += GetFluxXsec->Get( Time, RctIdx, BinIdx ) * (Binning::EndEnergy-Binning::BeginEnergy)/Binning::NHistoBin * pow( Baseline(RctIdx, m_AdNo), -2 ) / 4 /3.1415926 * gProtonNumber->Get( Time, m_AdNo ).NPGdLs * thislivetime * OstwEff * Phys::GdLS_H_Cap_Frac * SurvProb( s_2_2_13, Baseline(RctIdx, m_AdNo), Enu) * Phys::GdLS_Distance_22_eff; /* Not finalized. */ //cout<<s_2_2_13<<" "<<Baseline(RctIdx, m_AdNo)/CLHEP::m<<" "<<Enu/CLHEP::MeV<<" "<<SurvProb( s_2_2_13, Baseline(RctIdx, m_AdNo), Enu)<<endl; /// LS part Incre22 += GetFluxXsec->Get( Time, RctIdx, BinIdx ) * (Binning::EndEnergy-Binning::BeginEnergy)/Binning::NHistoBin * pow( Baseline(RctIdx, m_AdNo), -2 ) / 4 /3.1415926 * gProtonNumber->Get( Time, m_AdNo ).NPLs * thislivetime * OstwEff * Phys::En3sigma_eff * SurvProb( s_2_2_13, Baseline(RctIdx, m_AdNo), Enu) * Phys::LS_Distance_22_eff; /* Not finalized. */ } Increment = Incre8 + Incre22; SetBinContent( BinIdx, NTruth + Increment ); } } /* After all calculation, calculate the addtion for Time */ Time.Add( Step ); } } return 1; }