34 #include "TPostScript.h"
42 cout <<
"[DTNoiseComputation]: Constructor" << endl;
56 theNewFile =
new TFile(newRootFileName.c_str(),
"RECREATE");
69 string CheckHistoName;
72 TH1F *hAverageNoiseHisto;
73 TH1F *hAverageNoiseIntegratedHisto;
74 TH1F *hAverageNoiseHistoPerCh;
75 TH1F *hAverageNoiseIntegratedHistoPerCh;
79 string AverageNoiseName;
80 string AverageNoiseIntegratedName;
81 string AverageNoiseNamePerCh;
82 string AverageNoiseIntegratedNamePerCh;
87 vector<const DTChamber *>::const_iterator ch_it = dtGeom->chambers().begin();
88 vector<const DTChamber *>::const_iterator ch_end = dtGeom->chambers().end();
90 for (; ch_it != ch_end; ++ch_it) {
92 vector<const DTSuperLayer *>::const_iterator sl_it = (*ch_it)->superLayers().begin();
93 vector<const DTSuperLayer *>::const_iterator sl_end = (*ch_it)->superLayers().end();
95 for (; sl_it != sl_end; ++sl_it) {
97 vector<const DTLayer *>::const_iterator l_it = (*sl_it)->layers().begin();
98 vector<const DTLayer *>::const_iterator l_end = (*sl_it)->layers().end();
100 for (; l_it != l_end; ++l_it) {
105 CheckHistoName =
"DigiOccupancy_" + getLayerName(dtLId);
106 TH1F *hCheckHisto = (TH1F *)
theFile->Get(CheckHistoName.c_str());
112 if (someHowNoisyC.find(make_pair(ch.
wheel(), ch.
station())) == someHowNoisyC.end()) {
113 TString histoName_someHowNoisy =
"somehowNoisyCell_W" +
wheel +
"_St" +
station;
115 new TH1F(histoName_someHowNoisy, histoName_someHowNoisy, getMaxNumBins(ch), 1, getMaxNumBins(ch) + 1);
116 someHowNoisyC[make_pair(ch.
wheel(), ch.
station())] = hsomeHowNoisyC;
119 if (noisyC.find(make_pair(ch.
wheel(), ch.
station())) == noisyC.end()) {
120 TString histoName_noisy =
"noisyCell_W" +
wheel +
"_St" +
station;
121 hnoisyC =
new TH1F(histoName_noisy, histoName_noisy, getMaxNumBins(ch), 1, getMaxNumBins(ch) + 1);
126 if (AvNoisePerSuperLayer.find(dtLId.
superlayerId()) == AvNoisePerSuperLayer.end()) {
127 AverageNoiseName =
"AverageNoise_" + getSuperLayerName(dtLId.
superlayerId());
128 hAverageNoiseHisto =
new TH1F(AverageNoiseName.c_str(), AverageNoiseName.c_str(), 200, 0, 10000);
129 AverageNoiseIntegratedName =
"AverageNoiseIntegrated_" + getSuperLayerName(dtLId.
superlayerId());
130 hAverageNoiseIntegratedHisto =
131 new TH1F(AverageNoiseIntegratedName.c_str(), AverageNoiseIntegratedName.c_str(), 200, 0, 10000);
132 AvNoisePerSuperLayer[dtLId.
superlayerId()] = hAverageNoiseHisto;
133 AvNoiseIntegratedPerSuperLayer[dtLId.
superlayerId()] = hAverageNoiseIntegratedHisto;
135 cout <<
" New Average Noise Histo per SuperLayer : " << hAverageNoiseHisto->GetName() << endl;
136 cout <<
" New Average Noise Integrated Histo per SuperLayer : " << hAverageNoiseHisto->GetName()
141 AverageNoiseNamePerCh =
"AverageNoise_" + getChamberName(dtLId);
142 hAverageNoiseHistoPerCh =
143 new TH1F(AverageNoiseNamePerCh.c_str(), AverageNoiseNamePerCh.c_str(), 200, 0, 10000);
144 AverageNoiseIntegratedNamePerCh =
"AverageNoiseIntegrated_" + getChamberName(dtLId);
145 hAverageNoiseIntegratedHistoPerCh =
new TH1F(
146 AverageNoiseIntegratedNamePerCh.c_str(), AverageNoiseIntegratedNamePerCh.c_str(), 200, 0, 10000);
150 cout <<
" New Average Noise Histo per chamber : " << hAverageNoiseHistoPerCh->GetName() << endl;
153 HistoName =
"DigiOccupancy_" + getLayerName(dtLId);
156 int numBin = hOccHisto->GetXaxis()->GetNbins();
157 for (
int bin = 1;
bin <= numBin;
bin++) {
159 theAverageNoise[wireID] = hOccHisto->GetBinContent(
bin);
160 if (theAverageNoise[wireID] != 0) {
161 AvNoisePerSuperLayer[dtLId.
superlayerId()]->Fill(theAverageNoise[wireID]);
169 HistoName =
"DigiOccupancy_" + getLayerName(dtLId);
172 numBin = hOccHisto->GetXaxis()->GetNbins();
173 for (
int bin = 1;
bin <= numBin;
bin++) {
175 theAverageNoise[wireID] = hOccHisto->GetBinContent(
bin);
176 if (hOccHisto->GetBinContent(
bin) < 100) {
178 AvNoise += hOccHisto->GetBinContent(
bin);
180 if (hOccHisto->GetBinContent(
bin) > 100 && hOccHisto->GetBinContent(
bin) < 500) {
182 cout <<
"filling somehow noisy cell" << endl;
184 if (hOccHisto->GetBinContent(
bin) > 500) {
186 cout <<
"filling noisy cell" << endl;
189 AvNoise = AvNoise / numCell;
190 cout <<
"theAverageNoise for layer " << getLayerName(dtLId) <<
" is : " << AvNoise << endl;
194 for (
int evt = 0; evt < updates; evt++) {
195 Histo2Name =
"DigiPerWirePerEvent_" + getLayerName(dtLId) +
"_" + std::to_string(evt);
197 hEvtHisto = (TH2F *)
theFile->Get(Histo2Name.c_str());
200 cout <<
" New Histo with the number of events per evt per wire: " << hEvtHisto->GetName() << endl;
201 theEvtMap[dtLId].push_back(hEvtHisto);
215 cout <<
"[DTNoiseComputation] endjob called!" << endl;
216 TH1F *hEvtDistance =
nullptr;
217 TF1 *ExpoFit =
new TF1(
"ExpoFit",
"expo", 0.5, 1000.5);
218 ExpoFit->SetMarkerColor();
219 TProfile *theNoiseHisto =
new TProfile(
"theNoiseHisto",
"Time Constant versus Average Noise", 100000, 0, 100000);
222 for (
map<
DTLayerId, vector<TH2F *> >::const_iterator lHisto = theEvtMap.begin(); lHisto != theEvtMap.end();
224 for (
int bin = 1;
bin < (*lHisto).second[0]->GetYaxis()->GetNbins();
bin++) {
227 for (
int i = 0;
i <
int((*lHisto).second.size());
i++) {
228 for (
int evt = 1; evt <= (*lHisto).second[
i]->GetXaxis()->GetNbins(); evt++) {
229 if ((*lHisto).second[
i]->GetBinContent(evt,
bin) == 0)
232 if (toDel.find(wire) == toDel.end()) {
234 string Histo =
"EvtDistancePerWire_" + getLayerName((*lHisto).first) +
"_" + std::to_string(
bin);
235 hEvtDistance =
new TH1F(Histo.c_str(), Histo.c_str(), 50000, 0.5, 50000.5);
237 hEvtDistance->Fill(distanceEvt);
242 if (toDel.find(wire) != toDel.end()) {
243 theHistoEvtDistancePerWire[wire] = hEvtDistance;
245 theHistoEvtDistancePerWire[wire]->Fit(
"ExpoFit",
"R");
246 TF1 *
funct = theHistoEvtDistancePerWire[wire]->GetFunction(
"ExpoFit");
250 double chi2rid =
funct->GetChisquare() /
funct->GetNDF();
252 theTimeConstant[wire] = 1;
254 theTimeConstant[wire] =
par1;
256 theHistoEvtDistancePerWire[wire]->Write();
264 for (map<DTWireId, double>::const_iterator AvNoise = theAverageNoise.begin(); AvNoise != theAverageNoise.end();
267 theNoiseHisto->Fill((*AvNoise).second, theTimeConstant[wire]);
268 cout <<
"Layer: " << getLayerName(wire.layerId()) <<
" wire: " << wire.wire() << endl;
269 cout <<
"The Average noise: " << (*AvNoise).second << endl;
270 cout <<
"The time constant: " << theTimeConstant[wire] << endl;
273 theNoiseHisto->Write();
278 double integratedNoise,
bin, halfBin,
maxBin;
279 for (map<DTSuperLayerId, TH1F *>::const_iterator AvNoiseHisto = AvNoisePerSuperLayer.begin();
280 AvNoiseHisto != AvNoisePerSuperLayer.end();
283 numBin = (*AvNoiseHisto).second->GetXaxis()->GetNbins();
284 maxBin = (*AvNoiseHisto).second->GetXaxis()->GetXmax();
286 halfBin = double(
bin / 2);
288 (*AvNoiseHisto).second->Write();
289 for (
int i = 1;
i < numBin;
i++) {
290 integratedNoise += (*AvNoiseHisto).second->GetBinContent(
i);
291 AvNoiseIntegratedPerSuperLayer[(*AvNoiseHisto).first]->Fill(halfBin, integratedNoise);
295 AvNoiseIntegratedPerSuperLayer[(*AvNoiseHisto).first]->Write();
298 for (map<DTChamberId, TH1F *>::const_iterator AvNoiseHisto = AvNoisePerChamber.begin();
299 AvNoiseHisto != AvNoisePerChamber.end();
302 numBin = (*AvNoiseHisto).second->GetXaxis()->GetNbins();
303 maxBin = (*AvNoiseHisto).second->GetXaxis()->GetXmax();
307 (*AvNoiseHisto).second->Write();
308 for (
int i = 1;
i < numBin;
i++) {
309 integratedNoise += (*AvNoiseHisto).second->GetBinContent(
i);
310 AvNoiseIntegratedPerChamber[(*AvNoiseHisto).first]->Fill(halfBin, integratedNoise);
314 AvNoiseIntegratedPerChamber[(*AvNoiseHisto).first]->Write();
319 vector<const DTChamber *>::const_iterator chamber_it = dtGeom->chambers().begin();
320 vector<const DTChamber *>::const_iterator chamber_end = dtGeom->chambers().end();
322 for (; chamber_it != chamber_end; ++chamber_it) {
323 vector<const DTSuperLayer *>::const_iterator sl_it = (*chamber_it)->superLayers().begin();
324 vector<const DTSuperLayer *>::const_iterator sl_end = (*chamber_it)->superLayers().end();
326 for (; sl_it != sl_end; ++sl_it) {
328 vector<const DTLayer *>::const_iterator l_it = (*sl_it)->layers().begin();
329 vector<const DTLayer *>::const_iterator l_end = (*sl_it)->layers().end();
331 string canvasName =
"c" + getSuperLayerName(sl);
332 TCanvas
c1(canvasName.c_str(), canvasName.c_str(), 600, 780);
333 TLegend *leg =
new TLegend(0.5, 0.6, 0.7, 0.8);
334 for (; l_it != l_end; ++l_it) {
336 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
340 string TitleHisto =
"AverageNoise_" + getSuperLayerName(sl);
341 cout <<
"TitleHisto : " << TitleHisto << endl;
342 hOccHisto->SetTitle(TitleHisto.c_str());
343 string legendHisto =
"layer " + std::to_string(layerId.
layer());
344 leg->AddEntry(hOccHisto, legendHisto.c_str(),
"L");
345 hOccHisto->SetMaximum(getYMaximum(sl));
347 if (layerId.
layer() == 1)
350 hOccHisto->Draw(
"same");
351 hOccHisto->SetLineColor(layerId.
layer());
364 for (
map<pair<int, int>, TH1F *>::const_iterator nCell = noisyC.begin(); nCell != noisyC.end(); ++nCell) {
366 (*nCell).second->Write();
368 for (
map<pair<int, int>, TH1F *>::const_iterator somehownCell = someHowNoisyC.begin();
369 somehownCell != someHowNoisyC.end();
372 (*somehownCell).second->Write();
384 string layerName =
"W" + std::to_string(dtChId.
wheel()) +
"_St" + std::to_string(dtChId.
station()) +
"_Sec" +
385 std::to_string(dtChId.
sector()) +
"_SL" + std::to_string(dtSLId.
superlayer()) +
"_L" +
386 std::to_string(lId.
layer());
394 string superLayerName =
"W" + std::to_string(dtChId.
wheel()) +
"_St" + std::to_string(dtChId.
station()) +
"_Sec" +
395 std::to_string(dtChId.
sector()) +
"_SL" + std::to_string(dtSLId.
superlayer());
397 return superLayerName;
403 string chamberName =
"W" + std::to_string(dtChId.
wheel()) +
"_St" + std::to_string(dtChId.
station()) +
"_Sec" +
404 std::to_string(dtChId.
sector());
412 for (
int SL = 1; SL <= 3; SL++) {
413 if (!(chId.
station() == 4 && SL == 2)) {
414 for (
int L = 1;
L <= 4;
L++) {
416 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
420 if (hOccHisto->GetXaxis()->GetXmax() > maximum)
421 maximum = hOccHisto->GetXaxis()->GetNbins();
433 for (
int L = 1;
L <= 4;
L++) {
435 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
439 if (hOccHisto->GetMaximum(
dummy) > maximum)
440 maximum = hOccHisto->GetMaximum(
dummy);