00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014 #include "NueConvention.h"
00015 #include "AnalysisNtuples/ANtpDefaultValue.h"
00016
00017 #include "TMath.h"
00018 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00019 #include "NueAna/ANtpTruthInfoBeamNue.h"
00020 #include "MCNtuple/NtpMCTruth.h"
00021 #include "NueAna/NueRecord.h"
00022
00023 #include "MessageService/MsgService.h"
00024
00025
00026
00027 CVSID("");
00028
00029 Int_t NueConvention::DetermineClassType(Int_t inu, Int_t inunoosc, Int_t iaction)
00030 {
00031 int cType=ANtpDefVal::kInt;
00032
00033 if(iaction ==0){ cType= ClassType::NC;
00034 }
00035 else if(iaction >=1){
00036 if(inu ==14 || inu==-14){
00037 cType=ClassType::numu;
00038 }
00039 else
00040 if(inu==12 || inu==-12){
00041 if(inunoosc==14 || inunoosc==-14){
00042 cType=ClassType::nue;
00043 }
00044 else if(inunoosc==12 || inunoosc==-12){
00045 cType=ClassType::bnue;
00046 }
00047 }
00048 else if(inu==16 || inu==-16){
00049 cType= ClassType::nutau;
00050 }
00051 }
00052
00053 return cType;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 float NueConvention::Oscillate(NtpMCTruth *mcth,
00063 float L, float dm2, float theta23, float UE32)
00064 {
00065 return NueConvention::Oscillate(mcth->inu, mcth->inunoosc, mcth->p4neu[3],
00066 L, dm2, theta23, UE32);
00067 }
00068
00069 float NueConvention::Oscillate(ANtpTruthInfoBeam *ib,
00070 float L, float dm2, float theta23, float UE32)
00071 {
00072 return NueConvention::Oscillate(ib->nuFlavor, ib->nonOscNuFlavor,ib->nuEnergy,
00073 L, dm2, theta23, UE32);
00074 }
00075
00076 float NueConvention::Oscillate(ANtpTruthInfoBeamNue *ib)
00077 {
00078 return NueConvention::Oscillate(ib->nuFlavor, ib->nonOscNuFlavor,ib->nuEnergy, ib->Baseline, ib->DeltamSquared23,
00079 ib->Theta23, ib->Ue3Squared);
00080 }
00081
00082
00083 float NueConvention::Oscillate(int nuFlavor, int nonOscNuFlavor, float Energy,
00084 float L, float dm2, float theta23, float UE32)
00085 {
00086 float oscterm = TMath::Sin(1.269*dm2*L/Energy);
00087
00088
00089
00090
00091 float pmt=pow((1-UE32)*oscterm*TMath::Sin(2*theta23),2);
00092 float pme=pow(TMath::Sin(theta23),2)*4.*UE32*(1-UE32)*pow(oscterm,2);
00093 float pmm=1.-pmt-pme;
00094
00095 float pet=4*(1-UE32)*UE32*pow(TMath::Cos(theta23)*oscterm,2);
00096 float pem=pow(TMath::Sin(theta23),2)*4.*UE32*(1-UE32)*pow(oscterm,2);
00097 float pee=1.-pet-pem;
00098
00099
00100 if(abs(nonOscNuFlavor)==14){
00101 if(abs(nuFlavor)==12){
00102 return pme;
00103 }
00104 else if(abs(nuFlavor)==14){
00105 return pmm;
00106 }
00107 else if(abs(nuFlavor)==16){
00108 return pmt;
00109 }
00110 }
00111 else if(abs(nonOscNuFlavor)==12){
00112 if(abs(nuFlavor)==12){
00113 return pee;
00114 }
00115 else if(abs(nuFlavor)==14){
00116 return pem;
00117 }
00118 else if(abs(nuFlavor)==16){
00119 return pet;
00120 }
00121 }
00122 else{
00123 std::cout<<"I don't know what to do with "<<nonOscNuFlavor
00124 <<" "<<nuFlavor<<" "<<pee<<std::endl;
00125 }
00126 return 0.;
00127 }
00128
00129
00130
00131
00132
00133 int NueConvention::IsInsideNearFiducial_Nue_Extended(float x, float y, float z)
00134 {
00135 Float_t SuperModule1Beg = 0.50;
00136 Float_t SuperModule1End = 6.50;
00137
00138 Float_t radialInner = 0;
00139 Float_t radialOuter = 1;
00140 Float_t xCenter = 1.4885;
00141 Float_t yCenter = 0.1397;
00142 Bool_t zContained = false;
00143 Bool_t xyContained = false;
00144 Float_t r = TMath::Sqrt((x-xCenter)*(x-xCenter) + (y-yCenter)*(y-yCenter));
00145 if( z >= SuperModule1Beg && z <=SuperModule1End)
00146 zContained = true;
00147 if( r >= radialInner && r <= radialOuter)
00148 xyContained = true;
00149
00150 Int_t retVal = 0;
00151 if(zContained && xyContained) retVal = 1;
00152 if(!zContained) retVal = -1;
00153 if(!xyContained) retVal -= 2;
00154 return retVal;
00155 }
00156
00157
00158 int NueConvention::IsInsideFarFiducial_Nue_Extended(float x, float y, float z)
00159 {
00160 Float_t SuperModule1Beg = 0.35;
00161 Float_t SuperModule2Beg = 16.20;
00162 Float_t SuperModule1End = 14.57;
00163 Float_t SuperModule2End = 29.62;
00164
00165 Float_t radialInner = 0.40;
00166 Float_t radialOuter = 3.87;
00167 Bool_t zContained = false;
00168 Bool_t xyContained = false;
00169 Float_t r = TMath::Sqrt(x*x + y*y);
00170
00171 if( (z >= SuperModule1Beg && z <=SuperModule1End) ||
00172 (z >= SuperModule2Beg && z <=SuperModule2End) )
00173 zContained = true;
00174
00175 if( r >= radialInner && r <= radialOuter)
00176 xyContained = true;
00177
00178 Int_t retVal = 0;
00179 if(zContained && xyContained) retVal = 1;
00180 if(!zContained) retVal = -1;
00181 if(!xyContained) retVal -= 2;
00182
00183 return retVal;
00184
00185 }
00186
00187 int NueConvention::IsInsideNearFiducial_Nue_Standard(float x, float y, float z, bool )
00188 {
00189 Float_t SuperModule1Beg = 1.01080;
00190 Float_t SuperModule1End = 4.99059;
00191
00192 Float_t radialInner = 0;
00193 Float_t radialOuter = 0.8;
00194 Float_t xCenter = 1.4885;
00195 Float_t yCenter = 0.1397;
00196
00197 Bool_t zContained = false;
00198 Bool_t xyContained = false;
00199
00200 Float_t r = TMath::Sqrt((x-xCenter)*(x-xCenter) + (y-yCenter)*(y-yCenter));
00201
00202 if( z >= SuperModule1Beg && z <=SuperModule1End)
00203 zContained = true;
00204 if( r >= radialInner && r <= radialOuter)
00205 xyContained = true;
00206
00207 Int_t retVal = 0;
00208 if(zContained && xyContained) retVal = 1;
00209 if(!zContained) retVal = -1;
00210 if(!xyContained) retVal -= 2;
00211
00212 return retVal;
00213 }
00214
00215 int NueConvention::IsInsideFarFiducial_Nue_Standard(float x, float y, float z, bool isMC){
00216
00217 Float_t SuperModule1Beg = 0.49080;
00218 Float_t SuperModule2Beg = 16.27110;
00219 Float_t SuperModule1End = 14.29300;
00220 Float_t SuperModule2End = 27.98270;
00221
00222 if(isMC){
00223 SuperModule1Beg = 0.47692;
00224 SuperModule2Beg = 16.26470;
00225 SuperModule1End = 14.27860;
00226 SuperModule2End = 27.97240;
00227 }
00228
00229 Float_t radialInner = 0.50;
00230 Float_t radialOuter = TMath::Sqrt(14.0);
00231 Bool_t zContained = false;
00232 Bool_t xyContained = false;
00233
00234 Float_t r = TMath::Sqrt(x*x + y*y);
00235
00236 if( (z >= SuperModule1Beg && z <=SuperModule1End) ||
00237 (z >= SuperModule2Beg && z <=SuperModule2End) )
00238 zContained = true;
00239
00240 if( r >= radialInner && r <= radialOuter)
00241 xyContained = true;
00242
00243 Int_t retVal = 0;
00244 if(zContained && xyContained) retVal = 1;
00245 if(!zContained) retVal = -1;
00246 if(!xyContained) retVal -= 2;
00247
00248 return retVal;
00249
00250 }
00251
00252 int NueConvention::IsInsideNearFiducial_MRE_Standard(float x, float y, float z,
00253 bool )
00254 {
00255 Float_t SuperModule1Beg = 0.5;
00256
00257 Float_t SuperModule1End = 5.5;
00258
00259 Float_t radialInner = 0;
00260 Float_t radialOuter = 1.2;
00261 Float_t xCenter = 1.4885;
00262 Float_t yCenter = 0.1397;
00263
00264 Bool_t zContained = false;
00265 Bool_t xyContained = false;
00266
00267 Float_t r = TMath::Sqrt((x-xCenter)*(x-xCenter) + (y-yCenter)*(y-yCenter));
00268
00269 if( z >= SuperModule1Beg && z <=SuperModule1End)
00270 zContained = true;
00271 if( r >= radialInner && r <= radialOuter)
00272 xyContained = true;
00273
00274
00275 Int_t retVal = 0;
00276 if(zContained && xyContained) retVal = 1;
00277 if(!zContained) retVal = -1;
00278 if(!xyContained) retVal -= 2;
00279
00280 return retVal;
00281 }
00282
00283
00284
00285
00286
00287 Int_t NueConvention::InPartialRegion(UShort_t plane, UShort_t strip){
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 static bool first=true;
00306 static UShort_t ptype[282];
00307 if(first){
00308 ptype[0]=0;
00309 for(int i=1; i<=281; i++){
00310 if(i%2==0) ptype[i]=1;
00311 else ptype[i]=2;
00312 if((i-1)%5 == 0) ptype[i]+=2;
00313 else if(i>120) ptype[i]=0;
00314 }
00315 first=false;
00316 }
00317 if(plane>281){
00318
00319 return 0;
00320 }
00321 UShort_t pt = ptype[plane];
00322
00323 Int_t result;
00324 switch(pt){
00325 case 1:
00326 case 3:
00327 if(strip<=4 || strip>=67) result=1;
00328 else result = -1;
00329 break;
00330 case 2:
00331 if(strip==0 || strip == 63) result=1;
00332 else result = -1;
00333 break;
00334 case 4:
00335 if(strip<=26 || strip>=88) result=1;
00336 else result = -1;
00337 break;
00338 case 0:
00339 default:
00340 result=0;
00341 break;
00342 }
00343 return result;
00344
00345 }
00346
00347
00348
00349
00350
00351
00352
00353 void NueConvention::NueEnergyCorrection(NueRecord* nr, bool isLinearityFixMC)
00354 {
00355
00356
00357 int release = nr->GetHeader().GetRelease();
00358 int detector = nr->GetHeader().GetVldContext().GetDetector();
00359 bool isMC = (nr->GetHeader().GetVldContext().GetSimFlag()==SimFlag::kMC);
00360
00361 try
00362 {
00363 if(nr->srevent.phMeu>-9999)nr->srevent.phNueGeV=NueConvention::NueEnergyCorrection(nr->srevent.phMeu,release,isMC,detector, isLinearityFixMC);
00364 if(nr->srshower.phMeu>-9999)nr->srshower.phNueGeV=NueConvention::NueEnergyCorrection(nr->srshower.phMeu,release,isMC,detector, isLinearityFixMC);
00365 if(nr->srtrack.phMeu>-9999)nr->srtrack.phNueGeV=NueConvention::NueEnergyCorrection(nr->srtrack.phMeu,release,isMC,detector, isLinearityFixMC);
00366
00367 }
00368 catch (int e)
00369 {
00370 MSG("NueConvention",Msg::kError)<<"NueEnergyCorrection - attempted to correct energy for unknown specification "<<release<<endl;
00371 }
00372
00373 }
00374
00375
00376
00377 float NueConvention::NueEnergyCorrection(float meu, int type, bool isMC, int detector=2, bool isLinearityFixMC = false)
00378 {
00379
00380
00381
00382
00383 if(ReleaseType::IsCedar(type)&&ReleaseType::IsCarrot(type))
00384 {
00385 float offset = -1.52;
00386 float slope = 25.06;
00387 return (meu-offset)/slope;
00388 }
00389
00390
00391
00392
00393 else if(ReleaseType::IsCedar(type)&&(ReleaseType::IsDaikon(type)||ReleaseType::IsData(type))&&(ReleaseType::GetRecoSubVersion(type)==0 || ReleaseType::GetRecoSubVersion(type)==1 ) )
00394 {
00395 float offset = -1.515;
00396 float slope = 24.86;
00397 return (meu-offset)/slope;
00398 }
00399
00400
00401
00402
00403 else if(ReleaseType::IsCedar(type)&&(ReleaseType::IsDaikon(type)||ReleaseType::IsData(type))&&(ReleaseType::GetRecoSubVersion(type)==2 || ReleaseType::GetRecoSubVersion(type)==3))
00404 {
00405 if(isMC)
00406 {
00407 if(isLinearityFixMC)
00408 {
00409
00410 if(detector==2)
00411 {
00412 float offset = -1.17129;
00413 float slope = 24.2273;
00414 return (meu-offset)/slope;
00415 }
00416 else if(detector==1)
00417 {
00418 float offset = -0.820177;
00419 float slope = 23.7963;
00420 return (meu-offset)/slope;
00421 }
00422 }
00423 else
00424 {
00425
00426
00427
00428
00429 if(detector==2)
00430 {
00431
00432 float offset = -1.29686;
00433 float slope = 24.3332;
00434 return (meu-offset)/slope;
00435 }
00436 else if(detector==1)
00437 {
00438
00439 float offset = -2.8176;
00440 float slope = 25.7362;
00441 return (meu-offset)/slope;
00442 }
00443 }
00444 }
00445 else
00446 {
00447
00448
00449
00450 if(detector==2)
00451 {
00452
00453 float offset = -1.17129*(0.9978/0.9988);
00454 float slope = 24.2273*(0.9978/0.9988);
00455 return (meu-offset)/slope;
00456 }
00457 else if(detector==1)
00458 {
00459
00460 float offset = -1.17129*(0.9978/1.0039);
00461 float slope = 24.2273*(0.9978/1.0039);
00462 return (meu-offset)/slope;
00463 }
00464 }
00465 }
00466
00467
00468
00469
00470 else if(ReleaseType::IsDogwood(type)&& (ReleaseType::IsDaikon(type)||ReleaseType::IsData(type)))
00471 {
00472
00473
00474
00475
00476 if(detector==2)
00477 {
00478 float offset_mip = -2.483;
00479 float slope_MipPerGev = 23.56;
00480 return (meu-offset_mip)/slope_MipPerGev;
00481 }
00482 else if(detector==1)
00483 {
00484 float offset_mip = -1.071;
00485 float slope_MipPerGev = 22.87;
00486 return (meu-offset_mip)/slope_MipPerGev;
00487 }
00488 }
00489
00490
00491 throw -1;
00492 return -1;
00493 }
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 void NueConvention::NueEnergyCorrectionNeverUseThisFunction(NueRecord* nr)
00504 {
00505
00506
00507 int release = nr->GetHeader().GetRelease();
00508 int detector = nr->GetHeader().GetVldContext().GetDetector();
00509 bool isMC = (nr->GetHeader().GetVldContext().GetSimFlag()==SimFlag::kMC);
00510
00511 try
00512 {
00513 if(nr->srevent.phMeu>-9999)nr->srevent.phNueGeV=NueConvention::NueEnergyCorrectionNeverUseThisFunction(nr->srevent.phMeu,release,isMC,detector);
00514 if(nr->srshower.phMeu>-9999)nr->srshower.phNueGeV=NueConvention::NueEnergyCorrectionNeverUseThisFunction(nr->srshower.phMeu,release,isMC,detector);
00515 if(nr->srtrack.phMeu>-9999)nr->srtrack.phNueGeV=NueConvention::NueEnergyCorrectionNeverUseThisFunction(nr->srtrack.phMeu,release,isMC,detector);
00516
00517 }
00518 catch (int e)
00519 {
00520 MSG("NueConvention",Msg::kError)<<"NueEnergyCorrectionNeverUseThisFunction - attempted to correct energy for unknown specification\n";
00521 }
00522
00523 }
00524
00525
00526
00527 float NueConvention::NueEnergyCorrectionNeverUseThisFunction(float meu, int type, bool isMC, int detector=2)
00528 {
00529 if(ReleaseType::IsCedar(type)&&(ReleaseType::IsDaikon(type)||ReleaseType::IsData(type))&&(ReleaseType::GetRecoSubVersion(type)==2 || ReleaseType::GetRecoSubVersion(type)==3))
00530 {
00531 if(isMC)
00532 {
00533
00534
00535 if(detector==2)
00536 {
00537 float offset = ( (-1.29686)+(-1.17129) )/2.0;
00538 float slope = ( (24.3332)+(24.2273) )/2.0;
00539 return (meu-offset)/slope;
00540 }
00541 else if(detector==1)
00542 {
00543 float offset = ( (-2.8176)+(-0.820177) )/2.0;
00544 float slope = ( (25.7362)+(23.7963) )/2.0;
00545 return (meu-offset)/slope;
00546 }
00547 }
00548 else
00549 {
00550
00551
00552
00553 if(detector==2)
00554 {
00555
00556 float offset = -1.17129*(0.9978/0.9988);
00557 float slope = 24.2273*(0.9978/0.9988);
00558 return (meu-offset)/slope;
00559 }
00560 else if(detector==1)
00561 {
00562
00563 float offset = -1.17129*(0.9978/1.0039);
00564 float slope = 24.2273*(0.9978/1.0039);
00565 return (meu-offset)/slope;
00566 }
00567 }
00568 }
00569
00570
00571
00572 throw -1;
00573 return -1;
00574 }
00575
00576
00577
00578
00579
00580
00581 bool operator>(FilePosition one, FilePosition two)
00582 {
00583 bool result = false;
00584 if(one.Run > two.Run) result = true;
00585 if(one.Run == two.Run && one.SubRun > two.SubRun) result = true;
00586 if(one.Run == two.Run && one.SubRun == two.SubRun && one.Snarl > two.Snarl) result = true;
00587 if(one.Run == two.Run && one.SubRun == two.SubRun && one.Snarl == two.Snarl &&
00588 one.Event > two.Event) result = true;
00589
00590
00591 return result;
00592 }
00593
00594
00595 bool operator<(FilePosition one, FilePosition two)
00596 {
00597 bool result = false;
00598 if(one.Run < two.Run) result = true;
00599 if(one.Run == two.Run && one.SubRun < two.SubRun) result = true;
00600 if(one.Run == two.Run && one.SubRun == two.SubRun && one.Snarl < two.Snarl) result = true;
00601 if(one.Run == two.Run && one.SubRun == two.SubRun && one.Snarl == two.Snarl &&
00602 one.Event < two.Event) result = true;
00603
00604
00605 return result;
00606 }
00607
00608 bool operator==(FilePosition one, FilePosition two)
00609 {
00610 bool result = false;
00611 if(one.Run == two.Run && one.SubRun == two.SubRun && one.Snarl == two.Snarl &&
00612 one.Event == two.Event) result = true;
00613
00614 return result;
00615 }
00616
00617
00618
00619