data analysis scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

989 lines
32 KiB

  1. //////////////////////////////////////////////////////////
  2. // This class has been automatically generated on
  3. // Tue Sep 12 15:40:57 2017 by ROOT version 5.34/32
  4. // from TTree t/t
  5. // found on file: ../../HIT_26-11-2016/with_timestamp/pin/PiN_run1.root
  6. //////////////////////////////////////////////////////////
  7. #ifndef analyse2_h
  8. #define analyse2_h
  9. #include <TROOT.h>
  10. #include <TChain.h>
  11. #include <TFile.h>
  12. #include <TTree.h>
  13. #include <stdio.h>
  14. #include <TH2D.h>
  15. #include <TH1D.h>
  16. #include <TProfile.h>
  17. #include <TCanvas.h>
  18. #include <TF1.h>
  19. #include <TMath.h>
  20. #include <vector>
  21. #include <utility>
  22. #include <TString.h>
  23. #include <TDirectory.h>
  24. #include <TString.h>
  25. #include <TVectorD.h>
  26. #include <TGraph.h>
  27. #include <TGraphErrors.h>
  28. #include <cmath>
  29. #include <TPaveStats.h>
  30. #include <TText.h>
  31. #include <TStyle.h>
  32. #include <TObjArray.h>
  33. #include <TLegend.h>
  34. #include <TFitResult.h>
  35. #include <gsl/gsl_statistics.h>
  36. #include <math.h>
  37. #include <gsl/gsl_errno.h>
  38. #include <gsl/gsl_fft_complex.h>
  39. using namespace std;
  40. // Header file for the classes stored in the TTree if any.
  41. // Fixed size dimensions of array or collections stored in the TTree if any.
  42. class analyse2 {
  43. public :
  44. TTree *fChain; //!pointer to the analyzed TTree or TChain
  45. Int_t fCurrent; //!current Tree number in a TChain
  46. TTree *data;
  47. TTree *newdata;
  48. // Declaration of leaf types
  49. Double_t time;
  50. Double_t event_id;
  51. Double_t sync_out;
  52. Double_t sync_in;
  53. Double_t data_ok;
  54. Double_t led_voltage;
  55. Double_t current;
  56. Double_t ch00;
  57. Double_t ch01;
  58. Double_t ch02;
  59. Double_t ch03;
  60. Double_t ch04;
  61. Double_t ch05;
  62. Double_t ch06;
  63. Double_t ch07;
  64. Double_t ch08;
  65. Double_t ch09;
  66. Double_t ch10;
  67. Double_t ch11;
  68. Double_t ch12;
  69. Double_t ch13;
  70. Double_t ch14;
  71. Double_t ch15;
  72. Double_t ch16;
  73. Double_t ch17;
  74. Double_t ch18;
  75. Double_t ch19;
  76. Double_t ch20;
  77. Double_t ch21;
  78. Double_t ch22;
  79. Double_t ch23;
  80. Double_t ch24;
  81. Double_t ch25;
  82. Double_t ch26;
  83. Double_t ch27;
  84. Double_t ch28;
  85. Double_t ch29;
  86. Double_t ch30;
  87. Double_t ch31;
  88. Double_t ch32;
  89. Double_t ch33;
  90. Double_t ch34;
  91. Double_t ch35;
  92. Double_t ch36;
  93. Double_t ch37;
  94. Double_t ch38;
  95. Double_t ch39;
  96. Double_t ch40;
  97. Double_t ch41;
  98. Double_t ch42;
  99. Double_t ch43;
  100. Double_t ch44;
  101. Double_t ch45;
  102. Double_t ch46;
  103. Double_t ch47;
  104. Double_t ch48;
  105. Double_t ch49;
  106. Double_t ch50;
  107. Double_t ch51;
  108. Double_t ch52;
  109. Double_t ch53;
  110. Double_t ch54;
  111. Double_t ch55;
  112. Double_t ch56;
  113. Double_t ch57;
  114. Double_t ch58;
  115. Double_t ch59;
  116. Double_t ch60;
  117. Double_t ch61;
  118. Double_t ch62;
  119. Double_t ch63;
  120. Double_t ch64;
  121. Double_t ch65;
  122. Double_t ch66;
  123. Double_t ch67;
  124. Double_t ch68;
  125. Double_t ch69;
  126. Double_t ch70;
  127. Double_t ch71;
  128. Double_t ch72;
  129. Double_t ch73;
  130. Double_t ch74;
  131. Double_t ch75;
  132. Double_t ch76;
  133. Double_t ch77;
  134. Double_t ch78;
  135. Double_t ch79;
  136. Double_t ch80;
  137. Double_t ch81;
  138. Double_t ch82;
  139. Double_t ch83;
  140. Double_t ch84;
  141. Double_t ch85;
  142. Double_t ch86;
  143. Double_t ch87;
  144. Double_t ch88;
  145. Double_t ch89;
  146. Double_t ch90;
  147. Double_t ch91;
  148. Double_t ch92;
  149. Double_t ch93;
  150. Double_t ch94;
  151. Double_t ch95;
  152. Double_t ch96;
  153. Double_t ch97;
  154. Double_t ch98;
  155. Double_t ch99;
  156. Double_t ch100;
  157. Double_t ch101;
  158. Double_t ch102;
  159. Double_t ch103;
  160. Double_t ch104;
  161. Double_t ch105;
  162. Double_t ch106;
  163. Double_t ch107;
  164. Double_t ch108;
  165. Double_t ch109;
  166. Double_t ch110;
  167. Double_t ch111;
  168. Double_t ch112;
  169. Double_t ch113;
  170. Double_t ch114;
  171. Double_t ch115;
  172. Double_t ch116;
  173. Double_t ch117;
  174. Double_t ch118;
  175. Double_t ch119;
  176. Double_t ch120;
  177. Double_t ch121;
  178. Double_t ch122;
  179. Double_t ch123;
  180. Double_t ch124;
  181. Double_t ch125;
  182. Double_t ch126;
  183. Double_t ch127;
  184. Double_t ic1;
  185. Double_t ic2;
  186. Double_t mw1_focusx;
  187. Double_t mw1_focusy;
  188. Double_t mw2_focusx;
  189. Double_t mw2_focusy;
  190. Double_t mw1_posx;
  191. Double_t mw1_posy;
  192. Double_t mw2_posx;
  193. Double_t mw2_posy;
  194. // List of branches
  195. TBranch *b_time; //!
  196. TBranch *b_event_id; //!
  197. TBranch *b_sync_out; //!
  198. TBranch *b_sync_in; //!
  199. TBranch *b_data_ok; //!
  200. TBranch *b_led_voltage; //!
  201. TBranch *b_current; //!
  202. TBranch *b_ch00; //!
  203. TBranch *b_ch01; //!
  204. TBranch *b_ch02; //!
  205. TBranch *b_ch03; //!
  206. TBranch *b_ch04; //!
  207. TBranch *b_ch05; //!
  208. TBranch *b_ch06; //!
  209. TBranch *b_ch07; //!
  210. TBranch *b_ch08; //!
  211. TBranch *b_ch09; //!
  212. TBranch *b_ch10; //!
  213. TBranch *b_ch11; //!
  214. TBranch *b_ch12; //!
  215. TBranch *b_ch13; //!
  216. TBranch *b_ch14; //!
  217. TBranch *b_ch15; //!
  218. TBranch *b_ch16; //!
  219. TBranch *b_ch17; //!
  220. TBranch *b_ch18; //!
  221. TBranch *b_ch19; //!
  222. TBranch *b_ch20; //!
  223. TBranch *b_ch21; //!
  224. TBranch *b_ch22; //!
  225. TBranch *b_ch23; //!
  226. TBranch *b_ch24; //!
  227. TBranch *b_ch25; //!
  228. TBranch *b_ch26; //!
  229. TBranch *b_ch27; //!
  230. TBranch *b_ch28; //!
  231. TBranch *b_ch29; //!
  232. TBranch *b_ch30; //!
  233. TBranch *b_ch31; //!
  234. TBranch *b_ch32; //!
  235. TBranch *b_ch33; //!
  236. TBranch *b_ch34; //!
  237. TBranch *b_ch35; //!
  238. TBranch *b_ch36; //!
  239. TBranch *b_ch37; //!
  240. TBranch *b_ch38; //!
  241. TBranch *b_ch39; //!
  242. TBranch *b_ch40; //!
  243. TBranch *b_ch41; //!
  244. TBranch *b_ch42; //!
  245. TBranch *b_ch43; //!
  246. TBranch *b_ch44; //!
  247. TBranch *b_ch45; //!
  248. TBranch *b_ch46; //!
  249. TBranch *b_ch47; //!
  250. TBranch *b_ch48; //!
  251. TBranch *b_ch49; //!
  252. TBranch *b_ch50; //!
  253. TBranch *b_ch51; //!
  254. TBranch *b_ch52; //!
  255. TBranch *b_ch53; //!
  256. TBranch *b_ch54; //!
  257. TBranch *b_ch55; //!
  258. TBranch *b_ch56; //!
  259. TBranch *b_ch57; //!
  260. TBranch *b_ch58; //!
  261. TBranch *b_ch59; //!
  262. TBranch *b_ch60; //!
  263. TBranch *b_ch61; //!
  264. TBranch *b_ch62; //!
  265. TBranch *b_ch63; //!
  266. TBranch *b_ch64; //!
  267. TBranch *b_ch65; //!
  268. TBranch *b_ch66; //!
  269. TBranch *b_ch67; //!
  270. TBranch *b_ch68; //!
  271. TBranch *b_ch69; //!
  272. TBranch *b_ch70; //!
  273. TBranch *b_ch71; //!
  274. TBranch *b_ch72; //!
  275. TBranch *b_ch73; //!
  276. TBranch *b_ch74; //!
  277. TBranch *b_ch75; //!
  278. TBranch *b_ch76; //!
  279. TBranch *b_ch77; //!
  280. TBranch *b_ch78; //!
  281. TBranch *b_ch79; //!
  282. TBranch *b_ch80; //!
  283. TBranch *b_ch81; //!
  284. TBranch *b_ch82; //!
  285. TBranch *b_ch83; //!
  286. TBranch *b_ch84; //!
  287. TBranch *b_ch85; //!
  288. TBranch *b_ch86; //!
  289. TBranch *b_ch87; //!
  290. TBranch *b_ch88; //!
  291. TBranch *b_ch89; //!
  292. TBranch *b_ch90; //!
  293. TBranch *b_ch91; //!
  294. TBranch *b_ch92; //!
  295. TBranch *b_ch93; //!
  296. TBranch *b_ch94; //!
  297. TBranch *b_ch95; //!
  298. TBranch *b_ch96; //!
  299. TBranch *b_ch97; //!
  300. TBranch *b_ch98; //!
  301. TBranch *b_ch99; //!
  302. TBranch *b_ch100; //!
  303. TBranch *b_ch101; //!
  304. TBranch *b_ch102; //!
  305. TBranch *b_ch103; //!
  306. TBranch *b_ch104; //!
  307. TBranch *b_ch105; //!
  308. TBranch *b_ch106; //!
  309. TBranch *b_ch107; //!
  310. TBranch *b_ch108; //!
  311. TBranch *b_ch109; //!
  312. TBranch *b_ch110; //!
  313. TBranch *b_ch111; //!
  314. TBranch *b_ch112; //!
  315. TBranch *b_ch113; //!
  316. TBranch *b_ch114; //!
  317. TBranch *b_ch115; //!
  318. TBranch *b_ch116; //!
  319. TBranch *b_ch117; //!
  320. TBranch *b_ch118; //!
  321. TBranch *b_ch119; //!
  322. TBranch *b_ch120; //!
  323. TBranch *b_ch121; //!
  324. TBranch *b_ch122; //!
  325. TBranch *b_ch123; //!
  326. TBranch *b_ch124; //!
  327. TBranch *b_ch125; //!
  328. TBranch *b_ch126; //!
  329. TBranch *b_ch127; //!
  330. TBranch *b_ic1; //!
  331. TBranch *b_ic2; //!
  332. TBranch *b_mw1_focusx; //!
  333. TBranch *b_mw1_focusy; //!
  334. TBranch *b_mw2_focusx; //!
  335. TBranch *b_mw2_focusy; //!
  336. TBranch *b_mw1_posx; //!
  337. TBranch *b_mw1_posy; //!
  338. TBranch *b_mw2_posx; //!
  339. TBranch *b_mw2_posy; //!
  340. char *file;
  341. TFile *fileIn;
  342. TFile *fileOut;
  343. TObjArray objectArray;
  344. TBranch *b_channels[128];
  345. TBranch *b_baseline[128];
  346. double channels[128];
  347. double channelamp_smooth[128];
  348. double baseline[128];
  349. double channellist[128];
  350. double errorx[128];
  351. double errory[128];
  352. TBranch *b_beamNumX_1;
  353. TBranch *b_beamPosX_1;
  354. TBranch *b_beamFocusX_1;
  355. TBranch *b_beamSignal_1;
  356. TBranch *b_beamSidebandNoise_1;
  357. TBranch *b_beamSkewX_1;
  358. TBranch *b_beamKurtX_1;
  359. TBranch *b_beamPosX_fit;
  360. TBranch *b_beamFocusX_fit;
  361. TBranch *b_beamChi2_fit;
  362. TBranch *b_beamPeakX_fit;
  363. TBranch *b_beamPosX_fit2;
  364. TBranch *b_beamFocusX_fit2;
  365. TBranch *b_beamChi2_fit2;
  366. TBranch *b_beamPeakX_fit2;
  367. TBranch *b_ic1_1; //!
  368. TBranch *b_ic2_1; //!
  369. TBranch *b_mw1_focusx_1; //!
  370. TBranch *b_mw1_focusy_1; //!
  371. TBranch *b_mw2_focusx_1; //!
  372. TBranch *b_mw2_focusy_1; //!
  373. TBranch *b_mw1_posx_1; //!
  374. TBranch *b_mw1_posy_1; //!
  375. TBranch *b_mw2_posx_1; //!
  376. TBranch *b_mw2_posy_1; //!
  377. TBranch *b_baseline_integral;
  378. TBranch *b_time_1; //!
  379. TBranch *b_eventid_1; //!
  380. TBranch *b_rollingavg; //!
  381. TBranch *b_beamon; //!
  382. double time_1;
  383. double ic1_1;
  384. double ic2_1;
  385. double mw1_focusx_1;
  386. double mw2_focusx_1;
  387. double mw2_posx_1;
  388. double mw1_posx_1;
  389. double mw1_focusy_1;
  390. double mw2_focusy_1;
  391. double mw2_posy_1;
  392. double mw1_posy_1;
  393. double beamNumX_1;
  394. double beamPosX_1;
  395. double beamFocusX_1;
  396. double beamSignal_1;
  397. double beamSidebandNoise_1;
  398. double beamSkewX_1;
  399. double beamKurtX_1;
  400. double baseline_integral;
  401. double chargeintegral;
  402. double timeintegral;
  403. double eventid_1;
  404. double rollingavg;
  405. int beamon;
  406. double beamPosX_fit;
  407. double beamFocusX_fit;
  408. double beamChi2_fit;
  409. double beamPeakX_fit;
  410. double beamPosX_fit2;
  411. double beamFocusX_fit2;
  412. double beamChi2_fit2;
  413. double beamPeakX_fit2;
  414. analyse2(TTree *tree=0);
  415. virtual ~analyse2();
  416. virtual Int_t Cut(Long64_t entry);
  417. virtual Int_t GetEntry(Long64_t entry);
  418. virtual Long64_t LoadTree(Long64_t entry);
  419. virtual void Init(TTree *tree);
  420. virtual void Loop();
  421. virtual Bool_t Notify();
  422. virtual void Show(Long64_t entry = -1);
  423. double channelWidth;
  424. void Initialize(const char *dirname, const char *filename, int baselineEvents = 1000, int prelimEvents = 10000, double beamLevel = 0.1, bool firstFibermat = true, double readOutFrequency = 1000., int integrationTime = 100);
  425. void Baseline(bool useFirstEvents, int nBaselineEvents, int StartEvent, bool run50hz);
  426. void Save();
  427. void Close();
  428. double * FFTsmoothing(double arr[]);
  429. // double RollingAverage(const int length, double newdata);
  430. TH2D * th2d_mw1_beamPosX;
  431. TH2D * th2d_ic1_beamSignal;
  432. TH1D * th1d_beamSignal_ic1ratio;
  433. TH2D * th2d_beamSignal_channel;
  434. TH2D * th2d_bkg_channel;
  435. TH1D * th1d_baseline;
  436. TH1D * th1d_baselinesub;
  437. TH1D * th1d_chbaseline;
  438. TH1D * th1d_chbaselinesub;
  439. TH2D * th2d_fitdiff_channel;
  440. TH2D * th2d_fit2diff_channel;
  441. TH2D * th2d_AmpFFT_channel;
  442. TH2D * th2d_PhaseFFT_channel;
  443. TFitResultPtr bkgfitResult;
  444. Double_t bkgfitPar0[130];
  445. Double_t bkgfitPar1[130];
  446. Double_t bkgfitPar2[130];
  447. Double_t bkgfitPar3[130];
  448. Double_t bkgfitPar4[130];
  449. };
  450. #endif
  451. #ifdef analyse2_cxx
  452. analyse2::analyse2(TTree *tree) : fChain(0)
  453. {
  454. // if parameter tree is not specified (or zero), connect the file
  455. // used to generate this class and read the Tree.
  456. if (tree == 0) {
  457. cerr << "no TTree found." << endl;
  458. }
  459. Init(tree);
  460. }
  461. analyse2::~analyse2()
  462. {
  463. if (!fChain) return;
  464. delete fChain->GetCurrentFile();
  465. }
  466. Int_t analyse2::GetEntry(Long64_t entry)
  467. {
  468. // Read contents of entry.
  469. if (!fChain) return 0;
  470. return fChain->GetEntry(entry);
  471. }
  472. Long64_t analyse2::LoadTree(Long64_t entry)
  473. {
  474. // Set the environment to read one entry
  475. if (!fChain) return -5;
  476. Long64_t centry = fChain->LoadTree(entry);
  477. if (centry < 0) return centry;
  478. if (fChain->GetTreeNumber() != fCurrent) {
  479. fCurrent = fChain->GetTreeNumber();
  480. Notify();
  481. }
  482. return centry;
  483. }
  484. void analyse2::Init(TTree *tree)
  485. {
  486. // The Init() function is called when the selector needs to initialize
  487. // a new tree or chain. Typically here the branch addresses and branch
  488. // pointers of the tree will be set.
  489. // It is normally not necessary to make changes to the generated
  490. // code, but the routine can be extended by the user if needed.
  491. // Init() will be called many times when running on PROOF
  492. // (once per file to be processed).
  493. // Set branch addresses and branch pointers
  494. if (!tree) return;
  495. fChain = tree;
  496. fCurrent = -1;
  497. fChain->SetMakeClass(1);
  498. fChain->SetBranchAddress("time", &time, &b_time);
  499. fChain->SetBranchAddress("event_id", &event_id, &b_event_id);
  500. fChain->SetBranchAddress("sync_out", &sync_out, &b_sync_out);
  501. fChain->SetBranchAddress("sync_in", &sync_in, &b_sync_in);
  502. fChain->SetBranchAddress("data_ok", &data_ok, &b_data_ok);
  503. fChain->SetBranchAddress("led_voltage", &led_voltage, &b_led_voltage);
  504. fChain->SetBranchAddress("current", &current, &b_current);
  505. fChain->SetBranchAddress("ch00", &ch00, &b_ch00);
  506. fChain->SetBranchAddress("ch01", &ch01, &b_ch01);
  507. fChain->SetBranchAddress("ch02", &ch02, &b_ch02);
  508. fChain->SetBranchAddress("ch03", &ch03, &b_ch03);
  509. fChain->SetBranchAddress("ch04", &ch04, &b_ch04);
  510. fChain->SetBranchAddress("ch05", &ch05, &b_ch05);
  511. fChain->SetBranchAddress("ch06", &ch06, &b_ch06);
  512. fChain->SetBranchAddress("ch07", &ch07, &b_ch07);
  513. fChain->SetBranchAddress("ch08", &ch08, &b_ch08);
  514. fChain->SetBranchAddress("ch09", &ch09, &b_ch09);
  515. fChain->SetBranchAddress("ch10", &ch10, &b_ch10);
  516. fChain->SetBranchAddress("ch11", &ch11, &b_ch11);
  517. fChain->SetBranchAddress("ch12", &ch12, &b_ch12);
  518. fChain->SetBranchAddress("ch13", &ch13, &b_ch13);
  519. fChain->SetBranchAddress("ch14", &ch14, &b_ch14);
  520. fChain->SetBranchAddress("ch15", &ch15, &b_ch15);
  521. fChain->SetBranchAddress("ch16", &ch16, &b_ch16);
  522. fChain->SetBranchAddress("ch17", &ch17, &b_ch17);
  523. fChain->SetBranchAddress("ch18", &ch18, &b_ch18);
  524. fChain->SetBranchAddress("ch19", &ch19, &b_ch19);
  525. fChain->SetBranchAddress("ch20", &ch20, &b_ch20);
  526. fChain->SetBranchAddress("ch21", &ch21, &b_ch21);
  527. fChain->SetBranchAddress("ch22", &ch22, &b_ch22);
  528. fChain->SetBranchAddress("ch23", &ch23, &b_ch23);
  529. fChain->SetBranchAddress("ch24", &ch24, &b_ch24);
  530. fChain->SetBranchAddress("ch25", &ch25, &b_ch25);
  531. fChain->SetBranchAddress("ch26", &ch26, &b_ch26);
  532. fChain->SetBranchAddress("ch27", &ch27, &b_ch27);
  533. fChain->SetBranchAddress("ch28", &ch28, &b_ch28);
  534. fChain->SetBranchAddress("ch29", &ch29, &b_ch29);
  535. fChain->SetBranchAddress("ch30", &ch30, &b_ch30);
  536. fChain->SetBranchAddress("ch31", &ch31, &b_ch31);
  537. fChain->SetBranchAddress("ch32", &ch32, &b_ch32);
  538. fChain->SetBranchAddress("ch33", &ch33, &b_ch33);
  539. fChain->SetBranchAddress("ch34", &ch34, &b_ch34);
  540. fChain->SetBranchAddress("ch35", &ch35, &b_ch35);
  541. fChain->SetBranchAddress("ch36", &ch36, &b_ch36);
  542. fChain->SetBranchAddress("ch37", &ch37, &b_ch37);
  543. fChain->SetBranchAddress("ch38", &ch38, &b_ch38);
  544. fChain->SetBranchAddress("ch39", &ch39, &b_ch39);
  545. fChain->SetBranchAddress("ch40", &ch40, &b_ch40);
  546. fChain->SetBranchAddress("ch41", &ch41, &b_ch41);
  547. fChain->SetBranchAddress("ch42", &ch42, &b_ch42);
  548. fChain->SetBranchAddress("ch43", &ch43, &b_ch43);
  549. fChain->SetBranchAddress("ch44", &ch44, &b_ch44);
  550. fChain->SetBranchAddress("ch45", &ch45, &b_ch45);
  551. fChain->SetBranchAddress("ch46", &ch46, &b_ch46);
  552. fChain->SetBranchAddress("ch47", &ch47, &b_ch47);
  553. fChain->SetBranchAddress("ch48", &ch48, &b_ch48);
  554. fChain->SetBranchAddress("ch49", &ch49, &b_ch49);
  555. fChain->SetBranchAddress("ch50", &ch50, &b_ch50);
  556. fChain->SetBranchAddress("ch51", &ch51, &b_ch51);
  557. fChain->SetBranchAddress("ch52", &ch52, &b_ch52);
  558. fChain->SetBranchAddress("ch53", &ch53, &b_ch53);
  559. fChain->SetBranchAddress("ch54", &ch54, &b_ch54);
  560. fChain->SetBranchAddress("ch55", &ch55, &b_ch55);
  561. fChain->SetBranchAddress("ch56", &ch56, &b_ch56);
  562. fChain->SetBranchAddress("ch57", &ch57, &b_ch57);
  563. fChain->SetBranchAddress("ch58", &ch58, &b_ch58);
  564. fChain->SetBranchAddress("ch59", &ch59, &b_ch59);
  565. fChain->SetBranchAddress("ch60", &ch60, &b_ch60);
  566. fChain->SetBranchAddress("ch61", &ch61, &b_ch61);
  567. fChain->SetBranchAddress("ch62", &ch62, &b_ch62);
  568. fChain->SetBranchAddress("ch63", &ch63, &b_ch63);
  569. fChain->SetBranchAddress("ch64", &ch64, &b_ch64);
  570. fChain->SetBranchAddress("ch65", &ch65, &b_ch65);
  571. fChain->SetBranchAddress("ch66", &ch66, &b_ch66);
  572. fChain->SetBranchAddress("ch67", &ch67, &b_ch67);
  573. fChain->SetBranchAddress("ch68", &ch68, &b_ch68);
  574. fChain->SetBranchAddress("ch69", &ch69, &b_ch69);
  575. fChain->SetBranchAddress("ch70", &ch70, &b_ch70);
  576. fChain->SetBranchAddress("ch71", &ch71, &b_ch71);
  577. fChain->SetBranchAddress("ch72", &ch72, &b_ch72);
  578. fChain->SetBranchAddress("ch73", &ch73, &b_ch73);
  579. fChain->SetBranchAddress("ch74", &ch74, &b_ch74);
  580. fChain->SetBranchAddress("ch75", &ch75, &b_ch75);
  581. fChain->SetBranchAddress("ch76", &ch76, &b_ch76);
  582. fChain->SetBranchAddress("ch77", &ch77, &b_ch77);
  583. fChain->SetBranchAddress("ch78", &ch78, &b_ch78);
  584. fChain->SetBranchAddress("ch79", &ch79, &b_ch79);
  585. fChain->SetBranchAddress("ch80", &ch80, &b_ch80);
  586. fChain->SetBranchAddress("ch81", &ch81, &b_ch81);
  587. fChain->SetBranchAddress("ch82", &ch82, &b_ch82);
  588. fChain->SetBranchAddress("ch83", &ch83, &b_ch83);
  589. fChain->SetBranchAddress("ch84", &ch84, &b_ch84);
  590. fChain->SetBranchAddress("ch85", &ch85, &b_ch85);
  591. fChain->SetBranchAddress("ch86", &ch86, &b_ch86);
  592. fChain->SetBranchAddress("ch87", &ch87, &b_ch87);
  593. fChain->SetBranchAddress("ch88", &ch88, &b_ch88);
  594. fChain->SetBranchAddress("ch89", &ch89, &b_ch89);
  595. fChain->SetBranchAddress("ch90", &ch90, &b_ch90);
  596. fChain->SetBranchAddress("ch91", &ch91, &b_ch91);
  597. fChain->SetBranchAddress("ch92", &ch92, &b_ch92);
  598. fChain->SetBranchAddress("ch93", &ch93, &b_ch93);
  599. fChain->SetBranchAddress("ch94", &ch94, &b_ch94);
  600. fChain->SetBranchAddress("ch95", &ch95, &b_ch95);
  601. fChain->SetBranchAddress("ch96", &ch96, &b_ch96);
  602. fChain->SetBranchAddress("ch97", &ch97, &b_ch97);
  603. fChain->SetBranchAddress("ch98", &ch98, &b_ch98);
  604. fChain->SetBranchAddress("ch99", &ch99, &b_ch99);
  605. fChain->SetBranchAddress("ch100", &ch100, &b_ch100);
  606. fChain->SetBranchAddress("ch101", &ch101, &b_ch101);
  607. fChain->SetBranchAddress("ch102", &ch102, &b_ch102);
  608. fChain->SetBranchAddress("ch103", &ch103, &b_ch103);
  609. fChain->SetBranchAddress("ch104", &ch104, &b_ch104);
  610. fChain->SetBranchAddress("ch105", &ch105, &b_ch105);
  611. fChain->SetBranchAddress("ch106", &ch106, &b_ch106);
  612. fChain->SetBranchAddress("ch107", &ch107, &b_ch107);
  613. fChain->SetBranchAddress("ch108", &ch108, &b_ch108);
  614. fChain->SetBranchAddress("ch109", &ch109, &b_ch109);
  615. fChain->SetBranchAddress("ch110", &ch110, &b_ch110);
  616. fChain->SetBranchAddress("ch111", &ch111, &b_ch111);
  617. fChain->SetBranchAddress("ch112", &ch112, &b_ch112);
  618. fChain->SetBranchAddress("ch113", &ch113, &b_ch113);
  619. fChain->SetBranchAddress("ch114", &ch114, &b_ch114);
  620. fChain->SetBranchAddress("ch115", &ch115, &b_ch115);
  621. fChain->SetBranchAddress("ch116", &ch116, &b_ch116);
  622. fChain->SetBranchAddress("ch117", &ch117, &b_ch117);
  623. fChain->SetBranchAddress("ch118", &ch118, &b_ch118);
  624. fChain->SetBranchAddress("ch119", &ch119, &b_ch119);
  625. fChain->SetBranchAddress("ch120", &ch120, &b_ch120);
  626. fChain->SetBranchAddress("ch121", &ch121, &b_ch121);
  627. fChain->SetBranchAddress("ch122", &ch122, &b_ch122);
  628. fChain->SetBranchAddress("ch123", &ch123, &b_ch123);
  629. fChain->SetBranchAddress("ch124", &ch124, &b_ch124);
  630. fChain->SetBranchAddress("ch125", &ch125, &b_ch125);
  631. fChain->SetBranchAddress("ch126", &ch126, &b_ch126);
  632. fChain->SetBranchAddress("ch127", &ch127, &b_ch127);
  633. fChain->SetBranchAddress("ic1", &ic1, &b_ic1);
  634. fChain->SetBranchAddress("ic2", &ic2, &b_ic2);
  635. fChain->SetBranchAddress("mw1_focusx", &mw1_focusx, &b_mw1_focusx);
  636. fChain->SetBranchAddress("mw1_focusy", &mw1_focusy, &b_mw1_focusy);
  637. fChain->SetBranchAddress("mw2_focusx", &mw2_focusx, &b_mw2_focusx);
  638. fChain->SetBranchAddress("mw2_focusy", &mw2_focusy, &b_mw2_focusy);
  639. fChain->SetBranchAddress("mw1_posx", &mw1_posx, &b_mw1_posx);
  640. fChain->SetBranchAddress("mw1_posy", &mw1_posy, &b_mw1_posy);
  641. fChain->SetBranchAddress("mw2_posx", &mw2_posx, &b_mw2_posx);
  642. fChain->SetBranchAddress("mw2_posy", &mw2_posy, &b_mw2_posy);
  643. // v->ResizeTo(10);
  644. Notify();
  645. }
  646. Bool_t analyse2::Notify()
  647. {
  648. // The Notify() function is called when a new file is opened. This
  649. // can be either for a new TTree in a TChain or when when a new TTree
  650. // is started when using PROOF. It is normally not necessary to make changes
  651. // to the generated code, but the routine can be extended by the
  652. // user if needed. The return value is currently not used.
  653. return kTRUE;
  654. }
  655. void analyse2::Show(Long64_t entry)
  656. {
  657. // Print contents of entry.
  658. // If entry is not specified, print current entry
  659. if (!fChain) return;
  660. fChain->Show(entry);
  661. }
  662. Int_t analyse2::Cut(Long64_t entry)
  663. {
  664. // This function may be called from Loop.
  665. // returns 1 if entry is accepted.
  666. // returns -1 otherwise.
  667. return 1;
  668. }
  669. void analyse2::Initialize(const char *dirname, const char *filename, int baselineEvents, int prelimEvents, double beamLevel, bool firstFibermat, double readOutFrequency, int integrationTime)
  670. {
  671. TString fn = TString(filename);
  672. TString dn = TString(dirname);
  673. channelWidth = 0.8;
  674. TString inName = dn + "pin/" + fn;
  675. fileIn = new TFile(inName, "READ");
  676. fileIn->GetObject("t", fChain);
  677. fChain->Print();
  678. Init(fChain);
  679. TString outname = filename;
  680. outname.Insert(0, "SAVE_");
  681. outname.Insert(0, dirname);
  682. fileOut = new TFile(outname.Data(), "RECREATE");
  683. newdata = new TTree("newdata", "newdata");
  684. for (int n = 0; n < 128; n++)
  685. {
  686. baseline[n] = 0.;
  687. channellist[n] = double(n);
  688. errorx[n] = 0.0;
  689. errory[n] = 7.0;
  690. char bname[20];
  691. sprintf(bname, "ch%02d", n);
  692. b_channels[n] = fChain->GetBranch(bname);
  693. b_channels[n]->SetAddress(&channels[n]);
  694. }
  695. b_eventid_1 = newdata->Branch("eventid_1", &eventid_1);
  696. b_beamNumX_1 = newdata->Branch("beamNumX_1", &beamNumX_1);
  697. b_beamPosX_1 = newdata->Branch("beamPosX_1", &beamPosX_1);
  698. b_beamFocusX_1 = newdata->Branch("beamFocusX_1", &beamFocusX_1);
  699. b_beamSignal_1 = newdata->Branch("beamSignal_1", &beamSignal_1);
  700. b_beamSidebandNoise_1 = newdata->Branch("beamSidebandNoise_1", &beamSidebandNoise_1);
  701. b_beamSkewX_1 = newdata->Branch("beamSkewX_1", &beamSkewX_1);
  702. b_beamKurtX_1 = newdata->Branch("beamKurtX_1", &beamKurtX_1);
  703. b_beamPosX_fit = newdata->Branch("beamPosX_fit", &beamPosX_fit);
  704. b_beamFocusX_fit = newdata->Branch("beamFocusX_fit", &beamFocusX_fit);
  705. b_beamChi2_fit = newdata->Branch("beamChi2_fit", &beamChi2_fit);
  706. b_beamPeakX_fit = newdata->Branch("beamPeakX_fit", &beamPeakX_fit);
  707. b_beamPosX_fit2 = newdata->Branch("beamPosX_fit2", &beamPosX_fit2);
  708. b_beamFocusX_fit2 = newdata->Branch("beamFocusX_fit2", &beamFocusX_fit2);
  709. b_beamChi2_fit2 = newdata->Branch("beamChi2_fit2", &beamChi2_fit2);
  710. b_beamPeakX_fit2 = newdata->Branch("beamPeakX_fit2", &beamPeakX_fit2);
  711. b_ic1_1 = newdata->Branch("ic1_1", &ic1_1);
  712. b_ic2_1 = newdata->Branch("ic2_1", &ic2_1);
  713. b_mw1_focusx_1 = newdata->Branch("mw1_focusx_1", &mw1_focusx_1);
  714. b_mw1_posx_1 = newdata->Branch("mw1_posx_1", &mw1_posx_1);
  715. b_mw2_focusx_1 = newdata->Branch("mw2_focusx_1", &mw2_focusx_1);
  716. b_mw2_posx_1 = newdata->Branch("mw2_posx_1", &mw2_posx_1);
  717. b_mw1_focusy_1 = newdata->Branch("mw1_focusy_1", &mw1_focusy_1);
  718. b_mw1_posy_1 = newdata->Branch("mw1_posy_1", &mw1_posy_1);
  719. b_mw2_focusy_1 = newdata->Branch("mw2_focusy_1", &mw2_focusy_1);
  720. b_mw2_posy_1 = newdata->Branch("mw2_posy_1", &mw2_posy_1);
  721. b_rollingavg = newdata->Branch("rollingavg", &rollingavg);
  722. b_beamon = newdata->Branch("beamon", &beamon);
  723. b_time_1 = newdata->Branch("time_1", &time_1);
  724. //histograms;
  725. th2d_mw1_beamPosX = new TH2D("th2d_mw1_beamPosX","th2d_mw1_beamPosX",1000,0,64,1000,0,60);
  726. th2d_ic1_beamSignal = new TH2D("th2d_ic1_beamSignal","th2d_ic1_beamSignal",500,0,500,500,0,100000);
  727. th1d_beamSignal_ic1ratio = new TH1D("th1d_beamSignal_ic1ratio","th1d_beamSignal_ic1ratio",500,0,500.);
  728. th2d_beamSignal_channel = new TH2D("th2d_beamSignal_channel","th2d_beamSignal_channel",129,-0.5,128.5,5100,-1000,10000);
  729. th2d_fitdiff_channel = new TH2D("th2d_fitdiff_channel","th2d_fitdiff_channel",129,-0.5,128.5,510,-1000,1000);
  730. th2d_fit2diff_channel = new TH2D("th2d_fit2diff_channel","th2d_fit2diff_channel",129,-0.5,128.5,510,-1000,1000);
  731. th2d_bkg_channel = new TH2D("th2d_bkg_channel","th2d_bkg_channel",65,-0.5,64.5,500,-500,500);
  732. th1d_baseline = new TH1D("th1d_baseline","th1d_baseline",500,-1500,1500.);
  733. th1d_baselinesub = new TH1D("th1d_baselinesub","th1d_baselinesub",500,-1500,1500.);
  734. th1d_chbaseline = new TH1D("th1d_chbaseline","th1d_chbaseline",2100,-100,1000.);
  735. th1d_chbaselinesub = new TH1D("th1d_chbaselinesub","th1d_chbaselinesub",200,-100,100.);
  736. }
  737. void analyse2::Baseline(bool useFirstEvents, const int nBaselineEvents, int startevent, bool run50hz)
  738. {
  739. Long64_t nevents = fChain->GetEntriesFast();
  740. baseline_integral = 0.;
  741. // use the first/last nBaselineEvents events to calculate the average/baseline
  742. cout << "Start background subtraction event:" << startevent << endl;
  743. const int numbaseline = 1800;
  744. Double_t channelamp[numbaseline];
  745. Double_t basetime[numbaseline] = {0.};
  746. TGraph * g1;
  747. TF1 * fitfunc = new TF1("fitfunc","[0]+[1]*TMath::Cos(x*[2]*(2*3.14159)+[3])");
  748. fitfunc->SetParameters( 0.0, 10.0, 0.05, 0.0 );
  749. fitfunc->FixParameter(2,0.05);
  750. fChain->GetEvent(1);
  751. Double_t basetimeoffsetzero = time;
  752. fChain->GetEvent(startevent+numbaseline);
  753. Double_t basetimeoffset = time-basetimeoffsetzero;
  754. fChain->GetEvent(startevent);
  755. Double_t basetimeoffsetstart = time-basetimeoffsetzero;
  756. Int_t counter = 0;
  757. char bname[20];
  758. for (int ch = 0; ch < 128; ch++)
  759. {
  760. baseline[ch] =0.;
  761. }
  762. if (!useFirstEvents)
  763. { // last
  764. for (int i = nevents- numbaseline; i < nevents; i++)
  765. {
  766. fChain->GetEvent(i);
  767. for (int ch = 0; ch < 128; ch++)
  768. {
  769. if (channels[ch]>-100) baseline[ch] += channels[ch] / double(numbaseline);
  770. if (channels[ch]>-100) baseline_integral +=baseline[ch];
  771. th1d_chbaseline->Fill(channels[ch]);
  772. }
  773. }
  774. // cout << "baseline int: " << baseline_integral << endl;
  775. }
  776. else
  777. {
  778. for (int i = startevent ; i <= startevent+ numbaseline; i++)
  779. {
  780. fChain->GetEvent(i);
  781. for (int ch = 0; ch < 128; ch++)
  782. {
  783. if (channels[ch]>-100) baseline[ch] += channels[ch] / double(numbaseline);
  784. if (channels[ch]>-100) baseline_integral +=baseline[ch];
  785. th1d_chbaseline->Fill(channels[ch]);
  786. }
  787. // cout << "baseline int: " << baseline_integral << endl;
  788. }
  789. }
  790. if (run50hz){
  791. ///fit a 50Hz background noise to each channel
  792. for (int ch = 0; ch < 128; ch++)
  793. {
  794. counter = 0;
  795. for (int i = startevent ; i < startevent+numbaseline; i++)
  796. {
  797. fChain->GetEvent(i);
  798. // for (int ch = 0; ch < 64; ch++)
  799. //{
  800. channelamp[counter]= channels[ch]- baseline[ch];
  801. //}
  802. basetime[counter] = time-basetimeoffsetzero;
  803. counter++;
  804. }
  805. g1 = new TGraph(numbaseline,basetime,channelamp);
  806. ///////finished here. 1) need to fit the baseline to a Cosine function 2) return 3 parameters per channel. 50 Hz is fixed.
  807. bkgfitResult = g1->Fit(fitfunc,"QSR","",basetimeoffsetstart,basetimeoffset );
  808. bkgfitPar0[ch] = bkgfitResult->Parameter(0);
  809. bkgfitPar1[ch] = bkgfitResult->Parameter(1);
  810. bkgfitPar2[ch] = bkgfitResult->Parameter(2);
  811. bkgfitPar3[ch] = bkgfitResult->Parameter(3);
  812. sprintf(bname, "bkg_ch%02d_graph", ch);
  813. g1->SetTitle(bname);
  814. g1->SetName(bname);
  815. //fitResult->Print("V");
  816. // bkgfitResult->Write();
  817. g1->Write();
  818. } //end for (int ch = ...
  819. for (int ch = 0; ch < 128; ch++)
  820. {
  821. counter = 0;
  822. fitfunc->SetParameters( bkgfitPar0[ch], bkgfitPar1[ch], bkgfitPar2[ch], bkgfitPar3[ch]);
  823. for (Long64_t i = startevent ; i <startevent+ numbaseline; i++)
  824. {
  825. fChain->GetEvent(i);
  826. channelamp[counter] = channels[ch]- baseline[ch]- fitfunc->Eval(time-basetimeoffsetzero);
  827. th1d_chbaselinesub->Fill(channelamp[counter]);
  828. counter++;
  829. th2d_bkg_channel->Fill(ch,channelamp[counter]);
  830. }
  831. }
  832. Double_t channelampsum[numbaseline] = {0.};
  833. counter = 0;
  834. ///fit a 50Hz background noise to the sum of all channels
  835. for (Long64_t i = startevent ; i <startevent+ numbaseline; i++)
  836. {
  837. fChain->GetEvent(i);
  838. channelampsum[counter]=0.;
  839. for (int ch = 0; ch < 128; ch++){
  840. if (channels[ch]>-100 && baseline[ch]>-100) channelampsum[counter] += channels[ch] - baseline[ch]; //integrate the signal
  841. }
  842. basetime[counter] = (time-basetimeoffsetzero);
  843. counter++;
  844. }
  845. TGraph * g2 = new TGraph(counter,basetime,channelampsum);
  846. TF1 * fitfunc2 = new TF1("fitfunc2","[0]+[1]*TMath::Cos(x*[2]*(2*3.14159)+[3])");
  847. fitfunc2->SetParameters( 5120.0, 450.0, 0.05, 0.0 );
  848. // fitfunc2->SetParLimits(1,0.,1000.);
  849. fitfunc2->FixParameter(2,0.05);
  850. TFitResultPtr sumbkgfitResult = g2->Fit(fitfunc2,"QRS","", basetimeoffsetstart, basetimeoffset);
  851. g2->SetName("commonmodenoise"); g2->SetTitle("commonmodenoise");
  852. // g2->Write();
  853. sumbkgfitResult->Write();
  854. // fitfunc2->Write();
  855. bkgfitPar0[128] = fitfunc2->GetParameter(0);
  856. bkgfitPar1[128] = fitfunc2->GetParameter(1);
  857. bkgfitPar2[128] = fitfunc2->GetParameter(2);
  858. bkgfitPar3[128] = fitfunc2->GetParameter(3);
  859. counter=0;
  860. for (Long64_t i = startevent ; i <startevent+ numbaseline; i++)
  861. {
  862. fChain->GetEvent(i);
  863. channelampsum[counter] -= fitfunc2->Eval(time-basetimeoffsetzero);
  864. th1d_baselinesub->Fill(channelampsum[counter]);
  865. counter++;
  866. }
  867. th1d_baseline->Write();
  868. th1d_baselinesub->Write();
  869. th1d_chbaseline->Write();
  870. th1d_chbaselinesub->Write();
  871. TGraph * g3 = new TGraph(counter,basetime,channelampsum);
  872. g3->SetName("commonmodenoisesub"); g2->SetTitle("commonmodenoisesub");
  873. g3->Write();
  874. }
  875. }
  876. void analyse2::Save()
  877. {
  878. //fileIn->Close();
  879. //fileOut->cd();
  880. newdata->AutoSave();
  881. }
  882. void analyse2::Close()
  883. {
  884. fileIn->Close();
  885. fileOut->Close();
  886. if(fChain) delete fChain->GetCurrentFile();
  887. }
  888. #endif // #ifdef analyse2_cxx