00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "NCUtils/Extraction/NCExtractionCuts.h"
00012
00013 #include "MessageService/MsgService.h"
00014 #include "Conventions/Detector.h"
00015 #include "Conventions/SimFlag.h"
00016 #include "NCUtils/Cuts/NCAnalysisCutsNC.h"
00017
00018 #include "TDirectory.h"
00019
00020 #include <cassert>
00021
00022 #include "NCUtils/Extraction/MicroDSTMaker.h"
00023 REGISTER_NCEXTRACTION(NCExtractionCuts, Cuts)
00024
00025 static const int kNumPDFBaseNamesDP = 3;
00026
00027 ClassImp(NCExtractionCuts)
00028
00029 CVSID("$Id: NCExtractionCuts.cxx,v 1.10 2009/11/23 16:55:22 rodriges Exp $");
00030
00031
00032 NCExtractionCuts::NCExtractionCuts(NCAnalysisCuts* cuts,
00033 const Registry& r) :
00034 NCExtraction(cuts, r),
00035 fPDFsFilled(false),
00036 fBeamType(BeamType::kUnknown)
00037
00038 {
00039 MSG("JobC", Msg::kInfo) << "NCExtractionCuts::Constructor 2" << endl;
00040
00041
00042 const char* tmps;
00043 if (r.Get("BeamType", tmps)) fBeamType=BeamType::TagToEnum(tmps);
00044 }
00045
00046
00047 void NCExtractionCuts::ReadPDFs(NCEventInfo& evtInfo)
00048 {
00049 MSG("NCExtractionCuts", Msg::kInfo) << "ReadPDFs" << endl;
00050
00051 TDirectory *savedir = gDirectory;
00052
00053
00054 TString basedir(getenv("SRT_LOCAL"));
00055 if(basedir=="") basedir=getenv("SRT_PRIVATE_CONTEXT");
00056
00057 if(basedir==".") basedir=getenv("SRT_PUBLIC_CONTEXT");
00058
00059 TString pdfPath = basedir+"/NCUtils/data/";
00060
00061 Detector::Detector_t detType = (Detector::Detector_t)evtInfo.header->detector;
00062
00063 TString pdffile = WhichCCPIDFiles(detType, fReleaseType, fBeamType);
00064 assert(pdffile!="");
00065
00066 pdfPath += pdffile;
00067 MSG("NCExtractionCuts", Msg::kInfo)
00068 << "Reading PDFS from file " << pdfPath << endl;
00069 savedir->cd();
00070
00071 TFile pdfFile(pdfPath);
00072
00073
00074 fPDFs.clear();
00075 const char* pdfNamesInFile[kNumPDFBaseNamesDP] = {"Event length - %s",
00076 "Track ph frac - %s",
00077 "ph per plane (%s)"};
00078 vector<TString> ncccNames;
00079 ncccNames.resize(2);
00080 ncccNames[NCType::kNC]="nc";
00081 ncccNames[NCType::kCC]="cc";
00082
00083 for(int i=0; i<kNumPDFBaseNamesDP; ++i){
00084 for(int evtType=0; evtType<2; ++evtType){
00085 TString histname=Form(pdfNamesInFile[i], ncccNames[evtType].Data());
00086 TH1F* hist=(TH1F*)pdfFile.Get(histname);
00087 if(!hist){
00088 MSG("NCExtractionCuts", Msg::kFatal)
00089 << "Can't find histogram with name " << histname
00090 << " in file." << endl;
00091
00092 MSG("NCExtractionCuts", Msg::kFatal) << "Goodbye" << endl;
00093 }
00094 hist->SetDirectory(0);
00095 fPDFs[(NCType::EEventType)evtType].push_back(hist);
00096 }
00097 }
00098
00099 savedir->cd();
00100
00101 fPDFsFilled = true;
00102 }
00103
00104
00105 float NCExtractionCuts::FindPDFProbability(TH1F *pdf, float pdfValue)
00106 {
00107 int bin = 0;
00108 float binContent = 0.;
00109
00110 bin = pdf->FindBin(pdfValue);
00111 binContent = pdf->GetBinContent(bin);
00112
00113 if(binContent>0. && pdf->Integral()>0.) return binContent/pdf->Integral();
00114 else return 0;
00115 }
00116
00117
00118 double NCExtractionCuts::GetIdProbability(NCEventInfo& evtInfo, int)
00119 {
00120 MAXMSG("NCExtractionCuts", Msg::kDebug,20) << "GetIdProbabilty" << endl;
00121
00122 bool passesNCCuts=PassesNCCuts(evtInfo);
00123 bool passesCCCuts=PassesCCCuts(evtInfo);
00124
00125
00126
00127
00128
00129
00130
00131 if ( passesCCCuts && !passesNCCuts) return 1;
00132 else if(!passesCCCuts && passesNCCuts) return 0;
00133 else if( passesCCCuts && passesNCCuts) return -1;
00134 else if(!passesCCCuts && !passesNCCuts) return -2;
00135
00136 assert(0 && "This should never happen");
00137 }
00138
00139
00140 bool NCExtractionCuts::PassesNCCuts(NCEventInfo& evtInfo)
00141 {
00142 const Detector::Detector_t det = (Detector::Detector_t)evtInfo.header->detector;
00143
00144 int tracks = evtInfo.event->tracks;
00145
00146 int planes = det==Detector::kNear ? evtInfo.event->lengthInPlanes :
00147 evtInfo.event->planes;
00148
00149 int trackExtension = evtInfo.shower->planes - evtInfo.track->planes;
00150
00151
00152
00153
00154 if(planes >= 47) return false;
00155 else{
00156
00157 if(tracks == 0) {
00158 return true;
00159 } else {
00160
00161 if(trackExtension > -6) {
00162 return true;
00163 } else {
00164 return false;
00165 }
00166 }
00167 }
00168
00169 }
00170
00171
00172 bool NCExtractionCuts::PassesCCCuts(NCEventInfo& evtInfo)
00173 {
00174 const Detector::Detector_t det = (Detector::Detector_t)evtInfo.header->detector;
00175
00176
00177
00178 int dpPlanes = det==Detector::kNear ? evtInfo.event->lengthInPlanes :
00179 evtInfo.event->eventSummaryPlanes;
00180
00181 float trackSignalUseFraction = evtInfo.track->pulseHeight;
00182 if(evtInfo.event->pulseHeight > 0.)
00183 trackSignalUseFraction /= evtInfo.event->pulseHeight;
00184
00185 float trackSignalPerPlane = evtInfo.track->pulseHeight;
00186 if(evtInfo.track->planes > 0) trackSignalPerPlane /= evtInfo.track->planes;
00187
00188 vector<float> dpInputs;
00189
00190 dpInputs.push_back(dpPlanes);
00191 dpInputs.push_back(trackSignalUseFraction);
00192 dpInputs.push_back(trackSignalPerPlane);
00193
00194 float ncLikelihood = 1.;
00195 float ccLikelihood = 1.;
00196
00197 for(int i = 0; i < (int)dpInputs.size(); ++i){
00198
00199 float ncProbability = FindPDFProbability(fPDFs[NCType::kNC][i],
00200 dpInputs[i]);
00201 float ccProbability = FindPDFProbability(fPDFs[NCType::kCC][i],
00202 dpInputs[i]);
00203
00204 if(ncProbability == 0.) ncProbability = 1e-4;
00205 if(ccProbability == 0.) ccProbability = 1e-4;
00206
00207 ncLikelihood *= ncProbability;
00208 ccLikelihood *= ccProbability;
00209 }
00210
00211
00212
00213 double probPID = TMath::Sqrt(-TMath::Log(ccLikelihood)) -
00214 TMath::Sqrt(-TMath::Log(ncLikelihood));
00215 probPID *= -1.;
00216
00217 const float cc_cut = det == Detector::kNear ? -0.1 : -0.2;
00218
00219 int tracks = evtInfo.event->tracks;
00220
00221 bool passesCCCuts = probPID > cc_cut && tracks > 0;
00222
00223
00224 if(det == Detector::kNear)
00225 passesCCCuts = passesCCCuts && PassesTrackReclamation(evtInfo);
00226
00227 return passesCCCuts;
00228 }
00229
00230
00231 bool NCExtractionCuts::PassesTrackReclamation(NCEventInfo& evtInfo)
00232 {
00233 return evtInfo.track->passedFit>0 ||
00234 (TMath::Abs(evtInfo.track->begPlaneU - evtInfo.track->begPlaneV) < 6
00235 && TMath::Abs(evtInfo.track->endPlaneU - evtInfo.track->endPlaneV) < 41
00236 && evtInfo.track->endPlane < 270);
00237 }
00238
00239
00240 void NCExtractionCuts::FillAnalysisInfo(NCEventInfo& evtInfo, int beamType)
00241 {
00242
00243 if(!fPDFsFilled) ReadPDFs(evtInfo);
00244
00245 ANtpAnalysisInfo* ana=evtInfo.analysis;
00246
00247 double separationCut=GetCutPosition();
00248
00249 ana->Reset();
00250
00251 ana->separationParameterCut = separationCut;
00252 ana->separationParameter = GetIdProbability(evtInfo, beamType);
00253
00254
00255 ana->isNC = PassesNCCuts(evtInfo);
00256
00257 ana->isCC = (!ana->isNC) && PassesCCCuts(evtInfo);
00258
00259 if(ana->isCC) {
00260 ana->pass = (int)( evtInfo.reco->trackMomentum <= 0 &&
00261 fCuts->IsGoodBeamEvent() &&
00262 fCuts->InBeamFiducialVolume() );
00263 } else if(ana->isNC) {
00264 ana->pass = (int)fCuts->InBeamFiducialVolume();
00265 }
00266 else ana->pass=0;
00267 }
00268
00269
00270 TString NCExtractionCuts::WhichCCPIDFiles(Detector::Detector_t detType,
00271 ReleaseType::Release_t mcType,
00272 BeamType::BeamType_t beamType)
00273 {
00274
00275 if(ReleaseType::IsDogwood(mcType)){
00276 MAXMSG("NCExtractionCuts", Msg::kError,5) << endl
00277 << "****************************************************" << endl
00278 << "* USING CEDAR CC PID FILES ON DOGWOOD. FIX THIS *" << endl
00279 << "* BEFORE DOING A REAL ANALYSIS *" << endl
00280 << "****************************************************" << endl;
00281 }
00282
00283 assert(mcType != ReleaseType::kUnknown);
00284
00285 assert(!ReleaseType::IsCarrot(mcType));
00286
00287 if(detType == Detector::kFar) {
00288 if(ReleaseType::IsDaikon(mcType)) {
00289 switch (beamType){
00290 case BeamType::kL010z185i:
00291 case BeamType::kL010z185i_i124:
00292 case BeamType::kL010z185i_i191:
00293 case BeamType::kL010z185i_i213:
00294 case BeamType::kL010z185i_i224:
00295 case BeamType::kL010z185i_i232:
00296 case BeamType::kL010z185i_i243:
00297 case BeamType::kL010z185i_i257:
00298 case BeamType::kL010z185i_i282:
00299 case BeamType::kL010z185i_i303:
00300 case BeamType::kL010z185i_i324:
00301 case BeamType::kUnknown:
00302 return "dp_pdf_far_le_cedar_daikon.root";
00303 default:
00304 return "";
00305 }
00306 }
00307 return "";
00308 }
00309
00310 if(detType == Detector::kNear){
00311 if(ReleaseType::IsDaikon(mcType)){
00312 switch (beamType){
00313 case BeamType::kL000z200i:
00314 case BeamType::kL010z185i:
00315 case BeamType::kL010z185i_i124:
00316 case BeamType::kL010z185i_i191:
00317 case BeamType::kL010z185i_i213:
00318 case BeamType::kL010z185i_i224:
00319 case BeamType::kL010z185i_i232:
00320 case BeamType::kL010z185i_i243:
00321 case BeamType::kL010z185i_i257:
00322 case BeamType::kL010z185i_i282:
00323 case BeamType::kL010z185i_i303:
00324 case BeamType::kL010z185i_i324:
00325 case BeamType::kL050z200i:
00326 case BeamType::kL200z200i:
00327 case BeamType::kL010z000i:
00328 case BeamType::kL010z170i:
00329 case BeamType::kL010z200i:
00330 case BeamType::kL010z185i_lowintensity:
00331 case BeamType::kUnknown:
00332 return "dp_pdf_near_L010z185i_cedar_daikon.root";
00333
00334 case BeamType::kL100z200i:
00335 return "dp_pdf_near_L100z200i_cedar_daikon.root";
00336
00337 case BeamType::kL250z200i:
00338 return "dp_pdf_near_L250z200i_cedar_daikon.root";
00339
00340 case BeamType::kL150z200i:
00341 return "dp_pdf_near_L150z200i_cedar_daikon.root";
00342
00343 default:
00344 return "";
00345 }
00346 }
00347 return "";
00348 }
00349
00350 return "";
00351 }