35 #include "TPostScript.h" 45 cout <<
"[DTNoiseComputation]: Constructor" <<endl;
55 theFile =
new TFile(rootFileName.c_str(),
"READ");
59 theNewFile =
new TFile(newRootFileName.c_str(),
"RECREATE");
74 string CheckHistoName;
77 TH1F *hAverageNoiseHisto;
78 TH1F *hAverageNoiseIntegratedHisto;
79 TH1F *hAverageNoiseHistoPerCh;
80 TH1F *hAverageNoiseIntegratedHistoPerCh;
84 string AverageNoiseName;
85 string AverageNoiseIntegratedName;
86 string AverageNoiseNamePerCh;
87 string AverageNoiseIntegratedNamePerCh;
92 vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
93 vector<const DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
95 for (; ch_it != ch_end; ++ch_it) {
97 vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
98 vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
100 for(; sl_it != sl_end; ++sl_it) {
102 vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
103 vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
105 for(; l_it != l_end; ++l_it) {
110 CheckHistoName =
"DigiOccupancy_" + getLayerName(dtLId);
111 TH1F *hCheckHisto = (TH1F *)
theFile->Get(CheckHistoName.c_str());
117 if(someHowNoisyC.find(make_pair(ch.
wheel(),ch.
station())) == someHowNoisyC.end()) {
118 TString histoName_someHowNoisy =
"somehowNoisyCell_W"+wheel+
"_St"+
station;
119 hsomeHowNoisyC =
new TH1F(histoName_someHowNoisy,histoName_someHowNoisy,getMaxNumBins(ch),1,getMaxNumBins(ch)+1);
120 someHowNoisyC[make_pair(ch.
wheel(),ch.
station())]=hsomeHowNoisyC;
123 if(noisyC.find(make_pair(ch.
wheel(),ch.
station())) == noisyC.end()) {
124 TString histoName_noisy =
"noisyCell_W"+wheel+
"_St"+
station;
125 hnoisyC =
new TH1F(histoName_noisy,histoName_noisy,getMaxNumBins(ch),1,getMaxNumBins(ch)+1);
130 if(AvNoisePerSuperLayer.find(dtLId.
superlayerId()) == AvNoisePerSuperLayer.end()) {
131 AverageNoiseName =
"AverageNoise_" + getSuperLayerName(dtLId.
superlayerId());
132 hAverageNoiseHisto =
new TH1F(AverageNoiseName.c_str(), AverageNoiseName.c_str(), 200, 0, 10000);
133 AverageNoiseIntegratedName =
"AverageNoiseIntegrated_" + getSuperLayerName(dtLId.
superlayerId());
134 hAverageNoiseIntegratedHisto =
new TH1F(AverageNoiseIntegratedName.c_str(), AverageNoiseIntegratedName.c_str(), 200, 0, 10000);
135 AvNoisePerSuperLayer[dtLId.
superlayerId()] = hAverageNoiseHisto;
136 AvNoiseIntegratedPerSuperLayer[dtLId.
superlayerId()] = hAverageNoiseIntegratedHisto;
138 cout <<
" New Average Noise Histo per SuperLayer : " << hAverageNoiseHisto->GetName() << endl;
139 cout <<
" New Average Noise Integrated Histo per SuperLayer : " << hAverageNoiseHisto->GetName() << endl;
143 AverageNoiseNamePerCh =
"AverageNoise_" + getChamberName(dtLId);
144 hAverageNoiseHistoPerCh =
new TH1F(AverageNoiseNamePerCh.c_str(), AverageNoiseNamePerCh.c_str(), 200, 0, 10000);
145 AverageNoiseIntegratedNamePerCh =
"AverageNoiseIntegrated_" + getChamberName(dtLId);
146 hAverageNoiseIntegratedHistoPerCh =
new TH1F(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);
155 hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
156 int numBin = hOccHisto->GetXaxis()->GetNbins();
159 theAverageNoise[wireID]= hOccHisto->GetBinContent(
bin);
160 if(theAverageNoise[wireID] != 0) {
161 AvNoisePerSuperLayer[dtLId.
superlayerId()]->Fill(theAverageNoise[wireID]);
169 HistoName =
"DigiOccupancy_" + getLayerName(dtLId);
171 hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
172 numBin = hOccHisto->GetXaxis()->GetNbins();
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 int updates = MaxEvents/1000;
195 for(
int evt=0; evt<updates; evt++){
196 Histo2Name =
"DigiPerWirePerEvent_" + getLayerName(dtLId) +
"_" + std::to_string(evt);
198 hEvtHisto = (TH2F *)
theFile->Get(Histo2Name.c_str());
201 cout <<
" New Histo with the number of events per evt per wire: " << hEvtHisto->GetName() << endl;
202 theEvtMap[dtLId].push_back(hEvtHisto);
218 cout <<
"[DTNoiseComputation] endjob called!" <<endl;
219 TH1F *hEvtDistance=
nullptr;
220 TF1 *ExpoFit =
new TF1(
"ExpoFit",
"expo", 0.5, 1000.5);
221 ExpoFit->SetMarkerColor();
222 TProfile *theNoiseHisto =
new TProfile(
"theNoiseHisto",
"Time Constant versus Average Noise",100000,0,100000);
226 for(
map<
DTLayerId, vector<TH2F*> >::const_iterator lHisto = theEvtMap.begin();
227 lHisto != theEvtMap.end();
229 for(
int bin=1;
bin<(*lHisto).second[0]->GetYaxis()->GetNbins();
bin++){
232 for(
int i=0;
i<
int((*lHisto).second.size());
i++){
233 for(
int evt=1; evt<=(*lHisto).second[
i]->GetXaxis()->GetNbins(); evt++){
234 if((*lHisto).second[
i]->GetBinContent(evt,
bin) == 0) distanceEvt++;
236 if(toDel.find(wire) == toDel.end()) {
238 string Histo =
"EvtDistancePerWire_" + getLayerName((*lHisto).first) +
"_" + std::to_string(
bin);
239 hEvtDistance =
new TH1F(Histo.c_str(),Histo.c_str(), 50000,0.5,50000.5);
241 hEvtDistance->Fill(distanceEvt);
246 if(toDel.find(wire) != toDel.end()){
247 theHistoEvtDistancePerWire[wire] = hEvtDistance;
249 theHistoEvtDistancePerWire[wire]->Fit(
"ExpoFit",
"R");
250 TF1*
funct = theHistoEvtDistancePerWire[wire]->GetFunction(
"ExpoFit");
251 double par0 = funct->GetParameter(0);
252 double par1 = funct->GetParameter(1);
253 cout<<
"par0: "<<par0<<
" par1: "<<par1<<endl;
254 double chi2rid = funct->GetChisquare()/funct->GetNDF();
256 theTimeConstant[wire]=1;
258 theTimeConstant[wire]=
par1;
260 theHistoEvtDistancePerWire[wire]->Write();
268 for(map<DTWireId, double>::const_iterator AvNoise = theAverageNoise.begin();
269 AvNoise != theAverageNoise.end();
272 theNoiseHisto->Fill((*AvNoise).second, theTimeConstant[wire]);
273 cout<<
"Layer: "<<getLayerName(wire.layerId())<<
" wire: "<<wire.wire()<<endl;
274 cout<<
"The Average noise: "<<(*AvNoise).second<<endl;
275 cout<<
"The time constant: "<<theTimeConstant[wire]<<endl;
278 theNoiseHisto->Write();
284 double integratedNoise,
bin, halfBin, maxBin;
285 for(map<DTSuperLayerId, TH1F*>::const_iterator AvNoiseHisto = AvNoisePerSuperLayer.begin();
286 AvNoiseHisto != AvNoisePerSuperLayer.end();
289 numBin = (*AvNoiseHisto).second->GetXaxis()->GetNbins();
290 maxBin = (*AvNoiseHisto).second->GetXaxis()->GetXmax();
291 bin= double(maxBin/numBin);
292 halfBin=double(bin/2);
294 (*AvNoiseHisto).second->Write();
295 for(
int i=1;
i<numBin;
i++){
296 integratedNoise+=(*AvNoiseHisto).second->GetBinContent(
i);
297 AvNoiseIntegratedPerSuperLayer[(*AvNoiseHisto).first]->Fill(halfBin,integratedNoise);
301 AvNoiseIntegratedPerSuperLayer[(*AvNoiseHisto).first]->Write();
304 for(map<DTChamberId, TH1F*>::const_iterator AvNoiseHisto = AvNoisePerChamber.begin();
305 AvNoiseHisto != AvNoisePerChamber.end();
308 numBin = (*AvNoiseHisto).second->GetXaxis()->GetNbins();
309 maxBin = (*AvNoiseHisto).second->GetXaxis()->GetXmax();
313 (*AvNoiseHisto).second->Write();
314 for(
int i=1;
i<numBin;
i++){
315 integratedNoise+=(*AvNoiseHisto).second->GetBinContent(
i);
316 AvNoiseIntegratedPerChamber[(*AvNoiseHisto).first]->Fill(halfBin,integratedNoise);
320 AvNoiseIntegratedPerChamber[(*AvNoiseHisto).first]->Write();
326 vector<const DTChamber*>::const_iterator chamber_it = dtGeom->chambers().begin();
327 vector<const DTChamber*>::const_iterator chamber_end = dtGeom->chambers().end();
329 for (; chamber_it != chamber_end; ++chamber_it) {
330 vector<const DTSuperLayer*>::const_iterator sl_it = (*chamber_it)->superLayers().begin();
331 vector<const DTSuperLayer*>::const_iterator sl_end = (*chamber_it)->superLayers().end();
333 for(; sl_it != sl_end; ++sl_it) {
335 vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
336 vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
338 string canvasName =
"c" + getSuperLayerName(sl);
339 TCanvas
c1(canvasName.c_str(),canvasName.c_str(),600,780);
340 TLegend *
leg=
new TLegend(0.5,0.6,0.7,0.8);
341 for(; l_it != l_end; ++l_it) {
343 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
345 TH1F *hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
347 string TitleHisto =
"AverageNoise_" + getSuperLayerName(sl);
348 cout<<
"TitleHisto : "<<TitleHisto<<endl;
349 hOccHisto->SetTitle(TitleHisto.c_str());
350 string legendHisto =
"layer " + std::to_string(layerId.
layer());
351 leg->AddEntry(hOccHisto,legendHisto.c_str(),
"L");
352 hOccHisto->SetMaximum(getYMaximum(sl));
354 if(layerId.
layer() == 1)
357 hOccHisto->Draw(
"same");
358 hOccHisto->SetLineColor(layerId.
layer());
371 for(
map<pair<int,int>, TH1F*>::const_iterator nCell = noisyC.begin();
372 nCell != noisyC.end();
375 (*nCell).second->Write();
377 for(
map<pair<int,int>, TH1F*>::const_iterator somehownCell = someHowNoisyC.begin();
378 somehownCell != someHowNoisyC.end();
381 (*somehownCell).second->Write();
400 "W" + std::to_string(dtChId.
wheel())
401 +
"_St" + std::to_string(dtChId.
station())
402 +
"_Sec" + std::to_string(dtChId.
sector())
404 +
"_L" + std::to_string(lId.
layer());
414 string superLayerName =
415 "W" + std::to_string(dtChId.
wheel())
416 +
"_St" + std::to_string(dtChId.
station())
417 +
"_Sec" + std::to_string(dtChId.
sector())
418 +
"_SL" + std::to_string(dtSLId.
superlayer());
420 return superLayerName;
429 "W" + std::to_string(dtChId.
wheel())
430 +
"_St" + std::to_string(dtChId.
station())
431 +
"_Sec" + std::to_string(dtChId.
sector());
441 for(
int SL=1; SL<=3; SL++){
442 if(!(chId.
station()==4 && SL==2)){
443 for (
int L=1;
L<=4;
L++){
445 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
447 TH1F *hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
449 if (hOccHisto->GetXaxis()->GetXmax()>maximum)
450 maximum = hOccHisto->GetXaxis()->GetNbins();
464 for (
int L=1;
L<=4;
L++){
466 string HistoName =
"DigiOccupancy_" + getLayerName(layerId);
468 TH1F *hOccHisto = (TH1F *)
theFile->Get(HistoName.c_str());
470 if (hOccHisto->GetMaximum(dummy)>maximum)
471 maximum = hOccHisto->GetMaximum(dummy);
DTNoiseComputation(const edm::ParameterSet &ps)
Constructor.
T getUntrackedParameter(std::string const &, T const &) const
int getMaxNumBins(const DTChamberId &chId) const
double getYMaximum(const DTSuperLayerId &slId) const
DTChamberId chamberId() const
Return the corresponding ChamberId.
def setup(process, global_tag, zero_tesla=False)
int layer() const
Return the layer number.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
std::string getChamberName(const DTLayerId &lId) const
Get the name of the chamber.
void endJob() override
Endjob.
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
bin
set the eta bin as selection string.
int superlayer() const
Return the superlayer number (deprecated method name)
~DTNoiseComputation() override
Destructor.
std::string getLayerName(const DTLayerId &lId) const
Get the name of the layer.
std::string getSuperLayerName(const DTSuperLayerId &slId) const
Get the name of the superLayer.
int station() const
Return the station number.
int wheel() const
Return the wheel number.
void beginRun(const edm::Run &, const edm::EventSetup &setup) override
Power< A, B >::type pow(const A &a, const B &b)