//23Mar24: dtPeaksHE? //15Dec23: TDB: a) does grAvg2 and grCPAvg2 increment pointers? //14Oct22: CAUTION: correlateAndAverage FAILS when there are saturated waveforms owing to transform into frequency domain for average //30Aug22: Use XC to determine phase shift b/w WB events for Surface Rx? //2Jul22: consolidate SwitchChannelOff //6Jul22: FillPowerSpectrum /*to get DDA and TDA temperatures: getDdaTemp() and getTdaTemp() are the decrypt function that you are looking for. They took the values from sensorHk[xxxxxx].root and convert into actual temperature (not sure what is the unit though..) that we are seeing from AWARE! (edited) AtriSensorHkData.cxx ara-software/AraRoot | Added by GitHub AtriSensorHkData.cxx ara-software/AraRoot | Added by GitHub */ //220316: Use gr->Eval() function when subtracting/adding two graphs so they don't have to have the same binning! /* ibini=grAvg->GetXaxis()->FindBin(tBEDi); ibinf=grAvg->GetXaxis()->FindBin(tBEDf); yValM\ ax=TMath::MaxElement(ibinf-ibini,&grAvg->GetY()[ibini]); yValMin=TMath::MinElement(ibinf-ibini,&grAvg->GetY()[ibini]); grAvg->GetYaxis()->SetRangeUser(yValMin,yValMax); http://www.hep.ucl.ac.uk/~strutt/BensAnita3AnalysisTools/da/da5/_root_tools_8cxx_source.html - TCanvas* RootTools::drawArrayOfHistosPrettily(TH1D* hs[], Int_t numHists, TCanvas* can, Double_t* colWeights){ */ //ElecChan 0,8,16,24=RFChan 0,1,2,3 / 1,9,17,25=4,5,6,7 //CAUTION: SimplePowerEnvelope will JACK UP X-VALUES!!! //http://ara.icecube.wisc.edu/wiki/index.php/Main_Page#Operations_and_Hardware gives listing of all 'non-standard' operations //void TGraph::ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax) //The FFTtools::getHilbertEnvelope(TGraph *grWave) function is very slow as compared to the FFTtools::getSimplePowerEnvelopeGraph(TGraph *gr) //TBD: fix LICLev for A4 / determine saturation point channel-by-channel for each channel of each station - can likely do this dynamically each run by updating a maximum voltage parameter //Add a flag at end of run after code has figured out which channels are bunk //Brian: local coordinates: ARA2 SP: phi = -106.94 ICL: phi = -94.84 WT3: phi = -84.85 / ARA3 SP: phi = -128.61 ICL: phi = -122.30 WT3: phi = -131.43 //fitting options: https://root.cern.ch/doc/master/classTH1.html#a63eb028df86bc86c8e20c989eb23fb2a //A1: BH1 TH/TV/BH/BV=(12,0)/(8,4) // BH2 (13,1)/(9,5) // BH3 (14,2)/(10,6) // BH4 (15,3)/(11,7) //6Apr19: Now using only local station coordinates //7mar19:Dropping chan 15 from A2 //Dropping all of string four from A3 in 2014-2016 //Exclude channels 3/7/11/15 for ARA-3 for 2014 and 2015? //8jan19: CAUTION: A2 Ch6 has +6 ns offset (see MYL and Uzair slides) //31dec18: look at HV 3-d histogram to see if there is offset b/w (0,8), (1,9), etc. also, flesh out FillTriggerBits //overlay H/V response to surface pulser - does H rise more slowly because of limited BW? //all surface sources should be simultaneous in H/V - use this to determine offset. Similarly, what is H/V offset in NEV0 for ievt9 events, as f(theta)? //for ievtype==9 or ievtype==10 cut on rms of czavg //ievtypes: -333: trigger only / -99: pass all events / -33:trigger only / -11: run from event list / -4: full ana, but do not use araroot cable delays / -3: NEVT0 only/no getgrinfo / -2: MC only / 1: CP only / 3: DP only / 4: ICL / 5: Surface Pulser //-99 = pass all events //-11=run from event list //-4=use kSecondCalib and circumvent cable delays //-3=no MC//-2=MC only //-1=all events //0=RF triggers with CP veto //1=CP evts ONLY //2=UB events only //3=DP events only //4=ICL rooftop events //5=Surface Pulser events from SP survey //6=spice core events //7=exclusively thermal events //8=spiceDec18 analysis=>HitTime=tSlope //9=neutrino cands from cz info OR air shower cands down //11=fast fft and exit only //31=trigger throttled //to identify dt in double pulses, do XC for first part vs. second part of wf and take time difference in correlationgraph - deltTwinPeaks should do this already!!! //for double pulses, use XC for channels at same depth //Why doesn't LDP addition work anymore? //iDP=0: IC1D exclusively / iDP=1: IC1S / iDP=2: IC22S /*25 Jun data: 20:36: hole 1 powered ON / 21:16: Hole 1 powered down / 21:16 Hole 22 powered up / Hole 22 (Shallow Pulser) /21:28:00 pulsing ON 21:43:00 pulsing OFF Hole 22 (Shallow Pulser) 22:03:00 pulsing ON 22:18:00 pulsing OFF 22:22:00 Hole 22 powered down 22:22:00 Hole 1 powered up Hole 1 (Shallow Pulser) 22:23:42 pulsing ON 22:53:42 pulsing OFF 22:59:00 Hole 1 powered down*/ /*on “arapp”: Started ARA pulsar at 2018-01-20 19:44:15.769436UTC 1516477478 Stopped ARA Pulsar at 2018-01-20 20:04:16.102986 UTC 1516478678 Started ARA pulsar at 2018-01-20 20:15:20.345174UTC 1516479320 Stopped ARA Pulsar at 2018-01-20 20:35:20.776375 UTC 1516480520 Started ARA pulsar at 2018-01-20 20:35:34.676877UTC 1516480534 Stopped ARA Pulsar at 2018-01-20 20:45:35.116832 UTC 1516481134 Started ARA pulsar at 2018-01-20 20:58:17.917574UTC 1516481897 Stopped ARA Pulsar at 2018-01-20 21:18:18.298838 UTC 1516483098 on “arapc”: Started ARA pulsar at 2018-01-20 21:21:17.481426UTC 1516483278 Stopped ARA Pulsar at 2018-01-20 21:28:40.167687 UTC 1516483720 Started ARA pulsar at 2018-01-20 21:28:45.418216UTC 1516483725 Stopped ARA Pulsar at 2018-01-20 21:32:23.836326 UTC 1516483943 */ //Brian: IC1S: 1516477466->1516480500 / IC22S: 1516482000->1516483134 / IC1D: 1516483200->1516483920 //SPICE core data from 8Jan18, starting at 15:30:00 NZDT, starts at 1515378600 utc (NZDT-13 hours=GMT) // //Note: RxXYZ0 is close to (0,0,0) for AraRoot geometry, in which case 0 degrees (+x-axis) aligns with local ice-flow //18may18: consolidate grMaxZ / FFTtools:getpeakbin / getPeakabsVal / getPeakValZ //17may18: Figure out why // thecog=Maptheta0180deg(thecog); line in GetPheTheHat sometimes goes kablooey... //12Apr18: Add cross-correlation to template? //AngleDegAz needs cos(theta) if it will work; instead, use consistency of (HitTime)/Distance for parallel faces - e.g. (ch1,ch2)==(ch3,ch4)==etc... //root -b 'Vtx.C(-2,0,7,64,2,-2013,"1001800901")' for LXMCX, e.g. //utility to do FFT of trigger times to see periodicities in data //TE that for a single TGraph *gr; if it exists, then if(gr) evaluates as true and !gr evaluates as 0. //HOWEVER, for a TGraph array TGraph *gr[2], then if gr[0] exists, then gr[1] also returns TRUE!!!!! // // less /home/dbesson/arasrc/AraEvent/RawAtriStationEvent.and /home/dbesson/arasrc/AraEvent/RawAtriStationEvent.h //https://root.cern.ch/doc/v608/tree2_8C.html shows how to store struct members in a TTree //Add ZxcZ.h to this code to do interferometric reconstruction //for integrating n(z) profiles, can define a TF1 *f1, then do f1->Integral(zmin,zmax) to get total time. //kWhite = 0, kBlack = 1, kGray = 920, kRed = 632, kGreen = 416, kBlue = 600, kYellow = 400, kMagenta = 616, kCyan = 432, kOrange = 800, kSpring = 820, kTeal = 840, kAzure = 860, kViolet = 880, kPink = 900 //gr->GetMaximum() is in bins, no? #include #include //#include "FFTtools.h" using namespace std; #include //AraRoot Includes //#include "RawIcrrStationEvent.h" #include "RawAtriStationEvent.h" #include "UsefulAraStationEvent.h" #include "UsefulIcrrStationEvent.h" #include "UsefulAtriStationEvent.h" #define KNRM "\x1B[0m" #define KRED "\x1B[31m" #define KGRN "\x1B[32m" #define KYEL "\x1B[33m" #define KBLU "\x1B[34m" #define KMAG "\x1B[35m" #define KCYN "\x1B[36m" #define KWHT "\x1B[37m" #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ #define BOLDRED "\033[1m\033[31m" /* Bold Red */ #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ const Int_t CLOCK_TICKS_PER_SEC=1000000; //SHOULD BE IN HEADER, BUT ISN'T! const Int_t nHitsgr00DP=6; const Int_t MAXCPWFCOMP=128; const Int_t MBINSIGCP=64; const Int_t MWFLENMIN=400; //600; //minimum waveform to average const Float_t f0WB400MHz=404; const Float_t dfWB400MHz=6; const Float_t MAXDTRESID=64; const Float_t MINVWINDHIVWIND=12; const Float_t MAXVWINDLOVWIND=5; const Float_t MAXVHPOWER=800000; const Float_t VMAXMV=1024; const Float_t dtCH6A2ns=0; //=6; //http://ara.physics.wisc.edu/docs/0018/001808/002/190123_A2Fit.pdf const Float_t fWfVMax=0.8; //fraction of waveform that peak bin should be in, to ensure well ID'd signals. const Float_t fZENANGCUT=45; const Float_t CZRMSMAX=6; const Float_t FRQFRACFILTERMIN=0.16; //changed from 0.1 12dec23 const Float_t TOTMAXGD=64; const Float_t WFPTOTMINSURFPULSER=128; const Float_t Range2TxZIFG=256; const Float_t PHIMAXIFGZ=180; const Float_t THEMAXIFGZ=90; const Float_t DTNSMAX=32; const Float_t dTnsReSample=0.2; const Float_t nair=1.000293; Float_t GHz2MHz=1000; //const Float_t nano=1e-9; #define nano 1e-9 //const Float_t mega=1e6; #define mega 1e6 //const Float_t ft2m=0.3048; #define ft2m 0.3048 const Float_t NNN=9999999; const Float_t CPUTimeMax=NNN; const Float_t CPUTicksExecution=clock(); const Float_t CPUTime0Execution=CPUTicksExecution/CLOCK_TICKS_PER_SEC; const Float_t fLoPass0[20]={110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,32,32,32,32}; //25,25,25,25}; const Float_t fHiPass0[20]={1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,525,525,525,525}; Float_t fLoPass[20]={110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,32,32,32,32}; //25,25,25,25}; Float_t fHiPass[20]={1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,525,525,525,525}; const Float_t dtCD[6][4]={{0}}; //{{0,0,0,0},{0,0,0,0},{4,0,12,8},{4,0,12,8},{0,0,0,0},{0,0,0,0}}; const Int_t MFRQRJCT=128; const Int_t MBNPGR00=10; //const Float_t ff0GR00[MBNPGR00+2]={0.,0.05,0.1,0.148,0.152,0.198,0.202,0.248,0.252,0.298,0.302,0.348,0.352,0.398,0.402,0.448,0.452,0.498,0.502,0.8,2.}; const Int_t MAXCWWF=8; const Int_t MAXWFGREV=16; const Int_t MAXITERMINUIT=1024; const Int_t MAXEVCPANA=8; const Int_t MAXCPWFSV=8; const Int_t MMWFAVG=1024; const Int_t MWFAVGCP=1024; //cannot be larger than MMWFAVG or arrays below will break!!!!! const Int_t MWFAVGN=64; //4096; //was 64 - changed only for averaging A4 and A5 spice core runs! (must be >MEVN00) const Int_t MEVN00=64; //number of zTxz averages to make - changed for averaging SC runs 21Mar24 //Δl=Δz*Δz/(2*rSC2A) const Int_t MAXUBEV=4; const Int_t MXTMPL=16; const Int_t MAXTMPLAVGN=2048; const Int_t MFITVTXTMPL=6; //minimum number of hits for building template const Float_t FMAXPGR00=1000.; const Float_t MAXDTRMSGR1GR2=8; //max dtrms of good hits for building template const Float_t MAXDELA=0.2; Float_t dtrmsTmplMatch, dtTmplMatch, dATmplMatch, dtTmplMatchMin, dtrmsTmplMin, frac16ns, delATmplMin, utcTmpl[MXTMPL], utcUsTmpl[MXTMPL]; Int_t iBestTmpl=-1; const Int_t MEVSORT=99999; //Maximum number of events in putative skim file const Int_t M_NEVCUTS=32; const Int_t MCALTX=4; const Int_t MRCOCH=4; const Int_t MCH=20; const Int_t MCH8=8; const Int_t MCH16=16; const Int_t MDDA=4; const Int_t MDP=6; const Int_t MSurfPulsPos=31; const Int_t MSurfPulsPosA1=34; //const Int_t MAXRUNANA=8; const Int_t SNRHITMAX=1024; //ara01 problem child const Int_t VMAXMAX=4096; const Int_t MSTA=7; const Int_t MEVCLASS=32; const Int_t MEVRMSH1=32; const Int_t MSAMPLE_ONEBLOCK=32; const Int_t MBINZTX=10; const Int_t MBINRMS=64; const Int_t MFRQBIN=10; const Int_t MBNSMINFFT=32; //minimum number of bins for FFT const Int_t MBINFFTSPECTROGRAM=10; const Int_t MBINTIMESPECTROGRAM=32; //about 32 ns per time bin const Int_t MNSDELTPKS=64; Int_t MCHn=20; const Int_t zutcMIN=514000; const Int_t zutcMAX=527000; const Int_t MBNSPICELOG=zutcMAX-zutcMIN; Float_t zspicelogmin[MBNSPICELOG]; const Int_t MVARMINUIT=3; const char *ceventNumber="eventNumber"; char crfout[256], cpngtmp[512], cpngname[1024], cgrname[256], cgrtitle[256], chtitle[256], chname[256], cFileIn[256], cListFileIn[512], cchar[256], ctxtout[256], ctxtin[256], cgnudat[256], cObjName[256], cCanName[256], ctemp[512], crfouttemp[256], cpngname1[1024], cpngname2[1024], cCutsFile[256], cTxCoordsFile[256], cgrAvgOut[256], cProj[256], cEvCuts[256]; // char chitSeq[]=""; char chitSeq[256]=""; string stmp; std::ofstream evdump; std::ofstream UnbiasEvtsOut; std::ofstream DebugOut; //TMinuit* eventrecoMinuit=new TMinuit(MVARMINUIT); TMinuit* vtxSimMinuit=new TMinuit(MVARMINUIT); const Double_t R0FITMINUIT=128; const Double_t RMAXMINUIT=2048*2; //22dec19: changed from 2048*4 const Double_t THEMAXMINUIT=180; //I know it's dangerous, but it sure beats Rikers const Double_t PHIMAXMINUIT=180; vectorTxCoords_utc; vectorTxCoords_r; vectorTxCoords_phi; vectorTxCoords_z; TFile *fWind; TFile *fWBs, *fWB0; TFile *fSpiceDec18, *fSpiceDec18a, *fSpiceDec19; TProfile *hutcminz_pfx; TNtuple *NVTXEV; TNtuple *NWIND; TNtuple *NWB0, *NWBs; TNtuple *NLogSpice18, *NLS18utc; TTree *TLogSpice19; TNtuple *NTxCPCode; //TTree *TLogSpice18; TMultiGraph *mgrCPAvg, *mgrDPAvg[MDP], *mgrEVAvg; TGraph *grAvgVPol30degZen, *grAvgHPol30degZen, *grAvgVPol60degZen, *grAvgHPol60degZen; TGraph *grSpice18LogFile=new TGraph(); TGraph *grCPXX; TGraph *grSPAvgN[MSurfPulsPos][16][MMWFAVG]; TGraph *grDPAvgN[MDP][16][MMWFAVG]; TGraph *grEvWf[MAXWFGREV]; TGraph *grEvAvgN[2][16][MMWFAVG], *grEvAvg2[2][16], *grFFTEvAvg2[2][16]; TGraph *grUBAvg[20], *grUBFFTAvg[20]; TGraph *grDPN[16]; TGraph *grSPN[16]; TGraph *grEVN[2][16]; TGraph *grEVNZ[2][16]; TGraph *grEVN00[2][16][MEVN00]; TGraph *grDPAvg2[MDP][MCH]; TGraph *grCPAvg2[MCH], *grCPAvg2_0[MCH]; TGraph *grCPN[16], *grfftCPN[16]; TGraph *grCPAvgN[16][MMWFAVG]; TGraph *grCPMC[16][MMWFAVG]; //averaged waveform with VrmsCh noise voltages added prior to signal peak TGraph *grCPMCI[16][MMWFAVG]; TGraph *grCPMC2I[16][MMWFAVG]; TGraph *grCPMCC[16][MMWFAVG]; TGraph *grCPFileCh[16]; TGraph *grTmpl[MXTMPL][MCH]; //TGraph *grTmpl1[MXTMPL][MCH]; //TGraph *grTmplAvg[MXTMPL][MCH]; //TGraph *grTmplAvgCh[MXTMPL][MCH]; //TGraph *grTmplAvgN[MXTMPL][MCH][MAXTMPLAVGN]; TTree *TCOHINC; TTree *TX2A; TTree *TUTCEVT0; TTree *TUTCEVT1; TTree *TTRIGBITS; TTree *TUTC0; TTree *TFFTEV1; TTree *TFFTEV0; TTree *NSelIRUNEVT; TTree *TTVHIT, *TTVHITCP, *TTVHITDP, *TRCO; //TTree *T2HIT; TH1F *h1dum=new TH1F("h1dum","h1dum",1,-0.5,0.5); TH1F *h1PkXCThermalSNR[MCH][MCH]; TH1F *h1PThermal[MCH]; TH1F *h1PBkSub[MCH]; TH1F *h1PNoHit[MCH]; TH1F *h1Prms[MCH]; TH1F *h1PrmsUB[MCH]; TH1F *h1VrmsUB[MCH]; TH1F *h1PrmsMBN[MCH]; TH1F *h1VrmsMBN[MCH]; TH1F *h1Vrms00MBN[MCH]; TH1F *h1Vrms00MBN1ev[MCH]; TH1F *h1dtresid[MCH]; TH1F *h1frqIVCh[4]; TH2F *h2xyAwt; TH2F *histMapIFGV; TH2F *histMapIFGH; TH3I *h3devt; TH3I *h3dhit[MCH]; TH3F *h3Spectrogram[MBINZTX]; TH3F *h3PfftVfGalacDay[4]; const Int_t Mh2SNRVCh=6; TH2F *h2SNRVCh[Mh2SNRVCh]; TH2F *h2PkXCThermalSNR[MCH]; TH2I *h2PosNegZeroX[4]; TH2F *h2fPosNeg[4]; TH2F *h2fftVzTx[MCH][2]; TH2F *h2fftVzTxNorm[2]; TH2F *h2Zspx[MCH]; TH2F *h2fftVhr[MCH]; TH2F *h2SimVtxTimesVCh=new TH2F("h2SimVtxTimesVCh","h2SimVtxTimesVCh",256,0,512,20,-0.5,19.5); TH1F *h1nbOffset=new TH1F("h1nbOffset","h1nbOffset",2048,-1023.5,1023.5); TH2F *h2dtOffsetVCh=new TH2F("h2dtOffsetVCh","h2dtOffsetVCh",128,-63.5,64.5,16,-0.5,15.5); TH2F *h2delbinsVCh=new TH2F("h2delbinsVCh","h2delbinsVCh",64,-0.5,63.5,16,-0.5,15.5); TH2F *h2dfAvgCWX=new TH2F("h2dfAvgCWX","h2dfAvgCWX",32,-3.2,3.2,20,-0.5,19.5); TH2F *h2dfrq400MHz=new TH2F("h2dfrq400MHz","h2dfrq400MHz",128,-6.4,6.4,256,-0.5,255.5); TH2F *h2f400MHzVCh=new TH2F("h2f400MHzVCh","h2f400MHzVCh",64,400,406,20,-0.5,19.5); TH2F *h2frqRejectVCh=new TH2F("h2frqRejectVCh","h2frqRejectVCh",256,0,1024,20,-0.5,19.5); TH2F *h2nfrqRejectVCh=new TH2F("h2nfrqRejectVCh","h2nfrqRejectVCh",128,-0.5,256,20,-0.5,19.5); TH2F *h2Pin2PoutVCh=new TH2F("h2Pin2PoutVCh","h2Pin2PoutVCh",128,0,1.,20,-0.5,19.5); TH2F *h2TrigTimeOOS=new TH2F("h2TrigTimeOOS","h2TrigTimeOOS",1024,-1.024,0,3,-0.5,2.5); TH1F *h1dutcUsStack=new TH1F("h1dutcUsStack","h1dutcUsStack",10000,0,1.); //10 us binning TH1F *h1drsq4RxxyzV=new TH1F("h1drsq4RxxyzV","h1drsq4RxxyzV",50,-2.,3.); TH1F *h1drsq4RxxyzH=new TH1F("h1drsq4RxxyzH","h1drsq4RxxyzH",50,-2.,3.); TH1F *h1triggerInfo=new TH1F("h1triggerInfo","h1triggerInfo",4,-0.5,3.5); //MAX_TRIG_BLOCKS==4 TH1F *hRxdtns=new TH1F("hRxtdns","hRxdtns",20,-0.5,19.5); TH1F *hRxdtnsSim=new TH1F("hRxtdnsSim","hRxdtnsSim",20,-0.5,19.5); TH1F *hdutcCuts=new TH1F("hdutcCuts","hdutcCuts",1024,0,25.6); TH1F *h1TmplUs=new TH1F("h1TmplUs","h1TmplUs",200,0,5e5); TH1F *hdttrigEV=new TH1F("hdttrigEV","hdttrigEV",15000,0,3.); TH1F *hCPU=new TH1F("hCPU","hCPU",MEVCLASS,-0.5,MEVCLASS-0.5); TH1F *hdttrig=new TH1F("hdttrig","hdttrig",100,0,0.1); TH2F *h2fftVzTxVPol=new TH2F("h2fftVzTxVPol","h2fftVzTxVPol",500,0,1000,100,-1600,0); TH2F *h2fftVzTxHPol=new TH2F("h2fftVzTxHPol","h2fftVzTxHPol",500,0,1000,100,-1600,0); TH2F *h2fftVzTxSurf=new TH2F("h2fftVzTxSurf","h2fftVzTxSurf",500,0,1000,100,-1600,0); TH2F *h2fftWBVCh=new TH2F("h2fftWBVCh","h2fftWBVCh",180,310,490,20,-0.5,19.5); TH2F *h2fftXWBVCh=new TH2F("h2fftXWBVCh","h2fftXWBVCh",180,310,490,20,-0.5,19.5); TH2F *h2fftVtWB=new TH2F("h2fftVtWB","h2fftVtWB",500,0,1000,128,0,128); TH2F *h2tVMax00VCh=new TH2F("h2tVMax00VCh","h2tVMax00VCh",200,-100,1100,20,-0.5,19.5); TH2F *h2tNSig00VCh=new TH2F("h2tNSig00VCh","h2tNSig00VCh",200,-100,1100,20,-0.5,19.5); TH2F *h2VVCh=new TH2F("h2VVCh","h2VVCh",500,-2500,2500,20,-0.5,19.5); TH2F *h2VrmsVfGalacDay=new TH2F("h2VrmsVfGalacDay","h2VrmsVfGalacDay",64,0,1,20,-0.5,19.5); TH2F *h2Vrms00VCh=new TH2F("h2Vrms00VCh","h2Vrms00VCh",256,-0.5,63.5,20,-0.5,19.5); TH2F *h2VrmsUBVCh=new TH2F("h2VrmsUBVCh","h2VrmsxUBVCh",256,-0.5,127.5,20,-0.5,19.5); TH2F *h2VMax00VCh=new TH2F("h2VMax00VCh","h2VMax00VCh",256,-0.5,511.5,20,-0.5,19.5); TH2I *h2TmplnoVevno=new TH2I("h2TmplnoVevno","h2TmplnoVevno",16,-0.5,15.5,10000,0,100000); TH2F *h2fLoPassfHiPass=new TH2F("h2fLoPassfHiPass","h2fLoPassfHiPass",100,0,1000,16,-0.5,15.5); TH2F *h2RxUseMap=new TH2F("h2RxUseMap","h2RxUseMap",16,-0.5,15.5,16,-0.5,15.5); TH2F *h2nNadnZen=new TH2F("h2nNadnZen","h2nNadnZen",9,-0.5,8.5,9,-0.5,8.5); TH2F *h2PrmsVCh=new TH2F("h2PrmsVCh","h2Prms|ch",128,0,128,16,-0.5,16.5); TH2F *h2grDCX=new TH2F("h2grDCX","h2grDCX",2,-0.5,1.5,256,-255.5,256.5); TH2F *h2HitTimeCh=new TH2F("h2HitTimeCh","h2HitTimeCh",256,-2048,2048,16,-0.5,15.5); TH2F *h2CableDelayNsAR=new TH2F("h2CableDelayNsAR","h2CableDelayNsAR",256,0,256,16,-0.5,15.5); TH2F *h2CableDelayNsZ=new TH2F("h2CableDelayNsZ","h2CableDelayNsZ",256,0,256,16,-0.5,15.5); TH2F *h2ChOff=new TH2F("h2ChOff","h2ChOff",16,-0.5,15.5,32,-0.5,31.5); TH2F *h2TmplnHitMatchNoMatch=new TH2F("h2TmplnHitMatchNoMatch","Match (x) | unMatch (y)",9,-0.5,8.5,9,-0.5,8.5); TH2F *h2dtResidParPairs=new TH2F("h2dtResidParPairs","h2dtResidParPairs",16,-0.5,15.5,128,-64,64); TH2F *h2dtHV0=new TH2F("h2dtHV0","h2dtHV0",128,-64.5,63.5,8,-0.5,7.5); TH2F *h2dtHV0tNSig0=new TH2F("h2dtHV0tNSig0","h2dtHV0tNSig0",128,-64.5,63.5,8,-0.5,7.5); //TH2F *h2dtrmsTmplMin=new TH2F("h2dtrmsTmplMin","h2dtrmsTmplMin",32,-16.5,15.5,256,-0.5,63.5); TH2F *h2dtrmsVdA=new TH2F("h2dtrmsVdA","dA (frac) |dtrms (ns)",64,0.,0.64,256,-0.5,63.5); TH2F *h2dtrmsVdAMin=new TH2F("h2dtrmsVdAMin","h2dtrmsVdAMin",64,0.,0.64,256,-0.5,63.5); TH2F *h2dttrig00=new TH2F("h2dttrig00","h2dttrig00",400,0,8,100,0,20000); TH2F *h2ZphiVRxCode=new TH2F("h2ZphiVRxCodeV","h2ZphiVRxCodeV",180,-180.5,180.5,128,-0.5,127.5); TH2F *h2dttrig=new TH2F("h2dttrig","h2dttrig",M_NEVCUTS,-0.5,M_NEVCUTS-0.5,256,0,25.6); TH2F *h2AzEl=new TH2F("h2AzEl","h2AzEl",90,-180.5,180.5,45,-90.5,90.5); TH2F *h2MCdaz=new TH2F("h2MCdaz","dphi|phi",360,-180,180,360,-180,180); TH2F *h2SNRVCh00=new TH2F("h2SNRVCh00","h2SNRVCh00",128,-0.5,31.5,16,-0.5,15.5); TH2F *h2SNRVCh00CP=new TH2F("h2SNRVCh00CP","h2SNRVCh00CP",16,-0.5,15.5,128,-0.5,63.5); TH2F *h2dtTwinPeaksVCh=new TH2F("h2dtTwinPeaksVCh","h2dtTwinPeaksVCh",512,-0.5,511.5,16,-0.5,15.5); TH2F *h2timebaseVCh=new TH2F("h2timebaseVCh","timebase|Chno",128,0,1.28,20,-0.5,15.5); TH2F *h2dtijVCh=new TH2F("h2dtijVCh","h2dtijVCh",1024,-0.4,2.5,16,-0.5,15.5); TH2F *h2NSampleVCh=new TH2F("h2NSampleVCh","NSample|Chno",1024,0.5,2048.5,20,-0.5,15.5); TH2F *h2BufferLenVCh=new TH2F("h2BufferLenVCh","BufferLen|Chno",1024,0.5,1024.5,20,-0.5,15.5); TH2F *h2NFitVtx_if=new TH2F("h2NFitVtx_if","h2NFitVtx_if",16,-0.5,15.5,16,-0.5,15.5); TH2F *h2fftfrqMaxVCh=new TH2F("h2fftfrqMaxVCh","h2fftfrqMaxVCh",256,0,1024,20,-0.5,19.5); TH2F *h2frqMaxXThreshVCh=new TH2F("h2frqMaxXThreshVCh","h2frqMaxXThreshVCh",256,0,1024,20,-0.5,19.5); TH2F *h2fftVCh=new TH2F("h2fftVCh","h2fftVCh",1024,0,1024,20,-0.5,19.5); TH2F *h2fftVChPreF=new TH2F("h2fftVChPreF","h2fftVChPreF",1024,0,1024,20,-0.5,19.5); TH2F *h2fftVChEV=new TH2F("h2fftVChEV","h2fftVChEV",MFRQBIN,-0.5,MFRQBIN-0.5,20,-0.5,19.5); TH2F *h2fftVChLovW=new TH2F("h2fftVChLovW","h2fftVCh: v<10",1024,0,1024,20,-0.5,19.5); TH2F *h2fftVChMevW=new TH2F("h2fftVChMevW","h2fftVCh: 10'normal', -1=>'quiet' const Int_t convergence[2]={0,0}; // Convergence flags for SIMPLEX and MIGRAD (0 - conv, 4 - failed) //const Double_t UPvalue=0; const Double_t utc_1Jan11=1293840000; //const Double_t arglist[2]={200,1}; //,10,10}; // UP = 200, 1 - is not used Double_t * arglist=new Double_t[2]; const Double_t argsSimplexMigrad[2]={MAXITERMINUIT,0.8}; // MaxCalls = 1000, tolerance = EDM = 0.8 const Double_t step[MVARMINUIT]={10,5,5}; Float_t phiInitMinuit=0; Float_t theInitMinuit=90; //Int_t MDRAWPNGS=16; Int_t MAXEVDRAW=8; Int_t MAXEVDRAW0=2; Int_t MAXEVDRAWS=8; Int_t MAXEVDRAWGIF=8; Int_t ichSurf0=16; //const Float_t VSATMV=4096; const Float_t phiRotLoc2Glo=126.78; //phiGlobal = phiLocal + 126.78 const Float_t Vrms0=32; const Float_t TSECSOLARDAY=86400.002; const Float_t TSECSIDEREAL=86164.0916; const Float_t RxHitTime00=NNN; const Float_t T0event=NNN; const Double_t sLightAir=TMath::C()*1e-9; // 0.29970551819; //velocity of light in meters/ns const Double_t nIce=1.78; const Float_t nSurfIce=1.35; /* from ASC Drawing SSEDSKC-101.DWG / 12SEP2017 09:36: double station_coords[NSTATIONS][2]={ // this time the numbering is 5 ARA stations + ARIANNA station 51 {38881.57894736842, 50921.05263157895}, // in feet {35460.52631578947, 45328.94736842105}, {32302.631578947367, 51052.631578947374}, {35460.52631578947, 56710.52631578947}, {28947.36842105263, 45328.94736842105}, IceFlowDir=36 deg, 47' wrt GridNorth Shouldn't ice flow direction be positive below? */ const Float_t IceFlowwrtGridNorth=+36.7; //from Amy geometry note: N36◦46’23”W - const Float_t IceFlowwrtNegX=IceFlowwrtGridNorth-90; const Float_t IceFlowwrtGridNorthIC=+41; //https://www.igsoc.org/journal/59/218/t13J068.pdf actually states -40 degrees in caption to Fig. const Float_t IceFlowICwrtX=90+IceFlowwrtGridNorthIC; //note that IC uses 41 deg. west of north! const Float_t IC2ARA_global[3]={22400*ft2m,53900*ft2m,0}; //from Amy's note - surveyor's coordinates and not IC coordinates - center of A37 const Float_t IC22_1450[3]={static_cast(44884.51*ft2m-IC2ARA_global[0]),static_cast(51444.87*ft2m-IC2ARA_global[1]),-1401.026}; const Float_t IC1_1450[3]={static_cast(45660.03*ft2m-IC2ARA_global[0]),static_cast(50489.76*ft2m-IC2ARA_global[1]),-1399.46}; const Float_t IC1_2450[3]={static_cast(45660.03*ft2m-IC2ARA_global[0]),static_cast(50489.76*ft2m-IC2ARA_global[1]),-2477.72}; //Muray Aydin @uci.edu: The coordinates we have are 89 59' 20.168 S, 98 09'34.528 W, or in the relative coordinate system the station uses N48800.00, E 42600.00 const Float_t SpiceCore2015XYZ[3]={static_cast(42600*ft2m-IC2ARA_global[0]),static_cast(48800*ft2m-IC2ARA_global[1]),0}; //const Float_t SpiceCoreXYZ[3]={static_cast(42560*ft2m-IC2ARA_global[0]),static_cast(48790*ft2m-IC2ARA_global[1]),0}; //read off http://spicecore.org/about.shtml //const Float_t SpiceCoreXYZ[3]={static_cast(42383*ft2m-IC2ARA_global[0]),static_cast(49600*ft2m-IC2ARA_global[1]),0}; //ASC GPS January, 2019 const Float_t SpiceCoreXYZ[3]={static_cast(42358.94*ft2m-IC2ARA_global[0]),static_cast(48974.2*ft2m-IC2ARA_global[1]),0}; //Leah Street const Float_t AASTN51[3]={static_cast(41153.2175*ft2m-IC2ARA_global[0]),static_cast(50381.75*ft2m-IC2ARA_global[1]),0}; const Float_t ICLTxXYZ[3]={24030*ft2m,-1725*ft2m,0}; //in array coords const Float_t SPTXYZ[3]={24774*ft2m,-871.35*ft2m,0}; //south pole telescope const Float_t SPSXYZ[3]={27322.88*ft2m,-3369.89*ft2m,-36.02*ft2m}; // const Float_t ARAXYZA[6][3]={{0,0,0}, {static_cast(38881.5*ft2m-IC2ARA_global[0]),static_cast(50921*ft2m-IC2ARA_global[1]),0}, {static_cast(35460*ft2m-IC2ARA_global[0]),static_cast(45328*ft2m-IC2ARA_global[1]),0}, {static_cast(32302*ft2m-IC2ARA_global[0]),static_cast(51052*ft2m-IC2ARA_global[1]),0}, {static_cast(35460*ft2m-IC2ARA_global[0]),static_cast(56710*ft2m-IC2ARA_global[1]),0},{0,0,0}}; const Float_t ARAXYZ[6][3]={{17246.69*ft2m,-540.82*ft2m,-21.86*ft2m}, {16401.71*ft2m,-2835.37*ft2m,-25.67*ft2m}, {13126.70*ft2m,-8519.62*ft2m,-18.72*ft2m}, {9848.35*ft2m,-2835.37*ft2m,-12.70*ft2m}, {3977,900,-177},{3030,-4327,-180}}; const Float_t WT3XYZ[3]={18662.31*ft2m,-3552.64*ft2m,0}; char* datestamp; char cEvFileName[256]=""; string filename, runString, sfileList, sflistcomment, utcDayString, stem; Bool_t LxLimitsgr, LCWEv, LOKWvfms, LICLev, LWBON, LSameFrq400MHz; //Bool_t LFITCWX=true; Bool_t LWritegrEVN00=true; Bool_t LTxSpiceCore=false; Bool_t LTxCPCodeFile=true; Bool_t LBuildzIndex=true; Bool_t LInitAnaEv0=true; Bool_t LInitUB[MCH]={true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true}; Bool_t LInitTxCPCode=true; //Bool_t LinitRun=true; Bool_t LInitSpLog=true; Bool_t LInitAvgEv2[2]={1,1}; Bool_t LDrawAvgEv[2]={0,0}; //Bool_t LAvgdEv[2]={0,0}; Bool_t LVetoEv=false; Bool_t LDum, LDum1, LDebug, LAna, LDrawPngs, LEvType[MEVCLASS], LDP[MDP], LCP, LUB, LRF, LCP0, LSP[MSurfPulsPos], LMC, LEvCut, LAllFits, LDrawEv, LNewTmpl, LThermalEv, LIcrr, LAraRootv313, LenableTrigWindow, LenableTrigDelays, LUseCh[MCH], LUseCh0[MCH]; Bool_t LLVTX=false; Bool_t Lrindex1=true; Bool_t LPrintDbg=false; //Bool_t LUseCh[MCH]={1}; //Int_t iUseChVH[MCH], iUseChV[MCH], iUseChH[MCH]; Bool_t LParPairsV[8][8][8][8]={{{{false}}}}; //Int_t nParPairsV[8][8][8][8]={{{{0}}}}; Float_t dt4ParPairsV[8][8][8][8]={{{{0}}}}; Bool_t LParPairsH[8][8][8][8]={{{{false}}}}; //Int_t nParPairsH[8][8][8][8]={{{{0}}}}; Float_t dt4ParPairsH[8][8][8][8]={{{{0}}}}; Bool_t LParPairsEvV[8][8][8][8]={{{{false}}}}; //Int_t nParPairsV[8][8][8][8]={{{{0}}}}; Float_t dt4ParPairsV[8][8][8][8]={{{{0}}}}; Bool_t LParPairsEvH[8][8][8][8]={{{{false}}}}; //Int_t nParPairsH[8][8][8][8]={{{{0}}}}; Float_t dt4ParPairsH[8][8][8][8]={{{{0}}}}; Bool_t LVP5Dec11[4][3]={{false}}; Bool_t LHP5Dec11[4][3]={{false}}; Bool_t LVP05Dec11[4]={false}; Bool_t LHP05Dec11[4]={false}; Int_t NEvCuts[M_NEVCUTS][MEVCLASS], ndof, ierflg, ichMaxResid, iRxHits, iNPARI, iNPARX, ifitstatus, iparNumber, nhits, nhitsH, nhitsS, nhitsV, NEvTot0[M_NEVCUTS], NEvCP, NEvCPAvg, NEvUB, idum, idum1, idum2, idum3, NFileAna, ieventNumber, ieventNumberm1, irunNumber, iFileNameRunNo, iPolVtx, nFitVtx, ncharrunString, itrigZ, NSamples[MCH], ipkbin, NVrmsCh[MCH], istatus, ncombFit[MCH], trigCode, ievt0, ievt00, iSta0, ichMinHitTime, ichSNRMax, istafromString, iyrfromString, nSNRcomb, ientryMatchIndex, iFailCode0, iCutsLevel, nRxDimX, nRxDimY, nRxDimZ, nbinsVtgr[MCH], ngrAvg, ievana0, ievana1, ichMaxHitTime, itNSig[MCH], itNSigf[MCH], itSPE[MCH], nAnaEv[MEVCLASS][2], ichX[2], nhitNSig, nhitSlope, NDrawEv, NDrawEv0, NDrawEvGif, NDrawEvS, nrxV, nrxH, nrxS, iYrEv, iSurfPulsPos, iEvCode, NDPEv, NSPEv, NThermEv, ich0gr00, nhitsgr00V, nhitsgr00H, nhitsgr00S, iMatchUs, idutcUsMin, iStaEvPtr, intvar, nFitVTX, ihitsCodeV, ihitsCodeH, nRxADCX, nRxADCOOB, nSwitchOff[MCH], iptdum[MCH], ipttRx2A[MCH16], iptSNR[MCH], nHitsRx[MCH], nHitsRxMC[MCH], nHitsRx00[MCH], iStation0, iYear0, iDPcode, iICLPol, npkSpx[MCH], nZenithV, nNadirV, nZenithH, nNadirH, NUBStore, irunEv9, irun0Ev9, nczAvgHV, nSATSamples[MCH], itriggerBits[MCH16], itrigChanNum[MCH16], irunno, ievno, iStano, iTxCPCode, iTxCPrfin, iTxCPCh, nDPVDPH, itrigInfo0[MCH16], iTrigWindowns, iEnableTrig, iTrigDelayCh[MCH16], idaqChanNum[MCH16], nTrigChs, iSurfPuls2015Index, nX1VTot, nCWCh, iuseChgr00[MCH], nMatchdt[MCH], ncdtgtdr[MCH], ntp1NSigHit, ntSlopeHit, ntExpFitHit, nXCgHit, ntVMaxHit, ntNSigHit, nbnCWHPol, nbnCWVPol, ASMsolnCh[MCH], Fit4solnCh[MCH], Z4solnCh[MCH], iXCRxHV[8], ibnVtXp[4][MCH], ibnVtXm[4][MCH], ppsNumber, iPol3SNR, ich3SNRV, ich3SNRH, utcyr0, nfitfrq400MHz, fMinWfLen, iRanSeed0, ibntp1NSig[MCH], ibntm1NSig[MCH], ibntp2NSig[MCH], ibntm2NSig[MCH], ipow2C, ievCohC, ievtype0, nbOffsetgrAXgrBCh, nbOffsetgrAXgrB[MCH]; Int_t iPolVtxEvm1=-2; Int_t NEvUBCh[MCH]={0}; Int_t nCWWF=0; Int_t NEvBadGraphsAraRoot=0; Int_t NEvBadWfGraphs=0; Int_t NEvBadFFTGraphs=0; Int_t LTxRaiseTLowerF=-1; Int_t nEvAvg[2]={0}; //Int_t inEvAvg=0; Int_t nEvWf=0; Int_t ichSNRMaxEv[2][MMWFAVG]={{0}}; Int_t *iSortedEntries; //https://root-forum.cern.ch/t/sorting-a-tree/12560/2 Int_t nEVN00[2]={0}; vectoriptEntry2Ev; vectoriptEv2Entry; //vectorievno000; Int_t iOrderedEntries[MEVSORT]={0}; Int_t iptEv2utc[MEVSORT]={0}; Int_t iptHitTime2Rx[MCH16]; Int_t iptRx2Hit[MCH16]; Int_t iptTrigDelayCh2AR[MCH]={0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15}; Int_t iptRxAraRoot2Rxtrue[MCH]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}; //Int_t iptCDAraRoot2CDtrue[MCH]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}; Int_t ievnoV[MEVSORT]; Double_t utcV1d[MEVSORT]; const Int_t MSTACKN=64; Int_t utcUsStack[MSTACKN]={0}; //,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; Int_t itrigCodeStack[MSTACKN]={0}; //,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; Int_t utcStack[MSTACKN]={0}; //,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; Float_t PStackN[MSTACKN]={0}; //,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; Float_t dtutcStack[MSTACKN]={0}; Int_t iutcUsStack=0; Int_t NEvTot=0; Int_t nTotEntries=0; Int_t NAnaEvTot=0; Int_t NEvStack=0; Int_t NDrawPngs=-1; Int_t idtnsVHMC=0; Int_t NEvSimVtx=0; Int_t nSPEv[MSurfPulsPos]={0}; Int_t nDPEv[MDP]={0}; Int_t nDPAvg2[MDP]={0}; Float_t chisqvtx, tresidMax, fMaxResid, RxHitCode2, RxHitCode10, fdum0, fdum, fdum1, fdum2, fdum3, fdum4, fdum5, fdum6, WfPV, WfPH, WfPS, VCPTx[4][3], rCPTxSrc[3], CPTxSrc[3], d2IC1_1450[MCH], d2IC1_2450[MCH], d2IC22_1450[MCH], phiIC1_1450, phiIC1_2450, theIC1_1450, theIC1_2450, phiIC22_1450, theIC22_1450, Axc[MCH][MCH], dtxc[MCH16][MCH16], SNRxc[MCH][MCH], dtSumVPol, dtSumHPol, scale, VrmsCh[MCH], VrmsUB[MCH], Vrms1ev[MCH], PrmsCh[MCH], VrmsChSum[MCH], VrmsChAvg[MCH], AXCGaus[2], tXCGaus[2], timeNSig[2], xFitSrc, yFitSrc, zFitSrc, dtFitResid[MCH][MCH], tFitResid[MCH], SNRXCTone[2], VXCTone[2], tXCTone[2], pk2pkV[MCH][MEVCLASS], HPolPower, VPolPower, simVtx[3], E1V, E1H, E9V, E9H, E25V, E25H, phiMaxZIFG,theMaxZIFG,E1ZIFG,E9ZIFG,E25ZIFG, SNRxcperCh, AXCevCP, dtrmsCPxc, ACPxc, fTH1CPxc, xshiftCP, VgrPow, HgrPow, dtVtgr, AXCgrAvg, dtrmsXCgrAvg, dtCorrAndAvg2, xshiftgrAvg, MaxArrayTransitTime, AvgdtHV, CPUTimeTot, TOTSum, TOTSumGd, TOTCh[MCH], nSATSumV, nSATSumH, CPUUse[M_NEVCUTS], CPUt0, CPUt1, dxyzRxiRxj[MCH][MCH], czAvgEv, czRMSEv, dtSmearSimVtx, PMax1Ch, tSimVtxFirstHit, tSimVtxLastHit, phicog, thecog, SNRVtxMin, ichSNRVtxMin, ffft0[MCH], Afft0[MCH], phifft0[MCH], ffftWt[MCH], AfftWt[MCH], rGlo, phiGlo, theGlo, rIFGlo, phiIFGlo, theIFGlo, tHitTime[MCH], VMaxHit[MCH], VMinHit[MCH], VAvgCh[MCH], tNSigf[MCH], deltpks[MCH], dtp1p2NSig[MCH], ANSig1[MCH], ANSig2[MCH], ANSig3[MCH], ANSig4[MCH], tp1NSig[MCH], tm1NSig[MCH], tp2NSig[MCH], tm2NSig[MCH], tp3NSig[MCH], tm3NSig[MCH], tp4NSig[MCH], tm4NSig[MCH], deltTwinPeaks[MCH], dtXCGaus[MCH], AdtXCGaus[MCH], CentroidN[MSTA], CentroidE[MSTA], Centroidu[MSTA], CentroidN0[MSTA], CentroidE0[MSTA], Centroidu0[MSTA], CentroidN1[MSTA], CentroidE1[MSTA], Centroidu1[MSTA], tXCg[MCH], tiBox[MCH], tfBox[MCH], tSlope[MCH], phiMaxZIFG1, theMaxZIFG1, Rdr2dtHitx[8], Rdr2dtHity[8], Rdr2dtHitz[8], sumResidParPairsV, sumResidParPairsH, dtResidParPairs[MCH], tGFit[MCH], RxtNSig[MCH], RxtNSig0Ch[MCH], tXCRxHV[8], AXCRxHV[8], SNR2TOTMin, TrigRate, dtXC0[MCH16][MCH16], PGdPerCh, AngleDegcz0[8], AngleDegcz1[8], AngleDegcz2[8], AngleDegcz3[8], AngleDegczXCTB[8], AngleDegAzTV[6], AngleDegAzBV[6], AngleDegAzTH[6], AngleDegAzBH[6], AngleDegAz0[24], A1DubG[MCH], A2DubG[MCH], dtDubG[MCH], t1DubG[MCH], WidDubG[MCH], tTH1i[MCH], tTH1f[MCH], PDDA[4], zTx0z, zTx0zLF, zTx0zm1, zTx0za, zTx0zb, zTx0zc, zTx0zd, zTx0ze, RxPower[MCH], RxRawPower[MCH], dZCoordsAraRoot[3][MCH], dtTPif[MCH], fVExcursion, fHExcursion, ASlope[MCH], Pfreqbin[MFRQBIN], tVMax[MCH], WidtVMax[MCH], fftAvgf[MCH], tVMin[MCH], tVMaxXCableDelay[MCH], tVMinXCableDelay[MCH], tVMax2[MCH], VMax2[MCH], tVMinMx12[MCH], VMinMx12[MCH], AXCVMax1VMax2[MCH], dtXCVMax1VMax2[MCH], RxSNR[MCH], dtHtb[4], dtVtb[4], TOTMax, czV[4], czH[4], czVMin, czHMin, SNRgr00, SNRMax, SNRgr00Min, czAvgH, dczAvgH, czAvgV, dczAvgV, czAvgHV, dczAvgHV, czHV[MCH/2], dtHV, ddtHV, ddt0HV, dtHVCh[8], Ptp1tm1[MCH], Ptp2tm2[MCH], Pgr00[MBNPGR00], Pgr00Ch[MCH][MBNPGR00], zutcspice, ApkSpx[MCH], dtXCTV[MCH], AXCTV[MCH], Prms00MBN[MCH], Vrms00MBN[MCH], xpkSpx[MCH], xpk2Spx[MCH], Apk2Spx[MCH], y0ExpFit[MCH], tExpFit[MCH], AExpFit[MCH], SlopeExpFit[MCH], vWind, phiWind, T2mWind, hr0Wind, t2WB, tMinHit, fCWHPol, fCWVPol, SpxA0[MCH], SpxSlope[MCH], y0DubExp[MCH], t1DubExp[MCH], SlopeDubExp[MCH], A1DubExp[MCH], dtDubExp[MCH], A2DubExp[MCH], fGalacticDay, phicogX[MCH], thecogX[MCH], PowerFrqBndBk[MCH][MFRQBIN], PowerFrqBndSignal[MCH][MFRQBIN], PowerFrqBnd0[MCH][MFRQBIN], PowerFrqBndUB[MCH][MFRQBIN], WBxm, WBym, WBzm, P400MHzWB[MCH], P400MHzWBSB[MCH], AfCWX[MCH], ChiSqCWX[MCH], WBxm0, WBym0, PDirect[MCH], PRefrac[MCH], PFFTDir[MCH][8], PFFTRef[MCH][8], RCO_DCOffmV[MRCOCH], RCO_A[MRCOCH], RCO_FRQ[MRCOCH], RCO_PHI0[MRCOCH], Vrms50Ohm[MRCOCH], y0DubExpif[MCH], t1DubExpif[MCH], SlopeDubExpif[MCH], A1DubExpif[MCH], dtDubExpif[MCH], A2DubExpif[MCH], VMnVMx1VMx2[MCH], tVMnVMx1VMx2[MCH], dtgrxixf[MCH], Agrxixf[MCH], Rx3SNRV, Rx3P5nsV, Rx3SNRH, Rx3P5nsH, PFiltered[MCH], PhaseCWX[MCH], dtCWX[MCH], frqfCWX[MCH], fitfrq400MHz[MCH], tResidMag[MCH16], rms400MHz, avg400MHz, pkCWfft, WBphi, WBthe, WBr, WBxmtmp, frqbindf[MCH], dphiSxS400MHz[6], tICL2RxA[MCH], tIC22S2RxA[MCH], tIC1S2RxA[MCH], tIC1D2RxA[MCH], rIC22S2RxA[MCH], rIC1S2RxA[MCH], rIC1D2RxA[MCH], dSrc2Rx[MCH16], dtSrc2Rx[MCH16], dtSrc2RxMin, rms2p1C[MCH16], rmsm12p2C[MCH16], rmsp2pC[MCH16], rmsp32C[MCH16], rmsm32C[MCH16], dtp1p2C[MCH16], A1NSigC[MCH16], A2NSigC[MCH16], fbndMHzC, rmsp12m1C[MCH16], PNSig16C[MCH16], PNSig16_32C[MCH16], dtOffsetgrAXgrB[MCH], dtOffsetgrAXgrBCh; Float_t AskewX, AskewY, AskewZ, AkurtX, AkurtY, AkurtZ, xminRxArray, xmaxRxArray, yminRxArray, ymaxRxArray, zminRxArray, zmaxRxArray, dAskewX, dAskewY, dAskewZ, dAkurtX, dAkurtY, dAkurtZ, AWtrsqr, AxWtAvg, AyWtAvg, AzWtAvg, CCAxWt, CCAyWt, CCradius, PSNRRx[MCH], Awttcog[MCH]; Float_t zTx0z_lastAvg=NNN; Float_t VMaxCh[MCH]={0}; Float_t RxXYZ0[3]={0}; Float_t RxXYZA[3]={0}; const Float_t SNRxcMin0=4; Float_t SNRxcMin=SNRxcMin0; //Double_t utcT, utcz; Float_t dutcUsMin; Int_t iCodeC=0; Int_t irGen=0; Int_t itheGen=0; Int_t iphiGen=0; Int_t idtSmrGen=0; Float_t theMaxDegV, phiMaxDegV, theMaxDegH, phiMaxDegH, phiMaxDegV1, phiMaxDegH1, theMaxDegV1, theMaxDegH1; const Int_t MNTVAR=256; Float_t xntvar[MNTVAR]; Float_t CutVarMin[MNTVAR]={0}; Float_t CutVarMax[MNTVAR]={0}; const Int_t MA1A2SPICE18XTRIG=15; const Double_t utcA2spice18[MA1A2SPICE18XTRIG]={1515379257.96153402,1515379269.30915594,1515379280.62248898,1515379297.63990688,1515379303.30649996,1515379314.67083406,1515379320.37108994,1515379326.01750898,1515379331.72646093,1515379348.92514396,1515379354.69411492,1515379360.41223097,1515379371.8773129,1515379377.58849192,1515379383.32713795}; const Double_t utcA1spice18[MA1A2SPICE18XTRIG]={1515379257.96223211,1515379269.30636597,1515379280.621176,1515379297.63902092,1515379303.30591512,1515379314.66980004,1515379320.37056398,1515379326.01669312,1515379331.71879196,1515379348.92564702,1515379354.6933341,1515379360.41116905,1515379371.87613893,1515379377.5877111,1515379383.32698393}; Float_t rSurfPuls2015[MSurfPulsPos]={0,100,100,100,100,100,175,175,175,250,250,250,250,250,100,100,100,100,100,175,175,175,175,175,250,250,250}; //surface pulser phi positions Float_t phiSurfPulsLoc[MSurfPulsPos]={-999,304.708,233.041,161.311,89.367,16.858,340.900,268.943,197.636,125.339,53.172,17.185,305.069,233.340,161.187,89.442,89.064,17.166,305.224,233.161,161.114,125.147,53.250,341.003,269.165,197.215,161.162,89.122,17.175,305.096,233.179}; Float_t phiSurfPulsGlo[MSurfPulsPos]={-999,71.781,359.684,287.699,216.031,143.949,107.892,35.775,324.230,251.938,180.019,144.085,71.963,0.061,287.806,216.171,215.612,144.148,72.351,359.946,287.537,251.717,180.016,107.975,36.068,323.869,287.796,215.804,144.031,72.012,359.957}; Float_t A2SurfPuls2015PhiGlo[15]={71.781,359.684,287.699,216.031,143.949,107.892,35.775,324.230,251.938,180.019,144.085,71.963,0.061,287.806,216.171}; Float_t A2SurfPuls2015PhiLoc[15]={304.708,233.041,161.311,89.367,16.858,340.900,268.943,197.636,125.339,53.172,17.185,305.069,233.340,161.187,89.442}; Float_t A3SurfPuls2015PhiGlo[15]={215.612,144.148,72.351,359.946,287.537,251.717,180.016,107.975,36.068,323.869,287.796,215.804,144.031,72.012,359.957}; Float_t A3SurfPuls2015PhiLoc[15]={89.064,17.166,305.224,233.161,161.114,125.147,53.250,341.003,269.165,197.215,161.162,89.122,17.175,305.096,233.179}; UInt_t iutcARA1SP[MSurfPulsPosA1]={1449708095,1449708127,1449708479,1449708519,1449708846,1449708890,1449709223,1449709253,1449709740,1449709774,1449710013,1449710040,1449710346,1449710376,1449710663,1449710689,1449710963,1449710990,1449711443,1449711468,1449711601,1449711631,1449887548,1449887586,1449887622,1449887652,1449887824,1449887863,1449888046,1449888097,1449888264,1449888301,1449888469,1449888511}; UInt_t iutc0SP[MSurfPulsPos]={0,1421834700,1421837400,1421761080,1421767500,1421830980,1421832780,1421835480,1421764680,1421766600,1421838240,1421831760,1421833740,1421836260,1421765640,1421839200,1421927640,1421928540,1421929320,1421930160,1421926800,1421924460,1421922840,1421920440,1421918760,1421926020,1421925240,1421923620,1421922000,1421919660,1421917860}; UInt_t iutc1SP[MSurfPulsPos]={0,1421787900,1421790600,1421714280,1421720700,1421784180,1421785980,1421788680,1421717880,1421719800,1421791440,1421784960,1421786940,1421789460,1421718840,1421792400,1421880840,1421881740,1421882520,1421883360,1421880000,1421877660,1421876040,1421873640,1421871960,1421879220,1421878440,1421876820,1421875200,1421872860,1421871060}; //Int_t ichFirstHit=-1; Int_t ichLastHit=-1; Int_t MEVPRNT=32; //UInt_t utcCutsMin, utcCutsMax; Double_t utc000=-1; Double_t ChiSqTot, fitd2min, errpos, errneg, eparabolic, gccc, ddum, ddum1, ddum2, utcNow, unixTime0, unixTime1, unixTime, unixTimem1, unixTimeUs, unixTimeUsm1, unixTime10Ns, dtNtrig, dttrig, dttrig0, utcCutsMin, utcCutsMax, unixTimeEV, unixTimeEVm1, dunixTimeEV, unixTime00, unixTime00m1, dunixTime00, utcEvCuts[M_NEVCUTS][2], DubVec0[3], DubVec1[3], utc10Ns, utc00Ev, dtutc00Ev, utcT, utcz, utcCP, utcCP0, dtutcCP, dtutcUB, utcUB, theAVAR, phiAVAR; Double_t fitXV[MVARMINUIT], fitXVf[MVARMINUIT], fitXVH[MVARMINUIT], fitH[MVARMINUIT], fitxcV[MVARMINUIT], fitxcVH[MVARMINUIT], fitxcH[MVARMINUIT], FitPar[MVARMINUIT], FitErr[MVARMINUIT], FP[MVARMINUIT], FE[MVARMINUIT]; Double_t FitParSNR[4], FitErrSNR[4]; const Int_t MBNDS0=10; const Float_t PowerFrqBinBnds[MBNDS0]={0.14,0.22,0.305,0.39,0.41,0.49,0.58,0.7,0.8,9.9}; const Float_t PowerFrqBndsS[MBNDS0]={0.025,0.05,0.075,0.1,0.15,0.25,0.39,0.41,0.6,9.9}; Bool_t LUSEBOXCAR=false; //T gives slightly better reconstruction if LUSESPE true Bool_t LUSESPE=false; //F: Use Hilbert Envelope - this ties into SIGMA definition Float_t DTBOXCARNS=8; Float_t MSIGMASPE0=10; //changed from 10 on 12dec23; //changed from 12 on 15apr21 Float_t MSIGMASPE=MSIGMASPE0; Float_t MSIGMAV=6; Float_t MSIGMAGR00=6; Float_t MSIGMATOT=5; Float_t MSIGMACUTGD=2*MSIGMASPE; UInt_t utcDate; UInt_t utchour=0; UInt_t utchr0=0; UInt_t utcmin=0; UInt_t utcsec=0; UInt_t utcmin0=0; UInt_t irunNumberIcrr; Int_t utcday=0; Int_t nTmpl=-1; Int_t nTotTmpl=-1; Int_t igrRunAvg=0; Int_t ngrEvt=0; Int_t igrEvt=0; Int_t ngrEvent=0; Int_t iMatchTmpl[MXTMPL]={0}; Bool_t LVtxTmpl[MCH][MXTMPL]={{0}}; //kWhite = 0, kBlack = 1, kGray = 920, kRed = 632, kGreen = 416, kBlue = 600, kYellow = 400, kMagenta = 616, kCyan = 432, kOrange = 800, kSpring = 820, kTeal = 840, kAzure = 860, kViolet = 880, kPink = 900 Int_t izcolor[MCH]={616, 880, 881, 601, 600, 861, 434, 432, 841, 418, 416, 400, 801, 632, 1, 19, 17, 16, 15}; //const Double_t fitd2min=0; TF1 *fsinCWX; //TF1 *fsin400MHz; TF2 *fEllipse; TF1 *f2sinGalaxy; TF1 *fdubgp0; TF1 *fdubgp1; TF1 *fLattenVz; TF1 *fgp0; TF1 *fgp1; TF1 *f2Box; TF1 *npoly; TF1 *nexp; TF1 *nexp1; TF1 *nASim; TF1 *nUNL; TF1 *nexpZ; TF1 *nUz; AraGeomTool *AraGeomPtr; struct SphericalFit{Float_t r, phi, the, dr, dphi, dthe, t0, phiTH1, dphiTH1, phiTH1gfit, theTH1, dtheTH1, z; Int_t ncomb, nRxDimX, nRxDimY, nRxDimZ;}; SphericalFit Fit4, Vvtx4Z1, Vvtx4Z2, FitvtxMinuit, VvtxIFG, VvtxSim, ASMvtx; struct EvProps{ Float_t HPolPower, VPolPower, trigYr, trigDay, trigHr, trigMin, trigSec; UInt_t utc; Int_t utcUs, nhitsV, nhitsH; }; EvProps eVZ; struct RxChannel{ Bool_t LVtx, LXVtx, LVTX, LVtx0, LVtxCutsFile; char cID1[4], cID2[4], cLABID1[2], cLABID2[2], cHV[2], cRxType[9], cFullName[18], cPol, cLocation[3], cdum10[10], cdum11[11], choleName[6], cantName[6]; Int_t LPF, HPF, iLogCh, iRxno, ichno, iPol, indx, iBH, ibinNSig, nOOTH, ibnVMax, ibnVMax2, ibnPMax, ibnCOG, ihole, iPol0, nSample, nSatSample; //iPol=0: V / iPol=: H Float_t NF, x, y, z, cableDelayNs, HitTime, dtNsCorr, dtNsCorrSim, hitweight, dtFitResid, Vrms, VrmsUB, Prms, PrmsUB, xMC, yMC, zMC, dtijMC, tMC, A, dtSimTx, deldTijSimDa, t0, tVMax, tVMax2, PMax, tPMax, tPMax2, tNSig, tNSigf, tNSig0, tVMax4, tVMax4f, tVHalfMax, tSlope, tSlopef, tXCg, AXCg, ASlope, ASlopef, xcHitTime, VSPErms, d2Tx, A2, tVMax00, SNR, SNRZ, VMax, fVMax2, rxy, N, E, u, TOT, tHESlope, AHESlope, tHESlope1, AHESlope1, r, phi, the, pk2pkV, VAvg, VAvg32, Vrms0, Power, ffftMax, fFFTMax, AfftMax, frcPFFTMax, IceXAirx, IceXAiry, IceXAirz, tnsInAir, tnsInIce, tTPi, tTPf, VMaxTPi, VMaxTPf, VMinTPif, dtXCTPif, AXCTPif, tResolution, xcog, ycog, zcog, tNAvg, rmsNAvg, tXCtone, tGFit, SPERMSGFit, Arms, tiBox, tfBox, PRMSBox, SNRBox, h1Vrms, h1Prms, VrmsMBN, PrmsMBN, tp1NSig, tm1NSig, tp2NSig, tm2NSig, tp3NSig, tm3NSig, N0, E0, u0, N1, E1, u1, aE, aN, au, x0, y0, z0, cableDelayNs0, tXCRx, SNR2TOT, tTH1i, tTH1f, fpmExcursion, cablePlusTriggerDelayNs, Vrms00, Vrms00MBN, h1Vrms00, tNSig00, x00, y00, z00; // string commentstring; }; RxChannel Rx[MCH]; struct TxChannel{Float_t xLoc, yLoc, zLoc, xGlo, yGlo, zGlo, xGloA, yGloA, zGloA, rLoc, phiLoc0, phiLoc, theLoc, thepLoc, rGlo, phiGlo, theGlo, rGloA, phiGloA, theGloA;}; TxChannel CPTx[MCALTX], CPTxglo, DPTx[3], ICLTx, SPS, WindTurb3, SpiceCorePVA, AAStn51; void zutil(){ /* gSystem->AddIncludePath("-I${ARA_UTIL_INSTALL_DIR}/include"); gSystem->AddIncludePath("-I${ARA_UTIL_INSTALL_DIR}/lib"); gSystem->AddIncludePath("-I FFTtools.h"); gSystem->Load("libsqlite3.so"); cout<<"loading libsqlite3.so"<Load("libfftw3.so"); cout<<"loading libfftw3.so"<AddIncludePath(" -I/home/ikrav/work/software/gsl-1.16/ "); gSystem->Load("/home/ikrav/work/software/gsl-1.16/.libs/libgsl.so"); gSystem->Load("/home/ikrav/work/software/gsl-1.16/cblas/.libs/libgslcblas.so"); cout<<"Loading ilya libs"<Load("libRootFftwWrapper.so"); cout<<"loading libRootFftwWrapper.so"<Load("libAraEvent.so"); cout<<"loading libAraEvent.so"<Load("libAraConfig.so"); cout<<"loading libAraConfig.so"<Load("libAraDisplay.so"); cout<<"loading libAraDisplay.so"<Load("libAraCorrelator.so"); cout<<"loading libAraCorrelator.so"<Load("/home/dbesson/src/calcDeltTR_C.so"); */ /* gSystem->Load("libgsl.so"); cout<<"loading libgsl.so"<Load("libMathMore.so"); cout<<"loading libMathMore.so"<Load("libGeom.so"); cout<<"loading libGeom.so"<Load("libGraf3d.so"); cout<<"loading libGraf3d.so"<Load("libPhysics.so"); cout<<"loading libPhysics.so"<GetX()[gr->GetN()-1]-gr->GetX()[0])/gr->GetN();} inline Bool_t Leqppm(Float_t x1, Float_t x2){if(x1+x2==0)return false; return fabs(x1-x2)/(x1+x2)<0.001;} inline Float_t fUO1d(TH1 *h){if(h->GetEntries()<=0)return -1; return 1-h->Integral()/h->GetEntries();} inline double ranZ(){const int divisor=RAND_MAX;double rannum=((double)(rand()%divisor)/divisor); return rannum;} inline Float_t grIntZ(TGraph *gr){Float_t fInt=0; for(Int_t ib=0; ibGetN(); ib++)fInt+=gr->GetY()[ib]; return fInt;} inline TGraph *grZZ00(TGraph *gr){TGraph *grtmp=(TGraph*)gr->Clone(); grtmp->SetPoint(0,gr->GetX()[0],0); grtmp->SetPoint(gr->GetN()-1,gr->GetX()[gr->GetN()-1],0); return grtmp;} inline Int_t ix2bn(TGraph *gr, Float_t xval){ Float_t binwid=gr->GetX()[1]-gr->GetX()[0]; Float_t x0=gr->GetX()[0]; Float_t delx=gr->GetX()[gr->GetN()-1]-gr->GetX()[0]; return gr->GetN()*(xval-x0)/delx; } inline Float_t grRMSpm(Int_t MSAMPLErms, TGraph *grtmp){return TMath::Min(TMath::RMS(MSAMPLErms,&grtmp->GetY()[0]),TMath::RMS(MSAMPLErms,&grtmp->GetY()[grtmp->GetN()-MSAMPLErms-1]));} void PrintCPUUsage(){ MemInfo_t memInfo; CpuInfo_t cpuInfo; Float_t act_load = 0.0; Int_t memTotal = 0; Int_t memUsed = 0; Int_t memFree = 0; Int_t fSwapTotal = 0; Int_t fSwapUsed = 0; Int_t fSwapFree = 0; // prev_load = act_load; old_memUsage = memUsage; // Get CPU information gSystem->GetCpuInfo(&cpuInfo, 100); //https://root.cern.ch/doc/master/structCpuInfo__t.html // actual CPU load act_load = cpuInfo.fTotal; // Get Memory information gSystem->GetMemInfo(&memInfo); //https://root.cern.ch/doc/master/structMemInfo__t.html // choose which value to display // if (gMainWindow->GetActInfo() == 0) memTotal = memInfo.fMemTotal; // else if (gMainWindow->GetActInfo() == 1) memUsed = memInfo.fMemUsed; // else if (gMainWindow->GetActInfo() == 2) memFree = memInfo.fMemFree; fSwapUsed=memInfo.fSwapUsed; fSwapFree=memInfo.fSwapFree; fSwapTotal=memInfo.fSwapTotal; NMEM->Fill(memTotal,memUsed,memFree,fSwapUsed,fSwapFree,fSwapTotal); cout<<"CPU load="<Clone(); const Int_t MBNAVG=128; Int_t ibpk=TMath::LocMax(grHE->GetN(),grHE->GetY()); tpk=grHE->GetX()[ibpk]; avgp1=TMath::Mean(2*MBNAVG,grHE->GetY()); avgm1=TMath::Mean(2*MBNAVG,&grHE->GetY()[grHE->GetN()-2*MBNAVG-1]); Float_t avg=TMath::Min(avgp1,avgm1); Float_t rms=TMath::Min(TMath::RMS(2*MBNAVG,grHE->GetY()),TMath::RMS(2*MBNAVG,&grHE->GetY()[grHE->GetN()-2*MBNAVG-1])); tpHE=-1; tmHE=-1; tp90HE=-1; tm90HE=-1; ibntpHE=ibntmHE=avgp=avgm=ibntpHE1=ibntmHE1=-1; Apk=grHE->GetY()[ibpk]; SNRpk=(Apk-avg)/rms; if(LDebug)printf("avg=%g rms=%g SNRpk=%g\n",avg,rms,SNRpk); if(grHE->GetY()[ibpk]0; ibn--){ if(grHE->GetY()[ibn]<0.9*grHE->GetY()[ibpk] && tp90HE==-1)tp90HE=grHE->GetX()[ibn]; grHEtm->SetPointY(ibn,0); if(grHE->GetY()[ibn]>avg+rms*MSIGthresh)continue; ibntpHE=ibn; tpHE=grHE->GetX()[ibn]; avgp=TMath::Mean(TMath::Min(MBNAVG,ibntpHE),&grHE->GetY()[ibntpHE-MBNAVG]); break; } for(Int_t ibn=ibpk; ibnGetN(); ibn++){ if(grHE->GetY()[ibn]<0.9*grHE->GetY()[ibpk] && tm90HE==-1)tm90HE=grHE->GetX()[ibn]; grHEtm->SetPointY(ibn,0); if(grHE->GetY()[ibn]>avg+rms*MSIGthresh)continue; ibntmHE=ibn; avgm=TMath::Mean(TMath::Min(MBNAVG,grHE->GetN()-ibntmHE-1),&grHE->GetY()[ibntmHE]); tmHE=grHE->GetX()[ibn]; break; } for(Int_t ibn=TMath::Max(ibntpHE-4*MBNAVG,0); ibnGetN()); ibn++)grHEtm->SetPointY(ibn,0); Int_t jbpk=TMath::LocMax(grHEtm->GetN(),grHEtm->GetY()); for(Int_t ibn=jbpk; ibn>0; ibn--){ if(grHEtm->GetY()[ibn]>avg+rms*MSIGthresh)continue; ibntpHE1=ibn; break; } for(Int_t ibn=jbpk; ibnGetN(); ibn++){ if(grHEtm->GetY()[ibn]>avg+rms*MSIGthresh)continue; ibntmHE1=ibn; break; } } inline Float_t dtgr1gr2ibiibf(TGraph *gr1, TGraph*gr2, Int_t ib1i, Int_t ib1f, Int_t ib2i, Int_t ib2f, Float_t &ACorr){ Int_t MB=gr1->GetN(); TGraph *grtmp1=(TGraph*)gr1->Clone(); TGraph *grtmp2=(TGraph*)gr2->Clone(); Float_t gr1Avg=grtmp1->GetMean(2); Float_t gr2Avg=grtmp2->GetMean(2); Double_t *tV=grtmp1->GetX(); Double_t *V1=grtmp1->GetY(); Double_t *V2=grtmp2->GetY(); for(Int_t ib=0; ibib1i && ibSetPoint(ib,tV[ib],V1[ib]-gr1Avg); else grtmp1->SetPoint(ib,tV[ib],0); if(ib>ib2i && ibSetPoint(ib,tV[ib],V2[ib]-gr2Avg); else grtmp2->SetPoint(ib,tV[ib],0); } TGraph *grtmp0=FFTtools::getCorrelationGraph(grtmp1,grtmp2); Double_t *tVals=grtmp0->GetX(); Int_t ipkbin; ACorr=FFTtools::getPeakVal(grtmp0,&ipkbin); Float_t deltat=tVals[ipkbin]; if(LDebug)printf("ACorr=%g / deltat=%g\n",ACorr,deltat); delete grtmp0; delete grtmp1; delete grtmp2; return deltat; } inline Float_t dtXCZ(Bool_t LHilbert, TGraph *grtmp1, TGraph *grtmp2, Float_t xi, Float_t xf, Float_t dxXCwindow, Float_t &tXgr1, Float_t &tXgr2, Float_t &SNRgr1, Float_t &SNRgr2){ const Int_t MBRMS=128; const Int_t MSIGMA=5; TGraph *gr1, *gr2; if(LHilbert){gr1=FFTtools::getHilbertEnvelope(grtmp1); gr2=FFTtools::getHilbertEnvelope(grtmp2);} else{gr1=(TGraph*)grtmp1->Clone(); gr2=(TGraph*)grtmp2->Clone();} Float_t delx=(gr1->GetX()[1]-gr1->GetX()[0]); Float_t delx2=(gr2->GetX()[1]-gr2->GetX()[0]); if(gr1->GetN()!=gr2->GetN()||gr1->GetX()[0]!=gr2->GetX()[0]||delx!=delx2){cout<<"dtXCZ given two differently binned graphs! RETURNING -NNN!"<GetX()[0]||xf+dxXCwindow>gr1->GetX()[gr1->GetN()-1])cout<<"dtXCZ gr1 OOB"<GetX()[0]||xf+dxXCwindow>gr2->GetX()[gr2->GetN()-1])cout<<"dtXCZ gr2 OOB"<GetY()[ibi1]); Float_t rms2=TMath::RMS(MBRMS,&gr2->GetY()[ibi1]); Float_t avg1=TMath::Mean(MBRMS,&gr1->GetY()[ibi1]); Float_t avg2=TMath::Mean(MBRMS,&gr2->GetY()[ibi1]); tXgr1=-NNN; tXgr2=-NNN; SNRgr1=0.5*(TMath::MaxElement(ibf1-ibi1,&gr1->GetY()[ibi1])-TMath::MinElement(ibf1-ibi1,&gr1->GetY()[ibi1]))/rms1; SNRgr2=0.5*(TMath::MaxElement(ibf1-ibi1,&gr2->GetY()[ibi1])-TMath::MinElement(ibf1-ibi1,&gr2->GetY()[ibi1]))/rms2; // cout<<"ibi1="<%dσ t1=%g%s\t",avg1,rms1,SNRgr1,KMAG,MSIGMA,tXgr1,KNRM); break;} for(Int_t ib=ibi1+MBRMS; ibGetY()[ib])GetX()[ib]; printf("gr2 avg1=%g rms=%g peakSNR=%g %s>%dσ t2=%g%s\n",avg2,rms2,SNRgr2,KCYN,MSIGMA,tXgr2,KNRM); break;} for(Int_t idb=-idbins; idbgr2->GetN()){cout<<"ib2 OOB="<GetY()[ib]*gr2->GetY()[ib2]);} if(LDebug)printf("%g %g\n",dtXC,dotsum); dotarr[jdb]=dotsum; if(dotsum>dotmax){dotmax=dotsum; idbmax=jdb; dtXCMax=dtXC;} } printf("#%s ΔtXCMax(gr2 wrt gr1)=%g %s xi=%g->%g dotmax=%g dd=%g\n",KRED,dtXCMax*1e9,KNRM,gr1->GetX()[ibi1],gr1->GetX()[ibf1],dotmax,dotarr[idbmax]*2/TMath::Mean(8,&dotarr[idbmax-4])); return dtXCMax; } inline Float_t getTimeexpUzD(Int_t iFlag, Float_t Txx, Float_t Txy, Float_t Txz, Float_t Rxx, Float_t Rxy, Float_t Rxz){ const Float_t c0=TMath::C()*1e-9; Float_t dxyz=sqrt((Txx-Rxx)*(Txx-Rxx)+(Txy-Rxy)*(Txy-Rxy)+(Txz-Rxz)*(Txz-Rxz)); Float_t scale=dxyz/fabs(Rxz-Txz); //correction for slant angle if(LDebug)printf("dxyz=%g / Scale=%g\n",dxyz,scale); Float_t proptime; if(iFlag==0)proptime=nASim->Integral(TMath::Min(Rxz,Txz),TMath::Max(Rxz,Txz))*scale/c0; else if(iFlag==1) proptime=nUz->Integral(TMath::Min(Rxz,Txz),TMath::Max(Rxz,Txz))*scale/c0; else if(iFlag==2) proptime=nexpZ->Integral(TMath::Min(Rxz,Txz),TMath::Max(Rxz,Txz))*scale/c0; if(LDebug)printf("getTimeexpUzD iFlag=%d / proptime=%g\n",iFlag,proptime); return proptime; } inline Float_t agetTimeUzD(Float_t Txx, Float_t Txy, Float_t Txz, Float_t Rxx, Float_t Rxy, Float_t Rxz){ const Float_t c0=TMath::C()*1e-9; Float_t dtot=sqrt((Txx-Rxx)*(Txx-Rxx)+(Txy-Rxy)*(Txy-Rxy)+(Txz-Rxz)*(Txz-Rxz)); Float_t scale=dtot/fabs(Rxz-Txz); return nUz->Integral(TMath::Min(Rxz,Txz),TMath::Max(Rxz,Txz))*scale/c0; } inline Float_t Angle2R(Float_t Txx, Float_t Txy, Float_t Txz, Float_t Rxx, Float_t Rxy, Float_t Rxz){ Float_t dxy=sqrt((Txx-Rxx)*(Txx-Rxx)+(Txy-Rxy)*(Txy-Rxy)); Float_t dxyz=sqrt(dxy*dxy+(Txz-Rxz)*(Txz-Rxz)); Float_t fxyTx=fabs(Txz)/(fabs(Txz)+fabs(Rxz)); Float_t dxyTx2S=fxyTx*dxy; Float_t dxyzTx2S=sqrt(dxyTx2S*dxyTx2S+Txz*Txz); if(dxyzTx2S==0)return-1; else return asin(dxyTx2S/dxyzTx2S); } inline Float_t getTimeexpUzR(Int_t iFlag, Float_t Txx, Float_t Txy, Float_t Txz, Float_t Rxx, Float_t Rxy, Float_t Rxz){ Float_t proptime=-1; const Float_t c0=TMath::C()*1e-9; Float_t dxy=sqrt((Txx-Rxx)*(Txx-Rxx)+(Txy-Rxy)*(Txy-Rxy)); Float_t dxyz=sqrt(dxy*dxy+(Txz-Rxz)*(Txz-Rxz)); Float_t fxyTx=fabs(Txz)/(fabs(Txz)+fabs(Rxz)); Float_t dxyTx2S=fxyTx*dxy; Float_t dxyzTx2S=sqrt(dxyTx2S*dxyTx2S+Txz*Txz); Float_t scaleTx2S=dxyzTx2S/fabs(Txz); Float_t dxyS2Rx=(1-fxyTx)*dxy; Float_t dxyzRx2S=sqrt(dxyS2Rx*dxyS2Rx+Rxz*Rxz); Float_t scaleS2Rx=dxyzRx2S/fabs(Rxz); if(iFlag==0)proptime=(nASim->Integral(Txz,0)*scaleTx2S+nASim->Integral(Rxz,0)*scaleS2Rx)/c0; else if(iFlag==1)proptime=(nUz->Integral(Txz,0)*scaleTx2S+nUz->Integral(Rxz,0)*scaleS2Rx)/c0; else if(iFlag==2)proptime=(nexpZ->Integral(Txz,0)*scaleTx2S+nexpZ->Integral(Rxz,0)*scaleS2Rx)/c0; if(LDebug)printf("getTimeexpUzR iFlag=%d / proptime=%g\n",iFlag,proptime); return proptime; } //entries includes UO / Integral only in specified range inline Float_t grXGetWtAvg(TGraph *gr, Int_t ibin0, Int_t dnbins){ Float_t fden=0; Float_t fnum=0; if(ibin0gr->GetN()-dnbins)return gr->GetX()[ibin0]; for(Int_t ib=ibin0-dnbins; ib<=ibin0+dnbins; ib++){ fnum+=gr->GetX()[ib]*gr->GetY()[ib]; fden+=gr->GetY()[ib]; } return fnum/fden; } TGraph *MFSHgrSub(TGraph *spectrum1, TGraph *spectrum2){ vector v; v.insert(v.end(), spectrum1->GetX(), (spectrum1->GetX() + spectrum1->GetN()) ); v.insert(v.end(), spectrum2->GetX(), (spectrum2->GetX() + spectrum2->GetN()) ); std::sort(v.begin(), v.end() ); v.erase(std::unique( v.begin(), v.end() ), v.end() ); Int_t n = v.size(); TGraph *diff = new TGraph(n); for (Int_t k = 0; k < n; k++){diff->SetPoint(k, v[k], (spectrum1->Eval(v[k]) - spectrum2->Eval(v[k])));} return diff; } inline Float_t MaxElpm(TGraph *gr, Int_t &ibAMax){ Float_t fp=TMath::MaxElement(gr->GetN(),gr->GetY()); Float_t fm=TMath::MinElement(gr->GetN(),gr->GetY()); // printf("fp=%g fm=%g\n",fp,fm); Float_t AMax; if(-fm>fp){ AMax=fm; ibAMax=TMath::LocMin(gr->GetN(),gr->GetY()); } else{ AMax=fp; ibAMax=TMath::LocMax(gr->GetN(),gr->GetY()); } Float_t RMax2Min0=0; if(fm!=0&&fp!=0)RMax2Min0=fp/fm; Float_t t2pk=gr->GetX()[ibAMax]-gr->GetX()[0]; if(t2pk==0)printf("t2pk=%g AMax=%g ibAMax=%d nb=%d\n",t2pk,AMax,ibAMax,gr->GetN()); return AMax; } inline TGraph *grSetSpikesToZero(TGraph *gr, Float_t fThresh){ Float_t VMax=TMath::MaxElement(gr->GetN(),gr->GetY()); TGraph *grtmp=(TGraph*)gr->Clone(); for(Int_t ib=0; ibGetN(); ib++) if(fabs(grtmp->GetY()[ib])>fThresh*VMax)grtmp->GetY()[ib]=0; return grtmp; } inline TGraph *grTest(Int_t MPTS){ TGraph *grtmp=new TGraph(MPTS); for(Int_t ipt=0; iptSetPoint(ipt,ipt,gRandom->Uniform(-128,128)); return grtmp; } // frequency in MHz // depth in m (negative) // Returns attenuation in [meters] Double_t GetAttenuationLengthSP(Double_t f, Double_t z, Int_t model) { // model = 1 : Shahids model // model = 2 : Shahids model + 10% // model = 3 : Shahids model - 10% // model = 4 : Attenuation constant in frequencies. Only depth dependent (assuming freq=500Mhz) // model = 5 : Attenuation constant in depth. Only attenuation dependent (assuming depth=200m) // model = 9: Attenuation constant in all depth/frequencies = 700 m // model = 10: Attenuation constant in all depth/frequencies = 2000 m // Double_t depth = 0.5 * thickness - z; Double_t depth = -z; Double_t w = log(f * 0.001); Double_t w0 = -9.21; Double_t w2 = 1.15; Double_t t = -54.975 + 3.062 * exp(depth / 976.1); Double_t b0 = -6.7489 + t * (0.026709 - 8.84e-4 * t); Double_t b1 = -6.2212 - t * (0.070927 + 1.77e-3 * t); Double_t b2 = -4.0947 - t * (0.002213 + 3.32e-4 * t); Double_t x=0; Double_t smear; switch ( model ) { case 1: // Shahids depth = -z; w = log(f * 0.001); w0 = -9.21; w2 = 1.15; t = -54.975 + 3.062 * exp(depth / 976.1); b0 = -6.7489 + t * (0.026709 - 8.84e-4 * t); b1 = -6.2212 - t * (0.070927 + 1.77e-3 * t); b2 = -4.0947 - t * (0.002213 + 3.32e-4 * t); if (f < 1000.0 && f>0 ) { x = b1 - (b1 - b0) * w / w0; x=exp(-x);} else if (f>=1000.0) {x = b1 + (b2 - b1) * w / w2; x=exp(-x);} else x=700; // if frequency is negative or zero , use a constant attenuation length=700 m //printf ("Shahids model=%f \n",x); break; case 2: // Shahids + 10% depth = -z; smear = 1.1; w = log(f * 0.001); w0 = -9.21*smear; w2 = 1.15*smear; t = -54.975 + 3.062 * exp(depth / 976.1); b0 = -6.7489*smear + t * (0.026709*smear - smear*8.84e-4 * t); b1 = -6.2212*smear - t * (0.070927*smear + smear*1.77e-3 * t); b2 = -4.0947*smear - t * (0.002213*smear + smear*3.32e-4 * t); if (f < 1000.0 && f>0 ) { x = b1 - (b1 - b0) * w / w0; x=exp(-x);} else if (f>=1000.0) {x = b1 + (b2 - b1) * w / w2; x=exp(-x);} else x=700; // if frequency is negative or zero , use a constant attenuation length=700 m break; case 3: // Shahids - 10% depth = -z; smear = 0.9; w = log(f * 0.001); w0 = -9.21*smear; w2 = 1.15*smear; t = -54.975 + 3.062 * exp(depth / 976.1); b0 = -6.7489*smear + t * (0.026709*smear - smear*8.84e-4 * t); b1 = -6.2212*smear - t * (0.070927*smear + smear*1.77e-3 * t); b2 = -4.0947*smear - t * (0.002213*smear + smear*3.32e-4 * t); if (f < 1000.0 && f>0 ) { x = b1 - (b1 - b0) * w / w0; x=exp(-x);} else if (f>=1000.0) {x = b1 + (b2 - b1) * w / w2; x=exp(-x);} else x=700; // if frequency is negative or zero , use a constant attenuation length=700 m break; case 4: // model = 4 : Attenuation constant in frequencies. Only depth dependent (assuming freq=500Mhz) f=500; depth = -z; smear = 1; w = log(f * 0.001); w0 = -9.21*smear; w2 = 1.15*smear; t = -54.975 + 3.062 * exp(depth / 976.1); b0 = -6.7489*smear + t * (0.026709*smear - smear*8.84e-4 * t); b1 = -6.2212*smear - t * (0.070927*smear + smear*1.77e-3 * t); b2 = -4.0947*smear - t * (0.002213*smear + smear*3.32e-4 * t); if (f < 1000.0 && f>0 ) { x = b1 - (b1 - b0) * w / w0; x=exp(-x);} else if (f>=1000.0) {x = b1 + (b2 - b1) * w / w2; x=exp(-x);} else x=700; // if frequency is negative or zero , use a constant attenuation length=700 m break; case 5: // // model = 5 : Attenuation constant in depth. Only attenuation dependent (assuming depth=200m) depth = -200; smear = 1.; f=500; w = log(f * 0.001); w0 = -9.21*smear; w2 = 1.15*smear; t = -54.975 + 3.062 * exp(depth / 976.1); b0 = -6.7489*smear + t * (0.026709*smear - smear*8.84e-4 * t); b1 = -6.2212*smear - t * (0.070927*smear + smear*1.77e-3 * t); b2 = -4.0947*smear - t * (0.002213*smear + smear*3.32e-4 * t); if (f < 1000.0 && f>0 ) { x = b1 - (b1 - b0) * w / w0; x=exp(-x);} else if (f>=1000.0) {x = b1 + (b2 - b1) * w / w2; x=exp(-x);} else x=700; // if frequency is negative or zero , use a constant attenuation length=700 m break; case 9: // model = 9: Attenuation constant in all depth/frequencies = 700 m x=700; break; case 10: // model = 10: Attenuation constant in all depth/frequencies = 2000 m x=2000; break; } return x; } //https://www.overleaf.com/project/6106a46a226b1b7002cbe77c inline Float_t GetAttenuationLengthSS(Float_t fMHz, Float_t z_meters){ //z_meters negative Float_t ALdum=-800; // if(z_meters>-1500.)ALdum=-800; if(z_meters<=1500.)ALdum=1300+0.32*z_meters; return ALdum; } inline Float_t LattenVz(Float_t zi, Float_t zf){ const Float_t delz=10; const Float_t zbedSP=-2850; const Float_t f0=300; Float_t C0=1.; Float_t FluxFactor; for(Float_t zz=zi; zz>zf; zz-=delz){ C0*=exp(-2*delz/GetAttenuationLengthSP(f0,zz-delz/2,1)); //factor 2 for up/back FluxFactor=(zi/zf); if(LDebug)printf("depth=%g / Flux=%g zf=%g C0=%g\n",zz-delz/2,zf,FluxFactor,C0); } return C0; } inline Float_t getDeltatDR(Float_t zRx, Float_t rRx2Tx, Float_t theDeg, Float_t &dthe){ Float_t theRad=theDeg*TMath::DegToRad(); Float_t zTx=rRx2Tx*sin(theRad); if(zTx<=zRx)return -1; Float_t dD=sqrt(rRx2Tx*rRx2Tx+(zTx-zRx)*(zTx-zRx)); Float_t rXX=0.5*rRx2Tx*zRx/zTx; //surface intersection point: similar triangles Float_t drx2rXX=sqrt(zRx*zRx+rXX*rXX); Float_t dtx2rXX=sqrt(zTx*zTx+(rRx2Tx-rXX)*(rRx2Tx-rXX)); dthe=acos(zTx/dtx2rXX)*TMath::RadToDeg() - acos((zTx-zRx)/dD)*TMath::RadToDeg(); Float_t dR=drx2rXX+dtx2rXX; Float_t tD=1.4*dD/0.2998; Float_t tR=1.4*dR/0.2998; return tR-tD; } inline Float_t dtTx2RxSurfRefln1pt6(const char *cMsg,Float_t Txx, Float_t Txy, Float_t Txz, Float_t Rxx, Float_t Rxy, Float_t Rxz){ cout<GetN(); ib++){ ibnFFTarr=(grPFFTin->GetX()[ib]-fminPFFT)*nbinsFFT/(fmaxPFFT-fminPFFT); if(ibnFFTarr<0)ibnFFTarr=0; if(ibnFFTarr>nbinsFFT-1)ibnFFTarr=nbinsFFT-1; if(iDR==0)PFFTDir[ich][ibnFFTarr]+=grPFFTin->GetY()[ib]; else PFFTRef[ich][ibnFFTarr]+=grPFFTin->GetY()[ib]; if(LDebug)printf("ib=%d x=%g y=%g ibnfft=%d\n",ib,grPFFTin->GetX()[ib],grPFFTin->GetY()[ib],ibnFFTarr); } } inline TGraph *grabs(TGraph *gr){ TGraph *grtmp=(TGraph*)gr->Clone(); for(Int_t ib=0; ibGetN(); ib++) grtmp->SetPointY(ib,fabs(grtmp->GetY()[ib])); return grtmp; } inline TGraph *grDCX(TGraph *gr){ TGraph *grXDC=new TGraph(gr->GetN()); Float_t VDCOff=gr->GetMean(2); for(Int_t ibn=0; ibnGetN(); ibn++) grXDC->SetPoint(ibn,gr->GetX()[ibn],gr->GetY()[ibn]-VDCOff); return grXDC; } inline TGraph *grPkX(TGraph *gr, Float_t dx00, Float_t &APk, Float_t &xPk, Float_t &PPk){ Float_t binwid=(gr->GetX()[gr->GetN()-1]-gr->GetX()[0])/gr->GetN(); TGraph *grtmp=(TGraph*)gr->Clone(); Int_t ibnpk=TMath::LocMax(gr->GetN(),gr->GetY()); Int_t ibn0=TMath::Max(0,ibnpk-int(dx00/binwid)); for(Int_t ib=ibn0; ibGetN()); ib++)grtmp->SetPointY(ib,0); ibnpk=TMath::LocMax(grtmp->GetN(),grtmp->GetY()); APk=grtmp->GetY()[ibnpk]; xPk=grtmp->GetX()[ibnpk]; PPk=0; for(Int_t ib=TMath::Max(ibnpk-8,0); ibGetN()); ib++)PPk+=grtmp->GetY()[ib]*grtmp->GetY()[ib]; return grtmp; } inline TGraph *grSubgrSubbk(TGraph *gr, Float_t xi, Float_t xf, Float_t &xmax, Float_t &ymax){ Double_t binwid=(gr->GetX()[gr->GetN()-1]-gr->GetX()[0])/gr->GetN(); Int_t ibini=(xi-gr->GetX()[0])/binwid; Int_t ibinf=(xf-gr->GetX()[0])/binwid; if(LDebug)printf("xi=%g xf=%g ibini=%d ibinf=%d binwid=%g\n",xi,xf,ibini,ibinf,binwid); TGraph *grtmp=new TGraph(ibinf-ibini,&gr->GetX()[ibini],&gr->GetY()[ibini]); TGraph *grBk=(TGraph*)grtmp->Clone(); //new TGraph((ibinf-ibini)/4,&gr->GetX()[ibini],&gr->GetY()[ibini]); grBk->Fit("pol2"); for(Int_t ib=0; ibGetN(); ib++) grtmp->SetPointY(ib,fabs(grtmp->GetY()[ib]-grBk->GetFunction("pol2")->Eval(grtmp->GetX()[ib]))); Int_t ibnpk; ymax=MaxElpm(grtmp,ibnpk); xmax=grtmp->GetX()[ibnpk]; // delete grBk->GetFunction("pol2"); delete grBk; return grtmp; } inline TGraph *grSubgr(TGraph *gr, Float_t xi, Float_t xf, Float_t &xmax, Float_t &ymax, Int_t &ibini, Int_t &ibinf, Int_t &ibnpk){ Double_t binwid=(gr->GetX()[gr->GetN()-1]-gr->GetX()[0])/gr->GetN(); ibini=(xi-gr->GetX()[0])/binwid; ibinf=(xf-gr->GetX()[0])/binwid; if(LDebug)printf("xi=%g xf=%g ibini=%d ibinf=%d binwid=%g\n",xi,xf,ibini,ibinf,binwid); TGraph *grtmp=new TGraph(ibinf-ibini,&gr->GetX()[ibini],&gr->GetY()[ibini]); // TGraph *grtmp1=grDCX(grtmp2); TGraph *grtmp=grabs(grtmp1); delete grtmp1, grtmp2; ymax=MaxElpm(grtmp,ibnpk); xmax=grtmp->GetX()[ibnpk]; return grtmp; } inline TGraph *grSubgr00(TGraph *gr, Float_t xi, Float_t xf){ // Float_t xpts[16384*8], ypts[16384*8]; // memset(xpts,0,sizeof(xpts)); memset(ypts,0,sizeof(ypts)); TGraph *grtmp=new TGraph(); grtmp->SetName("grtmp"); //???? 29Jan22 Int_t npts=0; // if(LDebug)cout<<"grSubgr00: xpts[0]="<GetX()[0]="<GetX()[0]<<" gr->GetX()[1]="<GetX()[1]<GetN(); ib++){ if(gr->GetX()[ib]GetX()[ib]>xf)continue; grtmp->SetPoint(npts,gr->GetX()[ib],gr->GetY()[ib]); // xpts[npts]=gr->GetX()[ib]; ypts[npts]=gr->GetY()[ib]; npts++; } if(npts==0) for(Int_t idumbn=0; idumbn<8; idumbn++)grtmp->SetPoint(idumbn,idumbn,idumbn); // cout<GetX()[0]<<" "<GetX()[1]<GetXaxis()->SetRangeUser(xi,xf); ??? return grtmp; } Float_t tVXgrsub(TGraph *gr, Float_t Vthresh, Float_t xmin, Float_t xmax){ TGraph *grtmp=grSubgr00(gr,xmin,xmax); Float_t tVX=-1; for(Int_t ib=0; ibGetN(); ib++){ if(fabs(grtmp->GetY()[ib])>Vthresh){tVX=grtmp->GetX()[ib]; break;} } printf("tVX= %g\n",tVX); TCanvas *cgrsub=new TCanvas("cgrsub","cgrsub"); grtmp->Draw("al"); return tVX; } void Fringe2dt(Bool_t LDraw, TGraph *grfft, Int_t MBNF, Float_t &dt2frq, Float_t &ddt2frq, Float_t &Dt2frq, Float_t &dDt2frq, Float_t &h1dt2frq, Float_t &fEntries, Float_t &fffit){ Int_t MSRMS=grfft->GetN()/MBNF; Int_t ipt, ibAfMin; const Float_t Thresh=0.5; const Float_t fMin=0.1; const Float_t fMax=0.6; Float_t AfMin, AfAvg; Float_t rms00, Afsum, R, dRsq; TGraph *grtmp; TGraphErrors *grDev=new TGraphErrors(); grDev->SetNameTitle("grDev","grDev"); TGraphErrors *grdev=new TGraphErrors(); grDev->SetNameTitle("grdev","grdev"); TH1F *h1frq=new TH1F("h1frq","h1frq",64,0,64); Int_t ipD=0; Int_t ibglo; // grfft->Print("all"); abort(); for(Int_t ib=0; ibGetN()-MSRMS; ib+=MSRMS){ grtmp=new TGraph(MSRMS,&grfft->GetX()[ib],&grfft->GetY()[ib]); AfMin=TMath::MinElement(MSRMS,&grfft->GetY()[ib]); ibAfMin=TMath::LocMin(MSRMS,&grfft->GetY()[ib]); AfAvg=TMath::Mean(MSRMS,&grfft->GetY()[ib]); // if(LDebug)printf("ib=%d AfMin=%g AvAvg=%g ibAfMin=%d grfftX(ibAfMin)=%g grfftY(ibAfMin)=%g\n",ib,AfMin,AfAvg,ibAfMin,grfft->GetX()[ibAfMin],grfft->GetY()[ibAfMin]); if(AfMin/AfAvg>Thresh)continue; grDev->SetPoint(ipD,ipD+1,grfft->GetX()[ib+ibAfMin]); grDev->SetPointError(ipD,0,001/((AfMin-AfAvg)*(AfMin-AfAvg))); if(ipD>0)h1frq->Fill(1./(grDev->GetY()[ipD] - grDev->GetY()[ipD-1])); ipD++; } grDev->Fit("pol1","Q"); dt2frq=1./grDev->GetFunction("pol1")->GetParameter(1); ddt2frq=dt2frq*(grDev->GetFunction("pol1")->GetParError(1)/grDev->GetFunction("pol1")->GetParameter(1)); delete grtmp; ipD=0; MSRMS=8; TGraph *grtem=new TGraph(2*MSRMS-1); for(Int_t ib=MSRMS; ibGetN()-MSRMS; ib++){ Afsum=0; ipt=0; for(Int_t is=ib-MSRMS; isGetY()[is]; grtem->SetPoint(ipt,ipt,grfft->GetY()[is]); ipt++;} R=(2*MSRMS-1)*grfft->GetY()[ib]/Afsum; rms00=TMath::RMS(grtem->GetN(),grtem->GetY()); if(R>Thresh)continue; dRsq=R-1; grdev->SetPoint(ipD,ipD+1,grfft->GetX()[ib]); grdev->SetPointError(ipD,0,1/dRsq); ipD++; } grdev->Fit("pol1","Q"); Dt2frq=1./grdev->GetFunction("pol1")->GetParameter(1); dDt2frq=dt2frq*(grdev->GetFunction("pol1")->GetParError(1)/grdev->GetFunction("pol1")->GetParameter(1)); h1dt2frq=h1frq->GetBinCenter(h1frq->GetMaximumBin()); fEntries=h1frq->GetMaximum()/h1frq->GetEntries(); TF1 *fgcos=new TF1("fgcos","[0]*exp(-(x-[1])*(x-[1])/([2]*[2]))+[3]*cos([4]*x+[5])",fMin,fMax); grfft->GetXaxis()->SetRangeUser(fMin,fMax); Float_t Afft=0.5*TMath::MaxElement(grfft->GetN(),grfft->GetY()); Float_t xAfft=grfft->GetX()[TMath::LocMax(grfft->GetN(),grfft->GetY())]; fgcos->FixParameter(0,Afft); fgcos->FixParameter(1,xAfft); fgcos->FixParameter(2,0.05); fgcos->FixParameter(3,Afft); fgcos->FixParameter(4,TMath::TwoPi()/0.03); grfft->Fit("fgcos","BRQ"); fgcos->ReleaseParameter(0); fgcos->ReleaseParameter(1); grfft->Fit("fgcos"); fgcos->ReleaseParameter(4); grfft->Fit("fgcos"); fgcos->ReleaseParameter(3); grfft->Fit("fgcos"); fgcos->ReleaseParameter(2); grfft->Fit("fgcos"); if(LDraw){grfft->Draw("al"); gPad->SetGrid();} fffit=1000*TMath::TwoPi()/fgcos->GetParameter(4); printf("f0=%g+/-%g %g+/-%g h1f0=%g fE=%g dt(D,R) from ffit=%g ns\n",dt2frq,ddt2frq,Dt2frq,dDt2frq,h1dt2frq,fEntries,fffit); delete grDev, grdev, grtmp, h1frq, fgcos; } inline Float_t getXCZ(const char *cInfo, TGraph *grA, TGraph *grB, Float_t nsOffSet, Float_t &dotNrm2, Float_t &ASumApNns, Float_t &ASumBpNns, Float_t &ASumA, Float_t &ASumB){ Int_t ibA, ibB, ib0A, ib0B; Int_t nbNnsA=nsOffSet/(grA->GetX()[1]-grA->GetX()[0]); Int_t nbNnsB=nsOffSet/(grB->GetX()[1]-grB->GetX()[0]); Int_t nbA=grA->GetN(); Int_t nbB=grB->GetN(); Int_t ibmaxA=TMath::LocMax(nbA,grA->GetY()); Int_t ibmaxB=TMath::LocMax(nbB,grB->GetY()); Int_t ibminA=TMath::LocMin(nbA,grA->GetY()); Int_t ibminB=TMath::LocMin(nbB,grB->GetY()); ib0A=ibmaxA; if(fabs(grA->GetY()[ibminA])>grA->GetY()[ibmaxA])ib0A=ibminA; ib0B=ibmaxB; if(fabs(grB->GetY()[ibminB])>grB->GetY()[ibmaxB])ib0B=ibminB; //line up two TGraphs: if(nbA!=nbB)printf("different binning in getXCZ of two TGraphs: grA->GetN=%d / grB->GetN=%d / dtA=%g dtB=%g\n",nbA,nbB,grA->GetX()[1]-grA->GetX()[0],grB->GetX()[1]-grB->GetX()[0]); ASumA=0; ASumB=0; ASumApNns=0; ASumBpNns=0; // grA->Print("all"); grB->Print("all"); abort(); for(Int_t ib=0; ibGetY()[ib]); if(ibGetY()[ib]); } for(Int_t ib=0; ibGetY()[ib]); if(ibGetY()[ib]); } Float_t dot=0; for(Int_t ib=ib0A-nbNnsA; ibgrA->GetN())continue; if(ib+ib0B-ib0A<0||ib+ib0B-ib0A>grB->GetN())continue; dot+=grA->GetY()[ib]*grB->GetY()[ib+ib0B-ib0A]; } dotNrm2=dot/(ASumA*ASumA*ASumB*ASumB); printf("%s nbNnsA=%d nbNnsB=%d dot=%g dotNrm1=%g ib0A=%d ib0B=%d tMaxA=%g tMaxB=%g ASumA=%g ASumB=%g +NnsA=%g +NnsB=%g dotNrm2=%g\n",cInfo,nbNnsA,nbNnsB,dot,dot/(ASumA*ASumB),ib0A,ib0B,grA->GetX()[ib0A],grB->GetX()[ib0B],ASumA,ASumB,ASumApNns,ASumBpNns,dotNrm2); return dot/(ASumA*ASumB); } inline TGraph *grGenerateMCWfFromHitTime(Float_t tHitns, Int_t nsample, Float_t timebasens, Float_t rmsVoltagemV, Float_t SNRHit){ Int_t ibinHit=tHitns/timebasens; TGraph *grtmp=new TGraph(nsample); for(Int_t is=0; isSetPoint(is,is*timebasens,gRandom->Gaus(0,rmsVoltagemV)); if(abs(is-ibinHit)>2)continue; grtmp->SetPoint(is,is*timebasens,gRandom->Gaus(0,rmsVoltagemV)+SNRHit*rmsVoltagemV); } return grtmp; } //Add two TH1's with different weights and calculate chisquared inline TF1 *gr2TF1(TGraph *gr, Float_t xmin, Float_t xmax){TF1 * ftmp=new TF1("ftmp",[&](double*x, double *p){return p[0]*gr->Eval(x[0]); },xmin,xmax,1); return ftmp;} inline TF1 *TH12TF1(TH1 *h0, TH1 *h1, Float_t xmin, Float_t xmax){TF1 *ftmp=new TF1("ftmp",[&](double*x, double *p){return p[0]*h0->GetBinContent(h0->FindBin(x[0]))+p[1]*h1->GetBinContent(h1->FindBin(x[0])); },xmin,xmax,1); return ftmp;} void loadTF1(){ fLattenVz=new TF1("fLattenVz","1974.08+0.0281294*x+-0.00049572*x*x+-9.97253e-08*x*x*x",-2850,0); fsinCWX=new TF1("fsinCWX","[0]*cos([1]*x+[2])"); fEllipse=new TF2("fEllipse","[0]*(x-[1])*(x-[1])/[2]+[3]*(y-[4])*(y-[4])/[2]"); fEllipse->SetParNames("Ax","x0","sigXY","Ay","y0"); fgp1=new TF1("fgp1","gaus(0)+pol1(3)"); fgp1->SetParName(0,"Agauss"); fgp1->SetParName(1,"Mean"); fgp1->SetParName(2,"FWHM"); fgp1->SetParName(3,"pol0"); fgp1->SetParName(4,"linslope"); fgp1->SetLineColor(kYellow); // TF1 *f1dStep=new TF1("f1dStep","[2]+(x>[0]&&x<[1])*[3]",xmin,xmax); f2Box=new TF1("f2Box","[0]+([1]-[0])*(fabs([2]-x)<[3])+([4]-[0])*(fabs([2]+[5]-x)<[3])"); f2Box->SetParNames("A0","A1","xpk1","W","A2","dM"); fdubgp0=new TF1("fdubgp0","[5]+[0]*exp(-(x-[1])*(x-[1])/([2]*[2]))+[4]*[0]*exp(-(x-([1]+[3]))*(x-([1]+[3]))/([2]*[2]))"); fdubgp0->SetParNames("A0","M1","W","dM","RA2A1","pol0"); fdubgp1=new TF1("fdubgp1","[6]*x+[5]+[0]*exp(-(x-[1])*(x-[1])/([2]*[2]))+[4]*[0]*exp(-(x-([1]+[3]))*(x-([1]+[3]))/([2]*[2]))"); fdubgp1->SetParNames("A0","M1","W","dM","RA2A1","pol0","pol1"); // TF1 *fdubgp0=new TF1("fdubgp0","gaus(0)+gaus(3)+pol0(6)"); // fdubg->SetParNames("m1","a1","wid1","m2","a2","wid2"); f2sinGalaxy=new TF1("f2sinGalaxy","[0]+[1]*sin([2]*x+[3])",0,1440); f2sinGalaxy->SetParNames("yoff","Amplitude","k","phi0"); f2sinGalaxy->SetParameter(0,54.5); f2sinGalaxy->SetParameter(1,1.5); f2sinGalaxy->FixParameter(2,1.4584e-4); //fit to galactic Amplitude(time) fgp0=new TF1("fgp0","gaus(0)+pol0(3)"); fgp0->SetParName(0,"Agauss"); fgp0->SetParName(1,"Mean"); fgp0->SetParName(2,"FWHM"); fgp0->SetParName(3,"pol0"); fgp0->SetLineColor(kYellow); npoly=new TF1("npoly","((x>-175)*(1.39-(4.6198+13.72*x*0.001)*x*0.001) + (x<-175)*1.78)/[0]",-400,0); //-400,0); npoly->SetParameter(0,1); npoly->SetParName(0,"ctheta"); npoly->SetLineColor(kRed); npoly->GetXaxis()->SetTitle("z-location of ray [km] (z_{Tx}=-.2 km)"); npoly->GetYaxis()->SetTitle("Cumulative integral (/0.2998=total transit time [us])"); nUNL=new TF1("nUNL","1.78-0.463251*exp(0.0182*x)",-3000,0); nexpZ=new TF1("nexpZ","1.78-0.6*exp(0.024*x)",-3000,0); nASim=new TF1("nASim","1.78-0.43*exp(0.0132*x)",-3000,0); nUz=new TF1("nuz","(1.78-0.375*exp(0.01962*x))*(1-1./(1+exp(-(-14.58-x)/8)))+(1.78-0.609*exp(0.017177*x))*1./(1+exp(-(-14.58-x)/8))",-3000,0); nexp=new TF1("nexp","(0.8 + 0.98/(1+exp(30*x*0.001)))/[0]",-400,0); nexp->SetParameter(0,1); nexp->SetLineColor(kGreen); nexp1=new TF1("nexp1","(1 + 0.78/(1+exp(23*x*0.001)))/[0]",-400,0); nexp1->SetLineColor(kBlue); TF1 *nds6=new TF1("nds6","(sqrt((1.+0.915048*(0.917-0.469*exp(14.4*x*0.001)))/(1.-0.457524*(0.917-0.469*exp(14.4*x*0.001)))))/[0]",-400,0); TF1 *nZ2=new TF1("nZ2","(0.94642+0.848419/(1+exp(18.06088*x*0.001)))/[0]",-400,0); nds6->SetLineColor(kViolet); } void loadStyle(){ //need gStyle->ForceStyle(); or gROOT->ForceStyle() to make this stick... gROOT->SetStyle("Default"); // Just for reference, is overridden in the next line gROOT->SetStyle("Plain"); // close to PAW // gStyle->SetOptStat("neMRou"); gStyle->SetPalette(1); // nicer color map than default gStyle->SetOptStat(1112211); gStyle->SetOptStat(1111111); // Show overflow and underflow as well gStyle->SetOptFit(1011); gStyle->SetPadGridX(1); gStyle->SetPadGridY(1); gStyle->SetMarkerStyle(20); // Filled circles gStyle->SetMarkerSize(2); // larger than half a pixel ... gStyle->SetMarkerColor(kBlue); gStyle->SetLineWidth(2); gStyle->SetStatY(1.05); gStyle->SetStatX(0.9); gStyle->SetStatW(0.16); gStyle->SetStatH(0.16); gStyle->SetStatFontSize(0); // gStyle->SetPadColor(kWhite); gStyle->SetStatColor(0); gStyle->SetStatTextColor(1); gStyle->SetTitleColor(1); gStyle->SetTitleTextColor(1); gStyle->SetLabelColor(1,"xyz"); // Show functions in red... gStyle->SetFuncColor(2); // Set the size of the default canvas // 600x500 looks almost square gStyle->SetCanvasDefH(500); gStyle->SetCanvasDefW(600); gStyle->SetCanvasDefX(10); gStyle->SetCanvasDefY(10); // Fonts: I use Helvetica, upright, normal // I sort of wish they had something like "HIGZ portable" of PAW int style_label_font=42; gStyle->SetLabelFont(style_label_font,"xyz"); gStyle->SetLabelSize(0.045,"xyz"); gStyle->SetLabelOffset(0.015,"xyz"); gStyle->SetStatFont(style_label_font); gStyle->SetTitleFont(style_label_font,"xyz"); // axis titles gStyle->SetTitleFont(style_label_font,"h"); // histogram title gStyle->SetTitleSize(0.05,"xyz"); // axis titles gStyle->SetTitleSize(0.05,"h"); // histogram title // gStyle->SetTitleBorderSize(0.0001); // gStyle->SetTitleFillColor(kYellow); gStyle->SetTitleOffset(1.1,"x"); gStyle->SetTitleOffset(1.2,"y"); gStyle->SetStripDecimals(kFALSE); // if we have 1.5 do not set 1.0 -> 1 gStyle->SetTitleX(0.12); // spot where histogram title goes gStyle->SetTitleW(0.78); // width computed so that title is centered TGaxis::SetMaxDigits(5); // restrict the number of digits in labels // Set Line Widths gStyle->SetFrameLineWidth(2); gStyle->SetFuncWidth(2); gStyle->SetHistLineWidth(2); // Set all fill styles to be empty and line styles to be solid gStyle->SetFrameFillStyle(0); gStyle->SetHistFillStyle(1001); gStyle->SetFrameLineStyle(0); gStyle->SetHistLineStyle(0); gStyle->SetTitleStyle(1001); gStyle->SetTitleStyle(0); // sets title box to be transparent gStyle->SetFuncStyle(1); // Set margins -- I like to shift the plot a little up and to the // right to make more room for axis labels gStyle->SetPadTopMargin(0.08); gStyle->SetPadBottomMargin(0.12); gStyle->SetPadLeftMargin(0.14); gStyle->SetPadRightMargin(0.1); // Set Data/Stat/... and other options gStyle->SetOptDate(0); gStyle->SetDateX(0.01); gStyle->SetDateY(0.01); // no supressed zeroes! gStyle->SetHistMinimumZero(kTRUE); // use a pretty palette for color plots gStyle->SetPalette(1,0); //gStyle->SetLabelColor(1,"xyz"); // Force this style on all histograms gROOT->ForceStyle(); } Float_t EvalfFieldAtten(Float_t zi, Float_t zf){ const Int_t MZSTEP=256; Float_t fSignal=1; Float_t dz=fabs(zf-zi)/MZSTEP; Float_t z0=TMath::Max(zi,zf); for(Int_t iz=0; izutcScan0[iScan0]&&time<=utcScan0[iScan0]+450){ iPol=iScan0%2; iaz=iScan0/2; idumZ=(time-utcScan0[iScan0])/150; if(idumZ==0)imVTx=100; else if(idumZ==1)imVTx=300; else if(idumZ==2)imVTx=500; else cout<<"imVTx NOT defined!"<1323030037&&unixTime<1323030487; // run=9981 event=6141 -> 12486 LVP5Dec11[0][0]=unixTime>1323030037&&unixTime<1323030037+150; //0.1 V / azimuth 0 / VPol / 30 seconds per frequency setting LVP5Dec11[0][1]=unixTime>1323030037+150&&unixTime<1323030037+300; //0.3 V LVP5Dec11[0][2]=unixTime>1323030037+300&&unixTime<1323030037+450; //0.5 V LHP05Dec11[0]=unixTime>1323030667&&unixTime<1323031117; //9981/13419 -> 9982/395 LHP5Dec11[0][0]=unixTime>1323030667&&unixTime<1323030667+150; // 0.1 V / azimuth 0 / HPol LHP5Dec11[0][1]=unixTime>1323030667+150&&unixTime<1323030667+300; LHP5Dec11[0][2]=unixTime>1323030667+300&&unixTime<1323030667+450; LVP05Dec11[1]=unixTime>1323031927&&unixTime<1323032377; //9982/ 7942 ->13946 LVP5Dec11[1][0]=unixTime>1323031927&&unixTime<1323031927+150; LVP5Dec11[1][1]=unixTime>1323031927+150&&unixTime<1323031927+300; LVP5Dec11[1][2]=unixTime>1323031927+300&&unixTime<1323031927+450; LHP05Dec11[1]=unixTime>1323032467&&unixTime<1323032917; //9982/14403 -> 9983/1958 LHP5Dec11[1][0]=unixTime>1323032467&&unixTime<1323032467+150; LHP5Dec11[1][1]=unixTime>1323032467+150&&unixTime<1323032467+300; LHP5Dec11[1][2]=unixTime>1323032467+300&&unixTime<1323032467+450; LVP05Dec11[2]=unixTime>1323033997&&unixTime<1323034447; //9983/11014 -> 9983/17337 LVP5Dec11[2][0]=unixTime>1323033997&&unixTime<1323033997+150; LVP5Dec11[2][1]=unixTime>1323033997+150&&unixTime<1323033997+300; LVP5Dec11[2][2]=unixTime>1323033997+300&&unixTime<1323033997+450; LHP05Dec11[2]=unixTime>1323034717&&unixTime<1323035167; //9984/4853 -> 9984/15821 LHP5Dec11[2][0]=unixTime>1323034717&&unixTime<1323034717+150; LHP5Dec11[2][1]=unixTime>1323034717+150&&unixTime<1323034717+300; LHP5Dec11[2][2]=unixTime>1323034717+300&&unixTime<1323034717+450; LVP05Dec11[3]=unixTime>1323035887&&unixTime<1323036337; //9985/8013 -> 9985/15809 LVP5Dec11[3][0]=unixTime>1323035887&&unixTime<1323035887+150; LVP5Dec11[3][1]=unixTime>1323035887+150&&unixTime<1323035887+300; LVP5Dec11[3][2]=unixTime>1323035887+300&&unixTime<1323035887+450; LHP05Dec11[3]=unixTime>1323036427&&unixTime<1323036877; //9985/16374 -> 9986/4672 LHP5Dec11[3][0]=unixTime>1323036427&&unixTime<1323036427+150; LHP5Dec11[3][1]=unixTime>1323036427+150&&unixTime<1323036427+300; LHP5Dec11[3][2]=unixTime>1323036427+300&&unixTime<1323036427+450; } inline TGraph *grRebin(TGraph *gr, Float_t dtnew){ Float_t dtold=gr->GetX()[1]-gr->GetX()[0]; Float_t nbnrebn=dtnew/dtold; TGraph *grtmp=new TGraph(gr->GetN()/nbnrebn-1); Float_t xsum=0; Float_t ysum=0; Int_t ibnnew=0; Int_t ibnold; Int_t nptavg=0; for(Int_t ibn=0; ibnGetN() && ibnnewGetN(); ibn++){ ibnold=ibnnew; ibnnew=ibn/nbnrebn; if(ibnnew==ibnold){nptavg++; xsum+=gr->GetX()[ibn]; ysum+=gr->GetY()[ibn];} else{grtmp->SetPoint(ibnold,xsum/nptavg,ysum); xsum=0; ysum=0; nptavg=0;} } return grtmp; } inline TGraph *grSubp1Subgr(TGraph *gr, Float_t xi, Float_t xf){ TGraph *grtmp=grSubgr(gr,xi,xf,fdum,fdum1,idum,idum1,idum2); TGraph *grtmp1=(TGraph*)grtmp->Clone(); grtmp->Fit("pol1"); TF1 *fp1=grtmp->GetFunction("pol1"); for(Int_t ibn=0; ibnGetN(); ibn++){ // printf("ibn=%d x=%g y=%g fp1=%g\n",ibn,grtmp->GetX()[ibn],grtmp->GetY()[ibn],fp1->Eval(grtmp->GetX()[ibn])); grtmp1->SetPointY(ibn,grtmp->GetY()[ibn]-fp1->Eval(grtmp->GetX()[ibn])); } delete grtmp; return grtmp1; delete fp1; } inline TGraph *grSubp2Subgr(TGraph *gr, Float_t xi, Float_t xf){ TGraph *grtmp=grSubgr(gr,xi,xf,fdum,fdum1,idum,idum1,idum2); TGraph *grtmp1=(TGraph*)grtmp->Clone(); grtmp->Fit("pol2"); TF1 *fp2=grtmp->GetFunction("pol2"); for(Int_t ibn=0; ibnGetN(); ibn++){ // printf("ibn=%d x=%g y=%g fp2=%g\n",ibn,grtmp->GetX()[ibn],grtmp->GetY()[ibn],fp2->Eval(grtmp->GetX()[ibn])); grtmp1->SetPointY(ibn,grtmp->GetY()[ibn]-fp2->Eval(grtmp->GetX()[ibn])); } delete grtmp; return grtmp1; delete fp2; } inline TGraph *grDCXCh(TGraph *gr, Int_t ich){ TGraph *grtmp; TGraph *grXCD; const Float_t MAXDC=64; Int_t ibi=0; Int_t nbins=gr->GetN(); Int_t ibfi=nbins-MSAMPLE_ONEBLOCK; grtmp=new TGraph(MSAMPLE_ONEBLOCK,gr->GetX(),gr->GetY()); fdum=grtmp->GetMean(2); if(fabs(fdum)>MAXDC){ ibi=MSAMPLE_ONEBLOCK; nbins-=MSAMPLE_ONEBLOCK; h2grDCX->Fill(0.,fdum); printf("grDCX excluding first block of Ch %d: Mean=%g\n",ich,fdum); } delete grtmp; grtmp=new TGraph(MSAMPLE_ONEBLOCK,&gr->GetX()[ibfi],&gr->GetY()[ibfi]); fdum=grtmp->GetMean(2); if(fabs(fdum)>MAXDC){ if(NEvTot<64)printf("grDCX excluding last block: Mean=%g\n",grtmp->GetMean(2)); h2grDCX->Fill(1.,fdum); nbins-=MSAMPLE_ONEBLOCK; } grXCD=new TGraph(nbins,&gr->GetX()[ibi],&gr->GetY()[ibi]); delete grtmp; return grXCD; } TGraph *grGetPkSlices(TH2F *h2){ Int_t nbinx=h2->GetNbinsX(); TGraphErrors *grtmp=new TGraphErrors(nbinx); grtmp->SetName(Form("gr_%s",h2->GetName())); Int_t ibmax; for(Int_t ib=0; ibProjectionY("h2_py",ib,ib+1); TH2F *h2_py=(TH2F*)gDirectory->Get("h2_py"); if(h2_py->GetEntries()<=0||h2_py->Integral()<=0)continue; ibmax=h2_py->GetMaximumBin(); h2_py->Fit("gaus"); TF1 *fg=h2_py->GetFunction("gaus"); printf("Histo %s Bin %d Max xbin=%d ypk=%g xpk/xfit=%g/%g del=%g\n",h2->GetName(),ib,ibmax,h2_py->GetMaximum(),h2_py->GetBinCenter(ibmax),fg->GetParameter(1),h2_py->GetBinCenter(ibmax)-fg->GetParameter(1)); grtmp->SetPoint(ib,ib,(fg->GetParameter(1)+h2_py->GetBinCenter(ibmax))/2.); grtmp->SetPointError(ib,0,abs(h2_py->GetBinCenter(ibmax)-fg->GetParameter(1))); } return grtmp; cout<bin ibn0 / grB from bin ibn0->N, then cross-correlate grA x grB //Float_t dtselfcorrelate(TGraph *gr, Int_t ibn0){} inline Float_t Map2pm180deg(Float_t phiAngleInDeg){ if(phiAngleInDeg==-NNN)return phiAngleInDeg; Float_t phiAngleInDeg0=phiAngleInDeg; while(phiAngleInDeg0>=180) phiAngleInDeg0-=360; while(phiAngleInDeg0<-180) phiAngleInDeg0+=360; return phiAngleInDeg0; if(phiAngleInDeg0<-180 || phiAngleInDeg0>180) cout<<" phiAngleInDeg0 OOB="<=360)phiAngleInDeg0-=360; while(phiAngleInDeg0<0)phiAngleInDeg0+=360; return phiAngleInDeg0; if(phiAngleInDeg0<0 || phiAngleInDeg0>=360) cout<<" phiAngleInDeg0 OOB="<=180)theAngleInDeg0=360-theAngleInDeg0; return theAngleInDeg0; } inline Float_t AraRootLocPhi2ZGloPhi(Float_t Aphi){return Map2pm180deg(Aphi+126);} Int_t itxCPcode_rfile(Int_t iA, Int_t iyr, Int_t irunTxCPFile){ if(iyr>2016)return -1; Int_t iTxCPrfin0=-1; if(!LTxCPCodeFile)return -1; if(LInitTxCPCode){ LInitTxCPCode=false; TFile *fin=new TFile(Form("/home/dbesson/src/root/TxlogA%d_%d.root",iA,iyr)); if(fin->IsZombie()){ cout<<"No TxLog file!"<Get("N"); NTxCPCode->BuildIndex("irun"); } idum=NTxCPCode->GetEntryNumberWithIndex(irunTxCPFile); if(idum==-1)return -2; NTxCPCode->GetEntry(idum); iTxCPrfin0=NTxCPCode->GetLeaf("itxcode")->GetValue(); if(iTxCPrfin0==50)iTxCPCh=1; if(iTxCPrfin0==51)iTxCPCh=0; if(iTxCPrfin0==60)iTxCPCh=3; if(iTxCPrfin0==61)iTxCPCh=2; return iTxCPrfin0; } inline Int_t itxcpcode(string stmp){ size_t nstring2event=stmp.find("event"); size_t nstringevent=stmp.find("event")+sizeof("event")-1; size_t nstring2root=stmp.find(".root"); string stmpa=stmp.substr(0,nstringevent); string stmpc=stmp.substr(nstringevent,nstring2root-nstringevent); string stmp2event=stmp.substr(0,nstring2event); // string stmpb=stmp.substr(nstring+5,sizeof(stmp)+1); string sconfigfilestring=stmp2event+"configFile.run"+stmpc+".dat"; cout< D6 V //antennaIceA#I1=1 => D6 H //antennaIceB#I1=0 => D5 V //antennaIceB#I1=1 => D5 H //attIceA#I1 => VPol attenuation //attIceB#I1 => HPol attenuation while(fconfigfilein>>ctmp0){ if(LDebug)cout<Fill(Rx[ich].x,Rx[ich].y,Rx[ich].z,Rx[ich].SNR); h2tmp->Fill(Rx[ich].x,Rx[ich].y,Rx[ich].SNR); } AskewX=h3tmp->GetSkewness(1); dAskewX=h3tmp->GetSkewness(11); AskewY=h3tmp->GetSkewness(2); dAskewY=h3tmp->GetSkewness(12); AskewZ=h3tmp->GetSkewness(3); dAskewZ=h3tmp->GetSkewness(13); AkurtX=h3tmp->GetKurtosis(1); dAkurtX=h3tmp->GetKurtosis(11); AkurtY=h3tmp->GetKurtosis(2); dAkurtY=h3tmp->GetKurtosis(12); AkurtZ=h3tmp->GetKurtosis(3); dAkurtZ=h3tmp->GetKurtosis(13); AxWtAvg=h3tmp->GetMean(1); AyWtAvg=h3tmp->GetMean(2); AzWtAvg=h3tmp->GetMean(3); AWtrsqr=0; for(Int_t ich=0; ichSetParameters(1,AxWtAvg,sqrt(AWtrsqr),1,AyWtAvg); h2tmp->Fit(fEllipse); CCradius=sqrt(fEllipse->GetParameter(1)*fEllipse->GetParameter(1)+ fEllipse->GetParameter(4)*fEllipse->GetParameter(4)); CCAxWt=fEllipse->GetParameter(0); CCAyWt=fEllipse->GetParameter(3); if(!LKeepHisto){ delete h2tmp; delete h3tmp; } } inline Float_t zTxDepth(TNtuple *N, TFile *fSP, const char* cNtName, const char* cHrName, const char* cMinName, Float_t hrYrutc, Float_t minutc){ TNtuple *Nz=(TNtuple*)fSP->Get(cNtName); if(LBuildzIndex){ Nz->BuildIndex(cHrName,cMinName); LBuildzIndex=false; } Nz->GetEntryWithIndex(hrYrutc,minutc); Float_t NzHr=Nz->GetLeaf(cHrName)->GetValue(); if(NzHr!=hrYrutc)return 0; Float_t NzMin=Nz->GetLeaf(cMinName)->GetValue(); if(NzMin!=minutc)return 0; Float_t deltat=NzHr*60 + NzMin - (hrYrutc*60 + minutc); if(deltat>2)return 0; printf("ERRZ: zTxDepth returning zero!!!! utchr=%u deltat=%g z=%g\n",utchour,deltat,Nz->GetLeaf("z")->GetValue()); return 0; } void getPosNegZeroX(TGraph *gr, Int_t ich, Int_t &nPos2Neg, Int_t &nNeg2Pos, Float_t &fSamplePosAvg, Float_t &fSampleNegAvg){ //RCO clock is 100 MHz=>T=10 ns const Float_t RCOClockPeriod=10; f2sinGalaxy->SetParameters(0,TMath::MaxElement(gr->GetN(),gr->GetY()),TMath::TwoPi()/RCOClockPeriod,0); f2sinGalaxy->FixParameter(1,TMath::MaxElement(gr->GetN(),gr->GetY())); f2sinGalaxy->FixParameter(2,TMath::TwoPi()/RCOClockPeriod); gr->Fit("f2sinGalaxy"); f2sinGalaxy->ReleaseParameter(1); f2sinGalaxy->ReleaseParameter(2); gr->Fit("f2sinGalaxy"); RCO_DCOffmV[ich]=f2sinGalaxy->GetParameter(0); RCO_A[ich]=f2sinGalaxy->GetParameter(1); RCO_FRQ[ich]=f2sinGalaxy->GetParameter(2)*GHz2MHz/TMath::TwoPi(); RCO_PHI0[ich]=f2sinGalaxy->GetParameter(3)*TMath::RadToDeg(); nNeg2Pos=0; nPos2Neg=0; fSamplePosAvg=0; fSampleNegAvg=0; Float_t fSamplePosArr[2048]; Float_t fSampleNegArr[2048]; Int_t NSampleNeg=0; Int_t NSamplePos=0; ddum2; for(Int_t ip=1; ipGetN()-1; ip++){ ddum2=ddum1; gr->GetPoint(ip,ddum,ddum1); if(ip<=1)continue; if(ddum2<0 && ddum1<0)NSampleNeg++; if(ddum2>0 && ddum1>0)NSamplePos++; if(ddum2<0 && ddum1>0 && ip>1){ fSampleNegArr[nNeg2Pos]=NSampleNeg; nNeg2Pos++; NSampleNeg=0; } if(ddum2>0 && ddum1<0){ fSamplePosArr[nPos2Neg]=NSamplePos; nPos2Neg++; NSamplePos=0; } } fSamplePosAvg=TMath::Mean(nPos2Neg,fSamplePosArr); //fSamplePos.begin(),fSamplePos.end()); fSampleNegAvg=TMath::Mean(nNeg2Pos,fSampleNegArr); //.begin(),fSampleNeg.end()); } inline void InitializeRZ(){ gRandom->SetSeed(0); iRanSeed0=int(1e6*gRandom->Uniform()); //gRandom->Uniform() essentially the same as gRandom->Rndm() printf("First random number=%g\n",gRandom->Rndm()); TTimeStamp *tz=new TTimeStamp(); printf("Current time is DayOfYear=%d ns=%u\n",tz->GetDayOfYear(),tz->GetNanoSec()); } void SetichMinHitTime(){ ichMinHitTime=-1; Float_t MinHitTime=NNN; for(Int_t ich=0; ichMinHitTime)continue; ichMinHitTime=ich; MinHitTime=Rx[ich].HitTime; } } void ResetRxLVtx(){ ichMinHitTime=-1; for(Int_t ich=0; ich1; ich++){ // grTmplAvgCh[iTmpl][ich]=FFTtools::correlateAndAverage(iMatchTmpl[iTmpl],grTmplAvgN[iTmpl][ich]); sprintf(cgrname,"grTmpl%d_M%d_Ch%d",iTmpl,iMatchTmpl[iTmpl],ich); grTmpl[iTmpl][ich]->SetName(cgrname); grTmpl[iTmpl][ich]->SetTitle(cgrname); TFileOut->Append(grTmpl[iTmpl][ich]); /* grTmplAvgCh[iTmpl][ich]=grCorrAndAvg(iMatchTmpl[iTmpl],grTmplAvgN[iTmpl][ich]); sprintf(ctemp,"grTmplAvgFFT%d_M%d_Ch%d",iTmpl,iMatchTmpl[iTmpl],ich); grTmplAvgCh[iTmpl][ich]->SetName(ctemp); grTmplAvgCh[iTmpl][ich]->SetTitle(ctemp); TFileOut->Append(grTmplAvgCh[iTmpl][ich]); sprintf(cgrname,"grTmplAvg%d_M%d_Ch%d",iTmpl,iMatchTmpl[iTmpl],ich); grTmplAvg[iTmpl][ich]->SetName(cgrname); grTmplAvg[iTmpl][ich]->SetTitle(cgrname); TFileOut->Append(grTmplAvg[iTmpl][ich]); */ } } inline Float_t fgrpmExcursion(TGraph *gr){ Int_t ibmax=TMath::LocMax(gr->GetN(),gr->GetY()); Int_t ibmin=TMath::LocMin(gr->GetN(),gr->GetY()); Float_t ymax=gr->GetY()[ibmax]; Float_t ymin=gr->GetY()[ibmin]; Float_t fsample=0; for(Int_t ibn=0; ibnGetN(); ibn++){ if(fabs(ymin)>ymax) if(gr->GetY()[ibn]<0 && fabs(gr->GetY()[ibn])>ymax)fsample--; if(fabs(ymin)GetY()[ibn]>fabs(ymin))fsample++; } return fsample/gr->GetN(); } inline Bool_t LdtijEv1Ev2(Float_t tHitsEv1[16], Float_t tHitsEv2[16], Float_t dtResolution, Int_t &NMatch, Int_t &NUnMatch, TH1 *htmp, Float_t dtCh1Ch2Ev1Ev2[16]){ Bool_t L=false; NMatch=0; NUnMatch=0; for(Int_t ich=0; ich<16; ich++){ if(tHitsEv1[ich]<-256||tHitsEv1[ich]>1024)continue; if(tHitsEv2[ich]<-256||tHitsEv2[ich]>1024)continue; for(Int_t jch=ich+1; jch<16; jch++){ if(tHitsEv2[jch]<-256||tHitsEv2[jch]>1024)continue; if(tHitsEv2[jch]<-256||tHitsEv2[jch]>1024)continue; dtCh1Ch2Ev1Ev2[ich]=(tHitsEv1[ich]-tHitsEv2[ich])-(tHitsEv1[jch]-tHitsEv2[jch]); // htmp->Fill(dtCh1Ch2Ev1Ev2[ich]); cout<GetN(); i++) { gr->GetPoint(i,x,y); if(!isnormal(x)||!isnormal(y))continue; if(fabs(peakVal)0, then peak of gr1 *after* peak of gr2 inline Float_t dtgr1gr2(TGraph *gr1, TGraph*gr2, Float_t &ACorr, Int_t &idbins){ if(!gr1||!gr2){printf("dtgr1gr2 ERRZ: !gr1||!gr2=> Returning NNN in dtgr1gr2!\n"); return NNN;} if(gr1->GetN()<16||gr2->GetN()<16){printf("dtgr1gr2 ERRZ: gr1->GetN()=%d gr2->GetN()=%d Returning NNN in dtgr1gr2!\n",gr1->GetN(),gr2->GetN()); return NNN;} TGraph *grtmp0=FFTtools::getCorrelationGraph(gr1,gr2); ACorr=getPeakValZ(grtmp0,&ipkbin); if(ipkbin<=0){printf("dtgr1gr2 ERRZ: ipkbin=%d Returning NNN in dtgr1gr2!\n",ipkbin); return NNN;} Float_t deltt0=grtmp0->GetX()[TMath::LocMax(grtmp0->GetN(),grtmp0->GetY())]; Float_t deltat=grtmp0->GetX()[ipkbin]; idbins=deltat/((gr1->GetX()[gr1->GetN()-1]-gr1->GetX()[0])/gr1->GetN()); if(LDebug)printf("dtgr1gr2: ipkbin=%d deltt0=%g deltat=%g\n",ipkbin,deltt0,deltat); delete grtmp0; // delete grtmp1; // delete grtmp2; return deltat; } inline void Compare2Graphs(Int_t icode, Int_t ich, TGraph *gr1, TGraph *gr2){ if(LDebug)printf("Compare2Graphs icode=%d ich=%d\n",icode,ich); const Int_t MAXNDDBINS=8; Int_t ndelbins, ibnpkgr1, ibnpkgr2; Float_t AXCorr, dtXCorr, Apk1, Apk2; if(!gr1||!gr2)return; if(gr1->GetN()<256||gr2->GetN()<256)return; if(grGetBinWid(gr1)!=grGetBinWid(gr2))return; if(gr1->GetN()!=gr2->GetN())return; dtXCorr=dtgr1gr2(gr1,gr2,AXCorr,ndelbins); // ibnpkgr1=TMath::LocMax(gr1->GetN(),gr1->GetY()); ibnpkgr2=TMath::LocMax(gr2->GetN(),gr2->GetY()); Apk1=MaxElpm(gr1,ibnpkgr1); Apk2=MaxElpm(gr2,ibnpkgr2); if(fabs(ndelbins-(ibnpkgr1-ibnpkgr2))>MAXNDDBINS)return; // gr2->Print("all"); cout<=gr1->GetN())continue; Int_t jb=ib-ndelbins; if(jb<0||jb>=gr2->GetN())continue; NCPC->Fill(icode,ndelbins-(ibnpkgr1-ibnpkgr2),ich,ib-ibnpkgr1,AXCorr,Apk1/VrmsCh[ich],Apk2/VrmsCh[ich],gr1->GetY()[ib],gr2->GetY()[jb]); } } inline Float_t getdtTmplMatch(TGraph **gr, TGraph **grCP, Float_t &dtrmsCPxc, Float_t &fracdt16ns){ if(!gr[0] || !grCP[0])return -NNN; TH1F *htmpdtTmplMatch=new TH1F("htmpdtTmplMatch","htmpdtTmplMatch",513,-255.5,255.5); // TGraph *grtmp=(TGraph*)grCPXX->Clone(); // Int_t ibnglo=0; ACPxc=0; Int_t nACPxc=0; Int_t nVPolCPxc=0; Int_t nHPolCPxc=0; Float_t fdtxc; Float_t xshiftgr1gr2; Float_t ACorrgr1gr2; fracdt16ns=0; Int_t nLVtx=0; Int_t ngd=0; Int_t npolX=0; for(Int_t ich=0; ichGetN(),fdum1,ipk2,grCP[ich]->GetN()); if(LDebug)printf("deltat[%d]=%g / VMax d(bins)=%d\n",ich,fdtxc,ipk1-ipk2); htmpdtTmplMatch->Fill(fdtxc); if(isnormal(fdum)&&isnormal(fdum1))ACPxc+=ACorrgr1gr2; else printf("ERRZ! unphysical ACorrgr1gr2!\n"); nACPxc++; } if(fracdt16ns>nACPxc)cout<<"ERRRRRRRRRRRRRRRRRRRRRRRRRRRORRRRR!!!!!"<0){ ACPxc/=nACPxc; fracdt16ns/=nACPxc; fTH1CPxc=fdum/nACPxc; } idum=htmpdtTmplMatch->GetMaximumBin(); fdum=htmpdtTmplMatch->GetMaximum(); dtrmsCPxc=htmpdtTmplMatch->GetRMS(); xshiftCP=htmpdtTmplMatch->GetBinCenter(idum); xshiftgr1gr2=htmpdtTmplMatch->GetBinCenter(idum); // htmpdtTmplMatch->Print("all"); printf("getdtPolX: fdtxc=%g xshiftgr1gr2=%g nLVtx=%d ngd=%d npolX=%d nACPxc=%d ACPxc=%g nVPol=%d nHPol=%d dtrms=%g fTH1=%g dt=%g\n",fdtxc,xshiftgr1gr2,nLVtx,ngd,npolX,nACPxc,ACPxc,nVPolCPxc,nHPolCPxc,dtrmsCPxc,fTH1CPxc,htmpdtTmplMatch->GetXaxis()->GetBinCenter(idum)); delete htmpdtTmplMatch; return xshiftgr1gr2; // delete grtmp; //get rms of dt's of correlation graphs!!!!!! } inline Float_t dAgr1gr2(TGraph *gr1, TGraph*gr2){ if(!gr1||!gr2){printf("ERRZ: Returning NNN in dtgr1gr2!\n"); return NNN;} Float_t VMax1=TMath::MaxElement(gr1->GetN(),gr1->GetY()); Float_t VMin1=TMath::MinElement(gr1->GetN(),gr1->GetY()); Int_t ibVMax1=TMath::LocMax(gr1->GetN(),gr1->GetY()); Int_t ibVMin1=TMath::LocMin(gr1->GetN(),gr1->GetY()); Float_t VMax2=TMath::MaxElement(gr2->GetN(),gr2->GetY()); Float_t VMin2=TMath::MinElement(gr2->GetN(),gr2->GetY()); Int_t ibVMax2=TMath::LocMax(gr2->GetN(),gr2->GetY()); Int_t ibVMin2=TMath::LocMin(gr2->GetN(),gr2->GetY()); Float_t ASNR1=(VMax1-VMin1)/gr1->GetRMS(2); Float_t ASNR2=(VMax2-VMin2)/gr2->GetRMS(2); // printf("VMax1=%g ibVMax1=%d VMin1=%g ibVMax1=%d ASNR1=%g / VMax2=%g ibVMax2=%d VMin2=%g ibVMax2=%d ASNR2=%g\n",VMax1,ibVMax1,VMin1,ibVMin1,ASNR1,VMax2,ibVMax2,VMin2,ibVMin2,ASNR2); if(abs(ibVMax2-ibVMin2)>16)return -1; if(abs(ibVMax1-ibVMin1)>16)return -1; if(ASNR1<4||ASNR2<4)return -1; return fabs(ASNR1-ASNR2)/(ASNR1+ASNR2); } inline Float_t XCgrAnChgrBnCh(TGraph **grA, TGraph **grB, Int_t NChXC){ Float_t XCAB=0; Int_t ipkbin, ipkbnA, ipkbnB; for(Int_t ich=0; ichGetX()[ipkbin]; delete grtmp0; } XCAB/=NChXC; return XCAB; } inline Float_t dAgrgr(TGraph **gr1, TGraph **gr2){ Float_t fA; TH1F *htmpdAgrgr=new TH1F("htmpdAgrgr","htmpdAgrgr",100,0,1.); for(Int_t ich=0; ichFill(dAgr1gr2(gr1[ich],gr2[ich])); } Float_t delA=htmpdAgrgr->GetMean(1); if(htmpdAgrgr->GetEntries()==0)delA=-1; Float_t rmsA=htmpdAgrgr->GetRMS(1); delete htmpdAgrgr; return delA; } TGraph *grSumgrA2grB(TGraph *grA, TGraph *grB, Float_t dtA2B){ TGraph *grSum=(TGraph*)grB->Clone(); Int_t nbinAwrtB=dtA2B/(grA->GetX()[1]-grA->GetX()[0]); Int_t nbmax=TMath::Min(grA->GetN(),grB->GetN()); for(Int_t ib=0; ibgrB->GetN()){ grSum->SetPoint(ib,grB->GetX()[ib],0); continue;} if(ib+nbinAwrtB>=0&&ib+nbinAwrtB=0 && ib-nbinAwrtBSetPoint(ib,grB->GetX()[ib],grA->GetY()[ib+nbinAwrtB]+grB->GetY()[ib]); // else grSum->SetPoint(ib,grB->GetX()[ib],0); } return grSum; } void PrintEvtInfo(char *cinfo){ printf("%s / EvInfo: run=%d/ieventNumber=%d NEvTot=%d tUs=%g PH=%g PV=%g nFitVtx=%d nFitVTX=%d nHitsV=%d nHitsH=%d trigCode=%d\n",cinfo,irunNumber,ieventNumber,NEvTot,unixTimeUs,HPolPower,VPolPower,nFitVtx,nFitVTX,nhitsV,nhitsH,trigCode); for(Int_t ich=0; ichGetN()!=gr2->GetN()){ if(LDebug)printf("gr1->GetN()=%d != gr2->GetN()=%d\n",gr1->GetN(),gr2->GetN()); L=false; } Float_t timeBase1=gr1->GetX()[1]-gr1->GetX()[0]; Float_t timeBase2=gr2->GetX()[1]-gr2->GetX()[0]; if(timeBase1!=timeBase2){ if(LDebug)printf("timeBase1=%g != timeBase2=%g\n",timeBase1,timeBase2); L=false; } return L; } TGraph *grCorrAndAvgB2A(TGraph *grAZ, TGraph *grB, Bool_t LCheckBins){ if(LCheckBins){ if(!Lgr1gr2Nbinstime(grAZ,grB)){ if(LDebug)cout<<"grCorrAndAvgB2A nbinsA="<GetN()<<" nbinsB="<GetN()<<" RETURNING!"<Clone(); Int_t numPoints=grA->GetN(); Double_t *timeVals= grA->GetX(); Double_t *safeTimeVals = new Double_t[numPoints]; Double_t *sumVolts = new Double_t [numPoints]; for(int i=0;iGetN()GetN(); TGraph *grCorAB = FFTtools::getCorrelationGraph(grA,grB); Int_t peakBin = FFTtools::getPeakBin(grCorAB); // Double_t *deltaTVals=grCorAB->GetX(); // cout << peakBin << "\t" << grCorAB->GetN() << endl; Int_t offset=peakBin-(grCorAB->GetN()/2); nbOffsetgrAXgrBCh=offset; h1nbOffset->Fill(offset); // cout << deltaTVals[peakBin] << "\t" << safeTimeVals[offset] << endl; dtOffsetgrAXgrBCh=grCorAB->GetX()[peakBin]; Double_t *aVolts = grA->GetY(); Double_t *bVolts = grB->GetY(); for(int ind=0;ind=0 && bIndexClone(); Int_t numPoints=grA->GetN(); Double_t *timeVals= grA->GetX(); Double_t *safeTimeVals = new Double_t[numPoints]; Double_t *sumVolts = new Double_t [numPoints]; for(int i=0;iGetN()GetN(); // TGraph *grCorAB = FFTtools::getCorrelationGraph(grA,grB); Int_t peakBin = FFTtools::getPeakBin(grCorAB); cout << deltaTVals[peakBin] << "\t" << safeTimeVals[offset] << endl; dtOffsetgrAXgrBCh=grCorAB->GetX()[peakBin]; idum=grA->GetN()-1; Int_t offset=(dtOffsetgrAXgrB[ich]-dtOffsetgrAXgrB[ichSNRMax])/(grA->GetX()[idum]-grA->GetX()[0])/grA->GetN(); //nbinsoff=dtoff/(time/bin) if(offset!=0)printf("B2A_0 ich=%d offset=%d grA->GetN=%d grB->GetN=%d\n",ich,offset,grA->GetN(),grB->GetN()); Double_t *aVolts = grA->GetY(); Double_t *bVolts = grB->GetY(); for(int ind=0;ind=0 && bIndexFill(nHitMatch,nHitNoMatch); if(nHitNoMatch*4>nHitMatch)continue; //1/4 non-overlapping hits // idum=h1TmplUs->FindBin(abs(500000-unixTimeUs)); if(h1TmplUs->GetBinContent(idum)>0)LNewTmpl=false; dtTmplMatch=getdtTmplMatch(grVttmp,grTmpl[iTmpl],dtrmsTmplMatch,frac16ns); //find time correlation dATmplMatch=dAgrgr(grVttmp,grTmpl[iTmpl]); //find A correlation printf("dAgrgr=%g dtTmplMatch=%g / frac16ns=%g / rms=%g for Match to template %d\n",dATmplMatch,dtTmplMatch,frac16ns,dtrmsTmplMatch,iTmpl); h2dtrmsVdA->Fill(dATmplMatch,dtrmsTmplMatch); if(frac16ns>=0.5)LNewTmpl=false; if(dtrmsTmplMatchFill(delATmplMin,dtrmsTmplMin); if(dtrmsTmplMinClone(); // if(Lgr1Yequalgr2Y(grTmpl[iBestTmpl][ich],grTmpl1[iBestTmpl][ich]))printf("ERRZ: grTmpl==grTmpl1\n"); // if(Lgr1Yequalgr2Y(grTmpl[iBestTmpl][ich],grTmplAvg[iBestTmpl][ich]))printf("ERRZ: grTmpl==grTmplAvg\n"); } iMatchTmpl[iBestTmpl]++; h2TmplnoVevno->Fill(iBestTmpl,NEvTot); } if(LNewTmpl){ nTotTmpl++; h1TmplUs->Fill(abs(500000-unixTimeUs)); if(nTmplClone(); // grTmpl1[nTmpl][ich]=(TGraph*)grVttmp[ich]->Clone(); // grTmplAvg[nTmpl][ich]=(TGraph*)grVttmp[ich]->Clone(); } } } return LNewTmpl; } inline void GenNewTemplate(TGraph **grtst){} inline Int_t getRunFromFileNameString(string stmpstring){ idum=-1; Int_t nrunchars=stmpstring.find(".root")-(stmpstring.find("event")+5); if(nrunchars<=0)return -1; string srunString=stmpstring.substr(stmpstring.find("event")+5,nrunchars); stringstream(srunString)>>idum; return idum; } inline void OrderEntries(TTree *eventTree, Int_t ievtypeCP, Int_t &ievti, Int_t &ievtf){ Long64_t *iptEntry2EvA; //https://root.cern.ch/doc/master/classTTreeIndex.html // Long64_t *iptEv2EntryA; //https://root.cern.ch/doc/master/classTTreeIndex.html Int_t nTotEntries=eventTree->GetEntries(); eventTree->BuildIndex("unixTime","timeStamp"); TTreeIndex *I=(TTreeIndex*)eventTree->GetTreeIndex(); iptEntry2EvA=I->GetIndex(); // for(Int_t ie=0; ieGetEntry(ie); iptEntry2EvA.push_back(int(eventTree->GetLeaf("eventNumber")->GetValue())); iptEv2EntryA.push_back(iptEntry2EvA[ie]);} cout<<"Sorted "<Draw("eventNumber","timeStamp<1000","goff"); else eventTree->Draw("eventNumber","1","goff"); ievti=TMath::MinElement(eventTree->GetEntries(),eventTree->GetV1()); ievtf=TMath::MaxElement(eventTree->GetEntries(),eventTree->GetV1()); TLeaf* time=eventTree->GetLeaf("unixTime"); TLeaf *timeUs=eventTree->GetLeaf("timeStamp"); for(Int_t i=0; iGetEntry(i); //should not point to event number; should point to the number of this event in the list! cout<GetValue()+(timeUs->GetValue())*nano<ResetBranchAddresses(); } inline void aOrderEntries(TTree *eventTree){ Int_t nTotEntries=eventTree->GetEntries(); for(Int_t ie=0; ieGetEntry(ie); ievnoV[ie]=eventTree->GetLeaf("eventNumber")->GetValue(); utcV1d[ie]=eventTree->GetLeaf("unixTime")->GetValue()+(eventTree->GetLeaf("unixTimeUs")->GetValue())/mega; } TMath::Sort(nTotEntries,ievnoV,iOrderedEntries,false); TMath::Sort(nTotEntries,utcV1d,iptEv2utc,false); cout<<"Sorted "<GetEntry(iOrderedEntries[ie]); if(LDebug)cout<GetLeaf("eventNumber")->GetValue()<<" "<GetLeaf("unixTime")->GetValue()<Draw("Entry$>>hEvents","eventNumber","goff"); Double_t *ientryV=eventTree->GetV1(); Double_t *evnoV=eventTree->GetW(); Int_t ientryVa[MEVSORT]; TMath::Sort(nTotEntries,evnoV,ientryVa,false); TH1F *hutc; TH1F *hutc1; eventTree->Draw("unixTime+1e-6*unixTimeUs>>hutc"); Int_t iminbin=hutc->FindFirstBinAbove(0); //hutc->GetMinimumBin(); Int_t imaxbin=hutc->FindLastBinAbove(0); //MaximumBin(); Double_t utci=hutc->GetBinCenter(iminbin); Double_t utcf=hutc->GetBinCenter(imaxbin); cout<>hutc1","unixTime","goff"); //-utci Double_t *ientryV1=eventTree->GetV1(); Double_t *utcV1=eventTree->GetW(); Int_t ientryVb[MEVSORT]; TMath::Sort(nTotEntries,utcV1,ientryVb,false); delete hutc1; delete hEvents; // eventTree->Reset(); } inline Bool_t LGoodDDA(Int_t ich){ Int_t ih=ich%4; PDDA[ih]=(Rx[ih].VMax+Rx[ih+4].VMax+Rx[ih+8].VMax+Rx[ih+12].VMax); return PDDA[ih]<2*VMAXMAX; } inline Bool_t LEvCutsFile(Int_t ievtype){ if(utcCutsMin<=0 && utcCutsMax<=0)return false; Bool_t LEvCut=true; // if(ievtype==1)LEvCut=LCP; else LEvCut=!LCP; if(utcCutsMin>0&&utcCutsMax>0) if(unixTimeutcCutsMax)LEvCut=false; if(LDebug)cout<>ddum>>fdum>>fdum1>>fdum2){ TxCoords_utc.push_back(ddum); TxCoords_r.push_back(fdum); TxCoords_phi.push_back(fdum1); TxCoords_z.push_back(fdum2); cout<>Rx[ich].LVtxCutsFile; printf("Rx[%d].LVtxCutsFile=%d\t",ich,Rx[ich].LVtxCutsFile);} for(Int_t ich=0; ich>ipttmp[ich]; cout<<"Cuts file ch "<>fLoPass[ich]; cout<>fHiPass[ich]; cout<fHiPass0[ich])fHiPass[ich]=fHiPass0[ich];} cout<Fill(fLoPass[ich],ich); h2fLoPassfHiPass->Fill(fHiPass[ich],ich); if(Rx[ich].LVtx0)h2RxUseMap->Fill(ich,iptRxAraRoot2Rxtrue[ich]); } if(!InFileCuts)return; // printf("xntvar 0 fmin=%g/fmax=%g\n",CutVarMin[0],CutVarMax[0]); Int_t ivar; Int_t iVetoEv; InFileCuts>>LDum>>iVetoEv>>MAXEVDRAW0>>MAXEVDRAW>>utcCutsMin>>utcCutsMax; if(abs(iVetoEv)==1)LVetoEv=true; cout<<"LDumGenTmpl="<Print(); utcDayString=datime->AsSQLString(); // cout<GetEntries()<=0)return; idum=N->Draw(cProj,cCut,"goff"); TH1F *htmpZ=(TH1F*)gDirectory->Get("htmpZ"); if(idum<=0||htmpZ->GetEntries()==0||htmpZ->GetMean()==0)return; idum1=htmpZ->GetMaximumBin(); printf("<%s>=%g+/-%g xPk=%g/fPk=%g NPassCuts=%d/Nentry=%d\n",cProj,htmpZ->GetMean(),htmpZ->GetRMS(1),htmpZ->GetBinCenter(idum1),htmpZ->GetMaximum()/htmpZ->GetEntries(),idum,int(htmpZ->GetEntries())); delete htmpZ; } inline Int_t signof(float a) { return (a == 0) ? 0 : (a<0 ? -1 : 1); } /* z1\ \ \ \ z2 z1-z2=hypothenuse cdt=(z1-z2)*sin(theta) */ inline Bool_t LSamexy(Int_t ich, Int_t jch){ Bool_t L2ChSamexy=fabs(Rx[ich].x-Rx[jch].x)<0.1 && fabs(Rx[ich].y-Rx[jch].y)<0.1; Bool_t LSameHole=Rx[ich].ihole==Rx[jch].ihole; if(LDebug) if((L2ChSamexy && !LSameHole) || (LSameHole && !L2ChSamexy))printf("ERRZ: LSamexy(%d,%d)=%d BUT LSameHole=%d\n",ich,jch,L2ChSamexy,LSameHole); return L2ChSamexy&&LSameHole; } //thecog~czAvg+90 inline void aGetphitheHat(){ //first find cartesian cog of hits used: phicog=-NNN; thecog=-NNN; Int_t nhitsphithehat=0; Float_t rcogx=0; Float_t rcogy=0; Float_t rcogz=0; Float_t ctcog=0; Int_t irx=0; for(Int_t ich=0; ich999 && abs(Rx[ich].HitTime)999 && abs(Rx[ich].HitTime)Fill(phicogX[ichX]-phicog,ichX); h2dthecogVCh->Fill(thecogX[ichX]-thecog,ichX); } inline void getRdr2dt(){ Float_t Rdr2dt0; for(Int_t ich=0; ich<16; ich++){ if(!Rx[ich].LVtx)continue; for(Int_t jch=ich+1; jch<16; jch++){ if(!Rx[jch].LVtx)continue; Rdr2dt0=dxyzRxiRxj[ich][jch]/(Rx[ich].HitTime-Rx[jch].HitTime); } } } inline Float_t nIcez(Float_t z1, Float_t z2){ Float_t zAvg=(z1+z2)/2.; if(zAvg>0)zAvg*=-1; return 1.325+0.438*(1.-exp(0.0132*zAvg)); } //NB-CANNOT get azimuth! two hits alone cannot restrict the source to a single plane! inline Float_t Azimij(Int_t ich, Int_t jch){ // Float_t yRxct, xRxct; if(fabs(Rx[ich].z-Rx[jch].z)>1.6)return -NNN; //10 cm in z Float_t philocal=TMath::RadToDeg()*atan2(Rx[ich].y-Rx[jch].y,Rx[ich].x-Rx[jch].x); Float_t tHiti=Rx[ich].HitTime; Float_t tHitj=Rx[jch].HitTime; Float_t n0=nIcez(Rx[ich].z00,Rx[jch].z00); Float_t szxy=sLightAir*(Rx[ich].HitTime-Rx[jch].HitTime)/nIcez(Rx[ich].z00,Rx[jch].z00)/dxyzRxiRxj[ich][jch]; //tan(theta)=x Float_t szx=sLightAir*(tHiti-tHitj)/n0/(Rx[ich].x-Rx[jch].x); if(abs(szx)>1){ printf("%sWarning: |szx|=%g >1!%s\n",KRED,szx,KNRM); return -9999;} Float_t szy=sLightAir*(tHiti-tHitj)/n0/(Rx[ich].y-Rx[jch].y); if(abs(szy)>1){ printf("%sWarning: |szy|=%g >1!%s\n",KRED,szy,KNRM); return -9999;} Float_t cosx=90+asin(szx)*TMath::RadToDeg(); Float_t cosy=90+asin(szy)*TMath::RadToDeg(); if(abs(cosy-90)<10){ if(LDebug)printf("ich=%d jch=%d dxyz=%g dz=%g t1=%g t2=%g dt=%g philoc=%g n=%g cosx=%g cosy=%g phi+cosx=%g phisim=%g thesim=%g\n",ich,jch,dxyzRxiRxj[ich][jch],Rx[ich].z00-Rx[jch].z00,Rx[ich].dtSimTx,Rx[jch].dtSimTx,Rx[ich].HitTime-Rx[jch].HitTime,philocal,nIcez(Rx[ich].z00,Rx[jch].z00),cosx,cosy,cosx+philocal,simVtx[1],simVtx[2]); return cosx+philocal; } else return -99999; } //Hit in Rx1 at t1, hit in Rx2 at t2. True dtime=(Rx1-cable_delay1)-(Rx2-cable_delay2)=(Rx1-Rx2)-(cable_delay1-cable_delay2); cos(theta)=(c/n)/(deltaz/deltat) /* Rx1 |\ | \ | \ dz |the\ | \ | \. | _- |_ - ct=opposite side = time interval between hits in T1 (top) vs. T2 (bottom) want 90-the: sin(the)=(c/n)*(T1-T2)/dz theta'=90-asin(the) */ //formerly in terms of czHitTime - changed 4April19 inline Float_t czij(Int_t ich, Int_t jch, Int_t ipulse){ Float_t tHiti, tHitj; const Float_t smrcz=0.04; if(!LSamexy(ich,jch) || (Rx[ich].iPol!=Rx[jch].iPol))return -NNN; //avoid HV pairs if(ipulse==0){tHiti=Rx[ich].HitTime; tHitj=Rx[jch].HitTime;} if(ipulse==1){tHiti=Rx[ich].tp1NSig; tHitj=Rx[jch].tp1NSig;} if(ipulse==2){tHiti=Rx[ich].tp2NSig; tHitj=Rx[jch].tp2NSig;} if(ipulse==3){tHiti=Rx[ich].tSlope; tHitj=Rx[jch].tSlope;} if(ipulse==4){tHiti=-dtXCTV[ich]/2; tHitj=dtXCTV[ich]/2;} if(tHiti==tHitj)return -999999; if(tHiti<-200 || tHitj<-200)return -99999; Float_t acz=signof(Rx[ich].z-Rx[jch].z)*(sLightAir*(tHiti-tHitj)/nIcez(Rx[ich].z00,Rx[jch].z00))/dxyzRxiRxj[ich][jch]; Float_t sz0=sLightAir*(tHiti-tHitj)/nIcez(Rx[ich].z00,Rx[jch].z00)/(Rx[ich].z-Rx[jch].z); if(LDebug)printf("czij: NEvTot=%d Rx[%d].z00=%g Rx[%d].z00=%g dxyzRxiRxj=%g n=%g tHit1=%g tHit2=%g\n",NEvTot,ich,Rx[ich].z00,jch,Rx[jch].z00,dxyzRxiRxj[ich][jch],nIcez(Rx[ich].z00,Rx[jch].z00),tHiti,tHitj); if(LDebug)cout<<"/ti="<1!%s\n",KYEL,sz0,KNRM); return -9999; } // sz0=gRandom->Uniform(-1,1); Float_t cosloc=90+asin(sz0)*TMath::RadToDeg(); //VERIFIED!!!! 19APR19 Float_t cosloc1=90+asin(fabs(sz0))*TMath::RadToDeg(); if(sz0<0)cosloc1=180-cosloc1; if(!Leqppm(cosloc,cosloc1))printf("%s ERRZ: sz0=%g cosloc=%g cosloc1=%g %s\n",KYEL,sz0,cosloc,cosloc1,KNRM); return cosloc; } inline void getAvgcz(){ Float_t dxyz, AngleDeg0, AngleDeg1, AngleDeg2, AngleDeg3, AngleDegaz; Float_t sz0=-NNN; Float_t acz=-NNN; czRMSEv=-NNN; czAvgEv=-NNN; for(Int_t iTV=0; iTV<8; iTV++){ AngleDegcz0[iTV]=-NNN; AngleDegcz1[iTV]=-NNN; AngleDegcz2[iTV]=-NNN; AngleDegcz3[iTV]=-NNN; if(iTV>=6)continue; AngleDegAzTV[iTV]=-NNN; AngleDegAzBV[iTV]=-NNN; AngleDegAzTH[iTV]=-NNN; AngleDegAzBH[iTV]=-NNN; } TH1F *htmpcz=new TH1F("htmpcz","htmpcz",360,-90,90); //was 45 bins! for(Int_t ich=0; ichFill(AngleDeg0); if(LDebug)printf("ich=%d/jch=%d / acz=%g sz0=%g AngleDeg=%g\n",ich,jch,acz,sz0,AngleDeg0); } } for(Int_t iAz=0; iAz<6; iAz++){ AngleDegAz0[iAz]=AngleDegAzTV[iAz]; AngleDegAz0[6+iAz]=AngleDegAzBV[iAz]; AngleDegAz0[12+iAz]=AngleDegAzTH[iAz]; AngleDegAz0[18+iAz]=AngleDegAzBH[iAz]; } if(htmpcz->GetEntries()==0){ delete htmpcz; return; } // idum=htmp->GetMaximumBin(); czAvgEv=htmpcz->GetMean(); czRMSEv=htmpcz->GetRMS(); if(LDebug)printf("czAvgEv=%g czRMSEv=%g\n",czAvgEv,czRMSEv); // htmp->Print("all"); delete htmpcz; } inline Int_t Wait(){ cout << " Continue [|q]? "; char x; x=getchar(); if((x == 'q')||(x == 'Q')) return 1; return 0; } inline void Decode9Digits(Int_t i0, Int_t &ir, Int_t &iphi, Int_t &ithe){ ir=i0/1e6; iphi=(i0-1e6*ir)/1e3; ithe=(i0-1e6*ir-1e3*iphi); printf("i0=%d ir=%d / iphi=%d / ithe=%d\n",i0,ir,iphi,ithe); } inline Float_t sinDeg(Float_t argDeg){return sin(TMath::RadToDeg()*argDeg);} inline Float_t cosDeg(Float_t argDeg){return cos(TMath::RadToDeg()*argDeg);} inline void Decode10Digits(Int_t i0, Int_t &ir, Int_t &iphi, Int_t &ithe, Int_t &idtSmr){ ir=i0/1e7; iphi=(i0-1e7*ir)/1e4; ithe=(i0-1e7*ir-1e4*iphi)/10; idtSmr=(i0-1e7*ir-1e4*iphi-ithe*10); printf("i0=%d ir=%d / iphi=%d / ithe=%d / idtSmr=%d\n",i0,ir,iphi,ithe,idtSmr); } inline float ntimexp(float z1, float z2, float dtot){ const float c=TMath::C()*1e-9; //0.2998 m per nanosecond const float A=1.78; const float B=A*-0.35; const float C=0.0132; //16 if input is in km; 0.016 if input is m. float zmax=z2; float zmin=z1; if(zmin>zmax){ zmin=z2; zmax=z1; } float ctheta=fabs(z2-z1)/dtot; if(ctheta==0) ctheta=1.e-9; float ftimexp=0.0; // printf("zmax=%g zmin=%g ctheta=%g c=%g\n",zmax,zmin,ctheta,c); if(zmax<0. && zmin<0.)ftimexp=(A*(zmax-zmin)+(B/C)*(exp(C*zmax)-exp(C*zmin)))/(c * ctheta); else if(zmax>=0. && zmin<0.)ftimexp=(A*(0.-zmin)+(B/C)*(exp(C*0.)-exp(C*zmin))+zmax)/(c * ctheta); else if(zmax>=0. && zmin>=0.)ftimexp=(zmax-zmin)/(c * ctheta); else cout<<" CONDITION NOT COVERED IN NTIMEZ!!!"<meters } //delta_t0 in seconds, not ns!!! Float_t FindzGivenEchoTime(const Float_t deltat_t0){ //first guess: Float_t zn1pt6=-0.5*deltat_t0*TMath::C()/1.6; //depth for refractive index=1.6: d=ct/n, but two-way Float_t zn1pt78=-0.5*deltat_t0*TMath::C()/1.78; //depth for refractive index=1.6: d=ct/n, but two-way Float_t z0, transitTns,zm1,tm1; tm1=9999999; printf("znpt178=%g zn1pt6=%g dtt0=%g\n",zn1pt78,zn1pt6,deltat_t0); Float_t deltat_tns=deltat_t0*1e9; for(z0=zn1pt78; z0>zn1pt6; z0+=(zn1pt6-zn1pt78)/100.){ transitTns=2*ntimexp(z0,0.,z0); if(LDebug)printf("z0=%g transitTns=%g tm1=%g zn1pt6=%g zn1pt78=%g delta_t0=%g dt1=%g dt2=%g\n",z0,transitTns,tm1,zn1pt6,zn1pt78,deltat_tns,tm1-deltat_tns,transitTns-deltat_tns); if(tm1deltat_tns)break; tm1=transitTns; } return z0; } inline Float_t ntimexpPG(Float_t z1, Float_t z2, Float_t dtot){ const Float_t c=2.998e-1; //0.2998 m per nanosecond const Float_t A=1.325+0.438; const Float_t B=-0.438; const Float_t C=0.0132; //16 if input is in km; 0.016 if input is m. Float_t zmax=z2; Float_t zmin=z1; if(zmin>zmax){ zmin=z2; zmax=z1; } Float_t ctheta=fabs(z2-z1)/dtot; if(ctheta==0) ctheta=1.e-9; Float_t ftimexp=0.0; if(zmax<0. && zmin<0.)ftimexp=(A*(zmax-zmin)+(B/C)*(exp(C*zmax)-exp(C*zmin)))/(c * ctheta); else if(zmax>=0. && zmin<0.)ftimexp=(A*(0.-zmin)+(B/C)*(exp(C*0.)-exp(C*zmin))+zmax)/(c * ctheta); else if(zmax>=0. && zmin>=0.)ftimexp=(zmax-zmin)/(c * ctheta); else cout<<" CONDITION NOT COVERED IN NTIMEZ!!!"<meters } //Note that this curve is the integral of n(z), not n(z) directly: //units of distance are km!!!!! inline Float_t ntimepoly(Float_t zshallow, Float_t zdeep, Float_t dxyz){ const Float_t z178=-0.16; Float_t ctheta=(zshallow-zdeep)/dxyz; //{return fabs(((1.3739*z1 - 4.6198*z1*z1/2 - 13.72*z1*z1*z1/3) -(1.3739*z2 - 4.6198*z2*z2/2 - 13.72*z2*z2*z2/3))/(2.998e5*ctheta));} /* {return fabs(((-9.7645 * pow(z1,4) - 7.28567 * pow(z1,3) - 2.6427 * pow(z1,2) + 1.3239 * z1) / (2.998E5 * ctheta)) - (-9.7645 * pow(z2,4) - 7.28567 * pow(z2,3) - 2.6427 * pow(z2,2) + 1.3239 * z2) / (2.998E5 * ctheta));} */ Float_t z1=zshallow; //shallower antenna Float_t z2=TMath::Max(zdeep,z178); // Float_t fdxyz=fabs((z2-z1)/(z20-z1)); Float_t t0=0; if(ctheta>1./mega) t0=fabs(((-9.7645 * (z1*z1*z1*z1) - 7.28567 * (z1*z1*z1) - 2.6427 * (z1*z1) + 1.3239 * z1) / (2.998E5 * ctheta)) - (-9.7645 * (z2*z2*z2*z2) - 7.28567 * (z2*z2*z2) - 2.6427 * (z2*z2) + 1.3239 * z2) / (2.998E5 * ctheta))/nano; else t0=fabs(dxyz*(1.379*z1 - 4.6198*z1*z1/2 - 13.72*z1*z1*z1/3)/2.998E5)/nano; printf("z1=%g / z2=%g / z10=%g / z20=%g dxyz=%g ctheta=%g t0=%g ",z1,z2,zshallow,zdeep,dxyz,ctheta,t0); if(zdeepzmax){ zmin=z2; zmax=z1; } float ctheta=fabs(z2-z1)/dtot; if(ctheta==0)ctheta=1.e-9; float ftimexp=NNN; ftimexp=(A*(zmax-zmin)+(B/C)*(exp(C*zmax)-exp(C*zmin)))/(sLightAir * ctheta); if(false)ftimexp=dtot/sLightAir; /* if(zmax>=0. && zmin<0.) ftimexp=(A*(0.-zmin)+(B/C)*(exp(C*0.)-exp(C*zmin))+zmax)/(sLightAir * ctheta); if(zmax>=0. && zmin>=0.) ftimexp=(zmax-zmin)/(sLightAir * ctheta); if(zmax<0. && zmin>0.) cout<<" CONDITION NOT COVERED IN NTIMEZ!!!"<=SNRxcMin){ if(LDebug)printf("calc_chisq 2: x=%g/y=%g/z=%g Rx[%d].HitTime=%g / Rx[%d].HitTime=%g / TransitTimens[%d]=%g / [%d]=%g / delta=%g\n",x0,y0,z0,ich,Rx[ich].HitTime,jch,Rx[jch].HitTime,ich,TransitTimens[ich],jch,TransitTimens[jch],delta); delta=(TransitTimens[ich]-TransitTimens[jch])-dtxc[ich][jch]; //+Rx[ich].dtNsCorr; //remove dtNsCorr chisquare+=delta*delta; //Rx[ich].hitweight; dtFitResid[ich][jch]=delta; tFitResid[ich]+=delta; tFitResid[jch]+=delta; ncombFit[ich]++; ncombFit[jch]++; nchisq++; if(ich<=7&&jch>=8){ AvgdtHV-=delta; nCombHV++; } } } } } } // for(Int_t ich=0; ich0)dtFitResid[ich]/=ncombFit[ich]; chisquare/=nchisq; //chisq/dof ChiSqTot=chisquare; // if(isnan(chisquare))printf("chisquare/ndof=%g/%g\n",chisquare,ndof); if(nCombHV>0)AvgdtHV/=nCombHV; for(Int_t ich=0; ich0)tFitResid[ich]/=ncombFit[ich]; } xFitSrc=par[0]*cos(par[1]*TMath::DegToRad())*sin(par[2]*TMath::DegToRad()); yFitSrc=par[0]*sin(par[1]*TMath::DegToRad())*sin(par[2]*TMath::DegToRad()); zFitSrc=par[0]*cos(par[2]*TMath::DegToRad()); par[1]=Map2pm180deg(par[1]); // par[2]=ThetaPrime(par[0],par[1],par[2],RxXYZ0[2]); return; } inline void getRxArrayBounds(){ xminRxArray=yminRxArray=zminRxArray=NNN; xmaxRxArray=ymaxRxArray=zmaxRxArray=-NNN; for(Int_t ich=0; ichxmaxRxArray)xmaxRxArray=Rx[ich].x; if(Rx[ich].y>xmaxRxArray)ymaxRxArray=Rx[ich].y; if(Rx[ich].z>xmaxRxArray)zmaxRxArray=Rx[ich].z; if(Rx[ich].xExec("rm /home/dbesson/ph/tem/Vtx*.gif"); NDrawEv0=NDrawEvGif=0; NPFRQBINBNDS->Fill(PowerFrqBinBnds[0],PowerFrqBinBnds[1],PowerFrqBinBnds[2],PowerFrqBinBnds[3],PowerFrqBinBnds[4],PowerFrqBinBnds[5],PowerFrqBinBnds[6],PowerFrqBinBnds[7],PowerFrqBinBnds[8],PowerFrqBinBnds[9]); // TGraph *grPowerFrqBinBnds=new TGraph(MBNDS0,PowerFrqBinBnds); grPowerFrqBinBnds->SetNameAndTitle("grPowerFrqBinBnds","grPowerFrqBinBnds"); if(LUSESPE)MSIGMASPE0=14; ifstream Spice18LogFile("/home/dbesson/spice/SpiceDec18.txt"); Float_t tminSp18Log, zTxSp18Log, daySp18Log, hrSp18Log, minSp18Log; Int_t iptSp18Log=0; while(Spice18LogFile>>daySp18Log>>hrSp18Log>>minSp18Log>>zTxSp18Log){ tminSp18Log=(daySp18Log-1)*24*60+(hrSp18Log-13)*60+minSp18Log; // cout<SetPoint(iptSp18Log,tminSp18Log,zTxSp18Log); iptSp18Log++; } // Float_t zInterpolate=grSpice18LogFile->Eval(524283.); TVirtualFFT::SetTransform(0); loadTF1(); TFile *fth30ph90Exp18=new TFile("/home/dbesson/UD/th30ph90Exp18.root"); grAvgVPol30degZen=(TGraph*)fth30ph90Exp18->Get("AvgVPol"); grAvgHPol30degZen=(TGraph*)fth30ph90Exp18->Get("AvgHPol"); TFile *fth60ph90Exp18=new TFile("/home/dbesson/UD/th60ph90Exp18.root"); grAvgVPol60degZen=(TGraph*)fth60ph90Exp18->Get("AvgVPol"); grAvgHPol60degZen=(TGraph*)fth60ph90Exp18->Get("AvgHPol"); mgrCPAvg=new TMultiGraph("mgrCPAvg","Averaged CP Wf; time (ns); mV"); mgrEVAvg=new TMultiGraph("mgrEVAvg","Averaged EV Wf; time (ns); mV"); for(Int_t idp=0; idpcd(); iStation0=iStation; TRCO=new TTree("TRCO","TRCO"); TRCO->Branch("RCO_DCOffmV",&RCO_DCOffmV,"RCO_DCOffmV[4]/F"); TRCO->Branch("RCO_A",&RCO_A,"RCO_A[4]/F"); TRCO->Branch("RCO_FRQ",&RCO_FRQ,"RCO_FRQ[4]/F"); TRCO->Branch("RCO_PHI0",&RCO_PHI0,"RCO_PHI0[4]/F"); TTVHIT=new TTree("TTVHIT","TTVHIT"); TTVHIT->Branch("fftAvgf",&fftAvgf,"fftAvgf[16]/F"); TTVHIT->Branch("WidtVMax",&WidtVMax,"WidtVMax[16]/F"); TTVHIT->Branch("tHit",&tHitTime,"tHit[20]/F"); TTVHIT->Branch("dtXCTV",&dtXCTV,"dtXCTV[8]/F"); TTVHIT->Branch("AXCTV",&AXCTV,"AXCTV[8]/F"); TTVHIT->Branch("tNSig",&RxtNSig,"tNSig[16]/F"); TTVHIT->Branch("tXCg",&tXCg,"tXCg[16]/F"); TTVHIT->Branch("tSlope",&tSlope,"tSlope[16]/F"); TTVHIT->Branch("ASlope",&ASlope,"ASlope[16]/F"); TTVHIT->Branch("tNSig0",&RxtNSig0Ch,"tNSig0[16]/F"); TTVHIT->Branch("tXCRxHV",&tXCRxHV,"tXCRxHV[8]/F"); TTVHIT->Branch("AXCRxHV",&AXCRxHV,"AXCRxHV[8]/F"); TTVHIT->Branch("iXCRxHV",&iXCRxHV,"iXCRxHV[8]/I"); TTVHIT->Branch("VMaxHit",&VMaxHit,"VMaxHit[20]/F"); TTVHIT->Branch("VMinHit",&VMinHit,"VMinHit[20]/F"); TTVHIT->Branch("VMax2",&VMax2,"VMax2[20]/F"); TTVHIT->Branch("tVMax",&tVMax,"tVMax[20]/F"); TTVHIT->Branch("tVMin",&tVMin,"tVMin[20]/F"); TTVHIT->Branch("tVMaxXCableDelay",&tVMaxXCableDelay,"tVMaxXCableDelay[20]/F"); TTVHIT->Branch("tVMinXCableDelay",&tVMinXCableDelay,"tVMinXCableDelay[20]/F"); TTVHIT->Branch("tVMax2",&tVMax2,"tVMax2[20]/F"); TTVHIT->Branch("VMinMx12",&VMinMx12,"VMinMx12[16]/F"); TTVHIT->Branch("tVMinMx12",&tVMinMx12,"tVMinMx12[16]/F"); TTVHIT->Branch("VrmsCh",&VrmsCh,"VrmsCh[20]/F"); TTVHIT->Branch("Vrms1ev",&Vrms1ev,"Vrms1ev[20]/F"); TTVHIT->Branch("VrmsUB",&VrmsUB,"VrmsUB[20]/F"); TTVHIT->Branch("PrmsCh",&PrmsCh,"PrmsCh[16]/F"); TTVHIT->Branch("TOTCh",&TOTCh,"TOTCh[20]/F"); TTVHIT->Branch("tTH1i",&tTH1i,"tTH1i[16]/F"); TTVHIT->Branch("tTH1f",&tTH1f,"tTH1f[16]/F"); TTVHIT->Branch("tNSigf",&tNSigf,"tNSigf[16]/F"); TTVHIT->Branch("tp1NSig",&tp1NSig,"tp1NSig[16]/F"); TTVHIT->Branch("tm1NSig",&tm1NSig,"tm1NSig[16]/F"); TTVHIT->Branch("tp2NSig",&tp2NSig,"tp2NSig[16]/F"); TTVHIT->Branch("tm2NSig",&tm2NSig,"tm2NSig[16]/F"); TTVHIT->Branch("tp3NSig",&tp3NSig,"tp3NSig[16]/F"); TTVHIT->Branch("tm3NSig",&tm3NSig,"tm3NSig[16]/F"); TTVHIT->Branch("tp4NSig",&tp4NSig,"tp4NSig[16]/F"); TTVHIT->Branch("tm4NSig",&tm4NSig,"tm4NSig[16]/F"); TTVHIT->Branch("Ptp1tm1",&Ptp1tm1,"Ptp1tm1[16]/F"); TTVHIT->Branch("Ptp2tm2",&Ptp2tm2,"Ptp2tm2[16]/F"); TTVHIT->Branch("deltTwinPeaks",&deltTwinPeaks,"deltTwinPeaks[16]"); TTVHIT->Branch("dtTPif",&dtTPif,"dtTPif[16]"); TTVHIT->Branch("RxPower",&RxPower,"RxPower[20]/F"); TTVHIT->Branch("chitSeq",&chitSeq,"chitSeq[256]/C"); TTVHIT->Branch("AngleDegcz0",&AngleDegcz0,"AngleDegcz0[8]/F"); TTVHIT->Branch("AngleDegcz1",&AngleDegcz1,"AngleDegcz1[8]/F"); TTVHIT->Branch("AngleDegcz2",&AngleDegcz2,"AngleDegcz2[8]/F"); TTVHIT->Branch("AngleDegcz3",&AngleDegcz3,"AngleDegcz3[8]/F"); TTVHIT->Branch("AngleDegczXCTB",&AngleDegczXCTB,"AngleDegczXCTB[8]/F"); TTVHIT->Branch("dtResidParPairs",&dtResidParPairs,"dtResidParPairs[16]/F"); TTVHIT->Branch("nSATSamples",&nSATSamples,"nSATSamples[20]/I"); TTVHIT->Branch("PDDA",&PDDA,"PDDA[4]/F"); TTVHIT->Branch("Vrms00MBN",&Vrms00MBN,"Vrms00MBN[20]/F"); TTVHIT->Branch("A1DubG",&A1DubG,"A1DubG[16]/F"); TTVHIT->Branch("dtDubG",&dtDubG,"dtDubG[16]/F"); TTVHIT->Branch("A2DubG",&A2DubG,"A2DubG[16]/F"); TTVHIT->Branch("t1DubG",&t1DubG,"t1DubG[16]/F"); TTVHIT->Branch("WidDubG",&WidDubG,"WidDubG[16]/F"); TTVHIT->Branch("AngleDegAz0",&AngleDegAz0,"AngleDegAz0[24]/F"); TTVHIT->Branch("npkSpx",&npkSpx,"npkSpx[16]/I"); TTVHIT->Branch("deltpks",&deltpks,"deltpks[16]"); TTVHIT->Branch("xpkSpx",&xpkSpx,"xpkSpx[16]"); TTVHIT->Branch("ApkSpx",&ApkSpx,"ApkSpx[16]"); TTVHIT->Branch("xpk2Spx",&xpk2Spx,"xpk2Spx[16]"); TTVHIT->Branch("Apk2Spx",&Apk2Spx,"Apk2Spx[16]"); TTVHIT->Branch("dtp1p2NSig",&dtp1p2NSig,"dtp1p2NSig[16]"); TTVHIT->Branch("PDirect",&PDirect,"PDirect[16]"); TTVHIT->Branch("PRefrac",&PRefrac,"PRefrac[16]"); TTVHIT->Branch("ANSig1",&ANSig1,"ANSig1[16]"); TTVHIT->Branch("ANSig2",&ANSig2,"ANSig2[16]"); TTVHIT->Branch("ANSig3",&ANSig3,"ANSig3[16]"); TTVHIT->Branch("ANSig4",&ANSig4,"ANSig4[16]"); TTVHIT->Branch("dtXCGaus",&dtXCGaus,"dtXCGaus[16]"); TTVHIT->Branch("AdtXCGaus",&AdtXCGaus,"AdtXCGaus[16]"); TTVHIT->Branch("AXCVMax1VMax2",&AXCVMax1VMax2,"AXCVMax1VMax2[16]"); TTVHIT->Branch("dtXCVMax1VMax2",&dtXCVMax1VMax2,"dtXCVMax1VMax2[16]"); TTVHIT->Branch("LUseCh",&LUseCh,"LUseCh[16]/O"); TTVHIT->Branch("LUseCh0",&LUseCh0,"LUseCh0[16]/O"); TTVHIT->Branch("tExpFit",&tExpFit,"tExpFit[16]/F"); TTVHIT->Branch("AExpFit",&AExpFit,"AExpFit[16]/F"); TTVHIT->Branch("SlopeExpFit",&SlopeExpFit,"SlopeExpFit[16]/F"); TTVHIT->Branch("y0ExpFit",&y0ExpFit,"y0ExpFit[16]/F"); TTVHIT->Branch("nMatchdt",&nMatchdt,"nMatchdt[16]/I"); TTVHIT->Branch("y0DubExp",&y0DubExp,"y0DubExp[16]/F"); TTVHIT->Branch("SlopeDubExp",&SlopeDubExp,"SlopeDubExp[16]/F"); TTVHIT->Branch("A1DubExp",&A1DubExp,"A1DubExp[16]/F"); TTVHIT->Branch("t1DubExp",&t1DubExp,"t1DubExp[16]/F"); TTVHIT->Branch("dtDubExp",&dtDubExp,"dtDubExp[16]/F"); TTVHIT->Branch("A2DubExp",&A2DubExp,"A2DubExp[16]/F"); TTVHIT->Branch("y0DubExpif",&y0DubExpif,"y0DubExpif[16]/F"); TTVHIT->Branch("SlopeDubExpif",&SlopeDubExpif,"SlopeDubExpif[16]/F"); TTVHIT->Branch("A1DubExpif",&A1DubExpif,"A1DubExpif[16]/F"); TTVHIT->Branch("t1DubExpif",&t1DubExpif,"t1DubExpif[16]/F"); TTVHIT->Branch("dtDubExpif",&dtDubExpif,"dtDubExpif[16]/F"); TTVHIT->Branch("A2DubExpif",&A2DubExpif,"A2DubExpif[16]/F"); TTVHIT->Branch("dtgrxixf",&dtgrxixf,"dtgrxixf[16]/F"); TTVHIT->Branch("Agrxixf",&Agrxixf,"Agrxixf[16]/F"); TTVHIT->Branch("tVMnVMx1VMx2",&tVMnVMx1VMx2,"tVMnVMx1VMx2[16]/F"); TTVHIT->Branch("VMnVMx1VMx2",&VMnVMx1VMx2,"VMnVMx1VMx2[16]/F"); TTVHIT->Branch("PSNRRx",&PSNRRx,"PSNRRx[16]/F"); TTVHIT->Branch("dtresid",tFitResid,"dtresid[16]"); TTVHIT->Branch("phicogX",phicogX,"phicogX[16]"); TTVHIT->Branch("thecogX",thecogX,"thecogX[16]"); TTVHIT->Branch("ASMsolnCh",&ASMsolnCh,"ASMsolnCh[16]/I"); TTVHIT->Branch("Fit4solnCh",&Fit4solnCh,"Fit4solnCh[16]/I"); TTVHIT->Branch("Z4solnCh",&Z4solnCh,"Z4solnCh[16]/I"); TTVHIT->Branch("PFFTDir",&PFFTDir,"PFFTDir[20][8]"); TTVHIT->Branch("PFFTRef",&PFFTRef,"PFFTRef[20][8]"); if(LAllFits)TTVHIT->Branch("tGFit",&tGFit,"tGFit[16]/F"); if(LAllFits)TTVHIT->Branch("tiBox",&tiBox,"tiBox[16]/F"); if(LAllFits)TTVHIT->Branch("tfBox",&tfBox,"tfBox[16]/F"); if(LAllFits)TTVHIT->Branch("dtxc",&dtxc,"dtxc[16][16]/F"); if(LAllFits)TTVHIT->Branch("SNRxc",&SNRxc,"SNRxc[16][16]/F"); if(LAllFits)TTVHIT->Branch("dtXC0",&dtXC0,"dtXC0[16][16]/F"); // TTVHIT->Branch("AngleDegAzBV",&AngleDegAzBV,"AngleDegAzBV[6]/F"); // TTVHIT->Branch("AngleDegAzTH",&AngleDegAzTH,"AngleDegAzTH[6]/F"); // TTVHIT->Branch("AngleDegAzBH",&AngleDegAzBH,"AngleDegAzBH[6]/F"); TTVHITCP=new TTree("TTVHITCP","TTVHITCP"); TTVHITCP->Branch("tHit",&tHitTime,"tHit[16]/F"); TTVHITCP->Branch("tSlope",&tSlope,"tSlope[16]/F"); TTVHITCP->Branch("ASlope",&ASlope,"ASlope[16]/F"); TTVHITCP->Branch("tVMax",&tVMax,"tVMax[16]/F"); TTVHITCP->Branch("VMaxHit",&VMaxHit,"VMaxHit[16]/F"); TTVHITCP->Branch("PrmsCh",&PrmsCh,"PrmsCh[16]/F"); TTVHITCP->Branch("tp1NSig",&tp1NSig,"tp1NSig[16]/F"); TTVHITCP->Branch("tm1NSig",&tm1NSig,"tm1NSig[16]/F"); TTVHITCP->Branch("A1DubG",&A1DubG,"A1DubG[16]/F"); TTVHITCP->Branch("dtDubG",&dtDubG,"dtDubG[16]/F"); TTVHITCP->Branch("A2DubG",&A2DubG,"A2DubG[16]/F"); TTVHITCP->Branch("t1DubG",&t1DubG,"t1DubG[16]/F"); TTVHITCP->Branch("WidDubG",&WidDubG,"WidDubG[16]/F"); TTVHITDP=new TTree("TTVHITDP","TTVHITDP"); //(TTree*)TTVHIT->Clone(); TTVHITCP->SetName("TTVHITCP"); TTVHITCP->SetTitle("TTVHITCP"); TTVHITDP->Branch("iDPcode",&iDPcode,"iDPcode/I"); TTVHITDP->Branch("tHit",&tHitTime,"tHit[16]/F"); TTVHITDP->Branch("tSlope",&tSlope,"tSlope[16]/F"); TTVHITDP->Branch("ASlope",&ASlope,"ASlope[16]/F"); TTVHITDP->Branch("tVMax",&tVMax,"tVMax[16]/F"); TTVHITDP->Branch("VMaxHit",&VMaxHit,"VMaxHit[16]/F"); TTVHITDP->Branch("VMinHit",&VMinHit,"VMinHit[16]/F"); TTVHITDP->Branch("PrmsCh",&PrmsCh,"PrmsCh[16]/F"); TTVHITDP->Branch("tp1NSig",&tp1NSig,"tp1NSig[16]/F"); TTVHITDP->Branch("tm1NSig",&tm1NSig,"tm1NSig[16]/F"); TTVHITDP->Branch("tp2NSig",&tp2NSig,"tp2NSig[16]/F"); TTVHITDP->Branch("tm2NSig",&tm2NSig,"tm2NSig[16]/F"); TTVHITDP->Branch("ANSig1",&ANSig1,"ANSig1[16]"); TTVHITDP->Branch("ANSig2",&ANSig2,"ANSig2[16]"); TTVHITDP->Branch("Ptp1tm1",&Ptp1tm1,"Ptp1tm1[16]/F"); TTVHITDP->Branch("Ptp2tm2",&Ptp2tm2,"Ptp2tm2[16]/F"); TTVHITDP->Branch("A1DubG",&A1DubG,"A1DubG[16]/F"); TTVHITDP->Branch("dtDubG",&dtDubG,"dtDubG[16]/F"); TTVHITDP->Branch("A2DubG",&A2DubG,"A2DubG[16]/F"); TTVHITDP->Branch("t1DubG",&t1DubG,"t1DubG[16]/F"); TTVHITDP->Branch("WidDubG",&WidDubG,"WidDubG[16]/F"); TTVHITDP->Branch("dtXCGaus",&dtXCGaus,"dtXCGaus[16]"); TTVHITDP->Branch("AdtXCGaus",&AdtXCGaus,"AdtXCGaus[16]"); TTVHITDP->Branch("AXCVMax1VMax2",&AXCVMax1VMax2,"AXCVMax1VMax2[16]"); TTVHITDP->Branch("dtXCVMax1VMax2",&dtXCVMax1VMax2,"dtXCVMax1VMax2[16]"); TTVHITDP->Branch("PSNRRx",&PSNRRx,"PSNRRx[16]"); TUTC0=new TTree("TUTC0","TUTC0"); TUTC0->Branch("utc",&utc000,"utc/D"); TCOHINC=new TTree("TCOHINC","TCOHINC"); TCOHINC->Branch("fbndMHzC",&fbndMHzC,"fbndMHzC"); TCOHINC->Branch("iCodeC",&iCodeC,"iCodeC/I"); TCOHINC->Branch("rmsp12m1C",&rmsp12m1C,"rms2p2m1C[16]"); TCOHINC->Branch("rms2p1C",&rms2p1C,"rms2p1C[16]"); TCOHINC->Branch("rmsm12p2C",&rmsm12p2C,"rmsm12p2C[16]"); TCOHINC->Branch("rmsp2pC",&rmsp2pC,"rmsp2pC[16]"); TCOHINC->Branch("rmsp32C",&rmsp32C,"rmsp32C[16]"); TCOHINC->Branch("PNSig16C",&PNSig16C,"PNSig16C[16]"); TCOHINC->Branch("PNSig16_32C",&PNSig16_32C,"PNSig16_32C[16]"); TCOHINC->Branch("rmsm32C",&rmsm32C,"rmsm32C[16]"); TCOHINC->Branch("dtp1p2C",&dtp1p2C,"dtp1p2C[16]"); TCOHINC->Branch("A1NsigC",&A1NSigC,"A1NSigC[16]"); //last entry is local name TCOHINC->Branch("A2NSigC",&A2NSigC,"A2NSigC[16]"); TCOHINC->Branch("ievCohC",&ievCohC,"ievCohC/I"); TCOHINC->Branch("ipow2C",&ipow2C,"ipow2C/I"); TCOHINC->Branch("zTx0z",&zTx0z,"zTx0z"); TX2A=new TTree("TX2A","TX2A"); TX2A->Branch("tICL2RxA",&tICL2RxA,"tICL2RXA[16]"); TX2A->Branch("tIC22S2RxA",&tIC22S2RxA,"tIC22S2RXA[16]"); TX2A->Branch("tIC1S2RxA",&tIC1S2RxA,"tIC1S2RXA[16]"); TX2A->Branch("tIC1D2RxA",&tIC1D2RxA,"tIC1D2RXA[16]"); // TX2A->Branch("rIC22S2RxA",&rIC22S2RxA,"rIC22S2RXA[16]"); TX2A->Branch("rIC1S2RxA",&rIC1S2RxA,"rIC1S2RXA[16]"); TX2A->Branch("rIC1D2RxA",&rIC1D2RxA,"rIC1D2RXA[16]"); TX2A->Branch("ipttRx2A",&ipttRx2A,"ipttRx2A[16]/D"); TUTCEVT0=new TTree("TUTCEVT0","TUTCEVT0"); TUTCEVT0->Branch("utc",&unixTime0,"utc/D"); TUTCEVT0->Branch("utc10Ns",&utc10Ns,"utc10Ns/D"); TUTCEVT1=new TTree("TUTCEVT1","TUTCEVT1"); TUTCEVT1->Branch("utc",&unixTime0,"utc/D"); TUTCEVT1->Branch("utc10Ns",&utc10Ns,"utc10Ns/D"); TUTCEVT1->Branch("dutcEV",&dunixTimeEV,"dutcEV/D"); TFFTEV1=new TTree("TFFTEV1","TFFTEV1"); TFFTEV1->Branch("ffft0",&ffft0,"ffft0[16]"); TFFTEV1->Branch("Afft0",&Afft0,"Afft0[16]"); TFFTEV1->Branch("phifft0",&phifft0,"phifft0[16]"); TFFTEV1->Branch("PowerFrqBndSignal",&PowerFrqBndSignal,"PowerFrqBndSignal[20][10]"); TFFTEV1->Branch("PowerFrqBndBk",&PowerFrqBndBk,"PowerFrqBndBk[20][10]"); TFFTEV1->Branch("PowerFrqBnd0",&PowerFrqBnd0,"PowerFrqBnd0[20][10]"); TFFTEV1->Branch("PowerFrqBndUB",&PowerFrqBndUB,"PowerFrqBndUB[20][10]"); TFFTEV0=new TTree("TFFTEV0","TFFTEV0"); TFFTEV0->Branch("utc",&unixTime0,"utc/D"); TFFTEV0->Branch("PFiltered",&PFiltered,"PFiltered[20]"); TFFTEV0->Branch("ffft0",&ffft0,"ffft0[20]"); TFFTEV0->Branch("Afft0",&Afft0,"Afft0[20]"); TFFTEV0->Branch("phifft0",&phifft0,"phifft0[20]"); TFFTEV0->Branch("ffftWt",&ffftWt,"ffftWt[20]"); TFFTEV0->Branch("AfftWt",&AfftWt,"AfftWt[20]"); TFFTEV0->Branch("SpxA0",&SpxA0,"SpxA0[20]"); TFFTEV0->Branch("Vrms00MBN",&Vrms00MBN,"Vrms00MBN[20]"); TFFTEV0->Branch("Prms00MBN",&Prms00MBN,"Prms00MBN[20]"); TFFTEV0->Branch("SpxSlope",&SpxSlope,"SpxSlope[20]"); TFFTEV0->Branch("VMaxHit",&VMaxHit,"VMaxHit[20]"); TFFTEV0->Branch("tVMax",&tVMax,"tVMax[20]"); TFFTEV0->Branch("VMinHit",&VMinHit,"VMinHit[20]"); TFFTEV0->Branch("tVMin",&tVMin,"tVMin[20]/F"); TFFTEV0->Branch("tVMaxXCableDelay",&tVMaxXCableDelay,"tVMaxXCableDelay[20]/F"); TFFTEV0->Branch("tVMinXCableDelay",&tVMinXCableDelay,"tVMinXCableDelay[20]/F"); TFFTEV0->Branch("VrmsCh",&VrmsCh,"VrmsCh[20]"); TFFTEV0->Branch("RxRawPower",&RxRawPower,"RxRawPower[20]"); TFFTEV0->Branch("Pgr00Ch",&Pgr00Ch,"Pgr00Ch[20][10]"); TFFTEV0->Branch("PowerFrqBndUB",&PowerFrqBndUB,"PowerFrqBndUB[20][10]"); TFFTEV0->Branch("iTrigDelayCh",&iTrigDelayCh,"iTrigDelayCh[16]/I"); TFFTEV0->Branch("P400MHzWB",&P400MHzWB,"P400MHzWB[20]"); TFFTEV0->Branch("P400MHzWBSB",&P400MHzWBSB,"P400MHzWBSB[20]"); TFFTEV0->Branch("PhaseCWX",&PhaseCWX,"PhaseCWX[20]"); TFFTEV0->Branch("AfCWX",&AfCWX,"AfCWX[20]"); TFFTEV0->Branch("dtCWX",&dtCWX,"dtCWX[20]"); TFFTEV0->Branch("ChiSqCWX",&ChiSqCWX,"ChiSqCWX[20]"); // TFFTEV0->Branch("phifCWX",&phifCWX,"phifCWX[20]"); TFFTEV0->Branch("dphiSxS400MHz",&dphiSxS400MHz,"dphiSxS400MHz[6]"); TFFTEV0->Branch("frqfCWX",&frqfCWX,"frqfCWX[20]"); TTRIGBITS=new TTree("TTRIGBITS","TTRIGBITS"); TTRIGBITS->Branch("iptRx2Hit",&iptRx2Hit,"iptRx2Hit[16]/I"); TTRIGBITS->Branch("itriggerBits",&itriggerBits,"itriggerBits[16]/I"); // TTRIGBITS->Branch("itrigInfo0",&itrigInfo0,"itrigInfo0[16]/I"); for(Int_t ih=0; ih=16){ h3PfftVfGalacDay[ih-16]=new TH3F(Form("h3PfftVfGalacDay%d",ih),Form("h3PfftVfGalacDay%d",ih),100,0,1000,20,0,1,300,2,9); //fractional power in a given fft bin h1frqIVCh[ih-16]=new TH1F(Form("h1frqIVCh%d",ih),Form("h1frqIVCh%d",ih),100,0,1000); } for(Int_t jh=ih+1; jhClone(); h2fftVzTxNorm[1]=(TH2F*)h2fftVzTx[0][1]->Clone(); h2fftVzTxNorm[0]->SetNameTitle("h2fftVzTxNormR","h2fftVzTxNormR"); h2fftVzTxNorm[1]->SetNameTitle("h2fftVzTxNormL","h2fftVzTxNormL"); for(Int_t izTx=0; izTxSetOptStat("neMRou"); h3Spectrogram[izTx]=new TH3F(chname,chtitle,32,0,32*MBINTIMESPECTROGRAM,MBINFFTSPECTROGRAM,0,1.,16,-0.5,15.5); } for(Int_t ih2=0; ih2utc if(LDebug)printf("iuct0SP[%d]=%d -iutc1SP[%d]=%d /diff=%d\n",iSP,iutc0SP[iSP],iSP,iutc1SP[iSP],iutc0SP[iSP]-iutc1SP[iSP]); } fWBs=new TFile("/home/dbesson/src/root/WBs.root"); NWBs=(TNtuple*)fWBs->Get("NWB"); NWBs->BuildIndex("yr","min0"); fWB0=new TFile("/data/user/dbesson/WB/WB2011-2020.root"); NWB0=(TNtuple*)fWB0->Get("NWB0"); NWB0->BuildIndex("iYr","imin0"); fWind=new TFile(Form("/data/user/dbesson/wind/SPO/Wind%d.root",iYear0)); NWIND=(TNtuple*)fWind->Get("NWIND"); NWIND->BuildIndex("hr0","min"); } inline void GetWindVelocity(){ idum=NWIND->GetEntryNumberWithBestIndex(utchr0,utcmin); if(idum<=-1)return -NNN; NWIND->GetEntry(idum); vWind=NWIND->GetLeaf("v")->GetValue(); phiWind=NWIND->GetLeaf("phi")->GetValue(); T2mWind=NWIND->GetLeaf("T2m")->GetValue(); hr0Wind=NWIND->GetLeaf("hr0")->GetValue()+NWIND->GetLeaf("min")->GetValue()/60.; return NWIND->GetLeaf("v")->GetValue(); } inline void gett2WBfftMHz(TGraph *grfft0, Int_t ich){ const Int_t WBMINOFFSET=1; t2WB=-NNN; idum=NWBs->GetEntryNumberWithIndex(iYear0,60*utchr0+utcmin+WBMINOFFSET); if(idum>0){ NWBs->GetEntry(idum); t2WB=(utchr0*60+utcmin)-(60*NWBs->GetLeaf("hr0")->GetValue()+NWBs->GetLeaf("min")->GetValue()); if(LDebug)cout<<"iWB="<GetValue()<<" NWBsmin="<GetLeaf("min")->GetValue()<<" utchr0="<GetValue()+NWBs->GetLeaf("min")->GetValue())<<" t2WB1="<GetN(); ib++)if(ich<16)h2fftVtWB->Fill(grfft0->GetX()[ib],t2WB,grfft0->GetY()[ib]); } idum=NWB0->GetEntryNumberWithIndex(iYear0,utcmin0+WBMINOFFSET); //offset of one minute, assuming sonde on for 60 seconds if(idum>0){ LWBON=true; NWB0->GetEntry(idum); if(LDebug||ieventNumber%100==0)cout<<"gett2WB LWBON==1 for run="<GetValue(); WBxm+=WBxm0; WBxmtmp=WBxm; WBym=NWB0->GetLeaf("WBy")->GetValue(); WBym+=WBym0; WBzm=NWB0->GetLeaf("WBz")->GetValue()-2840; //offset for surface elevation!!!! WBphi=atan2(WBym,WBxm)*TMath::RadToDeg(); if(LDebug)cout<<8888888888888<<" "<GetN(); ib++)h2fftWBVCh->Fill(grfft0->GetX()[ib],ich,grfft0->GetY()[ib]); } else{for(Int_t ib=0; ibGetN(); ib++)h2fftXWBVCh->Fill(grfft0->GetX()[ib],ich,grfft0->GetY()[ib]);} } void SpherDeg2Cart(Float_t r0m, Float_t phi0Deg, Float_t the0Deg, Float_t &x, Float_t &y, Float_t &z){ x=r0m*sin(the0Deg*TMath::DegToRad())*cos(phi0Deg*TMath::DegToRad()); y=r0m*sin(the0Deg*TMath::DegToRad())*sin(phi0Deg*TMath::DegToRad()); z=r0m*cos(the0Deg*TMath::DegToRad()); } void Cart2SpherDeg(Float_t x0, Float_t y0, Float_t z0, Float_t &r, Float_t &phi, Float_t &the){ r=sqrt(x0*x0+y0*y0+z0*z0); phi=atan2(y0,x0)*TMath::RadToDeg(); the=acos(z0/r)*TMath::RadToDeg(); Float_t the1=atan2(sqrt(x0*x0+y0*y0),z0)*TMath::RadToDeg(); if(LDebug)printf("Cart2Spher r=%g rxy=%g phi=%g theta (wrt horizontal)=%g the1=%g\n",r,sqrt(x0*x0+y0*y0),phi,90-the,90-the1); } Float_t PgrSubgr(TGraph *gr, Float_t xi, Float_t xf){ fdum=0; for(Int_t ib=0; ibGetN(); ib++){ if(gr->GetX()[ib]GetX()[ib]>xf)continue; fdum+=gr->GetY()[ib]*gr->GetY()[ib]; } return fdum; } void VNorm2Avg(Float_t x0, Float_t y0, Float_t z0, Float_t &xNorm, Float_t &yNorm, Float_t &zNorm){ Float_t r=sqrt(x0*x0+y0*y0+z0*z0); xNorm=x0/r; yNorm=y0/r; zNorm=z0/r; } //assumes that the local coordinates are relative to the cog of global coordinates inline void ZLoc2AraRootLoc(Int_t iStation, Float_t V3SpherR, Float_t V3SpherPhi, Float_t V3SpherThe, Float_t &V3SpherGloR, Float_t &V3SpherGloPhi, Float_t &V3SpherGloThe){ Float_t fLocXYZ[3], fGloXYZ[3]; SpherDeg2Cart(V3SpherR,V3SpherPhi,V3SpherThe,fLocXYZ[0],fLocXYZ[1],fLocXYZ[2]); fGloXYZ[0]=fLocXYZ[0]+RxXYZ0[0]; fGloXYZ[1]=fLocXYZ[1]+RxXYZ0[1]; fGloXYZ[2]=fLocXYZ[2]+RxXYZ0[2]; Cart2SpherDeg(fGloXYZ[0], fGloXYZ[1], fGloXYZ[2], V3SpherGloR, V3SpherGloPhi, V3SpherGloThe); } inline void ZLoc2ArrayGlo(Float_t V3SpherR, Float_t V3SpherPhi, Float_t V3SpherThe, Float_t &V3SpherGloR, Float_t &V3SpherGloPhi, Float_t &V3SpherGloThe){ Float_t fLocXYZ[3], fGloXYZ[3]; SpherDeg2Cart(V3SpherR,V3SpherPhi,V3SpherThe,fLocXYZ[0],fLocXYZ[1],fLocXYZ[2]); fGloXYZ[0]=fLocXYZ[0]+RxXYZ0[0]; fGloXYZ[1]=fLocXYZ[1]+RxXYZ0[1]; fGloXYZ[2]=fLocXYZ[2]+RxXYZ0[2]; Cart2SpherDeg(fGloXYZ[0], fGloXYZ[1], fGloXYZ[2], V3SpherGloR, V3SpherGloPhi, V3SpherGloThe); } inline void ZGlo2ZLoc(Float_t V3SpherR, Float_t V3SpherPhi, Float_t V3SpherThe, Float_t &V3SpherLocR, Float_t &V3SpherLocPhi, Float_t &V3SpherLocThe){ Float_t fLocXYZ[3], fGloXYZ[3]; SpherDeg2Cart(V3SpherR,V3SpherPhi,V3SpherThe,fGloXYZ[0],fGloXYZ[1],fGloXYZ[2]); fLocXYZ[0]=fGloXYZ[0]-RxXYZ0[0]; fLocXYZ[1]=fGloXYZ[1]-RxXYZ0[1]; fLocXYZ[2]=fGloXYZ[2]-RxXYZ0[2]; Cart2SpherDeg(fLocXYZ[0], fLocXYZ[1], fLocXYZ[2], V3SpherLocR, V3SpherLocPhi, V3SpherLocThe); } inline void PrintGlobalCoords(){ for(Int_t iS=1; iS<5; iS++){ for(Int_t ixy=0; ixy<2; ixy++){ Float_t dtheX=atan2(SpiceCore2015XYZ[1]-ARAXYZ[iS][1],SpiceCore2015XYZ[0]-ARAXYZ[iS][0])*TMath::RadToDeg(); printf("ARAXYZ[%d][%d]=%g / ARAXYZA[%d][%d]=%g / dxSpice=%g dySpice=%g θ wrt SPICE=%g/δθ wrt ice flow=%g",ixy,iS,ARAXYZ[iS][ixy],ixy,iS,ARAXYZA[iS][ixy],(SpiceCore2015XYZ[0]-ARAXYZ[iS][0]),(SpiceCore2015XYZ[1]-ARAXYZ[iS][1]),dtheX,dtheX-IceFlowwrtNegX); cout<convertArrayToStationCoords(iStation, dGloXYZ, dLocXYZ); dLocXYZ[0]-=RxXYZ0[0]; dLocXYZ[1]-=RxXYZ0[1]; dLocXYZ[2]-=RxXYZ0[2]; Cart2SpherDeg(dLocXYZ[0],dLocXYZ[1],dLocXYZ[2],V3SpherLocR,V3SpherLocPhi,V3SpherLocThe); printf("%s %s Input global x=%g/y=%g/z=%g local x=%g/y=%g/z=%g/r=%g/phi=%g/the=%g\n%s",BOLDYELLOW,cmsg,xGlo,yGlo,zGlo,dLocXYZ[0],dLocXYZ[1],dLocXYZ[2],V3SpherLocR,V3SpherLocPhi,V3SpherLocThe,KNRM); // for(Int_t iA=0; iA<6; iA++){ Int_t iA=iStation; fdum=atan2(yGlo-ARAXYZ[iA][1],xGlo-ARAXYZ[iA][0])*TMath::RadToDeg(); dxy=sqrt(pow(xGlo-ARAXYZ[iA][0],2)+pow(yGlo-ARAXYZ[iA][1],2)); dxyz=sqrt(dxy*dxy+pow(zGlo-ARAXYZ[iA][2],2)); cos2A=dxy/dxyz; printf("Station A%d Global coords x=%g/y=%g/z=%g/phi=%g/wrtIceFlow=%g / in Station coords, this source has coordinates (r-Source)=>cos2A%d=%g d2A%dxy=%g d2A%dxyz=%g\t",iA,ARAXYZ[iA][0],ARAXYZ[iA][1],ARAXYZ[iA][2],fdum,fdum+180-IceFlowICwrtX,iA,cos2A,iA,dxy,iA,dxyz); // } cout<Rx dtSrc2RxMin=%g\n",KGRN,cmsg,dtSrc2RxMin); for(Int_t ichVH=0; ichVHconvertStationToArrayCoords(iStation, dLocXYZ, dGloXYZ); fdum=float(dGloXYZ[0]); fdum1=float(dGloXYZ[1]); fdum2=float(dGloXYZ[2]); Cart2SpherDeg(fdum, fdum1, fdum2, V3SpherGloR, V3SpherGloPhi, V3SpherGloThe); if(LDebug)printf("%s Translating with new pointer! output global spher=%g/%g/%g global xyz=%g/%g/%g\n%s",KNRM,V3SpherGloR,V3SpherGloPhi,V3SpherGloThe,dGloXYZ[0],dGloXYZ[1],dGloXYZ[2],KNRM); // delete AraGeomPtr; } Float_t GetdNSigmaCP0(TNtuple *N, const char* cProjVar,const char* cProjCut, Float_t VarVal){ Float_t dxSigmaCP, xrmsCP; if(N->GetEntries()>0){ N->Draw(cProjVar,cProjCut,"goff"); TH1F *htmpa=(TH1F*)gDirectory->Get("htemp"); if(htmpa->GetEntries()<=0)return NNN; // htmp->Print("all"); dxSigmaCP=(htmpa->GetMean()-VarVal); xrmsCP=htmpa->GetRMS(); delete htmpa; } if(xrmsCP>0) return fabs(dxSigmaCP/xrmsCP); //TMath::Prob(dxSigmaCP/xrmsCP,1); else return -1; } inline void FillNRXHITTV(){ for(Int_t ich=0; ichFill(xntvar); } inline void ReadCPXX(Int_t iStation, Int_t iYear){ sprintf(cFileIn,"/home/dbesson/src/txt/ara0%d_%d_CPXX.txt",iStation,iYear); grCPXX=new TGraph(cFileIn); for(Int_t ich=0; ichV; vectort; ifstream fCP(cFileIn); while(fCP>>fdum>>fdum1){ t.push_back(fdum); V.push_back(fdum1); } grCPXX=new TGraph(V.size(),t,V); */ } inline void FindAir2IceTransitTime(Int_t ich, Float_t xSrc, Float_t ySrc){ Float_t thetai=asin(1./nSurfIce); Float_t dxyHorizontal=fabs(Rx[ich].z)*tan(thetai); Float_t dxSrc=xSrc-Rx[ich].E; Float_t dySrc=ySrc-Rx[ich].N; Float_t dmag=sqrt(dxSrc*dxSrc+dySrc*dySrc); Float_t ScaleHorizontal=dxyHorizontal/dmag; Rx[ich].IceXAirx=ScaleHorizontal*dxSrc; Rx[ich].IceXAiry=ScaleHorizontal*dySrc; Rx[ich].IceXAirz=0; Float_t dmagAir=sqrt((xSrc-Rx[ich].IceXAirx)*(xSrc-Rx[ich].IceXAirx)+ (ySrc-Rx[ich].IceXAirx)*(ySrc-Rx[ich].IceXAiry)); Rx[ich].tnsInAir=dmagAir/sLightAir; Float_t dmagIce=sqrt(dxyHorizontal*dxyHorizontal+Rx[ich].z*Rx[ich].z); if(Rx[ich].z<0)Rx[ich].tnsInIce=ntimexp(0,Rx[ich].z,dmagIce); else Rx[ich].tnsInIce=0; if(LDebug||NEvTot<4)printf("FindAir2IceTransitTime: dxyHoriz=%g Rx[%d].z=%g tAir=%g tIce=%g ttot=%g dmag=%g\n",dxyHorizontal,ich,Rx[ich].z,Rx[ich].tnsInAir,Rx[ich].tnsInIce,Rx[ich].tnsInAir+Rx[ich].tnsInIce,dmag); } inline void CheckBinningNGraphs(Int_t ngr, TGraph **gr){ for(Int_t igr=0; igrGetX()[gr[igr]->GetN()-1]; for(Int_t jgr=igr+1; jgrGetX()[gr[jgr]->GetN()-1]; if(tfi!=tfj)printf("tfinali[%d]=%g/tfinalj[%d]=%g\n",igr,tfi,jgr,tfj); if(gr[igr]->GetN()!=gr[jgr]->GetN())printf("gr[%d]->GetN()=%d/gr[%d]->GetN()=%d!\n",igr,gr[igr]->GetN(),jgr,gr[jgr]->GetN()); Float_t dti=gr[igr]->GetX()[1]-gr[igr]->GetX()[0]; Float_t dtj=gr[jgr]->GetX()[1]-gr[jgr]->GetX()[0]; if(dti!=dtj)printf("dti[%d]=%g/dtj[%d]=%g\n",igr,dti,jgr,dtj); } } } inline Int_t nX1V(TGraph *gr){ Int_t iX1V=0; for(Int_t ib=0; ibGetN()-1; ib++){ if(abs(gr->GetY()[ib])<1000&&abs(gr->GetY()[ib+1])>1000)iX1V++; if(abs(gr->GetY()[ib])>1000&&abs(gr->GetY()[ib+1])<1000)iX1V++; } return iX1V; } inline TGraph *grEnvAutoCorr(TGraph *gr1, TGraph *gr2){ TGraph *grAutoXC=FFTtools::getCorrelationGraph(gr1,gr2); TGraph *grHE_AutoXC=FFTtools::getHilbertEnvelope(grAutoXC); delete grAutoXC; return grHE_AutoXC; } inline TGraph *grEv(TGraph **gr, Int_t nchi, Int_t nchf){ Int_t ntotbins=0; for(Int_t ich=nchi; ichGetN(); TGraph *grtmp=new TGraph(ntotbins); Int_t ib0=0; Float_t ttot=0; Float_t tmin=NNN; for(Int_t ich=0; ichGetX()[0]GetX()[0]; for(Int_t ich=nchi; ichFill(ich,jch,gr[ich]->GetX()[0],gr[jch]->GetX()[0],gr[ich]->GetX()[gr[ich]->GetN()-1],gr[jch]->GetX()[gr[jch]->GetN()-1],gr[ich]->GetN(),gr[jch]->GetN()); Float_t dtbins=gr[ich]->GetX()[1]-gr[ich]->GetX()[0]; for(Int_t ib=0; ibGetN(); ib++){ grtmp->SetPoint(ib0,ttot,gr[ich]->GetY()[ib]); ib0++; ttot+=dtbins; } } return grtmp; } inline TGraph *grMChits(Int_t ich){ Float_t tPadding=32; Float_t times[512]; Float_t Volts[512]; Int_t itimehit=-1; if(Rx[ich].LVtx)itimehit=Rx[ich].HitTime-tSimVtxFirstHit+tPadding; if(LDebug)cout<<"grMChits: "<Gaus(0,32); } if(itimehit>=0){ Volts[itimehit]+=1024; Volts[itimehit+1]+=1024; Volts[itimehit+2]+=1024; } TGraph *grtmp=new TGraph(512,times,Volts); return grtmp; } TGraph *grSum12(TGraph *grA, TGraph *grB){ Int_t N1=grA->GetN(); Int_t N2=grB->GetN(); TGraph *grtmp=(TGraph*)grA->Clone(); if(N1!=N2){printf("grSum12: grA->GetN=%d grB->GetN=%d\n",grA->GetN(),grB->GetN()); return grtmp;} delete grtmp; Double_t *newY = new Double_t [N1]; Double_t *xVals=grA->GetX(); Double_t x,yA,yB; for(int i=0;iGetPoint(i,x,yA); grB->GetPoint(i,x,yB); newY[i]=yA+yB; } TGraph *grSum = new TGraph(N1,xVals,newY); delete [] newY; return grSum; } //10may21 - use to sum by polarization in time domain inline TGraph *gr16Ch(TGraph **gr1, TGraph **gr2, Int_t iVH){ Int_t nbins1=gr1[0]->GetN(); Int_t nbins2=gr2[0]->GetN(); if(nbins2!=nbins1)printf("nbins2=%d != nbins1=%d\n",nbins2,nbins1); Int_t nbins=nbins1; Float_t tlength=gr1[0]->GetX()[nbins-1]; // TGraph *grtmp; // TGraph *grtmp1=new TGraph(nbins*16); // TGraph *grtmp2=new TGraph(nbins*16); TGraph *grtmpV1=new TGraph(nbins*8); TGraph *grtmpV2=new TGraph(nbins*8); TGraph *grtmpH1=new TGraph(nbins*8); TGraph *grtmpH2=new TGraph(nbins*8); for(Int_t ib=0; ib=8)continue; grtmpV1->SetPoint(ich*nbins+ib,gr1[ich]->GetX()[ib]+tlength*ich,gr1[ich]->GetY()[ib]); grtmpV2->SetPoint(ich*nbins+ib,gr2[ich]->GetX()[ib]+tlength*ich,gr2[ich]->GetY()[ib]); grtmpH1->SetPoint(ich*nbins+ib,gr1[ich+8]->GetX()[ib]+tlength*ich,gr1[ich+8]->GetY()[ib]); grtmpH2->SetPoint(ich*nbins+ib,gr1[ich+8]->GetX()[ib]+tlength*ich,gr1[ich+8]->GetY()[ib]); } } Float_t delt; if(iVH==0){ delt=dtgr1gr2(grtmpV1,grtmpV2,fdum,idum); TGraph *grtrans=FFTtools::translateGraph(grtmpH1,delt); TGraph *grSumH=grSum12(grtmpH2,grtrans); }else{ delt=dtgr1gr2(grtmpH1,grtmpH2,fdum,idum); TGraph *grtrans=FFTtools::translateGraph(grtmpV1,delt); TGraph *grSumV=grSum12(grtmpV2,grtrans); //now correlate and average polarization with highest power; find time offset and recreate event vector } return grtmpV1; } inline Int_t ibinCOG(TGraph *grSPE){ Float_t ysum=0; Float_t yWtSum=0; for(Int_t ib=0; ibGetN(); ib++){ yWtSum+=ib*fabs(grSPE->GetY()[ib]); ysum+=fabs(grSPE->GetY()[ib]); } if(LDebug)cout<Clone(); // Int_t ibnglo=0; ACPxc=0; Int_t nACPxc=0; Int_t nVPolCPxc=0; Int_t nHPolCPxc=0; Float_t fdtxc; for(Int_t ich=0; ichFill(fdtxc); if(LDebug)printf("ich=%d fdtxc=%g\n",ich,fdtxc); ACPxc+=fdum1; nACPxc++; } idum=htmp->GetMaximumBin(); fdum=htmp->GetMaximum(); dtrmsCPxc=htmp->GetRMS(); ACPxc/=nACPxc; fTH1CPxc=fdum/nACPxc; // htmp->Print("all"); if(LDebug)printf("ACPxc=%g nVPol=%d nHPol=%d dtrms=%g fTH1=%g dt=%g\n",ACPxc,nVPolCPxc,nHPolCPxc,dtrmsCPxc,fTH1CPxc,htmp->GetXaxis()->GetBinCenter(idum)); delete htmp; return 1; // delete grtmp; //get rms of dt's of correlation graphs!!!!!! } inline Float_t ThetaPrime(Float_t r0, Float_t phi0, Float_t the0, Float_t zshift){ if(the0==-NNN)return -NNN; Float_t xdum, ydum, zdum, theshift; SpherDeg2Cart(r0,phi0,the0,xdum,ydum,zdum); Cart2SpherDeg(xdum,ydum,zdum-zshift,fdum,fdum1,theshift); return theshift; } inline Int_t iTxMinimumAngle2Vtx(Float_t r0, Float_t phi0, Float_t the0, Float_t &rmin, Float_t &phimin, Float_t &themin){ Float_t delr, delphi, delthe, dphithe; Float_t dphithemin=NNN; Int_t iTxmin=-1; for(Int_t ich=0; ichdphithemin)continue; dphithemin=dphithe; rmin=delr; themin=delthe; phimin=delphi; iTxmin=ich; } return iTxmin; } inline void getAvgRMS3(Float_t f1, Float_t f2, Float_t f3, Float_t &fAvg, Float_t &fRMS){ fAvg=(f1+f2+f3)/3.; fRMS=(fabs(f1-fAvg)+fabs(f2-fAvg)+fabs(f3-fAvg))/3.; } inline void getAvgRMS4(Float_t f1, Float_t f2, Float_t f3, Float_t f4, Float_t &fAvg, Float_t &fRMS){ fAvg=(f1+f2+f3+f4)/4.; fRMS=(fabs(f1-fAvg)+fabs(f2-fAvg)+fabs(f3-fAvg)+fabs(f4-fAvg))/4.; } inline Float_t getdevHitTimes(Float_t ht0[16], Float_t ht1[16]){ Float_t dtSumSq=-1; Int_t ncomb=0; for(Int_t ich=0; ich0)return sqrt(dtSumSq)/ncomb; else return dtSumSq; } inline Float_t gettNSig2pm(TGraph *grSPE, Int_t ich, Int_t ievtype, Float_t DTNSSEPMIN){ Float_t ScaleNbinsX=nbinsVtgr[ich]/grSPE->GetN(); Float_t dt=grSPE->GetX()[1]-grSPE->GetX()[0]; Int_t MINBINSWID=int(DTNSSEPMIN/dt); if(ievtype==3)MINBINSWID=int(2*DTNSSEPMIN/dt); //if(ievtype==1111)MINBINSWID=16/dt; // Int_t MINBINSWID=64; if(ievtype==3)MINBINSWID=128; Int_t MINBINSSEP=2*MINBINSWID; tp1NSig[ich]=-NNN; tm1NSig[ich]=-NNN; tp2NSig[ich]=-NNN; tm2NSig[ich]=-NNN; tp3NSig[ich]=-NNN; tm3NSig[ich]=-NNN; ANSig1[ich]=-NNN; ANSig2[ich]=-NNN; ANSig3[ich]=-NNN; tp4NSig[ich]=-NNN; tm4NSig[ich]=-NNN; ANSig4[ich]=-NNN; ibntp1NSig[ich]=ibntm1NSig[ich]=ibntp2NSig[ich]=ibntm2NSig[ich]=-NNN; Int_t ibp1=-1; Int_t ibm1=-1; Int_t ibp2=-1; Int_t ibm2=-1; Int_t ibp3=-1; Int_t ibm3=-1; Int_t ibp4=-1; Int_t ibm4=-1; for(Int_t ib=0; ibGetN(); ib++){ if(fabs(grSPE->GetY()[ib])>Rx[ich].Prms*MSIGMASPE){ if(tp1NSig[ich]==-NNN){ tp1NSig[ich]=grSPE->GetX()[ib]; ibp1=ib; ibntp1NSig[ich]=ib; ibnVtXp[0][ich]=ib*ScaleNbinsX; } if(tm1NSig[ich]>-NNN && ib-ibm1>MINBINSSEP){ if(tp2NSig[ich]==-NNN){ tp2NSig[ich]=grSPE->GetX()[ib]; ibp2=ib; ibntp2NSig[ich]=ib; ibnVtXp[1][ich]=ib*ScaleNbinsX; } } if(tm2NSig[ich]>-NNN && ib-ibm2>MINBINSSEP){ if(tp3NSig[ich]==-NNN){ tp3NSig[ich]=grSPE->GetX()[ib]; ibp3=ib; ibnVtXp[2][ich]=ib*ScaleNbinsX; } } if(tm3NSig[ich]>-NNN && ib-ibm3>MINBINSSEP){ if(tp4NSig[ich]==-NNN){ tp4NSig[ich]=grSPE->GetX()[ib]; ibp4=ib; ibnVtXp[3][ich]=ib*ScaleNbinsX; } } } if(tp1NSig[ich]>-NNN && fabs(grSPE->GetY()[ib])MINBINSWID){ tm1NSig[ich]=grSPE->GetX()[ib]; ibm1=ib; ibntm1NSig[ich]=ib; ibnVtXm[0][ich]=ib*ScaleNbinsX; } if(tp2NSig[ich]>-NNN && ib-ibp2>MINBINSWID){ if(tm2NSig[ich]==-NNN){ tm2NSig[ich]=grSPE->GetX()[ib]; ibm2=ib; ibntm2NSig[ich]=ib; ibnVtXm[1][ich]=ib*ScaleNbinsX; } } if(tp3NSig[ich]>-NNN && ib-ibp3>MINBINSWID){ if(tm3NSig[ich]==-NNN){ tm3NSig[ich]=grSPE->GetX()[ib]; ibm3=ib; ibnVtXp[2][ich]=ib*ScaleNbinsX; } } if(tp4NSig[ich]>-NNN && ib-ibp4>MINBINSWID){ if(tm4NSig[ich]==-NNN){ tm4NSig[ich]=grSPE->GetX()[ib]; ibm4=ib; ibnVtXp[3][ich]=ib*ScaleNbinsX; } } } if(tm2NSig[ich]>-1 && tm3NSig[ich]>-1 && tm4NSig[ich]>-1)break; } for(Int_t ib=ibp1; ib<=ibm1; ib++)Ptp1tm1[ich]+=grSPE->GetY()[ib]; for(Int_t ib=ibp2; ib<=ibm2; ib++)Ptp2tm2[ich]+=grSPE->GetY()[ib]; if(ibm1>0)ANSig1[ich]=TMath::MaxElement(ibm1-ibp1,&grSPE->GetY()[ibp1]); if(ibm2>0)ANSig2[ich]=TMath::MaxElement(ibm2-ibp2,&grSPE->GetY()[ibp2]); if(ibm3>0)ANSig3[ich]=TMath::MaxElement(ibm3-ibp3,&grSPE->GetY()[ibp3]); if(ibm4>0)ANSig4[ich]=TMath::MaxElement(ibm4-ibp4,&grSPE->GetY()[ibp4]); Rx[ich].tp1NSig=tp1NSig[ich]; Rx[ich].tm1NSig=tm1NSig[ich]; Rx[ich].tp2NSig=tp2NSig[ich]; Rx[ich].tm2NSig=tm2NSig[ich]; Rx[ich].tp3NSig=tp3NSig[ich]; Rx[ich].tm3NSig=tm3NSig[ich]; if(ibm1>0&&ibm2>0&&ibp3==-1){PDirect[ich]=FFTtools::sumVoltageSquared(grSPE,ibp1,ibm1); PRefrac[ich]=FFTtools::sumVoltageSquared(grSPE,ibp2,ibm2);} if(Rx[ich].tm2NSig>-1 && LDebug)printf("Rx[%d].tp1NSig=%g / tm1NSig=%g / tp2NSig=%g / tm2NSig=%g\n",ich,Rx[ich].tp1NSig,Rx[ich].tm1NSig,Rx[ich].tp2NSig,Rx[ich].tm2NSig); return tp2NSig[ich]-tp1NSig[ich]; } inline Float_t rms4z0(Float_t v[4], Int_t iuse[4]){ Int_t n0=0; Float_t v0[4]; for(Int_t iv=0; iv<4; iv++){ if(abs(v[iv])==NNN||v[iv]==0)continue; if(iuse[iv]!=1)continue; v0[n0]=v[iv]; n0++; } if(LDebug)printf("rms4z0: n0=%d",n0); if(n0>1)return TMath::RMS(n0,v0); else return -1; } inline Float_t Cheap4rms(Float_t f1, Float_t f2, Float_t f3, Float_t f4){ fdum=(f1+f2+f3+f4)/4.; fdum1=fabs(f1-fdum)+fabs(f2-fdum)+fabs(f3-fdum)+fabs(f4-fdum); return fdum1/4.; } inline void FillNVTX(Int_t iStation, Int_t ievtype){ Float_t rAvg, rRMS, phiAvg, phiRMS, theAvg, theRMS, r2GloTx; memset(xntvar,0,sizeof(xntvar)); FitvtxMinuit.r=FitPar[0]; FitvtxMinuit.phi=Map2pm180deg(FitPar[1]); FitvtxMinuit.the=FitPar[2]; FitvtxMinuit.z=FitvtxMinuit.r*cos(FitvtxMinuit.the*TMath::DegToRad()); FitvtxMinuit.dthe=FitErr[2]; // FitvtxMinuit.the=ThetaPrime(FitPar[0],FitPar[1],FitPar[2],RxXYZ0[2]); dunixTimeEV=-1; if(!LCP&&ievtype!=1){ unixTimeEVm1=unixTimeEV; unixTimeEV=unixTime+unixTimeUs/mega; dunixTimeEV=unixTimeEV-unixTimeEVm1; hdttrigEV->Fill(dunixTimeEV); } xntvar[0]=irunNumber; xntvar[1]=ieventNumber; xntvar[2]=unixTime-utc_1Jan11; xntvar[3]=unixTimeUs; xntvar[4]=(Rx[0].SNR+Rx[1].SNR+Rx[2].SNR+Rx[3].SNR)/4; xntvar[5]=(Rx[8].SNR+Rx[9].SNR+Rx[10].SNR+Rx[11].SNR)/4; xntvar[6]=iPolVtx; xntvar[7]=xFitSrc; xntvar[8]=yFitSrc; xntvar[9]=zFitSrc; xntvar[10]=FitvtxMinuit.r; xntvar[11]=FitvtxMinuit.phi; xntvar[12]=fmod(FitvtxMinuit.the,180); xntvar[13]=ChiSqTot; xntvar[14]=FitvtxMinuit.dthe; xntvar[15]=Fit4.r; Fit4.phi=Map2pm180deg(Fit4.phi); xntvar[16]=Fit4.phi; // Fit4.the=ThetaPrime(Fit4.r,Fit4.phi,Fit4.the,RxXYZ0[2]); xntvar[17]=Fit4.the; xntvar[18]=Fit4.dphi; xntvar[19]=Fit4.dthe; xntvar[20]=Fit4.ncomb; Fit4.z=TMath::Max(Fit4.r*cos(Fit4.the*TMath::DegToRad()),-9999.); xntvar[21]=nFitVtx; xntvar[22]=phiMaxDegV; xntvar[23]=90-theMaxDegV; xntvar[24]=E9V; xntvar[25]=phiMaxDegH; xntvar[26]=90-theMaxDegH; xntvar[27]=E9H; xntvar[28]=Vvtx4Z1.r; Vvtx4Z1.phi=Map2pm180deg(Vvtx4Z1.phi); xntvar[29]=Vvtx4Z1.phi; xntvar[30]=Vvtx4Z1.the; xntvar[31]=Vvtx4Z1.dphi; xntvar[32]=Vvtx4Z1.dthe; Vvtx4Z1.z=TMath::Max(Vvtx4Z1.r*cos(Vvtx4Z1.the*TMath::DegToRad()),-9999.); getAvgRMS3(Vvtx4Z1.r,Fit4.r,FitPar[0],rAvg,rRMS); getAvgRMS3(Vvtx4Z1.phi,Fit4.phi,Map2pm180deg(FitPar[1]),phiAvg,phiRMS); getAvgRMS3(Vvtx4Z1.the,Fit4.the,FitvtxMinuit.the,theAvg,theRMS); if(nFitVtx==3||Fit4.phi==-1){ if(iPolVtx==0){ getAvgRMS3(phicog,phiMaxDegV,Map2pm180deg(FitPar[1]),phiAvg,phiRMS); getAvgRMS3(thecog,90-theMaxDegV,Map2pm180deg(FitPar[1]),theAvg,theRMS); } else{ getAvgRMS3(phicog,phiMaxDegH,Map2pm180deg(FitPar[1]),phiAvg,phiRMS); getAvgRMS3(thecog,90-theMaxDegH,Map2pm180deg(FitPar[1]),theAvg,theRMS); } } xntvar[33]=phiAvg; xntvar[34]=phiRMS; Float_t rminTx, phiminTx, theminTx; idum=iTxMinimumAngle2Vtx(FitPar[0],xntvar[11],xntvar[12],rminTx,phiminTx,theminTx); xntvar[35]=rminTx; xntvar[36]=phiminTx; xntvar[37]=theminTx; xntvar[38]=idum; xntvar[39]=SNRxcperCh; // if(iPolVtx==0)getAvgRMS4(Vvtx4Z1.the,Fit4.the,FitvtxMinuit.the,90-theMaxDegV,theAvg,theRMS); // else getAvgRMS4(Vvtx4Z1.the,Fit4.the,FitvtxMinuit.the,90-theMaxDegH,theAvg,theRMS); xntvar[40]=theAvg; xntvar[41]=theRMS; xntvar[42]=nRxDimX; xntvar[43]=nRxDimY; xntvar[44]=nRxDimZ; xntvar[45]=dtrmsCPxc; xntvar[46]=ACPxc; xntvar[47]=fTH1CPxc; xntvar[48]=trigCode; xntvar[49]=nbinsVtgr[0]; xntvar[50]=dtVtgr; xntvar[51]=nTmpl; xntvar[52]=nFitVTX; xntvar[53]=ievana0; xntvar[54]=ievana1; xntvar[55]=AvgdtHV; xntvar[56]=nhitsV; xntvar[57]=nhitsH; xntvar[58]=utcday; xntvar[59]=utchr0; xntvar[60]=utcmin; xntvar[61]=utcsec; xntvar[62]=nhitNSig; xntvar[63]=nhitSlope; xntvar[64]=iEvCode; xntvar[65]=czAvgEv; xntvar[66]=czRMSEv; xntvar[67]=phicog; xntvar[68]=thecog; xntvar[69]=SNRVtxMin; xntvar[70]=ichSNRVtxMin; /* AraRootLoc2ArrayGlo(iStation,r2GloTx,phiAvg,theAvg,rGlo,phiGlo,theGlo); xntvar[71]=phiGlo; xntvar[72]=theGlo; r2GloTx=rAvg; if(iPolVtx==0)AraRootLoc2ArrayGlo(iStation,r2GloTx,phiMaxDegV,90-theMaxDegV,rIFGlo,phiIFGlo,theIFGlo); else AraRootLoc2ArrayGlo(iStation,r2GloTx,phiMaxDegH,90-theMaxDegH,rIFGlo,phiIFGlo,theIFGlo); xntvar[73]=phiIFGlo; xntvar[74]=theIFGlo; xntvar[75]=rAvg; xntvar[76]=rRMS; Float_t rtmp=2*rAvg; if(ievana0==3)rtmp=DPTx[0].rGlo; if(ievana0==4)rtmp=ICLTx.rGlo; Float_t phitmp, thetmp; AraRootLoc2ArrayGlo(iStation,rtmp,phiAvg,theAvg,rGlo,phitmp,thetmp); xntvar[77]=rGlo; */ xntvar[78]=phiMaxZIFG; xntvar[79]=theMaxZIFG; //ThetaPrime(30,phiMaxZIFG,theMaxZIFG,RxXYZ0[2]); xntvar[80]=TOTSum/MCH16; xntvar[81]=nSATSumV; xntvar[82]=ichMinHitTime; xntvar[83]=FitErr[1]; xntvar[84]=phiMaxZIFG1; xntvar[85]=theMaxZIFG1; xntvar[86]=nhitsgr00V; xntvar[87]=nhitsgr00H; xntvar[88]=getdevHitTimes(tp1NSig,tSlope); xntvar[89]=sumResidParPairsV/nFitVtx; xntvar[90]=SNR2TOTMin; xntvar[91]=(Rx[4].SNR+Rx[5].SNR+Rx[6].SNR+Rx[7].SNR)/4; xntvar[92]=(Rx[12].SNR+Rx[13].SNR+Rx[14].SNR+Rx[15].SNR)/4; xntvar[93]=ihitsCodeV; xntvar[94]=ihitsCodeH; xntvar[95]=sumResidParPairsH/nFitVtx; xntvar[96]=Cheap4rms(Rx[0].SNR,Rx[1].SNR,Rx[2].SNR,Rx[3].SNR); xntvar[97]=Cheap4rms(Rx[8].SNR,Rx[9].SNR,Rx[10].SNR,Rx[11].SNR); xntvar[98]=Cheap4rms(Rx[4].SNR,Rx[5].SNR,Rx[6].SNR,Rx[7].SNR); xntvar[99]=Cheap4rms(Rx[12].SNR,Rx[13].SNR,Rx[14].SNR,Rx[15].SNR); xntvar[100]=nRxADCX; xntvar[101]=PGdPerCh/nFitVtx; xntvar[102]=zTx0z; TMath::Sort(MCH16,RxPower,iptdum,false); xntvar[103]=RxPower[iptdum[0]]+RxPower[iptdum[1]]+RxPower[iptdum[2]]+RxPower[iptdum[3]]; xntvar[104]=Rx[ichMinHitTime].phi; xntvar[105]=nSATSumH; xntvar[106]=WfPV; xntvar[107]=WfPH; xntvar[108]=fVExcursion; xntvar[109]=fHExcursion; xntvar[110]=iDPcode; xntvar[111]=dunixTime00; xntvar[112]=phiMaxDegV1; xntvar[113]=90-theMaxDegV1; //KLUDGE!!!!!! xntvar[114]=E25V; xntvar[115]=nX1VTot; xntvar[116]=nNadirV; xntvar[117]=nNadirH; xntvar[118]=nZenithV; xntvar[119]=nZenithH; xntvar[120]=TOTMax; xntvar[121]=dczAvgH; xntvar[122]=dczAvgV; xntvar[123]=czAvgH; xntvar[124]=czAvgV; // xntvar[125]=czAvgHV; xntvar[126]=dczAvgHV; xntvar[127]=nczAvgHV; xntvar[128]=dtHV; xntvar[129]=ddt0HV; xntvar[130]=zutcspice; xntvar[71]=ASMvtx.r; xntvar[72]=ASMvtx.phi; xntvar[73]=ASMvtx.the; ASMvtx.z=TMath::Max(ASMvtx.r*cos(ASMvtx.the*TMath::DegToRad()),-9999.); xntvar[74]=iTxCPCode; xntvar[75]=iTxCPrfin; xntvar[76]=nDPVDPH; xntvar[77]=dunixTimeEV; xntvar[131]=FitvtxMinuit.z; xntvar[132]=Fit4.z; xntvar[133]=Vvtx4Z1.z; xntvar[134]=ASMvtx.z; xntvar[135]=vWind; xntvar[136]=phiWind; xntvar[137]=T2mWind; xntvar[138]=hr0Wind; GetSkewKurt(false); xntvar[139]=AskewX; xntvar[140]=AskewY; xntvar[141]=AskewZ; xntvar[142]=AkurtX; xntvar[143]=AkurtY; xntvar[144]=AkurtZ; xntvar[145]=AWtrsqr; xntvar[146]=CCAxWt; xntvar[147]=CCAyWt; xntvar[148]=CCradius; xntvar[153]=Fit4.ncomb; xntvar[154]=Vvtx4Z1.ncomb; xntvar[155]=ASMvtx.dphi; xntvar[156]=ASMvtx.dthe; xntvar[157]=ASMvtx.ncomb; xntvar[158]=zTx0zb; xntvar[159]=FitParSNR[0]; xntvar[160]=FitParSNR[1]; xntvar[161]=Map2pm180deg(FitParSNR[2]); xntvar[162]=FitParSNR[3]; xntvar[163]=NEVT0->GetEntries()-1; xntvar[164]=LTxRaiseTLowerF; xntvar[165]=iICLPol; xntvar[166]=Rx3SNRV; xntvar[167]=iPol3SNR; xntvar[168]=ich3SNRV; xntvar[169]=Rx3P5nsV; xntvar[170]=Rx3SNRH; xntvar[171]=ich3SNRH; xntvar[172]=Rx3P5nsH; xntvar[173]=iPolVtxEvm1; xntvar[174]=zTx0zd; xntvar[175]=zTx0ze; xntvar[176]=phiAVAR; xntvar[177]=theAVAR; for(Int_t ich=0; ich<16; ich++){ if(!Rx[ich].LVtx)continue; h1dtresid[ich]->Fill(tFitResid[ich]); h2dtresidMinuitVCh->Fill(tFitResid[ich],ich); for(Int_t jch=ich+1; jch<16; jch++){ if(!Rx[jch].LVtx)continue; h2residij->Fill(ich,jch,dtFitResid[ich][jch]); } } ZLoc2ArrayGlo(FitvtxMinuit.r,FitvtxMinuit.phi,FitvtxMinuit.the,fdum,fdum1,fdum2); printf("%s LOC: phi=%6.1f Fit4phi=%6.1f Z4phi=%6.1f phihat=%6.1f phiIFGV=%6.1f / the=%6.1f Fit4the=%6.1f Z4the=%6.1f thehat=%6.1f theIFGV=%6.1f\n%s GLO: phi=%6.1f the=%6.1f%s\n",KRED,FitvtxMinuit.phi,Fit4.phi,Vvtx4Z1.phi,phicog,phiMaxDegV,FitvtxMinuit.the,Fit4.the,Vvtx4Z1.the,thecog,theMaxDegV,KBLU,fdum1,fdum2,KNRM); } inline Bool_t LnRxDimXYZ(Int_t ich0, Int_t ich1, Int_t ich2, Int_t ich3){ nRxDimX=1; nRxDimY=1; nRxDimZ=1; if(Rx[ich0].x==Rx[ich1].x)nRxDimX++; if(Rx[ich0].y==Rx[ich1].y)nRxDimY++; if(Rx[ich0].z==Rx[ich1].z)nRxDimZ++; if(Rx[ich0].x==Rx[ich2].x)nRxDimX++; if(Rx[ich0].y==Rx[ich2].y)nRxDimY++; if(Rx[ich0].z==Rx[ich2].z)nRxDimZ++; if(Rx[ich0].x==Rx[ich3].x)nRxDimX++; if(Rx[ich0].y==Rx[ich3].y)nRxDimY++; if(Rx[ich0].z==Rx[ich3].z)nRxDimZ++; if(nRxDimX==3 && LDebug)printf("X3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich0,Rx[ich0].x,ich1,Rx[ich1].x,ich2,Rx[ich2].x,ich3,Rx[ich3].x); if(nRxDimY==3 && LDebug)printf("Y3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich0,Rx[ich0].y,ich1,Rx[ich1].y,ich2,Rx[ich2].y,ich3,Rx[ich3].y); if(nRxDimZ==3 && LDebug)printf("Z3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich0,Rx[ich0].z,ich1,Rx[ich1].z,ich2,Rx[ich2].z,ich3,Rx[ich3].z); if(nRxDimX==3||nRxDimY==3||nRxDimZ==3)return false; nRxDimX=1; nRxDimY=1; nRxDimZ=1; if(Rx[ich1].x==Rx[ich0].x)nRxDimX++; if(Rx[ich1].y==Rx[ich0].y)nRxDimY++; if(Rx[ich1].z==Rx[ich0].z)nRxDimZ++; if(Rx[ich1].x==Rx[ich2].x)nRxDimX++; if(Rx[ich1].y==Rx[ich2].y)nRxDimY++; if(Rx[ich1].z==Rx[ich2].z)nRxDimZ++; if(Rx[ich1].x==Rx[ich3].x)nRxDimX++; if(Rx[ich1].y==Rx[ich3].y)nRxDimY++; if(Rx[ich1].z==Rx[ich3].z)nRxDimZ++; if(nRxDimX==3 && LDebug)printf("ich1=%d X3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich1,ich0,Rx[ich0].x,ich1,Rx[ich1].x,ich2,Rx[ich2].x,ich3,Rx[ich3].x); if(nRxDimY==3 && LDebug)printf("ich1=%d Y3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich1,ich0,Rx[ich0].y,ich1,Rx[ich1].y,ich2,Rx[ich2].y,ich3,Rx[ich3].y); if(nRxDimZ==3 && LDebug)printf("ich1=%d Z3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich1,ich0,Rx[ich0].z,ich1,Rx[ich1].z,ich2,Rx[ich2].z,ich3,Rx[ich3].z); if(nRxDimX==3||nRxDimY==3||nRxDimZ==3)return false; nRxDimX=1; nRxDimY=1; nRxDimZ=1; if(Rx[ich2].x==Rx[ich0].x)nRxDimX++; if(Rx[ich2].y==Rx[ich0].y)nRxDimY++; if(Rx[ich2].z==Rx[ich0].z)nRxDimZ++; if(Rx[ich2].x==Rx[ich1].x)nRxDimX++; if(Rx[ich2].y==Rx[ich1].y)nRxDimY++; if(Rx[ich2].z==Rx[ich1].z)nRxDimZ++; if(Rx[ich2].x==Rx[ich3].x)nRxDimX++; if(Rx[ich2].y==Rx[ich3].y)nRxDimY++; if(Rx[ich2].z==Rx[ich3].z)nRxDimZ++; if(nRxDimX==3 && LDebug)printf("ich2=%d X3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich2,ich0,Rx[ich0].x,ich1,Rx[ich1].x,ich2,Rx[ich2].x,ich3,Rx[ich3].x); if(nRxDimY==3 && LDebug)printf("ich2=%d Y3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich2,ich0,Rx[ich0].y,ich1,Rx[ich1].y,ich2,Rx[ich2].y,ich3,Rx[ich3].y); if(nRxDimZ==3 && LDebug)printf("ich2=%d Z3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich2,ich0,Rx[ich0].z,ich1,Rx[ich1].z,ich2,Rx[ich2].z,ich3,Rx[ich3].z); if(nRxDimX==3||nRxDimY==3||nRxDimZ==3)return false; nRxDimX=1; nRxDimY=1; nRxDimZ=1; if(Rx[ich3].x==Rx[ich0].x)nRxDimX++; if(Rx[ich3].y==Rx[ich0].y)nRxDimY++; if(Rx[ich3].z==Rx[ich0].z)nRxDimZ++; if(Rx[ich2].x==Rx[ich1].x)nRxDimX++; if(Rx[ich2].y==Rx[ich1].y)nRxDimY++; if(Rx[ich2].z==Rx[ich1].z)nRxDimZ++; if(Rx[ich3].x==Rx[ich2].x)nRxDimX++; if(Rx[ich3].y==Rx[ich2].y)nRxDimY++; if(Rx[ich3].z==Rx[ich2].z)nRxDimZ++; if(nRxDimX==3 && LDebug)printf("ich3 X3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich0,Rx[ich0].x,ich1,Rx[ich1].x,ich2,Rx[ich2].x,ich3,Rx[ich3].x); if(nRxDimY==3 && LDebug)printf("ich3 Y3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich0,Rx[ich0].y,ich1,Rx[ich1].y,ich2,Rx[ich2].y,ich3,Rx[ich3].y); if(nRxDimZ==3 && LDebug)printf("ich3 Z3: Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g Rx[%d]=%g\n",ich0,Rx[ich0].z,ich1,Rx[ich1].z,ich2,Rx[ich2].z,ich3,Rx[ich3].z); if(nRxDimX==3||nRxDimY==3||nRxDimZ==3)return false; return true; } inline void FMXC(const char *rC, const char *phiC, const char *theC, Bool_t LSim){ TMinuit *eM=new TMinuit(3); eM->SetPrintLevel(0); //-1 is minimum info eM->SetMaxIterations(MAXITERMINUIT); Int_t ierflg = 0; Int_t convergence[2] = {0,0}; // Convergence flags for SIMPLEX and MIGRAD (0 - conv, 4 - failed) Double_t arglist[2]={200,1}; //,10,10}; // UP = 200, 1 - is not used Double_t argsSimplexMigrad[2]={1000, 1}; // MaxCalls = 1000, tolerance = 1 Double_t step[4]={20,4,4,4}; // arglist[0]=200; // arglist[1]=1; eM->mnexcm("SET ERR",arglist,1,idum); // Parameter UP for both SIMPLEX and MIGRAD is set up here to 200 eM->SetFCN(calc_chi_square_XC); //chi square routine eM->mnparm(0,"r",Rx[ichMinHitTime].r,step[0],0,RMAXMINUIT,ierflg); eM->mnparm(1,"phi",Rx[ichMinHitTime].phi,step[1],-PHIMAXMINUIT*2,PHIMAXMINUIT*2,ierflg); eM->mnparm(2,"the",Rx[ichMinHitTime].the,step[2],0,180,ierflg); eM->mnexcm("SIMPLEX", argsSimplexMigrad, 2, convergence[0]); eM->mnexcm("MIGRAD", argsSimplexMigrad, 2, convergence[1]); // But MIGRAD somehow uses UP along with tolerance // eM->mnstat(chi_square, tmp_double, tmp_double, tmp_int, tmp_int, tmp_int); eM->GetParameter(0, FP[0], FitErr[0]); eM->GetParameter(1, FP[1], FitErr[1]); eM->GetParameter(2, FP[2], FitErr[2]); if(LSim)printf("%sdMinuit.r=%g+/-%g dMinuit.phi=%g+/-%g dMinuit.the=%g+/-%g %s\n",KYEL,FP[0]-simVtx[0],FitErr[0],FP[1]-simVtx[1],FitErr[1],FP[2]-simVtx[2],FitErr[2],KNRM); delete eM; } void calc_chi_square_A(Int_t &npar, Double_t *gin, Double_t &chisquare, Double_t *par, Int_t iflag){ // PrintRxHits(); chisquare=0.0; // memset(ncombFit,0,sizeof(ncombFit)); Float_t dxy2, DistanceSq[MCH], CosThe[MCH]; Float_t phirad=par[2]*TMath::DegToRad(); Float_t therad=par[3]*TMath::DegToRad(); Float_t x0=par[1]*sin(therad)*cos(phirad); Float_t y0=par[1]*sin(therad)*sin(phirad); Float_t z0=par[1]*cos(therad); if(LDebug)printf("Starting x/y/z=%g/%g/%g\n",x0,y0,z0); for(int ich=0; ichzSurfRx||Rx[ich].SNR<=0)continue; dxy2=(x0-Rx[ich].x)*(x0-Rx[ich].x)+(y0-Rx[ich].y)*(y0-Rx[ich].y); DistanceSq[ich]=dxy2+(z0-Rx[ich].z)*(z0-Rx[ich].z); CosThe[ich]=sqrt(dxy2/DistanceSq[ich]); if(LDebug)printf("ich=%d: x=%g/y=%g/z=%g Rx.HitTime=%g LVtx=%d TransitTimens=%g\n",ich,Rx[ich].x,Rx[ich].y,Rx[ich].z,Rx[ich].HitTime,Rx[ich].LVtx,CosThe[ich]); } Float_t delta; Int_t nXSATScope=0; Int_t nchisq=0; // const Int_t MAXXSATSCOPE=8; for(Int_t ich=0; ichMAXXSATSCOPE)nXSATScope++; if(TMath::IsNaN(AExpFit[ich]))continue; if(!Rx[ich].LVtx)continue; delta=par[0]*CosThe[ich]/sqrt(DistanceSq[ich])-AExpFit[ich]; ///Rx[ich].Prms; //x[ich].SNR; //AExpFit[ich]; //Rx[ich].SNR chisquare+=delta*delta; //Rx[ich].hitweight; if(LDebug)printf("AFit ich=%d xsrc=%g/ysrc=%g/zsrc=%g d2src=%g Rx[ich].SNR=%g delta=%g chisquare=%g\n",ich,x0,y0,z0,sqrt(DistanceSq[ich]),AExpFit[ich],delta,chisquare); nchisq++; } // for(Int_t ich=0; ich0)dtFitResid[ich]/=ncombFit[ich]; if(nchisq>0)chisquare/=nchisq; //chisq/dof ChiSqTot=chisquare; xFitSrc=par[1]*cos(par[2]*TMath::DegToRad())*sin(par[3]*TMath::DegToRad()); yFitSrc=par[1]*sin(par[2]*TMath::DegToRad())*sin(par[3]*TMath::DegToRad()); zFitSrc=par[1]*cos(par[3]*TMath::DegToRad()); par[2]=Map2pm180deg(par[2]); if(LDebug)printf("AFit A0=%g nchisq=%d nXSATScope=%d Ending x/y/z=%g/%g/%g\n",AExpFit[ichMinHitTime],nchisq,nXSATScope,xFitSrc,yFitSrc,zFitSrc); return; } inline void FitMinuitSNR(const char *rC, const char *phiC, const char *theC, Bool_t Lmnseek, Bool_t Lmigrad){ TMinuit* FitSNRMinuit=new TMinuit(MVARMINUIT); // FitSNRMinuit->mnrset(1); FitSNRMinuit->SetPrintLevel(0); //-1 is minimum info FitSNRMinuit->SetMaxIterations(MAXITERMINUIT); arglist[0]=200; arglist[1]=1; FitSNRMinuit->mnexcm("SET ERR",arglist,1,idum); //Parameter UP for both SIMPLEX and MIGRAD is set up here=200 FitSNRMinuit->SetFCN(calc_chi_square_A); //chi square routine - MUST RESET AFTER LOCAL CALL TO GAUS, E.G.!!!!!! CRASHES HERE FOR A1/ARAROOT 6 (6mar19) if(ichMinHitTime<0)cout<<"ERRZ!!! ichMinHitTime<0!"<mnparm(0,"A0",AExpFit[ichMinHitTime],1,1,8192*2,ierflg); FitSNRMinuit->mnparm(1,rC,Rx[ichMinHitTime].r,step[0],8,RMAXMINUIT,ierflg); FitSNRMinuit->mnparm(2,phiC,Rx[ichMinHitTime].phi,step[1],-PHIMAXMINUIT*2,PHIMAXMINUIT*2,ierflg); FitSNRMinuit->mnparm(3,theC,Rx[ichMinHitTime].the,step[2],0,180,ierflg); if(Lmnseek)FitSNRMinuit->mnseek(); //CPU-hog? FitSNRMinuit->mnsimp(); if(Lmigrad)FitSNRMinuit->mnmigr(); for(Int_t ivar=0; ivar<4; ivar++)FitSNRMinuit->GetParameter(ivar,FitParSNR[ivar],FitErrSNR[ivar]); FitSNRMinuit->mnerrs(0,ddum,ddum1,FitErrSNR[0],ddum2); FitSNRMinuit->mnerrs(1,ddum,ddum1,FitErrSNR[1],ddum2); FitSNRMinuit->mnerrs(2,ddum,ddum1,FitErrSNR[2],ddum2); FitSNRMinuit->mnerrs(3,ddum,ddum1,FitErrSNR[3],ddum2); if(LDebug)printf("%sMinuitSNR.A=%g+/-%g MinuitSNR.r=%g+/-%g MinuitSNR.phi=%g+/-%g MinuitSNR.the=%g+/-%g%s\n",KYEL,FitParSNR[0],FitErrSNR[0],FitParSNR[1],FitErrSNR[1],FitParSNR[2],FitErrSNR[2],FitParSNR[3],FitErrSNR[3],KNRM); delete FitSNRMinuit; } inline void FitMinuitXC(const char *rC, const char *phiC, const char *theC, Bool_t Lmnseek, Bool_t Lmigrad){ TMinuit* eventrecoMinuit=new TMinuit(MVARMINUIT); eventrecoMinuit->SetPrintLevel(0); //-1 is minimum info eventrecoMinuit->SetMaxIterations(MAXITERMINUIT); arglist[0]=200; arglist[1]=1; eventrecoMinuit->mnexcm("SET ERR",arglist,1,idum); // Parameter UP for both SIMPLEX and MIGRAD is set up here to 200 // eventrecoMinuit->mnrset(1); eventrecoMinuit->SetFCN(calc_chi_square_XC); //chi square routine - MUST RESET AFTER LOCAL CALL TO GAUS, E.G.!!!!!! CRASHES HERE FOR A1/ARAROOT 6 (6mar19) eventrecoMinuit->mnparm(0,rC,R0FITMINUIT,step[0],0,RMAXMINUIT,ierflg); eventrecoMinuit->mnparm(1,phiC,Rx[ichMinHitTime].phi,step[1],-PHIMAXMINUIT*2,PHIMAXMINUIT*2,ierflg); eventrecoMinuit->mnparm(2,theC,Rx[ichMinHitTime].the,step[2],0,THEMAXMINUIT*2,ierflg); if(nFitVtx==3){ eventrecoMinuit->mnparm(0,rC,1000.,step[0],0,RMAXMINUIT,ierflg); eventrecoMinuit->FixParameter(0); } if(Lmnseek)eventrecoMinuit->mnseek(); //CPU-hog? eventrecoMinuit->mnsimp(); if(Lmigrad)eventrecoMinuit->mnmigr(); for(Int_t ivar=0; ivar<3; ivar++)eventrecoMinuit->GetParameter(ivar,FitPar[ivar],FitErr[ivar]); eventrecoMinuit->mnerrs(1,ddum,ddum1,FitErr[1],ddum2); eventrecoMinuit->mnerrs(2,ddum,ddum1,FitErr[2],ddum2); if(LMC)printf("eventrecoMinuit phi=%g the=%g dphi=%g dthe=%g\n",FitPar[1],FitPar[2],FitErr[1],FitErr[2]); if(LMC)printf("Sim r=%g Simphi=%g Simthe=%g\n",simVtx[0],simVtx[1],simVtx[2]); eventrecoMinuit->mnprin(3,fdum); printf("ierflg=%d / chisquare=%g convergence=%d\n",ierflg,ChiSqTot,convergence[0]); //ChiSqTot==0 =>failed fit!!!! printf("Fit4.r=%g Fit4.phi=%g+/-%g Fit4.the=%g+/-%g ncomb=%d\n",Fit4.r,Fit4.phi,Fit4.dphi,Fit4.the,Fit4.dthe,Fit4.ncomb); delete eventrecoMinuit; } inline void FillNDT(){ NDELTVH->Fill(dtxc[8][0],dtxc[9][1],dtxc[10][2],dtxc[11][3],dtxc[12][4],dtxc[13][5],dtxc[14][6],dtxc[15][7],SNRxc[8][0],SNRxc[9][1],SNRxc[10][2],SNRxc[11][3],SNRxc[12][4],SNRxc[13][5],SNRxc[14][6]); } inline void hist2dSum(TH2 *hIn, TH2 *hOut){ for (Int_t ib=0;ibGetNbinsX();ib++){ for (Int_t jb=0;jbGetNbinsY();jb++){ Double_t AtempV=hIn->GetBinContent(ib,jb); hOut->Fill(ib,jb,AtempV); } } } inline void getParPairsV(){ Float_t dx0, dy0, dz0, dx1, dy1, dz1, drsq4Rxxyz; for(Int_t ich=0; ich<8; ich++){ for(Int_t jch=ich+1; jch<8; jch++){ dx0=Rx[ich].x-Rx[jch].x; dy0=Rx[ich].y-Rx[jch].y; dz0=Rx[ich].z-Rx[jch].z; for(Int_t kch=jch+1; kch<8; kch++){ if(kch==ich||kch==jch)continue; for(Int_t lch=kch+1; lch<8; lch++){ if(lch==ich||lch==jch)continue; dx1=Rx[kch].x-Rx[lch].x; dy1=Rx[kch].y-Rx[lch].y; dz1=Rx[kch].z-Rx[lch].z; drsq4Rxxyz=sqrt((dx0-dx1)*(dx0-dx1)+(dy0-dy1)*(dy0-dy1)+(dz0-dz1)*(dz0-dz1)); h1drsq4RxxyzV->Fill(log10(drsq4Rxxyz)); LParPairsV[ich][jch][kch][lch]=drsq4Rxxyz<0.4; //1 ns transit time if(LParPairsV[ich][jch][kch][lch])printf("LParPairs[%d][%d][%d][%d] drsq4Rxxyz=%g true!\n",ich,jch,kch,lch,drsq4Rxxyz); } } } } } inline void getParPairsH(){ Float_t dx0, dy0, dz0, dx1, dy1, dz1, drsq4Rxxyz; for(Int_t ich=8; ichFill(log10(drsq4Rxxyz)); LParPairsH[ich-8][jch-8][kch-8][lch-8]=drsq4Rxxyz<0.4; //1 ns transit time if(LParPairsH[ich-8][jch-8][kch-8][lch-8])printf("LParPairsH[%d][%d][%d][%d] drsq4Rxxyz=%g true!\n",ich-8,jch-8,kch-8,lch-8,drsq4Rxxyz); } } } } } inline Float_t ResidParPairsH(Float_t RxHitTime[16]){ const Float_t MAXDT01NS=2; Float_t dt01; sumResidParPairsH=0; for(Int_t ich=8; ichFill(ich,dt01); h2dtResidParPairs->Fill(jch,dt01); h2dtResidParPairs->Fill(kch,dt01); h2dtResidParPairs->Fill(lch,dt01); NPARPAIRSH->Fill(ich,jch,kch,lch,dt01); } } } } return sumResidParPairsH; } inline Float_t ResidParPairsV(Float_t RxHitTime[16]){ const Float_t MAXDT01NS=2; Float_t dt01; sumResidParPairsV=0; for(Int_t ich=0; ich<8; ich++)dtResidParPairs[ich]=0; for(Int_t ich=0; ich<8; ich++){ if(!Rx[ich].LVtx)continue; for(Int_t jch=ich+1; jch<8; jch++){ if(!Rx[jch].LVtx)continue; for(Int_t kch=jch+1; kch<8; kch++){ if(kch==ich||kch==jch)continue; if(!Rx[kch].LVtx)continue; for(Int_t lch=kch+1; lch<8; lch++){ if(lch==ich||lch==jch)continue; if(!Rx[lch].LVtx)continue; if(!LParPairsV[ich][jch][kch][lch])continue; dt01=(RxHitTime[ich]-RxHitTime[jch])-(RxHitTime[kch]-RxHitTime[lch]); LParPairsEvV[ich][jch][kch][lch]=fabs(dt01)<8; printf("LParPairsV[%d][%d][%d][%d] dt01=%g\n",ich,jch,kch,lch,dt01); sumResidParPairsV+=fabs(dt01); dtResidParPairs[ich]+=dt01; dtResidParPairs[jch]+=dt01; dtResidParPairs[kch]+=dt01; dtResidParPairs[lch]+=dt01; h2dtResidParPairs->Fill(ich,dt01); h2dtResidParPairs->Fill(jch,dt01); h2dtResidParPairs->Fill(kch,dt01); h2dtResidParPairs->Fill(lch,dt01); NPARPAIRSV->Fill(ich,jch,kch,lch,dt01); } } } } return sumResidParPairsV; } /*(from MD:) 06Jan15: 01:25 UTC→01:35 – Vpol Rooftop 01:36 UTC→01:46 – Hpol Rooftop 02:07 UTC→02:17 UTC – 2450 m pulser string 1 02:18→02:28 – 1450 m pulser IC string 1 02:34→02:44 – 1450 m pulser IC string 22 02:57→03:07 – Vpol Rooftop 03:07→03:17– Hpol Rooftop 03:18→03:28 – Hpol Rooftop 03:48→03:58 – Vpol Rooftop 07Jan15● 02:34→02:49 – Vpol Rooftop 02:52→03:07 – Hpol Rooftop 22:00→16:00 08Jan: both 1450 & 2450 deep pulsers string 1 10Jan15● 02:42→02:52 – Vpol Rooftop 02:53→03:03 – Hpol Rooftop 12Jan15 22:24→22:34 – Vpol Rooftop 22:35→22:45 – Hpol Rooftop */ /*Surface Pulser data: http://ara.physics.wisc.edu/docs/0013/001339/002/SurfacePulserStudyFull.pdf ALL TIMES BELOW NZDT=>MUST SUBTRACT 13 HOURS TO GET UTC! which means all locations for Ara02 were taken on Jan. 20th and all locations for Ara03 on Jan. 21st The pulser ran at 1 Hz, a band should show up in the triggering for each pulser location Location Date ON OFF 201 21 Jan 2015 10:05 10:15 / 1421834700 202 21 Jan 2015 10:50 11:00 / 1421837400 203 20 Jan 2015 13:38 13:48 / 1421761080 204 20 Jan 2015 15:25 15:35 / 1421767500 205 21 Jan 2015 9:03 9:13 / 1421831580 206 21 Jan 2015 9:33 9:43 / 1421832780 207 21 Jan 2015 10:18 10:28 / 1421835480 208 20 Jan 2015 14:38 14:48 / 1421764680 209 20 Jan 2015 15:10 15:20 / 1421766600 Didn’t work directly 210 21 Jan 2015 11:04 11:14 / 1421838240 211 21 Jan 2015 9:16 9:26 / 1421831760 212 21 Jan 2015 9:49 9:59 / 1421833740 / Didn’t work directly 213 21 Jan 2015 10:31:30 10:41:30 / 1421836290 214 20 Jan 2015 14:54 15:04 / 1421765640 / Didn’t work directly 215 21 Jan 2015 11:20 11:30 / 1421839200 216 22 Jan 2015 11:54:30 12:04:30 / 1421927640 217 22 Jan 2015 12:09:30 12:19:30 / 1421928540 218 22 Jan 2015 12:22:30 12:32:30 / 1421929350 219 22 Jan 2015 12:36:30 12:46:30 / 1421930190 220 22 Jan 2015 11:40 11:50 / 1421926800 221 22 Jan 2015 11:01 11:11 / 1421924460 222 22 Jan 2015 10:34 10:44 / 1421922840 223 22 Jan 2015 9:54 10:04:30 / 1421920440 224 22 Jan 2015 9:26 9:36 / 1421918760 First bip in the radio at 9:24 then it stopped due to loose cable. Once cable fixed, pulse restarted at 9:26 . 225 22 Jan 2015 11:27:30 11:37:30 / 1421926050 226 22 Jan 2015 11:14 11:24 / 1421925240 227 22 Jan 2015 10:47 10:57 / 1421923620 228 22 Jan 2015 10:20 10:30 / 1421922000 229 22 Jan 2015 9:41 9:51 / 1421919660 230 22 Jan 2015 9:11 9:21 / 1421917860 */ inline Bool_t LDeepPulserOnUTC(Int_t iStation){ memset(LDP,0,sizeof(LDP)); // if(WfPV1420510020 && unixTime<1420510620); //nada Bool_t LDP0_2015=(unixTime>=1420509186 && unixTime<=1420510612); if(LDP0_2015)LDP[0]=true; //dada! Bool_t LDP1_2015=(unixTime>1420511640 && unixTime<1420512240); if(LDP1_2015)LDP[1]=true; //verified Bool_t LDP2_2015=(unixTime>1420513020 && unixTime<1420513620); if(LDP2_2015)LDP[2]=true; //nada if(unixTime>=1420493804 && unixTime<=1420493807)LDP[1]=true; //subsecond around 0.75 if(unixTime>=1420493802 && unixTime<=1420493808)LDP[1]=true; //dzb changed 18Aug22 from LDP[0]=true; //A3: 888.8 milliseconds A2: 750 milliseconds if(unixTime>1663.63908e6&&unixTime<1663.64035e6)LDP[1]=true; //utcUs>209e3&&utcUs<209.5e3||utcUs>640.43e3&&utcUs<640.46e3 if(unixTime<1663.64148e6&&unixTime>1663.64035e6)LDP[2]=true; if(iStation==0){ //&&WfPV>12){ WfPV not defined yet! if(unixTimeUs>395000&&unixTimeUs<405000&&unixTime>1295.14e6&&unixTime<1295.18e6)LDP[0]=true; if(unixTime>1294.8925e6&&unixTime<1294.896e6)LDP[1]=true; if(unixTime>1294.7358e6&&unixTime<1294.737e6)LDP[2]=true; if(unixTime>1294.8905e6&&unixTime<1294.8925e6)LDP[2]=true; // if(unixTime>1294.7358e6 && unixTime<1294.737e6)LDP[1]=true; // if((unixTime>1294.88e6&&unixTime<1294.9e6) && (unixTimeUs>845000 && unixTimeUs<865000))LDP[1]=true; //16Jan21 if(((unixTime>1294.7358e6&&unixTime<1294.737e6) || (unixTime>1294.88e6&&unixTime<1294.9e6)) && !(unixTimeUs>845000 && unixTimeUs<865000))LDP[2]=true; } if(iStation==2){ if(unixTime>=IC1_2450_utci && unixTime<=IC1_1450_utci)LDP[0]=true; //IC1-2450 exclusively if((unixTime>=IC1_1450_utci && unixTime<=IC22_1450_utci)||(unixTime>=1485301680 && unixTime<=1485302400))LDP[1]=true; //IC1-1450 exclusively if((unixTime>=IC22_1450_utci && unixTime<=IC22_1450_utcf)||(unixTime>=1485302400 && unixTime<=1485303540))LDP[2]=true; //IC22-1450 exclusively if(unixTime>=IC1_1450_2450_utci && unixTime<=IC1_1450_2450_utcf)LDP[3]=true; //IC1-2450 and IC1-1450, in principle, actually all IC1-1450 if(unixTime>=1485301680 && unixTime<=1485302400)LDP[4]=true; //ara02/2017/IC1-1450 if(unixTime>=1485302400 && unixTime<=1485303540)LDP[5]=true; //ara02/2017/IC22-1450 if(unixTime>=1420509168&&unixTime<=1420510612&&unixTimeUs>805200&&unixTimeUs<805300)LDP[0]=true; //2015 Deep pulsing Bool_t LDPPulserOn=((unixTime>1420.49e6&&unixTime<1420.52e6) || (unixTime>1420.66e6&&unixTime<1420.75e6)) && ((unixTimeUs>315000&&unixTimeUs<321000) || (unixTimeUs>860000&&unixTimeUs<960000)); } if(iStation==3){ if(unixTime>=IC1_2450_utci && unixTime<=IC1_1450_utci)LDP[0]=true; if(unixTime>=IC1_1450_utci && unixTime<=IC22_1450_utci)LDP[1]=true; if(unixTime>=IC22_1450_utci && unixTime<=IC22_1450_utcf)LDP[2]=true; if(unixTime>=IC1_1450_2450_utci && unixTime<=IC1_1450_2450_utcf)LDP[3]=true; Bool_t LA3x=unixTime>1420.4939e6&&unixTime<1420.4941e6; } if(unixTime>=1516483200&&unixTime<=1516483920)LDP[0]=true; if(unixTime>=1516477466&&unixTime<=1516480500)LDP[1]=true; if(unixTime>=1516482000&&unixTime<=1516483134)LDP[2]=true; //21jan18 run: if(unixTime>=1516.5685e6&&unixTime<1516.5696e6&&unixTimeUs>683500&&unixTimeUs<685500)LDP[2]=true; if(unixTime>=1516.5639e6&&unixTime<1516.5651e6&&unixTimeUs>567000&&unixTimeUs<569000)LDP[1]=true; //also utcUs=400+/20 || utcUs=575+/-20 if(unixTime>=1516.56722e6&&unixTime<1516.567266e6&&unixTimeUs>38000&&unixTimeUs<400000)LDP[1]=true; //utcUs:675->750 //25jun18 run: if((unixTime>=1529.9621e6&&unixTime<=1529.9631e6) || //unixTime>=1529.9615e6&&unixTime<=1529.9632e6 || (unixTime>=1529.964e6&&unixTime<=1529.9652e6))LDP[2]=true; //IC22S if(unixTime>=1529.9652e6&&unixTime<=1529.966e6)LDP[1]=true; //IC1S - 6 dB on A4 if(unixTime>=1541.7030e6&&unixTime<=1541.7038e6&&((unixTimeUs>220000&&unixTimeUs<260000)||(unixTimeUs>111000&&unixTimeUs<113000)))LDP[1]=true; //November2018 running - 15 dB on A4 if(unixTime>=1541.7046e6&&unixTime<=1541.7060e6&&unixTimeUs>875000&&unixTimeUs<877000)LDP[2]=true; //Dec2018 A5 pulsing - A5 WfPV>8 if(unixTime>=1544.4752e6&&unixTime<=1544.4767e6)LDP[1]=true; if(unixTime>=1544.4767e6&&unixTime<=1544.4780e6)LDP[2]=true; return (LDP[0]||LDP[1]||LDP[2]||LDP[3]||LDP[4]||LDP[5]); } inline void GetutcStats(Int_t ievtype){ Float_t zTx0zm1, zTx0z0, zTx0zp1, utcminm1, utcminp1, utcmin00; Int_t ieLog; LCP0=unixTimeUs<2000 || unixTimeUs>998000; trigCode=0; if(LCP){ trigCode=1; ievana0=1; NEvCP++; dtutcCP=unixTime0-utcCP; utcCP=unixTime0; } if(LUB){ trigCode=2; ievana0=2; NEvUB++; dtutcUB=unixTime0-utcUB; utcUB=unixTime0; } if(LDeepPulserOnUTC(iStation0))ievana0=3; zTx0zLF=-1; zTx0za=-1; zTx0zb=-1; zTx0zc=-1; if(utc000==-1){ utc000=unixTime+unixTime10Ns/1e8; cout<Fill(); } dttrig=unixTime+unixTimeUs/mega-unixTimem1-unixTimeUsm1/mega; if(dttrig<0)printf("%sERRZ: utc times not sequential NEvTot=%d utcm1=%f utc=%f dttrig<0/=%g%s\n",KBLU,NEvTot,unixTimem1+unixTimeUsm1/mega,unixTime+unixTimeUs/mega,dttrig,KNRM); h2TrigTimeOOS->Fill(dttrig,trigCode); fGalacticDay=fmod(utchr0*3600+utcmin*60+utcsec,TSECSIDEREAL)/TSECSIDEREAL; hdttrig->Fill(dttrig); for(Int_t iutc=1; iutc0){ dttrig0=(utcStack[iutcUsStack] +utcUsStack[iutcUsStack]/mega)- (utcStack[iutcUsStack-1]+utcUsStack[iutcUsStack-1]/mega); if(fabs(dttrig0-dttrig)/(dttrig0+dttrig)>0.001)printf("ERRZ: dttrig0=%g != dttrig=%g\n",dttrig0,dttrig); } iMatchUs=0; for(Int_t i=0; iFill(fmod(unixTimeUs-utcUsStack[i],1.)); dtutcStack[i]=utc0S-(utcStack[i]+utcUsStack[i]/mega); if(fabs(utcUsStack[iutcUsStack]-utcUsStack[i])>fabs(idutcUsMin))continue; iMatchUs=i; idutcUsMin=utcUsStack[iutcUsStack]-utcUsStack[i]; } dutcUsMin=utc0S-(utcStack[iMatchUs]+utcUsStack[iMatchUs]/mega); if(LDebug)printf("NEvTot=%d iutcUsStack=%d utcUsStack[iutcUsStack]=%d utcUsStack[%d]=%d dtNtrig=%g idutcUsMin=%d\n",NEvTot,iutcUsStack,utcUsStack[iutcUsStack],iMatchUs,utcUsStack[iMatchUs],dtNtrig,idutcUsMin); NUTC->Fill(ieventNumber,dttrig0,dtNtrig,trigCode,idutcUsMin,unixTimeUs,dutcUsMin,utc0S-utc000,LDP[0],LDP[1],LDP[2],LCP,LUB); NEvStack++; getRealTime(unixTime,false); for(Int_t iz=0; iz2; iz++){ if(TxCoords_utc[iz+1]>unixTime+unixTimeUs/mega && TxCoords_utc[iz]=356&&abs(iYear0)==2018){ if(LInitSpLog){ fSpiceDec18=new TFile("/home/dbesson/src/root/Sp18Log.root"); fSpiceDec18a=new TFile("/home/dbesson/src/root/Sp18Loga.root"); NLogSpice18=(TNtuple*)fSpiceDec18->Get("N"); NLogSpice18->BuildIndex("utcmin0"); hutcminz_pfx=(TProfile*)fSpiceDec18->Get("hutcminz_pfx"); NLS18utc=(TNtuple*)fSpiceDec18a->Get("N"); NLS18utc->BuildIndex("unixtimez"); // NLogSpice18->BuildIndex("unixtime"); LInitSpLog=false; for(Int_t ib=0; ibGetBinContent(ib); } getRealTime(unixTime,false); Int_t ibinmin0=utcmin0-zutcMIN; zTx0zc=-1*(grSpice18LogFile->Eval(utcmin0)); zutcspice=-1; if(ibinmin0>=0&&ibinmin0GetEntryNumberWithBestIndex(unixTime); if(ieLog>0){NLS18utc->GetEntry(ieLog); zTx0zb=NLS18utc->GetLeaf("z")->GetValue();} ieLog=NLogSpice18->GetEntryNumberWithBestIndex(utcmin0); if(ieLog>0){NLS18utc->GetEntry(ieLog); zTx0zLF=NLS18utc->GetLeaf("z")->GetValue();} if(ieLog>0){ NLogSpice18->GetEntry(ieLog); zTx0z0=NLogSpice18->GetLeaf("z")->GetValue(); utcmin00=NLogSpice18->GetLeaf("utcmin0")->GetValue(); NLogSpice18->GetEntry(ieLog-1); zTx0zm1=NLogSpice18->GetLeaf("z")->GetValue(); utcminm1=NLogSpice18->GetLeaf("utcmin0")->GetValue(); NLogSpice18->GetEntry(ieLog+1); zTx0zp1=NLogSpice18->GetLeaf("z")->GetValue(); utcminp1=NLogSpice18->GetLeaf("utcmin0")->GetValue(); zTx0zd=zTx0zm1+(zTx0zp1-zTx0zm1)*(utcmin0-utcminm1)/(utcminp1-utcminm1); fdum=zTx0zm1+(zTx0z0-zTx0zm1)*(utcmin0-utcminm1)/(utcmin00-utcminm1); fdum1=zTx0z0+(zTx0zp1-zTx0z0)*(utcminp1-utcmin0)/(utcminp1-utcmin00); zTx0ze=(2*zTx0zd+fdum+fdum1)/4.; } if(LDebug){ printf("spice utcmin=%d / utcmin0=%d / unixtime=%14f\n",utcmin,utcmin0,unixTime); cout<<"spice cor: utcmin0="<GetValue()<<"/utc in eventTree="<GetValue(); NLogSpice18->Show(ieLog); TTimeStamp autcTime(utcz); printf("%s\n",autcTime.AsString("s")); NLogSpice18->Show(ieLog); cout<=330&&iYear0==2019){ if(LInitSpLog){ fSpiceDec19=new TFile("/home/dbesson/src/root/SpDec19Log.root"); TLogSpice19=(TTree*)fSpiceDec19->Get("TSpiceDec19"); TLogSpice19->BuildIndex("utc"); LInitSpLog=false; } ieLog=TLogSpice19->GetEntryNumberWithBestIndex(unixTime); if(LDebug)cout<<"unixTime="<GetValue(); if(fabs(utcz-unixTime)<60)zTx0zLF=TLogSpice19->GetLeaf("zTx")->GetValue(); if(zTx0zLF!=-1 && zTx0zLF>0)zTx0zLF*=-1; } } zTx0z=zTx0ze; if(zTx0z==-1)zTx0z=zTx0zc; if(zTx0z==-1)zTx0z=zTx0zd; if(zTx0z==-1)zTx0z=zutcspice; if(zTx0z==-1)zTx0z=zTx0zLF; if(zTx0z==-1)zTx0z=zTx0zb; if(zTx0z==-1)zTx0z=zTx0za; printf("zutcspice=%g zTx0zLF=%g zTx0z=%g zTx0za=%g zTx0zb=%g zTx0zc=%g zTx0zd=%g zTx0ze=%g\n",zutcspice,zTx0zLF,zTx0z,zTx0za,zTx0zb,zTx0zc,zTx0zd,zTx0ze); } inline Float_t dt2NextPulse(Float_t period, Float_t dtperiod, Bool_t LSignal){ fdum=-1; Float_t deltwrtPeriod; Bool_t LSigOrSB; if(itrigCodeStack[MSTACKN-1]==1)return -2; for(Int_t iutc=MSTACKN-2; iutc>=0; iutc--){ if(itrigCodeStack[iutc]==1||utcStack[iutc]<=0)continue; idum=int(dtutcStack[iutc]/period); deltwrtPeriod=fabs(dtutcStack[iutc]-idum*period); if(LSignal)LSigOrSB=deltwrtPeriodidum*dtperiod && deltwrtPeriod<2*idum*dtperiod; if(!LSigOrSB)continue; fdum=dtutcStack[iutc]; if(LPrintDbg||LDebug)cout<<"dt2NextPulse LSB="<180)continue; nczAvgHV++; czAvgHV+=czHV[ich]; if(LDebug)printf("nczAvgHV=%d czAvgHV=%g\n",nczAvgHV,czAvgHV); } if(nczAvgHV>1){ czAvgHV/=nczAvgHV; dtHV/=nHV; for(Int_t ich=0; ich<8; ich++){ if(Rx[ich+8].LVtx&&Rx[ich].LVtx){ dtHVCh[ich]=Rx[ich+8].HitTime-Rx[ich].HitTime; ddtHV+=dtHVCh[ich] - dtHV; ddt0HV+=fabs(dtHVCh[ich] - dtHV); } if(fabs(czHV[ich])>180)continue; dczAvgHV+=fabs(czHV[ich]-czAvgHV); } ddtHV/=nHV; ddt0HV/=nHV; dczAvgHV/=nczAvgHV; } if(LDebug)printf("dtHV=%g ddtHV=%g ddt0HV=%g\n",dtHV,ddtHV,ddt0HV); if(ddtHV!=0)printf("ERRZ Sum of deviations from mean ddtHV!=0; =%g\n",ddtHV); for(Int_t ich=0; ich<4; ich++){ dtVtb[ich]=-NNN; //actually string number is argument dtHtb[ich]=-NNN; czV[ich]=-NNN; czH[ich]=-NNN; if(Rx[ich].LVtx && Rx[ich+4].LVtx){ dtVtb[ich]=Rx[ich].HitTime-Rx[ich+4].HitTime; czV[ich]=czij(ich,ich+4,1); if(fabs(czV[ich])>180)continue; if(czV[ich]0)nNadirV++; else nZenithV++; czAvgV+=czV[ich]; } if(Rx[ich+8].LVtx && Rx[ich+12].LVtx){ dtHtb[ich]=Rx[ich+8].HitTime-Rx[ich+12].HitTime; czH[ich]=czij(ich+8,ich+12,1); if(fabs(czH[ich])>180)continue; if(czH[ich]0)nNadirH++; else nZenithH++; czAvgH+=czH[ich]; } } if(nNadirH+nZenithH>0)czAvgH/=(nNadirH+nZenithH); if(nNadirV+nZenithV>0)czAvgV/=(nNadirV+nZenithV); for(Int_t ich=0; ich<4; ich++){ if(fabs(czH[ich])<90)dczAvgH+=fabs(czH[ich]-czAvgH); if(fabs(czV[ich])<90)dczAvgV+=fabs(czV[ich]-czAvgV); } if(nNadirH+nZenithH>0)dczAvgH/=(nNadirH+nZenithH); if(nNadirV+nZenithV>0)dczAvgV/=(nNadirV+nZenithV); for(Int_t ich=0; ich<8; ich++){ if(!Rx[ich+8].LVtx || !Rx[ich].LVtx || czAvgV==0)continue; h3dtHVChVczV->Fill(dtHVCh[ich],ich,czAvgV); printf("dtHV[%d]=%g czAvgV=%g\n",ich,dtHVCh[ich],czAvgV); } } //upcoming->arriving from nadir inline Bool_t LNADIREV(Int_t nNadMin){return trigCode!=1 && ((czAvgV>0 && dczAvgV0 && dczAvgH=nNadMin;} // ((nNadirV-nZenithV)>=3||(nNadirV+nNadirH)-(nZenithV+nNadirH)>=5);} // ((nNadirV==CZRMSMAX&&nZenithV==0&&nZenithH==0)||((nNadirV+nNadirH>=6)&&(nZenithV+nZenithH)<=1)); inline Bool_t LZENITHEV(Int_t nZenMin){return trigCode!=1 && ((fabs(czAvgV)>fZENANGCUT && dczAvgVfZENANGCUT && dczAvgH=nZenMin&&nNadirH==0&&nNadirV==0;} inline void Drawevgr16(TGraph **gr0, const char *cin){ TGraph *grtmp16[16]; TCanvas *cDraw=new TCanvas("cDraw","cDraw"); cDraw->Divide(4,4,0.0001,0.0001); for(Int_t ich=0; ich<16; ich++){ grtmp16[ich]=new TGraph(gr0[ich]->GetN()); for(Int_t ipt=0; iptGetN(); ipt++)grtmp16[ich]->SetPoint(ipt,gr0[ich]->GetX()[ipt],gr0[ich]->GetY()[ipt]); cDraw->cd(ich+1); grtmp16[ich]->Draw("al");} cDraw->SaveAs(Form("$HOME/ctem/png/a%s.pdf",cin)); delete cDraw; for(Int_t ich=0; ich<16; ich++)delete grtmp16[ich]; return; } inline void Drawevgr(TGraph **gr0, const char *cin, Bool_t LZoom, Bool_t LDrawSimTx, Bool_t LtVH, Bool_t LDrawTix){ const Int_t iDrawTimeOffSetx=32; TLine *lHitTime[MCH]; TLine *ltNSig[MCH]; TLine *ltSlope[MCH]; TLine *ltNSig0[MCH]; TLine *ltp2NSig[MCH]; TLine *ltXCg[MCH]; TLine *ltVMax[MCH]; // if(NDrawPngs>=MDRAWPNGS)return; NDrawPngs++; cout<<" Drawing "<Divide(4,4,0.001,0.0015,kWhite); for(Int_t ich=0; ichClone(); // if(!gr0[ich])continue; gr[ich]=new TGraph(gr0[ich]->GetN()); for(Int_t ipt=0; iptGetN(); ipt++)gr[ich]->SetPoint(ipt,gr0[ich]->GetX()[ipt],gr0[ich]->GetY()[ipt]); if(LDebug)printf("Rx[%d].dtMC=%g Vmin=%g VMax=%g\n",ich,Rx[ich].dtijMC,TMath::MinElement(gr[ich]->GetN(),gr[ich]->GetY()),TMath::MaxElement(gr[ich]->GetN(),gr[ich]->GetY())); sprintf(cgrname,"ch%d_pol=%d",ich,Rx[ich].iPol); gr[ich]->GetHistogram()->SetTitleSize(0.1,"xyzh"); gStyle->SetTitleH(0.1); gr[ich]->GetYaxis()->SetTitleOffset(-0.16); gr[ich]->GetXaxis()->SetTitleOffset(-0.20); gr[ich]->GetXaxis()->SetLabelSize(0.07); gr[ich]->GetYaxis()->SetLabelSize(0.06); gr[ich]->GetXaxis()->SetNdivisions(8); gr[ich]->GetYaxis()->SetNdivisions(8); if(Rx[ich].Prms>256)printf("ERRZ: getgrInfo: Rx[%d].Prms=%g\n",ich,Rx[ich].Prms); if(LDrawTix)sprintf(cgrname,"=%3.0f/%3.0f t=%7.2f",Rx[ich].Vrms,Rx[ich].Prms,Rx[ich].HitTime); else{ if(iSta0>0){ if(ich<8)sprintf(cgrname,"VPol Ch%d zRx=%5.1f; time (ns); mV",ich,Rx[ich].z00); if(ich>=8)sprintf(cgrname,"HPol Ch%d zRx=%5.1f; time (ns); mV",ich,Rx[ich].z00); } else{ sprintf(cgrname,"Ch%d zRx=%3.0f; time (ns); mV",ich,Rx[ich].z00); if(ich==0||ich==1||ich==5|ich==7)sprintf(cgrname,"HPol Ch%d; time (ns); mV",ich); if(ich==2||ich==3||ich==4|ich==6)sprintf(cgrname,"VPol Ch%d; time (ns); mV",ich); } } // gr[ich]->SetName(cgrname); gr[ich]->SetTitle(cgrname); cgr4x4->cd(ich+1); gPad->SetGrid(); Int_t ibinmax=TMath::LocMax(gr[ich]->GetN(),gr[ich]->GetY()); Int_t ibinmin=TMath::LocMin(gr[ich]->GetN(),gr[ich]->GetY()); Float_t tibinmax=gr[ich]->GetX()[ibinmax]; if(gr[ich]->GetY()[ibinmin]>0)gPad->SetLogy(); if(LZoom){ gr[ich]->GetXaxis()->SetRangeUser(tibinmax-32,tibinmax+64); fdum=TMath::MinElement(96,&gr[ich]->GetY()[ibinmax]); gr[ich]->GetYaxis()->SetRangeUser(fdum,gr[ich]->GetY()[ibinmax]); } gr[ich]->SetLineColor(kBlack); if(Rx[ich].LVtx){ if(LDebug)printf("drawevgr: Rx[%d].HitTime=%g\n",ich,Rx[ich].HitTime); if(Rx[ich].iPol==0)gr[ich]->SetLineColor(kBlue); //VPol if(Rx[ich].iPol==1)gr[ich]->SetLineColor(kRed); //HPol if(Rx[ich].iPol==2)gr[ich]->SetLineColor(kGreen); //Surface } if(Rx[ich].LVTX){ if(Rx[ich].iPol==0)gr[ich]->SetLineColor(kCyan); //VPol if(Rx[ich].iPol==1)gr[ich]->SetLineColor(kMagenta); //HPol if(Rx[ich].iPol==2)gr[ich]->SetLineColor(kSpring); //Surface } gr[ich]->Draw("al"); Float_t ymax=TMath::MaxElement(gr[ich]->GetN(),gr[ich]->GetY()); Float_t ymin=TMath::MinElement(gr[ich]->GetN(),gr[ich]->GetY()); ltVMax[ich]=new TLine(Rx[ich].tVMax,ymin,Rx[ich].tVMax,ymax); ltVMax[ich]->SetLineStyle(10); ltVMax[ich]->SetLineColor(kOrange); if(Rx[ich].SNR>4 && LDrawTix)ltVMax[ich]->Draw("same"); if(Rx[ich].LVtx){ ltNSig0[ich]=new TLine(Rx[ich].tNSig0-iDrawTimeOffSetx,ymin,Rx[ich].tNSig0+iDrawTimeOffSetx,ymax); ltNSig0[ich]->SetLineColor(kGreen); // ltNSig0[ich]->SetLineStyle(4); if(LDrawTix)ltNSig0[ich]->Draw("same"); ltp2NSig[ich]=new TLine(Rx[ich].tp2NSig,ymin,Rx[ich].tp2NSig,ymax); ltp2NSig[ich]->SetLineStyle(7); ltp2NSig[ich]->SetLineColor(kYellow+2); if(LDrawTix)ltp2NSig[ich]->Draw("same"); ltNSig[ich]=new TLine(Rx[ich].tNSig,0,Rx[ich].tNSig,ymax*2); ltNSig[ich]->SetLineColor(kBlack); if(LDrawTix)ltNSig[ich]->Draw("same"); ltSlope[ich]=new TLine(Rx[ich].tSlope,ymin*2,Rx[ich].tSlope,0); ltSlope[ich]->SetLineColor(kViolet); if(LDrawTix)ltSlope[ich]->Draw("same"); ltXCg[ich]=new TLine(Rx[ich].tXCg+iDrawTimeOffSetx,ymin,Rx[ich].tXCg-iDrawTimeOffSetx,ymax); ltXCg[ich]->SetLineColor(13); ltXCg[ich]->SetLineStyle(1); if(LDrawTix)ltXCg[ich]->Draw("same"); } if(!LDrawSimTx)continue; lSim[ich]=new TLine(Rx[ich].dtijMC,ymin,Rx[ich].dtijMC,ymax); lSim[ich]->SetLineColor(kPink); lSim[ich]->SetLineWidth(4); if(LDrawTix)lSim[ich]->Draw("same"); } cgr4x4->SaveAs(cpngname); cout<<"cgr4x4 saved cpngname="<Divide(2,4); for(Int_t ich=0; ich<8; ich++){ cgr4x2->cd(ich+1); gPad->SetGrid(); gr[ich]->SetLineColor(kRed); gr[ich+8]->SetLineColor(kBlue); if(Rx[ich].tNSig>-256){ gr[ich]->GetXaxis()->SetRangeUser(Rx[ich].tNSig-64,Rx[ich].tNSig+32); gr[ich]->Draw("al"); gr[ich+8]->Draw("lsame"); } else{ gr[ich+8]->GetXaxis()->SetRangeUser(Rx[ich+8].tNSig-64,Rx[ich+8].tNSig+32); gr[ich+8]->Draw("al"); gr[ich]->Draw("lsame"); } } cgr4x2->SaveAs(cpngname1); delete cgr4x2; } Float_t fMsize; for(Int_t ich=0; ichFill(Rx[ich].x,Rx[ich].y,Rx[ich].z); h3dhit[ich]->SetMarkerColor(izcolor[ich]); if(!TMath::IsNaN(Rx[ich].SNR))fMsize=TMath::Min(1.+float(Rx[ich].SNR)/32.,4.); h3dhit[ich]->SetMarkerSize(fMsize); h3dhit[ich]->Draw("psame"); if(ltXCg[ich])delete ltXCg[ich]; if(ltNSig[ich])delete ltNSig[ich]; if(ltSlope[ich])delete ltSlope[ich]; if(ltNSig0[ich])delete ltNSig0[ich]; if(ltp2NSig[ich])delete ltp2NSig[ich]; } } } delete cgr4x4; // TCanvas *c3dhits=new TCanvas("c3dhits","c3dhits"); h3devt->Draw("lego"); c3dhits->SaveAs(cpngname2); delete c3dhits; } Bool_t LICLutc(){ // const Float_t PHMinICL=1e6; const Float_t PVMinICL=1e6; // Bool_t LICLevPow=(HPolPower>PHMinICL || VPolPower>PVMinICL); Bool_t LICLutc2017H=unixTime>1484604807&&unixTime<1484604807+1800; //no signal!!! Bool_t LICLutc2017V=unixTime>1484604807+1800&&unixTime<1484604807+3600; //no signal!!! Bool_t LICLutcUs=unixTimeUs>3 && unixTimeUs<36; //(unixTimeUs<2000||unixTimeUs>998000); true of both A2&A3 in 2014 - evidently A3 CP trigger is free-running! Bool_t LICLutc2013V=unixTime>1359.17466e6 && unixTime<1359.17526e6; //utcsubsecond>0.0008&&utcsubsecond<0.002; Bool_t LICLutc2013H=unixTime>1359.17851e6 && unixTime<1359.18032e6; //utcsubsecond>0.0002&&utcsubsecond<0.0008; Bool_t LICLutc2013=LICLutc2013V || LICLutc2013H; Bool_t LICLutc2014=(unixTime>1393.654e6 && unixTime<1393.659e6) || (unixTime>1394.847e6&&unixTime<1384.853e6); //seen in ara01 ONLY!!! Bool_t LICLutcUsA3_2013=unixTimeUs>720e3 && unixTimeUs<820e3; //make this a function of utc since drift is linear! Bool_t LICLutcUsA3_2014=unixTimeUs>730e3 && unixTimeUs<850e3; //make this a function of utc since drift is linear! Bool_t LICLutc2015V_MD=(unixTime>1420508100 && unixTime<1420508760) || (unixTime>1420513020 && unixTime<1420513620) || (unixTime>1420516080 && unixTime<1420516680) || (unixTime>1420598040 && unixTime<1420598940) || (unixTime>1420857720 && unixTime<1420858320) || (unixTime>1421101440 && unixTime<1421102040); //NOT SEEN AT ALL Bool_t LICLutc2015H_MD=(unixTime>1421102100 && unixTime<1421102700) || (unixTime>1420858380 && unixTime<1420858980) || (unixTime>1420599120 && unixTime<1420600020) || (unixTime>1420513020 && unixTime<1420514880) || (unixTime>1420508160 && unixTime<1420508760); //according to duvernois Bool_t LICLutc2015Va=unixTime>1420.49394e6&&unixTime<1420.49396e6; //PV>40e6 1420494289 Bool_t LICLutc2015Ha=unixTime>1420.49406e6&&unixTime<1420.4941e6; //PH>40e6 Bool_t LICLutc2015Vb=unixTime>1421.0653e6&&unixTime<1421.0659e6; Bool_t LICLutc2015Hb=unixTime>1421.0669e6&&unixTime<1421.0674e6; Bool_t LICLutc2015=LICLutc2015Va||LICLutc2015Ha||LICLutc2015Vb||LICLutc2015Hb; Bool_t LICLutc2018V=unixTime>1516.477e6&&unixTime<1516.4786e6; //utcsubsecond>0.12926&&utcsubsecond<0.12938 if(LICLutc2013H||LICLutc2015H_MD||LICLutc2015Ha||LICLutc2015Hb||LICLutc2017H)iICLPol=1; if(LICLutc2013V||LICLutc2015V_MD||LICLutc2015Va||LICLutc2015Vb||LICLutc2017V||LICLutc2018V)iICLPol=0; // cout<<"ievtype="<WfPH||nhitsgr00V>nhitsgr00H)iPolVtx=0; if(WfPH>WfPV&&nhitsgr00H>nhitsgr00V)iPolVtx=1; ievana0=-1; if(HPolPower==0||VPolPower==0)cout<<"ERRZ: LAnaEv0 passed HPolPower=0!!!"<GetMaximumBin(); if(dttrigGetBinCenter(idum+3))LEvType[31]=true; //running hot! //http://ara.physics.wisc.edu/docs/0012/001273/001/SurfacePulserStudy.pdf iEvCode=0; if(iStation==1){ if(WfPV+WfPH>2){ for(Int_t iSP=0; iSP=iutcARA1SP[iSP] && unixTime<=iutcARA1SP[iSP]+45)){ cout<<"iutcARA1SPCutOK"<30)continue; if(iSP<=9)rSurfPuls2015[iSP]=250; else if(iSP<=19)rSurfPuls2015[iSP]=175; else rSurfPuls2015[iSP]=100; } } } } if(iStation==2||iStation==3){ if(WfPV+WfPH>WFPTOTMINSURFPULSER){ for(Int_t iSP=1; iSP=iutc0SP[iSP]-30 && unixTime<=iutc0SP[iSP]+630){ LSP[iSP]=true; LEvType[5]=true; iSurfPulsPos=iSP+200; ievana0=5; iEvCode+=iSP; cout<<"iSurfPulsPos="<Fill(dtHVCh[ich],ich); // xntvar[27]=czV[0]; xntvar[28]=czV[1]; xntvar[29]=czV[2]; xntvar[30]=czV[3]; xntvar[31]=czH[0]; xntvar[32]=czH[1]; xntvar[33]=czH[2]; xntvar[34]=czH[3]; xntvar[27]=Rx[0].VMax/Rx[0].Vrms00; xntvar[28]=Rx[1].VMax/Rx[1].Vrms00; xntvar[29]=Rx[2].VMax/Rx[2].Vrms00; xntvar[30]=Rx[3].VMax/Rx[3].Vrms00; xntvar[31]=Rx[4].VMax/Rx[4].Vrms00; xntvar[32]=Rx[5].VMax/Rx[5].Vrms00; xntvar[33]=Rx[6].VMax/Rx[6].Vrms00; xntvar[34]=Rx[7].VMax/Rx[7].Vrms00; Float_t SNRSum0=0; Float_t SNRSumS1=0; Float_t SNRSumS2=0; Float_t SNRSumS3=0; Float_t SNRSumS4=0; for(Int_t ich=0; ich<8; ich++){ Rx[ich].LVtx?1:xntvar[27+ich]*=-1; SNRSum0+=Rx[ich].VMax/Rx[ich].Vrms00; if(ich%4==0)SNRSumS1+=Rx[ich].VMax/Rx[ich].Vrms00; if(ich%4==1)SNRSumS2+=Rx[ich].VMax/Rx[ich].Vrms00; if(ich%4==2)SNRSumS3+=Rx[ich].VMax/Rx[ich].Vrms00; if(ich%4==3)SNRSumS4+=Rx[ich].VMax/Rx[ich].Vrms00; } xntvar[35]=rms4z0(&tHitTime[8],&iuseChgr00[8]); xntvar[36]=rms4z0(&tHitTime[12],&iuseChgr00[12]); xntvar[37]=Rx[0].tVMax; xntvar[38]=Rx[0].tNSig00; xntvar[39]=SNRgr00Min; xntvar[40]=rms4z0(tHitTime,iuseChgr00); xntvar[41]=rms4z0(&tHitTime[4],&iuseChgr00[4]); xntvar[42]=czAvgEv; xntvar[43]=czRMSEv; xntvar[44]=SNRSumS1/SNRSum0; xntvar[45]=SNRSumS2/SNRSum0; xntvar[46]=SNRSumS3/SNRSum0; xntvar[47]=SNRSumS4/SNRSum0; xntvar[48]=iStation; xntvar[49]=iYear0; xntvar[50]=czAvgHV; xntvar[51]=dczAvgHV; xntvar[52]=nczAvgHV; xntvar[53]=dtHV; xntvar[54]=ddt0HV; xntvar[55]=LOKWvfms; xntvar[56]=nSATSumV; xntvar[57]=nSATSumH; xntvar[58]=LTxRaiseTLowerF; for(Int_t ipgr=0; ipgr=10 && NEvTot%ievtype==0){ TUTCEVT0->Fill(); //unixTime,unixTimeUs); LEvType[9]=LNADIREV(3) || LZENITHEV(4); LEvType[13]=vWind>MINVWINDHIVWIND; LEvType[14]=vWindFill(xntvar); TFFTEV0->Fill(); PrintCPUUsage(); if(LPrintDbg)NEVT0->Show(NEvTot); } if(LCP){ for(Int_t ich=0; ichVMAXMAX)continue; // cout<<"grCPAvg2["<Clone(); else{grCPAvg2[ich]=grCorrAndAvgB2A(gr[ich],grCPAvg2[ich],true); dtOffsetgrAXgrB[ich]=dtOffsetgrAXgrBCh;} //true->false 11oct23 } for(Int_t ich=0; ichFill(dtOffsetgrAXgrB[ich]-dtOffsetgrAXgrB[ichSNRMax],ich); if(LCP){ for(Int_t ich=0; ichVMAXMAX)continue; // cout<<"grCPAvg2_0["<Clone(); else{grCPAvg2_0[ich]=grCorrAndAvgB2A_0(ich,gr[ich],grCPAvg2_0[ich],true);} //true->false 11oct23 } } } if(LDeepPulserOnUTC(iStation)&&!LCP&&(nhitsgr00V+nhitsgr00H)>=nHitsgr00DP){ for(Int_t idp=0; idp15)continue; if(!grDPAvg2[idp][ich]){ printf("Booking grDPAvg2[idp=%d][ich=%d]\n",idp,ich); grDPAvg2[idp][ich]=(TGraph*)gr[ich]->Clone(); } else grDPAvg2[idp][ich]=grCorrAndAvgB2A(gr[ich],grDPAvg2[idp][ich],false); } nDPAvg2[idp]++; } } if(ievtype<0)return true; else return LEvType[ievtype]; } //correlateandaverage CP graphs and check coherence after 1, 2, 4, 8, 16, 32, 64 sums void AvggrCoherence(Int_t ievwfms, Int_t MWVFMS){ if(ievwfms==2&&NEvUB<4)return; const Float_t dfbndMHz=150; const Int_t MFBNDMHZ=4; Float_t rms2p1, rmsm12p2, rmsp2p; rms2p1=rmsm12p2=rmsp2p=0; TGraph *grVt, *grVtHE, *grtmp[16]; printf("AvggrCoherence ievwfms=%d MWVFMS=%d\n",ievwfms,MWVFMS); ievCohC=ievwfms; for(Int_t i2=2; i2Clone(); else if(ievwfms==10)grtmp[ich]=FFTtools::correlateAndAverage(i2,grEvAvgN[0][ich]); else if(ievwfms==11)grtmp[ich]=FFTtools::correlateAndAverage(i2,grEvAvgN[1][ich]); else if(ievwfms==100)grtmp[ich]=FFTtools::correlateAndAverage(i2,grDPAvgN[0][ich]); else if(ievwfms==101)grtmp[ich]=FFTtools::correlateAndAverage(i2,grDPAvgN[1][ich]); else if(ievwfms==102)grtmp[ich]=FFTtools::correlateAndAverage(i2,grDPAvgN[2][ich]); else{cout<<"ievwfms="<GetN()<256)continue; grVt=FFTtools::simplePassBandFilter(grtmp[ich],fbndMHz,fbndMHz+dfbndMHz); grVtHE=FFTtools::getHilbertEnvelope(grVt); Rx[ich].Prms=grVtHE->GetRMS(2)/4; //DANGER WILL ROBINSON!!!!!!!!! Factor of 4 empirical! 10FEB23 - maybe use minimum rms from first vs. last samples gettNSig2pm(grVtHE,ich,0,24); //changed from 32 21Jan23!!! dtp1p2C[ich]=rms2p1C[ich]=rmsm12p2C[ich]=rmsp2pC[ich]=rmsp12m1C[ich]=-NNN; //should we just use the numbers in memory? if(ibntp1NSig[ich]>0&&ibntp1NSig[ich]GetN()-32){A1NSigC[ich]=ANSig1[ich]; rms2p1C[ich]=TMath::RMS(ibntp1NSig[ich],grVt->GetY()); PNSig16C[ich]=FFTtools::sumVoltageSquared(grVt,ibntp1NSig[ich],ibntp1NSig[ich]+16); PNSig16_32C[ich]=FFTtools::sumVoltageSquared(grVt,ibntp1NSig[ich]+16,ibntp1NSig[ich]+32);} if(ibntm1NSig[ich]>0)rmsp12m1C[ich]=TMath::RMS(ibntm1NSig[ich]-ibntp1NSig[ich],&grVt->GetY()[ibntp1NSig[ich]]); if(ibntp2NSig[ich]>0){A2NSigC[ich]=ANSig2[ich]; dtp1p2C[ich]=tp2NSig[ich]-tp1NSig[ich]; rmsm12p2C[ich]=TMath::RMS(ibntp2NSig[ich]-ibntm1NSig[ich],&grVt->GetY()[ibntm1NSig[ich]]);} if(ibntm2NSig[ich]>0)rmsp2pC[ich]=TMath::RMS(grVt->GetN()-ibntm2NSig[ich]-1,&grVt->GetY()[ibntm2NSig[ich]]); rmsp32C[ich]=TMath::RMS(32,grVt->GetY()); rmsm32C[ich]=TMath::RMS(32,&grVt->GetY()[grVt->GetN()-33]); delete grVt; //, grVtHE; } TCOHINC->Fill(); } for(Int_t ich=0; ichClone(); for(Int_t ipt=0; iptGetN(); ipt++) grtemp->SetPoint(ipt,gr->GetX()[ipt],gr->GetY()[ipt]*Scale); return grtemp; } void AverageEvGraphs(TGraph **gr, TFile *rfile){ if(iPolVtx<0||iPolVtx>=2)return; if(LCP)return; if(nEvAvg[iPolVtx]==MWFAVGN-1&&zTx0z==zTx0z_lastAvg)return; printf("AverageEvGraphs storing nEvAvg[%d]=%d in memory zTx0z=%g zTx0z_lastAvg=%g\n",iPolVtx,nEvAvg[iPolVtx],zTx0z,zTx0z_lastAvg); for(Int_t ich=0; ichClone(); grEvAvgN[iPolVtx][ich][nEvAvg[iPolVtx]]->SetNameTitle(Form("grEvAvgN_pol%d_%d",iPolVtx,ich),Form("grEvAvgN_pol%d_%d",iPolVtx,ich)); if(LInitAvgEv2[iPolVtx]){ printf("Booking grEvAvg2[ich=%d]\n",ich); grEvAvg2[iPolVtx][ich]=(TGraph*)gr[ich]->Clone(); grEvAvg2[iPolVtx][ich]->SetNameTitle(Form("grEvAvg2_pol%d_%d",iPolVtx,ich),Form("grEvAvg2_pol%d_%d",iPolVtx,ich)); } else{ if(LDebug)printf("grEvAvgN correlate!\n"); // TGraph *grtmp=(TGraph*)grEvAvg2[iPolVtx][ich]->Clone(); // grEvAvg2[iPolVtx][ich]=grCorrAndAvgB2A(gr[ich],grtmp,false); // delete grtmp; //23Apr21 uncommented??? grEvAvg2[iPolVtx][ich]=grCorrAndAvgB2A(gr[ich],grEvAvg2[iPolVtx][ich],false); } } ichSNRMaxEv[iPolVtx][nEvAvg[iPolVtx]]=ichSNRMax; LInitAvgEv2[iPolVtx]=false; if(nEVN00[iPolVtx]+1==MEVN00)return; // if(zTx0z_lastAvg==zTx0z)return; if(nEvAvg[iPolVtx]>=MWFAVGN)printf("ERRZ: nEVAVg[%d]=%d > MWFAVGN=%d\n",iPolVtx,nEvAvg[iPolVtx],MWFAVGN); if(nEvAvg[iPolVtx]+1==MWFAVGN&&zTx0z!=zTx0z_lastAvg){ cout<<"AverageEvGraphs Correlate and averaging "<SetLineColor(izcolor[ich]); grEVN00[iPolVtx][ich][nEVN00[iPolVtx]]->SetNameTitle(Form("grEVN00_%d_%d_%d",iPolVtx,ich,nEVN00[iPolVtx]),cgrname); if(LWritegrEVN00)rfile->Append(grEVN00[iPolVtx][ich][nEVN00[iPolVtx]]); grEvAvgtmp[ich]=(TGraph*)grEVN00[iPolVtx][ich][nEVN00[iPolVtx]]->Clone(); } Drawevgr(grEvAvgtmp,Form("grEVN_iPolVtx%d_nEvAvg%d_iEvAvg%d_zTx0z%d",iPolVtx,nEvAvg[iPolVtx],nEVN00[iPolVtx],int(abs(zTx0z))),false,false,false,false); //Potential Memory Leak 27May23 for(Int_t ich=0; ich<16; ich++)delete grEvAvgtmp[ich]; nEVN00[iPolVtx]++; nEvAvg[iPolVtx]=0; AvggrCoherence(10+iPolVtx,MWFAVGN); for(Int_t iEvAvg=0; iEvAvg=0&&ievana0Fill(Rx[ich].SNR,ich); // const Float_t NTOTSumMin[6]={300,0,200,200,0,80}; if(LCP && LAvgWf && NEvCPAvg+1<=MWFAVGCP){ // && fMinWfLen>MWFLENMIN){ for(Int_t ich=0; ich<16; ich++)grCPAvgN[ich][NEvCPAvg]=(TGraph*)gr[ich]->Clone(); NEvCPAvg++; } if(iSurfPulsPos>0 && LEvType[5] && LAvgWf){ Int_t iSP=iSurfPulsPos-200; if(iSP<0 || iSP>=MSurfPulsPos)printf("ERRZ: iSP=%d OOB\n",iSP); if(nSPEv[iSP]+1Clone(); nSPEv[iSP]++; } NSPEv++; } // if(TOTSum>NTOTSumMin[iStation]&& if(LDeepPulserOnUTC(iStation) && LAvgWf){ for(Int_t idp=0; idp=MMWFAVG)continue; if(fMinWfLen15)continue; cout<<"Booking grDPAvgM["<SetLineColor(izcolor[ich]); // printf("grDPAvgN[%d][%d][%d]\n",idp,ich,nDPEv[idp]); } nDPEv[idp]++; NDPEv++; /* for(Int_t ich=0; ich<16; ich++){ if(!grDPAvg2[idp][ich]){ printf("Booking grDPAvg2[idp=%d][ich=%d]\n",idp,ich); grDPAvg2[idp][ich]=(TGraph*)gr[ich]->Clone(); } else grDPAvg2[idp][ich]=grCorrAndAvgB2A(gr[ich],grDPAvg2[idp][ich],false); } */ } } L=true; if(ievtype==3&&!LDeepPulserOnUTC(iStation))L=false; if(ievtype==9){ L=TOTMax=3 && (nZenithV+nZenithH)<=1) || LZENITHEV()); h2nNadnZen->Fill(nNadirH+nNadirV,nZenithH+nZenithV); if(LDebug)printf("trigCode=%d TOTMax=%g TOTMaxGD=%g nNadirV=%d nZenithV=%d nNadirH=%d nZenithH=%d L=%d =%g =%g =%g =%g L=%d\n",trigCode,TOTMax,TOTMAXGD,nNadirV,nZenithV,nNadirH,nZenithH,L,czAvgV,dczAvgV,czAvgH,dczAvgH,LNADIREV(3)); // case 10: L=TOTMaxiutcARA1SP[iindex]&&unixTime0Append(h2SimVtxTimesVCh); TFileOut->Append(h2dtOffsetVCh); TFileOut->Append(h2dfAvgCWX); TFileOut->Append(h2dfrq400MHz); TFileOut->Append(h2f400MHzVCh); TFileOut->Append(h2frqRejectVCh); TFileOut->Append(h2nfrqRejectVCh); TFileOut->Append(h2Pin2PoutVCh); TFileOut->Append(h2TrigTimeOOS); TFileOut->Append(h1dutcUsStack); TFileOut->Append(h2szijVCh); TFileOut->Append(h2szijVNEv); TFileOut->Append(h2szChiVChj); TFileOut->Append(h1drsq4RxxyzV); TFileOut->Append(h1drsq4RxxyzH); TFileOut->Append(h1triggerInfo); TFileOut->Append(h2HitTimeCh); TFileOut->Append(h2grDCX); TFileOut->Append(h2ChOff); TFileOut->Append(h2CableDelayNsAR); TFileOut->Append(h2CableDelayNsZ); TFileOut->Append(h2NFitVtx_if); TFileOut->Append(h3RxCoords); TFileOut->Append(h3dtHVChVczV); TFileOut->Append(h2TmplnHitMatchNoMatch); TFileOut->Append(h1TmplUs); TFileOut->Append(h2dtrmsVdA); TFileOut->Append(h2dtrmsVdAMin); TFileOut->Append(h3tXCChiChj); TFileOut->Append(h3tNSigChiChj); TFileOut->Append(h3tSlopeChiChj); TFileOut->Append(h2TmplnoVevno); TFileOut->Append(h2dtResidParPairs); TFileOut->Append(h2RxUseMap); TFileOut->Append(h2fLoPassfHiPass); TFileOut->Append(h2MCdaz); TFileOut->Append(h2dtHV0); TFileOut->Append(h2dtHV0tNSig0); TFileOut->Append(hdttrigEV); TFileOut->Append(h2dttrig00); TFileOut->Append(hdutcCuts); TFileOut->Append(h2dtTwinPeaksVCh); TFileOut->Append(h2SNRVCh00); TFileOut->Append(h2SNRVCh00CP); for(Int_t ih2=0; ih2Append(h2SNRVCh[ih2]); for(Int_t izTx=0; izTxGetEntries()>0)TFileOut->Append(h3Spectrogram[izTx]); TFileOut->Append(hEvCuts); TFileOut->Append(h2Vavg32Ch); TFileOut->Append(h2dtijVCh); TFileOut->Append(h2residij); TFileOut->Append(hRxdtns); TFileOut->Append(hRxdtnsSim); TFileOut->Append(h2OOTHCh); TFileOut->Append(h2residZ4VCh); TFileOut->Append(h2dphiZ41VCh); TFileOut->Append(h2dtheZ41VCh); // TFileOut->Append(h2dphiZ42VCh); TFileOut->Append(h2dtheZ42VCh); TFileOut->Append(h2dphicogVCh); TFileOut->Append(h2dthecogVCh); TFileOut->Append(h2dtresidMinuitVCh); TFileOut->Append(h2residMinuitVChSim); TFileOut->Append(h2dtNSigVM2Ch); TFileOut->Append(h2dtNSigVMxCh); TFileOut->Append(h2dtVM4VM2Ch); TFileOut->Append(h2PrmsVCh); TFileOut->Append(h2dtNSigtSlopeCh); TFileOut->Append(h2dtNSigtHESlopeCh); TFileOut->Append(h2timebaseVCh); TFileOut->Append(h2NSampleVCh); TFileOut->Append(h2BufferLenVCh); TFileOut->Append(h2Vrms00VCh); TFileOut->Append(h2VrmsUBVCh); TFileOut->Append(h2VrmsVfGalacDay); TFileOut->Append(h2VVCh); TFileOut->Append(h2VMax00VCh); TFileOut->Append(h2fftVtWB); TFileOut->Append(h2fftWBVCh); TFileOut->Append(h2fftXWBVCh); TFileOut->Append(h2tVMax00VCh); TFileOut->Append(h2tNSig00VCh); for(Int_t ich=0; ich=16){TFileOut->Append(h3PfftVfGalacDay[ich-16]); TFileOut->Append(h1frqIVCh[ich-16]);} TFileOut->Append(h2fftVhr[ich]); TFileOut->Append(h2Zspx[ich]); // if(LTxSpiceCore)TFileOut->Append(h2fftVzTx[ich][0]); // if(LTxSpiceCore)TFileOut->Append(h2fftVzTx[ich][1]); TFileOut->Append(h1PkXCThermalSNR[0][ich]); TFileOut->Append(h1PThermal[ich]); TFileOut->Append(h1PNoHit[ich]); TFileOut->Append(h1PBkSub[ich]); TFileOut->Append(h1Prms[ich]); TFileOut->Append(h1VrmsMBN[ich]); TFileOut->Append(h1PrmsMBN[ich]); TFileOut->Append(h1PrmsUB[ich]); TFileOut->Append(h1VrmsUB[ich]); } TFileOut->Append(histMapIFGV); TFileOut->Append(histMapIFGH); TFileOut->Append(h2nNadnZen); TFileOut->Append(h2fftfrqMaxVCh); TFileOut->Append(h2frqMaxXThreshVCh); TFileOut->Append(hZphithe); hZphithe->SetStats(0); TFileOut->Append(hZphithe0); TFileOut->Append(h2VdistVCh); TFileOut->Append(h2fftVCh); TFileOut->Append(h2fftVChPreF); TFileOut->Append(h2fftVChLovW); TFileOut->Append(h2fftVChMevW); TFileOut->Append(h2fftVChHivW); TFileOut->Append(h2fftVChEV); TFileOut->Append(h2ZphiVRxCode); TFileOut->Append(h2dttrig); TFileOut->Append(h2delbinsVCh); TFileOut->Append(hdttrig); TFileOut->Append(hCPU); TFileOut->Append(NCOHINCUB); TFileOut->Append(NCPC); TFileOut->Append(NPFRQBINBNDS); if(LAllFits)TFileOut->Append(NDTIJ2PHITHEV); // TFileOut->Append(NPFREQBIN); TFileOut->Append(NEVT0); TFileOut->Append(NMEM); TFileOut->Append(NTRIGBITS); TFileOut->Append(NDTGRIGRJ); // TFileOut->Append(NEVT1); TFileOut->Append(NUTC); if(false)TFileOut->Append(NEVSEL); TFileOut->Append(NPVRMS); TFileOut->Append(N000); TFileOut->Append(NTXCOORDSAR); TFileOut->Append(NRXCOORDS); TFileOut->Append(NFIT4ZSOLNS); TFileOut->Append(NDELTVH); TFileOut->Append(NRXHITTV); TFileOut->Append(NPARPAIRSV); TFileOut->Append(NPARPAIRSH); TFileOut->Append(NFRQBLIP); TFileOut->Append(NXTALK); // TFileOut->Append(NUBTRGSM); TFileOut->Append(TCOHINC); TFileOut->Append(TX2A); TFileOut->Append(TTVHIT); TFileOut->Append(TRCO); TFileOut->Append(TTVHITCP); TFileOut->Append(TTVHITDP); TFileOut->Append(TFFTEV1); TFileOut->Append(TUTC0); TFileOut->Append(TUTCEVT0); TFileOut->Append(TUTCEVT1); TFileOut->Append(TTRIGBITS); } void FillN000(){ xntvar[0]=DPTx[1].phiLoc; xntvar[1]=DPTx[1].theLoc; xntvar[2]=ICLTx.phiLoc; xntvar[3]=SPS.phiLoc; xntvar[4]=iStation0; xntvar[5]=MSIGMASPE; N000->Fill(xntvar); } void PrintEvtCuts(){ printf("PrintEvtCuts: run=%d ievno=%d NEvTot=%d NEVT0=%lld NVTXEV=%lld NEvCPAvg=%d NEvUB=%d NEvCP=%d NThermEv=%d NSPEv=%d NDPEv=%d nTmpl=%d \n",irunno,ieventNumber,NEvTot,NEVT0->GetEntries(),NVTXEV->GetEntries(),NEvCPAvg,NEvUB,NEvCP,NThermEv,NSPEv,NDPEv,nTmpl); if(NEvCP>0)printf("fLiveCP=%g\n",float(NEvCP)/(unixTime-utc000)); if(NEvUB>0)printf("fLiveUB=%g\n",float(NEvUB)/(unixTime-utc000)); for(Int_t icut=0; icut0) printf("PrintEvtCuts: NEvTot0[%d]=%d / CPUUse=%g seconds\n",icut,NEvTot0[icut],CPUUse[icut]); if(nTotTmpl>0)cout<<"Total of "<0)printf("nAnaEv[%d][0]=%d / nAnaEv[%d][1]=%d\n",jtrigCodeZ,nAnaEv[jtrigCodeZ][0],jtrigCodeZ,nAnaEv[jtrigCodeZ][1]); for(Int_t icut=0; icut0)printf("PrintEvtCuts: NEvCuts[icut=%d][trigCode=%d]=%d\n",icut,jtrigCodeZ,NEvCuts[icut][jtrigCodeZ]); } if(TProcessID::GetObjectCount()>0)cout<<" Total of "<0)printf("nHitsRx[%d]=%d/nHitsRx00=%d/nHitsRxMC=%d nXOff[%d]=%d h1PTherm med=%g =%g+/-%g/#=%g Prms=%g Vrms=%g h1Prms=%g+/-%g/#=%g\n",ich,nHitsRx[ich],nHitsRx00[ich],nHitsRxMC[ich],ich,nSwitchOff[ich],GetxMedian(h1PThermal[ich]),ich,GetxMax(h1PThermal[ich]),h1PThermal[ich]->GetRMS(),h1PThermal[ich]->GetEntries(),Rx[ich].Prms,Rx[ich].Vrms,h1Prms[ich]->GetMean(),h1Prms[ich]->GetRMS(),h1Prms[ich]->GetEntries()); } //void IncrementNPtr(){NPtr[iNPtr]++; iNPtr++;} inline TGraph *grPkpmNns(TGraph *gr, Int_t Nnspk, Float_t scale){ Int_t Nbnpk=float(Nnspk)/(gr->GetX()[1]-gr->GetX()[0]); TGraph *grtmp=new TGraph(Nbnpk); Int_t ibmax=TMath::LocMax(gr->GetN(),gr->GetY()); Int_t ibmin=TMath::LocMin(gr->GetN(),gr->GetY()); Float_t ymax=gr->GetY()[ibmax]; Float_t ymin=gr->GetY()[ibmin]; Int_t ipkbn=ibmax; if(fabs(ymin)>ymax)ipkbn=ibmin; for(Int_t ib=ipkbn-Nbnpk; ib=gr->GetN())continue; grtmp->SetPoint(ib,gr->GetX()[ib],gr->GetY()[ib]*scale); } return grtmp; } inline Float_t grMaxZ(TGraph *gr, Int_t *ibnmax){ Float_t ymax=TMath::MaxElement(gr->GetN(),gr->GetY()); Float_t ymin=TMath::MinElement(gr->GetN(),gr->GetY()); if(fabs(ymin)>ymax){ if(ibnmax)*ibnmax=TMath::LocMin(gr->GetN(),gr->GetY()); return ymin; } else{ if(ibnmax)*ibnmax=TMath::LocMax(gr->GetN(),gr->GetY()); return ymax; } } inline float fMAX(float float1, float float2){ if(float1>float2) return float1; else return float2;} inline float fMIN(float float1, float float2){ if(float1i2) return i1; else return i2;} inline int iMIN(int i1, int i2){ if(i1Fill(iCutsLevel,CPUt0-CPUt1); CPUt1=CPUt0; // if(!LCut)iFailCode0=iCutsLevel; // NEvTot0[iCutsLevel]++; // else{ if(!LCut){iFailCode0=iCutsLevel; NEvTot0[iCutsLevel]++;} else{ hEvCuts->Fill(iCutsLevel,trigCode); if(iCutsLevel>=0 && abs(ievtype)Fill(iCutsLevel,utcEvCuts[iCutsLevel][0]-utcEvCuts[iCutsLevel][1]); iCutsLevel++; } inline void getIFGStats(TH2 *hIFGMap, Float_t &phiMax, Float_t &theMax, Float_t &E1, Float_t &E9, Float_t &E25, Float_t &phiMax1, Float_t &theMax1){ Int_t ilocxMax, ilocyMax, iloczMax; phiMax=-NNN; theMax=-NNN; E1=-NNN; E9=-NNN; E25=-NNN; if(!hIFGMap)return; hIFGMap->GetMaximumBin(ilocxMax,ilocyMax,iloczMax); phiMax=hIFGMap->GetXaxis()->GetBinCenter(ilocxMax); theMax=hIFGMap->GetYaxis()->GetBinCenter(ilocyMax); E1=hIFGMap->GetBinContent(ilocxMax,ilocyMax); E9=0; E25=0; TH2F *htmp=(TH2F*)hIFGMap->Clone(); for(Int_t ibx=ilocxMax-8; ibx<=ilocxMax+8; ibx++){ // if(ilocxMax+ibx<0)continue; for(Int_t iby=ilocyMax-8; iby<=ilocyMax+8; iby++){ htmp->SetBinContent(ibx,iby,0); E25+=hIFGMap->GetBinContent(ibx,iby); if(abs(ibx-ilocxMax)>=2 || abs(iby-ilocyMax)>=2)continue; E9+=hIFGMap->GetBinContent(ibx,iby); } } htmp->GetMaximumBin(ilocxMax,ilocyMax,iloczMax); phiMax1=htmp->GetXaxis()->GetBinCenter(ilocxMax); theMax1=htmp->GetYaxis()->GetBinCenter(ilocyMax); delete htmp; } inline Float_t getNSigtime(TGraph *gr, Int_t MSAMPLE, Float_t &rmsbar, Int_t &nsamplerms){ Float_t rmssum=0; Int_t nrms; vectorrms; Int_t ib; for(ib=0; ibGetN(); ib+=MSAMPLE){ rms.push_back(TMath::RMS(MSAMPLE,&gr->GetY()[ib])); rmssum+=rms.back(); if(ib<=MSAMPLE)continue; nrms=rms.size(); rmsbar=(rmssum-rms.back())/(nrms-1); // rmsbar=accumulate(rms.begin(), rms.end(), 0.0)/nrms; if(LDebug)printf("rms[%d]=%g rmsbar=%g ",ib,rms.back(),rmsbar); if((rms.back()-rmsbar)/rmsbar>4)break; } nsamplerms=ib-MSAMPLE; printf("getNSigtime rms=%g time=%g / nsamplerms=%d",rmsbar,gr->GetX()[nsamplerms],nsamplerms); return gr->GetX()[nsamplerms]; } inline Int_t itimeVMax4(TGraph *gr, Float_t &tVM4, Float_t &tVM4f, Int_t &ibin, Int_t &ibinf){ tVM4=-1; tVM4f=-1; ibin=-1; ibinf=-1; Int_t jbin, jbinf; Float_t VMax4=TMath::MaxElement(gr->GetN(),gr->GetY())/4.; for(jbin=0; jbinGetN(); jbin++){ if(gr->GetY()[jbin]GetX()[jbin]; ibin=jbin; break; } for(jbinf=gr->GetN(); jbinf>jbin; jbinf--){ if(gr->GetY()[jbinf]GetX()[jbinf]; ibinf=jbinf; break; } if(tVM4f!=-1 && tVM4!=-1)return 1; else return 0; } inline Int_t itimeNSiga(TGraph *gr, Int_t MBNRMS, Float_t MSIGMACUT, Float_t &tNSig, Float_t &tNSigf, Int_t &ibin, Int_t &ibinf){ tNSig=-NNN; tNSigf=-NNN; ibin=-NNN; ibinf=-NNN; Int_t jbin, jbinf; Float_t Vrms=TMath::RMS(MBNRMS,gr->GetY()); for(jbin=MBNRMS; jbinGetN(); jbin++){ if(fabs(gr->GetY()[jbin])GetX()[jbin]; Vrms=TMath::RMS(jbin-4,gr->GetY()); ibin=jbin; break; } for(jbinf=gr->GetN()-MBNRMS; jbinf>jbin; jbinf--){ if(fabs(gr->GetY()[jbinf])GetX()[jbinf]; ibinf=jbinf; break; } if(LDebug)printf("timeNSig: tNSig=%g tNSigf=%g ibNSig=%d ibNSigf=%d\n",tNSig,tNSigf,ibin,ibinf); timeNSig[0]=tNSig; timeNSig[1]=tNSigf; if(tNSigf!=-1 && tNSig!=-1)return 1; else return 0; } //inline Double_t tNSigf(TGraph *gr, Float_t MSIGMACUT){ // Int_t ipt=gr->GetN(); // Float_t Vrms=TMath::RMS(MBiNRMS,gr->GetY()); //} //inline void DrawEvHits(TGraph **gr, Float_t Ztimes[MCH], Float_t ZAmpl[MCH]){ // Int_t index[MCH]; // TMath::Sort(MCH,Ztimes,index); //} inline Float_t LinSlope(Double_t *x, Double_t *y, Int_t NbinSlope, Float_t &chisqLinSlope){ //const vector& x, const vector& y){ chisqLinSlope=0; Float_t avgX=TMath::Mean(NbinSlope,x); Float_t avgY=TMath::Mean(NbinSlope,y); Float_t numerator=0.0; Float_t denominator=0.0; for(Int_t i=0; iGetN()-MBINSLOPE-1; ibHE++){ Slope=LinSlope(&grHE->GetX()[ibHE],&grHE->GetY()[ibHE],MBINSLOPE,chisqLinSlope); if(Slope<=MaxSlope)continue; tHESlope1=tHESlope; AHESlope1=AHESlope; tHESlope=grHE->GetX()[ibHE]; AHESlope=Slope; MaxSlope=Slope; } // delete *grHE; } //rough estimate: ~32 => Sum(V^2)~MSAMPLE*1000 inline void tSlopeXThresh(TGraph *gr,Float_t &Slopei, Float_t &Slopef, Float_t &tSlopei, Float_t &tSlopef, Int_t &ibini, Int_t &ibinf){ const Int_t MSAMPLE=16; const Float_t ThreshSlope=16; //avg increase of sqrt(ThreshSlope) in ibini=-1; ibinf=-1; tSlopei=-1; tSlopef=-1; Slopei=-NNN; Slopef=-NNN; for(Int_t ipt=MSAMPLE; iptGetN()-MSAMPLE; ipt+=MSAMPLE){ Slopei=FFTtools::sumVoltageSquared(gr,ipt,ipt+MSAMPLE)/FFTtools::sumVoltageSquared(gr,ipt-MSAMPLE,ipt); // cout<<" Slopei="<GetN()-MSAMPLE; iptf>0 && iptf>ipt; iptf-=MSAMPLE){ for(Int_t iptf=gr->GetN()-MSAMPLE; iptf>0 && iptf>ibini; iptf-=MSAMPLE){ Slopef=FFTtools::sumVoltageSquared(gr,iptf-MSAMPLE,iptf)/FFTtools::sumVoltageSquared(gr,iptf,iptf+MSAMPLE); if(Slopef>ThreshSlope){ tSlopef=gr->GetX()[iptf]; ibinf=iptf; break; } } //if(LDebug)printf("timeSlope: tSlope=%g tSlopef=%g ibSlope=%d ibSlopef=%d\n",tSlope,tSlopef,ibin,ibinf); if(LDebug)printf("timeSlope: tSlopei=%g tSlopef=%g ibSlope=%d ibSlopef=%d\n",tSlopei,tSlopef,ibini,ibinf); } void Draw4x4Gr(char *cgrID){ gStyle->SetTitleFontSize(0.1); gROOT->ForceStyle(); TCanvas *c0=new TCanvas("c0","c0"); c0->Divide(4,4); TCanvas *c1=new TCanvas("c1","c1"); c1->Divide(4,4); TCanvas *c2=new TCanvas("c2","c2"); c2->Divide(4,4); for(Int_t ich=0; ich<16; ich++){ c0->cd(ich+1); gPad->SetGrid(); sprintf(cgrname,"%s%d",cgrID,ich); TGraph *gr=(TGraph*)gROOT->FindObject(cgrname); TGraph *gr1=(TGraph*)gr->Clone(); TGraph *gr2=(TGraph*)gr->Clone(); gr->GetXaxis()->SetLabelSize(0.1); gr1->GetXaxis()->SetLabelSize(0.1); gr2->GetXaxis()->SetLabelSize(0.1); gr->SetLineWidth(2); gr->SetLineColor(izcolor[ich]); gr1->SetLineWidth(2); gr1->SetLineColor(izcolor[ich]); gr2->SetLineWidth(2); gr2->SetLineColor(izcolor[ich]); gr1->Draw("al"); gr2->Draw("al"); gr->Draw("al"); Int_t NSample_rms; getNSigtime(gr,16,fdum,NSample_rms); Int_t iduma=itimeVMax4(gr,Rx[ich].tVMax4,Rx[ich].tVMax4f,idum1,idum2); itimeNSiga(gr,NSample_rms,6,Rx[ich].tNSig,Rx[ich].tNSigf,Rx[ich].ibinNSig,idum1); SPESlope(gr,0,16,Rx[ich].tHESlope,Rx[ich].AHESlope,Rx[ich].tHESlope1,Rx[ich].AHESlope1); tSlopeXThresh(gr,Rx[ich].ASlope,Rx[ich].ASlopef,Rx[ich].tSlope,Rx[ich].tSlopef,idum2,idum3); printf("tNSig[%d]=%g tp1NSig=%g / SPESlope[%d]=%g tSlopeXThresh[%d]=%g tVMax4=%g\n",ich,Rx[ich].tNSig,Rx[ich].tp1NSig,ich,Rx[ich].tHESlope,ich,Rx[ich].tSlope,Rx[ich].tVMax4); c1->cd(ich+1); gPad->SetGrid(); gr1->GetXaxis()->SetRange(Rx[ich].ibinNSig-8,Rx[ich].ibinNSig+64); gr1->Draw("al"); Int_t ibmax=TMath::LocMax(gr->GetN(),gr->GetY()); c2->cd(ich+1); gPad->SetGrid(); gr2->GetXaxis()->SetRange(ibmax-64,ibmax); gr2->Draw("al"); } sprintf(cpngname,"$HOME/ctem/png/%s_4x4.pdf",cgrID); c0->SaveAs(cpngname); sprintf(cpngname,"$HOME/ctem/png/%s_4x4_zoom1.pdf",cgrID); c1->SaveAs(cpngname); sprintf(cpngname,"$HOME/ctem/png/%s_4x4_zoom2.pdf",cgrID); c2->SaveAs(cpngname); delete c0; delete c1; delete c2; } inline void gettTH1(TGraph *grSPE, Int_t ich){ Rx[ich].tTH1f=Rx[ich].tTH1i=-NNN; Double_t *xVal=grSPE->GetX(); Double_t *yVal=grSPE->GetY(); Int_t nbinstemp=grSPE->GetN(); Float_t binwidtemp=xVal[1]-xVal[0]; TH1F *htmp=new TH1F("htmp","htmp",nbinstemp+1,xVal[0]-0.5*binwidtemp,xVal[nbinstemp-1]+0.5*binwidtemp); htmp->FillN(nbinstemp,xVal,yVal); Int_t ibini=htmp->FindFirstBinAbove(MSIGMASPE*Rx[ich].Prms); Int_t ibinf=htmp->FindLastBinAbove(1.2*MSIGMASPE*Rx[ich].Prms); if(ibini<0){ delete htmp; return; } Rx[ich].tTH1f=htmp->GetBinCenter(ibinf); Rx[ich].tTH1i=htmp->GetBinCenter(ibini); tTH1i[ich]=Rx[ich].tTH1i; tTH1f[ich]=Rx[ich].tTH1f; // cout<<"tH1i="<ibmax)printf("gettNSig: MSIGMASPE=%g Scanning from ibmin=%d->ibmax=%d / Rx[ich].ibnVMax=%d rmsNSig=%g\n",MSIGMASPE,ibmin,ibmax,Rx[ich].ibnVMax,rmsNSig); for(Int_t ib=ibmin; ib<=ibmax; ib++){ if(fabs(grSPE->GetY()[ib])GetX()[ib],grSPE->GetN(),grSPE->GetY()[ib]); tXNSig=grSPE->GetX()[ib]; itNSig[ich]=tXNSig; break; } return tXNSig; } inline Float_t gettNSig0(TGraph *gr, Float_t fXThresh, Int_t &ibnX){ Float_t tX=-999; Int_t ibin=16; //avoid first block ibnX=-1; if(LDebug)cout<<"Threshold="<GetX()[ibin]<<" "<GetY()[ibin]<GetN()){ tX=gr->GetX()[ibin]; if(LDebug)printf("threshold=%g xval=%g yval=%g ymax=%g\n",fXThresh,gr->GetX()[ibin],gr->GetY()[ibin],TMath::MaxElement(gr->GetN(),gr->GetY())); } ibnX=ibin; return tX; } inline void GetXTalkGlitch(TGraph **grLoCal, Int_t iStringno){ const Int_t MCHSTRNG=4; Float_t tMaxNoCal[MCHSTRNG], AMaxNoCal[MCHSTRNG]; for(Int_t ich=iStringno; ich<16; ich+=MCHSTRNG){ AMaxNoCal[int(ich/MCHSTRNG)]=MaxElpm(grLoCal[ich],idum); tMaxNoCal[int(ich/MCHSTRNG)]=grLoCal[ich]->GetX()[idum]; if(LDebug)printf("NXTALK ich=%d t=%g A=%g\n",ich,tMaxNoCal[int(ich/MCHSTRNG)],AMaxNoCal[int(ich/MCHSTRNG)]); } // Float_t dtxcgrSigrSj, AxcgrSigrSj; for(Int_t ich=iStringno; ich<12; ich+=MCHSTRNG){ for(Int_t jch=ich+MCHSTRNG; jch<16; jch+=MCHSTRNG){ dtxcgrSigrSj=dtgr1gr2(grLoCal[ich],grLoCal[jch],AxcgrSigrSj); NXTALK->Fill(trigCode,iStringno,ich,jch,tMaxNoCal[ich],tMaxNoCal[jch],AMaxNoCal[ich]+AMaxNoCal[jch],dtxcgrSigrSj,AxcgrSigrSj),idum;} NXTALK->Fill(trigCode,iStringno,TMath::Mean(MCHSTRNG,tMaxNoCal),TMath::RMS(MCHSTRNG,tMaxNoCal),TMath::Mean(MCHSTRNG,AMaxNoCal),TMath::RMS(MCHSTRNG,AMaxNoCal),tMaxNoCal[0],tMaxNoCal[1],tMaxNoCal[2],tMaxNoCal[3],AMaxNoCal[0],AMaxNoCal[1],AMaxNoCal[2],AMaxNoCal[3]); } inline Bool_t LDAQX(TGraph *gr){ const Int_t MSAMPLE=32; Bool_t LGOOD=false; for(Int_t ibn=0; ibnGetY()[ibn]!=gr->GetY()[ibn+MSAMPLE])LGOOD=true; return !LGOOD; } TGraph *grSubHExShift(TGraph *gr1, TGraph *gr2){ TGraph *grVt1S=FFTtools::getInterpolatedGraph(gr1,0.1); TGraph *grVt2S=FFTtools::getInterpolatedGraph(gr2,0.1); TGraph *grHE1=FFTtools::getHilbertEnvelope(grVt1S); TGraph *grHE2=FFTtools::getHilbertEnvelope(grVt2S); TGraph *grSub=new TGraph(); Int_t ibdt=TMath::LocMax(grHE1->GetN(),grHE1->GetY())-TMath::LocMax(grHE2->GetN(),grHE2->GetY()); // for(Int_t ib=ibdt; ibGetN()-ibdt; ib++)grSub->SetPoint(ib,grHE1->GetX()[ib],grHE1->GetY()[ib-ibdt]-grHE2->GetY()[ib]); for(Int_t ib=ibdt; ibGetN()-ibdt; ib++){ Float_t yVal=grHE1->GetY()[ib-ibdt]-grHE2->GetY()[ib]; if(fabs(yVal)>1000)yVal=0; grSub->SetPoint(ib,grHE1->GetX()[ib],yVal); } delete grVt1S, grVt2S, grHE1, grHE2; return grSub; } //P(1sample)=exp(-x^2/2) => want N*P(1sample)GetX()[0]+8; Float_t xrmsf=xrmsi+32; TGraph *grtmp=grSubgr(grtmp0,xrmsi,xrmsf,fdum,fdum1,idum,idum1,idum2); Float_t rmstmp=grtmp->GetRMS(2); // TGraph *grSPE=FFTtools::getSimplePowerEnvelopeGraph(grtmp); // Float_t fSample=grSPE->GetN(); Float_t Thresh=rmstmp*sqrt(-2*log(PBk/fSample)); cout<<"Threshold="<=3){ tXThresh=gettNSig0(grVt,MSIG0*rmstmp,idum); MSIG0--; } delete grtmp0; return tXThresh; } inline Float_t gettNSigf(TGraph *grSPE, Int_t ich){ Float_t tXNSigf=-NNN; for(Int_t ib=grSPE->GetN()-1; ib>0; ib--){ if(fabs(grSPE->GetY()[ib])GetX()[ib]; itNSigf[ich]=Rx[ich].tNSigf; break; } return tXNSigf; } inline Float_t getAwttcog(TGraph *gr){ Float_t ATot=0; Float_t AwtTot=0; for(Int_t ib=0; ibGetN(); ib++){ AwtTot+=gr->GetX()[ib]*fabs(gr->GetY()[ib]); ATot+=fabs(gr->GetY()[ib]); } return AwtTot/ATot; } inline Float_t gettNSigV(TGraph *gr, Int_t ich, Int_t ibin0, Float_t VChRMS){ Float_t tNSig0=-NNN; for(Int_t ib=ibin0; ibGetN(); ib++){ if(fabs(gr->GetY()[ib])GetX()[ib]; break; } return tNSig0; } inline void DecodeListString(){ Int_t ncharString=sfileList.find("_20"); //number of characters to _20 string yearString=sfileList.substr(ncharString+1,4); iyrfromString=atoi(yearString.c_str()); string stationString=sfileList.substr(ncharString-2,2); Int_t ncharStringList=sfileList.find(".list"); sflistcomment=sfileList.substr(ncharString+6,ncharStringList-ncharString-6); cout<<"DecodeListString says "<Get("eventTree"); if(!eventTree) { std::cerr << "Can't find eventTree\n"; return -1; } //Now check the electronics type of the station int isIcrrEvent=0; int isAtriEvent=0; //Check an event in the run Tree and see if it is station1 or TestBed (stationId<2) eventTree->ResetBranchAddresses(); eventTree->SetBranchAddress("event",&rawEvPtr); eventTree->GetEntry(0); Int_t fIcrrData=AraGeomTool::isIcrrStation(rawEvPtr->stationId); iStaEvPtr=rawEvPtr->stationId; if((rawEvPtr->stationId)<2){ isIcrrEvent=1; isAtriEvent=0; } else{ isIcrrEvent=0; isAtriEvent=1; } eventTree->ResetBranchAddresses(); return rawEvPtr->stationId; /* UChar_t stationID; TTree *evtree=(TTree*)fin->Get("eventTree"); evtree->SetBranchAddress("stationID",&stationID); evtree->SetBranchAddress("run",&irun); evtree->Print(); evtree->GetEntry(0); cout<<"cout stationID="<GetMaximumBin(ilocxMax,ilocyMax,iloczMax); // phiMaxDegH=ilocxMax; // theMaxDegH=ilocyMax; // AMaxMapH=iloczMax; // histMapV->GetMaximumBin(ilocxMax,ilocyMax,iloczMax); // phiMaxDegV=ilocxMax; // theMaxDegV=ilocyMax; // AMaxMapV=iloczMax; // delete histMapH; // delete histMapV; // } #include "/home/dbesson/src/gsl_multiroot_finder/Vtx4Hit.C" void UVtxSpher4Hit(Bool_t LDebug0){ Float_t xRx[MCH16], yRx[MCH16], zRx[MCH16], HitTime[MCH16]; Float_t rZ, phiZ, theZ, dphiZ, dtheZ; Bool_t LUseAnt[MCH16]={false}; Int_t nUseAntSpher=0; for(Int_t ich=0; ichGetN(),gr->GetY())-TMath::MinElement(gr->GetN(),gr->GetY());} inline void CheckXlimitsgr(TGraph *gr){ Int_t nbins=gr->GetN(); LxLimitsgr=false; //if(nbins<=1){" CheckXlimitsgr graph has only "<GetX()[0])< 999 && fabs(gr->GetX()[nbins-1])<999)LxLimitsgr=true; } TH1F *hProjYgr(TGraph *gr,const char *cName,char *cTitle,Float_t &fPower){ const Int_t NB=256; Float_t xmin=TMath::MinElement(gr->GetN(),gr->GetY()); Float_t xmax=TMath::MaxElement(gr->GetN(),gr->GetY()); TH1F *htmp=new TH1F(cName,cTitle,NB,xmin,xmax); fPower=0; for(Int_t ib=0; ibGetN(); ib++){fPower+=gr->GetY()[ib]*gr->GetY()[ib]; htmp->Fill(gr->GetY()[ib]);} return htmp; } TH1F *hgr2TH1F(TGraph *gr){ Int_t Nbins=gr->GetN(); Float_t xi=gr->GetX()[0]; Float_t x1=gr->GetX()[1]; Float_t xf=gr->GetX()[Nbins-1]; Float_t dx=(xf-xi)/(Nbins-1); Float_t dx1=x1-xi; if(fabs(dx-dx1)/(dx+dx1)>1e-4)printf("hgr2TH1F: bin width dx=%g .ne. dx1=%g / dx2=%g / dx3=%g / dx4=%g / x0=%g x1=%g xf=%g Nbins=%d!\n",dx,dx1,gr->GetX()[2]-gr->GetX()[1],gr->GetX()[3]-gr->GetX()[2],gr->GetX()[4]-gr->GetX()[3],xi,x1,xf,Nbins); TH1F *htmp=new TH1F("htmp","htmp",Nbins,xi,xf); for(Int_t ib=0; ibFill(gr->GetX()[ib],gr->GetY()[ib]); return htmp; } inline TH1F *hRootFFT(TGraph *gr){ TH1 *hRFFT=0; TH1F *htime=hgr2TH1F(gr); // TVirtualFFT::SetTransform(0); hRFFT=htime->FFT(hRFFT,"MAG R2C"); //likely needs to be scaled by 1/htime binwidth // hRFFT=htime->FFT(hRFFT,"DHT"); //likely needs to be scaled by 1/htime binwidth delete htime; return (TH1F*)hRFFT; } TGraph *grDCZero(TGraph *gr){ const Int_t MOFF=32; //first 32 samples droop? TGraph *grtmp=new TGraph(gr->GetN()); Float_t VAvg=TMath::Mean(gr->GetN()-MOFF,&gr->GetY()[MOFF]); //==gr->GetMean(2) for(Int_t ipt=0; iptGetN(); ipt++) grtmp->SetPoint(ipt,gr->GetX()[ipt],gr->GetY()[ipt]-VAvg); grtmp->SetLineColor(kSpring); return grtmp; } TGraph *grDCZero_x0(TGraph *gr, Float_t x0){ TGraph *grtmp=new TGraph(gr->GetN()); Float_t dx=gr->GetX()[1]-gr->GetX()[0]; Int_t MOFF=(x0-gr->GetX()[0])/dx; Float_t VAvg=TMath::Mean(gr->GetN()-MOFF,&gr->GetY()[MOFF]); //==gr->GetMean(2) for(Int_t ipt=0; iptGetN(); ipt++) grtmp->SetPoint(ipt,gr->GetX()[ipt],gr->GetY()[ipt]-VAvg); grtmp->SetLineColor(kSpring); return grtmp; } inline Float_t getSNRZ(TGraph *gr, Float_t &SNR_FFTtools, Float_t &aVrms, Float_t &rmsMBNRMS){ const Int_t MOFF=32; const Int_t MBINSIG=64; aVrms=TMath::RMS(MBINRMS,&gr->GetY()[MOFF]); Double_t Pk2PkA, VrmsA; Int_t ipkbin; rmsMBNRMS=NNN; // cout<GetY())<<" "<GetY()[MOFF])<<" "<GetMaximum()<<" "<GetN()-MBINRMS; ib+=MBINRMS) rmsMBNRMS=TMath::Min(rmsMBNRMS,(Float_t)TMath::RMS(MBINRMS,&gr->GetY()[ib])); Float_t VpkZ=grMaxZ(gr,&ipkbin); Float_t Vrmsf=-9999; Float_t Vrmsi=-9999; if(ipkbin-MBINSIG>16)Vrmsi=TMath::RMS(ipkbin-MBINSIG,gr->GetY()); if(gr->GetN()-ipkbin-MBINSIG>16)Vrmsf=TMath::RMS(gr->GetN()-ipkbin-MBINSIG,&gr->GetY()[ipkbin+MBINSIG]); printf("VpkZ=%g rmsMBNRMS=%g Vrms=%g (nbins=%d) Vrmsi=%g (nbins=%d) Vrmsf=%g (nbins=%d)\n",VpkZ,rmsMBNRMS,aVrms,MBINRMS,Vrmsi,ipkbin-MBINSIG,Vrmsf,gr->GetN()-ipkbin-MBINSIG); return VpkZ/rmsMBNRMS; } inline Float_t rmsSPE(TGraph *grSPE, Int_t ich, Int_t MSAMPLERMS){ Int_t MBINSPERMS; if(MSAMPLERMS==-1)MBINSPERMS=MBINRMS; return TMath::Mean(MBINSPERMS,grSPE->GetY()); } inline void SwitchChannelOff(Int_t ich, const char* cmsg, Int_t ioff, Bool_t LDecrement){ if(!Rx[ich].LVtx)return; h2ChOff->Fill(ich,ioff); nSwitchOff[ich]++; Rx[ich].LVtx=false; if(LDecrement){ if(!LMC)cout<<"SwitchChannelOff ch="<GetN()-MBINRMS; ib+=MBINRMS){ rmsMBNRMS=TMath::RMS(MBINRMS,&gr->GetY()[ib]); hrms->Fill(rmsMBNRMS); if(rmsmin>rmsMBNRMS)rmsmin=rmsMBNRMS; if(rmsmaxDraw("al"); Float_t tnsXV0=-1; for(Int_t ib=0; ibGetN(); ib++){ if(fabs(gr->GetY()[ib])GetX()[ib]; break; } return tnsXV0; } inline Float_t tVXpos(TGraph *gr, Int_t ibini, Int_t ibinf, Float_t Vthresh){ Float_t tVX=0; for(Int_t jbin=ibini; jbinGetY()[jbin]GetX()[jbin]; break; } return tVX; } inline Float_t tVXneg(TGraph *gr, Int_t ibini, Int_t ibinf, Float_t Vthresh){ Float_t tVX=0; for(Int_t jbin=ibini; jbinGetY()[jbin]>Vthresh)continue; tVX=gr->GetX()[jbin]; break; } return tVX; } inline Float_t tfVMax(TGraph *gr, Float_t fracVMax){ Float_t tVMaxf=-1; Float_t VMax=TMath::MaxElement(gr->GetN(),gr->GetY()); Int_t ibnmax=TMath::LocMax(gr->GetN(),gr->GetY()); for(Int_t jbin=0; jbinGetY()[jbin]GetX()[jbin]; break; } return tVMaxf; } inline Float_t tfVMaxRev(TGraph *gr, Float_t fracVMax){ Float_t tVMaxf=-1; Float_t VMax=TMath::MaxElement(gr->GetN(),gr->GetY()); Int_t ibnmax=TMath::LocMax(gr->GetN(),gr->GetY()); for(Int_t jbin=gr->GetN()-1; jbin>ibnmax; jbin--){ if(gr->GetY()[jbin]GetX()[jbin]; break; } return tVMaxf; } inline Float_t tMaxV2(TGraph *gr, Int_t ich, Float_t &fVMax, Int_t &ibnVMax2){ Int_t ibnVMinMx12, ibnFirstVMax, ibnSecondVMax; const Float_t dtVMaxVMax2=16; Float_t timeSecondPeak; TGraph *grtmp=(TGraph*)gr->Clone(); Int_t nbin8=dtVMaxVMax2/(gr->GetX()[1]-gr->GetX()[0]); for(Int_t ib=Rx[ich].ibnVMax-nbin8; ibgr->GetN()-1)continue; grtmp->SetPoint(ib,grtmp->GetX()[ib],0); } ibnVMax2=FFTtools::getPeakBin(grtmp); fVMax=grtmp->GetY()[ibnVMax2]; timeSecondPeak=grtmp->GetX()[ibnVMax2]; // if(timeSecondPeak==Rx[ich].tVMax){printf("ibnVMax=%d ibnVMax2=%d fVMax2=%g VMax=%g t2=%g t1=%g t1prime=%g ich=%d\n",Rx[ich].ibnVMax,ibnVMax2,fVMax,gr->GetY()[Rx[ich].ibnVMax],timeSecondPeak,Rx[ich].tVMax,gr->GetX()[Rx[ich].ibnVMax],ich); gr->Print("all"); grtmp->Print("all"); abort();} ibnFirstVMax=TMath::Min(ibnVMax2,Rx[ich].ibnVMax); ibnSecondVMax=TMath::Max(ibnVMax2,Rx[ich].ibnVMax); TGraph *grtmpValley=new TGraph(ibnSecondVMax-ibnFirstVMax,&gr->GetX()[ibnFirstVMax],&gr->GetY()[ibnFirstVMax]); ibnVMinMx12=TMath::LocMin(ibnSecondVMax-ibnFirstVMax,&gr->GetY()[ibnFirstVMax]) + ibnFirstVMax; idum3=TMath::LocMin(ibnSecondVMax-ibnFirstVMax,&gr->GetY()[ibnFirstVMax]) + ibnFirstVMax; tVMinMx12[ich]=gr->GetX()[ibnVMinMx12]; VMinMx12[ich]=gr->GetY()[ibnVMinMx12]; TGraph *grVMax1=new TGraph(ibnVMinMx12,gr->GetX(),gr->GetY()); TGraph *grVMax2=new TGraph(gr->GetN()-ibnVMinMx12-1,&gr->GetX()[ibnVMinMx12],&gr->GetY()[ibnVMinMx12]); TGraph *grXC=FFTtools::getCorrelationGraph(grVMax1,grVMax2); AXCVMax1VMax2[ich]=getPeakValZ(grXC,&ipkbin); dtXCVMax1VMax2[ich]=-grXC->GetX()[ipkbin]; // if(ich>0){cout<GetN()<<" "<GetN()<<" "<GetN()<Print("all"); grVMax2->Print("all"); grXC->Print("all"); abort();} // if(idum1<=idum || ibnVMinMx12idum1 || ibnVMinMx12!=idum3){printf("ibntmin=%d/ibntmax=%d of two highest peaks minbin b/w them=%d idum3=%d\n",idum,idum1,ibnVMinMx12,idum3); abort();} delete grVMax1; delete grVMax2; delete grXC; delete grtmp; delete grtmpValley; return timeSecondPeak; } inline void getWell(TGraph *gr, Int_t ich, Float_t xi, Float_t xf){ const Float_t dtPk1Pk2Min=16; //16 ns minimum separation if(LDebug)cout<<"getWell making sub-graphs!"<GetN(); ib++){ if(grtmp->GetX()[ib]GetX()[0]+tp1NSig[ich])continue; if(grtmp->GetY()[ib]GetY()[ib]; tMx2=grtmp->GetX()[ib]; } for(Int_t ib=0; ibGetN(); ib++){ if(grtmp->GetX()[ib]GetX()[0]+tp1NSig[ich])continue; if(grtmp->GetX()[ib]>VMx2)continue; if(grtmp->GetY()[ib]>VMnVMx1VMx2[ich])continue; VMnVMx1VMx2[ich]=grtmp->GetY()[ib]; tVMnVMx1VMx2[ich]=grtmp->GetX()[ib]; } //now find XCor b/w gri and grf: TGraph *gri=grSubgr00(grtmp,xi,tVMnVMx1VMx2[ich]); TGraph *grf=grSubgr00(grtmp,tVMnVMx1VMx2[ich],xf); dtgrxixf[ich]=dtgr1gr2(gri,grf,Agrxixf[ich],idum); delete grtmp, gri, grf; } inline void FitBox(TGraph *grPE, Int_t ich, Float_t xmin, Float_t xmax, Float_t xStepUpi, Float_t xStepDowni, Float_t ApreStepi, Float_t AStepi, const char *ctmp){ TCanvas *c1dStep=new TCanvas("c1dStep","c1dStep"); TF1 *f1dStep=new TF1("f1dStep","[2]+(x>[0]&&x<[1])*[3]",xmin,xmax); f1dStep->SetParName(0,"xStepUp"); f1dStep->SetParName(1,"xStepDown"); f1dStep->SetParName(2,"pol0"); f1dStep->SetParName(3,"AStep"); f1dStep->FixParameter(0,xStepUpi); f1dStep->FixParameter(1,xStepDowni); f1dStep->FixParameter(2,ApreStepi); f1dStep->FixParameter(3,AStepi); // f1dStep->FixParameter(0); // f1dStep->FixParameter(1); // f1dStep->FixParameter(2); // f1dStep->FixParameter(3); f1dStep->SetParLimits(0,xmin,xmax); f1dStep->SetParLimits(1,xmin,xmax); f1dStep->SetParLimits(3,0,AStepi); printf("xStepUpi=%g xStepDowni=%g ApreStepi=%g AStepi=%g / limits=%g/%g",xStepUpi,xStepDowni,ApreStepi,AStepi,xmin,xmax); grPE->Fit(f1dStep,"BRMQ"); f1dStep->ReleaseParameter(0); grPE->Fit(f1dStep,"BRMQ"); f1dStep->ReleaseParameter(1); grPE->Fit(f1dStep,"BRMQ"); f1dStep->ReleaseParameter(2); grPE->Fit(f1dStep,"BRMQ"); Rx[ich].tiBox=f1dStep->GetParameter(0); tiBox[ich]=Rx[ich].tiBox; Rx[ich].tfBox=f1dStep->GetParameter(1); tfBox[ich]=Rx[ich].tfBox; Rx[ich].PRMSBox=f1dStep->GetParameter(2); Rx[ich].SNRBox=f1dStep->GetParameter(3)/Rx[ich].PRMSBox; printf("%sSignal Duration(s)= %g Astep/pol0= %g %s\n",KGRN,f1dStep->GetParameter(1)-f1dStep->GetParameter(0),Rx[ich].SNRBox,KNRM); // gr->Draw(); sprintf(cpngname,"$HOME/ctem/png/%s.png",ctmp); c1dStep->SaveAs(cpngname); delete f1dStep; delete c1dStep; } inline void FillPowerArray(TGraph *gr, Int_t ich){ TGraph *grtemp=FFTtools::makePowerSpectrum(gr); for(Int_t ib=0; ibGetN(); ib++){ Int_t ibfreq=TMath::Min(int(grtemp->GetX()[ib]*10),MFRQBIN-1); fdum=grtemp->GetY()[ib]; Pfreqbin[ibfreq]+=fdum; h2fftVChEV->Fill(ibfreq,ich,fdum); } delete grtemp; } inline void TwinPeaks(TGraph *gr, Int_t ich){ Int_t nindexf=gr->GetN()-Rx[ich].ibnCOG-1; if(nindexf<=16){ printf("ERRZ: TwinPeaks Rx[%d].nbnCOG=%d - RETURNING\n",ich,Rx[ich].ibnCOG); return; } TGraph *gri=new TGraph(Rx[ich].ibnCOG,gr->GetX(),gr->GetY()); TGraph *grf=new TGraph(nindexf,&gr->GetX()[nindexf],&gr->GetY()[nindexf]); Rx[ich].tTPi=gettNSigV(gri,ich,0,Rx[ich].Vrms); Rx[ich].tTPf=gettNSigV(grf,ich,0,Rx[ich].Vrms); dtTPif[ich]=Rx[ich].tTPf-Rx[ich].tTPi; Rx[ich].dtXCTPif=dtgr1gr2(grf,gri,Rx[ich].AXCTPif,idum); deltTwinPeaks[ich]=Rx[ich].dtXCTPif; if(Rx[ich].tTPi>-128 && Rx[ich].tTPf>-128)printf("TwinPeaks: Rx[%d].tTPi=%g / Rx[%d].tTPf=%g\n",ich,Rx[ich].tTPi,ich,Rx[ich].tTPf); delete gri; delete grf; } inline void getDRAt(TGraph *gr, Float_t tMargin, Float_t &xD, Float_t &AD, Float_t &xR, Float_t &AR){ //Float_t &xpk, Float_t &Apk, Float_t &xpk2, Float_t &Apk2){ xD=-1; AD=-1; xR=-1; AR=-1; Float_t xpk=-1; Float_t xpk2=-1; Float_t Apk2=-1; Float_t Apk=-1; Int_t ibpkp=TMath::LocMax(gr->GetN(),gr->GetY()); Int_t ibpkm=TMath::LocMin(gr->GetN(),gr->GetY()); Int_t ibpk=ibpkp; if(gr->GetY()[ibpkp]GetY()[ibpkm]))ibpk=ibpkm; xpk=gr->GetX()[ibpk]; Apk=fabs(gr->GetY()[ibpk]); for(Int_t ibn0=0; ibn0GetN(); ibn0++){ if(fabs(xpk-gr->GetX()[ibn0])GetY()[ibn0])GetY()[ibn0]); xpk2=gr->GetX()[ibn0]; } Int_t ibncoggr=ibinCOG(gr); for(Int_t ibnD=0; ibnDGetY()[ibnD])GetY()[ibnD]); xD=gr->GetX()[ibnD]; } for(Int_t ibnR=ibncoggr; ibnRGetN() && false; ibnR++){ if(fabs(gr->GetY()[ibnR])GetY()[ibnR]); xR=gr->GetX()[ibnR]; } AD=Apk; xD=xpk; AR=Apk2; xR=xpk2; if(xpk>xpk2){AD=Apk2; xD=xpk2; AR=Apk; xR=xpk;} printf("tD=%g AD=%g / tR=%g AR=%g \n",xD,AD,xR,AR); } inline Float_t dtPeaksHE(TGraph *grHE, Int_t ich, Float_t delt0){ const Int_t MAXPEAKS=4; const Float_t MSGSPX=4; Float_t POROG=0.16; //NB: ONE ITERATION AT 0.1 WORKS WELL!!! (4Feb21) Int_t ipt2pks[MAXPEAKS]; // TGraph *grPE=FFTtools::getSimplePowerEnvelopeGraph(gr); TH1F *h=hgr2TH1F(grHE); cout<<"TSpectrum setting hspex in dtPeaksHE!!!"<Search(h,MSGSPX,"",POROG); //search(const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05) while(npkSpx[ich]>2){ if(npkSpx[ich]==0){delete hspex; delete h; return -1;} while(npkSpx[ich]>2 && POROG<0.8){ POROG+=0.2; npkSpx[ich]=hspex->Search(h,MSGSPX,"",POROG); //search(const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05) while(npkSpx[ich]>2){ } if(POROG>=0.8){delete hspex; delete h; return -1;} Double_t *xpeaks=hspex->GetPositionX(); Double_t *ypeaks=hspex->GetPositionY(); idum=TMath::LocMax(npkSpx[ich],ypeaks); xpkSpx[ich]=xpeaks[idum]; ApkSpx[ich]=ypeaks[idum]; for(Int_t ihbn=0; ihbnGetNbinsX(); ihbn++) if(fabs(h->GetBinCenter(ihbn)-xpkSpx[ich])<16)h->SetBinContent(ihbn,0); idum=hspex->Search(h,MSGSPX,"",POROG); //search(const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05) if(idum==0){delete hspex; return -1;} idum1=TMath::LocMax(idum,hspex->GetPositionY()); xpk2Spx[ich]=hspex->GetPositionX()[idum1]; Apk2Spx[ich]=hspex->GetPositionY()[idum1]; delete hspex; delete h; return fabs(xpk2Spx[ich]-xpkSpx[ich]); } /* TF1 *dubg=new TF1("dubg","gaus(0)+gaus(3)",-6,6) dubg->SetParameters(1,0,1) dubg->FixParameter(3,dubg->GetParameter(0)) dubg->SetParLimits(4,dubg->GetParameter(1)+8,dubg->GetParameter(1)+512) dubg->FixParameter(5,dubg->GetParameter(2)) */ //inline Float_t dtdubgHE(TGraph *grHE){fdubg }; inline Int_t XCGausHE(TGraph *grHE, Int_t MBING, Int_t ndelbinsig, Int_t ich){ TGraph *grHEtmp=FFTtools::getBoxCar(grHE,8); Float_t FWHM=MBING/4; Float_t AMax=TMath::MaxElement(grHEtmp->GetN(),grHEtmp->GetY()); Int_t ibinAMax=TMath::LocMax(grHEtmp->GetN(),grHEtmp->GetY()); TF1 *fdubg=new TF1("fdubg","[5]+[0]*exp(-(x-[1])*(x-[1])/([2]*[2]))+[4]*[0]*exp(-(x-([1]+[3]))*(x-([1]+[3]))/([2]*[2]))"); Float_t fNorm=AMax/(sqrt(TMath::TwoPi())*FWHM/2.36); Float_t fpol0=TMath::Mean(64,grHEtmp->GetY()); fdubg->SetParameters(fNorm,grHEtmp->GetX()[ibinAMax],FWHM/2,tp2NSig[ich]-tp1NSig[ich],1,fpol0); // fdubg->SetParLimits(0,0,1024); fdubg->SetParLimits(2,16,64); // fdubg->SetParLimits(3,0,512); fdubg->SetParLimits(3,0.8*(tp2NSig[ich]-tp1NSig[ich]),1.2*(tp2NSig[ich]-tp1NSig[ich])); fdubg->FixParameter(4,1); fdubg->FixParameter(5,fpol0); fdubg->SetParNames("c0","t1","wid","dt","RA2A1","yoff"); // fdubg->SetParLimits(4,0.5,2); // fdubg->FixParameter(0,fNorm); grHEtmp->Fit("fdubg","Q"); fdubg->ReleaseParameter(5); grHEtmp->Fit("fdubg","Q"); fdubg->ReleaseParameter(4); grHEtmp->Fit("fdubg"); A1DubG[ich]=fdubg->GetParameter(0); t1DubG[ich]=fdubg->GetParameter(1); A2DubG[ich]=fdubg->GetParameter(0)*fdubg->GetParameter(4); WidDubG[ich]=fdubg->GetParameter(2); dtDubG[ich]=fdubg->GetParameter(3); Float_t dt=grHEtmp->GetX()[1]-grHEtmp->GetX()[0]; TGraph *grgaus=new TGraph(MBING,grHEtmp->GetX(),grHEtmp->GetY()); //gaussian with same binning as input gr for(Int_t ib=0; ibSetPoint(ib,dt*xval,AMax*exp(-0.5*xval*xval/(FWHM*FWHM))); } TGraph *grtmp, *grtmp1; grtmp=FFTtools::getCorrelationGraph(grHEtmp,grgaus); AXCGaus[0]=getPeakValZ(grtmp,&idum); tXCGaus[0]=grtmp->GetX()[idum]; // delete grtmp; // cout<GetN()<<" "<GetN()<<" "<GetN()); ib++) grHEtmp->SetPoint(ib,grHEtmp->GetX()[ib],0); // grHEtmp->Print("all"); abort(); grtmp1=FFTtools::getCorrelationGraph(grHEtmp,grgaus); AXCGaus[1]=getPeakValZ(grtmp1,&idum); tXCGaus[1]=grtmp1->GetX()[idum]; // cout<GetN()<<" "<GetN()<<" "<GetX()[0]<<" "<GetX()[grtmp->GetN()-1]<<" "<GetN()<<"/"<GetX()[0]<<" "<GetX()[gr->GetN()-1]<<" "<GetN()<<" "<GetX()[0]<<" "<GetX()[grgaus->GetN()-1]<<" "<GetN()<GetX()[1]-grtmp1->GetX()[0]; delete fdubg; delete grgaus; delete grtmp; delete grtmp1; delete grHEtmp; if(MBING*1.2*dt1>fabs(tXCGaus[1]-tXCGaus[0]))return 0; else return 1; } inline Float_t tgp0Fit(TGraph *grSPE, Int_t ich){ Float_t fgp0par1; grSPE->Fit("gaus","Q"); TF1 *ftmp=grSPE->GetFunction("gaus"); // grSPE->Fit("landau"); TF1 *ftmp=grSPE->GetFunction("landau"); TF1 *fgp0z=new TF1("fgp0z","gaus(0)+pol0(3)"); fgp0z->FixParameter(0,ftmp->GetParameter(0)); fgp0z->FixParameter(1,ftmp->GetParameter(1)); fgp0z->FixParameter(2,ftmp->GetParameter(2)); fgp0z->FixParameter(3,Rx[ich].Prms); // fgp0->FixParameter(0); // fgp0->FixParameter(1); // fgp0->FixParameter(2); // fgp0->FixParameter(3); grSPE->Fit("fgp0z","Q"); fdum=fgp0z->GetParameter(0); fgp0z->FixParameter(0,fdum); // fgp0->FixParameter(0); fgp0z->ReleaseParameter(1); fgp0z->ReleaseParameter(2); fgp0z->ReleaseParameter(3); grSPE->Fit("fgp0z","Q"); Rx[ich].SPERMSGFit=fgp0z->GetParameter(3); fgp0par1=fgp0z->GetParameter(1); // delete ftmp; //CRASHES! delete fgp0z; return fdum; // grSPE->Draw("al"); // c1->SaveAs("$HOME/ctem/png/a1.png"); // delete ftmp; } inline Float_t tXCGSPE(TGraph *grSPE, Int_t ich, Int_t MBING, Float_t &AXCGSPE){ Float_t tXCGauss=-NNN; Float_t FWHM=MBING/4; Float_t AMax=TMath::MaxElement(grSPE->GetN(),grSPE->GetY()); Int_t ibinAMax=TMath::LocMax(grSPE->GetN(),grSPE->GetY()); Float_t dt=grSPE->GetX()[1]-grSPE->GetX()[0]; TGraph *grgaus=new TGraph(MBING,grSPE->GetX(),grSPE->GetY()); for(Int_t ib=0; ibSetPoint(ib,dt*xval,AMax*exp(-0.5*xval*xval/(FWHM*FWHM))); } Int_t nbinmax=TMath::Min(grSPE->GetN()-1,Rx[ich].ibnVMax+64); Int_t nbinmin=TMath::Max(0,Rx[ich].ibnVMax-64); TGraph *grtmp1=new TGraph(nbinmax-nbinmin,&grSPE->GetX()[nbinmin],&grSPE->GetY()[nbinmin]); TGraph *grtmp=FFTtools::getCorrelationGraph(grSPE,grgaus); AXCGSPE=getPeakValZ(grtmp,&idum); tXCGauss=grtmp->GetX()[idum]; delete grtmp1; delete grtmp; delete grgaus; return tXCGauss; } //rough estimate: ~32 => Sum(V^2)~MSAMPLE*1000 inline Float_t tMaxSlope(TGraph *gr, Int_t ibnMax, Float_t &SlopeMax){ const Int_t MSAMPLE=16; Float_t SlopeLoc=-NNN; Float_t tSlopeLoc; const Int_t MFAC=8; SlopeMax=-NNN; for(Int_t ipt=MSAMPLE; iptGetN()-MSAMPLE && ipt[1])*[3]*exp([2]*(x-[1]))",xmin,xmax); fDExp->SetParName(0,"y0"); fDExp->SetParName(1,"xpk"); fDExp->SetParName(2,"exp"); fDExp->SetParName(3,"Aexp"); fDExp->SetParameters(y0,xpk,-1,Apk); fDExp->FixParameter(0,y0); fDExp->FixParameter(1,xpk); fDExp->FixParameter(3,Apk); grPE->Fit(fDExp,"BQ"); fDExp->ReleaseParameter(0); grPE->Fit(fDExp,"BQ"); fDExp->ReleaseParameter(1); grPE->Fit(fDExp,"BQ"); fDExp->ReleaseParameter(3); grPE->Fit(fDExp,"BQ"); y0ExpFit[ich]=fDExp->GetParameter(0); tExpFit[ich]=fDExp->GetParameter(1); SlopeExpFit[ich]=fDExp->GetParameter(2); AExpFit[ich]=fDExp->GetParameter(3); if(fabs(tExpFit[ich])>256||TMath::IsNaN(tExpFit[ich])){ tExpFit[ich]=-512; SlopeExpFit[ich]=-512; y0ExpFit[ich]=-512; AExpFit[ich]=-512; } delete fDExp; } inline void FitDubExp(TGraph *grPE, Int_t ich, Float_t dtpksmax){ const Float_t dtPk0=32; const Float_t expSlope0=-0.1; // Float_t Apk=grMaxZ(grPE,&idum); Float_t xpk=grPE->GetX()[idum]; // Float_t xmin=grPE->GetX()[0]; Float_t xmax=grPE->GetX()[grPE->GetN()-1]; Float_t Apk=ANSig1[ich]; Float_t xpk=tp1NSig[ich]; Float_t xmin=xpk-dtPk0; Float_t xmax=xpk+dtpksmax+dtPk0; // printf("FitDampedExp Apk=%g xpk=%g y0=%g\n",Apk,xpk,y0); Float_t y0=TMath::Mean(grPE->GetN()/8,grPE->GetY()); TF1 *fDubExp=new TF1("fDubExp","[0]+(x>[1])*[3]*exp([2]*(x-[1]))+(x>([1]+[4]))*[5]*exp([2]*(x-([1]+[4])))",xmin,xmax); fDubExp->SetParName(0,"y0"); fDubExp->SetParName(1,"x0DubExp"); fDubExp->SetParName(2,"expDubExp"); fDubExp->SetParName(3,"A1DubExp"); fDubExp->SetParName(4,"dtDubExp"); fDubExp->SetParName(5,"A2DubExp"); fDubExp->SetParameters(y0,xpk,expSlope0,Apk,64,Apk/4.); fDubExp->SetParLimits(5,Apk/2,1.5*Apk); if(tp2NSig[ich]>-999&&tp2NSig[ich]-tp1NSig[ich]SetParameter(4,tp2NSig[ich]-tp1NSig[ich]); fDubExp->FixParameter(4,tp2NSig[ich]-tp1NSig[ich]);} // grPE->Fit(fDubExp,"R"); abort(); fDubExp->FixParameter(0,y0); fDubExp->FixParameter(1,xpk); fDubExp->FixParameter(3,Apk); grPE->Fit(fDubExp,"BQ"); fDubExp->ReleaseParameter(0); grPE->Fit(fDubExp,"BRQ"); fDubExp->ReleaseParameter(1); grPE->Fit(fDubExp,"BRQ"); fDubExp->ReleaseParameter(3); grPE->Fit(fDubExp,"BRQ"); fDubExp->ReleaseParameter(4); fDubExp->SetParLimits(4,dtPk0,dtpksmax+dtPk0); grPE->Fit(fDubExp,"BRQ"); y0DubExp[ich]=fDubExp->GetParameter(0); t1DubExp[ich]=fDubExp->GetParameter(1); SlopeDubExp[ich]=fDubExp->GetParameter(2); A1DubExp[ich]=fDubExp->GetParameter(3); dtDubExp[ich]=fDubExp->GetParameter(4); A2DubExp[ich]=fDubExp->GetParameter(5); delete fDubExp; } inline void FitDubExpxixf(TGraph *grPE, Int_t ich, Float_t xi, Float_t xf){ TGraph *grtmp=grSubgr00(grPE,xi,xf); TF1 *fDubExp=new TF1("fDubExp","[0]+(x>[1])*[3]*exp([2]*(x-[1]))+(x>([1]+[4]))*[5]*exp([2]*(x-([1]+[4])))",xi,xf); fDubExp->SetParName(0,"y0if"); fDubExp->SetParName(1,"x0DubExpif"); fDubExp->SetParName(2,"expDubExpif"); fDubExp->SetParName(3,"A1DubExpif"); fDubExp->SetParName(4,"dtDubExpif"); fDubExp->SetParName(5,"A2DubExpif"); Float_t y0=TMath::Mean(grtmp->GetN()/8,grtmp->GetY()); Float_t Apk=grMaxZ(grPE,&idum); Float_t xpk=grPE->GetX()[idum]; // idum=TMath::LocMax(grtmp->GetN(),grtmp->GetY()); Float_t xpk=grtmp->GetX()[idum]; Float_t Apk=grtmp->GetY()[idum]; fDubExp->SetParameters(y0,grtmp->GetX()[idum],-0.1,grtmp->GetY()[idum],16,grtmp->GetY()[idum]); fDubExp->SetParLimits(4,16,xf-xi); fDubExp->SetParLimits(5,grtmp->GetY()[idum]/2.,1.5*grtmp->GetY()[idum]); fDubExp->FixParameter(0,y0); fDubExp->FixParameter(1,xpk); fDubExp->FixParameter(3,Apk); fDubExp->FixParameter(4,20); grtmp->Fit(fDubExp,"BQ"); fDubExp->ReleaseParameter(0); grtmp->Fit(fDubExp,"BRQ"); fDubExp->ReleaseParameter(1); grtmp->Fit(fDubExp,"BRQ"); fDubExp->ReleaseParameter(3); grtmp->Fit(fDubExp,"BRQ"); fDubExp->ReleaseParameter(4); grtmp->Fit(fDubExp,"BRQ"); y0DubExpif[ich]=fDubExp->GetParameter(0); if(TMath::IsNaN(y0DubExpif[ich]))y0DubExpif[ich]=-1; t1DubExpif[ich]=fDubExp->GetParameter(1); SlopeDubExpif[ich]=fDubExp->GetParameter(2); A1DubExpif[ich]=fDubExp->GetParameter(3); dtDubExpif[ich]=fDubExp->GetParameter(4); A2DubExpif[ich]=fDubExp->GetParameter(5); delete fDubExp; delete grtmp; } inline Float_t GetPSNR(TGraph *grV,Int_t ich){ Float_t PSum=0; Float_t Vrms0=rmsMinMBN(grV,h1dum); for(Int_t ib=0; ibGetN(); ib++)PSum+=(grV->GetY()[ib]-Vrms0)*(grV->GetY()[ib]-Vrms0)/(VrmsCh[ich]*VrmsCh[ich]); PSum/=grV->GetN(); return PSum; } //caution - LAllFits will break eventrecoMinuit! inline void getgrInfoCh(TGraph *gr, Int_t ich, Int_t ievtype){ MSIGMASPE=MSIGMASPE0; TGraph *grSPEtm; TGraph *grSPE; // TGraph *grtmp=FFTtools::simplePassBandFilter(gr,150,750); Float_t dtwfSPE, dtwfgr; nbinsVtgr[ich]=gr->GetN(); if(nbinsVtgr[ich]<=1){cout<<" Ch "<GetN()<<" bins / returning!"<GetX()[nbinsVtgr[ich]-1]-gr->GetX()[0]; if(LUSESPE && LxLimitsgr)grSPEtm=FFTtools::getSimplePowerEnvelopeGraph(gr); else grSPEtm=FFTtools::getHilbertEnvelope(gr); if(LUSEBOXCAR)grSPE=FFTtools::getBoxCar(grSPEtm,DTBOXCARNS); else grSPE=(TGraph*)grSPEtm->Clone(); delete grSPEtm; Int_t nbinsSPE=grSPE->GetN(); if(nbinsSPE<=1)cout<<" Ch "<GetN()<<" bins!!!"<GetX()[nbinsSPE-1]-grSPE->GetX()[0]; if(dtwfSPE!=dtwfgr){ printf("ERRZ PowerEnvelope!: grSPEdt=%g for nbins=%d / grdt=%g for nbins=%d\n",dtwfSPE,nbinsSPE,dtwfgr,gr->GetN()); delete grSPE; // grSPE=FFTtools::getSimplePowerEnvelopeGraph(gr); grSPE=FFTtools::getHilbertEnvelope(gr); nbinsSPE=grSPE->GetN(); dtwfSPE=grSPE->GetX()[nbinsSPE-1]-grSPE->GetX()[0]; if(dtwfSPE!=dtwfgr)printf("ERRZ Envelope!: grSPEdt=%g for nbins=%d / grdt=%g for nbins=%d\n",dtwfSPE,nbinsSPE,dtwfgr,gr->GetN()); // MSIGMASPE=MSIGMASPE0/2; //approximate rebinning } NSamples[ich]=grSPE->GetN(); Rx[ich].nSample=grSPE->GetN(); Rx[ich].tSlope=-NNN; Rx[ich].tSlopef=-NNN; Rx[ich].tHESlope=-NNN; Rx[ich].tNSig=-NNN; Rx[ich].tNSigf=-NNN; Rx[ich].tp1NSig=-NNN; Rx[ich].tm1NSig=-NNN; Rx[ich].tp2NSig=-NNN; Rx[ich].tm1NSig=-NNN; Rx[ich].tXCRx=-NNN; tp1NSig[ich]=-NNN; tm1NSig[ich]=-NNN; tp2NSig[ich]=-NNN; tm2NSig[ich]=-NNN; tSlope[ich]=-NNN; Rx[ich].tVHalfMax=-NNN; Rx[ich].tVMax4=-NNN; Rx[ich].tXCg=-NNN; Rx[ich].tiBox=-NNN; Rx[ich].tfBox=-NNN; Rx[ich].LVtx=false; Rx[ich].LVTX=false; Rx[ich].LXVtx=false; Rx[ich].HitTime=-NNN; Rx[ich].ibnVMax=FFTtools::getPeakBin(gr); //grSPE->gr 2/10/2020 Rx[ich].tVMax=gr->GetX()[Rx[ich].ibnVMax]; //grSPE->gr Rx[ich].VMax=gr->GetY()[Rx[ich].ibnVMax]; //grSPE->gr VMaxHit[ich]=Rx[ich].VMax; tVMax[ich]=Rx[ich].tVMax; VMinHit[ich]=TMath::MinElement(gr->GetN(),gr->GetY()); Rx[ich].ibnPMax=TMath::LocMax(grSPE->GetN(),grSPE->GetY()); Rx[ich].PMax=grSPE->GetY()[Rx[ich].ibnPMax]; //getPeakValZ(grSPE,Rx[ich].ibnVMax); Rx[ich].tPMax=grSPE->GetX()[Rx[ich].ibnPMax]; PSNRRx[ich]=GetPSNR(gr,ich); if(Rx[ich].ibnPMax>=16&&Rx[ich].ibnPMaxGetN()-16)WidtVMax[ich]=0.5*(grSPE->GetY()[Rx[ich].ibnPMax-16]+grSPE->GetY()[Rx[ich].ibnPMax+16])/Rx[ich].PMax; Rx[ich].tPMax2=tMaxV2(grSPE,ich,Rx[ich].fVMax2,Rx[ich].ibnVMax2); tVMax2[ich]=Rx[ich].tPMax2; VMax2[ich]=Rx[ich].fVMax2; Rx[ich].VSPErms=rmsSPE(grSPE,ich,-1); Rx[ich].VrmsMBN=rmsMinMBN(gr,h1VrmsMBN[ich]); Vrms1ev[ich]=Rx[ich].VrmsMBN; Rx[ich].h1Vrms=GetxMax(h1VrmsMBN[ich]); Rx[ich].Vrms=TMath::Max(Rx[ich].VrmsMBN,Rx[ich].h1Vrms); if(Rx[ich].Vrms>128){ printf("Channel %d rms=%g>128 / resetting to ",ich,Rx[ich].Vrms); Rx[ich].Vrms=TMath::Min(Rx[ich].VrmsMBN,Rx[ich].h1Vrms); printf("%g\n",Rx[ich].Vrms); } // if(NEvTot>=MEVRMSH1)Rx[ich].Vrms=Rx[ich].h1Vrms; Rx[ich].Arms=Rx[ich].Vrms; Rx[ich].PrmsMBN=rmsMinMBN(grSPE,h1PrmsMBN[ich]); Prms00MBN[ich]=Rx[ich].PrmsMBN; idum=h1PrmsMBN[ich]->GetMaximumBin(); Rx[ich].h1Prms=h1PrmsMBN[ich]->GetBinCenter(idum); Rx[ich].Prms=TMath::Max(Rx[ich].PrmsMBN,Rx[ich].h1Prms); h1Prms[ich]->Fill(Rx[ich].Prms); if(LDebug)printf("dtwfSPE=%g dtwfgr=%g Rx[%d].PMax=%g Rx[%d].VSPErms=%g PrmsMBN=%g h1Prms=%g Rx[%d].Prms=%g\n",dtwfSPE,dtwfgr,ich,Rx[ich].PMax,ich,Rx[ich].VSPErms,Rx[ich].PrmsMBN,Rx[ich].h1Prms,ich,Rx[ich].Prms); if(trigCode==2){ h1PrmsUB[ich]->Fill(grSPE->GetRMS(2)); Rx[ich].PrmsUB=h1PrmsUB[ich]->GetMean(); } // Rx[ich].TOT=TOT(gr,Rx[ich].nSatSample); TOTCh[ich]=Rx[ich].TOT; TOTSum+=Rx[ich].TOT; Rx[ich].SNR=fabs(Rx[ich].PMax)/Rx[ich].Prms; Rx[ich].tXCg=tXCGSPE(grSPE,ich,128,Rx[ich].AXCg); tXCg[ich]=Rx[ich].tXCg; Rx[ich].VAvg=TMath::Mean(gr->GetN(),gr->GetY()); Rx[ich].VAvg32=TMath::Mean(MSAMPLE_ONEBLOCK,gr->GetY()); h2Vavg32Ch->Fill(Rx[ich].VAvg32,ich); itNSig[ich]=-NNN; itNSigf[ich]=-NNN; Rx[ich].fpmExcursion=fgrpmExcursion(gr); if(Rx[ich].iPol==0)fVExcursion+=Rx[ich].fpmExcursion; else fHExcursion+=Rx[ich].fpmExcursion; // Int_t iduma=itimeVMax4(grSPE,Rx[ich].tVMax4,Rx[ich].tVMax4f,idum1,idum2); Awttcog[ich]=getAwttcog(gr); Rx[ich].pk2pkV=gtpk2pk(gr); Rx[ich].tVMax4=tfVMax(grSPE,0.25); Rx[ich].tVMax4f=tfVMaxRev(grSPE,0.25); Rx[ich].tVHalfMax=tfVMax(grSPE,0.5); Rx[ich].tNSig=gettNSig(grSPE,ich,64,Rx[ich].Prms); Rx[ich].tNSigf=gettNSigf(grSPE,ich); tNSigf[ich]=Rx[ich].tNSigf; Rx[ich].tNSig0=gettNSig(grSPE,ich,grSPE->GetN()*0.3,Rx[ich].Prms*0.8); RxtNSig[ich]=Rx[ich].tNSig; RxtNSig0Ch[ich]=Rx[ich].tNSig0; Rx[ich].ibnCOG=ibinCOG(grSPE); Rx[ich].tNAvg=(Rx[ich].tNSig+Rx[ich].tSlope+Rx[ich].tVMax)/3.; Rx[ich].rmsNAvg=fabs(Rx[ich].tNSig-Rx[ich].tNAvg)+fabs(Rx[ich].tSlope-Rx[ich].tNAvg)+fabs(Rx[ich].tVMax-Rx[ich].tNAvg); if(LDebug)printf("fbnCOG[%d]=%g\n",ich,float(Rx[ich].ibnCOG)/grSPE->GetN()); Float_t WidSigPk=24; if(LDP[0]||LDP[1]||LDP[2]||LDP[3]||LDP[4]||LDP[5])WidSigPk=64; dtp1p2NSig[ich]=gettNSig2pm(grSPE,ich,ievtype,WidSigPk); if(ich<=7 && dtp1p2NSig[ich]>0)nDPVDPH+=10; if(ich>7 && dtp1p2NSig[ich]>0)nDPVDPH+=1; // if(Rx[ich].tNSig==-NNN && Rx[ich].tp1NSig==-NNN){delete grSPE; return;} Rx[ich].tSlope=tMaxSlope(grSPE,Rx[ich].ibnPMax,Rx[ich].ASlope); ASlope[ich]=Rx[ich].ASlope; tSlope[ich]=Rx[ich].tSlope; if(abs(tSlope[ich])>2048 || TMath::IsNaN(tSlope[ich]))tSlope[ich]=-2048; gettTH1(grSPE,ich); if(Rx[ich].tSlope>-NNN)nhitSlope++; if(Rx[ich].tNSig>-NNN)nhitNSig++; //double pulse finding: TwinPeaks(gr,ich); if(Rx[ich].tTPi!=0 && Rx[ich].tTPf!=0)h2dtTwinPeaksVCh->Fill(Rx[ich].tTPf-Rx[ich].tTPi,ich); // tSlopeXThresh(grSPE,Rx[ich].ASlope,Rx[ich].ASlopef,Rx[ich].tSlope,Rx[ich].tSlopef,idum2,idum3); if(LDebug)printf("Fitting dtPeaksHE for channel %d\n",ich); deltpks[ich]=dtPeaksHE(grSPE,ich,MNSDELTPKS); if(LDebug)printf("Fitting XCGausHE for channel %d\n",ich); if(tm2NSig[ich]>0){ idum=XCGausHE(grSPE,32,64,ich); dtXCGaus[ich]=tXCGaus[1]-tXCGaus[0]; AdtXCGaus[ich]=AXCGaus[0]+AXCGaus[1]; } h2HitTimeCh->Fill(Rx[ich].HitTime,ich); // if(LEvType[8]||LEvType[3])Rx[ich].HitTime=Rx[ich].tp1NSig; if(LDebug)printf("Fitting DampedExp for channel %d\n",ich); FitDampedExp(grSPE,ich); if(LDebug)printf("Fitting DubExp for channel %d\n",ich); FitDubExp(grSPE,ich,256+32); if(LDebug)printf("Fitting DubExpxixf for channel %d\n",ich); FitDubExpxixf(grSPE,ich,tp1NSig[ich],tp1NSig[ich]+128); if(LDebug)printf("GettingWell for channel %d\n",ich); getWell(grSPE,ich,tp1NSig[ich],tp1NSig[ich]+128); if(ibnVtXm[1][ich]>0&&ibnVtXm[1][ich]-ibnVtXp[1][ich]>=MBNSMINFFT&&ibnVtXm[0][ich]-ibnVtXp[0][ich]>=MBNSMINFFT){ //two separate peaks detected TGraph *grVtR=new TGraph(ibnVtXm[1][ich]-ibnVtXp[1][ich],&gr->GetX()[ibnVtXp[1][ich]],&gr->GetY()[ibnVtXp[1][ich]]); TGraph *grFFTR=FFTtools::makePowerSpectrum(grVtR); TGraph *grVtD=new TGraph(ibnVtXm[0][ich]-ibnVtXp[0][ich],&gr->GetX()[ibnVtXp[0][ich]],&gr->GetY()[ibnVtXp[0][ich]]); TGraph *grFFTD=FFTtools::makePowerSpectrum(grVtD); PbinFFT(grFFTD,ich,8,0.16,0.8,0); PbinFFT(grFFTR,ich,8,0.16,0.8,1); // if(LDebug)for(Int_t ib=0; ib=10288 && irunNumber<=10292 && Rx[ich].tNSig>-128 && iStation0==1)Rx[ich].HitTime=Rx[ich].tSlope; // if(ievtype==3)Rx[ich].HitTime=Rx[ich].tNSig0; //for douple pulses from Deep Pulser // if(ievtype==5)Rx[ich].HitTime=Rx[ich].tVHalfMax; // if(iStation0==2 && ich==6)Rx[ich].HitTime+=dtCH6A2ns; // if(LPrintDbg){ // if(fabs(Rx[ich].VAvg)>dVMean||Rx[ich].VAvg32<-4*dVMean)printf("Rx[%d].VAvg=%g / Rx[%d].VAvg32=%g\n",ich,Rx[ich].VAvg,ich,Rx[ich].VAvg32); // } // TGraph *grtmp=FFTtools::getSimplePowerEnvelopeGraph(grSPE); // Int_t ipk=FFTtools::getPeakBin(grtmp); // itSPE[ich]=grtmp->GetX()[ipk]; // delete grtmp; if(Rx[ich].tp1NSig>-128 && Rx[ich].tp1NSig!=0)ntp1NSigHit++; if(Rx[ich].tNSig>-128 && Rx[ich].tNSig!=0)ntNSigHit++; if(Rx[ich].tSlope>-128 && Rx[ich].tSlope!=0)ntSlopeHit++; if(tExpFit[ich]>-128 && tExpFit[ich]!=0)ntExpFitHit++; if(tXCg[ich]>-128 && tXCg[ich]!=0)nXCgHit++; if(fabs(Rx[ich].tp1NSig-Rx[ich].tSlope)-NNN && Rx[ich].VMax0; Rx[ich].HitTime=Rx[ich].tp1NSig; if(ievtype==-7)Rx[ich].HitTime=Rx[ich].tVMax; Rx[ich].LVTX=Rx[ich].LVtx && nMatchdt[ich]>1; if(LLVTX)Rx[ich].LVtx=Rx[ich].LVTX; tHitTime[ich]=Rx[ich].HitTime; // if(iStation0==1 && (ich==1 || ich==5))SwitchChannelOff(ich,"Cable Delay for LRMCZ=true Ch. 5 (!LRMCZ=false Ch. 1) too large by 100 ns",1); if(Rx[ich].x==0 && Rx[ich].y==0 && Rx[ich].z==0)SwitchChannelOff(ich,"all of coordinates zero",2,true); if(LDebug)printf("getgrinfoCh (1) iev=%d ich=%d HitTime=%g LVtx=%d tNSig[%d]=%g tp1NSig=%g / tSlope=%g / tHESlope=%g tVMax=%g ibnVMax=%d nMatchdt=%d\n",ieventNumber,ich,Rx[ich].HitTime,Rx[ich].LVtx,ich,Rx[ich].tNSig,Rx[ich].tp1NSig,Rx[ich].tSlope,Rx[ich].tHESlope,Rx[ich].tVMax,Rx[ich].ibnVMax,nMatchdt[ich]); if(!Rx[ich].LVtxCutsFile)SwitchChannelOff(ich,"Rx.LVtxCutsFile=false!",3,true); //INTENDED TO SWITCH CHANNELS OFF IN CUTS FILE if(fabs(Rx[ich].VMax)>=VMAXMAX && Rx[ich].LVtx){ nRxADCX++; printf("Rx[%d].VMax=%g>%d \t",ich,Rx[ich].VMax,VMAXMAX); SwitchChannelOff(ich,"Rx.VMax too big!!",4,true); } if(fabs(Rx[ich].SNR)>=SNRHITMAX && Rx[ich].LVtx){ nRxADCX++; printf("Rx[%d].SNR=%g>%d \n",ich,Rx[ich].SNR,SNRHITMAX); SwitchChannelOff(ich,"Rx.SNR too big!",5,true); } if(!LGoodDDA(ich) && Rx[ich].LVtx){ printf("Rx[%d] DDA sum=%g \n",ich,fdum); SwitchChannelOff(ich,"High noise this DDA/hole!",6,false); } if(abs(Rx[ich].HitTime)>999 && Rx[ich].LVtx){ printf("getgrinfo: Rx[%d].HitTime=%g>999 / Setting LVtx=false!\n",ich,Rx[ich].HitTime); // grSPE->Print("all"); gr->Print("all"); SwitchChannelOff(ich,"HitTime OOB",7,true); } // if(Rx[ich].LVtx && iStation0==3 && (irunNumber>=1901 && iYear0<=2016) && fmod(ich,4)==3)SwitchChannelOff(ich,"A3/2016/string-4",8,true); if(Rx[ich].LVtx){ // FillPowerArray(gr,ich); if(Rx[ich].TOT>0)Rx[ich].SNR2TOT=Rx[ich].SNR/Rx[ich].TOT; if(Rx[ich].SNR2TOTGetX()[0],grSPE->GetX()[NSamples[ich]-1],Rx[ich].tNSig,Rx[ich].tNSigf,Rx[ich].Prms,Rx[ich].PMax,"tmp"); } if(PerCentDiff(Rx[ich].Vrms,Rx[ich].VrmsUB)>0.1 && Rx[ich].VrmsUB>0)printf("%s rms warning: ich=%d (voltage) Vrms=%g h1Vrms=%g Rx.Prms=%g Rx.PrmsMBN=%g Rx.h1Prms=%g VSPErms=%g SPERMSGFit=%g PRMSbox=%g VrmsUB=%g PrmsUB=%g \t tNSig=%g tNSig0=%g tMaxSlope=%g tVHalfMax=%g tfVMax(0.75)=%g tXCg=%g tGFit=%g tiBox=%g tHESlope=%g %s\n",KYEL,ich,Rx[ich].Vrms,Rx[ich].h1Vrms,Rx[ich].Prms,Rx[ich].PrmsMBN,Rx[ich].h1Prms,Rx[ich].VSPErms,Rx[ich].SPERMSGFit,Rx[ich].PRMSBox,Rx[ich].VrmsUB,Rx[ich].PrmsUB,Rx[ich].tNSig,Rx[ich].tNSig0,Rx[ich].tSlope,Rx[ich].tVHalfMax,tfVMax(grSPE,0.6),Rx[ich].tXCg,Rx[ich].tGFit,Rx[ich].tiBox,Rx[ich].tHESlope,KNRM); if(fabs(Rx[ich].tNSig-Rx[ich].tNSig0)>8)printf("%s tNSig/tNSig0 discrepancy: ich=%d (voltage) Vrms=%g h1Vrms=%g Rx.Prms=%g Rx.PrmsMBN=%g Rx.h1Prms=%g VSPErms=%g SPERMSGFit=%g PRMSbox=%g VrmsUB=%g PrmsUB=%g \t tNSig=%g tNSig0=%g tMaxSlope=%g tVHalfMax=%g tfVMax(0.75)=%g tXCg=%g tGFit=%g tiBox=%g tHESlope=%g %s\n",KYEL,ich,Rx[ich].Vrms,Rx[ich].h1Vrms,Rx[ich].Prms,Rx[ich].PrmsMBN,Rx[ich].h1Prms,Rx[ich].VSPErms,Rx[ich].SPERMSGFit,Rx[ich].PRMSBox,Rx[ich].VrmsUB,Rx[ich].PrmsUB,Rx[ich].tNSig,Rx[ich].tNSig0,Rx[ich].tSlope,Rx[ich].tVHalfMax,tfVMax(grSPE,0.6),Rx[ich].tXCg,Rx[ich].tGFit,Rx[ich].tiBox,Rx[ich].tHESlope,KNRM); NPVRMS->Fill(ich,Rx[ich].Vrms,Rx[ich].h1Vrms,Rx[ich].Prms,Rx[ich].PrmsMBN,Rx[ich].h1Prms,Rx[ich].VSPErms,Rx[ich].SPERMSGFit,Rx[ich].PRMSBox,Rx[ich].VrmsUB,Rx[ich].PrmsUB); h2dtNSigVM2Ch->Fill(Rx[ich].tNSig-Rx[ich].tVHalfMax,ich); h2dtNSigVMxCh->Fill(Rx[ich].tNSig-Rx[ich].tVMax,ich); h2dtVM4VM2Ch->Fill(Rx[ich].tVMax4-Rx[ich].tVHalfMax,ich); h2dtNSigtSlopeCh->Fill(Rx[ich].tNSig-Rx[ich].tSlope,ich); h2dtNSigtHESlopeCh->Fill(Rx[ich].tNSig-Rx[ich].tHESlope,ich); } if(LDebug)printf("getgrinfoCh (2) iev=%d ich=%d HitTime=%g LVtx=%d tNSig[%d]=%g tp1NSig=%g / tSlope=%g / tHESlope=%g tVMax=%g ibnVMax=%d nMatchdt=%d\n",ieventNumber,ich,Rx[ich].HitTime,Rx[ich].LVtx,ich,Rx[ich].tNSig,Rx[ich].tp1NSig,Rx[ich].tSlope,Rx[ich].tHESlope,Rx[ich].tVMax,Rx[ich].ibnVMax,nMatchdt[ich]); VrmsCh[ich]=Rx[ich].Vrms; PrmsCh[ich]=Rx[ich].Prms; if(LDebug)printf("Exiting getgrinfoCh[%d]\n",ich); delete grSPE; } void getXCtimesTV(TGraph **grPtrPtr){ for(Int_t igr=0; igr<4; igr++){ dtXCTV[igr]=dtgr1gr2(grPtrPtr[igr],grPtrPtr[igr+4],AXCTV[igr],idum); dtXCTV[igr+8]=dtgr1gr2(grPtrPtr[igr+8],grPtrPtr[igr+12],AXCTV[igr+8],idum); } } void getXCtimesij(TGraph **grPtrPtr){ nSNRcomb=0; SNRxcperCh=0; const Int_t MBNPK=4; Float_t AgrXC, fnum, fden; Int_t iXCHV=-1; for(Int_t igr=0; igrMCH16 if(!Rx[igr].LVtx0)continue; for(Int_t jgr=igr+1; jgrFill(jgr,fabs(AgrXC)); h1PkXCThermalSNR[igr][jgr]->Fill(fabs(AgrXC));} fnum=0; fden=0; for(Int_t ibn=TMath::Max(0,idum-MBNPK); ibnGetN()-1,idum+MBNPK); ibn++){ fnum+=grXC->GetX()[ibn]*fabs(grXC->GetY()[ibn]); fden+=fabs(grXC->GetY()[ibn]); } dtXC0[igr][jgr]=grXC->GetX()[idum]; if(LDebug)printf("1 dtXC0[%d][%d]=%g\n",igr,jgr,dtXC0[igr][jgr]); dtXC0[igr][jgr]=fnum/fden; if(LDebug)printf("2 dtXC0[%d][%d]=%g\n",igr,jgr,dtXC0[igr][jgr]); if(Rx[igr].ihole==Rx[jgr].ihole && Rx[igr].iPol+Rx[jgr].iPol==1 && fabs(Rx[igr].z-Rx[jgr].z)<12 && Rx[igr].z00<-16 && Rx[jgr].z00<-16){ if(iXCHV<7)iXCHV++; else printf("ERRZ! getXCtimesij iXCHV=%d OOB igr=%d/jgr=%d ihole=%d/jhole=%d ipoli=%d/ipolj=%d\n",iXCHV,igr,jgr,Rx[igr].ihole,Rx[jgr].ihole,Rx[igr].iPol,Rx[jgr].iPol); AXCRxHV[iXCHV]=AgrXC; tXCRxHV[iXCHV]=dtXC0[igr][jgr]; if(Rx[igr].iPol==1)tXCRxHV[iXCHV]*=-1; if(Rx[igr].iPol==1&&Rx[jgr].iPol==0)iXCRxHV[iXCHV]=10*jgr+igr; else if(Rx[igr].iPol==0&&Rx[jgr].iPol==1)iXCRxHV[iXCHV]=10*igr+jgr; else printf("getXCtimesij NOT has anomalous polarization! igr=%d/jgr=%d ihole=%d/jhole=%d ipoli=%d/ipolj=%d\n",igr,jgr,Rx[igr].ihole,Rx[jgr].ihole,Rx[igr].iPol,Rx[jgr].iPol); } if(fabs(dtXC0[igr][jgr])>MaxArrayTransitTime){ h2OOTHCh->Fill(igr,jgr); if(LDebug)printf("dtXC0[%d][%d]=%g > MaxArrayTransitTime=%g SNRxc=%g\n",igr,jgr,dtXC0[igr][jgr],MaxArrayTransitTime,SNRxc[igr][jgr]); // SNRxc[igr][jgr]=-1; // continue; } // SNRxc[igr][jgr]=fabs(grXC->GetY()[idum])/rmsZ(grXC); if(h1PkXCThermalSNR[igr][jgr]->GetMean()>0 && h1PkXCThermalSNR[igr][jgr]->GetRMS()>0)SNRxc[igr][jgr]=(fabs(AgrXC)-h1PkXCThermalSNR[igr][jgr]->GetMean())/h1PkXCThermalSNR[igr][jgr]->GetRMS();// SNRxc[igr][jgr]=fabs(AgrXC)/h1PkXCThermalSNR[igr][jgr]->GetMean(); else if(grXC->GetRMS(2)>0)SNRxc[igr][jgr]=fabs(AgrXC)/grXC->GetRMS(2); else SNRxc[igr][jgr]=Rx[igr].SNR+Rx[jgr].SNR; //SNRgr1+SNRgr2; dtxc[igr][jgr]=-888; nSNRcomb++; SNRxcperCh+=SNRxc[igr][jgr]; Float_t SNRgr1=getPeakValZ(grPtrPtr[igr],&idum1)/grPtrPtr[igr]->GetRMS(2); Float_t SNRgr2=getPeakValZ(grPtrPtr[jgr],&idum2)/grPtrPtr[jgr]->GetRMS(2); if(LDebug)printf("dtXC0[%d][%d]=%g / wtavg=%g GetRMS(2)=%g SNR1=%g SNR2=%g SNRXC=%g\n",igr,jgr,grXC->GetX()[idum],dtXC0[igr][jgr],grXC->GetRMS(2),SNRgr1,SNRgr2,SNRxc[igr][jgr]); delete grXC; } } if(nSNRcomb>0)SNRxcperCh/=nSNRcomb; Int_t ich0=ichMinHitTime; // for(Int_t ich=0; ichHitTimeMax){ ichMaxHitTime=ich; HitTimeMax=Rx[ich].HitTime; } if(Rx[ich].HitTime MaxArrayTransitTime=%g\n",ich,Rx[ich].HitTime,jch,Rx[jch].HitTime,MaxArrayTransitTime); // continue; } dtxc[ich][jch]=dtij; //Rx[ich].tNSig-Rx[jch].tNSig; SNRxc[ich][jch]=Rx[ich].SNR*Rx[jch].SNR; SNRxcperCh+=SNRxc[ich][jch]; nSNRcomb++; dtxc[jch][ich]=-dtxc[ich][jch]; SNRxc[jch][ich]=SNRxc[ich][jch]; } } TMath::Sort(MCH16,fdumArrTimes,iptHitTime2Rx,false); //true=>down strcpy(chitSeq,""); for(Int_t ich=0; ichFill(dtxc[ich][ichMinHitTime]/MaxArrayTransitTime,ich); htHit->Fill(Rx[ich].HitTime); } for(Int_t ich=0; ichGetEntries()>=4; ich++){ if(!Rx[ich].LVtx)continue; if(fabs(Rx[ich].HitTime-htHit->GetMean())>2*MaxArrayTransitTime){ SwitchChannelOff(ich,"OOB transit time/NOT decrementing",9,false); //double pulse confusion? printf("OOB transit time: Rx[%d].HitTime=%g vs. =%g+/-%g\n",ich,Rx[ich].HitTime,htHit->GetMean(),htHit->GetRMS()); } } Int_t irxch; for(Int_t ich=0; ich=2018 && ich%4==2)SwitchChannelOff(ich,"A5 turning off DDA3",10,true); //7May24: see clear hits in all CP channels if(iSta0==3 && (iYear0>=2014&&iYear0<=2015) && ich%4==3)SwitchChannelOff(ich,"A3 2014 turning off DDA4",11,true); if(iSta0==3 && iYear0>=2018 && Rx[0].LVtx&&Rx[4].LVtx&&Rx[8].LVtx&&Rx[12].LVtx&&nhitsgr00V==2&&nhitsgr00H==2 && ich%4==0)SwitchChannelOff(ich,"A3 2018 turning off DDA4",11,true); if(iSta0==4 && iYear0>=2018 && ich%4==3)SwitchChannelOff(ich,"A4 2018 turning off DDA4",12,true); irxch=iptHitTime2Rx[ich]; iptRx2Hit[irxch]=ich; if(!Rx[irxch].LVtx)continue; // if(abs(Rx[irxch].HitTime)>999){printf("ERRZ: getgrInfo: Rx[%d].HitTime=%g\n",irxch,Rx[irxch].HitTime); continue;} // if(abs(Rx[irxch].SNR)>999)printf("ERRZ: getgrInfo: Rx[%d].SNR=%g\n",irxch,Rx[irxch].SNR); if(false)sprintf(chitSeq,"%ds%03dt%03d_%s",irxch,int(Rx[irxch].SNR),int(Rx[irxch].HitTime),chitSeq); } delete htHit; for(Int_t ich=0; ich<8; ich++){ if(!Rx[ich].LVtx || !Rx[ich+8].LVtx)continue; h2dtHV0tNSig0->Fill(Rx[ich+8].tNSig0-Rx[ich].tNSig0,ich); } if(nSNRcomb>0)SNRxcperCh/=nSNRcomb; TMath::Sort(MCH16,RxPower,iptdum,false); getXCtimesij(gr); getXCtimesTV(gr); fdum=ResidParPairsV(tHitTime); fdum=ResidParPairsH(tHitTime); // NEVT1->Fill(NEVT0->GetEntries()-1,nhitsV,nhitsH); printf("getgrinfo: run/evt=%d/%d dttrig=%g tUs=%g nFitVtx=%d ntp1NSigHit=%d ntNSigHit=%d ntSlopeHit=%d ntExpFitHit=%d nXCgHit=%d\n",irunNumber,ieventNumber,dttrig,unixTimeUs,nFitVtx,ntp1NSigHit, ntNSigHit, ntSlopeHit, ntExpFitHit, nXCgHit); } Float_t getPeakabsVal(TGraph *gr, Int_t &ibnPkValZ) { Float_t peakVal=fabs(gr->GetY()[0]); ibnPkValZ=0; for(Int_t ipt=0; iptGetN(); ipt++){ if(fabs(gr->GetY()[ipt])GetY()[ipt]); ibnPkValZ=ipt; } return peakVal; } inline Float_t fTOTO(TGraph *gr, Float_t fAMax){ Float_t fTOT=0; Float_t AMax=TMath::MaxElement(gr->GetN(),gr->GetY()); Int_t nTOTO=0; for(Int_t ib=0; ibGetN(); ib++) if(fabs(gr->GetY()[ib])>fAMax*AMax)nTOTO++; fTOT=float(nTOTO)/gr->GetN(); if(LDebug)cout<GetN()<<"/"<GetRMS(2)<GetY()[MOFF]); for(Int_t ipt=0; iptGetN(); ipt++){ if(fabs(grVt->GetY()[ipt])>fabs(VMaxCh[ich]))VMaxCh[ich]=grVt->GetY()[ipt]; h2VVCh->Fill(grVt->GetY()[ipt],ich); if(fabs(grVt->GetY()[ipt])>Vrms*MSIGMATOT)TOT0++; if(fabs(grVt->GetY()[ipt])>1028)NSAT++; } return TOT0; } void grCorrAvgMaxVCh(TFile *rifle){ Float_t delt, ACorr; TGraph *grtmp0[MCH], *grtmp, *grtrans; Int_t nev=0; for(Int_t ipol=0; ipol<2; ipol++){ printf("grCorrAvgMaxVCh ipol=%d nEvAvg=%d ichSNRMaxEv=%d\n",ipol,nEvAvg[ipol],ichSNRMaxEv[ipol][0]); if(nEvAvg[ipol]<2)continue; for(Int_t ich=0; ich<16; ich++)grtmp0[ich]=(TGraph*)grEvAvgN[ipol][ich][0]->Clone(); // grtmp3=(TGraph*)grEvAvgN[ipol][ichSNRMaxEv[ipol][0]][0]->Clone(); for(Int_t iev=1; ievClone(); // printf("iev=%d grtmp->GetN=%d grtmp3->GetN=%d\n",iev,grtmp->GetN(),grtmp3->GetN()); delt=dtgr1gr2(grEvAvgN[ipol][ichSNRMaxEv[ipol][0]][0],grEvAvgN[ipol][ichSNRMaxEv[ipol][iev]][0],ACorr,idum); if(LDebug)printf("grEVNZ Summing for iev=%d ACorr=%g delt=%g\n",iev,ACorr,delt); for(Int_t ich=0; ich<16; ich++){ // grtmp=(TGraph*)grEvAvgN[ipol][ich][iev]->Clone(); grtrans=FFTtools::translateGraph(grEvAvgN[ipol][ich][iev],delt); //+delt or -delt??? grtmp=grSum12(grtmp0[ich],grtrans); delete grtmp0[ich], grtrans; grtmp0[ich]=(TGraph*)grtmp->Clone(); delete grtmp; if(ievClone(); grEVNZ[ipol][ich]->SetNameTitle(Form("grEVNZ_nev%d_pol%d_ch%d",nev,ipol,ich),Form("grEVNZ_nev%d_pol%d_ch%d_NEvTot%d",nev,ipol,ich,NEvTot)); grEVNZ[ipol][ich]->SetLineColor(izcolor[ich]); cout<<"Appending grEVNZ ch "<Append(grEVNZ[ipol][ich]); delete grtmp0[ich]; } } } } void FindCWLines(){ TH1F *h1frqV=new TH1F("h1frqV","h1frqV",90,0.1,1.0); TH1F *h1frqH=new TH1F("h1frqH","h1frqH",90,0.1,1.0); for(Int_t ich=0; ich<16; ich++){ if(ich<8)h1frqV->Fill(ffft0[ich]); else h1frqH->Fill(ffft0[ich]); } idum=h1frqV->GetMaximumBin(); nbnCWVPol=int(h1frqV->GetBinContent(idum)); fCWVPol=h1frqV->GetBinCenter(idum); if(idum1>2 && LDebug)printf("ev=%d FindCWLines: Max VPol frq bin=%d frqVal=%g / Entries=%d / ",ieventNumber,idum,fCWVPol,nbnCWVPol); idum=h1frqH->GetMaximumBin(); nbnCWHPol=int(h1frqH->GetBinContent(idum)); fCWHPol=h1frqH->GetBinCenter(idum); if(idum1>2 && LDebug)printf("ev=%d FindCWLines: Max HPol frq bin=%d frqVal=%g / Entries=%d / ",ieventNumber,idum,fCWHPol,nbnCWHPol); delete h1frqV; delete h1frqH; } //{TGraph *grtmp; for(Int_t ich=0; ichGetN(),grtmp->GetY()); phifCWX[ich]=360*grtmp->GetY()[0]/AfCWX[ich];} for(Int_t ich=1; ich15)continue; if(Afft0[ich]Fill(ffft0[ich]); if(fabs(ffft0[ich]-f0WB400MHz)>dfWB400MHz)continue; fitfrq400MHz[nfitfrq400MHz]=ffft0[ich]; nfitfrq400MHz++; } pkCWfft=h1pkCW->GetBinCenter(h1pkCW->GetMaximumBin()); delete h1pkCW; if(nfitfrq400MHz>=2){avg400MHz=TMath::Mean(nfitfrq400MHz,fitfrq400MHz); rms400MHz=TMath::RMS(nfitfrq400MHz,fitfrq400MHz);} for(Int_t ich=0; ichFill((avg400MHz-ffft0[ich])/(0.6*frqbindf[ich]),ich); if(!LFitCWX[ich])continue; // if(fabs(ffft0[ich]-f0WB400MHz)>dfWB400MHz || Afft0[ich]Clone(); //FFTtools::simplePassBandFilter(grVttmp[ich],avg400MHz-0.6*frqbindf[ich],avg400MHz+0.6*frqbindf[ich]); //ffft0[ich]-0.6*frqbindf[ich],ffft0[ich]+0.6*frqbindf[ich]); // fsin400MHz=new TF1("fsin400MHz","[0]*sin([1]*x+[2])"); AfCWX[ich]=1.36*grCWX[ich]->GetRMS(2); fsinCWX->SetParNames(Form("ACW%d",ich),Form("fCW%d",ich),Form("PhaseCW%d",ich)); fsinCWX->FixParameter(0,AfCWX[ich]); fsinCWX->FixParameter(1,TMath::TwoPi()*pkCWfft/1000.); // fsinCWX->SetParLimits(1,0.99*TMath::TwoPi()*pkCWfft/1000.,1.01*TMath::TwoPi()*pkCWfft/1000.); //ω=2πf // fsinCWX->SetParLimits(2,0,TMath::TwoPi()); // fsinCWX->SetParLimits(0,grCWX[ich]->GetRMS(2),2*TMath::MaxElement(grCWX[ich]->GetN(),grCWX[ich]->GetY())); fsinCWX->SetParLimits(2,-TMath::TwoPi(),TMath::TwoPi()); fsinCWX->SetLineColor(izcolor[ich]); grCWX[ich]->Fit("fsinCWX"); fsinCWX->ReleaseParameter(0); grCWX[ich]->Fit("fsinCWX"); fsinCWX->ReleaseParameter(1); grCWX[ich]->Fit("fsinCWX"); PhaseCWX[ich]=fsinCWX->GetParameter(2); dtCWX[ich]=fmod(PhaseCWX[ich]+2*TMath::TwoPi(),TMath::TwoPi())*1000/(TMath::TwoPi()*pkCWfft); //(φ/2π)*(T=1/f) - this is actually time lag b/w two waves //Map2pm180deg(TMath::RadToDeg()*fsinCWX->GetParameter(2)); if(LDebug){TCanvas *c400MHz=new TCanvas("c400MHz","c400MHz"); grCWX[ich]->SetTitle(Form("grCWX_Ch%d_run%d_evt%d",ich,irunNumber,ieventNumber)); grCWX[ich]->GetXaxis()->SetRangeUser(126,130); grCWX[ich]->Draw("al"); c400MHz->SaveAs(Form("/home/dbesson/ctem/png/grCWX_run%d_evt%d_Ch%d.png",irunNumber,ieventNumber,ich)); delete c400MHz;} //x(t)=Acos(ωt); ωt=φ(t), so φ(t)=acos(x(t)/A) // phifCWX[ich]=TMath::RadToDeg()*acos(grCWX[ich]->Eval(128.)/(TMath::MaxElement(grCWX[ich]->GetN(),grCWX[ich]->GetY())-TMath::MinElement(grCWX[ich]->GetN(),grCWX[ich]->GetY()))); frqfCWX[ich]=1000*fsinCWX->GetParameter(1)/TMath::TwoPi(); AfCWX[ich]=fsinCWX->GetParameter(0); ChiSqCWX[ich]=fsinCWX->GetChisquare(); h2f400MHzVCh->Fill(frqfCWX[ich],ich); for(Int_t jch=0; jch0)h2dfrq400MHz->Fill(frqfCWX[jch]-frqfCWX[ich],16*ich+jch); if(fabs(frqfCWX[ich]-frqfCWX[jch])<1){if(LDebug)printf("frqfCWX[%d]=%g / frqfCWX[%d]=%g / %d",ich,frqfCWX[ich],jch,frqfCWX[jch],16*ich+jch);} else LSameFrq400MHz=false; } } for(Int_t ich=0; ich=MAXCWWF)return; for(Int_t ich=0; ichClone(); grCWtmp[ich]->SetLineColor(izcolor[ich]); grCWtmp[ich]->SetNameTitle(Form("gr_nCWEv%d_CWf%d_Ch%d",nCWCh,int(pkCWfft),ich),Form("grCWf%d_run%d_evt%d_Ch%d_Afft%02d",int(pkCWfft),irunNumber,ieventNumber,ich,int(100*Afft0[ich]))); TFileOut->Append(grCWtmp[ich]); } nCWWF++; Int_t iSxS=0; for(Int_t ich=16; ich<19; ich++){ if(!Leqppm(ffft0[ich],pkCWfft))continue; for(Int_t jch=ich+1; jch<20; jch++){ if(!Leqppm(ffft0[jch],pkCWfft))continue; TGraph *grXC=FFTtools::getCorrelationGraph(grVttmp[ich],grVttmp[jch]); fdum=getPeakValZ(grXC,&ipkbin); dphiSxS400MHz[iSxS]=360*(-grXC->GetX()[ipkbin]*avg400MHz/1e3); //dt[ns] / f: [1e6 Hz] if(fabs(dphiSxS400MHz[iSxS])<360){ dphiSxS400MHz[iSxS]=Map2pm180deg(dphiSxS400MHz[iSxS]); printf("grVttmp[%d] X grVttmp[%d] / Corr=%g / dphi=%g\n",ich,jch,fdum,dphiSxS400MHz[iSxS]); } iSxS++; delete grXC; } } // cout<GetN()/(0.5/(grtmp0->GetX()[1]-grtmp0->GetX()[0])); if(idum<2048)idum=2048; if(idum>2048)cout<<"paddingwaveform grtmp0->GetN()="<GetX()[1]-grtmp0->GetX()[0])%g dt for FFT!",grtmp0->GetX()[1]-grtmp0->GetX()[0],dTnsReSample); // TGraph *interpolated_waveform=FFTtools::getInterpolatedGraph(grtmp0,dTnsReSample); //TGraph *padded_waveform = FFTtools::padWaveToLength(interpolated_waveform,idum); // grffttmp[ich]=FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grtmpVtInterpolate[ich]); // delete interpolated_waveform; //delete padded_waveform; // } // else{ //CAUTION! This is true FFT, so maximum is GHz!!!! inline void FillSignalPowerSpectrum(Int_t ich, TGraph *grVt, TGraph *grfft){ Int_t ipkbnVt,ibnVtPk0; TGraph *grtmpVtPk, *grfftPk, *grVt0, *grfft0, *grfftBk; Float_t frqi=0.025; frqi=0.001*Rx[ich].HPF; Float_t frqf=0.925; frqf=0.001*Rx[ich].LPF; if(ich>=16)frqf=0.525; Float_t df0; Float_t dfrqbnd=0.1; // dfrqbnd=(frqf-frqi)/MFRQBIN; // <0.14:0/0.14-0.24:1/0.24-0.34:2/0.84-0.94:8 Int_t nbdtns=int(DTNSMAX/dTnsReSample); Int_t jfrqbnd; Int_t ifrqbnd=-1; grVt0=(TGraph*)grVt->Clone(); ipkbnVt=TMath::LocMax(grVt->GetN(),grVt->GetY())-nbdtns/4; if(ipkbnVt+nbdtnsGetN())ibnVtPk0=ipkbnVt; else if(ipkbnVt+nbdtns/2GetN())ibnVtPk0=ipkbnVt-nbdtns/2; else ibnVtPk0=ipkbnVt-nbdtns; if(ibnVtPk0<0)ibnVtPk0=0; grtmpVtPk=new TGraph(nbdtns,grVt->GetX(),&grVt->GetY()[ibnVtPk0]); for(Int_t ipt=ibnVtPk0; iptSetPoint(ipt,grVt0->GetX()[ipt],0); grfftPk=FFTtools::makePowerSpectrum(grtmpVtPk); grfftBk=(TGraph*)grfft->Clone();//FFTtools::makePowerSpectrum(grVt0); grfft0=(TGraph*)grfft->Clone(); Float_t Rbins=float(grfftPk->GetN())/grfftBk->GetN(); for(Int_t ipt=0; iptGetN(); ipt++){ df0=fabs(grfft0->GetX()[ipt]-f0WB400MHz); if(df0<=dfWB400MHz){ P400MHzWB[ich]+=grfft0->GetY()[ipt]; if(LDebug)printf("Signal grfft0->GetX()[%d]=%g / grfft0->GetX()[%d]=%g\n",ipt,grfft0->GetX()[ipt],ipt,grfft0->GetY()[ipt]); } if(df0>2*dfWB400MHz && df0<5*dfWB400MHz){ P400MHzWBSB[ich]+=grfft0->GetY()[ipt]; // else P400MHzWB[ich]-=grfft0->GetY()[ipt]; if(LDebug)printf("SB grfft0->GetX()[%d]=%g / grfft0->GetX()[%d]=%g\n",ipt,grfft0->GetX()[ipt],ipt,grfft0->GetY()[ipt]); } ifrqbnd=(grfft0->GetX()[ipt]-frqi)/dfrqbnd; if(ifrqbnd<0)ifrqbnd=0; if(ifrqbnd>=MFRQBIN)ifrqbnd=MFRQBIN-1; // for(jfrqbnd=0; jfrqbndGetX()[ipt]MFRQBIN-1){printf("ERRZ: ifrqbnd OOB=%d\n",ifrqbnd); ifrqbnd=MFRQBIN-1;} PowerFrqBnd0[ich][ifrqbnd]+=grfft0->GetY()[ipt]; if(LUB)PowerFrqBndUB[ich][ifrqbnd]=PowerFrqBnd0[ich][ifrqbnd]; PowerFrqBndBk[ich][ifrqbnd]+=grfftBk->GetY()[ipt]*Rbins; // cout<GetN(); ipt++){ ifrqbnd=(grfftPk->GetX()[ipt]-frqi)/dfrqbnd; if(ifrqbnd<0)ifrqbnd=0; if(ifrqbnd>4)ifrqbnd=4; PowerFrqBndSignal[ich][ifrqbnd]+=grfftPk->GetY()[ipt]; } // if(LUB&&LDebug)printf("PowerFrqBndUB[0][0]=%g\n",PowerFrqBndUB[0][0]); delete grfft0; delete grVt0; delete grtmpVtPk; delete grfftPk; delete grfftBk; } inline TGraph *gr00(TGraph *gr0, TGraph *grfft00, Int_t ich, Float_t f0MHz, Float_t f1MHz, Bool_t LFilter, Bool_t LFilterSurf){ const Float_t SpiceCoreCWMinMHz=80; const Float_t SpiceCoreCWMaxGHz=520; Int_t ibnPgr00Ch=0; Int_t ibnfftMHz; Float_t tgr00=NNN; Int_t nbins0=gr0->GetN(); TGraph *grfft0=(TGraph*)grfft00->Clone(); TGraph *grfftWt=new TGraph(grfft00->GetN()); TGraph *grtmp, *grF; Float_t ff0MHzBinWid; if(LDebug)cout<<"f0MHz="<GetX()=%g\n",ibnfftMHz,grfft0->GetX()[ib]); if(ibnfftMHz>MBNPGR00)ibnfftMHz=MBNPGR00; if(ibnfftMHz<0)ibnfftMHz=0; Pgr00[ibnfftMHz]+=grfft0->GetY()[ib]; for(ibnPgr00Ch=0; ibnPgr00Chgrfft0->GetX()[ib])break; ff0MHzBinWid=(ff0GR00[ibnPgr00Ch+1]-ff0GR00[ibnPgr00Ch]); Pgr00Ch[ich][ibnPgr00Ch]+=grfft0->GetY()[ib]/ff0MHzBinWid; if(LDebug)printf("ibnfftMHz=%d\n",ibnfftMHz); if(!LFilter)continue; if(grfft0->GetX()[ib]GetX()[ib]>f1MHz)grfft0->SetPoint(ib,grfft0->GetX()[ib],0); } */ if(LDebug)printf("Pgr00[0]=%g Pgr00[1]=%g Pgr00[2]=%g\n",Pgr00[0],Pgr00[1],Pgr00[2]); h2timebaseVCh->Fill(gr0->GetX()[1]-gr0->GetX()[0],ich); h2NSampleVCh->Fill(gr0->GetN(),ich); h2BufferLenVCh->Fill(gr0->GetX()[gr0->GetN()-1]-gr0->GetX()[0],ich); if(gr0->GetX()[gr0->GetN()-1]-gr0->GetX()[0]GetX()[gr0->GetN()-1]-gr0->GetX()[0]; VAvgCh[ich]=gr0->GetMean(2); // cout<GetN(),grtmp->GetY())<GetN(); ib++)fIntPwr0+=grfft0->GetY()[ib]; //FFTtools::sumPower(grfft0,0,grfft0->GetN()-1); Float_t fAvgPwr=fIntPwr0/grfft0->GetN(); //2*(FFTtools::sumPower(grfft0,grfft0->GetN()/2,grfft0->GetN()-1)/grfft0->GetN())/grfft0->GetX()[grfft0->GetN()/2]; //clever trick to weight by shape of FFT Float_t threshRjct=128*fAvgPwr; if(iSta0==4&&ich%4==3)threshRjct/=4; Float_t Rpk2bkRjct=32; if(iSta0==4&&ich%4==3)Rpk2bkRjct/=2; //2*Avg Float_t delx=(grfft0->GetX()[grfft0->GetN()-1]-grfft0->GetX()[0])/grfft0->GetN(); // if(iSta0==4&&ich%4==3)delx*=4; Float_t fPwrRjct=0; Int_t nfrqreject=0; Double_t frqmin[MFRQRJCT], frqmax[MFRQRJCT]; if(LFilter){ nfrqreject=0; // frqmin[0]=0.402-0.008; frqmax[0]=0.402+0.008; nfrqreject=1; // if(ich==19&&iSta0==1)grF=FFTtools::simpleNotchFilter(gr0,198,202); //200 MHz peak in ch. 19 for A1/A2/A3 // if(ich==18&&iSta0==1)grF=FFTtools::simpleNotchFilter(gr0,98,116); //200 MHz peak in ch. 19 for A1/A2/A3 // else grF=(TGraph*)gr0->Clone(); for(Int_t ib=0; ibGetN()-1; ib++){ if(grfft0->GetX()[ib]GetX()[ib]>f1MHz||fabs(grfft0->GetX()[ib]-404)<4)continue; if(nfrqreject>=MFRQRJCT)continue; Float_t fPWR=grfft0->GetY()[ib]/grfft0->GetN(); Float_t Rpk2SB=grfft0->GetY()[ib]/(grfft0->GetY()[ib-1]+grfft0->GetY()[ib+1]); if(fPWR>threshRjct||Rpk2SB>Rpk2bkRjct){ fPwrRjct+=grfft0->GetY()[ib]; frqmin[nfrqreject]=grfft0->GetX()[ib]-delx; frqmax[nfrqreject]=grfft0->GetX()[ib+1]+delx; if(LDebug||(iSta0==4&&ich%4==3))printf("Ch %d: Nbins=%d grfilterCWlines rejecting line %d from %g->%g with fPwr=%g/thresh=%g .and. pk2bk=%g/thrsh=%g\n",ich,grfft0->GetN(),nfrqreject,frqmin[nfrqreject],frqmax[nfrqreject],fPWR,threshRjct,Rpk2SB,Rpk2bkRjct); h2frqRejectVCh->Fill(grfft0->GetX()[ib],ich); nfrqreject++; } else h2fftVCh->Fill(grfft0->GetX()[ib],ich,grfft0->GetY()[ib]); } // if(iSta0==4&&ich%4==3){grF=FFTtools::simplePassBandFilter(gr0,120,360);} //take out sharp edges // else grF=FFTtools::simplePassBandFilter(gr0,f0MHz,f1MHz); if(nfrqreject>0 && ((ich>=16&&LFilterSurf)||(iSta0==4&&ich%4==3)))grtmp=FFTtools::multipleSimpleNotchFilters(grF,nfrqreject,frqmin,frqmax); else grtmp=(TGraph*)grF->Clone(); delete grF; fdum=(grtmp->Eval(128.5)-grtmp->Eval(127.5))/fabs(grtmp->Eval(128.5)-grtmp->Eval(127.5)); phifft0[ich]=fdum*acos(2*grtmp->Eval(128.)/(TMath::MaxElement(grtmp->GetN(),grtmp->GetY())-TMath::MinElement(grtmp->GetN(),grtmp->GetY()))); //evaluate at 128 ns as reference TGraph *grfft1=FFTtools::makePowerSpectrum(grtmp); PFiltered[ich]=FFTtools::sumPower(grfft1,0,grfft1->GetN()-1); if(LDebug||LPrintDbg)printf("grFilter Ch %d: total of %d lines rejected / fIntPwr1=%g frcPwrRemain=%g\n",ich,nfrqreject,PFiltered[ich],PFiltered[ich]/fIntPwr0); h2Pin2PoutVCh->Fill(PFiltered[ich]/fIntPwr0,ich); if(ich>=16&&!LCP)for(Int_t ib=0; ibGetN(); ib++){ h3PfftVfGalacDay[ich-ichSurf0]->Fill(1000*grfft1->GetX()[ib],fGalacticDay,log10(grfft1->GetN()*grfft1->GetY()[ib])); h1frqIVCh[ich-ichSurf0]->Fill(1000*grfft1->GetX()[ib],grfft1->GetY()[ib]); } delete grfft1; } else grtmp=(TGraph*)gr0->Clone(); for(Int_t ib=0; ibGetN(); ib++) if(!LCP&&fabs(grtmp->GetY()[ib])/Rx[ich].Vrms<4.8)RxRawPower[ich]+=grtmp->GetY()[ib]*grtmp->GetY()[ib]; // h2nfrqRejectVCh->Fill(nfrqreject,ich); // TGraph *grtmp0=(TGraph*)grtmp->Clone(); // grtmp0->GetXaxis()->SetRangeUser(150,800); grfft0->Fit("pol1","Q"," ",150,800); SpxA0[ich]=grfft0->GetFunction("pol1")->GetParameter(0); SpxSlope[ich]=grfft0->GetFunction("pol1")->GetParameter(1); // delete grtmpfft; // delete grtmp0; // grtmp=grxShift(grtmp0,dtCD[iStation0][ich/4]); // delete grtmp0; if(LUB){ h1VrmsUB[ich]->Fill(grtmp->GetRMS(2)); Rx[ich].VrmsUB=h1VrmsUB[ich]->GetMean(); VrmsUB[ich]=grtmp->GetRMS(2); } // Rx[ich].ibnVMax=FFTtools::getPeakBin(grtmp); // Rx[ich].VMax=grtmp->GetY()[Rx[ich].ibnVMax]; //getPeakValZ(grSPE,Rx[ich].ibnVMax); Rx[ich].VMax=getPeakabsVal(grtmp,Rx[ich].ibnVMax); VMaxHit[ich]=TMath::MaxElement(grtmp->GetN(),grtmp->GetY()); VMinHit[ich]=TMath::MinElement(grtmp->GetN(),grtmp->GetY()); h2VMax00VCh->Fill(VMaxHit[ich],ich); Rx[ich].Power=0; for(Int_t ib=0; ibGetN(); ib++) if(!LUB||fabs(grtmp->GetY()[ib])/Rx[ich].Vrms<4)Rx[ich].Power+=grtmp->GetY()[ib]*grtmp->GetY()[ib]; Rx[ich].Power/=grtmp->GetN(); RxPower[ich]=Rx[ich].Power; // Rx[ich].tVMax=grtmp->GetX()[Rx[ich].ibnVMax]; idum=TMath::LocMax(grtmp->GetN(),grtmp->GetY()); tVMax[ich]=grtmp->GetX()[idum]; Rx[ich].tVMax=tVMax[ich]; idum1=TMath::LocMin(grtmp->GetN(),grtmp->GetY()); Rx[ich].ibnVMax=idum; if(fabs(VMinHit[ich])>VMaxHit[ich])Rx[ich].ibnVMax=idum1; tVMin[ich]=grtmp->GetX()[idum1]; tVMaxXCableDelay[ich]=tVMax[ich]+Rx[ich].cableDelayNs; tVMinXCableDelay[ich]=tVMin[ich]+Rx[ich].cableDelayNs; Rx[ich].tNSig00=gettNSigV(grtmp,ich,0,Rx[ich].Vrms00); if(LDebug)printf("Rx[%d].tVMax=%g Vrms00=%g tNSig00=%g\n",ich,Rx[ich].tVMax,Rx[ich].Vrms00,Rx[ich].tNSig00); Rx[ich].HitTime=Rx[ich].tVMax; //Rx[ich].tNSig00; tHitTime[ich]=Rx[ich].HitTime; // if(iStation0==2 && ich==6)Rx[ich].HitTime+=dtCH6A2ns; Rx[ich].TOT=TOT(grtmp,Rx[ich].nSatSample,ich); if(Rx[ich].TOT>TOTMax)TOTMax=Rx[ich].TOT; TOTSum+=Rx[ich].TOT; nSATSamples[ich]=Rx[ich].nSatSample; if(Rx[ich].iPol==0)nSATSumV+=Rx[ich].nSatSample; else nSATSumH+=Rx[ich].nSatSample; if(NSamples[ich]>4)TOTCh[ich]=Rx[ich].TOT/(NSamples[ich]+0.1); else TOTCh[ich]=0; Rx[ich].LVtx=false; Rx[ich].Vrms00MBN=rmsMinMBN(grtmp,h1Vrms00MBN[ich]); Vrms00MBN[ich]=Rx[ich].Vrms00MBN; h1Vrms00MBN1ev[ich]->Fill(Rx[ich].Vrms00MBN); if(LThermalEv)for(Int_t ib=grtmp->GetN()/2-32; ibGetN()/2+32; ib++)h2VdistVCh->Fill(ich,grtmp->GetY()[ib]); Rx[ich].h1Vrms00=GetxMax(h1Vrms00MBN[ich]); Rx[ich].Vrms00=TMath::Max(Rx[ich].Vrms00MBN,Rx[ich].h1Vrms00); Rx[ich].Vrms=Rx[ich].Vrms00; VrmsCh[ich]=Rx[ich].Vrms00; h2Vrms00VCh->Fill(Rx[ich].Vrms00,ich); h2VrmsVfGalacDay->Fill(fGalacticDay,ich,Rx[ich].Vrms); SNRgr00=Rx[ich].VMax/Rx[ich].Vrms00; RxSNR[ich]=fabs(Rx[ich].VMax)/Rx[ich].Vrms; h2SNRVCh00->Fill(SNRgr00,ich); if(LCP)h2SNRVCh00CP->Fill(ich,SNRgr00); if(LDebug&&Rx[ich].VMax>VMAXMAX)printf("Rx[%d].VMax=%g>%d\n",ich,Rx[ich].VMax,VMAXMAX); if(LDebug)printf("SNRgr00=%g VMax[%d]=%g/Vrms[%d]=%g/Vrms00=%g\n",SNRgr00,ich,Rx[ich].VMax,ich,Rx[ich].Vrms,Rx[ich].Vrms00); if(SNRgr00>MSIGMAGR00 && Rx[ich].VMaxSNRMax){SNRMax=SNRgr00; ichSNRMax=ich;} SNRgr00Min=TMath::Min(SNRgr00,SNRgr00Min); Rx[ich].tVMax00=Rx[ich].tVMax; Rx[ich].LVtx=true; iuseChgr00[ich]=Rx[ich].LVtx; h2tVMax00VCh->Fill(tVMax[ich],ich); h2tNSig00VCh->Fill(Rx[ich].tNSig00,ich); nHitsRx00[ich]++; if(LDebug)printf("Rx[%d].LVtx=%d\n",ich,Rx[ich].LVtx); if(Rx[ich].iPol==0)nhitsgr00V++; else if(Rx[ich].iPol==1)nhitsgr00H++; else nhitsgr00S++; // TOTSum+=TOT(gr0,Rx[ich].nSatSample); if(tgr00>Rx[ich].tVMax){ ich0gr00=ich; tgr00=Rx[ich].tVMax; } } if(Rx[ich].Power>PMax1Ch)PMax1Ch=Rx[ich].Power; if(Rx[ich].iPol==0){ nrxV++; VPolPower+=Rx[ich].Power; WfPV+=Rx[ich].Power/(Rx[ich].Vrms00*Rx[ich].Vrms00); } if(Rx[ich].iPol==1){ nrxH++; HPolPower+=Rx[ich].Power; WfPH+=Rx[ich].Power/(Rx[ich].Vrms00*Rx[ich].Vrms00); } if(Rx[ich].iPol==2)WfPS+=Rx[ich].Power; Int_t ibnHPFMHz=grfft0->GetXaxis()->FindBin(Rx[ich].HPF); Int_t ibnLPFMHz=grfft0->GetXaxis()->FindBin(Rx[ich].LPF); TGraph *grfftHPFLPF=new TGraph(ibnLPFMHz-ibnHPFMHz,&grfft0->GetX()[ibnHPFMHz],&grfft0->GetY()[ibnHPFMHz]); // Rx[ich].AfftMax=TMath::MaxElement(grfft0->GetN()-ibnHPFMHz,&grfft0->GetY()[ibnHPFMHz]); idum=TMath::LocMax(grfft0->GetN()-ibnHPFMHz-1,&grfft0->GetY()[ibnHPFMHz]); Rx[ich].AfftMax=TMath::MaxElement(grfftHPFLPF->GetN(),grfftHPFLPF->GetY()); idum=TMath::LocMax(grfftHPFLPF->GetN(),grfftHPFLPF->GetY()); if(Rx[ich].AfftMax!=grfftHPFLPF->GetY()[idum])printf("ERRZ: gr00: Rx[%d].MaxElement != GetMaxZ\n",ich); Rx[ich].AfftMax=grfftHPFLPF->GetY()[idum]; Rx[ich].ffftMax=grfftHPFLPF->GetX()[idum]; if(idum>1&&idumGetN()-2) Rx[ich].ffftMax= (grfftHPFLPF->GetX()[idum-2]*grfftHPFLPF->GetY()[idum-2]+grfftHPFLPF->GetX()[idum-1]*grfftHPFLPF->GetY()[idum-1]+grfftHPFLPF->GetX()[idum]*grfftHPFLPF->GetY()[idum]+grfftHPFLPF->GetX()[idum+1]*grfftHPFLPF->GetY()[idum+1]+grfftHPFLPF->GetX()[idum+2]*grfftHPFLPF->GetY()[idum+2])/(grfftHPFLPF->GetY()[idum-2]+grfftHPFLPF->GetY()[idum-1]+grfftHPFLPF->GetY()[idum]+grfftHPFLPF->GetY()[idum+1]+grfftHPFLPF->GetY()[idum+2]); // grfftHPFLPF->Print("all"); cout<GetY()[idum]<GetN()-1); ffftWt[ich]=-1; AfftWt[ich]=-1; for(Int_t ib=ibnHPFMHz; ibGetY()[ib]GetX()[ib]; AfftWt[ich]=grfftWt->GetY()[ib]; } if(LDebug){grfft0->Print("all"); grfftWt->Print("all"); cout<4096||VMinHit[ich]<-4096)nRxADCOOB++; if(LDebug)printf("Rx[%d].AfftMax=%g /Integral=%g // .fftMax=%g \n",ich,Rx[ich].AfftMax,Rx[ich].AfftMax/grfftHPFLPF->Integral(),Rx[ich].ffftMax); if(Afft0[ich]>FRQFRACFILTERMIN)h2frqMaxXThreshVCh->Fill(Rx[ich].ffftMax,ich); nbinsVtgr[ich]=gr0->GetN(); if(nbins0!=nbinsVtgr[ich])printf("ERRZ: gr00: nbins0=%d / nbinsVtgr[%d]=%d!!\n",nbins0,ich,nbinsVtgr[ich]); // grfftHPFLPF->GetXaxis()->SetRangeUser(-1,1000.); delete grfft0; delete grfftWt; delete grfftHPFLPF; return grtmp; } inline void getVHPower(TGraph **gr){ VgrPow=0; HgrPow=0; Int_t nrxVPow=0; Int_t nrxHPow=0; for(Int_t ich=0; ichGetY()); // } inline Float_t rmsif(TGraph *gr, Int_t ibni, Int_t ibnf){ TGraph *grtmp=new TGraph(ibnf-ibni,gr->GetX(),&gr->GetY()[ibni]); return grtmp->GetRMS(2); } TGraph *grCut(TGraph *gr, Float_t xmin, Float_t xmax){ Float_t dx=gr->GetX()[1]-gr->GetX()[0]; Int_t ibinxmin=xmin/dx-gr->GetX()[0]/dx; Int_t ibinxmax=xmax/dx-gr->GetX()[0]/dx; Int_t nb0=gr->GetN()-1; if(ibinxmax>gr->GetN())ibinxmax=gr->GetN(); //TMath::Min(int(xmax/dx),gr->GetN()); TGraph *grtmp=new TGraph(ibinxmax-ibinxmin,&gr->GetX()[ibinxmin],&gr->GetY()[ibinxmin]); return grtmp; } TGraph *grPEcutVt(TGraph *gr, Float_t xmin, Float_t xmax){ TGraph *grtmp=grCut(gr,xmin,xmax); TGraph *grPE=FFTtools::getSimplePowerEnvelopeGraph(grtmp); delete grtmp; grPE->SetLineColor(kPink); return grPE; } TGraph *grHEcutVt(TGraph *gr, Float_t xmin, Float_t xmax){ TGraph *grtmp=grCut(gr,xmin,xmax); TGraph *grHE=FFTtools::getHilbertEnvelope(grtmp); delete grtmp; grHE->SetLineColor(kPink); return grHE; } void getgrLimits(TGraph *gr, Float_t xmin, Float_t xmax, Float_t &yneg, Float_t &ypos){ ypos=TMath::MaxElement(gr->GetN(),gr->GetY()); yneg=TMath::MinElement(gr->GetN(),gr->GetY()); Float_t dx=gr->GetX()[1]-gr->GetX()[0]; Int_t ibinxmin=xmin/dx-gr->GetX()[0]/dx; Int_t ibinxmax=xmax/dx-gr->GetX()[0]/dx; Int_t nb0=gr->GetN()-1; if(ibinxmax>gr->GetN())ibinxmax=gr->GetN(); //TMath::Min(int(xmax/dx),gr->GetN()); if(ibinxmax-ibinxmin>0){ yneg=TMath::MinElement(ibinxmax-ibinxmin,&gr->GetY()[ibinxmin]); ypos=TMath::MaxElement(ibinxmax-ibinxmin,&gr->GetY()[ibinxmin]); } if(xmin>gr->GetY()[nb0] || xmaxGetY()[0]){ yneg=TMath::MinElement(nb0/2-1,&gr->GetY()[nb0/2]); ypos=TMath::MaxElement(nb0/2-1,&gr->GetY()[nb0/2]); } printf("ibinxmin=%d nb0=%d x0=%g ibinxmax=%d dx=%g ypos=%g yneg=%g\n",ibinxmin,nb0,gr->GetX()[0],ibinxmax,dx,ypos,yneg); } //http://stackoverflow.com/questions/26087106/refraction-in-raytracing for recursive ray-tracing inline void ARHV(Float_t cosI, Float_t n1, Float_t n2, Float_t &rn, Float_t &rt){ Float_t n = n1/n2; Float_t sinT2 = n*n * (1.0 - cosI * cosI); if(sinT2>1){ rn=1.1; rt=1.1; return; } Float_t cosT = sqrt(1.0 - sinT2); //fresnel equations rn = (n1 * cosI - n2 * cosT)/(n1 * cosI + n2 * cosT); rt = (n2 * cosI - n1 * cosT)/(n2 * cosI + n1 * cosT); //changed from +n2*cosT! return; } inline Float_t AReflH(Float_t thetai, Float_t n1, Float_t n2){ //n1*sin(thetai)=n2*sin(thetat); if(fabs(n1*sin(thetai)/n2)>1)return 1.1; //past TIR Float_t thetat=asin(n1*sin(thetai)/n2); Float_t AReflPar=(n2*cos(thetai)-n1*cos(thetat))/(n2*cos(thetai)+n1*cos(thetat)); //https://en.wikipedia.org/wiki/Fresnel_equations return AReflPar; } inline Float_t rpar(Float_t thetai, Float_t n1, Float_t n2){ //n1*sin(thetai)=n2*sin(thetat); if(fabs(n1*sin(thetai)/n2)>1)return 1.1; //past TIR Float_t thetat=asin(n1*sin(thetai)/n2); return tan(thetai-thetat)/tan(thetai+thetat); //http://hyperphysics.phy-astr.gsu.edu/hbase/phyopt/freseq.html } inline Float_t rperp(Float_t thetai, Float_t n1, Float_t n2){ //n1*sin(thetai)=n2*sin(thetat); if(fabs(n1*sin(thetai)/n2)>1)return 1.1; //past TIR Float_t thetat=asin(n1*sin(thetai)/n2); return -sin(thetai-thetat)/sin(thetai+thetat); } inline Float_t AReflV(Float_t thetai, Float_t n1, Float_t n2){ if(fabs(n1*sin(thetai)/n2)>1)return 1.1; //past TIR Float_t thetat=asin(n1*sin(thetai)/n2); Float_t AReflPerp=(n1*cos(thetai)-n2*cos(thetat))/(n1*cos(thetai)+n2*cos(thetat)); //https://en.wikipedia.org/wiki/Fresnel_equations return AReflPerp; } //Note that to get falling edge, use (1-Erf(x)) inline void FitErf(TGraph *gr, Float_t xmin, Float_t xmax, Float_t Ai, Float_t xXi, Float_t yBaselinei){ TF1 *ferf=new TF1("erf1","[0]*TMath::Erf(x-[1])+[2]",xmin,xmax); ferf->SetParName(0,"AStep"); ferf->SetParName(1,"xX"); ferf->SetParName(2,"yOff"); ferf->SetParLimits(0,0,1e9); ferf->SetParLimits(2,0,1e9); Int_t nbmax=gr->GetN()-1; ferf->SetParLimits(1,gr->GetX()[0],gr->GetX()[nbmax]); ferf->SetParameter(0,Ai-yBaselinei); ferf->FixParameter(1,xXi); // ferf->FixParameter(1); ferf->FixParameter(2,Ai+yBaselinei); // ferf->FixParameter(2); gr->Fit(ferf,"R"); ferf->ReleaseParameter(2); gr->Fit(ferf,"R"); fdum=ferf->GetParameter(0); ferf->FixParameter(0,fdum); // ferf->FixParameter(0); fdum=ferf->GetParameter(2); ferf->FixParameter(2,fdum); // ferf->FixParameter(2); ferf->ReleaseParameter(1); gr->Fit(ferf,"R"); delete ferf; // gr->Draw(); } // RXTOTMAXPERDOF=SetXCut(NCP,0.99,RXTOTMAXPERDOF,"RxTOT"); //If fracIntCut=0.99 => find cut such that 99% of area BELOW that cut //fracInt=0.01 => 99% of area ABOVE that cut Float_t SetXCut(TNtuple *N, Float_t fracIntCut, Float_t OldCut, string svarname){ const Int_t MQ=100; const Int_t MQQ=MQ*10; Int_t ibm, ibm1; Double_t yq[MQ]; Double_t xq[MQ]; if(N->GetEntries()==0) return OldCut; Float_t fmaxVNtuple=N->GetMaximum(svarname.c_str()); Float_t fminVNtuple=N->GetMinimum(svarname.c_str()); Float_t dmaxmin=fmaxVNtuple-fminVNtuple; if(TMath::IsNaN(fmaxVNtuple)||TMath::IsNaN(fminVNtuple))printf("fmaxVNtuple=%g / fminVNtuple=%g\n",fmaxVNtuple,fminVNtuple); sprintf(cProj,"htempZ(%d,%f,%f)",MQQ,fminVNtuple-0.001*dmaxmin,fmaxVNtuple+0.001*dmaxmin); N->Project(cProj,svarname.c_str(),Form("fabs(%s)<999",svarname.c_str())); TH1F *htempZ=(TH1F*)gDirectory->Get("htempZ"); for(Int_t i=0; iGetQuantiles(MQ,yq,xq); for(Int_t i=0; iGetQuantiles(MQ,yq,xq); TGraph *grtempq=new TGraph(htempZ); Double_t *ytempq=grtempq->GetY(); Double_t *xtempq=grtempq->GetX(); Int_t nbinstempq=grtempq->GetN(); Double_t *yInt=htempZ->GetIntegral(); TH1F *hgrItempq=new TH1F("hgrItempq","hgrItempq",MQQ,xtempq[0],xtempq[MQQ-1]); hgrItempq->FillN(nbinstempq,xtempq,yInt); ibm=hgrItempq->FindFirstBinAbove(fracIntCut); Int_t ibq=0; while(ibqfracIntCut)break; ibq++; } Float_t NewCut=xtempq[ibm]; delete grtempq; // delete grItempq; delete hgrItempq; printf("\nSetting %s for %g entries/mean=%g/rms=%g/ OldCut=%g / NewCut=%g Q01=%g Q99=%g yInt[%d]=%g\n",svarname.c_str(),htempZ->GetEntries(),htempZ->GetMean(),htempZ->GetRMS(),OldCut,NewCut,yq[1],yq[99],ibm1,xtempq[ibm1]); delete htempZ; return xtempq[ibm]; // Float_t fracInt=0; // if(fracIntCut<0.5){ // for(Int_t ibq=0; ibqfracIntCut){ // ibm=ibq; // ibq=nbinstempq; // } // } // } // else{ // for(Int_t ibq=nbinstempq-1; ibq>=0; ibq--){ // fracInt+=ytempq[ibq]/totInt; // if(fracIntGaus(0,Vchrms); Float_t noise_Re=gRandom->Gaus(0,Vchrms); Float_t noise_phase=atan2(noise_Im,noise_Re); Float_t noise_mag=sqrt(noise_Im*noise_Im+noise_Re*noise_Re); return noise_mag*cos(noise_phase); } Float_t DampExpPlusNoise(Double_t *x, Double_t *par){ const Float_t VkT=50; // if(x[0]TFirstNSig+32){TF1::RejectPoint(); return 0;} //A*exp((x-t0)/tau)*cos(omega*(x-t0)+phi) Float_t noise_Im=gRandom->Gaus(0,VkT/sqrt(2.)); Float_t noise_Re=gRandom->Gaus(0,VkT/sqrt(2.)); Float_t noise_phase=atan2(noise_Im,noise_Re); Float_t noise_mag=sqrt(noise_Im*noise_Im+noise_Re*noise_Re); if(x[0]VMAXMV) return noise_mag*cos(noise_phase); else return par[0]*exp(-(x[0]-par[1])/par[2])*cos(par[3]*(x[0]-par[1])+par[4])+noise_mag*cos(noise_phase); } Double_t DampExp(Double_t *x, Double_t *par){ // if(x[0]TFirstNSig+2*SigNanoSec){TF1::RejectPoint(); return 0;} //A*exp((x-t0)/tau)*cos(omega*(x-t0)+phi) if(fabs(par[0])Clone(); for(Int_t ib=0; ibGetN(); ib++){ if(grtemp->GetX()[ib]>xmin && grtemp->GetX()[ib]SetPoint(ib,grtemp->GetX()[ib],0); if(grtemp->GetX()[ib]>xmax)break; } return grtemp; } //Float_t x01, Float_t wid0, Float_t x02, Float_t dxmin, Float_t dxmax, inline void grDoubleGausFitVt(TGraph *gr, Float_t dxVMax,Float_t &x01, Float_t &x02, Float_t &A01, Float_t &A02, Float_t &PSum1, Float_t &PSum2, Float_t &A1, Float_t &x1, Float_t &wid1, Float_t &A2, Float_t &x2, Float_t &wid2, Float_t &tVXpos1, Float_t &tVXpos2, char ctext[256]){ TGraph *grPE1=FFTtools::getSimplePowerEnvelopeGraph(gr); Int_t ibinMax1=TMath::LocMax(grPE1->GetN(),grPE1->GetY()); Float_t x0a, A0a, x0b, A0b; x0a=grPE1->GetX()[ibinMax1]; A0a=grPE1->GetY()[ibinMax1]; tVXpos1=tVXpos(grPE1,20,grPE1->GetN()/2,1000); tVXpos2=tVXpos(grPE1,grPE1->GetN()/2,grPE1->GetN(),1000); grPE1->GetXaxis()->SetRangeUser(x0a-dxVMax,x0a+dxVMax); TF1 *fg1=new TF1("fg1","gaus",x0a-dxVMax,x0a+dxVMax); //"[0]*exp(-0.5*((x-[1])/[2])**2)" fg1->SetParameter(1,x0a); fg1->SetParameter(2,24); fg1->SetParLimits(0,0,1e9); fg1->SetParLimits(1,x0a-dxVMax,x0a+dxVMax); fg1->SetParLimits(2,4,48); fg1->SetLineColor(kRed); grPE1->Fit("fg1","BRMQ"); //"B": obey ParLiimites / R: Range Q: Quiet M: Improve errors grPE1->Fit("gaus","Q"); //," "," ",x0a-dxVMax,x0a+dxVMax); TF1 *g1=grPE1->GetFunction("gaus"); g1->SetLineColor(kPink); grPE1->GetXaxis()->SetRange(0,0); TGraph *grPE2=grZeroX(grPE1,x0a-dxVMax,x0a+dxVMax); // grPE1->Print("all"); grPE2->Print("all"); Int_t ibinMax2=TMath::LocMax(grPE2->GetN(),grPE2->GetY()); x0b=grPE2->GetX()[ibinMax2]; A0b=grPE2->GetY()[ibinMax2]; TF1 *fg2=new TF1("fg2","gaus",x0b-dxVMax,x0b+dxVMax); fg2->SetParameter(1,x0b); fg2->SetParameter(2,24); fg2->SetParLimits(0,0,1e9); fg2->SetParLimits(1,x0b-dxVMax,x0b+dxVMax); fg2->SetParLimits(2,4,48); grPE2->GetXaxis()->SetRangeUser(x0b-dxVMax,x0b+dxVMax); fg2->SetLineColor(kBlue); grPE2->Fit("fg2","BRMQ"); grPE2->Fit("gaus","Q"); TF1 *g2=grPE2->GetFunction("gaus"); g2->SetLineColor(kCyan); printf("grPE1: Afg1=%g/Ag1=%g x0a=%g xfg1=%g/xg1=%g widfg1=%g/widg1=%g\n",fg1->GetParameter(0),g1->GetParameter(0),x0a,fg1->GetParameter(1),g1->GetParameter(1),fg1->GetParameter(2),g1->GetParameter(2)); printf("grPE2: Afg2=%g/Ag2=%g x0b=%g xfg2=%g/xg2=%g widfg2=%g/widg2=%g\n",fg2->GetParameter(0),g2->GetParameter(0),x0b,fg2->GetParameter(1),g2->GetParameter(1),fg2->GetParameter(2),g2->GetParameter(2)); if(x0aGetParameter(0); x1=fg1->GetParameter(1); wid1=fg1->GetParameter(2); A2=fg2->GetParameter(0); x2=fg2->GetParameter(1); wid2=fg2->GetParameter(2); PSum1=FFTtools::sumPower(grPE1,ibinMax1,ibinMax1+dxVMax); PSum2=FFTtools::sumPower(grPE2,ibinMax2,ibinMax2+dxVMax); } else{ x01=x0b; x02=x0a; A01=A0b; A02=A0a; A1=fg2->GetParameter(0); x1=fg2->GetParameter(1); wid1=fg2->GetParameter(2); A2=fg1->GetParameter(0); x2=fg1->GetParameter(1); wid2=fg1->GetParameter(2); PSum2=FFTtools::sumPower(grPE1,ibinMax1,ibinMax1+dxVMax); PSum1=FFTtools::sumPower(grPE2,ibinMax2,ibinMax2+dxVMax); } TCanvas *c1=new TCanvas("c1","c1"); if(strlen(ctext)!=0){ sprintf(cpngname,"$HOME/ctem/png/%s.png",ctext); grPE1->Draw("al"); grPE2->Draw("lsame"); c1->SaveAs(cpngname); sprintf(cpngname,"$HOME/ctem/png/%s.png",ctext); c1->SaveAs(cpngname); } delete grPE1; delete grPE2; delete fg1; delete fg2; delete c1; return; } inline Float_t corrThe(Float_t rxyTx, Float_t zTx){ Float_t rxyz=sqrt(zTx*zTx+rxyTx*rxyTx); return (rxyz*rxyz)/(rxyTx*rxyTx); } //V1 near; V2 far: //V2/V1=(r1/r2)*exp(-(r2-r1)/L)=(r1/r2)*exp(r1-r2)/L) => log(r2V2/r1V1)=(r1-r2)/L => L=(r1-r2)/log(r2V2/r1V1) inline Float_t VLatten(Float_t V1, Float_t V2, Float_t rxy1, Float_t rxy2, Float_t zTx0){ Float_t V1corr=V1*corrThe(rxy1,zTx0); Float_t V2corr=V2*corrThe(rxy2,zTx0); Float_t rxyz1=sqrt(zTx0*zTx0+rxy1*rxy1); Float_t rxyz2=sqrt(zTx0*zTx0+rxy2*rxy2); Float_t xlog=log((rxyz2*V2corr)/(rxyz1*V1corr)); // cout<0)printf("V1=%g V2=%g rxy1=%g rxy2=%g zTx0=%g V1corr=%g V2corr=%g rxyz1=%g rxyz2=%g xlog=%g Latten=%g\n",V1,V2,rxy1,rxy2,zTx0,V1corr,V2corr,rxyz1,rxyz2,xlog,Latten); return Latten; // return 1./(log((r2*V2)/(r1*V1*pow(10,2.5)))/fabs(r2-r1)); } inline Float_t Latten_1byr(Float_t V1, Float_t V2, Float_t r1, Float_t r2){ Float_t xlog=log((r1*V1)/(r2*V2)); // cout<GetX()[1]-grHE->GetX()[0]; Int_t nbinTone=tWidthTone/dt; TGraph *grTone=new TGraph(nbinTone); for(Int_t ib=0; ibSetPoint(ib,dt*ib,1.); // grTone->Print("all"); printf("nbinTone=%d\n",nbinTone); grtmp=FFTtools::getCorrelationGraph(grHE,grTone); fdum=getPeakValZ(grtmp,&idum); tXCTone[0]=grtmp->GetX()[idum]; VXCTone[0]=TMath::MaxElement(grHE->GetN(),grHE->GetY()); Int_t nbindT=tXCTone[0]/dt; delete grtmp; printf("Total bins=%d dt=%g / nbindT=%d / grXCTone zeroing bins from %d to %d\n",grHE->GetN(),dt,nbindT,TMath::Max(0,nbindT-nbinTone/2),TMath::Min(nbindT+nbinTone/2,grHE->GetN())); for(Int_t ib=TMath::Max(0,nbindT-nbinTone/2); ibGetN()); ib++){ grHE->SetPoint(ib,grTone->GetX()[ib],0); } grtmp=FFTtools::getCorrelationGraph(grHE,grTone); fdum1=getPeakValZ(grtmp,&idum1); tXCTone[1]=grtmp->GetX()[idum1]; VXCTone[1]=TMath::MaxElement(grHE->GetN(),grHE->GetY()); if(VXCTone[1]!=grHE->GetY()[idum1]){ printf("VXCTone[1]!=grHE->GetY()! / aborting!"); abort; } Int_t nbinrms=TMath::Min(nbindT,int(tXCTone[1]/dt)); Float_t AvgV=TMath::Mean(nbinrms,grHE->GetY()); VXCTone[0]-=AvgV; VXCTone[1]-=AvgV; SNRXCTone[0]=VXCTone[0]/AvgV; SNRXCTone[1]=VXCTone[1]/AvgV; printf("%stXCTone[0]=%g/V=%g/SNR=%g / tXCTone[1]=%g/V=%g/SNR=%g%s\n",KCYN,tXCTone[0],VXCTone[0],SNRXCTone[0],tXCTone[1],VXCTone[1],SNRXCTone[1],KNRM); // Float_t dt1=grtmp->GetX()[1]-grtmp->GetX()[0]; delete grTone; delete grtmp; delete grHE; // if(MBING*1.2*dt1>fabs(tXCGaus[1]-tXCGaus[0]))return 0; // else return 1; return (tXCTone[1]-tXCTone[0])/dt; } //inline Float_t dtWtAvgZ(Double_t *dtVals_ij, Int_t peakBin_ij){return (dtVals_ij[peakBin_ij]*xcVals_ij[peakBin_ij]+dtVals_ij[peakBin_ij-1]*xcVals_ij[peakBin_ij-1]+dtVals_ij[peakBin_ij+1]*xcVals_ij[peakBin_ij+1])/(xcVals_ij[peakBin_ij]+xcVals_ij[peakBin_ij-1]+xcVals_ij[peakBin_ij+1]);} inline void PrintMsg(bool LPrintMsg, const char *cmsg){ // int &NErrPrint){ time_t now=time(0); // Convert now to tm struct for local timezone tm* localtm = localtime(&now); if(LPrintMsg)printf("*********NEvTot=%d CPUTimeTot=%g msg=%s ",NEvTot,(clock()-CPUTime0Execution)/CLOCK_TICKS_PER_SEC,cmsg); cout << "The local date and time is: " << asctime(localtm) << endl; // NErrPrint++; } inline Bool_t chk12(const char *cmsg, Float_t v1, Float_t v2, Float_t tolerance){ if(abs(v1-v2)/(v1+v2)>tolerance){ printf("Variables not equal! Checking %s / v1=%g / v2=%g\n",cmsg,v1,v2); return false; } return true; } inline Bool_t eql12(Float_t v1, Float_t v2, Float_t tolerance){ if(abs(v1-v2)/(v1+v2)>tolerance)return false; return true; } inline Float_t MaxEl0(TGraph *gr, Int_t &ibinAMax, Float_t &RMax2Min){ Float_t fp=TMath::MaxElement(gr->GetN(),gr->GetY()); Float_t fm=TMath::MinElement(gr->GetN(),gr->GetY()); // printf("fp=%g fm=%g\n",fp,fm); Float_t AMax; if(-fm>fp){ AMax=fm; ibinAMax=TMath::LocMin(gr->GetN(),gr->GetY());} else{ AMax=fp; ibinAMax=TMath::LocMax(gr->GetN(),gr->GetY());} RMax2Min=0; if(fm!=0&&fp!=0)RMax2Min=fp/fm; Float_t t2pk=gr->GetX()[ibinAMax]-gr->GetX()[0]; if(t2pk==0)printf("t2pk=%g AMax=%g ibAMax=%d nb=%d\n",t2pk,AMax,ibinAMax,gr->GetN()); return AMax; } inline void AvgVrmsCh(TGraph *gr, Int_t ich){ VrmsChSum[ich]+=gr->GetRMS(2); NVrmsCh[ich]++; VrmsChAvg[ich]=VrmsChSum[ich]/NVrmsCh[ich]; } inline void BookAndFillh2Spectrogram(Bool_t LinitBAF2S, Int_t ich, TGraph *gr, Int_t nsdeltaT){ Float_t ffpk, ffpk0, tmin, tmax, fmin, fmax; Int_t ibnfpk, ibnfpk0; Int_t nblip=0; Float_t dtgr=gr->GetX()[1]-gr->GetX()[0]; TGraph *grtemp, *grffttmp; TGraph *gr0fft=FFTtools::makePowerSpectrum(gr); gr0fft->SetPoint(0,gr0fft->GetX()[0],0); ibnfpk0=TMath::LocMax(gr0fft->GetN(),gr0fft->GetY()); ffpk0=gr0fft->GetX()[ibnfpk0]; fdum=gr0fft->GetY()[ibnfpk0]/(gr0fft->Integral()/(gr0fft->GetX()[1]-gr0fft->GetX()[0])); if(LinitBAF2S){ tmin=gr->GetX()[0]; tmax=gr->GetX()[gr->GetN()-1]; fmin=gr0fft->GetX()[0]; fmax=gr0fft->GetX()[gr0fft->GetN()-1]; fmin=0; fmax=1.024; Int_t MBINTIME=(tmax-tmin)/nsdeltaT; printf("Booking h2Spectrogram: MBINTIME=%d xmin=%g / xmax=%g / ymin=%g / ymax=%g\n",MBINTIME,gr->GetX()[0],gr->GetX()[gr->GetN()-1],gr0fft->GetMinimum(),gr0fft->GetMaximum()); h2Zspx[ich]=new TH2F(Form("h2Zspx_%d",ich),Form("h2Zspx_%d",ich),MBINTIME,tmin,tmax,nsdeltaT/2,fmin,fmax); } for(Int_t ib=0; ibGetN(); ib+=nsdeltaT/dtgr){ grtemp=new TGraph(nsdeltaT/dtgr,gr->GetX(),&gr->GetY()[ib]); grffttmp=FFTtools::makePowerSpectrum(grtemp); grffttmp->SetPoint(0,grffttmp->GetX()[0],0); ibnfpk=TMath::LocMax(grffttmp->GetN(),grffttmp->GetY()); if(ibnfpk<0||ibnfpk>grffttmp->GetN()-1)continue; ffpk=grffttmp->GetX()[ibnfpk]; fdum1=grffttmp->GetY()[ibnfpk]/(grffttmp->Integral()/(grffttmp->GetX()[1]-grffttmp->GetX()[0])); if(ffpk>0.1&&ffpk0>0.1&&abs(ffpk-ffpk0)/(ffpk+ffpk0)>0.08&&fdum>0.08&&fdum1>0.16){ nblip++; if(LDebug)printf("ich=%d ffpk=%g/ffpk0=%g t=%g\n",ich,ffpk,ffpk0,gr->GetX()[ib]); } for(Int_t ibfft=0; ibfftGetN(); ibfft++){ h2Zspx[ich]->Fill(gr->GetX()[ib],grffttmp->GetX()[ibfft],grffttmp->GetY()[ibfft]); } delete grtemp; delete grffttmp; } if(nblip==1)NFRQBLIP->Fill(ich,ffpk,ffpk0,fdum,fdum1,unixTime); delete gr0fft; // h2tmp->SetStats(0); sprintf(chtitle,"%s; Time (ns); Frequency (GHz)",ch2name); h2tmp->SetTitle(chtitle); } inline void Fillh3Spectrogram(TGraph *gr, Int_t ich){ if(!Rx[ich].LVtx)return; idum=TMath::Min(int(abs(zTx0z)/100),int(MBINZTX-1)); for(Int_t ibt=0; ibtGetN(); ibt+=MBINTIMESPECTROGRAM){ TGraph *grtemp=new TGraph(MBINTIMESPECTROGRAM,gr->GetX(),&gr->GetY()[ibt]); TGraph *grffttmp=FFTtools::makePowerSpectrum(grtemp); for(Int_t ibfft=0; ibfftGetN(); ibfft++) h3Spectrogram[idum]->Fill(gr->GetX()[ibt],grffttmp->GetX()[ibfft],ich,grffttmp->GetY()[ibfft]); delete grtemp; delete grffttmp; } } inline TGraph *grFillRndm(Int_t MBINS){ TGraph *grtemp=new TGraph(MBINS); for(Int_t ib=0; ibSetPoint(ib,ib,gRandom->Rndm()); return grtemp; } inline TGraph *grfrqFilter(TGraph *gr, Int_t ichfft, Float_t &freqMaxMHz, Float_t &PfracfreqMaxMHz){ TGraph *grtemp=FFTtools::makePowerSpectrum(gr); freqMaxMHz=-1; PfracfreqMaxMHz=-1; Float_t ptemp=-1; for(Int_t ib=2; ibGetN(); ib++){ if(grtemp->GetY()[ib]>PfracfreqMaxMHz){ freqMaxMHz=grtemp->GetX()[ib]; PfracfreqMaxMHz=grtemp->GetY()[ib]; } } TGraph *grfrqfilter=FFTtools::simpleNotchFilter(gr,freqMaxMHz*0.98,freqMaxMHz*1.02); PfracfreqMaxMHz/=FFTtools::sumPower(grtemp,-1,-1); delete grtemp; return grfrqfilter; } TGraph *grZerobins(TGraph *gr, Int_t ibini, Int_t ibinf){ TGraph *grtemp=(TGraph*)gr->Clone(); for(Int_t ib=TMath::Max(0,ibini); ibGetN(),ibinf); ib++) grtemp->SetPoint(ib,grtemp->GetX()[ib],0); return grtemp; } TH1 *hyShift2h(TH1 *h, TH1 *h2){ TH1 *htmp=(TH1*)h->Clone(); Float_t hMiny=htmp->GetMinimum(); Float_t hMaxy=htmp->GetMaximum(); Float_t h2Miny=h2->GetMinimum(); Float_t h2Maxy=h2->GetMaximum(); Float_t yshift=(h2Maxy-h2Miny)-(hMaxy-hMiny); for(Int_t ib=0; ibGetNbinsX(); ib++){ Float_t hy=h->GetBinContent(ib); htmp->SetBinContent(ib,hy+yshift); } return htmp; } //TGraph *gryShift2gr(TGraph *gr, TGraph *gr2){TGraph *grtmp=(TGraph*)gr->Clone(); Float_t grMiny=TMath::Min(grtmp->GetN(),grtmp->GetY()); Float_t grMaxy=TMath::Max(grtmp->GetN(),grtmp->GetY()); Float_t gr2Miny=TMath::Min(gr2->GetN(),gr2->GetY()); Float_t gr2Maxy=TMath::Max(gr2->GetN(),gr2->GetY()); Float_t yshift=(gr2Maxy-gr2Miny)-(grMaxy-grMiny); for(Int_t ib=0; ibGetN(); ib++)grtmp->SetPoint(ib,gr->GetX()[ib],gr->GetY()[ib]+yshift); return grtmp;} inline TGraph *grXCableDelay(TGraph *gr, Int_t ich){ TGraph *grtemp=(TGraph*)gr->Clone(); for(Int_t ib=0; ibGetN(); ib++) grtemp->SetPoint(ib,gr->GetX()[ib]+Rx[ich].cableDelayNs,gr->GetY()[ib]); return grtemp; } //SAME as virtual void MovePoints (Double_t dx, Double_t dy, Bool_t logx=kFALSE, Bool_t logy=kFALSE) //SAME as TGraph *FFTtools::translateGraph(TGraph *grWave, Double_t deltaT) TGraph *grxShift(TGraph *gr, Float_t dxshift){ TGraph *grtmp=new TGraph(gr->GetN()); for(Int_t ib=0; ibGetN(); ib++)grtmp->SetPoint(ib,gr->GetX()[ib]+dxshift,gr->GetY()[ib]); return grtmp; } Bool_t Lgr1Yequalgr2Y(TGraph *gr1, TGraph *gr2){ Bool_t L=true; if(gr1->GetN()!=gr2->GetN())L=false;; for(Int_t ib=0; ibGetN()-1; ib++) if(gr1->GetY()[ib]!=gr2->GetY()[ib])L=false; return L; } TGraph *grnbShift(TGraph *gr, Float_t dxshift){ TGraph *grtmp=(TGraph*)gr->Clone(); Int_t nbshift=dxshift/(gr->GetX()[1]-gr->GetX()[0]); for(Int_t ib=nbshift; ibGetN()-nbshift; ib++)grtmp->SetPoint(ib+nbshift,gr->GetX()[ib],gr->GetY()[ib]); return grtmp; } TGraph *grfftSub(TGraph *gr, Int_t ibini, Int_t nbins, Float_t &frqavg){ if(ibini+nbins>=gr->GetN()){ TGraph *grtemp=(TGraph*)gr->Clone(); return grtemp; } TGraph *grtemp=new TGraph(nbins,gr->GetX(),&gr->GetY()[ibini]); // cout<Print("all"); abort(); TGraph *grffttmp=FFTtools::makePowerSpectrum(grtemp); Double_t fNorm=TMath::Mean(grffttmp->GetN(),grffttmp->GetY()); frqavg=0; Float_t densum=0; //=P(Ei)*Ei for(Int_t ipt=0; iptGetN(); ipt++){ densum+=grffttmp->GetY()[ipt]; frqavg+=grffttmp->GetX()[ipt]*grffttmp->GetY()[ipt]; grffttmp->SetPoint(ipt,grffttmp->GetX()[ipt],grffttmp->GetY()[ipt]/fNorm); } frqavg/=densum; delete grtemp; return grffttmp; } inline void DrawGraphp2p(TGraph *gr,Float_t fnorm,char *copt){ Int_t ibnmax; Float_t AMax=fabs(grMaxZ(gr,&ibnmax)); TGraph *grtmp=grScale(gr,fnorm/AMax); grtmp->Draw(copt); } TGraph *grNorm1Z(TGraph *gr){ TGraph *grtmp=new TGraph(gr->GetN()); Int_t ibnmax; Float_t AMax=fabs(grMaxZ(gr,&ibnmax)); for(Int_t ib=0; ibGetN(); ib++)grtmp->SetPoint(ib,gr->GetX()[ib],gr->GetY()[ib]/AMax); return grtmp; } inline TGraph *grNorm0(TGraph *gr, const Float_t scalegr){ Float_t ymax=0; Float_t fInt=0; Int_t ibymax=-1; TGraph *grNrm=(TGraph*)gr->Clone(); ymax=MaxEl0(gr,idum,fdum1); for(Int_t ib=0; ibGetN(); ib++)fInt+=fabs(gr->GetY()[ib]); // if(fabs(gr->GetY()[ib]>fabs(ymax))){ ymax=gr->GetY()[ib]; ibymax=ib; } for(Int_t ib=0; ibGetN(); ib++) grNrm->SetPoint(ib,gr->GetX()[ib],scalegr*gr->GetY()[ib]/fabs(ymax)); if(fabs(MaxEl0(grNrm,idum,fdum1))-scalegr>1)printf("MaxEl0=%g ymax=%g ibymax=%d gr[ibymax]=%g grNrm[ibymax]=%g\n",MaxEl0(grNrm,idum,fdum1),ymax,ibymax,gr->GetY()[ibymax],grNrm->GetY()[ibymax]); // gr->Print("all"); grNrm->Print("all"); abort(); return grNrm; } TGraph *grNorm1to2(TGraph *gr1, TGraph *gr2, Float_t Scale){ TGraph *grtmp=new TGraph(gr1->GetN()); Int_t ibnmax; Float_t AMax1=fabs(grMaxZ(gr1,&ibnmax)); Float_t AMax2=fabs(grMaxZ(gr2,&ibnmax)); if(LDebug)printf("AMax2=%g / AMax1=%g\n",AMax2,AMax1); for(Int_t ib=0; ibGetN(); ib++)grtmp->SetPoint(ib,gr1->GetX()[ib],Scale*AMax2*gr1->GetY()[ib]/AMax1); return grtmp; } inline Float_t TOTHilEnv(TGraph *gr, TH1 *h0, Float_t threshold, Int_t ich, Int_t &iTOT0, Float_t &SNRMax, Float_t &tfirstbin, Float_t &tlastbin, Float_t &VMaxR, Float_t &tVMaxR, Float_t &TMathVrms){ const Int_t MSIGMA=4; const Int_t MBNRMS=2048; const Int_t MARGIN=128; const Int_t MSPM=16; Int_t MS=gr->GetN(); Double_t *Vtmp=gr->GetY(); Double_t *ttmp=gr->GetX(); TMathVrms=TMath::RMS(MBNRMS,Vtmp); Float_t TMathVAvg=TMath::Mean(MBNRMS,Vtmp); Float_t TMathVMax=TMath::MaxElement(MBNRMS,Vtmp); VMaxR=TMath::MaxElement(MS,Vtmp); Int_t ibVMaxR=TMath::LocMax(MS-2*MARGIN,Vtmp); iTOT0=0; tVMaxR=ttmp[ibVMaxR]; tfirstbin=-NNN; tlastbin=-NNN; Float_t thresh0; if(threshold<0)thresh0=TMathVMax+TMathVrms*MSIGMA; else thresh0=threshold; Float_t VMaxPosSlope=-999999; Float_t VMaxNegSlope=999999; Float_t VSlope, VSlopepos, VSlopeneg; for(Int_t ib=0; ibFill(ich,dVX/thresh0); if(fabs(dVX>thresh0))iTOT0++; if(ibMS-MARGIN)continue; //margin if(Vtmp[ib-MSPM]==Vtmp[ib-MSPM/2]||Vtmp[ib+MSPM]==Vtmp[ib+MSPM/2])continue; VSlope=Vtmp[ib+2]-Vtmp[ib-2]; // VSlopepos=(Vtmp[ib+MSPM]-Vtmp[ib+MSPM/2])/fabs(Vtmp[ib-MSPM]-Vtmp[ib-MSPM/2]); VSlopeneg=(Vtmp[ib-MSPM/2]-Vtmp[ib-MSPM])/fabs(Vtmp[ib+MSPM]-Vtmp[ib+MSPM/2]); if(VSlopepos>VMaxPosSlope && ibibVMaxR){ VMaxNegSlope=VSlopeneg; tlastbin=ttmp[ib]; } } // for(Int_t ib=0; ibthresh0){tfirstbin=ttmp[ib]; break;}} // for(Int_t ib=MS-1; ib>0; ib--){Float_t dVX=(Vtmp[ib]-TMathVrms); if(dVX>thresh0){tlastbin=ttmp[ib]; break;}} /* for(Int_t ib=0; ibFill(ich,dVX/thresh0); if(dVX>thresh0)iTOT0++; if(dVX>thresh0&&tfirstbin==-999)tfirstbin=ttmp[ib]; Int_t jb=MS-ib-1; if(dVX>thresh0&&tlastbin==-999)tlastbin=ttmp[jb]; } */ if(tlastbinGetXaxis()->SetRange(0,gr1->GetN()); gr2->GetXaxis()->SetRange(0,gr2->GetN()); Float_t tnsXV1=-1; for(Int_t ib=0; ibGetN(); ib++){ if(fabs(gr1->GetY()[ib])GetX()[ib]; break; } Float_t ymin=TMath::MinElement(gr1->GetN(),gr1->GetY()); Float_t ymax=TMath::MaxElement(gr1->GetN(),gr1->GetY()); TLine *l1=new TLine(tnsXV1,ymin,tnsXV1,ymax); Float_t tnsXV2=-1; for(Int_t ib=0; ibGetN(); ib++){ if(fabs(gr2->GetY()[ib])GetX()[ib]; break; } TLine *l2=new TLine(tnsXV2,ymin,tnsXV2,ymax); Float_t tnsXV3=-1; Int_t ib3=gr1->GetN()/2; for(Int_t ib=ib3; ibGetN(); ib++){ if(fabs(gr1->GetY()[ib])GetX()[ib]; break; } TLine *l3=new TLine(tnsXV3,ymin,tnsXV3,ymax); Float_t tnsXV4=-1; Int_t ib4=gr2->GetN()/2; for(Int_t ib=ib4; ibGetN(); ib++){ if(fabs(gr2->GetY()[ib])GetX()[ib]; break; } TLine *l4=new TLine(tnsXV4,ymin,tnsXV4,ymax); Float_t deltaT=NNN; if(LDrawgr){ TCanvas *c1=new TCanvas("c1","c1"); c1->SetGrid(1); gr1->SetLineColor(kBlue); gr2->SetLineColor(kRed); // if(tnsXV1GetXaxis()->SetRangeUser(tnsXV1-16,tnsXV2+16); // else gr1->GetXaxis()->SetRangeUser(tnsXV2-16,tnsXV1+16); gr1->Draw("al"); deltaT=dtgr1gr2(gr1,gr2,fdum,idum); TGraph *gr2_xshift=grxShift(gr2,deltaT); gr2_xshift->Draw("lsame"); l1->SetLineColor(kBlue+1); l2->SetLineColor(kRed+1); l3->SetLineColor(kBlue-1); l4->SetLineColor(kRed-1); l1->SetLineWidth(4); l2->SetLineWidth(4); l3->SetLineWidth(4); l4->SetLineWidth(4); l1->Draw("same"); l2->Draw("same"); l3->Draw("same"); l4->Draw("same"); TCanvas *c2=new TCanvas("c2","c2"); gr2->Draw("al"); } printf("tnsXV1=%g / tnsXV2=%g / dta=%g dtb=%g dtXC=%g\n",tnsXV1,tnsXV2,tnsXV1-tnsXV2,tnsXV4-tnsXV3,deltaT); return tnsXV1-tnsXV2; } inline void aStoreTGraph(char *cin, TGraph **gr0, TFile *TFileOut){ if(nEvAvg[iPolVtx]+1>=MMWFAVG-1)return; Int_t ipol=iPolVtx; if(ipol<0||ipol>=2)return; if(nEvAvg[ipol]>0){ for(Int_t ich=0; ichGetN()!=gr0[ich]->GetN()){ printf("StoreTGraph ERRZ: event %d: grEvAvgN[%d][%d]->GetN()=%d !=gr0->GetN()=%d nbinsVtgr=%d => RETURNING!\n",ieventNumber,ich,nEvAvg[ipol]-1,grEvAvgN[ipol][ich][nEvAvg[ipol]-1]->GetN(),gr0[ich]->GetN(),nbinsVtgr[ich]); return; } } } for(Int_t ich=0; ichClone(); sprintf(cgrtitle,"%s_run%d_ev%d_L%d_phi%d_the%d_A%d_Rx%d",cin,irunNumber,ieventNumber,Rx[ich].LVtx,int(FitvtxMinuit.phi),int(FitvtxMinuit.the),ich,iptRxAraRoot2Rxtrue[ich]); sprintf(cgrname,"%s_run%d_ev%d_ch%d_ipol%d",cin,irunNumber,ieventNumber,ich,ipol); cout<<"Polarization "<SetName(cgrname); grEvAvgN[ipol][ich][nEvAvg[ipol]]->SetTitle(cgrtitle); if(Rx[ich].iPol==0)grEvAvgN[ipol][ich][nEvAvg[ipol]]->SetLineColor(izcolor[ich]); //VPol // if(Rx[ich].iPol==1)grEvAvgN[ipol][ich][nEvAvg[ipol]]->SetLineColor(kRed); //HPol if(LDrawEv)TFileOut->Append(grEvAvgN[ipol][ich][nEvAvg[ipol]]); } } inline void WriteUnbiasEvt(TGraph **gr0, Int_t ista, Int_t iyr, const char *ctmp, TFile *TFileOut){ // if(!UnbiasEvtsOut.is_open())UnbiasEvtsOut.open("a.txt"); //Form("$HOME/ctem/txt/UnbiasEvts_a%d_%d_%s.txt",ista,iyr,ctmp)); // else UnbiasEvtsOut.open("a.txt",std::ios_base::app); //Form("$HOME/ctem/txt/UnbiasEvts_a%d_%d_%s.txt",ista,iyr,ctmp),std::ios_base::app); sprintf(ctemp,"$HOME/ctem/txt/UnbiasEvts_a%d_%d_%s.txt",ista,iyr,ctmp); UnbiasEvtsOut.open(ctemp,std::ios_base::app); for(Int_t ich=0; ichClone(); sprintf(cgrname,"grUB%d_%d",ich,NUBStore); grtmp->SetName(cgrname); grtmp->SetTitle(cgrname); if(NUBStore<=MAXUBEV)TFileOut->Append(grtmp); UnbiasEvtsOut<GetN()<<" "<GetX()[1]-gr0[ich]->GetX()[0]<<" "<GetX()[0]<GetN()<<" "<GetX()[1]-gr0[ich]->GetX()[0]<<" "<GetX()[0]<GetN(); ib++){ UnbiasEvtsOut<GetX()[ib]<<" "<GetY()[ib]<GetX()[ib]<<" "<GetY()[ib]<GetN(); ib++) evdump<GetX()[ib]<<" "<GetY()[ib]<Reset(); std::fill(std::begin(phicogX),std::end(phicogX),-NNN); for(Int_t ich=0; ichReset(); VMnVMx1VMx2[ich]=NNN; tVMnVMx1VMx2[ich]=NNN; phicogX[ich]=-NNN; thecogX[ich]=-NNN; tExpFit[ich]=-NNN; tXCg[ich]=-NNN; A1DubG[ich]=-NNN; t1DubG[ich]=-NNN; A2DubG[ich]=-NNN; WidDubG[ich]=-NNN; dtDubG[ich]=-NNN; Rx[ich].tVMax00=-NNN; Rx[ich].LXVtx=false; Rx[ich].LVtx=false; Rx[ich].LVtx0=false; Rx[ich].LVtxCutsFile=true; Rx[ich].HitTime=-NNN; for(Int_t jch=0; jchRndm(); simVtx[1]=360*(gRandom->Rndm()-0.5); simVtx[2]=90+90*gRandom->Rndm(); if(irGen!=0)simVtx[0]=irGen; if(iphiGen!=0)simVtx[1]=iphiGen; if(itheGen!=0)simVtx[2]=itheGen; Float_t phiSimTx=simVtx[1]*TMath::DegToRad(); Float_t theSimTx=simVtx[2]*TMath::DegToRad(); Float_t xSimTx=simVtx[0]*cos(phiSimTx)*sin(theSimTx); Float_t ySimTx=simVtx[0]*sin(phiSimTx)*sin(theSimTx); Float_t zSimTx=simVtx[0]*cos(theSimTx); dtSmearSimVtx=gRandom->Uniform(0,idtSmrGen); // for(Int_t ich=0; ichMCHVTXf)continue; Rx[ich].LVtx=true; Float_t dsqr=(xSimTx-Rx[ich].x)*(xSimTx-Rx[ich].x) + (ySimTx-Rx[ich].y)*(ySimTx-Rx[ich].y) + (zSimTx-Rx[ich].z)*(zSimTx-Rx[ich].z); if(Lrindex1)Rx[ich].dtSimTx=sqrt(dsqr)/(sLightAir/nIcez(Rx[ich].z00,Rx[ich].z00)); else Rx[ich].dtSimTx=ntimexp(zSimTx,Rx[ich].z,sqrt(dsqr)); Double_t ddum0=Rx[ich].dtSimTx+Rx[ich].dtNsCorrSim; if(Rx[ich].iPol==1)ddum0=Rx[ich].dtSimTx+idtnsVHMC; if(ddum0tSimVtxLastHit)tSimVtxLastHit=ddum0; Double_t ddum1=Rx[ich].tResolution; ddum1=dtSmearSimVtx; Rx[ich].HitTime=gRandom->Gaus(ddum0,ddum1); if(iwflenns>0)Rx[ich].HitTime=gRandom->Uniform(0,iwflenns); //assume 500 ns waveform Rx[ich].SNR=16; // arbitrary if(LDebug)printf("SIMVTX: Ev=%d Rx[%d].LVtx=%d xRx=%g m / yRx=%g m / zRx=%g m / UnSmearedTime=%g ns / xTx=%g m / yTx=%g m / zTx=%g m / Rx[%d].HitTime=%g ns (with smearing) / Rx refractive-index=%g / n=1.78 Time=%g\n",NEvTot,ich,Rx[ich].LVtx,Rx[ich].x,Rx[ich].y,Rx[ich].z00,Rx[ich].dtSimTx,xSimTx,ySimTx,zSimTx,ich,Rx[ich].HitTime,nIcez(Rx[ich].z00,Rx[ich].z00),sqrt(dsqr)/(sLightAir/nIcez(Rx[ich].z00,Rx[ich].z00))); nFitVtx++; } // SNRxcMin=-1; Float_t HitTimeMax=-NNN; Float_t HitTimeMin=NNN; for(Int_t ich=0; ichHitTimeMax){ ichMaxHitTime=ich; HitTimeMax=Rx[ich].HitTime; } if(Rx[ich].HitTimeFill(Rx[ich].HitTime,ich); } for(Int_t ich=0; ichFill(ich,jch,Map2pm180deg(fdum1),90-fdum); h2AzEl->Fill(Map2pm180deg(fdum1),90-fdum); } if(ich>=8)continue; printf("HPol Ch.=%d / VPol Ch.=%d / dz=%g vertical dt(H,V)=%g\n",ich+8,ich,(Rx[ich+8].z-Rx[ich].z),nIcez(Rx[ich].z00,Rx[ich+8].z00)*(Rx[ich+8].z-Rx[ich].z)/sLightAir); if(ich>=4)continue; printf("***VPol Chs. %d/%d / dz=%g vertical dt(B,T)=%g\n",ich,ich+4,(Rx[ich+4].z-Rx[ich].z),nIcez(Rx[ich+4].z00,Rx[ich].z00)*(Rx[ich+4].z-Rx[ich].z)/sLightAir); printf("***HPol Chs. %d/%d / dz=%g vertical dt(B,T)=%g\n",ich+8,ich+12,(Rx[ich+12].z-Rx[ich+8].z),nIcez(Rx[ich+12].z00,Rx[ich+8].z00)*(Rx[ich+12].z-Rx[ich+8].z)/sLightAir); } cout<<"MaxArrayTransitTimens(ns)="<>jS>>ich>>sBH>>sName>>E>>N>>u){ if(jS==iStation){ Rx[ich].aE=E*ft2m; Rx[ich].aN=N*ft2m; Rx[ich].au=u*ft2m; } } } inline void getLocRxCoordsAndDelaysMingYuan(Int_t iStation){ if(iStation==2){ Float_t cablePlusTriggerDelayNs[16]={19.44,19.8606,125.547,22.5759,93.41,93.8306,199.517,96.5459,7.24,7.66056,113.347,10.3759,81.2,81.6206,187.307,84.3359}; Float_t antcor2[16][3]={{10.5874,2.3432,9.7527},{4.85167,-10.3981,9.65333},{-2.58128,9.37815,8.41082},{-7.84111,-4.05791,4.62319},{10.5873,2.3428,-9.502},{4.85157,-10.3985,-9.39997},{-2.58138,9.37775,-10.6422},{-7.84131,-4.05821,-14.2658},{10.5874,2.3128,12.5076},{4.85167,-10.3981,12.5718},{-2.58128,9.37825,11.5317},{-7.84111,-4.05781,7.57979},{10.5873,2.3429,-6.5457},{4.85157,-10.3985,-6.11477},{-2.58138,9.37775,-7.52158},{-7.84111,-4.05821,-10.9806}}; for(Int_t ich=0; ich<16; ich++){ Rx[ich].x=antcor2[ich][0]; Rx[ich].y=antcor2[ich][1]; Rx[ich].z=antcor2[ich][2]; Rx[ich].cablePlusTriggerDelayNs=cablePlusTriggerDelayNs[ich]; Rx[ich].cableDelayNs=cablePlusTriggerDelayNs[ich]; } } } //fill x/y/z/delta(t) with true, rather than tabulated values inline void OverwriteRxXYZ(Int_t ipointer[MCH]){ for(Int_t ich=0; ich=MCH16)abort(); if(ipointer[ich]==ich)continue; printf("OverWritingRxXYZ ich=%d ipt=%d OLD: Rx[%d].x/y/z=%g/%g/%g\n",ich,ipointer[ich],ich,Rx[ich].x,Rx[ich].y,Rx[ich].z); Rx[ich].x=Rx[ipointer[ich]].x0; Rx[ich].y=Rx[ipointer[ich]].y0; Rx[ich].z=Rx[ipointer[ich]].z0; Rx[ich].iPol=Rx[ipointer[ich]].iPol0; printf("OverWritingRxXYZ NEW: Rx[%d].x/y/z=%g/%g/%g\n",ich,Rx[ich].x,Rx[ich].y,Rx[ich].z); } } //fill x/y/z/delta(t) with true, rather than tabulated values inline void OverwriteCableDelays(Int_t ipointer[MCH]){ for(Int_t ich=0; ich=MCH16)abort(); if(ipointer[ich]==ich)continue; printf("OverWritingCableDelays OLD: ich=%d ipt=%d Rx[%d].cableDelay=%g\n",ich,ipointer[ich],ich,Rx[ich].cableDelayNs); Rx[ich].cableDelayNs=Rx[ipointer[ich]].cableDelayNs0; h2CableDelayNsZ->Fill(Rx[ich].cableDelayNs,ich); printf("OverWritingCableDelays NEW: Rx[%d].cableDelayNs=%g\n",ich,Rx[ich].cableDelayNs); } } //Uzair from stationcor2.C inline void getGloRxCoordsUz(Int_t iStation){ if(iStation==0){ // Float_t antcor0[16][3]={{5248.37,-169.244,-27.1581},{5259.81,-154.431,-37.2189},{5256.37,-175.966,-29.1673},{5248.37,-169.244,-32.1581},{5266.01,-170.992,-34.3892},{5256.37,-175.966,-34.1673},{5259.81,-154.431,-32.2188},{5266.01,-170.992,-29.3892},{5254.31,-166.589,-7.87484},{5261.18,-167.249,-7.85102},{5258.37,-161.04,-7.85102},{5254.31,-166.589,-8.87484},{5247.72,-160.983,-33.0711},{5247.72,-160.983,-37.0711}{0,0,0}{0,0,0}}; //OLD Float_t antcor0[16][3]={{5265.36,-168.948,-27.1581},{5246.64,-168.65,-37.2189},{5265.96,-158.518,-29.1673},{5265.36,-168.948,-32.1581},{5256.2,-153.77,-34.3892},{5265.96,-158.518,-34.1673},{5246.64,-168.65,-32.2188},{5256.2,-153.77,-29.3892},{5259.68,-165.78,-7.87484},{5256.09,-159.879,-7.85102},{5252.8,-165.849,-7.85102},{5259.68,-165.78,-8.87484},{5259.13,-174.418,-33.0711},{5259.13,-174.418,-37.0711},{0,0,0},{0,0,0}}; for(Int_t ich=0; ich=0)continue; Rx[ich].x=Rx[ich].E1; Rx[ich].y=Rx[ich].N1; Rx[ich].z=Rx[ich].u1; } } if(iStation==3){ // Float_t antcor3[16][3]={{3006.6,-873.588,-176.477},{3012.42,-860.762,-180.079},{2999.77,-854.758,-177.975},{2993.63,-868.103,-176.084},{3006.6,-873.588,-195.53},{3012.42,-860.762,-198.803},{2999.77,-854.758,-196.536},{2993.63,-868.103,-195.137},{3006.6,-873.588,-173.356},{3012.42,-860.761,-177.122},{2999.77,-854.758,-174.487},{2993.63,-868.103,-173.127},{3006.6,-873.588,-192.278},{3012.42,-860.762,-195.847},{2999.77,-854.758,-193.579},{2993.63,-868.103,-192.016}}; //OLD Float_t antcor3[16][3]={{3006.44,-854.668,-176.477},{2992.68,-857.685,-180.079},{2995.44,-871.415,-177.975},{3009.81,-868.341,-176.084},{3006.44,-854.668,-195.53},{2992.68,-857.685,-198.803},{2995.44,-871.415,-196.536},{3009.81,-868.341,-195.137},{3006.44,-854.668,-173.356},{2992.68,-857.685,-177.122},{2995.44,-871.415,-174.487},{3009.81,-868.341,-173.127},{3006.44,-854.668,-192.278},{2992.68,-857.685,-195.847},{2995.44,-871.415,-193.579},{3009.81,-868.341,-192.016}}; for(Int_t ich=0; ichgetAntennaInfo(ich)->getLocationENU(); Rx[ich].E1=antLocRxENU[0]; Rx[ich].N1=antLocRxENU[1]; Rx[ich].u1=antLocRxENU[2];} } //The position of the ARA1 coordinate system, in the ARA global coordinate system, is E 16401.71’, N -2835.37’, -25.67’ elevation //The position of the ARA2 coordinate system, in the ARA global coordinate system, is E 13126.70’, N -8519.62’, -18.72’ elevation. //The position of the ARA3 coordinate system, in the ARA global coordinate system, is E 9848.35’, N -2835.19’, -12.70’ //The position of the Testbed coordinate system, in the ARA global coordinate system, is E 17246.69’, N -540.82’, -21.86’ elevation. inline void getGloRxCoordsAmy(Int_t iStation){ //from Amy $HOME/dox/ARAgeometry_doc.pdf Int_t iptA1u2u0[16]={7,14,13,15,8,9,10,11,4,5,6,7,0,1,2,3}; if(iStation==1){ Rx[0].E0=16389.9379; Rx[0].N0=-2860.792; Rx[0].u0=-234.962; Rx[4].E0=16389.9379; Rx[4].N0=-2860.792; Rx[4].u0=-296.879; Rx[8].E0=16389.9379; Rx[8].N0=-2860.792; Rx[8].u0=-228.212; Rx[12].E0=16389.9379; Rx[12].N0=-2860.792; Rx[12].u0=-285.712; Rx[1].E0=16381.828; Rx[1].N0=-2815.263; Rx[1].u0=-208.43; Rx[5].E0=16381.828; Rx[5].N0=-2815.263; Rx[5].u0=-267.098; Rx[9].E0=16381.828; Rx[9].N0=-2815.263; Rx[9].u0=-201.68; Rx[13].E0=16381.828; Rx[13].N0=-2815.263; Rx[13].u0=-255.977; Rx[2].E0=16434.956; Rx[2].N0=-2850.525; Rx[2].u0=-205.394; Rx[6].E0=16434.956; Rx[6].N0=-2850.525; Rx[6].u0=-267.311; Rx[10].E0=16434.956; Rx[10].N0=-2850.525; Rx[10].u0=-198.64; Rx[14].E0=16434.956; Rx[14].N0=-2850.525; Rx[14].u0=-255.765; Rx[3].E0=16425.802; Rx[3].N0=-2808.404; Rx[3].u0=-228.37; Rx[7].E0=16425.802; Rx[7].N0=-2808.404; Rx[7].u0=-286.03; Rx[11].E0=16425.802; Rx[11].N0=-2808.404; Rx[11].u0=-221.62; Rx[15].E0=16425.802; Rx[15].N0=-2808.404; Rx[15].u0=-275.70; } if(iStation==2){ Rx[0].E0=13101.5; Rx[0].N0=-8495.79; Rx[0].u0=-582.284; Rx[4].E0=13101.5; Rx[4].N0=-8495.79; Rx[4].u0=-640.493; Rx[8].E0=13101.5; Rx[8].N0=-8495.79; Rx[8].u0=-568.284; Rx[12].E0=13101.5; Rx[12].N0=-8495.79; Rx[12].u0=-630.793; Rx[1].E0=13146.2; Rx[1].N0=-8485.94; Rx[1].u0=-577.964; Rx[5].E0=13146.2; Rx[5].N0=-8485.94; Rx[5].u0=-640.473; Rx[9].E0=13146.2; Rx[9].N0=-8485.94; Rx[9].u0=-568.264; Rx[13].E0=13146.2; Rx[13].N0=-8485.94; Rx[13].u0=-629.696; Rx[2].E0=13110.9; Rx[2].N0=-8543.11; Rx[2].u0=-577.801; Rx[6].E0=13110.9; Rx[6].N0=-8543.11; Rx[6].u0=-640.311; Rx[10].E0=13110.9; Rx[10].N0=-8543.11; Rx[10].u0=-567.562; Rx[14].E0=13110.9; Rx[14].N0=-8543.11; Rx[14].u0=-630.072; Rx[3].E0=13155.3; Rx[3].N0=-8530.53; Rx[3].u0=-578.555; Rx[7].E0=13155.3; Rx[7].N0=-8530.53; Rx[7].u0=-640.555; Rx[11].E0=13155.3; Rx[11].N0=-8530.53; Rx[11].u0=-568.885; Rx[15].E0=13155.3; Rx[15].N0=-8530.53; Rx[15].u0=-629.778; } if(iStation==3){ Rx[0].E0=9866.37; Rx[0].N0=-2805.22; Rx[0].u0=-581.52; Rx[4].E0=9866.37; Rx[4].N0=-2805.22; Rx[4].u0=-644.029; Rx[8].E0=9866.37; Rx[8].N0=-2805.22; Rx[8].u0=-571.281; Rx[12].E0=9866.37; Rx[12].N0=-2805.22; Rx[12].u0=-633.359; Rx[1].E0=9820.13; Rx[1].N0=-2814.05; Rx[1].u0=-583.567; Rx[5].E0=9820.13; Rx[5].N0=-2814.05; Rx[5].u0=-644.998; Rx[9].E0=9820.13; Rx[9].N0=-2814.05; Rx[9].u0=-573.867; Rx[13].E0=9820.13; Rx[13].N0=-2814.05; Rx[13].u0=-635.299; Rx[2].E0=9829.57; Rx[2].N0=-2859.03; Rx[2].u0=-583.965; Rx[6].E0=9829.57; Rx[6].N0=-2859.03; Rx[6].u0=-644.858; Rx[10].E0=9829.57; Rx[10].N0=-2859.03; Rx[10].u0=-579.116; Rx[14].E0=9829.57; Rx[14].N0=-2859.03; Rx[14].u0=-635.299; Rx[3].E0=9876.01; Rx[3].N0=-2849.25; Rx[3].u0=-581.989; Rx[7].E0=9876.01; Rx[7].N0=-2849.25; Rx[7].u0=-644.499; Rx[11].E0=9876.01; Rx[11].N0=-2849.25; Rx[11].u0=-572.29; Rx[15].E0=9876.01; Rx[15].N0=-2849.25; Rx[15].u0=-634.26; } for(Int_t ich=0; ich0.5)printf("ERRZ! Rx[%d].E=%g / Rx[%d].E0=%g\n",ich,Rx[ich].E,ich,Rx[ich].E0); if(fabs(Rx[ich].N0-Rx[ich].N)>0.5)printf("ERRZ! Rx[%d].N=%g / Rx[%d].N0=%g\n",ich,Rx[ich].N,ich,Rx[ich].N0); if(fabs(Rx[ich].u0-Rx[ich].u)>0.5)printf("ERRZ! Rx[%d].u=%g / Rx[%d].u0=%g .u0pt=%g\n",ich,Rx[ich].u,ich,Rx[ich].u0,Rx[iptA1u2u0[ich]].u0); if(fabs(Rx[ich].E1-Rx[ich].E)>0.5)printf("ERRZ! Rx[%d].E=%g / Rx[%d].E1=%g / Rx[%d].E0=%g\n",ich,Rx[ich].E,ich,Rx[ich].E1,ich,Rx[ich].E0); if(fabs(Rx[ich].N1-Rx[ich].N)>0.5)printf("ERRZ! Rx[%d].N=%g / Rx[%d].N1=%g / Rx[%d].N0=%g\n",ich,Rx[ich].N,ich,Rx[ich].N1,ich,Rx[ich].N0); if(fabs(Rx[ich].u1-Rx[ich].u)>0.5)printf("ERRZ! Rx[%d].u=%g / Rx[%d].u1=%g / Rx[%d].u0=%g\n",ich,Rx[ich].u,ich,Rx[ich].u1,ich,Rx[ich].u0); } } CentroidN[iStation]/=MCH16; CentroidN0[iStation]/=MCH16; CentroidN1[iStation]/=MCH16; CentroidE[iStation]/=MCH16; CentroidE0[iStation]/=MCH16; CentroidE1[iStation]/=MCH16; Centroidu[iStation]/=MCH16; Centroidu0[iStation]/=MCH16; Centroidu1[iStation]/=MCH16; } inline void getRelPhase(Int_t ich, Float_t t0, Float_t tRef){ for(Float_t frqCWGHz=0.15; frqCWGHz<=0.31; frqCWGHz+=0.05){ Float_t Phase0=(((t0-tRef)*frqCWGHz-int((t0-tRef)*frqCWGHz)))/frqCWGHz; Float_t Phase1=fmod(t0-tRef,1./frqCWGHz); printf("f=%g φ00=%g +φ0=%g +φ1=%g OR -φ0=%g -φ1=%g\n",frqCWGHz,fmod(t0,1./frqCWGHz),Phase0,Phase1,1./frqCWGHz-Phase0,1./frqCWGHz-Phase1); DebugOut<>Rx[ich].x>>Rx[ich].y>>Rx[ich].z>>Rx[ich].cableDelayNs){ printf("Rx[%d].x=%g .y=%g .z=%g .cableDelay=%g\n",ich,Rx[ich].x,Rx[ich].y,Rx[ich].z,Rx[ich].cableDelayNs); if(ich<=7)Rx[ich].iPol=0; if(ich>7&&ich<=15)Rx[ich].iPol=1; if(ich>15)Rx[ich].iPol=2; ich++; } FilldxyzRxiRxj(); return; } ofstream RxCoordsOut(ctemp); Float_t Rxzmin=-200; if(iStaRx==0)Rxzmin=-30; if(iStaRx==100)Rxzmin=-85; h3devt=new TH3I("h3devt","h3devt",1,-12,12,1,-12,12,1,Rxzmin,Rxzmin+40); //h3devt->Draw(); then h3dhit[ich]->Draw("psame"); h3devt->SetStats(0); if(iStaRx==0){ fLoPass[14]=20; fLoPass[15]=20; } MaxArrayTransitTime=-1; getGloRxCoordsUz(iSta0); printf("CentroidE[%d]=%g/E0[%d]=%g/E1[%d]=%g CentroidN[%d]=%g/N0[%d]=%g/N1[%d]=%g\n",iSta0,CentroidE[iSta0],iSta0,CentroidE0[iSta0],iSta0,CentroidE1[iSta0],iSta0,CentroidN[iSta0],iSta0,CentroidN0[iSta0],iSta0,CentroidN1[iSta0]); getGloRxCoordsAmy(iSta0); getNorthingEasting(iStaRx); AraStationInfo *stationInfo=0; // AraGeomTool *AraGeomPtr=AraGeomTool::Instance(); stationInfo=new AraStationInfo(iStaRx,abs(iYear)); // else stationInfo=AraGeomPtr->getStationInfo(abs(iStaRx),abs(iYear0)); Int_t icht2SMin=-1; Float_t t2SMin=NNN; Float_t d2S[MCH], t2S0[MCH], t2S[MCH], t2S0m10[MCH], t2Sm10[MCH]; Double_t *antLocRx; Double_t *antLocRxENU; TCanvas *cArrGeom; if(LDebug){cArrGeom=new TCanvas("cArrGeom","cArrGeom",0); h3devt->Draw("lego");} // AraStationInfo *stationInfo=new AraStationInfo(iStaRx); for(Int_t ich=0; ichgetAntennaInfo(ich)->getTrigChan(); printf("Channel %d RFChanName %s trigChannum=%d ElecChan=%d DAQChan=%d\n",ich,stationInfo->getAntennaInfo(ich)->getRFChanName(),itrigChanNum[ich],stationInfo->getElecChanFromRFChan(ich),stationInfo->getAntennaInfo(ich)->daqChanNum); } // if(iCoords==4 && iStaRx==2 && LRemapChs)getLocRxCoordsAndDelaysMingYuan(iStaRx); for(Int_t ich=0; ichgetAntennaInfo(ich)->holeName,6); strncpy(Rx[ich].cantName,stationInfo->getAntennaInfo(ich)->antName,6); Rx[ich].LPF=stationInfo->getAntennaInfo(ich)->lowPassFilterMhz; Rx[ich].HPF=stationInfo->getAntennaInfo(ich)->highPassFilterMhz; Rx[ich].iPol=stationInfo->getAntennaInfo(ich)->polType; Rx[ich].iPol0=Rx[ich].iPol; Rx[ich].ihole=ich%4; if(iStaRx>0)stationInfo->getAntennaInfo(ich)->printAntennaInfoAtri(); antLocRx=stationInfo->getAntennaInfo(ich)->getLocationXYZ(); if(iStaRx==100 && fabs(antLocRx[1])>1e9)antLocRx[1]/=1e9; //kludge for ara01 channel 10 antLocRxENU=stationInfo->getAntennaInfo(ich)->getLocationENU(); Rx[ich].x00=antLocRx[0]; Rx[ich].y00=antLocRx[1]; Rx[ich].z00=antLocRx[2]; //default araroot local coordinates: if(iCoords==0 || iStaRx>3){ Rx[ich].x=antLocRx[0]; Rx[ich].y=antLocRx[1]; Rx[ich].z=antLocRx[2]; } else if(iCoords==10){ //default araroot global coordinates Rx[ich].x=Rx[ich].E; //-CentroidE[iStaRx]; Rx[ich].y=Rx[ich].N; //-CentroidN[iStaRx]; Rx[ich].z=Rx[ich].u; //-Centroidu[iStaRx]; // Rx[ich].z=Rx[ich].u; } else if(iCoords==2){ //Amy coordinates Rx[ich].x=Rx[ich].E0; //-CentroidE0[iStaRx]; Rx[ich].y=Rx[ich].N0; //-CentroidN0[iStaRx]; Rx[ich].z=Rx[ich].u0; //-Centroidu0[iStaRx]; // Rx[ich].z=Rx[ich].u0; } else if(iCoords==3){ //Uzair coordinates Rx[ich].x=Rx[ich].E1; //-CentroidE1[iStaRx]; Rx[ich].y=Rx[ich].N1; //-CentroidN1[iStaRx]; Rx[ich].z=Rx[ich].u1; //-Centroidu1[iStaRx]; // Rx[ich].z=Rx[ich].u1; } // if(iStaRx==2 && ich==6){ // Rx[ich].x+=5.58; //http://ara.physics.wisc.edu/docs/0017/001796/001/190114_A2Ch6Offset_calpulserReco.pdf // cout<<"CAUTION!!!! RAISING CHANNEL 6 OF A2 BY ALMOST 6 METERS!!!!"<getCableDelay(ich); else printf("Using non-araroot cabledelay[%d]=%g\n",ich,Rx[ich].cableDelayNs); h2CableDelayNsAR->Fill(Rx[ich].cableDelayNs,ich); Rx[ich].cableDelayNs0=stationInfo->getCableDelay(ich); idaqChanNum[ich]=stationInfo->getAntennaInfo(ich)->daqChanNum; printf("Name=%s Z: Rx[%d].x=%7.2f, Rx[%d].y=%7.2f, Rx[%d].z=%7.2f / daqChanNum=%d / Delay=%7.2f / poltype=%d HPF=%d LPF=%d\n",Rx[ich].cFullName,ich,Rx[ich].x,ich,Rx[ich].y,ich,Rx[ich].z,idaqChanNum[ich],Rx[ich].cableDelayNs,stationInfo->getAntennaInfo(ich)->polType,Rx[ich].HPF,Rx[ich].LPF); // printf("AC geo file: %s %f %f %f\n",Rx[ich].cFullName,Rx[ich].xt,Rx[ich].yt,Rx[ich].zt); // } RxXYZ0[0]+=Rx[ich].x; RxXYZ0[1]+=Rx[ich].y; RxXYZ0[2]+=Rx[ich].z; } if(iSta0==0)for(Int_t ich=16; ich<20; ich++){Rx[ich].iPol=2; Rx[ich].HPF=fLoPass0[ich]; Rx[ich].LPF=fHiPass0[ich];} if(LDebug){sprintf(cpngname,"$HOME/ctem/png/A%d_iOW%d_geom.pdf",iStaRx,iCoords); cArrGeom->SaveAs(cpngname); delete cArrGeom;} cout<1e9)Rx[ich].y/=1e9; //kludge for ara01 channel 10 Rx[ich].r=sqrt(Rx[ich].x*Rx[ich].x+Rx[ich].y*Rx[ich].y+Rx[ich].z*Rx[ich].z); Rx[ich].phi=atan2(Rx[ich].y,Rx[ich].x)*TMath::RadToDeg(); Rx[ich].the=acos(Rx[ich].z/Rx[ich].r)*TMath::RadToDeg(); Rx[ich].rxy=sqrt(Rx[ich].x*Rx[ich].x + Rx[ich].y*Rx[ich].y); Rx[ich].LVtx=true; cout<NNN)Rx[ich].E=Rx[ich].aE; if(fabs(Rx[ich].N)<1.e-9||fabs(Rx[ich].N)>NNN)Rx[ich].N=Rx[ich].aN; if(Rx[ich].u==0)Rx[ich].u=Rx[ich].z00; //E=(Rx[ich].aE+Rx[ich].aE+Rx[ich].E1)/2.; printf(" antlocRx[%d].x=%g/Rx[%d].x=%g antlocRx[%d].y=%g/Rx[%d].y=%g antlocRx[%d].z=%g/Rx[%d].z=%g\n antlocRx[%d].E=%g Rx[%d].E0=%g Rx[%d].aE=%g *Rx[%d].E1=%g \n antlocRx[%d].N=%g Rx[%d].N0=%g Rx[%d].aN=%g *Rx[%d].N1=%g \n antlocRx[%d].u=%g Rx[%d].u0=%g Rx[%d].au=%g *Rx[%d].u1=%g\n",ich,Rx[0].x00,ich,Rx[ich].x,ich,Rx[ich].y00,ich,Rx[ich].y,ich,Rx[ich].z00,ich,Rx[ich].z,ich,Rx[ich].E,ich,Rx[ich].E0,ich,Rx[ich].aE,ich,Rx[ich].E1,ich,Rx[ich].N,ich,Rx[ich].N0,ich,Rx[ich].aN,ich,Rx[ich].N1,ich,Rx[ich].u,ich,Rx[ich].u0,ich,Rx[ich].au,ich,Rx[ich].u1); RxCoordsOut<Draw(); then h3dhit[ich]->Draw("psame");1,Rx[ich].x-1,Rx[ich].x+1,1,Rx[ich].y-1,Rx[ich].y+1,1,Rx[ich].z-1,Rx[ich].z+1); h3dhit[ich]->SetName(chname); h3dhit[ich]->SetMarkerSize(2); h3dhit[ich]->Fill(Rx[ich].x,Rx[ich].y,Rx[ich].z); h3dhit[ich]->SetMarkerColor(izcolor[ich]); if(Rx[ich].iPol==0)h3dhit[ich]->SetMarkerStyle(21); if(Rx[ich].iPol==1)h3dhit[ich]->SetMarkerStyle(20); h3dhit[ich]->Draw("psame"); } for(Int_t ich=0; ichSetStats(0); h2AzEl->Draw("colz"); c1->SaveAs("/home/dbesson/ctem/png/h2AzEl.pdf"); delete c1; sprintf(ctemp,"/home/dbesson/src/txt/Rxdt_ara0%d.txt",iStaRx); ifstream Rxdt(ctemp); Int_t kch=0; while(Rxdt>>Rx[kch].dtNsCorr>>Rx[kch].dtNsCorrSim>>Rx[kch].tResolution){ // printf("Rx[%d].dtNsCorr=%g Rx[%d].dtNsCorrSim=%g Rx[%d].tResolution=%g\n",kch,Rx[kch].dtNsCorr,kch,Rx[kch].dtNsCorrSim,kch,Rx[kch].tResolution); hRxdtns->Fill(kch,Rx[kch].dtNsCorr); hRxdtnsSim->Fill(kch,Rx[kch].dtNsCorrSim); kch++; } NRXCOORDS->Fill(xntvar); getParPairsV(); getParPairsH(); delete stationInfo; getRxArrayBounds(); } //two dipoles with cos(the) patterns: Float_t CorrRelTheR(Float_t x0, Float_t y0, Float_t z0, Float_t x1, Float_t y1, Float_t z1, Float_t &dr, Float_t &cthe){ Float_t rsq=(x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)+(z0-z1)*(z0-z1); dr=sqrt(rsq); Float_t sthe=fabs(z1-z0)/dr; cthe=1-sthe*sthe; return cthe/dr; //E~1/r; E~cthe^2 } void getRelPhiThe(const Float_t xyzA[3],const Float_t xyzB[3], Float_t &phiA2B, Float_t &theA2B){ phiA2B=atan2(xyzA[0]-xyzB[0],xyzA[1]-xyzB[1])*TMath::RadToDeg(); theA2B=TMath::RadToDeg()*acos(xyzA[2]-xyzB[2]/sqrt((xyzA[0]-xyzB[0])*(xyzA[0]-xyzB[0])+(xyzA[1]-xyzB[1])*(xyzA[1]-xyzB[1])+(xyzA[2]-xyzB[2])*(xyzA[2]-xyzB[2]))); } void getSpiceCentricxy(Float_t EastingInFt, Float_t NorthingInFt, Float_t &x2SP, Float_t &y2SP){ x2SP=0.302058067 * EastingInFt - 6719.88518; y2SP=3.28882056 * NorthingInFt + 53919.464; } void FillTxInfo(Int_t iStation, Int_t iYear){ Int_t iStaTx=iStation; if(iStation==1)iStaTx=100; if(iYear<2011)return; // printf("IC22_1450 dt(wrt ch0)[%d]=%g\n",ich,ntimexp(Rx[0].u,IC22_1450[2],d2IC22_1450[0])-ntimexp(Rx[0].u,IC22_1450[2],d2IC22_1450[0])); printf(" IC1(1450).E=%g IC1(1450).N=%g IC1(1450).z=%g d2RxCh0=%g\n IC1(2450).E=%g IC1(2450).N=%g IC1(2450).z=%g d2Rxch0=%g\n IC22(1450).E=%g IC22(1450).N=%g IC22(1450).z=%g d2Rxch0=%g\n",IC1_1450[0],IC1_1450[1],IC1_1450[2], sqrt(pow(IC1_1450[0]-Rx[0].E1,2)+pow(IC1_1450[1]-Rx[0].N1,2)+pow(IC1_1450[2]-Rx[0].u1,2)), IC1_2450[0],IC1_2450[1],IC1_2450[2], sqrt(pow(IC1_2450[0]-Rx[0].E1,2)+pow(IC1_2450[1]-Rx[0].N1,2)+pow(IC1_2450[2]-Rx[0].u1,2)), IC22_1450[0],IC22_1450[1],IC22_1450[2], sqrt(pow(IC22_1450[0]-Rx[0].E1,2)+pow(IC22_1450[1]-Rx[0].N1,2)+pow(IC22_1450[2]-Rx[0].u1,2))); // if(iStation==1){cout<<"Tx NO ARASTATION INFO!!!!"<getWindTurbine(3); AraRootGlo2ArrayLoc("Converting ICL",iStation,ICLTxXYZ[0],ICLTxXYZ[1],ICLTxXYZ[2],ICLTx.rLoc,ICLTx.phiLoc,ICLTx.theLoc); for(Int_t ich=0; ichFill(); Double_t *ICLcorner0=AraGeomPtr->getICLCorner(0); Double_t *ICLcorner1=AraGeomPtr->getICLCorner(1); Double_t *ICLcorner2=AraGeomPtr->getICLCorner(2); Double_t *ICLcorner3=AraGeomPtr->getICLCorner(3); ICLTx.xGloA=(ICLcorner0[0]+ICLcorner1[0]+ICLcorner2[0]+ICLcorner3[0])/4; ICLTx.yGloA=(ICLcorner0[1]+ICLcorner1[1]+ICLcorner2[1]+ICLcorner3[1])/4; ICLTx.zGloA=(ICLcorner0[2]+ICLcorner1[2]+ICLcorner2[2]+ICLcorner3[2])/4; AraRootGlo2ArrayLoc("Converting ICLa",iStation,ICLTx.xGloA,ICLTx.yGloA,ICLTx.zGloA,fdum,fdum1,fdum2); AraStationInfo *stationTxInfo=0; stationTxInfo=new AraStationInfo(iStaTx,abs(iYear)); // else stationTxInfo=AraGeomPtr->getStationInfo(abs(iStaTx),abs(iYear)); Int_t MCHTX=MCALTX; if(iStaTx<2)MCHTX=3; //ich=0: Antenna Info for calAntId 0: CH1 at BH5: Quad-Slot Cylinder Horizontal polarisation: dzb iTxCPCode=51 //ich=1: Antenna Info for calAntId 1: CV1 at BH5: Bicone Vertical polarisation: dzb iTxCPCode=50 //ich=2: Antenna Info for calAntId 2: CH2 at BH6: Quad-Slot Cylinder Horizontal polarisation: dzb iTxCPCode=61 //ich=3: Antenna Info for calAntId 3: CV2 at BH6: Bicone Vertical polarisation: dzb iTxCPCode=60 for(Int_t ich=0; ichgetCalAntennaInfo(ich)->printAntennaInfo(); //in AraCalAntennaInfo.h Double_t *antLocTx=stationTxInfo->getCalAntennaInfo(ich)->getLocationXYZ(); Double_t *antLocTxENU=stationTxInfo->getCalAntennaInfo(ich)->getLocationENU(); antLocTxENU[2]=antLocTx[2]; Float_t d2Tx=sqrt(antLocTx[0]*antLocTx[0]+antLocTx[1]*antLocTx[1]+antLocTx[2]*antLocTx[2]); VCPTx[ich][0]=d2Tx; VCPTx[ich][1]=atan2(antLocTx[1],antLocTx[0])*TMath::RadToDeg(); VCPTx[ich][2]=acos(antLocTx[2]/d2Tx)*TMath::RadToDeg(); CPTx[ich].phiLoc0=VCPTx[ich][1]; CPTx[ich].xLoc=antLocTx[0]-RxXYZ0[0]; CPTx[ich].yLoc=antLocTx[1]-RxXYZ0[1]; CPTx[ich].zLoc=antLocTx[2]-RxXYZ0[2]; CPTx[ich].rLoc=sqrt(CPTx[ich].xLoc*CPTx[ich].xLoc + CPTx[ich].yLoc*CPTx[ich].yLoc + CPTx[ich].zLoc*CPTx[ich].zLoc); CPTx[ich].phiLoc=atan2(CPTx[ich].yLoc,CPTx[ich].xLoc)*TMath::RadToDeg(); CPTx[ich].theLoc=acos(CPTx[ich].zLoc/CPTx[ich].rLoc)*TMath::RadToDeg(); CPTx[ich].thepLoc=ThetaPrime(CPTx[ich].rLoc,CPTx[ich].phiLoc,CPTx[ich].theLoc,RxXYZ0[2]); if(antLocTx[0]==0&&antLocTx[1]==0&&antLocTx[2]==0){CPTx[ich].xLoc=-NNN; CPTx[ich].yLoc=-NNN; CPTx[ich].zLoc=-NNN; CPTx[ich].rLoc=-NNN; CPTx[ich].phiLoc=-NNN; CPTx[ich].theLoc=-NNN; CPTx[ich].thepLoc=-NNN;} printf("Tx Pulser %d at x=%g/y=%g/z=%g phi=%g the=%g the'=%g ENU=%g/%g/%g\n\n",ich,antLocTx[0],antLocTx[1],antLocTx[2],CPTx[ich].phiLoc,CPTx[ich].theLoc,CPTx[ich].thepLoc,antLocTxENU[0],antLocTxENU[1],antLocTxENU[2]); Float_t drTx2Rx, ctheTx2Rx; for(Int_t ichRx=0; ichRxFill(xntvar); NTXCOORDSAR->Show(0); /* Int_t ichTx=0; if(iStaTx==0 && iYear==2011)ichTx=0; if(iStaTx==0 && iYear==2012)ichTx=1; if(iStaTx==0 && iYear>2012)ichTx=0; Double_t *antLocTx=stationTxInfo->getCalAntennaInfo(ichTx)->getLocationXYZ(); Double_t *antLocTxENU=stationTxInfo->getCalAntennaInfo(ichTx)->getLocationENU(); antLocTxENU[2]=antLocTx[2]; Cart2SpherDeg(antLocTxENU[0],antLocTxENU[1],antLocTxENU[2],CPTx[0].rGlo,CPTx[0].phiGlo,CPTx[0].theGlo); printf("FillTxInfo ichTx=%d / iStaTx=%d / r=%g phi=%g the=%g\n",ichTx,iStaTx,CPTx[0].rGlo,CPTx[0].phiGlo,CPTx[0].theGlo); */ delete stationTxInfo; } inline Float_t agetdt2DPExpected(Int_t iStation, Int_t ich1, Int_t ich2, Int_t iDP){ FillRxInfo(iStation,iYear0,0); FillTxInfo(iStation,0); Float_t d1=sqrt( (Rx[ich1].E-DPTx[iDP].xGlo)*(Rx[ich1].E-DPTx[iDP].xGlo)+ (Rx[ich1].N-DPTx[iDP].yGlo)*(Rx[ich1].N-DPTx[iDP].yGlo)+ (Rx[ich1].u-DPTx[iDP].zGlo)*(Rx[ich1].u-DPTx[iDP].zGlo)); Float_t t1ns=d1*1.78/sLightAir; Float_t t1nsexp=ntimexp(Rx[ich1].z,DPTx[iDP].zGlo,d1); // cout<2)printf("getdtexpected theta=%g dt0=%g ntimexp dt=%g\n",theta,dt0,ti-tj); return ti-tj; } inline void FillXCNtuple(Float_t rMagSrc){ Float_t phiVal, theVal, phiValDeg, theValDeg, xsrc, ysrc, zsrc, T1, T2; for(phiValDeg=-PHIMAXIFGZ; phiValDegFill(ich,jch,phiValDeg,90-theValDeg,getdtExpected(ich,jch,phiVal,theVal,1.78,rMagSrc)); } } } inline void FillNZIFGV(TFile *TFileOut){ TFileOut->cd(); const Float_t DTIJRESOLNS=2; char cCut[256]; TH2F *htmp=(TH2F*)hZphithe->Clone(); htmp->SetName("htmp"); //new TH2F("htmp","htmp",360,-180,180,180,-90,90); for(Int_t ich=0; ichReset(); // cout<<"Adding "<Scan("ich:jch:phi:the:dtij",cCut); // NDTIJ2PHITHEV->Draw("the:phi>>htempZ(360,-180,180,180,-90,90)",cCut,"goff"); NDTIJ2PHITHEV->Project("htmp","the:phi",cCut); if(false)htmp->Scale(fabs(SNRxc[ich][jch])); //MADE THINGS WORSE!!!! if(htmp->GetEntries()<=0)continue; // htmp->Draw("colz"); sprintf(cpngname,"$HOME/ctem/png/aaaa%d_%d.png",ich,jch); c1->SaveAs(cpngname); hZphithe->Add(htmp); hZphithe0->Add(htmp); } } delete htmp; getIFGStats(hZphithe,phiMaxZIFG,theMaxZIFG,E1ZIFG,E9ZIFG,E25ZIFG,phiMaxZIFG1,theMaxZIFG1); // printf("NAnaEvTot=%d\n",NAnaEvTot); if(NAnaEvTot<8){ TCanvas *c1=new TCanvas("c1","c1"); hZphithe->Draw("colz"); sprintf(cpngname,"$HOME/ctem/png/hZphithe%d_nHit=%d_r=%g_phiSim=%g_phiReco=%g_theSim=%g_theReco=%g.png",NAnaEvTot,nFitVtx,simVtx[0],simVtx[1],phiMaxZIFG,simVtx[2],theMaxZIFG); c1->SaveAs(cpngname); delete c1; } } inline Float_t getGloTexpected(Int_t ich, Float_t GloSrcE, Float_t GloSrcN, Float_t GloSrcZ, Float_t rindex){ Float_t dr=sqrt((GloSrcE-Rx[ich].E)*(GloSrcE-Rx[ich].E)+(GloSrcN-Rx[ich].N)*(GloSrcN-Rx[ich].N)+(GloSrcZ-Rx[ich].z)*(GloSrcZ-Rx[ich].z)); Float_t transitTime=dr*rindex/sLightAir; printf("getdtexpected ich=%d dr=%g dt=%g\n",ich,dr,transitTime); return transitTime; } inline Float_t mperns(Int_t ich, Int_t jch, Float_t dt, Float_t Tx[3], Float_t &zAvg){ Float_t dRx1ToTx, dRx2ToTx, dzRx1Rx2, thetaRx1ToTx, thetaRx2ToTx, delta, costhetaRx1Rx2, dfar, dnear; Int_t ifarRx=ich; Int_t inearRx=jch; if(dt==0)return -1; else{ dRx1ToTx=sqrt((Rx[ich].x-Tx[0])*(Rx[ich].x-Tx[0]) + (Rx[ich].y-Tx[1])*(Rx[ich].y-Tx[1]) + (Rx[ich].z-Tx[2])*(Rx[ich].z-Tx[2])); thetaRx1ToTx=acos((Rx[ich].z-Tx[2])/dRx1ToTx); dRx2ToTx=sqrt((Rx[jch].x-Tx[0])*(Rx[jch].x-Tx[0]) + (Rx[jch].y-Tx[1])*(Rx[jch].y-Tx[1]) + (Rx[jch].z-Tx[2])*(Rx[jch].z-Tx[2])); thetaRx2ToTx=acos((Rx[jch].z-Tx[2])/dRx1ToTx); dzRx1Rx2=Rx[ich].z-Rx[jch].z; costhetaRx1Rx2=0.5*(dRx1ToTx*dRx1ToTx + dRx2ToTx*dRx2ToTx - dzRx1Rx2*dzRx1Rx2)/(dRx1ToTx*dRx2ToTx); //law of cosines dfar=dRx1ToTx; dnear=dRx2ToTx; // return dzRx1Rx2*sin(0.5*(thetaRx1ToTx+thetaRx2ToTx))/dt; if(dRx2ToTx>dRx1ToTx){ ifarRx=jch; inearRx=ich; dfar=dRx2ToTx; dnear=dRx1ToTx; } delta=(Rx[ifarRx].z-Tx[2])*(dfar-dnear*costhetaRx1Rx2)/dfar; zAvg=Rx[ifarRx].z-delta/2.; // printf("dnear=%g dfar=%g costhe=%g delta=%g zAvg=%g\n",dnear,dfar,costhetaRx1Rx2,delta,zAvg); return (dRx1ToTx-dRx2ToTx)/dt; } } inline Float_t dTShiftns(float RMAG, float PHIRX, float PHISUN, float THESUN){return 1e9*RMAG*cos(PHIRX-PHISUN)*cos(THESUN)/TMath::C();} inline Bool_t LSpacePts3D(double xyz[][3]){ bool Ltest=true; for(int i=0; i<4; i++) for(int j=i+1; j<4; j++) if(xyz[i][0]==xyz[j][0] || xyz[i][1]==xyz[j][1] || xyz[i][2]==xyz[j][2]) Ltest=false; return Ltest; } inline char* datechar(){ char *dst; setlocale (LC_ALL, ""); time_t tstartrun; tstartrun = time(NULL); struct tm *tp = localtime(&tstartrun); dst=(char*)malloc(16); datestamp=(char*)malloc(21); strftime(dst,16,"%d%h%y-%H%M%S",tp); //http://www.cplusplus.com/reference/ctime/strftime/ sprintf(datestamp,"%s_%d",dst,int(gRandom->Uniform(10000))); sprintf(datestamp,"%s",dst); //,gRandom->Uniform(1000)); return datestamp; } //PG(x)=1.325+0.438*(1.-exp(0.0132*x)) - favored form for ICRC17! //time difference between two peaks in same graph inline Float_t dtpk1pk2(TGraph *gr, Int_t ndelbinsig){ TGraph *grClone=(TGraph*)gr->Clone(); Int_t ibinmax=TMath::LocMax(gr->GetN(),gr->GetY()); TGraph *grtmp=new TGraph(2*ndelbinsig,&gr->GetX()[ibinmax-ndelbinsig],&gr->GetY()[ibinmax-ndelbinsig]); for(Int_t ib=TMath::Max(0,ibinmax-ndelbinsig); ibGetN(),ibinmax+ndelbinsig); ib++) grClone->SetPoint(ib,grClone->GetX()[ib],0); TGraph *grtmp0=FFTtools::getCorrelationGraph(grtmp,grClone); Float_t ACorr=getPeakValZ(grtmp0,&ipkbin); ACorr=fabs(ACorr); Float_t deltat=grtmp0->GetX()[ipkbin]; delete grtmp; delete grClone; delete grtmp0; return -deltat; } TGraph *grShiftnbdVMax(TGraph *gr1, TGraph*gr2){ TGraph *grtmp=(TGraph*)gr1->Clone(); Int_t nbshift=FFTtools::getPeakBin(gr1)-FFTtools::getPeakBin(gr2); for(Int_t ib=nbshift; ibGetN()-nbshift; ib++)grtmp->SetPoint(ib+nbshift,gr1->GetX()[ib],gr1->GetY()[ib]); return grtmp; } Float_t aRVValVt(TGraph *gr, Int_t ind0, Int_t indf, Int_t &index){ index=0; if(ind0<=0||indf<=0||indf>=gr->GetN()||!gr||(indf-ind0)<8)return -1; TGraph *gr0=new TGraph(indf-ind0,&gr->GetX()[ind0],&gr->GetY()[ind0]); TGraph *grHE=FFTtools::getSimplePowerEnvelopeGraph(gr0); if(!grHE){ delete gr0; return -1; } Float_t VVal=TMath::MinElement(grHE->GetN(),grHE->GetY()); VVal/=TMath::Mean(grHE->GetN(),grHE->GetY()); index=TMath::LocMin(grHE->GetN(),grHE->GetY()); // Float_t V0=fabs(grHE->GetY()[0]); Float_t Vf=fabs(grHE->GetY()[grHE->GetN()-1]); Float_t Vmin=TMath::MinElement(grHE->GetN(),grHE->GetY()); if(V0+Vf>0)return Vmin*2/(V0+Vf); delete grHE; delete gr0; return VVal; // else return -NNN; } inline Float_t heff(Float_t fMHz){return 0.2/fMHz;} //https://ham.stackexchange.com/questions/11895/effective-area-of-a-dipole //take effective height as lambda/2 inline Float_t heffDipoleBoreSight(Float_t fMHz, TGraph *grReflCoeff){ Float_t wavelength=1e-6*TMath::C()/fMHz; Float_t DipoleBoresightGain=2; //3 dB in voltage Float_t TC; if(fMHzGetX()[grReflCoeff->GetN()-1])TC=sqrt(1-grReflCoeff->Eval(fMHz)*grReflCoeff->Eval(fMHz)); else TC=0; if(grReflCoeff->Eval(fMHz)<0)TC=-TC; if(LDebug&&fabs(TC)>0)printf("heffDipoleBoresightgain RC=%g fMHz=%g TC=%g heff=%g\n",grReflCoeff->Eval(fMHz),fMHz,TC,TC*(wavelength/2)*DipoleBoresightGain); return TC*(wavelength/sqrt(4*TMath::Pi()))*DipoleBoresightGain; } //need to do once for real and once for imaginary component //from TGraph *FFTtools::getInterpolatedGraphFreqDom(TGraph *grIn, Double_t deltaT) TGraph *getFilteredGraph(TGraph *grVtIn, TGraph *grRealReflCoeff, TGraph *grImagReflCoeff, Float_t deltaTnsIn, Float_t LPFMHz, Float_t HPFMHz, Float_t ScaleF, Float_t rTx2Rx, Int_t &ibinMax, Float_t &TValMax, Float_t &VValMax){ if(ScaleF>1)cout<<"SCALE FACTOR GREATER THAN 1!"<GetN(); Double_t VMaxIn=0; Double_t *tIn=grVtIn->GetX(); Double_t *vIn=grVtIn->GetY(); FFTWComplex *theFFt = FFTtools::doFFT(numIn,vIn); Int_t fftLength=(numIn/2)+1; // Int_t newFFTLength=(oldDt/deltaT)*fftLength; Int_t newFFTLength=fftLength; FFTWComplex *thePaddedFft = new FFTWComplex[newFFTLength]; Int_t numPoints=(newFFTLength-1)*2; // std::cerr << numIn << "\t" << fftLength << "\t" << newFFTLength << "\n"; Double_t scaleFactor=Double_t(numPoints)/Double_t(numIn); for(int i=0;iVMaxIn)VMaxIn=vIn[i]; // thePaddedFft[i]=theFFt[i]; Float_t fMHz=float(i)/deltaTnsIn; Float_t wavelength=1e-6*TMath::C()/fMHz; Float_t sqrt4pi=2*sqrt(TMath::Pi()); if(fMHzLPFMHz) { // if(iHPFMHz && fMHzVValMax){ VValMax=fabs(newVolts[i]); TValMax=newTimes[i]; ibinMax=i; // std::cout << i<< "\t" << newTimes[i] // << "\t" << newVolts[i] << std::endl; } } if(VValMax>VMaxIn)cout<<"HPF="<VMaxIn="<GetY(); double *oldX = grWave->GetX(); double deltaT=oldX[1]-oldX[0]; int length=grWave->GetN(); FFTWComplex *theFFT=FFTtools::doFFT(length,oldY); int newLength=(length/2)+1; // double fMax = 1/(2*deltaT); // In Hz double deltaF=1/(deltaT*length); //Hz deltaF*=1e3; //MHz // std::cout << fMax << "\t" << deltaF << "\t" << deltaT << "\t" << length << std::endl; double tempF=0; for(int i=0;iminFreq[notch] && tempFFill(ich,drdtij); fdum=nIce*fabs(dxyzRxiRxj[ich][jch]/sLightAir); //fabs(Rx[ich].HitTime-Rx[jch].HitTime)*sLightAir*0.8; if(fdum0.25)ncdtgtdr[ich]=-ncdtgtdr[ich]; } } //set up for calc_chi_square_XC void setupVtx(Bool_t LXCReco, Int_t NHighestSNRHits, Bool_t LXChanl){ // SNRVtxMin=NNN; // ichSNRVtxMin=-1; Int_t nFitVtxi=0; for(Int_t ich=0; ich=8)ihitsCodeH+=pow(10,ich-8); if(ich>7 && LDebug)printf("**** Rx[%d].HitTime=%g nhitsH=%d\n",ich,Rx[ich].HitTime,nhitsH); if(h1PThermal[ich]->Integral()==0)fdum=Rx[ich].Prms*Rx[ich].Prms; else fdum=GetxMax(h1PThermal[ich]); PGdPerCh+=(Rx[ich].Power-fdum)/fdum; TOTSumGd+=Rx[ich].TOT; if(Rx[ich].HitTime>HitTimeMax){ ichMaxHitTime=ich; HitTimeMax=Rx[ich].HitTime; } if(Rx[ich].HitTimeFill(nFitVtxi,nFitVtx); if(nFitVtx>2)cout<<"setupVtx Total of "<nhitsH&&nhitsV>3)iPolVtx=0; if(nhitsV3)iPolVtx=1; if(LDebug)printf("nhitsV=%d nhitsH=%d iPolVtx=%d\n",nhitsV,nhitsH,iPolVtx); for(Int_t ich=0; ich=0)SwitchChannelOff(ich,"Channel polarization not equal iPolVtx",0,true); } for(Int_t ich=0; ichGetEntries()/NAnaEvTot<0.5)continue; if(h1dtresid[ich]->GetEntries()<8)continue; idum=h1dtresid[ich]->GetMaximumBin(); if(fabs(h1dtresid[ich]->GetBinCenter(idum))GetRMS() %g\n",ich,h1dtresid[ich]->GetBinCenter(idum),h1dtresid[ich]->GetRMS(),MAXDTRESID); SwitchChannelOff(ich,"dtresid too large",13,true); } for(Int_t ich=NHighestSNRHits; ichSNRHITMAX)SwitchChannelOff(iptSNR[ich],"Failed SNRMAX cut",14,true); // Rx[iptSNR[ich]].LVtx=false; if(false)SwitchChannelOff(NAnaEvTot%16," randomly switching off channel for vtx studies",15,true); for(Int_t ich=0; ichcalcDeltaTInfinity(ich0, ich1, phiSrc, theSrc, iStation0); Float_t chisq01=(Rx[ich0].HitTime-Rx[ich1].HitTime-fdum1)*(Rx[ich0].HitTime-Rx[ich1].HitTime-fdum1); fdum2=AraGeomPtr->calcDeltaTInfinity(ich0, ich2, phiSrc, theSrc, iStation0); Float_t chisq02=(Rx[ich0].HitTime-Rx[ich2].HitTime-fdum2)*(Rx[ich0].HitTime-Rx[ich2].HitTime-fdum2); fdum3=AraGeomPtr->calcDeltaTInfinity(ich0, ich3, phiSrc, theSrc, iStation0); Float_t chisq03=(Rx[ich0].HitTime-Rx[ich3].HitTime-fdum3)*(Rx[ich0].HitTime-Rx[ich3].HitTime-fdum3); return chisq01*chisq01+chisq02*chisq02+chisq03*chisq03; } //weight chisquared by 1/SNR? void FindBigResid(){ Float_t tResidMag[MCH16]; Int_t index[MCH16]; Int_t ndeltHitij[MCH16]={0}; Float_t deltHitij[MCH16]={0}; TH1F *htmp=new TH1F("htmp","htmp",255,-127.5,127.5); for(Int_t ich=0; ichFill(tFitResid[ich]); for(Int_t jch=0; jch0)deltHitij[ich]/=ndeltHitij[ich]; if(deltHitij[ich]GetMean()) /htmp->GetRMS(),ichX[1],tFitResid[ichX[1]],(tFitResid[ichX[1]]-htmp->GetMean())/htmp->GetRMS()); delete htmp; } inline Float_t d12(Float_t *v0, Float_t *v1){ return sqrt((v0[0]-v1[0])*(v0[0]-v1[0]) + (v0[1]-v1[1])*(v0[1]-v1[1]) + (v0[2]-v1[2])*(v0[2]-v1[2]));} inline Float_t dotprod(float V1[3], float V2[3]){ return (V1[0]*V2[0]+V1[1]*V2[1]+V1[2]*V2[2])/(sqrt(V1[0]*V1[0]+V1[1]*V1[1]+V1[2]*V1[2])*sqrt(V2[0]*V2[0]+V2[1]*V2[1]+V2[2]*V2[2])); } void cross(double V1[3], double V2[3], double V3[3]){ V3[0] = V1[1]*V2[2] - V1[2]*V2[1]; V3[1] = V1[2]*V2[0] - V1[0]*V2[2]; V3[2] = V1[0]*V2[1] - V1[1]*V2[0]; } TGraph *grIncoherentSum(Int_t numGraphs, TGraph **grPtrPtr){ if(numGraphs<2) return NULL; TGraph *grSum=new TGraph(grPtrPtr[0]->GetN()); for(Int_t igraph=1; igraphGetN() && ibGetN(); ib++) grSum->SetPoint(ib,grPtrPtr[0]->GetX()[ib],grSum->GetY()[ib]+grPtrPtr[igraph]->GetY()[ib]); return grSum; } //CAUTION: grB is being ADDED TO!!! TGraph *grCorrAndAvg(Int_t numGraphs, TGraph **grPtrPtr){ ngrAvg=1; AXCgrAvg=0; TH1F *htmp=new TH1F("htmp","htmp",64,-258,254); TGraph *grA=(TGraph*)grPtrPtr[0]->Clone(); for(int graphNum=1;graphNumFill(dtCorrAndAvg2); } grA=grScale(grA,1./ngrAvg); AXCgrAvg/=ngrAvg; dtrmsXCgrAvg=htmp->GetRMS(); idum=htmp->GetMaximumBin(); xshiftgrAvg=htmp->GetBinCenter(idum); delete htmp; return grA; } TGraph *grCorrAndAvg2tem(TGraph *grA, TGraph *grB){ Int_t numGraphs=2; Int_t numPoints=grA->GetN(); Double_t *timeVals= grA->GetX(); Float_t timeBaseA=timeVals[1]-timeVals[0]; Double_t *safeTimeVals = new Double_t[numPoints]; Double_t *sumVolts = new Double_t [numPoints]; for(int i=0;iGetN()GetN(); if(grB->GetN()!=numPoints){ if(LDebug)printf("grA->GetN()=%d != grB->GetN()=%d\n",grA->GetN(),grB->GetN()); continue; } Float_t timeBaseB=grB->GetX()[1]-grB->GetX()[0]; if(timeBaseB!=timeBaseA){ if(LDebug)printf("timeBaseA=%g != timeBaseB=%g\n",timeBaseA,timeBaseB); continue; } TGraph *grCorAB = FFTtools::getCorrelationGraph(grA,grB); Int_t peakBin = FFTtools::getPeakBin(grCorAB); // Double_t *deltaTVals=grCorAB->GetX(); // cout << peakBin << "\t" << grCorAB->GetN() << endl; Int_t offset=peakBin-(grCorAB->GetN()/2); // cout << deltaTVals[peakBin] << "\t" << safeTimeVals[offset] << endl; Double_t *aVolts = grA->GetY(); Double_t *bVolts = grB->GetY(); for(int ind=0;ind=0 && bIndex1) delete grA; grA=grComAB; countWaves++; } for(int i=0;iGetN(); Double_t *timeVals= grA->GetX(); Float_t timeBaseA=timeVals[1]-timeVals[0]; Double_t *safeTimeVals = new Double_t[numPoints]; Double_t *sumVolts = new Double_t [numPoints]; for(int i=0;iGetN()GetN(); if(grB->GetN()!=numPoints){ if(LDebug)printf("grA->GetN()=%d != grB->GetN()=%d\n",grA->GetN(),grB->GetN()); continue; } Float_t timeBaseB=grB->GetX()[1]-grB->GetX()[0]; if(timeBaseB!=timeBaseA){ if(LDebug)printf("timeBaseA=%g != timeBaseB=%g\n",timeBaseA,timeBaseB); continue; } ngrAvg++; TGraph *grCorAB = FFTtools::getCorrelationGraph(grA,grB); Int_t peakBin = FFTtools::getPeakBin(grCorAB); // Double_t *deltaTVals=grCorAB->GetX(); // cout << peakBin << "\t" << grCorAB->GetN() << endl; Int_t offset=peakBin-(grCorAB->GetN()/2); // cout << deltaTVals[peakBin] << "\t" << safeTimeVals[offset] << endl; Double_t *aVolts = grA->GetY(); Double_t *bVolts = grB->GetY(); for(int ind=0;ind=0 && bIndex1) delete grA; grA=grComAB; countWaves++; } for(int i=0;iGetN(); ibHE+=MSAMPLE){ R=FFTtools::sumVoltageSquared(grHE,ibHE+MSAMPLE,ibHE+2*MSAMPLE)/ FFTtools::sumVoltageSquared(grHE,ibHE,ibHE+MSAMPLE); if(LDebug)printf("ibHE=%d / R=%g / R0=%g\n",ibHE,R,R0); if(R/R0>R2R0Max) R2R0Max=R/R0; if(R/R0>SlopeX){ tZ=grHE->GetX()[ibHE]; cout<<"tZ="<GetX()="<GetX()[ibHE]< Efield0 = 0.55*(1.2e-8)*0.7*-1000 = 5 uVolt signal //on C-cone float Efield0=(hf-lf)*(nu00/f0)*(1/(1+0.4*(nu00/f0)*(nu00/f0))); float expfac=exp(-.5*(pow((Tc-AngNuAnt)/Cwidth,2.))); //Vantenna here in Volts float heff=0.2; //20 cm effective height double Vantenna = par[2]*heff*Efield0*(1000/Rmag)*polfac*expfac; float delta=(Rx[irx].VMax-Vantenna)/Rx[irx].Vrms; chi=delta/Rx[irx].hitweight; chisquare+=chi*chi; ChiSqTot=chisquare; Niter++; if(fmod(Niter,200)==0) cout<<"NuMomChiSq Niter/Vrx/Vant/Niter/chisqtot/par="<vertex //xyzant: (0,0,0)->Rx //Rant: vector from vertex->Rx for(int irx=0; irxGet("eventTree"); evtree->ResetBranchAddresses(); evtree->GetEntry(ientry); if(iS==0){ evtree->SetBranchAddress("event",&rawIcrrEvPtr); realIcrrEvPtr=new UsefulIcrrStationEvent(rawIcrrEvPtr, AraCalType::kLatestCalib); unixTime=realIcrrEvPtr->head.unixTime; unixTimeUs=realIcrrEvPtr->head.unixTimeUs; trigCode=int(realIcrrEvPtr->trig.trigType); isCalPulser=realIcrrEvPtr->isCalPulserEvent(); ievt0=realIcrrEvPtr->head.eventNumber; printf("unixTime=%10d isCalPulser=%d\n",unixTime,isCalPulser); delete rawIcrrEvPtr; delete realIcrrEvPtr; } else{ evtree->SetBranchAddress("event",&rawAtriEvPtr); realAtriEvPtr = new UsefulAtriStationEvent(rawAtriEvPtr, AraCalType::kLatestCalib); unitTime==rawAtriEvPtr->unixTime; unixTimeUs=rawAtriEvPtr->unixTimeUs; ievt0=realAtriEvPtr->eventNumber; delete rawAtriEvPtr; delete realAtriEvPtr; } evtree->ResetBranchAddresses(); delete evtree; } */ inline void Drawevgr1(TGraph *gr,const char *cin, Bool_t LZoom){ // if(NDrawPngs>=MDRAWPNGS)return; NDrawPngs++; TCanvas *cgr1x1=new TCanvas("cgr1x1","cgr1x1"); getRealTime(unixTime,false); if(unixTime!=0)sprintf(cpngname,"$HOME/ctem/png/%s_ara0%d_VP=%d_VH=%d_nhitV=%d_nhitH=%d_run=%d_evt=%d_utc=%d_hr%d_min%d_sec%d.pdf",cin,iSta0,int(WfPV),int(WfPH),nhitsV,nhitsH,irunNumber,ieventNumber,utcDate,utchour,utcmin,utcsec); else sprintf(cpngname,"$HOME/ctem/png/%s.pdf",cin); gr->GetXaxis()->SetLabelSize(0.08); gr->GetYaxis()->SetLabelSize(0.08); if(LZoom){ Int_t ibinmax=TMath::LocMax(gr->GetN(),gr->GetY()); Float_t tibinmax=gr->GetX()[ibinmax]; gr->GetXaxis()->SetRangeUser(tibinmax-256,tibinmax+512); } gr->Draw("al"); cgr1x1->SaveAs(cpngname); delete cgr1x1; } inline void Drawevgr4x5(TGraph **gr, char *cin, Bool_t LFFT, TFile *rfile, Bool_t LGIF){ TGraph *gr4x5tmp[20]; // if(NDrawPngs>=MDRAWPNGS)return; NDrawPngs++; gStyle->SetTitleSize(0.08,"xyzh"); gStyle->SetLabelSize(0.08,"xyzh"); TCanvas *cgr4x5=new TCanvas("cgr4x5","cgr4x5"); if(iSta0==0||LGIF)cgr4x5->Divide(4,4,0.001,0.0015,kWhite); else cgr4x5->Divide(4,5,0.001,0.0015,kWhite); for(Int_t ich=0; ich15)continue; cgr4x5->cd(ich+1); gr4x5tmp[ich]=new TGraph(gr[ich]->GetN()); //(TGraph*)gr[ich]->Clone(); for(Int_t ipt=0; iptGetN(); ipt++)gr4x5tmp[ich]->SetPoint(ipt,gr[ich]->GetX()[ipt],gr[ich]->GetY()[ipt]); gr4x5tmp[ich]->SetNameTitle(Form("%s4x5_run%d_ev%d_ch%d",cin,irunno,ievno,ich),Form("gr4x5_run%d_ev%d_ch%d",irunno,ievno,ich)); rfile->Append(gr4x5tmp[ich]); if(ich<=7)gr4x5tmp[ich]->SetLineColor(kBlue); if(ich>7&&ich<=15)gr4x5tmp[ich]->SetLineColor(kRed); if(LFFT){ gPad->SetLogy(1); gr4x5tmp[ich]->GetXaxis()->SetRangeUser(20,800); } gPad->SetGrid(); gr4x5tmp[ich]->Draw("al"); } // TGraph *grtmp1=new TGraph(gr->GetN()/2,gr->GetX(),gr->GetY()); grtmp1->SetLineColor(kRed); // TGraph *grtmp2=new TGraph(gr->GetN()/2,&gr->GetX()[gr->GetN()/2],&gr->GetY()[gr->GetN()/2]); grtmp2->SetLineColor(kBlue); getRealTime(unixTime,false); if(unixTime!=0)sprintf(cpngname,"$HOME/ctem/png/%s_ara0%d_VP=%d_VH=%d_nhitV=%d_nhitH=%d_run=%d_evt=%d_utc=%d_hr%d_min%d_sec%d.pdf",cin,iSta0,int(WfPV),int(WfPH),nhitsV,nhitsH,irunNumber,ieventNumber,utcDate,utchour,utcmin,utcsec); else sprintf(cpngname,"%s.pdf",cin); cgr4x5->SaveAs(cpngname); if(LGIF){cgr4x5->Print(Form("/home/dbesson/ph/tem/Vtx_A%d_r%d_%d_%9.0f_%d.gif+40",iSta0,irunno,iYear0,utc000,iRanSeed0));} // cgr4x5->Print("/home/dbesson/ph/tem/VtxVtx.gif+40");} delete cgr4x5; for(Int_t ich=0; ich15)continue; delete gr4x5tmp[ich];} } void AppendTGraphs(TFile *TFilerf, TFile *TFilegr){ grSpice18LogFile->SetNameTitle("grSpice18LogFile","grSpice18LogFile"); TFilegr->Append(grSpice18LogFile); printf("fout NbytesInfo=%d fout SizeOf=%d\n",TFilegr->GetNbytesInfo(),TFilegr->Sizeof()); TFilegr->DrawMap(); cout<<"Appending TGraphs! / Averaging "<ls(); for(Int_t ich=0; ichSetNameTitle(Form("grUBFFTAvg%d_%d_%d",ich,iYear0,NEvUBCh[ich]),Form("grUBFFTAvg%d_%d_%d",ich,iYear0,NEvUBCh[ich])); TFilegr->Append(grUBFFTAvg[ich]); TFilegr->Append(grUBAvg[ich]); } AvggrCoherence(2,2); if(nEvWf>1){ cout<<"AppendTGraphs nEvWf="<GetN()=%d\n",iEvWf,grEvWf[iEvWf]->GetN()); TGraph *grEvWfAvg=FFTtools::correlateAndAverage(nEvWf,grEvWf); grEvWfAvg->SetNameTitle("grEvWf","grEvWf"); TFilegr->Append(grEvWfAvg); } for(Int_t ipol=0; ipol<2; ipol++){ // if(ipol==1){cout<<"Averaging "<SetNameTitle(Form("grEvAvg2_pol%d_%d",ipol,ich),Form("grEvAvg2_pol%d_%d",ipol,ich)); grEvAvg2[ipol][ich]->SetLineColor(izcolor[ich]); TFilegr->Append(grEvAvg2[ipol][ich]); grFFTEvAvg2[ipol][ich]=FFTtools::makePowerSpectrum(grEvAvg2[ipol][ich]); grFFTEvAvg2[ipol][ich]->SetName(Form("grFFTEvAvg2_pol%d_%d",ipol,ich)); grFFTEvAvg2[ipol][ich]->SetTitle(Form("grFFTEvAvg2_pol%d_%d",ipol,ich)); TFilegr->Append(grFFTEvAvg2[ipol][ich]); } } cout<<"AppendTGraphs grEvAvgN ipol="<SetNameTitle(Form("grEVN00f_ipol%d_%d_%d_zTx%d",ipol,ich,nEvAvg[ipol],int(abs(zTx0z))),cgrname); grEVNtmp1->SetLineColor(izcolor[ich]); TFilerf->Append(grEVNtmp1); TFilegr->Append(grEVNtmp1); // Drawevgr(grEVN[ipol],Form("grEVAvgWf_Pol%d_nEv%d",ipol,nEvAvg[ipol]),false,false,false,true); //Potential Memory Leak 27May23 if(ich<15)continue; if(false)mgrEVAvg->Add(grEVNtmp1); if(false)TFilegr->Append(mgrEVAvg); } /* TGraph *grtmp=FFTtools::getHilbertEnvelope(grEVN[ich]); Rx[ich].VMax=grMaxZ(grtmp,&idum); Rx[ich].ibnVMax=idum; Rx[ich].tNSig=gettNSig(grtmp,ich,64,Rx[ich].Prms); Rx[ich].tNSig0=gettNSig(grtmp,ich,grEVN[ich]->GetN(),Rx[ich].Prms); fdum=gettNSig(grtmp,ich,grEVN[ich]->GetN(),Rx[ich].Prms/2); Rx[ich].tSlope=tMaxSlope(grtmp,Rx[ich].ibnVMax,Rx[ich].ASlope); printf("AppendTGraphs: grEVN[%d] tNSig=%g tNSig0=%g tNSig0 (lower thresh)=%g tSlope=%g\n",ich,Rx[ich].tNSig,Rx[ich].tNSig0,fdum,Rx[ich].tSlope); if(Rx[ich].tNSig>-NNN)Rx[ich].LVtx=true; delete grtmp; */ } //calculate int(fNSigma,NNN)/integral of grUBAvg and tabulate probability as f(NSigma) cut and fit and extrapolate // Int_t NTrigChsSimV=0; Int_t NTrigChsSimH=0; Float_t fSigmaMax[16]; //, PfSigma, VTrigThresh, fNorm, fVOverThresh; for(Int_t ich=0; ich15)||NEvUBCh[ich]==0)continue; fdum=grUBAvg[ich]->GetRMS(2)/sqrt(NEvUBCh[ich]); //incoherent sum h2VrmsUBVCh->Fill(fdum,ich); cout<<"RMS grUBAvg["<GetN(); ib++)htmpV->Fill(fabs(grUBAvg[ich]->GetY()[ib]/fdum)); TFilegr->Append(htmpV); // NUBTRGSM->Fill(ich,htmpV->GetBinCenter(ib)/htmpV->GetRMS(),htmpV->Integral(ib,9999)/htmpV->Integral()); /* grUBAvg[ich]->GetN(),0,TMath::MaxElement(grUBAvg[ich]->GetN(),grUBAvg[ich]->GetY())); htmp->FillN(grUBAvg[ich]->GetN(),grUBAvg[ich]->GetX(),grUBAvg[ich]->GetY()); TH1F *htmpV=htmp->ProjectionY(); htmpV->SetNameTitle(Form("h1UBVProj%d",ich),Form("h1UBVProj%d",ich)); for(Int_t ib=0; ibGetNbinsX(); ib++)NUBTRGSM->Fill(ich,htmpV->GetBinCenter(ib)/htmpV->GetRMS(),htmpV->Integral(ib,9999)/htmpV->Integral()); */ } /* PfSigma= for(Float_t fNSigma=4; fNSigma<6; fNSigma++){ VTrigThresh=fNSigma*grUBAvg[ich]->GetRMS(2); for(Int_t ib=0; ibGetN(); ib++) grUBAvg[ich]->GetXaxis()->SetRangeUser(VTrigThresh,NNN); fdum=grUBAvg[ich]-> if(fSigmaMax>fNSigma&&Rx[ich].iPol==0)NTrigChsSimV++; if(fSigmaMax>fNSigma&&Rx[ich].iPol==1)NTrigChsSimH++; } */ grCorrAvgMaxVCh(TFilerf); Int_t ibnPkCP1Ev, ibnPkCPAvg, jbnCP1Ev, ndelbins, ndelbins1, ibnCP1Ev, fSignRan; const Int_t MBNSG=32; Float_t dACPAvgCP1Ev, fRan; cout<<"Averaging "<0; ich++){ sprintf(cgrname,"grCPAvg2M%d_%d",NEvCP,ich); if(grCPAvg2[ich]){ grCPAvg2[ich]->SetName(Form("grCPAvg2_Ch%d",ich)); grCPAvg2[ich]->SetTitle(cgrname); grCPAvg2[ich]->SetLineColor(izcolor[ich]); // TFilerf->Append(grCPAvg2[ich]); TFilegr->Append(grCPAvg2[ich]); if(false)mgrCPAvg->Add(grCPAvg2[ich]); } cout<<"Averaged grCPAvg2!"<SetNameTitle(Form("grCPAvg2_0Ch_%d",ich),Form("grCPAvg2_0M%d_%d",NEvCP,ich)); grCPAvg2_0[ich]->SetLineColor(izcolor[ich]); // TFilerf->Append(grCPAvg2_0[ich]); TFilegr->Append(grCPAvg2_0[ich]); } cout<<"Averaged grCPAvg2_0!"<GetN(),grCPN[ich]->GetY()); for(Int_t j1Ev=0; j1EvClone(); grCPMC[ich][j1Ev]->SetNameTitle(Form("grCPMC%d_%d",ich,j1Ev),Form("grCPMC%d_%d",ich,j1Ev)); for(Int_t ib=0; ibSetPointY(ib,grCPAvgN[ich][j1Ev]->GetY()[ib]); // grCPMC[ich][j1Ev]->SetPointY(ib,gRandom->Gaus(0,VrmsCh[ich])); //6Feb23 grCPMCI[ich][j1Ev]=(TGraph*)grCPMC[ich][j1Ev]->Clone(); grCPMCI[ich][j1Ev]->SetNameTitle(Form("grCPMCI_%d_%d",ich,j1Ev),Form("grCPMCI_%d_%d",ich,j1Ev)); grCPMC2I[ich][j1Ev]=(TGraph*)grCPMC[ich][j1Ev]->Clone(); grCPMC2I[ich][j1Ev]->SetNameTitle(Form("grCPMC2I_%d_%d",ich,j1Ev),Form("grCPMC2I_%d_%d",ich,j1Ev)); for(Int_t ib=ibnPkCPAvg-MBNSG; ibUniform(-1,1); fSignRan=fRan/fabs(fRan); grCPMC[ich][j1Ev]->SetPointY(ib,grCPN[ich]->GetY()[ib]+fSignRan*sqrt(fabs(grCPAvgN[ich][j1Ev]->GetY()[ibnCP1Ev]))); //gRandom->Gaus(0,sqrt(VrmsCh[ich]))); grCPMCI[ich][j1Ev]->SetPointY(ib,grCPN[ich]->GetY()[ib]+grCPAvgN[ich][j1Ev]->GetY()[ibnCP1Ev]); grCPMC2I[ich][j1Ev]->SetPointY(ib,grCPN[ich]->GetY()[ib]+2*grCPAvgN[ich][j1Ev]->GetY()[ibnCP1Ev]); } grCPMCC[ich][j1Ev]=(TGraph*)grCPMC[ich][j1Ev]->Clone(); grCPMCC[ich][j1Ev]->SetNameTitle(Form("grCPMCC_%d_%d",ich,j1Ev),Form("grCPMCC_%d_%d",ich,j1Ev)); for(Int_t ib=ibnPkCPAvg+2*MBNSG; ibGetN(); ib++){ ibnCP1Ev++; fRan=gRandom->Uniform(-1,1); fSignRan=fRan/fabs(fRan); grCPMC[ich][j1Ev]->SetPointY(ib,fSignRan*sqrt(fabs(grCPAvgN[ich][j1Ev]->GetY()[ibnCP1Ev]))); //gRandom->Gaus(0,sqrt(VrmsCh[ich]))); grCPMCI[ich][j1Ev]->SetPointY(ib,grCPAvgN[ich][j1Ev]->GetY()[ibnCP1Ev]); grCPMC2I[ich][j1Ev]->SetPointY(ib,2*grCPAvgN[ich][j1Ev]->GetY()[ibnCP1Ev]); grCPMCC[ich][j1Ev]->SetPointY(ib,sqrt(ib)); } h2delbinsVCh->Fill(grCPAvgN[ich][j1Ev]->GetN()-grCPN[ich]->GetN(),ich); if(LDebug)if(grCPAvgN[ich][j1Ev]->GetN()!=grCPN[ich]->GetN() || (grCPAvgN[ich][j1Ev]->GetX()[1]-grCPAvgN[ich][j1Ev]->GetX()[0]!=grCPN[ich]->GetX()[1]-grCPN[ich]->GetX()[0])){printf("grCPAvgN[%d][%d]->GetN()=%d / grCPN[%d]->GetN()=%d\n",ich,j1Ev,grCPAvgN[ich][j1Ev]->GetN(),ich,grCPN[ich]->GetN()); continue;} ibnPkCP1Ev=TMath::LocMax(grCPAvgN[ich][j1Ev]->GetN(),grCPAvgN[ich][j1Ev]->GetY()); Compare2Graphs(1,ich,grCPAvgN[ich][j1Ev],grCPN[ich]); /* ndelbins1=ibnPkCPAvg-ibnPkCP1Ev; //-(ibnPkCP1Ev-ibnPkCPAvg); fdum1=dtgr1gr2(grCPN[ich],grCPAvgN[ich][j1Ev],fdum,ndelbins); if(LDebug)printf("NDELBINS ndelbinspks=%d / ndelbins dtgr1gr2=%d\n",ndelbins1,ndelbins); for(Int_t ib=ibnPkCPAvg-32; ib=grCPN[ich]->GetN())continue; jbnCP1Ev=ib-ndelbins; //Avg pk at 16, 1ev pk at 8, so sum up from 8 bins earlier in 1eV graph if(jbnCP1Ev<0||jbnCP1Ev>=grCPAvgN[ich][j1Ev]->GetN())continue; dACPAvgCP1Ev=(grCPN[ich]->GetY()[ib]-grCPAvgN[ich][j1Ev]->GetY()[jbnCP1Ev])/(fabs(grCPN[ich]->GetY()[ib])+fabs(grCPAvgN[ich][j1Ev]->GetY()[jbnCP1Ev])); NCPAVG1Ev->Fill(j1Ev,ib-ibnPkCPAvg,jbnCP1Ev-ibnPkCP1Ev,ich,fdum,grCPN[ich]->GetY()[ib]/Rx[ich].Vrms,grCPAvgN[ich][j1Ev]->GetY()[jbnCP1Ev]/Rx[ich].Vrms); } */ } // sprintf(cgrname,"grCPAvg_Ch%d",ich); Float_t Vpk2pk=TMath::MaxElement(grCPN[ich]->GetN(),grCPN[ich]->GetY())-TMath::MinElement(grCPN[ich]->GetN(),grCPN[ich]->GetY()); printf("CPSNR Ch %d pk2pk=%g rms64=%g SNR=%g SNRZ=%g FFTSNR=%g\n",ich,Vpk2pk,TMath::RMS(64,grCPN[ich]->GetY()),Vpk2pk/TMath::RMS(64,grCPN[ich]->GetY()),Vpk2pk/Rx[ich].Vrms,FFTtools::getWaveformSNR(grCPN[ich])); sprintf(cgrtitle,"grCPAvgN_M%d_%d",NEvCPAvg,ich); grCPN[ich]->SetName(cgrtitle); grCPN[ich]->SetTitle(cgrtitle); grCPN[ich]->SetLineColor(izcolor[ich]); grfftCPN[ich]=FFTtools::makePowerSpectrum(grCPN[ich]); for(Int_t ipt=0; iptGetN(); ipt++)if(grfftCPN[ich]->GetY()[ipt]<1)grfftCPN[ich]->SetPointY(ipt,1); sprintf(cgrtitle,"grfftCPAvgN_M%d_%d",NEvCPAvg,ich); grfftCPN[ich]->SetName(cgrtitle); grfftCPN[ich]->SetTitle(cgrtitle); grfftCPN[ich]->SetLineColor(izcolor[ich]); for(Int_t iCPwf=0; iCPwfSetNameTitle(Form("grCPEvt%d_ch%d",iCPwf,ich),Form("grCPEvt%d_ch%d",iCPwf,ich)); TFilegr->Append(grCPAvgN[ich][iCPwf]);} TFilerf->Append(grCPN[ich]); TFilegr->Append(grfftCPN[ich]); //Now compare grCPMC waveforms: XXXX for(Int_t ievCP=0; ievCPAppend(mgrCPAvg); } if(NEvCPAvg>=2)getgrInfo(grCPN,-1); TTVHITCP->Fill(); if(NEvCPAvg>=2&&false)AvggrCoherence(1,NEvCPAvg); //or NevCPAvg-1? cout<<"Averaging surface pulsers"<SetName(cgrname); grSPN[ich]->SetTitle(cgrname); grSPN[ich]->SetLineColor(izcolor[ich]); TFilerf->Append(grSPN[ich]); if(ich<15)continue; Drawevgr(grSPN,cgrname,false,false,false,false); } } cout<<"Averaging deep pulsers"<1; ich++){ if(iSta0==0&&ich>15)continue; // for(Int_t ich=0; ich<16&&; ich++){ sprintf(cgrname,"grDPAvg2_%d_%d_%d",nDPAvg2[idp],idp,ich); cout<<"Writing "<SetName(cgrname); grDPAvg2[idp][ich]->SetTitle(cgrname); grDPAvg2[idp][ich]->SetLineColor(izcolor[ich]); TFilegr->Append(grDPAvg2[idp][ich]); } // grDPAvgN[idp][ich][0]->SetName(cgrname); grDPAvgN[idp][ich][0]->SetTitle(cgrname); TFilerf->Append(grDPAvgN[idp][ich][0]); printf("nDPEv[%d]=%d\n",idp,nDPEv[idp]); if(nDPEv[idp]<2)continue; if(false)AvggrCoherence(idp+100,nDPEv[idp]); for(Int_t ich=0; ich<16; ich++){ TGraph *grDPNtmp=FFTtools::correlateAndAverage(nDPEv[idp],grDPAvgN[idp][ich]); grDPN[ich]=grScale(grDPNtmp,1./VrmsCh[ich]); delete grDPNtmp; sprintf(cgrname,"grDPAvgM%d_%d_%d",nDPEv[idp],idp,ich); cout<<"Writing "<SetNameTitle(cgrname,cgrname); grDPN[ich]->SetLineColor(izcolor[ich]); // if(false)mgrDPAvg[idp]->Add(grDPN[ich]); TFilegr->Append(grDPN[ich]); TFilerf->Append(grDPN[ich]); } if(false)TFilerf->Append(mgrDPAvg[idp]); Drawevgr(grDPN,Form("grDPAvgWf_%d",idp),false,false,false,false); //Potential Memory Leak 27May23 // Drawevgr16(grDPN,Form("grDPAvgWf_%d",idp)); printf("Appending grDPN to grSumV!\n"); TGraph *grSumV=FFTtools::correlateAndAverage(8,grDPN); sprintf(cgrname,"grSumV_idp%d",idp); grSumV->SetName(cgrname); grSumV->SetTitle(cgrname); TFilegr->Append(grSumV); if(!grDPN[14] || !grDPN[15])continue; TGraph *grSumH=FFTtools::correlateAndAverage(8,&grDPN[8]); sprintf(cgrname,"grSumH_idp%d",idp); grSumH->SetName(cgrname); grSumH->SetTitle(cgrname); TFilegr->Append(grSumH); //25Jan21?? iDPcode=idp; getgrInfo(grDPN,-1); iDPcode=pow(10,idp); TTVHITDP->Fill(); } cout<<"Appenda dadone!"<GetEntries()<=0)delete histMapIFGV; if(histMapIFGH->GetEntries()<=0)delete histMapIFGH; // } // gDirectory->ls(); if(false)TFilegr->ls(); if(false)TFilegr->Map(); PrintEvtCuts(); for(Int_t ich=0; ich<16; ich++) for(Int_t jch=ich+1; jch<16; jch++) delete h1PkXCThermalSNR[ich][jch]; //delete NDTIJ2PHITHEV; // TFilegr->Write(); // TFilegr->Close(); } inline void getreal(TFile *ftmp, Int_t ievt, Int_t iStation, Int_t iYr){ RawIcrrStationEvent *rawIcrrEvPtrtmp; RawAtriStationEvent *rawAtriEvPtrtmp; RawAraStationEvent *rawEvPtrtmp; UsefulIcrrStationEvent *realIcrrEvPtrtmp; UsefulAtriStationEvent *realAtriEvPtrtmp; // TFile *ftmp=new TFile(cfilein); TTree *eventTreetmp=(TTree*)ftmp->Get("eventTree"); eventTreetmp->ResetBranchAddresses(); TGraph *grVttmp[MCH]; if(iStation==0) eventTreetmp->SetBranchAddress("event",&rawIcrrEvPtrtmp); else eventTreetmp->SetBranchAddress("event",&rawAtriEvPtrtmp); zerozero(); //CAUTION!!!!! eventTreetmp->GetEntry(ievt); if(iStation==0){ realIcrrEvPtrtmp=new UsefulIcrrStationEvent(rawIcrrEvPtrtmp, AraCalType::kLatestCalib); unixTime=realIcrrEvPtrtmp->head.unixTime; unixTimeUs=realIcrrEvPtrtmp->head.unixTimeUs; trigCode=int(realIcrrEvPtrtmp->trig.trigType); if(trigCode==68){LUB=true; trigCode=2;} LCP=realIcrrEvPtrtmp->isCalPulserEvent()==1; LUB=int(realIcrrEvPtrtmp->trig.trigType)==68; ieventNumber=realIcrrEvPtrtmp->head.eventNumber; } else{ realAtriEvPtrtmp=new UsefulAtriStationEvent(rawAtriEvPtrtmp, AraCalType::kLatestCalib); unixTime=realAtriEvPtrtmp->unixTime; unixTime10Ns=realAtriEvPtrtmp->timeStamp; unixTimeUs=(realAtriEvPtrtmp->timeStamp)/100; LCP=rawAtriEvPtrtmp->isCalpulserEvent(); // && rawAtriEvPtrtmp->triggerInfo[2]!=1; // cout<isCalpulserEvent()<<" "<triggerInfo[2]<triggerInfo[1]==1 || realAtriEvPtrtmp->isSoftwareTrigger(); if(LCP)trigCode=1; if(LUB)trigCode=2; ieventNumber=realAtriEvPtrtmp->eventNumber; } for(Int_t ich=0; ichgetGraphFromRFChan(ich); else grVttmp[ich]=realAtriEvPtrtmp->getGraphFromRFChan(ich); } getgrInfo(grVttmp,-1); for(Int_t ich=0; ich