- int numGraphPoints= 0;
- int TowerNum = 0;
- for (int i = 0; i < fModules; i++) {
-
- for(int ic=0;ic < fColumns;ic++){
- for(int ir=0;ir < fRows;ir++){
-
- TowerNum = GetTowerNum(i, ic, ir);
-
- // 1st: high gain
- numGraphPoints= fGraphAmpVsTimeHighGain[TowerNum]->GetN();
- if( numGraphPoints>0 || saveEmptyGraphs) {
-
- // average the graphs points over time if requested and put them in a profile plot
- if(fUseAverage && numGraphPoints>0) {
-
- // get the values
- double *graphX = fGraphAmpVsTimeHighGain[TowerNum]->GetX();
- double *graphY = fGraphAmpVsTimeHighGain[TowerNum]->GetY();
-
- // create the TProfile: 1 is for High gain
- CreateProfile(i, ic, ir, TowerNum, 1,
- numProfBins, timeMin, timeMax);
-
- // loop over graph points and fill profile
- for(int ip=0; ip < numGraphPoints; ip++){
- fProfAmpVsTimeHighGain[TowerNum]->Fill(graphX[ip],graphY[ip]);
- }
-
- fProfAmpVsTimeHighGain[TowerNum]->GetXaxis()->SetTitle("Hours");
- fProfAmpVsTimeHighGain[TowerNum]->GetYaxis()->SetTitle("MaxAmplitude - Pedestal");
- fProfAmpVsTimeHighGain[TowerNum]->Write();
-
- }
- else{
- //otherwise, just save the graphs and forget the profiling
- fGraphAmpVsTimeHighGain[TowerNum]->GetXaxis()->SetTitle("Hours");
- fGraphAmpVsTimeHighGain[TowerNum]->GetYaxis()->SetTitle("MaxAmplitude - Pedestal");
- fGraphAmpVsTimeHighGain[TowerNum]->Write();
- }
-
- } // low gain graph info should be saved in one form or another
-
- // 2nd: now go to the low gain case
- numGraphPoints= fGraphAmpVsTimeLowGain[TowerNum]->GetN();
- if( numGraphPoints>0 || saveEmptyGraphs) {
-
- // average the graphs points over time if requested and put them in a profile plot
- if(fUseAverage && numGraphPoints>0) {
-
- double *graphX = fGraphAmpVsTimeLowGain[TowerNum]->GetX();
- double *graphY = fGraphAmpVsTimeLowGain[TowerNum]->GetY();
-
- // create the TProfile: 0 is for Low gain
- CreateProfile(i, ic, ir, TowerNum, 0,
- numProfBins, timeMin, timeMax);
-
- // loop over graph points and fill profile
- for(int ip=0; ip < numGraphPoints; ip++){
- fProfAmpVsTimeLowGain[TowerNum]->Fill(graphX[ip],graphY[ip]);
- }
-
- fProfAmpVsTimeLowGain[TowerNum]->GetXaxis()->SetTitle("Hours");
- fProfAmpVsTimeLowGain[TowerNum]->GetYaxis()->SetTitle("MaxAmplitude - Pedestal");
- fProfAmpVsTimeLowGain[TowerNum]->Write();
-
- }
- else{
- //otherwise, just save the graphs and forget the profiling
- fGraphAmpVsTimeLowGain[TowerNum]->GetXaxis()->SetTitle("Hours");
- fGraphAmpVsTimeLowGain[TowerNum]->GetYaxis()->SetTitle("MaxAmplitude - Pedestal");
- fGraphAmpVsTimeLowGain[TowerNum]->Write();
- }
-
- } // low gain graph info should be saved in one form or another
-
- } // fRows
- } // fColumns
-
- } // fModules
- destFile.Close();
-
+ // re-associating the branch addresses here seems to be needed for OK 'average' storage
+ fTreeAvgAmpVsTime->SetBranchAddress("fChannelNum", &fChannelNum);
+ fTreeAvgAmpVsTime->SetBranchAddress("fHour", &fHour);
+ fTreeAvgAmpVsTime->SetBranchAddress("fAvgAmp", &fAvgAmp);
+ fTreeAvgAmpVsTime->SetBranchAddress("fRMS", &fRMS);
+
+ //3: fill avg tree by looping over the profiles
+ for (fChannelNum = 0; fChannelNum<(fgkMaxTowers*2); fChannelNum++) {
+ if (profile[fChannelNum]) { // profile was created
+ if (profile[fChannelNum]->GetEntries() > 0) { // profile had some entries
+ for(int it=0; it<numProfBins; it++) {
+ if (profile[fChannelNum]->GetBinEntries(it+1) > 0) {
+ fAvgAmp = profile[fChannelNum]->GetBinContent(it+1);
+ fHour = profile[fChannelNum]->GetBinCenter(it+1);
+ fRMS = profile[fChannelNum]->GetBinError(it+1);
+ fTreeAvgAmpVsTime->Fill();
+ } // some entries for this bin
+ } // loop over bins
+ } // some entries for this profile
+ } // profile exists
+ } // loop over all possible channels
+
+
+ // and finally, go through same exercise for LED also..
+
+ //1: set up TProfiles for the towers that had data
+ TProfile * profileLED[fgkMaxRefs*2]; // *2 is since we include both high and low gains
+ memset(profileLED, 0, sizeof(profileLED));
+
+ for (int i = 0; i<fModules; i++) {
+ for(int j=0; j<fLEDRefs; j++){
+ for (int gain=0; gain<2; gain++) {
+ fRefNum = GetRefNum(i, j, gain);
+ if (fNRef[fRefNum] > 0) {
+ sprintf(name, "profileLEDRef%d", fRefNum);
+ profileLED[fRefNum] = new TProfile(name, name, numProfBins, timeMin, timeMax, "s");
+ }
+ }// gain
+ }
+ } // modules
+
+ //2: fill profiles by looping over tree
+ // Set addresses for tree-readback also
+ fTreeLEDAmpVsTime->SetBranchAddress("fRefNum", &fRefNum);
+ fTreeLEDAmpVsTime->SetBranchAddress("fHour", &fHour);
+ fTreeLEDAmpVsTime->SetBranchAddress("fAmp", &fAmp);
+
+ for (int ient=0; ient<fTreeLEDAmpVsTime->GetEntries(); ient++) {
+ fTreeLEDAmpVsTime->GetEntry(ient);
+ if (profileLED[fRefNum]) {
+ // profile should always have been created above, for active channels
+ profileLED[fRefNum]->Fill(fHour, fAmp);
+ }
+ }
+
+ // re-associating the branch addresses here seems to be needed for OK 'average' storage
+ fTreeLEDAvgAmpVsTime->SetBranchAddress("fRefNum", &fRefNum);
+ fTreeLEDAvgAmpVsTime->SetBranchAddress("fHour", &fHour);
+ fTreeLEDAvgAmpVsTime->SetBranchAddress("fAvgAmp", &fAvgAmp);
+ fTreeLEDAvgAmpVsTime->SetBranchAddress("fRMS", &fRMS);
+
+ //3: fill avg tree by looping over the profiles
+ for (fRefNum = 0; fRefNum<(fgkMaxRefs*2); fRefNum++) {
+ if (profileLED[fRefNum]) { // profile was created
+ if (profileLED[fRefNum]->GetEntries() > 0) { // profile had some entries
+ for(int it=0; it<numProfBins; it++) {
+ if (profileLED[fRefNum]->GetBinEntries(it+1) > 0) {
+ fAvgAmp = profileLED[fRefNum]->GetBinContent(it+1);
+ fHour = profileLED[fRefNum]->GetBinCenter(it+1);
+ fRMS = profileLED[fRefNum]->GetBinError(it+1);
+ fTreeLEDAvgAmpVsTime->Fill();
+ } // some entries for this bin
+ } // loop over bins
+ } // some entries for this profile
+ } // profile exists
+ } // loop over all possible channels
+
+ // OK, we're done..
+