00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00015 #include "NueAna/NueUtilities.h"
00016
00017 #include "MessageService/MsgService.h"
00018
00019 CVSID("");
00020
00021 TChain* NueUtilities::CreateChain(std::string treeName,std::string fileListName)
00022 {
00023 TChain *chain= new TChain(treeName.c_str());
00024 ifstream fileList(fileListName.c_str());
00025 if( fileList )
00026 {
00027 while( fileList.good() && !fileList.eof() )
00028 {
00029 std::string line;
00030 getline(fileList,line,'\n');
00031 if ( line.size()==0 ) continue;
00032 chain->Add(line.c_str());
00033 }
00034 }
00035 return chain;
00036 }
00037
00038
00039 Double_t NueUtilities::GetChainPOT(TChain *chain)
00040 {
00041 NuePOT *nuepot = NULL;
00042 chain->SetBranchAddress("NuePOT",&nuepot);
00043
00044 Double_t pot = 0;
00045 for( int i = 0; i<chain->GetEntries(); ++i )
00046 {
00047 chain->GetEntry(i);
00048 pot += nuepot->pot;
00049 }
00050 chain->ResetBranchAddresses();
00051
00052 return(pot);
00053 }
00054
00055
00056 NueUtilities::AnaNueProcessor::AnaNueProcessor()
00057 {
00058 filelist = "";
00059 ana_nue_chain = NULL;
00060 pottree_chain = NULL;
00061
00062 totalPOTNotFilled=true;
00063
00064 nueRecord = NULL;
00065 numEntries = 0;
00066 currentEntry = -1;
00067 lastfraction = -1;
00068
00069 ProcessedMC = false;
00070 ProcessedData = false;
00071 ProcessedFar = false;
00072 ProcessedNear = false;
00073 ProcessedNC = false;
00074 ProcessedCC = false;
00075 ProcessedBeamNue = false;
00076 ProcessedTau = false;
00077 ProcessedSignal = false;
00078 ProcessedRun1 = false;
00079 ProcessedRun2 = false;
00080 ProcessedRun3 = false;
00081 }
00082
00083 NueUtilities::AnaNueProcessor::AnaNueProcessor(std::string fileListName)
00084 {
00085 filelist = fileListName;
00086 ana_nue_chain= NueUtilities::CreateChain("ana_nue",fileListName);
00087 pottree_chain= NueUtilities::CreateChain("pottree",fileListName);
00088
00089 totalPOTNotFilled=true;
00090
00091 nueRecord = NULL;
00092 ana_nue_chain->SetBranchAddress("NueRecord",&nueRecord);
00093
00094 numEntries = ana_nue_chain->GetEntries();
00095 currentEntry = -1;
00096 lastfraction = -1;
00097
00098 ProcessedMC = false;
00099 ProcessedData = false;
00100 ProcessedFar = false;
00101 ProcessedNear = false;
00102 ProcessedNC = false;
00103 ProcessedCC = false;
00104 ProcessedBeamNue = false;
00105 ProcessedTau = false;
00106 ProcessedSignal = false;
00107 ProcessedRun1 = false;
00108 ProcessedRun2 = false;
00109 ProcessedRun3 = false;
00110 }
00111
00112
00113
00114 NueUtilities::AnaNueProcessor::AnaNueProcessor(const NueUtilities::AnaNueProcessor &original)
00115 {
00116 *this = original;
00117 }
00118
00119 NueUtilities::AnaNueProcessor & NueUtilities::AnaNueProcessor::operator=(const NueUtilities::AnaNueProcessor &original)
00120 {
00121
00122 if (this != &original)
00123 {
00124 filelist = original.GetFileListName();
00125
00126 ana_nue_chain= NueUtilities::CreateChain("ana_nue",filelist);
00127 pottree_chain= NueUtilities::CreateChain("pottree",filelist);
00128
00129 totalPOTNotFilled=true;
00130
00131 nueRecord = NULL;
00132 ana_nue_chain->SetBranchAddress("NueRecord",&nueRecord);
00133
00134 ProcessedMC = original.didMC();
00135 ProcessedData = original.didData();
00136 ProcessedFar = original.didFar();
00137 ProcessedNear = original.didNear();
00138 ProcessedNC = original.didNC();
00139 ProcessedCC = original.didCC();
00140 ProcessedBeamNue = original.didBeamNue();
00141 ProcessedTau = original.didTau();
00142 ProcessedSignal = original.didSignal();
00143 ProcessedRun1 = original.didRun1();
00144 ProcessedRun2 = original.didRun2();
00145 ProcessedRun3 = original.didRun3();
00146
00147 numEntries = ana_nue_chain->GetEntries();
00148 lastfraction = original.GetLastFraction();
00149
00150 this->SetEntry(original.CurrentEntry());
00151 }
00152 return *this;
00153
00154 }
00155
00156
00157
00158 NueUtilities::AnaNueProcessor::~AnaNueProcessor()
00159 {
00160 delete ana_nue_chain;
00161 delete pottree_chain;
00162
00163 }
00164
00165 Double_t NueUtilities::AnaNueProcessor::GetTotalPOT()
00166 {
00167 if(totalPOTNotFilled)
00168 {
00169 totalPOT = NueUtilities::GetChainPOT(pottree_chain);
00170 totalPOTNotFilled = false;
00171 }
00172 return (totalPOT);
00173
00174 }
00175
00176 Bool_t NueUtilities::AnaNueProcessor::NextEntry()
00177 {
00178 ++currentEntry;
00179 return (SetEntry(currentEntry));
00180 }
00181
00182 Bool_t NueUtilities::AnaNueProcessor::SetEntry(Long64_t entry)
00183 {
00184 currentEntry = entry;
00185 if(currentEntry <0 || currentEntry >= numEntries)
00186 {
00187 nueRecord= NULL;
00188 return(false);
00189 }
00190 ana_nue_chain->GetEntry(currentEntry);
00191 ProcessedMC |= isMC();
00192 ProcessedData |= isData();
00193 ProcessedFar |= isFar();
00194 ProcessedNear |= isNear();
00195 ProcessedNC |= isNC();
00196 ProcessedCC |= isCC();
00197 ProcessedBeamNue |= isBeamNue();
00198 ProcessedTau |= isTau();
00199 ProcessedSignal |= isSignal();
00200 ProcessedRun1 |= isRun1();
00201 ProcessedRun2 |= isRun2();
00202 ProcessedRun3 |= isRun3();
00203
00204
00205
00206
00207
00208
00209
00210 return(true);
00211
00212 }
00213
00214 void NueUtilities::AnaNueProcessor::PrintProgress(unsigned int percentInterval)
00215 {
00216 Int_t fraction = (100*currentEntry)/numEntries;
00217
00218 if ( (fraction-lastfraction) >= (Int_t)percentInterval )
00219 {
00220 std::cout<<"\n"<<fraction<<"% done"<<std::endl;
00221 lastfraction = fraction;
00222 }
00223
00224 if( currentEntry == (numEntries-1) )
00225 {
00226 std::cout<<"\nOn last entry"<<std::endl;
00227 lastfraction = fraction;
00228 }
00229 }
00230
00231 void NueUtilities::AnaNueProcessor::PrintFileNames()
00232 {
00233 Long64_t num = 0;
00234 std::cout << "\nProcessing the following files:";
00235 ifstream fileList(filelist.c_str());
00236 if( fileList )
00237 {
00238 while( fileList.good() && !fileList.eof() )
00239 {
00240 std::string line;
00241 getline(fileList,line,'\n');
00242 if ( line.size()==0 ) continue;
00243 std::cout << "\n " << line;
00244 ++num;
00245 }
00246 }
00247 std::cout << "\nTotal number of files = " << num << endl;
00248 }
00249
00250
00251 Bool_t NueUtilities::AnaNueProcessor::isMC()
00252 {
00253 return(nueRecord->GetHeader().GetVldContext().GetSimFlag() == SimFlag::kMC);
00254 }
00255
00256 Bool_t NueUtilities::AnaNueProcessor::isData()
00257 {
00258 return(nueRecord->GetHeader().GetVldContext().GetSimFlag() == SimFlag::kData);
00259 }
00260
00261 Bool_t NueUtilities::AnaNueProcessor::isFar()
00262 {
00263 return(nueRecord->GetHeader().GetVldContext().GetDetector() == Detector::kFar);
00264 }
00265
00266 Bool_t NueUtilities::AnaNueProcessor::isNear()
00267 {
00268 return(nueRecord->GetHeader().GetVldContext().GetDetector() == Detector::kNear);
00269 }
00270
00271 Bool_t NueUtilities::AnaNueProcessor::isNC()
00272 {
00273 return(isMC() && nueRecord->mctrue.interactionType==0);
00274 }
00275
00276 Bool_t NueUtilities::AnaNueProcessor::isCC()
00277 {
00278 return(isMC() && !isNC() && abs(nueRecord->mctrue.nuFlavor)==14);
00279 }
00280
00281 Bool_t NueUtilities::AnaNueProcessor::isBeamNue()
00282 {
00283 return(isMC() && !isNC() && abs(nueRecord->mctrue.nuFlavor)==12 && abs(nueRecord->mctrue.nonOscNuFlavor)==12);
00284 }
00285
00286 Bool_t NueUtilities::AnaNueProcessor::isTau()
00287 {
00288 return(isMC() && !isNC() && abs(nueRecord->mctrue.nuFlavor)==16);
00289 }
00290
00291 Bool_t NueUtilities::AnaNueProcessor::isSignal()
00292 {
00293 return( isMC() && !isNC() && abs(nueRecord->mctrue.nuFlavor)==12 && abs(nueRecord->mctrue.nonOscNuFlavor)==14 );
00294 }
00295
00296 Bool_t NueUtilities::AnaNueProcessor::isRun1()
00297 {
00298 return( NueStandard::IsRun1(nueRecord) );
00299 }
00300
00301 Bool_t NueUtilities::AnaNueProcessor::isRun2()
00302 {
00303 return( NueStandard::IsRun2(nueRecord) );
00304 }
00305
00306 Bool_t NueUtilities::AnaNueProcessor::isRun3()
00307 {
00308 return( NueStandard::IsRun3(nueRecord) );
00309 }
00310
00311 Double_t NueUtilities::AnaNueProcessor::Normalization_RunSeparatedSample()
00312 {
00313
00314 Double_t eventWeight =1;
00315 if(isNear())
00316 {
00317
00318 eventWeight = NueStandard::kNormalizedNearPOT/GetTotalPOT();
00319 }
00320 else if(isMC())
00321 {
00322
00323
00324 if( NueStandard::IsRun1(nueRecord) ) eventWeight = NueStandard::kNormalizedFarPOT_Run1/GetTotalPOT();
00325 else if( NueStandard::IsRun2(nueRecord) ) eventWeight = NueStandard::kNormalizedFarPOT_Run2/GetTotalPOT();
00326 else if( NueStandard::IsRun3(nueRecord) ) eventWeight = NueStandard::kNormalizedFarPOT_Run3/GetTotalPOT();
00327 }
00328
00329 return(eventWeight);
00330 }
00331
00332 Double_t NueUtilities::AnaNueProcessor::Normalization_MixedRunSample()
00333 {
00334
00335 Double_t eventWeight = 1;
00336 if(isNear())
00337 {
00338
00339 eventWeight = NueStandard::kNormalizedNearPOT/GetTotalPOT();
00340 }
00341 else if(isMC())
00342 {
00343
00344
00345 eventWeight = NueStandard::kNormalizedFarPOT/GetTotalPOT();
00346 }
00347
00348 return(eventWeight);
00349 }
00350
00351 Double_t NueUtilities::AnaNueProcessor::GetOscWeight_f210f213f214Separate()
00352 {
00353
00354
00355 Double_t eventWeight =1;
00356
00357 if( isMC() && isFar() && !isNC() )
00358 {
00359 eventWeight = NueStandard::GetOscWeight(nueRecord->mctrue.nuFlavor, nueRecord->mctrue.nonOscNuFlavor, nueRecord->mctrue.nuEnergy);
00360 }
00361
00362 return(eventWeight);
00363 }
00364
00365
00366 Double_t NueUtilities::AnaNueProcessor::GetOldANN11()
00367 {
00368 return( NueStandard::GetPIDValue(nueRecord, Selection::kANN2PE) );
00369 }
00370
00371 Double_t NueUtilities::AnaNueProcessor::GetANN11()
00372 {
00373 return( NueStandard::GetPIDValue(nueRecord, Selection::kANN2PE_DAIKON04) );
00374 }
00375
00376 Double_t NueUtilities::AnaNueProcessor::GetANN14()
00377 {
00378 return( NueStandard::GetPIDValue(nueRecord, Selection::kANN14_DAIKON04) );
00379 }
00380
00381 Double_t NueUtilities::AnaNueProcessor::GetSSPID()
00382 {
00383 return( NueStandard::GetPIDValue(nueRecord, Selection::kSSPID) );
00384 }
00385
00386 Double_t NueUtilities::AnaNueProcessor::GetParticlePID()
00387 {
00388 return( NueStandard::GetPIDValue(nueRecord, Selection::kParticlePID) );
00389 }
00390
00391 Double_t NueUtilities::AnaNueProcessor::GetRecoE()
00392 {
00393 return(nueRecord->srevent.phNueGeV);
00394 }
00395
00396
00397 Double_t NueUtilities::AnaNueProcessor::GetTruncatedOldANN11()
00398 {
00399 Double_t truncatedPID = GetOldANN11();
00400 if( truncatedPID < -0.049)
00401 {
00402 truncatedPID = -0.049;
00403 }
00404 else if(truncatedPID > 0.99)
00405 {
00406 truncatedPID = 0.99;
00407 }
00408 return(truncatedPID);
00409 }
00410
00411 Double_t NueUtilities::AnaNueProcessor::GetTruncatedANN11()
00412 {
00413 Double_t truncatedPID = GetANN11();
00414 if( truncatedPID < -0.049)
00415 {
00416 truncatedPID = -0.049;
00417 }
00418 else if(truncatedPID > 0.99)
00419 {
00420 truncatedPID = 0.99;
00421 }
00422 return(truncatedPID);
00423 }
00424
00425 Double_t NueUtilities::AnaNueProcessor::GetTruncatedANN14()
00426 {
00427 Double_t truncatedPID = GetANN14();
00428 if( truncatedPID < -0.049)
00429 {
00430 truncatedPID = -0.049;
00431 }
00432 else if(truncatedPID > 0.99)
00433 {
00434 truncatedPID = 0.99;
00435 }
00436 return(truncatedPID);
00437 }
00438
00439 Double_t NueUtilities::AnaNueProcessor::GetTruncatedSSPID()
00440 {
00441 Double_t truncatedPID = GetSSPID();
00442 if( truncatedPID < -0.049)
00443 {
00444 truncatedPID = -0.049;
00445 }
00446 else if(truncatedPID > 0.99)
00447 {
00448 truncatedPID = 0.99;
00449 }
00450 return(truncatedPID);
00451 }
00452
00453 Double_t NueUtilities::AnaNueProcessor::GetTruncatedParticlePID()
00454 {
00455 Double_t truncatedPID = GetParticlePID();
00456 if( truncatedPID < -0.049)
00457 {
00458 truncatedPID = -0.049;
00459 }
00460 else if(truncatedPID > 0.99)
00461 {
00462 truncatedPID = 0.99;
00463 }
00464 return(truncatedPID);
00465 }
00466
00467