//////////////////////////////////////////////////////////////////// /// \file PlotDataCleaningCuts.cc /// /// \brief Functions to plot data cleaning cuts. /// /// \author J Walker /// /// REVISION HISTORY:\n /// 2015-05-14 : J Walker - First version.\n /// /// \details Number of data cleaning flags for each cut are plotted. /// Note: The data cleaning processor should be applied to the data. /// //////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /// Create the data cleaning cut flags histogram /// /// @param[in] fileName of the RAT::DS root file to analyse /// @return the histogram plot TH1D* CreateDataCleaningFlagsHistogram( const string& fileName ) { // If this is being done on data that does not require remote database connection // eg.: a simple simulation with default run number (0) // We can disable the remote connections: // // NOTE: Don't do this if you are using real data!!! RAT::DB::Get()->SetAirplaneModeStatus(true); RAT::DU::DSReader dsReader( fileName ); RAT::DU::DataCleaningBits rDataCleaningBits = RAT::DU::Utility::Get()->GetDataCleaningBits(); // To get the data cleaning bits size_t numberOfCuts = rDataCleaningBits.GetInverseMapLast()->first+1; TH1D* hCutFlags = new TH1D( "hCutFlags", "Data cleaning cut flags", numberOfCuts, 0, numberOfCuts ); // Loop through entries in rootfile for( size_t iEntry = 0; iEntry < dsReader.GetEntryCount(); iEntry++ ){ const RAT::DS::Entry& rDS = dsReader.GetEntry( iEntry ); // Look at each triggered event in the entry for( size_t iEV = 0; iEV < rDS.GetEVCount(); iEV++ ){ const RAT::DS::EV& rEV = rDS.GetEV( iEV ); const RAT::DS::DataQCFlags& rDataQCFlags = rEV.GetDataCleaningFlags(); const RAT::DS::Meta& rMeta = dsReader.GetMeta(); const UInt_t pass = rMeta.GetCurrentPass(); // Check flags exist if(rDataQCFlags.ExistFlags(pass)){ // Checks flags exist const RAT::DS::BitMask& rBitMaskFlags = rDataQCFlags.GetFlags(pass); const RAT::DS::BitMask& rBitMaskApplied = rDataQCFlags.GetApplied(pass); // Loop through bits for( map::iterator iDCBits = rDataCleaningBits.GetInverseMapBegin(); iDCBits != rDataCleaningBits.GetInverseMapEnd(); iDCBits++ ) { Bool_t rApplied = rBitMaskApplied.Get( iDCBits->first ); if( rApplied ){ // Checks cut has been applied Bool_t rFlag = rBitMaskFlags.Get( iDCBits->first ); if( !rFlag ) hCutFlags->Fill( iDCBits->first ); // Fill if event fails the cut } } } } // EV } // Entry hCutFlags->GetYaxis()->SetTitle( "Number of events" ); for( map::iterator iDCBits = rDataCleaningBits.GetInverseMapBegin(); iDCBits != rDataCleaningBits.GetInverseMapEnd(); iDCBits++ ) { hCutFlags->GetXaxis()->SetBinLabel(iDCBits->first+1, rDataCleaningBits.GetBitName(iDCBits->first).c_str()); } return hCutFlags; } /// Plot the data cleaning cut flags /// /// @param[in] fileName of the RAT::DS root file to analyse void PlotDataCleaningFlags( const string& fileName ) { gStyle->SetFillColor( kWhite ); TCanvas* c1 = new TCanvas(); TH1D* dcCutFlags = CreateDataCleaningFlagsHistogram( fileName ); dcCutFlags->Draw(); c1->Update(); }