Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NCAnalysisCuts.cxx

Go to the documentation of this file.
00001 
00002 //$Id: NCAnalysisCuts.cxx,v 1.27 2009/12/02 14:21:12 tinti Exp $
00003 //
00004 //NCAnalysisCuts.cxx
00005 //
00006 //utility holding analysis cut algorithms
00007 //
00008 //B. Rebel 10/2005
00010 
00011 #include "NCUtils/Cuts/NCAnalysisCuts.h"
00012 #include "NCUtils/NCType.h"
00013 #include "NCUtils/NCUtility.h"
00014 #include "AnalysisNtuples/ANtpDefaultValue.h"
00015 #include "AnalysisNtuples/ANtpEventInfoNC.h"
00016 #include "AnalysisNtuples/ANtpShowerInfoNC.h"
00017 #include "AnalysisNtuples/ANtpBeamInfo.h"
00018 #include "AnalysisNtuples/ANtpHeaderInfo.h"
00019 #include "AnalysisNtuples/ANtpTrackInfoNC.h"
00020 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00021 #include "AnalysisNtuples/ANtpRecoInfo.h"
00022 #include "MessageService/MsgService.h"
00023 #include "Conventions/Detector.h"
00024 #include "Conventions/Munits.h"
00025 #include "Conventions/SimFlag.h"
00026 #include "Conventions/PlaneView.h"
00027 #include "Conventions/PlaneCoverage.h"
00028 #include "DataUtil/PlaneOutline.h"
00029 #include "DataUtil/EnergyCorrections.h"
00030 
00031 #include "TMath.h"
00032 
00033 #include <cassert>
00034 
00035 using namespace EnergyCorrections;
00036 using NC::Utility::SQR;
00037 
00038 CVSID("$Id: NCAnalysisCuts.cxx,v 1.27 2009/12/02 14:21:12 tinti Exp $");
00039 
00040 //----------------------------------------------------------------------
00041 NCAnalysisCuts::NCAnalysisCuts() :
00042   fBeamType(BeamType::kUnknown),
00043   fCurrentRun(-1),
00044   fCurrentSnarl(-1),
00045   fCurrentSubRun(-1)
00046 {
00047 }
00048 
00049 //----------------------------------------------------------------------
00050 NCAnalysisCuts::~NCAnalysisCuts()
00051 {
00052 }
00053 
00054 //----------------------------------------------------------------------
00055 //use this method to select data from the appropriate beam/horn/intensity
00056 //configurations this method assumes that it is only called for data as
00057 //there are not mixed target positions in the MC files
00058 bool NCAnalysisCuts::IsGoodTarget()
00059 {
00060   bool goodTarget = false;
00061 
00062   BeamType::BeamType_t bt = (BeamType::BeamType_t)(fEventInfo.beam->beamType);
00063 
00064   bool is185i = (bt == BeamType::kL010z185i
00065                  || bt == BeamType::kL010z185i_lowintensity);
00066   bool isL010z = (bt == BeamType::kL010z185i
00067                   || bt == BeamType::kL010z185i_lowintensity
00068                   || bt == BeamType::kL010z000i
00069                   || bt == BeamType::kL010z170i
00070                   || bt == BeamType::kL010z200i);
00071 
00072   //take any thing if the target position is set to all
00073   //beams or pME or pHE
00074   if(fUseAllBeams)
00075     goodTarget = true;
00076   else if(fBeamType == BeamType::kL100z200i && bt == fBeamType)
00077     goodTarget = true;
00078   else if(fBeamType == BeamType::kL250z200i && bt == fBeamType)
00079     goodTarget = true;
00080   else if(fBeamType == BeamType::kL010z185i
00081           && !fUseAll185i && !fUseAllL010z && bt == fBeamType)
00082     goodTarget = true;
00083   else if(fBeamType == BeamType::kL010z170i
00084           && !fUseAllL010z && bt == fBeamType)
00085     goodTarget = true;
00086   else if(fBeamType == BeamType::kL010z200i
00087           && !fUseAllL010z && bt == fBeamType)
00088     goodTarget = true;
00089   else if(fBeamType == BeamType::kL010z185i_lowintensity
00090           && !fUseAll185i && !fUseAllL010z && bt == fBeamType)
00091     goodTarget = true;
00092   else if(fBeamType == BeamType::kL010z000i
00093           && !fUseAllL010z && bt == fBeamType)
00094     goodTarget = true;
00095   else if(fUseAllL010z && isL010z)
00096     goodTarget = true;
00097   else if(fUseAll185i && is185i)
00098     goodTarget = true;
00099 
00100 
00101   MAXMSG("NCAnalysisCuts", Msg::kDebug, 10) << fEventInfo.beam->beamType << " "
00102                                            << BeamType::AsString(bt) << " "
00103                                            << goodTarget << " "
00104                                            << (int)fUseAllBeams << " "
00105                                            << is185i << " " << isL010z << endl;
00106 
00107 
00108   return goodTarget;
00109 }
00110 
00111 //----------------------------------------------------------------------
00112 bool NCAnalysisCuts::IsNewSnarl()
00113 {
00114   bool newSnarl = false;
00115 
00116   if(fEventInfo.header->run != fCurrentRun){
00117     newSnarl       = true;
00118     fCurrentRun    = fEventInfo.header->run;
00119     fCurrentSubRun = fEventInfo.header->subRun;
00120     fCurrentSnarl  = fEventInfo.header->snarl;
00121   }
00122   else if(fEventInfo.header->run == fCurrentRun &&
00123           fEventInfo.header->subRun != fCurrentSubRun){
00124     newSnarl = true;
00125     fCurrentRun = fEventInfo.header->run;
00126     fCurrentSubRun = fEventInfo.header->subRun;
00127     fCurrentSnarl = fEventInfo.header->snarl;
00128   }
00129   else if(fEventInfo.header->run == fCurrentRun &&
00130           fEventInfo.header->subRun == fCurrentSubRun &&
00131           fEventInfo.header->snarl != fCurrentSnarl){
00132     newSnarl = true;
00133     fCurrentRun = fEventInfo.header->run;
00134     fCurrentSubRun = fEventInfo.header->subRun;
00135     fCurrentSnarl = fEventInfo.header->snarl;
00136   }
00137 
00138   return newSnarl;
00139 }
00140 
00141 
00142 //----------------------------------------------------------------------
00143 bool NCAnalysisCuts::IsMultiCutsClean()
00144 {
00145   // 35ns timing cut
00146   if(TMath::Abs(fEventInfo.event->minTimeSeparation) < 35e-9) return false;
00147 
00148   // tiny events are mostly junk
00149   if(fEventInfo.event->totalStrips < 5) return false;
00150 
00151   // this cuts very steep showers, leaking in
00152   if(fEventInfo.event->totalStrips/SQR(fEventInfo.event->planes)>1.15)
00153     return false;
00154 
00155   // this cuts leakage which leaves activity in partially instrumented
00156   // region
00157   if(fEventInfo.event->edgeActivityStrips > 2 &&
00158      fEventInfo.event->edgeActivityPH > 1000 &&
00159      fEventInfo.event->energyGeV < 5.0 &&
00160      fEventInfo.shower->planes > fEventInfo.track->planes) // don't cut out CC
00161     return false;
00162 
00163   // also cut out events with too much activity in the opposite edge region
00164   if(fEventInfo.event->oppEdgeStrips > 2 &&
00165      fEventInfo.event->energyGeV < 5.0 &&
00166      fEventInfo.shower->planes > fEventInfo.track->planes) // don't cut out CC
00167     return false;
00168 
00169   // make additional deltaZ cuts if (|minDeltaT|<175ns)
00170   if(TMath::Abs(fEventInfo.event->closeTimeDeltaZ) < 1.0 &&
00171      TMath::Abs(fEventInfo.event->minTimeSeparation) < 175e-9)
00172     return false;
00173 
00174   // Survived all cuts
00175   return true;
00176 }
00177 
00178 //----------------------------------------------------------------------  
00179 bool NCAnalysisCuts::IsSimpleCutsClean()
00180 {
00181   // 155ns timing cut                                                      
00182   if(TMath::Abs(fEventInfo.event->minTimeSeparation) < 155e-9) 
00183     return false;
00184 
00185   //cut on portion of the slice in the event                              
00186   if(fEventInfo.event->slicePHFraction<0.9) return false;
00187 
00188   // also cut events that share a good fraction of physical strips with
00189   // other events                                                            
00190   // and don't cut out CC                                                  
00191   if(fEventInfo.event->sharedStripFraction>0.3 &&
00192      ((-fEventInfo.shower->planes + fEventInfo.track->planes)<=5.))
00193     return false;
00194 
00195 // Survived all cuts                                                    
00196   return true;
00197 }
00198 
00199 //----------------------------------------------------------------------
00200 bool NCAnalysisCuts::IsCleanLowMultSnarl()
00201 {
00202   return fEventInfo.header->events == 1 ||
00203     (fEventInfo.header->events == 2 &&
00204      TMath::Abs(fEventInfo.event->minTimeSeparation*1e6) > 0.2);
00205 }
00206 
00207 //----------------------------------------------------------------------
00208 void NCAnalysisCuts::SetInfoObjects(ANtpHeaderInfo* headerInfo,
00209                                     ANtpBeamInfo* beamInfo,
00210                                     ANtpEventInfoNC* eventInfo,
00211                                     ANtpTrackInfoNC* trackInfo,
00212                                     ANtpShowerInfoNC* showerInfo,
00213                                     ANtpTruthInfoBeam* truthInfo)
00214 {
00215   fEventInfo.header = headerInfo;
00216   fEventInfo.beam = beamInfo;
00217   fEventInfo.event = eventInfo;
00218   fEventInfo.track = trackInfo;
00219   fEventInfo.shower = showerInfo;
00220   fEventInfo.truth = truthInfo;
00221 }
00222 
00223 //----------------------------------------------------------------------
00224 void NCAnalysisCuts::SetBeamType(BeamType::BeamType_t type)
00225 {
00226   fBeamType = type;
00227 }
00228 
00229 //----------------------------------------------------------------------
00230 void NCAnalysisCuts::SetUseAllBeams(bool useAll)
00231 {
00232   fUseAllBeams = useAll;
00233 }
00234 
00235 //----------------------------------------------------------------------
00236 void NCAnalysisCuts::SetUseAllL010z(bool useAll)
00237 {
00238   fUseAllL010z = useAll;
00239 }
00240 
00241 //----------------------------------------------------------------------
00242 void NCAnalysisCuts::SetUseAll185i(bool useAll)
00243 {
00244   fUseAll185i = useAll;
00245 }
00246 
00247 //----------------------------------------------------------------------
00248 bool NCAnalysisCuts::IsGoodSpill()
00249 {
00250   //mc beam is always perfect and only using the
00251   //correct mc files with each beamType, so no need to
00252   //check the target
00253   if(fEventInfo.header->dataType == int(SimFlag::kMC)) return true;
00254 
00255   if(!IsGoodTarget()) return false;
00256 
00257   //check the beam quality cuts, the spill type and
00258   //error on the gps - error has to be big within 5 minutes of the
00259   //spill - only check the gps for far detector
00260   if(fEventInfo.beam->goodSpill < 1 ||
00261      (fEventInfo.header->detector == int(Detector::kFar) &&
00262       fEventInfo.beam->deltaSecToSpillGPS < 360 &&
00263       fEventInfo.beam->gpsError > 1000) ||
00264      fEventInfo.header->spillType == 3)
00265     return false;
00266 
00267   return true;
00268 }
00269 
00270 //----------------------------------------------------------------------
00271 bool NCAnalysisCuts::IsGoodBeamSnarl()
00272 {
00273   //MC snarls are always good
00274   if(fEventInfo.header->dataType == int(SimFlag::kMC)) return true;
00275 
00276   // check that there were no problems with the detector
00277   // Don't take reversed field data for uDSTs
00278   if(fEventInfo.header->coilStatus < 1 ||
00279      (fEventInfo.header->detector == int(Detector::kFar) &&
00280       fEventInfo.header->isGoodData < 1))
00281     return false;
00282 
00283   //the cuts in this method come from MINOS-doc-1342
00284   if(!IsGoodSpill()) return false;
00285 
00286   if(fEventInfo.header->detector == int(Detector::kNear) &&
00287      (fEventInfo.header->coilCurrent > -1000 ||
00288       fEventInfo.header->isGoodData < 1))
00289     return false;
00290 
00291   return true;
00292 }
00293 
00294 //----------------------------------------------------------------------
00295 //these cuts were presented in the 2/9/06 reconstruction meeting by
00296 //N. Saoulidou
00297 //this is a little cheesy as the code is similar to what is in NCUtils
00298 bool NCAnalysisCuts::IsGoodShower()
00299 {
00300   //set the version for the energy corrections.  mike uses R1_18 and cedar, the
00301   //values in ANtpHeaderInfo are Birch(Cedar) Data(Carrot/Daikon/Etc)
00302   if( fEventInfo.header->softVersion.Contains("Cedar") ){
00303     const EnergyCorrections::CorrectionVersion_t ver = EnergyCorrections::kCedar;
00304     SetCorrectionVersion(ver);
00305   }
00306   else if( fEventInfo.header->softVersion.Contains("Birch") ){
00307     const EnergyCorrections::CorrectionVersion_t ver = EnergyCorrections::kBirch;
00308     SetCorrectionVersion(ver);
00309   }
00310 
00311 
00312   bool isdata = true;
00313   if(fEventInfo.header->dataType == (int)SimFlag::kMC) isdata = false;
00314 
00315   Detector::Detector_t det = Detector::kNear;
00316   if(fEventInfo.header->detector == (int)Detector::kFar)
00317     det = Detector::kFar;
00318 
00319   double showerEnergy;
00320   //Protect against events without showers.
00321   if(fEventInfo.shower->linearCCGeV > 0.){
00322       showerEnergy = CorrectShowerEnergy(fEventInfo.shower->linearCCGeV,
00323                                          det,
00324                                          CandShowerHandle::kCC,
00325                                          1, isdata);
00326   }
00327   else showerEnergy = ANtpDefaultValue::kDouble;
00328 
00329   if(fEventInfo.event->tracks < 1
00330      || TMath::Abs(fEventInfo.shower->vtxZ - fEventInfo.track->aTrkvtx_ns) < 0.5
00331      ||  showerEnergy > 2. )
00332     return true;
00333 
00334   return false;
00335 }
00336 
00337 /*
00338 //----------------------------------------------------------------------
00339 void NCAnalysisCuts::RollBirchMCSnarlNoise(UInt_t& extraEvents,
00340                                              Double_t& extraPH){
00341 
00342   //Seed the generator.  Each snarl is uniquely identified by run,
00343   // ( 21 001 001 to 21 001 100 ) and snarl ( 0 to 2000ish ) numbers
00344   // each run is uniquely identifed by index numbers (0 to 5ish)
00345   // seed is a UInt_t  (0 to 4,294,967,295 )
00346 
00347   UInt_t seed(fEventInfo.header->run % 1000);
00348   seed *= 2048;
00349   seed += fEventInfo.header->snarl;
00350   seed *= 16;
00351   seed += fEventInfo.event->index;
00352   fRandom->SetSeed(seed);
00353 
00354   //roll a Poisson to add an event(s) randomly. lambda = 7.741e-4
00355   const Float_t meanEvt(7.741e-4);
00356 
00357   extraEvents = fRandom->Poisson(meanEvt);
00358 
00359   //Add PH based on how many events we added
00360   // sqrt(noise) has gaussian distn. Ignore the small probability of
00361   // going below zero---will square the result anyway.
00362 
00363    Double_t sqrtPH(0);
00364    if (extraEvents == 0) {
00365      sqrtPH = fRandom->Gaus(63.33, 8.673);
00366    }
00367    else if ( extraEvents == 1 && fRandom->Rndm() > 0.115 ) {
00368      //11.5% of 1 event fake trigger snarls seem to have something
00369      // substantial (a cosmic?)
00370      // Also use this distribution for > 1 events added.
00371      sqrtPH = fRandom->Gaus(71.02, 7.772);
00372    }
00373    else {
00374      sqrtPH = fRandom->Gaus(259.6, 90.27);
00375    }
00376 
00377    extraPH = sqrtPH*sqrtPH;
00378 
00379 }
00380 */
00381 //----------------------------------------------------------------------
00382 Int_t NCAnalysisCuts::GetReleaseType()
00383 {
00384   // Get the ReleaseType from the string.
00385 
00386   //const char* asCharArray= (const char*)fEventInfo.header->softVersion;
00387   ReleaseType::Release_t softType =
00388     ReleaseType::StringToType(fEventInfo.header->softVersion);
00389 
00390   assert(softType != -1);
00391 
00392   return softType;
00393 }

Generated on Mon Feb 15 11:07:02 2010 for loon by  doxygen 1.3.9.1